Skip to content

Commit 2bb888e

Browse files
Forward setUsedToPay highlights to network clients (Card-Forge#10272)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: tool4EvEr <tool4EvEr@>
1 parent ac1738b commit 2bb888e

11 files changed

Lines changed: 52 additions & 82 deletions

File tree

forge-gui-desktop/src/main/java/forge/view/arcane/CardPanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ protected final void paintComponent(final Graphics g) {
304304
final int offset = isTapped() && (!noBorderPref || cardImgHasAlpha) ? 1 : 0;
305305

306306
// Magenta outline for when card is chosen
307-
if (matchUI.isUsedToPay(getCard())) {
307+
if (matchUI.isHighlighted(getCard())) {
308308
g2d.setColor(Color.magenta);
309309
final int n2 = Math.max(1, Math.round(2 * cardWidth * CardPanel.SELECTED_BORDER_SIZE));
310310
g2d.fillRoundRect(cardXOffset - n2, (cardYOffset - n2) + offset, cardWidth + (n2 * 2), cardHeight + (n2 * 2), cornerSize + n2, cornerSize + n2);
@@ -577,7 +577,7 @@ else if (card.isBlocking()) {
577577
CardFaceSymbols.drawSymbol("phasing", g, stateXSymbols, ySymbols);
578578
}
579579

580-
if (matchUI.isUsedToPay(card)) {
580+
if (matchUI.isHighlighted(card)) {
581581
CardFaceSymbols.drawSymbol("sacrifice", g, (cardXOffset + (cardWidth / 2)) - 20,
582582
(cardYOffset + (cardHeight / 2)) - 20);
583583
}

forge-gui-mobile/src/forge/card/CardRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ public static void drawCardWithOverlays(Graphics g, CardView card, float x, floa
801801
CardFaceSymbols.drawSymbol("defend", g, combatXSymbols, ySymbols, otherSymbolsSize, otherSymbolsSize);
802802
}
803803

804-
if (MatchController.instance.isUsedToPay(card)) {
804+
if (MatchController.instance.isHighlighted(card)) {
805805
float sacSymbolSize = otherSymbolsSize * 1.2f;
806806
CardFaceSymbols.drawSymbol("sacrifice", g, (x + (w / 2)) - sacSymbolSize / 2, (y + (h / 2)) - sacSymbolSize / 2, otherSymbolsSize, otherSymbolsSize);
807807
}
@@ -815,7 +815,7 @@ public static void drawCardWithOverlays(Graphics g, CardView card, float x, floa
815815
g.fillRect(FSkinColor.getStandardColor(Color.BLACK).alphaColor(0.6f), cx, cy, cw, ch);
816816
}
817817
//Magenta outline when card is chosen
818-
if (MatchController.instance.isUsedToPay(card)) {
818+
if (MatchController.instance.isHighlighted(card)) {
819819
g.drawRect(BORDER_THICKNESS, Color.MAGENTA, cx, cy, cw, ch);
820820
}
821821
//Ability Icons

forge-gui/src/main/java/forge/gamemodes/match/AbstractGuiGame.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package forge.gamemodes.match;
22

33
import com.google.common.collect.*;
4+
import forge.game.GameEntityView;
45
import forge.game.GameLog;
56
import forge.game.GameView;
67
import forge.game.card.CardView;
@@ -278,33 +279,24 @@ public boolean mayFlip(final CardView cv) {
278279
}
279280
}
280281

281-
private final Set<PlayerView> highlightedPlayers = Sets.newHashSet();
282+
private final Set<GameEntityView> highlighted = Sets.newHashSet();
282283

283284
@Override
284-
public void setHighlighted(final PlayerView pv, final boolean b) {
285-
final boolean hasChanged = b ? highlightedPlayers.add(pv) : highlightedPlayers.remove(pv);
285+
public void setHighlighted(final GameEntityView gv, final boolean b) {
286+
final boolean hasChanged = b ? highlighted.add(gv) : highlighted.remove(gv);
286287
if (hasChanged) {
287-
updateLives(Collections.singleton(pv));
288-
}
289-
}
290-
291-
public boolean isHighlighted(final PlayerView player) {
292-
return highlightedPlayers.contains(player);
293-
}
294-
295-
private final Set<CardView> highlightedCards = Sets.newHashSet();
296-
297-
// used to highlight cards in UI
298-
@Override
299-
public void setUsedToPay(final CardView card, final boolean value) {
300-
final boolean hasChanged = value ? highlightedCards.add(card) : highlightedCards.remove(card);
301-
if (hasChanged) { // since we are in UI thread, may redraw the card right now
302-
updateSingleCard(card);
288+
if (gv instanceof PlayerView pv) {
289+
updateLives(Collections.singleton(pv));
290+
}
291+
if (gv instanceof CardView cv) {
292+
// since we are in UI thread, may redraw the card right now
293+
updateSingleCard(cv);
294+
}
303295
}
304296
}
305297

306-
public boolean isUsedToPay(final CardView card) {
307-
return highlightedCards.contains(card);
298+
public boolean isHighlighted(final GameEntityView ge) {
299+
return highlighted.contains(ge);
308300
}
309301

310302
private final Set<CardView> selectableCards = Sets.newHashSet();

forge-gui/src/main/java/forge/gamemodes/match/input/InputAttack.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import forge.game.event.GameEventCombatUpdate;
3030
import forge.game.keyword.Keyword;
3131
import forge.game.player.Player;
32-
import forge.game.player.PlayerView;
3332
import forge.game.staticability.StaticAbilityMustAttack;
3433
import forge.game.zone.ZoneType;
3534
import forge.gui.events.UiEventAttackerDeclared;
@@ -288,7 +287,7 @@ private void declareAttacker(final Card card) {
288287

289288
private boolean undeclareAttacker(final Card card) {
290289
combat.removeFromCombat(card);
291-
getController().getGui().setUsedToPay(CardView.get(card), false);
290+
getController().getGui().setHighlighted(CardView.get(card), false);
292291
// When removing an attacker clear the attacking band
293292
activateBand(null);
294293

@@ -300,12 +299,7 @@ private boolean undeclareAttacker(final Card card) {
300299
private void setCurrentDefender(final GameEntity def) {
301300
currentDefender = def;
302301
for (final GameEntity ge : defenders) {
303-
if (ge instanceof Card) {
304-
getController().getGui().setUsedToPay(CardView.get((Card) ge), ge == def);
305-
}
306-
else if (ge instanceof Player) {
307-
getController().getGui().setHighlighted(PlayerView.get((Player) ge), ge == def);
308-
}
302+
getController().getGui().setHighlighted(GameEntityView.get(ge), ge == def);
309303
}
310304
if (def != null) {
311305
potentialBanding = isBandingPossible();
@@ -317,14 +311,14 @@ else if (ge instanceof Player) {
317311
private void activateBand(final AttackingBand band) {
318312
if (activeBand != null) {
319313
for (final Card card : activeBand.getAttackers()) {
320-
getController().getGui().setUsedToPay(CardView.get(card), false);
314+
getController().getGui().setHighlighted(CardView.get(card), false);
321315
}
322316
}
323317
activeBand = band;
324318

325319
if (activeBand != null) {
326320
for (final Card card : activeBand.getAttackers()) {
327-
getController().getGui().setUsedToPay(CardView.get(card), true);
321+
getController().getGui().setHighlighted(CardView.get(card), true);
328322
}
329323
}
330324
}

forge-gui/src/main/java/forge/gamemodes/match/input/InputBlock.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ public final boolean onCardSelected(final Card card, final List<Card> otherCards
129129
if (isCorrectAction) {
130130
combat.addBlocker(currentAttacker, card);
131131
card.getGame().getMatch().fireEvent(new UiEventBlockerAssigned(
132-
CardView.get(card),
133-
CardView.get(currentAttacker)));
132+
CardView.get(card), CardView.get(currentAttacker)));
134133
}
135134
}
136135
}
@@ -162,9 +161,12 @@ public String getActivateAction(Card card) {
162161
}
163162

164163
private void setCurrentAttacker(final Card card) {
164+
if (currentAttacker != null) {
165+
getController().getGui().setHighlighted(CardView.get(currentAttacker), false);
166+
}
165167
currentAttacker = card;
166-
for (final Card c : combat.getAttackers()) {
167-
getController().getGui().setUsedToPay(CardView.get(c), card == c);
168+
if (card != null) {
169+
getController().getGui().setHighlighted(CardView.get(card), true);
168170
}
169171
}
170172
}

forge-gui/src/main/java/forge/gamemodes/match/input/InputLondonMulligan.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ public String getActivateAction(final Card card) {
133133
}
134134

135135
private void setCardHighlight(final Card card, final boolean state) {
136-
getController().getGui().setUsedToPay(card.getView(), state);
136+
getController().getGui().setHighlighted(card.getView(), state);
137137
}
138138

139139
private void resetCardHighlights() {
140140
for (final Card c : selected) {
141-
getController().getGui().setUsedToPay(c.getView(), false);
141+
getController().getGui().setHighlighted(c.getView(), false);
142142
}
143143
}
144144
}

forge-gui/src/main/java/forge/gamemodes/match/input/InputSelectManyBase.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import com.google.common.collect.Iterables;
44
import forge.game.GameEntity;
5-
import forge.game.card.Card;
5+
import forge.game.GameEntityView;
66
import forge.game.card.CardView;
7-
import forge.game.player.Player;
8-
import forge.game.player.PlayerView;
97
import forge.game.spellability.SpellAbility;
108
import forge.localinstance.properties.ForgePreferences;
119
import forge.model.FModel;
@@ -125,23 +123,13 @@ public void setMessage(String message0) {
125123
this.message = message0;
126124
}
127125

128-
protected void onSelectStateChanged(final GameEntity c, final boolean newState) {
129-
if (c instanceof Card) {
130-
getController().getGui().setUsedToPay(CardView.get((Card) c), newState); // UI supports card highlighting though this abstraction-breaking mechanism
131-
}
132-
else if (c instanceof Player) {
133-
getController().getGui().setHighlighted(PlayerView.get((Player) c), newState);
134-
}
126+
protected void onSelectStateChanged(final GameEntity ge, final boolean newState) {
127+
getController().getGui().setHighlighted(GameEntityView.get(ge), newState);
135128
}
136129

137130
private void resetUsedToPay() {
138-
for (final GameEntity c : getSelected()) {
139-
if (c instanceof Card) {
140-
getController().getGui().setUsedToPay(CardView.get((Card) c), false);
141-
}
142-
else if (c instanceof Player) {
143-
getController().getGui().setHighlighted(PlayerView.get((Player) c), false);
144-
}
131+
for (final GameEntity ge : getSelected()) {
132+
getController().getGui().setHighlighted(GameEntityView.get(ge), false);
145133
}
146134
}
147135

forge-gui/src/main/java/forge/gamemodes/match/input/InputSelectTargets.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import com.google.common.collect.Lists;
55
import com.google.common.collect.Sets;
66
import forge.game.GameEntity;
7+
import forge.game.GameEntityView;
78
import forge.game.GameObject;
89
import forge.game.ability.ApiType;
910
import forge.game.card.Card;
1011
import forge.game.card.CardView;
1112
import forge.game.player.Player;
12-
import forge.game.player.PlayerView;
1313
import forge.game.spellability.SpellAbility;
1414
import forge.game.spellability.TargetRestrictions;
1515
import forge.gui.FThreads;
@@ -71,7 +71,7 @@ public InputSelectTargets(final PlayerControllerHuman controller, final List<Car
7171
FThreads.invokeInEdtNowOrLater(() -> {
7272
for (final GameEntity c : targets) {
7373
if (c instanceof Card) {
74-
controller.getGui().setUsedToPay(CardView.get((Card) c), true);
74+
controller.getGui().setHighlighted(GameEntityView.get(c), true);
7575
}
7676
}
7777
controller.getGui().updateZones(zonesToUpdate);
@@ -382,14 +382,11 @@ else if (sa.getApi() == ApiType.PutCounter) {
382382

383383
private void addTarget(final GameEntity ge) {
384384
sa.getTargets().add(ge);
385-
if (ge instanceof Card) {
386-
getController().getGui().setUsedToPay(CardView.get((Card) ge), true);
387-
lastTarget = (Card) ge;
388-
}
389-
else if (ge instanceof Player) {
390-
getController().getGui().setHighlighted(PlayerView.get((Player) ge), true);
391-
}
392385
targets.add(ge);
386+
if (ge instanceof Card c) {
387+
lastTarget = c;
388+
}
389+
getController().getGui().setHighlighted(GameEntityView.get(ge), true);
393390

394391
if (hasAllTargets()) {
395392
bOk = true;
@@ -410,27 +407,19 @@ private void removeTarget(final GameEntity ge) {
410407
}
411408
targets.remove(ge);
412409
sa.getTargets().remove(ge);
413-
if (ge instanceof Card c) {
414-
getController().getGui().setUsedToPay(CardView.get(c), false);
410+
if (ge instanceof Card) {
415411
// try to get last selected card
416412
lastTarget = Iterables.getLast(IterableUtil.filter(targets, Card.class), null);
417413
}
418-
else if (ge instanceof Player p) {
419-
getController().getGui().setHighlighted(PlayerView.get(p), false);
420-
}
414+
getController().getGui().setHighlighted(GameEntityView.get(ge), false);
421415

422416
this.showMessage();
423417
}
424418

425419
private void done() {
426-
for (final GameEntity c : targets) {
420+
for (final GameEntity ge : targets) {
427421
//getController().macros().addRememberedAction(new TargetEntityAction(c.getView()));
428-
if (c instanceof Card) {
429-
getController().getGui().setUsedToPay(CardView.get((Card) c), false);
430-
}
431-
else if (c instanceof Player) {
432-
getController().getGui().setHighlighted(PlayerView.get((Player) c), false);
433-
}
422+
getController().getGui().setHighlighted(GameEntityView.get(ge), false);
434423
}
435424

436425
this.stop();

forge-gui/src/main/java/forge/gamemodes/net/ProtocolMethod.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public enum ProtocolMethod {
7373
setRememberedActions(Mode.SERVER, Void.TYPE),
7474
nextRememberedAction(Mode.SERVER, Void.TYPE),
7575
showWaitingTimer (Mode.SERVER, Void.TYPE, PlayerView.class, String.class),
76+
setHighlighted (Mode.SERVER, Void.TYPE, GameEntityView.class, Boolean.TYPE),
7677
handleGameEvents (Mode.SERVER, Void.TYPE, List.class),
7778

7879
// Client -> Server

forge-gui/src/main/java/forge/gamemodes/net/server/NetGuiGame.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ public List<CardView> manipulateCardList(final String title, final Iterable<Card
278278
return sendAndWait(ProtocolMethod.manipulateCardList, title, cards, manipulable, toTop, toBottom, toAnywhere);
279279
}
280280

281+
@Override
282+
public void setHighlighted(final GameEntityView ge, final boolean value) {
283+
super.setHighlighted(ge, value);
284+
send(ProtocolMethod.setHighlighted, ge, value);
285+
}
286+
281287
@Override
282288
public void setCard(final CardView card) {
283289
updateGameView();

0 commit comments

Comments
 (0)