Skip to content

Commit

Permalink
Automatic merge of T1.5-rc3-94-gf59d2015d and 15 pull requests
Browse files Browse the repository at this point in the history
- Pull request #630 at 704731a: Sky Color Fix (Addresses Trello Roadmap Card #367 for More accurate sunrise and sunset)
- Pull request #652 at 918fdb1: Add button functions to Raildriver
- Pull request #706 at 570ab21: Extended door functionality
- Pull request #713 at 4c52f58: https://blueprints.launchpad.net/or/+spec/cruise-control 
- Pull request #719 at 56d183c: Upgraded to MonoGame 3.8.0 (+ small update for other libraries)
- Pull request #722 at fb9079e: Fix Windows Forms deprecations in ActivityEditor
- Pull request #732 at 9cffa6d: Improvements for air brakes
- Pull request #733 at 72947b0: Fixed battery switch sound being repeted
- Pull request #734 at 8f8484c: Fixed battery switch timer not working properly
- Pull request #736 at a845085: Replaced truncated brake token table with lists
- Pull request #740 at b3e66ca: Refactored the circuit breaker and the traction cut-off relay in order to use the same design pattern as the C# signal scripts (compatible with current scripts)
- Pull request #741 at 2dd56ad: Fixed brake controller script not being loaded in timetable mode
- Pull request #742 at 48c1ac2: Update of Russian Locales 'Oct 2022
- Pull request #743 at 809cb6e: Default filename for include statements 
- Pull request #744 at 3c2dc07: Fixed and improved cabview control conditions related to power supply state
  • Loading branch information
openrails-bot committed Nov 7, 2022
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 34 deletions.
29 changes: 29 additions & 0 deletions Source/Orts.Formats.Msts/CabViewFile.cs
Expand Up @@ -457,6 +457,8 @@ public class CabViewControl

public bool DisabledIfLowVoltagePowerSupplyOff { get; private set; } = false;
public bool DisabledIfCabPowerSupplyOff { get; private set; } = false;
public bool HideIfDisabled { get; private set; } = true;
public float? ValueIfDisabled { get; private set; }

protected void ParseType(STFReader stf)
{
Expand Down Expand Up @@ -540,14 +542,27 @@ protected void ParseUnits(STFReader stf)
}
stf.SkipRestOfBlock();
}

protected void ParseDisabledIfLowVoltagePowerSupplyOff(STFReader stf)
{
DisabledIfLowVoltagePowerSupplyOff = stf.ReadBoolBlock(false);
}

protected void ParseDisabledIfCabPowerSupplyOff(STFReader stf)
{
DisabledIfCabPowerSupplyOff = stf.ReadBoolBlock(false);
}

protected void ParseHideIfDisabled(STFReader stf)
{
HideIfDisabled = stf.ReadBoolBlock(true);
}

protected void ParseValueIfDisabled(STFReader stf)
{
ValueIfDisabled = stf.ReadFloatBlock(STFReader.UNITS.None, 0f);
}

// Used by subclasses CVCGauge and CVCDigital
protected virtual color ParseControlColor( STFReader stf )
{
Expand Down Expand Up @@ -638,6 +653,8 @@ public CVCDial(STFReader stf, string basepath)
new STFReader.TokenProcessor("units", ()=>{ ParseUnits(stf); }),
new STFReader.TokenProcessor("disablediflowvoltagepowersupplyoff", ()=>{ ParseDisabledIfLowVoltagePowerSupplyOff(stf); }),
new STFReader.TokenProcessor("disabledifcabpowersupplyoff", ()=>{ ParseDisabledIfCabPowerSupplyOff(stf); }),
new STFReader.TokenProcessor("hideifdisabled", ()=>{ ParseHideIfDisabled(stf); }),
new STFReader.TokenProcessor("valueifdisabled", ()=>{ ParseValueIfDisabled(stf); }),

new STFReader.TokenProcessor("pivot", ()=>{ Center = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
new STFReader.TokenProcessor("dirincrease", ()=>{ Direction = stf.ReadIntBlock(null); }),
Expand Down Expand Up @@ -692,6 +709,8 @@ public CVCGauge(STFReader stf, string basepath)
new STFReader.TokenProcessor("units", ()=>{ ParseUnits(stf); }),
new STFReader.TokenProcessor("disablediflowvoltagepowersupplyoff", ()=>{ ParseDisabledIfLowVoltagePowerSupplyOff(stf); }),
new STFReader.TokenProcessor("disabledifcabpowersupplyoff", ()=>{ ParseDisabledIfCabPowerSupplyOff(stf); }),
new STFReader.TokenProcessor("hideifdisabled", ()=>{ ParseHideIfDisabled(stf); }),
new STFReader.TokenProcessor("valueifdisabled", ()=>{ ParseValueIfDisabled(stf); }),

new STFReader.TokenProcessor("zeropos", ()=>{ ZeroPos = stf.ReadIntBlock(null); }),
new STFReader.TokenProcessor("orientation", ()=>{ Orientation = stf.ReadIntBlock(null); }),
Expand Down Expand Up @@ -831,6 +850,8 @@ public CVCDigital(STFReader stf, string basepath)
new STFReader.TokenProcessor("units", ()=>{ ParseUnits(stf); }),
new STFReader.TokenProcessor("disablediflowvoltagepowersupplyoff", ()=>{ ParseDisabledIfLowVoltagePowerSupplyOff(stf); }),
new STFReader.TokenProcessor("disabledifcabpowersupplyoff", ()=>{ ParseDisabledIfCabPowerSupplyOff(stf); }),
new STFReader.TokenProcessor("hideifdisabled", ()=>{ ParseHideIfDisabled(stf); }),
new STFReader.TokenProcessor("valueifdisabled", ()=>{ ParseValueIfDisabled(stf); }),
new STFReader.TokenProcessor("leadingzeros", ()=>{ ParseLeadingZeros(stf); }),
new STFReader.TokenProcessor("accuracy", ()=>{ ParseAccuracy(stf); }),
new STFReader.TokenProcessor("accuracyswitch", ()=>{ ParseAccuracySwitch(stf); }),
Expand Down Expand Up @@ -937,6 +958,8 @@ public CVCDigitalClock(STFReader stf, string basepath)
new STFReader.TokenProcessor("style", ()=>{ ParseStyle(stf); }),
new STFReader.TokenProcessor("disablediflowvoltagepowersupplyoff", ()=>{ ParseDisabledIfLowVoltagePowerSupplyOff(stf); }),
new STFReader.TokenProcessor("disabledifcabpowersupplyoff", ()=>{ ParseDisabledIfCabPowerSupplyOff(stf); }),
new STFReader.TokenProcessor("hideifdisabled", ()=>{ ParseHideIfDisabled(stf); }),
new STFReader.TokenProcessor("valueifdisabled", ()=>{ ParseValueIfDisabled(stf); }),
new STFReader.TokenProcessor("accuracy", ()=>{ ParseAccuracy(stf); }),
new STFReader.TokenProcessor("controlcolour", ()=>{ PositiveColor = ParseControlColor(stf); }),
new STFReader.TokenProcessor("ortsfont", ()=>{ParseFont(stf); }),
Expand Down Expand Up @@ -1002,6 +1025,8 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
new STFReader.TokenProcessor("units", ()=>{ ParseUnits(stf); }),
new STFReader.TokenProcessor("disablediflowvoltagepowersupplyoff", ()=>{ ParseDisabledIfLowVoltagePowerSupplyOff(stf); }),
new STFReader.TokenProcessor("disabledifcabpowersupplyoff", ()=>{ ParseDisabledIfCabPowerSupplyOff(stf); }),
new STFReader.TokenProcessor("hideifdisabled", ()=>{ ParseHideIfDisabled(stf); }),
new STFReader.TokenProcessor("valueifdisabled", ()=>{ ParseValueIfDisabled(stf); }),
new STFReader.TokenProcessor("mousecontrol", ()=>{ MouseControl = stf.ReadBoolBlock(false); }),
new STFReader.TokenProcessor("orientation", ()=>{ Orientation = stf.ReadIntBlock(null); }),
new STFReader.TokenProcessor("dirincrease", ()=>{ Direction = stf.ReadIntBlock(null); }),
Expand Down Expand Up @@ -1353,6 +1378,8 @@ public CVCMultiStateDisplay(STFReader stf, string basepath)
new STFReader.TokenProcessor("units", ()=>{ ParseUnits(stf); }),
new STFReader.TokenProcessor("disablediflowvoltagepowersupplyoff", ()=>{ ParseDisabledIfLowVoltagePowerSupplyOff(stf); }),
new STFReader.TokenProcessor("disabledifcabpowersupplyoff", ()=>{ ParseDisabledIfCabPowerSupplyOff(stf); }),
new STFReader.TokenProcessor("hideifdisabled", ()=>{ ParseHideIfDisabled(stf); }),
new STFReader.TokenProcessor("valueifdisabled", ()=>{ ParseValueIfDisabled(stf); }),

new STFReader.TokenProcessor("states", ()=>{
stf.MustMatch("(");
Expand Down Expand Up @@ -1458,6 +1485,8 @@ public CVCScreen(STFReader stf, string basepath)
new STFReader.TokenProcessor("parameters", ()=>{ ParseCustomParameters(stf); }),
new STFReader.TokenProcessor("disablediflowvoltagepowersupplyoff", ()=>{ ParseDisabledIfLowVoltagePowerSupplyOff(stf); }),
new STFReader.TokenProcessor("disabledifcabpowersupplyoff", ()=>{ ParseDisabledIfCabPowerSupplyOff(stf); }),
new STFReader.TokenProcessor("hideifdisabled", ()=>{ ParseHideIfDisabled(stf); }),
new STFReader.TokenProcessor("valueifdisabled", ()=>{ ParseValueIfDisabled(stf); }),
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
Expand Down
87 changes: 58 additions & 29 deletions Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs
Expand Up @@ -1617,7 +1617,13 @@ public CABViewControlTypes GetControlType()
/// <returns>Data value as fraction (from 0 to 1) of the range between Min and Max values</returns>
public float GetRangeFraction(bool offsetFromZero = false)
{
var data = Locomotive.GetDataOf(Control);
float data;

if (!IsPowered && Control.ValueIfDisabled != null)
data = (float)Control.ValueIfDisabled;
else
data = Locomotive.GetDataOf(Control);

if (data < Control.MinValue)
return 0;
if (data > Control.MaxValue)
Expand All @@ -1637,9 +1643,7 @@ public CABViewControlStyles GetStyle()
[CallOnThread("Updater")]
public virtual void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
{
var noPower = (Control.DisabledIfLowVoltagePowerSupplyOff && !Locomotive.LocomotivePowerSupply.LowVoltagePowerSupplyOn)
|| (Control.DisabledIfCabPowerSupplyOff && !Locomotive.LocomotivePowerSupply.CabPowerSupplyOn);
if (noPower)
if (!IsPowered && Control.HideIfDisabled)
return;

frame.AddPrimitive(ControlView, this, RenderPrimitiveGroup.Cab, ref Matrix);
Expand Down Expand Up @@ -1803,7 +1807,10 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
float percent, xpos, ypos, zeropos;

percent = IsFire ? 1f : GetRangeFraction();
// LoadMeterPositive = percent + Gauge.MinValue / (Gauge.MaxValue - Gauge.MinValue) >= 0;

if (!IsPowered && Control.ValueIfDisabled != null)
Num = (float)Control.ValueIfDisabled;
else
Num = Locomotive.GetDataOf(Control);

if (Gauge.Orientation == 0) // gauge horizontal
Expand Down Expand Up @@ -2051,7 +2058,12 @@ public override void Draw(GraphicsDevice graphicsDevice)
/// <returns>index of the Texture</returns>
public virtual int GetDrawIndex()
{
var data = Locomotive.GetDataOf(Control);
float data;

if (!IsPowered && Control.ValueIfDisabled != null)
data = (float)Control.ValueIfDisabled;
else
data = Locomotive.GetDataOf(Control);

var index = OldFrameIndex;
switch (ControlDiscrete.ControlType)
Expand Down Expand Up @@ -2898,7 +2910,14 @@ public CabViewAnimationsRenderer(Viewer viewer, MSTSLocomotive locomotive, CVCAn

public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
{
var animate = Locomotive.GetDataOf(Control) != 0;
float data;

if (!IsPowered && Control.ValueIfDisabled != null)
data = (float)Control.ValueIfDisabled;
else
data = Locomotive.GetDataOf(Control);

var animate = data != 0;
if (animate)
AnimationOn = true;

Expand Down Expand Up @@ -2976,7 +2995,11 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
{
var digital = Control as CVCDigital;

if (!IsPowered && Control.ValueIfDisabled != null)
Num = (float)Control.ValueIfDisabled;
else
Num = Locomotive.GetDataOf(Control);

if (digital.MinValue < digital.MaxValue) Num = MathHelper.Clamp(Num, (float)digital.MinValue, (float)digital.MaxValue);
if (Math.Abs(Num) < digital.AccuracySwitch)
Format = Format2;
Expand Down Expand Up @@ -3057,7 +3080,12 @@ public string GetDigits(out Color DrawColor)
{
var digital = Control as CVCDigital;
string displayedText = "";

if (!IsPowered && Control.ValueIfDisabled != null)
Num = (float)Control.ValueIfDisabled;
else
Num = Locomotive.GetDataOf(Control);

if (Math.Abs(Num) < digital.AccuracySwitch)
Format = Format2;
else
Expand Down Expand Up @@ -3130,7 +3158,12 @@ public string GetDigits(out Color DrawColor)
{
var digital = Control as CVCDigital;
string displayedText = "";

if (!IsPowered && Control.ValueIfDisabled != null)
Num = (float)Control.ValueIfDisabled;
else
Num = Locomotive.GetDataOf(Control);

if (digital.MinValue < digital.MaxValue) Num = MathHelper.Clamp(Num, (float)digital.MinValue, (float)digital.MaxValue);
if (Math.Abs(Num) < digital.AccuracySwitch)
Format = Format2;
Expand Down Expand Up @@ -3367,11 +3400,6 @@ public override void HandleUserInput(ElapsedTime elapsedTime)
/// </summary>
public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
{
var trainCarShape = LocoViewer.ThreeDimentionCabViewer.TrainCarShape;
var animatedParts = LocoViewer.ThreeDimentionCabViewer.AnimateParts;
var controlMap = LocoViewer.ThreeDimentionCabRenderer.ControlMap;
var doShow = true;
CabViewControlRenderer cabRenderer;
foreach (var p in AnimateParts)
{
if (p.Value.Type >= CABViewControlTypes.EXTERNALWIPERS) //for wipers, doors and mirrors
Expand Down Expand Up @@ -3410,32 +3438,31 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
}
else
{
doShow = true;
cabRenderer = null;
if (LocoViewer.ThreeDimentionCabRenderer.ControlMap.TryGetValue(p.Key, out cabRenderer))
var doShow = true;
if (LocoViewer.ThreeDimentionCabRenderer.ControlMap.TryGetValue(p.Key, out var cabRenderer))
{
if (cabRenderer is CabViewDiscreteRenderer)
if (!cabRenderer.IsPowered && cabRenderer.Control.HideIfDisabled)
{
doShow = false;
}
else if (cabRenderer is CabViewDiscreteRenderer)
{
var control = cabRenderer.Control;
if (control.Screens != null && control.Screens[0] != "all")
{
doShow = false;
foreach (var screen in control.Screens)
{
if (LocoViewer.ThreeDimentionCabRenderer.ActiveScreen[control.Display] == screen)
{
doShow = true;
break;
}
}
doShow = control.Screens.Any(screen =>
LocoViewer.ThreeDimentionCabRenderer.ActiveScreen[control.Display] == screen);
}
}
}

foreach (var matrixIndex in p.Value.MatrixIndexes)
MatrixVisible[matrixIndex] = doShow;
p.Value.Update(this.LocoViewer, elapsedTime); //for all other intruments with animations

p.Value.Update(LocoViewer, elapsedTime); //for all other instruments with animations
}
}

foreach (var p in DigitParts3D)
{
var digital = p.Value.CVFR.Control;
Expand All @@ -3453,6 +3480,7 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
}
p.Value.PrepareFrame(frame, elapsedTime);
}

foreach (var p in DPIDisplays3D)
{
var dpdisplay = p.Value.CVFR.Control;
Expand All @@ -3470,6 +3498,7 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
}
p.Value.PrepareFrame(frame, elapsedTime);
}

foreach (var p in Gauges)
{
var gauge = p.Value.CVFR.Control;
Expand Down Expand Up @@ -3776,7 +3805,7 @@ static float GetTextureCoordY(char c)

public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
{
if (!CVFR.IsPowered)
if (!CVFR.IsPowered && CVFR.Control.HideIfDisabled)
return;

UpdateDigit();
Expand Down Expand Up @@ -3995,7 +4024,7 @@ private void UpdateShapePrimitive(Material material)

public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
{
if (!CVFR.IsPowered)
if (!CVFR.IsPowered && CVFR.Control.HideIfDisabled)
return;

UpdateDigit();
Expand Down Expand Up @@ -4041,7 +4070,7 @@ public void Update(MSTSLocomotiveViewer locoViewer, ElapsedTime elapsedTime)
{
if (!locoViewer._has3DCabRenderer) return;

var scale = CVFR.IsPowered ? CVFR.GetRangeFraction() : 0f;
var scale = CVFR.IsPowered || CVFR.Control.ValueIfDisabled == null ? CVFR.GetRangeFraction() : (float)CVFR.Control.ValueIfDisabled;

if (CVFR.GetStyle() == CABViewControlStyles.POINTER)
{
Expand Down
Expand Up @@ -540,7 +540,7 @@ public DistributedPowerInterfaceRenderer(Viewer viewer, MSTSLocomotive locomotiv

public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
{
if (!IsPowered)
if (!IsPowered && Control.HideIfDisabled)
return;

base.PrepareFrame(frame, elapsedTime);
Expand Down Expand Up @@ -974,7 +974,7 @@ static float GetTextureCoordY(string param, int iChar, Color color)

public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
{
if (!CVFR.IsPowered)
if (!CVFR.IsPowered && CVFR.Control.HideIfDisabled)
return;

Update3DDPITable();
Expand All @@ -993,4 +993,4 @@ internal void Mark()
}
} // class ThreeDimCabDPI

}
}
Expand Up @@ -798,7 +798,7 @@ public DriverMachineInterfaceRenderer(Viewer viewer, MSTSLocomotive locomotive,

public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
{
if (!IsPowered)
if (!IsPowered && Control.HideIfDisabled)
return;

base.PrepareFrame(frame, elapsedTime);
Expand Down Expand Up @@ -864,4 +864,4 @@ public override void Draw(GraphicsDevice graphicsDevice)
ControlView.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.Default, null, Shader);
}
}
}
}

0 comments on commit aa6603d

Please sign in to comment.