Skip to content

Commit c8927a4

Browse files
enhancements
1 parent c45c993 commit c8927a4

File tree

11 files changed

+801
-957
lines changed

11 files changed

+801
-957
lines changed
Loading

Source/Documentation/Manual/software-platform.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ If you choose to develop your own pages, please consider sharing them with the O
147147

148148
.. image:: images/web-page-map.png
149149

150+
- | The Switch Panel page shows a html panel with a selection of 40 buttons. Buttons which can be used to issue Open Rails commands, normally entered via the keyboard.
151+
| This panel is most usefull when used on a touch enabled device, such as a tablet.
152+
| The adress of the panel is "<OR host>:2150/SwitchPanel/index.html", where <OR host> must be replaced with the hostname or ip adress of the host where Open Rails is running.
153+
| Not all buttons are yet filled. Depends also on the type of locomotive.
154+
155+
.. image:: images/switch-panel.png
156+
150157
.. _web-server-api:
151158

152159
Application Programming Interfaces (APIs)

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.IsPressed(command) || SwitchPanelModule.IsDown(command))
311+
if (UserInput.IsPressed(command) || SwitchPanelModule.IsDown(command))
312312
{
313313
UserInputCommands[command][1]();
314314
//Debrief eval

Source/RunActivity/Viewer3D/UserInput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static bool IsPressed(UserCommand command)
148148
return true;
149149
var setting = InputSettings.Commands[(int)command];
150150
return (setting.IsKeyDown(KeyboardState) && !setting.IsKeyDown(LastKeyboardState)) ||
151-
SwitchPanelModule.IsPressed(command);
151+
SwitchPanelModule.IsDown(command);
152152
}
153153

