Skip to content

Commit

Permalink
I18n v2.2 (Scope: strategy.engine.framework.startup.ui) (#12841)
Browse files Browse the repository at this point in the history
* i18n_v2 #1 annotate I18n classes with @NonNls

* i18n_v2 #2 annotate @NonNls with .-pattern

(.*String .+ *= "\w+\.[A-Za-z]+[A-Za-z\.]*)

* i18n_v2 #3 fix via @NonNls imports

* i18n_v2 #4 add @NonNls to Strings based on review with pattern

(.*String .* = .*\+.*")

* i18n_v2 #5 add @NonNls import to

AbstractConditionsAttachment.java
AbstractImageFactory.java
AutoPlacementFinder.java
ClipPlayer.java
CliProperties.java
CommentPanel.java
DownloadFile.java
FileNameUtils.java
FlagIconImageFactory.java
GameParser.java
GameRunner.java
InGameLobbyWatcher.java
MapData.java
NodeBbForumPoster.java
NotificationMessages.java
ObjectiveProperties.java
PoliticsText.java
ProductionRepairPanel.java
ProductionTabsProperties.java
TooltipProperties.java
UnitIconProperties.java
UnitImageFactory.java

* i18n_v2.1 #6 add @NonNls to Strings based on review with static-String-pattern

(.*static final String .* = ")

* i18n_v2.1 #7 add @NonNls and Locals to getUpperCase() calls

(toUpperCase\()\)

* i18n_v2.1 #7 add @NonNls and Locals to toLowerCase() or toUpperCase() calls

(?<!NonNls) (p.* static final String)

* i18n_v2.1 #8 fix checkstyle error and spotlessJavaApply

* LanchesterDebugAction System.out -> log.info

* i18n v2.2

Scope: strategy.engine.framework.startup.ui
1. Invoke the Code | Analyse Code | Run Inspection by Name... action.
2. Select the Hardcoded strings inspection.

New class HtmlBuilder.java to introduce simple builder pattern for HTML
  • Loading branch information
frigoref authored Aug 18, 2024
1 parent 2219d8d commit 936b1df
Show file tree
Hide file tree
Showing 20 changed files with 395 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.triplea.ai.flowfield.FlowFieldAi;
import org.triplea.ai.flowfield.influence.TerritoryDebugAction;

@Slf4j
@RequiredArgsConstructor
public class LanchesterDebugAction implements Consumer<AiPlayerDebugAction> {

Expand Down Expand Up @@ -82,13 +84,13 @@ public void accept(final AiPlayerDebugAction aiPlayerDebugAction) {
.filter(Predicate.not(Territory::isWater))
.findFirst()
.orElseThrow(() -> new RuntimeException("Land territory is required."));
System.out.println("Using territory " + territory.getName());
log.info("Using territory {}", territory.getName());
final GamePlayer offender = ai.getGamePlayer();
final GamePlayer defender =
relationshipTracker.getEnemies(ai.getGamePlayer()).stream()
.findFirst()
.orElseThrow(() -> new RuntimeException("An enemy is required"));
System.out.println("Defender is " + defender.getName());
log.info("Defender is {}", defender.getName());

final List<Unit> attackingUnits = new ArrayList<>();
final List<Unit> defendingUnits = new ArrayList<>();
Expand Down Expand Up @@ -117,8 +119,8 @@ public void accept(final AiPlayerDebugAction aiPlayerDebugAction) {
defendingUnits.addAll(unitType.create(localRandom.nextInt(10), defender)));
}

System.out.println("Attack Units: " + MyFormatter.unitsToText(attackingUnits));
System.out.println("Defending Units: " + MyFormatter.unitsToText(defendingUnits));
log.info("Attack Units: {}", MyFormatter.unitsToText(attackingUnits));
log.info("Defending Units: {}", MyFormatter.unitsToText(defendingUnits));

final ConcurrentBattleCalculator hardAiCalculator = new ConcurrentBattleCalculator();
hardAiCalculator.setGameData(ai.getGameData());
Expand Down Expand Up @@ -162,22 +164,20 @@ public void accept(final AiPlayerDebugAction aiPlayerDebugAction) {
.build()),
1.45);

System.out.println("Hard AI Results");
System.out.println("Win percentage: " + hardAiResults.getAttackerWinPercent());
System.out.println(
"Avg attacking units remaining: "
+ hardAiResults.getAverageAttackingUnitsRemaining().size()
+ " - "
+ hardAiResults.getAverageAttackingUnitsRemaining());
System.out.println(
"Avg defending units remaining: "
+ hardAiResults.getAverageDefendingUnitsRemaining().size()
+ " - "
+ hardAiResults.getAverageDefendingUnitsRemaining());

System.out.println("Lanchester Results");
System.out.println("Winner: " + lanchesterCalculator.getWon());
System.out.println("Units Remaining: " + lanchesterCalculator.getRemainingUnits());
log.info("Hard AI Results");
log.info("Win percentage: {}", hardAiResults.getAttackerWinPercent());
log.info(
"Avg attacking units remaining: {} - {}",
hardAiResults.getAverageAttackingUnitsRemaining().size(),
hardAiResults.getAverageAttackingUnitsRemaining());
log.info(
"Avg defending units remaining: {} - {}",
hardAiResults.getAverageDefendingUnitsRemaining().size(),
hardAiResults.getAverageDefendingUnitsRemaining());

log.info("Lanchester Results");
log.info("Winner: {}", lanchesterCalculator.getWon());
log.info("Units Remaining: {}", lanchesterCalculator.getRemainingUnits());
}

private Collection<UnitType> getUnitTypes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class GamePlayer extends NamedAttachable implements NamedUnitHolder {
@NonNls private static final String DEFAULT_TYPE_DOES_NOTHING = "DoesNothing";

@RemoveOnNextMajorRelease @Deprecated
private static final GamePlayer NULL_PLAYERID =
private static final GamePlayer NULL_GAME_PLAYER =
// Kept for save game compatibility, or we'll get a class not found error loading neutrals.
new GamePlayer(Constants.PLAYER_NAME_NEUTRAL, true, false, null, false, null) {
private static final long serialVersionUID = -6596127754502509049L;
Expand All @@ -50,7 +50,12 @@ public boolean isNull() {
@Getter private ProductionFrontier productionFrontier;
@Getter private RepairFrontier repairFrontier;
private final TechnologyFrontierList technologyFrontiers;
@Getter private String whoAmI = "null:no_one";

@Getter
private String whoAmI =
// @TODO why : separation, no_one also used in ServerSetupPanel; create constant
"null:" + "no_one";

private TechAttachment techAttachment;

public GamePlayer(final String name, final GameData data) {
Expand Down Expand Up @@ -171,8 +176,8 @@ public boolean getIsDisabled() {
}

/**
* If I have no units with movement, And I own zero factories or have have no owned land, then I
* am basically dead, and therefore should not participate in things like politics.
* If I have no units with movement and I own zero factories or have no owned land, then I am
* basically dead, and therefore should not participate in things like politics.
*/
public boolean amNotDeadYet() {
for (final Territory t : getData().getMap().getTerritories()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package games.strategy.engine.data.gameparser;

import static games.strategy.engine.framework.startup.ui.PlayerTypes.PLAYER_TYPE_HUMAN_LABEL;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -419,7 +421,8 @@ private void parsePlayerList(final PlayerList playerListData) {
current.getName(),
Optional.ofNullable(current.getOptional()).orElse(false),
Optional.ofNullable(current.getCanBeDisabled()).orElse(false),
Optional.ofNullable(current.getDefaultType()).orElse("Human"),
Optional.ofNullable(current.getDefaultType())
.orElse(PLAYER_TYPE_HUMAN_LABEL),
Optional.ofNullable(current.getIsHidden()).orElse(false),
data)));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package games.strategy.engine.framework;

import org.jetbrains.annotations.Nls;

public class HtmlBuilder {
final StringBuilder s = new StringBuilder();

public HtmlBuilder() {
s.append("<html>");
}

public HtmlBuilder addText(@Nls String text) {
s.append(text);
return this;
}

public HtmlBuilder lineBreak() {
s.append("</br>");
return this;
}

@Override
public String toString() {
return s.toString() + "</html>";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ private HtmlUtils() {}
public static String getHtml(final String text) {
return "<html>" + text + "</html>";
}

public static HtmlBuilder getHtml() {
return new HtmlBuilder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.jetbrains.annotations.NonNls;

/**
* This is the main i18n (internationalization) class to retrieve langauge dependent outputs. The
* This is the main i18n (internationalization) class to retrieve language dependent outputs. The
* subclasses of this class should implement a singleton pattern and define the path to the resource
* property file(s).
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package games.strategy.engine.framework.startup.ui;

import games.strategy.engine.framework.I18nEngineFramework;
import games.strategy.engine.player.Player;
import games.strategy.triplea.ai.fast.FastAi;
import games.strategy.triplea.ai.pro.ProAi;
Expand All @@ -17,26 +18,30 @@ public class PlayerTypes {

public static final String DOES_NOTHING_PLAYER_LABEL = "Does Nothing (AI)";
public static final Type WEAK_AI =
new Type("Easy (AI)") {
new Type(I18nEngineFramework.get().getText("startup.PlayerTypes.PLAYER_TYPE_AI_EASY_LABEL")) {
@Override
public Player newPlayerWithName(final String name) {
return new WeakAi(name, getLabel());
}
};
public static final Type FAST_AI =
new Type("Fast (AI)") {
new Type(I18nEngineFramework.get().getText("startup.PlayerTypes.PLAYER_TYPE_AI_FAST_LABEL")) {
@Override
public Player newPlayerWithName(final String name) {
return new FastAi(name, getLabel());
}
};
public static final Type PRO_AI =
new Type("Hard (AI)") {
new Type(I18nEngineFramework.get().getText("startup.PlayerTypes.PLAYER_TYPE_AI_HARD_LABEL")) {
@Override
public Player newPlayerWithName(final String name) {
return new ProAi(name, getLabel());
}
};
public static final String PLAYER_TYPE_DEFAULT_LABEL =
I18nEngineFramework.get().getText("startup.PlayerTypes.PLAYER_TYPE_DEFAULT_LABEL");
public static final String PLAYER_TYPE_HUMAN_LABEL =
I18nEngineFramework.get().getText("startup.PlayerTypes.PLAYER_TYPE_HUMAN_LABEL");

Collection<Type> playerTypes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public static String integerUnitMapToString(
}

/**
* Adds HTML line breaks and indentation to a string so it wraps for things like long tooltips.
* Adds HTML line breaks and indentation to a string, so it wraps for things like long tooltips.
*
* <pre>
* string part 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
startup.MainPanel.btn.Cancel.Lbl=Cancel
startup.MainPanel.btn.Network.Lbl=Network...
startup.MainPanel.btn.Play.Lbl=Play
startup.MainPanel.btn.Play.Tltp.line1=Start your game!
startup.MainPanel.btn.Play.Tltp.line2=If not enabled, then you must select a way to play your game first:
startup.MainPanel.btn.Play.Tltp.line3=Play Online, or Local Game, or PBEM, or Host Networked.
startup.MainPanel.btn.Quit.Lbl=Quit
startup.MainPanel.btn.Quit.Tltp=Close TripleA.
startup.PbfSetupPanel.tab.ForumPosterEditor.Lbl=Play By Forum
startup.PlayerSelectorRow.btn.Alliances.Tltp=Click to play {0}
startup.PlayerTypes.PLAYER_TYPE_DEFAULT_LABEL=Client
startup.PlayerTypes.PLAYER_TYPE_HUMAN_LABEL=Human
startup.ServerSetupPanel.infoPanel.Address.Lbl=Address:
startup.ServerSetupPanel.infoPanel.Name.Lbl=Name:
startup.ServerSetupPanel.infoPanel.Port.Lbl=Port:
startup.SetupPanel.alliance.Lbl=Alliance
startup.SetupPanel.bonusIncome.Lbl=Bonus Income
startup.SetupPanel.btn.PlayerSelection.Lbl=Select Local Players and AI's
startup.SetupPanel.enable.Lbl=Use
startup.SetupPanel.income.Lbl=Income
startup.SetupPanel.local.Lbl=Local
startup.SetupPanel.name.Lbl=Name
startup.SetupPanel.noGameSelected.Lbl=No game selected!
startup.SetupPanel.noPlayers.Lbl=Load a game file first
startup.SetupPanel.player.Lbl=Played By
startup.SetupPanel.PlayerRow.alliance.Play.Tltp=Click to play {0}
startup.SetupPanel.PlayerRow.alliance.Release.Tltp=Click to release {0}
startup.SetupPanel.PlayerRow.Play=Play
startup.SetupPanel.PlayerRow.TakeNoAction.Lbl=Don't Play
startup.SetupPanel.PlayerSelection.Dialog.Title=Select Local Players and AI's
startup.SetupPanel.resourceModifiers.Lbl=Resource Modifiers
startup.SetupPanel.SET_ALL_DEFAULT_LABEL=Default
startup.SetupPanel.setAllTo.Lbl=Set All To:
startup.SetupPanel.type.Lbl=Type
startup.SetupPanelModel.btn.ConnectToNetworkedGame.Lbl=Connect to Networked Game
startup.SetupPanelModel.btn.EnginePreferences.Lbl=Engine Preferences
startup.SetupPanelModel.btn.EnginePreferences.Tltp=Configure certain options related to the engine.
Expand All @@ -9,15 +43,18 @@ startup.SetupPanelModel.btn.PlayByForum.Lbl=Play By Forum
startup.SetupPanelModel.btn.PlayByForum.Tltp=Starts a game which will be posted to an online forum or a message board.
startup.SetupPanelModel.btn.PlayOnline.ConnectToNetworkedGame.Tltp=Connects to someone''s hosted game\
<br/>=so long as you know their IP address.
startup.SetupPanelModel.btn.PlayOnline.Lbl=Play Online
startup.SetupPanelModel.btn.PlayOnline.HostNetworkGame.Tltp=Hosts a network game, which people can connect to.\
<br/>=Anyone on a LAN will be able to connect.\
<br/>=Anyone from the internet can connect as well, but only if the host has configured port forwarding correctly.
startup.SetupPanelModel.btn.PlayOnline.Lbl=Play Online
startup.SetupPanelModel.btn.PlayOnline.Tltp=Find Games Online on the Lobby Server.\
<br/>=TripleA is MEANT to be played Online against other humans.\
<br/>=Any other way is not as fun!
startup.SetupPanelModel.btn.StartLocalGame.Lbl=Start Local Game
startup.SetupPanelModel.btn.StartLocalGame.Tltp=Start a game on this computer.\
<br/>=You can play against a friend sitting besides you (hotseat mode),\
<br/>=You can play against a friend sitting beside you (hotseat mode),\
<br/>=or against one of the AIs.
startup.SetupPanelModel.btn.UserGuideHelp.Lbl=User Guide & Help
startup.PlayerTypes.PLAYER_TYPE_AI_EASY_LABEL=Easy (AI)
startup.PlayerTypes.PLAYER_TYPE_AI_FAST_LABEL=Fast (AI)
startup.PlayerTypes.PLAYER_TYPE_AI_HARD_LABEL=Hard (AI)
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
startup.MainPanel.btn.Cancel.Lbl=Abbrechen
startup.MainPanel.btn.Network.Lbl=Netzwerk...
startup.MainPanel.btn.Play.Lbl=Spiel
startup.MainPanel.btn.Play.Tltp.line1=Starte Dein Spiel!
startup.MainPanel.btn.Play.Tltp.line2=Wenn nicht ausw\u00E4hlbar, muss erst eine Spielweise ausgew\u00E4hlt werden:
startup.MainPanel.btn.Play.Tltp.line3=Spiele online, ein lokales Spiel, PBEM oder \u00F6ffne ein Netzwerkspiel.
startup.MainPanel.btn.Quit.Lbl=Beenden
startup.MainPanel.btn.Quit.Tltp=Schließe TripleA.
startup.PbfSetupPanel.tab.ForumPosterEditor.Lbl=Spiel per Forum
startup.PlayerSelectorRow.btn.Alliances.Tltp=Klick um {0} zu spielen
startup.PlayerTypes.PLAYER_TYPE_DEFAULT_LABEL=Client
startup.PlayerTypes.PLAYER_TYPE_HUMAN_LABEL=Mensch
startup.ServerSetupPanel.infoPanel.Address.Lbl=Adresse:
startup.ServerSetupPanel.infoPanel.Name.Lbl=Name:
startup.ServerSetupPanel.infoPanel.Port.Lbl=Port:
startup.SetupPanel.alliance.Lbl=Allianz
startup.SetupPanel.bonusIncome.Lbl=Bonuseinkommen
startup.SetupPanel.btn.PlayerSelection.Lbl=W\u00E4hle lokale Spieler und KIs
startup.SetupPanel.enable.Lbl=Use
startup.SetupPanel.income.Lbl=Einkommen
startup.SetupPanel.local.Lbl=Lokal
startup.SetupPanel.name.Lbl=Name
startup.SetupPanel.noGameSelected.Lbl=Kein Spiel ausgew\u00E4hlt!
startup.SetupPanel.noPlayers.Lbl=Lade erst eine Spieldatei
startup.SetupPanel.player.Lbl=Gespielt von
startup.SetupPanel.PlayerRow.alliance.Play.Tltp=Klick um {0} zu spielen
startup.SetupPanel.PlayerRow.alliance.Release.Tltp=Klick um {0} freizugeben
startup.SetupPanel.PlayerRow.Play=Spiel
startup.SetupPanel.PlayerRow.TakeNoAction.Lbl=Nicht spielen
startup.SetupPanel.PlayerSelection.Dialog.Title=W\u00E4hle lokale Spieler und KIs
startup.SetupPanel.resourceModifiers.Lbl=Ressourcen Modifikator
startup.SetupPanel.SET_ALL_DEFAULT_LABEL=Standard
startup.SetupPanel.setAllTo.Lbl=Alle setzen auf:
startup.SetupPanel.type.Lbl=Typ
startup.SetupPanelModel.btn.ConnectToNetworkedGame.Lbl=Verbinde zum Netzwerkspiel
startup.SetupPanelModel.btn.EnginePreferences.Lbl=Kerneinstellungen
startup.SetupPanelModel.btn.EnginePreferences.Tltp=Konfiguriere bestimmte Kerneinstellungen
Expand All @@ -9,10 +43,10 @@ startup.SetupPanelModel.btn.PlayByForum.Lbl=Spiel per Forum
startup.SetupPanelModel.btn.PlayByForum.Tltp=Beginnt ein Spiel, welches in einem Internetforum oder einem Nachrichtenboard gepostet wird.
startup.SetupPanelModel.btn.PlayOnline.ConnectToNetworkedGame.Tltp=Verbindet sich mit einem gehosteten Spiel,\
<br/>=solange Du deren IP-Adresse kennst.
startup.SetupPanelModel.btn.PlayOnline.Lbl=Spiel Online
startup.SetupPanelModel.btn.PlayOnline.HostNetworkGame.Tltp=Hosted ein Netzwerkspiel, zu welchem sich andere verbinden k\u00F6nnen.\
<br/>=Jeder im LAN wird sich verbinden k\u00F6nnen.\
<br/>=Auch jeder aus dem Internet kann wird sich verbinden k\u00F6nnen, solange der Host Port-Weiterleitung eingestellt hat.
startup.SetupPanelModel.btn.PlayOnline.Lbl=Spiel Online
startup.SetupPanelModel.btn.PlayOnline.Tltp=Finde Spiele online auf dem Lobby-Server.\
<br/>=TripleA ist daf\u00FCr gedacht, online gegen andere Menschen zu spielen.\
<br/>=Alles andere macht keinen Spa\u00DF!
Expand All @@ -21,3 +55,6 @@ startup.SetupPanelModel.btn.StartLocalGame.Tltp=Start a game on this computer.\
<br/>=Du kannst gegen einen Freund spielen, der neben Dir sitzt (Hotseat-Modus),\
<br/>=oder gegen eine der KIs.
startup.SetupPanelModel.btn.UserGuideHelp.Lbl=Spielanleitung & Hilfe
startup.PlayerTypes.PLAYER_TYPE_AI_EASY_LABEL=Einfach (KI)
startup.PlayerTypes.PLAYER_TYPE_AI_FAST_LABEL=Schnell (KI)
startup.PlayerTypes.PLAYER_TYPE_AI_HARD_LABEL=Schwer (KI)
Loading

0 comments on commit 936b1df

Please sign in to comment.