private static void GetItemList(IMyTerminalBlock block, List <MyTerminalControlListBoxItem> items, List <MyTerminalControlListBoxItem> selected)
        {
            IMyProjector me = (IMyProjector)block;

            if (me.ProjectedGrid != null)
            {
                StringBuilder  sb    = new StringBuilder();
                GridComponents comps = block.GameLogic.GetAs <InstantProjector>().GetComponents();
                foreach (KeyValuePair <MyDefinitionId, int> kv in comps)
                {
                    if (IPSession.Instance != null)
                    {
                        sb.Append(IPSession.Instance.GetComponentName(kv.Key));
                    }
                    else
                    {
                        sb.Append(kv.Key.SubtypeName);
                    }
                    sb.Append(": ").Append(kv.Value);
                    MyStringId s = MyStringId.GetOrCompute(sb.ToString());
                    MyTerminalControlListBoxItem item = new MyTerminalControlListBoxItem(s, s, 0);
                    items.Add(item);
                    sb.Clear();
                }
            }
        }
Beispiel #2
0
        internal static void CreateCurrentList(IMyTerminalBlock block, List <MyTerminalControlListBoxItem> listItems, List <MyTerminalControlListBoxItem> selectedItems)
        {
            FilteredContainer component = block?.GameLogic?.GetAs <FilteredContainer>();

            foreach (var item in component.FilterController.FilterList)
            {
                var listitem = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(item.DisplayName), MyStringId.NullOrEmpty, item);
                listItems.Add(listitem);
            }
        }
        public static IMyTerminalControl CallbackList <T>() where T : IMyTerminalBlock
        {
            var callbackList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, T>(string.Empty);

            callbackList.Title            = MyStringId.GetOrCompute("Callback");
            callbackList.Tooltip          = MyStringId.GetOrCompute("PB: Run with message passed as argument\nTimer: Trigger the timer\nNone: Pass message to queue");
            callbackList.VisibleRowsCount = 5;
            callbackList.Multiselect      = false;
            callbackList.ListContent      = (b, v, v2) =>
            {
                if (b.CubeGrid != null)
                {
                    var properties = Config.GetProperties(b.EntityId);
                    var blocks     = new List <IMyTerminalBlock>();
                    var timers     = new List <IMyTerminalBlock>();
                    var gts        = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(b.CubeGrid);
                    gts.GetBlocksOfType <IMyProgrammableBlock>(blocks);
                    gts.GetBlocksOfType <IMyTimerBlock>(timers);

                    blocks.AddRange(timers);

                    foreach (var block in blocks)
                    {
                        if (block.HasPlayerAccess(b.OwnerId))
                        {
                            var item = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(block.CustomName), default(MyStringId), block);
                            if (block.EntityId == properties.CallbackId)
                            {
                                v.Insert(0, item);
                                v2.Add(item);
                            }
                            else
                            {
                                v.Add(item);
                            }
                        }
                    }
                }
            };
            callbackList.ItemSelected = (b, v) =>
            {
                if ((v.Count > 0) && (v[0].UserData != null))
                {
                    var properties = Config.GetProperties(b.EntityId);
                    var pb         = (IMyTerminalBlock)v[0].UserData;
                    if (pb.HasPlayerAccess(b.OwnerId))
                    {
                        properties.CallbackId = pb.EntityId;
                        Config.SendSynced(properties);
                    }
                }
            };
            return(callbackList);
        }
        public static void SetSelectedGrid(IMyTerminalBlock block, List <MyTerminalControlListBoxItem> listItems)
        {
            //MyLog.Default.WriteLineAndConsole("Selected Item Changed to: "+listItems[0].Text);
            SelectedGrid = (MarketList)listItems[0].UserData;

            MyTerminalControlListBoxItem item = listItems[0];

            SelectedBoxItem = item;

            block.RefreshCustomInfo();
            UpdateGUI(block);
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="items"></param>
        internal void FillTerminalList(List <MyTerminalControlListBoxItem> items, List <MyTerminalControlListBoxItem> selected)
        {
            foreach (var entry in this)
            {
                var item = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(string.Format("({0}) {1}", entry.Enabled ? "X" : "-", entry.ItemClass.ToString())), MyStringId.NullOrEmpty, entry.ItemClass);
                items.Add(item);

                if (entry.ItemClass.Equals(Selected))
                {
                    selected.Add(item);
                }
            }
        }
        void AssemblerListCreate(IMyTerminalBlock block, List <MyTerminalControlListBoxItem> itemList, List <MyTerminalControlListBoxItem> selectedItems)
        {
            var gts           = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(block.SlimBlock.CubeGrid);
            var assemblerList = new List <IMyAssembler>();

            gts.GetBlocksOfType <IMyAssembler>(assemblerList);
            string selectedAssemblerId = "";

            if (block.Storage == null)
            {
                block.Storage = new MyModStorageComponent();
            }
            else if (block.Storage.ContainsKey(storageKey) == true)
            {
                selectedAssemblerId = block.Storage[storageKey];
            }
            else
            {
                block.Storage.Add(storageKey, "");
            }

            bool foundSelected = false;

            if (assemblerList.Count == 0)
            {
                block.Storage[storageKey] = "";
                return;
            }

            foreach (var assembler in assemblerList)
            {
                var assemblerId = assembler.EntityId.ToString();
                var listItem    = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(assembler.CustomName), MyStringId.GetOrCompute(""), assemblerId);
                itemList.Add(listItem);

                if (assemblerId == selectedAssemblerId && foundSelected == false)
                {
                    foundSelected = true;
                    selectedItems.Add(listItem);
                }
            }

            if (selectedItems.Count == 0 && itemList.Count > 0 && foundSelected == false)
            {
                selectedItems.Add(itemList[0]);
                var idName = itemList[0].UserData as string;
                block.Storage[storageKey] = idName;
            }
        }
Beispiel #7
0
        private bool TryGetOre(MyTerminalControlListBoxItem item, out Ore ore)
        {
            string longName = item.Text.ToString();

            foreach (Ore o in m_allOres)
            {
                if (o.LongName == longName)
                {
                    ore = o;
                    return(true);
                }
            }
            ore = null;
            return(false);
        }
Beispiel #8
0
        private void ListCommands(IMyTerminalBlock block, List <MyTerminalControlListBoxItem> allItems, List <MyTerminalControlListBoxItem> selected)
        {
            Log.DebugLog("block != m_block", Logger.severity.FATAL, condition: block != m_block);

            foreach (ACommand command in m_commandList)
            {
                // this will leak memory, as MyTerminalControlListBoxItem uses MyStringId for some stupid reason
                MyTerminalControlListBoxItem item = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(command.DisplayString), MyStringId.GetOrCompute(command.Description), command);
                allItems.Add(item);
                if (command == m_currentCommand && selected.Count == 0)
                {
                    selected.Add(item);
                }
            }
        }
        private static void ComponentList_content(IMyTerminalBlock block, List <MyTerminalControlListBoxItem> items, List <MyTerminalControlListBoxItem> selected)
        {
            var system = GetBlock(block);

            if (system != null && system.Settings.Items != null && system.Settings.Items.Count > 0)
            {
                for (var i = system.Settings.Items.Count - 1; i > -1; i--)
                {
                    var item    = system.Settings.Items[i];
                    var name    = item.PhysicalContent.SubtypeName + ": " + item.Amount;
                    var BoxItem = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(name.ToString()), MyStringId.NullOrEmpty, null);
                    items.Add(BoxItem);
                }
            }
        }
        private void FillGpsList(IMyTerminalBlock block, ICollection <MyTerminalControlListBoxItem> gpsItemList, ICollection <MyTerminalControlListBoxItem> selectedGpsItemList)
        {
            List <IMyGps> gpsList = new List <IMyGps>();

            gpsList = MyAPIGateway.Session.GPS.GetGpsList(MyAPIGateway.Session.Player.PlayerID);

            foreach (var gps in gpsList)
            {
                var item = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(gps.Name), MyStringId.NullOrEmpty, gps);
                gpsItemList.Add(item);

                if (m_selectedGps == gps)
                {
                    selectedGpsItemList.Add(item);
                }
            }
        }
        public int Compare(IMyEntity x, IMyEntity y)
        {
            MyTerminalControlListBoxItem typeItemx = null;
            MyTerminalControlListBoxItem typeItemy = null;
            int priorityx = -1;
            int priorityy = -1;

            if (!(x is IMyDecoy))
            {
                typeItemx = targetTypesListItems.Find((z) => { return((z.UserData as ListBoxItemData).id == targetTypeDictionary[x]); });
                priorityx = targetTypesListItems.IndexOf(typeItemx);
            }
            if (!(y is IMyDecoy))
            {
                typeItemy = targetTypesListItems.Find((z) => { return((z.UserData as ListBoxItemData).id == targetTypeDictionary[y]); });
                priorityy = targetTypesListItems.IndexOf(typeItemy);
            }

            if (priorityx > priorityy)
            {
                return(1);
            }
            else if (priorityx < priorityy)
            {
                return(-1);
            }
            else
            {
                double distx = Vector3D.DistanceSquared(x.GetPosition(), turretLocation);
                double disty = Vector3D.DistanceSquared(y.GetPosition(), turretLocation);

                if (distx > disty)
                {
                    return(1);
                }
                else if (disty > distx)
                {
                    return(-1);
                }
                else
                {
                    return(0);
                }
            }
        }
        private static void List_content(IMyTerminalBlock block, List <MyTerminalControlListBoxItem> items, List <MyTerminalControlListBoxItem> selected)
        {
            var system = GetBlock(block);

            if (system != null && system.Grids != null && system.Grids.Count > 0)
            {
                foreach (var item in system.Grids)
                {
                    var BoxItem = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(item.CustomName), MyStringId.NullOrEmpty, item);
                    items.Add(BoxItem);
                }
            }

            if (system.SelectedGrid != null)
            {
                selected.Add(new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(system.SelectedGrid.CustomName), MyStringId.NullOrEmpty, system.SelectedGrid));
            }
        }
Beispiel #13
0
        private void ListContent(IMyTerminalBlock autopilot, List <MyTerminalControlListBoxItem> items, List <MyTerminalControlListBoxItem> selected)
        {
            MyTerminalControlListBoxItem defaultItem = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("Default"), MyStringId.NullOrEmpty, null);

            items.Add(defaultItem);
            if (!m_selectedDirection.HasValue)
            {
                selected.Add(defaultItem);
            }
            foreach (Base6Directions.Direction direction in Base6Directions.EnumDirections)
            {
                MyTerminalControlListBoxItem item = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(direction.ToString()), MyStringId.NullOrEmpty, (Base6Directions.Direction?)direction);
                items.Add(item);
                if (m_selectedDirection == direction)
                {
                    selected.Add(item);
                }
            }
        }
Beispiel #14
0
        private void ListContent(IMyTerminalBlock autopilot, List <MyTerminalControlListBoxItem> items, List <MyTerminalControlListBoxItem> selected)
        {
            if (m_addingResponse)
            {
                foreach (EnemyFinder.Response response in  m_allResponses.Select(item => (EnemyFinder.Response)item.UserData).Except(m_activeResponses))
                {
                    items.Add(GetItem(response));
                }
                return;
            }

            foreach (EnemyFinder.Response response in m_activeResponses)
            {
                MyTerminalControlListBoxItem item = GetItem(response);
                items.Add(item);
                if (m_selected == response)
                {
                    selected.Add(item);
                }
            }
        }
Beispiel #15
0
        private void ListContent(IMyTerminalBlock autopilot, List <MyTerminalControlListBoxItem> items, List <MyTerminalControlListBoxItem> selected)
        {
            if (m_addingOres)
            {
                foreach (Ore ore in m_allOres.Except(m_activeOres))
                {
                    items.Add(GetItem(ore));
                }
                return;
            }

            foreach (Ore ore in m_activeOres)
            {
                MyTerminalControlListBoxItem item = GetItem(ore);
                if (m_selected == ore)
                {
                    selected.Add(item);
                }
                items.Add(item);
            }
        }
        public List <MyTerminalControlListBoxItem> GetTerminalOreList()
        {
            List <MyTerminalControlListBoxItem> list = new List <MyTerminalControlListBoxItem>();

            foreach (var item in MyDefinitionManager.Static.GetVoxelMaterialDefinitions().Select(x => x.MinedOre).Distinct())
            {
                MyStringId stringId = MyStringId.GetOrCompute(item);

                // Filter upgrade
                if (m_block.UpgradeValues["Scanning"] < 1f && (stringId.String == "Uranium" || stringId.String == "Platinum" || stringId.String == "Deuterium" || stringId.String == "Silver" || stringId.String == "Gold"))
                {
                    continue;
                }
                if (m_block.UpgradeValues["Scanning"] < 2f && (stringId.String == "Uranium" || stringId.String == "Platinum" || stringId.String == "Deuterium"))
                {
                    continue;
                }

                MyTerminalControlListBoxItem listItem = new MyTerminalControlListBoxItem(stringId, stringId, null);
                list.Add(listItem);
            }
            return(list);
        }
        private static void FillGroupList(List <MyTerminalControlListBoxItem> itemList,
                                          List <MyTerminalControlListBoxItem> selectedItemList, IMyTerminalBlock myTerminalBlock)
        {
            var patrol = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("Patrol"),
                                                          MyStringId.GetOrCompute("Orders the mercenaries to patrol between the below defined points"), null);
            var attackPoint = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("Attack Point"),
                                                               MyStringId.GetOrCompute("Orders the mercenaries to attack a specific point"), null);
            var standGuard = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("Hold Position"),
                                                              MyStringId.GetOrCompute("Orders the mercenaries to stand guard at a specific position"), null);

            itemList.Add(patrol);
            itemList.Add(attackPoint);
            itemList.Add(standGuard);

            var selected = getSelected(myTerminalBlock);

            MyLog.Default.WriteLine("found selected val: " + selected);
            if (selected.Equals(patrol.Text.String))
            {
                selectedItemList.Add(patrol);
            }
            else if (selected.Equals(attackPoint.Text.String))
            {
                selectedItemList.Add(attackPoint);
            }
            else if (selected.Equals(standGuard.Text.String))
            {
                selectedItemList.Add(standGuard);
            }

            if (selectedItemList.Count < 1)
            {
                selectedItemList.Add(standGuard);
                OnItemSelected(myTerminalBlock, standGuard.Text.String);
            }
        }
Beispiel #18
0
        /// <summary>
        /// Creates all of the custom controls for the blocks
        /// </summary>
        private void MakeControls()
        {
            IMyTerminalControlSeparator sep1
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyUpgradeModule>("Sep1");

            _radarControls.Add(sep1);

            IMyTerminalControlSlider rangeSlider
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyUpgradeModule>("RangeSlider");

            rangeSlider.Title   = MyStringId.GetOrCompute("Range");
            rangeSlider.Tooltip = MyStringId.GetOrCompute("Maximum range of this radar system");
            rangeSlider.SetLimits(100, 15000);
            rangeSlider.Getter = (block) => {
                RadarController controller = block.GameLogic.GetAs <RadarController>();
                return(controller.GetRange());
            };
            rangeSlider.Setter = (block, value) => {
                RadarController controller = block.GameLogic.GetAs <RadarController>();
                controller.SetRange((int)value);
                SendRadarSettings(new BlockAddress(block.CubeGrid.EntityId, block.EntityId));
            };
            rangeSlider.Writer = (block, str) => {
                RadarController controller = block.GameLogic.GetAs <RadarController>();
                str.Append(controller.GetRange() + "m");
            };
            _radarRangeSlider = rangeSlider;
            _radarControls.Add(rangeSlider);

            IMyTerminalControlSlider freqSlider
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyUpgradeModule>("FreqSlider");

            freqSlider.Title   = MyStringId.GetOrCompute("Frequency");
            freqSlider.Tooltip = MyStringId.GetOrCompute("Operating frequency of this system");
            freqSlider.SetLimits(8.0f, 12.0f);
            freqSlider.Getter = (block) => {
                RadarController controller = block.GameLogic.GetAs <RadarController>();
                return(controller.GetFreq());
            };
            freqSlider.Setter = (block, value) => {
                RadarController controller = block.GameLogic.GetAs <RadarController>();
                controller.SetFreq(value);
                SendRadarSettings(new BlockAddress(block.CubeGrid.EntityId, block.EntityId));
            };
            freqSlider.Writer = (block, str) => {
                RadarController controller = block.GameLogic.GetAs <RadarController>();
                str.Append(controller.GetFreq() + "GHz");
            };
            _radarFreqSlider = freqSlider;
            _radarControls.Add(freqSlider);

            IMyTerminalControlSeparator sep2
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyUpgradeModule>("Sep2");

            _radarControls.Add(sep2);

            IMyTerminalControlListbox unassignedList
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyUpgradeModule>("UnassignedList");

            unassignedList.Title = MyStringId.GetOrCompute("Available");
            //unassignedList.Tooltip = MyStringId.GetOrCompute("Radar blocks which are able to be assigned to this system.");
            unassignedList.Multiselect      = true;
            unassignedList.VisibleRowsCount = 6;
            unassignedList.ListContent      = (block, items, selected) => {
                RadarController controller
                    = block.GameLogic.GetAs <RadarController>();
                List <RadarController.Radar> available
                    = controller.GetAvailableRadars();

                foreach (RadarController.Radar r in available)
                {
                    MyTerminalControlListBoxItem item
                        = new MyTerminalControlListBoxItem(
                              MyStringId.GetOrCompute(r.block.FatBlock.DisplayNameText),
                              MyStringId.GetOrCompute(r.type.ToString()),
                              r
                              );
                    items.Add(item);
                }
            };
            unassignedList.ItemSelected = (block, items) => {
                _selectedUnassigned.Clear();

                foreach (MyTerminalControlListBoxItem item in items)
                {
                    _selectedUnassigned.Add(item.UserData as RadarController.Radar);
                }
            };
            _radarControls.Add(unassignedList);

            IMyTerminalControlButton addButton
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyUpgradeModule>("AddButton");

            addButton.Title   = MyStringId.GetOrCompute("Assign");
            addButton.Tooltip = MyStringId.GetOrCompute("Assign the selected radar to this system.");
            _radarControls.Add(addButton);

            IMyTerminalControlListbox assignedList
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyUpgradeModule>("AssignedList");

            assignedList.Title            = MyStringId.GetOrCompute("Assigned");
            assignedList.Tooltip          = MyStringId.GetOrCompute("Radar blocks which are currently assigned to this system.");
            assignedList.Multiselect      = true;
            assignedList.VisibleRowsCount = 6;
            assignedList.ListContent      = (block, items, selected) => {
                RadarController controller
                    = block.GameLogic.GetAs <RadarController>();
                List <RadarController.Radar> assigned
                    = controller.GetAssignedRadars();

                foreach (RadarController.Radar r in assigned)
                {
                    MyTerminalControlListBoxItem item
                        = new MyTerminalControlListBoxItem(
                              MyStringId.GetOrCompute(r.block.FatBlock.DisplayNameText),
                              MyStringId.GetOrCompute(r.type.ToString()),
                              r
                              );
                    items.Add(item);
                }
            };
            assignedList.ItemSelected = (block, items) => {
                _selectedAssigned.Clear();

                foreach (MyTerminalControlListBoxItem item in items)
                {
                    _selectedAssigned.Add(item.UserData as RadarController.Radar);
                }
            };
            _radarControls.Add(assignedList);

            // Add button action must be after assigned list because it
            // needs the pointer
            addButton.Action = (block) => {
                RadarController controller
                    = block.GameLogic.GetAs <RadarController>();

                foreach (RadarController.Radar radar in _selectedUnassigned)
                {
                    controller.AssignRadar(radar);
                }

                unassignedList.UpdateVisual();
                assignedList.UpdateVisual();

                SetRadarSliderLimits((int)controller.GetRadarType());
                rangeSlider.UpdateVisual();
                freqSlider.UpdateVisual();
            };

            IMyTerminalControlButton removeButton
                = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyUpgradeModule>("AddButton");

            removeButton.Title   = MyStringId.GetOrCompute("Remove");
            removeButton.Tooltip = MyStringId.GetOrCompute("Remove the selected radars from the system.");
            removeButton.Action  = (block) => {
                RadarController controller
                    = block.GameLogic.GetAs <RadarController>();

                foreach (RadarController.Radar radar in _selectedAssigned)
                {
                    controller.UnassignedRadar(radar);
                }

                unassignedList.UpdateVisual();
                assignedList.UpdateVisual();

                SetRadarSliderLimits((int)controller.GetRadarType());
                rangeSlider.UpdateVisual();
                freqSlider.UpdateVisual();
            };
            _radarControls.Add(removeButton);
        }
Beispiel #19
0
        public static void DisplayIndustrialCockpitControls(IMyTerminalBlock block, List <IMyTerminalControl> controls)
        {
            if (block.SlimBlock.BlockDefinition.Id.SubtypeName != "SmallBlockCockpitIndustrial" || !Logger.CurrentDebugTypeList.Contains(DebugTypeEnum.Terminal))
            {
                return;
            }

            //Select Block - Listbox
            var listBox = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyCockpit>("RAI-Debug-SelectTargetGrid");

            listBox.Enabled          = (b) => { return(true); };
            listBox.Visible          = (b) => { return(true); };
            listBox.VisibleRowsCount = 6;
            listBox.Multiselect      = false;
            listBox.ListContent      = (b, items, selectedItems) => {
                var settings = GetCockpitControls(b);

                var defaultItem = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("None"), MyStringId.GetOrCompute("None"), (long)0);
                items.Add(defaultItem);

                if (settings.SelectedGridId == 0)
                {
                    selectedItems.Add(defaultItem);
                }

                for (int i = BehaviorManager.Behaviors.Count - 1; i >= 0; i--)
                {
                    var behavior = BehaviorManager.Behaviors[i];

                    if (!behavior.IsAIReady())
                    {
                        continue;
                    }

                    var name = behavior.GridName;
                    var id   = behavior.GridId;

                    if (name == "N/A")
                    {
                        continue;
                    }

                    var stringId = MyStringId.GetOrCompute(string.Format("{0} - {1}", name, id));
                    var newItem  = new MyTerminalControlListBoxItem(stringId, stringId, id);
                    items.Add(newItem);

                    if (id == settings.SelectedGridId && selectedItems.Count == 0)
                    {
                        selectedItems.Add(newItem);
                    }
                }
            };
            listBox.ItemSelected = (b, selected) => {
                if (selected.Count == 0)
                {
                    return;
                }

                var settings = GetCockpitControls(b);

                if (settings.SelectedGridId != (long)selected[0].UserData)
                {
                    bool setNew = false;

                    for (int i = BehaviorManager.Behaviors.Count - 1; i >= 0; i--)
                    {
                        var behavior = BehaviorManager.Behaviors[i];

                        if (behavior.GridId == settings.SelectedGridId)
                        {
                            behavior.SetDebugCockpit(b as IMyCockpit, false);
                        }

                        if (behavior.GridId == (long)selected[0].UserData)
                        {
                            behavior.SetDebugCockpit(b as IMyCockpit, true);
                            setNew = true;
                        }
                    }

                    if (setNew)
                    {
                        settings.SelectedGridId = (long)selected[0].UserData;
                    }
                    else
                    {
                        settings.SelectedGridId = 0;
                    }

                    SetCockpitControls(b, settings);
                }
            };
            controls.Add(listBox);

            //Switch - Current Grid Invul
            var invulSwitch = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyCockpit>("RAI-Debug-GridInvul");

            invulSwitch.Enabled = (b) => { return(true); };
            invulSwitch.Visible = (b) => { return(true); };
            invulSwitch.Getter  = (b) => {
                var settings = GetCockpitControls(b);
                return(!settings.CurrentGridVulnerable);
            };

            invulSwitch.Setter = (b, mode) => {
                var settings = GetCockpitControls(b);
                var grid     = b.SlimBlock.CubeGrid as MyCubeGrid;
                grid.DestructibleBlocks        = !mode;
                settings.CurrentGridVulnerable = !mode;
                SetCockpitControls(b, settings);
            };
            invulSwitch.Title   = MyStringId.GetOrCompute("Grid Invulnerability");
            invulSwitch.OffText = MyStringId.GetOrCompute("Off");
            invulSwitch.OnText  = MyStringId.GetOrCompute("On");
            controls.Add(invulSwitch);

            //Switch - Current Grid Uneditable
            var editSwitch = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyCockpit>("RAI-Debug-GridEdit");

            editSwitch.Enabled = (b) => { return(true); };
            editSwitch.Visible = (b) => { return(true); };
            editSwitch.Getter  = (b) => {
                var settings = GetCockpitControls(b);
                return(!settings.CurrentGridEditable);
            };

            editSwitch.Setter = (b, mode) => {
                var settings = GetCockpitControls(b);
                var grid     = b.SlimBlock.CubeGrid as MyCubeGrid;
                grid.Editable = !mode;
                settings.CurrentGridEditable = !mode;
                SetCockpitControls(b, settings);
            };
            editSwitch.Title   = MyStringId.GetOrCompute("Grid Editable");
            editSwitch.OffText = MyStringId.GetOrCompute("Off");
            editSwitch.OnText  = MyStringId.GetOrCompute("On");
            controls.Add(editSwitch);
        }
Beispiel #20
0
        public static void GetForSaleGrids(IMyTerminalBlock block, List <MyTerminalControlListBoxItem> listItems, List <MyTerminalControlListBoxItem> selectedItems)
        {
            //We need to completley redo ALL this.

            try
            {
                foreach (MarketList grid in MarketGrids)
                {
                    //MyLog.Default.WriteLineAndConsole("Grid "+grid.Name+" is in the marked list grid out of "+MarketGrids.Count+" total grids");
                    if (!listItems.Any(x => x.Text == MyStringId.GetOrCompute(grid.Name)))
                    {
                        var dummy2 = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(grid.Name), MyStringId.GetOrCompute("PCU: " + grid.PCU), grid);
                        MyLog.Default.WriteLineAndConsole("Adding grid " + grid.Name + " to the block!");
                        listItems.Add(dummy2);
                    }
                }


                if (RemovedMarketGrids != null)
                {
                    try
                    {
                        var item = listItems.First(x => x.Text.String == RemovedMarketGrids.Name);
                        listItems.Remove(item);
                        MyLog.Default.WriteLineAndConsole("Removing grid from the block!");
                    }
                    catch
                    {
                        //Do freaking nothing. ffs
                    }



                    if (selectedItems.Count != 0 && selectedItems[0].Text.String == RemovedMarketGrids.Name)
                    {
                        selectedItems.Clear();
                    }



                    //Check to see if the selected item was our purchased item


                    RemovedMarketGrids = null;
                }



                //Reupdate selected items
                if (listItems.Count == 1)
                {
                    selectedItems.Clear();
                    selectedItems.Add(listItems[0]);
                    SelectedGrid = (MarketList)listItems[0].UserData;

                    MyTerminalControlListBoxItem item = listItems[0];
                    SelectedBoxItem = item;

                    block.RefreshCustomInfo();
                }
                else if (listItems.Count == 0)
                {
                    selectedItems.Clear();
                    block.RefreshCustomInfo();
                }
                else
                {
                    selectedItems.Clear();

                    if (listItems.Count == 0)
                    {
                        return;
                    }

                    selectedItems.Add(listItems.FirstOrDefault(x => x.Text == SelectedBoxItem.Text));
                }

                //var toList = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(grid.CustomName), MyStringId.GetOrCompute(grid.CustomName), objectText);


                //Can you do this?? Check to see if your saved selected item is in the new list?

                //Clear the selected grid
                //SelectedGrid = null;
                //block.RefreshCustomInfo();
            }
            catch (Exception e)
            {
                //Temp Debug
                MyLog.Default.WriteLineAndConsole("Exception Thrown! \n" + e);
            }

            //UpdateGUI(block);
        }
