Skip to content

Commit

Permalink
Localized strings for object names; #377
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Jan 16, 2024
1 parent 15e7c59 commit 442ea6d
Show file tree
Hide file tree
Showing 53 changed files with 212 additions and 69 deletions.
22 changes: 11 additions & 11 deletions Assets/Base/ActivatedSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public abstract class ActivatedSensor : Sensor
public interface Filter
{
bool EntityMatches(EntityComponent entityComponent);
string ToString(GUIStringSet s);
}

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

public override string ToString()
public string ToString(GUIStringSet s)
{
Entity e = entityRef.entity;
if (e == null)
return GUIPanel.StringSet.EntityRefNone;
return e.ToString();
return s.EntityRefNone;
return e.ToString(s);
}
}

Expand Down Expand Up @@ -105,7 +106,7 @@ public bool EntityMatches(EntityComponent entityComponent)
return false;
}

public override string ToString() => entityType.fullName;
public string ToString(GUIStringSet s) => entityType.displayName(s);
}

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

public override string ToString() =>
GUIPanel.StringSet.FilterWithTag(Entity.TagToString(tag));
public string ToString(GUIStringSet s) => s.FilterWithTag(Entity.TagToString(tag));
}

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

public override string ToString()
public string ToString(GUIStringSet s)
{
if (tagBits == 0)
return GUIPanel.StringSet.FilterNothing;
return s.FilterNothing;
else if (tagBits == 255)
return GUIPanel.StringSet.FilterAnything;
return s.AnythingName;
string str = "";
int count = 0;
for (byte i = 0; i < 8; i++)
Expand All @@ -166,9 +166,9 @@ public override string ToString()
}
}
if (count == 1)
return GUIPanel.StringSet.FilterWithTag(str);
return s.FilterWithTag(str);
else
return GUIPanel.StringSet.FilterMultipleTags(str);
return s.FilterMultipleTags(str);
}
}

Expand Down
1 change: 1 addition & 0 deletions Assets/Base/CustomTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class CustomTexture : PropertiesObject
public static PropertiesObjectType objectType = new PropertiesObjectType(
"Custom Texture", typeof(CustomTexture))
{
displayName = s => s.CustomTextureName,
description = s => s.CustomTextureDesc,
iconName = "image",
};
Expand Down
19 changes: 17 additions & 2 deletions Assets/Base/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public static IEnumerable<Property> JoinProperties(
public class PropertiesObjectType
{
public static readonly PropertiesObjectType NONE = new PropertiesObjectType("None", null)
{ iconName = "cancel" };
{
displayName = s => s.NoneName,
iconName = "cancel",
};

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

[XmlIgnore]
public Localizer displayName;
[XmlIgnore]
public Localizer description = GUIStringSet.Empty;
[XmlIgnore]
Expand All @@ -81,25 +86,30 @@ public Texture icon
public PropertiesObjectType()
{
constructor = DefaultConstructor;
displayName = DefaultDisplayName;
}

public PropertiesObjectType(string fullName, Type type)
{
this.fullName = fullName;
this.type = type;
constructor = DefaultConstructor;
displayName = DefaultDisplayName;
}

public PropertiesObjectType(PropertiesObjectType baseType, Func<PropertiesObject> newConstructor)
{
fullName = baseType.fullName;
displayName = baseType.displayName;
description = baseType.description;
longDescription = baseType.longDescription;
iconName = baseType.iconName;
type = baseType.type;
constructor = newConstructor;
}

private string DefaultDisplayName(GUIStringSet s) => fullName;

private PropertiesObject DefaultConstructor()
{
if (type == null)
Expand Down Expand Up @@ -174,7 +184,10 @@ public abstract class Entity : PropertiesObject
{
public static PropertiesObjectType objectType = new PropertiesObjectType(
"Anything", typeof(Entity))
{ iconName = "circle-outline" };
{
displayName = s => s.AnythingName,
iconName = "circle-outline",
};

public EntityComponent component;
public Sensor sensor;
Expand All @@ -192,6 +205,8 @@ public static string TagToString(byte tag)
}

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

public virtual PropertiesObjectType ObjectType => objectType;

Expand Down
22 changes: 11 additions & 11 deletions Assets/Base/EntityReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,39 +192,39 @@ public bool MatchesDirection(Transform transform, Vector3 direction)
return Vector3.Angle(targetDirection, direction) < 45;
}

public override string ToString()
public string ToString(GUIStringSet s)
{
if (entityRef.entity != null)
return entityRef.entity.ToString();
return entityRef.entity.ToString(s);
else
{
string dirStr = GUIPanel.StringSet.EntityRefNone;
string dirStr = s.EntityRefNone;
switch (direction & ~LOCAL_BIT)
{
case WEST:
dirStr = GUIPanel.StringSet.West;
dirStr = s.West;
break;
case EAST:
dirStr = GUIPanel.StringSet.East;
dirStr = s.East;
break;
case DOWN:
dirStr = GUIPanel.StringSet.Down;
dirStr = s.Down;
break;
case UP:
dirStr = GUIPanel.StringSet.Up;
dirStr = s.Up;
break;
case SOUTH:
dirStr = GUIPanel.StringSet.South;
dirStr = s.South;
break;
case NORTH:
dirStr = GUIPanel.StringSet.North;
dirStr = s.North;
break;
case RANDOM:
dirStr = GUIPanel.StringSet.TargetRandom;
dirStr = s.TargetRandom;
break;
}
if ((direction & LOCAL_BIT) != 0 && direction != NO_DIRECTION)
return GUIPanel.StringSet.TargetLocalDirection(dirStr);
return s.TargetLocalDirection(dirStr);
else
return dirStr;
}
Expand Down
1 change: 1 addition & 0 deletions Assets/Base/Object.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public abstract class ObjectEntity : DynamicEntity
public static new PropertiesObjectType objectType = new PropertiesObjectType(
"Object", typeof(ObjectEntity))
{
displayName = s => s.ObjectName,
description = s => s.ObjectDesc,
iconName = "circle",
};
Expand Down
1 change: 1 addition & 0 deletions Assets/Base/Substance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Substance : DynamicEntity
public static new PropertiesObjectType objectType = new PropertiesObjectType(
"Substance", typeof(Substance))
{
displayName = s => s.SubstanceName,
description = s => s.SubstanceDesc,
longDescription = s => s.SubstanceLongDesc,
iconName = "cube-outline",
Expand Down
1 change: 1 addition & 0 deletions Assets/Base/WorldProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class WorldProperties : PropertiesObject
public static PropertiesObjectType objectType = new PropertiesObjectType(
"World", typeof(WorldProperties))
{
displayName = s => s.WorldName,
description = s => s.WorldDesc,
iconName = "earth",
};
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Carryable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class CarryableBehavior : GenericEntityBehavior<CarryableBehavior, Carrya
public static new BehaviorType objectType = new BehaviorType(
"Carryable", typeof(CarryableBehavior))
{
displayName = s => s.CarryableName,
description = s => s.CarryableDesc,
longDescription = s => s.CarryableLongDesc,
iconName = "coffee",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/CharacterComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class CharacterBehavior : BasePhysicsBehavior
public static new BehaviorType objectType = new BehaviorType(
"Character", typeof(CharacterBehavior))
{
displayName = s => s.CharacterName,
description = s => s.CharacterDesc,
longDescription = s => s.CharacterLongDesc,
iconName = "human",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Clone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class CloneBehavior : TeleportBehavior
{
public static new BehaviorType objectType = new BehaviorType("Clone", typeof(CloneBehavior))
{
displayName = s => s.CloneName,
description = s => s.CloneDesc,
longDescription = s => s.CloneLongDesc,
iconName = "content-copy",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Force.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum ForceBehaviorMode

public static new BehaviorType objectType = new BehaviorType("Force", typeof(ForceBehavior))
{
displayName = s => s.ForceName,
description = s => s.ForceDesc,
longDescription = s => s.ForceLongDesc,
iconName = "rocket",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/HaloComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class HaloBehavior : GenericEntityBehavior<HaloBehavior, HaloComponent>
{
public static new BehaviorType objectType = new BehaviorType("Halo", typeof(HaloBehavior))
{
displayName = s => s.HaloName,
description = s => s.HaloDesc,
longDescription = s => s.HaloLongDesc,
iconName = "blur",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/HurtHeal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class HurtHealBehavior : GenericEntityBehavior<HurtHealBehavior, HurtHeal
public static new BehaviorType objectType = new BehaviorType(
"Hurt/Heal", typeof(HurtHealBehavior))
{
displayName = s => s.HurtHealName,
description = s => s.HurtHealDesc,
longDescription = s => s.HurtHealLongDesc,
iconName = "heart",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Joystick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum JoystickAlignment { HORIZONTAL, VERTICAL }
public static new BehaviorType objectType = new BehaviorType(
"Joystick", typeof(JoystickBehavior))
{
displayName = s => s.JoystickName,
description = s => s.JoystickDesc,
iconName = "joystick",
rule = BehaviorType.AndRule(
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/LightComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class LightBehavior : GenericEntityBehavior<LightBehavior, LightComponent
{
public static new BehaviorType objectType = new BehaviorType("Light", typeof(LightBehavior))
{
displayName = s => s.LightName,
description = s => s.LightDesc,
longDescription = s => s.LightLongDesc,
iconName = "lightbulb-on",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/LookAt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class LookAtBehavior : GenericEntityBehavior<LookAtBehavior, LookAtCompon
{
public static new BehaviorType objectType = new BehaviorType("Look At", typeof(LookAtBehavior))
{
displayName = s => s.LookAtName,
description = s => s.LookAtDesc,
longDescription = s => s.LookAtLongDesc,
iconName = "compass",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class MoveBehavior : GenericEntityBehavior<MoveBehavior, MoveComponent>
public static new BehaviorType objectType = new BehaviorType(
"Move", typeof(MoveBehavior))
{
displayName = s => s.MoveName,
description = s => s.MoveDesc,
longDescription = s => s.MoveLongDesc,
iconName = "arrow-right-bold-box-outline",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/MoveWith.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class MoveWithBehavior : GenericEntityBehavior<MoveWithBehavior, MoveWith
public static new BehaviorType objectType = new BehaviorType(
"Move With", typeof(MoveWithBehavior))
{
displayName = s => s.MoveWithName,
description = s => s.MoveWithDesc,
longDescription = s => s.MoveWithLongDesc,
iconName = "move-resize-variant",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/PhysicsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class PhysicsBehavior : BasePhysicsBehavior
public static new BehaviorType objectType = new BehaviorType(
"Physics", typeof(PhysicsBehavior))
{
displayName = s => s.PhysicsName,
description = s => s.PhysicsDesc,
longDescription = s => s.PhysicsLongDesc,
iconName = "soccer",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Reflector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class ReflectorBehavior : GenericEntityBehavior<ReflectorBehavior, Reflec
public static new BehaviorType objectType = new BehaviorType(
"Reflector", typeof(ReflectorBehavior))
{
displayName = s => s.ReflectorName,
description = s => s.ReflectorDesc,
longDescription = s => s.ReflectorLongDesc,
iconName = "mirror",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Scale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class ScaleBehavior : GenericEntityBehavior<ScaleBehavior, ScaleComponent
public static new BehaviorType objectType = new BehaviorType(
"Scale", typeof(ScaleBehavior))
{
displayName = s => s.ScaleName,
description = s => s.ScaleDesc,
longDescription = s => s.ScaleLongDesc,
iconName = "resize",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Score.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class ScoreBehavior : GenericEntityBehavior<ScoreBehavior, ScoreComponent
{
public static new BehaviorType objectType = new BehaviorType("Score", typeof(ScoreBehavior))
{
displayName = s => s.ScoreName,
description = s => s.ScoreDesc,
iconName = "counter"
};
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Solid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class SolidBehavior : GenericEntityBehavior<SolidBehavior, SolidComponent
{
public static new BehaviorType objectType = new BehaviorType("Solid", typeof(SolidBehavior))
{
displayName = s => s.SolidName,
description = s => s.SolidDesc,
iconName = "wall",
rule = BehaviorType.AndRule(
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Sound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class SoundBehavior : BaseSoundBehavior
{
public static new BehaviorType objectType = new BehaviorType("Sound", typeof(SoundBehavior))
{
displayName = s => s.SoundName,
description = s => s.SoundDesc,
longDescription = s => s.SoundLongDesc,
iconName = "volume-high",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Sound3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Sound3DBehavior : BaseSoundBehavior
public static new BehaviorType objectType = new BehaviorType(
"3D Sound", typeof(Sound3DBehavior))
{
displayName = s => s.Sound3DName,
description = s => s.Sound3DDesc,
longDescription = s => s.Sound3DLongDesc,
iconName = "headphones",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Spin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class SpinBehavior : GenericEntityBehavior<SpinBehavior, SpinComponent>
{
public static new BehaviorType objectType = new BehaviorType("Spin", typeof(SpinBehavior))
{
displayName = s => s.SpinName,
description = s => s.SpinDesc,
longDescription = s => s.SpinLongDesc,
iconName = "format-rotate-90",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Teleport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class TeleportBehavior : GenericEntityBehavior<TeleportBehavior, Teleport
public static new BehaviorType objectType = new BehaviorType(
"Teleport", typeof(TeleportBehavior))
{
displayName = s => s.TeleportName,
description = s => s.TeleportDesc,
longDescription = s => s.TeleportLongDesc,
iconName = "send",
Expand Down
1 change: 1 addition & 0 deletions Assets/Behaviors/Visible.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class VisibleBehavior : GenericEntityBehavior<VisibleBehavior, VisibleCom
{
public static new BehaviorType objectType = new BehaviorType("Visible", typeof(VisibleBehavior))
{
displayName = s => s.VisibleName,
description = s => s.VisibleDesc,
iconName = "eye",
rule = BehaviorType.AndRule(
Expand Down
Loading

0 comments on commit 442ea6d

Please sign in to comment.