diff --git a/Mage.Client/src/main/java/mage/client/components/KeyBindButton.java b/Mage.Client/src/main/java/mage/client/components/KeyBindButton.java new file mode 100644 index 00000000000..ff842f4a3b5 --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/components/KeyBindButton.java @@ -0,0 +1,94 @@ +package mage.client.components; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPopupMenu; + +/** + * + * @author Campbell Suter + */ +public class KeyBindButton extends JButton implements ActionListener { + + private final JPopupMenu menu; + private final PopupItem item; + private int keyCode; + private String text; + + public KeyBindButton() { + menu = new JPopupMenu(); + menu.add(item = new PopupItem()); + addActionListener(this); + + fixText(); + } + + private void applyNewKeycode(int code) { + keyCode = code; + switch (keyCode) { + case KeyEvent.VK_ESCAPE: + case KeyEvent.VK_SPACE: + keyCode = 0; + } + fixText(); + menu.setVisible(false); + setSize(getPreferredSize()); + System.out.println("text: " + text); + } + + private void fixText() { + if (keyCode == 0) { + text = ""; + } else { + text = KeyEvent.getKeyText(keyCode); + } + repaint(); + } + + public void setKeyCode(int keyCode) { + this.keyCode = keyCode; + fixText(); + } + + public int getKeyCode() { + return keyCode; + } + + @Override + public String getText() { + return text; + } + + @Override + public void actionPerformed(ActionEvent e) { + menu.show(this, 0, 0); + item.requestFocusInWindow(); + } + + private class PopupItem extends JLabel implements KeyListener { + + public PopupItem() { + super("Press a key"); + addKeyListener(this); + setFocusable(true); + } + + @Override + public void keyTyped(KeyEvent e) { + } + + @Override + public void keyPressed(KeyEvent e) { + applyNewKeycode(e.getKeyCode()); + } + + @Override + public void keyReleased(KeyEvent e) { + } + + } +} diff --git a/Mage.Client/src/main/java/mage/client/components/KeyboundButton.java b/Mage.Client/src/main/java/mage/client/components/KeyboundButton.java new file mode 100644 index 00000000000..c1f806cd712 --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/components/KeyboundButton.java @@ -0,0 +1,40 @@ +package mage.client.components; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import javax.swing.JButton; +import mage.client.dialog.PreferencesDialog; + +/** + * + * @author Campbell Suter + */ +public class KeyboundButton extends JButton { + + private final String text; + private static final Font keyFont = new Font(Font.SANS_SERIF, Font.BOLD, 13); + + public KeyboundButton(String key) { + text = PreferencesDialog.getCachedKeyText(key); + } + + @Override + protected void paintComponent(Graphics g) { + if (ui != null && g != null) { + Graphics sg = g.create(); + try { + ui.update(sg, this); + sg.setColor(Color.white); + sg.setFont(keyFont); + + int textWidth = sg.getFontMetrics(keyFont).stringWidth(text); + int centerX = (getWidth() - textWidth) / 2; + + sg.drawString(text, centerX, 28); + } finally { + sg.dispose(); + } + } + } +} diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form index 4cf0b3303cc..7a3e9afd3ee 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form @@ -3949,7 +3949,7 @@ - + @@ -4171,7 +4171,7 @@ - + @@ -4230,7 +4230,7 @@ - + @@ -4744,7 +4744,7 @@ - + @@ -5655,7 +5655,7 @@ - + @@ -5874,6 +5874,206 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java index 57ab43e6e32..f8a02a5cd03 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -37,6 +37,7 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Image; import java.awt.Rectangle; +import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; @@ -56,10 +57,12 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.JTextField; +import javax.swing.KeyStroke; import javax.swing.border.Border; import javax.swing.filechooser.FileFilter; import mage.client.MageFrame; import mage.client.SessionHandler; +import mage.client.components.KeyBindButton; import mage.client.util.Config; import mage.client.util.GUISizeHelper; import mage.client.util.ImageHelper; @@ -82,297 +85,308 @@ import org.apache.log4j.Logger; */ public class PreferencesDialog extends javax.swing.JDialog { - private static final Logger logger = Logger.getLogger(PreferencesDialog.class); + private static final Logger logger = Logger.getLogger(PreferencesDialog.class); - public static final String KEY_SHOW_TOOLTIPS_DELAY = "showTooltipsDelay"; - public static final String KEY_SHOW_CARD_NAMES = "showCardNames"; - public static final String KEY_PERMANENTS_IN_ONE_PILE = "nonLandPermanentsInOnePile"; - public static final String KEY_SHOW_PLAYER_NAMES_PERMANENTLY = "showPlayerNamesPermanently"; - public static final String KEY_SHOW_ABILITY_PICKER_FORCED = "showAbilityPicker"; - public static final String KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS = "gameAllowRequestShowHandCards"; - public static final String KEY_GAME_SHOW_STORM_COUNTER = "gameShowStormCounter"; - public static final String KEY_GAME_CONFIRM_EMPTY_MANA_POOL = "gameConfirmEmptyManaPool"; - public static final String KEY_GAME_ASK_MOVE_TO_GRAVE_ORDER = "gameAskMoveToGraveORder"; + public static final String KEY_SHOW_TOOLTIPS_DELAY = "showTooltipsDelay"; + public static final String KEY_SHOW_CARD_NAMES = "showCardNames"; + public static final String KEY_PERMANENTS_IN_ONE_PILE = "nonLandPermanentsInOnePile"; + public static final String KEY_SHOW_PLAYER_NAMES_PERMANENTLY = "showPlayerNamesPermanently"; + public static final String KEY_SHOW_ABILITY_PICKER_FORCED = "showAbilityPicker"; + public static final String KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS = "gameAllowRequestShowHandCards"; + public static final String KEY_GAME_SHOW_STORM_COUNTER = "gameShowStormCounter"; + public static final String KEY_GAME_CONFIRM_EMPTY_MANA_POOL = "gameConfirmEmptyManaPool"; + public static final String KEY_GAME_ASK_MOVE_TO_GRAVE_ORDER = "gameAskMoveToGraveORder"; - public static final String KEY_GUI_TABLE_FONT_SIZE = "guiTableFontSize"; - public static final String KEY_GUI_CHAT_FONT_SIZE = "guiChatFontSize"; - public static final String KEY_GUI_CARD_HAND_SIZE = "guiCardHandSize"; - public static final String KEY_GUI_CARD_EDITOR_SIZE = "guiCardEditorSize"; - public static final String KEY_GUI_CARD_OFFSET_SIZE = "guiCardOffsetSize"; - public static final String KEY_GUI_ENLARGED_IMAGE_SIZE = "guiEnlargedImageSize"; + public static final String KEY_GUI_TABLE_FONT_SIZE = "guiTableFontSize"; + public static final String KEY_GUI_CHAT_FONT_SIZE = "guiChatFontSize"; + public static final String KEY_GUI_CARD_HAND_SIZE = "guiCardHandSize"; + public static final String KEY_GUI_CARD_EDITOR_SIZE = "guiCardEditorSize"; + public static final String KEY_GUI_CARD_OFFSET_SIZE = "guiCardOffsetSize"; + public static final String KEY_GUI_ENLARGED_IMAGE_SIZE = "guiEnlargedImageSize"; - public static final String KEY_GUI_STACK_WIDTH = "guiStackWidth"; - public static final String KEY_GUI_TOOLTIP_SIZE = "guiTooltipSize"; - public static final String KEY_GUI_DIALOG_FONT_SIZE = "guiDialogFontSize"; - public static final String KEY_GUI_FEEDBACK_AREA_SIZE = "guiFeedbackAreaSize"; - public static final String KEY_GUI_CARD_OTHER_ZONES_SIZE = "guiCardOtherZonesSize"; - public static final String KEY_GUI_CARD_BATTLEFIELD_MIN_SIZE = "guiCardBattlefieldMinSize"; - public static final String KEY_GUI_CARD_BATTLEFIELD_MAX_SIZE = "guiCardBattlefieldMaxSize"; + public static final String KEY_GUI_STACK_WIDTH = "guiStackWidth"; + public static final String KEY_GUI_TOOLTIP_SIZE = "guiTooltipSize"; + public static final String KEY_GUI_DIALOG_FONT_SIZE = "guiDialogFontSize"; + public static final String KEY_GUI_FEEDBACK_AREA_SIZE = "guiFeedbackAreaSize"; + public static final String KEY_GUI_CARD_OTHER_ZONES_SIZE = "guiCardOtherZonesSize"; + public static final String KEY_GUI_CARD_BATTLEFIELD_MIN_SIZE = "guiCardBattlefieldMinSize"; + public static final String KEY_GUI_CARD_BATTLEFIELD_MAX_SIZE = "guiCardBattlefieldMaxSize"; - public static final String KEY_GAME_LOG_AUTO_SAVE = "gameLogAutoSave"; - public static final String KEY_DRAFT_LOG_AUTO_SAVE = "draftLogAutoSave"; + public static final String KEY_GAME_LOG_AUTO_SAVE = "gameLogAutoSave"; + public static final String KEY_DRAFT_LOG_AUTO_SAVE = "draftLogAutoSave"; - public static final String KEY_CARD_IMAGES_USE_DEFAULT = "cardImagesUseDefault"; - public static final String KEY_CARD_IMAGES_PATH = "cardImagesPath"; - public static final String KEY_CARD_IMAGES_THREADS = "cardImagesThreads"; - public static final String KEY_CARD_IMAGES_CHECK = "cardImagesCheck"; - public static final String KEY_CARD_IMAGES_SAVE_TO_ZIP = "cardImagesSaveToZip"; - public static final String KEY_CARD_IMAGES_PREF_LANGUAGE = "cardImagesPreferedImageLaguage"; + public static final String KEY_CARD_IMAGES_USE_DEFAULT = "cardImagesUseDefault"; + public static final String KEY_CARD_IMAGES_PATH = "cardImagesPath"; + public static final String KEY_CARD_IMAGES_THREADS = "cardImagesThreads"; + public static final String KEY_CARD_IMAGES_CHECK = "cardImagesCheck"; + public static final String KEY_CARD_IMAGES_SAVE_TO_ZIP = "cardImagesSaveToZip"; + public static final String KEY_CARD_IMAGES_PREF_LANGUAGE = "cardImagesPreferedImageLaguage"; - public static final String KEY_CARD_RENDERING_FALLBACK = "cardRenderingFallback"; - public static final String KEY_CARD_RENDERING_REMINDER_TEXT = "cardRenderingReminderText"; - public static final String KEY_CARD_RENDERING_SET_SYMBOL = "cardRenderingSetSymbol"; - - public static final String KEY_BACKGROUND_IMAGE = "backgroundImage"; - public static final String KEY_BATTLEFIELD_IMAGE = "battlefieldImage"; - public static final String KEY_BACKGROUND_IMAGE_DEFAULT = "backgroundImagedDefault"; - public static final String KEY_BATTLEFIELD_IMAGE_RANDOM = "battlefieldImagerandom"; - public static final String KEY_BATTLEFIELD_IMAGE_DEFAULT = "battlefieldImageDefault"; + public static final String KEY_CARD_RENDERING_FALLBACK = "cardRenderingFallback"; + public static final String KEY_CARD_RENDERING_REMINDER_TEXT = "cardRenderingReminderText"; + public static final String KEY_CARD_RENDERING_SET_SYMBOL = "cardRenderingSetSymbol"; - public static final String KEY_SOUNDS_GAME_ON = "soundsOn"; - public static final String KEY_SOUNDS_DRAFT_ON = "soundsDraftOn"; - public static final String KEY_SOUNDS_SKIP_BUTTONS_ON = "soundsSkipButtonsOn"; - public static final String KEY_SOUNDS_OTHER_ON = "soundsOtherOn"; - public static final String KEY_SOUNDS_MATCH_MUSIC_ON = "soundsMatchMusicOn"; - public static final String KEY_SOUNDS_MATCH_MUSIC_PATH = "soundsMatchMusicPath"; + public static final String KEY_BACKGROUND_IMAGE = "backgroundImage"; + public static final String KEY_BATTLEFIELD_IMAGE = "battlefieldImage"; + public static final String KEY_BACKGROUND_IMAGE_DEFAULT = "backgroundImagedDefault"; + public static final String KEY_BATTLEFIELD_IMAGE_RANDOM = "battlefieldImagerandom"; + public static final String KEY_BATTLEFIELD_IMAGE_DEFAULT = "battlefieldImageDefault"; - public static final String KEY_BIG_CARD_TOGGLED = "bigCardToggled"; + public static final String KEY_SOUNDS_GAME_ON = "soundsOn"; + public static final String KEY_SOUNDS_DRAFT_ON = "soundsDraftOn"; + public static final String KEY_SOUNDS_SKIP_BUTTONS_ON = "soundsSkipButtonsOn"; + public static final String KEY_SOUNDS_OTHER_ON = "soundsOtherOn"; + public static final String KEY_SOUNDS_MATCH_MUSIC_ON = "soundsMatchMusicOn"; + public static final String KEY_SOUNDS_MATCH_MUSIC_PATH = "soundsMatchMusicPath"; - // Phases - public static final String UPKEEP_YOU = "upkeepYou"; - public static final String DRAW_YOU = "drawYou"; - public static final String MAIN_YOU = "mainYou"; - public static final String BEFORE_COMBAT_YOU = "beforeCombatYou"; - public static final String END_OF_COMBAT_YOU = "endOfCombatYou"; - public static final String MAIN_TWO_YOU = "main2You"; - public static final String END_OF_TURN_YOU = "endOfTurnYou"; + public static final String KEY_BIG_CARD_TOGGLED = "bigCardToggled"; - public static final String UPKEEP_OTHERS = "upkeepOthers"; - public static final String DRAW_OTHERS = "drawOthers"; - public static final String MAIN_OTHERS = "mainOthers"; - public static final String BEFORE_COMBAT_OTHERS = "beforeCombatOthers"; - public static final String END_OF_COMBAT_OTHERS = "endOfCombatOthers"; - public static final String MAIN_TWO_OTHERS = "main2Others"; - public static final String END_OF_TURN_OTHERS = "endOfTurnOthers"; + // Phases + public static final String UPKEEP_YOU = "upkeepYou"; + public static final String DRAW_YOU = "drawYou"; + public static final String MAIN_YOU = "mainYou"; + public static final String BEFORE_COMBAT_YOU = "beforeCombatYou"; + public static final String END_OF_COMBAT_YOU = "endOfCombatYou"; + public static final String MAIN_TWO_YOU = "main2You"; + public static final String END_OF_TURN_YOU = "endOfTurnYou"; - public static final String KEY_STOP_ATTACK = "stopDeclareAttacksStep"; - public static final String KEY_STOP_BLOCK = "stopDeclareBlockersStep"; - public static final String KEY_STOP_ALL_MAIN_PHASES = "stopOnAllMainPhases"; - public static final String KEY_STOP_ALL_END_PHASES = "stopOnAllEndPhases"; - public static final String KEY_PASS_PRIORITY_CAST = "passPriorityCast"; - public static final String KEY_PASS_PRIORITY_ACTIVATION = "passPriorityActivation"; - public static final String KEY_AUTO_ORDER_TRIGGER = "autoOrderTrigger"; - public static final String KEY_USE_FIRST_MANA_ABILITY = "useFirstManaAbility"; + public static final String UPKEEP_OTHERS = "upkeepOthers"; + public static final String DRAW_OTHERS = "drawOthers"; + public static final String MAIN_OTHERS = "mainOthers"; + public static final String BEFORE_COMBAT_OTHERS = "beforeCombatOthers"; + public static final String END_OF_COMBAT_OTHERS = "endOfCombatOthers"; + public static final String MAIN_TWO_OTHERS = "main2Others"; + public static final String END_OF_TURN_OTHERS = "endOfTurnOthers"; - // mana auto payment - public static final String KEY_GAME_MANA_AUTOPAYMENT = "gameManaAutopayment"; - public static final String KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE = "gameManaAutopaymentOnlyOne"; + public static final String KEY_STOP_ATTACK = "stopDeclareAttacksStep"; + public static final String KEY_STOP_BLOCK = "stopDeclareBlockersStep"; + public static final String KEY_STOP_ALL_MAIN_PHASES = "stopOnAllMainPhases"; + public static final String KEY_STOP_ALL_END_PHASES = "stopOnAllEndPhases"; + public static final String KEY_PASS_PRIORITY_CAST = "passPriorityCast"; + public static final String KEY_PASS_PRIORITY_ACTIVATION = "passPriorityActivation"; + public static final String KEY_AUTO_ORDER_TRIGGER = "autoOrderTrigger"; + public static final String KEY_USE_FIRST_MANA_ABILITY = "useFirstManaAbility"; - // Size of frame to check if divider locations should be used - public static final String KEY_MAGE_PANEL_LAST_SIZE = "gamepanelLastSize"; + // mana auto payment + public static final String KEY_GAME_MANA_AUTOPAYMENT = "gameManaAutopayment"; + public static final String KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE = "gameManaAutopaymentOnlyOne"; - // pref settings of table settings and filtering - public static final String KEY_TABLES_FILTER_SETTINGS = "tablePanelFilterSettings"; - public static final String KEY_TABLES_COLUMNS_WIDTH = "tablePanelColumnWidth"; - public static final String KEY_TABLES_COLUMNS_ORDER = "tablePanelColumnSort"; + // Size of frame to check if divider locations should be used + public static final String KEY_MAGE_PANEL_LAST_SIZE = "gamepanelLastSize"; - // last sort settings used in deck editor - public static final String KEY_DECK_EDITOR_LAST_SORT = "deckEditorLastSort"; - public static final String KEY_DECK_EDITOR_LAST_SEPARATE_CREATURES = "deckEditorLastSeparateCreatures"; + // pref settings of table settings and filtering + public static final String KEY_TABLES_FILTER_SETTINGS = "tablePanelFilterSettings"; + public static final String KEY_TABLES_COLUMNS_WIDTH = "tablePanelColumnWidth"; + public static final String KEY_TABLES_COLUMNS_ORDER = "tablePanelColumnSort"; - // positions of divider bars - public static final String KEY_TABLES_DIVIDER_LOCATION_1 = "tablePanelDividerLocation1"; - public static final String KEY_TABLES_DIVIDER_LOCATION_2 = "tablePanelDividerLocation2"; - public static final String KEY_TABLES_DIVIDER_LOCATION_3 = "tablePanelDividerLocation3"; + // last sort settings used in deck editor + public static final String KEY_DECK_EDITOR_LAST_SORT = "deckEditorLastSort"; + public static final String KEY_DECK_EDITOR_LAST_SEPARATE_CREATURES = "deckEditorLastSeparateCreatures"; - // Positions of deck editor divider bars - public static final String KEY_EDITOR_HORIZONTAL_DIVIDER_LOCATION = "editorHorizontalDividerLocation"; - public static final String KEY_EDITOR_DECKAREA_SETTINGS = "editorDeckAreaSettings"; + // positions of divider bars + public static final String KEY_TABLES_DIVIDER_LOCATION_1 = "tablePanelDividerLocation1"; + public static final String KEY_TABLES_DIVIDER_LOCATION_2 = "tablePanelDividerLocation2"; + public static final String KEY_TABLES_DIVIDER_LOCATION_3 = "tablePanelDividerLocation3"; - // user list - public static final String KEY_USERS_COLUMNS_WIDTH = "userPanelColumnWidth"; - public static final String KEY_USERS_COLUMNS_ORDER = "userPanelColumnSort"; - // table waiting dialog - public static final String KEY_TABLE_WAITING_WIDTH = "tableWaitingPanelWidth"; - public static final String KEY_TABLE_WAITING_HEIGHT = "tableWaitingPanelHeight"; - public static final String KEY_TABLE_WAITING_COLUMNS_WIDTH = "tableWaitingPanelColumnWidth"; - public static final String KEY_TABLE_WAITING_COLUMNS_ORDER = "tableWaitingPanelColumnSort"; + // Positions of deck editor divider bars + public static final String KEY_EDITOR_HORIZONTAL_DIVIDER_LOCATION = "editorHorizontalDividerLocation"; + public static final String KEY_EDITOR_DECKAREA_SETTINGS = "editorDeckAreaSettings"; - public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_0 = "gamepanelDividerLocation0"; - public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_1 = "gamepanelDividerLocation1"; - public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_2 = "gamepanelDividerLocation2"; + // user list + public static final String KEY_USERS_COLUMNS_WIDTH = "userPanelColumnWidth"; + public static final String KEY_USERS_COLUMNS_ORDER = "userPanelColumnSort"; + // table waiting dialog + public static final String KEY_TABLE_WAITING_WIDTH = "tableWaitingPanelWidth"; + public static final String KEY_TABLE_WAITING_HEIGHT = "tableWaitingPanelHeight"; + public static final String KEY_TABLE_WAITING_COLUMNS_WIDTH = "tableWaitingPanelColumnWidth"; + public static final String KEY_TABLE_WAITING_COLUMNS_ORDER = "tableWaitingPanelColumnSort"; - public static final String KEY_TOURNAMENT_PLAYER_COLUMNS_WIDTH = "tournamentPlayerPanelColumnWidth"; - public static final String KEY_TOURNAMENT_PLAYER_COLUMNS_ORDER = "tournamentPlayerPanelColumnSort"; - public static final String KEY_TOURNAMENT_MATCH_COLUMNS_WIDTH = "tournamentMatchPanelColumnWidth"; - public static final String KEY_TOURNAMENT_MATCH_COLUMNS_ORDER = "tournamentMatchPanelColumnSort"; - public static final String KEY_TOURNAMENT_DIVIDER_LOCATION_1 = "tournamentPanelDividerLocation1"; - public static final String KEY_TOURNAMENT_DIVIDER_LOCATION_2 = "tournamentPanelDividerLocation2"; + public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_0 = "gamepanelDividerLocation0"; + public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_1 = "gamepanelDividerLocation1"; + public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_2 = "gamepanelDividerLocation2"; - // pref setting for new table dialog - public static final String KEY_NEW_TABLE_NAME = "newTableName"; - public static final String KEY_NEW_TABLE_PASSWORD = "newTablePassword"; - public static final String KEY_NEW_TABLE_PASSWORD_JOIN = "newTablePasswordJoin"; - public static final String KEY_NEW_TABLE_DECK_TYPE = "newTableDeckType"; - public static final String KEY_NEW_TABLE_TIME_LIMIT = "newTableTimeLimit"; - public static final String KEY_NEW_TABLE_GAME_TYPE = "newTableGameType"; - public static final String KEY_NEW_TABLE_NUMBER_OF_WINS = "newTableNumberOfWins"; - public static final String KEY_NEW_TABLE_ROLLBACK_TURNS_ALLOWED = "newTableRollbackTurnsAllowed"; - public static final String KEY_NEW_TABLE_NUMBER_OF_FREE_MULLIGANS = "newTableNumberOfFreeMulligans"; - public static final String KEY_NEW_TABLE_DECK_FILE = "newTableDeckFile"; - public static final String KEY_NEW_TABLE_RANGE = "newTableRange"; - public static final String KEY_NEW_TABLE_ATTACK_OPTION = "newTableAttackOption"; - public static final String KEY_NEW_TABLE_SKILL_LEVEL = "newTableSkillLevel"; - public static final String KEY_NEW_TABLE_NUMBER_PLAYERS = "newTableNumberPlayers"; - public static final String KEY_NEW_TABLE_PLAYER_TYPES = "newTablePlayerTypes"; - public static final String KEY_NEW_TABLE_QUIT_RATIO = "newTableQuitRatio"; - public static final String KEY_NEW_TABLE_RATED = "newTableRated"; + public static final String KEY_TOURNAMENT_PLAYER_COLUMNS_WIDTH = "tournamentPlayerPanelColumnWidth"; + public static final String KEY_TOURNAMENT_PLAYER_COLUMNS_ORDER = "tournamentPlayerPanelColumnSort"; + public static final String KEY_TOURNAMENT_MATCH_COLUMNS_WIDTH = "tournamentMatchPanelColumnWidth"; + public static final String KEY_TOURNAMENT_MATCH_COLUMNS_ORDER = "tournamentMatchPanelColumnSort"; + public static final String KEY_TOURNAMENT_DIVIDER_LOCATION_1 = "tournamentPanelDividerLocation1"; + public static final String KEY_TOURNAMENT_DIVIDER_LOCATION_2 = "tournamentPanelDividerLocation2"; - // pref setting for new tournament dialog - public static final String KEY_NEW_TOURNAMENT_NAME = "newTournamentName"; - public static final String KEY_NEW_TOURNAMENT_PASSWORD = "newTournamentPassword"; - public static final String KEY_NEW_TOURNAMENT_TIME_LIMIT = "newTournamentTimeLimit"; - public static final String KEY_NEW_TOURNAMENT_CONSTR_TIME = "newTournamentConstructionTime"; - public static final String KEY_NEW_TOURNAMENT_TYPE = "newTournamentType"; - public static final String KEY_NEW_TOURNAMENT_NUMBER_OF_FREE_MULLIGANS = "newTournamentNumberOfFreeMulligans"; - public static final String KEY_NEW_TOURNAMENT_NUMBER_OF_WINS = "newTournamentNumberOfWins"; - public static final String KEY_NEW_TOURNAMENT_PACKS_SEALED = "newTournamentPacksSealed"; - public static final String KEY_NEW_TOURNAMENT_PACKS_DRAFT = "newTournamentPacksDraft"; - public static final String KEY_NEW_TOURNAMENT_PACKS_RANDOM_DRAFT = "newTournamentPacksRandomDraft"; - public static final String KEY_NEW_TOURNAMENT_PLAYERS_SEALED = "newTournamentPlayersSealed"; - public static final String KEY_NEW_TOURNAMENT_PLAYERS_DRAFT = "newTournamentPlayersDraft"; - public static final String KEY_NEW_TOURNAMENT_DRAFT_TIMING = "newTournamentDraftTiming"; - public static final String KEY_NEW_TOURNAMENT_ALLOW_SPECTATORS = "newTournamentAllowSpectators"; - public static final String KEY_NEW_TOURNAMENT_ALLOW_ROLLBACKS = "newTournamentAllowRollbacks"; - public static final String KEY_NEW_TOURNAMENT_DECK_FILE = "newTournamentDeckFile"; - public static final String KEY_NEW_TOURNAMENT_QUIT_RATIO = "newTournamentQuitRatio"; - public static final String KEY_NEW_TOURNAMENT_RATED = "newTournamentRated"; + // pref setting for new table dialog + public static final String KEY_NEW_TABLE_NAME = "newTableName"; + public static final String KEY_NEW_TABLE_PASSWORD = "newTablePassword"; + public static final String KEY_NEW_TABLE_PASSWORD_JOIN = "newTablePasswordJoin"; + public static final String KEY_NEW_TABLE_DECK_TYPE = "newTableDeckType"; + public static final String KEY_NEW_TABLE_TIME_LIMIT = "newTableTimeLimit"; + public static final String KEY_NEW_TABLE_GAME_TYPE = "newTableGameType"; + public static final String KEY_NEW_TABLE_NUMBER_OF_WINS = "newTableNumberOfWins"; + public static final String KEY_NEW_TABLE_ROLLBACK_TURNS_ALLOWED = "newTableRollbackTurnsAllowed"; + public static final String KEY_NEW_TABLE_NUMBER_OF_FREE_MULLIGANS = "newTableNumberOfFreeMulligans"; + public static final String KEY_NEW_TABLE_DECK_FILE = "newTableDeckFile"; + public static final String KEY_NEW_TABLE_RANGE = "newTableRange"; + public static final String KEY_NEW_TABLE_ATTACK_OPTION = "newTableAttackOption"; + public static final String KEY_NEW_TABLE_SKILL_LEVEL = "newTableSkillLevel"; + public static final String KEY_NEW_TABLE_NUMBER_PLAYERS = "newTableNumberPlayers"; + public static final String KEY_NEW_TABLE_PLAYER_TYPES = "newTablePlayerTypes"; + public static final String KEY_NEW_TABLE_QUIT_RATIO = "newTableQuitRatio"; + public static final String KEY_NEW_TABLE_RATED = "newTableRated"; - // pref setting for deck generator - public static final String KEY_NEW_DECK_GENERATOR_DECK_SIZE = "newDeckGeneratorDeckSize"; - public static final String KEY_NEW_DECK_GENERATOR_SET = "newDeckGeneratorSet"; - public static final String KEY_NEW_DECK_GENERATOR_SINGLETON = "newDeckGeneratorSingleton"; - public static final String KEY_NEW_DECK_GENERATOR_ARTIFACTS = "newDeckGeneratorArtifacts"; - public static final String KEY_NEW_DECK_GENERATOR_NON_BASIC_LANDS = "newDeckGeneratorNonBasicLands"; - public static final String KEY_NEW_DECK_GENERATOR_COLORLESS = "newDeckGeneratorColorless"; - public static final String KEY_NEW_DECK_GENERATOR_ADVANCED = "newDeckGeneratorAdvanced"; - public static final String KEY_NEW_DECK_GENERATOR_CREATURE_PERCENTAGE = "newDeckGeneratorCreaturePercentage"; - public static final String KEY_NEW_DECK_GENERATOR_NON_CREATURE_PERCENTAGE = "newDeckGeneratorNonCreaturePercentage"; - public static final String KEY_NEW_DECK_GENERATOR_LAND_PERCENTAGE = "newDeckGeneratorLandPercentage"; - public static final String KEY_NEW_DECK_GENERATOR_ADVANCED_CMC = "newDeckGeneratorAdvancedCMC"; + // pref setting for new tournament dialog + public static final String KEY_NEW_TOURNAMENT_NAME = "newTournamentName"; + public static final String KEY_NEW_TOURNAMENT_PASSWORD = "newTournamentPassword"; + public static final String KEY_NEW_TOURNAMENT_TIME_LIMIT = "newTournamentTimeLimit"; + public static final String KEY_NEW_TOURNAMENT_CONSTR_TIME = "newTournamentConstructionTime"; + public static final String KEY_NEW_TOURNAMENT_TYPE = "newTournamentType"; + public static final String KEY_NEW_TOURNAMENT_NUMBER_OF_FREE_MULLIGANS = "newTournamentNumberOfFreeMulligans"; + public static final String KEY_NEW_TOURNAMENT_NUMBER_OF_WINS = "newTournamentNumberOfWins"; + public static final String KEY_NEW_TOURNAMENT_PACKS_SEALED = "newTournamentPacksSealed"; + public static final String KEY_NEW_TOURNAMENT_PACKS_DRAFT = "newTournamentPacksDraft"; + public static final String KEY_NEW_TOURNAMENT_PACKS_RANDOM_DRAFT = "newTournamentPacksRandomDraft"; + public static final String KEY_NEW_TOURNAMENT_PLAYERS_SEALED = "newTournamentPlayersSealed"; + public static final String KEY_NEW_TOURNAMENT_PLAYERS_DRAFT = "newTournamentPlayersDraft"; + public static final String KEY_NEW_TOURNAMENT_DRAFT_TIMING = "newTournamentDraftTiming"; + public static final String KEY_NEW_TOURNAMENT_ALLOW_SPECTATORS = "newTournamentAllowSpectators"; + public static final String KEY_NEW_TOURNAMENT_ALLOW_ROLLBACKS = "newTournamentAllowRollbacks"; + public static final String KEY_NEW_TOURNAMENT_DECK_FILE = "newTournamentDeckFile"; + public static final String KEY_NEW_TOURNAMENT_QUIT_RATIO = "newTournamentQuitRatio"; + public static final String KEY_NEW_TOURNAMENT_RATED = "newTournamentRated"; - // used to save and restore the settings for the cardArea (draft, sideboarding, deck builder) - public static final String KEY_DRAFT_VIEW = "draftView"; + // pref setting for deck generator + public static final String KEY_NEW_DECK_GENERATOR_DECK_SIZE = "newDeckGeneratorDeckSize"; + public static final String KEY_NEW_DECK_GENERATOR_SET = "newDeckGeneratorSet"; + public static final String KEY_NEW_DECK_GENERATOR_SINGLETON = "newDeckGeneratorSingleton"; + public static final String KEY_NEW_DECK_GENERATOR_ARTIFACTS = "newDeckGeneratorArtifacts"; + public static final String KEY_NEW_DECK_GENERATOR_NON_BASIC_LANDS = "newDeckGeneratorNonBasicLands"; + public static final String KEY_NEW_DECK_GENERATOR_COLORLESS = "newDeckGeneratorColorless"; + public static final String KEY_NEW_DECK_GENERATOR_ADVANCED = "newDeckGeneratorAdvanced"; + public static final String KEY_NEW_DECK_GENERATOR_CREATURE_PERCENTAGE = "newDeckGeneratorCreaturePercentage"; + public static final String KEY_NEW_DECK_GENERATOR_NON_CREATURE_PERCENTAGE = "newDeckGeneratorNonCreaturePercentage"; + public static final String KEY_NEW_DECK_GENERATOR_LAND_PERCENTAGE = "newDeckGeneratorLandPercentage"; + public static final String KEY_NEW_DECK_GENERATOR_ADVANCED_CMC = "newDeckGeneratorAdvancedCMC"; - public static final String KEY_DRAFT_SORT_BY = "draftSortBy"; - public static final String KEY_DRAFT_SORT_INDEX = "draftSortIndex"; - public static final String KEY_DRAFT_SORT_ASCENDING = "draftSortAscending"; - public static final String KEY_DRAFT_PILES_TOGGLE = "draftPilesToggle"; + // used to save and restore the settings for the cardArea (draft, sideboarding, deck builder) + public static final String KEY_DRAFT_VIEW = "draftView"; - public static final String KEY_BASE_SORT_BY = "baseSortBy"; - public static final String KEY_BASE_SORT_INDEX = "baseSortIndex"; - public static final String KEY_BASE_SORT_ASCENDING = "baseSortAscending"; - public static final String KEY_BASE_PILES_TOGGLE = "basePilesToggle"; + public static final String KEY_DRAFT_SORT_BY = "draftSortBy"; + public static final String KEY_DRAFT_SORT_INDEX = "draftSortIndex"; + public static final String KEY_DRAFT_SORT_ASCENDING = "draftSortAscending"; + public static final String KEY_DRAFT_PILES_TOGGLE = "draftPilesToggle"; - public static final String KEY_SIDEBOARD_SORT_BY = "sideboardSortBy"; - public static final String KEY_SIDEBOARD_SORT_INDEX = "sideboardSortIndex"; - public static final String KEY_SIDEBOARD_SORT_ASCENDING = "sideboardSortAscending"; - public static final String KEY_SIDEBOARD_PILES_TOGGLE = "sideboardPilesToggle"; + public static final String KEY_BASE_SORT_BY = "baseSortBy"; + public static final String KEY_BASE_SORT_INDEX = "baseSortIndex"; + public static final String KEY_BASE_SORT_ASCENDING = "baseSortAscending"; + public static final String KEY_BASE_PILES_TOGGLE = "basePilesToggle"; - public static final String KEY_DECK_SORT_BY = "deckSortBy"; - public static final String KEY_DECK_SORT_INDEX = "deckSortIndex"; - public static final String KEY_DECK_SORT_ASCENDING = "deckSortAscending"; - public static final String KEY_DECK_PILES_TOGGLE = "deckPilesToggle"; + public static final String KEY_SIDEBOARD_SORT_BY = "sideboardSortBy"; + public static final String KEY_SIDEBOARD_SORT_INDEX = "sideboardSortIndex"; + public static final String KEY_SIDEBOARD_SORT_ASCENDING = "sideboardSortAscending"; + public static final String KEY_SIDEBOARD_PILES_TOGGLE = "sideboardPilesToggle"; - public static final String KEY_PROXY_ADDRESS = "proxyAddress"; - public static final String KEY_PROXY_PORT = "proxyPort"; - public static final String KEY_PROXY_USERNAME = "proxyUsername"; - public static final String KEY_PROXY_REMEMBER = "proxyRemember"; - public static final String KEY_PROXY_TYPE = "proxyType"; - public static final String KEY_PROXY_PSWD = "proxyPassword"; - public static final String KEY_CONNECTION_URL_SERVER_LIST = "connectionURLServerList"; + public static final String KEY_DECK_SORT_BY = "deckSortBy"; + public static final String KEY_DECK_SORT_INDEX = "deckSortIndex"; + public static final String KEY_DECK_SORT_ASCENDING = "deckSortAscending"; + public static final String KEY_DECK_PILES_TOGGLE = "deckPilesToggle"; - public static final String KEY_AVATAR = "selectedId"; + public static final String KEY_PROXY_ADDRESS = "proxyAddress"; + public static final String KEY_PROXY_PORT = "proxyPort"; + public static final String KEY_PROXY_USERNAME = "proxyUsername"; + public static final String KEY_PROXY_REMEMBER = "proxyRemember"; + public static final String KEY_PROXY_TYPE = "proxyType"; + public static final String KEY_PROXY_PSWD = "proxyPassword"; + public static final String KEY_CONNECTION_URL_SERVER_LIST = "connectionURLServerList"; - public static final String KEY_CONNECT_AUTO_CONNECT = "autoConnect"; - public static final String KEY_CONNECT_FLAG = "connectFlag"; + // controls + public static final String KEY_CONTROL_CONFIRM = "controlConfirm"; + public static final String KEY_CONTROL_CANCEL_SKIP = "controlCancelSkip"; + public static final String KEY_CONTROL_NEXT_TURN = "controlNextTurn"; + public static final String KEY_CONTROL_END_STEP = "controlEndStep"; + public static final String KEY_CONTROL_SKIP_STEP = "controlSkipTurn"; + public static final String KEY_CONTROL_MAIN_STEP = "controlMainStep"; + public static final String KEY_CONTROL_YOUR_TURN = "controlYourTurn"; + public static final String KEY_CONTROL_SKIP_STACK = "controlSkipStack"; + public static final String KEY_CONTROL_PRIOR_END = "controlPriorEnd"; - private static final Map CACHE = new HashMap<>(); + public static final String KEY_AVATAR = "selectedId"; - private static final Boolean UPDATE_CACHE_POLICY = Boolean.TRUE; + public static final String KEY_CONNECT_AUTO_CONNECT = "autoConnect"; + public static final String KEY_CONNECT_FLAG = "connectFlag"; - public static final String OPEN_CONNECTION_TAB = "Open-Connection-Tab"; - public static final String OPEN_PHASES_TAB = "Open-Phases-Tab"; + private static final Map CACHE = new HashMap<>(); - public static String PHASE_ON = "on"; - public static String PHASE_OFF = "off"; + private static final Boolean UPDATE_CACHE_POLICY = Boolean.TRUE; - private static final Map PANELS = new HashMap<>(); + public static final String OPEN_CONNECTION_TAB = "Open-Connection-Tab"; + public static final String OPEN_PHASES_TAB = "Open-Phases-Tab"; - private static final Border GREEN_BORDER = BorderFactory.createLineBorder(Color.GREEN, 3); - private static final Border BLACK_BORDER = BorderFactory.createLineBorder(Color.BLACK, 3); + public static String PHASE_ON = "on"; + public static String PHASE_OFF = "off"; - private static int selectedAvatarId; + private static final Map PANELS = new HashMap<>(); - private final JFileChooser fc = new JFileChooser(); + private static final Border GREEN_BORDER = BorderFactory.createLineBorder(Color.GREEN, 3); + private static final Border BLACK_BORDER = BorderFactory.createLineBorder(Color.BLACK, 3); - { - fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - } + private static int selectedAvatarId; - private final JFileChooser fc_i = new JFileChooser(); + private final JFileChooser fc = new JFileChooser(); - { - fc_i.setAcceptAllFileFilterUsed(false); - fc_i.addChoosableFileFilter(new ImageFileFilter()); - } + { + fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + } - private static class ImageFileFilter extends FileFilter { + private final JFileChooser fc_i = new JFileChooser(); - @Override - public boolean accept(File f) { - String filename = f.getName(); - if (f.isDirectory()) { - return true; - } - if (filename != null) { - if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") - || filename.endsWith(".png") || filename.endsWith(".bmp")) { - return true; - } - } - return false; - } + { + fc_i.setAcceptAllFileFilterUsed(false); + fc_i.addChoosableFileFilter(new ImageFileFilter()); + } - @Override - public String getDescription() { - return "*.png | *.bmp |*.jpg | *.jpeg"; - } - } + private static class ImageFileFilter extends FileFilter { - /** - * Creates new form PreferencesDialog - * - * @param parent - * @param modal - */ - public PreferencesDialog(java.awt.Frame parent, boolean modal) { - super(parent, modal); - initComponents(); - txtImageFolderPath.setEditable(false); - cbProxyType.setModel(new DefaultComboBoxModel<>(Connection.ProxyType.values())); - addAvatars(); + @Override + public boolean accept(File f) { + String filename = f.getName(); + if (f.isDirectory()) { + return true; + } + if (filename != null) { + if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") + || filename.endsWith(".png") || filename.endsWith(".bmp")) { + return true; + } + } + return false; + } - cbPreferedImageLanguage.setModel(new DefaultComboBoxModel<>(new String[]{"en", "de", "fr", "it", "es", "pt", "jp", "cn", "ru", "tw", "ko"})); - cbNumberOfDownloadThreads.setModel(new DefaultComboBoxModel<>(new String[]{"10", "9", "8", "7", "6", "5", "4", "3", "2", "1"})); - } + @Override + public String getDescription() { + return "*.png | *.bmp |*.jpg | *.jpeg"; + } + } - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") + /** + * Creates new form PreferencesDialog + * + * @param parent + * @param modal + */ + public PreferencesDialog(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + txtImageFolderPath.setEditable(false); + cbProxyType.setModel(new DefaultComboBoxModel<>(Connection.ProxyType.values())); + addAvatars(); + + cbPreferedImageLanguage.setModel(new DefaultComboBoxModel<>(new String[]{"en", "de", "fr", "it", "es", "pt", "jp", "cn", "ru", "tw", "ko"})); + cbNumberOfDownloadThreads.setModel(new DefaultComboBoxModel<>(new String[]{"10", "9", "8", "7", "6", "5", "4", "3", "2", "1"})); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; @@ -538,6 +552,26 @@ public class PreferencesDialog extends javax.swing.JDialog { txtPasswordField = new javax.swing.JPasswordField(); rememberPswd = new javax.swing.JCheckBox(); jLabel11 = new javax.swing.JLabel(); + tabControls = new javax.swing.JPanel(); + labelNextTurn = new javax.swing.JLabel(); + labelEndStep = new javax.swing.JLabel(); + labelMainStep = new javax.swing.JLabel(); + labelYourTurn = new javax.swing.JLabel(); + lebelSkip = new javax.swing.JLabel(); + labelPriorEnd = new javax.swing.JLabel(); + labelCancel = new javax.swing.JLabel(); + keyCancelSkip = new mage.client.components.KeyBindButton(); + keyNextTurn = new mage.client.components.KeyBindButton(); + keyMainStep = new mage.client.components.KeyBindButton(); + keyEndStep = new mage.client.components.KeyBindButton(); + keyYourTurn = new mage.client.components.KeyBindButton(); + keySkipStack = new mage.client.components.KeyBindButton(); + keyPriorEnd = new mage.client.components.KeyBindButton(); + keySkipStep = new mage.client.components.KeyBindButton(); + labelSkipStep = new javax.swing.JLabel(); + keyConfirm = new mage.client.components.KeyBindButton(); + labelConfirm = new javax.swing.JLabel(); + controlsDescriptionLabel = new javax.swing.JLabel(); saveButton = new javax.swing.JButton(); exitButton = new javax.swing.JButton(); @@ -579,7 +613,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .add(main_cardLayout.createSequentialGroup() .add(6, 6, 6) .add(main_cardLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) - .add(tooltipDelayLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE) + .add(tooltipDelayLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 308, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.LEADING, showCardName) .add(tooltipDelay, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) @@ -1402,7 +1436,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .add(jLabelEndOfTurn) .add(checkBoxEndTurnOthers)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) - .add(phases_stopSettings, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE) + .add(phases_stopSettings, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE) .addContainerGap()) ); @@ -1481,7 +1515,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(cbNumberOfDownloadThreads, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 153, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))) .add(cbUseDefaultImageFolder)) - .add(0, 231, Short.MAX_VALUE))) + .add(0, 270, Short.MAX_VALUE))) .addContainerGap()) ); panelCardImagesLayout.setVerticalGroup( @@ -1676,7 +1710,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .add(panelCardImages, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(panelBackgroundImages, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .addContainerGap(53, Short.MAX_VALUE)) + .addContainerGap(125, Short.MAX_VALUE)) ); tabsPanel.addTab("Images", tabImages); @@ -2251,7 +2285,7 @@ public class PreferencesDialog extends javax.swing.JDialog { tabAvatarsLayout.setVerticalGroup( tabAvatarsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(tabAvatarsLayout.createSequentialGroup() - .add(avatarPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 484, Short.MAX_VALUE) + .add(avatarPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 584, Short.MAX_VALUE) .addContainerGap()) ); @@ -2286,7 +2320,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .add(connection_serversLayout.createSequentialGroup() .add(141, 141, 141) .add(jLabel17))) - .addContainerGap(91, Short.MAX_VALUE)) + .addContainerGap(198, Short.MAX_VALUE)) ); connection_serversLayout.setVerticalGroup( connection_serversLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) @@ -2440,6 +2474,123 @@ public class PreferencesDialog extends javax.swing.JDialog { tabsPanel.addTab("Connection", tabConnection); + labelNextTurn.setText("Next Turn"); + + labelEndStep.setText("End Step"); + + labelMainStep.setText("Main Step"); + + labelYourTurn.setText("Your Turn"); + + lebelSkip.setText("Skip Stack"); + + labelPriorEnd.setText("Prior End"); + + labelCancel.setText("Cancel Skip"); + + keyCancelSkip.setText("keyBindButton1"); + + keyNextTurn.setText("keyBindButton1"); + + keyMainStep.setText("keyBindButton1"); + + keyEndStep.setText("keyBindButton1"); + + keyYourTurn.setText("keyBindButton1"); + + keySkipStack.setText("keyBindButton1"); + + keyPriorEnd.setText("keyBindButton1"); + + keySkipStep.setText("keyBindButton1"); + + labelSkipStep.setText("Skip Step"); + + keyConfirm.setText("keyBindButton1"); + + labelConfirm.setText("Confirm"); + + controlsDescriptionLabel.setText("Click on a button and press a key to change a keybind.
Space and ESC are not available, and will set the keybind to nothing.
If you are currently playing a game, the changes will not take effect until you start a new game."); + controlsDescriptionLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP); + + org.jdesktop.layout.GroupLayout tabControlsLayout = new org.jdesktop.layout.GroupLayout(tabControls); + tabControls.setLayout(tabControlsLayout); + tabControlsLayout.setHorizontalGroup( + tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(tabControlsLayout.createSequentialGroup() + .addContainerGap() + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(labelCancel) + .add(labelNextTurn) + .add(labelEndStep) + .add(labelMainStep) + .add(labelYourTurn) + .add(lebelSkip) + .add(labelPriorEnd) + .add(labelSkipStep) + .add(labelConfirm)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(keyConfirm, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keyCancelSkip, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keyNextTurn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keySkipStack, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keyYourTurn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keyMainStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keyPriorEnd, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keySkipStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keyEndStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(controlsDescriptionLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 498, Short.MAX_VALUE) + .addContainerGap()) + ); + tabControlsLayout.setVerticalGroup( + tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(tabControlsLayout.createSequentialGroup() + .addContainerGap() + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) + .add(tabControlsLayout.createSequentialGroup() + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(labelConfirm) + .add(keyConfirm, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(labelCancel) + .add(keyCancelSkip, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(labelNextTurn) + .add(keyNextTurn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(labelEndStep) + .add(keyEndStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(labelSkipStep) + .add(keySkipStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(labelMainStep) + .add(keyMainStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(labelYourTurn) + .add(keyYourTurn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(lebelSkip) + .add(keySkipStack, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(labelPriorEnd) + .add(keyPriorEnd, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) + .add(controlsDescriptionLabel)) + .add(263, 263, 263)) + ); + + tabsPanel.addTab("Controls", tabControls); + saveButton.setLabel("Save"); saveButton.setMaximumSize(new java.awt.Dimension(100, 30)); saveButton.setMinimumSize(new java.awt.Dimension(100, 30)); @@ -2492,182 +2643,193 @@ public class PreferencesDialog extends javax.swing.JDialog { }//
//GEN-END:initComponents private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed - Preferences prefs = MageFrame.getPreferences(); + Preferences prefs = MageFrame.getPreferences(); - // main - save(prefs, dialog.tooltipDelay, KEY_SHOW_TOOLTIPS_DELAY, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.showCardName, KEY_SHOW_CARD_NAMES, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.nonLandPermanentsInOnePile, KEY_PERMANENTS_IN_ONE_PILE, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.showPlayerNamesPermanently, KEY_SHOW_PLAYER_NAMES_PERMANENTLY, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.showAbilityPickerForced, KEY_SHOW_ABILITY_PICKER_FORCED, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbAllowRequestToShowHandCards, KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbShowStormCounter, KEY_GAME_SHOW_STORM_COUNTER, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbConfirmEmptyManaPool, KEY_GAME_CONFIRM_EMPTY_MANA_POOL, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbAskMoveToGraveOrder, KEY_GAME_ASK_MOVE_TO_GRAVE_ORDER, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbGameLogAutoSave, KEY_GAME_LOG_AUTO_SAVE, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbDraftLogAutoSave, KEY_DRAFT_LOG_AUTO_SAVE, "true", "false", UPDATE_CACHE_POLICY); + // main + save(prefs, dialog.tooltipDelay, KEY_SHOW_TOOLTIPS_DELAY, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.showCardName, KEY_SHOW_CARD_NAMES, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.nonLandPermanentsInOnePile, KEY_PERMANENTS_IN_ONE_PILE, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.showPlayerNamesPermanently, KEY_SHOW_PLAYER_NAMES_PERMANENTLY, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.showAbilityPickerForced, KEY_SHOW_ABILITY_PICKER_FORCED, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbAllowRequestToShowHandCards, KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbShowStormCounter, KEY_GAME_SHOW_STORM_COUNTER, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbConfirmEmptyManaPool, KEY_GAME_CONFIRM_EMPTY_MANA_POOL, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbAskMoveToGraveOrder, KEY_GAME_ASK_MOVE_TO_GRAVE_ORDER, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbGameLogAutoSave, KEY_GAME_LOG_AUTO_SAVE, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbDraftLogAutoSave, KEY_DRAFT_LOG_AUTO_SAVE, "true", "false", UPDATE_CACHE_POLICY); - // GUI Size - boolean sizeGUIChanged = false; - if (getCachedValue(KEY_GUI_TABLE_FONT_SIZE, 14) != dialog.sliderFontSize.getValue()) { - save(prefs, dialog.sliderFontSize, KEY_GUI_TABLE_FONT_SIZE, "true", "false", UPDATE_CACHE_POLICY); - sizeGUIChanged = true; - } - if (getCachedValue(KEY_GUI_CHAT_FONT_SIZE, 14) != dialog.sliderChatFontSize.getValue()) { - save(prefs, dialog.sliderChatFontSize, KEY_GUI_CHAT_FONT_SIZE, "true", "false", UPDATE_CACHE_POLICY); - sizeGUIChanged = true; - } - if (getCachedValue(KEY_GUI_CARD_HAND_SIZE, 14) != dialog.sliderCardSizeHand.getValue()) { - save(prefs, dialog.sliderCardSizeHand, KEY_GUI_CARD_HAND_SIZE, "true", "false", UPDATE_CACHE_POLICY); - sizeGUIChanged = true; - } - if (getCachedValue(KEY_GUI_CARD_EDITOR_SIZE, 14) != dialog.sliderEditorCardSize.getValue()) { - save(prefs, dialog.sliderEditorCardSize, KEY_GUI_CARD_EDITOR_SIZE, "true", "false", UPDATE_CACHE_POLICY); - sizeGUIChanged = true; - } - if (getCachedValue(KEY_GUI_CARD_OFFSET_SIZE, 14) != dialog.sliderEditorCardOffset.getValue()) { - save(prefs, dialog.sliderEditorCardOffset, KEY_GUI_CARD_OFFSET_SIZE, "true", "false", UPDATE_CACHE_POLICY); - sizeGUIChanged = true; - } - if (getCachedValue(KEY_GUI_ENLARGED_IMAGE_SIZE, 20) != dialog.sliderEnlargedImageSize.getValue()) { - save(prefs, dialog.sliderEnlargedImageSize, KEY_GUI_ENLARGED_IMAGE_SIZE, "true", "false", UPDATE_CACHE_POLICY); - sizeGUIChanged = true; - } - if (getCachedValue(KEY_GUI_STACK_WIDTH, 30) != dialog.sliderStackWidth.getValue()) { - save(prefs, dialog.sliderStackWidth, KEY_GUI_STACK_WIDTH, "true", "false", UPDATE_CACHE_POLICY); - sizeGUIChanged = true; - } - if (getCachedValue(KEY_GUI_TOOLTIP_SIZE, 14) != dialog.sliderTooltipSize.getValue()) { - save(prefs, dialog.sliderTooltipSize, KEY_GUI_TOOLTIP_SIZE, "true", "false", UPDATE_CACHE_POLICY); - sizeGUIChanged = true; - } - if (getCachedValue(KEY_GUI_DIALOG_FONT_SIZE, 14) != dialog.sliderDialogFont.getValue()) { - save(prefs, dialog.sliderDialogFont, KEY_GUI_DIALOG_FONT_SIZE, "true", "false", UPDATE_CACHE_POLICY); - sizeGUIChanged = true; - } - if (getCachedValue(KEY_GUI_FEEDBACK_AREA_SIZE, 14) != dialog.sliderGameFeedbackArea.getValue()) { - save(prefs, dialog.sliderGameFeedbackArea, KEY_GUI_FEEDBACK_AREA_SIZE, "true", "false", UPDATE_CACHE_POLICY); - sizeGUIChanged = true; - } - if (getCachedValue(KEY_GUI_CARD_OTHER_ZONES_SIZE, 14) != dialog.sliderCardSizeOtherZones.getValue()) { - save(prefs, dialog.sliderCardSizeOtherZones, KEY_GUI_CARD_OTHER_ZONES_SIZE, "true", "false", UPDATE_CACHE_POLICY); - sizeGUIChanged = true; - } - if (getCachedValue(KEY_GUI_CARD_BATTLEFIELD_MIN_SIZE, 10) != dialog.sliderCardSizeMaxBattlefield.getValue()) { - save(prefs, dialog.sliderCardSizeMinBattlefield, KEY_GUI_CARD_BATTLEFIELD_MIN_SIZE, "true", "false", UPDATE_CACHE_POLICY); - sizeGUIChanged = true; - } - if (getCachedValue(KEY_GUI_CARD_BATTLEFIELD_MAX_SIZE, 14) != dialog.sliderCardSizeMaxBattlefield.getValue()) { - save(prefs, dialog.sliderCardSizeMaxBattlefield, KEY_GUI_CARD_BATTLEFIELD_MAX_SIZE, "true", "false", UPDATE_CACHE_POLICY); - sizeGUIChanged = true; - } - if (sizeGUIChanged) { - // do as worker job - GUISizeHelper.changeGUISize(); - } + // GUI Size + boolean sizeGUIChanged = false; + if (getCachedValue(KEY_GUI_TABLE_FONT_SIZE, 14) != dialog.sliderFontSize.getValue()) { + save(prefs, dialog.sliderFontSize, KEY_GUI_TABLE_FONT_SIZE, "true", "false", UPDATE_CACHE_POLICY); + sizeGUIChanged = true; + } + if (getCachedValue(KEY_GUI_CHAT_FONT_SIZE, 14) != dialog.sliderChatFontSize.getValue()) { + save(prefs, dialog.sliderChatFontSize, KEY_GUI_CHAT_FONT_SIZE, "true", "false", UPDATE_CACHE_POLICY); + sizeGUIChanged = true; + } + if (getCachedValue(KEY_GUI_CARD_HAND_SIZE, 14) != dialog.sliderCardSizeHand.getValue()) { + save(prefs, dialog.sliderCardSizeHand, KEY_GUI_CARD_HAND_SIZE, "true", "false", UPDATE_CACHE_POLICY); + sizeGUIChanged = true; + } + if (getCachedValue(KEY_GUI_CARD_EDITOR_SIZE, 14) != dialog.sliderEditorCardSize.getValue()) { + save(prefs, dialog.sliderEditorCardSize, KEY_GUI_CARD_EDITOR_SIZE, "true", "false", UPDATE_CACHE_POLICY); + sizeGUIChanged = true; + } + if (getCachedValue(KEY_GUI_CARD_OFFSET_SIZE, 14) != dialog.sliderEditorCardOffset.getValue()) { + save(prefs, dialog.sliderEditorCardOffset, KEY_GUI_CARD_OFFSET_SIZE, "true", "false", UPDATE_CACHE_POLICY); + sizeGUIChanged = true; + } + if (getCachedValue(KEY_GUI_ENLARGED_IMAGE_SIZE, 20) != dialog.sliderEnlargedImageSize.getValue()) { + save(prefs, dialog.sliderEnlargedImageSize, KEY_GUI_ENLARGED_IMAGE_SIZE, "true", "false", UPDATE_CACHE_POLICY); + sizeGUIChanged = true; + } + if (getCachedValue(KEY_GUI_STACK_WIDTH, 30) != dialog.sliderStackWidth.getValue()) { + save(prefs, dialog.sliderStackWidth, KEY_GUI_STACK_WIDTH, "true", "false", UPDATE_CACHE_POLICY); + sizeGUIChanged = true; + } + if (getCachedValue(KEY_GUI_TOOLTIP_SIZE, 14) != dialog.sliderTooltipSize.getValue()) { + save(prefs, dialog.sliderTooltipSize, KEY_GUI_TOOLTIP_SIZE, "true", "false", UPDATE_CACHE_POLICY); + sizeGUIChanged = true; + } + if (getCachedValue(KEY_GUI_DIALOG_FONT_SIZE, 14) != dialog.sliderDialogFont.getValue()) { + save(prefs, dialog.sliderDialogFont, KEY_GUI_DIALOG_FONT_SIZE, "true", "false", UPDATE_CACHE_POLICY); + sizeGUIChanged = true; + } + if (getCachedValue(KEY_GUI_FEEDBACK_AREA_SIZE, 14) != dialog.sliderGameFeedbackArea.getValue()) { + save(prefs, dialog.sliderGameFeedbackArea, KEY_GUI_FEEDBACK_AREA_SIZE, "true", "false", UPDATE_CACHE_POLICY); + sizeGUIChanged = true; + } + if (getCachedValue(KEY_GUI_CARD_OTHER_ZONES_SIZE, 14) != dialog.sliderCardSizeOtherZones.getValue()) { + save(prefs, dialog.sliderCardSizeOtherZones, KEY_GUI_CARD_OTHER_ZONES_SIZE, "true", "false", UPDATE_CACHE_POLICY); + sizeGUIChanged = true; + } + if (getCachedValue(KEY_GUI_CARD_BATTLEFIELD_MIN_SIZE, 10) != dialog.sliderCardSizeMaxBattlefield.getValue()) { + save(prefs, dialog.sliderCardSizeMinBattlefield, KEY_GUI_CARD_BATTLEFIELD_MIN_SIZE, "true", "false", UPDATE_CACHE_POLICY); + sizeGUIChanged = true; + } + if (getCachedValue(KEY_GUI_CARD_BATTLEFIELD_MAX_SIZE, 14) != dialog.sliderCardSizeMaxBattlefield.getValue()) { + save(prefs, dialog.sliderCardSizeMaxBattlefield, KEY_GUI_CARD_BATTLEFIELD_MAX_SIZE, "true", "false", UPDATE_CACHE_POLICY); + sizeGUIChanged = true; + } + if (sizeGUIChanged) { + // do as worker job + GUISizeHelper.changeGUISize(); + } - // Phases & Priority - save(prefs, dialog.checkBoxUpkeepYou, UPKEEP_YOU); - save(prefs, dialog.checkBoxDrawYou, DRAW_YOU); - save(prefs, dialog.checkBoxMainYou, MAIN_YOU); - save(prefs, dialog.checkBoxBeforeCYou, BEFORE_COMBAT_YOU); - save(prefs, dialog.checkBoxEndOfCYou, END_OF_COMBAT_YOU); - save(prefs, dialog.checkBoxMain2You, MAIN_TWO_YOU); - save(prefs, dialog.checkBoxEndTurnYou, END_OF_TURN_YOU); + // Phases & Priority + save(prefs, dialog.checkBoxUpkeepYou, UPKEEP_YOU); + save(prefs, dialog.checkBoxDrawYou, DRAW_YOU); + save(prefs, dialog.checkBoxMainYou, MAIN_YOU); + save(prefs, dialog.checkBoxBeforeCYou, BEFORE_COMBAT_YOU); + save(prefs, dialog.checkBoxEndOfCYou, END_OF_COMBAT_YOU); + save(prefs, dialog.checkBoxMain2You, MAIN_TWO_YOU); + save(prefs, dialog.checkBoxEndTurnYou, END_OF_TURN_YOU); - save(prefs, dialog.checkBoxUpkeepOthers, UPKEEP_OTHERS); - save(prefs, dialog.checkBoxDrawOthers, DRAW_OTHERS); - save(prefs, dialog.checkBoxMainOthers, MAIN_OTHERS); - save(prefs, dialog.checkBoxBeforeCOthers, BEFORE_COMBAT_OTHERS); - save(prefs, dialog.checkBoxEndOfCOthers, END_OF_COMBAT_OTHERS); - save(prefs, dialog.checkBoxMain2Others, MAIN_TWO_OTHERS); - save(prefs, dialog.checkBoxEndTurnOthers, END_OF_TURN_OTHERS); + save(prefs, dialog.checkBoxUpkeepOthers, UPKEEP_OTHERS); + save(prefs, dialog.checkBoxDrawOthers, DRAW_OTHERS); + save(prefs, dialog.checkBoxMainOthers, MAIN_OTHERS); + save(prefs, dialog.checkBoxBeforeCOthers, BEFORE_COMBAT_OTHERS); + save(prefs, dialog.checkBoxEndOfCOthers, END_OF_COMBAT_OTHERS); + save(prefs, dialog.checkBoxMain2Others, MAIN_TWO_OTHERS); + save(prefs, dialog.checkBoxEndTurnOthers, END_OF_TURN_OTHERS); - save(prefs, dialog.cbStopAttack, KEY_STOP_ATTACK, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbStopBlock, KEY_STOP_BLOCK, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbStopOnAllMain, KEY_STOP_ALL_MAIN_PHASES, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbStopOnAllEnd, KEY_STOP_ALL_END_PHASES, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbPassPriorityCast, KEY_PASS_PRIORITY_CAST, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbPassPriorityActivation, KEY_PASS_PRIORITY_ACTIVATION, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbAutoOrderTrigger, KEY_AUTO_ORDER_TRIGGER, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbStopAttack, KEY_STOP_ATTACK, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbStopBlock, KEY_STOP_BLOCK, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbStopOnAllMain, KEY_STOP_ALL_MAIN_PHASES, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbStopOnAllEnd, KEY_STOP_ALL_END_PHASES, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbPassPriorityCast, KEY_PASS_PRIORITY_CAST, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbPassPriorityActivation, KEY_PASS_PRIORITY_ACTIVATION, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbAutoOrderTrigger, KEY_AUTO_ORDER_TRIGGER, "true", "false", UPDATE_CACHE_POLICY); - // images - save(prefs, dialog.cbUseDefaultImageFolder, KEY_CARD_IMAGES_USE_DEFAULT, "true", "false", UPDATE_CACHE_POLICY); - saveImagesPath(prefs); - save(prefs, dialog.cbCheckForNewImages, KEY_CARD_IMAGES_CHECK, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbSaveToZipFiles, KEY_CARD_IMAGES_SAVE_TO_ZIP, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbNumberOfDownloadThreads, KEY_CARD_IMAGES_THREADS); - save(prefs, dialog.cbPreferedImageLanguage, KEY_CARD_IMAGES_PREF_LANGUAGE); + // images + save(prefs, dialog.cbUseDefaultImageFolder, KEY_CARD_IMAGES_USE_DEFAULT, "true", "false", UPDATE_CACHE_POLICY); + saveImagesPath(prefs); + save(prefs, dialog.cbCheckForNewImages, KEY_CARD_IMAGES_CHECK, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbSaveToZipFiles, KEY_CARD_IMAGES_SAVE_TO_ZIP, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbNumberOfDownloadThreads, KEY_CARD_IMAGES_THREADS); + save(prefs, dialog.cbPreferedImageLanguage, KEY_CARD_IMAGES_PREF_LANGUAGE); - save(prefs, dialog.cbUseDefaultBackground, KEY_BACKGROUND_IMAGE_DEFAULT, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbUseDefaultBattleImage, KEY_BATTLEFIELD_IMAGE_DEFAULT, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbUseRandomBattleImage, KEY_BATTLEFIELD_IMAGE_RANDOM, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbUseDefaultBackground, KEY_BACKGROUND_IMAGE_DEFAULT, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbUseDefaultBattleImage, KEY_BATTLEFIELD_IMAGE_DEFAULT, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbUseRandomBattleImage, KEY_BATTLEFIELD_IMAGE_RANDOM, "true", "false", UPDATE_CACHE_POLICY); - // rendering - save(prefs, dialog.cbCardRenderImageFallback, KEY_CARD_RENDERING_FALLBACK, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbCardRenderHideSetSymbol, KEY_CARD_RENDERING_SET_SYMBOL, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbCardRenderShowReminderText, KEY_CARD_RENDERING_REMINDER_TEXT, "true", "false", UPDATE_CACHE_POLICY); - - // sounds - save(prefs, dialog.cbEnableGameSounds, KEY_SOUNDS_GAME_ON, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbEnableDraftSounds, KEY_SOUNDS_DRAFT_ON, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbEnableSkipButtonsSounds, KEY_SOUNDS_SKIP_BUTTONS_ON, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbEnableOtherSounds, KEY_SOUNDS_OTHER_ON, "true", "false", UPDATE_CACHE_POLICY); - save(prefs, dialog.cbEnableBattlefieldBGM, KEY_SOUNDS_MATCH_MUSIC_ON, "true", "false", UPDATE_CACHE_POLICY); - saveSoundPath(prefs); + // rendering + save(prefs, dialog.cbCardRenderImageFallback, KEY_CARD_RENDERING_FALLBACK, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbCardRenderHideSetSymbol, KEY_CARD_RENDERING_SET_SYMBOL, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbCardRenderShowReminderText, KEY_CARD_RENDERING_REMINDER_TEXT, "true", "false", UPDATE_CACHE_POLICY); - // connection - save(prefs, dialog.cbProxyType, KEY_PROXY_TYPE); - save(prefs, dialog.txtProxyServer, KEY_PROXY_ADDRESS); - save(prefs, dialog.txtProxyPort, KEY_PROXY_PORT); - save(prefs, dialog.txtProxyUserName, KEY_PROXY_USERNAME); - save(prefs, dialog.rememberPswd, KEY_PROXY_REMEMBER, "true", "false", UPDATE_CACHE_POLICY); - if (dialog.rememberPswd.isSelected()) { - char[] input = txtPasswordField.getPassword(); - prefs.put(KEY_PROXY_PSWD, new String(input)); - } - save(prefs, dialog.txtURLServerList, KEY_CONNECTION_URL_SERVER_LIST); + // sounds + save(prefs, dialog.cbEnableGameSounds, KEY_SOUNDS_GAME_ON, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbEnableDraftSounds, KEY_SOUNDS_DRAFT_ON, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbEnableSkipButtonsSounds, KEY_SOUNDS_SKIP_BUTTONS_ON, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbEnableOtherSounds, KEY_SOUNDS_OTHER_ON, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.cbEnableBattlefieldBGM, KEY_SOUNDS_MATCH_MUSIC_ON, "true", "false", UPDATE_CACHE_POLICY); + saveSoundPath(prefs); - // Avatar - if (selectedAvatarId < MIN_AVATAR_ID || selectedAvatarId > MAX_AVATAR_ID) { - selectedAvatarId = DEFAULT_AVATAR_ID; - } - prefs.put(KEY_AVATAR, String.valueOf(selectedAvatarId)); - updateCache(KEY_AVATAR, String.valueOf(selectedAvatarId)); + // connection + save(prefs, dialog.cbProxyType, KEY_PROXY_TYPE); + save(prefs, dialog.txtProxyServer, KEY_PROXY_ADDRESS); + save(prefs, dialog.txtProxyPort, KEY_PROXY_PORT); + save(prefs, dialog.txtProxyUserName, KEY_PROXY_USERNAME); + save(prefs, dialog.rememberPswd, KEY_PROXY_REMEMBER, "true", "false", UPDATE_CACHE_POLICY); + if (dialog.rememberPswd.isSelected()) { + char[] input = txtPasswordField.getPassword(); + prefs.put(KEY_PROXY_PSWD, new String(input)); + } + save(prefs, dialog.txtURLServerList, KEY_CONNECTION_URL_SERVER_LIST); - try { - SessionHandler.updatePreferencesForServer(getUserData()); + // controls + save(prefs, dialog.keyConfirm, KEY_CONTROL_CONFIRM); + save(prefs, dialog.keyCancelSkip, KEY_CONTROL_CANCEL_SKIP); + save(prefs, dialog.keyNextTurn, KEY_CONTROL_NEXT_TURN); + save(prefs, dialog.keyEndStep, KEY_CONTROL_END_STEP); + save(prefs, dialog.keySkipStep, KEY_CONTROL_SKIP_STEP); + save(prefs, dialog.keyMainStep, KEY_CONTROL_MAIN_STEP); + save(prefs, dialog.keyYourTurn, KEY_CONTROL_YOUR_TURN); + save(prefs, dialog.keySkipStack, KEY_CONTROL_SKIP_STACK); + save(prefs, dialog.keyPriorEnd, KEY_CONTROL_PRIOR_END); - prefs.flush(); - } catch (BackingStoreException ex) { - logger.error("Error: couldn't save preferences", ex); - UserRequestMessage message = new UserRequestMessage("Error", "Error: couldn't save preferences. Please try once again."); - message.setButton1("OK", null); - MageFrame.getInstance().showUserRequestDialog(message); - } + // Avatar + if (selectedAvatarId < MIN_AVATAR_ID || selectedAvatarId > MAX_AVATAR_ID) { + selectedAvatarId = DEFAULT_AVATAR_ID; + } + prefs.put(KEY_AVATAR, String.valueOf(selectedAvatarId)); + updateCache(KEY_AVATAR, String.valueOf(selectedAvatarId)); - dialog.setVisible(false); + try { + SessionHandler.updatePreferencesForServer(getUserData()); + + prefs.flush(); + } catch (BackingStoreException ex) { + logger.error("Error: couldn't save preferences", ex); + UserRequestMessage message = new UserRequestMessage("Error", "Error: couldn't save preferences. Please try once again."); + message.setButton1("OK", null); + MageFrame.getInstance().showUserRequestDialog(message); + } + + dialog.setVisible(false); }//GEN-LAST:event_saveButtonActionPerformed private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed - dialog.setVisible(false); + dialog.setVisible(false); }//GEN-LAST:event_exitButtonActionPerformed - private void useDefaultPath() { - txtImageFolderPath.setText("./plugins/images/"); - txtImageFolderPath.setEnabled(false); - btnBrowseImageLocation.setEnabled(false); - } + private void useDefaultPath() { + txtImageFolderPath.setText("./plugins/images/"); + txtImageFolderPath.setEnabled(false); + btnBrowseImageLocation.setEnabled(false); + } - private void useConfigurablePath() { - String path = CACHE.get(KEY_CARD_IMAGES_PATH); - dialog.txtImageFolderPath.setText(path); - txtImageFolderPath.setEnabled(true); - btnBrowseImageLocation.setEnabled(true); - } + private void useConfigurablePath() { + String path = CACHE.get(KEY_CARD_IMAGES_PATH); + dialog.txtImageFolderPath.setText(path); + txtImageFolderPath.setEnabled(true); + btnBrowseImageLocation.setEnabled(true); + } private void cbProxyTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbProxyTypeActionPerformed - this.showProxySettings(); + this.showProxySettings(); }//GEN-LAST:event_cbProxyTypeActionPerformed private void txtPasswordFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPasswordFieldActionPerformed @@ -2680,128 +2842,128 @@ public class PreferencesDialog extends javax.swing.JDialog { }//GEN-LAST:event_rememberPswdActionPerformed private void cbEnableGameSoundsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEnableGameSoundsActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbEnableGameSoundsActionPerformed private void cbEnableBattlefieldBGMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEnableBattlefieldBGMActionPerformed - if (cbEnableBattlefieldBGM.isSelected()) { - txtBattlefieldIBGMPath.setEnabled(true); - btnBattlefieldBGMBrowse.setEnabled(true); - } else { - txtBattlefieldIBGMPath.setEnabled(false); - btnBattlefieldBGMBrowse.setEnabled(false); - } + if (cbEnableBattlefieldBGM.isSelected()) { + txtBattlefieldIBGMPath.setEnabled(true); + btnBattlefieldBGMBrowse.setEnabled(true); + } else { + txtBattlefieldIBGMPath.setEnabled(false); + btnBattlefieldBGMBrowse.setEnabled(false); + } }//GEN-LAST:event_cbEnableBattlefieldBGMActionPerformed - private void cbUseDefaultBackgroundActionPerformed(java.awt.event.ActionEvent evt) { - if (cbUseDefaultBackground.isSelected()) { - useDefaultBackgroundImage(); - } else { - useSelectBackgroundImage(); - } - } + private void cbUseDefaultBackgroundActionPerformed(java.awt.event.ActionEvent evt) { + if (cbUseDefaultBackground.isSelected()) { + useDefaultBackgroundImage(); + } else { + useSelectBackgroundImage(); + } + } - private void useDefaultBackgroundImage() { - txtBackgroundImagePath.setEnabled(false); - btnBrowseBackgroundImage.setEnabled(false); - txtBackgroundImagePath.setText(""); - } + private void useDefaultBackgroundImage() { + txtBackgroundImagePath.setEnabled(false); + btnBrowseBackgroundImage.setEnabled(false); + txtBackgroundImagePath.setText(""); + } - private void useSelectBackgroundImage() { - String path = CACHE.get(KEY_BACKGROUND_IMAGE); - dialog.txtBackgroundImagePath.setText(path); - txtBackgroundImagePath.setEnabled(true); - btnBrowseBackgroundImage.setEnabled(true); - } + private void useSelectBackgroundImage() { + String path = CACHE.get(KEY_BACKGROUND_IMAGE); + dialog.txtBackgroundImagePath.setText(path); + txtBackgroundImagePath.setEnabled(true); + btnBrowseBackgroundImage.setEnabled(true); + } - private void cbUseDefaultBattleImageActionPerformed(java.awt.event.ActionEvent evt) { - if (cbUseDefaultBattleImage.isSelected()) { - useDefaultBattlefield(); - } else { - useSelectedOrRandom(); - } - } + private void cbUseDefaultBattleImageActionPerformed(java.awt.event.ActionEvent evt) { + if (cbUseDefaultBattleImage.isSelected()) { + useDefaultBattlefield(); + } else { + useSelectedOrRandom(); + } + } - private void useDefaultBattlefield() { - cbUseRandomBattleImage.setEnabled(false); - txtBattlefieldImagePath.setEnabled(false); - btnBrowseBattlefieldImage.setEnabled(false); - } + private void useDefaultBattlefield() { + cbUseRandomBattleImage.setEnabled(false); + txtBattlefieldImagePath.setEnabled(false); + btnBrowseBattlefieldImage.setEnabled(false); + } - private void useSelectedOrRandom() { - cbUseRandomBattleImage.setEnabled(true); - String temp = CACHE.get(KEY_BATTLEFIELD_IMAGE_RANDOM); - if (temp != null) { - if (temp.equals("true")) { - useRandomBattleField(); - cbUseRandomBattleImage.setSelected(true); - } else { - useSelectedBattleField(); - cbUseRandomBattleImage.setSelected(false); - } - } else { - useSelectedBattleField(); - cbUseRandomBattleImage.setSelected(false); - } - } + private void useSelectedOrRandom() { + cbUseRandomBattleImage.setEnabled(true); + String temp = CACHE.get(KEY_BATTLEFIELD_IMAGE_RANDOM); + if (temp != null) { + if (temp.equals("true")) { + useRandomBattleField(); + cbUseRandomBattleImage.setSelected(true); + } else { + useSelectedBattleField(); + cbUseRandomBattleImage.setSelected(false); + } + } else { + useSelectedBattleField(); + cbUseRandomBattleImage.setSelected(false); + } + } - private void cbUseRandomBattleImageActionPerformed(java.awt.event.ActionEvent evt) { - if (cbUseRandomBattleImage.isSelected()) { - useRandomBattleField(); - } else { - useSelectedBattleField(); - } - } + private void cbUseRandomBattleImageActionPerformed(java.awt.event.ActionEvent evt) { + if (cbUseRandomBattleImage.isSelected()) { + useRandomBattleField(); + } else { + useSelectedBattleField(); + } + } - private void useRandomBattleField() { - txtBattlefieldImagePath.setEnabled(false); - btnBrowseBattlefieldImage.setEnabled(false); - } + private void useRandomBattleField() { + txtBattlefieldImagePath.setEnabled(false); + btnBrowseBattlefieldImage.setEnabled(false); + } - private void useSelectedBattleField() { - txtBattlefieldImagePath.setEnabled(true); - btnBrowseBattlefieldImage.setEnabled(true); - } + private void useSelectedBattleField() { + txtBattlefieldImagePath.setEnabled(true); + btnBrowseBattlefieldImage.setEnabled(true); + } - private void btnBrowseBackgroundImageActionPerformed(java.awt.event.ActionEvent evt) { - int returnVal = fc_i.showOpenDialog(PreferencesDialog.this); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = fc_i.getSelectedFile(); - txtBackgroundImagePath.setText(file.getAbsolutePath()); - } - } + private void btnBrowseBackgroundImageActionPerformed(java.awt.event.ActionEvent evt) { + int returnVal = fc_i.showOpenDialog(PreferencesDialog.this); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fc_i.getSelectedFile(); + txtBackgroundImagePath.setText(file.getAbsolutePath()); + } + } - private void btnBrowseBattlefieldImageActionPerformed(java.awt.event.ActionEvent evt) { - int returnVal = fc_i.showOpenDialog(PreferencesDialog.this); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = fc_i.getSelectedFile(); - txtBattlefieldImagePath.setText(file.getAbsolutePath()); - } - } + private void btnBrowseBattlefieldImageActionPerformed(java.awt.event.ActionEvent evt) { + int returnVal = fc_i.showOpenDialog(PreferencesDialog.this); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fc_i.getSelectedFile(); + txtBattlefieldImagePath.setText(file.getAbsolutePath()); + } + } private void txtBackgroundImagePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtBackgroundImagePathActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_txtBackgroundImagePathActionPerformed private void txtBattlefieldImagePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtBattlefieldImagePathActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_txtBattlefieldImagePathActionPerformed private void txtBattlefieldIBGMPathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtBattlefieldIBGMPathActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_txtBattlefieldIBGMPathActionPerformed private void btnBattlefieldBGMBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBattlefieldBGMBrowseActionPerformed - // TODO add your handling code here: - int returnVal = fc.showOpenDialog(PreferencesDialog.this); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = fc.getSelectedFile(); - txtBattlefieldIBGMPath.setText(file.getAbsolutePath()); - } + // TODO add your handling code here: + int returnVal = fc.showOpenDialog(PreferencesDialog.this); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + txtBattlefieldIBGMPath.setText(file.getAbsolutePath()); + } }//GEN-LAST:event_btnBattlefieldBGMBrowseActionPerformed private void cbGameLogAutoSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbGameLogAutoSaveActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbGameLogAutoSaveActionPerformed private void nonLandPermanentsInOnePileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nonLandPermanentsInOnePileActionPerformed @@ -2809,7 +2971,7 @@ public class PreferencesDialog extends javax.swing.JDialog { }//GEN-LAST:event_nonLandPermanentsInOnePileActionPerformed private void showPlayerNamesPermanentlyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showPlayerNamesPermanentlyActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_showPlayerNamesPermanentlyActionPerformed private void showCardNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showCardNameActionPerformed @@ -2817,653 +2979,714 @@ public class PreferencesDialog extends javax.swing.JDialog { }//GEN-LAST:event_showCardNameActionPerformed private void showAbilityPickerForcedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showAbilityPickerForcedActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_showAbilityPickerForcedActionPerformed private void cbEnableOtherSoundsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEnableOtherSoundsActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbEnableOtherSoundsActionPerformed private void cbStopAttackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbStopAttackActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbStopAttackActionPerformed private void cbStopBlockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbStopBlockActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbStopBlockActionPerformed private void cbStopOnAllMainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbStopOnAllMainActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbStopOnAllMainActionPerformed private void cbStopOnAllEndActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbStopOnAllEndActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbStopOnAllEndActionPerformed private void cbEnableDraftSoundsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEnableDraftSoundsActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbEnableDraftSoundsActionPerformed private void cbEnableSkipButtonsSoundsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEnableSkipButtonsSoundsActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbEnableSkipButtonsSoundsActionPerformed private void cbAllowRequestToShowHandCardsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbAllowRequestToShowHandCardsActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbAllowRequestToShowHandCardsActionPerformed private void cbShowStormCounterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbShowStormCounterActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbShowStormCounterActionPerformed private void cbConfirmEmptyManaPoolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbConfirmEmptyManaPoolActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbConfirmEmptyManaPoolActionPerformed private void cbAskMoveToGraveOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbAskMoveToGraveOrderActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbAskMoveToGraveOrderActionPerformed private void cbDraftLogAutoSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDraftLogAutoSaveActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbDraftLogAutoSaveActionPerformed private void cbPassPriorityCastActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPassPriorityCastActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbPassPriorityCastActionPerformed private void cbPassPriorityActivationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPassPriorityActivationActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbPassPriorityActivationActionPerformed private void cbAutoOrderTriggerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbAutoOrderTriggerActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbAutoOrderTriggerActionPerformed private void cbCardRenderImageFallbackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbCardRenderImageFallbackActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbCardRenderImageFallbackActionPerformed private void cbCardRenderShowReminderTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbCardRenderShowReminderTextActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbCardRenderShowReminderTextActionPerformed private void cbSaveToZipFilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSaveToZipFilesActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbSaveToZipFilesActionPerformed private void cbCheckForNewImagesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbCheckForNewImagesActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbCheckForNewImagesActionPerformed private void btnBrowseImageLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseImageLocationActionPerformed - int returnVal = fc.showOpenDialog(PreferencesDialog.this); + int returnVal = fc.showOpenDialog(PreferencesDialog.this); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = fc.getSelectedFile(); - txtImageFolderPath.setText(file.getAbsolutePath()); - } + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + txtImageFolderPath.setText(file.getAbsolutePath()); + } }//GEN-LAST:event_btnBrowseImageLocationActionPerformed private void cbUseDefaultImageFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbUseDefaultImageFolderActionPerformed - if (cbUseDefaultImageFolder.isSelected()) { - useDefaultPath(); - } else { - useConfigurablePath(); - } + if (cbUseDefaultImageFolder.isSelected()) { + useDefaultPath(); + } else { + useConfigurablePath(); + } }//GEN-LAST:event_cbUseDefaultImageFolderActionPerformed private void cbCardRenderHideSetSymbolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbCardRenderHideSetSymbolActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_cbCardRenderHideSetSymbolActionPerformed - private void showProxySettings() { - Connection.ProxyType proxyType = (Connection.ProxyType) cbProxyType.getSelectedItem(); - switch (proxyType) { - case SOCKS: - this.pnlProxy.setVisible(true); - this.pnlProxySettings.setVisible(true); - break; - case HTTP: - this.pnlProxy.setVisible(true); - this.pnlProxySettings.setVisible(true); - break; - case NONE: - this.pnlProxy.setVisible(false); - this.pnlProxySettings.setVisible(false); - break; - default: - break; - } - this.pack(); - this.repaint(); - } + private void showProxySettings() { + Connection.ProxyType proxyType = (Connection.ProxyType) cbProxyType.getSelectedItem(); + switch (proxyType) { + case SOCKS: + this.pnlProxy.setVisible(true); + this.pnlProxySettings.setVisible(true); + break; + case HTTP: + this.pnlProxy.setVisible(true); + this.pnlProxySettings.setVisible(true); + break; + case NONE: + this.pnlProxy.setVisible(false); + this.pnlProxySettings.setVisible(false); + break; + default: + break; + } + this.pack(); + this.repaint(); + } - public static void setProxyInformation(Connection connection) { - ProxyType configProxyType = Connection.ProxyType.valueByText(getCachedValue(KEY_PROXY_TYPE, "None")); - if (configProxyType == null) { - return; - } + public static void setProxyInformation(Connection connection) { + ProxyType configProxyType = Connection.ProxyType.valueByText(getCachedValue(KEY_PROXY_TYPE, "None")); + if (configProxyType == null) { + return; + } - connection.setProxyType(configProxyType); - if (!configProxyType.equals(ProxyType.NONE)) { - String host = getCachedValue(KEY_PROXY_ADDRESS, ""); - String port = getCachedValue(KEY_PROXY_PORT, ""); - if (!host.isEmpty() && !port.isEmpty()) { - connection.setProxyHost(host); - connection.setProxyPort(Integer.valueOf(port)); - String username = getCachedValue(KEY_PROXY_USERNAME, ""); - connection.setProxyUsername(username); - if (getCachedValue(KEY_PROXY_REMEMBER, "false").equals("true")) { - String password = getCachedValue(KEY_PROXY_PSWD, ""); - connection.setProxyPassword(password); - } - } else { - logger.warn("host or\\and port are empty: host=" + host + ", port=" + port); - } - } - } + connection.setProxyType(configProxyType); + if (!configProxyType.equals(ProxyType.NONE)) { + String host = getCachedValue(KEY_PROXY_ADDRESS, ""); + String port = getCachedValue(KEY_PROXY_PORT, ""); + if (!host.isEmpty() && !port.isEmpty()) { + connection.setProxyHost(host); + connection.setProxyPort(Integer.valueOf(port)); + String username = getCachedValue(KEY_PROXY_USERNAME, ""); + connection.setProxyUsername(username); + if (getCachedValue(KEY_PROXY_REMEMBER, "false").equals("true")) { + String password = getCachedValue(KEY_PROXY_PSWD, ""); + connection.setProxyPassword(password); + } + } else { + logger.warn("host or\\and port are empty: host=" + host + ", port=" + port); + } + } + } - /** - * @param args the command line arguments - */ - public static void main(String args[]) { - int param = 0; - if (args.length > 0) { - String param1 = args[0]; - if (param1.equals(OPEN_CONNECTION_TAB)) { - param = 4; - } - if (param1.equals(OPEN_PHASES_TAB)) { - param = 1; - } - } - final int openedTab = param; - java.awt.EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - if (!dialog.isVisible()) { - Preferences prefs = MageFrame.getPreferences(); + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + int param = 0; + if (args.length > 0) { + String param1 = args[0]; + if (param1.equals(OPEN_CONNECTION_TAB)) { + param = 4; + } + if (param1.equals(OPEN_PHASES_TAB)) { + param = 1; + } + } + final int openedTab = param; + java.awt.EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + if (!dialog.isVisible()) { + Preferences prefs = MageFrame.getPreferences(); - // Main & Phases - loadPhases(prefs); + // Main & Phases + loadPhases(prefs); - // Gui Size - loadGuiSize(prefs); + // Gui Size + loadGuiSize(prefs); - // Images - loadImagesSettings(prefs); + // Images + loadImagesSettings(prefs); - // Sounds - loadSoundSettings(prefs); + // Sounds + loadSoundSettings(prefs); - // Connection - loadProxySettings(prefs); + // Connection + loadProxySettings(prefs); - // Selected avatar - loadSelectedAvatar(prefs); + // Controls + loadControlSettings(prefs); - dialog.reset(); - // open specified tab before displaying - openTab(openedTab); + // Selected avatar + loadSelectedAvatar(prefs); - dialog.setLocation(300, 200); + dialog.reset(); + // open specified tab before displaying + openTab(openedTab); - dialog.setVisible(true); - } else { - dialog.requestFocus(); - } - } - }); - } + dialog.setLocation(300, 200); - private static void loadPhases(Preferences prefs) { - load(prefs, dialog.tooltipDelay, KEY_SHOW_TOOLTIPS_DELAY, "300"); - load(prefs, dialog.showCardName, KEY_SHOW_CARD_NAMES, "true"); - load(prefs, dialog.nonLandPermanentsInOnePile, KEY_PERMANENTS_IN_ONE_PILE, "true"); - load(prefs, dialog.showPlayerNamesPermanently, KEY_SHOW_PLAYER_NAMES_PERMANENTLY, "true"); - load(prefs, dialog.showAbilityPickerForced, KEY_SHOW_ABILITY_PICKER_FORCED, "true"); - load(prefs, dialog.cbAllowRequestToShowHandCards, KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true"); - load(prefs, dialog.cbShowStormCounter, KEY_GAME_SHOW_STORM_COUNTER, "true"); - load(prefs, dialog.cbConfirmEmptyManaPool, KEY_GAME_CONFIRM_EMPTY_MANA_POOL, "true"); - load(prefs, dialog.cbAskMoveToGraveOrder, KEY_GAME_ASK_MOVE_TO_GRAVE_ORDER, "true"); + dialog.setVisible(true); + } else { + dialog.requestFocus(); + } + } + }); + } - load(prefs, dialog.cbGameLogAutoSave, KEY_GAME_LOG_AUTO_SAVE, "true"); - load(prefs, dialog.cbDraftLogAutoSave, KEY_DRAFT_LOG_AUTO_SAVE, "true"); + private static void loadPhases(Preferences prefs) { + load(prefs, dialog.tooltipDelay, KEY_SHOW_TOOLTIPS_DELAY, "300"); + load(prefs, dialog.showCardName, KEY_SHOW_CARD_NAMES, "true"); + load(prefs, dialog.nonLandPermanentsInOnePile, KEY_PERMANENTS_IN_ONE_PILE, "true"); + load(prefs, dialog.showPlayerNamesPermanently, KEY_SHOW_PLAYER_NAMES_PERMANENTLY, "true"); + load(prefs, dialog.showAbilityPickerForced, KEY_SHOW_ABILITY_PICKER_FORCED, "true"); + load(prefs, dialog.cbAllowRequestToShowHandCards, KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true"); + load(prefs, dialog.cbShowStormCounter, KEY_GAME_SHOW_STORM_COUNTER, "true"); + load(prefs, dialog.cbConfirmEmptyManaPool, KEY_GAME_CONFIRM_EMPTY_MANA_POOL, "true"); + load(prefs, dialog.cbAskMoveToGraveOrder, KEY_GAME_ASK_MOVE_TO_GRAVE_ORDER, "true"); - load(prefs, dialog.checkBoxUpkeepYou, UPKEEP_YOU, "on", "on"); - load(prefs, dialog.checkBoxDrawYou, DRAW_YOU, "on", "on"); - load(prefs, dialog.checkBoxMainYou, MAIN_YOU, "on", "on"); - load(prefs, dialog.checkBoxBeforeCYou, BEFORE_COMBAT_YOU, "on", "on"); - load(prefs, dialog.checkBoxEndOfCYou, END_OF_COMBAT_YOU, "on", "on"); - load(prefs, dialog.checkBoxMain2You, MAIN_TWO_YOU, "on", "on"); - load(prefs, dialog.checkBoxEndTurnYou, END_OF_TURN_YOU, "on", "on"); + load(prefs, dialog.cbGameLogAutoSave, KEY_GAME_LOG_AUTO_SAVE, "true"); + load(prefs, dialog.cbDraftLogAutoSave, KEY_DRAFT_LOG_AUTO_SAVE, "true"); - load(prefs, dialog.checkBoxUpkeepOthers, UPKEEP_OTHERS, "on", "on"); - load(prefs, dialog.checkBoxDrawOthers, DRAW_OTHERS, "on", "on"); - load(prefs, dialog.checkBoxMainOthers, MAIN_OTHERS, "on", "on"); - load(prefs, dialog.checkBoxBeforeCOthers, BEFORE_COMBAT_OTHERS, "on", "on"); - load(prefs, dialog.checkBoxEndOfCOthers, END_OF_COMBAT_OTHERS, "on", "on"); - load(prefs, dialog.checkBoxMain2Others, MAIN_TWO_OTHERS, "on", "on"); - load(prefs, dialog.checkBoxEndTurnOthers, END_OF_TURN_OTHERS, "on", "on"); + load(prefs, dialog.checkBoxUpkeepYou, UPKEEP_YOU, "on", "on"); + load(prefs, dialog.checkBoxDrawYou, DRAW_YOU, "on", "on"); + load(prefs, dialog.checkBoxMainYou, MAIN_YOU, "on", "on"); + load(prefs, dialog.checkBoxBeforeCYou, BEFORE_COMBAT_YOU, "on", "on"); + load(prefs, dialog.checkBoxEndOfCYou, END_OF_COMBAT_YOU, "on", "on"); + load(prefs, dialog.checkBoxMain2You, MAIN_TWO_YOU, "on", "on"); + load(prefs, dialog.checkBoxEndTurnYou, END_OF_TURN_YOU, "on", "on"); - load(prefs, dialog.cbStopAttack, KEY_STOP_ATTACK, "true", "true"); - load(prefs, dialog.cbStopBlock, KEY_STOP_BLOCK, "true", "true"); - load(prefs, dialog.cbStopOnAllMain, KEY_STOP_ALL_MAIN_PHASES, "true", "false"); - load(prefs, dialog.cbStopOnAllEnd, KEY_STOP_ALL_END_PHASES, "true", "false"); - load(prefs, dialog.cbPassPriorityCast, KEY_PASS_PRIORITY_CAST, "true", "false"); - load(prefs, dialog.cbPassPriorityActivation, KEY_PASS_PRIORITY_ACTIVATION, "true", "false"); - load(prefs, dialog.cbAutoOrderTrigger, KEY_AUTO_ORDER_TRIGGER, "true", "true"); + load(prefs, dialog.checkBoxUpkeepOthers, UPKEEP_OTHERS, "on", "on"); + load(prefs, dialog.checkBoxDrawOthers, DRAW_OTHERS, "on", "on"); + load(prefs, dialog.checkBoxMainOthers, MAIN_OTHERS, "on", "on"); + load(prefs, dialog.checkBoxBeforeCOthers, BEFORE_COMBAT_OTHERS, "on", "on"); + load(prefs, dialog.checkBoxEndOfCOthers, END_OF_COMBAT_OTHERS, "on", "on"); + load(prefs, dialog.checkBoxMain2Others, MAIN_TWO_OTHERS, "on", "on"); + load(prefs, dialog.checkBoxEndTurnOthers, END_OF_TURN_OTHERS, "on", "on"); - } + load(prefs, dialog.cbStopAttack, KEY_STOP_ATTACK, "true", "true"); + load(prefs, dialog.cbStopBlock, KEY_STOP_BLOCK, "true", "true"); + load(prefs, dialog.cbStopOnAllMain, KEY_STOP_ALL_MAIN_PHASES, "true", "false"); + load(prefs, dialog.cbStopOnAllEnd, KEY_STOP_ALL_END_PHASES, "true", "false"); + load(prefs, dialog.cbPassPriorityCast, KEY_PASS_PRIORITY_CAST, "true", "false"); + load(prefs, dialog.cbPassPriorityActivation, KEY_PASS_PRIORITY_ACTIVATION, "true", "false"); + load(prefs, dialog.cbAutoOrderTrigger, KEY_AUTO_ORDER_TRIGGER, "true", "true"); - private static void loadGuiSize(Preferences prefs) { - load(prefs, dialog.sliderFontSize, KEY_GUI_TABLE_FONT_SIZE, "14"); - load(prefs, dialog.sliderChatFontSize, KEY_GUI_CHAT_FONT_SIZE, "14"); - load(prefs, dialog.sliderCardSizeHand, KEY_GUI_CARD_HAND_SIZE, "14"); - load(prefs, dialog.sliderEditorCardSize, KEY_GUI_CARD_EDITOR_SIZE, "14"); - load(prefs, dialog.sliderEditorCardOffset, KEY_GUI_CARD_OFFSET_SIZE, "14"); - load(prefs, dialog.sliderEnlargedImageSize, KEY_GUI_ENLARGED_IMAGE_SIZE, "20"); - load(prefs, dialog.sliderStackWidth, KEY_GUI_STACK_WIDTH, "14"); - load(prefs, dialog.sliderDialogFont, KEY_GUI_DIALOG_FONT_SIZE, "14"); - load(prefs, dialog.sliderTooltipSize, KEY_GUI_TOOLTIP_SIZE, "14"); - load(prefs, dialog.sliderGameFeedbackArea, KEY_GUI_FEEDBACK_AREA_SIZE, "14"); - load(prefs, dialog.sliderCardSizeOtherZones, KEY_GUI_CARD_OTHER_ZONES_SIZE, "14"); - load(prefs, dialog.sliderCardSizeMinBattlefield, KEY_GUI_CARD_BATTLEFIELD_MIN_SIZE, "10"); - load(prefs, dialog.sliderCardSizeMaxBattlefield, KEY_GUI_CARD_BATTLEFIELD_MAX_SIZE, "14"); - } + } - private static void loadImagesSettings(Preferences prefs) { - String prop = prefs.get(KEY_CARD_IMAGES_USE_DEFAULT, "true"); - if (prop.equals("true")) { - dialog.cbUseDefaultImageFolder.setSelected(true); - dialog.useDefaultPath(); - } else { - dialog.cbUseDefaultImageFolder.setSelected(false); - dialog.useConfigurablePath(); - String path = prefs.get(KEY_CARD_IMAGES_PATH, ""); - dialog.txtImageFolderPath.setText(path); - updateCache(KEY_CARD_IMAGES_PATH, path); - } - load(prefs, dialog.cbCheckForNewImages, KEY_CARD_IMAGES_CHECK, "true"); - load(prefs, dialog.cbSaveToZipFiles, KEY_CARD_IMAGES_SAVE_TO_ZIP, "true"); - dialog.cbNumberOfDownloadThreads.setSelectedItem(MageFrame.getPreferences().get(KEY_CARD_IMAGES_THREADS, "10")); - dialog.cbPreferedImageLanguage.setSelectedItem(MageFrame.getPreferences().get(KEY_CARD_IMAGES_PREF_LANGUAGE, "en")); + private static void loadGuiSize(Preferences prefs) { + load(prefs, dialog.sliderFontSize, KEY_GUI_TABLE_FONT_SIZE, "14"); + load(prefs, dialog.sliderChatFontSize, KEY_GUI_CHAT_FONT_SIZE, "14"); + load(prefs, dialog.sliderCardSizeHand, KEY_GUI_CARD_HAND_SIZE, "14"); + load(prefs, dialog.sliderEditorCardSize, KEY_GUI_CARD_EDITOR_SIZE, "14"); + load(prefs, dialog.sliderEditorCardOffset, KEY_GUI_CARD_OFFSET_SIZE, "14"); + load(prefs, dialog.sliderEnlargedImageSize, KEY_GUI_ENLARGED_IMAGE_SIZE, "20"); + load(prefs, dialog.sliderStackWidth, KEY_GUI_STACK_WIDTH, "14"); + load(prefs, dialog.sliderDialogFont, KEY_GUI_DIALOG_FONT_SIZE, "14"); + load(prefs, dialog.sliderTooltipSize, KEY_GUI_TOOLTIP_SIZE, "14"); + load(prefs, dialog.sliderGameFeedbackArea, KEY_GUI_FEEDBACK_AREA_SIZE, "14"); + load(prefs, dialog.sliderCardSizeOtherZones, KEY_GUI_CARD_OTHER_ZONES_SIZE, "14"); + load(prefs, dialog.sliderCardSizeMinBattlefield, KEY_GUI_CARD_BATTLEFIELD_MIN_SIZE, "10"); + load(prefs, dialog.sliderCardSizeMaxBattlefield, KEY_GUI_CARD_BATTLEFIELD_MAX_SIZE, "14"); + } - // rendering settings - load(prefs, dialog.cbCardRenderImageFallback, KEY_CARD_RENDERING_FALLBACK, "true"); - load(prefs, dialog.cbCardRenderHideSetSymbol, KEY_CARD_RENDERING_SET_SYMBOL, "true"); - load(prefs, dialog.cbCardRenderShowReminderText, KEY_CARD_RENDERING_REMINDER_TEXT, "true"); - - //add background load precedure - prop = prefs.get(KEY_BACKGROUND_IMAGE_DEFAULT, "true"); - if (prop.equals("true")) { - dialog.cbUseDefaultBackground.setSelected(true); - dialog.useDefaultBackgroundImage(); - } else { - dialog.cbUseDefaultBackground.setSelected(false); - dialog.useSelectBackgroundImage(); - String path = prefs.get(KEY_BACKGROUND_IMAGE, ""); - dialog.txtBackgroundImagePath.setText(path); - updateCache(KEY_BACKGROUND_IMAGE, path); - } - prop = prefs.get(KEY_BATTLEFIELD_IMAGE_DEFAULT, "true"); - if (prop.equals("true")) { - dialog.cbUseDefaultBattleImage.setSelected(true); - dialog.useDefaultBattlefield(); - } else { - dialog.cbUseDefaultBattleImage.setSelected(false); - dialog.useSelectedOrRandom(); - } - prop = prefs.get(KEY_BATTLEFIELD_IMAGE_RANDOM, "true"); + private static void loadImagesSettings(Preferences prefs) { + String prop = prefs.get(KEY_CARD_IMAGES_USE_DEFAULT, "true"); + if (prop.equals("true")) { + dialog.cbUseDefaultImageFolder.setSelected(true); + dialog.useDefaultPath(); + } else { + dialog.cbUseDefaultImageFolder.setSelected(false); + dialog.useConfigurablePath(); + String path = prefs.get(KEY_CARD_IMAGES_PATH, ""); + dialog.txtImageFolderPath.setText(path); + updateCache(KEY_CARD_IMAGES_PATH, path); + } + load(prefs, dialog.cbCheckForNewImages, KEY_CARD_IMAGES_CHECK, "true"); + load(prefs, dialog.cbSaveToZipFiles, KEY_CARD_IMAGES_SAVE_TO_ZIP, "true"); + dialog.cbNumberOfDownloadThreads.setSelectedItem(MageFrame.getPreferences().get(KEY_CARD_IMAGES_THREADS, "10")); + dialog.cbPreferedImageLanguage.setSelectedItem(MageFrame.getPreferences().get(KEY_CARD_IMAGES_PREF_LANGUAGE, "en")); - if (dialog.cbUseRandomBattleImage.isEnabled()) { - if (prop.equals("true")) { - dialog.cbUseRandomBattleImage.setSelected(true); - dialog.useRandomBattleField(); - } else { - dialog.cbUseRandomBattleImage.setSelected(false); - dialog.useSelectedBattleField(); - String path = prefs.get(KEY_BATTLEFIELD_IMAGE, ""); - dialog.txtBattlefieldImagePath.setText(path); - updateCache(KEY_BATTLEFIELD_IMAGE, path); - } - } - } + // rendering settings + load(prefs, dialog.cbCardRenderImageFallback, KEY_CARD_RENDERING_FALLBACK, "true"); + load(prefs, dialog.cbCardRenderHideSetSymbol, KEY_CARD_RENDERING_SET_SYMBOL, "true"); + load(prefs, dialog.cbCardRenderShowReminderText, KEY_CARD_RENDERING_REMINDER_TEXT, "true"); - private static void loadSoundSettings(Preferences prefs) { - dialog.cbEnableGameSounds.setSelected(prefs.get(KEY_SOUNDS_GAME_ON, "true").equals("true")); - dialog.cbEnableDraftSounds.setSelected(prefs.get(KEY_SOUNDS_DRAFT_ON, "true").equals("true")); - dialog.cbEnableSkipButtonsSounds.setSelected(prefs.get(KEY_SOUNDS_SKIP_BUTTONS_ON, "true").equals("true")); - dialog.cbEnableOtherSounds.setSelected(prefs.get(KEY_SOUNDS_OTHER_ON, "true").equals("true")); + //add background load precedure + prop = prefs.get(KEY_BACKGROUND_IMAGE_DEFAULT, "true"); + if (prop.equals("true")) { + dialog.cbUseDefaultBackground.setSelected(true); + dialog.useDefaultBackgroundImage(); + } else { + dialog.cbUseDefaultBackground.setSelected(false); + dialog.useSelectBackgroundImage(); + String path = prefs.get(KEY_BACKGROUND_IMAGE, ""); + dialog.txtBackgroundImagePath.setText(path); + updateCache(KEY_BACKGROUND_IMAGE, path); + } + prop = prefs.get(KEY_BATTLEFIELD_IMAGE_DEFAULT, "true"); + if (prop.equals("true")) { + dialog.cbUseDefaultBattleImage.setSelected(true); + dialog.useDefaultBattlefield(); + } else { + dialog.cbUseDefaultBattleImage.setSelected(false); + dialog.useSelectedOrRandom(); + } + prop = prefs.get(KEY_BATTLEFIELD_IMAGE_RANDOM, "true"); - // Match music - dialog.cbEnableBattlefieldBGM.setSelected(prefs.get(KEY_SOUNDS_MATCH_MUSIC_ON, "true").equals("true")); - dialog.txtBattlefieldIBGMPath.setEnabled(dialog.cbEnableBattlefieldBGM.isSelected()); - dialog.btnBattlefieldBGMBrowse.setEnabled(dialog.cbEnableBattlefieldBGM.isSelected()); - // load and save the path always, so you can reactivate music without selecting path again - String path = prefs.get(KEY_SOUNDS_MATCH_MUSIC_PATH, ""); - dialog.txtBattlefieldIBGMPath.setText(path); + if (dialog.cbUseRandomBattleImage.isEnabled()) { + if (prop.equals("true")) { + dialog.cbUseRandomBattleImage.setSelected(true); + dialog.useRandomBattleField(); + } else { + dialog.cbUseRandomBattleImage.setSelected(false); + dialog.useSelectedBattleField(); + String path = prefs.get(KEY_BATTLEFIELD_IMAGE, ""); + dialog.txtBattlefieldImagePath.setText(path); + updateCache(KEY_BATTLEFIELD_IMAGE, path); + } + } + } - updateCache(KEY_SOUNDS_MATCH_MUSIC_PATH, path); - } + private static void loadSoundSettings(Preferences prefs) { + dialog.cbEnableGameSounds.setSelected(prefs.get(KEY_SOUNDS_GAME_ON, "true").equals("true")); + dialog.cbEnableDraftSounds.setSelected(prefs.get(KEY_SOUNDS_DRAFT_ON, "true").equals("true")); + dialog.cbEnableSkipButtonsSounds.setSelected(prefs.get(KEY_SOUNDS_SKIP_BUTTONS_ON, "true").equals("true")); + dialog.cbEnableOtherSounds.setSelected(prefs.get(KEY_SOUNDS_OTHER_ON, "true").equals("true")); - private static void loadProxySettings(Preferences prefs) { - dialog.cbProxyType.setSelectedItem(Connection.ProxyType.valueOf(MageFrame.getPreferences().get(KEY_PROXY_TYPE, "NONE").toUpperCase())); + // Match music + dialog.cbEnableBattlefieldBGM.setSelected(prefs.get(KEY_SOUNDS_MATCH_MUSIC_ON, "true").equals("true")); + dialog.txtBattlefieldIBGMPath.setEnabled(dialog.cbEnableBattlefieldBGM.isSelected()); + dialog.btnBattlefieldBGMBrowse.setEnabled(dialog.cbEnableBattlefieldBGM.isSelected()); + // load and save the path always, so you can reactivate music without selecting path again + String path = prefs.get(KEY_SOUNDS_MATCH_MUSIC_PATH, ""); + dialog.txtBattlefieldIBGMPath.setText(path); - load(prefs, dialog.txtProxyServer, KEY_PROXY_ADDRESS, Config.serverName); - load(prefs, dialog.txtProxyPort, KEY_PROXY_PORT, Integer.toString(Config.port)); - load(prefs, dialog.txtProxyUserName, KEY_PROXY_USERNAME, ""); - load(prefs, dialog.rememberPswd, KEY_PROXY_REMEMBER, "true", "false"); - if (dialog.rememberPswd.isSelected()) { - load(prefs, dialog.txtPasswordField, KEY_PROXY_PSWD, ""); - } - load(prefs, dialog.txtURLServerList, KEY_CONNECTION_URL_SERVER_LIST, "http://XMage.de/files/server-list.txt"); - } + updateCache(KEY_SOUNDS_MATCH_MUSIC_PATH, path); + } - private static void loadSelectedAvatar(Preferences prefs) { - getSelectedAvatar(); - dialog.setSelectedId(selectedAvatarId); - } + private static void loadProxySettings(Preferences prefs) { + dialog.cbProxyType.setSelectedItem(Connection.ProxyType.valueOf(MageFrame.getPreferences().get(KEY_PROXY_TYPE, "NONE").toUpperCase())); - public static int getSelectedAvatar() { - try { - selectedAvatarId = Integer.valueOf(MageFrame.getPreferences().get(KEY_AVATAR, String.valueOf(DEFAULT_AVATAR_ID))); - } catch (NumberFormatException n) { - selectedAvatarId = DEFAULT_AVATAR_ID; - } finally { - if (selectedAvatarId < MIN_AVATAR_ID || selectedAvatarId > MAX_AVATAR_ID) { - selectedAvatarId = DEFAULT_AVATAR_ID; - } - } - return selectedAvatarId; - } + load(prefs, dialog.txtProxyServer, KEY_PROXY_ADDRESS, Config.serverName); + load(prefs, dialog.txtProxyPort, KEY_PROXY_PORT, Integer.toString(Config.port)); + load(prefs, dialog.txtProxyUserName, KEY_PROXY_USERNAME, ""); + load(prefs, dialog.rememberPswd, KEY_PROXY_REMEMBER, "true", "false"); + if (dialog.rememberPswd.isSelected()) { + load(prefs, dialog.txtPasswordField, KEY_PROXY_PSWD, ""); + } + load(prefs, dialog.txtURLServerList, KEY_CONNECTION_URL_SERVER_LIST, "http://XMage.de/files/server-list.txt"); + } - public static UserSkipPrioritySteps getUserSkipPrioritySteps() { - if (!dialog.isVisible()) { - loadPhases(MageFrame.getPreferences()); - } - UserSkipPrioritySteps userSkipPrioritySteps = new UserSkipPrioritySteps(); + private static void loadControlSettings(Preferences prefs) { + load(prefs, dialog.keyConfirm, KEY_CONTROL_CONFIRM); + load(prefs, dialog.keyCancelSkip, KEY_CONTROL_CANCEL_SKIP); + load(prefs, dialog.keyNextTurn, KEY_CONTROL_NEXT_TURN); + load(prefs, dialog.keyEndStep, KEY_CONTROL_END_STEP); + load(prefs, dialog.keySkipStep, KEY_CONTROL_SKIP_STEP); + load(prefs, dialog.keyMainStep, KEY_CONTROL_MAIN_STEP); + load(prefs, dialog.keyYourTurn, KEY_CONTROL_YOUR_TURN); + load(prefs, dialog.keySkipStack, KEY_CONTROL_SKIP_STACK); + load(prefs, dialog.keyPriorEnd, KEY_CONTROL_PRIOR_END); + } - userSkipPrioritySteps.getYourTurn().setUpkeep(dialog.checkBoxUpkeepYou.isSelected()); - userSkipPrioritySteps.getYourTurn().setDraw(dialog.checkBoxDrawYou.isSelected()); - userSkipPrioritySteps.getYourTurn().setMain1(dialog.checkBoxMainYou.isSelected()); - userSkipPrioritySteps.getYourTurn().setBeforeCombat(dialog.checkBoxBeforeCYou.isSelected()); - userSkipPrioritySteps.getYourTurn().setEndOfCombat(dialog.checkBoxEndOfCYou.isSelected()); - userSkipPrioritySteps.getYourTurn().setMain2(dialog.checkBoxMain2You.isSelected()); - userSkipPrioritySteps.getYourTurn().setEndOfTurn(dialog.checkBoxEndTurnYou.isSelected()); + private static void loadSelectedAvatar(Preferences prefs) { + getSelectedAvatar(); + dialog.setSelectedId(selectedAvatarId); + } - userSkipPrioritySteps.getOpponentTurn().setUpkeep(dialog.checkBoxUpkeepOthers.isSelected()); - userSkipPrioritySteps.getOpponentTurn().setDraw(dialog.checkBoxDrawOthers.isSelected()); - userSkipPrioritySteps.getOpponentTurn().setMain1(dialog.checkBoxMainOthers.isSelected()); - userSkipPrioritySteps.getOpponentTurn().setBeforeCombat(dialog.checkBoxBeforeCOthers.isSelected()); - userSkipPrioritySteps.getOpponentTurn().setEndOfCombat(dialog.checkBoxEndOfCOthers.isSelected()); - userSkipPrioritySteps.getOpponentTurn().setMain2(dialog.checkBoxMain2Others.isSelected()); - userSkipPrioritySteps.getOpponentTurn().setEndOfTurn(dialog.checkBoxEndTurnOthers.isSelected()); + public static int getSelectedAvatar() { + try { + selectedAvatarId = Integer.valueOf(MageFrame.getPreferences().get(KEY_AVATAR, String.valueOf(DEFAULT_AVATAR_ID))); + } catch (NumberFormatException n) { + selectedAvatarId = DEFAULT_AVATAR_ID; + } finally { + if (selectedAvatarId < MIN_AVATAR_ID || selectedAvatarId > MAX_AVATAR_ID) { + selectedAvatarId = DEFAULT_AVATAR_ID; + } + } + return selectedAvatarId; + } - userSkipPrioritySteps.setStopOnDeclareAttackersDuringSkipActions(dialog.cbStopAttack.isSelected()); - userSkipPrioritySteps.setStopOnDeclareBlockerIfNoneAvailable(dialog.cbStopBlock.isSelected()); - userSkipPrioritySteps.setStopOnAllEndPhases(dialog.cbStopOnAllEnd.isSelected()); - userSkipPrioritySteps.setStopOnAllMainPhases(dialog.cbStopOnAllMain.isSelected()); + public static UserSkipPrioritySteps getUserSkipPrioritySteps() { + if (!dialog.isVisible()) { + loadPhases(MageFrame.getPreferences()); + } + UserSkipPrioritySteps userSkipPrioritySteps = new UserSkipPrioritySteps(); - return userSkipPrioritySteps; - } + userSkipPrioritySteps.getYourTurn().setUpkeep(dialog.checkBoxUpkeepYou.isSelected()); + userSkipPrioritySteps.getYourTurn().setDraw(dialog.checkBoxDrawYou.isSelected()); + userSkipPrioritySteps.getYourTurn().setMain1(dialog.checkBoxMainYou.isSelected()); + userSkipPrioritySteps.getYourTurn().setBeforeCombat(dialog.checkBoxBeforeCYou.isSelected()); + userSkipPrioritySteps.getYourTurn().setEndOfCombat(dialog.checkBoxEndOfCYou.isSelected()); + userSkipPrioritySteps.getYourTurn().setMain2(dialog.checkBoxMain2You.isSelected()); + userSkipPrioritySteps.getYourTurn().setEndOfTurn(dialog.checkBoxEndTurnYou.isSelected()); - private static void openTab(int index) { - try { - if (index > 0) { - dialog.tabsPanel.setSelectedIndex(index); - } - } catch (Exception e) { - logger.error("Error during open tab", e); - } - } + userSkipPrioritySteps.getOpponentTurn().setUpkeep(dialog.checkBoxUpkeepOthers.isSelected()); + userSkipPrioritySteps.getOpponentTurn().setDraw(dialog.checkBoxDrawOthers.isSelected()); + userSkipPrioritySteps.getOpponentTurn().setMain1(dialog.checkBoxMainOthers.isSelected()); + userSkipPrioritySteps.getOpponentTurn().setBeforeCombat(dialog.checkBoxBeforeCOthers.isSelected()); + userSkipPrioritySteps.getOpponentTurn().setEndOfCombat(dialog.checkBoxEndOfCOthers.isSelected()); + userSkipPrioritySteps.getOpponentTurn().setMain2(dialog.checkBoxMain2Others.isSelected()); + userSkipPrioritySteps.getOpponentTurn().setEndOfTurn(dialog.checkBoxEndTurnOthers.isSelected()); - private static void saveImagesPath(Preferences prefs) { - if (!dialog.cbUseDefaultImageFolder.isSelected()) { - String path = dialog.txtImageFolderPath.getText(); - prefs.put(KEY_CARD_IMAGES_PATH, path); - updateCache(KEY_CARD_IMAGES_PATH, path); - } - // background path save precedure - if (!dialog.cbUseDefaultBackground.isSelected()) { - String path = dialog.txtBackgroundImagePath.getText(); - prefs.put(KEY_BACKGROUND_IMAGE, path); - updateCache(KEY_BACKGROUND_IMAGE, path); - } - if (!dialog.cbUseDefaultBattleImage.isSelected() && !dialog.cbUseRandomBattleImage.isSelected()) { - String path = dialog.txtBattlefieldImagePath.getText(); - prefs.put(KEY_BATTLEFIELD_IMAGE, path); - updateCache(KEY_BATTLEFIELD_IMAGE, path); - } - } + userSkipPrioritySteps.setStopOnDeclareAttackersDuringSkipActions(dialog.cbStopAttack.isSelected()); + userSkipPrioritySteps.setStopOnDeclareBlockerIfNoneAvailable(dialog.cbStopBlock.isSelected()); + userSkipPrioritySteps.setStopOnAllEndPhases(dialog.cbStopOnAllEnd.isSelected()); + userSkipPrioritySteps.setStopOnAllMainPhases(dialog.cbStopOnAllMain.isSelected()); - private static void saveSoundPath(Preferences prefs) { - String path = dialog.txtBattlefieldIBGMPath.getText(); - prefs.put(KEY_SOUNDS_MATCH_MUSIC_PATH, path); - updateCache(KEY_SOUNDS_MATCH_MUSIC_PATH, path); - } + return userSkipPrioritySteps; + } - public static boolean isSaveImagesToZip() { - return PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_SAVE_TO_ZIP, "true").equals("true"); - } + private static void openTab(int index) { + try { + if (index > 0) { + dialog.tabsPanel.setSelectedIndex(index); + } + } catch (Exception e) { + logger.error("Error during open tab", e); + } + } - private static void load(Preferences prefs, JCheckBox checkBox, String propName, String yesValue) { - String prop = prefs.get(propName, yesValue); - checkBox.setSelected(prop.equals(yesValue)); - } + private static void saveImagesPath(Preferences prefs) { + if (!dialog.cbUseDefaultImageFolder.isSelected()) { + String path = dialog.txtImageFolderPath.getText(); + prefs.put(KEY_CARD_IMAGES_PATH, path); + updateCache(KEY_CARD_IMAGES_PATH, path); + } + // background path save precedure + if (!dialog.cbUseDefaultBackground.isSelected()) { + String path = dialog.txtBackgroundImagePath.getText(); + prefs.put(KEY_BACKGROUND_IMAGE, path); + updateCache(KEY_BACKGROUND_IMAGE, path); + } + if (!dialog.cbUseDefaultBattleImage.isSelected() && !dialog.cbUseRandomBattleImage.isSelected()) { + String path = dialog.txtBattlefieldImagePath.getText(); + prefs.put(KEY_BATTLEFIELD_IMAGE, path); + updateCache(KEY_BATTLEFIELD_IMAGE, path); + } + } - private static void load(Preferences prefs, JCheckBox checkBox, String propName, String yesValue, String defaultValue) { - String prop = prefs.get(propName, defaultValue); - checkBox.setSelected(prop.equals(yesValue)); - updateCache(propName, prop); - } + private static void saveSoundPath(Preferences prefs) { + String path = dialog.txtBattlefieldIBGMPath.getText(); + prefs.put(KEY_SOUNDS_MATCH_MUSIC_PATH, path); + updateCache(KEY_SOUNDS_MATCH_MUSIC_PATH, path); + } - private static void load(Preferences prefs, JTextField field, String propName, String defaultValue) { - String prop = prefs.get(propName, defaultValue); - field.setText(prop); - } + public static boolean isSaveImagesToZip() { + return PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_SAVE_TO_ZIP, "true").equals("true"); + } - private static void load(Preferences prefs, JSlider field, String propName, String defaultValue) { - String prop = prefs.get(propName, defaultValue); - int value; - try { - value = Integer.parseInt(prop); - } catch (NumberFormatException e) { - // It's OK to ignore "e" here because returning a default value is the documented behaviour on invalid input. - value = Integer.parseInt(defaultValue); - } - field.setValue(value); - } + private static void load(Preferences prefs, JCheckBox checkBox, String propName, String yesValue) { + String prop = prefs.get(propName, yesValue); + checkBox.setSelected(prop.equals(yesValue)); + } - private static void load(Preferences prefs, JComboBox field, String propName, String defaultValue) { - String prop = prefs.get(propName, defaultValue); - field.setSelectedItem(prop); - } + private static void load(Preferences prefs, JCheckBox checkBox, String propName, String yesValue, String defaultValue) { + String prop = prefs.get(propName, defaultValue); + checkBox.setSelected(prop.equals(yesValue)); + updateCache(propName, prop); + } - private static void load(Preferences prefs, JCheckBox checkBox, String propName) { - load(prefs, checkBox, propName, PHASE_ON); - } + private static void load(Preferences prefs, JTextField field, String propName, String defaultValue) { + String prop = prefs.get(propName, defaultValue); + field.setText(prop); + } - private static void save(Preferences prefs, JCheckBox checkBox, String propName) { - save(prefs, checkBox, propName, PHASE_ON, PHASE_OFF, false); - } + private static void load(Preferences prefs, JSlider field, String propName, String defaultValue) { + String prop = prefs.get(propName, defaultValue); + int value; + try { + value = Integer.parseInt(prop); + } catch (NumberFormatException e) { + // It's OK to ignore "e" here because returning a default value is the documented behaviour on invalid input. + value = Integer.parseInt(defaultValue); + } + field.setValue(value); + } - public static void setPrefValue(String key, boolean value) { - switch (key) { - case KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS: - dialog.cbAllowRequestToShowHandCards.setSelected(value); - save(MageFrame.getPreferences(), dialog.cbAllowRequestToShowHandCards, KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true", "false", UPDATE_CACHE_POLICY); - break; - } - } + private static void load(Preferences prefs, JComboBox field, String propName, String defaultValue) { + String prop = prefs.get(propName, defaultValue); + field.setSelectedItem(prop); + } - private static void save(Preferences prefs, JCheckBox checkBox, String propName, String yesValue, String noValue, boolean updateCache) { - prefs.put(propName, checkBox.isSelected() ? yesValue : noValue); - if (updateCache) { - updateCache(propName, checkBox.isSelected() ? yesValue : noValue); - } - } + private static void load(Preferences prefs, JCheckBox checkBox, String propName) { + load(prefs, checkBox, propName, PHASE_ON); + } - private static void save(Preferences prefs, JSlider slider, String propName, String yesValue, String noValue, boolean updateCache) { - prefs.put(propName, Integer.toString(slider.getValue())); - if (updateCache) { - updateCache(propName, Integer.toString(slider.getValue())); - } - } + private static void load(Preferences prefs, KeyBindButton button, String propName) { + int prop = prefs.getInt(propName, getDefaultControlKey(propName)); + button.setKeyCode(prop); + } - private static void save(Preferences prefs, JTextField textField, String propName) { - prefs.put(propName, textField.getText().trim()); - updateCache(propName, textField.getText().trim()); - } + private static void save(Preferences prefs, JCheckBox checkBox, String propName) { + save(prefs, checkBox, propName, PHASE_ON, PHASE_OFF, false); + } - private static void save(Preferences prefs, JComboBox comboBox, String propName) { - prefs.put(propName, comboBox.getSelectedItem().toString().trim()); - updateCache(propName, comboBox.getSelectedItem().toString().trim()); - } + public static void setPrefValue(String key, boolean value) { + switch (key) { + case KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS: + dialog.cbAllowRequestToShowHandCards.setSelected(value); + save(MageFrame.getPreferences(), dialog.cbAllowRequestToShowHandCards, KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true", "false", UPDATE_CACHE_POLICY); + break; + } + } - public void reset() { - tabsPanel.setSelectedIndex(0); - } + private static void save(Preferences prefs, JCheckBox checkBox, String propName, String yesValue, String noValue, boolean updateCache) { + prefs.put(propName, checkBox.isSelected() ? yesValue : noValue); + if (updateCache) { + updateCache(propName, checkBox.isSelected() ? yesValue : noValue); + } + } - public static int getCachedValue(String key, int def) { - String stringValue = getCachedValue(key, String.valueOf(def)); - int value; - try { - value = Integer.parseInt(stringValue); - } catch (NumberFormatException e) { - // It's OK to ignore "e" here because returning a default value is the documented behaviour on invalid input. - value = def; - } - return value; - } + private static void save(Preferences prefs, JSlider slider, String propName, String yesValue, String noValue, boolean updateCache) { + prefs.put(propName, Integer.toString(slider.getValue())); + if (updateCache) { + updateCache(propName, Integer.toString(slider.getValue())); + } + } - public static String getCachedValue(String key, String def) { - if (CACHE.containsKey(key)) { - return CACHE.get(key); - } else { - Preferences prefs = MageFrame.getPreferences(); - String value = prefs.get(key, def); - if (value == null) { - return null; - } - CACHE.put(key, value); - return value; - } - } + private static void save(Preferences prefs, JTextField textField, String propName) { + prefs.put(propName, textField.getText().trim()); + updateCache(propName, textField.getText().trim()); + } - private static void updateCache(String key, String value) { - CACHE.put(key, value); - } + private static void save(Preferences prefs, JComboBox comboBox, String propName) { + prefs.put(propName, comboBox.getSelectedItem().toString().trim()); + updateCache(propName, comboBox.getSelectedItem().toString().trim()); + } - public static void saveValue(String key, String value) { - Preferences prefs = MageFrame.getPreferences(); - prefs.put(key, value); - try { - prefs.flush(); - } catch (BackingStoreException ex) { - ex.printStackTrace(); - JOptionPane.showMessageDialog(null, "Error: couldn't save preferences. Please try once again."); - } - updateCache(key, value); - } + private static void save(Preferences prefs, KeyBindButton button, String propName) { + int code = button.getKeyCode(); + prefs.putInt(propName, code); + updateCache(propName, Integer.toString(code)); + } - private void addAvatars() { - try { - addAvatar(jPanel10, 10, true, false); - addAvatar(jPanel11, 11, false, false); - addAvatar(jPanel12, 12, false, false); - addAvatar(jPanel13, 13, false, false); - addAvatar(jPanel14, 14, false, false); - addAvatar(jPanel15, 15, false, false); - addAvatar(jPanel16, 16, false, false); - addAvatar(jPanel17, 17, false, false); - addAvatar(jPanel18, 18, false, false); - addAvatar(jPanel19, 19, false, false); - addAvatar(jPanel20, 20, false, false); - addAvatar(jPanel21, 21, false, false); - addAvatar(jPanel22, 22, false, false); - addAvatar(jPanel23, 23, false, false); - addAvatar(jPanel24, 24, false, false); - addAvatar(jPanel25, 25, false, false); - addAvatar(jPanel26, 26, false, false); - addAvatar(jPanel27, 27, false, false); - addAvatar(jPanel28, 28, false, false); - addAvatar(jPanel29, 29, false, false); - addAvatar(jPanel30, 30, false, false); - addAvatar(jPanel31, 31, false, false); - addAvatar(jPanel32, 32, false, false); + public void reset() { + tabsPanel.setSelectedIndex(0); + } - } catch (Exception e) { - logger.error(e, e); - } - } + public static int getCachedValue(String key, int def) { + String stringValue = getCachedValue(key, String.valueOf(def)); + int value; + try { + value = Integer.parseInt(stringValue); + } catch (NumberFormatException e) { + // It's OK to ignore "e" here because returning a default value is the documented behaviour on invalid input. + value = def; + } + return value; + } - public void setSelectedId(int id) { - if (id >= MIN_AVATAR_ID && id <= MAX_AVATAR_ID) { - for (JPanel panel : PANELS.values()) { - panel.setBorder(BLACK_BORDER); - } - PreferencesDialog.selectedAvatarId = id; - PANELS.get(PreferencesDialog.selectedAvatarId).setBorder(GREEN_BORDER); - } - } + public static String getCachedValue(String key, String def) { + if (CACHE.containsKey(key)) { + return CACHE.get(key); + } else { + Preferences prefs = MageFrame.getPreferences(); + String value = prefs.get(key, def); + if (value == null) { + return null; + } + CACHE.put(key, value); + return value; + } + } - private void addAvatar(JPanel jPanel, final int id, boolean selected, boolean locked) { - String path = "/avatars/" + String.valueOf(id) + ".jpg"; - PANELS.put(id, jPanel); - Image image = ImageHelper.getImageFromResources(path); + private static int getDefaultControlKey(String key) { + switch (key) { + case KEY_CONTROL_CONFIRM: + return KeyEvent.VK_F2; + case KEY_CONTROL_CANCEL_SKIP: + return KeyEvent.VK_F3; + case KEY_CONTROL_NEXT_TURN: + return KeyEvent.VK_F4; + case KEY_CONTROL_END_STEP: + return KeyEvent.VK_F5; + case KEY_CONTROL_SKIP_STEP: + return KeyEvent.VK_F6; + case KEY_CONTROL_MAIN_STEP: + return KeyEvent.VK_F7; + case KEY_CONTROL_YOUR_TURN: + return KeyEvent.VK_F9; + case KEY_CONTROL_SKIP_STACK: + return KeyEvent.VK_F10; + case KEY_CONTROL_PRIOR_END: + return KeyEvent.VK_F11; + default: + return 0; + } + } - Rectangle r = new Rectangle(jPanel.getWidth() - 5, jPanel.getHeight() - 5); - BufferedImage bufferedImage; - if (!locked) { - bufferedImage = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB); - } else { - bufferedImage = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB, new Color(150, 150, 150, 170)); - } - BufferedImage resized = ImageHelper.getResizedImage(bufferedImage, r); - final JLabel jLabel = new JLabel(); - jLabel.setIcon(new ImageIcon(resized)); - if (selected) { - jPanel.setBorder(GREEN_BORDER); - } else { - jPanel.setBorder(BLACK_BORDER); - } - jPanel.setLayout(new BorderLayout()); - jPanel.add(jLabel); - if (!locked) { - jLabel.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - if (selectedAvatarId != id) { - setSelectedId(id); - SessionHandler.updatePreferencesForServer(getUserData()); - } - } - }); - } - } + public static KeyStroke getCachedKeystroke(String key) { + int code = getCachedValue(key, getDefaultControlKey(key)); + return KeyStroke.getKeyStroke(code, 0); + } - public static UserData getUserData() { - if (selectedAvatarId == 0) { - getSelectedAvatar(); - } - return new UserData(UserGroup.PLAYER, - PreferencesDialog.selectedAvatarId, - PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_ABILITY_PICKER_FORCED, "true").equals("true"), - PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true").equals("true"), - PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_CONFIRM_EMPTY_MANA_POOL, "true").equals("true"), - getUserSkipPrioritySteps(), - MageFrame.getPreferences().get(KEY_CONNECT_FLAG, "world"), - PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_ASK_MOVE_TO_GRAVE_ORDER, "false").equals("true"), - PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), - PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), - PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PASS_PRIORITY_CAST, "true").equals("true"), - PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PASS_PRIORITY_ACTIVATION, "true").equals("true"), - PreferencesDialog.getCachedValue(PreferencesDialog.KEY_AUTO_ORDER_TRIGGER, "true").equals("true"), - PreferencesDialog.getCachedValue(PreferencesDialog.KEY_USE_FIRST_MANA_ABILITY, "false").equals("true") - ); - } + public static String getCachedKeyText(String key) { + int code = getCachedValue(key, getDefaultControlKey(key)); + return KeyEvent.getKeyText(code); + } + + private static void updateCache(String key, String value) { + CACHE.put(key, value); + } + + public static void saveValue(String key, String value) { + Preferences prefs = MageFrame.getPreferences(); + prefs.put(key, value); + try { + prefs.flush(); + } catch (BackingStoreException ex) { + ex.printStackTrace(); + JOptionPane.showMessageDialog(null, "Error: couldn't save preferences. Please try once again."); + } + updateCache(key, value); + } + + private void addAvatars() { + try { + addAvatar(jPanel10, 10, true, false); + addAvatar(jPanel11, 11, false, false); + addAvatar(jPanel12, 12, false, false); + addAvatar(jPanel13, 13, false, false); + addAvatar(jPanel14, 14, false, false); + addAvatar(jPanel15, 15, false, false); + addAvatar(jPanel16, 16, false, false); + addAvatar(jPanel17, 17, false, false); + addAvatar(jPanel18, 18, false, false); + addAvatar(jPanel19, 19, false, false); + addAvatar(jPanel20, 20, false, false); + addAvatar(jPanel21, 21, false, false); + addAvatar(jPanel22, 22, false, false); + addAvatar(jPanel23, 23, false, false); + addAvatar(jPanel24, 24, false, false); + addAvatar(jPanel25, 25, false, false); + addAvatar(jPanel26, 26, false, false); + addAvatar(jPanel27, 27, false, false); + addAvatar(jPanel28, 28, false, false); + addAvatar(jPanel29, 29, false, false); + addAvatar(jPanel30, 30, false, false); + addAvatar(jPanel31, 31, false, false); + addAvatar(jPanel32, 32, false, false); + + } catch (Exception e) { + logger.error(e, e); + } + } + + public void setSelectedId(int id) { + if (id >= MIN_AVATAR_ID && id <= MAX_AVATAR_ID) { + for (JPanel panel : PANELS.values()) { + panel.setBorder(BLACK_BORDER); + } + PreferencesDialog.selectedAvatarId = id; + PANELS.get(PreferencesDialog.selectedAvatarId).setBorder(GREEN_BORDER); + } + } + + private void addAvatar(JPanel jPanel, final int id, boolean selected, boolean locked) { + String path = "/avatars/" + String.valueOf(id) + ".jpg"; + PANELS.put(id, jPanel); + Image image = ImageHelper.getImageFromResources(path); + + Rectangle r = new Rectangle(jPanel.getWidth() - 5, jPanel.getHeight() - 5); + BufferedImage bufferedImage; + if (!locked) { + bufferedImage = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB); + } else { + bufferedImage = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB, new Color(150, 150, 150, 170)); + } + BufferedImage resized = ImageHelper.getResizedImage(bufferedImage, r); + final JLabel jLabel = new JLabel(); + jLabel.setIcon(new ImageIcon(resized)); + if (selected) { + jPanel.setBorder(GREEN_BORDER); + } else { + jPanel.setBorder(BLACK_BORDER); + } + jPanel.setLayout(new BorderLayout()); + jPanel.add(jLabel); + if (!locked) { + jLabel.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + if (selectedAvatarId != id) { + setSelectedId(id); + SessionHandler.updatePreferencesForServer(getUserData()); + } + } + }); + } + } + + public static UserData getUserData() { + if (selectedAvatarId == 0) { + getSelectedAvatar(); + } + return new UserData(UserGroup.PLAYER, + PreferencesDialog.selectedAvatarId, + PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_ABILITY_PICKER_FORCED, "true").equals("true"), + PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true").equals("true"), + PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_CONFIRM_EMPTY_MANA_POOL, "true").equals("true"), + getUserSkipPrioritySteps(), + MageFrame.getPreferences().get(KEY_CONNECT_FLAG, "world"), + PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_ASK_MOVE_TO_GRAVE_ORDER, "false").equals("true"), + PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), + PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), + PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PASS_PRIORITY_CAST, "true").equals("true"), + PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PASS_PRIORITY_ACTIVATION, "true").equals("true"), + PreferencesDialog.getCachedValue(PreferencesDialog.KEY_AUTO_ORDER_TRIGGER, "true").equals("true"), + PreferencesDialog.getCachedValue(PreferencesDialog.KEY_USE_FIRST_MANA_ABILITY, "false").equals("true") + ); + } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JScrollPane avatarPane; @@ -3518,6 +3741,7 @@ public class PreferencesDialog extends javax.swing.JDialog { private javax.swing.JCheckBox checkBoxUpkeepOthers; private javax.swing.JCheckBox checkBoxUpkeepYou; private javax.swing.JPanel connection_servers; + private javax.swing.JLabel controlsDescriptionLabel; private javax.swing.JButton exitButton; private javax.swing.JLabel fontSizeLabel; private javax.swing.JPanel guiSizeBasic; @@ -3562,25 +3786,43 @@ public class PreferencesDialog extends javax.swing.JDialog { private javax.swing.JPanel jPanel31; private javax.swing.JPanel jPanel32; private javax.swing.JPanel jPanel33; + private mage.client.components.KeyBindButton keyCancelSkip; + private mage.client.components.KeyBindButton keyConfirm; + private mage.client.components.KeyBindButton keyEndStep; + private mage.client.components.KeyBindButton keyMainStep; + private mage.client.components.KeyBindButton keyNextTurn; + private mage.client.components.KeyBindButton keyPriorEnd; + private mage.client.components.KeyBindButton keySkipStack; + private mage.client.components.KeyBindButton keySkipStep; + private mage.client.components.KeyBindButton keyYourTurn; + private javax.swing.JLabel labelCancel; private javax.swing.JLabel labelCardSizeHand; private javax.swing.JLabel labelCardSizeMaxBattlefield; private javax.swing.JLabel labelCardSizeMinBattlefield; private javax.swing.JLabel labelCardSizeOtherZones; + private javax.swing.JLabel labelConfirm; private javax.swing.JLabel labelDialogFont; private javax.swing.JLabel labelEditorCardOffset; private javax.swing.JLabel labelEditorCardSize; + private javax.swing.JLabel labelEndStep; private javax.swing.JLabel labelEnlargedImageSize; private javax.swing.JLabel labelGameFeedback; + private javax.swing.JLabel labelMainStep; + private javax.swing.JLabel labelNextTurn; private javax.swing.JLabel labelNumberOfDownloadThreads; private javax.swing.JLabel labelPreferedImageLanguage; + private javax.swing.JLabel labelPriorEnd; + private javax.swing.JLabel labelSkipStep; private javax.swing.JLabel labelStackWidth; private javax.swing.JLabel labelTooltipSize; + private javax.swing.JLabel labelYourTurn; private javax.swing.JLabel lblProxyPassword; private javax.swing.JLabel lblProxyPort; private javax.swing.JLabel lblProxyServer; private javax.swing.JLabel lblProxyType; private javax.swing.JLabel lblProxyUserName; private javax.swing.JLabel lblURLServerList; + private javax.swing.JLabel lebelSkip; private javax.swing.JPanel main_card; private javax.swing.JPanel main_game; private javax.swing.JPanel main_gamelog; @@ -3612,6 +3854,7 @@ public class PreferencesDialog extends javax.swing.JDialog { private javax.swing.JPanel sounds_clips; private javax.swing.JPanel tabAvatars; private javax.swing.JPanel tabConnection; + private javax.swing.JPanel tabControls; private javax.swing.JPanel tabGuiSize; private javax.swing.JPanel tabImages; private javax.swing.JPanel tabMain; @@ -3631,9 +3874,9 @@ public class PreferencesDialog extends javax.swing.JDialog { private javax.swing.JTextField txtURLServerList; // End of variables declaration//GEN-END:variables - private static final PreferencesDialog dialog = new PreferencesDialog(new javax.swing.JFrame(), true); + private static final PreferencesDialog dialog = new PreferencesDialog(new javax.swing.JFrame(), true); - static { - dialog.setResizable(false); - } + static { + dialog.setResizable(false); + } } diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java index 4508045ac9f..729ab26b029 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -90,6 +90,7 @@ import mage.client.cards.BigCard; import mage.client.chat.ChatPanelBasic; import mage.client.combat.CombatManager; import mage.client.components.HoverButton; +import mage.client.components.KeyboundButton; import mage.client.components.MageComponents; import mage.client.components.ext.dlg.DialogManager; import mage.client.components.layout.RelativeLayout; @@ -99,9 +100,7 @@ import mage.client.dialog.PickChoiceDialog; import mage.client.dialog.PickNumberDialog; import mage.client.dialog.PickPileDialog; import mage.client.dialog.PreferencesDialog; -import static mage.client.dialog.PreferencesDialog.KEY_GAME_MANA_AUTOPAYMENT; -import static mage.client.dialog.PreferencesDialog.KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE; -import static mage.client.dialog.PreferencesDialog.KEY_USE_FIRST_MANA_ABILITY; +import static mage.client.dialog.PreferencesDialog.*; import mage.client.dialog.ShowCardsDialog; import mage.client.game.FeedbackPanel.FeedbackMode; import mage.client.plugins.adapters.MageActionCallback; @@ -146,2353 +145,2360 @@ import org.mage.plugins.card.utils.impl.ImageManagerImpl; */ public final class GamePanel extends javax.swing.JPanel { - private static final Logger logger = Logger.getLogger(GamePanel.class); - private static final String YOUR_HAND = "Your hand"; - private static final int X_PHASE_WIDTH = 55; - private static final int STACK_MIN_CARDS_OFFSET_Y = 7; // TODO: Size bui GUISize value - - private static final String CMD_AUTO_ORDER_FIRST = "cmdAutoOrderFirst"; - private static final String CMD_AUTO_ORDER_LAST = "cmdAutoOrderLast"; - private static final String CMD_AUTO_ORDER_NAME_FIRST = "cmdAutoOrderNameFirst"; - private static final String CMD_AUTO_ORDER_NAME_LAST = "cmdAutoOrderNameLast"; - private static final String CMD_AUTO_ORDER_RESET_ALL = "cmdAutoOrderResetAll"; - - private final Map players = new HashMap<>(); - private final Map playersWhoLeft = new HashMap<>(); - - // non modal frames - private final Map exiles = new HashMap<>(); - private final Map revealed = new HashMap<>(); - private final Map lookedAt = new HashMap<>(); - private final Map graveyardWindows = new HashMap<>(); - private final Map graveyards = new HashMap<>(); - - private final ArrayList pickTarget = new ArrayList<>(); - private UUID gameId; - private UUID playerId; // playerId of the player - GamePane gamePane; - private ReplayTask replayTask; - private final PickNumberDialog pickNumber; - private JLayeredPane jLayeredPane; - private String chosenHandKey = "You"; - private boolean smallMode = false; - private boolean initialized = false; - - private boolean menuNameSet = false; - private boolean handCardsOfOpponentAvailable = false; - - private Map loadedCards = new HashMap<>(); - - private int storedHeight; - private Map hoverButtons; - - private MageDialogState choiceWindowState; - - private boolean initComponents; - - private Timer resizeTimer; - - private enum PopUpMenuType { - - TRIGGER_ORDER - } - // CardView popupMenu was invoked last - private CardView cardViewPopupMenu; - - // popup menu for triggered abilities order - private JPopupMenu popupMenuTriggerOrder; - - public GamePanel() { - initComponents = true; - initComponents(); - - pickNumber = new PickNumberDialog(); - MageFrame.getDesktop().add(pickNumber, JLayeredPane.MODAL_LAYER); - - this.feedbackPanel.setConnectedChatPanel(this.userChatPanel); - - this.stackObjects.setMinOffsetY(STACK_MIN_CARDS_OFFSET_Y); - - // Override layout (I can't edit generated code) - this.setLayout(new BorderLayout()); - final JLayeredPane jLayeredBackgroundPane = new JLayeredPane(); - jLayeredBackgroundPane.setSize(1024, 768); - this.add(jLayeredBackgroundPane); - jLayeredBackgroundPane.add(jSplitPane0, JLayeredPane.DEFAULT_LAYER); - - Map myUi = getUIComponents(jLayeredBackgroundPane); - Plugins.getInstance().updateGamePanel(myUi); - - // Enlarge jlayeredpane on resize of game panel - addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - int width = ((JComponent) e.getSource()).getWidth(); - int height = ((JComponent) e.getSource()).getHeight(); - jLayeredBackgroundPane.setSize(width, height); - jSplitPane0.setSize(width, height); - - if (height < storedHeight) { - pnlBattlefield.setSize(0, 200); - } - storedHeight = height; - - sizeToScreen(); - - if (!initialized) { - String state = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BIG_CARD_TOGGLED, null); - if (state != null && state.equals("down")) { - jSplitPane0.setDividerLocation(1.0); - } - initialized = true; - } - - } - }); - // Resize the width of the stack area if the size of the play area is changed - ComponentAdapter componentAdapterPlayField = new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - if (!initComponents) { - if (resizeTimer.isRunning()) { - resizeTimer.restart(); - } else { - resizeTimer.start(); - } - } - } - }; - - resizeTimer = new Timer(1000, new ActionListener() { - @Override - public void actionPerformed(ActionEvent evt) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - resizeTimer.stop(); - setGUISize(); - feedbackPanel.changeGUISize(); - - } - }); - } - }); - - pnlHelperHandButtonsStackArea.addComponentListener(componentAdapterPlayField); - initComponents = false; - } - - private Map getUIComponents(JLayeredPane jLayeredPane) { - Map components = new HashMap<>(); - - components.put("jSplitPane1", jSplitPane1); - components.put("pnlBattlefield", pnlBattlefield); - components.put("pnlHelperHandButtonsStackArea", pnlHelperHandButtonsStackArea); - components.put("hand", handContainer); - components.put("gameChatPanel", gameChatPanel); - components.put("userChatPanel", userChatPanel); - components.put("jLayeredPane", jLayeredPane); - components.put("gamePanel", this); - - return components; - } - - public void cleanUp() { - MageFrame.removeGame(gameId); - saveDividerLocations(); - this.gameChatPanel.disconnect(); - this.userChatPanel.disconnect(); - - this.removeListener(); - - this.handContainer.cleanUp(); - this.stackObjects.cleanUp(); - for (Map.Entry playAreaPanelEntry : players.entrySet()) { - playAreaPanelEntry.getValue().CleanUp(); - } - this.players.clear(); - this.playersWhoLeft.clear(); - - jLayeredPane.remove(abilityPicker); - this.abilityPicker.cleanUp(); - - jLayeredPane.remove(DialogManager.getManager(gameId)); - DialogManager.removeGame(gameId); - - if (pickNumber != null) { - pickNumber.removeDialog(); - } - for (CardInfoWindowDialog exileDialog : exiles.values()) { - exileDialog.cleanUp(); - exileDialog.removeDialog(); - } - for (CardInfoWindowDialog graveyardDialog : graveyardWindows.values()) { - graveyardDialog.cleanUp(); - graveyardDialog.removeDialog(); - } - for (CardInfoWindowDialog revealDialog : revealed.values()) { - revealDialog.cleanUp(); - revealDialog.removeDialog(); - } - for (CardInfoWindowDialog lookedAtDialog : lookedAt.values()) { - lookedAtDialog.cleanUp(); - lookedAtDialog.removeDialog(); - } - for (ShowCardsDialog pickTargetDialog : pickTarget) { - pickTargetDialog.cleanUp(); - pickTargetDialog.removeDialog(); - } - Plugins.getInstance().getActionCallback().hideTooltipPopup(); - try { - Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER); - popupContainer.setVisible(false); - } catch (InterruptedException ex) { - logger.fatal("popupContainer error:", ex); - } - jPanel2.remove(bigCard); - this.bigCard = null; - } - - public void changeGUISize() { - initComponents = true; - setGUISize(); - stackObjects.changeGUISize(); - feedbackPanel.changeGUISize(); - handContainer.changeGUISize(); - for (PlayAreaPanel playAreaPanel : players.values()) { - playAreaPanel.changeGUISize(); - } - - for (CardInfoWindowDialog cardInfoWindowDialog : exiles.values()) { - cardInfoWindowDialog.changeGUISize(); - } - for (CardInfoWindowDialog cardInfoWindowDialog : revealed.values()) { - cardInfoWindowDialog.changeGUISize(); - } - for (CardInfoWindowDialog cardInfoWindowDialog : lookedAt.values()) { - cardInfoWindowDialog.changeGUISize(); - } - for (CardInfoWindowDialog cardInfoWindowDialog : graveyardWindows.values()) { - cardInfoWindowDialog.changeGUISize(); - } - for (ShowCardsDialog showCardsDialog : pickTarget) { - showCardsDialog.changeGUISize(); - } - - this.revalidate(); - this.repaint(); - initComponents = false; - } - - private void setGUISize() { - jSplitPane0.setDividerSize(GUISizeHelper.dividerBarSize); - jSplitPane1.setDividerSize(GUISizeHelper.dividerBarSize); - jSplitPane2.setDividerSize(GUISizeHelper.dividerBarSize); - stackObjects.setCardDimension(GUISizeHelper.handCardDimension); - - txtSpellsCast.setFont(new Font(GUISizeHelper.gameDialogAreaFont.getFontName(), Font.BOLD, GUISizeHelper.gameDialogAreaFont.getSize())); - txtHoldPriority.setFont(new Font(GUISizeHelper.gameDialogAreaFont.getFontName(), Font.BOLD, GUISizeHelper.gameDialogAreaFont.getSize())); - GUISizeHelper.changePopupMenuFont(popupMenuTriggerOrder); - - int newStackWidth = pnlHelperHandButtonsStackArea.getWidth() * GUISizeHelper.stackWidth / 100; - if (newStackWidth < 410) { - newStackWidth = 410; - } - Dimension newDimension = new Dimension(pnlHelperHandButtonsStackArea.getWidth() - newStackWidth, GUISizeHelper.handCardDimension.height + GUISizeHelper.scrollBarSize); - handContainer.setPreferredSize(newDimension); - handContainer.setMaximumSize(newDimension); - - newDimension = new Dimension(newStackWidth, STACK_MIN_CARDS_OFFSET_Y + GUISizeHelper.handCardDimension.height + GUISizeHelper.scrollBarSize); - stackObjects.setPreferredSize(newDimension); - stackObjects.setMinimumSize(newDimension); - stackObjects.setMaximumSize(newDimension); - - newDimension = new Dimension(newStackWidth, (int) pnlShortCuts.getPreferredSize().getHeight()); - pnlShortCuts.setPreferredSize(newDimension); - pnlShortCuts.setMinimumSize(newDimension); - pnlShortCuts.setMaximumSize(newDimension); - } - - private void saveDividerLocations() { - // save panel sizes and divider locations. - Rectangle rec = MageFrame.getDesktop().getBounds(); - String sb = Double.toString(rec.getWidth()) + "x" + Double.toString(rec.getHeight()); - PreferencesDialog.saveValue(PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE, sb); - PreferencesDialog.saveValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_0, Integer.toString(this.jSplitPane0.getDividerLocation())); - PreferencesDialog.saveValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_1, Integer.toString(this.jSplitPane1.getDividerLocation())); - PreferencesDialog.saveValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_2, Integer.toString(this.jSplitPane2.getDividerLocation())); - } - - private void restoreDividerLocations() { - Rectangle rec = MageFrame.getDesktop().getBounds(); - if (rec != null) { - String size = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE, null); - String sb = Double.toString(rec.getWidth()) + "x" + Double.toString(rec.getHeight()); - // use divider positions only if screen size is the same as it was the time the settings were saved - if (size != null && size.equals(sb)) { - - String location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_0, null); - if (location != null && jSplitPane0 != null) { - jSplitPane0.setDividerLocation(Integer.parseInt(location)); - } - location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_1, null); - if (location != null && jSplitPane1 != null) { - jSplitPane1.setDividerLocation(Integer.parseInt(location)); - } - location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_2, null); - if (location != null && jSplitPane2 != null) { - jSplitPane2.setDividerLocation(Integer.parseInt(location)); - } - } - } - } - - private void sizeToScreen() { - Rectangle rect = this.getBounds(); - - if (rect.height < 720) { - if (!smallMode) { - smallMode = true; - Dimension bbDimension = new Dimension(128, 184); - bigCard.setMaximumSize(bbDimension); - bigCard.setMinimumSize(bbDimension); - bigCard.setPreferredSize(bbDimension); - pnlShortCuts.revalidate(); - pnlShortCuts.repaint(); - for (PlayAreaPanel p : players.values()) { - p.sizePlayer(smallMode); - } - } - } else if (smallMode) { - smallMode = false; - Dimension bbDimension = new Dimension(256, 367); - bigCard.setMaximumSize(bbDimension); - bigCard.setMinimumSize(bbDimension); - bigCard.setPreferredSize(bbDimension); - pnlShortCuts.revalidate(); - pnlShortCuts.repaint(); - for (PlayAreaPanel p : players.values()) { - p.sizePlayer(smallMode); - } - } - - ArrowBuilder.getBuilder().setSize(rect.width, rect.height); - - DialogManager.getManager(gameId).setScreenWidth(rect.width); - DialogManager.getManager(gameId).setScreenHeight(rect.height); - DialogManager.getManager(gameId).setBounds(0, 0, rect.width, rect.height); - } - - public synchronized void showGame(UUID gameId, UUID playerId, GamePane gamePane) { - this.gameId = gameId; - this.gamePane = gamePane; - this.playerId = playerId; - MageFrame.addGame(gameId, this); - this.feedbackPanel.init(gameId); - this.feedbackPanel.clear(); - this.abilityPicker.init(gameId); - - this.btnConcede.setVisible(true); - this.btnStopWatching.setVisible(false); - this.btnSwitchHands.setVisible(false); - this.btnCancelSkip.setVisible(true); - - this.btnSkipToNextTurn.setVisible(true); - this.btnSkipToEndTurn.setVisible(true); - this.btnSkipToNextMain.setVisible(true); - this.btnSkipStack.setVisible(true); - this.btnSkipToYourTurn.setVisible(true); - this.btnSkipToEndStepBeforeYourTurn.setVisible(true); - - this.pnlReplay.setVisible(false); - - this.gameChatPanel.clear(); - this.gameChatPanel.connect(SessionHandler.getGameChatId(gameId)); - if (!SessionHandler.joinGame(gameId)) { - removeGame(); - } else { - // play start sound - AudioManager.playYourGameStarted(); - } - } - - public synchronized void watchGame(UUID gameId, GamePane gamePane) { - this.gameId = gameId; - this.gamePane = gamePane; - this.playerId = null; - MageFrame.addGame(gameId, this); - this.feedbackPanel.init(gameId); - this.feedbackPanel.clear(); - - this.btnConcede.setVisible(false); - this.btnStopWatching.setVisible(true); - this.btnSwitchHands.setVisible(false); - this.chosenHandKey = ""; - this.btnCancelSkip.setVisible(false); - - this.btnSkipToNextTurn.setVisible(false); - this.btnSkipToEndTurn.setVisible(false); - this.btnSkipToNextMain.setVisible(false); - this.btnSkipStack.setVisible(false); - this.btnSkipToYourTurn.setVisible(false); - this.btnSkipToEndStepBeforeYourTurn.setVisible(false); - - this.pnlReplay.setVisible(false); - this.gameChatPanel.clear(); - this.gameChatPanel.connect(SessionHandler.getGameChatId(gameId)); - if (!SessionHandler.watchGame(gameId)) { - removeGame(); - } - for (PlayAreaPanel panel : getPlayers().values()) { - panel.setPlayingMode(false); - } - } - - public synchronized void replayGame(UUID gameId) { - this.gameId = gameId; - this.playerId = null; - MageFrame.addGame(gameId, this); - this.feedbackPanel.init(gameId); - this.feedbackPanel.clear(); - this.btnConcede.setVisible(false); - this.btnSkipToNextTurn.setVisible(false); - this.btnSwitchHands.setVisible(false); - this.btnStopWatching.setVisible(false); - this.pnlReplay.setVisible(true); - this.gameChatPanel.clear(); - if (!SessionHandler.startReplay(gameId)) { - removeGame(); - } - for (PlayAreaPanel panel : getPlayers().values()) { - panel.setPlayingMode(false); - } - } - - /** - * Closes the game and it's resources - */ - public void removeGame() { - Component c = this.getParent(); - while (c != null && !(c instanceof GamePane)) { - c = c.getParent(); - } - if (c != null) { - ((GamePane) c).removeGame(); - } - } - - public synchronized void init(GameView game) { - addPlayers(game); - // default menu states - setMenuStates( - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), - holdingPriority - ); - - updateGame(game); - } - - private void addPlayers(GameView game) { - this.players.clear(); - this.playersWhoLeft.clear(); - this.pnlBattlefield.removeAll(); - //arrange players in a circle with the session player at the bottom left - int numSeats = game.getPlayers().size(); - int numColumns = (numSeats + 1) / 2; - boolean oddNumber = (numColumns > 1 && numSeats % 2 == 1); - int col = 0; - int row = 1; - int playerSeat = 0; - if (playerId != null) { - for (PlayerView player : game.getPlayers()) { - if (playerId.equals(player.getPlayerId())) { - break; - } - playerSeat++; - } - } - PlayerView player = game.getPlayers().get(playerSeat); - PlayAreaPanel playAreaPanel = new PlayAreaPanel(player, bigCard, gameId, game.getPriorityTime(), this, - new PlayAreaPanelOptions(game.isPlayer(), game.isPlayer(), game.isRollbackTurnsAllowed(), row == 0)); - players.put(player.getPlayerId(), playAreaPanel); - playersWhoLeft.put(player.getPlayerId(), false); - GridBagConstraints c = new GridBagConstraints(); - c.fill = GridBagConstraints.BOTH; - c.weightx = 0.5; - c.weighty = 0.5; - if (oddNumber) { - c.gridwidth = 2; - } - c.gridx = col; - c.gridy = 0; - - // Top panel (row=0) - JPanel topPanel = new JPanel(); - topPanel.setOpaque(false); - - // Bottom panel (row=1) - JPanel bottomPanel = new JPanel(); - bottomPanel.setOpaque(false); - topPanel.setLayout(new GridBagLayout()); - bottomPanel.setLayout(new GridBagLayout()); - - bottomPanel.add(playAreaPanel, c); - playAreaPanel.setVisible(true); - if (oddNumber) { - col++; - } - int playerNum = playerSeat + 1; - if (playerNum >= numSeats) { - playerNum = 0; - } - while (true) { - if (row == 1) { - col++; - } else { - col--; - } - if (col >= numColumns) { - row = 0; - col = numColumns - 1; - } - player = game.getPlayers().get(playerNum); - PlayAreaPanel playerPanel = new PlayAreaPanel(player, bigCard, gameId, game.getPriorityTime(), this, - new PlayAreaPanelOptions(game.isPlayer(), false, game.isRollbackTurnsAllowed(), row == 0)); - players.put(player.getPlayerId(), playerPanel); - playersWhoLeft.put(player.getPlayerId(), false); - c = new GridBagConstraints(); - c.fill = GridBagConstraints.BOTH; - c.weightx = 0.5; - c.weighty = 0.5; - c.gridx = col; - c.gridy = 0; - - if (row == 0) { - topPanel.add(playerPanel, c); - } else { - bottomPanel.add(playerPanel, c); - } - - playerPanel.setVisible(true); - playerNum++; - if (playerNum >= numSeats) { - playerNum = 0; - } - if (playerNum == playerSeat) { - break; - } - } - for (PlayAreaPanel p : players.values()) { - p.sizePlayer(smallMode); - } - - GridBagConstraints panelC = new GridBagConstraints(); - panelC.fill = GridBagConstraints.BOTH; - panelC.weightx = 0.5; - panelC.weighty = 0.5; - panelC.gridwidth = 1; - panelC.gridy = 0; - this.pnlBattlefield.add(topPanel, panelC); - panelC.gridy = 1; - this.pnlBattlefield.add(bottomPanel, panelC); - } - - public synchronized void updateGame(GameView game) { - updateGame(game, null); - } - - public synchronized void updateGame(GameView game, Map options) { - if (playerId == null && game.getWatchedHands() == null) { - this.handContainer.setVisible(false); - } else { - this.handContainer.setVisible(true); - handCards.clear(); - if (game.getWatchedHands() != null) { - for (Map.Entry hand : game.getWatchedHands().entrySet()) { - handCards.put(hand.getKey(), CardsViewUtil.convertSimple(hand.getValue(), loadedCards)); - } - } - if (playerId != null) { - handCards.put(YOUR_HAND, game.getHand()); - // Mark playable - if (game.getCanPlayInHand() != null) { - for (CardView card : handCards.get(YOUR_HAND).values()) { - if (game.getCanPlayInHand().contains(card.getId())) { - card.setPlayable(true); - } - } - } - // Get opponents hand cards if available (only possible for players) - if (game.getOpponentHands() != null) { - for (Map.Entry hand : game.getOpponentHands().entrySet()) { - handCards.put(hand.getKey(), CardsViewUtil.convertSimple(hand.getValue(), loadedCards)); - } - } - if (!handCards.containsKey(chosenHandKey)) { - chosenHandKey = YOUR_HAND; - } - } else if (chosenHandKey.isEmpty() && handCards.size() > 0) { - chosenHandKey = handCards.keySet().iterator().next(); - } - if (chosenHandKey != null && handCards.containsKey(chosenHandKey)) { - handContainer.loadCards(handCards.get(chosenHandKey), bigCard, gameId); - } - - hideAll(); - - if (playerId != null) { - // set visible only if we have any other hand visible than ours - btnSwitchHands.setVisible(handCards.size() > 1); - boolean change = (handCardsOfOpponentAvailable != (game.getOpponentHands() != null)); - if (change) { - handCardsOfOpponentAvailable = !handCardsOfOpponentAvailable; - if (handCardsOfOpponentAvailable) { - JOptionPane.showMessageDialog(null, "You control other player's turn. \nUse \"Switch Hand\" button to switch between cards in different hands."); - } else { - JOptionPane.showMessageDialog(null, "You lost control on other player's turn."); - } - } - } else { - btnSwitchHands.setVisible(!handCards.isEmpty()); - } - } - - if (game.getPhase() != null) { - this.txtPhase.setText(game.getPhase().toString()); - } else { - this.txtPhase.setText(""); - } - - if (game.getStep() != null) { - updatePhases(game.getStep()); - this.txtStep.setText(game.getStep().toString()); - } else { - logger.debug("Step is empty"); - this.txtStep.setText(""); - } - if (game.getSpellsCastCurrentTurn() > 0 && PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_SHOW_STORM_COUNTER, "true").equals("true")) { - this.txtSpellsCast.setVisible(true); - this.txtSpellsCast.setText(" " + Integer.toString(game.getSpellsCastCurrentTurn()) + " "); - } else { - this.txtSpellsCast.setVisible(false); - } - - this.txtActivePlayer.setText(game.getActivePlayerName()); - this.txtPriority.setText(game.getPriorityPlayerName()); - this.txtTurn.setText(Integer.toString(game.getTurn())); - - List possibleAttackers = new ArrayList<>(); - if (options != null && options.containsKey(Constants.Option.POSSIBLE_ATTACKERS)) { - if (options.get(Constants.Option.POSSIBLE_ATTACKERS) instanceof List) { - possibleAttackers.addAll((List) options.get(Constants.Option.POSSIBLE_ATTACKERS)); - } - } - - for (PlayerView player : game.getPlayers()) { - if (players.containsKey(player.getPlayerId())) { - if (!possibleAttackers.isEmpty()) { - for (UUID permanentId : possibleAttackers) { - if (player.getBattlefield().containsKey(permanentId)) { - player.getBattlefield().get(permanentId).setCanAttack(true); - } - } - } - players.get(player.getPlayerId()).update(player); - if (player.getPlayerId().equals(playerId)) { - updateSkipButtons(player.isPassedTurn(), player.isPassedUntilEndOfTurn(), player.isPassedUntilNextMain(), player.isPassedAllTurns(), player.isPassedUntilStackResolved(), - player.isPassedUntilEndStepBeforeMyTurn()); - } - // update open or remove closed graveyard windows - graveyards.put(player.getName(), player.getGraveyard()); - if (graveyardWindows.containsKey(player.getName())) { - CardInfoWindowDialog cardInfoWindowDialog = graveyardWindows.get(player.getName()); - if (cardInfoWindowDialog.isClosed()) { - graveyardWindows.remove(player.getName()); - } else { - cardInfoWindowDialog.loadCards(player.getGraveyard(), bigCard, gameId, false); - } - } - // show top card window - if (player.getTopCard() != null) { - CardsView cardsView = new CardsView(); - cardsView.put(player.getTopCard().getId(), player.getTopCard()); - handleGameInfoWindow(revealed, ShowType.REVEAL_TOP_LIBRARY, player.getName() + "'s top library card", cardsView); - } - } else { - logger.warn("Couldn't find player."); - logger.warn(" uuid:" + player.getPlayerId()); - logger.warn(" players:"); - for (PlayAreaPanel p : players.values()) { - logger.warn("" + p); - } - } - } - if (!menuNameSet) { - StringBuilder sb = new StringBuilder(); - if (playerId == null) { - sb.append("Watching: "); - } else { - sb.append("Playing: "); - } - boolean first = true; - for (PlayerView player : game.getPlayers()) { - if (first) { - first = false; - } else { - sb.append(" - "); - } - sb.append(player.getName()); - } - menuNameSet = true; - gamePane.setTitle(sb.toString()); - } - - GameManager.getInstance().setStackSize(game.getStack().size()); - displayStack(game, bigCard, feedbackPanel, gameId); - - for (ExileView exile : game.getExile()) { - if (!exiles.containsKey(exile.getId())) { - CardInfoWindowDialog newExile = new CardInfoWindowDialog(ShowType.EXILE, exile.getName()); - exiles.put(exile.getId(), newExile); - MageFrame.getDesktop().add(newExile, JLayeredPane.MODAL_LAYER); - newExile.show(); - } - exiles.get(exile.getId()).loadCards(exile, bigCard, gameId); - } - - showRevealed(game); - showLookedAt(game); - if (game.getCombat().size() > 0) { - CombatManager.getInstance().showCombat(game.getCombat(), gameId); - } else { - CombatManager.getInstance().hideCombat(gameId); - } - - for (PlayerView player : game.getPlayers()) { - if (player.hasLeft() && !playersWhoLeft.get(player.getPlayerId())) { - PlayAreaPanel playerLeftPanel = players.get(player.getPlayerId()); - playersWhoLeft.put(player.getPlayerId(), true); - - Container parent = playerLeftPanel.getParent(); - GridBagLayout layout = (GridBagLayout) parent.getLayout(); - - for (Component otherPanel : parent.getComponents()) { - - if (otherPanel instanceof PlayAreaPanel) { - GridBagConstraints gbc = layout.getConstraints(otherPanel); - if (gbc.weightx > 0.1) { - gbc.weightx = 0.99; - } - gbc.fill = GridBagConstraints.BOTH; - gbc.anchor = GridBagConstraints.WEST; - if (gbc.gridx > 0) { - gbc.anchor = GridBagConstraints.EAST; - } - if (otherPanel == playerLeftPanel) { - gbc.weightx = 0.01; - Dimension d = playerLeftPanel.getPreferredSize(); - d.width = 95; - otherPanel.setPreferredSize(d); - } - parent.remove(otherPanel); - parent.add(otherPanel, gbc); - } - } - - parent.validate(); - parent.repaint(); - } - } - - feedbackPanel.disableUndo(); - - this.revalidate(); - this.repaint(); - } - - static final int BORDER_SIZE = 2; - - private void updateSkipButtons(boolean turn, boolean endOfTurn, boolean nextMain, boolean allTurns, boolean stack, boolean endStepBeforeYourStep) { - if (turn) { //F4 - btnSkipToNextTurn.setBorder(new LineBorder(Color.orange, BORDER_SIZE)); - } else { - btnSkipToNextTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - } - if (endOfTurn) { // F5 - btnSkipToEndTurn.setBorder(new LineBorder(Color.orange, BORDER_SIZE)); - } else { - btnSkipToEndTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - } - if (nextMain) { // F7 - btnSkipToNextMain.setBorder(new LineBorder(Color.orange, BORDER_SIZE)); - } else { - btnSkipToNextMain.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - } - if (stack) { // F8 - btnSkipStack.setBorder(new LineBorder(Color.orange, BORDER_SIZE)); - } else { - btnSkipStack.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - } - if (allTurns) { // F9 - btnSkipToYourTurn.setBorder(new LineBorder(Color.orange, BORDER_SIZE)); - } else { - btnSkipToYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - } - - if (endStepBeforeYourStep) { // F11 - btnSkipToEndStepBeforeYourTurn.setBorder(new LineBorder(Color.orange, BORDER_SIZE)); - } else { - btnSkipToEndStepBeforeYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - } - - } - - /** - * Set the same state for menu selections to all player areas. - * - * @param manaPoolAutomatic - * @param manaPoolAutomaticRestricted - * @param useFirstManaAbility - */ - public void setMenuStates(boolean manaPoolAutomatic, boolean manaPoolAutomaticRestricted, boolean useFirstManaAbility, boolean holdPriority) { - for (PlayAreaPanel playAreaPanel : players.values()) { - playAreaPanel.setMenuStates(manaPoolAutomatic, manaPoolAutomaticRestricted, useFirstManaAbility, holdPriority); - } - } - - private void displayStack(GameView game, BigCard bigCard, FeedbackPanel feedbackPanel, UUID gameId) { - this.stackObjects.loadCards(game.getStack(), bigCard, gameId, true); - } - - /** - * Update phase buttons\labels. - */ - private void updatePhases(PhaseStep step) { - if (step == null) { - logger.warn("step is null"); - return; - } - if (currentStep != null) { - currentStep.setLocation(prevPoint); - } - switch (step) { - case UNTAP: - updateButton("Untap"); - break; - case UPKEEP: - updateButton("Upkeep"); - break; - case DRAW: - updateButton("Draw"); - break; - case PRECOMBAT_MAIN: - updateButton("Main1"); - break; - case BEGIN_COMBAT: - updateButton("Combat_Start"); - break; - case DECLARE_ATTACKERS: - updateButton("Combat_Attack"); - break; - case DECLARE_BLOCKERS: - updateButton("Combat_Block"); - break; - case FIRST_COMBAT_DAMAGE: - case COMBAT_DAMAGE: - updateButton("Combat_Damage"); - break; - case END_COMBAT: - updateButton("Combat_End"); - break; - case POSTCOMBAT_MAIN: - updateButton("Main2"); - break; - case END_TURN: - updateButton("Cleanup"); - break; - } - } - - private void updateButton(String name) { - if (hoverButtons.containsKey(name)) { - currentStep = hoverButtons.get(name); - prevPoint = currentStep.getLocation(); - currentStep.setLocation(prevPoint.x - 15, prevPoint.y); - } - } - - // Called if the game frame is deactivated because the tabled the deck editor or other frames go to foreground - public void deactivated() { - // hide the non modal windows (because otherwise they are shown on top of the new active pane) - for (CardInfoWindowDialog exileDialog : exiles.values()) { - exileDialog.hideDialog(); - } - for (CardInfoWindowDialog graveyardDialog : graveyardWindows.values()) { - graveyardDialog.hideDialog(); - } - for (CardInfoWindowDialog revealDialog : revealed.values()) { - revealDialog.hideDialog(); - } - for (CardInfoWindowDialog lookedAtDialog : lookedAt.values()) { - lookedAtDialog.hideDialog(); - } - } - - // Called if the game frame comes to front again - public void activated() { - // hide the non modal windows (because otherwise they are shown on top of the new active pane) - for (CardInfoWindowDialog exileDialog : exiles.values()) { - exileDialog.show(); - } - for (CardInfoWindowDialog graveyardDialog : graveyardWindows.values()) { - graveyardDialog.show(); - } - for (CardInfoWindowDialog revealDialog : revealed.values()) { - revealDialog.show(); - } - for (CardInfoWindowDialog lookedAtDialog : lookedAt.values()) { - lookedAtDialog.show(); - } - } - - public void openGraveyardWindow(String playerName) { - if (graveyardWindows.containsKey(playerName)) { - CardInfoWindowDialog cardInfoWindowDialog = graveyardWindows.get(playerName); - if (cardInfoWindowDialog.isVisible()) { - cardInfoWindowDialog.hideDialog(); - } else { - cardInfoWindowDialog.show(); - } - return; - } - CardInfoWindowDialog newGraveyard = new CardInfoWindowDialog(ShowType.GRAVEYARD, playerName); - graveyardWindows.put(playerName, newGraveyard); - MageFrame.getDesktop().add(newGraveyard, JLayeredPane.MODAL_LAYER); - newGraveyard.loadCards(graveyards.get(playerName), bigCard, gameId, false); - } - - public void openTopLibraryWindow(String playerName) { - String title = playerName + "'s top library card"; - if (revealed.containsKey(title)) { - CardInfoWindowDialog cardInfoWindowDialog = revealed.get(title); - if (cardInfoWindowDialog.isVisible()) { - cardInfoWindowDialog.hideDialog(); - } else { - cardInfoWindowDialog.show(); - } - } - } - - private void showRevealed(GameView game) { - for (RevealedView revealView : game.getRevealed()) { - handleGameInfoWindow(revealed, ShowType.REVEAL, revealView.getName(), revealView.getCards()); - } - removeClosedCardInfoWindows(revealed); - } - - private void showLookedAt(GameView game) { - for (LookedAtView lookedAtView : game.getLookedAt()) { - handleGameInfoWindow(lookedAt, ShowType.LOOKED_AT, lookedAtView.getName(), lookedAtView.getCards()); - } - removeClosedCardInfoWindows(lookedAt); - } - - private void handleGameInfoWindow(Map windowMap, ShowType showType, String name, LinkedHashMap cardsView) { - CardInfoWindowDialog cardInfoWindowDialog; - if (!windowMap.containsKey(name)) { - cardInfoWindowDialog = new CardInfoWindowDialog(showType, name); - windowMap.put(name, cardInfoWindowDialog); - MageFrame.getDesktop().add(cardInfoWindowDialog, JLayeredPane.MODAL_LAYER); - } else { - cardInfoWindowDialog = windowMap.get(name); - } - - if (cardInfoWindowDialog != null && !cardInfoWindowDialog.isClosed()) { - switch (showType) { - case REVEAL: - case REVEAL_TOP_LIBRARY: - cardInfoWindowDialog.loadCards((CardsView) cardsView, bigCard, gameId); - break; - case LOOKED_AT: - cardInfoWindowDialog.loadCards((SimpleCardsView) cardsView, bigCard, gameId); - break; - } - } - } - - private void removeClosedCardInfoWindows(Map windowMap) { - // Remove closed window objects from the maps - for (Iterator> iterator = windowMap.entrySet().iterator(); iterator.hasNext();) { - Map.Entry entry = iterator.next(); - if (entry.getValue().isClosed()) { - iterator.remove(); - } - } - } - - public void ask(String question, GameView gameView, int messageId, Map options) { - updateGame(gameView); - this.feedbackPanel.getFeedback(FeedbackMode.QUESTION, question, false, options, messageId); - } - - /** - * Shows a pick target dialog and allows the player to pick a target (e.g. - * the pick triggered ability) - * - * @param message - * @param cardView - * @param gameView - * @param targets - * @param required - * @param options - * @param messageId - */ - public void pickTarget(String message, CardsView cardView, GameView gameView, Set targets, boolean required, Map options, int messageId) { - PopUpMenuType popupMenuType = null; - if (options != null) { - if (options.containsKey("targetZone")) { - if (Zone.HAND.equals(options.get("targetZone"))) { // mark selectable target cards in hand - List choosen = null; - if (options.containsKey("chosen")) { - choosen = (List) options.get("chosen"); - } - for (CardView card : gameView.getHand().values()) { - if (targets == null || targets.isEmpty()) { - card.setPlayable(false); - card.setChoosable(true); - } else if (targets.contains(card.getId())) { - card.setPlayable(false); - card.setChoosable(true); - } - if (choosen != null && choosen.contains(card.getId())) { - card.setSelected(true); - } - } - } - } - if (options.containsKey("queryType") && PlayerQueryEvent.QueryType.PICK_ABILITY.equals(options.get("queryType"))) { - popupMenuType = PopUpMenuType.TRIGGER_ORDER; - } - } - updateGame(gameView); - Map options0 = options == null ? new HashMap<>() : options; - ShowCardsDialog dialog = null; - if (cardView != null && cardView.size() > 0) { - dialog = showCards(message, cardView, required, options0, popupMenuType); - options0.put("dialog", dialog); - } - this.feedbackPanel.getFeedback(required ? FeedbackMode.INFORM : FeedbackMode.CANCEL, message, gameView.getSpecial(), options0, messageId); - if (dialog != null) { - this.pickTarget.add(dialog); - } - } - - public void inform(String information, GameView gameView, int messageId) { - updateGame(gameView); - this.feedbackPanel.getFeedback(FeedbackMode.INFORM, information, gameView.getSpecial(), null, messageId); - } - - public void endMessage(String message, int messageId) { - this.feedbackPanel.getFeedback(FeedbackMode.END, message, false, null, messageId); - ArrowBuilder.getBuilder().removeAllArrows(gameId); - } - - public void select(String message, GameView gameView, int messageId, Map options) { - holdingPriority = false; - txtHoldPriority.setVisible(false); - setMenuStates( - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), - false); - - updateGame(gameView, options); - boolean controllingPlayer = false; - for (PlayerView playerView : gameView.getPlayers()) { - if (playerView.getPlayerId().equals(playerId)) { - // magenoxx: because of uncaught bug with saving state, rolling back and stack - // undo is allowed only for empty stack - controllingPlayer = !gameView.getPriorityPlayerName().equals(playerView.getName()); - if (playerView.getStatesSavedSize() > 0 && gameView.getStack().isEmpty()) { - feedbackPanel.allowUndo(playerView.getStatesSavedSize()); - } - break; - } - - } - Map panelOptions = new HashMap<>(); - if (options != null) { - panelOptions.putAll(options); - } - panelOptions.put("your_turn", true); - String activePlayerText; - if (gameView.getActivePlayerId().equals(playerId)) { - activePlayerText = "Your turn"; - } else { - activePlayerText = gameView.getActivePlayerName() + "'s turn"; - } - String priorityPlayerText = ""; - if (controllingPlayer) { - priorityPlayerText = " / priority " + gameView.getPriorityPlayerName(); - } - String messageToDisplay = message + FeedbackPanel.getSmallText(activePlayerText + " / " + gameView.getStep().toString() + priorityPlayerText); - this.feedbackPanel.getFeedback(FeedbackMode.SELECT, messageToDisplay, gameView.getSpecial(), panelOptions, messageId); - } - - public void playMana(String message, GameView gameView, Map options, int messageId) { - updateGame(gameView); - DialogManager.getManager(gameId).fadeOut(); - this.feedbackPanel.getFeedback(FeedbackMode.CANCEL, message, gameView.getSpecial(), options, messageId); - } - - public void playXMana(String message, GameView gameView, int messageId) { - updateGame(gameView); - DialogManager.getManager(gameId).fadeOut(); - this.feedbackPanel.getFeedback(FeedbackMode.CONFIRM, message, gameView.getSpecial(), null, messageId); - } - - public void replayMessage(String message) { - //TODO: implement this - } - - public void pickAbility(AbilityPickerView choices) { - hideAll(); - DialogManager.getManager(gameId).fadeOut(); - this.abilityPicker.show(choices, MageFrame.getDesktop().getMousePosition()); - } - - private void hideAll() { - ActionCallback callback = Plugins.getInstance().getActionCallback(); - ((MageActionCallback) callback).hideGameUpdate(gameId); - } - - private ShowCardsDialog showCards(String title, CardsView cards, boolean required, Map options, PopUpMenuType popupMenuType) { - hideAll(); - ShowCardsDialog showCards = new ShowCardsDialog(); - JPopupMenu popupMenu = null; - if (PopUpMenuType.TRIGGER_ORDER.equals(popupMenuType)) { - popupMenu = popupMenuTriggerOrder; - } - showCards.loadCards(title, cards, bigCard, gameId, required, options, popupMenu, getShowCardsEventListener(showCards)); - return showCards; - } - - public void getAmount(int min, int max, String message) { - pickNumber.showDialog(min, max, message); - if (pickNumber.isCancel()) { - SessionHandler.sendPlayerBoolean(gameId, false); - } else { - SessionHandler.sendPlayerInteger(gameId, pickNumber.getAmount()); - } - } - - public void getChoice(Choice choice, UUID objectId) { - hideAll(); - PickChoiceDialog pickChoice = new PickChoiceDialog(); - pickChoice.showDialog(choice, objectId, choiceWindowState); - if (choice.isKeyChoice()) { - if (pickChoice.isAutoSelect()) { - SessionHandler.sendPlayerString(gameId, "#" + choice.getChoiceKey()); - } else { - SessionHandler.sendPlayerString(gameId, choice.getChoiceKey()); - } - } else { - SessionHandler.sendPlayerString(gameId, choice.getChoice()); - } - choiceWindowState = new MageDialogState(pickChoice); - pickChoice.removeDialog(); - } - - public void pickPile(String message, CardsView pile1, CardsView pile2) { - hideAll(); - PickPileDialog pickPileDialog = new PickPileDialog(); - pickPileDialog.loadCards(message, pile1, pile2, bigCard, gameId); - SessionHandler.sendPlayerBoolean(gameId, pickPileDialog.isPickedPile1()); - pickPileDialog.cleanUp(); - pickPileDialog.removeDialog(); - } - - public Map getPlayers() { - return players; - } - - @SuppressWarnings("unchecked") - private void initComponents() { - - abilityPicker = new mage.client.components.ability.AbilityPicker(); - jSplitPane1 = new javax.swing.JSplitPane(); - jSplitPane0 = new javax.swing.JSplitPane(); - jPanel2 = new javax.swing.JPanel(); - pnlHelperHandButtonsStackArea = new javax.swing.JPanel(); - pnlShortCuts = new javax.swing.JPanel(); - lblPhase = new javax.swing.JLabel(); - txtPhase = new javax.swing.JLabel(); - lblStep = new javax.swing.JLabel(); - txtStep = new javax.swing.JLabel(); - lblTurn = new javax.swing.JLabel(); - txtTurn = new javax.swing.JLabel(); - txtActivePlayer = new javax.swing.JLabel(); - lblActivePlayer = new javax.swing.JLabel(); - txtPriority = new javax.swing.JLabel(); - lblPriority = new javax.swing.JLabel(); - feedbackPanel = new mage.client.game.FeedbackPanel(); - - txtSpellsCast = new javax.swing.JLabel(); - Border paddingBorder = BorderFactory.createEmptyBorder(4, 4, 4, 4); - Border border = BorderFactory.createLineBorder(Color.DARK_GRAY, 2); - txtSpellsCast.setBorder(BorderFactory.createCompoundBorder(border, paddingBorder)); - txtSpellsCast.setBackground(Color.LIGHT_GRAY); - txtSpellsCast.setOpaque(true); - txtSpellsCast.setToolTipText("spells cast during the current turn"); - - txtHoldPriority = new javax.swing.JLabel(); - txtHoldPriority.setText("Hold"); - txtHoldPriority.setBorder(BorderFactory.createCompoundBorder(border, paddingBorder)); - txtHoldPriority.setBackground(Color.LIGHT_GRAY); - txtHoldPriority.setOpaque(true); - txtHoldPriority.setToolTipText("Holding priority after the next spell cast or ability activation"); - txtHoldPriority.setVisible(false); - - btnCancelSkip = new javax.swing.JButton(); // F3 - btnSkipToNextTurn = new javax.swing.JButton(); // F4 - btnSkipToEndTurn = new javax.swing.JButton(); // F5 - btnSkipToNextMain = new javax.swing.JButton(); // F7 - btnSkipStack = new javax.swing.JButton(); // F8 - btnSkipToYourTurn = new javax.swing.JButton(); // F9 - btnSkipToEndStepBeforeYourTurn = new javax.swing.JButton(); // F11 - - btnConcede = new javax.swing.JButton(); - btnSwitchHands = new javax.swing.JButton(); - btnStopWatching = new javax.swing.JButton(); - - bigCard = new mage.client.cards.BigCard(); - pnlReplay = new javax.swing.JPanel(); - btnStopReplay = new javax.swing.JButton(); - btnNextPlay = new javax.swing.JButton(); - btnPlay = new javax.swing.JButton(); - btnSkipForward = new javax.swing.JButton(); - btnPreviousPlay = new javax.swing.JButton(); - pnlBattlefield = new javax.swing.JPanel(); - gameChatPanel = new mage.client.chat.ChatPanelBasic(); - gameChatPanel.useExtendedView(ChatPanelBasic.VIEW_MODE.GAME); - userChatPanel = new mage.client.chat.ChatPanelBasic(); - userChatPanel.setParentChat(gameChatPanel); - userChatPanel.useExtendedView(ChatPanelBasic.VIEW_MODE.CHAT); - userChatPanel.setChatType(ChatPanelBasic.ChatType.GAME); - gameChatPanel.setConnectedChat(userChatPanel); - gameChatPanel.disableInput(); - gameChatPanel.setMinimumSize(new java.awt.Dimension(100, 48)); - gameChatPanel.enableHyperlinks(); - jSplitPane2 = new javax.swing.JSplitPane(); - handContainer = new HandPanel(); - handCards = new HashMap<>(); - - pnlShortCuts.setOpaque(false); - pnlShortCuts.setPreferredSize(new Dimension(410, 72)); - - stackObjects = new mage.client.cards.Cards(); - - jSplitPane1.setBorder(null); - jSplitPane1.setDividerSize(7); - jSplitPane1.setResizeWeight(1.0); - jSplitPane1.setOneTouchExpandable(true); - jSplitPane1.setMinimumSize(new java.awt.Dimension(26, 48)); - - jSplitPane0.setBorder(null); - jSplitPane0.setDividerSize(7); - jSplitPane0.setResizeWeight(1.0); - jSplitPane0.setOneTouchExpandable(true); - - restoreDividerLocations(); - - lblPhase.setLabelFor(txtPhase); - lblPhase.setText("Phase:"); - - txtPhase.setText("Phase"); - txtPhase.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true)); - txtPhase.setMinimumSize(new java.awt.Dimension(0, 16)); - - lblStep.setLabelFor(txtStep); - lblStep.setText("Step:"); - - txtStep.setText("Step"); - txtStep.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true)); - txtStep.setMinimumSize(new java.awt.Dimension(0, 16)); - - lblTurn.setLabelFor(txtTurn); - lblTurn.setText("Turn:"); - - txtTurn.setText("Turn"); - txtTurn.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true)); - txtTurn.setMinimumSize(new java.awt.Dimension(0, 16)); - - txtActivePlayer.setText("Active Player"); - txtActivePlayer.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true)); - txtActivePlayer.setMinimumSize(new java.awt.Dimension(0, 16)); - - lblActivePlayer.setLabelFor(txtActivePlayer); - lblActivePlayer.setText("Active Player:"); - - txtPriority.setText("Priority Player"); - txtPriority.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true)); - txtPriority.setMinimumSize(new java.awt.Dimension(0, 16)); - - lblPriority.setLabelFor(txtPriority); - lblPriority.setText("Priority Player:"); - - bigCard.setBorder(new LineBorder(Color.black, 1, true)); - - int c = JComponent.WHEN_IN_FOCUSED_WINDOW; - - KeyStroke ks3 = KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0); - this.getInputMap(c).put(ks3, "F3_PRESS"); - this.getActionMap().put("F3_PRESS", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - restorePriorityActionPerformed(actionEvent); - } - }); - - btnCancelSkip.setContentAreaFilled(false); - btnCancelSkip.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnCancelSkip.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getCancelSkipButtonImage())); - btnCancelSkip.setToolTipText("Cancel all skip actions (F3)."); - btnCancelSkip.setFocusable(false); - btnCancelSkip.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent evt) { - if (evt.getButton() == MouseEvent.BUTTON1) { - restorePriorityActionPerformed(null); - } - } - }); - - btnSkipToNextTurn.setContentAreaFilled(false); - btnSkipToNextTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnSkipToNextTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipNextTurnButtonImage())); - btnSkipToNextTurn.setToolTipText("Skip to next turn (F4)."); - btnSkipToNextTurn.setFocusable(false); - btnSkipToNextTurn.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent evt) { - if (evt.getButton() == MouseEvent.BUTTON1) { - btnEndTurnActionPerformed(null); - } - } - }); - - KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0); - this.getInputMap(c).put(ks, "F4_PRESS"); - this.getActionMap().put("F4_PRESS", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - btnEndTurnActionPerformed(actionEvent); - } - }); - - btnSkipToEndTurn.setContentAreaFilled(false); - btnSkipToEndTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnSkipToEndTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipEndTurnButtonImage())); - btnSkipToEndTurn.setToolTipText("Skip to (opponents/next) end of turn step (F5) - adjust using preferences."); - btnSkipToEndTurn.setFocusable(false); - btnSkipToEndTurn.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent evt) { - if (evt.getButton() == MouseEvent.BUTTON1) { - btnUntilEndOfTurnActionPerformed(null); - } - } - }); - - ks = KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0); - this.getInputMap(c).put(ks, "F5_PRESS"); - this.getActionMap().put("F5_PRESS", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - btnUntilEndOfTurnActionPerformed(actionEvent); - } - }); - - ks = KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0); - this.getInputMap(c).put(ks, "F6_PRESS"); - this.getActionMap().put("F6_PRESS", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - btnEndTurnSkipStackActionPerformed(actionEvent); - } - }); - - btnSkipToNextMain.setContentAreaFilled(false); - btnSkipToNextMain.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnSkipToNextMain.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipMainButtonImage())); - btnSkipToNextMain.setToolTipText("Skip to (your) next main phase (F7) - adjust using preferences."); - btnSkipToNextMain.setFocusable(false); - btnSkipToNextMain.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent evt) { - if (evt.getButton() == MouseEvent.BUTTON1) { - btnUntilNextMainPhaseActionPerformed(null); - } - } - }); - - ks = KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0); - this.getInputMap(c).put(ks, "F7_PRESS"); - this.getActionMap().put("F7_PRESS", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - btnUntilNextMainPhaseActionPerformed(actionEvent); - } - }); - - btnSkipToYourTurn.setContentAreaFilled(false); - btnSkipToYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnSkipToYourTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipYourNextTurnButtonImage())); - btnSkipToYourTurn.setToolTipText("Skip to your next turn (F9)."); - btnSkipToYourTurn.setFocusable(false); - btnSkipToYourTurn.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent evt) { - if (evt.getButton() == MouseEvent.BUTTON1) { - btnPassPriorityUntilNextYourTurnActionPerformed(null); - } - } - }); - - KeyStroke ks9 = KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0); - this.getInputMap(c).put(ks9, "F9_PRESS"); - this.getActionMap().put("F9_PRESS", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - btnPassPriorityUntilNextYourTurnActionPerformed(actionEvent); - } - }); - - btnSkipToEndStepBeforeYourTurn.setContentAreaFilled(false); - btnSkipToEndStepBeforeYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnSkipToEndStepBeforeYourTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipEndStepBeforeYourTurnButtonImage())); - btnSkipToEndStepBeforeYourTurn.setToolTipText("Skip to the end step before your turn (F11) - adjust using preferences."); - btnSkipToEndStepBeforeYourTurn.setFocusable(false); - btnSkipToEndStepBeforeYourTurn.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent evt) { - if (evt.getButton() == MouseEvent.BUTTON1) { - btnSkipToEndStepBeforeYourTurnActionPerformed(null); - } - } - }); - - KeyStroke ks11 = KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0); - this.getInputMap(c).put(ks11, "F11_PRESS"); - this.getActionMap().put("F11_PRESS", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - btnSkipToEndStepBeforeYourTurnActionPerformed(actionEvent); - } - }); - - btnSkipStack.setContentAreaFilled(false); - btnSkipStack.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnSkipStack.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipStackButtonImage())); - btnSkipStack.setToolTipText("Skip until stack is resolved (F10)."); - btnSkipStack.setFocusable(false); - btnSkipStack.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent evt) { - if (evt.getButton() == MouseEvent.BUTTON1) { - btnPassPriorityUntilStackResolvedActionPerformed(null); - } - } - }); - - ks = KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0); - this.getInputMap(c).put(ks, "F10_PRESS"); - this.getActionMap().put("F10_PRESS", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - btnPassPriorityUntilStackResolvedActionPerformed(actionEvent); - } - }); - - btnConcede.setContentAreaFilled(false); - btnConcede.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnConcede.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getConcedeButtonImage())); - btnConcede.setToolTipText("Concede the current game."); - btnConcede.setFocusable(false); - btnConcede.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent evt) { - if (evt.getButton() == MouseEvent.BUTTON1) { - btnConcedeActionPerformed(null); - } - } - }); - - KeyStroke ks2 = KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0); - this.getInputMap(c).put(ks2, "F2_PRESS"); - this.getActionMap().put("F2_PRESS", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - if (feedbackPanel != null) { - feedbackPanel.pressOKYesOrDone(); - } - } - }); - - KeyStroke ksAltE = KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK); - this.getInputMap(c).put(ksAltE, "ENLARGE"); - this.getActionMap().put("ENLARGE", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - ActionCallback callback = Plugins.getInstance().getActionCallback(); - ((MageActionCallback) callback).enlargeCard(EnlargeMode.NORMAL); - } - }); - - KeyStroke ksAltS = KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK); - this.getInputMap(c).put(ksAltS, "ENLARGE_SOURCE"); - this.getActionMap().put("ENLARGE_SOURCE", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - ActionCallback callback = Plugins.getInstance().getActionCallback(); - ((MageActionCallback) callback).enlargeCard(EnlargeMode.ALTERNATE); - } - }); - - KeyStroke ksAltD = KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.ALT_MASK); - this.getInputMap(c).put(ksAltD, "BIG_IMAGE"); - this.getActionMap().put("BIG_IMAGE", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - imagePanelState = !imagePanelState; - if (!imagePanelState) { - jSplitPane0.resetToPreferredSizes(); - jSplitPane0.setDividerLocation(jSplitPane0.getSize().width - jSplitPane0.getInsets().right - jSplitPane0.getDividerSize() - 260); - } else { - jSplitPane0.setDividerLocation(1.0); - } - } - }); - - KeyStroke ksAlt1 = KeyStroke.getKeyStroke(KeyEvent.VK_1, InputEvent.ALT_MASK); - this.getInputMap(c).put(ksAlt1, "USEFIRSTMANAABILITY"); - this.getActionMap().put("USEFIRSTMANAABILITY", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - SessionHandler.sendPlayerAction(PlayerAction.USE_FIRST_MANA_ABILITY_ON, gameId, null); - setMenuStates( - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), - holdingPriority); - } - }); - - final BasicSplitPaneUI myUi = (BasicSplitPaneUI) jSplitPane0.getUI(); - final BasicSplitPaneDivider divider = myUi.getDivider(); - final JButton upArrowButton = (JButton) divider.getComponent(0); - upArrowButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - PreferencesDialog.saveValue(PreferencesDialog.KEY_BIG_CARD_TOGGLED, "up"); - } - }); - - final JButton downArrowButton = (JButton) divider.getComponent(1); - downArrowButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - PreferencesDialog.saveValue(PreferencesDialog.KEY_BIG_CARD_TOGGLED, "down"); - } - }); - - KeyStroke ksAltEReleased = KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK, true); - this.getInputMap(c).put(ksAltEReleased, "ENLARGE_RELEASE"); - KeyStroke ksAltSReleased = KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK, true); - this.getInputMap(c).put(ksAltSReleased, "ENLARGE_RELEASE"); - this.getActionMap().put("ENLARGE_RELEASE", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - ActionCallback callback = Plugins.getInstance().getActionCallback(); - ((MageActionCallback) callback).hideEnlargedCard(); - } - }); - - KeyStroke ksAlt1Released = KeyStroke.getKeyStroke(KeyEvent.VK_1, InputEvent.ALT_MASK, true); - this.getInputMap(c).put(ksAlt1Released, "USEFIRSTMANAABILITY_RELEASE"); - this.getActionMap().put("USEFIRSTMANAABILITY_RELEASE", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - SessionHandler.sendPlayerAction(PlayerAction.USE_FIRST_MANA_ABILITY_OFF, gameId, null); - setMenuStates( - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), - holdingPriority); - } - }); - - btnSwitchHands.setContentAreaFilled(false); - btnSwitchHands.setBorder(new EmptyBorder(0, 0, 0, 0)); - btnSwitchHands.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSwitchHandsButtonImage())); - btnSwitchHands.setFocusable(false); - btnSwitchHands.setToolTipText("Switch between your hand cards and hand cards of controlled players."); - btnSwitchHands.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent evt) { - if (evt.getButton() == MouseEvent.BUTTON1) { - btnSwitchHandActionPerformed(null); - } - } - }); - - btnStopWatching.setContentAreaFilled(false); - btnStopWatching.setBorder(new EmptyBorder(0, 0, 0, 0)); - btnStopWatching.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getStopWatchButtonImage())); - btnStopWatching.setFocusable(false); - btnStopWatching.setToolTipText("Stop watching this game."); - btnStopWatching.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent evt) { - if (evt.getButton() == MouseEvent.BUTTON1) { - btnStopWatchingActionPerformed(null); - } - } - }); - - stackObjects.setBackgroundColor(new Color(0, 0, 0, 40)); - - btnStopReplay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_stop.png"))); - btnStopReplay.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnStopReplayActionPerformed(evt); - } - }); - - btnNextPlay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_stop_right.png"))); - btnNextPlay.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnNextPlayActionPerformed(evt); - } - }); - - btnPlay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_right.png"))); - btnPlay.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnPlayActionPerformed(evt); - } - }); - - btnSkipForward.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_double_stop_right.png"))); - btnSkipForward.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnSkipForwardActionPerformed(evt); - } - }); - - btnPreviousPlay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_stop_left.png"))); - btnPreviousPlay.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnPreviousPlayActionPerformed(evt); - } - }); - - initPopupMenuTriggerOrder(); - - setGUISize(); - - // Replay panel to control replay of games - javax.swing.GroupLayout gl_pnlReplay = new javax.swing.GroupLayout(pnlReplay); - pnlReplay.setLayout(gl_pnlReplay); - gl_pnlReplay.setHorizontalGroup( - gl_pnlReplay.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(gl_pnlReplay.createSequentialGroup() - .addComponent(btnPreviousPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(btnPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(btnStopReplay, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(btnNextPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(btnSkipForward, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)) - ); - gl_pnlReplay.setVerticalGroup( - gl_pnlReplay.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(btnSkipForward, 0, 0, Short.MAX_VALUE) - .addComponent(btnNextPlay, 0, 0, Short.MAX_VALUE) - .addComponent(btnStopReplay, 0, 0, Short.MAX_VALUE) - .addComponent(btnPlay, 0, 0, Short.MAX_VALUE) - .addComponent(btnPreviousPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 31, Short.MAX_VALUE) - ); - - // Game info panel (buttons on the right panel) - javax.swing.GroupLayout gl_pnlShortCuts = new javax.swing.GroupLayout(pnlShortCuts); - pnlShortCuts.setLayout(gl_pnlShortCuts); - gl_pnlShortCuts.setHorizontalGroup(gl_pnlShortCuts.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(gl_pnlShortCuts.createSequentialGroup() - .addComponent(btnSkipToNextTurn) - .addComponent(btnSkipToEndTurn) - .addComponent(btnSkipToNextMain) - .addComponent(btnSkipToYourTurn) - .addComponent(btnSkipStack) - .addComponent(btnSkipToEndStepBeforeYourTurn) - ) - .addGroup(gl_pnlShortCuts.createSequentialGroup() - .addComponent(txtHoldPriority) - .addComponent(txtSpellsCast) - .addComponent(btnSwitchHands) - .addComponent(btnCancelSkip) - .addComponent(btnConcede) - .addComponent(btnStopWatching) - ) - //.addComponent(bigCard, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE) - //.addComponent(feedbackPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE) - //.addComponent(stack, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE) - - .addGroup(gl_pnlShortCuts.createSequentialGroup() - .addContainerGap() - .addComponent(pnlReplay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(51, Short.MAX_VALUE)) - ); - gl_pnlShortCuts.setVerticalGroup(gl_pnlShortCuts.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(gl_pnlShortCuts.createSequentialGroup() - //.addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - //.addGap(1, 1, 1) - //.addComponent(feedbackPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE) - //.addComponent(stack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 164, Short.MAX_VALUE) - .addComponent(pnlReplay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(gl_pnlShortCuts.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(btnSkipToNextTurn) - .addComponent(btnSkipToEndTurn) - .addComponent(btnSkipToNextMain) - .addComponent(btnSkipToYourTurn) - .addComponent(btnSkipStack) - .addComponent(btnSkipToEndStepBeforeYourTurn) - ) - .addGroup(gl_pnlShortCuts.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(txtHoldPriority) - .addComponent(txtSpellsCast) - .addComponent(btnSwitchHands) - .addComponent(btnCancelSkip) - .addComponent(btnConcede) - .addComponent(btnStopWatching) - ) - ) - ); - - pnlBattlefield.setLayout(new java.awt.GridBagLayout()); - - jPhases = new JPanel(); - jPhases.setBackground(new Color(0, 0, 0, 0)); - jPhases.setLayout(null); - jPhases.setPreferredSize(new Dimension(X_PHASE_WIDTH, 435)); - - MouseAdapter phasesMouseAdapter = new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent evt) { - mouseClickPhaseBar(evt); - } - }; - String[] phases = {"Untap", "Upkeep", "Draw", "Main1", - "Combat_Start", "Combat_Attack", "Combat_Block", "Combat_Damage", "Combat_End", - "Main2", "Cleanup", "Next_Turn"}; - for (String name : phases) { - createPhaseButton(name, phasesMouseAdapter); - } - - int i = 0; - for (String name : hoverButtons.keySet()) { - HoverButton hoverButton = hoverButtons.get(name); - hoverButton.setAlignmentX(LEFT_ALIGNMENT); - hoverButton.setBounds(X_PHASE_WIDTH - 36, i * 36, 36, 36); - jPhases.add(hoverButton); - i++; - } - jPhases.addMouseListener(phasesMouseAdapter); - - pnlReplay.setOpaque(false); - - helper = new HelperPanel(); - feedbackPanel.setHelperPanel(helper); - - jSplitPane2.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); - jSplitPane2.setResizeWeight(0.5); - jSplitPane2.setLeftComponent(userChatPanel); - jSplitPane2.setBottomComponent(gameChatPanel); - - phasesContainer = new JPanel(); - phasesContainer.setLayout(new RelativeLayout(RelativeLayout.Y_AXIS)); - phasesContainer.setBackground(new Color(0, 0, 0, 0)); - Float ratio = (float) 1; - JPanel empty1 = new JPanel(); - empty1.setBackground(new Color(0, 0, 0, 0)); - phasesContainer.add(empty1, ratio); - phasesContainer.add(jPhases); - - javax.swing.GroupLayout gl_helperHandButtonsStackArea = new javax.swing.GroupLayout(pnlHelperHandButtonsStackArea); - gl_helperHandButtonsStackArea.setHorizontalGroup( - gl_helperHandButtonsStackArea.createParallelGroup(Alignment.LEADING) - .addGroup(gl_helperHandButtonsStackArea.createSequentialGroup() - // .addGap(0) - .addGroup(gl_helperHandButtonsStackArea.createParallelGroup(Alignment.LEADING) - .addGroup(gl_helperHandButtonsStackArea.createSequentialGroup() - .addGroup(gl_helperHandButtonsStackArea.createParallelGroup(Alignment.LEADING) - .addComponent(helper, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(handContainer, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - ) - .addGroup(gl_helperHandButtonsStackArea.createParallelGroup(Alignment.LEADING) - .addComponent(pnlShortCuts, 410, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) - .addComponent(stackObjects, 410, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) - ) - ) - .addGap(0) - //.addComponent(jPhases, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(gl_helperHandButtonsStackArea.createSequentialGroup() - .addComponent(pnlBattlefield, GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE) - .addComponent(phasesContainer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - ))) - ); - gl_helperHandButtonsStackArea.setVerticalGroup( - gl_helperHandButtonsStackArea.createParallelGroup(Alignment.TRAILING) - .addGroup(gl_helperHandButtonsStackArea.createSequentialGroup() - .addGroup(gl_helperHandButtonsStackArea.createParallelGroup(Alignment.LEADING) - .addComponent(pnlBattlefield, GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE) - .addComponent(phasesContainer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - ) - //.addPreferredGap(ComponentPlacement.RELATED) - .addGroup(gl_helperHandButtonsStackArea.createParallelGroup(Alignment.LEADING) - .addGroup(gl_helperHandButtonsStackArea.createSequentialGroup() - .addGap(2) - .addComponent(pnlShortCuts, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(stackObjects, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - ) - .addGroup(gl_helperHandButtonsStackArea.createSequentialGroup() - .addComponent(helper, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(handContainer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - ) - ) - ) - ); - pnlHelperHandButtonsStackArea.setLayout(gl_helperHandButtonsStackArea); - - jSplitPane1.setLeftComponent(pnlHelperHandButtonsStackArea); - jSplitPane1.setRightComponent(jSplitPane2); - - // Set individual area sizes of big card pane - GridBagLayout gbl = new GridBagLayout(); - jPanel2.setLayout(gbl); - - GridBagConstraints gbc = new GridBagConstraints(); - gbc.fill = GridBagConstraints.BOTH; - gbc.gridx = 0; - gbc.gridy = 0; - gbc.gridwidth = 1; - gbc.gridheight = 4; // size 4/5 - gbc.weightx = 1.0; - gbc.weighty = 1.0; - gbl.setConstraints(bigCard, gbc); - jPanel2.add(bigCard); - - jPanel2.setOpaque(false); - - // game pane and chat/log pane - jSplitPane0.setLeftComponent(jSplitPane1); - // big card and buttons - jSplitPane0.setRightComponent(jPanel2); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jSplitPane0, javax.swing.GroupLayout.DEFAULT_SIZE, 1078, Short.MAX_VALUE) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jSplitPane0, javax.swing.GroupLayout.DEFAULT_SIZE, 798, Short.MAX_VALUE) - ); - } - - private void removeListener() { - for (MouseListener ml : this.getMouseListeners()) { - this.removeMouseListener(ml); - } - for (MouseListener ml : this.btnCancelSkip.getMouseListeners()) { - this.btnCancelSkip.removeMouseListener(ml); - } - for (MouseListener ml : this.btnConcede.getMouseListeners()) { - this.btnConcede.removeMouseListener(ml); - } - for (MouseListener ml : this.btnSkipToYourTurn.getMouseListeners()) { - this.btnSkipToYourTurn.removeMouseListener(ml); - } - for (MouseListener ml : this.btnSkipStack.getMouseListeners()) { - this.btnSkipStack.removeMouseListener(ml); - } - for (MouseListener ml : this.btnSkipToEndStepBeforeYourTurn.getMouseListeners()) { - this.btnSkipToEndStepBeforeYourTurn.removeMouseListener(ml); - } - for (MouseListener ml : this.btnSkipToEndTurn.getMouseListeners()) { - this.btnSkipToEndTurn.removeMouseListener(ml); - } - for (MouseListener ml : this.btnSkipToNextMain.getMouseListeners()) { - this.btnSkipToNextMain.removeMouseListener(ml); - } - for (MouseListener ml : this.btnSkipToNextTurn.getMouseListeners()) { - this.btnSkipToNextTurn.removeMouseListener(ml); - } - for (MouseListener ml : this.btnSwitchHands.getMouseListeners()) { - this.btnSwitchHands.removeMouseListener(ml); - } - for (MouseListener ml : this.btnStopWatching.getMouseListeners()) { - this.btnStopWatching.removeMouseListener(ml); - } - for (MouseListener ml : this.jPhases.getMouseListeners()) { - this.jPhases.removeMouseListener(ml); - } - for (String name : hoverButtons.keySet()) { - HoverButton hoverButton = hoverButtons.get(name); - for (MouseListener ml : hoverButton.getMouseListeners()) { - hoverButton.removeMouseListener(ml); - } - } - for (ActionListener al : this.btnPlay.getActionListeners()) { - this.btnPlay.removeActionListener(al); - } - for (ActionListener al : this.btnStopReplay.getActionListeners()) { - this.btnStopReplay.removeActionListener(al); - } - for (ActionListener al : this.btnNextPlay.getActionListeners()) { - this.btnNextPlay.removeActionListener(al); - } - for (ActionListener al : this.btnNextPlay.getActionListeners()) { - this.btnNextPlay.removeActionListener(al); - } - for (ActionListener al : this.btnPreviousPlay.getActionListeners()) { - this.btnPreviousPlay.removeActionListener(al); - } - for (ActionListener al : this.btnSkipForward.getActionListeners()) { - this.btnSkipForward.removeActionListener(al); - } - - final BasicSplitPaneUI myUi = (BasicSplitPaneUI) jSplitPane0.getUI(); - final BasicSplitPaneDivider divider = myUi.getDivider(); - final JButton upArrowButton = (JButton) divider.getComponent(0); - for (ActionListener al : upArrowButton.getActionListeners()) { - upArrowButton.removeActionListener(al); - } - final JButton downArrowButton = (JButton) divider.getComponent(1); - for (ActionListener al : downArrowButton.getActionListeners()) { - downArrowButton.removeActionListener(al); - } - - for (ComponentListener cl : this.getComponentListeners()) { - this.removeComponentListener(cl); - } - } - - private void btnConcedeActionPerformed(java.awt.event.ActionEvent evt) { - UserRequestMessage message = new UserRequestMessage("Confirm concede", "Are you sure you want to concede?"); - message.setButton1("No", null); - message.setButton2("Yes", PlayerAction.CLIENT_CONCEDE_GAME); - message.setGameId(gameId); - MageFrame.getInstance().showUserRequestDialog(message); - } - - private void btnEndTurnActionPerformed(java.awt.event.ActionEvent evt) { - SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN, gameId, null); - AudioManager.playOnSkipButton(); - updateSkipButtons(true, false, false, false, false, false); - } - - private void btnUntilEndOfTurnActionPerformed(java.awt.event.ActionEvent evt) { - SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_TURN_END_STEP, gameId, null); - AudioManager.playOnSkipButton(); - updateSkipButtons(false, true, false, false, false, false); - } - - private void btnEndTurnSkipStackActionPerformed(java.awt.event.ActionEvent evt) { - SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN_SKIP_STACK, gameId, null); - AudioManager.playOnSkipButton(); - updateSkipButtons(true, false, false, false, true, false); - } - - private void btnUntilNextMainPhaseActionPerformed(java.awt.event.ActionEvent evt) { - SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_MAIN_PHASE, gameId, null); - AudioManager.playOnSkipButton(); - updateSkipButtons(false, false, true, false, false, false); - } - - private void btnPassPriorityUntilNextYourTurnActionPerformed(java.awt.event.ActionEvent evt) { - SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_MY_NEXT_TURN, gameId, null); - AudioManager.playOnSkipButton(); - updateSkipButtons(false, false, false, true, false, false); - } - - private void btnPassPriorityUntilStackResolvedActionPerformed(java.awt.event.ActionEvent evt) { - SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_STACK_RESOLVED, gameId, null); - AudioManager.playOnSkipButton(); - updateSkipButtons(false, false, false, false, true, false); - } - - private void btnSkipToEndStepBeforeYourTurnActionPerformed(java.awt.event.ActionEvent evt) { - SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_END_STEP_BEFORE_MY_NEXT_TURN, gameId, null); - AudioManager.playOnSkipButton(); - updateSkipButtons(false, false, false, false, false, true); - } - - private void restorePriorityActionPerformed(java.awt.event.ActionEvent evt) { - SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_CANCEL_ALL_ACTIONS, gameId, null); - AudioManager.playOnSkipButtonCancel(); - updateSkipButtons(false, false, false, false, false, false); - } - - private void mouseClickPhaseBar(MouseEvent evt) { - if (evt.getButton() == MouseEvent.BUTTON1) { // Left button - PreferencesDialog.main(new String[]{PreferencesDialog.OPEN_PHASES_TAB}); - } - } - - private void btnSwitchHandActionPerformed(java.awt.event.ActionEvent evt) { - String[] choices = handCards.keySet().toArray(new String[0]); - - String newChosenHandKey = (String) JOptionPane.showInputDialog( - this, - "Choose hand to display:", "Switch between hands", - JOptionPane.PLAIN_MESSAGE, - null, - choices, - this.chosenHandKey); - - if (newChosenHandKey != null && newChosenHandKey.length() > 0) { - this.chosenHandKey = newChosenHandKey; - CardsView cards = handCards.get(chosenHandKey); - handContainer.loadCards(cards, bigCard, gameId); - } - } + private static final Logger logger = Logger.getLogger(GamePanel.class); + private static final String YOUR_HAND = "Your hand"; + private static final int X_PHASE_WIDTH = 55; + private static final int STACK_MIN_CARDS_OFFSET_Y = 7; // TODO: Size bui GUISize value + + private static final String CMD_AUTO_ORDER_FIRST = "cmdAutoOrderFirst"; + private static final String CMD_AUTO_ORDER_LAST = "cmdAutoOrderLast"; + private static final String CMD_AUTO_ORDER_NAME_FIRST = "cmdAutoOrderNameFirst"; + private static final String CMD_AUTO_ORDER_NAME_LAST = "cmdAutoOrderNameLast"; + private static final String CMD_AUTO_ORDER_RESET_ALL = "cmdAutoOrderResetAll"; + + private final Map players = new HashMap<>(); + private final Map playersWhoLeft = new HashMap<>(); + + // non modal frames + private final Map exiles = new HashMap<>(); + private final Map revealed = new HashMap<>(); + private final Map lookedAt = new HashMap<>(); + private final Map graveyardWindows = new HashMap<>(); + private final Map graveyards = new HashMap<>(); + + private final ArrayList pickTarget = new ArrayList<>(); + private UUID gameId; + private UUID playerId; // playerId of the player + GamePane gamePane; + private ReplayTask replayTask; + private final PickNumberDialog pickNumber; + private JLayeredPane jLayeredPane; + private String chosenHandKey = "You"; + private boolean smallMode = false; + private boolean initialized = false; + + private boolean menuNameSet = false; + private boolean handCardsOfOpponentAvailable = false; + + private Map loadedCards = new HashMap<>(); + + private int storedHeight; + private Map hoverButtons; + + private MageDialogState choiceWindowState; + + private boolean initComponents; + + private Timer resizeTimer; + + private enum PopUpMenuType { + + TRIGGER_ORDER + } + // CardView popupMenu was invoked last + private CardView cardViewPopupMenu; + + // popup menu for triggered abilities order + private JPopupMenu popupMenuTriggerOrder; + + public GamePanel() { + initComponents = true; + initComponents(); + + pickNumber = new PickNumberDialog(); + MageFrame.getDesktop().add(pickNumber, JLayeredPane.MODAL_LAYER); + + this.feedbackPanel.setConnectedChatPanel(this.userChatPanel); + + this.stackObjects.setMinOffsetY(STACK_MIN_CARDS_OFFSET_Y); + + // Override layout (I can't edit generated code) + this.setLayout(new BorderLayout()); + final JLayeredPane jLayeredBackgroundPane = new JLayeredPane(); + jLayeredBackgroundPane.setSize(1024, 768); + this.add(jLayeredBackgroundPane); + jLayeredBackgroundPane.add(jSplitPane0, JLayeredPane.DEFAULT_LAYER); + + Map myUi = getUIComponents(jLayeredBackgroundPane); + Plugins.getInstance().updateGamePanel(myUi); + + // Enlarge jlayeredpane on resize of game panel + addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + int width = ((JComponent) e.getSource()).getWidth(); + int height = ((JComponent) e.getSource()).getHeight(); + jLayeredBackgroundPane.setSize(width, height); + jSplitPane0.setSize(width, height); + + if (height < storedHeight) { + pnlBattlefield.setSize(0, 200); + } + storedHeight = height; + + sizeToScreen(); + + if (!initialized) { + String state = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BIG_CARD_TOGGLED, null); + if (state != null && state.equals("down")) { + jSplitPane0.setDividerLocation(1.0); + } + initialized = true; + } + + } + }); + // Resize the width of the stack area if the size of the play area is changed + ComponentAdapter componentAdapterPlayField = new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + if (!initComponents) { + if (resizeTimer.isRunning()) { + resizeTimer.restart(); + } else { + resizeTimer.start(); + } + } + } + }; + + resizeTimer = new Timer(1000, new ActionListener() { + @Override + public void actionPerformed(ActionEvent evt) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + resizeTimer.stop(); + setGUISize(); + feedbackPanel.changeGUISize(); + + } + }); + } + }); + + pnlHelperHandButtonsStackArea.addComponentListener(componentAdapterPlayField); + initComponents = false; + } + + private Map getUIComponents(JLayeredPane jLayeredPane) { + Map components = new HashMap<>(); + + components.put("jSplitPane1", jSplitPane1); + components.put("pnlBattlefield", pnlBattlefield); + components.put("pnlHelperHandButtonsStackArea", pnlHelperHandButtonsStackArea); + components.put("hand", handContainer); + components.put("gameChatPanel", gameChatPanel); + components.put("userChatPanel", userChatPanel); + components.put("jLayeredPane", jLayeredPane); + components.put("gamePanel", this); + + return components; + } + + public void cleanUp() { + MageFrame.removeGame(gameId); + saveDividerLocations(); + this.gameChatPanel.disconnect(); + this.userChatPanel.disconnect(); + + this.removeListener(); + + this.handContainer.cleanUp(); + this.stackObjects.cleanUp(); + for (Map.Entry playAreaPanelEntry : players.entrySet()) { + playAreaPanelEntry.getValue().CleanUp(); + } + this.players.clear(); + this.playersWhoLeft.clear(); + + jLayeredPane.remove(abilityPicker); + this.abilityPicker.cleanUp(); + + jLayeredPane.remove(DialogManager.getManager(gameId)); + DialogManager.removeGame(gameId); + + if (pickNumber != null) { + pickNumber.removeDialog(); + } + for (CardInfoWindowDialog exileDialog : exiles.values()) { + exileDialog.cleanUp(); + exileDialog.removeDialog(); + } + for (CardInfoWindowDialog graveyardDialog : graveyardWindows.values()) { + graveyardDialog.cleanUp(); + graveyardDialog.removeDialog(); + } + for (CardInfoWindowDialog revealDialog : revealed.values()) { + revealDialog.cleanUp(); + revealDialog.removeDialog(); + } + for (CardInfoWindowDialog lookedAtDialog : lookedAt.values()) { + lookedAtDialog.cleanUp(); + lookedAtDialog.removeDialog(); + } + for (ShowCardsDialog pickTargetDialog : pickTarget) { + pickTargetDialog.cleanUp(); + pickTargetDialog.removeDialog(); + } + Plugins.getInstance().getActionCallback().hideTooltipPopup(); + try { + Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER); + popupContainer.setVisible(false); + } catch (InterruptedException ex) { + logger.fatal("popupContainer error:", ex); + } + jPanel2.remove(bigCard); + this.bigCard = null; + } + + public void changeGUISize() { + initComponents = true; + setGUISize(); + stackObjects.changeGUISize(); + feedbackPanel.changeGUISize(); + handContainer.changeGUISize(); + for (PlayAreaPanel playAreaPanel : players.values()) { + playAreaPanel.changeGUISize(); + } + + for (CardInfoWindowDialog cardInfoWindowDialog : exiles.values()) { + cardInfoWindowDialog.changeGUISize(); + } + for (CardInfoWindowDialog cardInfoWindowDialog : revealed.values()) { + cardInfoWindowDialog.changeGUISize(); + } + for (CardInfoWindowDialog cardInfoWindowDialog : lookedAt.values()) { + cardInfoWindowDialog.changeGUISize(); + } + for (CardInfoWindowDialog cardInfoWindowDialog : graveyardWindows.values()) { + cardInfoWindowDialog.changeGUISize(); + } + for (ShowCardsDialog showCardsDialog : pickTarget) { + showCardsDialog.changeGUISize(); + } + + this.revalidate(); + this.repaint(); + initComponents = false; + } + + private void setGUISize() { + jSplitPane0.setDividerSize(GUISizeHelper.dividerBarSize); + jSplitPane1.setDividerSize(GUISizeHelper.dividerBarSize); + jSplitPane2.setDividerSize(GUISizeHelper.dividerBarSize); + stackObjects.setCardDimension(GUISizeHelper.handCardDimension); + + txtSpellsCast.setFont(new Font(GUISizeHelper.gameDialogAreaFont.getFontName(), Font.BOLD, GUISizeHelper.gameDialogAreaFont.getSize())); + txtHoldPriority.setFont(new Font(GUISizeHelper.gameDialogAreaFont.getFontName(), Font.BOLD, GUISizeHelper.gameDialogAreaFont.getSize())); + GUISizeHelper.changePopupMenuFont(popupMenuTriggerOrder); + + int newStackWidth = pnlHelperHandButtonsStackArea.getWidth() * GUISizeHelper.stackWidth / 100; + if (newStackWidth < 410) { + newStackWidth = 410; + } + Dimension newDimension = new Dimension(pnlHelperHandButtonsStackArea.getWidth() - newStackWidth, GUISizeHelper.handCardDimension.height + GUISizeHelper.scrollBarSize); + handContainer.setPreferredSize(newDimension); + handContainer.setMaximumSize(newDimension); + + newDimension = new Dimension(newStackWidth, STACK_MIN_CARDS_OFFSET_Y + GUISizeHelper.handCardDimension.height + GUISizeHelper.scrollBarSize); + stackObjects.setPreferredSize(newDimension); + stackObjects.setMinimumSize(newDimension); + stackObjects.setMaximumSize(newDimension); + + newDimension = new Dimension(newStackWidth, (int) pnlShortCuts.getPreferredSize().getHeight()); + pnlShortCuts.setPreferredSize(newDimension); + pnlShortCuts.setMinimumSize(newDimension); + pnlShortCuts.setMaximumSize(newDimension); + } + + private void saveDividerLocations() { + // save panel sizes and divider locations. + Rectangle rec = MageFrame.getDesktop().getBounds(); + String sb = Double.toString(rec.getWidth()) + "x" + Double.toString(rec.getHeight()); + PreferencesDialog.saveValue(PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE, sb); + PreferencesDialog.saveValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_0, Integer.toString(this.jSplitPane0.getDividerLocation())); + PreferencesDialog.saveValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_1, Integer.toString(this.jSplitPane1.getDividerLocation())); + PreferencesDialog.saveValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_2, Integer.toString(this.jSplitPane2.getDividerLocation())); + } + + private void restoreDividerLocations() { + Rectangle rec = MageFrame.getDesktop().getBounds(); + if (rec != null) { + String size = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE, null); + String sb = Double.toString(rec.getWidth()) + "x" + Double.toString(rec.getHeight()); + // use divider positions only if screen size is the same as it was the time the settings were saved + if (size != null && size.equals(sb)) { + + String location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_0, null); + if (location != null && jSplitPane0 != null) { + jSplitPane0.setDividerLocation(Integer.parseInt(location)); + } + location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_1, null); + if (location != null && jSplitPane1 != null) { + jSplitPane1.setDividerLocation(Integer.parseInt(location)); + } + location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_2, null); + if (location != null && jSplitPane2 != null) { + jSplitPane2.setDividerLocation(Integer.parseInt(location)); + } + } + } + } + + private void sizeToScreen() { + Rectangle rect = this.getBounds(); + + if (rect.height < 720) { + if (!smallMode) { + smallMode = true; + Dimension bbDimension = new Dimension(128, 184); + bigCard.setMaximumSize(bbDimension); + bigCard.setMinimumSize(bbDimension); + bigCard.setPreferredSize(bbDimension); + pnlShortCuts.revalidate(); + pnlShortCuts.repaint(); + for (PlayAreaPanel p : players.values()) { + p.sizePlayer(smallMode); + } + } + } else if (smallMode) { + smallMode = false; + Dimension bbDimension = new Dimension(256, 367); + bigCard.setMaximumSize(bbDimension); + bigCard.setMinimumSize(bbDimension); + bigCard.setPreferredSize(bbDimension); + pnlShortCuts.revalidate(); + pnlShortCuts.repaint(); + for (PlayAreaPanel p : players.values()) { + p.sizePlayer(smallMode); + } + } + + ArrowBuilder.getBuilder().setSize(rect.width, rect.height); + + DialogManager.getManager(gameId).setScreenWidth(rect.width); + DialogManager.getManager(gameId).setScreenHeight(rect.height); + DialogManager.getManager(gameId).setBounds(0, 0, rect.width, rect.height); + } + + public synchronized void showGame(UUID gameId, UUID playerId, GamePane gamePane) { + this.gameId = gameId; + this.gamePane = gamePane; + this.playerId = playerId; + MageFrame.addGame(gameId, this); + this.feedbackPanel.init(gameId); + this.feedbackPanel.clear(); + this.abilityPicker.init(gameId); + + this.btnConcede.setVisible(true); + this.btnStopWatching.setVisible(false); + this.btnSwitchHands.setVisible(false); + this.btnCancelSkip.setVisible(true); + + this.btnSkipToNextTurn.setVisible(true); + this.btnSkipToEndTurn.setVisible(true); + this.btnSkipToNextMain.setVisible(true); + this.btnSkipStack.setVisible(true); + this.btnSkipToYourTurn.setVisible(true); + this.btnSkipToEndStepBeforeYourTurn.setVisible(true); + + this.pnlReplay.setVisible(false); + + this.gameChatPanel.clear(); + this.gameChatPanel.connect(SessionHandler.getGameChatId(gameId)); + if (!SessionHandler.joinGame(gameId)) { + removeGame(); + } else { + // play start sound + AudioManager.playYourGameStarted(); + } + } + + public synchronized void watchGame(UUID gameId, GamePane gamePane) { + this.gameId = gameId; + this.gamePane = gamePane; + this.playerId = null; + MageFrame.addGame(gameId, this); + this.feedbackPanel.init(gameId); + this.feedbackPanel.clear(); + + this.btnConcede.setVisible(false); + this.btnStopWatching.setVisible(true); + this.btnSwitchHands.setVisible(false); + this.chosenHandKey = ""; + this.btnCancelSkip.setVisible(false); + + this.btnSkipToNextTurn.setVisible(false); + this.btnSkipToEndTurn.setVisible(false); + this.btnSkipToNextMain.setVisible(false); + this.btnSkipStack.setVisible(false); + this.btnSkipToYourTurn.setVisible(false); + this.btnSkipToEndStepBeforeYourTurn.setVisible(false); + + this.pnlReplay.setVisible(false); + this.gameChatPanel.clear(); + this.gameChatPanel.connect(SessionHandler.getGameChatId(gameId)); + if (!SessionHandler.watchGame(gameId)) { + removeGame(); + } + for (PlayAreaPanel panel : getPlayers().values()) { + panel.setPlayingMode(false); + } + } + + public synchronized void replayGame(UUID gameId) { + this.gameId = gameId; + this.playerId = null; + MageFrame.addGame(gameId, this); + this.feedbackPanel.init(gameId); + this.feedbackPanel.clear(); + this.btnConcede.setVisible(false); + this.btnSkipToNextTurn.setVisible(false); + this.btnSwitchHands.setVisible(false); + this.btnStopWatching.setVisible(false); + this.pnlReplay.setVisible(true); + this.gameChatPanel.clear(); + if (!SessionHandler.startReplay(gameId)) { + removeGame(); + } + for (PlayAreaPanel panel : getPlayers().values()) { + panel.setPlayingMode(false); + } + } + + /** + * Closes the game and it's resources + */ + public void removeGame() { + Component c = this.getParent(); + while (c != null && !(c instanceof GamePane)) { + c = c.getParent(); + } + if (c != null) { + ((GamePane) c).removeGame(); + } + } + + public synchronized void init(GameView game) { + addPlayers(game); + // default menu states + setMenuStates( + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), + holdingPriority + ); + + updateGame(game); + } + + private void addPlayers(GameView game) { + this.players.clear(); + this.playersWhoLeft.clear(); + this.pnlBattlefield.removeAll(); + //arrange players in a circle with the session player at the bottom left + int numSeats = game.getPlayers().size(); + int numColumns = (numSeats + 1) / 2; + boolean oddNumber = (numColumns > 1 && numSeats % 2 == 1); + int col = 0; + int row = 1; + int playerSeat = 0; + if (playerId != null) { + for (PlayerView player : game.getPlayers()) { + if (playerId.equals(player.getPlayerId())) { + break; + } + playerSeat++; + } + } + PlayerView player = game.getPlayers().get(playerSeat); + PlayAreaPanel playAreaPanel = new PlayAreaPanel(player, bigCard, gameId, game.getPriorityTime(), this, + new PlayAreaPanelOptions(game.isPlayer(), game.isPlayer(), game.isRollbackTurnsAllowed(), row == 0)); + players.put(player.getPlayerId(), playAreaPanel); + playersWhoLeft.put(player.getPlayerId(), false); + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.BOTH; + c.weightx = 0.5; + c.weighty = 0.5; + if (oddNumber) { + c.gridwidth = 2; + } + c.gridx = col; + c.gridy = 0; + + // Top panel (row=0) + JPanel topPanel = new JPanel(); + topPanel.setOpaque(false); + + // Bottom panel (row=1) + JPanel bottomPanel = new JPanel(); + bottomPanel.setOpaque(false); + topPanel.setLayout(new GridBagLayout()); + bottomPanel.setLayout(new GridBagLayout()); + + bottomPanel.add(playAreaPanel, c); + playAreaPanel.setVisible(true); + if (oddNumber) { + col++; + } + int playerNum = playerSeat + 1; + if (playerNum >= numSeats) { + playerNum = 0; + } + while (true) { + if (row == 1) { + col++; + } else { + col--; + } + if (col >= numColumns) { + row = 0; + col = numColumns - 1; + } + player = game.getPlayers().get(playerNum); + PlayAreaPanel playerPanel = new PlayAreaPanel(player, bigCard, gameId, game.getPriorityTime(), this, + new PlayAreaPanelOptions(game.isPlayer(), false, game.isRollbackTurnsAllowed(), row == 0)); + players.put(player.getPlayerId(), playerPanel); + playersWhoLeft.put(player.getPlayerId(), false); + c = new GridBagConstraints(); + c.fill = GridBagConstraints.BOTH; + c.weightx = 0.5; + c.weighty = 0.5; + c.gridx = col; + c.gridy = 0; + + if (row == 0) { + topPanel.add(playerPanel, c); + } else { + bottomPanel.add(playerPanel, c); + } + + playerPanel.setVisible(true); + playerNum++; + if (playerNum >= numSeats) { + playerNum = 0; + } + if (playerNum == playerSeat) { + break; + } + } + for (PlayAreaPanel p : players.values()) { + p.sizePlayer(smallMode); + } + + GridBagConstraints panelC = new GridBagConstraints(); + panelC.fill = GridBagConstraints.BOTH; + panelC.weightx = 0.5; + panelC.weighty = 0.5; + panelC.gridwidth = 1; + panelC.gridy = 0; + this.pnlBattlefield.add(topPanel, panelC); + panelC.gridy = 1; + this.pnlBattlefield.add(bottomPanel, panelC); + } + + public synchronized void updateGame(GameView game) { + updateGame(game, null); + } + + public synchronized void updateGame(GameView game, Map options) { + if (playerId == null && game.getWatchedHands() == null) { + this.handContainer.setVisible(false); + } else { + this.handContainer.setVisible(true); + handCards.clear(); + if (game.getWatchedHands() != null) { + for (Map.Entry hand : game.getWatchedHands().entrySet()) { + handCards.put(hand.getKey(), CardsViewUtil.convertSimple(hand.getValue(), loadedCards)); + } + } + if (playerId != null) { + handCards.put(YOUR_HAND, game.getHand()); + // Mark playable + if (game.getCanPlayInHand() != null) { + for (CardView card : handCards.get(YOUR_HAND).values()) { + if (game.getCanPlayInHand().contains(card.getId())) { + card.setPlayable(true); + } + } + } + // Get opponents hand cards if available (only possible for players) + if (game.getOpponentHands() != null) { + for (Map.Entry hand : game.getOpponentHands().entrySet()) { + handCards.put(hand.getKey(), CardsViewUtil.convertSimple(hand.getValue(), loadedCards)); + } + } + if (!handCards.containsKey(chosenHandKey)) { + chosenHandKey = YOUR_HAND; + } + } else if (chosenHandKey.isEmpty() && handCards.size() > 0) { + chosenHandKey = handCards.keySet().iterator().next(); + } + if (chosenHandKey != null && handCards.containsKey(chosenHandKey)) { + handContainer.loadCards(handCards.get(chosenHandKey), bigCard, gameId); + } + + hideAll(); + + if (playerId != null) { + // set visible only if we have any other hand visible than ours + btnSwitchHands.setVisible(handCards.size() > 1); + boolean change = (handCardsOfOpponentAvailable != (game.getOpponentHands() != null)); + if (change) { + handCardsOfOpponentAvailable = !handCardsOfOpponentAvailable; + if (handCardsOfOpponentAvailable) { + JOptionPane.showMessageDialog(null, "You control other player's turn. \nUse \"Switch Hand\" button to switch between cards in different hands."); + } else { + JOptionPane.showMessageDialog(null, "You lost control on other player's turn."); + } + } + } else { + btnSwitchHands.setVisible(!handCards.isEmpty()); + } + } + + if (game.getPhase() != null) { + this.txtPhase.setText(game.getPhase().toString()); + } else { + this.txtPhase.setText(""); + } + + if (game.getStep() != null) { + updatePhases(game.getStep()); + this.txtStep.setText(game.getStep().toString()); + } else { + logger.debug("Step is empty"); + this.txtStep.setText(""); + } + if (game.getSpellsCastCurrentTurn() > 0 && PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_SHOW_STORM_COUNTER, "true").equals("true")) { + this.txtSpellsCast.setVisible(true); + this.txtSpellsCast.setText(" " + Integer.toString(game.getSpellsCastCurrentTurn()) + " "); + } else { + this.txtSpellsCast.setVisible(false); + } + + this.txtActivePlayer.setText(game.getActivePlayerName()); + this.txtPriority.setText(game.getPriorityPlayerName()); + this.txtTurn.setText(Integer.toString(game.getTurn())); + + List possibleAttackers = new ArrayList<>(); + if (options != null && options.containsKey(Constants.Option.POSSIBLE_ATTACKERS)) { + if (options.get(Constants.Option.POSSIBLE_ATTACKERS) instanceof List) { + possibleAttackers.addAll((List) options.get(Constants.Option.POSSIBLE_ATTACKERS)); + } + } + + for (PlayerView player : game.getPlayers()) { + if (players.containsKey(player.getPlayerId())) { + if (!possibleAttackers.isEmpty()) { + for (UUID permanentId : possibleAttackers) { + if (player.getBattlefield().containsKey(permanentId)) { + player.getBattlefield().get(permanentId).setCanAttack(true); + } + } + } + players.get(player.getPlayerId()).update(player); + if (player.getPlayerId().equals(playerId)) { + updateSkipButtons(player.isPassedTurn(), player.isPassedUntilEndOfTurn(), player.isPassedUntilNextMain(), player.isPassedAllTurns(), player.isPassedUntilStackResolved(), + player.isPassedUntilEndStepBeforeMyTurn()); + } + // update open or remove closed graveyard windows + graveyards.put(player.getName(), player.getGraveyard()); + if (graveyardWindows.containsKey(player.getName())) { + CardInfoWindowDialog cardInfoWindowDialog = graveyardWindows.get(player.getName()); + if (cardInfoWindowDialog.isClosed()) { + graveyardWindows.remove(player.getName()); + } else { + cardInfoWindowDialog.loadCards(player.getGraveyard(), bigCard, gameId, false); + } + } + // show top card window + if (player.getTopCard() != null) { + CardsView cardsView = new CardsView(); + cardsView.put(player.getTopCard().getId(), player.getTopCard()); + handleGameInfoWindow(revealed, ShowType.REVEAL_TOP_LIBRARY, player.getName() + "'s top library card", cardsView); + } + } else { + logger.warn("Couldn't find player."); + logger.warn(" uuid:" + player.getPlayerId()); + logger.warn(" players:"); + for (PlayAreaPanel p : players.values()) { + logger.warn("" + p); + } + } + } + if (!menuNameSet) { + StringBuilder sb = new StringBuilder(); + if (playerId == null) { + sb.append("Watching: "); + } else { + sb.append("Playing: "); + } + boolean first = true; + for (PlayerView player : game.getPlayers()) { + if (first) { + first = false; + } else { + sb.append(" - "); + } + sb.append(player.getName()); + } + menuNameSet = true; + gamePane.setTitle(sb.toString()); + } + + GameManager.getInstance().setStackSize(game.getStack().size()); + displayStack(game, bigCard, feedbackPanel, gameId); + + for (ExileView exile : game.getExile()) { + if (!exiles.containsKey(exile.getId())) { + CardInfoWindowDialog newExile = new CardInfoWindowDialog(ShowType.EXILE, exile.getName()); + exiles.put(exile.getId(), newExile); + MageFrame.getDesktop().add(newExile, JLayeredPane.MODAL_LAYER); + newExile.show(); + } + exiles.get(exile.getId()).loadCards(exile, bigCard, gameId); + } + + showRevealed(game); + showLookedAt(game); + if (game.getCombat().size() > 0) { + CombatManager.getInstance().showCombat(game.getCombat(), gameId); + } else { + CombatManager.getInstance().hideCombat(gameId); + } + + for (PlayerView player : game.getPlayers()) { + if (player.hasLeft() && !playersWhoLeft.get(player.getPlayerId())) { + PlayAreaPanel playerLeftPanel = players.get(player.getPlayerId()); + playersWhoLeft.put(player.getPlayerId(), true); + + Container parent = playerLeftPanel.getParent(); + GridBagLayout layout = (GridBagLayout) parent.getLayout(); + + for (Component otherPanel : parent.getComponents()) { + + if (otherPanel instanceof PlayAreaPanel) { + GridBagConstraints gbc = layout.getConstraints(otherPanel); + if (gbc.weightx > 0.1) { + gbc.weightx = 0.99; + } + gbc.fill = GridBagConstraints.BOTH; + gbc.anchor = GridBagConstraints.WEST; + if (gbc.gridx > 0) { + gbc.anchor = GridBagConstraints.EAST; + } + if (otherPanel == playerLeftPanel) { + gbc.weightx = 0.01; + Dimension d = playerLeftPanel.getPreferredSize(); + d.width = 95; + otherPanel.setPreferredSize(d); + } + parent.remove(otherPanel); + parent.add(otherPanel, gbc); + } + } + + parent.validate(); + parent.repaint(); + } + } + + feedbackPanel.disableUndo(); + + this.revalidate(); + this.repaint(); + } + + static final int BORDER_SIZE = 2; + + private void updateSkipButtons(boolean turn, boolean endOfTurn, boolean nextMain, boolean allTurns, boolean stack, boolean endStepBeforeYourStep) { + if (turn) { //F4 + btnSkipToNextTurn.setBorder(new LineBorder(Color.orange, BORDER_SIZE)); + } else { + btnSkipToNextTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + } + if (endOfTurn) { // F5 + btnSkipToEndTurn.setBorder(new LineBorder(Color.orange, BORDER_SIZE)); + } else { + btnSkipToEndTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + } + if (nextMain) { // F7 + btnSkipToNextMain.setBorder(new LineBorder(Color.orange, BORDER_SIZE)); + } else { + btnSkipToNextMain.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + } + if (stack) { // F8 + btnSkipStack.setBorder(new LineBorder(Color.orange, BORDER_SIZE)); + } else { + btnSkipStack.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + } + if (allTurns) { // F9 + btnSkipToYourTurn.setBorder(new LineBorder(Color.orange, BORDER_SIZE)); + } else { + btnSkipToYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + } + + if (endStepBeforeYourStep) { // F11 + btnSkipToEndStepBeforeYourTurn.setBorder(new LineBorder(Color.orange, BORDER_SIZE)); + } else { + btnSkipToEndStepBeforeYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + } + + } + + /** + * Set the same state for menu selections to all player areas. + * + * @param manaPoolAutomatic + * @param manaPoolAutomaticRestricted + * @param useFirstManaAbility + */ + public void setMenuStates(boolean manaPoolAutomatic, boolean manaPoolAutomaticRestricted, boolean useFirstManaAbility, boolean holdPriority) { + for (PlayAreaPanel playAreaPanel : players.values()) { + playAreaPanel.setMenuStates(manaPoolAutomatic, manaPoolAutomaticRestricted, useFirstManaAbility, holdPriority); + } + } + + private void displayStack(GameView game, BigCard bigCard, FeedbackPanel feedbackPanel, UUID gameId) { + this.stackObjects.loadCards(game.getStack(), bigCard, gameId, true); + } + + /** + * Update phase buttons\labels. + */ + private void updatePhases(PhaseStep step) { + if (step == null) { + logger.warn("step is null"); + return; + } + if (currentStep != null) { + currentStep.setLocation(prevPoint); + } + switch (step) { + case UNTAP: + updateButton("Untap"); + break; + case UPKEEP: + updateButton("Upkeep"); + break; + case DRAW: + updateButton("Draw"); + break; + case PRECOMBAT_MAIN: + updateButton("Main1"); + break; + case BEGIN_COMBAT: + updateButton("Combat_Start"); + break; + case DECLARE_ATTACKERS: + updateButton("Combat_Attack"); + break; + case DECLARE_BLOCKERS: + updateButton("Combat_Block"); + break; + case FIRST_COMBAT_DAMAGE: + case COMBAT_DAMAGE: + updateButton("Combat_Damage"); + break; + case END_COMBAT: + updateButton("Combat_End"); + break; + case POSTCOMBAT_MAIN: + updateButton("Main2"); + break; + case END_TURN: + updateButton("Cleanup"); + break; + } + } + + private void updateButton(String name) { + if (hoverButtons.containsKey(name)) { + currentStep = hoverButtons.get(name); + prevPoint = currentStep.getLocation(); + currentStep.setLocation(prevPoint.x - 15, prevPoint.y); + } + } + + // Called if the game frame is deactivated because the tabled the deck editor or other frames go to foreground + public void deactivated() { + // hide the non modal windows (because otherwise they are shown on top of the new active pane) + for (CardInfoWindowDialog exileDialog : exiles.values()) { + exileDialog.hideDialog(); + } + for (CardInfoWindowDialog graveyardDialog : graveyardWindows.values()) { + graveyardDialog.hideDialog(); + } + for (CardInfoWindowDialog revealDialog : revealed.values()) { + revealDialog.hideDialog(); + } + for (CardInfoWindowDialog lookedAtDialog : lookedAt.values()) { + lookedAtDialog.hideDialog(); + } + } + + // Called if the game frame comes to front again + public void activated() { + // hide the non modal windows (because otherwise they are shown on top of the new active pane) + for (CardInfoWindowDialog exileDialog : exiles.values()) { + exileDialog.show(); + } + for (CardInfoWindowDialog graveyardDialog : graveyardWindows.values()) { + graveyardDialog.show(); + } + for (CardInfoWindowDialog revealDialog : revealed.values()) { + revealDialog.show(); + } + for (CardInfoWindowDialog lookedAtDialog : lookedAt.values()) { + lookedAtDialog.show(); + } + } + + public void openGraveyardWindow(String playerName) { + if (graveyardWindows.containsKey(playerName)) { + CardInfoWindowDialog cardInfoWindowDialog = graveyardWindows.get(playerName); + if (cardInfoWindowDialog.isVisible()) { + cardInfoWindowDialog.hideDialog(); + } else { + cardInfoWindowDialog.show(); + } + return; + } + CardInfoWindowDialog newGraveyard = new CardInfoWindowDialog(ShowType.GRAVEYARD, playerName); + graveyardWindows.put(playerName, newGraveyard); + MageFrame.getDesktop().add(newGraveyard, JLayeredPane.MODAL_LAYER); + newGraveyard.loadCards(graveyards.get(playerName), bigCard, gameId, false); + } + + public void openTopLibraryWindow(String playerName) { + String title = playerName + "'s top library card"; + if (revealed.containsKey(title)) { + CardInfoWindowDialog cardInfoWindowDialog = revealed.get(title); + if (cardInfoWindowDialog.isVisible()) { + cardInfoWindowDialog.hideDialog(); + } else { + cardInfoWindowDialog.show(); + } + } + } + + private void showRevealed(GameView game) { + for (RevealedView revealView : game.getRevealed()) { + handleGameInfoWindow(revealed, ShowType.REVEAL, revealView.getName(), revealView.getCards()); + } + removeClosedCardInfoWindows(revealed); + } + + private void showLookedAt(GameView game) { + for (LookedAtView lookedAtView : game.getLookedAt()) { + handleGameInfoWindow(lookedAt, ShowType.LOOKED_AT, lookedAtView.getName(), lookedAtView.getCards()); + } + removeClosedCardInfoWindows(lookedAt); + } + + private void handleGameInfoWindow(Map windowMap, ShowType showType, String name, LinkedHashMap cardsView) { + CardInfoWindowDialog cardInfoWindowDialog; + if (!windowMap.containsKey(name)) { + cardInfoWindowDialog = new CardInfoWindowDialog(showType, name); + windowMap.put(name, cardInfoWindowDialog); + MageFrame.getDesktop().add(cardInfoWindowDialog, JLayeredPane.MODAL_LAYER); + } else { + cardInfoWindowDialog = windowMap.get(name); + } + + if (cardInfoWindowDialog != null && !cardInfoWindowDialog.isClosed()) { + switch (showType) { + case REVEAL: + case REVEAL_TOP_LIBRARY: + cardInfoWindowDialog.loadCards((CardsView) cardsView, bigCard, gameId); + break; + case LOOKED_AT: + cardInfoWindowDialog.loadCards((SimpleCardsView) cardsView, bigCard, gameId); + break; + } + } + } + + private void removeClosedCardInfoWindows(Map windowMap) { + // Remove closed window objects from the maps + for (Iterator> iterator = windowMap.entrySet().iterator(); iterator.hasNext();) { + Map.Entry entry = iterator.next(); + if (entry.getValue().isClosed()) { + iterator.remove(); + } + } + } + + public void ask(String question, GameView gameView, int messageId, Map options) { + updateGame(gameView); + this.feedbackPanel.getFeedback(FeedbackMode.QUESTION, question, false, options, messageId); + } + + /** + * Shows a pick target dialog and allows the player to pick a target (e.g. + * the pick triggered ability) + * + * @param message + * @param cardView + * @param gameView + * @param targets + * @param required + * @param options + * @param messageId + */ + public void pickTarget(String message, CardsView cardView, GameView gameView, Set targets, boolean required, Map options, int messageId) { + PopUpMenuType popupMenuType = null; + if (options != null) { + if (options.containsKey("targetZone")) { + if (Zone.HAND.equals(options.get("targetZone"))) { // mark selectable target cards in hand + List choosen = null; + if (options.containsKey("chosen")) { + choosen = (List) options.get("chosen"); + } + for (CardView card : gameView.getHand().values()) { + if (targets == null || targets.isEmpty()) { + card.setPlayable(false); + card.setChoosable(true); + } else if (targets.contains(card.getId())) { + card.setPlayable(false); + card.setChoosable(true); + } + if (choosen != null && choosen.contains(card.getId())) { + card.setSelected(true); + } + } + } + } + if (options.containsKey("queryType") && PlayerQueryEvent.QueryType.PICK_ABILITY.equals(options.get("queryType"))) { + popupMenuType = PopUpMenuType.TRIGGER_ORDER; + } + } + updateGame(gameView); + Map options0 = options == null ? new HashMap<>() : options; + ShowCardsDialog dialog = null; + if (cardView != null && cardView.size() > 0) { + dialog = showCards(message, cardView, required, options0, popupMenuType); + options0.put("dialog", dialog); + } + this.feedbackPanel.getFeedback(required ? FeedbackMode.INFORM : FeedbackMode.CANCEL, message, gameView.getSpecial(), options0, messageId); + if (dialog != null) { + this.pickTarget.add(dialog); + } + } + + public void inform(String information, GameView gameView, int messageId) { + updateGame(gameView); + this.feedbackPanel.getFeedback(FeedbackMode.INFORM, information, gameView.getSpecial(), null, messageId); + } + + public void endMessage(String message, int messageId) { + this.feedbackPanel.getFeedback(FeedbackMode.END, message, false, null, messageId); + ArrowBuilder.getBuilder().removeAllArrows(gameId); + } + + public void select(String message, GameView gameView, int messageId, Map options) { + holdingPriority = false; + txtHoldPriority.setVisible(false); + setMenuStates( + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), + false); + + updateGame(gameView, options); + boolean controllingPlayer = false; + for (PlayerView playerView : gameView.getPlayers()) { + if (playerView.getPlayerId().equals(playerId)) { + // magenoxx: because of uncaught bug with saving state, rolling back and stack + // undo is allowed only for empty stack + controllingPlayer = !gameView.getPriorityPlayerName().equals(playerView.getName()); + if (playerView.getStatesSavedSize() > 0 && gameView.getStack().isEmpty()) { + feedbackPanel.allowUndo(playerView.getStatesSavedSize()); + } + break; + } + + } + Map panelOptions = new HashMap<>(); + if (options != null) { + panelOptions.putAll(options); + } + panelOptions.put("your_turn", true); + String activePlayerText; + if (gameView.getActivePlayerId().equals(playerId)) { + activePlayerText = "Your turn"; + } else { + activePlayerText = gameView.getActivePlayerName() + "'s turn"; + } + String priorityPlayerText = ""; + if (controllingPlayer) { + priorityPlayerText = " / priority " + gameView.getPriorityPlayerName(); + } + String messageToDisplay = message + FeedbackPanel.getSmallText(activePlayerText + " / " + gameView.getStep().toString() + priorityPlayerText); + this.feedbackPanel.getFeedback(FeedbackMode.SELECT, messageToDisplay, gameView.getSpecial(), panelOptions, messageId); + } + + public void playMana(String message, GameView gameView, Map options, int messageId) { + updateGame(gameView); + DialogManager.getManager(gameId).fadeOut(); + this.feedbackPanel.getFeedback(FeedbackMode.CANCEL, message, gameView.getSpecial(), options, messageId); + } + + public void playXMana(String message, GameView gameView, int messageId) { + updateGame(gameView); + DialogManager.getManager(gameId).fadeOut(); + this.feedbackPanel.getFeedback(FeedbackMode.CONFIRM, message, gameView.getSpecial(), null, messageId); + } + + public void replayMessage(String message) { + //TODO: implement this + } + + public void pickAbility(AbilityPickerView choices) { + hideAll(); + DialogManager.getManager(gameId).fadeOut(); + this.abilityPicker.show(choices, MageFrame.getDesktop().getMousePosition()); + } + + private void hideAll() { + ActionCallback callback = Plugins.getInstance().getActionCallback(); + ((MageActionCallback) callback).hideGameUpdate(gameId); + } + + private ShowCardsDialog showCards(String title, CardsView cards, boolean required, Map options, PopUpMenuType popupMenuType) { + hideAll(); + ShowCardsDialog showCards = new ShowCardsDialog(); + JPopupMenu popupMenu = null; + if (PopUpMenuType.TRIGGER_ORDER.equals(popupMenuType)) { + popupMenu = popupMenuTriggerOrder; + } + showCards.loadCards(title, cards, bigCard, gameId, required, options, popupMenu, getShowCardsEventListener(showCards)); + return showCards; + } + + public void getAmount(int min, int max, String message) { + pickNumber.showDialog(min, max, message); + if (pickNumber.isCancel()) { + SessionHandler.sendPlayerBoolean(gameId, false); + } else { + SessionHandler.sendPlayerInteger(gameId, pickNumber.getAmount()); + } + } + + public void getChoice(Choice choice, UUID objectId) { + hideAll(); + PickChoiceDialog pickChoice = new PickChoiceDialog(); + pickChoice.showDialog(choice, objectId, choiceWindowState); + if (choice.isKeyChoice()) { + if (pickChoice.isAutoSelect()) { + SessionHandler.sendPlayerString(gameId, "#" + choice.getChoiceKey()); + } else { + SessionHandler.sendPlayerString(gameId, choice.getChoiceKey()); + } + } else { + SessionHandler.sendPlayerString(gameId, choice.getChoice()); + } + choiceWindowState = new MageDialogState(pickChoice); + pickChoice.removeDialog(); + } + + public void pickPile(String message, CardsView pile1, CardsView pile2) { + hideAll(); + PickPileDialog pickPileDialog = new PickPileDialog(); + pickPileDialog.loadCards(message, pile1, pile2, bigCard, gameId); + SessionHandler.sendPlayerBoolean(gameId, pickPileDialog.isPickedPile1()); + pickPileDialog.cleanUp(); + pickPileDialog.removeDialog(); + } + + public Map getPlayers() { + return players; + } + + @SuppressWarnings("unchecked") + private void initComponents() { + + abilityPicker = new mage.client.components.ability.AbilityPicker(); + jSplitPane1 = new javax.swing.JSplitPane(); + jSplitPane0 = new javax.swing.JSplitPane(); + jPanel2 = new javax.swing.JPanel(); + pnlHelperHandButtonsStackArea = new javax.swing.JPanel(); + pnlShortCuts = new javax.swing.JPanel(); + lblPhase = new javax.swing.JLabel(); + txtPhase = new javax.swing.JLabel(); + lblStep = new javax.swing.JLabel(); + txtStep = new javax.swing.JLabel(); + lblTurn = new javax.swing.JLabel(); + txtTurn = new javax.swing.JLabel(); + txtActivePlayer = new javax.swing.JLabel(); + lblActivePlayer = new javax.swing.JLabel(); + txtPriority = new javax.swing.JLabel(); + lblPriority = new javax.swing.JLabel(); + feedbackPanel = new mage.client.game.FeedbackPanel(); + + txtSpellsCast = new javax.swing.JLabel(); + Border paddingBorder = BorderFactory.createEmptyBorder(4, 4, 4, 4); + Border border = BorderFactory.createLineBorder(Color.DARK_GRAY, 2); + txtSpellsCast.setBorder(BorderFactory.createCompoundBorder(border, paddingBorder)); + txtSpellsCast.setBackground(Color.LIGHT_GRAY); + txtSpellsCast.setOpaque(true); + txtSpellsCast.setToolTipText("spells cast during the current turn"); + + txtHoldPriority = new javax.swing.JLabel(); + txtHoldPriority.setText("Hold"); + txtHoldPriority.setBorder(BorderFactory.createCompoundBorder(border, paddingBorder)); + txtHoldPriority.setBackground(Color.LIGHT_GRAY); + txtHoldPriority.setOpaque(true); + txtHoldPriority.setToolTipText("Holding priority after the next spell cast or ability activation"); + txtHoldPriority.setVisible(false); + + btnCancelSkip = new KeyboundButton(KEY_CONTROL_CANCEL_SKIP); // F3 + btnSkipToNextTurn = new KeyboundButton(KEY_CONTROL_NEXT_TURN); // F4 + btnSkipToEndTurn = new KeyboundButton(KEY_CONTROL_END_STEP); // F5 + btnSkipToNextMain = new KeyboundButton(KEY_CONTROL_MAIN_STEP); // F7 + btnSkipStack = new KeyboundButton(KEY_CONTROL_SKIP_STACK); // F10 + btnSkipToYourTurn = new KeyboundButton(KEY_CONTROL_YOUR_TURN); // F9 + btnSkipToEndStepBeforeYourTurn = new KeyboundButton(KEY_CONTROL_PRIOR_END); // F11 + + btnConcede = new javax.swing.JButton(); + btnSwitchHands = new javax.swing.JButton(); + btnStopWatching = new javax.swing.JButton(); + + bigCard = new mage.client.cards.BigCard(); + pnlReplay = new javax.swing.JPanel(); + btnStopReplay = new javax.swing.JButton(); + btnNextPlay = new javax.swing.JButton(); + btnPlay = new javax.swing.JButton(); + btnSkipForward = new javax.swing.JButton(); + btnPreviousPlay = new javax.swing.JButton(); + pnlBattlefield = new javax.swing.JPanel(); + gameChatPanel = new mage.client.chat.ChatPanelBasic(); + gameChatPanel.useExtendedView(ChatPanelBasic.VIEW_MODE.GAME); + userChatPanel = new mage.client.chat.ChatPanelBasic(); + userChatPanel.setParentChat(gameChatPanel); + userChatPanel.useExtendedView(ChatPanelBasic.VIEW_MODE.CHAT); + userChatPanel.setChatType(ChatPanelBasic.ChatType.GAME); + gameChatPanel.setConnectedChat(userChatPanel); + gameChatPanel.disableInput(); + gameChatPanel.setMinimumSize(new java.awt.Dimension(100, 48)); + gameChatPanel.enableHyperlinks(); + jSplitPane2 = new javax.swing.JSplitPane(); + handContainer = new HandPanel(); + handCards = new HashMap<>(); + + pnlShortCuts.setOpaque(false); + pnlShortCuts.setPreferredSize(new Dimension(410, 72)); + + stackObjects = new mage.client.cards.Cards(); + + jSplitPane1.setBorder(null); + jSplitPane1.setDividerSize(7); + jSplitPane1.setResizeWeight(1.0); + jSplitPane1.setOneTouchExpandable(true); + jSplitPane1.setMinimumSize(new java.awt.Dimension(26, 48)); + + jSplitPane0.setBorder(null); + jSplitPane0.setDividerSize(7); + jSplitPane0.setResizeWeight(1.0); + jSplitPane0.setOneTouchExpandable(true); + + restoreDividerLocations(); + + lblPhase.setLabelFor(txtPhase); + lblPhase.setText("Phase:"); + + txtPhase.setText("Phase"); + txtPhase.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true)); + txtPhase.setMinimumSize(new java.awt.Dimension(0, 16)); + + lblStep.setLabelFor(txtStep); + lblStep.setText("Step:"); + + txtStep.setText("Step"); + txtStep.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true)); + txtStep.setMinimumSize(new java.awt.Dimension(0, 16)); + + lblTurn.setLabelFor(txtTurn); + lblTurn.setText("Turn:"); + + txtTurn.setText("Turn"); + txtTurn.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true)); + txtTurn.setMinimumSize(new java.awt.Dimension(0, 16)); + + txtActivePlayer.setText("Active Player"); + txtActivePlayer.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true)); + txtActivePlayer.setMinimumSize(new java.awt.Dimension(0, 16)); + + lblActivePlayer.setLabelFor(txtActivePlayer); + lblActivePlayer.setText("Active Player:"); + + txtPriority.setText("Priority Player"); + txtPriority.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true)); + txtPriority.setMinimumSize(new java.awt.Dimension(0, 16)); + + lblPriority.setLabelFor(txtPriority); + lblPriority.setText("Priority Player:"); + + bigCard.setBorder(new LineBorder(Color.black, 1, true)); + + int c = JComponent.WHEN_IN_FOCUSED_WINDOW; + + KeyStroke ks3 = getCachedKeystroke(KEY_CONTROL_CANCEL_SKIP); + this.getInputMap(c).put(ks3, "F3_PRESS"); + this.getActionMap().put("F3_PRESS", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + restorePriorityActionPerformed(actionEvent); + } + }); + + btnCancelSkip.setContentAreaFilled(false); + btnCancelSkip.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + btnCancelSkip.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getCancelSkipButtonImage())); + btnCancelSkip.setToolTipText("Cancel all skip actions (" + + getCachedKeyText(KEY_CONTROL_CANCEL_SKIP) + ")."); + btnCancelSkip.setFocusable(false); + btnCancelSkip.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent evt) { + if (evt.getButton() == MouseEvent.BUTTON1) { + restorePriorityActionPerformed(null); + } + } + }); + + btnSkipToNextTurn.setContentAreaFilled(false); + btnSkipToNextTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + btnSkipToNextTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipNextTurnButtonImage())); + btnSkipToNextTurn.setToolTipText("Skip to next turn (" + + getCachedKeyText(KEY_CONTROL_NEXT_TURN) + ")."); + btnSkipToNextTurn.setFocusable(false); + btnSkipToNextTurn.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent evt) { + if (evt.getButton() == MouseEvent.BUTTON1) { + btnEndTurnActionPerformed(null); + } + } + }); + + KeyStroke ks = getCachedKeystroke(KEY_CONTROL_NEXT_TURN); + this.getInputMap(c).put(ks, "F4_PRESS"); + this.getActionMap().put("F4_PRESS", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + btnEndTurnActionPerformed(actionEvent); + } + }); + + btnSkipToEndTurn.setContentAreaFilled(false); + btnSkipToEndTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + btnSkipToEndTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipEndTurnButtonImage())); + btnSkipToEndTurn.setToolTipText("Skip to (opponents/next) end of turn step (" + + getCachedKeyText(KEY_CONTROL_END_STEP) + ") - adjust using preferences."); + btnSkipToEndTurn.setFocusable(false); + btnSkipToEndTurn.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent evt) { + if (evt.getButton() == MouseEvent.BUTTON1) { + btnUntilEndOfTurnActionPerformed(null); + } + } + }); + + ks = getCachedKeystroke(KEY_CONTROL_END_STEP); + this.getInputMap(c).put(ks, "F5_PRESS"); + this.getActionMap().put("F5_PRESS", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + btnUntilEndOfTurnActionPerformed(actionEvent); + } + }); + + ks = getCachedKeystroke(KEY_CONTROL_SKIP_STEP); + this.getInputMap(c).put(ks, "F6_PRESS"); + this.getActionMap().put("F6_PRESS", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + btnEndTurnSkipStackActionPerformed(actionEvent); + } + }); + + btnSkipToNextMain.setContentAreaFilled(false); + btnSkipToNextMain.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + btnSkipToNextMain.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipMainButtonImage())); + btnSkipToNextMain.setToolTipText("Skip to (your) next main phase (" + + getCachedKeyText(KEY_CONTROL_MAIN_STEP) + ") - adjust using preferences."); + btnSkipToNextMain.setFocusable(false); + btnSkipToNextMain.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent evt) { + if (evt.getButton() == MouseEvent.BUTTON1) { + btnUntilNextMainPhaseActionPerformed(null); + } + } + }); + + ks = getCachedKeystroke(KEY_CONTROL_MAIN_STEP); + this.getInputMap(c).put(ks, "F7_PRESS"); + this.getActionMap().put("F7_PRESS", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + btnUntilNextMainPhaseActionPerformed(actionEvent); + } + }); + + btnSkipToYourTurn.setContentAreaFilled(false); + btnSkipToYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + btnSkipToYourTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipYourNextTurnButtonImage())); + btnSkipToYourTurn.setToolTipText("Skip to your next turn (" + + getCachedKeyText(KEY_CONTROL_YOUR_TURN) + ")."); + btnSkipToYourTurn.setFocusable(false); + btnSkipToYourTurn.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent evt) { + if (evt.getButton() == MouseEvent.BUTTON1) { + btnPassPriorityUntilNextYourTurnActionPerformed(null); + } + } + }); + + KeyStroke ks9 = getCachedKeystroke(KEY_CONTROL_YOUR_TURN); + this.getInputMap(c).put(ks9, "F9_PRESS"); + this.getActionMap().put("F9_PRESS", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + btnPassPriorityUntilNextYourTurnActionPerformed(actionEvent); + } + }); + + btnSkipToEndStepBeforeYourTurn.setContentAreaFilled(false); + btnSkipToEndStepBeforeYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + btnSkipToEndStepBeforeYourTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipEndStepBeforeYourTurnButtonImage())); + btnSkipToEndStepBeforeYourTurn.setToolTipText("Skip to the end step before your turn (" + + getCachedKeyText(KEY_CONTROL_PRIOR_END) + ") - adjust using preferences."); + btnSkipToEndStepBeforeYourTurn.setFocusable(false); + btnSkipToEndStepBeforeYourTurn.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent evt) { + if (evt.getButton() == MouseEvent.BUTTON1) { + btnSkipToEndStepBeforeYourTurnActionPerformed(null); + } + } + }); + + KeyStroke ks11 = getCachedKeystroke(KEY_CONTROL_PRIOR_END); + this.getInputMap(c).put(ks11, "F11_PRESS"); + this.getActionMap().put("F11_PRESS", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + btnSkipToEndStepBeforeYourTurnActionPerformed(actionEvent); + } + }); + + btnSkipStack.setContentAreaFilled(false); + btnSkipStack.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + btnSkipStack.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipStackButtonImage())); + btnSkipStack.setToolTipText("Skip until stack is resolved (" + + getCachedKeyText(KEY_CONTROL_SKIP_STACK) + ")."); + btnSkipStack.setFocusable(false); + btnSkipStack.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent evt) { + if (evt.getButton() == MouseEvent.BUTTON1) { + btnPassPriorityUntilStackResolvedActionPerformed(null); + } + } + }); + + ks = getCachedKeystroke(KEY_CONTROL_SKIP_STACK); + this.getInputMap(c).put(ks, "F10_PRESS"); + this.getActionMap().put("F10_PRESS", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + btnPassPriorityUntilStackResolvedActionPerformed(actionEvent); + } + }); + + btnConcede.setContentAreaFilled(false); + btnConcede.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); + btnConcede.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getConcedeButtonImage())); + btnConcede.setToolTipText("Concede the current game."); + btnConcede.setFocusable(false); + btnConcede.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent evt) { + if (evt.getButton() == MouseEvent.BUTTON1) { + btnConcedeActionPerformed(null); + } + } + }); + + KeyStroke ks2 = getCachedKeystroke(KEY_CONTROL_CONFIRM); + this.getInputMap(c).put(ks2, "F2_PRESS"); + this.getActionMap().put("F2_PRESS", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (feedbackPanel != null) { + feedbackPanel.pressOKYesOrDone(); + } + } + }); + + KeyStroke ksAltE = KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK); + this.getInputMap(c).put(ksAltE, "ENLARGE"); + this.getActionMap().put("ENLARGE", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + ActionCallback callback = Plugins.getInstance().getActionCallback(); + ((MageActionCallback) callback).enlargeCard(EnlargeMode.NORMAL); + } + }); + + KeyStroke ksAltS = KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK); + this.getInputMap(c).put(ksAltS, "ENLARGE_SOURCE"); + this.getActionMap().put("ENLARGE_SOURCE", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + ActionCallback callback = Plugins.getInstance().getActionCallback(); + ((MageActionCallback) callback).enlargeCard(EnlargeMode.ALTERNATE); + } + }); + + KeyStroke ksAltD = KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.ALT_MASK); + this.getInputMap(c).put(ksAltD, "BIG_IMAGE"); + this.getActionMap().put("BIG_IMAGE", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + imagePanelState = !imagePanelState; + if (!imagePanelState) { + jSplitPane0.resetToPreferredSizes(); + jSplitPane0.setDividerLocation(jSplitPane0.getSize().width - jSplitPane0.getInsets().right - jSplitPane0.getDividerSize() - 260); + } else { + jSplitPane0.setDividerLocation(1.0); + } + } + }); + + KeyStroke ksAlt1 = KeyStroke.getKeyStroke(KeyEvent.VK_1, InputEvent.ALT_MASK); + this.getInputMap(c).put(ksAlt1, "USEFIRSTMANAABILITY"); + this.getActionMap().put("USEFIRSTMANAABILITY", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + SessionHandler.sendPlayerAction(PlayerAction.USE_FIRST_MANA_ABILITY_ON, gameId, null); + setMenuStates( + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), + holdingPriority); + } + }); + + final BasicSplitPaneUI myUi = (BasicSplitPaneUI) jSplitPane0.getUI(); + final BasicSplitPaneDivider divider = myUi.getDivider(); + final JButton upArrowButton = (JButton) divider.getComponent(0); + upArrowButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + PreferencesDialog.saveValue(PreferencesDialog.KEY_BIG_CARD_TOGGLED, "up"); + } + }); + + final JButton downArrowButton = (JButton) divider.getComponent(1); + downArrowButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + PreferencesDialog.saveValue(PreferencesDialog.KEY_BIG_CARD_TOGGLED, "down"); + } + }); + + KeyStroke ksAltEReleased = KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK, true); + this.getInputMap(c).put(ksAltEReleased, "ENLARGE_RELEASE"); + KeyStroke ksAltSReleased = KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK, true); + this.getInputMap(c).put(ksAltSReleased, "ENLARGE_RELEASE"); + this.getActionMap().put("ENLARGE_RELEASE", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + ActionCallback callback = Plugins.getInstance().getActionCallback(); + ((MageActionCallback) callback).hideEnlargedCard(); + } + }); + + KeyStroke ksAlt1Released = KeyStroke.getKeyStroke(KeyEvent.VK_1, InputEvent.ALT_MASK, true); + this.getInputMap(c).put(ksAlt1Released, "USEFIRSTMANAABILITY_RELEASE"); + this.getActionMap().put("USEFIRSTMANAABILITY_RELEASE", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + SessionHandler.sendPlayerAction(PlayerAction.USE_FIRST_MANA_ABILITY_OFF, gameId, null); + setMenuStates( + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), + holdingPriority); + } + }); + + btnSwitchHands.setContentAreaFilled(false); + btnSwitchHands.setBorder(new EmptyBorder(0, 0, 0, 0)); + btnSwitchHands.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSwitchHandsButtonImage())); + btnSwitchHands.setFocusable(false); + btnSwitchHands.setToolTipText("Switch between your hand cards and hand cards of controlled players."); + btnSwitchHands.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent evt) { + if (evt.getButton() == MouseEvent.BUTTON1) { + btnSwitchHandActionPerformed(null); + } + } + }); + + btnStopWatching.setContentAreaFilled(false); + btnStopWatching.setBorder(new EmptyBorder(0, 0, 0, 0)); + btnStopWatching.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getStopWatchButtonImage())); + btnStopWatching.setFocusable(false); + btnStopWatching.setToolTipText("Stop watching this game."); + btnStopWatching.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent evt) { + if (evt.getButton() == MouseEvent.BUTTON1) { + btnStopWatchingActionPerformed(null); + } + } + }); + + stackObjects.setBackgroundColor(new Color(0, 0, 0, 40)); + + btnStopReplay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_stop.png"))); + btnStopReplay.addActionListener(new java.awt.event.ActionListener() { + @Override + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnStopReplayActionPerformed(evt); + } + }); + + btnNextPlay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_stop_right.png"))); + btnNextPlay.addActionListener(new java.awt.event.ActionListener() { + @Override + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnNextPlayActionPerformed(evt); + } + }); + + btnPlay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_right.png"))); + btnPlay.addActionListener(new java.awt.event.ActionListener() { + @Override + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnPlayActionPerformed(evt); + } + }); + + btnSkipForward.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_double_stop_right.png"))); + btnSkipForward.addActionListener(new java.awt.event.ActionListener() { + @Override + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnSkipForwardActionPerformed(evt); + } + }); + + btnPreviousPlay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/control_stop_left.png"))); + btnPreviousPlay.addActionListener(new java.awt.event.ActionListener() { + @Override + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnPreviousPlayActionPerformed(evt); + } + }); + + initPopupMenuTriggerOrder(); + + setGUISize(); + + // Replay panel to control replay of games + javax.swing.GroupLayout gl_pnlReplay = new javax.swing.GroupLayout(pnlReplay); + pnlReplay.setLayout(gl_pnlReplay); + gl_pnlReplay.setHorizontalGroup( + gl_pnlReplay.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(gl_pnlReplay.createSequentialGroup() + .addComponent(btnPreviousPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btnPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(btnStopReplay, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btnNextPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btnSkipForward, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)) + ); + gl_pnlReplay.setVerticalGroup( + gl_pnlReplay.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(btnSkipForward, 0, 0, Short.MAX_VALUE) + .addComponent(btnNextPlay, 0, 0, Short.MAX_VALUE) + .addComponent(btnStopReplay, 0, 0, Short.MAX_VALUE) + .addComponent(btnPlay, 0, 0, Short.MAX_VALUE) + .addComponent(btnPreviousPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 31, Short.MAX_VALUE) + ); + + // Game info panel (buttons on the right panel) + javax.swing.GroupLayout gl_pnlShortCuts = new javax.swing.GroupLayout(pnlShortCuts); + pnlShortCuts.setLayout(gl_pnlShortCuts); + gl_pnlShortCuts.setHorizontalGroup(gl_pnlShortCuts.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(gl_pnlShortCuts.createSequentialGroup() + .addComponent(btnSkipToNextTurn) + .addComponent(btnSkipToEndTurn) + .addComponent(btnSkipToNextMain) + .addComponent(btnSkipToYourTurn) + .addComponent(btnSkipStack) + .addComponent(btnSkipToEndStepBeforeYourTurn) + ) + .addGroup(gl_pnlShortCuts.createSequentialGroup() + .addComponent(txtHoldPriority) + .addComponent(txtSpellsCast) + .addComponent(btnSwitchHands) + .addComponent(btnCancelSkip) + .addComponent(btnConcede) + .addComponent(btnStopWatching) + ) + //.addComponent(bigCard, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE) + //.addComponent(feedbackPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE) + //.addComponent(stack, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE) + + .addGroup(gl_pnlShortCuts.createSequentialGroup() + .addContainerGap() + .addComponent(pnlReplay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(51, Short.MAX_VALUE)) + ); + gl_pnlShortCuts.setVerticalGroup(gl_pnlShortCuts.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(gl_pnlShortCuts.createSequentialGroup() + //.addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + //.addGap(1, 1, 1) + //.addComponent(feedbackPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE) + //.addComponent(stack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 164, Short.MAX_VALUE) + .addComponent(pnlReplay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(gl_pnlShortCuts.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(btnSkipToNextTurn) + .addComponent(btnSkipToEndTurn) + .addComponent(btnSkipToNextMain) + .addComponent(btnSkipToYourTurn) + .addComponent(btnSkipStack) + .addComponent(btnSkipToEndStepBeforeYourTurn) + ) + .addGroup(gl_pnlShortCuts.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(txtHoldPriority) + .addComponent(txtSpellsCast) + .addComponent(btnSwitchHands) + .addComponent(btnCancelSkip) + .addComponent(btnConcede) + .addComponent(btnStopWatching) + ) + ) + ); + + pnlBattlefield.setLayout(new java.awt.GridBagLayout()); + + jPhases = new JPanel(); + jPhases.setBackground(new Color(0, 0, 0, 0)); + jPhases.setLayout(null); + jPhases.setPreferredSize(new Dimension(X_PHASE_WIDTH, 435)); + + MouseAdapter phasesMouseAdapter = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent evt) { + mouseClickPhaseBar(evt); + } + }; + String[] phases = {"Untap", "Upkeep", "Draw", "Main1", + "Combat_Start", "Combat_Attack", "Combat_Block", "Combat_Damage", "Combat_End", + "Main2", "Cleanup", "Next_Turn"}; + for (String name : phases) { + createPhaseButton(name, phasesMouseAdapter); + } + + int i = 0; + for (String name : hoverButtons.keySet()) { + HoverButton hoverButton = hoverButtons.get(name); + hoverButton.setAlignmentX(LEFT_ALIGNMENT); + hoverButton.setBounds(X_PHASE_WIDTH - 36, i * 36, 36, 36); + jPhases.add(hoverButton); + i++; + } + jPhases.addMouseListener(phasesMouseAdapter); + + pnlReplay.setOpaque(false); + + helper = new HelperPanel(); + feedbackPanel.setHelperPanel(helper); + + jSplitPane2.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); + jSplitPane2.setResizeWeight(0.5); + jSplitPane2.setLeftComponent(userChatPanel); + jSplitPane2.setBottomComponent(gameChatPanel); + + phasesContainer = new JPanel(); + phasesContainer.setLayout(new RelativeLayout(RelativeLayout.Y_AXIS)); + phasesContainer.setBackground(new Color(0, 0, 0, 0)); + Float ratio = (float) 1; + JPanel empty1 = new JPanel(); + empty1.setBackground(new Color(0, 0, 0, 0)); + phasesContainer.add(empty1, ratio); + phasesContainer.add(jPhases); + + javax.swing.GroupLayout gl_helperHandButtonsStackArea = new javax.swing.GroupLayout(pnlHelperHandButtonsStackArea); + gl_helperHandButtonsStackArea.setHorizontalGroup( + gl_helperHandButtonsStackArea.createParallelGroup(Alignment.LEADING) + .addGroup(gl_helperHandButtonsStackArea.createSequentialGroup() + // .addGap(0) + .addGroup(gl_helperHandButtonsStackArea.createParallelGroup(Alignment.LEADING) + .addGroup(gl_helperHandButtonsStackArea.createSequentialGroup() + .addGroup(gl_helperHandButtonsStackArea.createParallelGroup(Alignment.LEADING) + .addComponent(helper, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(handContainer, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ) + .addGroup(gl_helperHandButtonsStackArea.createParallelGroup(Alignment.LEADING) + .addComponent(pnlShortCuts, 410, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) + .addComponent(stackObjects, 410, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) + ) + ) + .addGap(0) + //.addComponent(jPhases, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(gl_helperHandButtonsStackArea.createSequentialGroup() + .addComponent(pnlBattlefield, GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE) + .addComponent(phasesContainer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + ))) + ); + gl_helperHandButtonsStackArea.setVerticalGroup( + gl_helperHandButtonsStackArea.createParallelGroup(Alignment.TRAILING) + .addGroup(gl_helperHandButtonsStackArea.createSequentialGroup() + .addGroup(gl_helperHandButtonsStackArea.createParallelGroup(Alignment.LEADING) + .addComponent(pnlBattlefield, GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE) + .addComponent(phasesContainer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + ) + //.addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl_helperHandButtonsStackArea.createParallelGroup(Alignment.LEADING) + .addGroup(gl_helperHandButtonsStackArea.createSequentialGroup() + .addGap(2) + .addComponent(pnlShortCuts, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(stackObjects, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + ) + .addGroup(gl_helperHandButtonsStackArea.createSequentialGroup() + .addComponent(helper, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(handContainer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + ) + ) + ) + ); + pnlHelperHandButtonsStackArea.setLayout(gl_helperHandButtonsStackArea); + + jSplitPane1.setLeftComponent(pnlHelperHandButtonsStackArea); + jSplitPane1.setRightComponent(jSplitPane2); + + // Set individual area sizes of big card pane + GridBagLayout gbl = new GridBagLayout(); + jPanel2.setLayout(gbl); + + GridBagConstraints gbc = new GridBagConstraints(); + gbc.fill = GridBagConstraints.BOTH; + gbc.gridx = 0; + gbc.gridy = 0; + gbc.gridwidth = 1; + gbc.gridheight = 4; // size 4/5 + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gbl.setConstraints(bigCard, gbc); + jPanel2.add(bigCard); + + jPanel2.setOpaque(false); + + // game pane and chat/log pane + jSplitPane0.setLeftComponent(jSplitPane1); + // big card and buttons + jSplitPane0.setRightComponent(jPanel2); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jSplitPane0, javax.swing.GroupLayout.DEFAULT_SIZE, 1078, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jSplitPane0, javax.swing.GroupLayout.DEFAULT_SIZE, 798, Short.MAX_VALUE) + ); + } + + private void removeListener() { + for (MouseListener ml : this.getMouseListeners()) { + this.removeMouseListener(ml); + } + for (MouseListener ml : this.btnCancelSkip.getMouseListeners()) { + this.btnCancelSkip.removeMouseListener(ml); + } + for (MouseListener ml : this.btnConcede.getMouseListeners()) { + this.btnConcede.removeMouseListener(ml); + } + for (MouseListener ml : this.btnSkipToYourTurn.getMouseListeners()) { + this.btnSkipToYourTurn.removeMouseListener(ml); + } + for (MouseListener ml : this.btnSkipStack.getMouseListeners()) { + this.btnSkipStack.removeMouseListener(ml); + } + for (MouseListener ml : this.btnSkipToEndStepBeforeYourTurn.getMouseListeners()) { + this.btnSkipToEndStepBeforeYourTurn.removeMouseListener(ml); + } + for (MouseListener ml : this.btnSkipToEndTurn.getMouseListeners()) { + this.btnSkipToEndTurn.removeMouseListener(ml); + } + for (MouseListener ml : this.btnSkipToNextMain.getMouseListeners()) { + this.btnSkipToNextMain.removeMouseListener(ml); + } + for (MouseListener ml : this.btnSkipToNextTurn.getMouseListeners()) { + this.btnSkipToNextTurn.removeMouseListener(ml); + } + for (MouseListener ml : this.btnSwitchHands.getMouseListeners()) { + this.btnSwitchHands.removeMouseListener(ml); + } + for (MouseListener ml : this.btnStopWatching.getMouseListeners()) { + this.btnStopWatching.removeMouseListener(ml); + } + for (MouseListener ml : this.jPhases.getMouseListeners()) { + this.jPhases.removeMouseListener(ml); + } + for (String name : hoverButtons.keySet()) { + HoverButton hoverButton = hoverButtons.get(name); + for (MouseListener ml : hoverButton.getMouseListeners()) { + hoverButton.removeMouseListener(ml); + } + } + for (ActionListener al : this.btnPlay.getActionListeners()) { + this.btnPlay.removeActionListener(al); + } + for (ActionListener al : this.btnStopReplay.getActionListeners()) { + this.btnStopReplay.removeActionListener(al); + } + for (ActionListener al : this.btnNextPlay.getActionListeners()) { + this.btnNextPlay.removeActionListener(al); + } + for (ActionListener al : this.btnNextPlay.getActionListeners()) { + this.btnNextPlay.removeActionListener(al); + } + for (ActionListener al : this.btnPreviousPlay.getActionListeners()) { + this.btnPreviousPlay.removeActionListener(al); + } + for (ActionListener al : this.btnSkipForward.getActionListeners()) { + this.btnSkipForward.removeActionListener(al); + } + + final BasicSplitPaneUI myUi = (BasicSplitPaneUI) jSplitPane0.getUI(); + final BasicSplitPaneDivider divider = myUi.getDivider(); + final JButton upArrowButton = (JButton) divider.getComponent(0); + for (ActionListener al : upArrowButton.getActionListeners()) { + upArrowButton.removeActionListener(al); + } + final JButton downArrowButton = (JButton) divider.getComponent(1); + for (ActionListener al : downArrowButton.getActionListeners()) { + downArrowButton.removeActionListener(al); + } + + for (ComponentListener cl : this.getComponentListeners()) { + this.removeComponentListener(cl); + } + } + + private void btnConcedeActionPerformed(java.awt.event.ActionEvent evt) { + UserRequestMessage message = new UserRequestMessage("Confirm concede", "Are you sure you want to concede?"); + message.setButton1("No", null); + message.setButton2("Yes", PlayerAction.CLIENT_CONCEDE_GAME); + message.setGameId(gameId); + MageFrame.getInstance().showUserRequestDialog(message); + } + + private void btnEndTurnActionPerformed(java.awt.event.ActionEvent evt) { + SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN, gameId, null); + AudioManager.playOnSkipButton(); + updateSkipButtons(true, false, false, false, false, false); + } + + private void btnUntilEndOfTurnActionPerformed(java.awt.event.ActionEvent evt) { + SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_TURN_END_STEP, gameId, null); + AudioManager.playOnSkipButton(); + updateSkipButtons(false, true, false, false, false, false); + } + + private void btnEndTurnSkipStackActionPerformed(java.awt.event.ActionEvent evt) { + SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN_SKIP_STACK, gameId, null); + AudioManager.playOnSkipButton(); + updateSkipButtons(true, false, false, false, true, false); + } + + private void btnUntilNextMainPhaseActionPerformed(java.awt.event.ActionEvent evt) { + SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_MAIN_PHASE, gameId, null); + AudioManager.playOnSkipButton(); + updateSkipButtons(false, false, true, false, false, false); + } + + private void btnPassPriorityUntilNextYourTurnActionPerformed(java.awt.event.ActionEvent evt) { + SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_MY_NEXT_TURN, gameId, null); + AudioManager.playOnSkipButton(); + updateSkipButtons(false, false, false, true, false, false); + } + + private void btnPassPriorityUntilStackResolvedActionPerformed(java.awt.event.ActionEvent evt) { + SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_STACK_RESOLVED, gameId, null); + AudioManager.playOnSkipButton(); + updateSkipButtons(false, false, false, false, true, false); + } + + private void btnSkipToEndStepBeforeYourTurnActionPerformed(java.awt.event.ActionEvent evt) { + SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_END_STEP_BEFORE_MY_NEXT_TURN, gameId, null); + AudioManager.playOnSkipButton(); + updateSkipButtons(false, false, false, false, false, true); + } + + private void restorePriorityActionPerformed(java.awt.event.ActionEvent evt) { + SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_CANCEL_ALL_ACTIONS, gameId, null); + AudioManager.playOnSkipButtonCancel(); + updateSkipButtons(false, false, false, false, false, false); + } + + private void mouseClickPhaseBar(MouseEvent evt) { + if (evt.getButton() == MouseEvent.BUTTON1) { // Left button + PreferencesDialog.main(new String[]{PreferencesDialog.OPEN_PHASES_TAB}); + } + } + + private void btnSwitchHandActionPerformed(java.awt.event.ActionEvent evt) { + String[] choices = handCards.keySet().toArray(new String[0]); + + String newChosenHandKey = (String) JOptionPane.showInputDialog( + this, + "Choose hand to display:", "Switch between hands", + JOptionPane.PLAIN_MESSAGE, + null, + choices, + this.chosenHandKey); + + if (newChosenHandKey != null && newChosenHandKey.length() > 0) { + this.chosenHandKey = newChosenHandKey; + CardsView cards = handCards.get(chosenHandKey); + handContainer.loadCards(cards, bigCard, gameId); + } + } private void btnStopWatchingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopWatchingActionPerformed - UserRequestMessage message = new UserRequestMessage("Stop watching", "Are you sure you want to stop watching?"); - message.setButton1("No", null); - message.setButton2("Yes", PlayerAction.CLIENT_STOP_WATCHING); - message.setGameId(gameId); - MageFrame.getInstance().showUserRequestDialog(message); + UserRequestMessage message = new UserRequestMessage("Stop watching", "Are you sure you want to stop watching?"); + message.setButton1("No", null); + message.setButton2("Yes", PlayerAction.CLIENT_STOP_WATCHING); + message.setGameId(gameId); + MageFrame.getInstance().showUserRequestDialog(message); }//GEN-LAST:event_btnStopWatchingActionPerformed private void btnStopReplayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopReplayActionPerformed - if (replayTask != null && !replayTask.isDone()) { - replayTask.cancel(true); - } else { - UserRequestMessage message = new UserRequestMessage("Stop replay", "Are you sure you want to stop replay?"); - message.setButton1("No", null); - message.setButton2("Yes", PlayerAction.CLIENT_REPLAY_ACTION); - message.setGameId(gameId); - MageFrame.getInstance().showUserRequestDialog(message); - } + if (replayTask != null && !replayTask.isDone()) { + replayTask.cancel(true); + } else { + UserRequestMessage message = new UserRequestMessage("Stop replay", "Are you sure you want to stop replay?"); + message.setButton1("No", null); + message.setButton2("Yes", PlayerAction.CLIENT_REPLAY_ACTION); + message.setGameId(gameId); + MageFrame.getInstance().showUserRequestDialog(message); + } }//GEN-LAST:event_btnStopReplayActionPerformed private void btnNextPlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextPlayActionPerformed - SessionHandler.nextPlay(gameId); + SessionHandler.nextPlay(gameId); }//GEN-LAST:event_btnNextPlayActionPerformed private void btnPreviousPlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPreviousPlayActionPerformed - SessionHandler.previousPlay(gameId); + SessionHandler.previousPlay(gameId); }//GEN-LAST:event_btnPreviousPlayActionPerformed private void btnPlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPlayActionPerformed - if (replayTask == null || replayTask.isDone()) { - replayTask = new ReplayTask(gameId); - replayTask.execute(); - } + if (replayTask == null || replayTask.isDone()) { + replayTask = new ReplayTask(gameId); + replayTask.execute(); + } }//GEN-LAST:event_btnPlayActionPerformed private void btnSkipForwardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSkipForwardActionPerformed - SessionHandler.skipForward(gameId, 10); + SessionHandler.skipForward(gameId, 10); }//GEN-LAST:event_btnSkipForwardActionPerformed - public void setJLayeredPane(JLayeredPane jLayeredPane) { - this.jLayeredPane = jLayeredPane; - } + public void setJLayeredPane(JLayeredPane jLayeredPane) { + this.jLayeredPane = jLayeredPane; + } - public void installComponents() { - jLayeredPane.setOpaque(false); - jLayeredPane.add(abilityPicker); - jLayeredPane.add(DialogManager.getManager(gameId), JLayeredPane.MODAL_LAYER, 0); - abilityPicker.setVisible(false); - } + public void installComponents() { + jLayeredPane.setOpaque(false); + jLayeredPane.add(abilityPicker); + jLayeredPane.add(DialogManager.getManager(gameId), JLayeredPane.MODAL_LAYER, 0); + abilityPicker.setVisible(false); + } - private void createPhaseButton(String name, MouseAdapter mouseAdapter) { - if (hoverButtons == null) { - hoverButtons = new LinkedHashMap<>(); - } - Rectangle rect = new Rectangle(36, 36); - HoverButton button = new HoverButton("", ImageManagerImpl.getInstance().getPhaseImage(name), rect); - button.setToolTipText(name.replaceAll("_", " ")); - button.setPreferredSize(new Dimension(36, 36)); - button.addMouseListener(mouseAdapter); - hoverButtons.put(name, button); - } + private void createPhaseButton(String name, MouseAdapter mouseAdapter) { + if (hoverButtons == null) { + hoverButtons = new LinkedHashMap<>(); + } + Rectangle rect = new Rectangle(36, 36); + HoverButton button = new HoverButton("", ImageManagerImpl.getInstance().getPhaseImage(name), rect); + button.setToolTipText(name.replaceAll("_", " ")); + button.setPreferredSize(new Dimension(36, 36)); + button.addMouseListener(mouseAdapter); + hoverButtons.put(name, button); + } - // Event listener for the ShowCardsDialog - private Listener getShowCardsEventListener(final ShowCardsDialog dialog) { - return new Listener() { - @Override - public void event(Event event) { - if (event.getEventName().equals("show-popup-menu")) { - if (event.getComponent() != null && event.getComponent() instanceof CardPanel) { - JPopupMenu menu = ((CardPanel) event.getComponent()).getPopupMenu(); - if (menu != null) { - cardViewPopupMenu = ((CardView) event.getSource()); - menu.show(event.getComponent(), event.getxPos(), event.getyPos()); - } - } - } - if (event.getEventName().equals("action-consumed")) { - dialog.removeDialog(); - } - } - }; - } + // Event listener for the ShowCardsDialog + private Listener getShowCardsEventListener(final ShowCardsDialog dialog) { + return new Listener() { + @Override + public void event(Event event) { + if (event.getEventName().equals("show-popup-menu")) { + if (event.getComponent() != null && event.getComponent() instanceof CardPanel) { + JPopupMenu menu = ((CardPanel) event.getComponent()).getPopupMenu(); + if (menu != null) { + cardViewPopupMenu = ((CardView) event.getSource()); + menu.show(event.getComponent(), event.getxPos(), event.getyPos()); + } + } + } + if (event.getEventName().equals("action-consumed")) { + dialog.removeDialog(); + } + } + }; + } - public void handleTriggerOrderPopupMenuEvent(ActionEvent e) { - UUID abilityId = null; - String abilityRuleText = null; - if (cardViewPopupMenu instanceof CardView && cardViewPopupMenu.getAbility() != null) { - abilityId = cardViewPopupMenu.getAbility().getId(); - if (!cardViewPopupMenu.getAbility().getRules().isEmpty() - && !cardViewPopupMenu.getAbility().getRules().get(0).isEmpty()) { - abilityRuleText = cardViewPopupMenu.getAbility().getRules().get(0); - } - } - switch (e.getActionCommand()) { - case CMD_AUTO_ORDER_FIRST: - SessionHandler.sendPlayerAction(TRIGGER_AUTO_ORDER_ABILITY_FIRST, gameId, abilityId); - SessionHandler.sendPlayerUUID(gameId, abilityId); - break; - case CMD_AUTO_ORDER_LAST: - SessionHandler.sendPlayerAction(TRIGGER_AUTO_ORDER_ABILITY_LAST, gameId, abilityId); - SessionHandler.sendPlayerUUID(gameId, null); // Don't use this but refresh the displayed abilities - break; - case CMD_AUTO_ORDER_NAME_FIRST: - if (abilityRuleText != null) { - SessionHandler.sendPlayerAction(TRIGGER_AUTO_ORDER_NAME_FIRST, gameId, abilityRuleText); - SessionHandler.sendPlayerUUID(gameId, abilityId); - } - break; - case CMD_AUTO_ORDER_NAME_LAST: - if (abilityRuleText != null) { - SessionHandler.sendPlayerAction(TRIGGER_AUTO_ORDER_NAME_LAST, gameId, abilityRuleText); - SessionHandler.sendPlayerUUID(gameId, null); // Don't use this but refresh the displayed abilities - } - break; - case CMD_AUTO_ORDER_RESET_ALL: - SessionHandler.sendPlayerAction(TRIGGER_AUTO_ORDER_RESET_ALL, gameId, null); - break; - } - for (ShowCardsDialog dialog : pickTarget) { - dialog.removeDialog(); - } - } + public void handleTriggerOrderPopupMenuEvent(ActionEvent e) { + UUID abilityId = null; + String abilityRuleText = null; + if (cardViewPopupMenu instanceof CardView && cardViewPopupMenu.getAbility() != null) { + abilityId = cardViewPopupMenu.getAbility().getId(); + if (!cardViewPopupMenu.getAbility().getRules().isEmpty() + && !cardViewPopupMenu.getAbility().getRules().get(0).isEmpty()) { + abilityRuleText = cardViewPopupMenu.getAbility().getRules().get(0); + } + } + switch (e.getActionCommand()) { + case CMD_AUTO_ORDER_FIRST: + SessionHandler.sendPlayerAction(TRIGGER_AUTO_ORDER_ABILITY_FIRST, gameId, abilityId); + SessionHandler.sendPlayerUUID(gameId, abilityId); + break; + case CMD_AUTO_ORDER_LAST: + SessionHandler.sendPlayerAction(TRIGGER_AUTO_ORDER_ABILITY_LAST, gameId, abilityId); + SessionHandler.sendPlayerUUID(gameId, null); // Don't use this but refresh the displayed abilities + break; + case CMD_AUTO_ORDER_NAME_FIRST: + if (abilityRuleText != null) { + SessionHandler.sendPlayerAction(TRIGGER_AUTO_ORDER_NAME_FIRST, gameId, abilityRuleText); + SessionHandler.sendPlayerUUID(gameId, abilityId); + } + break; + case CMD_AUTO_ORDER_NAME_LAST: + if (abilityRuleText != null) { + SessionHandler.sendPlayerAction(TRIGGER_AUTO_ORDER_NAME_LAST, gameId, abilityRuleText); + SessionHandler.sendPlayerUUID(gameId, null); // Don't use this but refresh the displayed abilities + } + break; + case CMD_AUTO_ORDER_RESET_ALL: + SessionHandler.sendPlayerAction(TRIGGER_AUTO_ORDER_RESET_ALL, gameId, null); + break; + } + for (ShowCardsDialog dialog : pickTarget) { + dialog.removeDialog(); + } + } - private void initPopupMenuTriggerOrder() { + private void initPopupMenuTriggerOrder() { - ActionListener actionListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - handleTriggerOrderPopupMenuEvent(e); - } - }; + ActionListener actionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + handleTriggerOrderPopupMenuEvent(e); + } + }; - popupMenuTriggerOrder = new JPopupMenu(); + popupMenuTriggerOrder = new JPopupMenu(); - // String tooltipText = ""; - JMenuItem menuItem; - menuItem = new JMenuItem("Put this ability always first on the stack"); - menuItem.setActionCommand(CMD_AUTO_ORDER_FIRST); - menuItem.addActionListener(actionListener); - popupMenuTriggerOrder.add(menuItem); + // String tooltipText = ""; + JMenuItem menuItem; + menuItem = new JMenuItem("Put this ability always first on the stack"); + menuItem.setActionCommand(CMD_AUTO_ORDER_FIRST); + menuItem.addActionListener(actionListener); + popupMenuTriggerOrder.add(menuItem); - menuItem = new JMenuItem("Put this ability always last on the stack"); - menuItem.setActionCommand(CMD_AUTO_ORDER_LAST); - menuItem.addActionListener(actionListener); - popupMenuTriggerOrder.add(menuItem); + menuItem = new JMenuItem("Put this ability always last on the stack"); + menuItem.setActionCommand(CMD_AUTO_ORDER_LAST); + menuItem.addActionListener(actionListener); + popupMenuTriggerOrder.add(menuItem); - menuItem = new JMenuItem("Put all abilities with that rule text always first on the stack"); - menuItem.setActionCommand(CMD_AUTO_ORDER_NAME_FIRST); - menuItem.addActionListener(actionListener); - popupMenuTriggerOrder.add(menuItem); + menuItem = new JMenuItem("Put all abilities with that rule text always first on the stack"); + menuItem.setActionCommand(CMD_AUTO_ORDER_NAME_FIRST); + menuItem.addActionListener(actionListener); + popupMenuTriggerOrder.add(menuItem); - menuItem = new JMenuItem("Put all abilities with that rule text always last on the stack"); - menuItem.setActionCommand(CMD_AUTO_ORDER_NAME_LAST); - menuItem.addActionListener(actionListener); - popupMenuTriggerOrder.add(menuItem); + menuItem = new JMenuItem("Put all abilities with that rule text always last on the stack"); + menuItem.setActionCommand(CMD_AUTO_ORDER_NAME_LAST); + menuItem.addActionListener(actionListener); + popupMenuTriggerOrder.add(menuItem); - menuItem = new JMenuItem("Reset all order settings for triggered abilities"); - menuItem.setActionCommand(CMD_AUTO_ORDER_RESET_ALL); - menuItem.addActionListener(actionListener); - popupMenuTriggerOrder.add(menuItem); - } + menuItem = new JMenuItem("Reset all order settings for triggered abilities"); + menuItem.setActionCommand(CMD_AUTO_ORDER_RESET_ALL); + menuItem.addActionListener(actionListener); + popupMenuTriggerOrder.add(menuItem); + } - public String getGameLog() { - return gameChatPanel.getText(); - } + public String getGameLog() { + return gameChatPanel.getText(); + } - public Map getLoadedCards() { - return loadedCards; - } + public Map getLoadedCards() { + return loadedCards; + } - public void setLoadedCards(Map loadedCards) { - this.loadedCards = loadedCards; - } + public void setLoadedCards(Map loadedCards) { + this.loadedCards = loadedCards; + } - public FeedbackPanel getFeedbackPanel() { - return feedbackPanel; - } + public FeedbackPanel getFeedbackPanel() { + return feedbackPanel; + } - // Use Cmd on OSX since Ctrl+click is already used to simulate right click - private static int holdPriorityMask = System.getProperty("os.name").contains("Mac OS X") ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK; + // Use Cmd on OSX since Ctrl+click is already used to simulate right click + private static int holdPriorityMask = System.getProperty("os.name").contains("Mac OS X") ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK; - public void handleEvent(AWTEvent event) { - if (event instanceof InputEvent) { - int id = event.getID(); - boolean isActionEvent = false; - if (id == MouseEvent.MOUSE_PRESSED) { - isActionEvent = true; - } else if (id == KeyEvent.KEY_PRESSED) { - KeyEvent key = (KeyEvent) event; - int keyCode = key.getKeyCode(); - if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_SPACE) { - isActionEvent = true; - } - } - if (isActionEvent) { - InputEvent input = (InputEvent) event; - if ((input.getModifiersEx() & holdPriorityMask) != 0) { - setMenuStates( - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), - PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), - true); - holdPriority(true); - } - } - } - } + public void handleEvent(AWTEvent event) { + if (event instanceof InputEvent) { + int id = event.getID(); + boolean isActionEvent = false; + if (id == MouseEvent.MOUSE_PRESSED) { + isActionEvent = true; + } else if (id == KeyEvent.KEY_PRESSED) { + KeyEvent key = (KeyEvent) event; + int keyCode = key.getKeyCode(); + if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_SPACE) { + isActionEvent = true; + } + } + if (isActionEvent) { + InputEvent input = (InputEvent) event; + if ((input.getModifiersEx() & holdPriorityMask) != 0) { + setMenuStates( + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, "true").equals("true"), + PreferencesDialog.getCachedValue(KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), + true); + holdPriority(true); + } + } + } + } - public void holdPriority(boolean holdPriority) { - if (holdingPriority != holdPriority) { - holdingPriority = holdPriority; - txtHoldPriority.setVisible(holdPriority); - if (holdPriority) { - SessionHandler.sendPlayerAction(PlayerAction.HOLD_PRIORITY, gameId, null); - } else { - SessionHandler.sendPlayerAction(PlayerAction.UNHOLD_PRIORITY, gameId, null); - } - } - } + public void holdPriority(boolean holdPriority) { + if (holdingPriority != holdPriority) { + holdingPriority = holdPriority; + txtHoldPriority.setVisible(holdPriority); + if (holdPriority) { + SessionHandler.sendPlayerAction(PlayerAction.HOLD_PRIORITY, gameId, null); + } else { + SessionHandler.sendPlayerAction(PlayerAction.UNHOLD_PRIORITY, gameId, null); + } + } + } - private boolean holdingPriority; - private mage.client.components.ability.AbilityPicker abilityPicker; - private mage.client.cards.BigCard bigCard; + private boolean holdingPriority; + private mage.client.components.ability.AbilityPicker abilityPicker; + private mage.client.cards.BigCard bigCard; // private JPanel cancelSkipPanel; - private javax.swing.JButton btnCancelSkip; - private javax.swing.JButton btnSkipToNextTurn; // F4 - private javax.swing.JButton btnSkipToEndTurn; // F5 - private javax.swing.JButton btnSkipToNextMain; // F7 - private javax.swing.JButton btnSkipStack; // F8 - private javax.swing.JButton btnSkipToYourTurn; // F9 - private javax.swing.JButton btnSkipToEndStepBeforeYourTurn; // F11 + private KeyboundButton btnCancelSkip; + private KeyboundButton btnSkipToNextTurn; // F4 + private KeyboundButton btnSkipToEndTurn; // F5 + private KeyboundButton btnSkipToNextMain; // F7 + private KeyboundButton btnSkipStack; // F8 + private KeyboundButton btnSkipToYourTurn; // F9 + private KeyboundButton btnSkipToEndStepBeforeYourTurn; // F11 - private javax.swing.JButton btnConcede; - private javax.swing.JButton btnSwitchHands; + private javax.swing.JButton btnConcede; + private javax.swing.JButton btnSwitchHands; - private javax.swing.JButton btnNextPlay; - private javax.swing.JButton btnPlay; - private javax.swing.JButton btnPreviousPlay; - private javax.swing.JButton btnSkipForward; - private javax.swing.JButton btnStopReplay; + private javax.swing.JButton btnNextPlay; + private javax.swing.JButton btnPlay; + private javax.swing.JButton btnPreviousPlay; + private javax.swing.JButton btnSkipForward; + private javax.swing.JButton btnStopReplay; - private javax.swing.JButton btnStopWatching; + private javax.swing.JButton btnStopWatching; - private mage.client.chat.ChatPanelBasic gameChatPanel; - private mage.client.game.FeedbackPanel feedbackPanel; - private HelperPanel helper; - private mage.client.chat.ChatPanelBasic userChatPanel; - private javax.swing.JPanel jPanel2; - private javax.swing.JPanel pnlHelperHandButtonsStackArea; - private javax.swing.JSplitPane jSplitPane0; - private javax.swing.JSplitPane jSplitPane1; - private javax.swing.JLabel lblActivePlayer; - private javax.swing.JLabel lblPhase; - private javax.swing.JLabel lblPriority; - private javax.swing.JLabel lblStep; - private javax.swing.JLabel lblTurn; - private javax.swing.JPanel pnlBattlefield; - private javax.swing.JPanel pnlShortCuts; - private javax.swing.JPanel pnlReplay; - private javax.swing.JLabel txtActivePlayer; - private javax.swing.JLabel txtPhase; - private javax.swing.JLabel txtPriority; - private javax.swing.JLabel txtStep; - private javax.swing.JLabel txtTurn; + private mage.client.chat.ChatPanelBasic gameChatPanel; + private mage.client.game.FeedbackPanel feedbackPanel; + private HelperPanel helper; + private mage.client.chat.ChatPanelBasic userChatPanel; + private javax.swing.JPanel jPanel2; + private javax.swing.JPanel pnlHelperHandButtonsStackArea; + private javax.swing.JSplitPane jSplitPane0; + private javax.swing.JSplitPane jSplitPane1; + private javax.swing.JLabel lblActivePlayer; + private javax.swing.JLabel lblPhase; + private javax.swing.JLabel lblPriority; + private javax.swing.JLabel lblStep; + private javax.swing.JLabel lblTurn; + private javax.swing.JPanel pnlBattlefield; + private javax.swing.JPanel pnlShortCuts; + private javax.swing.JPanel pnlReplay; + private javax.swing.JLabel txtActivePlayer; + private javax.swing.JLabel txtPhase; + private javax.swing.JLabel txtPriority; + private javax.swing.JLabel txtStep; + private javax.swing.JLabel txtTurn; - private Map handCards; + private Map handCards; - private mage.client.cards.Cards stackObjects; - private HandPanel handContainer; + private mage.client.cards.Cards stackObjects; + private HandPanel handContainer; - private javax.swing.JSplitPane jSplitPane2; - private JPanel jPhases; - private JPanel phasesContainer; - private javax.swing.JLabel txtSpellsCast; - private javax.swing.JLabel txtHoldPriority; + private javax.swing.JSplitPane jSplitPane2; + private JPanel jPhases; + private JPanel phasesContainer; + private javax.swing.JLabel txtSpellsCast; + private javax.swing.JLabel txtHoldPriority; - private HoverButton currentStep; - private Point prevPoint; + private HoverButton currentStep; + private Point prevPoint; - private boolean imagePanelState; + private boolean imagePanelState; } class ReplayTask extends SwingWorker> { - private final UUID gameId; + private final UUID gameId; - private static final Logger logger = Logger.getLogger(ReplayTask.class); + private static final Logger logger = Logger.getLogger(ReplayTask.class); - ReplayTask(UUID gameId) { - this.gameId = gameId; - } + ReplayTask(UUID gameId) { + this.gameId = gameId; + } - @Override - protected Void doInBackground() throws Exception { - while (!isCancelled()) { - SessionHandler.nextPlay(gameId); - Thread.sleep(1000); - } - return null; - } + @Override + protected Void doInBackground() throws Exception { + while (!isCancelled()) { + SessionHandler.nextPlay(gameId); + Thread.sleep(1000); + } + return null; + } - @Override - protected void done() { - try { - get(); - } catch (InterruptedException ex) { - logger.fatal("Replay Match Task error", ex); - } catch (ExecutionException ex) { - logger.fatal("Replay Match Task error", ex); - } catch (CancellationException ex) { - } - } + @Override + protected void done() { + try { + get(); + } catch (InterruptedException ex) { + logger.fatal("Replay Match Task error", ex); + } catch (ExecutionException ex) { + logger.fatal("Replay Match Task error", ex); + } catch (CancellationException ex) { + } + } } diff --git a/Mage.Client/src/main/resources/buttons/cancel_skip.png b/Mage.Client/src/main/resources/buttons/cancel_skip.png index 30755df9317..4df1d6db2f7 100644 Binary files a/Mage.Client/src/main/resources/buttons/cancel_skip.png and b/Mage.Client/src/main/resources/buttons/cancel_skip.png differ diff --git a/Mage.Client/src/main/resources/buttons/skip_all.png b/Mage.Client/src/main/resources/buttons/skip_all.png index 53c01378ade..2120e016d97 100644 Binary files a/Mage.Client/src/main/resources/buttons/skip_all.png and b/Mage.Client/src/main/resources/buttons/skip_all.png differ diff --git a/Mage.Client/src/main/resources/buttons/skip_stack.png b/Mage.Client/src/main/resources/buttons/skip_stack.png index 06816b1f393..2ddce1c39b3 100644 Binary files a/Mage.Client/src/main/resources/buttons/skip_stack.png and b/Mage.Client/src/main/resources/buttons/skip_stack.png differ diff --git a/Mage.Client/src/main/resources/buttons/skip_to_end.png b/Mage.Client/src/main/resources/buttons/skip_to_end.png index 86df3bcf7c4..4a609a06252 100644 Binary files a/Mage.Client/src/main/resources/buttons/skip_to_end.png and b/Mage.Client/src/main/resources/buttons/skip_to_end.png differ diff --git a/Mage.Client/src/main/resources/buttons/skip_to_main.png b/Mage.Client/src/main/resources/buttons/skip_to_main.png index 0d1b2bf1155..d1bbef6b864 100644 Binary files a/Mage.Client/src/main/resources/buttons/skip_to_main.png and b/Mage.Client/src/main/resources/buttons/skip_to_main.png differ diff --git a/Mage.Client/src/main/resources/buttons/skip_to_previous_end.png b/Mage.Client/src/main/resources/buttons/skip_to_previous_end.png index 2e93fd55bbb..03043c96b7c 100644 Binary files a/Mage.Client/src/main/resources/buttons/skip_to_previous_end.png and b/Mage.Client/src/main/resources/buttons/skip_to_previous_end.png differ diff --git a/Mage.Client/src/main/resources/buttons/skip_turn.png b/Mage.Client/src/main/resources/buttons/skip_turn.png index c7c3bfe393b..8f9ad5432ae 100644 Binary files a/Mage.Client/src/main/resources/buttons/skip_turn.png and b/Mage.Client/src/main/resources/buttons/skip_turn.png differ