Skip to content

Commit 317d385

Browse files
Merge pull request #831 from sweiland-openrails/SwitchPanel
poor mans switch panel on tablet
2 parents 782e611 + f6ca1e1 commit 317d385

File tree

26 files changed

+2134
-26
lines changed

26 files changed

+2134
-26
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/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(string context, Enum value)
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.Simulation/Simulation/Physics/Train.cs

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

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

332332
private TRAIN_CONTROL controlMode = TRAIN_CONTROL.UNDEFINED;

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Door.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
using System.IO;
1818
using Orts.Common;
1919
using Orts.Parsers.Msts;
20+
using ORTS.Common;
2021
using ORTS.Scripting.Api;
2122

2223
namespace Orts.Simulation.RollingStocks.SubSystems
2324
{
2425
// Door state: do not change the order of this enum
2526
public enum DoorState
2627
{
27-
Closed,
28-
Closing,
29-
Opening,
30-
Open,
28+
[GetParticularString("Door", "Closed")] Closed,
29+
[GetParticularString("Door", "Closing")] Closing,
30+
[GetParticularString("Door", "Opening")] Opening,
31+
[GetParticularString("Door", "Open")] Open,
3132
}
3233
public enum DoorSide
3334
{

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/CircuitBreaker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class ScriptedCircuitBreaker : ITractionCutOffSubsystem
3333
public Simulator Simulator => Locomotive.Simulator;
3434

3535
public bool Activated = false;
36-
string ScriptName = "Automatic";
36+
public string ScriptName { get; protected set; } = "Automatic";
3737
CircuitBreaker Script;
3838

3939
public float DelayS { get; protected set; } = 0f;

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/TractionCutOffRelay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ScriptedTractionCutOffRelay : ITractionCutOffSubsystem
3434
public Simulator Simulator => LocomotivePowerSupply.Locomotive.Simulator;
3535

3636
public bool Activated = false;
37-
string ScriptName = "Automatic";
37+
public string ScriptName { get; protected set; } = "Automatic";
3838
TractionCutOffRelay Script;
3939

4040
public float DelayS { get; protected set; } = 0f;

Source/RunActivity/Viewer3D/Popups/HUDWindow.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ public class HUDWindow : LayeredWindow
4949

5050
readonly Viewer Viewer;
5151
readonly Action<TableData>[] TextPages;
52+
public readonly int TextPagesLength;
5253
readonly WindowTextFont TextFont;
5354
readonly HUDGraphMaterial HUDGraphMaterial;
5455

55-
int TextPage;
56+
public int TextPage;
5657
int LocomotivePage = 2;
5758
int LastTextPage;
5859
TableData TextTable = new TableData() { Cells = new string[0, 0] };
@@ -96,6 +97,7 @@ public HUDWindow(WindowManager owner)
9697
textPages.Add(TextPageWeather);
9798
textPages.Add(TextPageDebugInfo);
9899
TextPages = textPages.ToArray();
100+
TextPagesLength = TextPages.Length;
99101

100102
TextFont = owner.TextFontDefaultOutlined;
101103
ColumnWidth *= TextFont.Height;

Source/RunActivity/Viewer3D/Popups/TrackMonitorWindow.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class TrackMonitorWindow : Window
3939
Label SpeedAllowed;
4040
Label ControlMode;
4141
Label Gradient;
42-
TrackMonitor Monitor;
42+
public TrackMonitor Monitor { get; private set; }
4343

4444
readonly Dictionary<Train.TRAIN_CONTROL, string> ControlModeLabels;
4545

@@ -191,10 +191,10 @@ public class TrackMonitor : Control
191191
readonly Viewer Viewer;
192192
private bool metric => Viewer.MilepostUnitsMetric;
193193
private readonly SavingProperty<int> StateProperty;
194-
private DisplayMode Mode
194+
public DisplayMode Mode
195195
{
196196
get => (DisplayMode)StateProperty.Value;
197-
set
197+
private set
198198
{
199199
StateProperty.Value = (int)value;
200200
}

Source/RunActivity/Viewer3D/Processes/WebServerProcess.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
namespace Orts.Viewer3D.Processes
3434
{
3535
public class WebServerProcess
36-
{
36+
{
3737
public readonly Profiler Profiler = new Profiler("WebServer");
3838
private readonly ProcessState State = new ProcessState("WebServer");
3939
private readonly Game Game;
@@ -64,11 +64,10 @@ void WebServerThread()
6464
Profiler.SetThread();
6565
Game.SetThreadLanguage();
6666

67-
string myWebContentPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Content\\Web");
6867
EndPointManager.UseIpv6 = true;
6968
try
7069
{
71-
using (EmbedIO.WebServer server = WebServer.CreateWebServer($"http://*:{Game.Settings.WebServerPort}", myWebContentPath))
70+
using (EmbedIO.WebServer server = WebServer.CreateWebServer($"http://*:{Game.Settings.WebServerPort}", myWebContentPath()))
7271
server.RunAsync(StopServer.Token).Wait();
7372
}
7473
catch(AggregateException ex)
@@ -83,5 +82,19 @@ void WebServerThread()
8382
}
8483
}
8584
}
85+
86+
private string myWebContentPath()
87+
{
88+
string exePath = Path.GetDirectoryName(Application.ExecutablePath);
89+
if (!System.Diagnostics.Debugger.IsAttached)
90+
{
91+
// no debugger attached, not developing
92+
return Path.Combine(exePath, "Content", "Web");
93+
}
94+
else
95+
{
96+
return Path.Combine(Directory.GetParent(exePath).FullName, "Source", "RunActivity", "Viewer3D", "WebServices", "Web");
97+
}
98+
}
8699
}
87100
}

0 commit comments

Comments
 (0)