Search in sources :

Example 6 with UserRequestMessage

use of mage.view.UserRequestMessage in project mage by magefree.

the class PreferencesDialog method saveButtonActionPerformed.

// </editor-fold>//GEN-END:initComponents
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_saveButtonActionPerformed
    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.showFullImagePath, KEY_SHOW_FULL_IMAGE_PATH, "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.displayLifeOnAvatar, KEY_DISPLAY_LIVE_ON_AVATAR, "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.cbGameLogShowTurnInfo, KEY_GAME_LOG_SHOW_TURN_INFO, "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);
    save(prefs, dialog.cbGameJsonLogAutoSave, KEY_JSON_GAME_LOG_AUTO_SAVE, "true", "false", UPDATE_CACHE_POLICY);
    String paramName = KEY_BATTLEFIELD_FEEDBACK_COLORIZING_MODE;
    int paramValue = dialog.cbBattlefieldFeedbackColorizingMode.getSelectedIndex();
    int paramDefault = BATTLEFIELD_FEEDBACK_COLORIZING_MODE_ENABLE_BY_MULTICOLOR;
    if (getCachedValue(paramName, paramDefault) != paramValue) {
        prefs.putInt(paramName, paramValue);
        if (UPDATE_CACHE_POLICY) {
            updateCache(paramName, Integer.toString(paramValue));
        }
    }
    saveGUISize();
    // 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.cbStopAttack, KEY_STOP_ATTACK, "true", "false", UPDATE_CACHE_POLICY);
    save(prefs, dialog.cbStopBlockWithAny, KEY_STOP_BLOCK_WITH_ANY, "true", "false", UPDATE_CACHE_POLICY);
    save(prefs, dialog.cbStopBlockWithZero, KEY_STOP_BLOCK_WITH_ZERO, "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.cbStopOnNewStackObjects, KEY_STOP_NEW_STACK_OBJECTS, "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.cbUseSameSettingsForReplacementEffect, KEY_USE_SAME_SETTINGS_FOR_SAME_REPLACEMENT_EFFECTS, "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.cbSaveToZipFiles, KEY_CARD_IMAGES_SAVE_TO_ZIP, "true", "false", UPDATE_CACHE_POLICY);
    save(prefs, dialog.cbNumberOfDownloadThreads, KEY_CARD_IMAGES_THREADS);
    save(prefs, dialog.cbPreferredImageLanguage, 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);
    // rendering
    save(prefs, dialog.cbCardRenderImageFallback, KEY_CARD_RENDERING_FALLBACK, "true", "false", UPDATE_CACHE_POLICY);
    save(prefs, dialog.cbCardRenderIconsForAbilities, KEY_CARD_RENDERING_ICONS_FOR_ABILITIES, "true", "false", UPDATE_CACHE_POLICY);
    save(prefs, dialog.cbCardRenderIconsForPlayable, KEY_CARD_RENDERING_ICONS_FOR_PLAYABLE, "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);
    save(prefs, dialog.cbCardRenderShowAbilityTextOverlay, KEY_CARD_RENDERING_ABILITY_TEXT_OVERLAY, "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);
    // 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);
    // controls
    save(prefs, dialog.keyConfirm);
    save(prefs, dialog.keyCancelSkip);
    save(prefs, dialog.keyNextTurn);
    save(prefs, dialog.keyEndStep);
    save(prefs, dialog.keySkipStep);
    save(prefs, dialog.keyMainStep);
    save(prefs, dialog.keyYourTurn);
    save(prefs, dialog.keySkipStack);
    save(prefs, dialog.keyPriorEnd);
    save(prefs, dialog.keyToggleRecordMacro);
    save(prefs, dialog.keySwitchChat);
    // Themes
    save(prefs, dialog.cbTheme, KEY_THEME);
    // 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));
    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);
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences) UserRequestMessage(mage.view.UserRequestMessage)

Example 7 with UserRequestMessage

use of mage.view.UserRequestMessage in project mage by magefree.

the class MagePaneMenuItem method showMessage.

@Override
public void showMessage(String message) {
    final UserRequestMessage requestMessage = new UserRequestMessage("Message", message);
    requestMessage.setButton1("OK", null);
    showUserRequestDialog(requestMessage);
}
Also used : UserRequestMessage(mage.view.UserRequestMessage)

Example 8 with UserRequestMessage

use of mage.view.UserRequestMessage in project mage by magefree.

the class MagePaneMenuItem method showError.

@Override
public void showError(final String message) {
    final UserRequestMessage requestMessage = new UserRequestMessage("Error", message);
    requestMessage.setButton1("OK", null);
    showUserRequestDialog(requestMessage);
}
Also used : UserRequestMessage(mage.view.UserRequestMessage)

Example 9 with UserRequestMessage

use of mage.view.UserRequestMessage in project mage by magefree.

the class UpdateTournamentTask method btnQuitTournamentActionPerformed.

// GEN-LAST:event_btnCloseWindowActionPerformed
private void btnQuitTournamentActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_btnQuitTournamentActionPerformed
    UserRequestMessage message = new UserRequestMessage("Confirm quit tournament", "Are you sure you want to quit the tournament?");
    message.setButton1("No", null);
    message.setButton2("Yes", PlayerAction.CLIENT_QUIT_TOURNAMENT);
    message.setTournamentId(tournamentId);
    MageFrame.getInstance().showUserRequestDialog(message);
}
Also used : UserRequestMessage(mage.view.UserRequestMessage)

