Skip to content

Commit 271b7c4

Browse files
- replaced IsDown with IsPressed and IsUp with IsReleased to be more inline with rest of the OR code. Except in the html/javascript part.
- added some code to make translations possible, not 100% yet, to be done in the next iteration
1 parent c8927a4 commit 271b7c4

File tree

12 files changed

+370
-380
lines changed

12 files changed

+370
-380
lines changed

Source/ORTS.Common/GetStringAttribute.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static string GetPrettyName(Enum value)
3535
return type.GetField(Enum.GetName(type, value))
3636
.GetCustomAttributes(false)
3737
.OfType<GetStringAttribute>()
38-
.SingleOrDefault()
38+
.FirstOrDefault()
3939
.Name;
4040
}
4141
}
@@ -48,5 +48,17 @@ public class GetParticularStringAttribute : GetStringAttribute
4848
{
4949
public string Context { get; protected set; }
5050
public GetParticularStringAttribute(string context, string name) : base(name) { Context = context; }
51+
52+
public static string GetParticularPrettyName(Enum value, string context)
53+
{
54+
var type = value.GetType();
55+
string toBeReturned = type.GetField(Enum.GetName(type, value))
56+
.GetCustomAttributes(false)
57+
.OfType<GetParticularStringAttribute>()
58+
.SingleOrDefault()
59+
.Name;
60+
61+
return toBeReturned;
62+
}
5163
}
5264
}

Source/ORTS.Common/Input/UserCommand.cs

Lines changed: 226 additions & 226 deletions
Large diffs are not rendered by default.

Source/Orts.Simulation/Simulation/Physics/Train.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,14 @@ public bool IsPlayerDriven
318318

319319
public enum TRAIN_CONTROL
320320
{
321-
AUTO_SIGNAL,
322-
AUTO_NODE,
323-
MANUAL,
324-
EXPLORER,
325-
OUT_OF_CONTROL,
326-
INACTIVE,
327-
TURNTABLE,
328-
UNDEFINED
321+
[GetParticularString("TrainControl", "Auto Signal")] AUTO_SIGNAL,
322+
[GetParticularString("TrainControl", "Auto Node")] AUTO_NODE,
323+
[GetParticularString("TrainControl", "Manual")] MANUAL,
324+
[GetParticularString("TrainControl", "Explorer")] EXPLORER,
325+
[GetParticularString("TrainControl", "Out of Control")] OUT_OF_CONTROL,
326+
[GetParticularString("TrainControl", "Inactive")] INACTIVE,
327+
[GetParticularString("TrainControl", "Turntable")] TURNTABLE,
328+
[GetParticularString("TrainControl", "Undefined")] UNDEFINED
329329
}
330330

331331
private TRAIN_CONTROL controlMode = TRAIN_CONTROL.UNDEFINED;

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public override void HandleUserInput(ElapsedTime elapsedTime)
308308