154154
public static bool IsReleased(UserCommand command)

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

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,40 @@ namespace Orts.Viewer3D.WebServices.SwitchPanel
2222
{
2323
public class SwitchOnPanel
2424
{
25-
public SwitchOnPanelDefinition Definition = new SwitchOnPanelDefinition();
26-
public SwitchOnPanelStatus Status = new SwitchOnPanelStatus();
25+
private readonly Viewer Viewer;
26+
27+
public SwitchOnPanelDefinition Definition;
28+
public SwitchOnPanelStatus Status;
2729

28-
public bool[] IsPressed = new bool[] { false };
2930
public bool[] IsDown = new bool[] { false };
3031
public bool[] IsUp = new bool[] { false };
3132

32-
// almost empty non functioning button
33-
public void init0(UserCommand userCommand = ORTS.Common.Input.UserCommand.GamePauseMenu, string description = "")
33+
public SwitchOnPanel(Viewer viewer)
3434
{
35-
Definition.NoOffButtons = 0;
36-
Definition.Button = TypeOfButton.none;
37-
Definition.UserCommand = new UserCommand[] { userCommand };
38-
Definition.Description = description;
39-
initIs();
35+
Viewer = viewer;
36+
Definition = new SwitchOnPanelDefinition(Viewer);
37+
Status = new SwitchOnPanelStatus(Viewer);
4038
}
4139

42-
// 1 button
43-
public void init1(UserCommand userCommand, string description, TypeOfButton typeOfButton = TypeOfButton.click)
40+
public void initDefinition(UserCommand userCommand)
4441
{
45-
Definition.NoOffButtons = 1;
46-
Definition.Button = typeOfButton;
47-
Definition.UserCommand = new UserCommand[] { userCommand };
48-
Definition.Description = description;
49-
initIs();
42+
Definition.init(userCommand);
5043
}
5144

52-
// 2 buttons
53-
public void init2(UserCommand userCommandTop, UserCommand userCommandBottom, string description, TypeOfButton typeOfButton = TypeOfButton.click)
45+
public void initDefinitionEmpty()
5446
{
55-
Definition.NoOffButtons = 2;
56-
Definition.Button = typeOfButton;
57-
Definition.UserCommand = new UserCommand[] { userCommandTop, userCommandBottom };
58-
Definition.Description = description;
59-
initIs();
47+
Definition.initEmpty();
6048
}
6149

6250
public void initIs()
6351
{
6452
if (Definition.NoOffButtons == 1)
6553
{
66-
IsPressed = new bool[] { false };
6754
IsDown = new bool[] { false };
6855
IsUp = new bool[] { false };
6956
}
7057
if (Definition.NoOffButtons == 2)
7158
{
72-
IsPressed = new bool[] { false, false };
7359
IsDown = new bool[] { false, false };
7460
IsUp = new bool[] { false, false };
7561
}

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

Lines changed: 143 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,158 @@
1717
//
1818

1919
using System.Collections.Generic;
20+
using Orts.Simulation.RollingStocks;
2021
using ORTS.Common.Input;
22+
using ORTS.Settings;
2123

2224
namespace Orts.Viewer3D.WebServices.SwitchPanel
2325
{
2426
public class SwitchOnPanelDefinition
2527
{
28+
private readonly Viewer Viewer;
29+
2630
public int NoOffButtons = 0;
27-
public TypeOfButton Button = TypeOfButton.none;
2831
public UserCommand[] UserCommand = { ORTS.Common.Input.UserCommand.GamePauseMenu };
2932
public string Description = "";
3033

31-
public SwitchOnPanelDefinition() { }
34+
public SwitchOnPanelDefinition(Viewer viewer)
35+
{
36+
Viewer = viewer;
37+
}
38+
39+
public void init(UserCommand userCommand)
40+
{
41+
MSTSLocomotive locomotive = Viewer.PlayerLocomotive as MSTSLocomotive;
42+
43+
switch (userCommand)
44+
{
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+
57+
case ORTS.Common.Input.UserCommand.ControlBatterySwitchClose:
58+
switch (locomotive.LocomotivePowerSupply.BatterySwitch.Mode)
59+
{
60+
case Simulation.RollingStocks.SubSystems.PowerSupplies.BatterySwitch.ModeType.AlwaysOn:
61+
init0(ORTS.Common.Input.UserCommand.ControlBatterySwitchClose, "Battery Switch");
62+
break;
63+
case Simulation.RollingStocks.SubSystems.PowerSupplies.BatterySwitch.ModeType.Switch:
64+
init1(ORTS.Common.Input.UserCommand.ControlBatterySwitchClose, "Battery Switch");
65+
break;
66+
case Simulation.RollingStocks.SubSystems.PowerSupplies.BatterySwitch.ModeType.PushButtons:
67+
init2(ORTS.Common.Input.UserCommand.ControlBatterySwitchClose, ORTS.Common.Input.UserCommand.ControlBatterySwitchOpen, "Battery Switch");
68+
break;
69+
}
70+
break;
71+
72+
case ORTS.Common.Input.UserCommand.ControlMasterKey:
73+
if (locomotive.LocomotivePowerSupply.MasterKey.Mode == Simulation.RollingStocks.SubSystems.PowerSupplies.MasterKey.ModeType.AlwaysOn)
74+
init0(ORTS.Common.Input.UserCommand.ControlMasterKey, "Master Key");
75+
else
76+
init1(ORTS.Common.Input.UserCommand.ControlMasterKey, "Master Key");
77+
break;
78+
79+
case ORTS.Common.Input.UserCommand.ControlCircuitBreakerClosingOrder:
80+
if ((locomotive as MSTSElectricLocomotive).ElectricPowerSupply.CircuitBreaker.ScriptName == "Automatic")
81+
init0(ORTS.Common.Input.UserCommand.ControlCircuitBreakerClosingOrder, "Circuit Breaker");
82+
else
83+
init1(ORTS.Common.Input.UserCommand.ControlCircuitBreakerClosingOrder, "Circuit Breaker");
84+
break;
85+
86+
case ORTS.Common.Input.UserCommand.ControlGearUp:
87+
if ((locomotive as MSTSDieselLocomotive).DieselEngines.HasGearBox)
88+
init2(ORTS.Common.Input.UserCommand.ControlGearUp, ORTS.Common.Input.UserCommand.ControlGearDown, "Gear");
89+
else
90+
init0(ORTS.Common.Input.UserCommand.ControlGearUp, "Gear");
91+
break;
92+
93+
case ORTS.Common.Input.UserCommand.ControlTractionCutOffRelayClosingOrder:
94+
if ((locomotive as MSTSDieselLocomotive).DieselPowerSupply.TractionCutOffRelay.ScriptName == "Automatic")
95+
init0(ORTS.Common.Input.UserCommand.ControlTractionCutOffRelayClosingOrder, "traction cut-off");
96+
else
97+
init1(ORTS.Common.Input.UserCommand.ControlTractionCutOffRelayClosingOrder, "traction cut-off");
98+
break;
99+
100+
case ORTS.Common.Input.UserCommand.DisplayNextStationWindow:
101+
Orts.Simulation.Activity act = Viewer.Simulator.ActivityRun;
102+
if ((act != null) && (act.EventList.Count) > 0)
103+
init1(ORTS.Common.Input.UserCommand.DisplayNextStationWindow, "Activity");
104+
else
105+
init0(ORTS.Common.Input.UserCommand.DisplayNextStationWindow, "Activity");
106+
break;
107+
108+
case ORTS.Common.Input.UserCommand.ControlHeadlightIncrease:
109+
init2(ORTS.Common.Input.UserCommand.ControlHeadlightIncrease, ORTS.Common.Input.UserCommand.ControlHeadlightDecrease, "Front Light");
110+
break;
111+
112+
case ORTS.Common.Input.UserCommand.ControlForwards:
113+
init2(ORTS.Common.Input.UserCommand.ControlForwards, ORTS.Common.Input.UserCommand.ControlBackwards, "Direction");
114+
break;
115+
116+
default:
117+
string description = determineDescription(userCommand);
118+
init1(userCommand, description);
119+
break;
120+
}
121+
}
122+
123+
public void initEmpty()
124+
{
125+
init0();
126+
}
127+
128+
private string determineDescription(UserCommand userCommand)
129+
{
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);
145+
146+
return description;
147+
}
148+
149+
// almost empty non functioning button
150+
public void init0(UserCommand userCommand = ORTS.Common.Input.UserCommand.GamePauseMenu, string description = "")
151+
{
152+
NoOffButtons = 0;
153+
UserCommand = new UserCommand[] { userCommand };
154+
Description = description;
155+
}
156+
157+
// 1 button
158+
public void init1(UserCommand userCommand, string description)
159+
{
160+
NoOffButtons = 1;
161+
UserCommand = new UserCommand[] { userCommand };
162+
Description = description;
163+
}
164+
165+
// 2 buttons
166+
public void init2(UserCommand userCommandTop, UserCommand userCommandBottom, string description)
167+
{
168+
NoOffButtons = 2;
169+
UserCommand = new UserCommand[] { userCommandTop, userCommandBottom };
170+
Description = description;
171+
}
32172

33173
public override bool Equals(object obj)
34174
{
@@ -54,14 +194,12 @@ public override bool Equals(object obj)
54194
}
55195
}
56196

57-
return ((SwitchOnPanelDefinition)obj).Button == Button &&
58-
((SwitchOnPanelDefinition)obj).Description == Description;
197+
return ((SwitchOnPanelDefinition)obj).Description == Description;
59198
}
60199

61200
public static void deepCopy(SwitchOnPanelDefinition to, SwitchOnPanelDefinition from)
62201
{
63202
to.NoOffButtons = from.NoOffButtons;
64-
to.Button = from.Button;
65203
to.Description = from.Description;
66204

67205
to.UserCommand = new UserCommand[from.NoOffButtons];
@@ -75,7 +213,6 @@ public override int GetHashCode()
75213
{
76214
var hashCode = 1410623761;
77215
hashCode = hashCode * -1521134295 + NoOffButtons.GetHashCode();
78-
hashCode = hashCode * -1521134295 + Button.GetHashCode();
79216
hashCode = hashCode * -1521134295 + EqualityComparer<UserCommand[]>.Default.GetHashCode(UserCommand);
80217
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Description);
81218
return hashCode;

0 commit comments

Comments
 (0)