Skip to content

Commit

Permalink
Language selection menu; #377
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Jan 19, 2024
1 parent 9cc0df8 commit 3ebf630
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Assets/Menu/MenuOverflowGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ public override void WindowGUI()
Application.OpenURL("https://chroma.zone/donate");
}),
#endif
new OverflowMenuGUI.MenuItem(StringSet.Language, IconSet.language, () =>
{
var languageMenu = gameObject.AddComponent<OverflowMenuGUI>();
languageMenu.stealFocus = true;
languageMenu.depth = 1;
languageMenu.items = new OverflowMenuGUI.MenuItem[]
{
new OverflowMenuGUI.MenuItem(StringSet.LanguageAuto, null, () =>
{
GUIManager.SetLanguage(GUIManager.Language.Auto);
}),
new OverflowMenuGUI.MenuItem("English", null, () =>
{
GUIManager.SetLanguage(GUIManager.Language.English);
}),
new OverflowMenuGUI.MenuItem("Português", null, () =>
{
GUIManager.SetLanguage(GUIManager.Language.Portuguese);
}),
};
}, stayOpen: true),
};
}
GUILayout.EndHorizontal();
Expand Down
5 changes: 5 additions & 0 deletions Assets/Menu/menuScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ MonoBehaviour:
random: {fileID: 0}
baseLayer: {fileID: 0}
overlayLayer: {fileID: 0}
plusOne: {fileID: 0}
minusOne: {fileID: 0}
color: {fileID: 0}
camera: {fileID: 0}
language: {fileID: 2800000, guid: 147a008df0bbd8743a1943cdab71897a, type: 3}
indoorLarge: {fileID: 2800000, guid: 8429c955cd8746144b2d97cae562dce3, type: 3}
floatingLarge: {fileID: 2800000, guid: 97faa5cce5f220b4caf45ea271a96c03, type: 3}
newWorldLarge: {fileID: 2800000, guid: a6b7305e08a770c42aa700fbd66af21a, type: 3}
Expand Down
2 changes: 1 addition & 1 deletion Assets/VoxelEditor/GUI/GUIIconSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public struct GUIIconSet
public Texture entityTag, target, rename, copy, delete, share, bevel, no, pause, restart, editor, playAudio;
public Texture reddit, youTube, undo, import, fill, draw, singleObject, objectType, behavior, newTexture;
public Texture worldImport, newItem, website, donate, pan, orbit, sensor, random, baseLayer, overlayLayer;
public Texture plusOne, minusOne, color, camera;
public Texture plusOne, minusOne, color, camera, language;
public Texture indoorLarge, floatingLarge, newWorldLarge, helpLarge, compassLarge;

public Texture[] tagIcons;
Expand Down
31 changes: 31 additions & 0 deletions Assets/VoxelEditor/GUI/GUIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public class GUIManager : MonoBehaviour
{
public enum Language { Auto, English, Portuguese }

// minimum supported targetHeight value
// (so the largest supported interface scale)
private const int MIN_TARGET_HEIGHT = 1080;
Expand All @@ -24,9 +26,38 @@ public class GUIManager : MonoBehaviour
// fix bug that causes fonts to be unloaded when Resources.UnloadUnusedAssets is called
public Font[] alternateFonts;

public static void SetLanguage(Language language)
{
PlayerPrefs.SetInt("language", (int)language);
UpdateLanguage(language);
}

private static void UpdateLanguage(Language language)
{
if (language == Language.Auto)
{
language = Application.systemLanguage switch
{
SystemLanguage.Portuguese => Language.Portuguese,
_ => Language.English
};
}
switch (language)
{
case Language.English:
GUIPanel.StringSet = new GUIStringSet();
break;
case Language.Portuguese:
GUIPanel.StringSet = new PortugueseStrings();
break;
}
}

void Awake()
{
instance = this;

UpdateLanguage((Language)PlayerPrefs.GetInt("language", (int)Language.Auto));
}

void Start()
Expand Down
1 change: 1 addition & 0 deletions Assets/VoxelEditor/GUI/OverflowMenuGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public MenuItem(string text, Texture icon, System.Action action, bool stayOpen =
public MenuItem[] items;
public int depth = 0;
private int selected = -1;
public new bool stealFocus { get => base.stealFocus; set => base.stealFocus = value; } // :(

public static readonly System.Lazy<GUIStyle> buttonStyle = new System.Lazy<GUIStyle>(() =>
{
Expand Down
Binary file added Assets/VoxelEditor/GUI/icons/translate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
121 changes: 121 additions & 0 deletions Assets/VoxelEditor/GUI/icons/translate.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Assets/VoxelEditor/GUI/localization/GUIStringSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public virtual string UntitledWorldName(System.DateTime date) =>
"Videos";
public virtual string Donate =>
"Donate";
public virtual string Language =>
"Language";
public virtual string LanguageAuto =>
"<i>Auto</i>";

// Import
public virtual string ImportWorldNamePrompt =>
Expand Down
4 changes: 4 additions & 0 deletions Assets/VoxelEditor/GUI/localization/PortugueseStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public override string WorldDeleteConfirm(string name) =>
"Vídeos";
public override string Donate =>
"Doar";
public override string Language =>
"Idioma";
public override string LanguageAuto =>
"<i>Automático</i>";

public override string ImportWorldNamePrompt =>
"Digite o nome do mundo importado...";
Expand Down

0 comments on commit 3ebf630

Please sign in to comment.