309309
foreach (var command in UserInputCommands.Keys)
310310
{
311-
if (UserInput.IsPressed(command) || SwitchPanelModule.IsDown(command))
311+
if (UserInput.IsPressed(command))
312312
{
313313
UserInputCommands[command][1]();
314314
//Debrief eval

Source/RunActivity/Viewer3D/WebServices/SwitchPanel/SwitchOnPanel.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public class SwitchOnPanel
2727
public SwitchOnPanelDefinition Definition;
2828
public SwitchOnPanelStatus Status;
2929

30-
public bool[] IsDown = new bool[] { false };
31-
public bool[] IsUp = new bool[] { false };
30+
public bool[] IsPressed = new bool[] { false };
31+
public bool[] IsReleased = new bool[] { false };
3232

3333
public SwitchOnPanel(Viewer viewer)
3434
{
@@ -51,13 +51,13 @@ public void initIs()
5151
{
5252
if (Definition.NoOffButtons == 1)
5353
{
54-
IsDown = new bool[] { false };
55-
IsUp = new bool[] { false };
54+
IsPressed = new bool[] { false };
55+
IsReleased = new bool[] { false };
5656
}
5757
if (Definition.NoOffButtons == 2)
5858
{
59-
IsDown = new bool[] { false, false };
60-
IsUp = new bool[] { false, false };
59+
IsPressed = new bool[] { false, false };
60+
IsReleased = new bool[] { false, false };
6161
}
6262
}
6363
}

Source/RunActivity/Viewer3D/WebServices/SwitchPanel/SwitchOnPanelDefinition.cs

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
using System.Collections.Generic;
2020
using Orts.Simulation.RollingStocks;
2121
using ORTS.Common.Input;
22-
using ORTS.Settings;
22+
using ORTS.Common;
2323

2424
namespace Orts.Viewer3D.WebServices.SwitchPanel
2525
{
@@ -42,79 +42,68 @@ public void init(UserCommand userCommand)
4242

4343
switch (userCommand)
4444
{
45-
case ORTS.Common.Input.UserCommand.ControlLight:
46-
init1(userCommand, "Cabin Light");
47-
break;
48-
49-
case ORTS.Common.Input.UserCommand.ControlAlerter:
50-
init1(userCommand, "Reset");
51-
break;
52-
53-
case ORTS.Common.Input.UserCommand.GameMultiPlayerDispatcher:
54-
init1(userCommand, "Map");
55-
break;
56-
5745
case ORTS.Common.Input.UserCommand.ControlBatterySwitchClose:
5846
switch (locomotive.LocomotivePowerSupply.BatterySwitch.Mode)
5947
{
6048
case Simulation.RollingStocks.SubSystems.PowerSupplies.BatterySwitch.ModeType.AlwaysOn:
61-
init0(ORTS.Common.Input.UserCommand.ControlBatterySwitchClose, "Battery Switch");
49+
init0(ORTS.Common.Input.UserCommand.ControlBatterySwitchClose, GetParticularString("SwitchPanel", "Battery switch"));
6250
break;
6351
case Simulation.RollingStocks.SubSystems.PowerSupplies.BatterySwitch.ModeType.Switch:
64-
init1(ORTS.Common.Input.UserCommand.ControlBatterySwitchClose, "Battery Switch");
52+
init1(ORTS.Common.Input.UserCommand.ControlBatterySwitchClose, GetParticularString("SwitchPanel", "Battery switch"));
6553
break;
6654
case Simulation.RollingStocks.SubSystems.PowerSupplies.BatterySwitch.ModeType.PushButtons:
67-
init2(ORTS.Common.Input.UserCommand.ControlBatterySwitchClose, ORTS.Common.Input.UserCommand.ControlBatterySwitchOpen, "Battery Switch");
55+
init2(ORTS.Common.Input.UserCommand.ControlBatterySwitchClose, ORTS.Common.Input.UserCommand.ControlBatterySwitchOpen, GetParticularString("SwitchPanel", "Battery switch"));
6856
break;
6957
}
7058
break;
7159

7260
case ORTS.Common.Input.UserCommand.ControlMasterKey:
7361
if (locomotive.LocomotivePowerSupply.MasterKey.Mode == Simulation.RollingStocks.SubSystems.PowerSupplies.MasterKey.ModeType.AlwaysOn)
74-
init0(ORTS.Common.Input.UserCommand.ControlMasterKey, "Master Key");
62+
init0(ORTS.Common.Input.UserCommand.ControlMasterKey, GetParticularString("SwitchPanel", "Master key"));
7563
else
76-
init1(ORTS.Common.Input.UserCommand.ControlMasterKey, "Master Key");
64+
init1(ORTS.Common.Input.UserCommand.ControlMasterKey, GetParticularString("SwitchPanel", "Master key"));
7765
break;
7866

7967
case ORTS.Common.Input.UserCommand.ControlCircuitBreakerClosingOrder:
8068
if ((locomotive as MSTSElectricLocomotive).ElectricPowerSupply.CircuitBreaker.ScriptName == "Automatic")
81-
init0(ORTS.Common.Input.UserCommand.ControlCircuitBreakerClosingOrder, "Circuit Breaker");
69+
init0(ORTS.Common.Input.UserCommand.ControlCircuitBreakerClosingOrder, GetParticularString("SwitchPanel", "Circuit breaker"));
8270
else
83-
init1(ORTS.Common.Input.UserCommand.ControlCircuitBreakerClosingOrder, "Circuit Breaker");
71+
init1(ORTS.Common.Input.UserCommand.ControlCircuitBreakerClosingOrder, GetParticularString("SwitchPanel", "Circuit breaker"));
8472
break;
8573

8674
case ORTS.Common.Input.UserCommand.ControlGearUp:
8775
if ((locomotive as MSTSDieselLocomotive).DieselEngines.HasGearBox)
88-
init2(ORTS.Common.Input.UserCommand.ControlGearUp, ORTS.Common.Input.UserCommand.ControlGearDown, "Gear");
76+
init2(ORTS.Common.Input.UserCommand.ControlGearUp, ORTS.Common.Input.UserCommand.ControlGearDown, GetParticularString("SwitchPanel", "Gear"));
8977
else
90-
init0(ORTS.Common.Input.UserCommand.ControlGearUp, "Gear");
78+
init0(ORTS.Common.Input.UserCommand.ControlGearUp, GetParticularString("SwitchPanel", "Gear"));
9179
break;
9280

9381
case ORTS.Common.Input.UserCommand.ControlTractionCutOffRelayClosingOrder:
9482
if ((locomotive as MSTSDieselLocomotive).DieselPowerSupply.TractionCutOffRelay.ScriptName == "Automatic")
95-
init0(ORTS.Common.Input.UserCommand.ControlTractionCutOffRelayClosingOrder, "traction cut-off");
83+
init0(ORTS.Common.Input.UserCommand.ControlTractionCutOffRelayClosingOrder, GetParticularString("SwitchPanel", "Traction cut-off"));
9684
else
97-
init1(ORTS.Common.Input.UserCommand.ControlTractionCutOffRelayClosingOrder, "traction cut-off");
85+
init1(ORTS.Common.Input.UserCommand.ControlTractionCutOffRelayClosingOrder, GetParticularString("SwitchPanel", "Traction cut-off"));
9886
break;
9987

10088
case ORTS.Common.Input.UserCommand.DisplayNextStationWindow:
10189
Orts.Simulation.Activity act = Viewer.Simulator.ActivityRun;
10290
if ((act != null) && (act.EventList.Count) > 0)
103-
init1(ORTS.Common.Input.UserCommand.DisplayNextStationWindow, "Activity");
91+
init1(ORTS.Common.Input.UserCommand.DisplayNextStationWindow, GetParticularStringAttribute.GetParticularPrettyName(userCommand, "SwitchPanel"));
10492
else
105-
init0(ORTS.Common.Input.UserCommand.DisplayNextStationWindow, "Activity");
93+
init0(ORTS.Common.Input.UserCommand.DisplayNextStationWindow, GetParticularStringAttribute.GetParticularPrettyName(userCommand, "SwitchPanel"));
10694
break;
10795

10896
case ORTS.Common.Input.UserCommand.ControlHeadlightIncrease:
109-
init2(ORTS.Common.Input.UserCommand.ControlHeadlightIncrease, ORTS.Common.Input.UserCommand.ControlHeadlightDecrease, "Front Light");
97+
init2(ORTS.Common.Input.UserCommand.ControlHeadlightIncrease, ORTS.Common.Input.UserCommand.ControlHeadlightDecrease, GetParticularString("SwitchPanel", "Front Light"));
11098
break;
11199

112100
case ORTS.Common.Input.UserCommand.ControlForwards:
113-
init2(ORTS.Common.Input.UserCommand.ControlForwards, ORTS.Common.Input.UserCommand.ControlBackwards, "Direction");
101+
init2(ORTS.Common.Input.UserCommand.ControlForwards, ORTS.Common.Input.UserCommand.ControlBackwards, GetParticularString("SwitchPanel", "Direction"));
114102
break;
115103

116104
default:
117105
string description = determineDescription(userCommand);
106+
118107
init1(userCommand, description);
119108
break;
120109
}
@@ -127,43 +116,48 @@ public void initEmpty()
127116

128117
private string determineDescription(UserCommand userCommand)
129118
{
130-
string description = InputSettings.GetPrettyCommandName(userCommand);
131-
132-
if (description.StartsWith("Control "))
133-
description = description.Substring("Control ".Length);
134-
if (description.StartsWith("Game "))
135-
description = description.Substring("Game ".Length);
136-
if (description.StartsWith("Display "))
137-
description = description.Substring("Display ".Length);
138-
139-
if (description.EndsWith(" Push Button"))
140-
description = description.Substring(0, description.Length - " Push Button".Length);
141-
if (description.EndsWith(" Mode"))
142-
description = description.Substring(0, description.Length - " Mode".Length);
143-
if (description.EndsWith(" Window"))
144-
description = description.Substring(0, description.Length - " Window".Length);
119+
string description = GetParticularStringAttribute.GetParticularPrettyName(userCommand, "SwitchPanel");
120+
121+
description = capitalize(Viewer.Catalog.GetParticularString("SwitchPanel", description));
145122

146123
return description;
147124
}
148125

126+
private string GetParticularString(string context, string description)
127+
{
128+
return capitalize(Viewer.Catalog.GetParticularString(context, description));
129+
}
130+
131+
private string capitalize(string value)
132+
{
133+
if (value.Length > 0)
134+
{
135+
return char.ToUpper(value[0]) + value.Substring(1);
136+
}
137+
else
138+
{
139+
return "";
140+
}
141+
}
142+
149143
// almost empty non functioning button
150-
public void init0(UserCommand userCommand = ORTS.Common.Input.UserCommand.GamePauseMenu, string description = "")
144+
private void init0(UserCommand userCommand = ORTS.Common.Input.UserCommand.GamePauseMenu, string description = "")
151145
{
152146
NoOffButtons = 0;
153147
UserCommand = new UserCommand[] { userCommand };
154148
Description = description;
155149
}
156150

157151
// 1 button
158-
public void init1(UserCommand userCommand, string description)
152+
private void init1(UserCommand userCommand, string description)
159153
{
160154
NoOffButtons = 1;
161155
UserCommand = new UserCommand[] { userCommand };
162156
Description = description;
163157
}
164158

165159
// 2 buttons
166-
public void init2(UserCommand userCommandTop, UserCommand userCommandBottom, string description)
160+
private void init2(UserCommand userCommandTop, UserCommand userCommandBottom, string description)
167161
{
168162
NoOffButtons = 2;
169163
UserCommand = new UserCommand[] { userCommandTop, userCommandBottom };
@@ -212,9 +206,9 @@ public static void deepCopy(SwitchOnPanelDefinition to, SwitchOnPanelDefinition
212206
public override int GetHashCode()
213207
{
214208
var hashCode = 1410623761;
215-
hashCode = hashCode * -1521134295 + NoOffButtons.GetHashCode();
216-
hashCode = hashCode * -1521134295 + EqualityComparer<UserCommand[]>.Default.GetHashCode(UserCommand);
217-
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Description);
209+
hashCode = (hashCode * -1521134295) + NoOffButtons.GetHashCode();
210+
hashCode = (hashCode * -1521134295) + EqualityComparer<UserCommand[]>.Default.GetHashCode(UserCommand);
211+
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(Description);
218212
return hashCode;
219213
}
220214
}

Source/RunActivity/Viewer3D/WebServices/SwitchPanel/SwitchOnPanelStatus.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Orts.Simulation.Physics;
2323
using Orts.Simulation.RollingStocks.SubSystems;
2424
using Orts.Simulation.RollingStocks;
25+
using ORTS.Common;
2526

2627
namespace Orts.Viewer3D.WebServices.SwitchPanel
2728
{
@@ -72,7 +73,7 @@ private static void getStatusDoors(UserCommand userCommand, ref SwitchOnPanelSta
7273
switchOnPanelStatus.Color = "";
7374
switchOnPanelStatus.Blinking = false;
7475
}
75-
switchOnPanelStatus.Status = door.ToString();
76+
switchOnPanelStatus.Status = Viewer.Catalog.GetString(GetStringAttribute.GetPrettyName(door));
7677
}
7778

7879
private static void getStatusControlPantograph(UserCommand userCommand, ref SwitchOnPanelStatus switchOnPanelStatus)
@@ -91,7 +92,7 @@ private static void getStatusControlPantograph(UserCommand userCommand, ref Swit
9192
switchOnPanelStatus.Color = "lightblue";
9293
switchOnPanelStatus.Blinking = true;
9394
}
94-
switchOnPanelStatus.Status = locomotive.Pantographs.List[pantographIndex].State.ToString();
95+
switchOnPanelStatus.Status = GetStringAttribute.GetPrettyName(locomotive.Pantographs.List[pantographIndex].State);
9596
}
9697

9798
private static void getStatusControlHeadlight(ref SwitchOnPanelStatus switchOnPanelStatus)
@@ -135,7 +136,7 @@ private static void getStatusControlDirection(ref SwitchOnPanelStatus switchOnPa
135136
switchOnPanelStatus.Color = "orange";
136137
break;
137138
}
138-
switchOnPanelStatus.Status = locomotive.Direction.ToString();
139+
switchOnPanelStatus.Status = Viewer.Catalog.GetString(GetStringAttribute.GetPrettyName(locomotive.Direction));
139140
}
140141

141142
private static void getStatusControlSander(ref SwitchOnPanelStatus switchOnPanelStatus)
@@ -195,7 +196,7 @@ private static void getStatusGameControlMode(ref SwitchOnPanelStatus switchOnPan
195196
case Train.TRAIN_CONTROL.UNDEFINED:
196197
break;
197198
}
198-
switchOnPanelStatus.Status = Viewer.PlayerTrain.ControlMode.ToString();
199+
switchOnPanelStatus.Status = GetStringAttribute.GetPrettyName(Viewer.PlayerTrain.ControlMode);
199200
}
200201