Beispiel #21
0
        public static void MergeNewCollection(List <MarketListing> NewOffers)
        {
            //No need to do any merge checks if the new list is null
            if (NewOffers == null || NewOffers.Count == 0)
            {
                //Remove any selected items
                SelectedBoxItem = -1;
                SelectedOffer   = null;


                MarketOffers.Clear();
                List.Clear();
                UpdateAllBlocks();
                return;
            }


            //First, lets see if we need to remove any items
            for (int i = MarketOffers.Count - 1; i >= 0; i--)
            {
                if (!NewOffers.Contains(MarketOffers[i]))
                {
                    if (SelectedOffer == MarketOffers[i])
                    {
                        //Remove any selected items
                        SelectedBoxItem = -1;
                        SelectedOffer   = null;
                    }

                    MarketOffers.RemoveAt(i);
                }
            }


            //Now see if we need to add any items
            for (int i = NewOffers.Count - 1; i >= 0; i--)
            {
                if (!MarketOffers.Contains(NewOffers[i]))
                {
                    MarketOffers.Add(NewOffers[i]);
                }
            }


            //Clear the listbox view
            List.Clear();
            for (int i = 0; i < MarketOffers.Count; i++)
            {
                MyStringId Name    = MyStringId.GetOrCompute(MarketOffers[i].Name);
                MyStringId ToolTip = MyStringId.GetOrCompute("Price: " + MarketOffers[i].Price);

                MyTerminalControlListBoxItem NewItem = new MyTerminalControlListBoxItem(Name, ToolTip, MarketOffers[i]);
                List.Add(NewItem);

                if (MarketOffers[i] == SelectedOffer)
                {
                    SelectedBoxItem = i;
                }
            }

            UpdateAllBlocks();
        }
        //MAIN TARGETING. The main targeting method, only to be run on other threads because this is laggy af.
        public static void validateTargetsThread(WorkData tempData)
        {
            Guid profilerId = SmartTurretsProfiler.Instance.Start("validateTargetsThread");

            try
            {
                TargetingData data           = (TargetingData)tempData;
                Vector3D      turretLocation = data.turret.Entity.GetPosition();
                Dictionary <IMyEntity, ushort> targetTypeDictionary = getTargetTypeDictionary(data.targets);

                //log("Turret: " + data.turret.Entity.EntityId.ToString() + " 0: " + targetTypeDictionary.Count.ToString() + " : " + getTypes(targetTypeDictionary));
                //Eliminate targets that are not functional.
                for (int i = targetTypeDictionary.Count - 1; i >= 0; i--)
                {
                    ushort curretType = targetTypeDictionary.ElementAt(i).Value;

                    //Ignore non-cube types.
                    if (curretType != 31 && curretType != 32 && curretType != 33)
                    {
                        if (((IMyCubeBlock)targetTypeDictionary.ElementAt(i).Key).IsFunctional == false)
                        {
                            targetTypeDictionary.Remove(targetTypeDictionary.ElementAt(i).Key);
                        }
                    }
                }

                //log("Turret: " + data.turret.Entity.EntityId.ToString() + " 1: " + targetTypeDictionary.Count.ToString() + " : " + getTypes(targetTypeDictionary));
                //Eliminate targets that are disabled in targeting settings.
                for (int i = targetTypeDictionary.Count - 1; i >= 0; i--)
                {
                    ushort CurretType = targetTypeDictionary.ElementAt(i).Value;
                    if (CurretType != 35)
                    {
                        MyTerminalControlListBoxItem typeItem = data.turret.targetTypesListItems.Find((x) => { return((x.UserData as ListBoxItemData).id == CurretType); });
                        if ((typeItem.UserData as ListBoxItemData).enabledState == false)
                        {
                            targetTypeDictionary.Remove(targetTypeDictionary.ElementAt(i).Key);
                        }
                    }
                }

                //log("Turret: " + data.turret.Entity.EntityId.ToString() + " 2: " + targetTypeDictionary.Count.ToString() + " : " + getTypes(targetTypeDictionary));
                //Eliminate targets that are friendly or are neutral should that be set appropriatly.
                for (int i = targetTypeDictionary.Count - 1; i >= 0; i--)
                {
                    ushort curretType = targetTypeDictionary.ElementAt(i).Value;

                    var cubeEntity = (data.turret.Entity as IMyCubeBlock);
                    if (cubeEntity != null)
                    {
                        if (curretType != 31 && curretType != 32 && curretType != 33)
                        {
                            if (curretType != 13)
                            {
                                //Check relation of blocks with ownership
                                IMyCubeBlock cubeBlock = (IMyCubeBlock)targetTypeDictionary.ElementAt(i).Key;
                                MyRelationsBetweenPlayerAndBlock relation = cubeBlock.GetUserRelationToOwner(cubeEntity.OwnerId);

                                if ((relation != MyRelationsBetweenPlayerAndBlock.Enemies && relation != MyRelationsBetweenPlayerAndBlock.Neutral) || ((relation == MyRelationsBetweenPlayerAndBlock.Neutral || relation == MyRelationsBetweenPlayerAndBlock.NoOwnership) && data.turret.targetNeutralsStateDictionary[targetTypeDictionary.ElementAt(i).Value] == false))
                                {
                                    targetTypeDictionary.Remove(targetTypeDictionary.ElementAt(i).Key);
                                }
                            }
                            else
                            {
                                //Check relation of blocks that cannot have ownership based on grid ownership
                                IMyCubeGrid cubeGrid = (targetTypeDictionary.ElementAt(i).Key as IMyCubeBlock).CubeGrid;
                                MyRelationsBetweenPlayerAndBlock relation = MyRelationsBetweenPlayerAndBlock.NoOwnership;

                                if (cubeGrid.BigOwners.Count > 0)
                                {
                                    relation = cubeEntity.GetUserRelationToOwner(cubeGrid.BigOwners[0]);
                                }

                                if ((relation != MyRelationsBetweenPlayerAndBlock.Enemies && relation != MyRelationsBetweenPlayerAndBlock.Neutral) || ((relation == MyRelationsBetweenPlayerAndBlock.Neutral || relation == MyRelationsBetweenPlayerAndBlock.NoOwnership) && data.turret.targetNeutralsStateDictionary[targetTypeDictionary.ElementAt(i).Value] == false))
                                {
                                    targetTypeDictionary.Remove(targetTypeDictionary.ElementAt(i).Key);
                                }
                            }
                        }
                        else if (curretType == 31) //Check relation of players
                        {
                            if (cubeEntity != null)
                            {
                                List <IMyPlayer> Players = new List <IMyPlayer>();
                                MyAPIGateway.Players.GetPlayers(Players, (x) => { return(x.Character.EntityId == targetTypeDictionary.ElementAt(i).Key.EntityId); });

                                //IDK why this uses MyRelationsBetweenPlayerAndBlock when MyRelationsBetweenPlayers is a thing... KEEN!
                                MyRelationsBetweenPlayerAndBlock relation = Players.First().GetRelationTo(cubeEntity.OwnerId);
                                if ((relation != MyRelationsBetweenPlayerAndBlock.Enemies && relation != MyRelationsBetweenPlayerAndBlock.Neutral) || ((relation == MyRelationsBetweenPlayerAndBlock.Neutral || relation == MyRelationsBetweenPlayerAndBlock.NoOwnership) && data.turret.targetNeutralsStateDictionary[targetTypeDictionary.ElementAt(i).Value] == false))
                                {
                                    targetTypeDictionary.Remove(targetTypeDictionary.ElementAt(i).Key);
                                }
                            }
                        }
                    }

                    //Ignore non-cube types.
                }

                //log("Turret: " + data.turret.Entity.EntityId.ToString() + " 3: " + targetTypeDictionary.Count.ToString() + " : " + getTypes(targetTypeDictionary));
                //Eliminate targets that are out of range.
                for (int i = targetTypeDictionary.Count - 1; i >= 0; i--)
                {
                    ushort CurretType = targetTypeDictionary.ElementAt(i).Value;

                    if (CurretType != 35)
                    {
                        if (checkTargetOutOfRange(turretLocation, data.turret.rangeStateDictionary[CurretType], targetTypeDictionary.ElementAt(i).Key.GetPosition()))
                        {
                            targetTypeDictionary.Remove(targetTypeDictionary.ElementAt(i).Key);
                        }
                    }
                    else
                    {
                        var terminalEntity = data.turret.Entity as IMyTerminalBlock;
                        if (terminalEntity != null)
                        {
                            if (checkTargetOutOfRange(turretLocation, getTurretMaxRange(terminalEntity), targetTypeDictionary.ElementAt(i).Key.GetPosition()))
                            {
                                targetTypeDictionary.Remove(targetTypeDictionary.ElementAt(i).Key);
                            }
                        }
                    }
                }

                //log("Turret: " + data.turret.Entity.EntityId.ToString() + " 4: " + targetTypeDictionary.Count.ToString() + " : " + getTypes(targetTypeDictionary));
                //Eliminate targets that are on the wrong type of grid.
                for (int i = targetTypeDictionary.Count - 1; i >= 0; i--)
                {
                    ushort curretType = targetTypeDictionary.ElementAt(i).Value;

                    //Ignore non-cube types and decoys.
                    if (curretType != 31 && curretType != 32 && curretType != 33 && curretType != 35)
                    {
                        IMyCubeGrid grid          = ((IMyCubeBlock)targetTypeDictionary.ElementAt(i).Key).CubeGrid;
                        bool        targetLarge   = data.turret.targetLargeGridsStateDictionary[targetTypeDictionary.ElementAt(i).Value];
                        bool        targetSmall   = data.turret.targetSmallGridsStateDictionary[targetTypeDictionary.ElementAt(i).Value];
                        bool        targetStation = data.turret.targetStationsStateDictionary[targetTypeDictionary.ElementAt(i).Value];

                        if ((grid.GridSizeEnum == MyCubeSize.Large && targetLarge == false) || (grid.GridSizeEnum == MyCubeSize.Small && targetSmall == false) || (grid.IsStatic == true && targetStation == false))
                        {
                            targetTypeDictionary.Remove(targetTypeDictionary.ElementAt(i).Key);
                        }
                    }
                }

                //log("Turret: " + data.turret.Entity.EntityId.ToString() + " 5: " + targetTypeDictionary.Count.ToString() + " : " + getTypes(targetTypeDictionary));
                //Eliminate targets that are on grids that are too small.
                for (int i = targetTypeDictionary.Count - 1; i >= 0; i--)
                {
                    ushort curretType = targetTypeDictionary.ElementAt(i).Value;

                    //Ignore non-cube types and decoys.
                    if (curretType != 31 && curretType != 32 && curretType != 33 && curretType != 35)
                    {
                        List <IMySlimBlock> gridBlocks = new List <IMySlimBlock>();
                        try
                        {
                            ((IMyCubeBlock)targetTypeDictionary.ElementAt(i).Key).CubeGrid.GetBlocks(gridBlocks);
                        }
                        catch
                        {
                            //Problematic Enumeration error, stop targeting.
                            data.validTargetID = null;
                            return;
                        }

                        //MinGridSize
                        if (gridBlocks.Count < data.turret.minimumGridSizeStateDictionary[targetTypeDictionary.ElementAt(i).Value])
                        {
                            targetTypeDictionary.Remove(targetTypeDictionary.ElementAt(i).Key);
                        }
                    }
                }

                //log("Turret: " + data.turret.Entity.EntityId.ToString() + " 6: " + targetTypeDictionary.Count.ToString() + " : " + getTypes(targetTypeDictionary));
                //Eliminate targets that are out of the turrets firing ark.

                for (int i = targetTypeDictionary.Count - 1; i >= 0; i--)
                {
                    if (isInFiringArk(data.turret, targetTypeDictionary.ElementAt(i).Key.GetPosition()) == false)
                    {
                        targetTypeDictionary.Remove(targetTypeDictionary.ElementAt(i).Key);
                    }
                }


                //log("Turret: " + data.turret.Entity.EntityId.ToString() + " 7: " + targetTypeDictionary.Count.ToString() + " : " + getTypes(targetTypeDictionary));
                //Sort targets by priority and distance.
                List <IMyEntity> tempTargets = targetTypeDictionary.Keys.ToList();
                if (data.turret.Entity != null)
                {
                    tempTargets.Sort(new SortByTargetingPriorityAndDistance(data.turret.Entity.GetPosition(), targetTypeDictionary, data.turret.targetTypesListItems));
                }


                //log("Turret: " + data.turret.Entity.EntityId.ToString() + " 8");
                //Update TargetTypeDictionary with new order.
                targetTypeDictionary = getTargetTypeDictionary(tempTargets);

                //log("Turret: " + data.turret.Entity.EntityId.ToString() + " 9: " + targetTypeDictionary.Count.ToString() + " : " + getTypes(targetTypeDictionary));
                //Start shooting rays.
                //try
                //{
                data.validTargetID = castTargetingRay(targetTypeDictionary, data.turret);
                //}
                //catch (Exception err)
                //{
                //    log(err.Message);
                //    log(err.StackTrace);
                //}
            }
            catch (Exception e)
            {
                log(e.Message);
                log(e.StackTrace);
            }

            SmartTurretsProfiler.Instance.Stop(profilerId);
        }