internal static void RedrawControls() { if (RangeControl != null) { RangeControl.UpdateVisual(); } }
/// <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); }
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); }