public void UpdateCallPanels() { if (craneConnector == null || cranePiston == null || craneRotor == null) { return; } for (int key = 0; key < callPanels.Count; key++) { string areaPrefix = callPanels[key].CustomName.Substring(0, callPanels[key].CustomName.Length - callPanelName.Length); IMyShipConnector areaConnector = GridTerminalSystem.GetBlockWithName(areaPrefix + "Connector") as IMyShipConnector; IMyTextSurfaceProvider panelScreens = (IMyTextSurfaceProvider)callPanels[key]; IMyTextSurface callScreen = panelScreens.GetSurface(0); if (areaConnector != null) { if (callOverride == null && areaConnector.Status == MyShipConnectorStatus.Connected && areaConnector.OtherConnector == craneConnector) { callScreen.FontColor = Color.Green; } else { callScreen.FontColor = callOverride != null ? Color.Yellow : Color.White; } } else { callScreen.FontColor = Color.Red; } } UpdateStatusPanels(); }
/// <summary> /// Disconnects all displays in provided multi-display block. /// </summary> /// <param name="DisplayHolder">Example: A Cockpit.</param> public void DisconnectDisplay(IMyTextSurfaceProvider DisplayHolder) { for (int i = 0; i < DisplayHolder.SurfaceCount; i++) { DisconnectDisplay(DisplayHolder.GetSurface(i)); } }
public Program() { Runtime.UpdateFrequency = UpdateFrequency.Update10; GridTerminalSystem.GetBlocks(blocks); foreach (IMyTerminalBlock block in blocks) { IMyTextSurfaceProvider surfaceProvider = block as IMyTextSurfaceProvider; if (null != surfaceProvider) { surfaceProviders.Add(surfaceProvider); } } foreach (IMyTextSurfaceProvider prov in surfaceProviders) { int count = prov.SurfaceCount; for (int i = 0; i < count; i++) { IMyTextSurface surface = prov.GetSurface(i); surface.ContentType = ContentType.SCRIPT; surface.Script = "None"; surfaces.Add(surface); } } //Runtime.UpdateFrequency = UpdateFrequency.Update100; }
private static IMyTextSurface FindDisplay(string DisplayName, IMyGridTerminalSystem gts, IMyTerminalBlock anyBlock) { IMyTextSurface TextSurface = null; int x = DisplayName.IndexOf('('); if (x == -1) { TextSurface = FindBlockOfType <IMyTextSurface>(DisplayName, gts, anyBlock); } else { string mName = DisplayName.Substring(0, x); IMyTextSurfaceProvider sp = FindBlockOfType <IMyTextSurfaceProvider>(mName, gts, anyBlock); if (sp != null) { int y = DisplayName.IndexOf(')'); string indexStr = DisplayName.Substring(x + 1, y - x - 1).Trim(); int surfIndex = int.Parse(indexStr); TextSurface = sp.GetSurface(surfIndex); } } return(TextSurface); }
/// <summary>Adds an output window to a specific screen surface. Does not affect other windows.</summary> /// <param name="block">Block that provides the surface</param> /// <param name="surf">Surface number</param> /// <param name="area">Area for the window to take up.</param> /// <param name="job">Output provider that will use this window.</param> /// <param name="mode">String describing the contents of the window (provider-defined).</param> /// <returns>Window object.</returns> public Window AddWindow(IMyTextSurfaceProvider block, int surf, RectangleF area, IHasOutput job, string mode) { object data; if (surf >= block.SurfaceCount) { Owner.Log($"Surface #{surf} does not exist on '{(block as IMyTerminalBlock).CustomName}'"); } else if (!job.TryParseMode(mode, out data)) { Owner.Log($"'{mode}' is not a valid mode string for '{job.ID}'."); } else { var surface = block.GetSurface(surf); if (!Screens.ContainsKey(surface)) { Screens[surface] = new List <Window>(); Updater.Dispose(); Updater = Screens.GetEnumerator(); } var w = new Window(new WindowLocation(block, surf, area), surface, data, job); Screens[surface].Add(w); UpdateScreen(surface, Screens[surface]); return(w); } return(null); }
public void Search() { Monitors = new List <Monitor>(); List <IMyTerminalBlock> blocks; blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyTextSurfaceProvider>(blocks, BlockFilter); foreach (IMyTerminalBlock block in blocks) { IMyTextSurfaceProvider provider = block as IMyTextSurfaceProvider; for (int i = 0; i < provider.SurfaceCount; i++) { Monitor monitor = new Monitor(Program, MBParser, MBBuilder) { Surface = provider.GetSurface(i), Name = $"{block.CustomName}[{i}]" }; if (!monitor.TryParse(block.CustomData, i)) { Echo("parse failure!"); continue; } if (monitor.MonitorBlocks.Count > 0) { Monitors.Add(monitor); //if (DEBUG) Echo($"Add monitor: {monitor.Name}"); } } } }
/// <summary>Replaces contents of a specific screen with an output window.</summary> /// <param name="block">Block that provides the surface</param> /// <param name="surf">Surface number</param> /// <param name="job">Output provider that will use this window.</param> /// <param name="mode">String describing the contents of the window (provider-defined).</param> /// <returns>Window object.</returns> public Window SetScreen(IMyTextSurfaceProvider block, int surf, IHasOutput job, string mode) { RectangleF area = new RectangleF(0, 0, 1, 1); ClearScreen(block as IMyTextSurfaceProvider, surf); return(AddWindow(block as IMyTextSurfaceProvider, surf, area, job, mode)); }
/// <summary>Removes all windows that intersect specific area on the given surface.</summary> /// <param name="block">Block that provides the surface</param> /// <param name="surf">Surface number</param> /// <param name="area">Any window that intersects this area will be removed.</param> public void RemoveWindowsIn(IMyTextSurfaceProvider block, int surf, RectangleF area) { RectangleF intersect; if (surf >= block.SurfaceCount) { Owner.Log($"Surface #{surf} does not exist on '{(block as IMyTerminalBlock).CustomName}'"); } else { var surface = block.GetSurface(surf); if (Screens.ContainsKey(surface)) { var ws = Screens[surface]; if (ws.Count == ws.RemoveAll((w) => RectangleF.Intersect(ref area, ref w.Location.Area, out intersect))) { ClearScreen(block, surf); } else { UpdateScreen(surface, ws); } } } }
private void Add(IMyTextSurfaceProvider p, List <IMyTextSurface> surfaces) { for (int i = 0; i < p.SurfaceCount; i++) { surfaces.Add(p.GetSurface(i)); } }
protected override void updateDisplayImpl() { _stringBuilder.Clear(); double distanceToPlanetSurface = (getTargetingBlockPosition() - _planetPosition).Length() - _nearestPlanet.getNearestPlanetOrbitRadius(); _stringBuilder.Append(string.Format("{0} gravity:\n ", _nearestPlanet.getNearestPlanetName())); _stringBuilder.Append(string.Format("{0:0.00} km", distanceToPlanetSurface / 1000)); _stringBuilder.Append("\n"); string text = _stringBuilder.ToString(); foreach (IMyCockpit cockpit in _cockpits) { IMyTextSurfaceProvider surfaceProvider = cockpit as IMyTextSurfaceProvider; if (surfaceProvider.SurfaceCount > 0) { IMyTextSurface surface = surfaceProvider.GetSurface(0); surface.ContentType = ContentType.TEXT_AND_IMAGE; surface.WriteText(text); surface.FontSize = 2.3f; surface.Alignment = TextAlignment.CENTER; } } foreach (IMyTextPanel panel in _textPanels) { panel.ContentType = ContentType.TEXT_AND_IMAGE; panel.WriteText(text); panel.FontSize = 2.3f; panel.Alignment = TextAlignment.CENTER; } }
public Program() { StepScheduler = new Scheduler(this); MyThruster = new Thruster(this); IMyTextSurfaceProvider debugoutputblock = GridTerminalSystem.GetBlockWithName("LCD Panel debug") as IMyTextSurfaceProvider; debugoutput = debugoutputblock.GetSurface(0); }
public bool _TextSurfacesOutputPredicate(IMyTextSurfaceProvider provider) { IMyTerminalBlock block = (IMyTerminalBlock)provider; string name = block.CustomName; string prefix = BLOCK_WITH_TEXT_SURFACE_PATTERN.Split('*')[0]; string postfix = BLOCK_WITH_TEXT_SURFACE_PATTERN.Split('*')[1]; return(!(name.StartsWith(prefix) && name.EndsWith(postfix))); }
private void LogLine(String msg) { IMyTextSurfaceProvider prov = Me; var disp = Me.GetSurface(0); disp.ContentType = ContentType.TEXT_AND_IMAGE; Echo(msg); this.missileDiagLogger.OutputLine(msg, true); }
public void ResetScreenHandlerForSurface(int surfaceIndex) { _screenHandlers.Remove(surfaceIndex); IMyTextSurfaceProvider surfaceProvider = _block as IMyTextSurfaceProvider; IMyTextSurface surface = surfaceProvider.GetSurface(surfaceIndex); surface.Script = ""; surface.ContentType = ContentType.NONE; }
private IMyTextSurface ParseSurfaceProperty(string surfaceDef, string warnPrefix = "WARNING: ") { string[] fields = surfaceDef.Split(':'); IMyTextSurface result = Me.GetSurface(0); string blockName = fields[0]; int surfaceIdx = 0; if (fields.Length > 2) { Echo($"{warnPrefix}Awaiting maximum 2 fields, but got {fields.Length}. Ignoring unnecessary fields."); } if (fields.Length > 1) { try { surfaceIdx = (int)ParseFloat(fields[1], $"Value of field #2 (display-nr) is not a number: {fields[1]}"); } catch (Exception ex) { Echo($"{warnPrefix}{ex.Message}. Using display-nr {surfaceIdx}."); } } IMyEntity ent = GridTerminalSystem.GetBlockWithName(blockName) as IMyEntity; if (ent == null) { Echo($"{warnPrefix}'{blockName}' not found on this grid. Using programmable block for output."); } else if (ent is IMyTextSurfaceProvider) { IMyTextSurfaceProvider provider = (IMyTextSurfaceProvider)ent; if (surfaceIdx >= provider.SurfaceCount) { Echo($"{warnPrefix}You provided a display-nr {surfaceIdx} which '{blockName}' doesn't have (max. {provider.SurfaceCount - 1}). Using display-nr 0 instead."); surfaceIdx = 0; } result = provider.GetSurface(surfaceIdx); } else if (ent is IMyTextSurface) { if (fields.Length == 2) { Echo($"{warnPrefix}You provided a display-nr, but '{blockName}' is not providing multiple displays. Ignoring display-nr."); } result = (IMyTextSurface)ent; } else { Echo($"{warnPrefix}'{blockName}' is not valid. Using programmable block for output."); } return(result); }
/// <summary> /// Clears specified surface if it exists. /// </summary> /// <param name="block">Block that provides the surface</param> /// <param name="surf">Surface ID</param> public void ClearScreen(IMyTextSurfaceProvider block, int surf) { if (surf >= block.SurfaceCount) { Owner.Log($"Surface #{surf} does not exist on '{(block as IMyTerminalBlock).CustomName}'"); } else { ClearScreen(block.GetSurface(surf)); } }
public static void ForEachSurface(this IMyTextSurfaceProvider surfaceProvider, Action <IMyTextSurface, Int32> action) { var surfaces = surfaceProvider.SurfaceCount; var i = 0; while (i < surfaces) { action(surfaceProvider.GetSurface(i), i); i++; } }
public DisplayGroup(IMyTextSurfaceProvider textSurfaceProvider) : base(null) { if (textSurfaceProvider == null) { throw new ArgumentNullException(nameof(textSurfaceProvider)); } for (int i = 0; i < textSurfaceProvider.SurfaceCount; i++) { new Display(textSurfaceProvider.GetSurface(i), this); } }
public Program() { IMyTerminalBlock block; if (string.IsNullOrWhiteSpace(lcdName)) { block = Me; } else { block = GridTerminalSystem.GetBlockWithName(lcdName); if (block == null) { throw new Exception("Unable to find lcd."); } } if (block is IMyTextSurface) { canvas = (IMyTextSurface)block; } else if (block is IMyTextSurfaceProvider) { IMyTextSurfaceProvider temp = (IMyTextSurfaceProvider)block; lcdIndex = Math.Max(temp.SurfaceCount - 1, lcdIndex); canvas = temp.GetSurface(lcdIndex); } else { throw new Exception("Unable to find lcd."); } if (string.IsNullOrWhiteSpace(projectorName)) { List <IMyTerminalBlock> temp = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyProjector>(temp, (b) => temp.Count <= 1); projector = (IMyProjector)temp.FirstOrDefault(); } else { projector = GridTerminalSystem.GetBlockWithName(projectorName) as IMyProjector; } if (projector == null) { throw new Exception("Unable to find projector."); } spawnProjection = projector.GetActionWithName("BuildGrid"); projectedGridComps = projector.GetProperty("RequiredComponents").As <Dictionary <MyItemType, int> >(); projectedGridTimer = projector.GetProperty("GridTimerProjection").As <int>(); timer = projector.GetProperty("GridTimerCurrent").As <int>(); Runtime.UpdateFrequency = UpdateFrequency.Update10; }
public static RenderTargetID fromSurfaceProvider(IMyTextSurfaceProvider provider, int index) { IMyTerminalBlock block = provider as IMyTerminalBlock; if (block != null) { return(new RenderTargetID(block.BlockDefinition.TypeIdString, block.BlockDefinition.SubtypeId, index)); } return(Invalid); }
private void LogLine(string msg, bool broadcast = true) { IMyTextSurfaceProvider prov = Me; var disp = Me.GetSurface(0); disp.ContentType = ContentType.TEXT_AND_IMAGE; disp.WriteText(msg + Environment.NewLine, true); Echo(msg + Environment.NewLine); if (this.msgHandler != null && broadcast) { // TODO: this belongs to a MessageSender class(maybe) IGC.SendBroadcastMessage(this.tag, $"[{uuid}] {msg}"); } }
private IMyTextSurface getDisplay(string argument, string command) { int position = argument.IndexOf(command); string displayName = argument.Substring(position + command.Length); this.displayName = displayName; int displayIndex = 0; if (displayName.Contains(',')) { displayIndex = int.Parse(displayName.Split(',')[1]); if (displayIndex < 0) { displayIndex = 0; } displayName = displayName.Split(',')[0]; } Echo("set display name to " + displayName); IMyTextSurface display = GridTerminalSystem.GetBlockWithName(displayName) as IMyTextSurface; if (display == null) { Echo("No surface found"); IMyTextSurfaceProvider provider = GridTerminalSystem.GetBlockWithName(displayName) as IMyTextSurfaceProvider; if (provider != null) { Echo("Surface provider found"); Echo("Surface provider has " + provider.SurfaceCount + " displays"); if (provider.SurfaceCount > 0) { int surfaceIndex = provider.SurfaceCount > displayIndex ? displayIndex : 0; Echo("selecting display " + surfaceIndex); display = provider.GetSurface(surfaceIndex); } } else { Echo("No surface provider found"); } } Echo("display init " + (display == null ? "failed" : "succeded")); if (display != null) { display.FontSize = 240 / display.SurfaceSize.Y; //display.TextPadding = 2; } return(display); }
public Program() { Runtime.UpdateFrequency = UpdateFrequency.Update10; Cockpit = GridTerminalSystem.GetBlockWithName("Cockpit") as IMyTextSurfaceProvider; RotorMain = GridTerminalSystem.GetBlockWithName("RotorMain") as IMyMotorStator; RotorL = GridTerminalSystem.GetBlockWithName("RotorL") as IMyMotorStator; RotorR = GridTerminalSystem.GetBlockWithName("RotorR") as IMyMotorStator; AdRotL = GridTerminalSystem.GetBlockWithName("AdRotL") as IMyMotorStator; AdRotR = GridTerminalSystem.GetBlockWithName("AdRotR") as IMyMotorStator; RemoteControl = GridTerminalSystem.GetBlockWithName("Remote") as IMyShipController; GridTerminalSystem.GetBlocksOfType <IMyPistonBase>(PistonsList); dic = Dictionary("rus"); WriteStatusDisplay(); WriteNavigateDisplay(cursor); }
public Program() { // The constructor, called only once every session and // always before any other method is called. Use it to // initialize your script. // // The constructor is optional and can be removed if not // needed. this.block = Me; surface = (IMyTextPanel)GridTerminalSystem.GetBlockWithName("Panel"); sensor = (IMySensorBlock)GridTerminalSystem.GetBlockWithName("Sensor"); cockpit = (IMyCockpit)GridTerminalSystem.GetBlockWithName("Azimuth Open Cockpit"); // set surface contentType // this is selecting type on terminal surface.ContentType = ContentType.SCRIPT; Runtime.UpdateFrequency = UpdateFrequency.Update1; }
public void Initalize() { surfaces_.Clear(); surfaces_.Add(App.Me.GetSurface(0)); // ToDo: Implement a more customizeable version App.GridTerminalSystem.GetBlocksOfType <IMyTextSurfaceProvider>(null, block => { if (block.CustomName.Contains(App.lcdTag_)) { IMyTextSurfaceProvider provider = block as IMyTextSurfaceProvider; surfaces_.Add(provider.GetSurface(0)); } return(false); }); }
public override void ReadConfig() { EnableImmersion = GetValue("EnableImmersion").ToBoolean(EnableImmersion); IMyTextSurfaceProvider surfaceProvider = _block as IMyTextSurfaceProvider; for (int n = 0; n < surfaceProvider.SurfaceCount; n++) { string key = $"Surface{n}"; if (KeyExists(key)) { string screen = GetValue(key).ToString(); SetScreenHandlerForSurface(screen, n); } else if (_screenHandlers.ContainsKey(n)) { ResetScreenHandlerForSurface(n); } } }
private int GetTextSurfaceIndex(IMyTerminalBlock block) { IMyTextSurfaceProvider displayProvider = (IMyTextSurfaceProvider)block; int surfaceIndex = 0; if (displayProvider.SurfaceCount > 1) { string indexRaw = block.CustomData.Split('\n').FirstOrDefault(o => o.StartsWith(SURFACE_INDEX_PREFIX)); if (indexRaw != null) { if (!int.TryParse(indexRaw.Substring(SURFACE_INDEX_PREFIX.Length), out surfaceIndex)) { Echo("Warning: Unable parse display index from '" + indexRaw + "'. First display will be used."); } } } return(surfaceIndex); }
public bool redirectConsole(IMyTextSurfaceProvider provider, int displayId) { if (provider != null && displayId < provider.SurfaceCount && displayId >= 0) { if (renderTarget_ != null) { renderTarget_.releaseSurface(); } renderTarget_ = new RenderTarget(RenderTargetID.fromSurfaceProvider(provider, displayId), new Vector2I(0, 0)); renderTarget_.setupSurface(provider.GetSurface(displayId)); renderTarget_.BackgroundColor = Color.Black; float lineCount = (renderTarget_.Size.Y / (Default.CharHeight * fontSize_)); lineHeight_ = renderTarget_.Size.Y / (int)lineCount; lineCorrection_ = (lineCount - (int)lineCount) * (int)(lineCount + 1); return(true); } return(false); }
private IMyTextSurface FindTextSurface() { string monitorName = _ini.Get("config", "monitor").ToString(); IMyTextSurface display = null; if (monitorName != "") { display = GridTerminalSystem.GetBlockWithName(monitorName) as IMyTextSurface; if (display == null) { Echo(string.Format("Display '{0}' missing", monitorName)); } else { Echo(string.Format("Display '{0}' found", monitorName)); } } else { string cockpitName = _ini.Get("config", "cockpit").ToString(); if (cockpitName != "") { int surfaceNumber = _ini.Get("config", "surface").ToInt32(0); IMyTextSurfaceProvider cockpit = GridTerminalSystem.GetBlockWithName(cockpitName) as IMyTextSurfaceProvider; if (cockpit != null) { display = cockpit.GetSurface(surfaceNumber); } if (cockpitName == null) { Echo(string.Format("Display '{0}' of '{1}' missing", surfaceNumber, cockpitName)); } else { Echo(string.Format("Display '{0}' of '{1}' found", surfaceNumber, cockpitName)); } } } return(display); }
public static IMyTextSurface GetScreen(IMyGridTerminalSystem gridTerminalSystem, IMyProgrammableBlock Me, LCDConfigItem config) { List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); gridTerminalSystem.SearchBlocksOfName(config.BlockName, blocks, b => b.IsSameConstructAs(Me)); if (blocks.Count == 0) { throw new Exception($"No blocks with name \"{config.BlockName}\" found"); } if (blocks.Count > 1) { throw new Exception($"Multiple blocks with name \"{config.BlockName}\" found"); } if (config.IsProvider) { IMyTextSurfaceProvider surfaceProvider = blocks[0] as IMyTextSurfaceProvider; return(surfaceProvider.GetSurface(config.ProviderScreenIndex)); } else { return(blocks[0] as IMyTextSurface); } }