use of games.strategy.triplea.attachments.TerritoryAttachment in project triplea by triplea-game.
the class TripleAFrame method getArrowKeyListener.
private KeyListener getArrowKeyListener() {
return new KeyListener() {
@Override
public void keyPressed(final KeyEvent e) {
isCtrlPressed = e.isControlDown();
// scroll map according to wasd/arrowkeys
final int diffPixel = computeScrollSpeed();
final int x = mapPanel.getXOffset();
final int y = mapPanel.getYOffset();
final int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_RIGHT) {
getMapPanel().setTopLeft(x + diffPixel, y);
} else if (keyCode == KeyEvent.VK_LEFT) {
getMapPanel().setTopLeft(x - diffPixel, y);
} else if (keyCode == KeyEvent.VK_DOWN) {
getMapPanel().setTopLeft(x, y + diffPixel);
} else if (keyCode == KeyEvent.VK_UP) {
getMapPanel().setTopLeft(x, y - diffPixel);
}
// I for info
if (keyCode == KeyEvent.VK_I || keyCode == KeyEvent.VK_V) {
String unitInfo = "";
if (unitsBeingMousedOver != null && !unitsBeingMousedOver.isEmpty()) {
final Unit unit = unitsBeingMousedOver.get(0);
final UnitAttachment ua = UnitAttachment.get(unit.getType());
if (ua != null) {
unitInfo = "<b>Unit:</b><br>" + unit.getType().getName() + ": " + ua.toStringShortAndOnlyImportantDifferences(unit.getOwner(), true, false);
}
}
String terrInfo = "";
if (territoryLastEntered != null) {
final TerritoryAttachment ta = TerritoryAttachment.get(territoryLastEntered);
if (ta != null) {
terrInfo = "<b>Territory:</b><br>" + ta.toStringForInfo(true, true) + "<br>";
} else {
terrInfo = "<b>Territory:</b><br>" + territoryLastEntered.getName() + "<br>Water Territory";
}
}
String tipText = unitInfo;
if (unitInfo.length() > 0 && terrInfo.length() > 0) {
tipText = tipText + "<br><br><br><br><br>";
}
tipText = tipText + terrInfo;
if (tipText.length() > 0) {
final Point currentPoint = MouseInfo.getPointerInfo().getLocation();
final PopupFactory popupFactory = PopupFactory.getSharedInstance();
final JToolTip info = new JToolTip();
info.setTipText("<html>" + tipText + "</html>");
final Popup popup = popupFactory.getPopup(mapPanel, info, currentPoint.x, currentPoint.y);
popup.show();
new Thread(() -> {
Interruptibles.sleep(5000);
popup.hide();
}, "popup waiter").start();
}
}
}
@Override
public void keyTyped(final KeyEvent e) {
}
@Override
public void keyReleased(final KeyEvent e) {
isCtrlPressed = e.isControlDown();
}
};
}
use of games.strategy.triplea.attachments.TerritoryAttachment in project triplea by triplea-game.
the class HistoryLog method printTerritorySummary.
private void printTerritorySummary(final Collection<PlayerID> players, final Collection<Territory> territories) {
if (players == null || players.isEmpty() || territories == null || territories.isEmpty()) {
return;
}
final PrintWriter logWriter = printWriter;
// print all units in all territories, including "flags"
logWriter.println("Territory Summary for " + MyFormatter.defaultNamedToTextList(players) + " : \n");
for (final Territory t : territories) {
final List<Unit> ownedUnits = t.getUnits().getMatches(Matches.unitIsOwnedByOfAnyOfThesePlayers(players));
// see if there's a flag
final TerritoryAttachment ta = TerritoryAttachment.get(t);
final boolean hasFlag = ta != null && t.getOwner() != null && players.contains(t.getOwner()) && (ta.getOriginalOwner() == null || !players.contains(ta.getOriginalOwner()));
if (hasFlag || !ownedUnits.isEmpty()) {
logWriter.print(" " + t.getName() + " : ");
if (hasFlag && ownedUnits.isEmpty()) {
logWriter.println("1 flag");
} else if (hasFlag) {
logWriter.print("1 flag, ");
}
if (!ownedUnits.isEmpty()) {
logWriter.println(MyFormatter.unitsToTextNoOwner(ownedUnits));
}
}
}
logWriter.println();
logWriter.println();
textArea.setText(stringWriter.toString());
}
use of games.strategy.triplea.attachments.TerritoryAttachment in project triplea by triplea-game.
the class HistoryLog method getProduction.
// copied from StatPanel
private static int getProduction(final PlayerID player, final GameData data) {
int production = 0;
for (final Territory place : data.getMap().getTerritories()) {
boolean isConvoyOrLand = false;
final TerritoryAttachment ta = TerritoryAttachment.get(place);
if (!place.isWater() || place.isWater() && ta != null && OriginalOwnerTracker.getOriginalOwner(place) != PlayerID.NULL_PLAYERID && OriginalOwnerTracker.getOriginalOwner(place) == player && place.getOwner().equals(player)) {
isConvoyOrLand = true;
}
if (place.getOwner().equals(player) && isConvoyOrLand) {
if (ta != null) {
production += ta.getProduction();
}
}
}
return production;
}
use of games.strategy.triplea.attachments.TerritoryAttachment in project triplea by triplea-game.
the class TileManager method drawTerritory.
private void drawTerritory(final Territory territory, final GameData data, final MapData mapData) {
final Set<Tile> drawnOn = new HashSet<>();
final Set<IDrawable> drawing = new HashSet<>();
if (territoryOverlays.get(territory.getName()) != null) {
drawing.add(territoryOverlays.get(territory.getName()));
}
if (uiContext.getShowTerritoryEffects()) {
drawTerritoryEffects(territory, mapData, drawing);
}
if (uiContext.getShowUnits()) {
drawUnits(territory, mapData, drawnOn, drawing, data);
}
drawing.add(new BattleDrawable(territory.getName()));
final TerritoryAttachment ta = TerritoryAttachment.get(territory);
if (!territory.isWater()) {
drawing.add(new LandTerritoryDrawable(territory.getName()));
} else {
if (ta != null) {
// Kamikaze Zones
if (ta.getKamikazeZone()) {
drawing.add(new KamikazeZoneDrawable(territory, uiContext));
}
// Blockades
if (ta.getBlockadeZone()) {
drawing.add(new BlockadeZoneDrawable(territory));
}
// Convoy Routes
if (ta.getConvoyRoute()) {
drawing.add(new ConvoyZoneDrawable(territory.getOwner(), territory, uiContext));
}
// Convoy Centers
if (ta.getProduction() > 0) {
drawing.add(new ConvoyZoneDrawable(territory.getOwner(), territory, uiContext));
}
}
drawing.add(new SeaZoneOutlineDrawable(territory.getName()));
}
final OptionalExtraBorderLevel optionalBorderLevel = uiContext.getDrawTerritoryBordersAgain();
if (optionalBorderLevel != OptionalExtraBorderLevel.LOW) {
drawing.add(new OptionalExtraTerritoryBordersDrawable(territory.getName(), optionalBorderLevel));
}
drawing.add(new TerritoryNameDrawable(territory.getName(), uiContext));
if (ta != null && ta.isCapital() && mapData.drawCapitolMarkers()) {
final PlayerID capitalOf = data.getPlayerList().getPlayerId(ta.getCapital());
drawing.add(new CapitolMarkerDrawable(capitalOf, territory, uiContext));
}
if (ta != null && (ta.getVictoryCity() != 0)) {
drawing.add(new VcDrawable(territory));
}
// add to the relevant tiles
for (Tile tile : getTiles(mapData.getBoundingRect(territory.getName()))) {
drawnOn.add(tile);
tile.addDrawables(drawing);
}
territoryDrawables.put(territory.getName(), drawing);
territoryTiles.put(territory.getName(), drawnOn);
}
use of games.strategy.triplea.attachments.TerritoryAttachment in project triplea by triplea-game.
the class KamikazeZoneDrawable method draw.
@Override
public void draw(final Rectangle bounds, final GameData data, final Graphics2D graphics, final MapData mapData, final AffineTransform unscaled, final AffineTransform scaled) {
// Change so only original owner gets the kamikazi zone marker
final Territory terr = data.getMap().getTerritory(location);
final TerritoryAttachment ta = TerritoryAttachment.get(terr);
PlayerID owner;
if (Properties.getKamikazeSuicideAttacksDoneByCurrentTerritoryOwner(data)) {
owner = terr.getOwner();
if (owner == null) {
owner = PlayerID.NULL_PLAYERID;
}
} else {
if (ta == null) {
owner = PlayerID.NULL_PLAYERID;
} else {
owner = ta.getOriginalOwner();
if (owner == null) {
owner = PlayerID.NULL_PLAYERID;
}
}
}
final Image img = uiContext.getFlagImageFactory().getFadedFlag(owner);
final Point point = mapData.getKamikazeMarkerLocation(data.getMap().getTerritory(location));
graphics.drawImage(img, point.x - bounds.x, point.y - bounds.y, null);
}
Aggregations