From: <ev...@us...> - 2010-10-27 21:54:18
|
Revision: 1454 http://rails.svn.sourceforge.net/rails/?rev=1454&view=rev Author: evos Date: 2010-10-27 21:54:11 +0000 (Wed, 27 Oct 2010) Log Message: ----------- Partial fix of the map display problem when a game is started via RunGame with a saved file parameter. Modified Paths: -------------- trunk/18xx/rails/game/GameManager.java trunk/18xx/rails/game/GameManagerI.java trunk/18xx/rails/game/OperatingRound.java trunk/18xx/rails/ui/swing/ORUIManager.java trunk/18xx/rails/ui/swing/UpgradesPanel.java trunk/18xx/rails/ui/swing/hexmap/GUITile.java Modified: trunk/18xx/rails/game/GameManager.java =================================================================== --- trunk/18xx/rails/game/GameManager.java 2010-10-16 22:43:59 UTC (rev 1453) +++ trunk/18xx/rails/game/GameManager.java 2010-10-27 21:54:11 UTC (rev 1454) @@ -158,7 +158,7 @@ * It will only be used inside the GM objects. * All other objects will access it via NDC. */ - protected static final String GM_KEY = "01"; + public static final String GM_KEY = "01"; public static final String GM_NAME = "GameManager"; /** @@ -205,9 +205,14 @@ * <br>This is a fix to maintain backwards compatibility when redundant * actions are skipped in new code versions (such as the bypassing of * a treasury trading step if it cannot be executed). - * <br>This flag will be reset after processing <i>any</i> action (not just Done). + * <br>This flag must be reset after processing <i>any</i> action (not just Done). */ protected boolean skipNextDone = false; + /** Step that must be in effect to do an actual Done skip during reloading. + * <br> This is to ensure that Done actions in different OR steps are + * considered separately. + */ + protected GameDef.OrStep skippedStep = null; protected static Logger log = Logger.getLogger(GameManager.class.getPackage().getName()); @@ -950,7 +955,7 @@ DisplayBuffer.clear(); - // XXX TEMPORARY FIX TO ALLOW OLD 1856 SAVED FILES TO BE PROCESSED + // TEMPORARY FIX TO ALLOW OLD 1856 SAVED FILES TO BE PROCESSED if (gameName.equals("1856") && possibleActions.contains(RepayLoans.class) && (!possibleActions.contains(action.getClass()) @@ -967,17 +972,19 @@ try { log.debug("Action ("+action.getPlayerName()+"): " + action); - // XXX FOR BACKWARDS COMPATIBILITY + // FOR BACKWARDS COMPATIBILITY boolean doProcess = true; - log.debug("SkipNextDone="+skipNextDone); if (skipNextDone) { if (action instanceof NullAction && ((NullAction)action).getMode() == NullAction.DONE) { - log.info("Skipping processing a Done action during reload"); - doProcess = false; + if (currentRound.get() instanceof OperatingRound + && ((OperatingRound)currentRound.get()).getStep() == skippedStep) { + doProcess = false; + } } } skipNextDone = false; + skippedStep = null; if (doProcess && !processCorrectionActions(action) && !getCurrentRound().process(action)) { String msg = "Player "+action.getPlayerName()+"\'s action \"" @@ -1717,8 +1724,9 @@ this.reloading = reloading; } - public void setSkipDone () { + public void setSkipDone (GameDef.OrStep step) { skipNextDone = true; + skippedStep = step; } } Modified: trunk/18xx/rails/game/GameManagerI.java =================================================================== --- trunk/18xx/rails/game/GameManagerI.java 2010-10-16 22:43:59 UTC (rev 1453) +++ trunk/18xx/rails/game/GameManagerI.java 2010-10-27 21:54:11 UTC (rev 1454) @@ -207,5 +207,5 @@ public List<PublicCompanyI> getCompaniesInRunningOrder (); public boolean isReloading(); public void setReloading(boolean reloading); - public void setSkipDone (); + public void setSkipDone (GameDef.OrStep step); } \ No newline at end of file Modified: trunk/18xx/rails/game/OperatingRound.java =================================================================== --- trunk/18xx/rails/game/OperatingRound.java 2010-10-16 22:43:59 UTC (rev 1453) +++ trunk/18xx/rails/game/OperatingRound.java 2010-10-27 21:54:11 UTC (rev 1454) @@ -1265,7 +1265,7 @@ // XXX For BACKWARDS COMPATIBILITY only, // register a Done skip action during reloading. if (gameManager.isReloading()) { - gameManager.setSkipDone(); + gameManager.setSkipDone(GameDef.OrStep.TRADE_SHARES); log.debug("If the next saved action is 'Done', skip it"); } log.info("Skipping Treasury share trading step"); Modified: trunk/18xx/rails/ui/swing/ORUIManager.java =================================================================== --- trunk/18xx/rails/ui/swing/ORUIManager.java 2010-10-16 22:43:59 UTC (rev 1453) +++ trunk/18xx/rails/ui/swing/ORUIManager.java 2010-10-27 21:54:11 UTC (rev 1454) @@ -31,6 +31,7 @@ private RemainingTilesWindow remainingTiles; public GameUIManager gameUIManager; + protected TileManager tileManager; private OperatingRound oRound; private PublicCompanyI[] companies; @@ -95,6 +96,7 @@ public void setGameUIManager (GameUIManager gameUIManager) { this.gameUIManager = gameUIManager; + this.tileManager = gameUIManager.getGameManager().getTileManager(); } public void init(ORWindow orWindow) { @@ -1904,8 +1906,12 @@ return gameUIManager; } - private void displayRemainingTiles() { + public TileManager getTileManager() { + return tileManager; + } + private void displayRemainingTiles() { + if (remainingTiles == null) { remainingTiles = new RemainingTilesWindow(orWindow); } else { Modified: trunk/18xx/rails/ui/swing/UpgradesPanel.java =================================================================== --- trunk/18xx/rails/ui/swing/UpgradesPanel.java 2010-10-16 22:43:59 UTC (rev 1453) +++ trunk/18xx/rails/ui/swing/UpgradesPanel.java 2010-10-27 21:54:11 UTC (rev 1454) @@ -19,12 +19,11 @@ import rails.ui.swing.elements.ActionLabel; import rails.ui.swing.hexmap.GUIHex; import rails.ui.swing.hexmap.HexMap; -import rails.util.Config; import rails.util.LocalText; public class UpgradesPanel extends Box implements MouseListener, ActionListener { private static final long serialVersionUID = 1L; - + private ORUIManager orUIManager; private List<ActionLabel> tokenLabels; private List<CorrectionTokenLabel> correctionTokenLabels; @@ -34,7 +33,7 @@ static private Color defaultLabelBgColour = new JLabel("").getBackground(); static private Color selectedLabelBgColour = new Color(255, 220, 150); private static final int defaultNbPanelElements = 15; - + private JPanel upgradePanel; private JScrollPane scrollPane; private Dimension preferredSize; @@ -109,10 +108,10 @@ } } } - + public void showUpgrades() { upgradePanel.removeAll(); - + // reset to the number of elements GridLayout panelLayout = (GridLayout)upgradePanel.getLayout(); panelLayout.setRows(defaultNbPanelElements); @@ -200,12 +199,12 @@ // deactivate correctionTokenMode and tokenmode correctionTokenMode = false; tokenMode = false; - + // activate upgrade panel upgradePanel.removeAll(); GridLayout panelLayout = (GridLayout)upgradePanel.getLayout(); List<TileI> tiles = orUIManager.tileUpgrades; - + if (tiles == null || tiles.size() == 0) { // reset to the number of elements panelLayout.setRows(defaultNbPanelElements); @@ -249,12 +248,12 @@ // activate correctionTokenMode and deactivate standard tokenMode correctionTokenMode = true; tokenMode = false; - + // activate upgrade panel upgradePanel.removeAll(); GridLayout panelLayout = (GridLayout)upgradePanel.getLayout(); List<? extends TokenI> tokens = orUIManager.tokenLays; - + if (tokens == null || tokens.size() == 0) { // reset to the number of elements panelLayout.setRows(defaultNbPanelElements); @@ -288,16 +287,16 @@ correctionTokenLabels.add(tokenLabel); upgradePanel.add(tokenLabel); } - + } upgradePanel.add(doneButton); upgradePanel.add(cancelButton); // repaint(); revalidate(); - + } - + public void clear() { upgradePanel.removeAll(); upgradePanel.add(doneButton); @@ -456,25 +455,25 @@ setCancelEnabled(false); } - + /** ActionLabel extension that allows to attach the token */ private class CorrectionTokenLabel extends ActionLabel { - + private static final long serialVersionUID = 1L; - + private TokenI token; - + CorrectionTokenLabel(Icon tokenIcon, TokenI token) { super(tokenIcon); this.token = token; } - + TokenI getToken() { return token; } - + } - + /** JLabel extension to allow attaching the internal hex ID */ private class HexLabel extends JLabel { @@ -496,11 +495,11 @@ public String getToolTip() { return toolTip; } - + void setTextFromTile(TileI tile) { StringBuffer text = new StringBuffer(); if (tile.getExternalId() > 0) { - text.append("<HTML><BODY>" + tile.getExternalId()); + text.append("<HTML><BODY>" + tile.getExternalId()); if (tile.countFreeTiles() != -1) { text.append("<BR> (" + tile.countFreeTiles() + ")"); } Modified: trunk/18xx/rails/ui/swing/hexmap/GUITile.java =================================================================== --- trunk/18xx/rails/ui/swing/hexmap/GUITile.java 2010-10-16 22:43:59 UTC (rev 1453) +++ trunk/18xx/rails/ui/swing/hexmap/GUITile.java 2010-10-27 21:54:11 UTC (rev 1454) @@ -51,7 +51,8 @@ this.guiHex = guiHex; this.tileId = tileId; this.hex = (MapHex)guiHex.getModel(); - tile = GameManager.getInstance().getTileManager().getTile(tileId); + TileManager tileManager = guiHex.getHexMap().orUIManager.getTileManager(); + tile = tileManager.getTile(tileId); if (hex.getTileOrientation() == MapHex.EW) { baseRotation = 0.5 * DEG60; @@ -248,6 +249,7 @@ public void paintTile(Graphics2D g2, int x, int y) { int zoomStep = guiHex.getHexMap().getZoomStep(); + tileImage = imageLoader.getTile(tileId, zoomStep); if (tileImage != null) { @@ -280,6 +282,8 @@ AffineTransformOp aop = new AffineTransformOp(af, rh); g2.drawImage(tileImage, aop, x - xCenter, y - yCenter); + } else { + log.error("No image for tile "+tileId+" on hex "+guiHex.getName()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |