From: Erik V. <ev...@us...> - 2010-01-14 20:49:36
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv4187/rails/ui/swing Modified Files: GameUIManager.java Log Message: Reworked updateUI() for use of GuiHints Index: GameUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameUIManager.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** GameUIManager.java 11 Jan 2010 23:06:15 -0000 1.32 --- GameUIManager.java 14 Jan 2010 20:49:22 -0000 1.33 *************** *** 9,13 **** import org.apache.log4j.Logger; ! import rails.common.Defs; import rails.game.*; import rails.game.action.*; --- 9,14 ---- import org.apache.log4j.Logger; ! import rails.common.GuiDef; ! import rails.common.GuiHints; import rails.game.*; import rails.game.action.*; *************** *** 33,42 **** public static ImageLoader imageLoader; ! private GameManagerI gameManager; ! private PossibleAction lastAction; ! private ActionPerformer activeWindow = null; ! private RoundI currentRound; ! private RoundI previousRound = null; ! private StartRound startRound; protected static final String DEFAULT_SAVE_DIRECTORY = "save"; --- 34,49 ---- public static ImageLoader imageLoader; ! protected GameManagerI gameManager; ! protected PossibleAction lastAction; ! protected ActionPerformer activeWindow = null; ! protected StartRound startRound; ! ! protected RoundI currentRound; ! protected RoundI previousRound; ! protected Class<? extends RoundI> previousRoundType = null; ! protected Class<? extends RoundI> currentRoundType = null; ! protected GuiHints uiHints= null; ! protected String previousRoundName; ! protected String currentRoundName; protected static final String DEFAULT_SAVE_DIRECTORY = "save"; *************** *** 54,57 **** --- 61,68 ---- protected File lastFile, lastDirectory; + protected boolean previousStockChartVisibilityHint; + protected boolean previousStatusWindowVisibilityHint; + protected boolean previousORWindowVisibilityHint; + protected static Logger log = Logger.getLogger(GameUIManager.class.getPackage().getName()); *************** *** 65,68 **** --- 76,80 ---- instance = this; this.gameManager = gameManager; + uiHints = gameManager.getUIHints(); saveDirectory = Config.get("save.directory"); *************** *** 98,102 **** orUIManager = orWindow.getORUIManager(); ! String statusWindowClassName = getClassName(Defs.ClassName.STATUS_WINDOW); try { Class<? extends StatusWindow> statusWindowClass = --- 110,114 ---- orUIManager = orWindow.getORUIManager(); ! String statusWindowClassName = getClassName(GuiDef.ClassName.STATUS_WINDOW); try { Class<? extends StatusWindow> statusWindowClass = *************** *** 171,207 **** public void updateUI() { ! currentRound = gameManager.getCurrentRound(); ! log.debug("Current round=" + currentRound + ", previous round=" ! + previousRound); ! // Process consequences of a round type change to the UI ! Class<? extends RoundI> previousRoundType ! = previousRound == null ? null : previousRound.getClass(); ! Class<? extends RoundI> currentRoundType ! = currentRound.getClass(); ! Class<? extends RoundI> previousRoundUItype ! = previousRound == null ? null : previousRound.getRoundTypeForUI(); ! Class<? extends RoundI> currentRoundUItype ! = currentRound.getRoundTypeForUI(); ! /* Distinguish actual round type from visible round type. ! * Actual round type is the class of the active Round subclass. ! * Visible round type is the class of one of the three 'basic' ! * round types: Start, Stock or Operating. ! * The latter type determines what UI windows will become visible. ! */ /* Process actual round type changes */ ! if (previousRound == null || !previousRound.equals(currentRound)) { /* Finish previous round UI processing */ ! if (previousRound != null) { if (StockRound.class.isAssignableFrom(previousRoundType)) { ! log.debug("UI leaving Stock Round"); statusWindow.finishRound(); } else if (StartRound.class.isAssignableFrom(previousRoundType)) { ! log.debug("UI leaving Start Round"); if (startRoundWindow != null) { startRoundWindow.close(); --- 183,209 ---- public void updateUI() { ! previousRoundType = currentRoundType; ! previousRoundName = currentRoundName; ! previousRound = currentRound; ! currentRound = gameManager.getCurrentRound(); ! currentRoundName = currentRound.toString(); ! log.debug("Current round=" + currentRoundName + ", previous round=" ! + previousRoundName); ! currentRoundType = uiHints.getCurrentRoundType(); /* Process actual round type changes */ ! if (previousRoundType != currentRoundType) { /* Finish previous round UI processing */ ! if (previousRoundType != null) { if (StockRound.class.isAssignableFrom(previousRoundType)) { ! log.debug("UI leaving Stock Round "+previousRoundName); statusWindow.finishRound(); } else if (StartRound.class.isAssignableFrom(previousRoundType)) { ! log.debug("UI leaving Start Round "+previousRoundName); if (startRoundWindow != null) { startRoundWindow.close(); *************** *** 209,223 **** } } else if (OperatingRound.class.isAssignableFrom(previousRoundType)) { ! log.debug("UI leaving Operating Round"); orUIManager.finish(); } else if (SwitchableUIRound.class.isAssignableFrom(previousRoundType) ) { ! log.debug("UI leaving switchable round type"); } } // Start the new round UI processing if (StartRound.class.isAssignableFrom(currentRoundType)) { ! log.debug("UI entering Start Round"); startRound = (StartRound) currentRound; if (startRoundWindow == null) { --- 211,229 ---- } } else if (OperatingRound.class.isAssignableFrom(previousRoundType)) { ! log.debug("UI leaving Operating Round "+previousRoundName); orUIManager.finish(); } else if (SwitchableUIRound.class.isAssignableFrom(previousRoundType) ) { ! log.debug("UI leaving switchable round type "+previousRoundName); } } + } + + if (currentRound != previousRound) { + // Start the new round UI processing if (StartRound.class.isAssignableFrom(currentRoundType)) { ! log.debug("UI entering Start Round "+currentRoundName); startRound = (StartRound) currentRound; if (startRoundWindow == null) { *************** *** 227,293 **** } else if (StockRound.class.isAssignableFrom(currentRoundType)) { ! log.debug("UI entering Stock Round"); ! orWindow.setVisible(false); ! stockChart.setVisible(true); } else if (OperatingRound.class.isAssignableFrom(currentRoundType)) { ! log.debug("UI entering Operating Round"); orUIManager.initOR((OperatingRound) currentRound); - orWindow.setVisible(true); - stockChart.setVisible(false); } else if (SwitchableUIRound.class.isAssignableFrom(currentRoundType) ) { ! log.debug("UI entering switchable round type"); ! orWindow.setVisible(true); statusWindow.pack(); - stockChart.setVisible(true); } } /* Process visible round type changes */ - if (previousRoundUItype == null || !previousRoundUItype.equals(currentRoundUItype)) { ! if (previousRoundUItype != null) { ! // Finish the previous round UI aspects ! if (StockRound.class.isAssignableFrom(previousRoundUItype)) { ! log.debug("Leaving Stock Round UI type"); ! } else if (StartRound.class.isAssignableFrom(previousRoundUItype)) { ! log.debug("Leaving Start Round UI type"); ! } else if (OperatingRound.class.isAssignableFrom(previousRoundUItype)) { ! log.debug("Leaving Operating Round UI type"); ! //orWindow.setVisible(false); } ! } ! ! // Start the new round UI aspects ! if (StartRound.class.isAssignableFrom(currentRoundUItype)) { ! log.debug("Entering Start Round UI type"); ! activeWindow = startRoundWindow; ! //stockChart.setVisible(false); ! } else if (StockRound.class.isAssignableFrom(currentRoundUItype)) { ! log.debug("Entering Stock Round UI type"); ! activeWindow = statusWindow; ! //stockChart.setVisible(true); ! //statusWindow.setVisible(true); ! } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { ! log.debug("Entering Operating Round UI type "); ! activeWindow = orWindow; ! //stockChart.setVisible(false); ! //orWindow.setVisible(true); ! } } statusWindow.setupFor(currentRound); - previousRound = currentRound; // Update the currently visible round window // "Switchable" rounds will be handled from subclasses of this class. ! if (StartRound.class.isAssignableFrom(currentRoundUItype)) { log.debug("Updating Start round window"); --- 233,321 ---- } else if (StockRound.class.isAssignableFrom(currentRoundType)) { ! log.debug("UI entering Stock Round "+currentRoundName); } else if (OperatingRound.class.isAssignableFrom(currentRoundType)) { ! log.debug("UI entering Operating Round "+currentRoundName); orUIManager.initOR((OperatingRound) currentRound); } else if (SwitchableUIRound.class.isAssignableFrom(currentRoundType) ) { ! log.debug("UI entering switchable round type "+currentRoundName); statusWindow.pack(); } } /* Process visible round type changes */ ! // Visibility settings are handled first. ! // Any window not represented in a setting is left unaffected. ! // Each window set visible or already being visible will be put ! // in front as well. ! // As the settings are handled in which these have been entered, ! // this means that this way the window top-to-bottom sequence ! // can be influenced. ! // To make this work, clearVisbilityHints() should be called ! // before each sequence of settings (usually at the start of a round). ! for (GuiHints.VisibilityHint hint : uiHints.getVisibilityHints()) { ! switch (hint.getType()) { ! case STOCK_MARKET: ! boolean stockChartVisibilityHint = hint.getVisibility(); ! if (stockChartVisibilityHint != previousStockChartVisibilityHint) { ! stockChart.setVisible(stockChartVisibilityHint); ! previousStockChartVisibilityHint = stockChartVisibilityHint; } ! if (stockChartVisibilityHint) stockChart.toFront(); ! break; ! case STATUS: ! boolean statusWindowVisibilityHint = hint.getVisibility(); ! if (statusWindowVisibilityHint != previousStatusWindowVisibilityHint) { ! statusWindow.setVisible(statusWindowVisibilityHint); ! previousStatusWindowVisibilityHint = statusWindowVisibilityHint; ! } ! if (statusWindowVisibilityHint) statusWindow.toFront(); ! break; ! case MAP: ! boolean orWindowVisibilityHint = hint.getVisibility(); ! if (orWindowVisibilityHint != previousORWindowVisibilityHint) { ! orWindow.setVisible(orWindowVisibilityHint); ! previousORWindowVisibilityHint = orWindowVisibilityHint; ! } ! if (orWindowVisibilityHint) orWindow.toFront(); ! break; ! case START_ROUND: ! // Handled elsewhere ! } ! } ! // Active window settings are handled last. ! // Side effects: the active window is made visible and put on top. ! if (uiHints.getActivePanel() == GuiDef.Panel.START_ROUND) { ! log.debug("Entering Start Round UI type"); ! activeWindow = startRoundWindow; ! startRoundWindow.setVisible(true); ! startRoundWindow.toFront(); ! } else if (uiHints.getActivePanel() == GuiDef.Panel.STATUS) { ! log.debug("Entering Stock Round UI type"); ! activeWindow = statusWindow; ! statusWindow.setVisible(true); ! statusWindow.toFront(); ! } else if (uiHints.getActivePanel() == GuiDef.Panel.MAP) { ! log.debug("Entering Operating Round UI type "); ! activeWindow = orWindow; ! orWindow.setVisible(true); ! orWindow.toFront(); } + + statusWindow.setupFor(currentRound); // Update the currently visible round window // "Switchable" rounds will be handled from subclasses of this class. ! if (StartRoundWindow.class.isAssignableFrom(activeWindow.getClass())) { log.debug("Updating Start round window"); *************** *** 295,320 **** startRoundWindow.setSRPlayerTurn(startRound.getCurrentPlayerIndex()); ! } else if (StockRound.class.isAssignableFrom(currentRoundUItype)) { log.debug("Updating Stock (status) round window"); statusWindow.updateStatus(); ! } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { log.debug("Updating Operating round window"); orUIManager.updateStatus(); - - } else { - // Handle special rounds that do not fall in a standard category - // The round must indicate which main window to raise - if (StockRound.class.isAssignableFrom(currentRoundUItype)) { - log.debug("Updating switched Stock (status) round window"); - activeWindow = statusWindow; - } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { - log.debug("Updating switched Operating round window"); - activeWindow = orWindow; - } - updateStatus(activeWindow); } } --- 323,338 ---- startRoundWindow.setSRPlayerTurn(startRound.getCurrentPlayerIndex()); ! } else if (StatusWindow.class.isAssignableFrom(activeWindow.getClass())) { log.debug("Updating Stock (status) round window"); statusWindow.updateStatus(); ! } else if (ORWindow.class.isAssignableFrom(activeWindow.getClass())) { log.debug("Updating Operating round window"); orUIManager.updateStatus(); } + + updateStatus(activeWindow); } *************** *** 615,627 **** } ! public String getClassName (Defs.ClassName key) { return gameManager.getClassName(key); } ! public Object getGameParameter (Defs.Parm key) { ! return gameManager.getGameParameter(key); } ! public boolean getGameParameterAsBoolean (Defs.Parm key) { return (Boolean) getGameParameter(key); } --- 633,645 ---- } ! public String getClassName (GuiDef.ClassName key) { return gameManager.getClassName(key); } ! public Object getGameParameter (GuiDef.Parm key) { ! return gameManager.getGuiParameter(key); } ! public boolean getGameParameterAsBoolean (GuiDef.Parm key) { return (Boolean) getGameParameter(key); } |