From: Stefan F. <ste...@us...> - 2010-03-28 17:06:04
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv17978/rails/ui/swing Modified Files: UpgradesPanel.java ORUIManager.java Log Message: Added MapCorrection Mode and some refactoring on the CorrectionClasses Index: UpgradesPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/UpgradesPanel.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** UpgradesPanel.java 28 Feb 2010 21:38:04 -0000 1.24 --- UpgradesPanel.java 28 Mar 2010 17:05:56 -0000 1.25 *************** *** 16,19 **** --- 16,21 ---- import rails.game.*; import rails.game.action.*; + import rails.game.correct.CorrectionAction; + import rails.game.correct.MapCorrectionAction; import rails.ui.swing.elements.ActionLabel; import rails.ui.swing.hexmap.GUIHex; *************** *** 23,26 **** --- 25,29 ---- public class UpgradesPanel extends Box implements MouseListener, ActionListener { private static final long serialVersionUID = 1L; + private ORUIManager orUIManager; private List<ActionLabel> tokenLabels; *************** *** 30,34 **** static private Color defaultLabelBgColour = new JLabel("").getBackground(); static private Color selectedLabelBgColour = new Color(255, 220, 150); ! private JPanel upgradePanel; private JScrollPane scrollPane; --- 33,38 ---- 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; *************** *** 59,63 **** upgradePanel.setBackground(Color.DARK_GRAY); upgradePanel.setBorder(border); ! upgradePanel.setLayout(new GridLayout(15, 1)); scrollPane = new JScrollPane(upgradePanel); --- 63,67 ---- upgradePanel.setBackground(Color.DARK_GRAY); upgradePanel.setBorder(border); ! upgradePanel.setLayout(new GridLayout(defaultNbPanelElements, 1)); scrollPane = new JScrollPane(upgradePanel); *************** *** 100,106 **** } } ! public void showUpgrades() { upgradePanel.removeAll(); if (tokenMode && possibleTokenLays != null && possibleTokenLays.size() > 0) { --- 104,115 ---- } } ! public void showUpgrades() { upgradePanel.removeAll(); + + // reset to the number of elements + GridLayout panelLayout = (GridLayout)upgradePanel.getLayout(); + panelLayout.setRows(defaultNbPanelElements); + if (tokenMode && possibleTokenLays != null && possibleTokenLays.size() > 0) { *************** *** 181,184 **** --- 190,241 ---- } + // populate version for corrections + public void showCorrectionUpgrades() { + 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); + // set to position 0 + scrollPane.getVerticalScrollBar().setValue(0); + } else { + // set to the max of available or the default number of elements + panelLayout.setRows(Math.max(tiles.size() + 2, defaultNbPanelElements)); + for (TileI tile : tiles) { + + BufferedImage hexImage = getHexImage(tile.getId()); + ImageIcon hexIcon = new ImageIcon(hexImage); + + // Cheap n' Easy rescaling. + hexIcon.setImage(hexIcon.getImage().getScaledInstance( + (int) (hexIcon.getIconWidth() * GUIHex.NORMAL_SCALE * 0.8), + (int) (hexIcon.getIconHeight() * GUIHex.NORMAL_SCALE * 0.8), + Image.SCALE_SMOOTH)); + + HexLabel hexLabel = new HexLabel(hexIcon, tile.getId()); + hexLabel.setName(tile.getName()); + if (tile.getExternalId() > 0) + hexLabel.setText("" + tile.getExternalId()); + else + hexLabel.setText(""); + hexLabel.setOpaque(true); + hexLabel.setVisible(true); + hexLabel.setBorder(border); + hexLabel.addMouseListener(this); + + upgradePanel.add(hexLabel); + } + } + + upgradePanel.add(doneButton); + upgradePanel.add(cancelButton); + + // repaint(); + revalidate(); + } + + public void clear() { upgradePanel.removeAll(); Index: ORUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORUIManager.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** ORUIManager.java 5 Mar 2010 20:51:15 -0000 1.61 --- ORUIManager.java 28 Mar 2010 17:05:56 -0000 1.62 *************** *** 52,55 **** --- 52,59 ---- private LayToken selectedTokenAllowance; + // map corrections + private boolean mapCorrectionEnabled = false; + private MapCorrectionAction mapCorrectionAction = null; + /** * Will be set true if a cancelled action does not need to be reported to *************** *** 69,72 **** --- 73,77 ---- public static final int SET_REVENUE = 7; public static final int SELECT_PAYOUT = 8; + public static final int MAP_CORRECTION = 9; /* Message key per substep */ *************** *** 74,78 **** new String[] { "Inactive", "SelectAHexForTile", "SelectATile", "RotateTile", "SelectAHexForToken", "SelectAToken", ! "ConfirmToken", "SetRevenue", "SelectPayout" }; protected static Logger log = --- 79,84 ---- new String[] { "Inactive", "SelectAHexForTile", "SelectATile", "RotateTile", "SelectAHexForToken", "SelectAToken", ! "ConfirmToken", "SetRevenue", "SelectPayout", ! "CorrectMap" }; protected static Logger log = *************** *** 114,118 **** } } ! public <T extends PossibleAction> void setMapRelatedActions(List<T> actions) { --- 120,124 ---- } } ! public <T extends PossibleAction> void setMapRelatedActions(List<T> actions) { *************** *** 122,125 **** --- 128,132 ---- allowedTileLays.clear(); allowedTokenLays.clear(); + for (T action : actions) { if (action instanceof LayTile) { *************** *** 159,163 **** } } ! setLocalStep(nextSubStep); tileLayingEnabled = allowedTileLays.size() > 0; --- 166,170 ---- } } ! setLocalStep(nextSubStep); tileLayingEnabled = allowedTileLays.size() > 0; *************** *** 184,187 **** --- 191,200 ---- /* Add any extra messages */ String extraMessage = ""; + + if (localStep == ORUIManager.MAP_CORRECTION) { + if (mapCorrectionAction != null) + extraMessage = LocalText.getText("CorrectMap" + mapCorrectionAction.getStep().name()); + } + if (localStep == ORUIManager.SELECT_HEX_FOR_TILE) { /* Compose prompt for tile laying */ *************** *** 467,471 **** public void hexClicked(GUIHex clickedHex, GUIHex selectedHex) { ! if (tokenLayingEnabled) { List<LayToken> allowances = map.getTokenAllowanceForHex(clickedHex.getHexModel()); --- 480,504 ---- public void hexClicked(GUIHex clickedHex, GUIHex selectedHex) { ! if (mapCorrectionEnabled) { ! boolean checkClickedHex = false; ! switch (mapCorrectionAction.getStep()) { ! case SELECT_HEX: ! case SELECT_TILE: // if tile is selected see ! checkClickedHex = true; ! break; ! case SELECT_ORIENTATION: ! if (clickedHex == selectedHex) { ! selectedHex.forcedRotateTile(); ! map.repaint(selectedHex.getBounds()); ! } else ! checkClickedHex = true; ! break; ! } ! if (checkClickedHex && clickedHex !=null && clickedHex != selectedHex) { ! map.selectHex(clickedHex); ! mapCorrectionAction.selectHex(clickedHex.getHexModel()); ! orWindow.process(mapCorrectionAction); ! } ! } else if (tokenLayingEnabled) { List<LayToken> allowances = map.getTokenAllowanceForHex(clickedHex.getHexModel()); *************** *** 520,525 **** public void tileSelected(int tileId) { - GUIHex hex = map.getSelectedHex(); TileI tile = gameUIManager.getGameManager().getTileManager().getTile(tileId); // Check if the new tile must be connected to some other track --- 553,569 ---- public void tileSelected(int tileId) { TileI tile = gameUIManager.getGameManager().getTileManager().getTile(tileId); + GUIHex hex = map.getSelectedHex(); + + // map correction override + if (mapCorrectionEnabled) { + // paint tile + hex.forcedDropTile(tileId, 0); + map.repaint(hex.getBounds()); + // inform map correction manager + mapCorrectionAction.selectTile(tile); + orWindow.process(mapCorrectionAction); + return; + } // Check if the new tile must be connected to some other track *************** *** 543,547 **** upgradePanel.showUpgrades(); } - } --- 587,590 ---- *************** *** 1049,1053 **** --- 1092,1112 ---- public void executeUpgrade() { + GUIHex selectedHex = map.getSelectedHex(); + + // map correction override + if (mapCorrectionEnabled) { + if (selectedHex != null && selectedHex.getProvisionalTile() != null) { + mapCorrectionAction.selectOrientation(selectedHex.getProvisionalTileRotation()); + if (orWindow.process(mapCorrectionAction)) { + selectedHex.fixTile(); + } else { + selectedHex.removeTile(); + } + map.selectHex(null); + } + return; + } + if (tileLayingEnabled) { if (selectedHex == null) { *************** *** 1074,1077 **** --- 1133,1145 ---- GUIHex selectedHex = mapPanel.getMap().getSelectedHex(); + // map correction override + if (mapCorrectionEnabled) { + if (selectedHex != null) selectedHex.removeTile(); + mapCorrectionAction.selectCancel(); + orWindow.process(mapCorrectionAction); + map.selectHex(null); + return; + } + if (tokenLayingEnabled) { if (selectedHex != null) selectedHex.removeToken(); *************** *** 1201,1206 **** orPanel.initOperatingCosts(possibleActions.contains(OperatingCost.class)); ! //if (possibleActions.contains(LayTile.class)) { ! if (orStep == GameDef.OrStep.LAY_TRACK) { orPanel.initTileLayingStep(); --- 1269,1287 ---- orPanel.initOperatingCosts(possibleActions.contains(OperatingCost.class)); ! // MapTileCorrection Actions ! mapCorrectionEnabled = false; ! mapCorrectionAction = null; ! if (possibleActions.contains(MapCorrectionAction.class)) { ! orPanel.initTileLayingStep(); ! orWindow.requestFocus(); ! ! MapCorrectionAction action = (MapCorrectionAction) ! (possibleActions.getType(MapCorrectionAction.class)).get(0); ! ! mapCorrectionEnabled = true; ! mapCorrectionAction = action; ! updateUpgradesPanel(action); ! } else if (orStep == GameDef.OrStep.LAY_TRACK) { ! //if (possibleActions.contains(LayTile.class)) { orPanel.initTileLayingStep(); *************** *** 1296,1300 **** } ! setMapRelatedActions(mapRelatedActions); GameAction undoAction = null; --- 1377,1382 ---- } ! if (!mapCorrectionEnabled) ! setMapRelatedActions(mapRelatedActions); GameAction undoAction = null; *************** *** 1394,1400 **** } - // Correction Actions - - checkForGameSpecificActions(); --- 1476,1479 ---- *************** *** 1481,1484 **** --- 1560,1565 ---- upgradePanel.setDoneEnabled(true); break; + case MAP_CORRECTION: + return; // this is done in their own initialization default: upgradePanel.setDoneEnabled(false); *************** *** 1492,1495 **** --- 1573,1621 ---- } + + public void updateUpgradesPanel(MapCorrectionAction action) { + setLocalStep(MAP_CORRECTION); + + switch (action.getStep()) { + case SELECT_HEX: + // done text will be used by token lay + upgradePanel.setDoneText("LayTile"); + upgradePanel.setDoneEnabled(false); + upgradePanel.setCancelText("Cancel"); + upgradePanel.setCancelEnabled(false); + tileUpgrades = new ArrayList<TileI>(); + break; + case SELECT_TILE: + upgradePanel.setDoneText("LayTile"); + upgradePanel.setDoneEnabled(false); + upgradePanel.setCancelText("Cancel"); + upgradePanel.setCancelEnabled(true); + tileUpgrades = action.getTiles(); + break; + case SELECT_ORIENTATION: + upgradePanel.setDoneText("LayTile"); + upgradePanel.setDoneEnabled(true); + upgradePanel.setCancelText("Cancel"); + upgradePanel.setCancelEnabled(true); + + // next step already set to finished => preprinted tile with fixed orientation + if (action.getNextStep() == MapCorrectionManager.ActionStep.FINISHED) { + GUIHex selectedHex = map.getSelectedHex(); + selectedHex.setTileOrientation(action.getOrientation()); + map.repaint(selectedHex.getBounds()); + if (orWindow.process(mapCorrectionAction)) { + selectedHex.fixTile(); + } else { + selectedHex.removeTile(); + } + map.selectHex(null); + return; + } + break; + } + + log.debug("Active map tile correction"); + upgradePanel.showCorrectionUpgrades(); + } public void setMessage(String message) { |