[IKO] Implement Companion and 2 companions

Keruga, the Macrosage and Umori, the Collector
This commit is contained in:
emerald000 2020-04-12 08:23:04 -04:00
parent 395ae9ec11
commit c3684a732b
21 changed files with 866 additions and 128 deletions

View file

@ -30,7 +30,7 @@ public class CardInfoWindowDialog extends MageDialog {
private static final Logger LOGGER = Logger.getLogger(CardInfoWindowDialog.class);
public enum ShowType {
REVEAL, REVEAL_TOP_LIBRARY, LOOKED_AT, EXILE, GRAVEYARD, OTHER
REVEAL, REVEAL_TOP_LIBRARY, LOOKED_AT, EXILE, GRAVEYARD, COMPANION, OTHER
}
private final ShowType showType;
@ -72,6 +72,10 @@ public class CardInfoWindowDialog extends MageDialog {
case EXILE:
this.setFrameIcon(new ImageIcon(ImageManagerImpl.instance.getExileImage()));
break;
case COMPANION:
this.setFrameIcon(new ImageIcon(ImageManagerImpl.instance.getTokenIconImage()));
this.setClosable(false);
break;
default:
// no icon yet
}

View file

@ -40,6 +40,7 @@ import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyVetoException;
import java.io.Serializable;
import java.util.List;
import java.util.*;
@ -74,6 +75,7 @@ public final class GamePanel extends javax.swing.JPanel {
private final Map<String, CardInfoWindowDialog> revealed = new HashMap<>();
private final Map<String, CardInfoWindowDialog> lookedAt = new HashMap<>();
private final Map<String, CardInfoWindowDialog> graveyardWindows = new HashMap<>();
private final Map<String, CardInfoWindowDialog> companion = new HashMap<>();
private final Map<String, CardsView> graveyards = new HashMap<>();
private final ArrayList<ShowCardsDialog> pickTarget = new ArrayList<>();
@ -241,6 +243,10 @@ public final class GamePanel extends javax.swing.JPanel {
lookedAtDialog.cleanUp();
lookedAtDialog.removeDialog();
}
for (CardInfoWindowDialog companionDialog : companion.values()) {
companionDialog.cleanUp();
companionDialog.removeDialog();
}
for (ShowCardsDialog pickTargetDialog : pickTarget) {
pickTargetDialog.cleanUp();
pickTargetDialog.removeDialog();
@ -275,6 +281,9 @@ public final class GamePanel extends javax.swing.JPanel {
for (CardInfoWindowDialog cardInfoWindowDialog : lookedAt.values()) {
cardInfoWindowDialog.changeGUISize();
}
for (CardInfoWindowDialog cardInfoWindowDialog : companion.values()) {
cardInfoWindowDialog.changeGUISize();
}
for (CardInfoWindowDialog cardInfoWindowDialog : graveyardWindows.values()) {
cardInfoWindowDialog.changeGUISize();
}
@ -781,6 +790,7 @@ public final class GamePanel extends javax.swing.JPanel {
showRevealed(game);
showLookedAt(game);
showCompanion(game);
if (!game.getCombat().isEmpty()) {
CombatManager.instance.showCombat(game.getCombat(), gameId);
} else {
@ -1085,6 +1095,9 @@ public final class GamePanel extends javax.swing.JPanel {
for (CardInfoWindowDialog lookedAtDialog : lookedAt.values()) {
lookedAtDialog.hideDialog();
}
for (CardInfoWindowDialog companionDialog : companion.values()) {
companionDialog.hideDialog();
}
}
// Called if the game frame comes to front again
@ -1102,6 +1115,9 @@ public final class GamePanel extends javax.swing.JPanel {
for (CardInfoWindowDialog lookedAtDialog : lookedAt.values()) {
lookedAtDialog.show();
}
for (CardInfoWindowDialog companionDialog : companion.values()) {
companionDialog.show();
}
}
public void openGraveyardWindow(String playerName) {
@ -1146,6 +1162,23 @@ public final class GamePanel extends javax.swing.JPanel {
removeClosedCardInfoWindows(lookedAt);
}
private void showCompanion(GameView game) {
for (RevealedView revealView : game.getCompanion()) {
handleGameInfoWindow(companion, ShowType.COMPANION, revealView.getName(), revealView.getCards());
}
// Close the companion view if not in the game view
companion.forEach((name, companionDialog) -> {
if (game.getCompanion().stream().noneMatch(revealedView -> revealedView.getName().equals(name))) {
try {
companionDialog.setClosed(true);
} catch (PropertyVetoException e) {
logger.error("Couldn't close companion dialog", e);
}
}
});
removeClosedCardInfoWindows(companion);
}
private void handleGameInfoWindow(Map<String, CardInfoWindowDialog> windowMap, ShowType showType, String name, LinkedHashMap cardsView) {
CardInfoWindowDialog cardInfoWindowDialog;
if (!windowMap.containsKey(name)) {
@ -1160,6 +1193,7 @@ public final class GamePanel extends javax.swing.JPanel {
switch (showType) {
case REVEAL:
case REVEAL_TOP_LIBRARY:
case COMPANION:
cardInfoWindowDialog.loadCards((CardsView) cardsView, bigCard, gameId);
break;
case LOOKED_AT:
@ -1332,6 +1366,22 @@ public final class GamePanel extends javax.swing.JPanel {
}
}
// companion
for (RevealedView rev : gameView.getCompanion()) {
for (Map.Entry<UUID, CardView> card : rev.getCards().entrySet()) {
if (needSelectable.contains(card.getKey())) {
card.getValue().setChoosable(true);
}
if (needChoosen.contains(card.getKey())) {
card.getValue().setSelected(true);
}
if (needPlayable.containsKey(card.getKey())) {
card.getValue().setPlayable(true);
card.getValue().setPlayableAmount(needPlayable.get(card.getKey()));
}
}
}
// looked at
for (LookedAtView look : gameView.getLookedAt()) {
for (Map.Entry<UUID, SimpleCardView> card : look.getCards().entrySet()) {