Skip to content

Commit 442ea6d

Browse files
committed
Localized strings for object names; #377
1 parent 15e7c59 commit 442ea6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+212
-69
lines changed

Assets/Base/ActivatedSensor.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public abstract class ActivatedSensor : Sensor
77
public interface Filter
88
{
99
bool EntityMatches(EntityComponent entityComponent);
10+
string ToString(GUIStringSet s);
1011
}
1112

1213
public class EntityFilter : Filter
@@ -27,12 +28,12 @@ public bool EntityMatches(EntityComponent entityComponent)
2728
return entityComponent.entity == entityRef.entity; // also matches clones
2829
}
2930

30-
public override string ToString()
31+
public string ToString(GUIStringSet s)
3132
{
3233
Entity e = entityRef.entity;
3334
if (e == null)
34-
return GUIPanel.StringSet.EntityRefNone;
35-
return e.ToString();
35+
return s.EntityRefNone;
36+
return e.ToString(s);
3637
}
3738
}
3839

@@ -105,7 +106,7 @@ public bool EntityMatches(EntityComponent entityComponent)
105106
return false;
106107
}
107108

108-
public override string ToString() => entityType.fullName;
109+
public string ToString(GUIStringSet s) => entityType.displayName(s);
109110
}
110111

111112
// for maps before version 10
@@ -127,8 +128,7 @@ public bool EntityMatches(EntityComponent entityComponent)
127128
return entityComponent.entity.tag == tag;
128129
}
129130

130-
public override string ToString() =>
131-
GUIPanel.StringSet.FilterWithTag(Entity.TagToString(tag));
131+
public string ToString(GUIStringSet s) => s.FilterWithTag(Entity.TagToString(tag));
132132
}
133133

134134
public class MultipleTagFilter : Filter
@@ -149,12 +149,12 @@ public bool EntityMatches(EntityComponent entityComponent)
149149
return ((1 << entityComponent.entity.tag) & tagBits) != 0;
150150
}
151151

152-
public override string ToString()
152+
public string ToString(GUIStringSet s)
153153
{
154154
if (tagBits == 0)
155-
return GUIPanel.StringSet.FilterNothing;
155+
return s.FilterNothing;
156156
else if (tagBits == 255)
157-
return GUIPanel.StringSet.FilterAnything;
157+
return s.AnythingName;
158158
string str = "";
159159
int count = 0;
160160
for (byte i = 0; i < 8; i++)
@@ -166,9 +166,9 @@ public override string ToString()
166166
}
167167
}
168168
if (count == 1)
169-
return GUIPanel.StringSet.FilterWithTag(str);
169+
return s.FilterWithTag(str);
170170
else
171-
return GUIPanel.StringSet.FilterMultipleTags(str);
171+
return s.FilterMultipleTags(str);
172172
}
173173
}
174174

Assets/Base/CustomTexture.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class CustomTexture : PropertiesObject
77
public static PropertiesObjectType objectType = new PropertiesObjectType(
88
"Custom Texture", typeof(CustomTexture))
99
{
10+
displayName = s => s.CustomTextureName,
1011
description = s => s.CustomTextureDesc,
1112
iconName = "image",
1213
};

