Show warning message if invalid decks on starting a new game.
parent
940c55cfeb
commit
78888c8151
|
@ -184,4 +184,8 @@ public class MagicDeck extends ArrayList<MagicCardDefinition> {
|
|||
? getDeckType().toString() + " / " + getName()
|
||||
: getName();
|
||||
}
|
||||
|
||||
public boolean isNotValid() {
|
||||
return !isValid();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -259,4 +259,9 @@ public class MagicDuel {
|
|||
instance.load(duelFile);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasInvalidDecks() {
|
||||
return !getPlayer(0).getDeck().isValid()
|
||||
|| !getPlayer(1).getDeck().isValid();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -463,8 +463,10 @@ public class MagicPlayer extends MagicObjectImpl implements MagicSource, MagicTa
|
|||
Thread thread = Thread.currentThread();
|
||||
for (int i = 0; i < deck.size() && thread.isInterrupted() == false; i++) {
|
||||
final MagicCardDefinition cardDefinition = deck.get(i);
|
||||
final long id = currGame.getUniqueId();
|
||||
library.add(new MagicCard(cardDefinition,this,id));
|
||||
if (cardDefinition.isValid()) {
|
||||
final long id = currGame.getUniqueId();
|
||||
library.add(new MagicCard(cardDefinition,this,id));
|
||||
}
|
||||
}
|
||||
|
||||
library.initialShuffle(MagicRandom.nextRNGInt());
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package magic.ui.screen.duel.decks;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.JOptionPane;
|
||||
import magic.data.DuelConfig;
|
||||
import magic.data.MagicIcon;
|
||||
import magic.exception.InvalidDeckException;
|
||||
|
@ -17,6 +17,7 @@ import magic.ui.IDeckProvider;
|
|||
import magic.ui.MagicImages;
|
||||
import magic.ui.ScreenController;
|
||||
import magic.ui.WikiPage;
|
||||
import magic.ui.helpers.MouseHelper;
|
||||
import magic.ui.screen.HeaderFooterScreen;
|
||||
import magic.ui.screen.deck.editor.IDeckEditorClient;
|
||||
import magic.ui.screen.widget.DuelSettingsPanel;
|
||||
|
@ -42,6 +43,9 @@ public class DuelDecksScreen extends HeaderFooterScreen
|
|||
private static final String _S12 = "Deck View";
|
||||
private static final String _S13 = "Shows complete deck using tiled card images.";
|
||||
private static final String _S14 = "%s's deck is illegal.\n\n%s";
|
||||
private static final String _S15 = "Invalid cards will not be included.";
|
||||
private static final String _S16 = "Start a new duel anyway?";
|
||||
private static final String _S17 = "Confirm new duel";
|
||||
|
||||
// UI components
|
||||
private DuelSettingsPanel settingsPanel;
|
||||
|
@ -51,6 +55,7 @@ public class DuelDecksScreen extends HeaderFooterScreen
|
|||
private OptionsPanel optionsPanel;
|
||||
|
||||
private MagicGame nextGame;
|
||||
private MagicDuel duel;
|
||||
|
||||
public DuelDecksScreen() {
|
||||
super(MText.get(_S1));
|
||||
|
@ -59,7 +64,7 @@ public class DuelDecksScreen extends HeaderFooterScreen
|
|||
|
||||
private void initUI() {
|
||||
|
||||
final MagicDuel duel = MagicDuel.instance;
|
||||
duel = MagicDuel.instance;
|
||||
|
||||
screenContent = new DuelDecksPanel(duel);
|
||||
nextGameButton = new StartGameButton(getStartDuelCaption(), getPlayGameAction());
|
||||
|
@ -167,14 +172,35 @@ public class DuelDecksScreen extends HeaderFooterScreen
|
|||
config.setCube(settingsPanel.getCube());
|
||||
}
|
||||
|
||||
private boolean confirmPlayWithInvalidDecks() {
|
||||
final String message = String.format("<html><b>%s</b><br><br>%s</html>",
|
||||
MText.get(_S15), MText.get(_S16)
|
||||
);
|
||||
final Object[] params = {message};
|
||||
final int n = JOptionPane.showConfirmDialog(screenContent,
|
||||
params,
|
||||
MText.get(_S17),
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
return n == JOptionPane.YES_OPTION;
|
||||
}
|
||||
|
||||
private void doPlayGame() {
|
||||
if (duel.getGamesPlayed() == 0 && duel.hasInvalidDecks()) {
|
||||
if (!confirmPlayWithInvalidDecks()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
updateDuelConfig();
|
||||
startNextGame();
|
||||
}
|
||||
|
||||
private AbstractAction getPlayGameAction() {
|
||||
return new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
updateDuelConfig();
|
||||
startNextGame();
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
MouseHelper.showBusyCursor();
|
||||
doPlayGame();
|
||||
MouseHelper.showDefaultCursor();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue