Example #1
0
        //protected static IMyTerminalControlButton SaveButton;
        protected void CreateTerminalControls <T>()
        {
            if (m_ControlsInited.Contains(typeof(T)))
            {
                return;
            }
            m_ControlsInited.Add(typeof(T));
            if (Seperator == null)
            {
                Seperator         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, T>(string.Empty);
                Seperator.Visible = (b) => b.IsRadar();
            }
            MyAPIGateway.TerminalControls.AddControl <T>(Seperator);
            if (RangeControl == null)
            {
                RangeControl         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, T>("Draygo.Radar.Range");
                RangeControl.Visible = (b) => b.IsRadar();                // b.IsRadar();
                RangeControl.Enabled = (b) => b.IsRadar();
                RangeControl.Getter  = (b) => b.GameLogic.GetAs <Radar>().Range;
                RangeControl.Writer  = (b, v) => v.AppendFormat("{0:N1} {1}", b.GameLogic.GetAs <Radar>().Range, MyStringId.GetOrCompute("km"));
                RangeControl.Setter  = (b, v) => b.GameLogic.GetAs <Radar>().Range = v;
                RangeControl.Title   = MyStringId.GetOrCompute("Range");
                RangeControl.Tooltip = MyStringId.GetOrCompute("Range in KM");
                RangeControl.SupportsMultipleBlocks = true;
                RangeControl.SetLimits(0.001f, 50.0f);
            }
            MyAPIGateway.TerminalControls.AddControl <T>(RangeControl);
            if (Seperator2 == null)
            {
                Seperator2         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, T>(string.Empty);
                Seperator2.Visible = (b) => b.IsRadar();
            }
            MyAPIGateway.TerminalControls.AddControl <T>(Seperator2);
            //MyAPIGateway.TerminalControls.AddControl<T>(RangeControl);
            //if (PitchCheck == null)
            //{
            //	PitchCheck = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlCheckbox, IMyTerminalBlock>("Draygo.ControlSurface.Pitch");
            //	PitchCheck.Visible = (b) => b.IsControlSurface();
            //	PitchCheck.Enabled = (b) => b.IsControlSurface() && b.IsWorking;
            //	PitchCheck.Getter = (b) => b.GameLogic.GetAs<Holo>().Control.EnablePitch;
            //	PitchCheck.Setter = (b, v) => b.GameLogic.GetAs<Holo>().Control.EnablePitch = v;
            //	PitchCheck.Title = MyStringId.GetOrCompute("Pitch");
            //	PitchCheck.Tooltip = MyStringId.GetOrCompute("Enable Pitch Control");
            //	PitchCheck.SupportsMultipleBlocks = true;
            //}
            //MyAPIGateway.TerminalControls.AddControl<T>(PitchCheck);
            var RangeProperty = MyAPIGateway.TerminalControls.CreateProperty <float, T>("Radar.Range");

            if (RangeProperty != null)
            {
                RangeProperty.Enabled = (b) => b.IsRadar();
                RangeProperty.Getter  = (b) => b.GameLogic.GetAs <Radar>().Range;
                RangeProperty.Setter  = (b, v) => b.GameLogic.GetAs <Radar>().Range = v;
                MyAPIGateway.TerminalControls.AddControl <T>(RangeProperty);
            }
        }
Example #2
0
        public static void CreateControlSeperator(string id, Func <IMyTerminalBlock, bool> visible)
        {
            if (ControlIdExists(id) != null)
            {
                return;
            }

            IMyTerminalControlSeparator seperator = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyUpgradeModule>(id);

            seperator.Visible = visible;
            MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(seperator);
        }
Example #3
0
        private void create_controller_widgets <_controller_type_>() where _controller_type_ : IMyShipController
        {
            if (!screen_info.torque_disabled)
            {
                IMyTerminalControlSeparator controller_line = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, _controller_type_>("TTDTWM_LINE1");
                MyAPIGateway.TerminalControls.AddControl <_controller_type_>(controller_line);
                create_checkbox <_controller_type_>("RotationalDamping", "Rotational Damping", null, "On", "Off", thruster_and_grid_tagger.is_grid_rotational_damping_on, thruster_and_grid_tagger.set_grid_rotational_damping, thruster_and_grid_tagger.is_grid_control_available);
                create_switch <_controller_type_>("CoTMode", "Active Control Reference", null, "CoT", "CoM", "CoT", "CoM", thruster_and_grid_tagger.is_grid_CoT_mode_on, thruster_and_grid_tagger.set_grid_CoT_mode, thruster_and_grid_tagger.is_grid_control_available);
                create_switch <_controller_type_>("IndividualCalibration", "Thrust Calibration Method", null, "Ind.", "Quad", "Ind.", "Quad", thruster_and_grid_tagger.use_individual_calibration, thruster_and_grid_tagger.choose_calibration_method, thruster_and_grid_tagger.is_grid_control_available);
                create_switch <_controller_type_>("LandingMode", "Touchdown Mode", null, "On", "Off", "Land", "Flight", thruster_and_grid_tagger.is_grid_touchdown_mode_on, thruster_and_grid_tagger.set_grid_touchdown_mode, thruster_and_grid_tagger.is_grid_touchdown_mode_available);

                create_slider <_controller_type_>("ControlSensitivity", "Thrust Control Sensitivity",
                                                  thruster_and_grid_tagger.get_control_sensitivity, thruster_and_grid_tagger.set_control_sensitivity, thruster_and_grid_tagger.control_sensitivity_text,
                                                  0.1f, 20.0f, 0.1f, "IncreaseSensitivity", "DecreaseSensitivity", "Increase Control Sensitivity", "Decrease Control Sensitivity");

                IMyTerminalControlSeparator controller_line2 = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, _controller_type_>("TTDTWM_LINE2");
                MyAPIGateway.TerminalControls.AddControl <_controller_type_>(controller_line2);
                IMyTerminalControlLabel controller_line_ID_override_label = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlLabel, _controller_type_>("TTDTWM_ID_OVR");
                controller_line_ID_override_label.Label = MyStringId.GetOrCompute("Inertia Damper Overrides");
                MyAPIGateway.TerminalControls.AddControl <_controller_type_>(controller_line_ID_override_label);
                create_checkbox <_controller_type_>("ForeAftIDDisable", "Disable fore/aft", null, "On", "Off", thruster_and_grid_tagger.create_damper_override_reader(2), thruster_and_grid_tagger.create_damper_override_setter(2), thruster_and_grid_tagger.is_grid_control_available);
                create_checkbox <_controller_type_>("PortStarboardIDDisable", "Disable port/starboard", null, "On", "Off", thruster_and_grid_tagger.create_damper_override_reader(0), thruster_and_grid_tagger.create_damper_override_setter(0), thruster_and_grid_tagger.is_grid_control_available);
                create_checkbox <_controller_type_>("DorsalVentralIDDisable", "Disable dorsal/ventral", null, "On", "Off", thruster_and_grid_tagger.create_damper_override_reader(1), thruster_and_grid_tagger.create_damper_override_setter(1), thruster_and_grid_tagger.is_grid_control_available);
            }

            IMyTerminalControlLabel controller_line_ID_mode = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlLabel, _controller_type_>("TTDTWM_IDMODE");

            controller_line_ID_mode.Label = MyStringId.GetOrCompute("Inertia Damper Mode");
            MyAPIGateway.TerminalControls.AddControl <_controller_type_>(controller_line_ID_mode);
            create_button <_controller_type_>("IDFullStop", "Full Stop", null, "Select", thruster_and_grid_tagger.create_ID_mode_selector(false), thruster_and_grid_tagger.is_grid_control_available, thruster_and_grid_tagger.create_ID_mode_indicator(false));
            create_button <_controller_type_>("IDCircularise", "Circularise", null, "Select", thruster_and_grid_tagger.create_ID_mode_selector(true), thruster_and_grid_tagger.is_grid_circularise_mode_available, thruster_and_grid_tagger.create_ID_mode_indicator(true));

            IMyTerminalControlLabel controller_line_manoeuvre = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlLabel, _controller_type_>("TTDTWM_IDmanoeuvre");

            controller_line_manoeuvre.Label = MyStringId.GetOrCompute("Manoeuvres");
            MyAPIGateway.TerminalControls.AddControl <_controller_type_>(controller_line_manoeuvre);
            create_button <_controller_type_>("IDPrograde", "Prograde", null, "Start", thruster_and_grid_tagger.create_manoeuvre_starter(engine_control_unit.ID_manoeuvres.burn_prograde), thruster_and_grid_tagger.is_grid_circularise_mode_available, thruster_and_grid_tagger.create_manoeuvre_indicator(engine_control_unit.ID_manoeuvres.burn_prograde));
            create_button <_controller_type_>("IDRetrograde", "Retrograde", null, "Start", thruster_and_grid_tagger.create_manoeuvre_starter(engine_control_unit.ID_manoeuvres.burn_retrograde), thruster_and_grid_tagger.is_grid_circularise_mode_available, thruster_and_grid_tagger.create_manoeuvre_indicator(engine_control_unit.ID_manoeuvres.burn_retrograde));
            create_button <_controller_type_>("IDNormal", "Normal", null, "Start", thruster_and_grid_tagger.create_manoeuvre_starter(engine_control_unit.ID_manoeuvres.burn_normal), thruster_and_grid_tagger.is_grid_circularise_mode_available, thruster_and_grid_tagger.create_manoeuvre_indicator(engine_control_unit.ID_manoeuvres.burn_normal));
            create_button <_controller_type_>("IDAntiNormal", "Anti-normal", null, "Start", thruster_and_grid_tagger.create_manoeuvre_starter(engine_control_unit.ID_manoeuvres.burn_antinormal), thruster_and_grid_tagger.is_grid_circularise_mode_available, thruster_and_grid_tagger.create_manoeuvre_indicator(engine_control_unit.ID_manoeuvres.burn_antinormal));
            create_button <_controller_type_>("IDOutward", "Outward", null, "Start", thruster_and_grid_tagger.create_manoeuvre_starter(engine_control_unit.ID_manoeuvres.burn_outward), thruster_and_grid_tagger.is_grid_circularise_mode_available, thruster_and_grid_tagger.create_manoeuvre_indicator(engine_control_unit.ID_manoeuvres.burn_outward));
            create_button <_controller_type_>("IDInward", "Inward", null, "Start", thruster_and_grid_tagger.create_manoeuvre_starter(engine_control_unit.ID_manoeuvres.burn_inward), thruster_and_grid_tagger.is_grid_circularise_mode_available, thruster_and_grid_tagger.create_manoeuvre_indicator(engine_control_unit.ID_manoeuvres.burn_inward));

            create_PB_property <int, _controller_type_>("CurrentIDMode", get_current_ID_mode);
        }
Example #4
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);
        }
        // Context: All
        public override void UpdateOnceBeforeFrame()
        {
            if (me.CubeGrid?.Physics == null)
            {
                return;
            }

            _state = new SyncableProjectorState(me, State.Idle, 0);

            if (Constants.IsServer)
            {
                LoadStorage();
                _settings.OnValueReceived += SaveStorage;
                BuildState           = State.Idle;
                me.IsWorkingChanged += Me_IsWorkingChanged;
            }
            else
            {
                _settings = new SyncableProjectorSettings(me, 0, true);
                _state.RequestFromServer();
                _settings.RequestFromServer();
                _state.OnValueReceived += ReceivedNewState;
            }

            MyProjectorDefinition def = (MyProjectorDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(me.BlockDefinition);

            minPower = def.RequiredPowerInput;
            sink     = me.Components.Get <MyResourceSinkComponent>();
            MyDefinitionId powerDef = MyResourceDistributorComponent.ElectricityId;

            sink.SetRequiredInputFuncByType(powerDef, GetCurrentPower);
            sink.Update();
            _settings.OnValueReceived += RefreshUI;

            me.AppendingCustomInfo += CustomInfo;
            me.RefreshCustomInfo();

            Settings.MapSettings config = IPSession.Instance.MapSettings;
            config.OnSubgridsChanged += ClearCachedComps;
            config.OnComponentCostModifierChanged += ClearCachedComps;
            config.OnExtraComponentChanged        += ClearCachedComps;
            config.OnExtraCompCostChanged         += ClearCachedComps;

            if (!controls)
            {
                // Terminal controls

                IMyTerminalControlSeparator sep = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyProjector>("BuildGridSep");
                sep.Enabled = IsValid;
                sep.Visible = IsValid;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sep);

                IMyTerminalControlButton btnBuild = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("BuildGrid");
                btnBuild.Enabled = IsWorking;
                btnBuild.Visible = IsValid;
                btnBuild.SupportsMultipleBlocks = true;
                btnBuild.Title   = MyStringId.GetOrCompute("Build Grid");
                btnBuild.Action  = BuildClient;
                btnBuild.Tooltip = MyStringId.GetOrCompute("Builds the projection instantly.\nThere will be a cooldown after building.");
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnBuild);

                IMyTerminalControlButton btnCancel = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("CancelBuildGrid");
                btnCancel.Enabled = IsWorking;
                btnCancel.Visible = IsValid;
                btnCancel.SupportsMultipleBlocks = true;
                btnCancel.Title   = MyStringId.GetOrCompute("Cancel");
                btnCancel.Action  = CancelClient;
                btnCancel.Tooltip = MyStringId.GetOrCompute("Cancels the build process.");
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnCancel);

                IMyTerminalControlCheckbox chkShift = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCheckbox, IMyProjector>("MoveProjectionArea");
                chkShift.Enabled = IsWorking;
                chkShift.Visible = IsValid;
                chkShift.SupportsMultipleBlocks = true;
                chkShift.Title   = MyStringId.GetOrCompute("Loose Projection Area");
                chkShift.OnText  = MyStringId.GetOrCompute("On");
                chkShift.OffText = MyStringId.GetOrCompute("Off");
                chkShift.Tooltip = MyStringId.GetOrCompute("Allow the projection to spawn in a different area if the original area is occupied.");
                chkShift.Setter  = SetLooseArea;
                chkShift.Getter  = GetLooseArea;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(chkShift);

                IMyTerminalControlSlider sliderSpeed = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyProjector>("BuildSpeed");
                sliderSpeed.Enabled = IsWorking;
                sliderSpeed.Visible = IsValid;
                sliderSpeed.SupportsMultipleBlocks = true;
                sliderSpeed.Title   = MyStringId.GetOrCompute("Speed");
                sliderSpeed.Tooltip = MyStringId.GetOrCompute("Increasing the speed will use more energy.");
                sliderSpeed.SetLogLimits(Constants.minSpeed, Constants.maxSpeed);
                sliderSpeed.Writer = GetSpeedText;
                sliderSpeed.Getter = GetSpeed;
                sliderSpeed.Setter = SetSpeed;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sliderSpeed);

                IMyTerminalControlTextbox txtTimeout = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, IMyProjector>("GridTimer");
                txtTimeout.Enabled = (b) => false;
                txtTimeout.Visible = IsValid;
                txtTimeout.Getter  = GetTimer;
                txtTimeout.Setter  = (b, s) => { };
                txtTimeout.SupportsMultipleBlocks = false;
                txtTimeout.Title   = MyStringId.GetOrCompute("Build Timer");
                txtTimeout.Tooltip = MyStringId.GetOrCompute("The amount of time you must wait after building a grid to be able to build another.");
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(txtTimeout);

                // Terminal actions
                // Button panels are special and trigger on the server instead of the client, making everything more complicated.

                IMyTerminalAction aCancel = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildAction");
                aCancel.Enabled             = IsValid;
                aCancel.Action              = CancelClient; // For all except button panels
                aCancel.ValidForGroups      = true;
                aCancel.Name                = new StringBuilder("Cancel Spawn Grid");
                aCancel.Writer              = (b, s) => s.Append("Cancel");
                aCancel.InvalidToolbarTypes = new[] { MyToolbarType.ButtonPanel }.ToList();
                MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel);
                IMyTerminalAction aCancel2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildGrid");
                aCancel2.Enabled             = IsValid;
                aCancel2.Action              = CancelClientUnsafe; // For only button panels
                aCancel2.ValidForGroups      = true;
                aCancel2.Name                = new StringBuilder("Cancel Spawn Grid");
                aCancel2.Writer              = (b, s) => s.Append("Cancel");
                aCancel2.InvalidToolbarTypes = new List <MyToolbarType> {
                    MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit,
                    MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator
                };
                MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel2);

                IMyTerminalAction aBuild = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGridAction");
                aBuild.Enabled             = IsValid;
                aBuild.Action              = BuildClient; // For all except button panels
                aBuild.ValidForGroups      = true;
                aBuild.Name                = new StringBuilder("Spawn Grid");
                aBuild.Writer              = (b, s) => s.Append("Spawn");
                aBuild.InvalidToolbarTypes = new [] { MyToolbarType.ButtonPanel }.ToList();
                MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild);
                IMyTerminalAction aBuild2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGrid");
                aBuild2.Enabled             = IsValid;
                aBuild2.Action              = BuildClientUnsafe; // For only button panels
                aBuild2.ValidForGroups      = true;
                aBuild2.Name                = new StringBuilder("Spawn Grid");
                aBuild2.Writer              = (b, s) => s.Append("Spawn");
                aBuild2.InvalidToolbarTypes = new List <MyToolbarType> {
                    MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit,
                    MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator
                };
                MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild2);

                IMyTerminalControlListbox itemList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyProjector>("ComponentList");
                itemList.Enabled                = IsWorking;
                itemList.Visible                = IsValid;
                itemList.ListContent            = GetItemList;
                itemList.Multiselect            = false;
                itemList.SupportsMultipleBlocks = false;
                itemList.Title            = MyStringId.GetOrCompute("Components");
                itemList.VisibleRowsCount = 10;
                itemList.ItemSelected     = (b, l) => { };
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemList);


                // Programmable Block stuff

                IMyTerminalControlProperty <Dictionary <MyItemType, int> > itemListProp
                    = MyAPIGateway.TerminalControls.CreateProperty <Dictionary <MyItemType, int>, IMyProjector>("RequiredComponents");
                itemListProp.Enabled = IsWorking;
                itemListProp.Visible = IsValid;
                itemListProp.SupportsMultipleBlocks = false;
                itemListProp.Setter = (b, l) => { };
                itemListProp.Getter = GetItemListPB;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemListProp);

                IMyTerminalControlProperty <int> gridTimeoutProp
                    = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerProjection");
                gridTimeoutProp.Enabled = IsWorking;
                gridTimeoutProp.Visible = IsValid;
                gridTimeoutProp.SupportsMultipleBlocks = false;
                gridTimeoutProp.Setter = (b, l) => { };
                gridTimeoutProp.Getter = GetMaxTimerPB;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutProp);

                IMyTerminalControlProperty <int> gridTimeoutActive
                    = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerCurrent");
                gridTimeoutActive.Enabled = IsWorking;
                gridTimeoutActive.Visible = IsValid;
                gridTimeoutActive.SupportsMultipleBlocks = false;
                gridTimeoutActive.Setter = (b, l) => { };
                gridTimeoutActive.Getter = GetCurrentTimerPB;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive);

                IMyTerminalControlProperty <int> buildState
                    = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("BuildState");
                buildState.Enabled = IsWorking;
                buildState.Visible = IsValid;
                buildState.SupportsMultipleBlocks = false;
                buildState.Setter = (b, l) => { };
                buildState.Getter = GetStatePB;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive);

                MyLog.Default.WriteLineAndConsole("Initialized Instant Projector.");
                controls = true;
            }
        }
        public static void Create()
        {
            if (controls)
            {
                return;
            }

            IMyTerminalControlSeparator sep = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyProjector>("BuildGridSep");

            sep.Enabled = IsValid;
            sep.Visible = IsValid;
            sep.SupportsMultipleBlocks = true;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sep);

            IMyTerminalControlLabel lbl = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlLabel, IMyProjector>("BuildGridLabel");

            lbl.Enabled = IsValid;
            lbl.Visible = IsValid;
            lbl.SupportsMultipleBlocks = true;
            lbl.Label = MyStringId.GetOrCompute("Instant Projector Controls");
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(lbl);

            IMyTerminalControlButton btnBuild = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("BuildGrid");

            btnBuild.Enabled = IsWorking;
            btnBuild.Visible = IsValid;
            btnBuild.SupportsMultipleBlocks = true;
            btnBuild.Title   = MyStringId.GetOrCompute("Build Grid");
            btnBuild.Action  = BuildClient;
            btnBuild.Tooltip = MyStringId.GetOrCompute("Builds the projection instantly.\nThere will be a cooldown after building.");
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnBuild);

            IMyTerminalControlButton btnCancel = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("CancelBuildGrid");

            btnCancel.Enabled = IsWorking;
            btnCancel.Visible = IsValid;
            btnCancel.SupportsMultipleBlocks = true;
            btnCancel.Title   = MyStringId.GetOrCompute("Cancel");
            btnCancel.Action  = CancelClient;
            btnCancel.Tooltip = MyStringId.GetOrCompute("Cancels the build process.");
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnCancel);

            IMyTerminalControlCheckbox chkShift = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCheckbox, IMyProjector>("MoveProjectionArea");

            chkShift.Enabled = IsWorking;
            chkShift.Visible = IsValid;
            chkShift.SupportsMultipleBlocks = true;
            chkShift.Title   = MyStringId.GetOrCompute("Loose Projection Area");
            chkShift.OnText  = MyStringId.GetOrCompute("On");
            chkShift.OffText = MyStringId.GetOrCompute("Off");
            chkShift.Tooltip = MyStringId.GetOrCompute("Allow the projection to spawn in a different area if the original area is occupied.");
            chkShift.Setter  = SetLooseArea;
            chkShift.Getter  = GetLooseArea;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(chkShift);

            IMyTerminalControlSlider sliderSpeed = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyProjector>("BuildSpeed");

            sliderSpeed.Enabled = IsWorking;
            sliderSpeed.Visible = IsValid;
            sliderSpeed.SupportsMultipleBlocks = true;
            sliderSpeed.Title   = MyStringId.GetOrCompute("Speed");
            sliderSpeed.Tooltip = MyStringId.GetOrCompute("Increasing the speed will use more energy.");
            sliderSpeed.SetLogLimits(Constants.minSpeed, Constants.maxSpeed);
            sliderSpeed.Writer = GetSpeedText;
            sliderSpeed.Getter = GetSpeed;
            sliderSpeed.Setter = SetSpeed;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sliderSpeed);

            IMyTerminalControlTextbox txtTimeout = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, IMyProjector>("GridTimer");

            txtTimeout.Enabled = (b) => false;
            txtTimeout.Visible = IsValid;
            txtTimeout.Getter  = GetTimer;
            txtTimeout.Setter  = (b, s) => { };
            txtTimeout.SupportsMultipleBlocks = false;
            txtTimeout.Title   = MyStringId.GetOrCompute("Build Timer");
            txtTimeout.Tooltip = MyStringId.GetOrCompute("The amount of time you must wait after building a grid to be able to build another.");
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(txtTimeout);

            // Terminal actions
            // Button panels are special and trigger on the server instead of the client, making everything more complicated.

            IMyTerminalAction aCancel = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildAction");

            aCancel.Enabled             = IsValid;
            aCancel.Action              = CancelClient; // For all except button panels
            aCancel.ValidForGroups      = true;
            aCancel.Name                = new StringBuilder("Cancel Spawn Grid");
            aCancel.Writer              = (b, s) => s.Append("Cancel");
            aCancel.InvalidToolbarTypes = new[] { MyToolbarType.ButtonPanel }.ToList();
            MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel);
            IMyTerminalAction aCancel2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildGrid");

            aCancel2.Enabled             = IsValid;
            aCancel2.Action              = CancelClientUnsafe; // For only button panels
            aCancel2.ValidForGroups      = true;
            aCancel2.Name                = new StringBuilder("Cancel Spawn Grid");
            aCancel2.Writer              = (b, s) => s.Append("Cancel");
            aCancel2.InvalidToolbarTypes = new List <MyToolbarType> {
                MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit,
                MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator
            };
            MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel2);

            IMyTerminalAction aBuild = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGridAction");

            aBuild.Enabled             = IsValid;
            aBuild.Action              = BuildClient; // For all except button panels
            aBuild.ValidForGroups      = true;
            aBuild.Name                = new StringBuilder("Spawn Grid");
            aBuild.Writer              = (b, s) => s.Append("Spawn");
            aBuild.InvalidToolbarTypes = new[] { MyToolbarType.ButtonPanel }.ToList();
            MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild);
            IMyTerminalAction aBuild2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGrid");

            aBuild2.Enabled             = IsValid;
            aBuild2.Action              = BuildClientUnsafe; // For only button panels
            aBuild2.ValidForGroups      = true;
            aBuild2.Name                = new StringBuilder("Spawn Grid");
            aBuild2.Writer              = (b, s) => s.Append("Spawn");
            aBuild2.InvalidToolbarTypes = new List <MyToolbarType> {
                MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit,
                MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator
            };
            MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild2);

            IMyTerminalControlListbox itemList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyProjector>("ComponentList");

            itemList.Enabled                = IsWorking;
            itemList.Visible                = IsValid;
            itemList.ListContent            = GetItemList;
            itemList.Multiselect            = false;
            itemList.SupportsMultipleBlocks = false;
            itemList.Title            = MyStringId.GetOrCompute("Components");
            itemList.VisibleRowsCount = 10;
            itemList.ItemSelected     = (b, l) => { };
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemList);

            IMyTerminalControlButton itemListInfo = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("ComponentListInfo");

            itemListInfo.Enabled = IsWorking;
            itemListInfo.Visible = IsValid;
            itemListInfo.SupportsMultipleBlocks = false;
            itemListInfo.Title  = MyStringId.GetOrCompute("Check Inventory");
            itemListInfo.Action = OpenItemList;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemListInfo);


            // Programmable Block stuff

            IMyTerminalControlProperty <Dictionary <MyItemType, int> > itemListProp
                = MyAPIGateway.TerminalControls.CreateProperty <Dictionary <MyItemType, int>, IMyProjector>("RequiredComponents");

            itemListProp.Enabled = IsWorking;
            itemListProp.Visible = IsValid;
            itemListProp.SupportsMultipleBlocks = false;
            itemListProp.Setter = (b, l) => { };
            itemListProp.Getter = GetItemListPB;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemListProp);

            IMyTerminalControlProperty <int> gridTimeoutProp
                = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerProjection");

            gridTimeoutProp.Enabled = IsWorking;
            gridTimeoutProp.Visible = IsValid;
            gridTimeoutProp.SupportsMultipleBlocks = false;
            gridTimeoutProp.Setter = (b, l) => { };
            gridTimeoutProp.Getter = GetMaxTimerPB;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutProp);

            IMyTerminalControlProperty <int> gridTimeoutActive
                = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerCurrent");

            gridTimeoutActive.Enabled = IsWorking;
            gridTimeoutActive.Visible = IsValid;
            gridTimeoutActive.SupportsMultipleBlocks = false;
            gridTimeoutActive.Setter = (b, l) => { };
            gridTimeoutActive.Getter = GetCurrentTimerPB;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive);

            IMyTerminalControlProperty <int> buildState
                = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("BuildState");

            buildState.Enabled = IsWorking;
            buildState.Visible = IsValid;
            buildState.SupportsMultipleBlocks = false;
            buildState.Setter = (b, l) => { };
            buildState.Getter = GetStatePB;
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive);

            MyLog.Default.WriteLineAndConsole("Initialized Instant Projector.");
            controls = true;
        }
Example #7
0
        public override void UpdateOnceBeforeFrame()
        {
            if (_init)
            {
                return;
            }

            _init  = true;
            _block = Entity as IMyCollector;

            if (_block == null)
            {
                return;
            }

            //create terminal controls
            IMyTerminalControlSeparator sep = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyCollector>(string.Empty);

            sep.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(sep);

            IMyTerminalControlOnOffSwitch guideSwitch = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyCollector>("Shipyard_GuideSwitch");

            guideSwitch.Title   = MyStringId.GetOrCompute("Guide Boxes");
            guideSwitch.Tooltip = MyStringId.GetOrCompute("Toggles the guide boxes drawn around grids in the shipyard.");
            guideSwitch.OnText  = MyStringId.GetOrCompute("On");
            guideSwitch.OffText = MyStringId.GetOrCompute("Off");
            guideSwitch.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            guideSwitch.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b) != null;
            guideSwitch.SupportsMultipleBlocks = true;
            guideSwitch.Getter = GetGuideEnabled;
            guideSwitch.Setter = SetGuideEnabled;
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(guideSwitch);
            Controls.Add(guideSwitch);

            var lockSwitch = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyCollector>("Shipyard_LockSwitch");

            lockSwitch.Title   = MyStringId.GetOrCompute("Advanced Locking");
            lockSwitch.Tooltip = MyStringId.GetOrCompute("Toggles locking grids in the shipyard when grinding or welding while moving.");
            lockSwitch.OnText  = MyStringId.GetOrCompute("On");
            lockSwitch.OffText = MyStringId.GetOrCompute("Off");
            lockSwitch.Visible = b => b.BlockDefinition.SubtypeId.Equals("ShipyardCorner_Small");
            lockSwitch.Enabled = b => b.BlockDefinition.SubtypeId.Equals("ShipyardCorner_Small") && GetYard(b) != null;
            lockSwitch.SupportsMultipleBlocks = true;
            lockSwitch.Getter = GetLockEnabled;
            lockSwitch.Setter = SetLockEnabled;
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(lockSwitch);
            Controls.Add(lockSwitch);

            IMyTerminalControlButton grindButton = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyCollector>("Shipyard_GrindButton");
            IMyTerminalControlButton weldButton  = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyCollector>("Shipyard_WeldButton");
            IMyTerminalControlButton stopButton  = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyCollector>("Shipyard_StopButton");

            grindButton.Title   = MyStringId.GetOrCompute("Grind");
            grindButton.Tooltip = MyStringId.GetOrCompute("Begins grinding ships in the yard.");
            grindButton.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b)?.YardType == ShipyardType.Disabled;
            grindButton.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            grindButton.SupportsMultipleBlocks = true;
            grindButton.Action = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Grind);
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(grindButton);
            Controls.Add(grindButton);

            weldButton.Title   = MyStringId.GetOrCompute("Weld");
            weldButton.Tooltip = MyStringId.GetOrCompute("Begins welding ships in the yard.");
            weldButton.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b)?.YardType == ShipyardType.Disabled;
            weldButton.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            weldButton.SupportsMultipleBlocks = true;
            weldButton.Action = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Weld);
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(weldButton);
            Controls.Add(weldButton);

            stopButton.Title   = MyStringId.GetOrCompute("Stop");
            stopButton.Tooltip = MyStringId.GetOrCompute("Stops the shipyard.");
            stopButton.Enabled = b =>
            {
                if (!b.BlockDefinition.SubtypeId.Contains("ShipyardCorner"))
                {
                    return(false);
                }

                ShipyardItem yard = GetYard(b);

                return(yard?.YardType == ShipyardType.Weld || yard?.YardType == ShipyardType.Grind);
            };
            stopButton.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            stopButton.SupportsMultipleBlocks = true;
            stopButton.Action = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Disabled);
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(stopButton);
            Controls.Add(stopButton);

            IMyTerminalControlCombobox buildPattern = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCombobox, IMyCollector>("Shipyard_BuildPattern");

            buildPattern.Title           = MyStringId.GetOrCompute("Build Pattern");
            buildPattern.Tooltip         = MyStringId.GetOrCompute("Pattern used to build projections.");
            buildPattern.ComboBoxContent = FillPatternCombo;
            buildPattern.Visible         = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            buildPattern.Enabled         = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b)?.YardType == ShipyardType.Disabled;
            buildPattern.Getter          = GetBuildPattern;
            buildPattern.Setter          = SetBuildPattern;
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(buildPattern);
            Controls.Add(buildPattern);

            IMyTerminalControlSlider beamCountSlider = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyCollector>("Shipyard_BeamCount");

            beamCountSlider.Title = MyStringId.GetOrCompute("Beam Count");

            beamCountSlider.Tooltip = MyStringId.GetOrCompute("Number of beams this shipyard can use per corner.");
            beamCountSlider.SetLimits(1, 3);
            beamCountSlider.Writer  = (b, result) => result.Append(GetBeamCount(b));
            beamCountSlider.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            beamCountSlider.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b) != null;
            beamCountSlider.Getter  = b => GetBeamCount(b);
            beamCountSlider.Setter  = (b, v) =>
            {
                SetBeamCount(b, (int)Math.Round(v, 0, MidpointRounding.ToEven));
                beamCountSlider.UpdateVisual();
            };
            beamCountSlider.SupportsMultipleBlocks = true;
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(beamCountSlider);
            Controls.Add(beamCountSlider);

            IMyTerminalControlSlider grindSpeedSlider = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyCollector>("Shipyard_GrindSpeed");

            grindSpeedSlider.Title = MyStringId.GetOrCompute("Grind Speed");

            grindSpeedSlider.Tooltip = MyStringId.GetOrCompute("How fast this shipyard grinds grids.");
            grindSpeedSlider.SetLimits(0.01f, 2);
            grindSpeedSlider.Writer  = (b, result) => result.Append(GetGrindSpeed(b));
            grindSpeedSlider.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            grindSpeedSlider.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b) != null;
            grindSpeedSlider.Getter  = GetGrindSpeed;
            grindSpeedSlider.Setter  = (b, v) =>
            {
                SetGrindSpeed(b, (float)Math.Round(v, 2, MidpointRounding.ToEven));
                grindSpeedSlider.UpdateVisual();
            };
            grindSpeedSlider.SupportsMultipleBlocks = true;
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(grindSpeedSlider);
            Controls.Add(grindSpeedSlider);

            IMyTerminalControlSlider weldSpeedSlider = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyCollector>("Shipyard_WeldSpeed");

            weldSpeedSlider.Title = MyStringId.GetOrCompute("Weld Speed");

            weldSpeedSlider.Tooltip = MyStringId.GetOrCompute("How fast this shipyard welds grids.");
            weldSpeedSlider.SetLimits(0.01f, 2);
            weldSpeedSlider.Writer  = (b, result) => result.Append(GetWeldSpeed(b));
            weldSpeedSlider.Visible = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            weldSpeedSlider.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner") && GetYard(b) != null;
            weldSpeedSlider.Getter  = GetWeldSpeed;
            weldSpeedSlider.Setter  = (b, v) =>
            {
                SetWeldSpeed(b, (float)Math.Round(v, 2, MidpointRounding.ToEven));
                weldSpeedSlider.UpdateVisual();
            };
            weldSpeedSlider.SupportsMultipleBlocks = true;
            MyAPIGateway.TerminalControls.AddControl <IMyCollector>(weldSpeedSlider);
            Controls.Add(weldSpeedSlider);

            IMyTerminalAction grindAction = MyAPIGateway.TerminalControls.CreateAction <IMyCollector>("Shipyard_GrindAction");

            grindAction.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            grindAction.Name    = new StringBuilder("Grind");
            grindAction.Icon    = @"Textures\GUI\Icons\Actions\Start.dds";
            grindAction.Action  = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Grind);
            MyAPIGateway.TerminalControls.AddAction <IMyCollector>(grindAction);

            IMyTerminalAction weldAction = MyAPIGateway.TerminalControls.CreateAction <IMyCollector>("Shipyard_WeldAction");

            weldAction.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            weldAction.Name    = new StringBuilder("Weld");
            weldAction.Icon    = @"Textures\GUI\Icons\Actions\Start.dds";
            weldAction.Action  = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Weld);
            MyAPIGateway.TerminalControls.AddAction <IMyCollector>(weldAction);

            IMyTerminalAction stopAction = MyAPIGateway.TerminalControls.CreateAction <IMyCollector>("Shipyard_StopAction");

            stopAction.Enabled = b => b.BlockDefinition.SubtypeId.Contains("ShipyardCorner");
            stopAction.Name    = new StringBuilder("Stop");
            stopAction.Icon    = @"Textures\GUI\Icons\Actions\Reset.dds";
            stopAction.Action  = b => Communication.SendYardCommand(b.CubeGrid.EntityId, ShipyardType.Disabled);
            MyAPIGateway.TerminalControls.AddAction <IMyCollector>(stopAction);
        }
Example #8
0
        private void try_register_handlers()
        {
            sync_helper.try_register_handlers();
            screen_info.try_register_handlers();
            if (!_entity_events_set && screen_info.settings_loaded && MyAPIGateway.Entities != null)
            {
                var existing_entities = new HashSet <IMyEntity>();
                MyAPIGateway.Entities.GetEntities(existing_entities);
                foreach (IMyEntity cur_entity in existing_entities)
                {
                    on_entity_added(cur_entity);
                }
                MyAPIGateway.Entities.OnEntityAdd    += on_entity_added;
                MyAPIGateway.Entities.OnEntityRemove += on_entity_removed;
                _entity_events_set = true;
            }

            if (!screen_info.settings_loaded || MyAPIGateway.TerminalControls == null)
            {
                return;
            }

            if (!_ship_controller_controls_set)
            {
                if (_sample_controller?.GetProperty("DampenersOverride") == null)
                {
                    return;
                }
                create_controller_widgets <IMyCockpit>();
                create_controller_widgets <IMyRemoteControl>();
                _ship_controller_controls_set = true;
                _sample_controller            = null;
            }

            if (!_thruster_controls_set)
            {
                if (!screen_info.torque_disabled && _sample_thruster?.GetProperty("Override") == null)
                {
                    return;
                }
                _thruster_controls_set = true;
                _sample_thruster       = null;
                if (screen_info.torque_disabled)
                {
                    return;
                }
                IMyTerminalControlSeparator thruster_line = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyThrust>("TTDTWM_LINE1");
                MyAPIGateway.TerminalControls.AddControl <IMyThrust>(thruster_line);
                create_switch <IMyThrust>("ActiveControl", "Steering", null, "On", "Off", "On", "Off", thruster_and_grid_tagger.is_under_active_control, thruster_and_grid_tagger.set_active_control, thruster_and_grid_tagger.is_active_control_available);
                create_switch <IMyThrust>("AntiSlip", "Thrust Trimming", null, "On", "Off", "On", "Off", thruster_and_grid_tagger.is_anti_slip, thruster_and_grid_tagger.set_anti_slip, thruster_and_grid_tagger.is_anti_slip_available);
                create_checkbox <IMyThrust>("DisableLinearInput", "Disable linear input", null, "On", "Off", thruster_and_grid_tagger.is_rotational_only, thruster_and_grid_tagger.toggle_linear_input, thruster_and_grid_tagger.is_active_control_available);
                create_switch <IMyThrust>("StaticLimit", "Thrust Limiter", null, "On", "Off", "On", "Off", thruster_and_grid_tagger.is_thrust_limiter_on, thruster_and_grid_tagger.set_thrust_limiter, thruster_and_grid_tagger.is_thrust_limiter_available);
                create_slider <IMyThrust>("ManualThrottle", "Manual throttle",
                                          thruster_and_grid_tagger.get_manual_throttle, thruster_and_grid_tagger.set_manual_throttle, thruster_and_grid_tagger.throttle_status,
                                          0.0f, 100.0f, 5.0f, "IncreaseThrottle", "DecreaseThrottle", "Increase Manual Throttle", "Decrease Manual Throttle");
                create_PB_property <float, IMyThrust>("BalancedLevel", thruster_and_grid_tagger.get_thrust_limit);
            }

            if (!_programmable_block_properties_set)
            {
                if (_sample_PB?.GetProperty("ShowInToolbarConfig") == null)
                {
                    return;
                }
                create_PB_property <Func <string, string, bool>, IMyProgrammableBlock>("ComputeOrbitElements", get_ship_elements_calculator);
                create_PB_property <Func <string, Vector3D, Vector3D, bool>, IMyProgrammableBlock>("ComputeOrbitElementsFromVectors", get_vector_elements_calculator);
                create_PB_property <Func <string>, IMyProgrammableBlock>("GetReferenceBodyName", get_reference_name_fetcher);
                create_PB_property <Action <Dictionary <string, Vector3D> >, IMyProgrammableBlock>("GetPrimaryVectors", get_vector_fetcher);
                create_PB_property <Action <Dictionary <string, double> >, IMyProgrammableBlock>("GetPrimaryScalars", get_scalar_fetcher);
                create_PB_property <Action <Dictionary <string, double> >, IMyProgrammableBlock>("GetDerivedElements", get_derived_fetcher);
                create_PB_property <Action <double?, Dictionary <string, double> >, IMyProgrammableBlock>("GetPositionalElements", get_positional_fetcher);
                create_PB_property <Action <double, Dictionary <string, Vector3D> >, IMyProgrammableBlock>("GetStateVectors", get_state_vector_fetcher);

                create_PB_property <Func <double, double, double>, IMyProgrammableBlock>("ConvertTrueAnomalyToMean", get_true_to_mean_converter);
                create_PB_property <Func <double, double, double>, IMyProgrammableBlock>("ConvertMeanAnomalyToTrue", get_mean_to_true_converter);
                create_PB_property <Func <double, double, Vector3D>, IMyProgrammableBlock>("ComputeOrbitNormal", get_orbit_normal_calculator);
                create_PB_property <Func <Vector3D, Vector3D, Vector3D, double, double>, IMyProgrammableBlock>("ConvertRadialToTtrueAnomaly", get_radius_to_anomaly_converter);
                create_PB_property <Func <double, double, double, double, double, double, ValueTuple <double, double>?>, IMyProgrammableBlock>
                    ("ComputeOrbitIntersections", get_intersection_calculator);
                _programmable_block_properties_set = true;
                _sample_PB = null;
            }

            _setup_complete = _ship_controller_controls_set && _thruster_controls_set && _programmable_block_properties_set && _entity_events_set &&
                              screen_info.settings_loaded && sync_helper.network_handlers_registered;
        }
        public static void CreateControls(IMyTerminalBlock block, List <IMyTerminalControl> controls)
        {
            if (block as IMyCargoContainer == null || controlsCreated == true)
            {
                return;
            }

            controlsCreated = true;

            //seperator and label
            var separatorA = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyCargoContainer>("FilterSectionSeparator");

            separatorA.Enabled = Block => true;
            separatorA.SupportsMultipleBlocks = false;
            separatorA.Visible = Block => ContainerControls.ControlVisibility(Block);
            MyAPIGateway.TerminalControls.AddControl <IMyCargoContainer>(separatorA);
            controls.Add(separatorA);

            var labelA = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlLabel, IMyCargoContainer>("FilterSectionLabel");

            labelA.Enabled = Block => true;
            labelA.SupportsMultipleBlocks = false;
            labelA.Visible = Block => ContainerControls.ControlVisibility(Block);
            labelA.Label   = MyStringId.GetOrCompute("Container Filter Controls");
            MyAPIGateway.TerminalControls.AddControl <IMyCargoContainer>(labelA);
            controls.Add(labelA);

            IMyTerminalControlSeparator separatorb = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyCargoContainer>("FilterSectionSeparatorlower");

            separatorb.Enabled = Block => true;
            separatorb.SupportsMultipleBlocks = false;
            separatorb.Visible = Block => ContainerControls.ControlVisibility(Block);
            MyAPIGateway.TerminalControls.AddControl <IMyCargoContainer>(separatorb);
            controls.Add(separatorb);

            // BlackList/WhiteList comboBox

            var filterMode = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCombobox, IMyCargoContainer>("filterMode");

            filterMode.Enabled = Block => true;
            filterMode.Visible = Block => ContainerControls.ControlVisibility(Block);
            filterMode.Title   = MyStringId.GetOrCompute("Filter Mode:");
            filterMode.Tooltip = MyStringId.GetOrCompute("");
            filterMode.SupportsMultipleBlocks = false;
            filterMode.ComboBoxContent        = ContainerControls.CreateFilterMode;
            filterMode.Setter = ContainerControls.SetFilterMode;
            filterMode.Getter = ContainerControls.GetFilterMode;
            MyAPIGateway.TerminalControls.AddControl <IMyCargoContainer>(filterMode);
            controls.Add(filterMode);

            // "Clear Filter" Button

            var clearFilter = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyCargoContainer>("ClearFilterButton");

            clearFilter.Enabled = Block => true;
            clearFilter.Visible = Block => ContainerControls.ControlVisibility(block);
            clearFilter.Title   = MyStringId.GetOrCompute("Clear Filter");
            clearFilter.Tooltip = MyStringId.GetOrCompute("Removes all items and types from Filter");
            clearFilter.SupportsMultipleBlocks = false;
            clearFilter.Action = ContainerControls.ClearFilter;
            MyAPIGateway.TerminalControls.AddControl <IMyCargoContainer>(clearFilter);
            controls.Add(clearFilter);

            // Current filter list

            var Currentlist = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyCargoContainer>("CurrentList");

            Currentlist.Enabled = Block => true;
            Currentlist.SupportsMultipleBlocks = false;
            Currentlist.Visible          = Block => ContainerControls.ControlVisibility(Block);
            Currentlist.Title            = MyStringId.GetOrCompute("Current Filter:");
            Currentlist.VisibleRowsCount = 6;
            Currentlist.Multiselect      = true;
            Currentlist.ListContent      = ContainerControls.CreateCurrentList;
            Currentlist.ItemSelected     = ContainerControls.SetSelectedcurrentItem;
            MyAPIGateway.TerminalControls.AddControl <IMyCargoContainer>(Currentlist);
            controls.Add(Currentlist);

            // "Remove" button

            var removeButton = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyCargoContainer>("RemoveButton");

            removeButton.Enabled = Block => true;
            removeButton.SupportsMultipleBlocks = false;
            removeButton.Visible = Block => ContainerControls.ControlVisibility(block);
            removeButton.Title   = MyStringId.GetOrCompute("Remove");
            removeButton.Tooltip = MyStringId.GetOrCompute("Removes the item selected in Current list from filter");
            removeButton.Action  = ContainerControls.RemoveFromFilter;
            MyAPIGateway.TerminalControls.AddControl <IMyCargoContainer>(removeButton);
            controls.Add(removeButton);

            // Filter Candidates list

            var CandidatesList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyCargoContainer>("CandidatesList");

            CandidatesList.Enabled = Block => true;
            CandidatesList.SupportsMultipleBlocks = false;
            CandidatesList.Visible          = Block => ContainerControls.ControlVisibility(Block);
            CandidatesList.ListContent      = ContainerControls.CreateCandidateList;
            CandidatesList.Title            = MyStringId.GetOrCompute("Filter Candidates:");
            CandidatesList.VisibleRowsCount = 8;
            CandidatesList.Multiselect      = true;
            CandidatesList.ItemSelected     = ContainerControls.SetSelectedCandidate;
            MyAPIGateway.TerminalControls.AddControl <IMyCargoContainer>(CandidatesList);
            controls.Add(CandidatesList);

            // "Add" button

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

            addButton.Enabled = Block => true;
            addButton.SupportsMultipleBlocks = false;
            addButton.Visible = Block => ContainerControls.ControlVisibility(Block);
            addButton.Title   = MyStringId.GetOrCompute("Add");
            addButton.Tooltip = MyStringId.GetOrCompute("Adds the selected candidate to filter");
            addButton.Action  = ContainerControls.AddToFilter;
            MyAPIGateway.TerminalControls.AddControl <IMyCargoContainer>(addButton);
            controls.Add(addButton);
        }