Assets/Base/Entity.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ public static IEnumerable<Property> JoinProperties(
4848
public class PropertiesObjectType
4949
{
5050
public static readonly PropertiesObjectType NONE = new PropertiesObjectType("None", null)
51-
{ iconName = "cancel" };
51+
{
52+
displayName = s => s.NoneName,
53+
iconName = "cancel",
54+
};
5255

5356
// This name is used for identifying types and for error messages if a type is not recognized.
5457
// It is always in English (not localized) and can never change.
@@ -59,6 +62,8 @@ public class PropertiesObjectType
5962
[XmlIgnore]
6063
public Func<PropertiesObject> constructor;
6164

65+
[XmlIgnore]
66+
public Localizer displayName;
6267
[XmlIgnore]
6368
public Localizer description = GUIStringSet.Empty;
6469
[XmlIgnore]
@@ -81,25 +86,30 @@ public Texture icon
8186
public PropertiesObjectType()
8287
{
8388
constructor = DefaultConstructor;
89+
displayName = DefaultDisplayName;
8490
}
8591

8692
public PropertiesObjectType(string fullName, Type type)
8793
{
8894
this.fullName = fullName;
8995
this.type = type;
9096
constructor = DefaultConstructor;
97+
displayName = DefaultDisplayName;
9198
}
9299

93100
public PropertiesObjectType(PropertiesObjectType baseType, Func<PropertiesObject> newConstructor)
94101
{
95102
fullName = baseType.fullName;
103+
displayName = baseType.displayName;
96104
description = baseType.description;
97105
longDescription = baseType.longDescription;
98106
iconName = baseType.iconName;
99107
type = baseType.type;
100108
constructor = newConstructor;
101109
}
102110

111+
private string DefaultDisplayName(GUIStringSet s) => fullName;
112+
103113
private PropertiesObject DefaultConstructor()
104114
{
105115
if (type == null)
@@ -174,7 +184,10 @@ public abstract class Entity : PropertiesObject
174184
{
175185
public static PropertiesObjectType objectType = new PropertiesObjectType(
176186
"Anything", typeof(Entity))
177-
{ iconName = "circle-outline" };
187+
{
188+
displayName = s => s.AnythingName,
189+
iconName = "circle-outline",
190+
};
178191

179192
public EntityComponent component;
180193
public Sensor sensor;
@@ -192,6 +205,8 @@ public static string TagToString(byte tag)
192205
}
193206

194207
public override string ToString() => TagToString(tag) + " " + ObjectType.fullName;
208+
public string ToString(GUIStringSet s) =>
209+
TagToString(tag) + " " + ObjectType.displayName(s);
195210

196211
public virtual PropertiesObjectType ObjectType => objectType;
197212

Assets/Base/EntityReference.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,39 +192,39 @@ public bool MatchesDirection(Transform transform, Vector3 direction)
192192
return Vector3.Angle(targetDirection, direction) < 45;
193193
}
194194

195-
public override string ToString()
195+
public string ToString(GUIStringSet s)
196196
{
197197
if (entityRef.entity != null)
198-
return entityRef.entity.ToString();
198+
return entityRef.entity.ToString(s);
199199
else
200200
{
201-
string dirStr = GUIPanel.StringSet.EntityRefNone;
201+
string dirStr = s.EntityRefNone;
202202
switch (direction & ~LOCAL_BIT)
203203
{
204204
case WEST:
205-
dirStr = GUIPanel.StringSet.West;
205+
dirStr = s.West;
206206
break;
207207
case EAST:
208-
dirStr = GUIPanel.StringSet.East;
208+
dirStr = s.East;
209209
break;
210210
case DOWN:
211-
dirStr = GUIPanel.StringSet.Down;
211+
dirStr = s.Down;
212212
break;
213213
case UP:
214-
dirStr = GUIPanel.StringSet.Up;
214+
dirStr = s.Up;
215215
break;
216216
case SOUTH:
217-
dirStr = GUIPanel.StringSet.South;
217+
dirStr = s.South;
218218
break;
219219
case NORTH:
220-
dirStr = GUIPanel.StringSet.North;
220+
dirStr = s.North;
221221
break;
222222
case RANDOM:
223-
dirStr = GUIPanel.StringSet.TargetRandom;
223+
dirStr = s.TargetRandom;
224224
break;
225225
}
226226
if ((direction & LOCAL_BIT) != 0 && direction != NO_DIRECTION)
227-
return GUIPanel.StringSet.TargetLocalDirection(dirStr);
227+
return s.TargetLocalDirection(dirStr);
228228
else
229229
return dirStr;
230230
}

Assets/Base/Object.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public abstract class ObjectEntity : DynamicEntity
66
public static new PropertiesObjectType objectType = new PropertiesObjectType(
77
"Object", typeof(ObjectEntity))
88
{
9+
displayName = s => s.ObjectName,
910
description = s => s.ObjectDesc,
1011
iconName = "circle",
1112
};

Assets/Base/Substance.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class Substance : DynamicEntity
1212
public static new PropertiesObjectType objectType = new PropertiesObjectType(
1313
"Substance", typeof(Substance))
1414
{
15+
displayName = s => s.SubstanceName,
1516
description = s => s.SubstanceDesc,
1617
longDescription = s => s.SubstanceLongDesc,
1718
iconName = "cube-outline",

Assets/Base/WorldProperties.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class WorldProperties : PropertiesObject
1515
public static PropertiesObjectType objectType = new PropertiesObjectType(
1616
"World", typeof(WorldProperties))
1717
{
18+
displayName = s => s.WorldName,
1819
description = s => s.WorldDesc,
1920
iconName = "earth",
2021
};

Assets/Behaviors/Carryable.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class CarryableBehavior : GenericEntityBehavior<CarryableBehavior, Carrya
77
public static new BehaviorType objectType = new BehaviorType(
88
"Carryable", typeof(CarryableBehavior))
99
{
10+
displayName = s => s.CarryableName,
1011
description = s => s.CarryableDesc,
1112
longDescription = s => s.CarryableLongDesc,
1213
iconName = "coffee",

Assets/Behaviors/CharacterComponent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class CharacterBehavior : BasePhysicsBehavior
66
public static new BehaviorType objectType = new BehaviorType(
77
"Character", typeof(CharacterBehavior))
88
{
9+
displayName = s => s.CharacterName,
910
description = s => s.CharacterDesc,
1011
longDescription = s => s.CharacterLongDesc,
1112
iconName = "human",

Assets/Behaviors/Clone.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class CloneBehavior : TeleportBehavior
44
{
55
public static new BehaviorType objectType = new BehaviorType("Clone", typeof(CloneBehavior))
66
{
7+
displayName = s => s.CloneName,
78
description = s => s.CloneDesc,
89
longDescription = s => s.CloneLongDesc,
910
iconName = "content-copy",

Assets/Behaviors/Force.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public enum ForceBehaviorMode
1010

1111
public static new BehaviorType objectType = new BehaviorType("Force", typeof(ForceBehavior))
1212
{
13+
displayName = s => s.ForceName,
1314
description = s => s.ForceDesc,
1415
longDescription = s => s.ForceLongDesc,
1516
iconName = "rocket",

Assets/Behaviors/HaloComponent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class HaloBehavior : GenericEntityBehavior<HaloBehavior, HaloComponent>
66
{
77
public static new BehaviorType objectType = new BehaviorType("Halo", typeof(HaloBehavior))
88
{
9+
displayName = s => s.HaloName,
910
description = s => s.HaloDesc,
1011
longDescription = s => s.HaloLongDesc,
1112
iconName = "blur",

Assets/Behaviors/HurtHeal.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class HurtHealBehavior : GenericEntityBehavior<HurtHealBehavior, HurtHeal
66
public static new BehaviorType objectType = new BehaviorType(
77
"Hurt/Heal", typeof(HurtHealBehavior))
88
{
9+
displayName = s => s.HurtHealName,
910
description = s => s.HurtHealDesc,
1011
longDescription = s => s.HurtHealLongDesc,
1112
iconName = "heart",

Assets/Behaviors/Joystick.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public enum JoystickAlignment { HORIZONTAL, VERTICAL }
1010
public static new BehaviorType objectType = new BehaviorType(
1111
"Joystick", typeof(JoystickBehavior))
1212
{
13+
displayName = s => s.JoystickName,
1314
description = s => s.JoystickDesc,
1415
iconName = "joystick",
1516
rule = BehaviorType.AndRule(

Assets/Behaviors/LightComponent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class LightBehavior : GenericEntityBehavior<LightBehavior, LightComponent
66
{
77
public static new BehaviorType objectType = new BehaviorType("Light", typeof(LightBehavior))
88
{
9+
displayName = s => s.LightName,
910
description = s => s.LightDesc,
1011
longDescription = s => s.LightLongDesc,
1112
iconName = "lightbulb-on",

Assets/Behaviors/LookAt.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public class LookAtBehavior : GenericEntityBehavior<LookAtBehavior, LookAtCompon
55
{
66
public static new BehaviorType objectType = new BehaviorType("Look At", typeof(LookAtBehavior))
77
{
8+
displayName = s => s.LookAtName,
89
description = s => s.LookAtDesc,
910
longDescription = s => s.LookAtLongDesc,
1011
iconName = "compass",

Assets/Behaviors/Move.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class MoveBehavior : GenericEntityBehavior<MoveBehavior, MoveComponent>
66
public static new BehaviorType objectType = new BehaviorType(
77
"Move", typeof(MoveBehavior))
88
{
9+
displayName = s => s.MoveName,
910
description = s => s.MoveDesc,
1011
longDescription = s => s.MoveLongDesc,
1112
iconName = "arrow-right-bold-box-outline",

Assets/Behaviors/MoveWith.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class MoveWithBehavior : GenericEntityBehavior<MoveWithBehavior, MoveWith
66
public static new BehaviorType objectType = new BehaviorType(
77
"Move With", typeof(MoveWithBehavior))
88
{
9+
displayName = s => s.MoveWithName,
910
description = s => s.MoveWithDesc,
1011
longDescription = s => s.MoveWithLongDesc,
1112
iconName = "move-resize-variant",

Assets/Behaviors/PhysicsComponent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class PhysicsBehavior : BasePhysicsBehavior
1212
public static new BehaviorType objectType = new BehaviorType(
1313
"Physics", typeof(PhysicsBehavior))
1414
{
15+
displayName = s => s.PhysicsName,
1516
description = s => s.PhysicsDesc,
1617
longDescription = s => s.PhysicsLongDesc,
1718
iconName = "soccer",

Assets/Behaviors/Reflector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class ReflectorBehavior : GenericEntityBehavior<ReflectorBehavior, Reflec
88
public static new BehaviorType objectType = new BehaviorType(
99
"Reflector", typeof(ReflectorBehavior))
1010
{
11+
displayName = s => s.ReflectorName,
1112
description = s => s.ReflectorDesc,
1213
longDescription = s => s.ReflectorLongDesc,
1314
iconName = "mirror",

Assets/Behaviors/Scale.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class ScaleBehavior : GenericEntityBehavior<ScaleBehavior, ScaleComponent
66
public static new BehaviorType objectType = new BehaviorType(
77
"Scale", typeof(ScaleBehavior))
88
{
9+
displayName = s => s.ScaleName,
910
description = s => s.ScaleDesc,
1011
longDescription = s => s.ScaleLongDesc,
1112
iconName = "resize",

Assets/Behaviors/Score.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class ScoreBehavior : GenericEntityBehavior<ScoreBehavior, ScoreComponent
44
{
55
public static new BehaviorType objectType = new BehaviorType("Score", typeof(ScoreBehavior))
66
{
7+
displayName = s => s.ScoreName,
78
description = s => s.ScoreDesc,
89
iconName = "counter"
910
};

Assets/Behaviors/Solid.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class SolidBehavior : GenericEntityBehavior<SolidBehavior, SolidComponent
44
{
55
public static new BehaviorType objectType = new BehaviorType("Solid", typeof(SolidBehavior))
66
{
7+
displayName = s => s.SolidName,
78
description = s => s.SolidDesc,
89
iconName = "wall",
910
rule = BehaviorType.AndRule(

Assets/Behaviors/Sound.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class SoundBehavior : BaseSoundBehavior
1818
{
1919
public static new BehaviorType objectType = new BehaviorType("Sound", typeof(SoundBehavior))
2020
{
21+
displayName = s => s.SoundName,
2122
description = s => s.SoundDesc,
2223
longDescription = s => s.SoundLongDesc,
2324
iconName = "volume-high",

Assets/Behaviors/Sound3D.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class Sound3DBehavior : BaseSoundBehavior
1111
public static new BehaviorType objectType = new BehaviorType(
1212
"3D Sound", typeof(Sound3DBehavior))
1313
{
14+
displayName = s => s.Sound3DName,
1415
description = s => s.Sound3DDesc,
1516
longDescription = s => s.Sound3DLongDesc,
1617
iconName = "headphones",

Assets/Behaviors/Spin.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public class SpinBehavior : GenericEntityBehavior<SpinBehavior, SpinComponent>
55
{
66
public static new BehaviorType objectType = new BehaviorType("Spin", typeof(SpinBehavior))
77
{
8+
displayName = s => s.SpinName,
89
description = s => s.SpinDesc,
910
longDescription = s => s.SpinLongDesc,
1011
iconName = "format-rotate-90",

Assets/Behaviors/Teleport.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class TeleportBehavior : GenericEntityBehavior<TeleportBehavior, Teleport
66
public static new BehaviorType objectType = new BehaviorType(
77
"Teleport", typeof(TeleportBehavior))
88
{
9+
displayName = s => s.TeleportName,
910
description = s => s.TeleportDesc,
1011
longDescription = s => s.TeleportLongDesc,
1112
iconName = "send",

Assets/Behaviors/Visible.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public class VisibleBehavior : GenericEntityBehavior<VisibleBehavior, VisibleCom
55
{
66
public static new BehaviorType objectType = new BehaviorType("Visible", typeof(VisibleBehavior))
77
{
8+
displayName = s => s.VisibleName,
89
description = s => s.VisibleDesc,
910
iconName = "eye",
1011
rule = BehaviorType.AndRule(

0 commit comments

Comments
 (0)