Search in sources :

Example 16 with UnitCategory

use of games.strategy.triplea.util.UnitCategory in project triplea by triplea-game.

the class TerritoryDetailPanel method unitsInTerritoryPanel.

private static JPanel unitsInTerritoryPanel(final Collection<Unit> unitsInTerritory, final UiContext uiContext) {
    final JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(2, 20, 2, 2));
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    final Set<UnitCategory> units = UnitSeperator.categorize(unitsInTerritory);
    PlayerID currentPlayer = null;
    for (final UnitCategory item : units) {
        // seperate players with a seperator
        if (item.getOwner() != currentPlayer) {
            currentPlayer = item.getOwner();
            panel.add(Box.createVerticalStrut(15));
        }
        // TODO Kev determine if we need to identify if the unit is hit/disabled
        final Optional<ImageIcon> unitIcon = uiContext.getUnitImageFactory().getIcon(item.getType(), item.getOwner(), item.hasDamageOrBombingUnitDamage(), item.getDisabled());
        if (unitIcon.isPresent()) {
            // overlay flag onto upper-right of icon
            final ImageIcon flagIcon = new ImageIcon(uiContext.getFlagImageFactory().getSmallFlag(item.getOwner()));
            final Icon flaggedUnitIcon = new OverlayIcon(unitIcon.get(), flagIcon, unitIcon.get().getIconWidth() - (flagIcon.getIconWidth() / 2), 0);
            final JLabel label = new JLabel("x" + item.getUnits().size(), flaggedUnitIcon, SwingConstants.LEFT);
            final String toolTipText = "<html>" + item.getType().getName() + ": " + item.getType().getTooltip(currentPlayer) + "</html>";
            label.setToolTipText(toolTipText);
            panel.add(label);
        }
    }
    return panel;
}
Also used : JPanel(javax.swing.JPanel) PlayerID(games.strategy.engine.data.PlayerID) ImageIcon(javax.swing.ImageIcon) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) Icon(javax.swing.Icon) OverlayIcon(games.strategy.ui.OverlayIcon) ImageIcon(javax.swing.ImageIcon) OverlayIcon(games.strategy.ui.OverlayIcon) UnitCategory(games.strategy.triplea.util.UnitCategory)

Example 17 with UnitCategory

use of games.strategy.triplea.util.UnitCategory in project triplea by triplea-game.

the class UnitChooser method createEntries.

private void createEntries(final Collection<Unit> units, final Map<Unit, Collection<Unit>> dependent, final boolean categorizeMovement, final boolean categorizeTransportCost, final Collection<Unit> defaultSelections) {
    final Collection<UnitCategory> categories = UnitSeperator.categorize(units, dependent, categorizeMovement, categorizeTransportCost);
    final Collection<UnitCategory> defaultSelectionsCategorized = UnitSeperator.categorize(defaultSelections, dependent, categorizeMovement, categorizeTransportCost);
    final IntegerMap<UnitCategory> defaultValues = createDefaultSelectionsMap(defaultSelectionsCategorized);
    for (final UnitCategory category : categories) {
        addCategory(category, defaultValues.getInt(category));
    }
}
Also used : UnitCategory(games.strategy.triplea.util.UnitCategory)

Aggregations

UnitCategory (games.strategy.triplea.util.UnitCategory)17 Unit (games.strategy.engine.data.Unit)8 ArrayList (java.util.ArrayList)7 Territory (games.strategy.engine.data.Territory)5 Point (java.awt.Point)5 GameData (games.strategy.engine.data.GameData)4 PlayerID (games.strategy.engine.data.PlayerID)4 UnitType (games.strategy.engine.data.UnitType)4 TripleAUnit (games.strategy.triplea.TripleAUnit)4 JPanel (javax.swing.JPanel)4 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)3 Image (java.awt.Image)3 Collection (java.util.Collection)3 LinkedHashSet (java.util.LinkedHashSet)3 List (java.util.List)3 BoxLayout (javax.swing.BoxLayout)3 ImageIcon (javax.swing.ImageIcon)3 JLabel (javax.swing.JLabel)3 Matches (games.strategy.triplea.delegate.Matches)2 UnitSeperator (games.strategy.triplea.util.UnitSeperator)2