Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .agent/rules/text-localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ UI text should always get localized. Localization files are located in `Assets/S
- The format is `KEY,Value`.
- When adding new text:
1. Add the `KEY,English Value` to `Localization.English.txt`.
2. **CRITICAL**: Add a translated version `KEY,Translated Value` to *all* other relevant files (`Localization.German.txt`, `Localization.French.txt`, `Localization.Spanish.txt`, `Localization.Italian.txt`, etc.) **IMMEDIATELY**. Do not defer this task. Failing to do so will result in missing text for users of those languages.
2. **CRITICAL**: Add a translated version `KEY,Translated Value` to *all* other relevant files (`Localization.German.txt`, `Localization.French.txt`, `Localization.Spanish.txt`, `Localization.Italian.txt`, etc.) where the value is translated to the language specified in the filename **IMMEDIATELY**. Do not defer this task. Failing to do so will result in missing text for users of those languages.
3. In C# code, use `new StringKey("val", "KEY")` to reference the text.
4. For commonly used keys, add a static reference in `Assets/Scripts/Content/CommonStringKeys.cs`.
5. **VERIFICATION**: Before finishing the task, use find_by_name or list_dir to list all Localization.*.txt files. Confirm that the new key has been added and translated to the respective file language to EACH file. Do not assume; verify.
11 changes: 11 additions & 0 deletions unity/Assets/Scripts/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ void Awake()
debugTests = true;
}

// Apply background audio setting
string s_playAudio = config.data.Get("UserConfig", "playAudioInBackground");
if (s_playAudio == "1")
{
Application.runInBackground = true;
}
else
{
Application.runInBackground = false;
}

// Apply saved resolution and fullscreen settings
string savedRes = config.data.Get("UserConfig", "resolution");
string savedFs = config.data.Get("UserConfig", "fullscreen");
Expand Down
54 changes: 41 additions & 13 deletions unity/Assets/Scripts/UI/Screens/OptionsScreen.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Expand Down Expand Up @@ -29,6 +29,7 @@ public class OptionsScreen
private readonly StringKey EXPORT_LOG = new StringKey("val", "EXPORT_LOG");
private readonly StringKey OptionON = new StringKey("val", "ON");
private readonly StringKey OptionOff = new StringKey("val", "OFF");
private readonly StringKey PLAY_AUDIO_IN_BACKGROUND = new StringKey("val", "PLAY_AUDIO_IN_BACKGROUND");

Game game = Game.Get();

Expand Down Expand Up @@ -223,7 +224,7 @@ private void CreateEditorTransparencyElements()

// Select language text
UIElement ui = new UIElement(Game.DIALOG);
ui.SetLocation(UIScaler.GetHCenter() - 8, 5, 16, 2);
ui.SetLocation(UIScaler.GetHCenter() - 10, 5, 16, 2);
ui.SetText(SET_EDITOR_ALPHA);
ui.SetTextAlignment(TextAnchor.MiddleCenter);
ui.SetFont(game.gameType.GetHeaderFont());
Expand All @@ -232,7 +233,7 @@ private void CreateEditorTransparencyElements()
Texture2D SampleTex = ContentData.FileToTexture(game.cd.Get<ImageData>(IMG_LOW_EDITOR_TRANSPARENCY).image);
Sprite SampleSprite = Sprite.Create(SampleTex, new Rect(0, 0, SampleTex.width, SampleTex.height), Vector2.zero, 1);
ui = new UIElement(Game.DIALOG);
ui.SetLocation(UIScaler.GetHCenter() - 3, 8, 6, 6);
ui.SetLocation(UIScaler.GetHCenter() - 5, 8, 6, 6);
ui.SetButton(delegate { UpdateEditorTransparency(0.2f); });
ui.SetImage(SampleSprite);
if (game.editorTransparency == 0.2f)
Expand All @@ -241,7 +242,7 @@ private void CreateEditorTransparencyElements()
SampleTex = ContentData.FileToTexture(game.cd.Get<ImageData>(IMG_MEDIUM_EDITOR_TRANSPARENCY).image);
SampleSprite = Sprite.Create(SampleTex, new Rect(0, 0, SampleTex.width, SampleTex.height), Vector2.zero, 1);
ui = new UIElement(Game.DIALOG);
ui.SetLocation(UIScaler.GetHCenter() - 3, 15, 6, 6);
ui.SetLocation(UIScaler.GetHCenter() - 5, 15, 6, 6);
ui.SetButton(delegate { UpdateEditorTransparency(0.3f); });
ui.SetImage(SampleSprite);
if (game.editorTransparency == 0.3f)
Expand All @@ -250,7 +251,7 @@ private void CreateEditorTransparencyElements()
SampleTex = ContentData.FileToTexture(game.cd.Get<ImageData>(IMG_HIGH_EDITOR_TRANSPARENCY).image);
SampleSprite = Sprite.Create(SampleTex, new Rect(0, 0, SampleTex.width, SampleTex.height), Vector2.zero, 1);
ui = new UIElement(Game.DIALOG);
ui.SetLocation(UIScaler.GetHCenter() - 3, 22, 6, 6);
ui.SetLocation(UIScaler.GetHCenter() - 5, 22, 6, 6);
ui.SetButton(delegate { UpdateEditorTransparency(0.4f); });
ui.SetImage(SampleSprite);
if (game.editorTransparency == 0.4f)
Expand All @@ -261,7 +262,7 @@ private void CreateEditorTransparencyElements()
private void CreateAudioElements()
{
UIElement ui = new UIElement();
ui.SetLocation((0.75f * UIScaler.GetWidthUnits()) - 4, 5, 10, 2);
ui.SetLocation((0.75f * UIScaler.GetWidthUnits()) - 4, 4, 10, 2);
ui.SetText(MUSIC);
ui.SetFont(game.gameType.GetHeaderFont());
ui.SetFontSize(UIScaler.GetMediumFont());
Expand All @@ -272,7 +273,7 @@ private void CreateAudioElements()
if (vSet.Length == 0) mVolume = 1;

ui = new UIElement();
ui.SetLocation((0.75f * UIScaler.GetWidthUnits()) - 6, 8, 14, 2);
ui.SetLocation((0.75f * UIScaler.GetWidthUnits()) - 6, 6, 14, 2);
ui.SetBGColor(Color.clear);
new UIElementBorder(ui);

Expand All @@ -281,7 +282,7 @@ private void CreateAudioElements()
musicSlideObj.transform.SetParent(game.uICanvas.transform);
musicSlide = musicSlideObj.AddComponent<Slider>();
RectTransform musicSlideRect = musicSlideObj.GetComponent<RectTransform>();
musicSlideRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 8 * UIScaler.GetPixelsPerUnit(), 2 * UIScaler.GetPixelsPerUnit());
musicSlideRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 6 * UIScaler.GetPixelsPerUnit(), 2 * UIScaler.GetPixelsPerUnit());
musicSlideRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, ((0.75f * UIScaler.GetWidthUnits()) - 6) * UIScaler.GetPixelsPerUnit(), 14 * UIScaler.GetPixelsPerUnit());
musicSlide.onValueChanged.AddListener(delegate { UpdateMusic(); });

Expand All @@ -300,7 +301,7 @@ private void CreateAudioElements()
musicSlideObjRev.transform.SetParent(game.uICanvas.transform);
musicSlideRev = musicSlideObjRev.AddComponent<Slider>();
RectTransform musicSlideRectRev = musicSlideObjRev.GetComponent<RectTransform>();
musicSlideRectRev.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 8 * UIScaler.GetPixelsPerUnit(), 2 * UIScaler.GetPixelsPerUnit());
musicSlideRectRev.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 6 * UIScaler.GetPixelsPerUnit(), 2 * UIScaler.GetPixelsPerUnit());
musicSlideRectRev.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, ((0.75f * UIScaler.GetWidthUnits()) - 6) * UIScaler.GetPixelsPerUnit(), 14 * UIScaler.GetPixelsPerUnit());
musicSlideRev.onValueChanged.AddListener(delegate { UpdateMusicRev(); });
musicSlideRev.direction = Slider.Direction.RightToLeft;
Expand All @@ -319,7 +320,7 @@ private void CreateAudioElements()
musicSlideRev.value = 1 - mVolume;

ui = new UIElement();
ui.SetLocation((0.75f * UIScaler.GetWidthUnits()) - 4, 11, 10, 2);
ui.SetLocation((0.75f * UIScaler.GetWidthUnits()) - 4, 8.5f, 10, 2);
ui.SetText(EFFECTS);
ui.SetFont(game.gameType.GetHeaderFont());
ui.SetFontSize(UIScaler.GetMediumFont());
Expand All @@ -330,7 +331,7 @@ private void CreateAudioElements()
if (vSet.Length == 0) eVolume = 1;

ui = new UIElement();
ui.SetLocation((0.75f * UIScaler.GetWidthUnits()) - 6, 14, 14, 2);
ui.SetLocation((0.75f * UIScaler.GetWidthUnits()) - 6, 10.5f, 14, 2);
ui.SetBGColor(Color.clear);
new UIElementBorder(ui);

Expand All @@ -339,7 +340,7 @@ private void CreateAudioElements()
effectSlideObj.transform.SetParent(game.uICanvas.transform);
effectSlide = effectSlideObj.AddComponent<Slider>();
RectTransform effectSlideRect = effectSlideObj.GetComponent<RectTransform>();
effectSlideRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 14 * UIScaler.GetPixelsPerUnit(), 2 * UIScaler.GetPixelsPerUnit());
effectSlideRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 10.5f * UIScaler.GetPixelsPerUnit(), 2 * UIScaler.GetPixelsPerUnit());
effectSlideRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, ((0.75f * UIScaler.GetWidthUnits()) - 6) * UIScaler.GetPixelsPerUnit(), 14 * UIScaler.GetPixelsPerUnit());
effectSlide.onValueChanged.AddListener(delegate { UpdateEffects(); });
EventTrigger.Entry entry = new EventTrigger.Entry();
Expand All @@ -362,7 +363,7 @@ private void CreateAudioElements()
effectSlideObjRev.transform.SetParent(game.uICanvas.transform);
effectSlideRev = effectSlideObjRev.AddComponent<Slider>();
RectTransform effectSlideRectRev = effectSlideObjRev.GetComponent<RectTransform>();
effectSlideRectRev.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 14 * UIScaler.GetPixelsPerUnit(), 2 * UIScaler.GetPixelsPerUnit());
effectSlideRectRev.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 10.5f * UIScaler.GetPixelsPerUnit(), 2 * UIScaler.GetPixelsPerUnit());
effectSlideRectRev.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, ((0.75f * UIScaler.GetWidthUnits()) - 6) * UIScaler.GetPixelsPerUnit(), 14 * UIScaler.GetPixelsPerUnit());
effectSlideRev.onValueChanged.AddListener(delegate { UpdateEffectsRev(); });
effectSlideRev.direction = Slider.Direction.RightToLeft;
Expand All @@ -379,6 +380,33 @@ private void CreateAudioElements()

effectSlide.value = eVolume;
effectSlideRev.value = 1 - eVolume;

// Background Audio Toggle
// Only render on Windows, Mac or Linux (player or editor)
var p = Application.platform;
bool isSupportedPlatform =
p == RuntimePlatform.WindowsPlayer || p == RuntimePlatform.OSXPlayer || p == RuntimePlatform.LinuxPlayer
|| p == RuntimePlatform.WindowsEditor || p == RuntimePlatform.OSXEditor || p == RuntimePlatform.LinuxEditor;

if (isSupportedPlatform)
{
// Check config
string configBgAudio = game.config.data.Get("UserConfig", "playAudioInBackground");
bool isBgAudio = configBgAudio == "1";

ui = new UIElement();
ui.SetLocation((0.75f * UIScaler.GetWidthUnits()) - 6, 13.5f, 14, 2);
ui.SetText(PLAY_AUDIO_IN_BACKGROUND);
ui.SetButton(delegate
{
bool newState = !isBgAudio;
Application.runInBackground = newState;
game.config.data.Add("UserConfig", "playAudioInBackground", newState ? "1" : "0");
game.config.Save();
new OptionsScreen();
});
new UIElementBorder(ui, isBgAudio ? Color.white : Color.grey);
}
}


Expand Down
1 change: 1 addition & 0 deletions unity/Assets/StreamingAssets/text/Localization.Chinese.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ spellattack,特殊攻擊


//Audio
PLAY_AUDIO_IN_BACKGROUND,后台播放音频
menu,目錄
music,音樂
quest,劇本
Expand Down
1 change: 1 addition & 0 deletions unity/Assets/StreamingAssets/text/Localization.Czech.txt
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ spelldefence,Obranné kouzlo
spellattack,Útočné kouzlo

//Audio
PLAY_AUDIO_IN_BACKGROUND,Přehrávat zvuk na pozadí
menu,Menu
music,Hudba
quest,Úkol
Expand Down
1 change: 1 addition & 0 deletions unity/Assets/StreamingAssets/text/Localization.English.txt
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ spelldefence,Defence spell
spellattack,Attack spell

//Audio
PLAY_AUDIO_IN_BACKGROUND,Play Audio in Background
menu,Menu
music,Music
quest,Quest
Expand Down
1 change: 1 addition & 0 deletions unity/Assets/StreamingAssets/text/Localization.French.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ evidence,Preuve
ally,Allié

//Audio
PLAY_AUDIO_IN_BACKGROUND,Lire l'audio en arrière-plan
menu,Menu
music,Musique
newround,Nouveau tour
Expand Down
1 change: 1 addition & 0 deletions unity/Assets/StreamingAssets/text/Localization.German.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ spelldefence,Verteid.-Zauber
spellattack,Angriff-Zauber

//Audio
PLAY_AUDIO_IN_BACKGROUND,Audio im Hintergrund abspielen
menu,Menü
music,Musik
quest,Szenario
Expand Down
1 change: 1 addition & 0 deletions unity/Assets/StreamingAssets/text/Localization.Italian.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ evidence,Prova
ally,Alleato

//Audio
PLAY_AUDIO_IN_BACKGROUND,Riproduci audio in background
menu,Menu
music,Musica
quest,Scenario
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ spelldefence,特殊防御
spellattack,特殊攻撃

//Audio
PLAY_AUDIO_IN_BACKGROUND,バックグラウンドでオーディオを再生
menu,メニュー
music,音楽
quest,クエスト
Expand Down
1 change: 1 addition & 0 deletions unity/Assets/StreamingAssets/text/Localization.Korean.txt
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ spelldefence,방어 마법
spellattack,공격 마법

//Audio
PLAY_AUDIO_IN_BACKGROUND,백그라운드에서 오디오 재생
menu,메뉴
music,음악
quest,퀘스트
Expand Down
1 change: 1 addition & 0 deletions unity/Assets/StreamingAssets/text/Localization.Polish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ evidence,Dowód
ally,Sprzymieńca

//Audio
PLAY_AUDIO_IN_BACKGROUND,Odtwarzaj dźwięk w tle
menu,Menu
music,Muzyka
quest,Scenariusz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ spelldefence,Feitiço de Defesa
spellattack,Feitiço de Ataque

//Audio
PLAY_AUDIO_IN_BACKGROUND,Reproduzir áudio em segundo plano
menu,Menu
music,Música
quest,Aventura
Expand Down
1 change: 1 addition & 0 deletions unity/Assets/StreamingAssets/text/Localization.Russian.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ spelldefence,Защитное заклинаниеэ
spellattack,Атакующее заклинание

//Audio
PLAY_AUDIO_IN_BACKGROUND,Воспроизводить звук в фоне
menu,Меню
music,Музыка
quest,Задание
Expand Down
1 change: 1 addition & 0 deletions unity/Assets/StreamingAssets/text/Localization.Spanish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ evidence,Pista
ally,Aliado

//Audio
PLAY_AUDIO_IN_BACKGROUND,Reproducir audio en segundo plano
menu,Menú
music,Música
quest,Escenario
Expand Down
Loading