Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Mage.Client/src/main/java/mage/client/MageFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,8 @@ private void endTables() {
* Use it after new images downloaded, new fonts or theme settings selected.
*/
public void refreshGUIAndCards() {
ThreadUtils.ensureRunInGUISwingThread();

ImageCaches.clearAll();

setGUISize();
Expand Down
15 changes: 8 additions & 7 deletions Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void update(Map<UUID, PermanentView> battlefield) {
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);
removePermanent(entry.getKey());
iterator.remove();
changed = true;
}
Expand Down Expand Up @@ -293,9 +293,12 @@ private void addPermanent(PermanentView permanent, final int count) {

permanents.put(permanent.getId(), perm);

perm.setAlpha(0f);
this.jPanel.add(perm, (Integer) 10);
moveToFront(jPanel);
Plugins.instance.onAddCard(perm, 1);
Plugins.instance.onAddCard(perm).thenRunAsync(() -> {
perm.setAlpha(1f);
}, SwingUtilities::invokeLater);

if (permanent.isArtifact()) {
addedArtifact = true;
Expand All @@ -306,19 +309,17 @@ private void addPermanent(PermanentView permanent, final int count) {
}
}

private void removePermanent(UUID permanentId, final int count) {
private void removePermanent(UUID permanentId) {
for (Component comp : this.jPanel.getComponents()) {
if (comp instanceof MageCard) {
MageCard mageCard = (MageCard) comp;
if (mageCard.getMainPanel() instanceof MagePermanent) {
MagePermanent magePermanent = (MagePermanent) mageCard.getMainPanel();
if (magePermanent.getOriginal().getId().equals(permanentId)) {
Thread t = new Thread(() -> {
Plugins.instance.onRemoveCard(mageCard, count);
Plugins.instance.onRemoveCard(mageCard).thenRunAsync(() -> {
mageCard.setVisible(false);
this.jPanel.remove(mageCard);
});
t.start();
}, SwingUtilities::invokeLater);
}
if (magePermanent.getOriginal().isCreature()) {
removedCreature = true;
Expand Down
4 changes: 2 additions & 2 deletions Mage.Client/src/main/java/mage/client/game/GamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
import mage.game.events.PlayerQueryEvent;
import mage.players.PlayableObjectStats;
import mage.players.PlayableObjectsList;
import mage.util.CardUtil;
import mage.util.DebugUtil;
import mage.util.MultiAmountMessage;
import mage.util.StreamUtils;
import mage.view.*;
import org.apache.log4j.Logger;
import org.mage.card.arcane.Animation;
import org.mage.plugins.card.utils.impl.ImageManagerImpl;

import javax.swing.Timer;
Expand Down Expand Up @@ -392,6 +391,7 @@ private Map<String, JComponent> getUIComponents(JLayeredPane jLayeredPane) {
}

public void cleanUp() {
Animation.cancelRunningAnimations(gameId);
MageFrame.removeGame(gameId);

this.gameChatPanel.cleanUp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.awt.image.BufferedImage;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

public interface MagePlugins {

Expand Down Expand Up @@ -41,9 +42,9 @@ public interface MagePlugins {

void addGamesPlayed();

void onAddCard(MageCard card, int count);
CompletableFuture<Void> onAddCard(MageCard card);

void onRemoveCard(MageCard card, int count);
CompletableFuture<Void> onRemoveCard(MageCard card);

JComponent getCardInfoPane();

Expand Down
17 changes: 11 additions & 6 deletions Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

import static org.mage.plugins.card.utils.CardImageUtils.getImagesDir;

Expand Down Expand Up @@ -186,17 +187,21 @@ public boolean isThemePluginLoaded() {
}

@Override
public void onAddCard(MageCard card, int count) {
if (this.cardPlugin != null) {
this.cardPlugin.onAddCard(card, count);
public CompletableFuture<Void> onAddCard(MageCard card) {
if (cardPlugin != null) {
return cardPlugin.onAddCard(card);
}

return CompletableFuture.completedFuture(null);
}

@Override
public void onRemoveCard(MageCard card, int count) {
if (this.cardPlugin != null) {
this.cardPlugin.onRemoveCard(card, count);
public CompletableFuture<Void> onRemoveCard(MageCard card) {
if (cardPlugin != null) {
return cardPlugin.onRemoveCard(card);
}

return CompletableFuture.completedFuture(null);
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions Mage.Client/src/main/java/mage/client/util/GUISizeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import mage.client.MageFrame;
import mage.client.dialog.PreferencesDialog;
import mage.client.util.gui.GuiDisplayUtil;
import mage.util.ThreadUtils;
import org.mage.card.arcane.CardRenderer;

import javax.swing.*;
Expand Down Expand Up @@ -90,6 +91,8 @@ public static Font getCardFont() {
* @param reloadTheme use it after theme changes only
*/
public static void refreshGUIAndCards(boolean reloadTheme) {
ThreadUtils.ensureRunInGUISwingThread();

calculateGUISizes();
if (reloadTheme) {
GuiDisplayUtil.refreshThemeSettings();
Expand Down
Loading
Loading