diff --git a/source/OpenBVE/Graphics/Renderer/Touch.cs b/source/OpenBVE/Graphics/Renderer/Touch.cs index 1179c45b2e..d7fbbd5c0d 100644 --- a/source/OpenBVE/Graphics/Renderer/Touch.cs +++ b/source/OpenBVE/Graphics/Renderer/Touch.cs @@ -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: diff --git a/source/OpenBVE/OldCode/TrainManager.cs b/source/OpenBVE/OldCode/TrainManager.cs index 8014fa644c..d2a54ed42e 100644 --- a/source/OpenBVE/OldCode/TrainManager.cs +++ b/source/OpenBVE/OldCode/TrainManager.cs @@ -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(); diff --git a/source/OpenBVE/Parsers/Panel/Panel2CfgParser.cs b/source/OpenBVE/Parsers/Panel/Panel2CfgParser.cs index b28a296954..f4a7afd20d 100644 --- a/source/OpenBVE/Parsers/Panel/Panel2CfgParser.cs +++ b/source/OpenBVE/Parsers/Panel/Panel2CfgParser.cs @@ -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); } } } diff --git a/source/OpenBVE/Parsers/Panel/PanelAnimatedXmlParser.cs b/source/OpenBVE/Parsers/Panel/PanelAnimatedXmlParser.cs index 92caa64394..a73c66897b 100644 --- a/source/OpenBVE/Parsers/Panel/PanelAnimatedXmlParser.cs +++ b/source/OpenBVE/Parsers/Panel/PanelAnimatedXmlParser.cs @@ -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; @@ -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; diff --git a/source/OpenBVE/System/Options.cs b/source/OpenBVE/System/Options.cs index 0f6515c2aa..0d35f83022 100644 --- a/source/OpenBVE/System/Options.cs +++ b/source/OpenBVE/System/Options.cs @@ -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; @@ -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 } @@ -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; } @@ -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)); }