From 1a75c064902365832ac62626554c603d481840e8 Mon Sep 17 00:00:00 2001 From: tool4EvEr Date: Wed, 18 Dec 2024 20:35:59 +0100 Subject: [PATCH] Refactor menu opening --- .../src/main/java/forge/screens/match/CMatchUI.java | 11 +++++++---- .../java/forge/screens/match/controllers/CField.java | 8 +++++++- .../util/PlayerControllerForTests.java | 3 +-- .../src/forge/screens/match/MatchController.java | 9 ++++++--- .../src/forge/screens/match/views/VAvatar.java | 8 ++++++++ .../gamemodes/match/input/InputPassPriority.java | 9 --------- .../java/forge/gamemodes/net/server/NetGuiGame.java | 7 ------- .../src/main/java/forge/gui/interfaces/IGuiGame.java | 4 ---- .../src/main/java/forge/player/HumanCostDecision.java | 3 --- 9 files changed, 29 insertions(+), 33 deletions(-) diff --git a/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java b/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java index 40cdb688e02..05459f6074b 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java +++ b/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java @@ -19,6 +19,7 @@ import java.awt.*; import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Collection; @@ -1523,8 +1524,11 @@ private void createLandPopupPanel(Card land) { } } - @Override - public void showFullControl(PlayerView pv, Set controlFlags) { + public void showFullControl(PlayerView pv, MouseEvent e) { + if (pv.isAI()) { + return; + } + Set controlFlags = getGameView().getGame().getPlayer(pv).getController().getFullControl(); final String lblFullControl = Localizer.getInstance().getMessage("lblFullControl"); final JPopupMenu menu = new JPopupMenu(lblFullControl); GuiUtils.addMenuItem(menu, lblFullControl, null, () -> { @@ -1537,8 +1541,7 @@ public void showFullControl(PlayerView pv, Set controlFlags) { addFullControlEntry(menu, "lblNoFreeCombatCostHandling", FullControlFlag.NoFreeCombatCostHandling, controlFlags); addFullControlEntry(menu, "lblAllowPaymentStartWithMissingResources", FullControlFlag.AllowPaymentStartWithMissingResources, controlFlags); - Component parent = view.getControl().getFieldViewFor(pv).getAvatarArea(); - menu.show(parent, parent.getX(), parent.getY()); + menu.show(view.getControl().getFieldViewFor(pv).getAvatarArea(), e.getX(), e.getY()); } private void addFullControlEntry(JPopupMenu menu, String label, FullControlFlag flag, Set controlFlags) { diff --git a/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CField.java b/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CField.java index 2bb49c8c518..554c14e2680 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CField.java +++ b/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CField.java @@ -22,6 +22,8 @@ import java.awt.event.MouseListener; import java.util.function.Function; +import javax.swing.SwingUtilities; + import forge.game.player.PlayerView; import forge.game.zone.ZoneType; import forge.gamemodes.match.input.Input; @@ -46,7 +48,11 @@ public class CField implements ICDoc { private final MouseListener madAvatar = new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { - matchUI.getGameController().selectPlayer(player, new MouseTriggerEvent(e)); + if (SwingUtilities.isRightMouseButton(e)) { + matchUI.showFullControl(player, e); + } else { + matchUI.getGameController().selectPlayer(player, new MouseTriggerEvent(e)); + } } }; diff --git a/forge-gui-desktop/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java b/forge-gui-desktop/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java index d0dfd52faf9..44686e6f731 100644 --- a/forge-gui-desktop/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java +++ b/forge-gui-desktop/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java @@ -789,7 +789,6 @@ public List chooseSpellAbilitiesForEffect(List spell @Override public List orderCosts(List costs) { - // TODO Auto-generated method stub - return null; + return costs; } } diff --git a/forge-gui-mobile/src/forge/screens/match/MatchController.java b/forge-gui-mobile/src/forge/screens/match/MatchController.java index 240c81035a1..98c255ffa60 100644 --- a/forge-gui-mobile/src/forge/screens/match/MatchController.java +++ b/forge-gui-mobile/src/forge/screens/match/MatchController.java @@ -744,8 +744,11 @@ public static HostedMatch getHostedMatch() { return hostedMatch; } - @Override - public void showFullControl(PlayerView selected, Set controlFlags) { + public void showFullControl(PlayerView selected, float x, float y) { + if (selected.isAI()) { + return; + } + Set controlFlags = getGameView().getGame().getPlayer(selected).getController().getFullControl(); FPopupMenu menu = new FPopupMenu() { @Override protected void buildMenu() { @@ -761,7 +764,7 @@ protected void buildMenu() { } }; - menu.show(getView(), getView().getPlayerPanel(selected).localToScreenX(0), getView().getPlayerPanel(selected).localToScreenY(0)); + menu.show(getView(), getView().getPlayerPanel(selected).localToScreenX(x), getView().getPlayerPanel(selected).localToScreenY(y)); } private FCheckBoxMenuItem getFullControlMenuEntry(String label, FullControlFlag flag, Set controlFlags) { diff --git a/forge-gui-mobile/src/forge/screens/match/views/VAvatar.java b/forge-gui-mobile/src/forge/screens/match/views/VAvatar.java index ae087cf7180..424f0ccfddd 100644 --- a/forge-gui-mobile/src/forge/screens/match/views/VAvatar.java +++ b/forge-gui-mobile/src/forge/screens/match/views/VAvatar.java @@ -97,6 +97,7 @@ protected void onEnd(boolean endingAll) { player.setAvatarLifeDifference(0); } } + @Override public boolean tap(float x, float y, int count) { //must invoke in game thread in case a dialog needs to be shown @@ -104,6 +105,13 @@ public boolean tap(float x, float y, int count) { return true; } + @Override + public boolean longPress(float x, float y) { + //must invoke in game thread in case a dialog needs to be shown + ThreadUtil.invokeInGameThread(() -> MatchController.instance.showFullControl(player, x, y)); + return true; + } + public Vector2 getTargetingArrowOrigin() { Vector2 origin = new Vector2(this.screenPos.x, this.screenPos.y); origin.x += getWidth()-getWidth()/8f; diff --git a/forge-gui/src/main/java/forge/gamemodes/match/input/InputPassPriority.java b/forge-gui/src/main/java/forge/gamemodes/match/input/InputPassPriority.java index 9ba01c81c5c..1de6e932620 100644 --- a/forge-gui/src/main/java/forge/gamemodes/match/input/InputPassPriority.java +++ b/forge-gui/src/main/java/forge/gamemodes/match/input/InputPassPriority.java @@ -20,7 +20,6 @@ import forge.game.Game; import forge.game.card.Card; import forge.game.player.Player; -import forge.game.player.PlayerController; import forge.game.player.actions.PassPriorityAction; import forge.game.spellability.SpellAbility; import forge.localinstance.properties.ForgePreferences.FPref; @@ -121,14 +120,6 @@ private void passPriority(final Runnable runnable) { public List getChosenSa() { return chosenSa; } - @Override - protected final void onPlayerSelected(Player selected, final ITriggerEvent triggerEvent) { - PlayerController pc = selected.getController(); - if (!pc.isAI()) { - getController().getGui().showFullControl(selected.getView(), pc.getFullControl()); - } - } - @Override protected boolean onCardSelected(final Card card, final List otherCardsToSelect, final ITriggerEvent triggerEvent) { //remove unplayable unless triggerEvent specified, in which case unplayable may be shown as disabled options diff --git a/forge-gui/src/main/java/forge/gamemodes/net/server/NetGuiGame.java b/forge-gui/src/main/java/forge/gamemodes/net/server/NetGuiGame.java index 9674c4023fd..04f0e1fa70b 100644 --- a/forge-gui/src/main/java/forge/gamemodes/net/server/NetGuiGame.java +++ b/forge-gui/src/main/java/forge/gamemodes/net/server/NetGuiGame.java @@ -9,7 +9,6 @@ import forge.game.phase.PhaseType; import forge.game.player.DelayedReveal; import forge.game.player.IHasIcon; -import forge.game.player.PlayerController.FullControlFlag; import forge.game.player.PlayerView; import forge.game.spellability.SpellAbilityView; import forge.game.zone.ZoneType; @@ -26,7 +25,6 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.function.Function; public class NetGuiGame extends AbstractGuiGame { @@ -321,9 +319,4 @@ protected void updateCurrentPlayer(final PlayerView player) { // TODO Auto-generated method stub } - @Override - public void showFullControl(PlayerView view, Set controlFlags) { - // TODO Auto-generated method stub - } - } diff --git a/forge-gui/src/main/java/forge/gui/interfaces/IGuiGame.java b/forge-gui/src/main/java/forge/gui/interfaces/IGuiGame.java index b4899a77a7f..601bbb9b9cf 100644 --- a/forge-gui/src/main/java/forge/gui/interfaces/IGuiGame.java +++ b/forge-gui/src/main/java/forge/gui/interfaces/IGuiGame.java @@ -12,7 +12,6 @@ import forge.game.phase.PhaseType; import forge.game.player.DelayedReveal; import forge.game.player.IHasIcon; -import forge.game.player.PlayerController.FullControlFlag; import forge.game.player.PlayerView; import forge.game.spellability.SpellAbilityView; import forge.game.zone.ZoneType; @@ -28,7 +27,6 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.function.Function; public interface IGuiGame { @@ -275,6 +273,4 @@ public interface IGuiGame { void clearAutoYields(); void setCurrentPlayer(PlayerView player); - - void showFullControl(PlayerView view, Set controlFlags); } diff --git a/forge-gui/src/main/java/forge/player/HumanCostDecision.java b/forge-gui/src/main/java/forge/player/HumanCostDecision.java index 91d3112402b..71834f72e7d 100644 --- a/forge-gui/src/main/java/forge/player/HumanCostDecision.java +++ b/forge-gui/src/main/java/forge/player/HumanCostDecision.java @@ -1316,9 +1316,6 @@ public PaymentDecision visit(final CostUntapType cost) { CardCollection typeList = CardLists.getValidCards(player.getGame().getCardsIn(ZoneType.Battlefield), cost.getType().split(";"), player, source, ability); typeList = CardLists.filter(typeList, CardPredicates.TAPPED, c -> c.getCounters(CounterEnumType.STUN) == 0 || c.canRemoveCounters(CounterType.get(CounterEnumType.STUN))); - if (!cost.canUntapSource) { - typeList.remove(source); - } int c = cost.getAbilityAmount(ability); final InputSelectCardsFromList inp = new InputSelectCardsFromList(controller, c, c, typeList, ability); inp.setCancelAllowed(true);