internal static void CreateSliderActionSet(Session session, IMyTerminalControlSlider tc, string name, int id, int min, int max, float incAmt, Func <IMyTerminalBlock, bool> enabler, bool group) { var action0 = MyAPIGateway.TerminalControls.CreateAction <T>($"WC_{id}_Increase"); action0.Icon = @"Textures\GUI\Icons\Actions\Increase.dds"; action0.Name = new StringBuilder($"Increase {name}"); action0.Action = (b) => tc.Setter(b, tc.Getter(b) + incAmt <= max ? tc.Getter(b) + incAmt : max); action0.Writer = TerminalHelpers.EmptyStringBuilder; action0.Enabled = enabler; action0.ValidForGroups = group; MyAPIGateway.TerminalControls.AddAction <T>(action0); session.CustomActions.Add(action0); var action1 = MyAPIGateway.TerminalControls.CreateAction <T>($"WC_{id}_Decrease"); action1.Icon = @"Textures\GUI\Icons\Actions\Decrease.dds"; action1.Name = new StringBuilder($"Decrease {name}"); action1.Action = (b) => tc.Setter(b, tc.Getter(b) - incAmt >= min ? tc.Getter(b) - incAmt : min); action1.Writer = TerminalHelpers.EmptyStringBuilder; action1.Enabled = enabler; action1.ValidForGroups = group; MyAPIGateway.TerminalControls.AddAction <T>(action1); session.CustomActions.Add(action1); }
private void create_slider <_block_>(string id, string title, Func <IMyTerminalBlock, float> getter, Action <IMyTerminalBlock, float> setter, Action <IMyTerminalBlock, StringBuilder> status, float minimum, float maximum, float change_amount, string increase_action_name, string decrease_action_name, string increase_text, string decrease_text) where _block_ : IMyTerminalBlock { IMyTerminalControlSlider slider = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, _block_>(id); slider.Getter = getter; slider.Setter = setter; slider.Title = MyStringId.GetOrCompute(title); slider.Writer = status; slider.SupportsMultipleBlocks = true; slider.SetLimits(minimum, maximum); MyAPIGateway.TerminalControls.AddControl <_block_>(slider); create_slider_action <_block_>(increase_action_name, increase_text, delegate(IMyTerminalBlock block) { setter(block, getter(block) + change_amount); }, status, "Increase"); create_slider_action <_block_>(decrease_action_name, decrease_text, delegate(IMyTerminalBlock block) { setter(block, getter(block) - change_amount); }, status, "Decrease"); }
public static IMyTerminalControlSlider CreateControlSilder(string id, string title, string tooltip, float min, float max, Func <IMyTerminalBlock, bool> visible, Func <IMyTerminalBlock, bool> enabled, Func <IMyTerminalBlock, float> getter, Action <IMyTerminalBlock, float> setter, Action <IMyTerminalBlock, StringBuilder> writer) { IMyTerminalControlSlider slider = ControlIdExists(id) as IMyTerminalControlSlider; if (slider != null) { return(slider); } slider = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyUpgradeModule>(id); slider.Enabled = enabled; slider.Visible = visible; slider.SupportsMultipleBlocks = false; if (title != null) { slider.Title = MyStringId.GetOrCompute(title); } if (tooltip != null) { slider.Tooltip = MyStringId.GetOrCompute(tooltip); } slider.SetLimits(min, max); slider.Writer = writer; slider.Getter = getter; slider.Setter = setter; MyAPIGateway.TerminalControls.AddControl <IMyUpgradeModule>(slider); return(slider); }
// This code will run on all clients and the server, so we need to isolate it to the server only. public override void Init(MyObjectBuilder_EntityBase objectBuilder) { _objectBuilder = objectBuilder; this.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME; if (!_staticIsInitialized) { _staticIsInitialized = true; _initialRemoteControlMaxSpeed = (float)ConfigurableSpeedComponentLogic.Instance.EnvironmentComponent.RemoteControlMaxSpeed; } if (!_isInitilized) { // Use this space to initialize and hook up events. NOT TO PROCESS ANYTHING. _isInitilized = true; if (_initialRemoteControlMaxSpeed > 0) { _remoteControlEntity = (IMyRemoteControl)Entity; List <IMyTerminalControl> controls; MyAPIGateway.TerminalControls.GetControls <IMyRemoteControl>(out controls); //VRage.Utils.MyLog.Default.WriteLine($"#### SpeedLimit {_remoteControlEntity.SpeedLimit} {_initialRemoteControlMaxSpeed}"); IMyTerminalControl control = controls.FirstOrDefault(c => c.Id == "SpeedLimit"); IMyTerminalControlSlider sliderControl = control as IMyTerminalControlSlider; // control limits are set universally and cannot be applied individually. sliderControl?.SetLimits(0, _initialRemoteControlMaxSpeed); } } }
private void CreateActionDamageModRate <T>(IMyTerminalControlSlider c, float defaultValue = 100f, // HACK terminal controls don't have a default value built in... float modifier = 10f, string iconReset = null, string iconIncrease = null, string iconDecrease = null, bool gridSizeDefaultValue = false) // hacky quick way to get a dynamic default value depending on grid size) { try { var id = ((IMyTerminalControl)c).Id; var name = c.Title.String; if (iconReset == null && iconIncrease == null && iconDecrease == null) { var gamePath = MyAPIGateway.Utilities.GamePaths.ContentPath; iconReset = gamePath + @"\Textures\GUI\Icons\Actions\Reset.dds"; iconIncrease = gamePath + @"\Textures\GUI\Icons\Actions\Increase.dds"; iconDecrease = gamePath + @"\Textures\GUI\Icons\Actions\Decrease.dds"; } { var a = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_Reset"); a.Name = new StringBuilder($"{Localization.GetText("ActionDefault")} ").Append(name); if (!gridSizeDefaultValue) { a.Name.Append(" (").Append(defaultValue.ToString("0.###")).Append(")"); } a.Icon = iconReset; a.ValidForGroups = true; a.Action = (b) => c.Setter(b, gridSizeDefaultValue ? b.CubeGrid.GridSize : defaultValue); a.Writer = (b, s) => s.Append(c.Getter(b)); MyAPIGateway.TerminalControls.AddAction <T>(a); } { var a = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_Increase"); a.Name = new StringBuilder($"{Localization.GetText("ActionIncrease")} ").Append(name).Append(" (+").Append(modifier.ToString("0.###")).Append(")"); a.Icon = iconIncrease; a.ValidForGroups = true; a.Action = ActionAddDamageMod; a.Writer = (b, s) => s.Append(c.Getter(b)); MyAPIGateway.TerminalControls.AddAction <T>(a); } { var a = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_Decrease"); a.Name = new StringBuilder($"{Localization.GetText("ActionDecrease")} ").Append(name).Append(" (-").Append(modifier.ToString("0.###")).Append(")"); a.Icon = iconDecrease; a.ValidForGroups = true; a.Action = ActionSubtractDamageMod; a.Writer = (b, s) => s.Append(c.Getter(b).ToString("0.###")); MyAPIGateway.TerminalControls.AddAction <T>(a); } } catch (Exception ex) { Log.Line($"Exception in CreateActionDamageModRate: {ex}"); } }
//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); } }
public static void InitAntennae() { List <IMyTerminalControl> antennactrls = new List <IMyTerminalControl>(); MyAPIGateway.TerminalControls.GetControls <IMyRadioAntenna>(out antennactrls); IMyTerminalControlSlider RadiusSlider = antennactrls.Find(x => x.Id == "Radius") as IMyTerminalControlSlider; RadiusSlider.SetLogLimits((Antenna) => 1, (Antenna) => (Antenna as IMyRadioAntenna).GetMaxRange()); InitedSession = true; }
public static IMyTerminalAction CreateResetAction <TBlock>(this IMyTerminalControlSlider slider, Func <IMyTerminalBlock, float> defaultValue, string iconPath) where TBlock : IMyTerminalBlock { var action = MyAPIGateway.TerminalControls.CreateAction <TBlock>("Reset" + ((IMyTerminalControl)slider).Id); action.Name = Combine(MySpaceTexts.ToolbarAction_Reset, slider.Title); action.Action = block => slider.Setter(block, defaultValue(block)); action.Writer = slider.Writer; action.Icon = iconPath; action.Enabled = slider.Enabled; return(action); }
public static IMyTerminalAction CreateIncreaseAction <TBlock>(this IMyTerminalControlSlider slider, float step, Func <IMyTerminalBlock, float> min, Func <IMyTerminalBlock, float> max, string iconPath) where TBlock : IMyTerminalBlock { var action = MyAPIGateway.TerminalControls.CreateAction <TBlock>("Increase" + ((IMyTerminalControl)slider).Id); action.Name = Combine(MySpaceTexts.ToolbarAction_Increase, slider.Title); action.Action = block => slider.Setter(block, MathHelper.Clamp(slider.Getter(block) + max(block) * step, min(block), max(block))); action.Writer = slider.Writer; action.Icon = iconPath; action.Enabled = slider.Enabled; return(action); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { NeedsUpdate |= VRage.ModAPI.MyEntityUpdateEnum.BEFORE_NEXT_FRAME; List <IMyTerminalControl> controls; MyAPIGateway.TerminalControls.GetControls <IMyRemoteControl>(out controls); IMyTerminalControl control = controls.FirstOrDefault(c => c.Id == "SpeedLimit"); SliderControl = control as IMyTerminalControlSlider; RelativeTopSpeed.SettingsChanged += OnSettingsChanged; OnSettingsChanged(Settings.Instance); }
public override void UpdateOnceBeforeFrame() { beacon = Entity as IMyBeacon; List <IMyTerminalControl> antennactrls = new List <IMyTerminalControl>(); MyAPIGateway.TerminalControls.GetControls <IMyBeacon>(out antennactrls); IMyTerminalControlSlider RadiusSlider = antennactrls.Find(x => x.Id == "Radius") as IMyTerminalControlSlider; float maxVal = beacon.ParseMaxRange(); RadiusSlider.SetLimits(0, Extensions.ParseMaxRange(beacon)); }
public static IMyTerminalControlSlider LaserBeam <T>() where T : IMyTerminalBlock { IMyTerminalControlSlider LaserBeam = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, T>("BeamLength"); LaserBeam.Title = MyStringId.GetOrCompute("Beam Length"); LaserBeam.Tooltip = MyStringId.GetOrCompute("Sets the laser beam's length."); LaserBeam.SupportsMultipleBlocks = true; LaserBeam.Enabled = HasBlockLogic; LaserBeam.Visible = HasBlockLogic; LaserBeam.SetLimits(Block => BlockReturn(Block, x => x.MinBeamLengthBlocks), Block => BlockReturn(Block, x => x.MaxBeamLengthBlocks)); LaserBeam.Getter = (Block) => BlockReturn(Block, x => x.BeamLength); LaserBeam.Setter = (Block, NewLength) => BlockAction(Block, x => x.BeamLength = (int)NewLength); LaserBeam.Writer = (Block, Info) => Info.Append($"{BlockReturn(Block, x => x.BeamLength)} blocks"); return(LaserBeam); }
public static IMyTerminalControlSlider HarvestEfficiency() { IMyTerminalControlSlider HarvestEfficiency = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyShipDrill>("HarvestEfficiency"); HarvestEfficiency.Title = MyStringId.GetOrCompute("Harvest Efficiency"); HarvestEfficiency.Tooltip = MyStringId.GetOrCompute("Allows to increase drill's yield at the cost of power usage."); HarvestEfficiency.SupportsMultipleBlocks = true; HarvestEfficiency.Enabled = HasDrillLogic; HarvestEfficiency.Visible = HasDrillLogic; HarvestEfficiency.SetLimits(1, 2); HarvestEfficiency.Getter = (Block) => DrillReturn(Block, x => x.HarvestEfficiency); HarvestEfficiency.Setter = (Block, NewEfficiency) => DrillAction(Block, x => x.HarvestEfficiency = NewEfficiency); HarvestEfficiency.Writer = (Block, Info) => Info.Append($"x{Math.Round(DrillReturn(Block, x => x.HarvestEfficiency), 2)}"); return(HarvestEfficiency); }
public static IMyTerminalControlSlider SpeedMultiplier <T>() where T : IMyTerminalBlock { IMyTerminalControlSlider SpeedMultiplier = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, T>("SpeedMultiplier"); SpeedMultiplier.Title = MyStringId.GetOrCompute("Speed Multiplier"); SpeedMultiplier.Tooltip = MyStringId.GetOrCompute("Allows to increase tool's speed at the cost of power usage.\nThis is more efficient than piling on multiple tools."); SpeedMultiplier.SupportsMultipleBlocks = true; SpeedMultiplier.Enabled = HasBlockLogic; SpeedMultiplier.Visible = HasBlockLogic; SpeedMultiplier.SetLimits(1, 4); SpeedMultiplier.Getter = (Block) => BlockReturn(Block, x => x.SpeedMultiplier); SpeedMultiplier.Setter = (Block, NewSpeed) => BlockAction(Block, x => x.SpeedMultiplier = (int)NewSpeed); SpeedMultiplier.Writer = (Block, Info) => Info.Append($"x{BlockReturn(Block, x => x.SpeedMultiplier)}"); return(SpeedMultiplier); }
internal static void CreateSliderActionSet <T>(IMyTerminalControlSlider tc, string name, int id, int min, int max, float incAmt, Func <IMyTerminalBlock, int, bool> enabler) where T : IMyTerminalBlock { var action0 = MyAPIGateway.TerminalControls.CreateAction <T>($"WC_{id}_Increase"); action0.Icon = @"Textures\GUI\Icons\Actions\Increase.dds"; action0.Name = new StringBuilder($"Increase {name}"); action0.Action = (b) => tc.Setter(b, tc.Getter(b) + incAmt <= max ? tc.Getter(b) + incAmt : max); action0.Writer = (b, t) => t.Append(""); action0.Enabled = (b) => enabler(b, id); action0.ValidForGroups = false; MyAPIGateway.TerminalControls.AddAction <T>(action0); var action1 = MyAPIGateway.TerminalControls.CreateAction <T>($"WC_{id}_Decrease"); action1.Icon = @"Textures\GUI\Icons\Actions\Decrease.dds"; action1.Name = new StringBuilder($"Decrease {name}"); action1.Action = (b) => tc.Setter(b, tc.Getter(b) - incAmt >= min ? tc.Getter(b) - incAmt : min); action1.Writer = (b, t) => t.Append(""); action1.Enabled = (b) => enabler(b, id); action1.ValidForGroups = false; MyAPIGateway.TerminalControls.AddAction <T>(action1); }
public void CreateFitAction <T>(IMyTerminalControlSlider c) { var id = ((IMyTerminalControl)c).Id; var action0 = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_FitIncrease"); action0.Icon = @"Textures\GUI\Icons\Actions\Increase.dds"; action0.Name = new StringBuilder(Localization.GetText("ActionFitIncrease")); action0.Action = TerminalActioFitSizeIncrease; action0.Writer = FitSizeWriter; action0.Enabled = HasShield; MyAPIGateway.TerminalControls.AddAction <T>(action0); var action1 = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_FitDecrease"); action1.Icon = @"Textures\GUI\Icons\Actions\Decrease.dds"; action1.Name = new StringBuilder(Localization.GetText("ActionFitDecrease")); action1.Action = TerminalActionFitSizeDecrease; action1.Writer = FitSizeWriter; action1.Enabled = HasShield; MyAPIGateway.TerminalControls.AddAction <T>(action1); }
public void CreateHeightAction <T>(IMyTerminalControlSlider c) { var id = ((IMyTerminalControl)c).Id; var action0 = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_HeightIncrease"); action0.Icon = @"Textures\GUI\Icons\Actions\Increase.dds"; action0.Name = new StringBuilder($"Height Increase"); action0.Action = TerminalActioHeightIncrease; action0.Writer = HeightWriter; action0.Enabled = HasShield; MyAPIGateway.TerminalControls.AddAction <T>(action0); var action1 = MyAPIGateway.TerminalControls.CreateAction <T>(id + "_HeightDecrease"); action1.Icon = @"Textures\GUI\Icons\Actions\Decrease.dds"; action1.Name = new StringBuilder($"Height Decrease"); action1.Action = TerminalActionHeightDecrease; action1.Writer = HeightWriter; action1.Enabled = HasShield; MyAPIGateway.TerminalControls.AddAction <T>(action1); }
public static void InitLate() { initialized = true; powerSwitch = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyTerminalBlock>("HoverRail_OnOff"); powerSwitch.Title = MyStringId.GetOrCompute("Maglev Engine"); powerSwitch.Tooltip = MyStringId.GetOrCompute("Enable to apply force to stick to the track."); powerSwitch.Getter = b => (bool)SettingsStore.Get(b, "power_on", true); powerSwitch.Setter = (b, v) => SettingsStore.Set(b, "power_on", v); powerSwitch.SupportsMultipleBlocks = true; powerSwitch.OnText = MyStringId.GetOrCompute("On"); powerSwitch.OffText = MyStringId.GetOrCompute("Off"); powerSwitch.Visible = BlockIsEngine; MyAPIGateway.TerminalControls.AddControl <IMyTerminalBlock>(powerSwitch); forceSlider = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyTerminalBlock>("HoverRail_ForceLimit"); forceSlider.Title = MyStringId.GetOrCompute("Force Limit"); forceSlider.Tooltip = MyStringId.GetOrCompute("The amount of force applied to align this motor with the track."); forceSlider.SetLogLimits(10000.0f, 50000000.0f); forceSlider.SupportsMultipleBlocks = true; forceSlider.Getter = b => (float)SettingsStore.Get(b, "force_slider", 100000.0f); forceSlider.Setter = (b, v) => SettingsStore.Set(b, "force_slider", (float)LogRound(v)); forceSlider.Writer = (b, result) => result.Append(String.Format("{0}N", SIFormat((float)SettingsStore.Get(b, "force_slider", 100000.0f)))); forceSlider.Visible = BlockIsEngine; MyAPIGateway.TerminalControls.AddControl <IMyTerminalBlock>(forceSlider); heightSlider = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyTerminalBlock>("HoverRail_HeightOffset"); heightSlider.Title = MyStringId.GetOrCompute("Height Offset"); heightSlider.Tooltip = MyStringId.GetOrCompute("The height we float above the track."); heightSlider.SetLimits(0.1f, 2.5f); heightSlider.SupportsMultipleBlocks = true; heightSlider.Getter = b => (float)SettingsStore.Get(b, "height_offset", 1.25f); heightSlider.Setter = (b, v) => SettingsStore.Set(b, "height_offset", (float)Math.Round(v, 1)); heightSlider.Writer = (b, result) => result.Append(String.Format("{0}m", (float)SettingsStore.Get(b, "height_offset", 1.25f))); heightSlider.Visible = BlockIsEngine; MyAPIGateway.TerminalControls.AddControl <IMyTerminalBlock>(heightSlider); lowerHeightAction = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailEngine_LowerHeight0.1"); lowerHeightAction.Name = new StringBuilder("Lower Height"); lowerHeightAction.Action = LowerHeightAction; lowerHeightAction.Writer = (block, builder) => { builder.Clear(); builder.Append(String.Format("{0} -", (float)SettingsStore.Get(block, "height_offset", 1.25f))); }; MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(lowerHeightAction); raiseHeightAction = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailEngine_RaiseHeight0.1"); raiseHeightAction.Name = new StringBuilder("Raise Height"); raiseHeightAction.Action = RaiseHeightAction; raiseHeightAction.Writer = (block, builder) => { builder.Clear(); builder.Append(String.Format("{0} +", (float)SettingsStore.Get(block, "height_offset", 1.25f))); }; MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(raiseHeightAction); turnOnAction = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailEngine_On"); turnOnAction.Name = new StringBuilder("Power On"); turnOnAction.Action = TurnOnAction; turnOnAction.Writer = OnOffWriter; MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(turnOnAction); turnOffAction = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailEngine_Off"); turnOffAction.Name = new StringBuilder("Power Off"); turnOffAction.Action = TurnOffAction; turnOffAction.Writer = OnOffWriter; MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(turnOffAction); turnOnOffAction = MyAPIGateway.TerminalControls.CreateAction <IMyTerminalBlock>("HoverRailEngine_OnOff"); turnOnOffAction.Name = new StringBuilder("Power On/Off"); turnOnOffAction.Action = TurnOnOffAction; turnOnOffAction.Writer = OnOffWriter; MyAPIGateway.TerminalControls.AddAction <IMyTerminalBlock>(turnOnOffAction); MyAPIGateway.TerminalControls.CustomActionGetter += GetEngineActions; }
/// <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); }
private void CreateTerminalControls() { // Just to make sure we're not subscribing twice without using locks MyAPIGateway.TerminalControls.CustomControlGetter -= CustomControlGetter; MyAPIGateway.TerminalControls.CustomControlGetter += CustomControlGetter; IMyTerminalControlCheckbox checkbox = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCheckbox, IMyThrust>("LockFlameColors"); checkbox.Title = MyStringId.GetOrCompute("Lock Flame Colors"); checkbox.Getter = (block) => { if (block == null || block.GameLogic == null) { return(false); } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); return(logic != null ? logic.m_flameColorsLocked : false); }; checkbox.Setter = (block, value) => { var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); if (logic != null) { logic.m_flameColorsLocked = value; logic.UpdateFlames(); logic.UpdateCustomData(); } }; checkbox.SupportsMultipleBlocks = true; m_customControls.Add(checkbox); // FlameIdleColor IMyTerminalControlColor color = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlColor, IMyThrust>("FlameIdleColor"); color.Title = MyStringId.GetOrCompute("Idle"); color.Getter = (block) => { if (block == null || block.GameLogic == null) { return((Vector4)Color.Black); } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); return(logic != null ? logic.m_flameIdleColor : (Vector4)Color.Black); }; color.Setter = (block, value) => { var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); if (logic != null) { Vector3 v = value.ToVector3(); logic.m_flameIdleColor = new Vector4(v.X, v.Y, v.Z, logic.m_flameIdleColor.W); if (logic.m_renderMode == RenderMode.Linked) { logic.m_flameFullColor = logic.m_flameIdleColor; } foreach (var control in m_customControls) { if (control.Id == "FlameFullColor") { control.UpdateVisual(); } } logic.UpdateFlames(); logic.UpdateCustomData(); } }; m_customControls.Add(color); IMyTerminalControlSlider alpha = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyThrust>("FlameIdleColorAlpha"); alpha.Title = MyStringId.GetOrCompute("Alpha"); alpha.SetLimits(0f, 1f); alpha.Getter = (block) => { if (block == null || block.GameLogic == null) { return(1f); } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); return(logic != null ? logic.m_flameIdleColor.W : 1f); }; alpha.Setter = (block, value) => { var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); if (logic != null) { logic.m_flameIdleColor.W = value; if (logic.m_renderMode == RenderMode.Linked) { logic.m_flameFullColor.W = logic.m_flameIdleColor.W; } foreach (var control in m_customControls) { if (control.Id == "FlameFullColorAlpha" || control.Id == "FlameFullColor" || control.Id == "FlameIdleColor") { control.UpdateVisual(); } } logic.UpdateFlames(); logic.UpdateCustomData(); } }; m_customControls.Add(alpha); var propertyIC = MyAPIGateway.TerminalControls.CreateProperty <Color, IMyThrust>("FlameIdleColorOverride"); propertyIC.SupportsMultipleBlocks = false; propertyIC.Getter = (block) => { if (block == null || block.GameLogic == null) { return(Vector4.Zero); } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); return(logic != null ? (Color)logic.FlameIdleColor : Color.Transparent); }; propertyIC.Setter = (block, value) => { if (block == null || block.GameLogic == null) { return; } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); if (logic != null) { logic.m_flameIdleColor = value.ToVector4(); // logic.m_flameIdleColor.W = 0.75f; if (logic.m_renderMode == RenderMode.Linked) { logic.FlameFullColor = logic.FlameIdleColor; } } }; MyAPIGateway.TerminalControls.AddControl <IMyThrust>(propertyIC); // FlameFullColor color = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlColor, IMyThrust>("FlameFullColor"); color.Title = MyStringId.GetOrCompute("Full"); color.Enabled = (block) => { if (block == null || block.GameLogic == null) { return(false); } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); return(logic != null ? (logic.m_renderMode != RenderMode.Linked) : false); }; color.Getter = (block) => { if (block == null || block.GameLogic == null) { return((Vector4)Color.Black); } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); return(logic != null ? logic.m_flameFullColor : (Vector4)Color.Black); }; color.Setter = (block, value) => { var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); if (logic != null) { Vector3 v = value.ToVector3(); logic.m_flameFullColor = new Vector4(v.X, v.Y, v.Z, logic.m_flameFullColor.W); logic.UpdateFlames(); logic.UpdateCustomData(); } }; m_customControls.Add(color); alpha = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyThrust>("FlameFullColorAlpha"); alpha.Title = MyStringId.GetOrCompute("Alpha"); alpha.SetLimits(0f, 1f); alpha.Getter = (block) => { if (block == null || block.GameLogic == null) { return(1f); } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); return(logic != null ? logic.m_flameFullColor.W : 1f); }; alpha.Setter = (block, value) => { var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); if (logic != null) { logic.m_flameFullColor.W = value; if (logic.m_renderMode == RenderMode.Linked) { logic.m_flameIdleColor.W = logic.m_flameFullColor.W; } foreach (var control in m_customControls) { if (control.Id == "FlameIdleColorAlpha" || control.Id == "FlameFullColor" || control.Id == "FlameIdleColor") { control.UpdateVisual(); } } logic.UpdateFlames(); logic.UpdateCustomData(); } }; m_customControls.Add(alpha); var propertyFC = MyAPIGateway.TerminalControls.CreateProperty <Color, IMyThrust>("FlameFullColorOverride"); propertyFC.SupportsMultipleBlocks = false; propertyFC.Getter = (block) => { if (block == null || block.GameLogic == null) { return(Vector4.Zero); } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); return(logic != null ? (Color)logic.FlameFullColor : Color.Transparent); }; propertyFC.Setter = (block, value) => { if (block == null || block.GameLogic == null) { return; } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); if (logic != null && logic.m_renderMode != RenderMode.Linked) { logic.m_flameFullColor = value.ToVector4(); } }; MyAPIGateway.TerminalControls.AddControl <IMyThrust>(propertyFC); IMyTerminalControlSlider renderMode = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyThrust>("FlameRenderMode"); renderMode.Title = MyStringId.GetOrCompute("Flame Render Mode"); renderMode.SetLimits(0, 2); renderMode.Getter = (block) => { if (block == null || block.GameLogic == null) { return((int)m_renderMode); } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); return(logic != null ? (int)logic.m_renderMode : 0); }; renderMode.Setter = (block, value) => { if (block == null || block.GameLogic == null) { return; } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); if (logic != null) { logic.m_renderMode = (RenderMode)value; if (logic.m_renderMode == RenderMode.Linked) { logic.m_flameFullColor = logic.m_flameIdleColor; } logic.UpdateFlames(); logic.UpdateCustomData(); foreach (var control in m_customControls) { if (control.Id == "FlameFullColor") { control.UpdateVisual(); } } } }; renderMode.Writer = (block, sb) => { if (block == null || block.GameLogic == null) { return; } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); if (logic != null) { sb.Append(logic.m_renderMode.ToString()); } }; renderMode.SupportsMultipleBlocks = true; m_customControls.Add(renderMode); var hideFlamesCheckbox = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCheckbox, IMyThrust>("HideThrustFlames"); hideFlamesCheckbox.Title = MyStringId.GetOrCompute("Hide Thrust Flames"); hideFlamesCheckbox.Getter = (block) => { if (block == null || block.GameLogic == null) { return(false); } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); return(logic != null ? logic.m_hideFlames : false); }; hideFlamesCheckbox.Setter = (block, value) => { var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); if (logic != null) { logic.m_hideFlames = value; logic.UpdateFlames(); logic.UpdateCustomData(); } }; hideFlamesCheckbox.SupportsMultipleBlocks = true; m_customControls.Add(hideFlamesCheckbox); var propertyHF = MyAPIGateway.TerminalControls.CreateProperty <bool, IMyThrust>("HideThrustFlames"); propertyHF.SupportsMultipleBlocks = false; propertyHF.Getter = (block) => { if (block == null || block.GameLogic == null) { return(false); } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); return(logic != null ? logic.HideThrustFlames : false); }; propertyHF.Setter = (block, value) => { if (block == null || block.GameLogic == null) { return; } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); if (logic != null) { logic.HideThrustFlames = value; } }; MyAPIGateway.TerminalControls.AddControl <IMyThrust>(propertyHF); var resetButton = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyThrust>("ResetDefaultColors"); resetButton.Title = MyStringId.GetOrCompute("Reset Default Colors"); resetButton.Action = (block) => { if (block == null || block.GameLogic == null) { return; } var logic = block.GameLogic.GetAs <RecolorableThrustFlameLogic>(); if (logic != null) { var blockDefinition = block.SlimBlock.BlockDefinition as MyThrustDefinition; logic.m_flameIdleColor = blockDefinition.FlameIdleColor; logic.m_flameFullColor = blockDefinition.FlameFullColor; if (logic.m_flameFullColor != logic.m_flameIdleColor) { logic.m_renderMode = RenderMode.Blended; } foreach (var control in m_customControls) { control.UpdateVisual(); } logic.UpdateFlames(); logic.UpdateCustomData(); } }; resetButton.SupportsMultipleBlocks = true; m_customControls.Add(resetButton); }
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); }
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; }
public static IMyTerminalAction CreateIncreaseAction <TBlock>(this IMyTerminalControlSlider slider, float step, Func <IMyTerminalBlock, float> min, Func <IMyTerminalBlock, float> max) where TBlock : IMyTerminalBlock { return(CreateIncreaseAction <TBlock>(slider, step, min, max, TerminalActionIcons.INCREASE)); }
// 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 IMyTerminalAction CreateResetAction <TBlock>(this IMyTerminalControlSlider slider, Func <IMyTerminalBlock, float> defaultValue) where TBlock : IMyTerminalBlock { return(CreateResetAction <TBlock>(slider, defaultValue, TerminalActionIcons.RESET)); }
public static IMyTerminalControlProperty <float> CreateProperty <TBlock>(this IMyTerminalControlSlider slider) where TBlock : IMyTerminalBlock { return(slider.CreateProperty <TBlock, float>()); }
private void InitControls() { ThrusterOverclock = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyThrust>("Overclock"); ThrusterOverclock.Title = MyStringId.GetOrCompute("Overclock"); ThrusterOverclock.Tooltip = MyStringId.GetOrCompute("Multiplies thruster power at the cost of heat and degradation."); ThrusterOverclock.SetLimits(1, maxThrusterOverclock); ThrusterOverclock.SupportsMultipleBlocks = true; ThrusterOverclock.Getter = (x) => { if (x == null || x.GameLogic == null) { return(1f); } var logic = x.GameLogic.GetAs <ThrustOverride>(); return(logic != null ? logic.Overclock : 1f); }; ThrusterOverclock.Setter = (x, y) => { var logic = x.GameLogic.GetAs <ThrustOverride>(); if (logic != null) { logic.Overclock = y; if (Sync.IsClient) { var message = new MessageThrusterVariables(); message.EntityId = logic.Entity.EntityId; message.UpdateCustomData = true; message.Overclock = logic.Overclock; message.SafetySwitch = logic.SafetySwitch; Messaging.SendMessageToServer(message); } } }; ThrusterOverclock.Writer = (x, y) => { if (x == null || x.GameLogic == null) { return; } var logic = x.GameLogic.GetAs <ThrustOverride>(); if (logic != null) { y.Append(logic.Overclock.ToString() + "x"); } }; SafetySwitch = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyThrust>("SafetySwitch"); SafetySwitch.Title = MyStringId.GetOrCompute("Safety Switch"); SafetySwitch.Tooltip = MyStringId.GetOrCompute("When enabled, reduces thrust when necessary to prevent damage from excessive heat.\nTurning this off can allow steady thrust over longer periods of time,\nwhich can be useful in emergencies."); SafetySwitch.OnText = MyStringId.GetOrCompute("On"); SafetySwitch.OffText = MyStringId.GetOrCompute("Off"); SafetySwitch.SupportsMultipleBlocks = true; SafetySwitch.Getter = x => { if (x == null || x.GameLogic == null) { return(true); } var logic = x.GameLogic.GetAs <ThrustOverride>(); return(logic != null ? logic.SafetySwitch : true); }; SafetySwitch.Setter = (x, y) => { Debug.Write("Attempting to set safety switch", 1); if (x == null || x.GameLogic == null) { return; } var logic = x.GameLogic.GetAs <ThrustOverride>(); logic.SafetySwitch = y; if (Sync.IsClient) { Debug.Write("Set safety switch on client", 1); } if (Sync.IsServer) { Debug.Write("Set safety switch on server", 1); } if (Sync.IsClient) { var message = new MessageThrusterVariables(); message.UpdateCustomData = true; message.EntityId = logic.Entity.EntityId; message.Overclock = logic.Overclock; message.SafetySwitch = logic.SafetySwitch; Messaging.SendMessageToServer(message); } }; safetySwitchAction = MyAPIGateway.TerminalControls.CreateAction <IMyThrust>("SafetySwitchAction"); safetySwitchAction.Enabled = (x) => true; safetySwitchAction.Name = new StringBuilder(string.Format("Safety Toggle On/Off")); safetySwitchAction.Icon = @"Textures\GUI\Icons\Actions\Toggle.dds"; safetySwitchAction.Action = (x) => { if (x == null || SafetySwitch == null) { return; } SafetySwitch.Setter(x, !SafetySwitch.Getter(x)); }; safetySwitchAction.ValidForGroups = true; safetySwitchAction.Writer = (x, y) => { if (x == null || SafetySwitch == null) { return; } y.Append(SafetySwitch.Getter(x) ? "On" : "Off"); }; safetySwitchAction.InvalidToolbarTypes = new List <MyToolbarType>(); overclockActionIncrease = MyAPIGateway.TerminalControls.CreateAction <IMyThrust>("OverclockActionIncrease"); overclockActionIncrease.Enabled = (x) => true; overclockActionIncrease.Name = new StringBuilder(string.Format("Increase Overclock")); overclockActionIncrease.Icon = @"Textures\GUI\Icons\Actions\Increase.dds"; overclockActionIncrease.ValidForGroups = true; overclockActionIncrease.Action = (x) => { if (x == null || ThrusterOverclock == null) { return; } ThrusterOverclock.Setter(x, Math.Min(ThrusterOverclock.Getter(x) + 1f, maxThrusterOverclock)); }; overclockActionIncrease.Writer = (x, y) => { if (x == null || ThrusterOverclock == null) { return; } y.Append(ThrusterOverclock.Getter(x).ToString() + "x"); }; overclockActionIncrease.InvalidToolbarTypes = new List <MyToolbarType>(); overclockActionDecrease = MyAPIGateway.TerminalControls.CreateAction <IMyThrust>("OverclockActionDecrease"); overclockActionDecrease.Enabled = (x) => true; overclockActionDecrease.Name = new StringBuilder(string.Format("Decrease Overclock")); overclockActionDecrease.Icon = @"Textures\GUI\Icons\Actions\Decrease.dds"; overclockActionDecrease.ValidForGroups = true; overclockActionDecrease.Action = (x) => { if (x == null || ThrusterOverclock == null) { return; } ThrusterOverclock.Setter(x, Math.Max(ThrusterOverclock.Getter(x) - 1f, 1f)); }; overclockActionDecrease.Writer = (x, y) => { if (x == null || ThrusterOverclock == null) { return; } y.Append(ThrusterOverclock.Getter(x).ToString() + "x"); }; overclockActionDecrease.InvalidToolbarTypes = new List <MyToolbarType>(); }
public static void InitLate() { initialized = true; nextFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_NextFrame"); nextFrameAction.Name = new StringBuilder("Next Frame"); nextFrameAction.Action = ActionNextFrame; nextFrameAction.Writer = FrameNumWriterGen("+1"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(nextFrameAction); prevFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_PrevFrame"); prevFrameAction.Name = new StringBuilder("Prev Frame"); prevFrameAction.Action = ActionPrevFrame; prevFrameAction.Writer = FrameNumWriterGen("-1"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(prevFrameAction); nextFrame10Action = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_NextFrame10"); nextFrame10Action.Name = new StringBuilder("Next Frame +10"); nextFrame10Action.Action = ActionNextFrame10; nextFrame10Action.Writer = FrameNumWriterGen("+10"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(nextFrame10Action); prevFrame10Action = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_PrevFrame10"); prevFrame10Action.Name = new StringBuilder("Prev Frame -10"); prevFrame10Action.Action = ActionPrevFrame10; prevFrame10Action.Writer = FrameNumWriterGen("-10"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(prevFrame10Action); nextKeyFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_NextKeyFrame"); nextKeyFrameAction.Name = new StringBuilder("Next Keyframe"); nextKeyFrameAction.Action = ActionNextKeyFrame; nextKeyFrameAction.Writer = FrameNumWriterGen("+K"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(nextKeyFrameAction); prevKeyFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_PrevKeyFrame"); prevKeyFrameAction.Name = new StringBuilder("Prev Keyframe"); prevKeyFrameAction.Action = ActionPrevKeyFrame; prevKeyFrameAction.Writer = FrameNumWriterGen("-K"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(prevKeyFrameAction); playAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_Play"); playAction.Name = new StringBuilder("Play"); playAction.Action = ActionPlay; playAction.Writer = ConditionToggleWriterGen((cam) => cam.PlaybackState == PlaybackMode.Playing, "Play"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(playAction); pauseAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_Pause"); pauseAction.Name = new StringBuilder("Pause"); pauseAction.Action = ActionPause; pauseAction.Writer = ConditionToggleWriterGen((cam) => cam.PlaybackState == PlaybackMode.Paused, "Paus"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(pauseAction); playPauseAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_PlayPause"); playPauseAction.Name = new StringBuilder("Play/Pause"); playPauseAction.Action = ActionPlayPause; playPauseAction.Writer = ConditionToggleWriterGen((cam) => cam.PlaybackState == PlaybackMode.Playing, "Play"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(playPauseAction); stopAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_Stop"); stopAction.Name = new StringBuilder("Stop"); stopAction.Action = ActionStop; stopAction.Writer = ConditionToggleWriterGen((cam) => cam.PlaybackState == PlaybackMode.Stopped, "Stop"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(stopAction); setFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_SetKey"); setFrameAction.Name = new StringBuilder("Set Frame"); setFrameAction.Action = ActionSetFrame; setFrameAction.Writer = (b, sb) => { sb.Clear(); sb.Append("^Frm"); }; MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(setFrameAction); setPosFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_SetPosKey"); setPosFrameAction.Name = new StringBuilder("Set Pos"); setPosFrameAction.Action = ActionSetPosFrame; setPosFrameAction.Writer = (b, sb) => { sb.Clear(); sb.Append("^Pos"); }; MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(setPosFrameAction); setViewFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_SetViewKey"); setViewFrameAction.Name = new StringBuilder("Set View"); setViewFrameAction.Action = ActionSetViewFrame; setViewFrameAction.Writer = (b, sb) => { sb.Clear(); sb.Append("^View"); }; MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(setViewFrameAction); delKeyframeAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_DelKeyframe"); delKeyframeAction.Name = new StringBuilder("Remove Keyframe"); delKeyframeAction.Action = ActionDelKeyframe; delKeyframeAction.Writer = (b, sb) => { sb.Clear(); sb.Append("RmFrm"); }; MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(delKeyframeAction); toggleKeyframeModeAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_ToggleTransitionMode"); toggleKeyframeModeAction.Name = new StringBuilder("Change Transition"); toggleKeyframeModeAction.Action = ActionToggleKeyframeMode; toggleKeyframeModeAction.Writer = KeyframeModeWriter; MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(toggleKeyframeModeAction); lockViewAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_LockViewToTarget"); lockViewAction.Name = new StringBuilder("Lock View to Target"); lockViewAction.Action = ActionLockViewToTarget; lockViewAction.Writer = ConditionToggleWriterGen((cam) => cam.view_locked_to != null, "VTgt"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(lockViewAction); lockPosAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_LockPosToTarget"); lockPosAction.Name = new StringBuilder("Lock Pos to Target"); lockPosAction.Action = ActionLockPosToTarget; lockPosAction.Writer = ConditionToggleWriterGen((cam) => cam.pos_locked_to != null, "PTgt"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(lockPosAction); setFocusAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_SetFocusToViewLock"); setFocusAction.Name = new StringBuilder("Set Focus to View Lock"); setFocusAction.Action = ActionSetFocusToViewLock; setFocusAction.Writer = (b, sb) => { sb.Clear(); sb.Append("Focus"); }; MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(setFocusAction); rangeSlider = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyCameraBlock>("Camera_FocusDistance"); rangeSlider.Title = MyStringId.GetOrCompute("Focus Distance"); rangeSlider.Tooltip = MyStringId.GetOrCompute("Focus distance. Important when camera is locked to a distant object."); rangeSlider.SetLogLimits(1.0f, 100000.0f); rangeSlider.SupportsMultipleBlocks = true; rangeSlider.Getter = b => (float)SettingsStore.Get(b, "focus_distance", 1.0f); rangeSlider.Setter = (b, v) => SettingsStore.Set(b, "focus_distance", (float)LogRound(v)); rangeSlider.Writer = (b, result) => result.Append(SettingsStore.Get(b, "focus_distance", 1.0f)); rangeSlider.Visible = BlockIsMyCamera; MyAPIGateway.TerminalControls.AddControl <IMyCameraBlock>(rangeSlider); MyAPIGateway.TerminalControls.CustomActionGetter += GetCameraActions; }