17
17
//
18
18
19
19
using System . Collections . Generic ;
20
+ using Orts . Simulation . RollingStocks ;
20
21
using ORTS . Common . Input ;
22
+ using ORTS . Settings ;
21
23
22
24
namespace Orts . Viewer3D . WebServices . SwitchPanel
23
25
{
24
26
public class SwitchOnPanelDefinition
25
27
{
28
+ private readonly Viewer Viewer ;
29
+
26
30
public int NoOffButtons = 0 ;
27
- public TypeOfButton Button = TypeOfButton . none ;
28
31
public UserCommand [ ] UserCommand = { ORTS . Common . Input . UserCommand . GamePauseMenu } ;
29
32
public string Description = "" ;
30
33
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
+ }
32
172
33
173
public override bool Equals ( object obj )
34
174
{
@@ -54,14 +194,12 @@ public override bool Equals(object obj)
54
194
}
55
195
}
56
196
57
- return ( ( SwitchOnPanelDefinition ) obj ) . Button == Button &&
58
- ( ( SwitchOnPanelDefinition ) obj ) . Description == Description ;
197
+ return ( ( SwitchOnPanelDefinition ) obj ) . Description == Description ;
59
198
}
60
199
61
200
public static void deepCopy ( SwitchOnPanelDefinition to , SwitchOnPanelDefinition from )
62
201
{
63
202
to . NoOffButtons = from . NoOffButtons ;
64
- to . Button = from . Button ;
65
203
to . Description = from . Description ;
66
204
67
205
to . UserCommand = new UserCommand [ from . NoOffButtons ] ;
@@ -75,7 +213,6 @@ public override int GetHashCode()
75
213
{
76
214
var hashCode = 1410623761 ;
77
215
hashCode = hashCode * - 1521134295 + NoOffButtons . GetHashCode ( ) ;
78
- hashCode = hashCode * - 1521134295 + Button . GetHashCode ( ) ;
79
216
hashCode = hashCode * - 1521134295 + EqualityComparer < UserCommand [ ] > . Default . GetHashCode ( UserCommand ) ;
80
217
hashCode = hashCode * - 1521134295 + EqualityComparer < string > . Default . GetHashCode ( Description ) ;
81
218
return hashCode ;
0 commit comments