Example #1
0
            internal void LoadCarSections(UnifiedObject currentObject, bool visibleFromInterior)
            {
                int j = CarSections.Length;

                Array.Resize(ref CarSections, j + 1);
                CarSections[j] = new CarSection(Program.CurrentHost, ObjectType.Dynamic);
                CarSections[j].VisibleFromInterior = visibleFromInterior;
                if (currentObject is StaticObject)
                {
                    StaticObject s = (StaticObject)currentObject;
                    CarSections[j].Groups[0].Elements    = new AnimatedObject[1];
                    CarSections[j].Groups[0].Elements[0] = new AnimatedObject(Program.CurrentHost)
                    {
                        States       = new[] { new ObjectState(s) },
                        CurrentState = 0
                    };
                    Program.CurrentHost.CreateDynamicObject(ref CarSections[j].Groups[0].Elements[0].internalObject);
                }
                else if (currentObject is AnimatedObjectCollection)
                {
                    AnimatedObjectCollection a = (AnimatedObjectCollection)currentObject;
                    CarSections[j].Groups[0].Elements = new AnimatedObject[a.Objects.Length];
                    for (int h = 0; h < a.Objects.Length; h++)
                    {
                        CarSections[j].Groups[0].Elements[h] = a.Objects[h].Clone();
                        Program.CurrentHost.CreateDynamicObject(ref CarSections[j].Groups[0].Elements[h].internalObject);
                    }
                }
            }
Example #2
0
        public void LoadCarSections(UnifiedObject currentObject, bool visibleFromInterior)
        {
            int j = CarSections.Length;

            Array.Resize(ref CarSections, j + 1);
            CarSections[j] = new CarSection(TrainManagerBase.currentHost, ObjectType.Dynamic, visibleFromInterior, currentObject);
        }
Example #3
0
            internal void LoadCarSections(UnifiedObject currentObject)
            {
                int j = CarSections.Length;

                Array.Resize(ref CarSections, j + 1);
                CarSections[j] = new CarSection();
                if (currentObject is ObjectManager.StaticObject)
                {
                    ObjectManager.StaticObject s = (ObjectManager.StaticObject)currentObject;
                    CarSections[j].Elements    = new ObjectManager.AnimatedObject[1];
                    CarSections[j].Elements[0] = new ObjectManager.AnimatedObject
                    {
                        States = new ObjectManager.AnimatedObjectState[1]
                    };
                    CarSections[j].Elements[0].States[0].Position = Vector3.Zero;
                    CarSections[j].Elements[0].States[0].Object   = s;
                    CarSections[j].Elements[0].CurrentState       = 0;
                    CarSections[j].Elements[0].ObjectIndex        = ObjectManager.CreateDynamicObject();
                }
                else if (currentObject is ObjectManager.AnimatedObjectCollection)
                {
                    ObjectManager.AnimatedObjectCollection a = (ObjectManager.AnimatedObjectCollection)currentObject;
                    CarSections[j].Elements = new ObjectManager.AnimatedObject[a.Objects.Length];
                    for (int h = 0; h < a.Objects.Length; h++)
                    {
                        CarSections[j].Elements[h]             = a.Objects[h].Clone();
                        CarSections[j].Elements[h].ObjectIndex = ObjectManager.CreateDynamicObject();
                    }
                }
            }
Example #4
0
            internal void LoadCarSections(UnifiedObject currentObject)
            {
                int j = CarSections.Length;

                Array.Resize(ref CarSections, j + 1);
                CarSections[j] = new CarSection
                {
                    Groups = new ElementsGroup[1]
                };
                CarSections[j].Groups[0] = new ElementsGroup();
                if (currentObject is StaticObject)
                {
                    StaticObject s = (StaticObject)currentObject;
                    CarSections[j].Groups[0].Elements    = new AnimatedObject[1];
                    CarSections[j].Groups[0].Elements[0] = new AnimatedObject(Program.CurrentHost)
                    {
                        States = new[] { new ObjectState() }
                    };
                    CarSections[j].Groups[0].Elements[0].States[0].Prototype = s;
                    CarSections[j].Groups[0].Elements[0].CurrentState        = 0;
                    Program.CurrentHost.CreateDynamicObject(ref CarSections[j].Groups[0].Elements[0].internalObject);
                }
                else if (currentObject is AnimatedObjectCollection)
                {
                    AnimatedObjectCollection a = (AnimatedObjectCollection)currentObject;
                    CarSections[j].Groups[0].Elements = new AnimatedObject[a.Objects.Length];
                    for (int h = 0; h < a.Objects.Length; h++)
                    {
                        CarSections[j].Groups[0].Elements[h] = a.Objects[h].Clone();
                        Program.CurrentHost.CreateDynamicObject(ref CarSections[j].Groups[0].Elements[h].internalObject);
                    }
                }
            }
        private void ParsePanelAnimatedNode(XElement Element, string FileName, string TrainPath, TrainBase Train, int Car, CarSection CarSection, int GroupIndex)
        {
            System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture;

            int    currentSectionElement   = 0;
            int    numberOfSectionElements = Element.Elements().Count();
            double invfac = numberOfSectionElements == 0 ? 1.0 : 1.0 / (double)numberOfSectionElements;

            foreach (XElement SectionElement in Element.Elements())
            {
                Plugin.CurrentProgress = Plugin.CurrentProgress + invfac * (double)currentSectionElement;
                if ((currentSectionElement & 4) == 0)
                {
                    System.Threading.Thread.Sleep(1);
                    if (Plugin.Cancel)
                    {
                        return;
                    }
                }

                string Section = SectionElement.Name.LocalName;

                switch (SectionElement.Name.LocalName.ToLowerInvariant())
                {
                case "group":
                    if (GroupIndex == 0)
                    {
                        int n = 0;

                        foreach (XElement KeyNode in SectionElement.Elements())
                        {
                            string Key        = KeyNode.Name.LocalName;
                            string Value      = KeyNode.Value;
                            int    LineNumber = ((IXmlLineInfo)KeyNode).LineNumber;

                            switch (Key.ToLowerInvariant())
                            {
                            case "number":
                                if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out n))
                                {
                                    Plugin.currentHost.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName);
                                }
                                break;
                            }
                        }

                        if (n + 1 >= CarSection.Groups.Length)
                        {
                            Array.Resize(ref CarSection.Groups, n + 2);
                            CarSection.Groups[n + 1] = new ElementsGroup(ObjectType.Overlay);
                        }

                        ParsePanelAnimatedNode(SectionElement, FileName, TrainPath, Train, Car, CarSection, n + 1);
                    }
                    break;

                case "touch":
                    if (GroupIndex > 0)
                    {
                        Vector3             Position       = Vector3.Zero;
                        Vector3             Size           = Vector3.Zero;
                        int                 JumpScreen     = GroupIndex - 1;
                        List <int>          SoundIndices   = new List <int>();
                        List <CommandEntry> CommandEntries = new List <CommandEntry>();
                        CommandEntry        CommandEntry   = new CommandEntry();

                        foreach (XElement KeyNode in SectionElement.Elements())
                        {
                            string Key        = KeyNode.Name.LocalName;
                            string Value      = KeyNode.Value;
                            int    LineNumber = ((IXmlLineInfo)KeyNode).LineNumber;

                            switch (Key.ToLowerInvariant())
                            {
                            case "position":
                                if (!Vector3.TryParse(KeyNode.Value, ',', out Position))
                                {
                                    Plugin.currentHost.AddMessage(MessageType.Error, false, "Position is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName);
                                }
                                break;

                            case "size":
                                if (!Vector3.TryParse(KeyNode.Value, ',', out Size))
                                {
                                    Plugin.currentHost.AddMessage(MessageType.Error, false, "Size is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName);
                                }
                                break;

                            case "jumpscreen":
                                if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out JumpScreen))
                                {
                                    Plugin.currentHost.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName);
                                }
                                break;

                            case "soundindex":
                                if (Value.Length != 0)
                                {
                                    int SoundIndex;

                                    if (!NumberFormats.TryParseIntVb6(Value, out SoundIndex))
                                    {
                                        Plugin.currentHost.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName);
                                    }

                                    SoundIndices.Add(SoundIndex);
                                }
                                break;

                            case "command":
                            {
                                if (!CommandEntries.Contains(CommandEntry))
                                {
                                    CommandEntries.Add(CommandEntry);
                                }

                                if (string.Compare(Value, "N/A", StringComparison.InvariantCultureIgnoreCase) == 0)
                                {
                                    break;
                                }

                                int i;
                                for (i = 0; i < Translations.CommandInfos.Length; i++)
                                {
                                    if (string.Compare(Value, Translations.CommandInfos[i].Name, StringComparison.OrdinalIgnoreCase) == 0)
                                    {
                                        break;
                                    }
                                }
                                if (i == Translations.CommandInfos.Length || Translations.CommandInfos[i].Type != Translations.CommandType.Digital)
                                {
                                    Plugin.currentHost.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName);
                                }
                                else
                                {
                                    CommandEntry.Command = Translations.CommandInfos[i].Command;
                                }
                            }
                            break;

                            case "commandoption":
                                if (!CommandEntries.Contains(CommandEntry))
                                {
                                    CommandEntries.Add(CommandEntry);
                                }

                                if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out CommandEntry.Option))
                                {
                                    Plugin.currentHost.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName);
                                }
                                break;

                            case "soundentries":
                                if (!KeyNode.HasElements)
                                {
                                    Plugin.currentHost.AddMessage(MessageType.Error, false, $"An empty list of touch sound indices was defined at line {((IXmlLineInfo)KeyNode).LineNumber} in XML file {FileName}");
                                    break;
                                }

                                ParseTouchSoundEntryNode(FileName, KeyNode, SoundIndices);
                                break;

                            case "commandentries":
                                if (!KeyNode.HasElements)
                                {
                                    Plugin.currentHost.AddMessage(MessageType.Error, false, $"An empty list of touch commands was defined at line {((IXmlLineInfo)KeyNode).LineNumber} in XML file {FileName}");
                                    break;
                                }

                                ParseTouchCommandEntryNode(FileName, KeyNode, CommandEntries);
                                break;
                            }
                        }
                        CreateTouchElement(CarSection.Groups[GroupIndex], Position, Size, JumpScreen, SoundIndices.ToArray(), CommandEntries.ToArray());
                    }
                    break;

                case "include":
                {
                    foreach (XElement KeyNode in SectionElement.Elements())
                    {
                        string Key        = KeyNode.Name.LocalName;
                        string Value      = KeyNode.Value;
                        int    LineNumber = ((IXmlLineInfo)KeyNode).LineNumber;

                        switch (Key.ToLowerInvariant())
                        {
                        case "filename":
                        {
                            string File = OpenBveApi.Path.CombineFile(TrainPath, Value);
                            if (System.IO.File.Exists(File))
                            {
                                System.Text.Encoding e = TextEncoding.GetSystemEncodingFromFile(File);
                                UnifiedObject        currentObject;
                                Plugin.currentHost.LoadObject(File, e, out currentObject);
                                var a = currentObject as AnimatedObjectCollection;
                                if (a != null)
                                {
                                    for (int i = 0; i < a.Objects.Length; i++)
                                    {
                                        Plugin.currentHost.CreateDynamicObject(ref a.Objects[i].internalObject);
                                    }
                                    CarSection.Groups[GroupIndex].Elements = a.Objects;
                                }
                                else
                                {
                                    Plugin.currentHost.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName);
                                }
                            }
                        }
                        break;
                        }
                    }
                }
                break;
                }
            }
        }