mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 03:51:58 -08:00
GUI: added stacked feature for a same creature tokens (#12256)
This commit is contained in:
parent
199345db07
commit
f53c9da3e4
2 changed files with 66 additions and 23 deletions
|
|
@ -63,7 +63,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
|
||||
private javax.swing.Timer gameUpdateTimer; // timer for custom GUI re-drawing (example: update attack arrows)
|
||||
|
||||
//private static int iCounter = 0;
|
||||
// private static int iCounter = 0;
|
||||
private boolean addedPermanent;
|
||||
private boolean addedArtifact;
|
||||
private boolean addedCreature;
|
||||
|
|
@ -89,10 +89,10 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
}
|
||||
});
|
||||
|
||||
gameUpdateTimer = new Timer(GAME_REDRAW_TIMEOUT_MS, evt -> SwingUtilities.invokeLater(() -> {
|
||||
gameUpdateTimer = new Timer(GAME_REDRAW_TIMEOUT_MS, evt -> SwingUtilities.invokeLater(() -> {
|
||||
gameUpdateTimer.stop();
|
||||
ClientCallback updateMessage = new ClientCallback(ClientCallbackMethod.GAME_REDRAW_GUI, gameId);
|
||||
MageFrame.getInstance().onCallback(updateMessage);
|
||||
ClientCallback updateMessage = new ClientCallback(ClientCallbackMethod.GAME_REDRAW_GUI, gameId);
|
||||
MageFrame.getInstance().onCallback(updateMessage);
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
@ -151,6 +151,32 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
}
|
||||
MageCard oldFound = permanents.get(permanent.getId());
|
||||
MagePermanent oldMagePermanent = oldFound == null ? null : (MagePermanent) oldFound.getMainPanel();
|
||||
|
||||
// Check if there was a change in the power or toughness of the permanent
|
||||
int permanentPower = 0;
|
||||
int permanentToughness = 0;
|
||||
int oldMagePermanentPower = 0;
|
||||
int oldMagePermanentToughness = 0;
|
||||
if (permanent != null && oldMagePermanent != null && permanent.getOriginal() != null
|
||||
&& oldMagePermanent.getOriginal() != null) {
|
||||
permanentPower = permanent.getOriginal().getOriginalPower() != null
|
||||
? permanent.getOriginal().getOriginalPower().getValue()
|
||||
: 0;
|
||||
permanentToughness = permanent.getOriginal().getOriginalToughness() != null
|
||||
? permanent.getOriginal().getOriginalToughness().getValue()
|
||||
: 0;
|
||||
oldMagePermanentPower = oldMagePermanent.getOriginal().getOriginalPower() != null
|
||||
? oldMagePermanent.getOriginal().getOriginalPower().getValue()
|
||||
: 0;
|
||||
oldMagePermanentToughness = oldMagePermanent.getOriginal().getOriginalToughness() != null
|
||||
? oldMagePermanent.getOriginal().getOriginalToughness().getValue()
|
||||
: 0;
|
||||
|
||||
if (permanentPower != oldMagePermanentPower || permanentToughness != oldMagePermanentToughness) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (oldMagePermanent == null) {
|
||||
permanentsToAdd.add(permanent);
|
||||
changed = true;
|
||||
|
|
@ -182,7 +208,8 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
if (!changed) {
|
||||
UUID attachedToIdBefore = oldMagePermanent.getOriginalPermanent().getAttachedTo();
|
||||
UUID attachedToId = permanent.getAttachedTo();
|
||||
if (attachedToIdBefore == null && attachedToId != null || attachedToId == null && attachedToIdBefore != null
|
||||
if (attachedToIdBefore == null && attachedToId != null
|
||||
|| attachedToId == null && attachedToIdBefore != null
|
||||
|| (attachedToIdBefore != null && !attachedToIdBefore.equals(attachedToId))) {
|
||||
changed = true;
|
||||
}
|
||||
|
|
@ -219,7 +246,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
|
||||
removedCreature = false;
|
||||
|
||||
for (Iterator<Entry<UUID, MageCard>> iterator = permanents.entrySet().iterator(); iterator.hasNext(); ) {
|
||||
for (Iterator<Entry<UUID, MageCard>> iterator = permanents.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<UUID, MageCard> entry = iterator.next();
|
||||
if (!battlefield.containsKey(entry.getKey()) || !battlefield.get(entry.getKey()).isPhasedIn()) {
|
||||
removePermanent(entry.getKey(), 1);
|
||||
|
|
@ -254,13 +281,15 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
|
||||
private void addPermanent(PermanentView permanent, final int count) {
|
||||
if (cardDimension == null) {
|
||||
cardDimension = new Dimension(ClientDefaultSettings.dimensions.getFrameWidth(), ClientDefaultSettings.dimensions.getFrameHeight());
|
||||
cardDimension = new Dimension(ClientDefaultSettings.dimensions.getFrameWidth(),
|
||||
ClientDefaultSettings.dimensions.getFrameHeight());
|
||||
}
|
||||
final MageCard perm = Plugins.instance.getMagePermanent(permanent, bigCard, new CardIconRenderSettings(), cardDimension, gameId, true, PreferencesDialog.getRenderMode(), true);
|
||||
final MageCard perm = Plugins.instance.getMagePermanent(permanent, bigCard, new CardIconRenderSettings(),
|
||||
cardDimension, gameId, true, PreferencesDialog.getRenderMode(), true);
|
||||
perm.setCardContainerRef(jPanel);
|
||||
perm.update(permanent);
|
||||
// cards sizes changes in parent call by sortLayout
|
||||
//perm.setCardBounds
|
||||
// perm.setCardBounds
|
||||
|
||||
permanents.put(permanent.getId(), perm);
|
||||
|
||||
|
|
|
|||
|
|
@ -113,7 +113,6 @@ public class CardPluginImpl implements CardPlugin {
|
|||
needFullPermanentRender);
|
||||
default:
|
||||
throw new IllegalStateException("Unknown render mode " + renderMode);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +144,7 @@ public class CardPluginImpl implements CardPlugin {
|
|||
continue;
|
||||
}
|
||||
|
||||
if ((!perm.isLand() && !perm.isToken()) || (perm.isCreature())) {
|
||||
if ((!perm.isLand() && !perm.isToken()) || (perm.isCreature() && !perm.isToken())) {
|
||||
Stack newStack = new Stack();
|
||||
newStack.add(perm);
|
||||
workingRow.add(newStack);
|
||||
|
|
@ -153,6 +152,17 @@ public class CardPluginImpl implements CardPlugin {
|
|||
}
|
||||
|
||||
int insertIndex = -1;
|
||||
int cardPower = perm.getOriginal().getOriginalPower() != null
|
||||
? perm.getOriginal().getOriginalPower().getValue()
|
||||
: 0;
|
||||
int cardToughness = perm.getOriginal().getOriginalToughness() != null
|
||||
? perm.getOriginalPermanent().getOriginalToughness().getValue()
|
||||
: 0;
|
||||
List<CounterView> cardCounters = perm.getOriginalPermanent().getCounters() != null
|
||||
? perm.getOriginalPermanent().getCounters()
|
||||
: Collections.emptyList();
|
||||
List<String> cardAbilities = perm.getOriginal().getRules() != null ? perm.getOriginal().getRules()
|
||||
: new ArrayList<>();
|
||||
|
||||
// Find already added to with the same name.
|
||||
for (int i = 0, n = workingRow.size(); i < n; i++) {
|
||||
|
|
@ -161,8 +171,23 @@ public class CardPluginImpl implements CardPlugin {
|
|||
Stack stack = workingRow.get(i);
|
||||
MagePermanent firstPanelPerm = stack.get(0);
|
||||
|
||||
int stackPower = firstPanelPerm.getOriginal().getOriginalPower() != null
|
||||
? firstPanelPerm.getOriginal().getOriginalPower().getValue()
|
||||
: 0;
|
||||
int stackToughness = firstPanelPerm.getOriginal().getOriginalToughness() != null
|
||||
? firstPanelPerm.getOriginal().getOriginalToughness().getValue()
|
||||
: 0;
|
||||
List<CounterView> stackCounters = firstPanelPerm.getOriginalPermanent().getCounters() != null
|
||||
? firstPanelPerm.getOriginalPermanent().getCounters()
|
||||
: Collections.emptyList();
|
||||
|
||||
List<String> stackAbilities = firstPanelPerm.getOriginal().getRules() != null
|
||||
? firstPanelPerm.getOriginal().getRules()
|
||||
: new ArrayList<>();
|
||||
// Check the names are equal and are creatures with the same summoning sickness
|
||||
if (firstPanelPerm.getOriginal().getName().equals(perm.getOriginal().getName())
|
||||
&& stackPower == cardPower && stackToughness == cardToughness
|
||||
&& stackAbilities.equals(cardAbilities) && stackCounters.equals(cardCounters)
|
||||
&& (!perm.isCreature() || firstPanelPerm.getOriginalPermanent().hasSummoningSickness() == perm
|
||||
.getOriginalPermanent().hasSummoningSickness())) {
|
||||
|
||||
|
|
@ -171,24 +196,13 @@ public class CardPluginImpl implements CardPlugin {
|
|||
insertIndex = i;
|
||||
break;
|
||||
}
|
||||
List<CounterView> counters = firstPanelPerm.getOriginalPermanent().getCounters();
|
||||
if (counters != null && !counters.isEmpty()) {
|
||||
// don't put to first panel if it has counters
|
||||
insertIndex = i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty(perm.getOriginalPermanent().getAttachments()) || stack.size() == cardStackMax) {
|
||||
// If this land has attachments or the stack is full, put it to the right.
|
||||
insertIndex = i + 1;
|
||||
continue;
|
||||
}
|
||||
counters = perm.getOriginalPermanent().getCounters();
|
||||
if (counters != null && !counters.isEmpty()) {
|
||||
// if a land has counter, put it to the right
|
||||
insertIndex = i + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add to stack.
|
||||
stack.add(0, perm);
|
||||
continue outerLoop;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue