Advertisement
GreytideSkye

Space Engineers - Exposing Jump as a terminal action

Oct 22nd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.79 KB | None | 0 0
  1. using Sandbox.ModAPI;
  2. using Sandbox.ModAPI.Interfaces.Terminal;
  3. using System;
  4. using System.Text;
  5. using VRage.Game.Components;
  6. using VRage.Utils;
  7.  
  8. //Cobbled together from various forms of advice, tutorials, and depression.
  9.  
  10. namespace JumpAnyway
  11. {
  12.    [MySessionComponentDescriptor(MyUpdateOrder.BeforeSimulation)]
  13.     public class Program : MySessionComponentBase
  14.     {
  15.         private bool init = false;
  16.         private int updateCount = 0;
  17.         public override void UpdateBeforeSimulation()
  18.         {
  19.             try
  20.             {
  21.                 if (!init)
  22.                 {
  23.                     //MyAPIGateway.Utilities.ShowMessage("Jump", "UpdateBeforeSimulation");
  24.                     CreateJumpCommand();
  25.                     init = true;
  26.                 }
  27.             }
  28.             catch (Exception e)
  29.             {
  30.                 MyAPIGateway.Utilities.ShowMessage("Error", e.Message);
  31.             }
  32.         }
  33.  
  34.  
  35.         void TriggerJumpCommand(IMyTerminalBlock jumpDrive)
  36.         {
  37.             //MyAPIGateway.Utilities.ShowMessage("Jump", "Triggering!");
  38.             IMyJumpDrive jd = jumpDrive as IMyJumpDrive;
  39.             jd.Jump(false);
  40.         }
  41.  
  42.         public Action<IMyTerminalBlock> JumpAction
  43.         {
  44.             get
  45.             {
  46.                 //MyAPIGateway.Utilities.ShowMessage("JumpAction", "Get");
  47.                 return TriggerJumpCommand;
  48.                 //return true;
  49.             }
  50.             set
  51.             {
  52.                 //MyAPIGateway.Utilities.ShowMessage("JumpAction", "SET");
  53.             }
  54.         }
  55.  
  56.         void CreateJumpCommand()
  57.         {
  58.             //MyAPIGateway.Utilities.ShowMessage("Jump","Creating Jump Command");
  59.             //Create a jump button in the terminal after the list of GPS coordinates. Too much work to put it higher.
  60.             var jumpButton = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlButton, Sandbox.ModAPI.Ingame.IMyJumpDrive>("JumpAnyways");//"engage"?
  61.  
  62.             jumpButton.Action = JumpAction;
  63.             jumpButton.Title = MyStringId.GetOrCompute("Jump");
  64.             jumpButton.Tooltip = MyStringId.GetOrCompute("Attempt to initate space-time distortion fields, bypassing in-cockpit safety check.");
  65.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.Ingame.IMyJumpDrive>(jumpButton);
  66.  
  67.             //Create the action for timers, buttons, etc.
  68.             var jumpAction = MyAPIGateway.TerminalControls.CreateAction<Sandbox.ModAPI.Ingame.IMyJumpDrive>("Jump Please");
  69.             jumpAction.Action =  JumpAction;
  70.             jumpAction.Name = new StringBuilder("Jump Please");
  71.             //jumpAction.Writer = CruiseControlSwitchHotbarText; //??
  72.             MyAPIGateway.TerminalControls.AddAction<Sandbox.ModAPI.Ingame.IMyJumpDrive>(jumpAction);
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement