Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/OpenBVE/Graphics/Renderer/Touch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,13 @@ internal static bool MoveCheck(Vector2 Point, out Cursor.Status Status)
{
switch (TouchElement.Command)
{
case Translations.Command.SinglePower:
case Translations.Command.PowerIncrease:
case Translations.Command.BrakeIncrease:
case Translations.Command.ReverserForward:
Status = Cursor.Status.Plus;
break;
case Translations.Command.SingleBrake:
case Translations.Command.PowerDecrease:
case Translations.Command.BrakeDecrease:
case Translations.Command.ReverserBackward:
Expand Down
4 changes: 4 additions & 0 deletions source/OpenBVE/OldCode/TrainManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ internal static void ParsePanelConfig(string TrainPath, System.Text.Encoding Enc
a.Objects[i].ObjectIndex = ObjectManager.CreateDynamicObject();
}
Train.Cars[Train.DriverCar].CarSections[0].Groups[0].Elements = a.Objects;
if (Interface.CurrentOptions.PanelAnimatedExtendedMode)
{
PanelAnimatedXmlParser.CreateTouchElementForExtendedMode(Train.Cars[Train.DriverCar].CarSections[0], Train);
}
Train.Cars[Train.DriverCar].CameraRestrictionMode = Camera.RestrictionMode.NotAvailable;
World.CameraRestriction = Camera.RestrictionMode.NotAvailable;
World.UpdateViewingDistances();
Expand Down
40 changes: 34 additions & 6 deletions source/OpenBVE/Parsers/Panel/Panel2CfgParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -919,22 +919,50 @@ internal static void ParsePanel2Config(string PanelFile, string TrainPath, Syste
{
if (wday >= Interface.CurrentOptions.Panel2ExtendedMinSize && Interval >= Interface.CurrentOptions.Panel2ExtendedMinSize)
{
Vector2[] Positions = new Vector2[2];
Positions[0] = new Vector2(LocationX, LocationY);
Positions[1] = new Vector2(LocationX, LocationY + Interval / 2.0);
Vector2 Size = new Vector2(wday, Interval / 2.0);
Translations.Command[] Commands = new Translations.Command[2];

if (Subject == "power")
{
PanelXmlParser.CreateTouchElement(Train.Cars[Car].CarSections[0].Groups[GroupIndex], new Vector2(LocationX, LocationY), new Vector2(wday, Interval / 2.0), GroupIndex - 1, -1, Translations.Command.PowerDecrease, 0, new Vector2(0.5, 0.5), PanelResolution, PanelBottom, PanelCenter, Train.Cars[Car].Driver);
PanelXmlParser.CreateTouchElement(Train.Cars[Car].CarSections[0].Groups[GroupIndex], new Vector2(LocationX, LocationY + Interval / 2.0), new Vector2(wday, Interval / 2.0), GroupIndex - 1, -1, Translations.Command.PowerIncrease, 0, new Vector2(0.5, 0.5), PanelResolution, PanelBottom, PanelCenter, Train.Cars[Car].Driver);
if (Train.Handles.SingleHandle)
{
Commands[0] = Translations.Command.SingleBrake;
Commands[1] = Translations.Command.SinglePower;
}
else
{
Commands[0] = Translations.Command.PowerDecrease;
Commands[1] = Translations.Command.PowerIncrease;
}
}

if (Subject == "brake")
{
PanelXmlParser.CreateTouchElement(Train.Cars[Car].CarSections[0].Groups[GroupIndex], new Vector2(LocationX, LocationY), new Vector2(wday, Interval / 2.0), GroupIndex - 1, -1, Translations.Command.BrakeIncrease, 0, new Vector2(0.5, 0.5), PanelResolution, PanelBottom, PanelCenter, Train.Cars[Car].Driver);
PanelXmlParser.CreateTouchElement(Train.Cars[Car].CarSections[0].Groups[GroupIndex], new Vector2(LocationX, LocationY + Interval / 2.0), new Vector2(wday, Interval / 2.0), GroupIndex - 1, -1, Translations.Command.BrakeDecrease, 0, new Vector2(0.5, 0.5), PanelResolution, PanelBottom, PanelCenter, Train.Cars[Car].Driver);
if (Train.Handles.SingleHandle)
{
Commands[0] = Translations.Command.SingleBrake;
Commands[1] = Translations.Command.SinglePower;
}
else
{
Commands[0] = Translations.Command.BrakeIncrease;
Commands[1] = Translations.Command.BrakeDecrease;
}
}

if (Subject == "reverser")
{
PanelXmlParser.CreateTouchElement(Train.Cars[Car].CarSections[0].Groups[GroupIndex], new Vector2(LocationX, LocationY), new Vector2(wday, Interval / 2.0), GroupIndex - 1, -1, Translations.Command.ReverserForward, 0, new Vector2(0.5, 0.5), PanelResolution, PanelBottom, PanelCenter, Train.Cars[Car].Driver);
PanelXmlParser.CreateTouchElement(Train.Cars[Car].CarSections[0].Groups[GroupIndex], new Vector2(LocationX, LocationY + Interval / 2.0), new Vector2(wday, Interval / 2.0), GroupIndex - 1, -1, Translations.Command.ReverserBackward, 0, new Vector2(0.5, 0.5), PanelResolution, PanelBottom, PanelCenter, Train.Cars[Car].Driver);
Commands[0] = Translations.Command.ReverserForward;
Commands[1] = Translations.Command.ReverserBackward;
}

if (Commands[0] != Translations.Command.None && Commands[1] != Translations.Command.None)
{
PanelXmlParser.CreateTouchElement(Train.Cars[Car].CarSections[0].Groups[GroupIndex], Positions[0], Size, GroupIndex - 1, -1, Commands[0], 0, new Vector2(0.5, 0.5), PanelResolution, PanelBottom, PanelCenter, Train.Cars[Car].Driver);
PanelXmlParser.CreateTouchElement(Train.Cars[Car].CarSections[0].Groups[GroupIndex], Positions[1], Size, GroupIndex - 1, -1, Commands[1], 0, new Vector2(0.5, 0.5), PanelResolution, PanelBottom, PanelCenter, Train.Cars[Car].Driver);
}
}
}
Expand Down
154 changes: 146 additions & 8 deletions source/OpenBVE/Parsers/Panel/PanelAnimatedXmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Xml.Linq;
using OpenBveApi;
using OpenBveApi.Colors;
using OpenBveApi.FunctionScripting;
using OpenBveApi.Interface;
using OpenBveApi.Math;
using OpenBveApi.Objects;
Expand Down Expand Up @@ -251,19 +252,156 @@ private static void ParsePanelAnimatedNode(XElement Element, string FileName, Sy
}
}

internal static void CreateTouchElementForExtendedMode(TrainManager.CarSection CarSection, TrainManager.Train Train)
{
Array.Resize(ref CarSection.Groups, 2);
CarSection.Groups[1] = new TrainManager.ElementsGroup
{
Elements = new ObjectManager.AnimatedObject[] { },
Overlay = true
};
foreach (var Element in CarSection.Groups[0].Elements)
{
FunctionType Type;
if (CheckTouchFunctions(Element, out Type))
{
if (Element.States != null && Element.States.Any())
{
Vector3[] Positions = new Vector3[2];
Positions[0] = Element.States[0].Position + new Vector3(0.0, 0.0, Interface.CurrentOptions.PanelAnimatedExtendedSize / 2.0);
Positions[1] = Element.States[0].Position - new Vector3(0.0, 0.0, Interface.CurrentOptions.PanelAnimatedExtendedSize / 2.0);
Vector3 Size = new Vector3(Interface.CurrentOptions.PanelAnimatedExtendedSize, Interface.CurrentOptions.PanelAnimatedExtendedSize, Interface.CurrentOptions.PanelAnimatedExtendedSize / 2.0);
Translations.Command[] Commands = new Translations.Command[2];
switch (Type)
{
case FunctionType.Power:
if (Train.Handles.SingleHandle)
{
Commands[0] = Translations.Command.SingleBrake;
Commands[1] = Translations.Command.SinglePower;
}
else
{
Commands[0] = Translations.Command.PowerDecrease;
Commands[1] = Translations.Command.PowerIncrease;
}
break;
case FunctionType.Brake:
if (Train.Handles.SingleHandle)
{
Commands[0] = Translations.Command.SingleBrake;
Commands[1] = Translations.Command.SinglePower;
}
else
{
Commands[0] = Translations.Command.BrakeIncrease;
Commands[1] = Translations.Command.BrakeDecrease;
}
break;
case FunctionType.Reverser:
Commands[0] = Translations.Command.ReverserForward;
Commands[1] = Translations.Command.ReverserBackward;
break;
}
CreateTouchElement(CarSection.Groups[1], Positions[0], Size, 0, -1, Commands[0], 0);
CreateTouchElement(CarSection.Groups[1], Positions[1], Size, 0, -1, Commands[1], 0);
}
}
}
}

private enum FunctionType
{
None,
Power,
Brake,
Reverser
}

private static bool CheckTouchFunctions(ObjectManager.AnimatedObject Element, out FunctionType Type)
{
if (CheckTouchFunction(Element.StateFunction, out Type))
{
return true;
}
if (CheckTouchFunction(Element.TranslateXFunction, out Type))
{
return true;
}
if (CheckTouchFunction(Element.TranslateYFunction, out Type))
{
return true;
}
if (CheckTouchFunction(Element.TranslateZFunction, out Type))
{
return true;
}
if (CheckTouchFunction(Element.RotateXFunction, out Type))
{
return true;
}
if (CheckTouchFunction(Element.RotateYFunction, out Type))
{
return true;
}
if (CheckTouchFunction(Element.RotateZFunction, out Type))
{
return true;
}
if (CheckTouchFunction(Element.TextureShiftXFunction, out Type))
{
return true;
}
if (CheckTouchFunction(Element.TextureShiftYFunction, out Type))
{
return true;
}
if (CheckTouchFunction(Element.LEDFunction, out Type))
{
return true;
}
Type = FunctionType.None;
return false;
}

private static bool CheckTouchFunction(FunctionScript Function, out FunctionType Type)
{
if (Function != null)
{
foreach (var Instruction in Function.InstructionSet)
{
switch (Instruction)
{
case Instructions.PowerNotch:
Type = FunctionType.Power;
return true;
case Instructions.BrakeNotch:
case Instructions.BrakeNotchLinear:
Type = FunctionType.Brake;
return true;
case Instructions.ReverserNotch:
Type = FunctionType.Reverser;
return true;
}
}
}
Type = FunctionType.None;
return false;
}

private static void CreateTouchElement(TrainManager.ElementsGroup Group, Vector3 Position, Vector3 Size, int ScreenIndex, int SoundIndex, Translations.Command Command, int CommandOption)
{
Vertex t0 = new Vertex(Size.X, Size.Y, -Size.Z);
Vertex t1 = new Vertex(Size.X, -Size.Y, -Size.Z);
Vertex t2 = new Vertex(-Size.X, -Size.Y, -Size.Z);
Vertex t3 = new Vertex(-Size.X, Size.Y, -Size.Z);
Vertex t4 = new Vertex(Size.X, Size.Y, Size.Z);
Vertex t5 = new Vertex(Size.X, -Size.Y, Size.Z);
Vertex t6 = new Vertex(-Size.X, -Size.Y, Size.Z);
Vertex t7 = new Vertex(-Size.X, Size.Y, Size.Z);
Vertex t1 = new Vertex(Size.X, -Size.Y, -Size.Z);
Vertex t2 = new Vertex(-Size.X, -Size.Y, -Size.Z);
Vertex t3 = new Vertex(-Size.X, Size.Y, -Size.Z);
Vertex t4 = new Vertex(Size.X, Size.Y, Size.Z);
Vertex t5 = new Vertex(Size.X, -Size.Y, Size.Z);
Vertex t6 = new Vertex(-Size.X, -Size.Y, Size.Z);
Vertex t7 = new Vertex(-Size.X, Size.Y, Size.Z);
ObjectManager.StaticObject Object = new ObjectManager.StaticObject();
Object.Mesh.Vertices = new VertexTemplate[] { t0, t1, t2, t3, t4, t5, t6, t7 };
Object.Mesh.Faces = new MeshFace[] { new MeshFace(new int[] { 0, 1, 2, 3 }), new MeshFace(new int[] { 0, 4, 5, 1 }), new MeshFace(new int[] { 0, 3, 7, 4 }), new MeshFace(new int[] { 6, 5, 4, 7 }), new MeshFace(new int[] { 6, 7, 3, 2 }), new MeshFace(new int[] { 6, 2, 1, 5 }) };
Object.Mesh.Faces = new MeshFace[] { new MeshFace(new int[] { 0, 1, 2, 3 }), new MeshFace(new int[] { 0, 4, 5, 1 }), new MeshFace(new int[] { 0, 3, 7, 4 }), new MeshFace(new int[] { 6, 5, 4, 7 }), new MeshFace(new int[] { 6, 7, 3, 2 }), new MeshFace(new int[] { 6, 2, 1, 5 }) };
Object.Mesh.Materials = new MeshMaterial[1];
Object.Mesh.Materials[0].Flags = 0;
Object.Mesh.Materials[0].Color = Color32.White;
Expand Down
15 changes: 15 additions & 0 deletions source/OpenBVE/System/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ internal class Options
internal string CursorFileName;
internal bool Panel2ExtendedMode;
internal int Panel2ExtendedMinSize;
internal bool PanelAnimatedExtendedMode;
internal double PanelAnimatedExtendedSize;

internal XParsers CurrentXParser;
internal ObjParsers CurrentObjParser;
Expand Down Expand Up @@ -278,6 +280,8 @@ internal Options()
this.CursorFileName = "nk.png";
this.Panel2ExtendedMode = false;
this.Panel2ExtendedMinSize = 128;
this.PanelAnimatedExtendedMode = false;
this.PanelAnimatedExtendedSize = 0.050;
this.CurrentXParser = XParsers.Original; //Set to Michelle's original X parser by default
this.CurrentObjParser = ObjParsers.Original; //Set to original Obj parser by default
}
Expand Down Expand Up @@ -812,6 +816,15 @@ internal static void LoadOptions()
int.TryParse(Value, NumberStyles.Integer, Culture, out a);
Interface.CurrentOptions.Panel2ExtendedMinSize = a;
} break;
case "panelanimatedextended":
Interface.CurrentOptions.PanelAnimatedExtendedMode = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
case "panelanimatedextendedsize":
{
double a;
double.TryParse(Value, NumberStyles.Float, Culture, out a);
Interface.CurrentOptions.PanelAnimatedExtendedSize = a;
} break;
}
break;
}
Expand Down Expand Up @@ -1034,6 +1047,8 @@ internal static void SaveOptions()
Builder.AppendLine("cursor = " + CurrentOptions.CursorFileName);
Builder.AppendLine("panel2extended = " + (CurrentOptions.Panel2ExtendedMode ? "true" : "false"));
Builder.AppendLine("panel2extendedminsize = " + CurrentOptions.Panel2ExtendedMinSize.ToString(Culture));
Builder.AppendLine("panelanimatedextended = " + (CurrentOptions.PanelAnimatedExtendedMode ? "true" : "false"));
Builder.AppendLine("panelanimatedextendedsize = " + CurrentOptions.PanelAnimatedExtendedSize.ToString(Culture));
string File = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "1.5.0/options.cfg");
System.IO.File.WriteAllText(File, Builder.ToString(), new System.Text.UTF8Encoding(true));
}
Expand Down