Skip to content

Commit 88cadc9

Browse files
committed
Added CurrentNotch and IntermediateValue to support mouse control with scripted brake controller
1 parent 109f48b commit 88cadc9

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

Source/Orts.Simulation/Common/Scripting/BrakeController.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,21 @@ public float MainReservoirPressureBar()
141141
/// </summary>
142142
public float CurrentValue() => Host.CurrentValue;
143143

144+
/// <summary>
145+
/// Intermediate value of the brake controller
146+
/// </summary>
147+
public float IntermediateValue
148+
{
149+
get
150+
{
151+
return Host.IntermediateValue;
152+
}
153+
set
154+
{
155+
Host.IntermediateValue = value;
156+
}
157+
}
158+
144159
/// <summary>
145160
/// Minimum value of the brake controller
146161
/// </summary>
@@ -171,6 +186,21 @@ public float MainReservoirPressureBar()
171186
/// </summary>
172187
public float CruiseControlBrakeDemand() => Locomotive.CruiseControl != null ? Locomotive.CruiseControl.TrainBrakePercent/100 : 0;
173188

189+
/// <summary>
190+
/// Current notch of the brake controller
191+
/// </summary>
192+
public int CurrentNotch
193+
{
194+
get
195+
{
196+
return Host.CurrentNotch;
197+
}
198+
set
199+
{
200+
Host.CurrentNotch = value;
201+
}
202+
}
203+
174204
/// <summary>
175205
/// Sets the current value of the brake controller lever
176206
/// </summary>

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Controllers/BrakeController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ public bool OverchargeButtonPressed
155155
/// <summary>
156156
/// Needed for proper mouse operation in the cabview
157157
/// </summary>
158-
public float IntermediateValue { get { return Script is MSTSBrakeController ? (Script as MSTSBrakeController).NotchController.IntermediateValue : CurrentValue; } }
158+
public float IntermediateValue { get; set; }
159159

160160
/// <summary>
161161
/// Knowing actual notch and its change is needed for proper repeatability of mouse and RailDriver operation
162162
/// </summary>
163-
public int CurrentNotch { get { return Script is MSTSBrakeController ? (Script as MSTSBrakeController).NotchController.CurrentNotch : 0; } set { } }
163+
public int CurrentNotch { get; set; }
164164

165165
public ControllerState TrainBrakeControllerState
166166
{

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Controllers/MSTSBrakeController.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
1717

18-
using ORTS.Scripting.Api;
1918
using System;
20-
using System.Diagnostics;
19+
using ORTS.Scripting.Api;
2120

2221
namespace Orts.Simulation.RollingStocks.SubSystems.Controllers
2322
{
@@ -61,13 +60,16 @@ public override void InitializeMoving()
6160
NotchController.SetValue(0);
6261
if (NotchController.NotchCount() > 0) NotchController.CurrentNotch = 0;
6362
else NotchController.CurrentNotch = -1;
63+
CurrentNotch = NotchController.CurrentNotch;
6464
}
6565

6666
public override float Update(float elapsedSeconds)
6767
{
6868
float value = NotchController.Update(elapsedSeconds);
6969
SetCurrentValue(value);
70+
IntermediateValue = NotchController.IntermediateValue;
7071
SetUpdateValue(NotchController.UpdateValue);
72+
CurrentNotch = NotchController.CurrentNotch;
7173
return value;
7274
}
7375

0 commit comments

Comments
 (0)