static MyProgrammableBlock() { var console = new MyTerminalControlButton <MyProgrammableBlock>("Edit", MySpaceTexts.TerminalControlPanel_EditCode, MySpaceTexts.TerminalControlPanel_EditCode_Tooltip, (b) => b.SyncObject.SendOpenEditorRequest(Sync.MyId)); console.Visible = (b) => MyFakes.ENABLE_PROGRAMMABLE_BLOCK && MySession.Static.EnableIngameScripts; MyTerminalControlFactory.AddControl(console); var arg = new MyTerminalControlTextbox <MyProgrammableBlock>("ConsoleCommand", MySpaceTexts.TerminalControlPanel_RunArgument, MySpaceTexts.TerminalControlPanel_RunArgument_ToolTip); arg.Visible = (e) => MyFakes.ENABLE_PROGRAMMABLE_BLOCK && MySession.Static.EnableIngameScripts; arg.Getter = (e) => new StringBuilder(e.TerminalRunArgument); arg.Setter = (e, v) => e.TerminalRunArgument = v.ToString(); MyTerminalControlFactory.AddControl(arg); var terminalRun = new MyTerminalControlButton <MyProgrammableBlock>("TerminalRun", MySpaceTexts.TerminalControlPanel_RunCode, MySpaceTexts.TerminalControlPanel_RunCode_Tooltip, (b) => b.Run()); terminalRun.Visible = (b) => MyFakes.ENABLE_PROGRAMMABLE_BLOCK && MySession.Static.EnableIngameScripts; terminalRun.Enabled = (b) => b.IsWorking == true && b.IsFunctional == true; MyTerminalControlFactory.AddControl(terminalRun); var runAction = new MyTerminalAction <MyProgrammableBlock>("Run", MyTexts.Get(MySpaceTexts.TerminalControlPanel_RunCode), OnRunApplied, null, MyTerminalActionIcons.START); runAction.Enabled = (b) => b.IsWorking == true && b.IsFunctional == true; runAction.DoUserParameterRequest = RequestRunArgument; runAction.ParameterDefinitions.Add(TerminalActionParameter.Get(string.Empty)); MyTerminalControlFactory.AddAction(runAction); }
public override bool Init(MyObjectBuilder_ToolbarItem objectBuilder) { Debug.Assert(objectBuilder is MyObjectBuilder_ToolbarItemTerminalBlock, "Wrong definition put to toolbar"); WantsToBeActivated = false; WantsToBeSelected = false; ActivateOnClick = true; m_block = null; var builder = (MyObjectBuilder_ToolbarItemTerminalBlock)objectBuilder; m_blockEntityId = builder.BlockEntityId; if (m_blockEntityId == 0) { m_wasValid = false; return(false); } TryGetBlock(); SetAction(builder.Action); if (builder.Parameters != null && builder.Parameters.Count > 0) { m_parameters.Clear(); foreach (var item in builder.Parameters) { m_parameters.Add(TerminalActionParameter.Deserialize(item.Value, item.TypeCode)); } } return(true); }
/// <summary> /// Logs a message. /// </summary> /// <param name="msg">The message to be logged.</param> void Log(string msg) { if (_logger != null) { _logger.ApplyAction("Run", new List <TerminalActionParameter>() { TerminalActionParameter.Get("log=" + msg) }); } }
/// <summary> /// Shows a dialog to configure a custom argument to provide the Run action. /// </summary> /// <param name="list"></param> /// <param name="callback"></param> private static void RequestRunArgument(IList <TerminalActionParameter> list, Action <bool> callback) { // TODO: allocations, needs GUI redo MyGuiScreenDialogText dialog = new MyGuiScreenDialogText(string.Empty, MySpaceTexts.DialogText_RunArgument); dialog.OnConfirmed += argument => { list[0] = TerminalActionParameter.Get(argument); callback(true); }; MyGuiSandbox.AddScreen(dialog); }
private void Loop(string key) { loopProg.ApplyAction("Run", new List <TerminalActionParameter>() { TerminalActionParameter.Get( Me.CustomName + Seperator + Me.CubeGrid + Seperator + Me.NumberInGrid + Seperator + key) }); }
public new void Main(string arguments) { enemies.Clear(); lostContact.Clear(); sinceLastAlarm += Runtime.TimeSinceLastRun; DetectedEntityData entityData; foreach (string serialized in arguments.Split(entitySeparator)) { if (DetectedEntityData.TryDeserialize(serialized, out entityData)) { if (entityData.relations == Relation_Enemy) { enemies.Add(TerminalActionParameter.Get(entityData.entityId)); // sound alarm if enemy is near if (sinceLastAlarm >= alarmInterval && (entityData.volume > 100 || entityData.volume == 0f) && entityData.secondsSinceDetected < 60 && Vector3D.DistanceSquared(Me.GetPosition(), entityData.predictedPosition) < 10000 * 10000) { sinceLastAlarm = new TimeSpan(); IMySoundBlock alarm = GridTerminalSystem.GetBlockWithName("Proximity Alarm") as IMySoundBlock; if (alarm == null) { Terminate("Proximity Alarm is not a sound block"); return; } else { alarm.ApplyAction("PlaySound"); } } } else if (entityData.relations == Relation_Owner && entityData.secondsSinceDetected > 10) { lostContact.Add(TerminalActionParameter.Get(entityData.entityId)); } } else { Terminate("Deserialize failed: " + serialized); return; } } DisplayEntitiesOnPanel("Wide LCD panel for Enemy", enemies); DisplayEntitiesOnPanel("Wide LCD panel for Lost Contact", lostContact); }
void Main(string argument) { Echo("Global Count: " + _globalCount); _globalCount++; if (argument != null) { Echo("Argument: " + argument); if (!argument.Equals("")) { try { _count = int.Parse(argument); Echo("Argument parsed as " + _count); } catch (Exception) { Echo("Argument not parsable"); _count = 0; } } } else { Echo("Argument null"); return; } if (_globalCount < 10) { string newArg = (_count + 1).ToString(); Echo("Try: " + newArg); //Me.ApplyAction("Run"); IMyProgrammableBlock prog = GridTerminalSystem.GetBlockWithName("Prog Loop 2") as IMyProgrammableBlock; if (prog != null) { prog.ApplyAction("Run", new List <TerminalActionParameter>() { TerminalActionParameter.Get(newArg) }); } List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyTimerBlock>(blocks); if (blocks.Count > 0) { IMyTimerBlock timer = blocks[0] as IMyTimerBlock; if (timer != null) { timer.ApplyAction("TriggerNow"); } } } }
bool IMyProgrammableBlock.TryRun(string argument) { // If we find some reason why a run couldn't possibly work, return false if (m_instance == null || m_isRunning || this.IsWorking == false || this.IsFunctional == false) { return(false); } // Fill the arguments list. Make sure the argument is never null! m_tryRunArguments[0] = TerminalActionParameter.Get(argument ?? ""); this.ApplyAction("Run", m_tryRunArguments); return(true); }
/// <summary> /// Sends commands to the autopilot. /// </summary> /// <param name="content">The commands for the autopilot.</param> void SendMessageToAutopilot(string content) { Echo("AP: " + content); parameters[2] = TerminalActionParameter.Get(content); ITerminalAction action = Me.GetActionWithName("SendMessage"); if (action == null) { Echo("ARMS is not loaded. ARMS is a prerequisite for this script."); } else { Me.ApplyAction("SendMessage", parameters); } }
void Main(string argument) { // Name;CubeGrid;NumberInGrid;Arguments string[] args = argument.Split(new char[] { ';' }, 4); Echo("Arguments:"); for (int i = 0; i < args.Length; i++) { Echo(args[i]); } int gridNum = -1; if (!int.TryParse(args[2], out gridNum)) { Echo("Could not parse 2nd argument to integer."); return; } List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyProgrammableBlock>(blocks, b => b.NumberInGrid == gridNum && b.CubeGrid.ToString().Equals(args[1]) && b.CustomName.Equals(args[0])); if (blocks.Count > 1) { Echo("Too many Programmable Blocks with name '" + args[0] + "' and grid number '" + gridNum + "'."); return; } else if (blocks.Count == 0) { Echo("Could not found the Programmable Block with name '" + args[0] + "' and grid number '" + gridNum + "'."); return; } Echo("Run Prog: " + blocks[0].CustomName); Echo("Argument: " + args[3]); IMyProgrammableBlock prog = blocks[0] as IMyProgrammableBlock; prog.ApplyAction("Run", new List <TerminalActionParameter>() { TerminalActionParameter.Deserialize(args[3], TypeCode.String) }); }
/// <summary> /// Sends a message to one or more blocks. All matching Programmable blocks and Autopilot blocks /// will be sent a message. /// </summary> /// <param name="targetGrid">Every grid with targetGrid in the name will receive a message</param> /// <param name="targetBlock">Every Programmable Block or Autopilot block with targetBlock in /// the name will receive a message</param> /// <param name="content">The content of the message</param> void SendMessage(string targetGrid, string targetBlock, string content) { arguments.Clear(); arguments.Add(TerminalActionParameter.Get(targetGrid)); arguments.Add(TerminalActionParameter.Get(targetBlock)); arguments.Add(TerminalActionParameter.Get(content)); ITerminalAction action = Me.GetActionWithName("SendMessage"); if (action == null) { Echo("ARMS is not loaded. ARMS is a prerequisite for this script."); } else { Me.ApplyAction("SendMessage", arguments); } }
protected override void CreateTerminalControls() { if (MyTerminalControlFactory.AreControlsCreated <MyProgrammableBlock>()) { return; } base.CreateTerminalControls(); var console = new MyTerminalControlButton <MyProgrammableBlock>("Edit", MySpaceTexts.TerminalControlPanel_EditCode, MySpaceTexts.TerminalControlPanel_EditCode_Tooltip, (b) => b.SendOpenEditorRequest()); console.Visible = (b) => MyFakes.ENABLE_PROGRAMMABLE_BLOCK && MySession.Static.EnableIngameScripts; console.Enabled = (b) => MySession.Static.IsScripter; MyTerminalControlFactory.AddControl(console); var arg = new MyTerminalControlTextbox <MyProgrammableBlock>("ConsoleCommand", MySpaceTexts.TerminalControlPanel_RunArgument, MySpaceTexts.TerminalControlPanel_RunArgument_ToolTip); arg.Visible = (e) => MyFakes.ENABLE_PROGRAMMABLE_BLOCK && MySession.Static.EnableIngameScripts; arg.Getter = (e) => new StringBuilder(e.TerminalRunArgument); arg.Setter = (e, v) => e.TerminalRunArgument = v.ToString(); MyTerminalControlFactory.AddControl(arg); var terminalRun = new MyTerminalControlButton <MyProgrammableBlock>("TerminalRun", MySpaceTexts.TerminalControlPanel_RunCode, MySpaceTexts.TerminalControlPanel_RunCode_Tooltip, (b) => b.Run()); terminalRun.Visible = (b) => MyFakes.ENABLE_PROGRAMMABLE_BLOCK && MySession.Static.EnableIngameScripts; terminalRun.Enabled = (b) => b.IsWorking == true && b.IsFunctional == true; MyTerminalControlFactory.AddControl(terminalRun); var recompile = new MyTerminalControlButton <MyProgrammableBlock>("Recompile", MySpaceTexts.TerminalControlPanel_Recompile, MySpaceTexts.TerminalControlPanel_Recompile_Tooltip, (b) => b.Recompile()); recompile.Visible = (b) => MyFakes.ENABLE_PROGRAMMABLE_BLOCK && MySession.Static.EnableIngameScripts; recompile.Enabled = (b) => b.IsWorking == true && b.IsFunctional == true; MyTerminalControlFactory.AddControl(recompile); var runAction = new MyTerminalAction <MyProgrammableBlock>("Run", MyTexts.Get(MySpaceTexts.TerminalControlPanel_RunCode), OnRunApplied, null, MyTerminalActionIcons.START); runAction.Enabled = (b) => b.IsFunctional == true; runAction.DoUserParameterRequest = RequestRunArgument; runAction.ParameterDefinitions.Add(TerminalActionParameter.Get(string.Empty)); MyTerminalControlFactory.AddAction(runAction); var runwithDefault = new MyTerminalAction <MyProgrammableBlock>("RunWithDefaultArgument", MyTexts.Get(MySpaceTexts.TerminalControlPanel_RunCodeDefault), OnRunDefaultApplied, MyTerminalActionIcons.START); runwithDefault.Enabled = (b) => b.IsFunctional == true; MyTerminalControlFactory.AddAction(runwithDefault); }
public void Main(string args) { lastUpdate_uranium += Runtime.TimeSinceLastRun; lastUpdate_gas += Runtime.TimeSinceLastRun; lastUpdate_cargo += Runtime.TimeSinceLastRun; if (allTasks == null) { allTasks = new List <Task>(); string first = "L Connector ; B Connector ; G"; allTasks.Add(new Task(UraniumLow, UraniumHigh, first + "Uranium Platform")); allTasks.Add(new Task(HydrogenLow, HydrogenHigh, first + "Hydrogen Platform ; A Hydrogen Tank, Stockpile_On")); allTasks.Add(new Task(OxygenLow, OxygenHigh, first + "Oxygen Platform ; A Oxygen Tank, Stockpile_On")); allTasks.Add(new Task(CargoPartFull, CargoEmpty, first + "Receiving Platform")); allTasks.Add(new Task(null, CargoFull, "L Connector ; B Connector ; G Sending Platform")); parameters = new List <TerminalActionParameter>(); parameters.Add(TerminalActionParameter.Get("Cargo Hauler")); parameters.Add(TerminalActionParameter.Get("Autopilot")); parameters.Add(new TerminalActionParameter()); } if (currentTask != null) { if (IsDocked() && !currentTask.endWhen.Invoke()) { Echo("Continuing current task"); return; } currentTask = null; } for (int i = 0; i < allTasks.Count; i++) { if (allTasks[i].startWhen == null || allTasks[i].startWhen.Invoke()) { currentTask = allTasks[i]; DisableStockpile(); SendMessageToAutopilot(allTasks[i].commands); return; } } }
public Program() { this.Runtime.UpdateFrequency = UpdateFrequency.Update1; this.manager = Process.CreateManager(this.Echo); var screen = this.GridTerminalSystem.GetBlockWithName("LCD (Rear Seat)") as IMyTextPanel; var logger = new Logger(this.manager, this.Me.GetSurface(0), size: 0.25f); this.logger = logger.Log; this.manager.SetLogger(logger.Log); this.cmd = new CommandLine("Small Mobile Base", logger.Log, this.manager); IMyTerminalBlock wheel = this.GridTerminalSystem.GetBlockWithName("Wheel test"); ITerminalAction attach = wheel.GetActionWithName("Add Top Part"); var proj = this.GridTerminalSystem.GetBlockWithName("Projector test") as IMyProjector; ITerminalAction spawn = proj.GetActionWithName("SpawnProjection"); //attach.Apply(wheel); //var param = TerminalActionParameter.Get("Blueprints/cloud/Boring Machine Drill/bp.sbc"); //var param = TerminalActionParameter.Get("Boring Machine Drill"); //var param = TerminalActionParameter.Get("Blueprints/cloud/Boring Machine Drill"); var param = TerminalActionParameter.Get("Welder"); proj.ApplyAction("SpawnProjection", new List <TerminalActionParameter> { param }); this.logger(spawn.Name.ToString()); var sb = new StringBuilder(""); spawn.WriteValue(proj, sb); this.logger(sb.ToString()); var list = new List <IMyShipToolBase>(); GridTerminalSystem.GetBlocksOfType(list, c => c.CubeGrid == this.Me.CubeGrid); this.logger("====="); foreach (var t in list) { this.logger(t.CustomName); } }