* Changed handling of phases to stop to server based handling.

This commit is contained in:
LevelX2 2014-09-25 00:33:58 +02:00
parent e6d2bce95d
commit f3ea64e27c
19 changed files with 221 additions and 176 deletions

View file

@ -714,6 +714,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
connection.setProxyPassword(proxyPassword);
connection.setAvatarId(avatarId);
connection.setShowAbilityPickerForced(showAbilityPickerForced);
connection.setUserSkipPrioritySteps(PreferencesDialog.getUserSkipPrioritySteps());
logger.debug("connecting (auto): " + proxyType + " " + proxyServer + " " + proxyPort + " " + proxyUsername);
if (MageFrame.connect(connection)) {
showGames(false);

View file

@ -310,6 +310,7 @@ public class ConnectDialog extends MageDialog {
connection.setAvatarId(avatarId);
boolean showAbilityPickerForced = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_ABILITY_PICKER_FORCED, "true").equals("true");
connection.setShowAbilityPickerForced(showAbilityPickerForced);
connection.setUserSkipPrioritySteps(PreferencesDialog.getUserSkipPrioritySteps());
logger.debug("connecting: " + connection.getProxyType() + " " + connection.getProxyHost() + " " + connection.getProxyPort());
task = new ConnectTask();
task.execute();

View file

@ -499,7 +499,7 @@
<Component id="panelCardImages" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="panelBackgroundImages" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="54" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>

View file

@ -62,10 +62,10 @@ import javax.swing.filechooser.FileFilter;
import mage.client.MageFrame;
import mage.client.util.Config;
import mage.client.util.ImageHelper;
import mage.client.util.PhaseManager;
import mage.client.util.gui.BufferedImageBuilder;
import mage.remote.Connection;
import mage.remote.Connection.ProxyType;
import mage.players.net.UserSkipPrioritySteps;
import org.apache.log4j.Logger;
/**
@ -104,9 +104,26 @@ public class PreferencesDialog extends javax.swing.JDialog {
public static final String KEY_BIG_CARD_TOGGLED = "bigCardToggled";
// Size of frame to check if divider locations should be used
public static final String KEY_MAGE_PANEL_LAST_SIZE = "gamepanelLastSize";
// Phases
public static String UPKEEP_YOU = "upkeepYou";
public static String DRAW_YOU = "drawYou";
public static String MAIN_YOU = "mainYou";
public static String BEFORE_COMBAT_YOU = "beforeCombatYou";
public static String END_OF_COMBAT_YOU = "endOfCombatYou";
public static String MAIN_2_YOU = "main2You";
public static String END_OF_TURN_YOU = "endOfTurnYou";
public static String UPKEEP_OTHERS = "upkeepOthers";
public static String DRAW_OTHERS = "drawOthers";
public static String MAIN_OTHERS = "mainOthers";
public static String BEFORE_COMBAT_OTHERS = "beforeCombatOthers";
public static String END_OF_COMBAT_OTHERS = "endOfCombatOthers";
public static String MAIN_2_OTHERS = "main2Others";
public static String END_OF_TURN_OTHERS = "endOfTurnOthers";
// Size of frame to check if divider locations should be used
public static final String KEY_MAGE_PANEL_LAST_SIZE = "gamepanelLastSize";
// positions of divider bars
public static final String KEY_TABLES_DIVIDER_LOCATION_1 = "tablePanelDividerLocation1";
public static final String KEY_TABLES_DIVIDER_LOCATION_2 = "tablePanelDividerLocation2";
@ -188,7 +205,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
public static final String OPEN_CONNECTION_TAB = "Open-Connection-Tab";
public static String PHASE_ON = "on";
public static String PHASE_OFF = "off";
public static final int DEFAULT_AVATAR_ID = 51;
private static int selectedAvatarId = DEFAULT_AVATAR_ID;
@ -1355,21 +1373,21 @@ public class PreferencesDialog extends javax.swing.JDialog {
save(prefs, dialog.cbGameLogAutoSave, KEY_GAME_LOG_AUTO_SAVE, "true", "false", UPDATE_CACHE_POLICY);
// Phases
save(prefs, dialog.checkBoxUpkeepYou, PhaseManager.UPKEEP_YOU);
save(prefs, dialog.checkBoxDrawYou, PhaseManager.DRAW_YOU);
save(prefs, dialog.checkBoxMainYou, PhaseManager.MAIN_YOU);
save(prefs, dialog.checkBoxBeforeCYou, PhaseManager.BEFORE_COMBAT_YOU);
save(prefs, dialog.checkBoxEndOfCYou, PhaseManager.END_OF_COMBAT_YOU);
save(prefs, dialog.checkBoxMain2You, PhaseManager.MAIN_2_YOU);
save(prefs, dialog.checkBoxEndTurnYou, PhaseManager.END_OF_TURN_YOU);
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_2_YOU);
save(prefs, dialog.checkBoxEndTurnYou, END_OF_TURN_YOU);
save(prefs, dialog.checkBoxUpkeepOthers, PhaseManager.UPKEEP_OTHERS);
save(prefs, dialog.checkBoxDrawOthers, PhaseManager.DRAW_OTHERS);
save(prefs, dialog.checkBoxMainOthers, PhaseManager.MAIN_OTHERS);
save(prefs, dialog.checkBoxBeforeCOthers, PhaseManager.BEFORE_COMBAT_OTHERS);
save(prefs, dialog.checkBoxEndOfCOthers, PhaseManager.END_OF_COMBAT_OTHERS);
save(prefs, dialog.checkBoxMain2Others, PhaseManager.MAIN_2_OTHERS);
save(prefs, dialog.checkBoxEndTurnOthers, PhaseManager.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_2_OTHERS);
save(prefs, dialog.checkBoxEndTurnOthers, END_OF_TURN_OTHERS);
// images
save(prefs, dialog.cbUseDefaultImageFolder, KEY_CARD_IMAGES_USE_DEFAULT, "true", "false", UPDATE_CACHE_POLICY);
@ -1408,7 +1426,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
try {
MageFrame.getSession().updatePreferencesForServer(
getSelectedAvatar(),
dialog.showAbilityPickerForced.isSelected());
dialog.showAbilityPickerForced.isSelected(),
getUserSkipPrioritySteps());
prefs.flush();
} catch (BackingStoreException ex) {
@ -1688,21 +1707,21 @@ public class PreferencesDialog extends javax.swing.JDialog {
}
private static void loadPhases(Preferences prefs) {
load(prefs, dialog.checkBoxUpkeepYou, PhaseManager.UPKEEP_YOU);
load(prefs, dialog.checkBoxDrawYou, PhaseManager.DRAW_YOU);
load(prefs, dialog.checkBoxMainYou, PhaseManager.MAIN_YOU);
load(prefs, dialog.checkBoxBeforeCYou, PhaseManager.BEFORE_COMBAT_YOU);
load(prefs, dialog.checkBoxEndOfCYou, PhaseManager.END_OF_COMBAT_YOU);
load(prefs, dialog.checkBoxMain2You, PhaseManager.MAIN_2_YOU);
load(prefs, dialog.checkBoxEndTurnYou, PhaseManager.END_OF_TURN_YOU);
load(prefs, dialog.checkBoxUpkeepYou, UPKEEP_YOU);
load(prefs, dialog.checkBoxDrawYou, DRAW_YOU);
load(prefs, dialog.checkBoxMainYou, MAIN_YOU);
load(prefs, dialog.checkBoxBeforeCYou, BEFORE_COMBAT_YOU);
load(prefs, dialog.checkBoxEndOfCYou, END_OF_COMBAT_YOU);
load(prefs, dialog.checkBoxMain2You, MAIN_2_YOU);
load(prefs, dialog.checkBoxEndTurnYou, END_OF_TURN_YOU);
load(prefs, dialog.checkBoxUpkeepOthers, PhaseManager.UPKEEP_OTHERS);
load(prefs, dialog.checkBoxDrawOthers, PhaseManager.DRAW_OTHERS);
load(prefs, dialog.checkBoxMainOthers, PhaseManager.MAIN_OTHERS);
load(prefs, dialog.checkBoxBeforeCOthers, PhaseManager.BEFORE_COMBAT_OTHERS);
load(prefs, dialog.checkBoxEndOfCOthers, PhaseManager.END_OF_COMBAT_OTHERS);
load(prefs, dialog.checkBoxMain2Others, PhaseManager.MAIN_2_OTHERS);
load(prefs, dialog.checkBoxEndTurnOthers, PhaseManager.END_OF_TURN_OTHERS);
load(prefs, dialog.checkBoxUpkeepOthers, UPKEEP_OTHERS);
load(prefs, dialog.checkBoxDrawOthers, DRAW_OTHERS);
load(prefs, dialog.checkBoxMainOthers, MAIN_OTHERS);
load(prefs, dialog.checkBoxBeforeCOthers, BEFORE_COMBAT_OTHERS);
load(prefs, dialog.checkBoxEndOfCOthers, END_OF_COMBAT_OTHERS);
load(prefs, dialog.checkBoxMain2Others, MAIN_2_OTHERS);
load(prefs, dialog.checkBoxEndTurnOthers, END_OF_TURN_OTHERS);
load(prefs, dialog.displayBigCardsInHand, KEY_HAND_USE_BIG_CARDS, "true");
load(prefs, dialog.showToolTipsInAnyZone, KEY_SHOW_TOOLTIPS_ANY_ZONE, "true");
@ -1824,6 +1843,31 @@ public class PreferencesDialog extends javax.swing.JDialog {
return selectedAvatarId;
}
public static UserSkipPrioritySteps getUserSkipPrioritySteps() {
if (!dialog.isVisible()) {
loadPhases(MageFrame.getPreferences());
}
UserSkipPrioritySteps userSkipPrioritySteps = new 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());
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());
return userSkipPrioritySteps;
}
private static void openTab(int index) {
try {
if (index > 0) {
@ -1885,11 +1929,11 @@ public class PreferencesDialog extends javax.swing.JDialog {
}
private static void load(Preferences prefs, JCheckBox checkBox, String propName) {
load(prefs, checkBox, propName, PhaseManager.PHASE_ON);
load(prefs, checkBox, propName, PHASE_ON);
}
private static void save(Preferences prefs, JCheckBox checkBox, String propName) {
save(prefs, checkBox, propName, PhaseManager.PHASE_ON, PhaseManager.PHASE_OFF, false);
save(prefs, checkBox, propName, PHASE_ON, PHASE_OFF, false);
}
private static void save(Preferences prefs, JCheckBox checkBox, String propName, String yesValue, String noValue, boolean updateCache) {
@ -2000,7 +2044,10 @@ public class PreferencesDialog extends javax.swing.JDialog {
public void mousePressed(MouseEvent e) {
if (selectedAvatarId != id) {
setSelectedId(id);
MageFrame.getSession().updatePreferencesForServer(id, PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_ANY_ZONE, "true").equals("true"));
MageFrame.getSession().updatePreferencesForServer(
id,
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_ANY_ZONE, "true").equals("true"),
getUserSkipPrioritySteps());
}
}
});

View file

@ -44,7 +44,6 @@ import mage.client.plugins.impl.Plugins;
import mage.client.util.CardsViewUtil;
import mage.client.util.Config;
import mage.client.util.GameManager;
import mage.client.util.PhaseManager;
import mage.client.util.gui.ArrowBuilder;
import mage.constants.Constants;
import mage.constants.EnlargeMode;
@ -735,13 +734,6 @@ public final class GamePanel extends javax.swing.JPanel {
}
}
this.feedbackPanel.getFeedback(FeedbackMode.SELECT, messageToDisplay, gameView.getSpecial(), panelOptions, messageId);
if (PhaseManager.getInstance().isSkip(gameView, message)) {
this.feedbackPanel.doClick();
logger.debug(new StringBuilder("Phase skipped: ").append(message).append(" id: ").append(messageId));
} else {
logger.debug(new StringBuilder("Phase not skipped: ").append(message).append(" id: ").append(messageId));
}
}
public void playMana(String message, GameView gameView, int messageId) {

View file

@ -1,110 +0,0 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.client.util;
import java.util.HashMap;
import java.util.Map;
import java.util.prefs.Preferences;
import mage.client.MageFrame;
import mage.view.GameView;
import org.apache.log4j.Logger;
public class PhaseManager {
private static final Logger logger = Logger.getLogger(PhaseManager.class);
private static final PhaseManager fInstance = new PhaseManager();
public static String DEFAULT_PLAYER_NAME = "player";
public static String PHASE_ON = "on";
public static String PHASE_OFF = "off";
public static String UPKEEP_YOU = "upkeepYou";
public static String DRAW_YOU = "drawYou";
public static String MAIN_YOU = "mainYou";
public static String BEFORE_COMBAT_YOU = "beforeCombatYou";
public static String END_OF_COMBAT_YOU = "endOfCombatYou";
public static String MAIN_2_YOU = "main2You";
public static String END_OF_TURN_YOU = "endOfTurnYou";
public static String UPKEEP_OTHERS = "upkeepOthers";
public static String DRAW_OTHERS = "drawOthers";
public static String MAIN_OTHERS = "mainOthers";
public static String BEFORE_COMBAT_OTHERS = "beforeCombatOthers";
public static String END_OF_COMBAT_OTHERS = "endOfCombatOthers";
public static String MAIN_2_OTHERS = "main2Others";
public static String END_OF_TURN_OTHERS = "endOfTurnOthers";
private static final Preferences prefs = MageFrame.getPreferences();
private static final Map<String, String> mapYou = new HashMap<String, String>() {{
put("Upkeep - play instants and activated abilities.", UPKEEP_YOU);
put("Draw - play instants and activated abilities.", DRAW_YOU);
put("Precombat Main - play spells and abilities.", MAIN_YOU);
put("Begin Combat - play instants and activated abilities.", BEFORE_COMBAT_YOU);
put("End Combat - play instants and activated abilities.", END_OF_COMBAT_YOU);
put("Postcombat Main - play spells and abilities.", MAIN_2_YOU);
put("End Turn - play instants and activated abilities.", END_OF_TURN_YOU);
}};
private static final Map<String, String> mapOthers = new HashMap<String, String>() {{
put("Upkeep - play instants and activated abilities.", UPKEEP_OTHERS);
put("Draw - play instants and activated abilities.", DRAW_OTHERS);
put("Precombat Main - play instants and activated abilities.", MAIN_OTHERS);
put("Begin Combat - play instants and activated abilities.", BEFORE_COMBAT_OTHERS);
put("End Combat - play instants and activated abilities.", END_OF_COMBAT_OTHERS);
put("Postcombat Main - play instants and activated abilities.", MAIN_2_OTHERS);
put("End Turn - play instants and activated abilities.", END_OF_TURN_OTHERS);
}};
public static PhaseManager getInstance() {
return fInstance;
}
public boolean isSkip(GameView gameView, String message) {
// no skipping if stack is not empty
if (GameManager.getInstance().getStackSize() > 0) {
return false;
}
if (gameView.getActivePlayerId() == null) {
throw new IllegalStateException("No active player found.");
}
String prefKey;
if (gameView.getActivePlayerId().equals(GameManager.getInstance().getCurrentPlayerUUID())) {
prefKey = mapYou.get(message);
} else {
prefKey = mapOthers.get(message);
}
if (prefKey != null) {
String prop = prefs.get(prefKey, PHASE_ON);
return !prop.equals(PHASE_ON);
}
return false;
}
}