Example 10 with UserRequestMessage

use of mage.view.UserRequestMessage in project mage by magefree.

the class PlayAreaPanel method addPopupMenuPlayer.

private void addPopupMenuPlayer(boolean allowRequestToShowHandCards) {
    JMenuItem menuItem;
    ActionListener skipListener = e -> {
        switch(e.getActionCommand()) {
            case "F2":
                {
                    if (gamePanel.getFeedbackPanel() != null) {
                        gamePanel.getFeedbackPanel().pressOKYesOrDone();
                    }
                    break;
                }
            case "F3":
                {
                    SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_CANCEL_ALL_ACTIONS, gameId, null);
                    break;
                }
            case "F4":
                {
                    SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN, gameId, null);
                    break;
                }
            case "F5":
                {
                    SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_TURN_END_STEP, gameId, null);
                    break;
                }
            case "F6":
                {
                    SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN_SKIP_STACK, gameId, null);
                    break;
                }
            case "F7":
                {
                    SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_MAIN_PHASE, gameId, null);
                    break;
                }
            case "F9":
                {
                    SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_MY_NEXT_TURN, gameId, null);
                    break;
                }
            case "F11":
                {
                    SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_END_STEP_BEFORE_MY_NEXT_TURN, gameId, null);
                    break;
                }
            default:
                break;
        }
    };
    menuItem = new JMenuItem("<html><b>F2</b> - Confirm current request");
    menuItem.setActionCommand("F2");
    menuItem.setMnemonic(KeyEvent.VK_O);
    popupMenu.add(menuItem);
    menuItem.addActionListener(skipListener);
    menuItem = new JMenuItem("<html><b>F3</b> - Cancel active skip action");
    menuItem.setActionCommand("F3");
    menuItem.setMnemonic(KeyEvent.VK_N);
    popupMenu.add(menuItem);
    menuItem.addActionListener(skipListener);
    holdPriorityMenuItem = new JCheckBoxMenuItem("<html><b>" + (System.getProperty("os.name").contains("Mac OS X") ? "Cmd" : "Ctrl") + "+click</b> - Hold Priority");
    holdPriorityMenuItem.setMnemonic(KeyEvent.VK_P);
    holdPriorityMenuItem.setToolTipText("<html>Hold priority after casting a spell or activating an ability, instead of automatically passing priority.");
    popupMenu.add(holdPriorityMenuItem);
    holdPriorityMenuItem.addActionListener(e -> {
        boolean holdPriority = ((JCheckBoxMenuItem) e.getSource()).getState();
        gamePanel.setMenuStates(manaPoolMenuItem1.getState(), manaPoolMenuItem2.getState(), useFirstManaAbilityItem.getState(), holdPriority);
        gamePanel.holdPriority(holdPriority);
    });
    JMenu skipMenu = new JMenu("Skip");
    skipMenu.setMnemonic(KeyEvent.VK_S);
    popupMenu.add(skipMenu);
    String tooltipText = "<html>This skip actions stops if something goes to <br><b>stack</b> and if <b>attackers</b> or <b>blocker</b> have to be <b>declared</b>.";
    String everythingTooltipText = "<html>This skip actions stops if <b>attackers</b> or <b>blocker</b> have to be <b>declared</b>, but not if something goes to the <b>stack</b>.";
    menuItem = new JMenuItem("<html><b>F4</b> - Phases until next turn");
    menuItem.setActionCommand("F4");
    menuItem.setToolTipText(tooltipText);
    menuItem.setMnemonic(KeyEvent.VK_T);
    skipMenu.add(menuItem);
    menuItem.addActionListener(skipListener);
    menuItem = new JMenuItem("<html><b>F5</b> - Phases until next end step");
    menuItem.setActionCommand("F5");
    menuItem.setToolTipText(tooltipText);
    menuItem.setMnemonic(KeyEvent.VK_E);
    skipMenu.add(menuItem);
    menuItem.addActionListener(skipListener);
    menuItem = new JMenuItem("<html><b>F6</b> - Everything until the next turn");
    menuItem.setActionCommand("F6");
    menuItem.setToolTipText(everythingTooltipText);
    menuItem.setMnemonic(KeyEvent.VK_U);
    skipMenu.add(menuItem);
    menuItem.addActionListener(skipListener);
    menuItem = new JMenuItem("<html><b>F7</b> - Phases until begin of next main phase");
    menuItem.setToolTipText(tooltipText);
    menuItem.setActionCommand("F7");
    menuItem.setMnemonic(KeyEvent.VK_M);
    skipMenu.add(menuItem);
    menuItem.addActionListener(skipListener);
    menuItem = new JMenuItem("<html><b>F9</b> - Everything until your own next turn");
    menuItem.setActionCommand("F9");
    menuItem.setToolTipText(everythingTooltipText);
    menuItem.setMnemonic(KeyEvent.VK_V);
    skipMenu.add(menuItem);
    menuItem.addActionListener(skipListener);
    menuItem = new JMenuItem("<html><b>F11</b> - Everything until end step prior to your own next turn");
    menuItem.setActionCommand("F11");
    menuItem.setToolTipText(everythingTooltipText);
    menuItem.setMnemonic(KeyEvent.VK_P);
    skipMenu.add(menuItem);
    menuItem.addActionListener(skipListener);
    popupMenu.addSeparator();
    JMenu manaPoolMenu = new JMenu("Mana payment");
    manaPoolMenu.setMnemonic(KeyEvent.VK_M);
    popupMenu.add(manaPoolMenu);
    manaPoolMenuItem1 = new JCheckBoxMenuItem("Automatically", true);
    manaPoolMenuItem1.setMnemonic(KeyEvent.VK_A);
    manaPoolMenuItem1.setToolTipText("<html>If not active, produced mana goes only to the mana pool<br>" + "and you have to click the type of mana you want to use <br>" + "in the player mana pool panel for payment.");
    manaPoolMenu.add(manaPoolMenuItem1);
    // Auto pay mana from mana pool
    manaPoolMenuItem1.addActionListener(e -> {
        boolean manaPoolAutomatic = ((JCheckBoxMenuItem) e.getSource()).getState();
        PreferencesDialog.saveValue(KEY_GAME_MANA_AUTOPAYMENT, manaPoolAutomatic ? "true" : "false");
        gamePanel.setMenuStates(manaPoolAutomatic, manaPoolMenuItem2.getState(), useFirstManaAbilityItem.getState(), holdPriorityMenuItem.getState());
        SessionHandler.sendPlayerAction(manaPoolAutomatic ? PlayerAction.MANA_AUTO_PAYMENT_ON : PlayerAction.MANA_AUTO_PAYMENT_OFF, gameId, null);
    });
    manaPoolMenuItem2 = new JCheckBoxMenuItem("No automatic usage for mana already in the pool", true);
    manaPoolMenuItem2.setMnemonic(KeyEvent.VK_N);
    manaPoolMenuItem2.setToolTipText("<html>Mana that is already in the mana pool as you start casting a spell or activating an ability<br>" + " needs to be payed manually. So you use the mana in the pool only by clicking on the related<br>" + " mana symbols of mana pool area.");
    manaPoolMenu.add(manaPoolMenuItem2);
    // Auto pay mana from mana pool
    manaPoolMenuItem2.addActionListener(e -> {
        boolean manaPoolAutomaticRestricted = ((JCheckBoxMenuItem) e.getSource()).getState();
        PreferencesDialog.saveValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, manaPoolAutomaticRestricted ? "true" : "false");
        gamePanel.setMenuStates(manaPoolMenuItem1.getState(), manaPoolAutomaticRestricted, useFirstManaAbilityItem.getState(), holdPriorityMenuItem.getState());
        SessionHandler.sendPlayerAction(manaPoolAutomaticRestricted ? PlayerAction.MANA_AUTO_PAYMENT_RESTRICTED_ON : PlayerAction.MANA_AUTO_PAYMENT_RESTRICTED_OFF, gameId, null);
    });
    useFirstManaAbilityItem = new JCheckBoxMenuItem("Use first mana ability when tapping lands", false);
    useFirstManaAbilityItem.setMnemonic(KeyEvent.VK_F);
    useFirstManaAbilityItem.setToolTipText("<html>Use the first mana ability when<br>" + " tapping lands for mana<br>" + "You can hold Alt+1 whilst tapping lands to use this feature");
    manaPoolMenu.add(useFirstManaAbilityItem);
    // Use first mana ability of lands
    useFirstManaAbilityItem.addActionListener(e -> {
        boolean useFirstManaAbility = ((JCheckBoxMenuItem) e.getSource()).getState();
        PreferencesDialog.saveValue(KEY_USE_FIRST_MANA_ABILITY, useFirstManaAbility ? "true" : "false");
        gamePanel.setMenuStates(manaPoolMenuItem1.getState(), manaPoolMenuItem2.getState(), useFirstManaAbility, holdPriorityMenuItem.getState());
        SessionHandler.sendPlayerAction(useFirstManaAbility ? PlayerAction.USE_FIRST_MANA_ABILITY_ON : PlayerAction.USE_FIRST_MANA_ABILITY_OFF, gameId, null);
    });
    JMenu automaticConfirmsMenu = new JMenu("Auto-answers");
    automaticConfirmsMenu.setMnemonic(KeyEvent.VK_U);
    popupMenu.add(automaticConfirmsMenu);
    menuItem = new JMenuItem("Replacement effects - reset all auto-answers");
    menuItem.setMnemonic(KeyEvent.VK_R);
    menuItem.setToolTipText("Reset all effects that were added to the list of auto select replacement effects this game.");
    automaticConfirmsMenu.add(menuItem);
    // Reset the replacement effcts that were auto selected for the game
    menuItem.addActionListener(e -> SessionHandler.sendPlayerAction(PlayerAction.RESET_AUTO_SELECT_REPLACEMENT_EFFECTS, gameId, null));
    menuItem = new JMenuItem("Triggered abilities - reset all auto-answers for stack order");
    menuItem.setMnemonic(KeyEvent.VK_T);
    menuItem.setToolTipText("Reset all triggered ability order settings you added during the game.");
    automaticConfirmsMenu.add(menuItem);
    // Reset the replacement effcts that were auto selected for the game
    menuItem.addActionListener(e -> SessionHandler.sendPlayerAction(PlayerAction.TRIGGER_AUTO_ORDER_RESET_ALL, gameId, null));
    menuItem = new JMenuItem("Yes/no requests - reset all auto-answers");
    menuItem.setMnemonic(KeyEvent.VK_T);
    menuItem.setToolTipText("Reset all defined automatic answers for Yes/No usage requests (with two buttons).");
    automaticConfirmsMenu.add(menuItem);
    // Reset the replacement and yes/no dialogs that were auto selected for the game
    menuItem.addActionListener(e -> SessionHandler.sendPlayerAction(PlayerAction.REQUEST_AUTO_ANSWER_RESET_ALL, gameId, null));
    JMenu handCardsMenu = new JMenu("Cards on hand");
    handCardsMenu.setMnemonic(KeyEvent.VK_H);
    popupMenu.add(handCardsMenu);
    if (!options.playerItself) {
        menuItem = new JMenuItem("Request permission to see the hand cards");
        menuItem.setMnemonic(KeyEvent.VK_P);
        handCardsMenu.add(menuItem);
        // Request to see hand cards
        menuItem.addActionListener(e -> SessionHandler.sendPlayerAction(PlayerAction.REQUEST_PERMISSION_TO_SEE_HAND_CARDS, gameId, playerId));
    } else {
        allowViewHandCardsMenuItem = new JCheckBoxMenuItem("Allow hand requests from other users", allowRequestToShowHandCards);
        allowViewHandCardsMenuItem.setMnemonic(KeyEvent.VK_A);
        allowViewHandCardsMenuItem.setToolTipText("Watchers or other players can request your hand cards once per game. Re-activate it to allow new requests.");
        handCardsMenu.add(allowViewHandCardsMenuItem);
        // requests allowed (disable -> enable to reset requested list)
        allowViewHandCardsMenuItem.addActionListener(e -> {
            boolean requestsAllowed = ((JCheckBoxMenuItem) e.getSource()).getState();
            PreferencesDialog.setPrefValue(KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, requestsAllowed);
            SessionHandler.sendPlayerAction(requestsAllowed ? PlayerAction.PERMISSION_REQUESTS_ALLOWED_ON : PlayerAction.PERMISSION_REQUESTS_ALLOWED_OFF, gameId, null);
        });
        menuItem = new JMenuItem("Revoke all permission(s) to see your hand cards");
        menuItem.setMnemonic(KeyEvent.VK_R);
        menuItem.setToolTipText("Revoke already granted permission for all spectators to see your hand cards.");
        handCardsMenu.add(menuItem);
        // revoke permissions to see hand cards
        menuItem.addActionListener(e -> SessionHandler.sendPlayerAction(PlayerAction.REVOKE_PERMISSIONS_TO_SEE_HAND_CARDS, gameId, null));
    }
    if (options.rollbackTurnsAllowed) {
        ActionListener rollBackActionListener = e -> {
            int turnsToRollBack = Integer.parseInt(e.getActionCommand());
            SessionHandler.sendPlayerAction(PlayerAction.ROLLBACK_TURNS, gameId, turnsToRollBack);
        };
        JMenu rollbackMainItem = new JMenu("Rollback");
        rollbackMainItem.setMnemonic(KeyEvent.VK_R);
        rollbackMainItem.setToolTipText("The game will be rolled back to the start of the requested turn if all players agree.");
        popupMenu.add(rollbackMainItem);
        menuItem = new JMenuItem("To the start of the current turn");
        menuItem.setMnemonic(KeyEvent.VK_C);
        menuItem.setActionCommand("0");
        menuItem.addActionListener(rollBackActionListener);
        rollbackMainItem.add(menuItem);
        menuItem = new JMenuItem("To the start of the previous turn");
        menuItem.setMnemonic(KeyEvent.VK_P);
        menuItem.setActionCommand("1");
        menuItem.addActionListener(rollBackActionListener);
        rollbackMainItem.add(menuItem);
        menuItem = new JMenuItem("The current turn and the 2 turns before");
        menuItem.setMnemonic(KeyEvent.VK_2);
        menuItem.setActionCommand("2");
        menuItem.addActionListener(rollBackActionListener);
        rollbackMainItem.add(menuItem);
        menuItem = new JMenuItem("The current turn and the 3 turns before");
        menuItem.setMnemonic(KeyEvent.VK_3);
        menuItem.setActionCommand("3");
        menuItem.addActionListener(rollBackActionListener);
        rollbackMainItem.add(menuItem);
    }
    JMenu concedeMenu = new JMenu("Concede");
    concedeMenu.setMnemonic(KeyEvent.VK_C);
    popupMenu.add(concedeMenu);
    ActionListener concedeListener = e -> {
        switch(e.getActionCommand()) {
            case "Game":
                {
                    UserRequestMessage message = new UserRequestMessage("Confirm concede game", "Are you sure you want to concede the game?");
                    message.setButton1("No", null);
                    message.setButton2("Yes", PlayerAction.CLIENT_CONCEDE_GAME);
                    message.setGameId(gameId);
                    MageFrame.getInstance().showUserRequestDialog(message);
                    break;
                }
            case "Match":
                {
                    UserRequestMessage message = new UserRequestMessage("Confirm concede match", "Are you sure you want to concede the complete match?");
                    message.setButton1("No", null);
                    message.setButton2("Yes", PlayerAction.CLIENT_CONCEDE_MATCH);
                    message.setGameId(gameId);
                    MageFrame.getInstance().showUserRequestDialog(message);
                    break;
                }
            default:
                break;
        }
    };
    // Concede Game
    menuItem = new JMenuItem("Game");
    menuItem.setMnemonic(KeyEvent.VK_G);
    menuItem.setActionCommand("Game");
    menuItem.setToolTipText("Concedes only the current game and after that the next game of the match is started if there is another game needed.");
    concedeMenu.add(menuItem);
    menuItem.addActionListener(concedeListener);
    // Concede Match
    menuItem = new JMenuItem("Match");
    menuItem.setMnemonic(KeyEvent.VK_M);
    menuItem.setActionCommand("Match");
    menuItem.setToolTipText("Concedes the complete match. So if you're in a tournament you finish the current tournament round.");
    concedeMenu.add(menuItem);
    menuItem.addActionListener(concedeListener);
    battlefieldPanel.getMainPanel().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            this.checkMenu(e);
        }

        // neccessary for linux and mac systems
        @Override
        public void mousePressed(MouseEvent e) {
            this.checkMenu(e);
        }

        private void checkMenu(MouseEvent e) {
            if (e.isPopupTrigger() && playingMode) {
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });
    popupMenu.addSeparator();
    // view deck
    menuItem = new JMenuItem("<html>View player's deck");
    menuItem.setMnemonic(KeyEvent.VK_D);
    popupMenu.add(menuItem);
    menuItem.addActionListener(e -> {
        SessionHandler.sendPlayerAction(PlayerAction.VIEW_LIMITED_DECK, gameId, null);
    });
    // it's a client side checks... same checks must be on server side too (see PlayerView)
    if (options.playerItself || !options.isHuman) {
        String menuCaption = "<html>View my sideboard";
        if (!options.isHuman) {
            menuCaption = "<html>View computer's sideboard";
        }
        menuItem = new JMenuItem(menuCaption);
        menuItem.setMnemonic(KeyEvent.VK_S);
        popupMenu.add(menuItem);
        menuItem.addActionListener(e -> {
            SessionHandler.sendPlayerAction(PlayerAction.VIEW_SIDEBOARD, gameId, playerId);
        });
    }
}
Also used : MageFrame(mage.client.MageFrame) UserRequestMessage(mage.view.UserRequestMessage) DeckImporter(mage.cards.decks.importer.DeckImporter) PlayerView(mage.view.PlayerView) Set(java.util.Set) ComponentPlacement(javax.swing.LayoutStyle.ComponentPlacement) UUID(java.util.UUID) Field(java.lang.reflect.Field) GameView(mage.view.GameView) java.awt(java.awt) PreferencesDialog(mage.client.dialog.PreferencesDialog) Alignment(javax.swing.GroupLayout.Alignment) BigCard(mage.client.cards.BigCard) java.awt.event(java.awt.event) PlayerAction(mage.constants.PlayerAction) GUISizeHelper(mage.client.util.GUISizeHelper) ChangeListener(javax.swing.event.ChangeListener) SessionHandler(mage.client.SessionHandler) javax.swing(javax.swing) UserRequestMessage(mage.view.UserRequestMessage)

Aggregations

UserRequestMessage (mage.view.UserRequestMessage)10 java.awt (java.awt)1 java.awt.event (java.awt.event)1 Field (java.lang.reflect.Field)1 Set (java.util.Set)1 UUID (java.util.UUID)1 BackingStoreException (java.util.prefs.BackingStoreException)1 Preferences (java.util.prefs.Preferences)1 javax.swing (javax.swing)1 Alignment (javax.swing.GroupLayout.Alignment)1 ComponentPlacement (javax.swing.LayoutStyle.ComponentPlacement)1 ChangeListener (javax.swing.event.ChangeListener)1 DeckImporter (mage.cards.decks.importer.DeckImporter)1 MageFrame (mage.client.MageFrame)1 SessionHandler (mage.client.SessionHandler)1 BigCard (mage.client.cards.BigCard)1 PreferencesDialog (mage.client.dialog.PreferencesDialog)1 GUISizeHelper (mage.client.util.GUISizeHelper)1 PlayerAction (mage.constants.PlayerAction)1 GameView (mage.view.GameView)1