201202
private static void getStatusGameAutopilotMode(ref SwitchOnPanelStatus switchOnPanelStatus)
@@ -299,7 +300,7 @@ private static void getStatusTractionCutOffRelay(ref SwitchOnPanelStatus switchO
299300
string scriptName = locomotive.DieselPowerSupply.TractionCutOffRelay.ScriptName;
300301
if (scriptName == "Automatic")
301302
{
302-
switchOnPanelStatus.Status = Viewer.Catalog.GetString("Automatic") + " <br> ";
303+
switchOnPanelStatus.Status = Viewer.Catalog.GetString("Always on") + " <br> ";
303304
switchOnPanelStatus.Color = "lightgray";
304305
}
305306

@@ -339,7 +340,7 @@ private static void getStatusDieselEnginePlayerHelper(MSTSDieselLocomotive Locom
339340
switchOnPanelStatus.Color = "lightgray";
340341
break;
341342
}
342-
switchOnPanelStatus.Status = (Locomotive as MSTSDieselLocomotive).DieselEngines.State.ToString();
343+
switchOnPanelStatus.Status = Viewer.Catalog.GetParticularString("Engine", (Locomotive as MSTSDieselLocomotive).DieselEngines.State.ToString());
343344
}
344345

345346
private static void getStatusDieselEngine(UserCommand userCommand, ref SwitchOnPanelStatus switchOnPanelStatus)
@@ -447,9 +448,9 @@ public static void deepCopy(SwitchOnPanelStatus to, SwitchOnPanelStatus from)
447448
public override int GetHashCode()
448449
{
449450
var hashCode = -1070463442;
450-
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Status);
451-
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Color);
452-
hashCode = hashCode * -1521134295 + Blinking.GetHashCode();
451+
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(Status);
452+
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(Color);
453+
hashCode = (hashCode * -1521134295) + Blinking.GetHashCode();
453454
return hashCode;
454455
}
455456
}

0 commit comments

Comments
 (0)