Fix Localization for game.

This commit is contained in:
kirill.khorkov
2025-12-16 01:18:11 +03:00
parent d2a9b1d4ce
commit e0ad1b8de3
5 changed files with 121 additions and 35 deletions

View File

@@ -73,8 +73,8 @@ public class BuildingPlacer {
game.updateUI();
game.setMessageText(tempBuilding.isOverlapping ?
"🎨 Здание пересекается с существующими! Это добавляет уникальности! 🎨" :
"🌟 Отличное место для строительства! Введите ответ: 🌟");
Localization.buildingOverlaps() :
Localization.greatPlace());
game.setMessageColor(tempBuilding.isOverlapping ? com.badlogic.gdx.graphics.Color.ORANGE : com.badlogic.gdx.graphics.Color.GREEN);
game.setTyping(true);
@@ -85,7 +85,7 @@ public class BuildingPlacer {
if (game.getCurrentBuilding() != null) {
Rectangle buildingBounds = game.getCurrentBuilding().getBounds();
if (buildingBounds.contains(worldX, worldY)) {
game.setMessageText("🎯 Кликните вне здания для нового строительства. Ctrl+Z или Delete для удаления. 🎯");
game.setMessageText(Localization.clickOutside());
game.setMessageColor(com.badlogic.gdx.graphics.Color.CYAN);
} else {
if (!game.isTyping()) {

View File

@@ -1226,7 +1226,8 @@ public class BuildingRenderer {
font.setColor(pulseColor);
font.getData().setScale(1.1f * building.getSizeScale());
glyphLayout.setText(font, building.type);
String localizedName = Localization.getBuildingName(building);
glyphLayout.setText(font, localizedName);
float textWidth = glyphLayout.width;
// Фон с закругленными краями
@@ -1241,7 +1242,7 @@ public class BuildingRenderer {
batch.draw(whitePixel, x - textWidth/2 - 15, y + 10, textWidth + 30, 5); // Низ
batch.setColor(Color.WHITE);
font.draw(batch, building.type, x - textWidth/2, y);
font.draw(batch, localizedName, x - textWidth/2, y);
font.getData().setScale(1.0f);
}
@@ -1252,9 +1253,8 @@ public class BuildingRenderer {
font.setColor(Color.YELLOW);
font.getData().setScale(0.9f * building.getSizeScale());
String cleanType = building.type.replace("", "").replace("🏥", "").replace("🎒", "")
.replace("🎪", "").replace("💰", "").replace("💊", "")
.replace("🎭", "").replace("🎬", "").trim();
String localizedName = Localization.getBuildingName(building);
String cleanType = localizedName.replaceAll("[✨🏥🎒🎪💰💊🎭🎬🚀🔴🛰️⚡💧🌌🤖🧪🌋🔥🌅☁️💎🌡️🌀]", "").trim();
String progressText = cleanType + " (" + building.constructionProgress + "/3)";
glyphLayout.setText(font, progressText);
float textWidth = glyphLayout.width;
@@ -1274,10 +1274,9 @@ public class BuildingRenderer {
font.setColor(Color.YELLOW);
font.getData().setScale(1.0f * building.getSizeScale());
String cleanType = building.type.replace("", "").replace("🏥", "").replace("🎒", "")
.replace("🎪", "").replace("💰", "").replace("💊", "")
.replace("🎭", "").replace("🎬", "").trim();
String prefix = building.constructionProgress == 0 ? "Место для: " : "Строится: ";
String localizedName = Localization.getBuildingName(building);
String cleanType = localizedName.replaceAll("[✨🏥🎒🎪💰💊🎭🎬🚀🔴🛰️⚡💧🌌🤖🧪🌋🔥🌅☁️💎🌡️🌀]", "").trim();
String prefix = building.constructionProgress == 0 ? Localization.placeFor() : Localization.constructing();
String progressText = prefix + cleanType + " (" + building.constructionProgress + "/3)";
glyphLayout.setText(font, progressText);
float textWidth = glyphLayout.width;
@@ -1291,7 +1290,7 @@ public class BuildingRenderer {
if (building.isOverlapping) {
font.setColor(Color.RED);
font.getData().setScale(0.8f * building.getSizeScale());
String warning = "⚠ Пересечение! ⚠";
String warning = Localization.overlapWarning();
glyphLayout.setText(font, warning);
font.draw(batch, warning, x - glyphLayout.width/2, y - 25);
font.getData().setScale(1.0f);

View File

@@ -18,8 +18,8 @@ public class InputHandler {
game.setSelectedBuildingType(newType);
game.updateUI();
game.setMessageText("Выбран: " +
Building.BUILDING_TYPES_BY_PLANET[game.getCurrentPlanet().ordinal()][newType]);
game.setMessageText(Localization.selected() + ": " +
Localization.getBuildingName(game.getCurrentPlanet(), newType));
game.setMessageColor(com.badlogic.gdx.graphics.Color.CYAN);
}
}
@@ -31,8 +31,8 @@ public class InputHandler {
game.setSelectedBuildingType(newType);
game.updateUI();
game.setMessageText("Выбран: " +
Building.BUILDING_TYPES_BY_PLANET[game.getCurrentPlanet().ordinal()][newType]);
game.setMessageText(Localization.selected() + ": " +
Localization.getBuildingName(game.getCurrentPlanet(), newType));
game.setMessageColor(com.badlogic.gdx.graphics.Color.CYAN);
}
}
@@ -72,15 +72,15 @@ public class InputHandler {
game.setCurrentProblem(null);
game.setTyping(false);
game.getInputText().setLength(0);
game.setMessageText("Строительство отменено. Выберите новое место.");
game.setMessageText(Localization.constructionCancelled());
game.setMessageColor(com.badlogic.gdx.graphics.Color.YELLOW);
game.updateUI();
} else if (game.getBuildings().size > 0) {
game.getBuildings().removeIndex(game.getBuildings().size - 1);
game.setMessageText("Последнее здание удалено.");
game.setMessageText(Localization.lastBuildingRemoved());
game.setMessageColor(com.badlogic.gdx.graphics.Color.ORANGE);
} else {
game.setMessageText("Нет зданий для удаления.");
game.setMessageText(Localization.noBuildingsToRemove());
game.setMessageColor(com.badlogic.gdx.graphics.Color.YELLOW);
}
}
@@ -128,7 +128,7 @@ public class InputHandler {
game.getInputText().deleteCharAt(game.getInputText().length() - 1);
} else if (!game.isTyping() && game.getCurrentBuilding() != null && game.getCurrentBuilding().constructionProgress > 0) {
game.getCurrentBuilding().removeBlock();
game.setMessageText("Блок удален! Текущий прогресс: " + game.getCurrentBuilding().constructionProgress + "/3");
game.setMessageText(Localization.blockRemoved(game.getCurrentBuilding().constructionProgress));
game.setMessageColor(com.badlogic.gdx.graphics.Color.YELLOW);
game.updateUI();
}
@@ -143,7 +143,7 @@ public class InputHandler {
if (game.isTyping()) {
game.setTyping(false);
game.getInputText().setLength(0);
game.setMessageText("Ввод отменен. Можно продолжить строительство.");
game.setMessageText(Localization.inputCancelled());
game.setMessageColor(com.badlogic.gdx.graphics.Color.YELLOW);
}
}

View File

@@ -68,6 +68,88 @@ public class Localization {
return isRu() ? "Отлично! Блок построен!" : "Great! Block built!";
}
public static String selected() {
return isRu() ? "Выбран" : "Selected";
}
public static String overlapping() {
return isRu() ? "(пересекается!)" : "(overlapping!)";
}
public static String colorTheme() {
return isRu() ? "Цвет: Тема" : "Color: Theme";
}
public static String building() {
return isRu() ? "Строим" : "Building";
}
public static String planet() {
return isRu() ? "Планета" : "Planet";
}
public static String buildingType() {
return isRu() ? "Тип здания" : "Building type";
}
public static String arrowsToSelect() {
return isRu() ? "(←/→ для выбора, кликните для строительства)" : "(←/→ to select, click to build)";
}
public static String menu() {
return isRu() ? "меню" : "menu";
}
public static String flyingTo() {
return isRu() ? "Перелет на" : "Flying to";
}
public static String placeFor() {
return isRu() ? "Место для: " : "Place for: ";
}
public static String constructing() {
return isRu() ? "Строится: " : "Building: ";
}
public static String overlapWarning() {
return isRu() ? "⚠ Пересечение! ⚠" : "⚠ Overlap! ⚠";
}
public static String buildingOverlaps() {
return isRu()
? "🎨 Здание пересекается с существующими! Это добавляет уникальности! 🎨"
: "🎨 Building overlaps with existing ones! This adds uniqueness! 🎨";
}
public static String greatPlace() {
return isRu()
? "🌟 Отличное место для строительства! Введите ответ: 🌟"
: "🌟 Great place to build! Enter your answer: 🌟";
}
public static String clickOutside() {
return isRu()
? "🎯 Кликните вне здания для нового строительства. Ctrl+Z или Delete для удаления. 🎯"
: "🎯 Click outside building for new construction. Ctrl+Z or Delete to remove. 🎯";
}
public static String constructionCancelled() {
return isRu()
? "Строительство отменено. Выберите новое место."
: "Construction cancelled. Select a new place.";
}
public static String lastBuildingRemoved() {
return isRu() ? "Последнее здание удалено." : "Last building removed.";
}
public static String inputCancelled() {
return isRu()
? "Ввод отменен. Можно продолжить строительство."
: "Input cancelled. You can continue building.";
}
public static String changePlanet() {
return isRu() ? "↑/↓ - сменить планету" : "↑/↓ - change planet";
}
@@ -245,10 +327,6 @@ public class Localization {
return isRu() ? "Строительство отменено. Выберите новое место." : "Construction canceled. Choose a new location.";
}
public static String lastBuildingRemoved() {
return isRu() ? "Последнее здание удалено." : "Last building removed.";
}
public static String noBuildingsToRemove() {
return isRu() ? "Нет зданий для удаления." : "No buildings to remove.";
}
@@ -281,6 +359,16 @@ public class Localization {
return BUILDING_NAMES_EN;
}
// Получить локализованное название здания по индексам
public static String getBuildingName(Planet planet, int typeIndex) {
return getBuildingNames()[planet.ordinal()][typeIndex];
}
// Получить локализованное название для Building объекта
public static String getBuildingName(Building building) {
return getBuildingNames()[building.planetIndex][building.buildingTypeIndex];
}
private static final String[][] BUILDING_NAMES_EN = {
// Earth
{

View File

@@ -7,27 +7,26 @@ public class UIUpdater {
}
Planet planet = game.getCurrentPlanet();
String[] planetBuildings = Building.BUILDING_TYPES_BY_PLANET[planet.ordinal()];
if (game.getCurrentBuilding() != null && game.getCurrentProblem() != null) {
String overlapText = game.getCurrentBuilding().isOverlapping ? " (пересекается!)" : "";
String overlapText = game.getCurrentBuilding().isOverlapping ? " " + Localization.overlapping() : "";
String colorInfo = "";
if (game.getCurrentBuilding().isComplete()) {
colorInfo = String.format(" [Цвет: Тема %d]", game.getCurrentBuilding().colorThemeIndex + 1);
colorInfo = String.format(" [%s %d]", Localization.colorTheme(), game.getCurrentBuilding().colorThemeIndex + 1);
}
String fullText = "Строим " + game.getCurrentBuilding().type +
String fullText = Localization.building() + " " + Localization.getBuildingName(game.getCurrentBuilding()) +
" (" + game.getCurrentBuilding().constructionProgress + "/3)" + colorInfo +
": " + game.getCurrentProblem().getQuestion() + overlapText;
game.setProblemText(fullText);
} else {
String planetText = game.isSwitchingPlanets() ?
"Перелет на " + game.getTargetPlanet().getName() + "..." :
"Планета: " + planet.getName();
Localization.flyingTo() + " " + Localization.planetName(game.getTargetPlanet()) + "..." :
Localization.planet() + ": " + Localization.planetName(planet);
game.setProblemText(planetText +
" | Тип здания: " + planetBuildings[game.getSelectedBuildingType()] +
" (←/→ для выбора, кликните на поле для строительства)" +
" | ESC - меню");
" | " + Localization.buildingType() + ": " + Localization.getBuildingName(planet, game.getSelectedBuildingType()) +
" " + Localization.arrowsToSelect() +
" | ESC - " + Localization.menu());
}
}
}