Esempio n. 1
0
        private void Setup()
        {
            bool isValid = true;

            Inventories.Clear();
            var allBlocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(allBlocks, block => block.HasInventory);

            foreach (var block in allBlocks)
            {
                for (var i = 0; i < block.InventoryCount; i++)
                {
                    Inventories.Add(new InventoryManager(block.GetInventory(i)));
                }
            }

            var ini = new MyIni();
            MyIniParseResult result;
            var panels = new List <IMyTextPanel>();

            GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(panels, panel => MyIni.HasSection(panel.CustomData, panelSectionName));
            foreach (var panel in panels)
            {
                if (!ini.TryParse(panel.CustomData, out result))
                {
                    Echo("Invalid configuration for panel " + panel.DisplayNameText);
                    isValid = false;
                    continue;
                }

                if (ini.ContainsKey(panelSectionName, componentKeyName))
                {
                    var index  = ini.Get(panelSectionName, componentKeyName).ToInt16();
                    var dPanel = ComponentPanels.FirstOrDefault(i => i.Index == index);
                    if (dPanel == null)
                    {
                        dPanel = new DisplayPanels()
                        {
                            Index = index,
                        };
                        ComponentPanels.Add(dPanel);
                    }
                    dPanel.Panels.Add(panel);
                }
                else if (ini.ContainsKey(panelSectionName, oreKeyName))
                {
                    var index  = ini.Get(panelSectionName, oreKeyName).ToInt16();
                    var dPanel = OrePanels.FirstOrDefault(i => i.Index == index);
                    if (dPanel == null)
                    {
                        dPanel = new DisplayPanels()
                        {
                            Index = index,
                        };
                        OrePanels.Add(dPanel);
                    }
                    dPanel.Panels.Add(panel);
                }
                else if (ini.ContainsKey(panelSectionName, ingotKeyName))
                {
                    var index  = ini.Get(panelSectionName, ingotKeyName).ToInt16();
                    var dPanel = IngotsPanels.FirstOrDefault(i => i.Index == index);
                    if (dPanel == null)
                    {
                        dPanel = new DisplayPanels()
                        {
                            Index = index,
                        };
                        IngotsPanels.Add(dPanel);
                    }
                    dPanel.Panels.Add(panel);
                }

                panel.ContentType = VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE;
            }

            if (ComponentPanels.Count + OrePanels.Count + IngotsPanels.Count == 0)
            {
                Echo("No valid panels found for display");
                isValid = false;
            }

            if (!isValid)
            {
                Runtime.UpdateFrequency = UpdateFrequency.None;
            }

            ComponentPanels.Sort();
            IngotsPanels.Sort();
            OrePanels.Sort();
        }
Esempio n. 2
0
        private void GetPanelList()
        {
            Displays.Add(ItemType.Ore, new List <DisplayPanels>());
            Displays.Add(ItemType.Ingot, new List <DisplayPanels>());
            Displays.Add(ItemType.Componenet, new List <DisplayPanels>());

            var ini = new MyIni();
            MyIniParseResult result;
            var panels = new List <IMyTextPanel>();

            GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(panels, panel => MyIni.HasSection(panel.CustomData, panelSectionName));

            foreach (var panel in panels)
            {
                if (!ini.TryParse(panel.CustomData, out result))
                {
                    Echo("Invalid configuration for panel " + panel.DisplayNameText);
                    continue;
                }

                if (ini.ContainsKey(panelSectionName, componentKeyName))
                {
                    var index  = ini.Get(panelSectionName, componentKeyName).ToInt16();
                    var dPanel = Displays[ItemType.Componenet].FirstOrDefault(i => i.Index == index);
                    if (dPanel == null)
                    {
                        dPanel = new DisplayPanels()
                        {
                            Index = index,
                        };
                        Displays[ItemType.Componenet].Add(dPanel);
                    }
                    dPanel.Panels.Add(panel);
                }
                else if (ini.ContainsKey(panelSectionName, oreKeyName))
                {
                    var index  = ini.Get(panelSectionName, oreKeyName).ToInt16();
                    var dPanel = Displays[ItemType.Ore].FirstOrDefault(i => i.Index == index);
                    if (dPanel == null)
                    {
                        dPanel = new DisplayPanels()
                        {
                            Index = index,
                        };
                        Displays[ItemType.Ore].Add(dPanel);
                    }
                    dPanel.Panels.Add(panel);
                }
                else if (ini.ContainsKey(panelSectionName, ingotKeyName))
                {
                    var index  = ini.Get(panelSectionName, ingotKeyName).ToInt16();
                    var dPanel = Displays[ItemType.Ingot].FirstOrDefault(i => i.Index == index);
                    if (dPanel == null)
                    {
                        dPanel = new DisplayPanels()
                        {
                            Index = index,
                        };
                        Displays[ItemType.Ingot].Add(dPanel);
                    }
                    dPanel.Panels.Add(panel);
                }
            }

            if (Displays[ItemType.Componenet].Count == 0)
            {
                Echo("No component panels configured.");
            }
            else
            {
                Displays[ItemType.Componenet].Sort();
            }

            if (Displays[ItemType.Ore].Count == 0)
            {
                Echo("No ore panels configured.");
            }
            else
            {
                Displays[ItemType.Ore].Sort();
            }

            if (Displays[ItemType.Ingot].Count == 0)
            {
                Echo("No ingot panels configured.");
            }
            else
            {
                Displays[ItemType.Ingot].Sort();
            }
        }