private void UpdateLocalKey(byte[] bytes) { var id = BitConverter.ToInt64(bytes, 0); var key = BitConverter.ToString(bytes, 8); if (!MyAPIGateway.Entities.EntityExists(id)) { return; } var logic = MyAPIGateway.Entities.GetEntityById(id)?.GameLogic?.GetAs <WebApiBlockComp>(); if (logic == null) { return; } logic.LocalKey = key; _keyControl.UpdateVisual(); }
static void createUI() { if (m_controlsInit) { return; } m_controlsInit = true; MyAPIGateway.TerminalControls.CustomControlGetter -= customControlGetter; MyAPIGateway.TerminalControls.CustomControlGetter += customControlGetter; // sender/receiver switch m_controlSender = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyRefinery>("Cython.RPT.SenderReceiver"); m_controlSender.Enabled = (b) => true; m_controlSender.Visible = (b) => b.BlockDefinition.SubtypeId.Equals("LargeBlockSmallRadialPowerTransmitter") || b.BlockDefinition.SubtypeId.Equals("SmallBlockSmallRadialPowerTransmitter"); m_controlSender.Title = MyStringId.GetOrCompute("Mode"); m_controlSender.Tooltip = MyStringId.GetOrCompute("Switches this transmitters mode to Sender or Receiver"); m_controlSender.OnText = MyStringId.GetOrCompute("Send"); m_controlSender.OffText = MyStringId.GetOrCompute("Rec."); m_controlSender.Getter = (b) => b.GameLogic.GetAs <RadialPowerTransmitter>().m_sender; m_controlSender.Setter = (b, v) => { b.GameLogic.GetAs <RadialPowerTransmitter>().m_sender = v; b.GameLogic.GetAs <RadialPowerTransmitter>().m_info.sender = v; m_controlSender.UpdateVisual(); m_controlPower.UpdateVisual(); byte[] message = new byte[13]; byte[] messageId = BitConverter.GetBytes(0); byte[] entityId = BitConverter.GetBytes(b.EntityId); for (int i = 0; i < 4; i++) { message[i] = messageId[i]; } for (int i = 0; i < 8; i++) { message[i + 4] = entityId[i]; } message[12] = BitConverter.GetBytes(v)[0]; MyAPIGateway.Multiplayer.SendMessageToOthers(5910, message, true); }; MyAPIGateway.TerminalControls.AddControl <IMyRefinery>(m_controlSender); // channel field m_controlChannel = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, IMyRefinery>("Cython.RPT.Channel"); m_controlChannel.Enabled = (b) => true; m_controlChannel.Visible = (b) => b.BlockDefinition.SubtypeId.Equals("LargeBlockSmallRadialPowerTransmitter") || b.BlockDefinition.SubtypeId.Equals("SmallBlockSmallRadialPowerTransmitter"); m_controlChannel.Title = MyStringId.GetOrCompute("Channel"); m_controlChannel.Tooltip = MyStringId.GetOrCompute("Channel this transmitter is supposed to send or receive on."); m_controlChannel.Getter = (b) => (new StringBuilder()).Append(b.GameLogic.GetAs <RadialPowerTransmitter>().m_channel); m_controlChannel.Setter = (b, s) => { uint channel; if (uint.TryParse(s.ToString(), out channel)) { var RPT = b.GameLogic.GetAs <RadialPowerTransmitter>(); RPT.m_channel = channel; RPT.m_info.channel = channel; byte[] message = new byte[16]; byte[] messageId = BitConverter.GetBytes(1); byte[] entityId = BitConverter.GetBytes(b.EntityId); byte[] value = BitConverter.GetBytes(channel); for (int i = 0; i < 4; i++) { message[i] = messageId[i]; } for (int i = 0; i < 8; i++) { message[i + 4] = entityId[i]; } for (int i = 0; i < 4; i++) { message[i + 12] = value[i]; } MyAPIGateway.Multiplayer.SendMessageToOthers(5910, message, true); } }; MyAPIGateway.TerminalControls.AddControl <IMyRefinery>(m_controlChannel); // power field m_controlPower = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, IMyRefinery>("Cython.RPT.Power"); m_controlPower.Enabled = (b) => b.GameLogic.GetAs <RadialPowerTransmitter>().m_sender; m_controlPower.Visible = (b) => b.BlockDefinition.SubtypeId.Equals("LargeBlockSmallRadialPowerTransmitter") || b.BlockDefinition.SubtypeId.Equals("SmallBlockSmallRadialPowerTransmitter"); m_controlPower.Title = MyStringId.GetOrCompute("Power"); m_controlPower.Tooltip = MyStringId.GetOrCompute("Maximum power this transmitter is supposed to send."); m_controlPower.Getter = (b) => (new StringBuilder()).Append(b.GameLogic.GetAs <RadialPowerTransmitter>().m_transmittedPower); m_controlPower.Setter = (b, s) => { float power; if (float.TryParse(s.ToString(), out power)) { var RPT = b.GameLogic.GetAs <RadialPowerTransmitter>(); RPT.m_transmittedPower = power; if (RPT.m_transmittedPower > RPT.m_currentMaxPower) { RPT.m_transmittedPower = RPT.m_currentMaxPower; } byte[] message = new byte[16]; byte[] messageId = BitConverter.GetBytes(2); byte[] entityId = BitConverter.GetBytes(b.EntityId); byte[] value = BitConverter.GetBytes(RPT.m_transmittedPower); for (int i = 0; i < 4; i++) { message[i] = messageId[i]; } for (int i = 0; i < 8; i++) { message[i + 4] = entityId[i]; } for (int i = 0; i < 4; i++) { message[i + 12] = value[i]; } MyAPIGateway.Multiplayer.SendMessageToOthers(5910, message, true); } }; MyAPIGateway.TerminalControls.AddControl <IMyRefinery>(m_controlPower); }
static void createUI() { if (m_controlsInit) { return; } m_controlsInit = true; MyAPIGateway.TerminalControls.CustomControlGetter -= customControlGetter; MyAPIGateway.TerminalControls.CustomControlGetter += customControlGetter; // sender/receiver switch m_controlSender = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyRefinery>("Cython.OPT.SenderReceiver"); m_controlSender.Enabled = (b) => true; m_controlSender.Visible = (b) => b.BlockDefinition.SubtypeId.Equals("LargeBlockSmallOpticalPowerTransmitter") || b.BlockDefinition.SubtypeId.Equals("SmallBlockSmallOpticalPowerTransmitter"); m_controlSender.Title = MyStringId.GetOrCompute("Mode"); m_controlSender.Tooltip = MyStringId.GetOrCompute("Switches this transmitters mode to Sender or Receiver"); m_controlSender.OnText = MyStringId.GetOrCompute("Send"); m_controlSender.OffText = MyStringId.GetOrCompute("Rec."); m_controlSender.Getter = (b) => b.GameLogic.GetAs <OpticalPowerTransmitter>().m_sender; m_controlSender.Setter = (b, v) => { b.GameLogic.GetAs <OpticalPowerTransmitter>().m_sender = v; b.GameLogic.GetAs <OpticalPowerTransmitter>().m_info.sender = v; m_controlSender.UpdateVisual(); m_controlPower.UpdateVisual(); byte[] message = new byte[13]; byte[] messageId = BitConverter.GetBytes(3); byte[] entityId = BitConverter.GetBytes(b.EntityId); for (int i = 0; i < 4; i++) { message[i] = messageId[i]; } for (int i = 0; i < 8; i++) { message[i + 4] = entityId[i]; } message[12] = BitConverter.GetBytes(v)[0]; MyAPIGateway.Multiplayer.SendMessageToOthers(5910, message, true); }; MyAPIGateway.TerminalControls.AddControl <IMyRefinery>(m_controlSender); // channel field m_controlId = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, IMyRefinery>("Cython.OPT.ID"); m_controlId.Enabled = (b) => true; m_controlId.Visible = (b) => b.BlockDefinition.SubtypeId.Equals("LargeBlockSmallOpticalPowerTransmitter") || b.BlockDefinition.SubtypeId.Equals("SmallBlockSmallOpticalPowerTransmitter"); m_controlId.Title = MyStringId.GetOrCompute("ID"); m_controlId.Tooltip = MyStringId.GetOrCompute("ID this transmitter is being identified as when being receiver or it is supposed to send to."); m_controlId.Getter = (b) => { if (b.GameLogic.GetAs <OpticalPowerTransmitter>().m_sender) { return((new StringBuilder()).Append(b.GameLogic.GetAs <OpticalPowerTransmitter>().m_targetId)); } else { return((new StringBuilder()).Append(b.GameLogic.GetAs <OpticalPowerTransmitter>().m_id)); } }; m_controlId.Setter = (b, s) => { uint id; if (uint.TryParse(s.ToString(), out id)) { var OPT = b.GameLogic.GetAs <OpticalPowerTransmitter>(); if (OPT.m_sender) { OPT.m_targetId = id; } else { OPT.m_id = id; OPT.m_info.id = id; } byte[] message = new byte[16]; byte[] messageId = BitConverter.GetBytes(4); byte[] entityId = BitConverter.GetBytes(b.EntityId); byte[] value = BitConverter.GetBytes(id); for (int i = 0; i < 4; i++) { message[i] = messageId[i]; } for (int i = 0; i < 8; i++) { message[i + 4] = entityId[i]; } for (int i = 0; i < 4; i++) { message[i + 12] = value[i]; } MyAPIGateway.Multiplayer.SendMessageToOthers(5910, message, true); } }; MyAPIGateway.TerminalControls.AddControl <Sandbox.ModAPI.Ingame.IMyRefinery>(m_controlId); // power field m_controlPower = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, Sandbox.ModAPI.Ingame.IMyRefinery>("Cython.OPT.Power"); m_controlPower.Enabled = (b) => b.GameLogic.GetAs <OpticalPowerTransmitter>().m_sender; m_controlPower.Visible = (b) => b.BlockDefinition.SubtypeId.Equals("LargeBlockSmallOpticalPowerTransmitter") || b.BlockDefinition.SubtypeId.Equals("SmallBlockSmallOpticalPowerTransmitter"); m_controlPower.Title = MyStringId.GetOrCompute("Power"); m_controlPower.Tooltip = MyStringId.GetOrCompute("Maximum power this transmitter is supposed to send."); m_controlPower.Getter = (b) => (new StringBuilder()).Append(b.GameLogic.GetAs <OpticalPowerTransmitter>().m_transmittedPower); m_controlPower.Setter = (b, s) => { float power; if (float.TryParse(s.ToString(), out power)) { var OPT = b.GameLogic.GetAs <OpticalPowerTransmitter>(); OPT.m_transmittedPower = power; if (OPT.m_transmittedPower > OPT.m_currentMaxPower) { OPT.m_transmittedPower = OPT.m_currentMaxPower; } byte[] message = new byte[16]; byte[] messageId = BitConverter.GetBytes(5); byte[] entityId = BitConverter.GetBytes(b.EntityId); byte[] value = BitConverter.GetBytes(OPT.m_transmittedPower); for (int i = 0; i < 4; i++) { message[i] = messageId[i]; } for (int i = 0; i < 8; i++) { message[i + 4] = entityId[i]; } for (int i = 0; i < 4; i++) { message[i + 12] = value[i]; } MyAPIGateway.Multiplayer.SendMessageToOthers(5910, message, true); } }; MyAPIGateway.TerminalControls.AddControl <IMyRefinery>(m_controlPower); }