예제 #1
0
        /// <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));
        }
예제 #2
0
 /// <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);
         }
     }
 }
예제 #3
0
        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);
        }
예제 #4
0
        /// <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);
                }
            }
        }
예제 #5
0
        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;
        }
예제 #6
0
 /// <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;
 }
예제 #7
0
        /// <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);
        }
예제 #8
0
 public static OutputHook GetOutput(this IHasOutput node, string name)
 {
     return(FindHookByName(node.OutputHooks, name) as OutputHook);
 }
예제 #9
0
 public static void Set(this IHasOutput node, string name, object value)
 {
     GetOutput(node, name).Value = value;
 }
예제 #10
0
 public void Execute(IHasInput input, IHasOutput output)
 {
     InternalAction(input, output);
 }