Skip to content

Commit

Permalink
Refactor menu opening
Browse files Browse the repository at this point in the history
  • Loading branch information
tool4EvEr authored and tool4EvEr committed Dec 18, 2024
1 parent 932d02f commit 1a75c06
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1523,8 +1524,11 @@ private void createLandPopupPanel(Card land) {
}
}

@Override
public void showFullControl(PlayerView pv, Set<FullControlFlag> controlFlags) {
public void showFullControl(PlayerView pv, MouseEvent e) {
if (pv.isAI()) {
return;
}
Set<FullControlFlag> 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, () -> {
Expand All @@ -1537,8 +1541,7 @@ public void showFullControl(PlayerView pv, Set<FullControlFlag> 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<FullControlFlag> controlFlags) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,6 @@ public List<SpellAbility> chooseSpellAbilitiesForEffect(List<SpellAbility> spell

@Override
public List<CostPart> orderCosts(List<CostPart> costs) {
// TODO Auto-generated method stub
return null;
return costs;
}
}
9 changes: 6 additions & 3 deletions forge-gui-mobile/src/forge/screens/match/MatchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,11 @@ public static HostedMatch getHostedMatch() {
return hostedMatch;
}

@Override
public void showFullControl(PlayerView selected, Set<FullControlFlag> controlFlags) {
public void showFullControl(PlayerView selected, float x, float y) {
if (selected.isAI()) {
return;
}
Set<FullControlFlag> controlFlags = getGameView().getGame().getPlayer(selected).getController().getFullControl();
FPopupMenu menu = new FPopupMenu() {
@Override
protected void buildMenu() {
Expand All @@ -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<FullControlFlag> controlFlags) {
Expand Down
8 changes: 8 additions & 0 deletions forge-gui-mobile/src/forge/screens/match/views/VAvatar.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,21 @@ 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
ThreadUtil.invokeInGameThread(() -> MatchController.instance.getGameController().selectPlayer(player, null));
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,14 +120,6 @@ private void passPriority(final Runnable runnable) {

public List<SpellAbility> 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<Card> otherCardsToSelect, final ITriggerEvent triggerEvent) {
//remove unplayable unless triggerEvent specified, in which case unplayable may be shown as disabled options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -321,9 +319,4 @@ protected void updateCurrentPlayer(final PlayerView player) {
// TODO Auto-generated method stub
}

@Override
public void showFullControl(PlayerView view, Set<FullControlFlag> controlFlags) {
// TODO Auto-generated method stub
}

}
4 changes: 0 additions & 4 deletions forge-gui/src/main/java/forge/gui/interfaces/IGuiGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -275,6 +273,4 @@ public interface IGuiGame {
void clearAutoYields();

void setCurrentPlayer(PlayerView player);

void showFullControl(PlayerView view, Set<FullControlFlag> controlFlags);
}
3 changes: 0 additions & 3 deletions forge-gui/src/main/java/forge/player/HumanCostDecision.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1a75c06

Please sign in to comment.