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; }
// Context: All public override void UpdateOnceBeforeFrame() { if (me.CubeGrid?.Physics == null) { return; } _state = new SyncableProjectorState(me, State.Idle, 0); if (Constants.IsServer) { LoadStorage(); _settings.OnValueReceived += SaveStorage; BuildState = State.Idle; me.IsWorkingChanged += Me_IsWorkingChanged; } else { _settings = new SyncableProjectorSettings(me, 0, true); _state.RequestFromServer(); _settings.RequestFromServer(); _state.OnValueReceived += ReceivedNewState; } MyProjectorDefinition def = (MyProjectorDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(me.BlockDefinition); minPower = def.RequiredPowerInput; sink = me.Components.Get <MyResourceSinkComponent>(); MyDefinitionId powerDef = MyResourceDistributorComponent.ElectricityId; sink.SetRequiredInputFuncByType(powerDef, GetCurrentPower); sink.Update(); _settings.OnValueReceived += RefreshUI; me.AppendingCustomInfo += CustomInfo; me.RefreshCustomInfo(); Settings.MapSettings config = IPSession.Instance.MapSettings; config.OnSubgridsChanged += ClearCachedComps; config.OnComponentCostModifierChanged += ClearCachedComps; config.OnExtraComponentChanged += ClearCachedComps; config.OnExtraCompCostChanged += ClearCachedComps; if (!controls) { // Terminal controls IMyTerminalControlSeparator sep = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyProjector>("BuildGridSep"); sep.Enabled = IsValid; sep.Visible = IsValid; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sep); IMyTerminalControlButton btnBuild = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("BuildGrid"); btnBuild.Enabled = IsWorking; btnBuild.Visible = IsValid; btnBuild.SupportsMultipleBlocks = true; btnBuild.Title = MyStringId.GetOrCompute("Build Grid"); btnBuild.Action = BuildClient; btnBuild.Tooltip = MyStringId.GetOrCompute("Builds the projection instantly.\nThere will be a cooldown after building."); MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnBuild); IMyTerminalControlButton btnCancel = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("CancelBuildGrid"); btnCancel.Enabled = IsWorking; btnCancel.Visible = IsValid; btnCancel.SupportsMultipleBlocks = true; btnCancel.Title = MyStringId.GetOrCompute("Cancel"); btnCancel.Action = CancelClient; btnCancel.Tooltip = MyStringId.GetOrCompute("Cancels the build process."); MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnCancel); IMyTerminalControlCheckbox chkShift = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCheckbox, IMyProjector>("MoveProjectionArea"); chkShift.Enabled = IsWorking; chkShift.Visible = IsValid; chkShift.SupportsMultipleBlocks = true; chkShift.Title = MyStringId.GetOrCompute("Loose Projection Area"); chkShift.OnText = MyStringId.GetOrCompute("On"); chkShift.OffText = MyStringId.GetOrCompute("Off"); chkShift.Tooltip = MyStringId.GetOrCompute("Allow the projection to spawn in a different area if the original area is occupied."); chkShift.Setter = SetLooseArea; chkShift.Getter = GetLooseArea; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(chkShift); IMyTerminalControlSlider sliderSpeed = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyProjector>("BuildSpeed"); sliderSpeed.Enabled = IsWorking; sliderSpeed.Visible = IsValid; sliderSpeed.SupportsMultipleBlocks = true; sliderSpeed.Title = MyStringId.GetOrCompute("Speed"); sliderSpeed.Tooltip = MyStringId.GetOrCompute("Increasing the speed will use more energy."); sliderSpeed.SetLogLimits(Constants.minSpeed, Constants.maxSpeed); sliderSpeed.Writer = GetSpeedText; sliderSpeed.Getter = GetSpeed; sliderSpeed.Setter = SetSpeed; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sliderSpeed); IMyTerminalControlTextbox txtTimeout = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, IMyProjector>("GridTimer"); txtTimeout.Enabled = (b) => false; txtTimeout.Visible = IsValid; txtTimeout.Getter = GetTimer; txtTimeout.Setter = (b, s) => { }; txtTimeout.SupportsMultipleBlocks = false; txtTimeout.Title = MyStringId.GetOrCompute("Build Timer"); txtTimeout.Tooltip = MyStringId.GetOrCompute("The amount of time you must wait after building a grid to be able to build another."); MyAPIGateway.TerminalControls.AddControl <IMyProjector>(txtTimeout); // Terminal actions // Button panels are special and trigger on the server instead of the client, making everything more complicated. IMyTerminalAction aCancel = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildAction"); aCancel.Enabled = IsValid; aCancel.Action = CancelClient; // For all except button panels aCancel.ValidForGroups = true; aCancel.Name = new StringBuilder("Cancel Spawn Grid"); aCancel.Writer = (b, s) => s.Append("Cancel"); aCancel.InvalidToolbarTypes = new[] { MyToolbarType.ButtonPanel }.ToList(); MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel); IMyTerminalAction aCancel2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildGrid"); aCancel2.Enabled = IsValid; aCancel2.Action = CancelClientUnsafe; // For only button panels aCancel2.ValidForGroups = true; aCancel2.Name = new StringBuilder("Cancel Spawn Grid"); aCancel2.Writer = (b, s) => s.Append("Cancel"); aCancel2.InvalidToolbarTypes = new List <MyToolbarType> { MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit, MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator }; MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel2); IMyTerminalAction aBuild = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGridAction"); aBuild.Enabled = IsValid; aBuild.Action = BuildClient; // For all except button panels aBuild.ValidForGroups = true; aBuild.Name = new StringBuilder("Spawn Grid"); aBuild.Writer = (b, s) => s.Append("Spawn"); aBuild.InvalidToolbarTypes = new [] { MyToolbarType.ButtonPanel }.ToList(); MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild); IMyTerminalAction aBuild2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGrid"); aBuild2.Enabled = IsValid; aBuild2.Action = BuildClientUnsafe; // For only button panels aBuild2.ValidForGroups = true; aBuild2.Name = new StringBuilder("Spawn Grid"); aBuild2.Writer = (b, s) => s.Append("Spawn"); aBuild2.InvalidToolbarTypes = new List <MyToolbarType> { MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit, MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator }; MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild2); IMyTerminalControlListbox itemList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyProjector>("ComponentList"); itemList.Enabled = IsWorking; itemList.Visible = IsValid; itemList.ListContent = GetItemList; itemList.Multiselect = false; itemList.SupportsMultipleBlocks = false; itemList.Title = MyStringId.GetOrCompute("Components"); itemList.VisibleRowsCount = 10; itemList.ItemSelected = (b, l) => { }; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemList); // Programmable Block stuff IMyTerminalControlProperty <Dictionary <MyItemType, int> > itemListProp = MyAPIGateway.TerminalControls.CreateProperty <Dictionary <MyItemType, int>, IMyProjector>("RequiredComponents"); itemListProp.Enabled = IsWorking; itemListProp.Visible = IsValid; itemListProp.SupportsMultipleBlocks = false; itemListProp.Setter = (b, l) => { }; itemListProp.Getter = GetItemListPB; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemListProp); IMyTerminalControlProperty <int> gridTimeoutProp = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerProjection"); gridTimeoutProp.Enabled = IsWorking; gridTimeoutProp.Visible = IsValid; gridTimeoutProp.SupportsMultipleBlocks = false; gridTimeoutProp.Setter = (b, l) => { }; gridTimeoutProp.Getter = GetMaxTimerPB; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutProp); IMyTerminalControlProperty <int> gridTimeoutActive = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerCurrent"); gridTimeoutActive.Enabled = IsWorking; gridTimeoutActive.Visible = IsValid; gridTimeoutActive.SupportsMultipleBlocks = false; gridTimeoutActive.Setter = (b, l) => { }; gridTimeoutActive.Getter = GetCurrentTimerPB; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive); IMyTerminalControlProperty <int> buildState = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("BuildState"); buildState.Enabled = IsWorking; buildState.Visible = IsValid; buildState.SupportsMultipleBlocks = false; buildState.Setter = (b, l) => { }; buildState.Getter = GetStatePB; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive); MyLog.Default.WriteLineAndConsole("Initialized Instant Projector."); controls = true; } }
public static void Create() { if (controls) { return; } IMyTerminalControlSeparator sep = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyProjector>("BuildGridSep"); sep.Enabled = IsValid; sep.Visible = IsValid; sep.SupportsMultipleBlocks = true; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sep); IMyTerminalControlLabel lbl = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlLabel, IMyProjector>("BuildGridLabel"); lbl.Enabled = IsValid; lbl.Visible = IsValid; lbl.SupportsMultipleBlocks = true; lbl.Label = MyStringId.GetOrCompute("Instant Projector Controls"); MyAPIGateway.TerminalControls.AddControl <IMyProjector>(lbl); IMyTerminalControlButton btnBuild = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("BuildGrid"); btnBuild.Enabled = IsWorking; btnBuild.Visible = IsValid; btnBuild.SupportsMultipleBlocks = true; btnBuild.Title = MyStringId.GetOrCompute("Build Grid"); btnBuild.Action = BuildClient; btnBuild.Tooltip = MyStringId.GetOrCompute("Builds the projection instantly.\nThere will be a cooldown after building."); MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnBuild); IMyTerminalControlButton btnCancel = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("CancelBuildGrid"); btnCancel.Enabled = IsWorking; btnCancel.Visible = IsValid; btnCancel.SupportsMultipleBlocks = true; btnCancel.Title = MyStringId.GetOrCompute("Cancel"); btnCancel.Action = CancelClient; btnCancel.Tooltip = MyStringId.GetOrCompute("Cancels the build process."); MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnCancel); IMyTerminalControlCheckbox chkShift = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCheckbox, IMyProjector>("MoveProjectionArea"); chkShift.Enabled = IsWorking; chkShift.Visible = IsValid; chkShift.SupportsMultipleBlocks = true; chkShift.Title = MyStringId.GetOrCompute("Loose Projection Area"); chkShift.OnText = MyStringId.GetOrCompute("On"); chkShift.OffText = MyStringId.GetOrCompute("Off"); chkShift.Tooltip = MyStringId.GetOrCompute("Allow the projection to spawn in a different area if the original area is occupied."); chkShift.Setter = SetLooseArea; chkShift.Getter = GetLooseArea; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(chkShift); IMyTerminalControlSlider sliderSpeed = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyProjector>("BuildSpeed"); sliderSpeed.Enabled = IsWorking; sliderSpeed.Visible = IsValid; sliderSpeed.SupportsMultipleBlocks = true; sliderSpeed.Title = MyStringId.GetOrCompute("Speed"); sliderSpeed.Tooltip = MyStringId.GetOrCompute("Increasing the speed will use more energy."); sliderSpeed.SetLogLimits(Constants.minSpeed, Constants.maxSpeed); sliderSpeed.Writer = GetSpeedText; sliderSpeed.Getter = GetSpeed; sliderSpeed.Setter = SetSpeed; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sliderSpeed); IMyTerminalControlTextbox txtTimeout = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, IMyProjector>("GridTimer"); txtTimeout.Enabled = (b) => false; txtTimeout.Visible = IsValid; txtTimeout.Getter = GetTimer; txtTimeout.Setter = (b, s) => { }; txtTimeout.SupportsMultipleBlocks = false; txtTimeout.Title = MyStringId.GetOrCompute("Build Timer"); txtTimeout.Tooltip = MyStringId.GetOrCompute("The amount of time you must wait after building a grid to be able to build another."); MyAPIGateway.TerminalControls.AddControl <IMyProjector>(txtTimeout); // Terminal actions // Button panels are special and trigger on the server instead of the client, making everything more complicated. IMyTerminalAction aCancel = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildAction"); aCancel.Enabled = IsValid; aCancel.Action = CancelClient; // For all except button panels aCancel.ValidForGroups = true; aCancel.Name = new StringBuilder("Cancel Spawn Grid"); aCancel.Writer = (b, s) => s.Append("Cancel"); aCancel.InvalidToolbarTypes = new[] { MyToolbarType.ButtonPanel }.ToList(); MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel); IMyTerminalAction aCancel2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildGrid"); aCancel2.Enabled = IsValid; aCancel2.Action = CancelClientUnsafe; // For only button panels aCancel2.ValidForGroups = true; aCancel2.Name = new StringBuilder("Cancel Spawn Grid"); aCancel2.Writer = (b, s) => s.Append("Cancel"); aCancel2.InvalidToolbarTypes = new List <MyToolbarType> { MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit, MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator }; MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel2); IMyTerminalAction aBuild = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGridAction"); aBuild.Enabled = IsValid; aBuild.Action = BuildClient; // For all except button panels aBuild.ValidForGroups = true; aBuild.Name = new StringBuilder("Spawn Grid"); aBuild.Writer = (b, s) => s.Append("Spawn"); aBuild.InvalidToolbarTypes = new[] { MyToolbarType.ButtonPanel }.ToList(); MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild); IMyTerminalAction aBuild2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGrid"); aBuild2.Enabled = IsValid; aBuild2.Action = BuildClientUnsafe; // For only button panels aBuild2.ValidForGroups = true; aBuild2.Name = new StringBuilder("Spawn Grid"); aBuild2.Writer = (b, s) => s.Append("Spawn"); aBuild2.InvalidToolbarTypes = new List <MyToolbarType> { MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit, MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator }; MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild2); IMyTerminalControlListbox itemList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyProjector>("ComponentList"); itemList.Enabled = IsWorking; itemList.Visible = IsValid; itemList.ListContent = GetItemList; itemList.Multiselect = false; itemList.SupportsMultipleBlocks = false; itemList.Title = MyStringId.GetOrCompute("Components"); itemList.VisibleRowsCount = 10; itemList.ItemSelected = (b, l) => { }; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemList); IMyTerminalControlButton itemListInfo = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("ComponentListInfo"); itemListInfo.Enabled = IsWorking; itemListInfo.Visible = IsValid; itemListInfo.SupportsMultipleBlocks = false; itemListInfo.Title = MyStringId.GetOrCompute("Check Inventory"); itemListInfo.Action = OpenItemList; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemListInfo); // Programmable Block stuff IMyTerminalControlProperty <Dictionary <MyItemType, int> > itemListProp = MyAPIGateway.TerminalControls.CreateProperty <Dictionary <MyItemType, int>, IMyProjector>("RequiredComponents"); itemListProp.Enabled = IsWorking; itemListProp.Visible = IsValid; itemListProp.SupportsMultipleBlocks = false; itemListProp.Setter = (b, l) => { }; itemListProp.Getter = GetItemListPB; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemListProp); IMyTerminalControlProperty <int> gridTimeoutProp = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerProjection"); gridTimeoutProp.Enabled = IsWorking; gridTimeoutProp.Visible = IsValid; gridTimeoutProp.SupportsMultipleBlocks = false; gridTimeoutProp.Setter = (b, l) => { }; gridTimeoutProp.Getter = GetMaxTimerPB; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutProp); IMyTerminalControlProperty <int> gridTimeoutActive = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerCurrent"); gridTimeoutActive.Enabled = IsWorking; gridTimeoutActive.Visible = IsValid; gridTimeoutActive.SupportsMultipleBlocks = false; gridTimeoutActive.Setter = (b, l) => { }; gridTimeoutActive.Getter = GetCurrentTimerPB; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive); IMyTerminalControlProperty <int> buildState = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("BuildState"); buildState.Enabled = IsWorking; buildState.Visible = IsValid; buildState.SupportsMultipleBlocks = false; buildState.Setter = (b, l) => { }; buildState.Getter = GetStatePB; MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive); MyLog.Default.WriteLineAndConsole("Initialized Instant Projector."); controls = true; }
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; }
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; }