Skip to content

Commit

Permalink
Localized strings for property names #377
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Jan 15, 2024
1 parent fa9648b commit 430e7c9
Show file tree
Hide file tree
Showing 41 changed files with 290 additions and 135 deletions.
5 changes: 5 additions & 0 deletions .vscode/snippets.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
"prefix": "pvs",
"body": "public virtual string ",
},
"Localizer": {
"scope": "csharp",
"prefix": "loc",
"body": "s => s.",
},
}
2 changes: 1 addition & 1 deletion Assets/Base/ActivatedSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public override string ToString()
public override IEnumerable<Property> Properties() =>
Property.JoinProperties(new Property[]
{
new Property("fil", "Filter",
new Property("fil", s => s.PropFilter,
() => filter,
v => filter = (Filter)v,
PropertyGUIs.Filter,
Expand Down
8 changes: 4 additions & 4 deletions Assets/Base/CustomTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ public static CustomTexture FromBaseMaterial(Material baseMat, bool overlay)
public IEnumerable<Property> Properties() =>
new Property[]
{
new Property("bas", "Base",
new Property("bas", s => s.PropBase,
() => baseMat,
v => baseMat = (Material)v,
PropertyGUIs.Material(isOverlay ? "Overlays" : "Materials", isOverlay, customTextureBase: true)),
new Property("tex", "Texture",
new Property("tex", s => s.PropTexture,
() => texture,
v => texture = (Texture2D)v,
PropertyGUIs.Texture),
new Property("dim", "Size",
new Property("dim", s => s.PropSize,
() => scale,
v => scale = ((float, float))v,
PropertyGUIs.FloatDimensions),
new Property("flt", "Filter",
new Property("flt", s => s.PropPixelFilter,
() => filter,
v => filter = (CustomFilter)v,
PropertyGUIs.Enum)
Expand Down
27 changes: 12 additions & 15 deletions Assets/Base/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public struct Property
{
public string id;
public string name;
public Localizer name;
public Func<object> getter;
public Action<object> setter;
public PropertyGUI gui;
Expand All @@ -25,7 +25,7 @@ public object value
}
public bool explicitType; // store object type with property in file

public Property(string id, string name, Func<object> getter, Action<object> setter,
public Property(string id, Localizer name, Func<object> getter, Action<object> setter,
PropertyGUI gui, bool explicitType = false)
{
this.id = id;
Expand All @@ -48,8 +48,7 @@ public static IEnumerable<Property> JoinProperties(
public class PropertiesObjectType
{
public static readonly PropertiesObjectType NONE =
new PropertiesObjectType("None", DefaultDescription, "cancel", null);
public delegate string Localizer(GUIStringSet stringSet);
new PropertiesObjectType("None", GUIStringSet.Empty, "cancel", null);

public string fullName; // not readonly so it can be serialized
[XmlIgnore]
Expand Down Expand Up @@ -79,8 +78,8 @@ public PropertiesObjectType() { }
public PropertiesObjectType(string fullName, Type type)
{
this.fullName = fullName;
description = DefaultDescription;
longDescription = DefaultDescription;
description = GUIStringSet.Empty;
longDescription = GUIStringSet.Empty;
iconName = "";
this.type = type;
constructor = DefaultConstructor;
Expand All @@ -91,7 +90,7 @@ public PropertiesObjectType(string fullName, Localizer description, string iconN
{
this.fullName = fullName;
this.description = description;
longDescription = DefaultDescription;
longDescription = GUIStringSet.Empty;
this.iconName = iconName;
this.type = type;
this.constructor = constructor ?? DefaultConstructor;
Expand All @@ -118,8 +117,6 @@ public PropertiesObjectType(PropertiesObjectType baseType, Func<PropertiesObject
constructor = newConstructor;
}

private static string DefaultDescription(GUIStringSet _) => "";

private PropertiesObject DefaultConstructor()
{
if (type == null)
Expand Down Expand Up @@ -193,7 +190,7 @@ public interface PropertiesObject
public abstract class Entity : PropertiesObject
{
public static PropertiesObjectType objectType = new PropertiesObjectType(
"Anything", s => "", "circle-outline", typeof(Entity));
"Anything", GUIStringSet.Empty, "circle-outline", typeof(Entity));

public EntityComponent component;
public Sensor sensor;
Expand All @@ -217,7 +214,7 @@ public static string TagToString(byte tag)
public virtual IEnumerable<Property> Properties() =>
new Property[]
{
new Property("tag", "Tag",
new Property("tag", s => s.PropTag,
() => tag,
v => tag = (byte)v,
PropertyGUIs.Tag),
Expand Down Expand Up @@ -453,7 +450,7 @@ public BehaviorTargetProperty(EntityReference targetEntity, bool targetEntityIsA
public virtual IEnumerable<Property> Properties() =>
new Property[]
{
new Property("tar", "Target",
new Property("tar", s => s.PropTarget,
() => new BehaviorTargetProperty(targetEntity, targetEntityIsActivator),
v => {
var prop = (BehaviorTargetProperty)v;
Expand Down Expand Up @@ -484,7 +481,7 @@ public virtual IEnumerable<Property> Properties() =>
targetEntityIsActivator = prop.targetEntityIsActivator;
},
PropertyGUIs.BehaviorTarget),
new Property("con", "Condition",
new Property("con", s => s.PropCondition,
() => condition,
v => condition = (Condition)v,
(Property property) => {
Expand Down Expand Up @@ -732,11 +729,11 @@ public abstract class DynamicEntity : Entity
public override IEnumerable<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("xra", "X-Ray?",
new Property("xra", s => s.PropXRay,
() => xRay,
v => {xRay = (bool)v; UpdateEntityEditor();},
PropertyGUIs.Toggle),
new Property("hea", "Health",
new Property("hea", s => s.PropHealth,
() => health,
v => health = (float)v,
PropertyGUIs.Float)
Expand Down
2 changes: 1 addition & 1 deletion Assets/Base/Substance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Substance : DynamicEntity
public override IEnumerable<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("piv", "Pivot",
new Property("piv", s => s.PropPivot,
() => pivot,
v => pivot = (Pivot)v,
PropertyGUIs.PivotProp),
Expand Down
24 changes: 12 additions & 12 deletions Assets/Base/WorldProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,25 @@ private void UpdateEnvironment()
public IEnumerable<Property> Properties() =>
new Property[]
{
new Property("sky", "Sky",
new Property("sky", s => s.PropSky,
() => RenderSettings.skybox,
v => {
SetSky((Material)v);
},
PropertyGUIs.Material("Skies", false)),
new Property("amb", "Ambient light intensity",
new Property("amb", s => s.PropAmbientLightIntensity,
() => RenderSettings.ambientIntensity,
v => RenderSettings.ambientIntensity = (float)v,
PropertyGUIs.Slider(0, 3)),
new Property("sin", "Sun intensity",
new Property("sin", s => s.PropSunIntensity,
() => RenderSettings.sun.intensity,
v => RenderSettings.sun.intensity = (float)v,
PropertyGUIs.Slider(0, 3)),
new Property("sco", "Sun color",
new Property("sco", s => s.PropSunColor,
() => RenderSettings.sun.color,
v => RenderSettings.sun.color = (Color)v,
PropertyGUIs.Color),
new Property("spi", "Sun pitch",
new Property("spi", s => s.PropSunPitch,
() => {
float value = RenderSettings.sun.transform.rotation.eulerAngles.x;
if (value >= 270)
Expand All @@ -87,7 +87,7 @@ public IEnumerable<Property> Properties() =>
UpdateEnvironment();
},
PropertyGUIs.Slider(-90, 90)),
new Property("sya", "Sun yaw",
new Property("sya", s => s.PropSunYaw,
() => RenderSettings.sun.transform.rotation.eulerAngles.y,
v => {
Vector3 eulerAngles = RenderSettings.sun.transform.rotation.eulerAngles;
Expand All @@ -97,26 +97,26 @@ public IEnumerable<Property> Properties() =>
UpdateSky();
},
PropertyGUIs.Slider(0, 360)),
new Property("sha", "Shadows",
new Property("sha", s => s.PropShadows,
() => RenderSettings.sun.shadowStrength,
v => RenderSettings.sun.shadowStrength = (float)v,
PropertyGUIs.Slider(0, 1)),
new Property("ref", "Reflections",
new Property("ref", s => s.PropReflections,
() => GetReflectionProbe().intensity,
v => GetReflectionProbe().intensity = (float)v,
PropertyGUIs.Slider(0, 1)),
new Property("fog", "Fog",
new Property("fog", s => s.PropFog,
() => RenderSettings.fog,
v => RenderSettings.fog = (bool)v,
PropertyGUIs.Toggle),
new Property("fd2", "Fog density",
new Property("fd2", s => s.PropFogDensity,
() => Mathf.Sqrt(RenderSettings.fogDensity),
v => {
float value = (float)v;
RenderSettings.fogDensity = value * value;
},
PropertyGUIs.Slider(0, 1)),
new Property("fco", "Fog color",
new Property("fco", s => s.PropFogColor,
() => RenderSettings.fogColor,
v => RenderSettings.fogColor = (Color) v,
PropertyGUIs.Color)
Expand All @@ -125,7 +125,7 @@ public IEnumerable<Property> Properties() =>
public IEnumerable<Property> DeprecatedProperties() =>
new Property[]
{
new Property("fdn", "Fog density",
new Property("fdn", GUIStringSet.Empty,
() => RenderSettings.fog ? Mathf.Sqrt(RenderSettings.fogDensity) : 0.0f,
v => {
float value = (float)v;
Expand Down
4 changes: 2 additions & 2 deletions Assets/Behaviors/Carryable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class CarryableBehavior : GenericEntityBehavior<CarryableBehavior, Carrya
public override IEnumerable<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("ths", "Throw speed",
new Property("ths", s => s.PropThrowSpeed,
() => throwSpeed,
v => throwSpeed = (float)v,
PropertyGUIs.Float),
new Property("tha", "Throw angle",
new Property("tha", s => s.PropThrowAngle,
() => throwAngle,
v => throwAngle = (float)v,
PropertyGUIs.Float),
Expand Down
2 changes: 1 addition & 1 deletion Assets/Behaviors/CharacterComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CharacterBehavior : BasePhysicsBehavior
public override IEnumerable<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("den", "Density",
new Property("den", s => s.PropDensity,
() => density,
v => density = (float)v,
PropertyGUIs.Float)
Expand Down
10 changes: 5 additions & 5 deletions Assets/Behaviors/Force.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ public enum ForceBehaviorMode
public override IEnumerable<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("fmo", "Mode",
new Property("fmo", s => s.PropMode,
() => mode,
v => mode = (ForceBehaviorMode)v,
PropertyGUIs.Enum),
new Property("ima", "Ignore mass?",
new Property("ima", s => s.PropIgnoreMass,
() => ignoreMass,
v => ignoreMass = (bool)v,
PropertyGUIs.Toggle),
new Property("sto", "Stop object first?",
new Property("sto", s => s.PropStopObjectFirst,
() => stopObjectFirst,
v => stopObjectFirst = (bool)v,
PropertyGUIs.Toggle),
new Property("mag", "Strength",
new Property("mag", s => s.PropStrength,
() => strength,
v => strength = (float)v,
PropertyGUIs.Float),
new Property("dir", "Toward",
new Property("dir", s => s.PropToward,
() => target,
v => target = (Target)v,
PropertyGUIs.Target)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Behaviors/HaloComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class HaloBehavior : GenericEntityBehavior<HaloBehavior, HaloComponent>
public override IEnumerable<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("siz", "Size",
new Property("siz", s => s.PropSize,
() => size,
v => size = (float)v,
PropertyGUIs.Slider(0.5f, 15)),
new Property("col", "Color",
new Property("col", s => s.PropColor,
() => color,
v => color = (Color)v,
PropertyGUIs.Color)
Expand Down
10 changes: 5 additions & 5 deletions Assets/Behaviors/HurtHeal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public class HurtHealBehavior : GenericEntityBehavior<HurtHealBehavior, HurtHeal
public override IEnumerable<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("num", "Amount",
new Property("num", s => s.PropAmount,
() => amount,
v => amount = (float)v,
PropertyGUIs.Float),
new Property("rat", "Rate",
new Property("rat", s => s.PropRate,
() => rate,
v => rate = (float)v,
PropertyGUIs.Time),
new Property("ran", "Keep within",
new Property("ran", s => s.PropKeepWithin,
() => healthRange,
v => healthRange = ((float, float))v,
PropertyGUIs.FloatRange)
Expand All @@ -32,11 +32,11 @@ public override IEnumerable<Property> Properties() =>
public override IEnumerable<Property> DeprecatedProperties() =>
Property.JoinProperties(base.DeprecatedProperties(), new Property[]
{
new Property("min", "Min health",
new Property("min", GUIStringSet.Empty,
() => healthRange.Item1,
v => healthRange.Item1 = (float)v,
PropertyGUIs.Float),
new Property("max", "Max health",
new Property("max", GUIStringSet.Empty,
() => healthRange.Item2,
v => healthRange.Item2 = (float)v,
PropertyGUIs.Float)
Expand Down
6 changes: 3 additions & 3 deletions Assets/Behaviors/Joystick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public enum JoystickAlignment { HORIZONTAL, VERTICAL }
public override IEnumerable<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("vel", "Speed",
new Property("vel", s => s.PropSpeed,
() => speed,
v => speed = (float)v,
PropertyGUIs.Float),
new Property("dir", "Facing",
new Property("dir", s => s.PropFacing,
() => facing,
v => facing = (Target)v,
PropertyGUIs.TargetFacing),
new Property("alg", "Alignment",
new Property("alg", s => s.PropAlignment,
() => alignment,
v => alignment = (JoystickAlignment)v,
PropertyGUIs.Enum),
Expand Down
10 changes: 5 additions & 5 deletions Assets/Behaviors/LightComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ public class LightBehavior : GenericEntityBehavior<LightBehavior, LightComponent
public override IEnumerable<Property> Properties() =>
Property.JoinProperties(base.Properties(), new Property[]
{
new Property("siz", "Size",
new Property("siz", s => s.PropSize,
() => size,
v => size = (float)v,
PropertyGUIs.Slider(1, 30)),
new Property("col", "Color",
new Property("col", s => s.PropColor,
() => color,
v => color = (Color)v,
PropertyGUIs.Color),
new Property("int", "Intensity",
new Property("int", s => s.PropIntensity,
() => intensity,
v => intensity = (float)v,
PropertyGUIs.Slider(0, 5)),
new Property("sha", "Shadows?",
new Property("sha", s => s.PropShadowsEnable,
() => shadows,
v => shadows = (bool)v,
PropertyGUIs.Toggle)
Expand All @@ -37,7 +37,7 @@ public override IEnumerable<Property> Properties() =>
public override IEnumerable<Property> DeprecatedProperties() =>
Property.JoinProperties(base.DeprecatedProperties(), new Property[]
{
new Property("hal", "Halo?",
new Property("hal", GUIStringSet.Empty,
() => halo,
v => halo = (bool)v,
PropertyGUIs.Toggle)
Expand Down
Loading

0 comments on commit 430e7c9

Please sign in to comment.