Skip to content

Commit

Permalink
Localized strings for properties #377
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Jan 14, 2024
1 parent 90aca7d commit c1e24fa
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 35 deletions.
5 changes: 3 additions & 2 deletions Assets/Behaviors/Teleport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public class TeleportBehavior : GenericEntityBehavior<TeleportBehavior, Teleport
property.value = new EntityReference(
EntityReferencePropertyManager.CurrentEntity());
}
PropertyGUIs._EntityReferenceCustom(property, targetEntityIsActivator,
targetEntityIsActivator ? "Activator" : "None");
var none = targetEntityIsActivator ? GUIPanel.StringSet.EntityRefActivator
: GUIPanel.StringSet.EntityRefNone;
PropertyGUIs._EntityReferenceCustom(property, targetEntityIsActivator, none);
})
});
}
Expand Down
5 changes: 3 additions & 2 deletions Assets/Sensors/InputThreshold.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ private void InputsGUI(Property property)
{
Input[] inputs = (Input[])property.value;

GUILayout.Label("Inputs:");
if (GUILayout.Button(new GUIContent(" Add Input", GUIPanel.IconSet.newItem)))
GUILayout.Label(GUIPanel.StringSet.InputsHeader);
if (GUILayout.Button(
GUIUtils.PadContent(GUIPanel.StringSet.AddInput, GUIPanel.IconSet.newItem)))
{
EntityPickerGUI picker = GUIPanel.GuiGameObject.AddComponent<EntityPickerGUI>();
picker.voxelArray = VoxelArrayEditor.instance;
Expand Down
2 changes: 1 addition & 1 deletion Assets/VoxelEditor/GUI/MaterialSelectorGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private void CategorySelected(string category)
if (dirEntry.name.StartsWith("$"))
continue; // special alternate materials for game
if (dirEntry.isDirectory)
categoriesList.Add(dirEntry.name);
categoriesList.Add(dirEntry.name); // TODO: localize!
else
{
if (dirEntry.name.EndsWith(PREVIEW_SUFFIX))
Expand Down
62 changes: 33 additions & 29 deletions Assets/VoxelEditor/GUI/Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

public static class PropertyGUIs
{
private static GUIStringSet StringSet =>
(GUIManager.instance != null) ? GUIManager.instance.stringSet : null;

private static TouchScreenKeyboard numberKeyboard = null;
private static Action<string> keyboardHandler;

Expand Down Expand Up @@ -78,6 +81,7 @@ public static void Enum(Property property)
GUILayout.BeginHorizontal();
foreach (var enumValue in System.Enum.GetValues(e.GetType()))
{
// TODO: localize!
string name = enumValue.ToString();
// sentence case
if (name[0] == '_')
Expand Down Expand Up @@ -175,12 +179,12 @@ public static void FloatPair(Property property, string separator)

public static void FloatRange(Property property)
{
FloatPair(property, "to");
FloatPair(property, StringSet.RangeSeparator);
}

public static void FloatDimensions(Property property)
{
FloatPair(property, "x");
FloatPair(property, StringSet.DimensionSeparator);
}

public static void Vector3(Property property)
Expand Down Expand Up @@ -224,7 +228,7 @@ public static void Tag(Property property)
if (GUILayout.Button(" " + tagString + " ", tagFieldStyle.Value, GUILayout.ExpandWidth(false)))
{
TagPickerGUI picker = GUIPanel.GuiGameObject.AddComponent<TagPickerGUI>();
picker.title = "Change " + property.name;
picker.title = StringSet.ChangeProperty(property.name);
picker.multiSelection = (byte)(1 << (byte)property.value);
picker.handler = (byte tag) =>
{
Expand All @@ -237,16 +241,17 @@ public static void Tag(Property property)
public static void BehaviorCondition(Property property)
{
var condition = (EntityBehavior.Condition)property.value;
GUILayout.Label("When sensor is:");
GUILayout.Label(StringSet.BehaviorConditionHeader);
TutorialGUI.TutorialHighlight("behavior condition");
property.value = (EntityBehavior.Condition)GUILayout.SelectionGrid(
(int)condition, new string[] { "On", "Off", "Both" }, 3, GUIPanel.StyleSet.buttonTab);
property.value = (EntityBehavior.Condition)GUILayout.SelectionGrid((int)condition,
new string[] { StringSet.SensorOn, StringSet.SensorOff, StringSet.SensorBoth }, 3,
GUIPanel.StyleSet.buttonTab);
TutorialGUI.ClearHighlight();
}

public static void ActivatorBehaviorCondition(Property property)
{
GUILayout.Label("When sensor is On");
GUILayout.Label(StringSet.WhenSensorIsOn);
property.value = EntityBehavior.Condition.ON;
}

Expand All @@ -257,7 +262,7 @@ public static void BehaviorTarget(Property property)
string text;
if (value.targetEntityIsActivator)
{
text = "Activators";
text = StringSet.EntityActivators;
}
else if (behaviorTarget != null)
{
Expand Down Expand Up @@ -294,7 +299,7 @@ public static void BehaviorTarget(Property property)
entityPicker.allowNone = true;
entityPicker.allowMultiple = false;
entityPicker.allowNull = true;
entityPicker.nullName = "Activators";
entityPicker.nullName = StringSet.EntityActivators;
entityPicker.handler = (ICollection<Entity> entities) =>
{
entityPicker = null;
Expand All @@ -315,12 +320,12 @@ public static void BehaviorTarget(Property property)

public static void EntityReference(Property property)
{
_EntityReferenceCustom(property, false, "None");
_EntityReferenceCustom(property, false, StringSet.EntityRefNone);
}

public static void EntityReferenceWithNull(Property property)
{
_EntityReferenceCustom(property, true, "None");
_EntityReferenceCustom(property, true, StringSet.EntityRefNone);
}

public static void _EntityReferenceCustom(Property property, bool allowNull, string nullName)
Expand Down Expand Up @@ -384,7 +389,7 @@ public static void Filter(Property property)
if (GUILayout.Button(filterString, GUI.skin.textField))
{
FilterGUI filterGUI = GUIPanel.GuiGameObject.AddComponent<FilterGUI>();
filterGUI.title = property.name + " by...";
filterGUI.title = StringSet.FilterByTitle;
filterGUI.voxelArray = VoxelArrayEditor.instance;
filterGUI.current = filter;
filterGUI.handler = (ActivatedSensor.Filter newFilter) =>
Expand Down Expand Up @@ -414,7 +419,7 @@ public static void Filter(Property property)
{
MaterialSelectorGUI materialSelector
= GUIPanel.GuiGameObject.AddComponent<MaterialSelectorGUI>();
materialSelector.title = "Change " + property.name;
materialSelector.title = StringSet.ChangeProperty(property.name);
materialSelector.voxelArray = VoxelArrayEditor.instance;
materialSelector.rootDirectory = materialDirectory;
materialSelector.highlightMaterial = (Material)property.value;
Expand Down Expand Up @@ -543,7 +548,7 @@ public static void TargetFacing(Property property)
string targetString = target.ToString();

if (target.entityRef.entity == null && target.direction == global::Target.NO_DIRECTION)
targetString = "Camera";
targetString = StringSet.Camera;

GUILayout.BeginHorizontal();
AlignedLabel(property);
Expand All @@ -556,7 +561,7 @@ public static void TargetFacing(Property property)
targetGUI.allowObjectTarget = false;
targetGUI.allowRandom = false;
targetGUI.allowVertical = false;
targetGUI.nullTargetName = "Camera";
targetGUI.nullTargetName = StringSet.Camera;
targetGUI.nullTargetIcon = GUIPanel.IconSet.camera;
targetGUI.handler = (Target newTarget) =>
{
Expand All @@ -572,7 +577,7 @@ public static void TargetDirectionFilter(Property property)
string targetString = target.ToString();

if (target.entityRef.entity == null && target.direction == global::Target.NO_DIRECTION)
targetString = "Any";
targetString = StringSet.TargetAny;

GUILayout.BeginHorizontal();
AlignedLabel(property);
Expand All @@ -592,30 +597,29 @@ public static void TargetDirectionFilter(Property property)
GUILayout.EndHorizontal();
}


private static readonly string[] PIVOT_X_NAMES = new string[] { "West ", "", "East " };
private static readonly string[] PIVOT_X_LETTERS = new string[] { "W", "", "E" };
private static readonly string[] PIVOT_Y_NAMES = new string[] { "Bottom ", "", "Top " };
private static readonly string[] PIVOT_Z_NAMES = new string[] { "South ", "", "North " };
private static readonly string[] PIVOT_Z_LETTERS = new string[] { "S", "", "N" };
public static void PivotProp(Property property)
{
var pivot = (Pivot)property.value;
string pivotString;
if (pivot.x == Pivot.Pos.Center && pivot.y == Pivot.Pos.Center && pivot.z == Pivot.Pos.Center)
pivotString = "Center";
pivotString = StringSet.Center;
else
{
pivotString = PIVOT_Y_NAMES[(int)pivot.y];
pivotString = (int)pivot.y switch
{0 => StringSet.Bottom + " ", 2 => StringSet.Top + " ", _ => ""};
if (pivot.x == Pivot.Pos.Center || pivot.z == Pivot.Pos.Center)
{
pivotString += PIVOT_Z_NAMES[(int)pivot.z];
pivotString += PIVOT_X_NAMES[(int)pivot.x];
pivotString += (int)pivot.z switch
{0 => StringSet.South, 2 => StringSet.North, _ => ""};
pivotString += (int)pivot.x switch
{0 => StringSet.West, 2 => StringSet.East, _ => ""};
}
else
{
pivotString += PIVOT_Z_LETTERS[(int)pivot.z];
pivotString += PIVOT_X_LETTERS[(int)pivot.x];
pivotString += (int)pivot.z switch
{0 => StringSet.SouthLetter, 2 => StringSet.NorthLetter, _ => ""};
pivotString += (int)pivot.x switch
{0 => StringSet.WestLetter, 2 => StringSet.EastLetter, _ => ""};
}
}

Expand All @@ -641,7 +645,7 @@ public static void PivotProp(Property property)
if (GUILayout.Button(embeddedData.name, GUI.skin.textField))
{
var import = GUIPanel.GuiGameObject.AddComponent<DataImportGUI>();
import.title = "Select " + property.name;
import.title = StringSet.SelectProperty(property.name);
import.type = type;
import.playerFactory = playerFactory;
import.dataAction = (data) =>
Expand Down
36 changes: 35 additions & 1 deletion Assets/VoxelEditor/GUI/localization/GUIStringSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ public class GUIStringSet
"Top";
public virtual string Bottom =>
"Bottom";
public virtual string NorthLetter =>
"N";
public virtual string SouthLetter =>
"S";
public virtual string EastLetter =>
"E";
public virtual string WestLetter =>
"W";

// Material panel
public virtual string MaterialCustomCategory =>
Expand Down Expand Up @@ -232,7 +240,7 @@ public class GUIStringSet
"None";
public virtual string TargetEntity(string name) =>
$"Target: {name}";
public virtual string EntityActivators =>
public virtual string EntityActivators => // plural!
"Activators";

// Property GUIs
Expand All @@ -242,6 +250,32 @@ public class GUIStringSet
"Self";
public virtual string EntityRefTarget =>
"Target";
public virtual string EntityRefActivator => // singular!
"Activator";
public virtual string RangeSeparator =>
"to";
public virtual string ChangeProperty(string name) =>
$"Change {name}";
public virtual string SelectProperty(string name) =>
$"Select {name}";
public virtual string BehaviorConditionHeader =>
"When sensor is:";
public virtual string SensorOn =>
"On";
public virtual string SensorOff =>
"Off";
public virtual string SensorBoth =>
"Both";
public virtual string WhenSensorIsOn =>
"When sensor is On";
public virtual string FilterByTitle =>
"Filter by...";
public virtual string Camera =>
"Camera";
public virtual string InputsHeader =>
"Inputs:";
public virtual string AddInput =>
"Add Input";

// Help menu
public virtual string HelpMenuTitle =>
Expand Down

0 comments on commit c1e24fa

Please sign in to comment.