public List <ITerminalAction> GetActions(IMyTerminalBlock block) { if (m_customActionGetter != null) { // This is a double list copy :( var actionList = MyTerminalControlFactory.GetActions(block.GetType()).Cast <IMyTerminalAction>().ToList(); m_customActionGetter(block, actionList); return(actionList.Cast <ITerminalAction>().ToList()); } else { return(MyTerminalControlFactory.GetActions(block.GetType()).ToList()); } }
public List <ITerminalControl> GetControls(IMyTerminalBlock block) { if (m_customControlGetter != null) { // This is a double list copy :( var controlList = MyTerminalControlFactory.GetControls(block.GetType()).Cast <IMyTerminalControl>().ToList(); m_customControlGetter(block, controlList); return(controlList.Cast <ITerminalControl>().ToList()); } else { return(MyTerminalControlFactory.GetControls(block.GetType()).ToList()); } }
public ACPWrapper(Program p, string antennaName) { CommonInit(p); IMyTerminalBlock temp = P.GridTerminalSystem.GetBlockWithName(antennaName); if (temp.GetType() == typeof(IMyRadioAntenna)) { this.antenna = (IMyRadioAntenna)temp; } else if (temp.GetType() == typeof(IMyLaserAntenna)) { this.lAntenna = (IMyLaserAntenna)temp; isLaser = true; } }
/// <summary> /// Returns true if the block has ownership permissions /// </summary> public static bool GetIsBlockOwnable(this IMyTerminalBlock block) { bool isOwnable; if (!ownableBlockMap.TryGetValue(block.GetType(), out isOwnable)) { IMyCubeGrid grid = block.CubeGrid; var def = MyDefinitionManager.Static.GetDefinition(block.BlockDefinition) as MyCubeBlockDefinition; // Terminal blocks with computers are ownable. If there are no bigOwners, the grid is unowned. isOwnable = def?.Components.Any(x => x.Definition.Id.SubtypeName == "Computer") ?? false; ownableBlockMap.Add(block.GetType(), isOwnable); } return(isOwnable); }
public static void SetCustomName(IMyTerminalBlock terminalBlock, string text) { try { StringBuilder newCustomName = new StringBuilder(text); InvokeStaticMethod(terminalBlock.GetType( ), TerminalBlockBroadcastCustomNameMethod, new object[] { terminalBlock, newCustomName }); } catch (Exception ex) { ApplicationLog.BaseLog.Error(string.Format("SetCustomName(): {0}", ex)); } }
public TerminalBlock(IMyTerminalBlock block, bool light = true) { Name = block.CustomName; var def = block.BlockDefinition; Type = $"{def.TypeId}/{def.SubtypeId}"; Id = block.EntityId; if (light) { return; } if (block.HasInventory) { var count = block.InventoryCount; for (var i = 0; i < count; i++) { Inventories.Add(new Inventory(block.GetInventory(i))); } } block.GetProperties(new List <ITerminalProperty>(), p => { var prop = new BlockProperty(p, block); if (prop.IsValid) { Properties.Add(prop); } return(false); }); foreach (var action in MyTerminalControlFactory.GetActions(block.GetType())) { Actions.Add(action.Id); } }
public static void SetCustomName( IMyTerminalBlock terminalBlock, string text ) { try { StringBuilder newCustomName = new StringBuilder( text ); InvokeStaticMethod( terminalBlock.GetType( ), TerminalBlockBroadcastCustomNameMethod, new object[ ] { terminalBlock, newCustomName } ); } catch ( Exception ex ) { ApplicationLog.BaseLog.Error( string.Format( "SetCustomName(): {0}", ex ) ); } }
private void RunCommand(string argument) { MyProperty.Load(); Init(); if (argument != null) { commandLine.TryParse(argument); var command = commandLine.Argument(0); if (command != null) { command = command.Trim().ToLower(); } switch (command) { case "default": Me.CustomData = ""; MyProperty.Load(); MyProperty.Save(); break; case "forceupdate": ForceUpdate = true; break; case "test": IMyTextPanel lcd = (IMyTextPanel)GridTerminalSystem.GetBlockWithName(commandLine.Argument(1)); lcd.ScriptBackgroundColor = Color.Black; Drawing drawing = new Drawing(lcd); drawing.Test(); drawing.Dispose(); break; case "getname": int index = 0; int.TryParse(commandLine.Argument(1), out index); var names = new List <string>(); drawingSurface.GetSprites(names); Echo($"Sprite {index} name={names[index]}"); IMyTextPanel lcdResult = (IMyTextPanel)GridTerminalSystem.GetBlockWithName("Result Name"); lcdResult.ContentType = ContentType.TEXT_AND_IMAGE; lcdResult.WriteText($"Sprite {index}\n", false); lcdResult.WriteText($"name={names[index]}", true); break; case "gettype": int.TryParse(commandLine.Argument(1), out index); string name = commandLine.Argument(1); IMyTerminalBlock block = (IMyTerminalBlock)GridTerminalSystem.GetBlockWithName(name); IMyTextPanel lcdResult2 = (IMyTextPanel)GridTerminalSystem.GetBlockWithName("Result Type"); lcdResult2.ContentType = ContentType.TEXT_AND_IMAGE; lcdResult2.WriteText($"Block {name}\n", false); lcdResult2.WriteText($"Type Name={block.GetType().Name}\n", true); lcdResult2.WriteText($"SubtypeName={block.BlockDefinition.SubtypeName}\n", true); lcdResult2.WriteText($"SubtypeId={block.BlockDefinition.SubtypeId}\n", true); break; default: search = true; Search(); break; } } }
public void Main(string argument, UpdateType updateSource) { /**/ String[] eval = argument.Split(' '); if (eval.Length <= 0) { SwitchRedAlert(); } else { switch (eval[0].ToLower()) { case "lazy": List <IMyLightingBlock> temp = new List <IMyLightingBlock>(); GridTerminalSystem.GetBlocksOfType(temp); foreach (IMyLightingBlock bl in temp) { if ( !CheckForIgnore(bl) && !bl.CustomName.Equals(ALARM_LIGHT) && !bl.CustomName.Equals(ROTAT_LIGHT) && !bl.CustomName.Equals(SWITCH_LIGHT) && !bl.CustomName.Equals(OTHER_LIGHT) && bl.CubeGrid.Equals(Me.CubeGrid) ) { if (bl.BlockDefinition.SubtypeName.Equals("RotatingLightLarge") || bl.BlockDefinition.SubtypeName.Equals("RotatingLightSmall")) { bl.CustomName = ROTAT_LIGHT; } else if (bl.BlockDefinition.SubtypeName.Equals("LargeBlockFrontLight") || bl.BlockDefinition.SubtypeName.Equals("SmallBlockFrontLight")) { bl.CustomName = SHIP_NAME + "/Spotlight"; } else { bl.CustomName = OTHER_LIGHT; } } } break; case "test": string chckName = argument.Substring(eval[0].Length + 1); IMyTerminalBlock block = GridTerminalSystem.GetBlockWithName(chckName) as IMyTerminalBlock; if (block == null) { Echo("UnU"); return; } Echo(block.GetType().FullName); List <ITerminalAction> list = new List <ITerminalAction>(); block.GetActions(list); Echo(block.BlockDefinition.SubtypeId); Echo(UnpackList(list)); break; default: SwitchRedAlert(); break; } } }