コード例 #1
0
        public Plugin()
        {
            if (TrainDatParser == null)
            {
                TrainDatParser = new TrainDatParser(this);
            }

            if (ExtensionsCfgParser == null)
            {
                ExtensionsCfgParser = new ExtensionsCfgParser(this);
            }

            if (SoundCfgParser == null)
            {
                SoundCfgParser  = new SoundCfgParser(this);
                BVE2SoundParser = new BVE2SoundParser(this);
                BVE4SoundParser = new BVE4SoundParser(this);
                SoundXmlParser  = new SoundXmlParser(this);
            }

            if (PanelCfgParser == null)
            {
                PanelCfgParser         = new PanelCfgParser(this);
                Panel2CfgParser        = new Panel2CfgParser(this);
                PanelXmlParser         = new PanelXmlParser(this);
                PanelAnimatedXmlParser = new PanelAnimatedXmlParser(this);
            }

            if (TrainXmlParser == null)
            {
                TrainXmlParser = new TrainXmlParser(this);
            }
        }
コード例 #2
0
        /// <summary>Attempts to load and parse the current train's panel configuration file.</summary>
        /// <param name="TrainPath">The absolute on-disk path to the train folder.</param>
        /// <param name="Encoding">The automatically detected or manually set encoding of the panel configuration file.</param>
        /// <param name="Train">The base train on which to apply the panel configuration.</param>
        internal static void ParsePanelConfig(string TrainPath, System.Text.Encoding Encoding, TrainManager.Train Train)
        {
            string File = OpenBveApi.Path.CombineFile(TrainPath, "panel.animated");

            if (System.IO.File.Exists(File))
            {
                Program.AppendToLogFile("Loading train panel: " + File);
                ObjectManager.AnimatedObjectCollection a = AnimatedObjectParser.ReadObject(File, Encoding, ObjectManager.ObjectLoadMode.DontAllowUnloadOfTextures);
                try
                {
                    for (int i = 0; i < a.Objects.Length; i++)
                    {
                        a.Objects[i].ObjectIndex = ObjectManager.CreateDynamicObject();
                    }
                    Train.Cars[Train.DriverCar].CarSections[0].Elements = a.Objects;
                    Train.Cars[Train.DriverCar].CameraRestrictionMode   = World.CameraRestrictionMode.NotAvailable;
                    World.CameraRestriction = World.CameraRestrictionMode.NotAvailable;
                    World.UpdateViewingDistances();
                }
                catch
                {
                    var currentError = Interface.GetInterfaceString("error_critical_file");
                    currentError = currentError.Replace("[file]", "panel.animated");
                    MessageBox.Show(currentError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    Program.RestartArguments = " ";
                    Loading.Cancel           = true;
                }
            }
            else
            {
                var Panel2 = false;
                try
                {
                    File = OpenBveApi.Path.CombineFile(TrainPath, "panel2.cfg");
                    if (System.IO.File.Exists(File))
                    {
                        Program.AppendToLogFile("Loading train panel: " + File);
                        Panel2 = true;
                        Panel2CfgParser.ParsePanel2Config("panel2.cfg", TrainPath, Encoding, Train, Train.DriverCar);
                        Train.Cars[Train.DriverCar].CameraRestrictionMode = World.CameraRestrictionMode.On;
                        World.CameraRestriction = World.CameraRestrictionMode.On;
                    }
                    else
                    {
                        File = OpenBveApi.Path.CombineFile(TrainPath, "panel.cfg");
                        if (System.IO.File.Exists(File))
                        {
                            Program.AppendToLogFile("Loading train panel: " + File);
                            PanelCfgParser.ParsePanelConfig(TrainPath, Encoding, Train);
                            Train.Cars[Train.DriverCar].CameraRestrictionMode = World.CameraRestrictionMode.On;
                            World.CameraRestriction = World.CameraRestrictionMode.On;
                        }
                        else
                        {
                            World.CameraRestriction = World.CameraRestrictionMode.NotAvailable;
                        }
                    }
                }
                catch
                {
                    var currentError = Interface.GetInterfaceString("errors_critical_file");
                    currentError = currentError.Replace("[file]", Panel2 == true ? "panel2.cfg" : "panel.cfg");
                    MessageBox.Show(currentError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    Program.RestartArguments = " ";
                    Loading.Cancel           = true;
                }
            }
        }
コード例 #3
0
        /// <summary>Attempts to load and parse the current train's panel configuration file.</summary>
        /// <param name="TrainPath">The absolute on-disk path to the train folder.</param>
        /// <param name="Encoding">The automatically detected or manually set encoding of the panel configuration file.</param>
        /// <param name="Train">The base train on which to apply the panel configuration.</param>
        internal static void ParsePanelConfig(string TrainPath, System.Text.Encoding Encoding, Train Train)
        {
            Train.Cars[Train.DriverCar].CarSections    = new CarSection[1];
            Train.Cars[Train.DriverCar].CarSections[0] = new CarSection
            {
                Groups = new ElementsGroup[1]
            };
            Train.Cars[Train.DriverCar].CarSections[0].Groups[0] = new ElementsGroup
            {
                Elements = new ObjectManager.AnimatedObject[] { },
                Overlay  = true
            };
            string File = OpenBveApi.Path.CombineFile(TrainPath, "panel.xml");

            if (!System.IO.File.Exists(File))
            {
                //Try animated variant too
                File = OpenBveApi.Path.CombineFile(TrainPath, "panel.animated.xml");
            }
            if (System.IO.File.Exists(File))
            {
                Program.FileSystem.AppendToLogFile("Loading train panel: " + File);
                try
                {
                    /*
                     * First load the XML. We use this to determine
                     * whether this is a 2D or a 3D animated panel
                     */
                    XDocument CurrentXML = XDocument.Load(File, LoadOptions.SetLineInfo);

                    // Check for null
                    if (CurrentXML.Root != null)
                    {
                        IEnumerable <XElement> DocumentElements = CurrentXML.Root.Elements("PanelAnimated");
                        if (DocumentElements.Any())
                        {
                            PanelAnimatedXmlParser.ParsePanelAnimatedXml(System.IO.Path.GetFileName(File), TrainPath, Train, Train.DriverCar);
                            Train.Cars[Train.DriverCar].CameraRestrictionMode = Camera.RestrictionMode.NotAvailable;
                            World.CameraRestriction = Camera.RestrictionMode.NotAvailable;
                        }

                        DocumentElements = CurrentXML.Root.Elements("Panel");
                        if (DocumentElements.Any())
                        {
                            PanelXmlParser.ParsePanelXml(System.IO.Path.GetFileName(File), TrainPath, Train, Train.DriverCar);
                            Train.Cars[Train.DriverCar].CameraRestrictionMode = Camera.RestrictionMode.On;
                            World.CameraRestriction = Camera.RestrictionMode.On;
                        }
                    }
                }
                catch
                {
                    var currentError = Translations.GetInterfaceString("errors_critical_file");
                    currentError = currentError.Replace("[file]", "panel.xml");
                    MessageBox.Show(currentError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    Program.RestartArguments = " ";
                    Loading.Cancel           = true;
                    return;
                }

                if (Train.Cars[Train.DriverCar].CarSections[0].Groups[0].Elements.Any())
                {
                    World.UpdateViewingDistances();
                    return;
                }
                Interface.AddMessage(MessageType.Error, false, "The panel.xml file " + File + " failed to load. Falling back to legacy panel.");
            }
            else
            {
                File = OpenBveApi.Path.CombineFile(TrainPath, "panel.animated");
                if (System.IO.File.Exists(File))
                {
                    Program.FileSystem.AppendToLogFile("Loading train panel: " + File);
                    if (System.IO.File.Exists(OpenBveApi.Path.CombineFile(TrainPath, "panel2.cfg")) || System.IO.File.Exists(OpenBveApi.Path.CombineFile(TrainPath, "panel.cfg")))
                    {
                        Program.FileSystem.AppendToLogFile("INFO: This train contains both a 2D and a 3D panel. The 3D panel will always take precedence");
                    }
                    ObjectManager.AnimatedObjectCollection a = AnimatedObjectParser.ReadObject(File, Encoding);
                    if (a != null)
                    {
                        //HACK: If a == null , loading our animated object completely failed (Missing objects?). Fallback to trying the panel2.cfg
                        try
                        {
                            for (int i = 0; i < a.Objects.Length; i++)
                            {
                                a.Objects[i].ObjectIndex = ObjectManager.CreateDynamicObject();
                            }
                            Train.Cars[Train.DriverCar].CarSections[0].Groups[0].Elements = a.Objects;
                            Train.Cars[Train.DriverCar].CameraRestrictionMode             = Camera.RestrictionMode.NotAvailable;
                            World.CameraRestriction = Camera.RestrictionMode.NotAvailable;
                            World.UpdateViewingDistances();
                            return;
                        }
                        catch
                        {
                            var currentError = Translations.GetInterfaceString("errors_critical_file");
                            currentError = currentError.Replace("[file]", "panel.animated");
                            MessageBox.Show(currentError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            Program.RestartArguments = " ";
                            Loading.Cancel           = true;
                            return;
                        }
                    }
                    Interface.AddMessage(MessageType.Error, false, "The panel.animated file " + File + " failed to load. Falling back to 2D panel.");
                }
            }

            var Panel2 = false;

            try
            {
                File = OpenBveApi.Path.CombineFile(TrainPath, "panel2.cfg");
                if (System.IO.File.Exists(File))
                {
                    Program.FileSystem.AppendToLogFile("Loading train panel: " + File);
                    Panel2 = true;
                    Panel2CfgParser.ParsePanel2Config("panel2.cfg", TrainPath, Encoding, Train, Train.DriverCar);
                    Train.Cars[Train.DriverCar].CameraRestrictionMode = Camera.RestrictionMode.On;
                    World.CameraRestriction = Camera.RestrictionMode.On;
                }
                else
                {
                    File = OpenBveApi.Path.CombineFile(TrainPath, "panel.cfg");
                    if (System.IO.File.Exists(File))
                    {
                        Program.FileSystem.AppendToLogFile("Loading train panel: " + File);
                        PanelCfgParser.ParsePanelConfig(TrainPath, Encoding, Train);
                        Train.Cars[Train.DriverCar].CameraRestrictionMode = Camera.RestrictionMode.On;
                        World.CameraRestriction = Camera.RestrictionMode.On;
                    }
                    else
                    {
                        World.CameraRestriction = Camera.RestrictionMode.NotAvailable;
                    }
                }
            }
            catch
            {
                var currentError = Translations.GetInterfaceString("errors_critical_file");
                currentError = currentError.Replace("[file]", Panel2 ? "panel2.cfg" : "panel.cfg");
                MessageBox.Show(currentError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                Program.RestartArguments = " ";
                Loading.Cancel           = true;
            }
        }
コード例 #4
0
            /// <summary>Attempts to load and parse the current train's panel configuration file.</summary>
            /// <param name="TrainPath">The absolute on-disk path to the train folder.</param>
            /// <param name="Encoding">The selected train encoding</param>
            internal void ParsePanelConfig(string TrainPath, System.Text.Encoding Encoding)
            {
                Cars[DriverCar].CarSections    = new CarSection[1];
                Cars[DriverCar].CarSections[0] = new CarSection(Program.CurrentHost, ObjectType.Overlay);
                string File = OpenBveApi.Path.CombineFile(TrainPath, "panel.xml");

                if (!System.IO.File.Exists(File))
                {
                    //Try animated variant too
                    File = OpenBveApi.Path.CombineFile(TrainPath, "panel.animated.xml");
                }

                if (System.IO.File.Exists(File))
                {
                    Program.FileSystem.AppendToLogFile("Loading train panel: " + File);
                    try
                    {
                        /*
                         * First load the XML. We use this to determine
                         * whether this is a 2D or a 3D animated panel
                         */
                        XDocument CurrentXML = XDocument.Load(File, LoadOptions.SetLineInfo);

                        // Check for null
                        if (CurrentXML.Root != null)
                        {
                            IEnumerable <XElement> DocumentElements = CurrentXML.Root.Elements("PanelAnimated");
                            if (DocumentElements.Any())
                            {
                                PanelAnimatedXmlParser.ParsePanelAnimatedXml(System.IO.Path.GetFileName(File), TrainPath, this, DriverCar);
                                if (Cars[DriverCar].CameraRestrictionMode != CameraRestrictionMode.Restricted3D)
                                {
                                    Cars[DriverCar].CameraRestrictionMode = CameraRestrictionMode.NotAvailable;
                                }
                            }

                            DocumentElements = CurrentXML.Root.Elements("Panel");
                            if (DocumentElements.Any())
                            {
                                PanelXmlParser.ParsePanelXml(System.IO.Path.GetFileName(File), TrainPath, this, DriverCar);
                                Cars[DriverCar].CameraRestrictionMode      = CameraRestrictionMode.On;
                                Program.Renderer.Camera.CurrentRestriction = CameraRestrictionMode.On;
                            }
                        }
                    }
                    catch
                    {
                        var currentError = Translations.GetInterfaceString("errors_critical_file");
                        currentError = currentError.Replace("[file]", "panel.xml");
                        MessageBox.Show(currentError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        Program.RestartArguments = " ";
                        Loading.Cancel           = true;
                        return;
                    }

                    if (Cars[DriverCar].CarSections[0].Groups[0].Elements.Any())
                    {
                        OpenBVEGame.RunInRenderThread(() =>
                        {
                            //Needs to be on the thread containing the openGL context
                            Program.Renderer.InitializeVisibility();
                        });
                        Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance);
                        return;
                    }

                    Interface.AddMessage(MessageType.Error, false, "The panel.xml file " + File + " failed to load. Falling back to legacy panel.");
                }
                else
                {
                    File = OpenBveApi.Path.CombineFile(TrainPath, "panel.animated");
                    if (System.IO.File.Exists(File))
                    {
                        Program.FileSystem.AppendToLogFile("Loading train panel: " + File);
                        if (System.IO.File.Exists(OpenBveApi.Path.CombineFile(TrainPath, "panel2.cfg")) || System.IO.File.Exists(OpenBveApi.Path.CombineFile(TrainPath, "panel.cfg")))
                        {
                            Program.FileSystem.AppendToLogFile("INFO: This train contains both a 2D and a 3D panel. The 3D panel will always take precedence");
                        }

                        UnifiedObject currentObject;
                        Program.CurrentHost.LoadObject(File, Encoding, out currentObject);
                        var a = currentObject as AnimatedObjectCollection;
                        if (a != null)
                        {
                            //HACK: If a == null , loading our animated object completely failed (Missing objects?). Fallback to trying the panel2.cfg
                            try
                            {
                                for (int i = 0; i < a.Objects.Length; i++)
                                {
                                    Program.CurrentHost.CreateDynamicObject(ref a.Objects[i].internalObject);
                                }

                                Cars[DriverCar].CarSections[0].Groups[0].Elements = a.Objects;
                                if (Cars[DriverCar].CameraRestrictionMode != CameraRestrictionMode.Restricted3D)
                                {
                                    Cars[DriverCar].CameraRestrictionMode      = CameraRestrictionMode.NotAvailable;
                                    Program.Renderer.Camera.CurrentRestriction = CameraRestrictionMode.NotAvailable;
                                }

                                Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance);
                                return;
                            }
                            catch
                            {
                                var currentError = Translations.GetInterfaceString("errors_critical_file");
                                currentError = currentError.Replace("[file]", "panel.animated");
                                MessageBox.Show(currentError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                                Program.RestartArguments = " ";
                                Loading.Cancel           = true;
                                return;
                            }
                        }

                        Interface.AddMessage(MessageType.Error, false, "The panel.animated file " + File + " failed to load. Falling back to 2D panel.");
                    }
                }

                var Panel2 = false;

                try
                {
                    File = OpenBveApi.Path.CombineFile(TrainPath, "panel2.cfg");
                    if (System.IO.File.Exists(File))
                    {
                        Program.FileSystem.AppendToLogFile("Loading train panel: " + File);
                        Panel2 = true;
                        Panel2CfgParser.ParsePanel2Config("panel2.cfg", TrainPath, Cars[DriverCar]);
                        Cars[DriverCar].CameraRestrictionMode      = CameraRestrictionMode.On;
                        Program.Renderer.Camera.CurrentRestriction = CameraRestrictionMode.On;
                    }
                    else
                    {
                        File = OpenBveApi.Path.CombineFile(TrainPath, "panel.cfg");
                        if (System.IO.File.Exists(File))
                        {
                            Program.FileSystem.AppendToLogFile("Loading train panel: " + File);
                            PanelCfgParser.ParsePanelConfig(TrainPath, Encoding, Cars[DriverCar]);
                            Cars[DriverCar].CameraRestrictionMode      = CameraRestrictionMode.On;
                            Program.Renderer.Camera.CurrentRestriction = CameraRestrictionMode.On;
                        }
                        else
                        {
                            Program.Renderer.Camera.CurrentRestriction = CameraRestrictionMode.NotAvailable;
                        }
                    }
                }
                catch
                {
                    var currentError = Translations.GetInterfaceString("errors_critical_file");
                    currentError = currentError.Replace("[file]", Panel2 ? "panel2.cfg" : "panel.cfg");
                    MessageBox.Show(currentError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    Program.RestartArguments = " ";
                    Loading.Cancel           = true;
                }
            }
コード例 #5
0
        /// <summary>Attempts to load and parse the current train's panel configuration file.</summary>
        /// <param name="TrainPath">The absolute on-disk path to the train folder.</param>
        /// <param name="Encoding">The automatically detected or manually set encoding of the panel configuration file.</param>
        /// <param name="Train">The base train on which to apply the panel configuration.</param>
        internal static void ParsePanelConfig(string TrainPath, System.Text.Encoding Encoding, Train Train)
        {
            Train.Cars[Train.DriverCar].CarSections    = new CarSection[1];
            Train.Cars[Train.DriverCar].CarSections[0] = new CarSection
            {
                Elements = new ObjectManager.AnimatedObject[] { },
                Overlay  = true
            };
            string File = OpenBveApi.Path.CombineFile(TrainPath, "panel.animated");

            if (System.IO.File.Exists(File))
            {
                Program.FileSystem.AppendToLogFile("Loading train panel: " + File);
                if (System.IO.File.Exists(OpenBveApi.Path.CombineFile(TrainPath, "panel2.cfg")) || System.IO.File.Exists(OpenBveApi.Path.CombineFile(TrainPath, "panel.cfg")))
                {
                    Program.FileSystem.AppendToLogFile("INFO: This train contains both a 2D and a 3D panel. The 3D panel will always take precedence");
                }
                ObjectManager.AnimatedObjectCollection a = AnimatedObjectParser.ReadObject(File, Encoding);
                if (a != null)
                {
                    //HACK: If a == null , loading our animated object completely failed (Missing objects?). Fallback to trying the panel2.cfg
                    try
                    {
                        for (int i = 0; i < a.Objects.Length; i++)
                        {
                            a.Objects[i].ObjectIndex = ObjectManager.CreateDynamicObject();
                        }
                        Train.Cars[Train.DriverCar].CarSections[0].Elements = a.Objects;
                        Train.Cars[Train.DriverCar].CameraRestrictionMode   = Camera.RestrictionMode.NotAvailable;
                        World.CameraRestriction = Camera.RestrictionMode.NotAvailable;
                        World.UpdateViewingDistances();
                        return;
                    }
                    catch
                    {
                        var currentError = Translations.GetInterfaceString("errors_critical_file");
                        currentError = currentError.Replace("[file]", "panel.animated");
                        MessageBox.Show(currentError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        Program.RestartArguments = " ";
                        Loading.Cancel           = true;
                        return;
                    }
                }
                Interface.AddMessage(MessageType.Error, false, "The panel.animated file " + File + " failed to load. Falling back to 2D panel.");
            }

            var Panel2 = false;

            try
            {
                File = OpenBveApi.Path.CombineFile(TrainPath, "panel2.cfg");
                if (System.IO.File.Exists(File))
                {
                    Program.FileSystem.AppendToLogFile("Loading train panel: " + File);
                    Panel2 = true;
                    Panel2CfgParser.ParsePanel2Config("panel2.cfg", TrainPath, Encoding, Train, Train.DriverCar);
                    Train.Cars[Train.DriverCar].CameraRestrictionMode = Camera.RestrictionMode.On;
                    World.CameraRestriction = Camera.RestrictionMode.On;
                }
                else
                {
                    File = OpenBveApi.Path.CombineFile(TrainPath, "panel.cfg");
                    if (System.IO.File.Exists(File))
                    {
                        Program.FileSystem.AppendToLogFile("Loading train panel: " + File);
                        PanelCfgParser.ParsePanelConfig(TrainPath, Encoding, Train);
                        Train.Cars[Train.DriverCar].CameraRestrictionMode = Camera.RestrictionMode.On;
                        World.CameraRestriction = Camera.RestrictionMode.On;
                    }
                    else
                    {
                        World.CameraRestriction = Camera.RestrictionMode.NotAvailable;
                    }
                }
            }
            catch
            {
                var currentError = Translations.GetInterfaceString("errors_critical_file");
                currentError = currentError.Replace("[file]", Panel2 == true ? "panel2.cfg" : "panel.cfg");
                MessageBox.Show(currentError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                Program.RestartArguments = " ";
                Loading.Cancel           = true;
            }
        }