Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions forge-gui-mobile/src/forge/adventure/character/DialogActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ public class DialogActor extends CharacterSprite {
public AdventureQuestData questData;

public DialogActor(MapStage stage, int id, String S, TextureRegion textureRegion) {
this(stage, id, S, textureRegion, null);
}
public DialogActor(MapStage stage, int id, String S, TextureRegion textureRegion, String sourceMapFile) {
super(id,"");
this.stage = stage;
dialog = new MapDialog(S, stage, id);
dialog = new MapDialog(S, stage, id, sourceMapFile);
this.textureRegion = textureRegion;
}
public DialogActor(MapStage stage, int id, String S, String sprite) {
this(stage, id, S, sprite, null);
}
public DialogActor(MapStage stage, int id, String S, String sprite, String sourceMapFile) {
super(id,sprite);
this.stage = stage;
dialog = new MapDialog(S, stage, id);
dialog = new MapDialog(S, stage, id, sourceMapFile);
this.textureRegion = null;
}

Expand Down
28 changes: 14 additions & 14 deletions forge-gui-mobile/src/forge/adventure/scene/NewGameScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,48 +399,48 @@ public void enter() {
}

private void showDifficultyHelp() {
Localizer localizer = Forge.getLocalizer();
DifficultyData selectedDifficulty = Config.instance().getConfigData().difficulties[difficulty.getCurrentIndex()];
boolean enableGeneticAI = Config.instance().getConfigData().enableGeneticAI;
String startingEquipment = selectedDifficulty.startItems == null || selectedDifficulty.startItems.length == 0
? "None"
? localizer.getMessage("lblNone")
: String.join(", ", selectedDifficulty.startItems);

difficultySummary = new DialogData();
difficultySummary.name = "Summary";
difficultySummary.name = localizer.getMessage("lblSummary");
switch (selectedDifficulty.name) {
case "Easy":
difficultySummary.text = String.format("Difficulty: %s\nFor newer players or those who want a relaxed experience.\nStarter decks are monocolored.\nStarting equipment: %s", selectedDifficulty.name, startingEquipment);
difficultySummary.text = localizer.getMessage("advDifficultySummaryEasy", selectedDifficulty.name, startingEquipment);
break;
case "Normal":
difficultySummary.text = String.format("Difficulty: %s\nHow Adventure Mode is intended to be played.\nStarter decks will include a second color.\nStarting equipment: %s", selectedDifficulty.name, startingEquipment);
difficultySummary.text = localizer.getMessage("advDifficultySummaryNormal", selectedDifficulty.name, startingEquipment);
break;
case "Hard":
if (enableGeneticAI) {
difficultySummary.text = String.format("Difficulty: %s\nFor players who want a challenge.\nSome enemies will use genetic AI decks.\nStarter decks will include 2-3 colors.\nStarting equipment: %s", selectedDifficulty.name, startingEquipment);
difficultySummary.text = localizer.getMessage("advDifficultySummaryHardGenetic", selectedDifficulty.name, startingEquipment);
} else {
difficultySummary.text = String.format("Difficulty: %s\nFor players who want a challenge.\nStarter decks will include 2-3 colors.\nStarting equipment: %s", selectedDifficulty.name, startingEquipment);
difficultySummary.text = localizer.getMessage("advDifficultySummaryHard", selectedDifficulty.name, startingEquipment);
}
break;
case "Insane":
difficultySummary.text = String.format("Difficulty: %s\nFor players who don't want to like the game.\nIdentical to Hard difficulty, but with even less forgiving and rewarding results.\nStarter decks will include 2-3 colors.\nStarting equipment: %s", selectedDifficulty.name, startingEquipment);
difficultySummary.text = localizer.getMessage("advDifficultySummaryInsane", selectedDifficulty.name, startingEquipment);
break;
default:
difficultySummary.text = "((Custom difficulty settings))";
difficultySummary.text = localizer.getMessage("advDifficultySummaryCustom");
break;
}


DialogData dismiss = new DialogData();
//todo: add translation
dismiss.name = "OK";
dismiss.name = localizer.getMessage("lblOK");

DialogData matchImpacts = new DialogData();
matchImpacts.text = String.format("Difficulty: %s\nStarting Life: %d\nEnemy Health: %d%%\nGold loss on defeat: %d%%\nLife loss on defeat: %d%%", selectedDifficulty.name, selectedDifficulty.startingLife, (int) (selectedDifficulty.enemyLifeFactor * 100), (int) (selectedDifficulty.goldLoss * 100), (int) (selectedDifficulty.lifeLoss * 100));
matchImpacts.name = "Duels";
matchImpacts.text = localizer.getMessage("advDifficultyMatchImpacts", selectedDifficulty.name, selectedDifficulty.startingLife, (int) (selectedDifficulty.enemyLifeFactor * 100), (int) (selectedDifficulty.goldLoss * 100), (int) (selectedDifficulty.lifeLoss * 100));
matchImpacts.name = localizer.getMessage("lblDuels");

DialogData economyImpacts = new DialogData();
economyImpacts.text = String.format("Difficulty: %s\nStarting Gold: %d\nStarting Mana Shards: %d\nCard Sale Price: %d%%\nMana Shard Sale Price: %d%%\nRandom loot rate: %d%%", selectedDifficulty.name, selectedDifficulty.startingMoney, selectedDifficulty.startingShards, (int) (selectedDifficulty.sellFactor * 100), (int) (selectedDifficulty.shardSellRatio * 100), (int) (selectedDifficulty.rewardMaxFactor * 100));
economyImpacts.name = "Economy";
economyImpacts.text = localizer.getMessage("advDifficultyEconomyImpacts", selectedDifficulty.name, selectedDifficulty.startingMoney, selectedDifficulty.startingShards, (int) (selectedDifficulty.sellFactor * 100), (int) (selectedDifficulty.shardSellRatio * 100), (int) (selectedDifficulty.rewardMaxFactor * 100));
economyImpacts.name = localizer.getMessage("lblEconomy");

difficultySummary.options = new DialogData[3];
difficultySummary.options[0] = matchImpacts;
Expand Down
2 changes: 1 addition & 1 deletion forge-gui-mobile/src/forge/adventure/stage/GameHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public void enter() {
case "town":
if (MapStage.getInstance().isInMap()) {
int rep = TileMapScene.instance().getPointOfInterestChanges().getMapReputation();
String reputationText = TileMapScene.instance().rootPoint.getDisplayName() + "\nReputation: " + (rep > 0 ? "[GREEN]" : rep < 0 ? "[RED]" : "[WHITE]") + rep + "[/]";
String reputationText = TileMapScene.instance().rootPoint.getDisplayName() + "\n" + Forge.getLocalizer().getMessage("advReputation") + ": " + (rep > 0 ? "[GREEN]" : rep < 0 ? "[RED]" : "[WHITE]") + rep + "[/]";
if (fromWorldMap) {
addNotification(reputationText);
fromWorldMap = false;
Expand Down
4 changes: 2 additions & 2 deletions forge-gui-mobile/src/forge/adventure/stage/GameStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ public boolean keyDown(int keycode) {
if (TileMapScene.instance().currentMap().isInMap()) {
DialogData noQuicksave = new DialogData();
DialogData noQuicksaveOK = new DialogData();
noQuicksave.text = "Game not saved. Quicksave is only available on the world map.";
noQuicksaveOK.name = "OK";
noQuicksave.text = Forge.getLocalizer().getMessageorUseDefault("lblQuicksaveOnlyOnWorldMap", "Game not saved. Quicksave is only available on the world map.");
noQuicksaveOK.name = Forge.getLocalizer().getMessage("lblOK");
noQuicksave.options = new DialogData[]{noQuicksaveOK};
MapDialog noQuicksaveDialog = new MapDialog(noQuicksave, MapStage.getInstance(), -1, null);
showDialog();
Expand Down
8 changes: 4 additions & 4 deletions forge-gui-mobile/src/forge/adventure/stage/MapStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,11 @@ else if (prop.containsKey("portalState")) {
EnemySprite mob = new EnemySprite(id, EN);
Object dialogObject = prop.get("dialog"); //Check if the enemy has a dialogue attached to it.
if (dialogObject != null && !dialogObject.toString().isEmpty()) {
mob.dialog = new MapDialog(dialogObject.toString(), this, mob.getId());
mob.dialog = new MapDialog(dialogObject.toString(), this, mob.getId(), currentMap);
}
dialogObject = prop.get("defeatDialog"); //Check if the enemy has a defeat dialogue attached to it.
if (dialogObject != null && !dialogObject.toString().isEmpty()) {
mob.defeatDialog = new MapDialog(dialogObject.toString(), this, mob.getId());
mob.defeatDialog = new MapDialog(dialogObject.toString(), this, mob.getId(), currentMap);
}
dialogObject = prop.get("displayNameOverride"); //Check for name override.
if (dialogObject != null && !dialogObject.toString().isEmpty()) {
Expand Down Expand Up @@ -612,9 +612,9 @@ else if (prop.containsKey("portalState")) {
TiledMapTileMapObject tiledObj = (TiledMapTileMapObject) obj;
DialogActor dialog;
if (prop.containsKey("sprite"))
dialog = new DialogActor(this, id, prop.get("dialog").toString(), prop.get("sprite").toString());
dialog = new DialogActor(this, id, prop.get("dialog").toString(), prop.get("sprite").toString(), currentMap);
else {
dialog = new DialogActor(this, id, prop.get("dialog").toString(), tiledObj.getTextureRegion());
dialog = new DialogActor(this, id, prop.get("dialog").toString(), tiledObj.getTextureRegion(), currentMap);
}
if (prop.containsKey("hidden") && Boolean.parseBoolean(prop.get("hidden").toString()))
{
Expand Down
4 changes: 4 additions & 0 deletions forge-gui-mobile/src/forge/adventure/util/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ public String getPrefix() {
return prefix;
}

public String getLang() {
return Lang;
}

public String getFilePath(String path) {
return prefix + path;
}
Expand Down
86 changes: 86 additions & 0 deletions forge-gui-mobile/src/forge/adventure/util/DialogTranslations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package forge.adventure.util;

import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.JsonReader;
import com.badlogic.gdx.utils.JsonValue;
import forge.adventure.data.DialogData;

import java.util.HashMap;
import java.util.Map;

public class DialogTranslations {

private static final String CATALOG_SUBDIR = "maps/";
private static final Map<String, Map<String, String>> catalogCache = new HashMap<>();

private DialogTranslations() {}

public static void apply(String sourceMapFile, int parentID, Array<DialogData> roots) {
if (sourceMapFile == null || sourceMapFile.isEmpty() || roots == null || roots.size == 0) return;

Map<String, String> catalog = getCatalog();
if (catalog.isEmpty()) return;

String baseKey = fileBaseName(sourceMapFile) + "#" + parentID;
for (int i = 0; i < roots.size; i++) {
applyRecursive(catalog, roots.get(i), baseKey + "#" + i);
}
}

private static void applyRecursive(Map<String, String> catalog, DialogData node, String path) {
if (node == null) return;

if (node.text != null && !node.text.isEmpty()) {
String translated = catalog.get(path + ":text");
if (translated != null) node.text = translated;
}
if (node.name != null && !node.name.isEmpty()) {
String translated = catalog.get(path + ":name");
if (translated != null) node.name = translated;
}
if (node.options != null) {
for (int i = 0; i < node.options.length; i++) {
applyRecursive(catalog, node.options[i], path + "." + i);
}
}
}

private static String fileBaseName(String path) {
String name = path.replace('\\', '/');
int slash = name.lastIndexOf('/');
return slash >= 0 ? name.substring(slash + 1) : name;
}

private static Map<String, String> getCatalog() {
String lang = Config.instance().getLang();
Map<String, String> cached = catalogCache.get(lang);
if (cached != null) return cached;

Map<String, String> merged = new HashMap<>();
String catalogFileName = CATALOG_SUBDIR + "dialog-" + lang + ".json";
loadCatalogFile(Config.instance().getCommonFilePath(catalogFileName), merged);
loadCatalogFile(Config.instance().getFilePath(catalogFileName), merged);
catalogCache.put(lang, merged);
return merged;
}

private static void loadCatalogFile(String path, Map<String, String> target) {
FileHandle file = new FileHandle(path);
if (!file.exists()) return;
try {
JsonValue root = new JsonReader().parse(file);
for (JsonValue entry = root.child; entry != null; entry = entry.next) {
if (entry.name != null && !entry.name.startsWith("_") && entry.isString()) {
target.put(entry.name, entry.asString());
}
}
} catch (Exception e) {
System.err.println("Error loading dialog translation catalog " + path + ": " + e.getMessage());
}
}

public static void reset() {
catalogCache.clear();
}
}
9 changes: 7 additions & 2 deletions forge-gui-mobile/src/forge/adventure/util/MapDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public class MapDialog {


public MapDialog(String S, MapStage stage, int parentID) {
this(S, stage, parentID, null);
}

public MapDialog(String S, MapStage stage, int parentID, String sourceMapFile) {
this.stage = stage;
this.parentID = parentID;
try {
Expand All @@ -70,6 +74,7 @@ public MapDialog(String S, MapStage stage, int parentID) {
return;
}
this.data = JSONStringLoader.parse(Array.class, DialogData.class, S, defaultJSON);
DialogTranslations.apply(sourceMapFile, parentID, this.data);
} catch (Exception exception) {
exception.printStackTrace();

Expand Down Expand Up @@ -167,7 +172,7 @@ private boolean loadDialog(DialogData dialog) { //Displays a dialog with dialogu
if (actor instanceof CharacterSprite)
sprite = ((CharacterSprite) actor).getAvatar();
String text; //Check for localized string (locname), otherwise print text.
if (dialog.loctext != null && !dialog.loctext.isEmpty()) text = L.getMessage(dialog.loctext);
if (dialog.loctext != null && !dialog.loctext.isEmpty()) text = L.getMessageorUseDefault(dialog.loctext, dialog.text);
else text = dialog.text;
disposeAudio();
if (dialog.voiceFile != null) {
Expand Down Expand Up @@ -228,7 +233,7 @@ public void run() {
for (DialogData option : dialog.options) {
if (isConditionOk(option.condition)) {
String name; //Get localized label if present.
if (option.locname != null && !option.locname.isEmpty()) name = L.getMessage(option.locname);
if (option.locname != null && !option.locname.isEmpty()) name = L.getMessageorUseDefault(option.locname, option.name);
else name = option.name;
TextraButton B;
if (option.isDisabled) {
Expand Down
Loading
Loading