/// <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> /// Immediately redraws all screens that have windows belonging to the given output provider.<para/> /// Warning: not only this provider's windows will be redrawn! /// </summary> /// <param name="job"></param> public void ForceUpdateFor(IHasOutput job) { foreach (var kv in Screens) { if (kv.Value.Any((w) => ReferenceEquals(w.Job, job))) { UpdateScreen(kv.Key, kv.Value); } } }
public static IHasOutput SetOutputs(this IHasOutput outputNode, params OutputHook[] outputs) { if (outputNode.OutputHooks != null) { throw new InvalidOperationException("Output has already been set!"); } outputNode.OutputHooks = outputs; (outputNode as Node).AddHooks(outputs); return(outputNode); }
/// <summary>Removes all windows that belong to a specific output provider.</summary> /// <param name="job"></param> public void RemoveWindowsFor(IHasOutput job) { var keys = Screens.Keys.ToArray(); foreach (var key in keys) { var ws = Screens[key]; ws.RemoveAll((w) => ReferenceEquals(job, w.Job)); if (ws.Count == 0) { ClearScreen(key); } } }
public void SetRightSide(IHasOutput rightSide) { if (_rightSide != null) { // ToDO: create custom error throw new ArgumentException("Cannot set right side multiple times"); } if (_rightSideType != rightSide.OutputType()) { // TODO: use custom error instead of this throw new ArgumentException("Incompatible output types"); } _rightSide = rightSide; }
/// <summary>Constructor - only to be used by screen manager.</summary> public Window(WindowLocation loc, IMyTextSurface surface, object data, IHasOutput job) { Location = loc; Surface = surface; Data = data; Job = job; }
/// <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 static OutputHook GetOutput(this IHasOutput node, string name) { return(FindHookByName(node.OutputHooks, name) as OutputHook); }
public static void Set(this IHasOutput node, string name, object value) { GetOutput(node, name).Value = value; }
public void Execute(IHasInput input, IHasOutput output) { InternalAction(input, output); }