From: Stefan F. <ste...@us...> - 2010-05-29 23:33:51
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv13817/rails/ui/swing Modified Files: UpgradesPanel.java ORUIManager.java Log Message: Updated and slightly restricted map correction functionality Index: UpgradesPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/UpgradesPanel.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** UpgradesPanel.java 29 May 2010 09:38:58 -0000 1.26 --- UpgradesPanel.java 29 May 2010 23:33:43 -0000 1.27 *************** *** 16,20 **** import rails.game.*; import rails.game.action.*; - import rails.game.correct.CorrectionAction; import rails.game.correct.MapCorrectionAction; import rails.ui.swing.elements.ActionLabel; --- 16,19 ---- *************** *** 28,31 **** --- 27,31 ---- private ORUIManager orUIManager; private List<ActionLabel> tokenLabels; + private List<CorrectionTokenLabel> correctionTokenLabels; private int selectedTokenIndex; private List<LayToken> possibleTokenLays = new ArrayList<LayToken>(3); *************** *** 42,45 **** --- 42,46 ---- private final String INIT_DONE_TEXT = "LayTile"; private boolean tokenMode = false; + private boolean correctionTokenMode = false; private JButton cancelButton = new JButton(LocalText.getText(INIT_CANCEL_TEXT)); *************** *** 173,177 **** HexLabel hexLabel = new HexLabel(hexIcon, tile.getId()); hexLabel.setName(tile.getName()); ! hexLabel.setText("<HTML><BODY>" + tile.getExternalId() + "<BR/>#" + tile.countFreeTiles() + "</BODY></HTML>"); hexLabel.setOpaque(true); hexLabel.setVisible(true); --- 174,178 ---- HexLabel hexLabel = new HexLabel(hexIcon, tile.getId()); hexLabel.setName(tile.getName()); ! hexLabel.setTextFromTile(tile); hexLabel.setOpaque(true); hexLabel.setVisible(true); *************** *** 192,195 **** --- 193,201 ---- // populate version for corrections public void showCorrectionTileUpgrades() { + // deactivate correctionTokenMode and tokenmode + correctionTokenMode = false; + tokenMode = false; + + // activate upgrade panel upgradePanel.removeAll(); GridLayout panelLayout = (GridLayout)upgradePanel.getLayout(); *************** *** 217,224 **** HexLabel hexLabel = new HexLabel(hexIcon, tile.getId()); hexLabel.setName(tile.getName()); ! if (tile.getExternalId() > 0) ! hexLabel.setText("<HTML><BODY>" + tile.getExternalId() + "<BR/>#" + tile.countFreeTiles() + "</BODY></HTML>"); ! else ! hexLabel.setText(""); hexLabel.setOpaque(true); hexLabel.setVisible(true); --- 223,227 ---- HexLabel hexLabel = new HexLabel(hexIcon, tile.getId()); hexLabel.setName(tile.getName()); ! hexLabel.setTextFromTile(tile); hexLabel.setOpaque(true); hexLabel.setVisible(true); *************** *** 238,242 **** // populate version for corrections ! public void showCorrectionTokenUpgrades() { upgradePanel.removeAll(); GridLayout panelLayout = (GridLayout)upgradePanel.getLayout(); --- 241,250 ---- // populate version for corrections ! public void showCorrectionTokenUpgrades(MapCorrectionAction action) { ! // activate correctionTokenMode and deactivate standard tokenMode ! correctionTokenMode = true; ! tokenMode = false; ! ! // activate upgrade panel upgradePanel.removeAll(); GridLayout panelLayout = (GridLayout)upgradePanel.getLayout(); *************** *** 254,259 **** String description = null; TokenIcon icon; ! ActionLabel tokenLabel; ! tokenLabels = new ArrayList<ActionLabel>(); for (TokenI token:tokens) { if (token instanceof BaseToken) { --- 262,267 ---- String description = null; TokenIcon icon; ! CorrectionTokenLabel tokenLabel; ! correctionTokenLabels = new ArrayList<CorrectionTokenLabel>(); for (TokenI token:tokens) { if (token instanceof BaseToken) { *************** *** 264,268 **** } icon = new TokenIcon(25, fgColour, bgColour, text); ! tokenLabel = new ActionLabel(icon); tokenLabel.setName(description); tokenLabel.setText(description); --- 272,276 ---- } icon = new TokenIcon(25, fgColour, bgColour, text); ! tokenLabel = new CorrectionTokenLabel(icon, token); tokenLabel.setName(description); tokenLabel.setText(description); *************** *** 272,276 **** tokenLabel.setBorder(border); tokenLabel.addMouseListener(this); ! tokenLabels.add(tokenLabel); upgradePanel.add(tokenLabel); } --- 280,285 ---- tokenLabel.setBorder(border); tokenLabel.addMouseListener(this); ! tokenLabel.addPossibleAction(action); ! correctionTokenLabels.add(tokenLabel); upgradePanel.add(tokenLabel); } *************** *** 307,310 **** --- 316,328 ---- } + private void setSelectedCorrectionToken() { + if (correctionTokenLabels == null || correctionTokenLabels.isEmpty()) return; + int index = -1; + for (CorrectionTokenLabel tokenLabel : correctionTokenLabels) { + tokenLabel.setBackground(++index == selectedTokenIndex + ? selectedLabelBgColour : defaultLabelBgColour); + } + } + private BufferedImage getHexImage(int tileId) { return GameUIManager.getImageLoader().getTile(tileId, 10); *************** *** 387,390 **** --- 405,412 ---- } setSelectedToken(); + } else if (correctionTokenMode) { + int id = correctionTokenLabels.indexOf(source); + selectedTokenIndex = id; + log.info("Correction Token index = " + selectedTokenIndex + " selected"); } else { *************** *** 400,404 **** if (!(source instanceof JLabel)) return; ! if (!tokenMode) { // tile mode HexLabel tile = (HexLabel) e.getSource(); --- 422,426 ---- if (!(source instanceof JLabel)) return; ! if (!tokenMode && !correctionTokenMode) { // tile mode HexLabel tile = (HexLabel) e.getSource(); *************** *** 414,418 **** if (!(source instanceof JLabel)) return; ! if (!tokenMode) { // tile mode HexLabel tile = (HexLabel) e.getSource(); --- 436,440 ---- if (!(source instanceof JLabel)) return; ! if (!tokenMode && !correctionTokenMode) { // tile mode HexLabel tile = (HexLabel) e.getSource(); *************** *** 430,433 **** --- 452,474 ---- } + + /** 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 { *************** *** 451,454 **** --- 492,507 ---- return toolTip; } + + void setTextFromTile(TileI tile) { + StringBuffer text = new StringBuffer(); + if (tile.getExternalId() > 0) { + text.append("<HTML><BODY>" + tile.getExternalId()); + if (tile.countFreeTiles() != -1) { + text.append("<BR/>#" + tile.countFreeTiles()); + } + text.append("</BODY></HTML>"); + } + this.setText(text.toString()); + } protected void setToolTip() { Index: ORUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORUIManager.java,v retrieving revision 1.76 retrieving revision 1.77 diff -C2 -d -r1.76 -r1.77 *** ORUIManager.java 29 May 2010 09:38:58 -0000 1.76 --- ORUIManager.java 29 May 2010 23:33:43 -0000 1.77 *************** *** 13,16 **** --- 13,17 ---- import rails.game.action.*; import rails.game.correct.*; + import rails.game.correct.MapCorrectionManager.ActionStep; import rails.game.special.*; import rails.ui.swing.elements.*; *************** *** 879,882 **** --- 880,917 ---- } + private Station correctionRelayBaseToken(BaseToken token, List<Station> possibleStations){ + GUIHex selectedHex = map.getSelectedHex(); + + PublicCompanyI company = token.getCompany(); + List<String> prompts = new ArrayList<String>(); + + Map<String, Station> promptToStationMap = new HashMap<String, Station>(); + String prompt; + for (Station station:possibleStations) { + prompt = LocalText.getText( + "SelectStationForTokenOption", + station.getNumber(), + ((MapHex) selectedHex.getModel()).getConnectionString( + selectedHex.getProvisionalTile(), + selectedHex.getProvisionalTileRotation(), + station.getNumber())) ; + prompts.add(prompt); + promptToStationMap.put(prompt, station); + } + String selected = + (String) JOptionPane.showInputDialog(orWindow, + LocalText.getText("SelectStationForToken", + "", + selectedHex.getName(), + company.getName()), + LocalText.getText("WhichStation"), + JOptionPane.PLAIN_MESSAGE, null, + prompts.toArray(), prompts.get(0)); + if (selected == null) return null; + Station station = promptToStationMap.get(selected); + return station; + } + + /** * Lay Token finished. *************** *** 1210,1214 **** if (mapCorrectionEnabled) { if (selectedHex != null && selectedHex.getProvisionalTile() != null) { ! mapCorrectionAction.selectOrientation(selectedHex.getProvisionalTileRotation()); if (orWindow.process(mapCorrectionAction)) { selectedHex.fixTile(); --- 1245,1253 ---- if (mapCorrectionEnabled) { if (selectedHex != null && selectedHex.getProvisionalTile() != null) { ! if (mapCorrectionAction.getStep() == ActionStep.SELECT_ORIENTATION) { ! mapCorrectionAction.selectOrientation(selectedHex.getProvisionalTileRotation()); ! } else if (mapCorrectionAction.getStep() == ActionStep.CONFIRM) { ! mapCorrectionAction.selectConfirmed(); ! } if (orWindow.process(mapCorrectionAction)) { selectedHex.fixTile(); *************** *** 1694,1699 **** public void updateUpgradesPanel(MapCorrectionAction action) { setLocalStep(MAP_CORRECTION); - GUIHex selectedHex = map.getSelectedHex(); boolean showTilesInUpgrade = true; switch (action.getStep()) { --- 1733,1738 ---- public void updateUpgradesPanel(MapCorrectionAction action) { setLocalStep(MAP_CORRECTION); GUIHex selectedHex = map.getSelectedHex(); + boolean showTilesInUpgrade = true; switch (action.getStep()) { *************** *** 1706,1709 **** --- 1745,1752 ---- tileUpgrades = new ArrayList<TileI>(); showTilesInUpgrade = true; + // checks if there is still a hex selected (due to errors) + if (selectedHex != null) { + map.selectHex(null); + } break; case SELECT_TILE: *************** *** 1713,1722 **** upgradePanel.setCancelEnabled(true); tileUpgrades = action.getTiles(); // checks if there is still a tile displayed (due to errors) ! if (selectedHex.canFixTile()){ selectedHex.removeTile(); - map.setSelectedHex(selectedHex); } ! showTilesInUpgrade = true; break; case SELECT_ORIENTATION: --- 1756,1767 ---- upgradePanel.setCancelEnabled(true); tileUpgrades = action.getTiles(); + showTilesInUpgrade = true; // checks if there is still a tile displayed (due to errors) ! if (selectedHex != null && selectedHex.canFixTile()){ selectedHex.removeTile(); } ! // activate hex selection ! map.selectHex(null); ! map.selectHex(map.getHexByName(action.getLocation().getName())); break; case SELECT_ORIENTATION: *************** *** 1726,1756 **** upgradePanel.setCancelEnabled(true); // next step already set to finished => preprinted tile with fixed orientation ! if (action.getNextStep() == MapCorrectionManager.ActionStep.FINISHED) { ! selectedHex.setTileOrientation(action.getOrientation()); ! map.repaint(selectedHex.getBounds()); ! if (orWindow.process(mapCorrectionAction)) { ! selectedHex.fixTile(); ! } else { ! selectedHex.removeTile(); ! } ! map.selectHex(null); ! return; ! } showTilesInUpgrade = true; break; case RELAY_BASETOKENS: ! upgradePanel.setDoneText("RelayToken"); upgradePanel.setDoneEnabled(true); upgradePanel.setCancelText("Cancel"); upgradePanel.setCancelEnabled(true); ! tokenLays= action.getTokensToRelay(); ! showTilesInUpgrade = false; } ! log.debug("Active map tile correction"); if (showTilesInUpgrade) { upgradePanel.showCorrectionTileUpgrades(); } else { ! upgradePanel.showCorrectionTokenUpgrades(); } } --- 1771,1828 ---- upgradePanel.setCancelEnabled(true); // next step already set to finished => preprinted tile with fixed orientation ! // if (action.getNextStep() == MapCorrectionManager.ActionStep.FINISHED) { ! // selectedHex.setTileOrientation(action.getOrientation()); ! // map.repaint(selectedHex.getBounds()); ! // if (orWindow.process(mapCorrectionAction)) { ! // selectedHex.fixTile(); ! // } else { ! // selectedHex.removeTile(); ! // } ! // map.selectHex(null); ! // return; } ! ! // } showTilesInUpgrade = true; break; case RELAY_BASETOKENS: ! // define open slots for each station ! List<Station> possibleStations = new ArrayList<Station>(action.getPossibleStations()); ! Map<Station, Integer> openSlots = new HashMap<Station, Integer>(); ! for (Station station:possibleStations) { ! openSlots.put(station, station.getBaseSlots()); ! } ! // ask for the new stations ! List<Station> chosenStations = new ArrayList<Station>(); ! for (BaseToken token:action.getTokensToRelay()) { ! Station chosenStation = correctionRelayBaseToken(token, possibleStations); ! chosenStations.add(chosenStation); ! // check the number of available slots ! openSlots.put(chosenStation, openSlots.get(chosenStation) - 1); ! if (openSlots.get(chosenStation) == 0) { ! possibleStations.remove(chosenStation); ! } ! } ! action.selectRelayBaseTokens(chosenStations); ! if (orWindow.process(mapCorrectionAction)) { ! selectedHex.fixTile(); ! } else { ! selectedHex.removeTile(); ! } ! map.selectHex(null); ! return; ! case CONFIRM: ! // only wait for laytile or cancel command, for those lays that do not need adjustment of orientation ! upgradePanel.setDoneText("LayTile"); upgradePanel.setDoneEnabled(true); upgradePanel.setCancelText("Cancel"); upgradePanel.setCancelEnabled(true); ! showTilesInUpgrade = true; } ! log.debug("Active map tile correction"); if (showTilesInUpgrade) { upgradePanel.showCorrectionTileUpgrades(); } else { ! upgradePanel.showCorrectionTokenUpgrades(action); } } |