feat(text): the race menu reads its texts from translation files
First step of moving every piece of text out of the code so modders can translate the mod. The texts live in Translations/<Language>/*.json, one file per kind of text, which Jotunn finds on its own and falls back to English for. ModText reads them; values take Valheim's $1, $2 placeholders. This step covers the race selection menu: title, buttons, every race's name and description, in English and Italian. The race ID and the name on screen are now separate strings. The ID is what the save and the ZDO hold, so it must never be translated. The files are deployed to plugins\RacesOfValheim\Translations and packed into both release zips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a835a58003
commit
73b67cd6ce
5 changed files with 169 additions and 22 deletions
|
|
@ -303,7 +303,7 @@ namespace RacesOfValheim
|
|||
titleObj.transform.SetParent(selectionPanel.transform, false);
|
||||
Text titleText = titleObj.AddComponent<Text>();
|
||||
titleText.font = GUIManager.Instance.AveriaSerifBold;
|
||||
titleText.text = "Choose your Race";
|
||||
titleText.text = ModText.Get("rov_menu_choose_race");
|
||||
titleText.fontSize = 50;
|
||||
titleText.alignment = TextAnchor.MiddleCenter;
|
||||
titleText.color = Color.white;
|
||||
|
|
@ -346,7 +346,7 @@ namespace RacesOfValheim
|
|||
btnOkTxtObj.transform.SetParent(btnOkObj.transform, false);
|
||||
Text btnOkTxt = btnOkTxtObj.AddComponent<Text>();
|
||||
btnOkTxt.font = GUIManager.Instance.AveriaSerifBold;
|
||||
btnOkTxt.text = "OK";
|
||||
btnOkTxt.text = ModText.Get("rov_menu_ok");
|
||||
btnOkTxt.fontSize = 24;
|
||||
btnOkTxt.alignment = TextAnchor.MiddleCenter;
|
||||
btnOkTxt.color = Color.white;
|
||||
|
|
@ -371,7 +371,7 @@ namespace RacesOfValheim
|
|||
btnBackTxtObj.transform.SetParent(btnBackObj.transform, false);
|
||||
Text btnBackTxt = btnBackTxtObj.AddComponent<Text>();
|
||||
btnBackTxt.font = GUIManager.Instance.AveriaSerifBold;
|
||||
btnBackTxt.text = "Back";
|
||||
btnBackTxt.text = ModText.Get("rov_menu_back");
|
||||
btnBackTxt.fontSize = 24;
|
||||
btnBackTxt.alignment = TextAnchor.MiddleCenter;
|
||||
btnBackTxt.color = Color.white;
|
||||
|
|
@ -379,34 +379,40 @@ namespace RacesOfValheim
|
|||
btnBackTxtRect.anchorMin = Vector2.zero; btnBackTxtRect.anchorMax = Vector2.one;
|
||||
btnBackTxtRect.offsetMin = Vector2.zero; btnBackTxtRect.offsetMax = Vector2.zero;
|
||||
|
||||
void CreateRaceButtonWithConfirm(string label, Vector2 position, Sprite iconSprite, string description, UnityEngine.Events.UnityAction onConfirm)
|
||||
// The race ID picks the texts and is what gets saved; the button, the title and the
|
||||
// description only ever show the translated name. See ModText.RaceName for why the two
|
||||
// must never be the same string.
|
||||
void CreateRaceButtonWithConfirm(string raceId, Vector2 position, Sprite iconSprite, UnityEngine.Events.UnityAction onConfirm, params object[] descArgs)
|
||||
{
|
||||
CreateRaceButton(label, position, iconSprite, selectionPanel.transform, () => {
|
||||
string name = ModText.RaceName(raceId);
|
||||
CreateRaceButton(raceId, name, position, iconSprite, selectionPanel.transform, () => {
|
||||
selectionPanel.SetActive(false);
|
||||
confirmationPanel.SetActive(true);
|
||||
confTitleText.text = label;
|
||||
confDescText.text = description;
|
||||
confTitleText.text = name;
|
||||
confDescText.text = ModText.RaceDescription(raceId, descArgs);
|
||||
btnOk.onClick.RemoveAllListeners();
|
||||
btnOk.onClick.AddListener(onConfirm);
|
||||
});
|
||||
}
|
||||
|
||||
// Row 1 (y = 100)
|
||||
CreateRaceButtonWithConfirm("Human", new Vector2(-450, 100), GetHumanIcon(), "The versatile founders of Midgard. Balanced stats with no specific weaknesses.", SelectHuman);
|
||||
CreateRaceButtonWithConfirm("Fenrir", new Vector2(-150, 100), GetFenrirIcon(), "Cursed by the blood of the wolf. Fast and deadly, but vulnerable to silver.", SelectFenrir);
|
||||
CreateRaceButtonWithConfirm("Skadi", new Vector2(150, 100), GetSkadiIcon(), "Children of the mountains. Resistant to frost, at home in the freezing cold.", SelectSkadi);
|
||||
CreateRaceButtonWithConfirm("Skeleton", new Vector2(450, 100), GetSkeletonIcon(), "Undead warriors. Immune to poison, but brittle against blunt trauma.", SelectSkeleton);
|
||||
|
||||
CreateRaceButtonWithConfirm("Human", new Vector2(-450, 100), GetHumanIcon(), SelectHuman);
|
||||
CreateRaceButtonWithConfirm("Fenrir", new Vector2(-150, 100), GetFenrirIcon(), SelectFenrir);
|
||||
CreateRaceButtonWithConfirm("Skadi", new Vector2(150, 100), GetSkadiIcon(), SelectSkadi);
|
||||
CreateRaceButtonWithConfirm(SkeletonVisuals.RaceId, new Vector2(450, 100), GetSkeletonIcon(), SelectSkeleton);
|
||||
|
||||
// Row 2 (y = -20)
|
||||
CreateRaceButtonWithConfirm("Aswid", new Vector2(-450, -20), GetAswidIcon(), "Fierce night stalker. Strong and resilient, transforms into a bat.", SelectAswid);
|
||||
CreateRaceButtonWithConfirm("Furling", new Vector2(-150, -20), GetFurlingIcon(), "Cunning goblin-like creatures. Agile and resourceful.", SelectFurling);
|
||||
CreateRaceButtonWithConfirm("Trol", new Vector2(150, -20), GetTrolIcon(), $"Massive brute strength. Towering over others, at peace with the Black Forest - but fire burns a Trol {(TrolConfig.FireWeaknessMultiplier.Value - 1f) * 100f:0}% harder than anyone else.", SelectTrol);
|
||||
CreateRaceButtonWithConfirm("Draugh", new Vector2(450, -20), GetDraughIcon(), "A decaying undead warrior fueled by dark magic and extreme metal.", SelectDraugh);
|
||||
CreateRaceButtonWithConfirm("Aswid", new Vector2(-450, -20), GetAswidIcon(), SelectAswid);
|
||||
CreateRaceButtonWithConfirm("Furling", new Vector2(-150, -20), GetFurlingIcon(), SelectFurling);
|
||||
// $1 in the Trol's description is how much harder fire burns it, read from the config.
|
||||
CreateRaceButtonWithConfirm("Trol", new Vector2(150, -20), GetTrolIcon(), SelectTrol,
|
||||
((TrolConfig.FireWeaknessMultiplier.Value - 1f) * 100f).ToString("0"));
|
||||
CreateRaceButtonWithConfirm(DraughVisuals.RaceId, new Vector2(450, -20), GetDraughIcon(), SelectDraugh);
|
||||
|
||||
// Row 3 (y = -140)
|
||||
CreateRaceButtonWithConfirm("Dvergar", new Vector2(-450, -140), GetDvergarIcon(), "Small, stubborn smiths of the deep. Frail of frame, but masters of metal, mine and market.", SelectDvergar);
|
||||
CreateRaceButtonWithConfirm("Trenta", new Vector2(-150, -140), GetTrentaIcon(), "Tree-born folk, kin to root and leaf. Patient and hard to fell.", SelectTrenta);
|
||||
CreateRaceButtonWithConfirm("Sverm", new Vector2(150, -140), GetSvermIcon(), "Chitin-born swarm kin. Armoured from birth and never slowed, venomous, at peace with every crawling thing - but blunt trauma and fire find the seams.", SelectSverm);
|
||||
CreateRaceButtonWithConfirm(DvergarConfig.RaceId, new Vector2(-450, -140), GetDvergarIcon(), SelectDvergar);
|
||||
CreateRaceButtonWithConfirm(TrentaConfig.RaceId, new Vector2(-150, -140), GetTrentaIcon(), SelectTrenta);
|
||||
CreateRaceButtonWithConfirm(SvermConfig.RaceId, new Vector2(150, -140), GetSvermIcon(), SelectSverm);
|
||||
|
||||
GUIManager.BlockInput(true);
|
||||
}
|
||||
|
|
@ -481,9 +487,9 @@ namespace RacesOfValheim
|
|||
return null;
|
||||
}
|
||||
|
||||
private void CreateRaceButton(string label, Vector2 position, Sprite iconSprite, Transform parentTransform, UnityEngine.Events.UnityAction onClick)
|
||||
private void CreateRaceButton(string raceId, string label, Vector2 position, Sprite iconSprite, Transform parentTransform, UnityEngine.Events.UnityAction onClick)
|
||||
{
|
||||
GameObject btnObj = new GameObject(label + "Button");
|
||||
GameObject btnObj = new GameObject(raceId + "Button");
|
||||
btnObj.transform.SetParent(parentTransform, false);
|
||||
RectTransform btnRect = btnObj.AddComponent<RectTransform>();
|
||||
btnRect.sizeDelta = new Vector2(250, 80);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue