public void populate(PhaseI currentPhase) { if (hexMap == null) hexMap = orUIManager.getMapPanel().getMap(); GUIHex uiHex = hexMap.getSelectedHex(); MapHex hex = uiHex.getHexModel(); orUIManager.tileUpgrades = new ArrayList<TileI>(); List<TileI> tiles; Set<String> allowedColours = currentPhase.getTileColours().keySet(); for (LayTile layTile : hexMap.getTileAllowancesForHex(hex)) { tiles = layTile.getTiles(); if (tiles == null) { for (TileI tile : uiHex .getCurrentTile() .getValidUpgrades(hex, orUIManager.gameUIManager.getCurrentPhase())) { // Skip if not allowed in LayTile // if (!layTile.isTileColourAllowed(tile.getColourName())) continue; if (!orUIManager.tileUpgrades.contains(tile)) orUIManager.tileUpgrades.add(tile); } } else { for (TileI tile : tiles) { // Skip if colour is not allowed yet if (!allowedColours.contains(tile.getColourName())) continue; if (!orUIManager.tileUpgrades.contains(tile)) orUIManager.tileUpgrades.add(tile); } } } }
protected void setToolTip() { TileI currentTile = orUIManager.getGameUIManager().getGameManager().getTileManager().getTile(internalId); StringBuffer tt = new StringBuffer("<html>"); tt.append("<b>Tile</b>: ").append(currentTile.getName()); // or // getId() if (currentTile.hasStations()) { // for (Station st : currentTile.getStations()) int cityNumber = 0; // TileI has stations, but for (Station st : currentTile.getStations()) { cityNumber++; // = city.getNumber(); tt.append("<br> ") .append(st.getType()) .append(" ") .append(cityNumber) // .append("/").append(st.getNumber()) .append(": value "); tt.append(st.getValue()); if (st.getBaseSlots() > 0) { tt.append(", ").append(st.getBaseSlots()).append(" slots"); } } } tt.append("</html>"); toolTip = tt.toString(); }
void setTextFromTile(TileI tile) { StringBuffer text = new StringBuffer(); if (Util.hasValue(tile.getExternalId())) { text.append("<HTML><BODY>" + tile.getExternalId()); if (tile.countFreeTiles() != -1) { text.append("<BR> (" + tile.countFreeTiles() + ")"); } text.append("</BODY></HTML>"); } this.setText(text.toString()); }
// 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(); 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()); hexLabel.setTextFromTile(tile); 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 showUpgrades() { upgradePanel.removeAll(); // reset to the number of elements GridLayout panelLayout = (GridLayout) upgradePanel.getLayout(); panelLayout.setRows(defaultNbPanelElements); if (tokenMode && possibleTokenLays != null && possibleTokenLays.size() > 0) { Color fgColour = null; Color bgColour = null; String text = null; String description = null; TokenIcon icon; ActionLabel tokenLabel; tokenLabels = new ArrayList<ActionLabel>(); for (LayToken action : possibleTokenLays) { if (action instanceof LayBaseToken) { PublicCompanyI comp = ((LayBaseToken) action).getCompany(); fgColour = comp.getFgColour(); bgColour = comp.getBgColour(); description = text = comp.getName(); if (action.getSpecialProperty() != null) { description += " (" + action.getSpecialProperty().getOriginalCompany().getName() + ")"; } } else if (action instanceof LayBonusToken) { fgColour = Color.BLACK; bgColour = Color.WHITE; BonusToken token = (BonusToken) action.getSpecialProperty().getToken(); description = token.getName(); text = "+" + token.getValue(); } icon = new TokenIcon(25, fgColour, bgColour, text); tokenLabel = new ActionLabel(icon); tokenLabel.setName(description); tokenLabel.setText(description); tokenLabel.setBackground(defaultLabelBgColour); tokenLabel.setOpaque(true); tokenLabel.setVisible(true); tokenLabel.setBorder(border); tokenLabel.addMouseListener(this); tokenLabel.addPossibleAction(action); tokenLabels.add(tokenLabel); upgradePanel.add(tokenLabel); } setSelectedToken(); } else if (orUIManager.tileUpgrades == null) {; } else if (orUIManager.tileUpgrades.size() == 0) { orUIManager.setMessage(LocalText.getText("NoTiles")); } else { for (TileI tile : orUIManager.tileUpgrades) { BufferedImage hexImage = getHexImage(tile.getPictureId()); 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()); hexLabel.setTextFromTile(tile); hexLabel.setOpaque(true); hexLabel.setVisible(true); hexLabel.setBorder(border); hexLabel.addMouseListener(this); upgradePanel.add(hexLabel); } } upgradePanel.add(doneButton); upgradePanel.add(cancelButton); // repaint(); revalidate(); }