Skip to content

Commit

Permalink
Localized strings for main menu; #377
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Jan 13, 2024
1 parent 6f99a98 commit 677909b
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 36 deletions.
6 changes: 3 additions & 3 deletions Assets/Files/WorldFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ public static bool ValidateName(string name, out string errorMessage)
return false;
if (name.IndexOfAny(Path.GetInvalidFileNameChars()) != -1)
{
errorMessage = "That name contains a special character which is not allowed.";
errorMessage = GUIPanel.StringSet.ErrorSpecialCharacter;
return false;
}

if (name.StartsWith("."))
{
errorMessage = "Name can't start with a period.";
errorMessage = GUIPanel.StringSet.ErrorPeriodName;
return false;
}

string path = WorldFiles.GetNewWorldPath(name);
if (File.Exists(path))
{
errorMessage = "A world with that name already exists.";
errorMessage = GUIPanel.StringSet.ErrorWorldAlreadyExists;
return false;
}
return true; // you are valid <3
Expand Down
40 changes: 22 additions & 18 deletions Assets/Menu/MenuGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ void Start()
UpdateWorldList();
startOptions = new GUIContent[]
{
new GUIContent("Tutorial", IconSet.helpLarge),
new GUIContent("New World", IconSet.newWorldLarge)
new GUIContent(StringSet.StartTutorial, IconSet.helpLarge),
new GUIContent(StringSet.CreateNewWorld, IconSet.newWorldLarge)
};
}

Expand All @@ -47,13 +47,13 @@ public override void WindowGUI()

// copied from TemplatePickerGUI
GUILayout.BeginVertical(GUI.skin.box, GUILayout.Width(900), GUILayout.Height(480));
GUILayout.Label("Welcome to N-Space\nFollowing the tutorial is recommended!", GUIUtils.LABEL_HORIZ_CENTERED.Value);
GUILayout.Label(StringSet.WelcomeMessage, GUIUtils.LABEL_HORIZ_CENTERED.Value);
int selection = GUILayout.SelectionGrid(-1, startOptions, 2,
TemplatePickerGUI.buttonStyle.Value, GUILayout.ExpandHeight(true));
if (selection == 0)
{
TutorialGUI.StartTutorial(Tutorials.INTRO_TUTORIAL, null, null, null);
HelpGUI.OpenDemoWorld("Tutorial - Introduction", "Templates/indoor");
HelpGUI.OpenDemoWorld(StringSet.IntroTutorialWorldName, "Templates/indoor");
}
else if (selection == 1)
{
Expand All @@ -67,9 +67,12 @@ public override void WindowGUI()
}
else
{
if (GUIUtils.HighlightedButton(GUIUtils.MenuContent("New World", IconSet.newItem),
if (GUIUtils.HighlightedButton(
GUIUtils.MenuContent(StringSet.CreateNewWorld, IconSet.newItem),
StyleSet.buttonLarge))
{
AskNewWorldTemplate();
}
scroll = GUILayout.BeginScrollView(scroll);
for (int i = 0; i < worldPaths.Count; i++)
{
Expand Down Expand Up @@ -117,8 +120,8 @@ private void AskNewWorldTemplate()
private void AskNewWorldName(TextAsset template)
{
TextInputDialogGUI inputDialog = gameObject.AddComponent<TextInputDialogGUI>();
inputDialog.prompt = "Enter new world name...";
inputDialog.text = "Untitled " + System.DateTime.Now.ToString("yyyy-MM-dd HHmmss");
inputDialog.prompt = StringSet.WorldNamePrompt;
inputDialog.text = StringSet.UntitledWorldName(System.DateTime.Now);
inputDialog.handler = (string name) => NewWorld(name, template);
}

Expand All @@ -140,7 +143,7 @@ private void NewWorld(string name, TextAsset template)
}
catch (System.Exception ex)
{
DialogGUI.ShowMessageDialog(gameObject, "Error creating world file");
DialogGUI.ShowMessageDialog(gameObject, StringSet.ErrorCreatingWorld);
Debug.LogError(ex);
return;
}
Expand All @@ -161,33 +164,34 @@ private void CreateWorldOverflowMenu(string path)
selectedWorldPath = path;
worldOverflowMenu.items = new OverflowMenuGUI.MenuItem[]
{
new OverflowMenuGUI.MenuItem("Play", IconSet.play, () => {
new OverflowMenuGUI.MenuItem(StringSet.PlayWorld, IconSet.play, () => {
MenuGUI.OpenWorld(path, Scenes.GAME);
}),
new OverflowMenuGUI.MenuItem("Rename", IconSet.rename, () => {
new OverflowMenuGUI.MenuItem(StringSet.RenameWorld, IconSet.rename, () => {
TextInputDialogGUI inputDialog = gameObject.AddComponent<TextInputDialogGUI>();
inputDialog.prompt = "Enter new name for " + name;
inputDialog.prompt = StringSet.WorldRenamePrompt(name);
inputDialog.text = name;
inputDialog.handler = RenameWorld;
}),
new OverflowMenuGUI.MenuItem("Copy", IconSet.copy, () => {
new OverflowMenuGUI.MenuItem(StringSet.CopyWorld, IconSet.copy, () => {
TextInputDialogGUI inputDialog = gameObject.AddComponent<TextInputDialogGUI>();
inputDialog.prompt = "Enter new world name...";
inputDialog.prompt = StringSet.WorldNamePrompt;
inputDialog.handler = CopyWorld;
}),
new OverflowMenuGUI.MenuItem("Delete", IconSet.delete, () => {
new OverflowMenuGUI.MenuItem(StringSet.DeleteWorld, IconSet.delete, () => {
DialogGUI dialog = gameObject.AddComponent<DialogGUI>();
dialog.message = "Are you sure you want to delete " + name + "?";
dialog.yesButtonText = "Yes";
dialog.noButtonText = "No";
dialog.message = StringSet.WorldDeleteConfirm(name);
dialog.yesButtonText = StringSet.Yes;
dialog.noButtonText = StringSet.No;
dialog.yesButtonHandler = () =>
{
File.Delete(path);
UpdateWorldList();
};
}),
#if (UNITY_ANDROID || UNITY_IOS)
new OverflowMenuGUI.MenuItem("Share", IconSet.share, () => ShareMap.Share(path))
new OverflowMenuGUI.MenuItem(StringSet.ShareWorld, IconSet.share,
() => ShareMap.Share(path))
#endif
};
}
Expand Down
15 changes: 8 additions & 7 deletions Assets/Menu/MenuOverflowGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,35 @@ public override void WindowGUI()
var overflow = gameObject.AddComponent<OverflowMenuGUI>();
overflow.items = new OverflowMenuGUI.MenuItem[]
{
new OverflowMenuGUI.MenuItem("Help", IconSet.help, () =>
new OverflowMenuGUI.MenuItem(StringSet.OpenHelp, IconSet.help, () =>
{
gameObject.AddComponent<HelpGUI>();
}),
new OverflowMenuGUI.MenuItem("About", IconSet.about, () =>
new OverflowMenuGUI.MenuItem(StringSet.OpenAbout, IconSet.about, () =>
{
string text = System.String.Format("Version {0}\nMade with Unity {1}\n\n{2}"
// TODO: localize!
string text = string.Format("Version {0}\nMade with Unity {1}\n\n{2}"
+ "\n\n----------\n\nSystem Info:\nResolution: {3}x{4}\nDPI: {5}"
+ "\nAudio: {6}Hz {7}",
Application.version, Application.unityVersion, creditsText.text,
Screen.width, Screen.height, Screen.dpi,
AudioSettings.outputSampleRate, AudioSettings.speakerMode);
LargeMessageGUI.ShowLargeMessageDialog(gameObject, text);
}),
new OverflowMenuGUI.MenuItem("Website", IconSet.website, () =>
new OverflowMenuGUI.MenuItem(StringSet.OpenWebsite, IconSet.website, () =>
{
Application.OpenURL("https://chroma.zone/voxel-editor/");
}),
new OverflowMenuGUI.MenuItem("Subreddit", IconSet.reddit, () =>
new OverflowMenuGUI.MenuItem(StringSet.OpenSubreddit, IconSet.reddit, () =>
{
Application.OpenURL("https://www.reddit.com/r/nspace/");
}),
new OverflowMenuGUI.MenuItem("Videos", IconSet.youTube, () =>
new OverflowMenuGUI.MenuItem(StringSet.OpenVideos, IconSet.youTube, () =>
{
Application.OpenURL("https://www.youtube.com/playlist?list=PLMiQPjIk5IrpgNcQY5EUYaGFDuAf7PLY2");
}),
#if !UNITY_IOS
new OverflowMenuGUI.MenuItem("Donate", IconSet.donate, () =>
new OverflowMenuGUI.MenuItem(StringSet.Donate, IconSet.donate, () =>
{
Application.OpenURL("https://chroma.zone/donate");
}),
Expand Down
6 changes: 3 additions & 3 deletions Assets/VoxelEditor/GUI/DialogGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static DialogGUI ShowMessageDialog(GameObject gameObject, string message)
{
DialogGUI dialog = gameObject.AddComponent<DialogGUI>();
dialog.message = message;
dialog.yesButtonText = "OK";
dialog.yesButtonText = StringSet.Ok;
return dialog;
}

Expand Down Expand Up @@ -136,7 +136,7 @@ public override void WindowGUI()
{
text = GUILayout.TextField(text);
GUILayout.FlexibleSpace();
if (GUILayout.Button("Done"))
if (GUILayout.Button(StringSet.Done))
{
handler(text);
Destroy(this);
Expand Down Expand Up @@ -174,7 +174,7 @@ public override void WindowGUI()
GUILayout.Label(message, GUIUtils.LABEL_WORD_WRAPPED.Value);
GUILayout.FlexibleSpace();
GUILayout.EndScrollView();
if (GUILayout.Button("OK"))
if (GUILayout.Button(StringSet.Ok))
Destroy(this);
}
}
2 changes: 1 addition & 1 deletion Assets/VoxelEditor/GUI/GUIPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void _WindowGUI(int id)
{
GUILayout.BeginHorizontal();
GUILayout.Label(title, GUIUtils.LABEL_HORIZ_CENTERED.Value);
if (showCloseButton && GUILayout.Button("Done", GUILayout.ExpandWidth(false)))
if (showCloseButton && GUILayout.Button(StringSet.Done, GUILayout.ExpandWidth(false)))
Destroy(this);
GUILayout.EndHorizontal();
}
Expand Down
6 changes: 3 additions & 3 deletions Assets/VoxelEditor/GUI/TemplatePickerGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class TemplatePickerGUI : GUIPanel

void Start()
{
title = "New World";
title = StringSet.CreateNewWorld;
options = new GUIContent[]
{
new GUIContent("Indoor", IconSet.indoorLarge),
new GUIContent("Floating", IconSet.floatingLarge)
new GUIContent(StringSet.IndoorWorld, IconSet.indoorLarge),
new GUIContent(StringSet.FloatingWorld, IconSet.floatingLarge)
};
}

Expand Down
64 changes: 63 additions & 1 deletion Assets/VoxelEditor/GUI/localization/GUIStringSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,71 @@
// Other languages are implemented as subclasses that override these methods.
public class GUIStringSet
{
public virtual string Yes =>
"Yes";
public virtual string No =>
"No";
public virtual string Ok =>
"OK";
public virtual string Done =>
"Done";

// Main menu
public virtual string WelcomeMessage =>
"Welcome to N-Space\nFollowing the tutorial is recommended!";
public virtual string StartTutorial =>
"Tutorial";
public virtual string CreateNewWorld =>
"New World";
public virtual string IndoorWorld =>
"Indoor";
public virtual string FloatingWorld =>
"Floating";
public virtual string PlayWorld =>
"Play";
public virtual string RenameWorld =>
"Rename";
public virtual string CopyWorld =>
"Copy";
public virtual string DeleteWorld =>
"Delete";
public virtual string ShareWorld =>
"Share";
public virtual string WorldNamePrompt =>
"Enter new world name...";
public virtual string WorldRenamePrompt(string oldName) =>
$"Enter new name for {oldName}";
public virtual string WorldDeleteConfirm(string name) =>
$"Are you sure you want to delete {name}?";
public virtual string ErrorCreatingWorld =>
"Error creating world file";
public virtual string ErrorSpecialCharacter =>
"That name contains a special character which is not allowed.";
public virtual string ErrorPeriodName =>
"Name can't start with a period.";
public virtual string ErrorWorldAlreadyExists =>
"A world with that name already exists.";
public virtual string UntitledWorldName(System.DateTime date) =>
$"Untitled {date:yyyy-MM-dd HHmmss}";
public virtual string IntroTutorialWorldName =>
"Tutorial - Introduction";

// Main menu overflow
public virtual string OpenHelp =>
"Help";
public virtual string OpenAbout =>
"About";
public virtual string OpenWebsite =>
"Website";
public virtual string OpenSubreddit =>
"Subreddit";
public virtual string OpenVideos =>
"Videos";
public virtual string Donate =>
"Donate";

// Tutorial messages...
// Tutorials use <i>italics</i> to mark commands for the user.

public virtual string TutorialWelcome =>
"Welcome! This is a brief tutorial that will guide you through the app. You can access this tutorial and others at any time. Press the right arrow to continue.";
public virtual string TutorialRoom =>
Expand Down

0 comments on commit 677909b

Please sign in to comment.