From: <ev...@us...> - 2011-03-26 20:42:59
|
Revision: 1501 http://rails.svn.sourceforge.net/rails/?rev=1501&view=rev Author: evos Date: 2011-03-26 20:42:51 +0000 (Sat, 26 Mar 2011) Log Message: ----------- Phase 1 of autosave/load Modified Paths: -------------- trunk/18xx/LocalisedText.properties trunk/18xx/rails/game/action/GameAction.java trunk/18xx/rails/game/action/PossibleAction.java trunk/18xx/rails/ui/swing/ActionPerformer.java trunk/18xx/rails/ui/swing/GameUIManager.java trunk/18xx/rails/ui/swing/ORUIManager.java trunk/18xx/rails/ui/swing/ORWindow.java trunk/18xx/rails/ui/swing/StartRoundWindow.java trunk/18xx/rails/ui/swing/StatusWindow.java trunk/18xx/rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java trunk/18xx/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java Added Paths: ----------- trunk/18xx/rails/ui/swing/AutoLoadPoller.java trunk/18xx/rails/ui/swing/AutoSaveLoadDialog.java Modified: trunk/18xx/LocalisedText.properties =================================================================== --- trunk/18xx/LocalisedText.properties 2011-03-17 21:16:44 UTC (rev 1500) +++ trunk/18xx/LocalisedText.properties 2011-03-26 20:42:51 UTC (rev 1501) @@ -19,6 +19,8 @@ AutodiscardTrain=discard {0}-train Autopass=Autopass Autopasses={0} autopasses +AutoSaveLoad=Autosave/load +AutoSaveLoadOptions=Autosave/load options BANK=Bank BANK_SHARES=Bank shares BASE_PRICE=<html>Base<br>Price</html> @@ -439,6 +441,8 @@ OCLayBaseToken=Lay base token -- {0} OCLayBaseTokenExecuted={0} lays base token for {1} OK=OK +On=On +Off=Off OPTIONS=Options OR=or ORWORTHINCR=OR +/- @@ -600,6 +604,7 @@ StockSpaceIsConfiguredTwice=Stock space {0} is configured twice. StockSpaceTypeConfiguredTwice=Stock space type {0} is configured twice StockSpaceTypeUndefined=Stock space type {0} is undefined. +Suspended=Suspended SwapsPrivateForCertificate={0} swaps {1} for a {2}% share of {3}. SwapPrivateForCertificate=Swap {0} for a {1}% share of {2} SwapPrivateForCertificates=Swap {0} for {1} {2}% shares of {3} Modified: trunk/18xx/rails/game/action/GameAction.java =================================================================== --- trunk/18xx/rails/game/action/GameAction.java 2011-03-17 21:16:44 UTC (rev 1500) +++ trunk/18xx/rails/game/action/GameAction.java 2011-03-26 20:42:51 UTC (rev 1501) @@ -13,8 +13,8 @@ public static final int RELOAD = 6; public static final int MAX_MODE = 6; - private String[] name = - new String[] { "Save", "Load", "Undo", "Undo!", "Redo", "Export", "Reload" }; + private static String[] names = + new String[] { "Save", "Load", "Undo", "Undo!", "Redo", "Export", "Reload"}; // Server-side settings protected int mode = -1; @@ -65,6 +65,9 @@ } public String toString() { - return name[mode]; + StringBuilder b = new StringBuilder(names[mode]); + if (filepath != null) b.append(" path="+filepath); + if (moveStackIndex > -1) b.append (" index="+moveStackIndex); + return b.toString(); } } Modified: trunk/18xx/rails/game/action/PossibleAction.java =================================================================== --- trunk/18xx/rails/game/action/PossibleAction.java 2011-03-17 21:16:44 UTC (rev 1500) +++ trunk/18xx/rails/game/action/PossibleAction.java 2011-03-26 20:42:51 UTC (rev 1501) @@ -38,6 +38,7 @@ public PossibleAction() { gameManager = GameManager.getInstance(); + if (gameManager == null) return; // TODO If created in client ?!?! Player player = gameManager.getCurrentPlayer(); if (player != null) { playerName = player.getName(); Modified: trunk/18xx/rails/ui/swing/ActionPerformer.java =================================================================== --- trunk/18xx/rails/ui/swing/ActionPerformer.java 2011-03-17 21:16:44 UTC (rev 1500) +++ trunk/18xx/rails/ui/swing/ActionPerformer.java 2011-03-26 20:42:51 UTC (rev 1501) @@ -5,7 +5,7 @@ public interface ActionPerformer { - public void updateStatus(); + public void updateStatus(boolean myTurn); public boolean process(PossibleAction action); Added: trunk/18xx/rails/ui/swing/AutoLoadPoller.java =================================================================== --- trunk/18xx/rails/ui/swing/AutoLoadPoller.java (rev 0) +++ trunk/18xx/rails/ui/swing/AutoLoadPoller.java 2011-03-26 20:42:51 UTC (rev 1501) @@ -0,0 +1,157 @@ +package rails.ui.swing; + +import java.io.*; +import java.util.Calendar; + +import javax.swing.SwingUtilities; + +import org.apache.log4j.Logger; + +import rails.game.action.GameAction; + +public class AutoLoadPoller extends Thread { + + private GameUIManager guiMgr; + private String saveDirectory; + private String savePrefix; + private String ownPostfix; + private int pollingInterval; + private int pollingStatus; + + private boolean pollingActive = false; + + private String lastSavedFilenameFilepath; + private String lastSavedFilename = ""; + + public static final int OFF = 0; + public static final int ON = 1; + public static final int SUSPENDED = 2; + + protected static Logger log = + Logger.getLogger(AutoLoadPoller.class.getPackage().getName()); + + public AutoLoadPoller (GameUIManager guiMgr, String saveDirectory, String savePrefix, String ownPostfix, + int status, int pollingInterval) { + + this.guiMgr = guiMgr; + this.saveDirectory = saveDirectory; + this.savePrefix = savePrefix; + this.ownPostfix = ownPostfix; + this.pollingStatus = status; + this.pollingInterval = pollingInterval; + + lastSavedFilenameFilepath = saveDirectory + "/" + savePrefix + ".last_rails"; + + } + + @Override + public void run () { + + log.info ("AutoLoadPoller started"); + + int secs, sleepTime; + String currentFilename; + + for (;;) { + + log.debug ("Polling cycle"); + // Process + if (pollingActive && pollingStatus == ON) { + log.debug("Polling..."); + try { + BufferedReader in = new BufferedReader (new FileReader (lastSavedFilenameFilepath)); + currentFilename = in.readLine(); + in.close(); + log.debug("Read filename "+currentFilename+"; last saved filename "+lastSavedFilename); + + if (!lastSavedFilename.equals(currentFilename)) { + final GameAction reload = new GameAction (GameAction.RELOAD); + reload.setFilepath(saveDirectory+"/"+currentFilename); + lastSavedFilename = currentFilename; + + // The GUI must be accessed on the event dispatch thread only. + SwingUtilities.invokeLater (new Runnable() { + public void run() { + guiMgr.processOnServer(reload); + } + }); + + } + + } catch (IOException e) { + + } + } + + + + secs = Calendar.getInstance().get(Calendar.SECOND); + try { + sleepTime = 1000 * (pollingInterval - secs%pollingInterval); + sleep (sleepTime); + } catch (InterruptedException e) { + continue; + } + } + // This thread never exits + } + + public String getSaveDirectory() { + return saveDirectory; + } + + public void setSaveDirectory(String saveDirectory) { + this.saveDirectory = saveDirectory; + } + + public String getSavePrefix() { + return savePrefix; + } + + public void setSavePrefix(String savePrefix) { + this.savePrefix = savePrefix; + } + + public String getOwnPostfix() { + return ownPostfix; + } + + public void setOwnPostfix(String ownPostfix) { + this.ownPostfix = ownPostfix; + } + + public int getPollingInterval() { + return pollingInterval; + } + + public void setPollingInterval(int pollingInterval) { + this.pollingInterval = pollingInterval; + } + + public int getStatus() { + return pollingStatus; + } + + public void setStatus(int status) { + this.pollingStatus = status; + } + + public boolean isActive() { + return pollingActive; + } + + public void setActive(boolean pollingActive) { + this.pollingActive = pollingActive; + log.debug("AutoLoad polling set to "+pollingActive); + } + + public String getLastSavedFilename() { + return lastSavedFilename; + } + + public void setLastSavedFilename(String lastSavedFilename) { + this.lastSavedFilename = lastSavedFilename; + } + + +} Property changes on: trunk/18xx/rails/ui/swing/AutoLoadPoller.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/18xx/rails/ui/swing/AutoSaveLoadDialog.java =================================================================== --- trunk/18xx/rails/ui/swing/AutoSaveLoadDialog.java (rev 0) +++ trunk/18xx/rails/ui/swing/AutoSaveLoadDialog.java 2011-03-26 20:42:51 UTC (rev 1501) @@ -0,0 +1,146 @@ +/* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/ui/swing/elements/AutoSaveLoadDialog.java,v 1.8 2010/01/31 22:22:34 macfreek Exp $*/ +package rails.ui.swing; + +import java.awt.*; +import java.awt.event.*; + +import javax.swing.*; + +import org.apache.log4j.Logger; + +import rails.ui.swing.elements.DialogOwner; +import rails.ui.swing.elements.Spinner; +import rails.util.LocalText; + +/** + * A generic dialog for presenting choices by radio buttons. + */ +public class AutoSaveLoadDialog extends JDialog implements ActionListener { + + private static final long serialVersionUID = 1L; + GridBagConstraints gc; + JPanel optionsPane, buttonPane; + JButton okButton, cancelButton; + JRadioButton[] choiceButtons; + Spinner intervalSpinner; + Dimension size, optSize; + ButtonGroup group; + DialogOwner owner; + + int status; + int interval; + + private static final int NUM_OPTIONS = 3; + + protected static Logger log = + Logger.getLogger(AutoSaveLoadDialog.class.getPackage().getName()); + + public AutoSaveLoadDialog(DialogOwner owner, int oldStatus, int oldInterval) { + super((Frame) null, "AutoSaveLoad settings", false); // Non-modal + this.owner = owner; + this.status = oldStatus; + this.interval = oldInterval; + + initialize(); + pack(); + + int x = 400; + int y = 400; + setLocation(x, y); + + setVisible(true); + setAlwaysOnTop(true); + } + + private void initialize() { + gc = new GridBagConstraints(); + + optionsPane = new JPanel(); + buttonPane = new JPanel(); + + okButton = new JButton(LocalText.getText("OK")); + okButton.setMnemonic(KeyEvent.VK_O); + okButton.addActionListener(this); + buttonPane.add(okButton); + + cancelButton = new JButton(LocalText.getText("Cancel")); + cancelButton.setMnemonic(KeyEvent.VK_C); + cancelButton.addActionListener(this); + buttonPane.add(cancelButton); + + choiceButtons = new JRadioButton[3]; + intervalSpinner = new Spinner (interval, 10, 0, 10); + + getContentPane().setLayout(new GridBagLayout()); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + optionsPane.setLayout(new GridBagLayout()); + // optionsPane.setBorder(BorderFactory.createLoweredBevelBorder()); + optionsPane.add(new JLabel(LocalText.getText("AutoSaveLoadOptions")), + constraints(0, 0, 10, 10, 10, 10)); + + choiceButtons = new JRadioButton[NUM_OPTIONS]; + group = new ButtonGroup(); + String[] options = new String[] { + LocalText.getText("Off"), + LocalText.getText("On"), + LocalText.getText("Suspended") + }; + + for (int i = 0; i < NUM_OPTIONS; i++) { + choiceButtons[i] = + new JRadioButton(options[i], i == status); + optionsPane.add(choiceButtons[i], constraints(0, 1 + i, 0, 0, 0, 0)); + choiceButtons[i].setPreferredSize(size); + group.add(choiceButtons[i]); + } + + optionsPane.add (new JLabel("Polling interval:"), constraints (0,5,0,0,0,0)); + intervalSpinner.setVisible(true); + optionsPane.add (intervalSpinner, constraints (1, 5, 0,0,0,0)); + optionsPane.add (new JLabel("sec."), constraints (2,5,0,0,0,0)); + + getContentPane().add(optionsPane, constraints(0, 0, 0, 0, 0, 0)); + getContentPane().add(buttonPane, constraints(0, 1, 0, 0, 0, 0)); + } + + private GridBagConstraints constraints(int gridx, int gridy, int leftinset, + int topinset, int rightinset, int bottominset) { + if (gridx >= 0) gc.gridx = gridx; + if (gridy >= 0) gc.gridy = gridy; + gc.fill = GridBagConstraints.BOTH; + gc.weightx = 0.5; + gc.weighty = 0.5; + if (leftinset >= 0) gc.insets.left = leftinset; + if (topinset >= 0) gc.insets.top = topinset; + if (rightinset >= 0) gc.insets.right = rightinset; + if (bottominset >= 0) gc.insets.bottom = bottominset; + + return gc; + } + + public void actionPerformed(ActionEvent arg0) { + if (arg0.getSource().equals(okButton)) { + for (int i = 0; i < NUM_OPTIONS; i++) { + if (choiceButtons[i].isSelected()) { + status = i; + break; + } + } + interval = ((Integer) intervalSpinner.getValue()).intValue(); + } else if (arg0.getSource().equals(cancelButton)) { + status = -1; + } + this.setVisible(false); + this.dispose(); + owner.dialogActionPerformed(); + } + + public synchronized int getStatus() { + return status; + } + + public synchronized int getInterval() { + return interval; + } +} Property changes on: trunk/18xx/rails/ui/swing/AutoSaveLoadDialog.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/18xx/rails/ui/swing/GameUIManager.java =================================================================== --- trunk/18xx/rails/ui/swing/GameUIManager.java 2011-03-17 21:16:44 UTC (rev 1500) +++ trunk/18xx/rails/ui/swing/GameUIManager.java 2011-03-26 20:42:51 UTC (rev 1501) @@ -4,7 +4,7 @@ import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; -import java.io.File; +import java.io.*; import java.text.SimpleDateFormat; import java.util.*; @@ -60,11 +60,20 @@ protected String saveDirectory; protected String savePattern; protected String saveExtension; + protected String savePrefix; protected String saveSuffixSpec = ""; protected String saveSuffix = ""; protected String providedName = null; protected SimpleDateFormat saveDateTimeFormat; protected File lastFile, lastDirectory; + + protected boolean autoSaveLoadInitialized = false; + protected int autoSaveLoadStatus = 0; + protected int autoSaveLoadPollingInterval = 30; + protected AutoLoadPoller autoLoadPoller = null; + protected boolean myTurn = true; + protected String lastSavedFilenameFilepath; + protected String lastSavedFilename = ""; protected WindowSettings windowSettings; @@ -88,6 +97,7 @@ instance = this; this.gameManager = gameManager; uiHints = gameManager.getUIHints(); + savePrefix = gameManager.getGameName(); initWindowSettings(); initSaveSettings(); @@ -133,7 +143,9 @@ } saveSuffixSpec = Config.get("save.filename.suffix"); if (Util.hasValue(saveSuffixSpec) && !saveSuffixSpec.equals(NEXT_PLAYER_SUFFIX)) { - saveSuffix = "_" + saveSuffixSpec; + saveSuffix = saveSuffixSpec; + } else { + saveSuffix = getPlayerNames().get(0); } } @@ -241,30 +253,26 @@ // Follow-up the result log.debug("==Result from server: " + result); reportWindow.updateLog(); - /* - if (DisplayBuffer.getAutoDisplay()) { - if (displayServerMessage()) { - // Interrupt processing. - // Will be continued via dialogActionPerformed(). - return true; + + // Process any autosaving and turn relinquishing, resp. autoloading and turn pickup + if (autoSaveLoadInitialized && autoSaveLoadStatus != AutoLoadPoller.OFF) { + Player newPlayer = getCurrentPlayer(); + boolean wasMyTurn = myTurn; + myTurn = newPlayer.getName().equals(saveSuffix); + if (newPlayer != player) { + if (wasMyTurn && !myTurn) { + log.info ("Relinquishing turn to "+newPlayer.getName()); + autoSave (newPlayer.getName()); + autoLoadPoller.setLastSavedFilename(lastSavedFilename); + autoLoadPoller.setActive(true); + } else if (!wasMyTurn && myTurn) { + log.info ("Resuming turn as "+saveSuffix); + autoLoadPoller.setActive(false); + } } - }*/ + } } - // End of game checks -// if (gameManager.isGameOver()) { -// -// statusWindow.reportGameOver(); -// -// return true; -// -// } -// else if (gameManager.getBank().isJustBroken()) { -// -// statusWindow.reportBankBroken(); -// -// } - // Check in which round we are now, // and make sure that the right window is active. updateUI(); @@ -450,19 +458,19 @@ if (StartRoundWindow.class.isAssignableFrom(activeWindow.getClass())) { log.debug("Updating Start round window"); - startRoundWindow.updateStatus(); + startRoundWindow.updateStatus(myTurn); startRoundWindow.setSRPlayerTurn(startRound.getCurrentPlayerIndex()); } else if (StatusWindow.class.isAssignableFrom(activeWindow.getClass())) { // } else { log.debug("Updating Stock (status) round window"); - statusWindow.updateStatus(); + statusWindow.updateStatus(myTurn); } else if (ORWindow.class.isAssignableFrom(activeWindow.getClass())) { log.debug("Updating Operating round window"); - orUIManager.updateStatus(); + orUIManager.updateStatus(myTurn); } updateStatus(activeWindow); @@ -648,16 +656,48 @@ RepayLoans action = (RepayLoans) currentDialogAction; int selected = dialog.getSelectedOption(); action.setNumberTaken(action.getMinNumber() + selected); + } else if (currentDialog instanceof MessageDialog) { // Nothing to do currentDialogAction = null; // Should already be null + + } else if (currentDialog instanceof AutoSaveLoadDialog) { + + autoSaveLoadGame2 ((AutoSaveLoadDialog)currentDialog); + } else { return; } } - processOnServer(currentDialogAction); + if (currentDialogAction != null) processOnServer(currentDialogAction); + } + + protected void autoSave (String newPlayer) { + lastSavedFilename = savePrefix + "_" + + saveDateTimeFormat.format(new Date()) + "_" + + newPlayer + "." + + saveExtension; + GameAction saveAction = new GameAction(GameAction.SAVE); + saveAction.setFilepath(saveDirectory + "/" + lastSavedFilename); + log.debug("Autosaving to "+lastSavedFilename); + processOnServer (saveAction); + + try { + File f = new File (lastSavedFilenameFilepath); + PrintWriter out = new PrintWriter (new FileWriter (f)); + out.println (lastSavedFilename); + out.close(); + } catch (IOException e) { + log.error ("Exception whilst autosaving file '"+lastSavedFilenameFilepath+"'", e); + } + + } + + protected boolean pollingIsOn () { + return autoLoadPoller != null && autoLoadPoller.getStatus() == AutoLoadPoller.ON; + } /** Stub, can be overridden by subclasses */ protected boolean checkGameSpecificDialogAction() { @@ -713,8 +753,8 @@ if (providedName != null) { filename = providedName; } else { - filename = saveDirectory + "/" + gameManager.getGameName() + "_" - + saveDateTimeFormat.format(new Date()) + filename = saveDirectory + "/" + savePrefix + "_" + + saveDateTimeFormat.format(new Date())+ "_" + saveSuffix + ".txt"; } @@ -747,11 +787,11 @@ filename = providedName; } else { if (NEXT_PLAYER_SUFFIX.equals(saveSuffixSpec)) { - saveSuffix = "_" + gameManager.getCurrentPlayer().getName().replaceAll("[^-\\w\\.]", "_"); + saveSuffix = gameManager.getCurrentPlayer().getName().replaceAll("[^-\\w\\.]", "_"); } filename = - saveDirectory + "/" + gameManager.getGameName() + "_" - + saveDateTimeFormat.format(new Date()) + saveDirectory + "/" + savePrefix + "_" + + saveDateTimeFormat.format(new Date()) + "_" + saveSuffix + "." + saveExtension; } @@ -767,7 +807,17 @@ String filepath = selectedFile.getPath(); saveDirectory = selectedFile.getParent(); if (!selectedFile.getName().equalsIgnoreCase(proposedFile.getName())) { - providedName = filepath; + // User has not accepted the default name but entered a different one. + // Check the new name. If only the prefix has changed, only remember that part. + String[] proposedParts = proposedFile.getName().split("_", 2); + String[] selectedParts = selectedFile.getName().split("_", 2); + if (!proposedParts[0].equals(selectedParts[0]) + && proposedParts[1].equals(selectedParts[1])) { + savePrefix = selectedParts[0]; + } else { + // Otherwise, remember and keep using the whole filename. + providedName = filepath; + } } saveAction.setFilepath(filepath); processOnServer(saveAction); @@ -791,7 +841,81 @@ } - public void setSaveDirectory(String saveDirectory) { + public void autoSaveLoadGame () { + + AutoSaveLoadDialog dialog = new AutoSaveLoadDialog (this, + autoSaveLoadStatus, + autoSaveLoadPollingInterval); + setCurrentDialog(dialog, null); + } + + public void autoSaveLoadGame2 (AutoSaveLoadDialog dialog) { + + autoSaveLoadStatus = dialog.getStatus(); + autoSaveLoadPollingInterval = dialog.getInterval(); + + if (autoLoadPoller == null && autoSaveLoadStatus > 0) { + autoLoadPoller = new AutoLoadPoller (this, saveDirectory, savePrefix, + saveSuffix, autoSaveLoadStatus, autoSaveLoadPollingInterval); + autoLoadPoller.start(); + } else if (autoLoadPoller != null) { + autoLoadPoller.setStatus(autoSaveLoadStatus); + autoLoadPoller.setPollingInterval(autoSaveLoadPollingInterval); + } + log.debug("AutoSaveLoad parameters: status="+autoSaveLoadStatus + +" interval="+autoSaveLoadPollingInterval); + + if (autoLoadPoller != null && autoSaveLoadStatus != AutoLoadPoller.OFF + && !autoSaveLoadInitialized) { + + /* The first time (only) we use the normal save process, + * so the player can select a directory, and change + * the prefix if so desired. + */ + GameAction saveAction = new GameAction(GameAction.SAVE); + saveGame (saveAction); + File lastSavedFile = new File (saveAction.getFilepath()); + saveDirectory = lastSavedFile.getParentFile().getPath(); + + /* Now also save the "last saved file" file */ + String lastSavedFilename = lastSavedFile.getName(); + lastSavedFilenameFilepath = saveDirectory + "/" + savePrefix + ".last_rails"; + try { + File f = new File (lastSavedFilenameFilepath); + PrintWriter out = new PrintWriter (new FileWriter (f)); + out.println (lastSavedFilename); + out.close(); + autoSaveLoadInitialized = true; + } catch (IOException e) { + log.error ("Exception whilst creating .last_rails file '" + + lastSavedFilenameFilepath + "'", e); + } + } + + myTurn = getCurrentPlayer().getName().equals(saveSuffix); + + if (!myTurn) { + // Start autoload polling + autoLoadPoller.setActive(autoSaveLoadStatus == AutoLoadPoller.ON && !myTurn); + log.debug("MyTurn="+myTurn+" poller status="+autoLoadPoller.getStatus() + +" active="+autoLoadPoller.isActive()); + + } else { + myTurn = true; + log.debug("MyTurn="+myTurn); + } + + } + + public boolean isMyTurn() { + return myTurn; + } + + public void setMyTurn(boolean myTurn) { + this.myTurn = myTurn; + } + + public void setSaveDirectory(String saveDirectory) { this.saveDirectory = saveDirectory; } Modified: trunk/18xx/rails/ui/swing/ORUIManager.java =================================================================== --- trunk/18xx/rails/ui/swing/ORUIManager.java 2011-03-17 21:16:44 UTC (rev 1500) +++ trunk/18xx/rails/ui/swing/ORUIManager.java 2011-03-26 20:42:51 UTC (rev 1501) @@ -498,7 +498,7 @@ } else { log.debug("Allocation is unknown, asking for it"); setLocalStep(SELECT_PAYOUT); - updateStatus(action); + updateStatus(action, true); // Locally update revenue if we don't inform the server yet. orPanel.setRevenue(orCompIndex, amount); @@ -1443,13 +1443,13 @@ } - public void updateStatus() { + public void updateStatus(boolean myTurn) { - updateStatus(null); + updateStatus(null, myTurn); } - public void updateStatus(PossibleAction actionToComplete) { + public void updateStatus(PossibleAction actionToComplete, boolean myTurn) { mapRelatedActions.clear(); @@ -1457,6 +1457,8 @@ messagePanel.setMessage(null); + if (!myTurn) return; + if (actionToComplete != null) { log.debug("ExecutedAction: " + actionToComplete); } Modified: trunk/18xx/rails/ui/swing/ORWindow.java =================================================================== --- trunk/18xx/rails/ui/swing/ORWindow.java 2011-03-17 21:16:44 UTC (rev 1500) +++ trunk/18xx/rails/ui/swing/ORWindow.java 2011-03-26 20:42:51 UTC (rev 1501) @@ -192,12 +192,12 @@ requestFocus(); } - public void updateStatus() { + public void updateStatus(boolean myTurn) { // Safety check. Do nothing if this method is called outside Operating Rounds, // for instance when a token is exchanged during a Stock Round. if (!(gameUIManager.getCurrentRound() instanceof OperatingRound)) return; - orUIManager.updateStatus(); + orUIManager.updateStatus(myTurn); requestFocus(); } Modified: trunk/18xx/rails/ui/swing/StartRoundWindow.java =================================================================== --- trunk/18xx/rails/ui/swing/StartRoundWindow.java 2011-03-17 21:16:44 UTC (rev 1500) +++ trunk/18xx/rails/ui/swing/StartRoundWindow.java 2011-03-26 20:42:51 UTC (rev 1501) @@ -374,7 +374,7 @@ } - public void updateStatus() { + public void updateStatus(boolean myTurn) { StartItem item; int i, j; @@ -384,6 +384,8 @@ } // Unselect the selected private dummyButton.setSelected(true); + + if (!myTurn) return; // For debugging for (PossibleAction action : possibleActions.getList()) { Modified: trunk/18xx/rails/ui/swing/StatusWindow.java =================================================================== --- trunk/18xx/rails/ui/swing/StatusWindow.java 2011-03-17 21:16:44 UTC (rev 1500) +++ trunk/18xx/rails/ui/swing/StatusWindow.java 2011-03-26 20:42:51 UTC (rev 1501) @@ -31,6 +31,8 @@ protected static final String SAVE_CMD = "Save"; protected static final String RELOAD_CMD = "Reload"; + + protected static final String AUTOSAVELOAD_CMD = "AutoSaveLoad"; protected static final String EXPORT_CMD = "Export"; @@ -80,8 +82,7 @@ private JMenuItem menuItem; - private ActionMenuItem saveItem; - private ActionMenuItem reloadItem; + private ActionMenuItem actionMenuItem; private ActionMenuItem undoItem, forcedUndoItem, redoItem, redoItem2; @@ -109,27 +110,36 @@ moderatorMenu.setMnemonic(KeyEvent.VK_M); specialMenu.setMnemonic(KeyEvent.VK_S); - saveItem = new ActionMenuItem(LocalText.getText("SAVE")); - saveItem.setActionCommand(SAVE_CMD); - saveItem.setMnemonic(KeyEvent.VK_S); - saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, + actionMenuItem = new ActionMenuItem(LocalText.getText("SAVE")); + actionMenuItem.setActionCommand(SAVE_CMD); + actionMenuItem.setMnemonic(KeyEvent.VK_S); + actionMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.ALT_MASK)); - saveItem.addActionListener(this); - saveItem.setEnabled(true); - saveItem.setPossibleAction(new GameAction(GameAction.SAVE)); - fileMenu.add(saveItem); + actionMenuItem.addActionListener(this); + actionMenuItem.setEnabled(true); + actionMenuItem.setPossibleAction(new GameAction(GameAction.SAVE)); + fileMenu.add(actionMenuItem); - reloadItem = new ActionMenuItem(LocalText.getText("Reload")); - reloadItem.setActionCommand(RELOAD_CMD); - reloadItem.setMnemonic(KeyEvent.VK_R); - reloadItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, + actionMenuItem = new ActionMenuItem(LocalText.getText("Reload")); + actionMenuItem.setActionCommand(RELOAD_CMD); + actionMenuItem.setMnemonic(KeyEvent.VK_R); + actionMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK)); - reloadItem.addActionListener(this); - reloadItem.setEnabled(true); - reloadItem.setPossibleAction(new GameAction(GameAction.RELOAD)); - fileMenu.add(reloadItem); + actionMenuItem.addActionListener(this); + actionMenuItem.setEnabled(true); + actionMenuItem.setPossibleAction(new GameAction(GameAction.RELOAD)); + fileMenu.add(actionMenuItem); - // export menu item + menuItem = new JMenuItem(LocalText.getText("AutoSaveLoad")); + menuItem.setActionCommand(AUTOSAVELOAD_CMD); + menuItem.setMnemonic(KeyEvent.VK_A); + menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, + ActionEvent.ALT_MASK)); + menuItem.addActionListener(this); + menuItem.setEnabled(true); + fileMenu.add(menuItem); + + // export menu item // exportItem = new ActionMenuItem(LocalText.getText("EXPORT")); // exportItem.setActionCommand(EXPORT_CMD); // exportItem.addActionListener(this); @@ -182,7 +192,7 @@ menuItem.addActionListener(this); optMenu.add(menuItem); - // new config menu only for non legacy configgfiles + // new config menu only for non legacy configfiles if (!Config.isLegacyConfigFile()) { menuItem = new JCheckBoxMenuItem(LocalText.getText("CONFIG")); menuItem.setName(CONFIG_CMD); @@ -289,9 +299,6 @@ setSize(800, 300); -// Rectangle bounds = graphicsConfiguration.getBounds(); -// setLocation(bounds.x+ 25, bounds.y + 450); - buttonPanel.setBorder(BorderFactory.createEtchedBorder()); buttonPanel.setOpaque(false); @@ -350,17 +357,13 @@ forcedUndoItem.setEnabled(false); redoItem.setEnabled(false); redoItem2.setEnabled(false); - // SAVE is always enabled - + // SAVE, RELOAD, AUTOSAVELOAD are always enabled + List<GameAction> gameActions = possibleActions.getType(GameAction.class); if (gameActions != null) { for (GameAction na : gameActions) { switch (na.getMode()) { - // SAVE is now enabled by default - //case GameAction.SAVE: - // saveItem.setPossibleAction(na); - // break; case GameAction.UNDO: undoItem.setEnabled(true); undoItem.setPossibleAction(na); @@ -425,11 +428,13 @@ } - public void updateStatus() { + public void updateStatus(boolean myTurn) { if (!(currentRound instanceof StockRound || currentRound instanceof EndOfGameRound)) return; + if (!myTurn) return; + // Moved here from StatusWindow_1856. It's getting generic... if (possibleActions.contains(DiscardTrain.class)) { immediateAction = possibleActions.getType(DiscardTrain.class).get(0); @@ -635,6 +640,8 @@ gameUIManager.orWindow.setVisible(((JMenuItem) actor.getSource()).isSelected()); } else if (command.equals(CONFIG_CMD)) { gameUIManager.configWindow.setVisible(((JMenuItem) actor.getSource()).isSelected()); + } else if (command.equals(AUTOSAVELOAD_CMD)) { + gameUIManager.autoSaveLoadGame(); } else if (executedAction == null) { ; } else if (executedAction instanceof GameAction) { Modified: trunk/18xx/rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java =================================================================== --- trunk/18xx/rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java 2011-03-17 21:16:44 UTC (rev 1500) +++ trunk/18xx/rails/ui/swing/gamespecific/_1835/StatusWindow_1835.java 2011-03-26 20:42:51 UTC (rev 1501) @@ -31,10 +31,10 @@ } @Override - public void updateStatus() { + public void updateStatus(boolean myTurn) { RoundI currentRound = gameUIManager.getCurrentRound(); if (!(currentRound instanceof PrussianFormationRound)) { - super.updateStatus(); + super.updateStatus(myTurn); } else if (possibleActions.contains(FoldIntoPrussian.class)) { immediateAction = possibleActions.getType(FoldIntoPrussian.class).get(0); } else if (possibleActions.contains(DiscardTrain.class)) { Modified: trunk/18xx/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java =================================================================== --- trunk/18xx/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java 2011-03-17 21:16:44 UTC (rev 1500) +++ trunk/18xx/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java 2011-03-26 20:42:51 UTC (rev 1501) @@ -20,10 +20,10 @@ } @Override - public void updateStatus() { + public void updateStatus(boolean myTurn) { RoundI currentRound = gameUIManager.getCurrentRound(); if (!(currentRound instanceof CGRFormationRound)) { - super.updateStatus(); + super.updateStatus(myTurn); } else if (possibleActions.contains(RepayLoans.class)) { //RepayLoans action = possibleActions.getType(RepayLoans.class).get(0); //repayLoans (action); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |