Пример #1
0
        public void Main(string argument, UpdateType updateSource)
        {
            Dictionary <string, object> inputs = Me.GetProperty("ControlModule.Inputs")?.As <Dictionary <string, object> >()?.GetValue(Me);

            if (inputs != null)
            {
                blocks.Clear();
                foreach (long key in spritesPreviewers.Keys)
                {
                    missingSpritePreviewers.Add(key);
                }
                GridTerminalSystem.GetBlocks(blocks);
                foreach (IMyTerminalBlock block in blocks)
                {
                    if (block is IMyTextPanel)
                    {
                        IMyTextPanel text_panel = (IMyTextPanel)block;
                        if (text_panel.CustomData.Trim() == "previewSprites")
                        {
                            if (!(spritesPreviewers.ContainsKey(text_panel.EntityId)))
                            {
                                List <string> sprites = new List <string>();
                                text_panel.GetSprites(sprites);
                                spritesPreviewers.Add(text_panel.EntityId, new SpritesPreviewer(text_panel, sprites));
                            }
                            missingSpritePreviewers.Remove(text_panel.EntityId);
                        }
                    }
                }
                foreach (long key in missingSpritePreviewers)
                {
                    spritesPreviewers.Remove(key);
                }
                missingSpritePreviewers.Clear();
                foreach (string input in inputs.Keys)
                {
                    if (spritesPreviewersKeyInputActions.ContainsKey(input))
                    {
                        SpritesPreviewerKeyInputActionDelegate sprites_previewers_key_input_action = spritesPreviewersKeyInputActions[input];
                        foreach (SpritesPreviewer sprite_previewer in spritesPreviewers.Values)
                        {
                            sprites_previewers_key_input_action(sprite_previewer);
                        }
                    }
                }
                foreach (SpritesPreviewer sprite_previewer in spritesPreviewers.Values)
                {
                    string selected_sprite = sprite_previewer.SelectedSprite;
                    if (selected_sprite != null)
                    {
                        sprite_previewer.TextPanel.ContentType = ContentType.SCRIPT;
                        using (MySpriteDrawFrame sprite_draw_frame = sprite_previewer.TextPanel.DrawFrame())
                        {
                            sprite_draw_frame.Add(MySprite.CreateSprite(selected_sprite, sprite_previewer.TextPanel.SurfaceSize * 0.5f, sprite_previewer.TextPanel.SurfaceSize * sprite_previewer.ZoomFactor));
                            sprite_draw_frame.Add(MySprite.CreateText(selected_sprite, "DEBUG", Color.White, 1.0f, TextAlignment.CENTER));
                        }
                    }
                }
            }
        }
        public static void DrawScaledSpriteText(this IMyTextSurface textSurface, StringBuilder text, String fontId, Color color, Single?scale = null, TextAlignment textAlignment = TextAlignment.CENTER)
        {
            textSurface.Script      = "";
            textSurface.ContentType = ContentType.SCRIPT;

            using (var frame = textSurface.DrawFrame())
            {
                var fillArea = textSurface.TextureSize - new Vector2(textSurface.TextPadding * 2);

                if (scale == null)
                {
                    var tryScale    = 10f;
                    var currentSize = textSurface.MeasureStringInPixels(text, fontId, tryScale);

                    while (currentSize.X > fillArea.X || currentSize.Y > fillArea.Y)
                    {
                        tryScale   *= 0.9f;
                        currentSize = textSurface.MeasureStringInPixels(text, fontId, tryScale);
                    }

                    scale = tryScale;
                }

                var sprite = MySprite.CreateText(text.ToString(), fontId, color, scale.Value, textAlignment);
                sprite.Position = new Vector2(textSurface.TextPadding, textSurface.TextPadding);
                frame.Add(sprite);
            }
        }
Пример #3
0
            public void flush()
            {
                if (renderTarget_ != null && newMesssages_ == true)
                {
                    float offset    = (messages_.Count * lineHeight_ + lineCorrection_) - (renderTarget_.Size.Y + renderTarget_.Position.Y);
                    int   lineCount = 0;
                    newMesssages_ = false;

                    using (MySpriteDrawFrame frame = renderTarget_.getRenderFrame())
                    {
                        // Workaround to fix the MP Sprite issue
                        if (drawEmpty_)
                        {
                            frame.Add(new MySprite());
                        }
                        drawEmpty_ = !drawEmpty_;

                        // background
                        renderTarget_.clearDrawArea(sprite => frame.Add(sprite));

                        // flush message lines
                        foreach (var message in messages_)
                        {
                            MySprite line = MySprite.CreateText(message.Value, font_, getFontColor(message.Key), fontSize_, TextAlignment.LEFT);
                            line.Position = new Vector2(renderTarget_.Position.X, lineCount++ *lineHeight_ - offset);
                            frame.Add(line);
                        }
                    }
                }
            }
Пример #4
0
        public void DrawSprites(ref MySpriteDrawFrame frame, RectangleF _viewport)
        {
            var background = MySprite.CreateSprite("SquareSimple", _viewport.Center, _viewport.Size);

            background.Color = new Color(26, 28, 32);
            frame.Add(background);

            Vector2 ocSize      = percentageSize(80, _viewport);
            var     outerCircle = MySprite.CreateSprite("Circle", _viewport.Center, ocSize);

            outerCircle.Color = new Color(29, 229, 128);
            frame.Add(outerCircle);

            Vector2 icSize      = percentageSize(60, _viewport);
            var     innerCircle = MySprite.CreateSprite("Circle", _viewport.Center, icSize);

            innerCircle.Color = new Color(37, 39, 45);
            frame.Add(innerCircle);

            float size         = TextSize(40, _viewport);
            float offset       = TextSizeOffset(size);
            var   platformCode = MySprite.CreateText("01", "White", Color.White, size, TextAlignment.CENTER);
            // Vector2 pcPos = new Vector2(_viewport.Center.X, _viewport.Center.Y - 100);
            Vector2 pcPos = new Vector2(_viewport.Size.X / 2, _viewport.Size.Y / 2 - offset) + _viewport.Position;

            platformCode.Position = pcPos;
            frame.Add(platformCode);
        }
            private void DrawProduction(List <MySprite> productionSpriteList, float screenOffset)
            {
                Vector2 b_pos      = new Vector2(130.5f + screenOffset, 130);
                Vector2 b_size     = new Vector2(241, 124);
                var     background = MySprite.CreateSprite("SquareSimple", b_pos, b_size);

                background.Color = Constants.COLOR_BACKGROUND_MASK;

                Vector2 h_pos  = new Vector2(130.5f + screenOffset, 78);
                Vector2 h_size = new Vector2(241, 20);
                var     header = MySprite.CreateSprite("SquareSimple", h_pos, h_size);

                header.Color = Constants.COLOR_GREEN;

                var headerText = MySprite.CreateText("PRODUCTION INFO", "White", Constants.COLOR_WHITE, 0.6f, TextAlignment.LEFT);

                headerText.Position = new Vector2(20 + screenOffset, 69);

                Vector2 gb_pos  = new Vector2(130.5f + screenOffset, 116.5f);
                Vector2 gb_size = new Vector2(221, 37);
                var     generatorsBackground = MySprite.CreateSprite("SquareSimple", gb_pos, gb_size);

                generatorsBackground.Color = Constants.COLOR_BACKGROUND_LIGHT;

                Vector2 ofb_pos              = new Vector2(130.5f + screenOffset, 163.5f);
                Vector2 ofb_size             = new Vector2(221, 37);
                var     oxygenFarmBackground = MySprite.CreateSprite("SquareSimple", ofb_pos, ofb_size);

                oxygenFarmBackground.Color = Constants.COLOR_BACKGROUND_LIGHT;

                Vector2 gs_pos           = new Vector2(30 + screenOffset, 116.5f);
                Vector2 gs_size          = new Vector2(20, 37);
                var     generatorsSwitch = MySprite.CreateSprite("SquareSimple", gs_pos, gs_size);

                generatorsSwitch.Color = myProgram.productionController.LifeSupportInfo.IsGeneratorsWorking ? Constants.COLOR_GREEN : Constants.COLOR_RED;

                Vector2 ofs_pos          = new Vector2(30 + screenOffset, 163.5f);
                Vector2 ofs_size         = new Vector2(20, 37);
                var     oxygenFarmSwitch = MySprite.CreateSprite("SquareSimple", ofs_pos, ofs_size);

                oxygenFarmSwitch.Color = myProgram.productionController.LifeSupportInfo.IsOxygenFarmWorking ? Constants.COLOR_GREEN : Constants.COLOR_RED;

                var generatorsSwitchText = MySprite.CreateText($"H2/O2 GENERATORS\n{myProgram.productionController.WorkingGenerators}", "White", Constants.COLOR_WHITE, 0.6f, TextAlignment.LEFT);

                generatorsSwitchText.Position = new Vector2(47 + screenOffset, 98.5f);

                var oxygenFarmSwitchText = MySprite.CreateText($"OXYGEN FARMS\n{myProgram.productionController.WorkingOxygenFarms}", "White", Constants.COLOR_WHITE, 0.6f, TextAlignment.LEFT);

                oxygenFarmSwitchText.Position = new Vector2(47 + screenOffset, 145.5f);

                productionSpriteList.Add(background);
                productionSpriteList.Add(header);
                productionSpriteList.Add(headerText);
                productionSpriteList.Add(generatorsBackground);
                productionSpriteList.Add(oxygenFarmBackground);
                productionSpriteList.Add(generatorsSwitch);
                productionSpriteList.Add(oxygenFarmSwitch);
                productionSpriteList.Add(generatorsSwitchText);
                productionSpriteList.Add(oxygenFarmSwitchText);
            }
Пример #6
0
            public void DrawString(Vector2 position, string value, string font, Color c, TextAlignment alignment = TextAlignment.LEFT, float scale = 1)
            {
                MySprite s = MySprite.CreateText(value, font, c, scale, alignment);

                s.Position = position;
                AddObject(s);
            }
Пример #7
0
                /// <summary>Draws some text on the frame</summary>
                /// <param name="text">Text to draw</param>
                /// <param name="position">Where to draw the text, in conjunction with <paramref name="alignment"/>. Affected by the display's scale</param>
                /// <param name="color">Color of the text, by default it will be the <see cref="d"/>'s <see cref="ColorScheme.Light"/> color</param>
                /// <param name="scale">Scale of the text. Compounded with the display's scale</param>
                /// <param name="alignment">Alignment</param>
                public void DrawText(string text, Vector2 position, Color?color = null, float scale = 1, TextAlignment alignment = TextAlignment.CENTER)
                {
                    var sprite = MySprite.CreateText(text, "Monospace", color ?? this.d.scheme.Light, scale * this.d.scale, alignment);

                    sprite.Position = (position * this.d.scale) + this.d.offset;
                    this.f.Add(sprite);
                }
Пример #8
0
            public static void DrawText(Vector2 position, Color color, string text, float fontSize = 1.0f, TextAlignment textAlignment = TextAlignment.CENTER)
            {
                MySprite sprite;

                sprite          = MySprite.CreateText(text, paint.Font, color, fontSize, textAlignment);
                sprite.Position = position + paint.Offset;
                frame.Add(sprite);
            }
Пример #9
0
            public static void TextEx(Vector2 position, Color color, string text, float fontSize = 1.0f, TextAlignment textAlignment = TextAlignment.CENTER)
            {
                MySprite sprite;

                sprite          = MySprite.CreateText(text, _surface.Font, color, fontSize, textAlignment);
                sprite.Position = position + _offset;
                _frame.Add(sprite);
            }
            private void DrawOxygenInfo(Airlock airlock, List <MySprite> oxygenInfoSpriteList)
            {
                Vector2 orl_pos       = new Vector2(112.5f, 390);
                Vector2 orl_size      = new Vector2(205, 30);
                var     outerRectLeft = MySprite.CreateSprite("SquareSimple", orl_pos, orl_size);

                outerRectLeft.Color = Constants.COLOR_WHITE;

                Vector2 orlm_pos          = new Vector2(112.5f, 390);
                Vector2 orlm_size         = new Vector2(201, 26);
                var     outerRectLeftMask = MySprite.CreateSprite("SquareSimple", orlm_pos, orlm_size);

                outerRectLeftMask.Color = Constants.COLOR_BACKGROUND;

                Vector2 bfl_pos     = new Vector2(112.5f, 390);
                Vector2 bfl_size    = new Vector2((197 * float.Parse(airlock.OxygenLevelDecimals)), 22);
                var     barFillLeft = MySprite.CreateSprite("SquareSimple", bfl_pos, bfl_size);

                barFillLeft.Color = Constants.COLOR_WHITE;

                var oxigenText = MySprite.CreateText("AIRLOCK OXYGEN", "Debug", Constants.COLOR_WHITE, 0.5f, TextAlignment.CENTER);

                oxigenText.Position = new Vector2(112.5f, 410);

                Vector2 orr_pos        = new Vector2(399.5f, 390);
                Vector2 orr_size       = new Vector2(205, 30);
                var     outerRectRight = MySprite.CreateSprite("SquareSimple", orr_pos, orr_size);

                outerRectRight.Color = Constants.COLOR_WHITE;

                Vector2 orrm_pos           = new Vector2(399.5f, 390);
                Vector2 orrm_size          = new Vector2(201, 26);
                var     outerRectRightMask = MySprite.CreateSprite("SquareSimple", orrm_pos, orrm_size);

                outerRectRightMask.Color = Constants.COLOR_BACKGROUND;

                Vector2 bfr_pos      = new Vector2(399.5f, 390);
                Vector2 bfr_size     = new Vector2((197 * float.Parse(airlock.OxygenTankFillDecimals)), 22);
                var     barFillRight = MySprite.CreateSprite("SquareSimple", bfr_pos, bfr_size);

                barFillRight.Color = Constants.COLOR_WHITE;

                var tankText = MySprite.CreateText("02 TANKS STORAGE", "Debug", Constants.COLOR_WHITE, 0.5f, TextAlignment.CENTER);

                tankText.Position = new Vector2(399.5f, 410);

                oxygenInfoSpriteList.Add(outerRectLeft);
                oxygenInfoSpriteList.Add(outerRectLeftMask);
                oxygenInfoSpriteList.Add(barFillLeft);
                oxygenInfoSpriteList.Add(oxigenText);

                oxygenInfoSpriteList.Add(outerRectRight);
                oxygenInfoSpriteList.Add(outerRectRightMask);
                oxygenInfoSpriteList.Add(barFillRight);
                oxygenInfoSpriteList.Add(tankText);
            }
Пример #11
0
 public Label(string text, string font, Color fontColor, float fontSize, TextAlignment alignment, Vector2 position, IUIControl parent) : base(parent)
 {
     labelSprite          = MySprite.CreateText(text, font, fontColor, fontSize, alignment);
     base.Text            = text;
     base.Font            = font;
     base.ForegroundColor = fontColor;
     base.FontSize        = fontSize;
     Alignment            = alignment;
     Position             = position;
 }
Пример #12
0
            protected static void renderTextLine(Display display, RenderTarget rt, AddSpriteDelegate addSprite,
                                                 string font, float fontSize, Vector2 position, Color fontColor, string textLine, TextAlignment alignment)
            {
                // fix font position
                Vector2  offset = new Vector2(rt.DisplayOffset.X, rt.DisplayOffset.Y - (0.61f * (fontSize * Default.CharHeight)));
                MySprite sprite = MySprite.CreateText(textLine, font, fontColor, fontSize, alignment);

                sprite.Position = position + offset;
                addSprite(sprite);
            }
        MySprite AddTextSprite(string text, Vector2 position, int fontSize = 1, string font = "Debug", Color?color = null)
        {
            var sprite = MySprite.CreateText(text, font, color == null ? Color.White : color.Value, fontSize);

            sprite.Size     = MeasureSize(text, fontSize, font);
            position.Y     += sprite.Size.Value.Y * 0.5f / PixelsPerMeter;
            sprite.Position = position;
            SpriteScratchpad.Add(sprite);
            return(sprite);
        }
Пример #14
0
        private void drawText(List <MySpriteDrawFrame> li, float x, float y, string s, Color?c = null)
        {
            MySprite text = MySprite.CreateText(s, "monospace", c != null && c.HasValue ? c.Value : Color.White, lineSize / 24F);

            text.Alignment = TextAlignment.LEFT;
            text.Position  = new Vector2(x, y);
            foreach (MySpriteDrawFrame frame in li)
            {
                frame.Add(text);
            }
        }
Пример #15
0
            void drawInitScreen()
            {
                using (MySpriteDrawFrame frame = getRenderFrame())
                {
                    MySprite textInit = MySprite.CreateText("Initilize screen", "debug", Color.LawnGreen, 1f, TextAlignment.LEFT);
                    textInit.Position = new Vector2(5f, Default.CharHeight) + Position;

                    clearDrawArea(sprite => frame.Add(sprite));
                    frame.Add(textInit);
                }
            }
Пример #16
0
            public void TextBox(BoxStyle style, string text)
            {
                if (style.SizeRule == SizeRule.Auto)
                {
                    style = new BoxStyle(style)
                    {
                        Size = CalcStringSize(text, FontId, FontScale)
                    };
                }

                Vector2       size  = style.Size * Scale;
                TextAlignment align = style.Align;
                MySprite      sprite;
                BoundingBox2  box       = new BoundingBox2(Cursor, Cursor + size);
                Vector2       innerSize = style.InnerSize * Scale;

                float textScale;

                if (size.Y != 0)
                {
                    textScale = innerSize.Y / size.Y;
                }
                else
                {
                    textScale = 0;
                }

                Vector2 textPos = new Vector2(box.Center.X, box.Center.Y - innerSize.Y / 2.0f);

                if (align == TextAlignment.LEFT)
                {
                    textPos.X -= innerSize.X / 2.0f;
                }
                else if (align == TextAlignment.RIGHT)
                {
                    textPos.X += innerSize.X / 2.0f;
                }

                if (Sprites != null)
                {
                    //sprite = MySprite.CreateSprite(SpriteId.SquareSimple, box.Center, box.Size);
                    //sprite.Color = BGColor;
                    //Sprites.Add(sprite);

                    sprite          = MySprite.CreateText(text, FontId, Color, textScale * FontScale * Scale, align);
                    sprite.Position = textPos;
                    Sprites.Add(sprite);
                }

                MoveCursor(box.Width);
                MergeBox(box);
            }
Пример #17
0
        public void Main()           //called each cycle
        {
            List <MySpriteDrawFrame> li = new List <MySpriteDrawFrame>();

            foreach (IMyTextPanel scr in screens)
            {
                li.Add(prepareScreen(scr));
            }

            float x = edgePadding;

            foreach (string gas in systems.Keys)
            {
                float tankFrac = 0;
                float compFrac = 0;
                int   flowDir  = 0;
                systems[gas].handleTanks(out tankFrac, out compFrac, out flowDir);

                foreach (MySpriteDrawFrame frame in li)
                {
                    addBarToScreen(frame, tankFrac, x);
                    addBarToScreen(frame, compFrac, x + barGap + barSizeBorder.X);
                    Vector2 flowPos = new Vector2(x + barSizeBorder.X + barGap / 2, 256);
                    switch (flowDir)
                    {
                    case -1:
                        frame.Add(new MySprite(SpriteType.TEXTURE, "Triangle", size: flowBox, color: WHITE, position: flowPos, rotation: -1.57F));                                 //radians
                        break;

                    case 1:
                        frame.Add(new MySprite(SpriteType.TEXTURE, "Triangle", size: flowBox, color: WHITE, position: flowPos, rotation: 1.57F));
                        break;

                    case 0:
                        frame.Add(new MySprite(SpriteType.TEXTURE, "SquareSimple", size: flowBox, color: WHITE, position: flowPos));
                        break;
                    }
                    MySprite text = MySprite.CreateText(gas, "monospace", WHITE, 3);
                    text.Position = new Vector2(flowPos.X, flowPos.Y + 96);
                    frame.Add(text);
                }
                x += groupGap + barGap + barSizeBorder.X * 2;
            }

            foreach (MySpriteDrawFrame frame in li)
            {
                frame.Dispose();
            }
        }
            private void DrawFooter(Airlock airlock, List <MySprite> footerSpriteList)
            {
                Vector2 fb_pos    = new Vector2(256, 457.5f);
                Vector2 fb_size   = new Vector2(492, 5);
                var     footerBar = MySprite.CreateSprite("SquareSimple", fb_pos, fb_size);

                footerBar.Color = Constants.COLOR_ORANGE;

                var airlockNameText = MySprite.CreateText(airlock.Name, "Debug", Constants.COLOR_ORANGE, 1.5f, TextAlignment.CENTER);

                airlockNameText.Position = new Vector2(256, 462f);

                footerSpriteList.Add(footerBar);
                footerSpriteList.Add(airlockNameText);
            }
Пример #19
0
            private void DrawFooter(int count, List <MySprite> footerSpriteList, int page)
            {
                Vector2  pf_pos    = new Vector2(256, 405);
                Vector2  pf_size   = new Vector2(492, 30);
                MySprite pageFrame = MySprite.CreateSprite("SquareSimple", pf_pos, pf_size);

                pageFrame.Color = Constants.COLOR_BACKGROUND_MASK;

                int numPages = 1;

                if (count % 10 == 0)
                {
                    numPages = count / 10;
                }
                else
                {
                    numPages = count / 10 + 1;
                }
                MySprite pageNumber = MySprite.CreateText($"Page {page} of {numPages}", "Debug", Constants.COLOR_WHITE, 0.8f, TextAlignment.CENTER);

                pageNumber.Position = new Vector2(256, 392);

                Vector2  ff_pos      = new Vector2(256, 466);
                Vector2  ff_size     = new Vector2(492, 72);
                MySprite footerFrame = MySprite.CreateSprite("SquareSimple", ff_pos, ff_size);
                string   statusText  = "";

                if (myProgram.isLeakManagementOn)
                {
                    footerFrame.Color = Constants.COLOR_GREEN;
                    statusText        = "ON";
                }
                else
                {
                    footerFrame.Color = Constants.COLOR_RED;
                    statusText        = "OFF";
                }

                MySprite leakStatus = MySprite.CreateText($"Leak Prevention: {statusText}", "Debug", Constants.COLOR_WHITE, 1.5f, TextAlignment.CENTER);

                leakStatus.Position = new Vector2(256, 442);

                footerSpriteList.Add(pageFrame);
                footerSpriteList.Add(pageNumber);
                footerSpriteList.Add(footerFrame);
                footerSpriteList.Add(leakStatus);
            }
Пример #20
0
            private void DrawScreenDebug(Platform platform)
            {
                foreach (IMyTextSurfaceProvider surfaceProvider in platform.Surfaces)
                {
                    IMyTextSurface surface = surfaceProvider.GetSurface(0);
                    surface.ContentType = ContentType.SCRIPT;
                    RectangleF _viewport = new RectangleF((surface.TextureSize - surface.SurfaceSize) / 2f, surface.SurfaceSize);
                    using (var frame = surface.DrawFrame()) {
                        var background = MySprite.CreateSprite("SquareSimple", _viewport.Center, _viewport.Size);
                        background.Color = Constants.COLOR_BACKGROUND;
                        frame.Add(background);

                        Vector2 ocSize      = percentageSize(80, _viewport);
                        var     outerCircle = MySprite.CreateSprite("Circle", _viewport.Center, ocSize);
                        if (platform.Status.Equals(Platform.PlatformStatus.Clear))
                        {
                            outerCircle.Color = Constants.COLOR_WHITE;
                        }
                        else if (platform.Status.Equals(Platform.PlatformStatus.Requested))
                        {
                            outerCircle.Color = Constants.COLOR_GREEN;
                        }
                        else if (platform.Status.Equals(Platform.PlatformStatus.Obstructed))
                        {
                            outerCircle.Color = Constants.COLOR_YELLOW;
                        }
                        else if (platform.Status.Equals(Platform.PlatformStatus.Occupied))
                        {
                            outerCircle.Color = Constants.COLOR_RED;
                        }
                        frame.Add(outerCircle);

                        Vector2 icSize      = percentageSize(60, _viewport);
                        var     innerCircle = MySprite.CreateSprite("Circle", _viewport.Center, icSize);
                        innerCircle.Color = Constants.COLOR_BACKGROUND_MASK;
                        frame.Add(innerCircle);

                        float   size         = TextSize(40, _viewport);
                        float   offset       = TextSizeOffset(size);
                        var     platformCode = MySprite.CreateText($"{platform.Code}", "White", Color.White, size, TextAlignment.CENTER);
                        Vector2 pcPos        = new Vector2(_viewport.Size.X / 2, _viewport.Size.Y / 2 - offset) + _viewport.Position;
                        platformCode.Position = pcPos;
                        frame.Add(platformCode);
                    }
                }
            }
            private void DrawHeader(List <MySprite> headerSpriteList, float screenOffset)
            {
                Color color = (myProgram.isProductionOn) ? Constants.COLOR_GREEN : Constants.COLOR_RED;

                Vector2 b_pos      = new Vector2(256 + screenOffset, 34);
                Vector2 b_size     = new Vector2(492, 48);
                var     background = MySprite.CreateSprite("SquareSimple", b_pos, b_size);

                background.Color = color;

                string text       = (myProgram.isProductionOn) ? "ON" : "OFF";
                var    headerText = MySprite.CreateText($"AUTO O2 PRODUCTION: {text}", "White", Constants.COLOR_WHITE, 1.5f, TextAlignment.CENTER);

                headerText.Position = new Vector2(256 + screenOffset, 10);


                headerSpriteList.Add(background);
                headerSpriteList.Add(headerText);
            }
Пример #22
0
        public override void Run()
        {
            base.Run(); // do not remove

            using (var frame = Surface.DrawFrame())
            {
                Vector2 screenSize   = Surface.SurfaceSize;
                Vector2 screenCorner = (Surface.TextureSize - screenSize) * 0.5f;

                // Drawing sprites works exactly like in PB API.
                // Therefore this guide applies: https://github.com/malware-dev/MDK-SE/wiki/Text-Panels-and-Drawing-Sprites

                var text = MySprite.CreateText("Hi!", "Monospace", Surface.ScriptForegroundColor, 1f, TextAlignment.LEFT);
                text.Position = screenCorner + new Vector2(16, 16); // 16px from topleft corner of the visible surface
                frame.Add(text);

                // add more sprites and stuff
            }
        }
            private void DrawPressureInfo(Airlock airlock, List <MySprite> pressureInfoSpriteList)
            {
                Color contrastColor = new Color();

                if (airlock.RoomPressure.Equals("High Pressure"))
                {
                    contrastColor = Constants.COLOR_GREEN;
                }
                else if (airlock.RoomPressure.Equals("Low Pressure"))
                {
                    contrastColor = Constants.COLOR_YELLOW;
                }
                else
                {
                    contrastColor = Constants.COLOR_RED;
                }

                Vector2 oc_pos      = new Vector2(256, 150);
                Vector2 oc_size     = new Vector2(240, 240);
                var     outerCircle = MySprite.CreateSprite("Circle", oc_pos, oc_size);

                outerCircle.Color = contrastColor;

                Vector2 ocm_pos         = new Vector2(256, 150);
                Vector2 ocm_size        = new Vector2(230, 230);
                var     outerCircleMask = MySprite.CreateSprite("Circle", ocm_pos, ocm_size);

                outerCircleMask.Color = Constants.COLOR_BACKGROUND_MASK;

                var pressureText = MySprite.CreateText(airlock.OxygenLevel, "Debug", Constants.COLOR_WHITE, 4f, TextAlignment.CENTER);

                pressureText.Position = new Vector2(256, 90);

                var barText = MySprite.CreateText("BAR", "Debug", contrastColor, 1f, TextAlignment.CENTER);

                barText.Position = new Vector2(256, 200);

                pressureInfoSpriteList.Add(outerCircle);
                pressureInfoSpriteList.Add(outerCircleMask);
                pressureInfoSpriteList.Add(pressureText);
                pressureInfoSpriteList.Add(barText);
            }
Пример #24
0
            private void setScreenContent(IMyTextPanel scr, float f)
            {
                scr.ContentType = ContentType.SCRIPT;
                MySpriteDrawFrame frame = scr.DrawFrame();

                frame.Add(new MySprite(SpriteType.TEXTURE, "SquareSimple", size: screenSize, color: BLACK));
                frame.Add(new MySprite(SpriteType.TEXTURE, "SquareSimple", size: barSize1, color: GRAY1));
                frame.Add(new MySprite(SpriteType.TEXTURE, "SquareSimple", size: barSize2, color: GRAY2));

                drawBox(frame, f, BLUE_COLOR, 1);
                drawBox(frame, f, GREEN_COLOR, BLUE_THRESH);
                drawBox(frame, f, YELLOW_COLOR, GREEN_THRESH);
                drawBox(frame, f, ORANGE_COLOR, YELLOW_THRESH);
                drawBox(frame, f, RED_COLOR, ORANGE_THRESH);
                drawBox(frame, f, DARKRED_COLOR, RED_THRESH);

                frame.Add(MySprite.CreateText(String.Format("{0:0.000}", (f * 100)) + "%", "monospace", WHITE, 3));

                frame.Dispose();
            }
Пример #25
0
        public MeterText(SurfaceMath sm, MeterDefinition def, Dictionary <Data, IData> shipData)
        {
            sm.PostionInterpreter(def);
            this.def      = def;
            this.shipData = shipData;

            if (def.min == 0 && def.max == 0)
            {
                UseDataMinMax = true;
            }
            else
            {
                total = def.max - def.min;
            }

            if (def.size.X == 0)
            {
                def.size.X = 1;
            }

            def.position   += sm.Center;
            def.position.Y -= sm.TextHeight(def.size.X) * 0.5f;

            sprite          = MySprite.CreateText(def.textData, "Debug", def.color, def.size.X);
            sprite.Position = def.position;
            switch (def.anchor)
            {
            case Anchor.Left:
                sprite.Alignment = TextAlignment.LEFT;
                break;

            case Anchor.Right:
                sprite.Alignment = TextAlignment.RIGHT;
                break;

            case Anchor.Center:
            default:
                sprite.Alignment = TextAlignment.CENTER;
                break;
            }
        }
Пример #26
0
            public override void render(Display display, RenderTarget rt, AddSpriteDelegate addSprite)
            {
                // render info text
                string text      = "Size=" + rt.Size.X.ToString("0000.00") + ";" + rt.Size.Y.ToString("0000.00");
                var    fontSize  = display.measureLineInPixels(text, "debug", 1f);
                float  fontScale = Math.Min((rt.Size.X * 0.8f) / fontSize.X, (rt.Size.Y * 0.8f) / fontSize.Y);

                var font = MySprite.CreateText(text, "debug", Color.White, fontScale);

                font.Position = new Vector2(rt.Size.X * 0.5f, fontSize.Y * fontScale + 10.0f) + rt.DisplayOffset;
                addSprite(font);

                // render edges
                Vector2 blockSize = new Vector2(20f, 20f);

                addSprite(new MySprite(SpriteType.TEXTURE, IconNameSquareSimple, (rt.Size / 2f) + rt.DisplayOffset, blockSize, Color.White));
                addSprite(new MySprite(SpriteType.TEXTURE, IconNameSquareSimple, (blockSize / 2f) + rt.DisplayOffset, blockSize, Color.Red));
                addSprite(new MySprite(SpriteType.TEXTURE, IconNameSquareSimple, new Vector2(rt.Size.X - blockSize.X / 2f, blockSize.Y / 2f) + rt.DisplayOffset, blockSize, Color.Green));
                addSprite(new MySprite(SpriteType.TEXTURE, IconNameSquareSimple, new Vector2(blockSize.X / 2f, rt.Size.Y - blockSize.Y / 2f) + rt.DisplayOffset, blockSize, Color.Blue));
                addSprite(new MySprite(SpriteType.TEXTURE, IconNameSquareSimple, (rt.Size - (blockSize / 2f)) + rt.DisplayOffset, blockSize, Color.Yellow));
            }
Пример #27
0
        public void Main(string argument, UpdateType updateSource)
        {
            IMyTextSurface surface = GridTerminalSystem.GetBlockWithName("LCD") as IMyTextSurface;

            if (surface != null)
            {
                Echo("Surface panel found");

                surface.ContentType = ContentType.SCRIPT;

                using (var frame = surface.DrawFrame())
                {
                    MySprite test = MySprite.CreateText("Test", "Debug", new Color(1f), 2f, TextAlignment.CENTER);

                    frame.Add(test);
                }
            }
            else
            {
                Echo("No surface panel found");
            }
        }
Пример #28
0
            void DrawMiddleHUD()
            {
                if (Host.ActiveLookingGlass.MiddleHUDs.Count == 0)
                {
                    return;
                }
                SpriteScratchpad.Clear();

                Host.GetDefaultSprites(SpriteScratchpad);

//                Builder.Clear();

                foreach (var screen in Host.ActiveLookingGlass.MiddleHUDs)
                {
                    using (var frame = screen.DrawFrame())
                    {
                        foreach (var spr in SpriteScratchpad)
                        {
                            frame.Add(spr);
                        }

                        if (FeedbackText != string.Empty)
                        {
                            var prompt = MySprite.CreateText(FeedbackText, "Debug", Color.HotPink, 0.9f);
                            prompt.Position = new Vector2(0, -35) + screen.TextureSize / 2f;
                            frame.Add(prompt);
                        }

//                         var HUD = MySprite.CreateText(Builder.ToString(), "Monospace", Color.LightBlue, 0.3f);
//                         HUD.Position = new Vector2(0, -25) + screen.TextureSize / 2f;
//                         frame.Add(HUD);
                    }
                }

                FeedbackText = string.Empty;
                //FeedbackOnTarget = false; // warning CS0414: The field 'Program.LookingGlass_Pascal.FeedbackOnTarget' is assigned but its value is never used
            }
Пример #29
0
        void DrawOutsidePBLcd()
        {
            if (pbSurface == null)
            {
                return;
            }
            using (var frame = pbSurface.DrawFrame())
            {
                Vector2 headerPos = new Vector2(pbSM.Center.X, pbSM.Center.Y - pbSM.Size.Y * 0.333f);

                MySprite sprite;

                sprite          = new MySprite(SpriteType.TEXTURE, "SquareSimple", color: pbSquare);        //This cannot be reused?
                sprite.Size     = new Vector2(pbSM.Size.X, pbSM.Size.Y * 0.333f);
                sprite.Position = headerPos;
                frame.Add(sprite);

                sprite      = new MySprite(SpriteType.TEXTURE, "Grid", color: pbSurface.ScriptForegroundColor);
                sprite.Size = pbSM.BGSize * 2;
                frame.Add(sprite);



                string status   = "";
                string problems = "";
                if (Initialized < 2)
                {
                    status = "Initializing...\nPlease wait.";
                }
                else
                {
                    if (InitProblemBlockNames.Count > 0)
                    {
                        status = "Problem(s) with:";
                        for (int i = 0; i < InitProblemBlockNames.Count; i++)
                        {
                            problems += InitProblemBlockNames[i] + "\n";
                        }
                        pbSurface.ScriptBackgroundColor = problemBG;
                    }
                    else
                    {
                        status = "Running";
                        pbSurface.ScriptBackgroundColor = defaultBG;

                        heartBeatIndex++;
                        sprite          = new MySprite(SpriteType.TEXTURE, "SquareSimple", color: pbSquare);
                        sprite.Size     = Vector2.One * (pbSM.SmallestSize * 0.15f) * heartBeat[heartBeatIndex % heartBeat.Length];
                        sprite.Position = new Vector2(pbSM.Center.X, pbSM.Center.Y + pbSM.Size.Y * 0.165f);
                        frame.Add(sprite);
                    }
                }

                //Add text
                MySprite textSprite;                 //This can be reused after running frame.Add
                textSprite          = MySprite.CreateText("Blargmode's\nFancy Flight Info", "Debug", pbSurface.ScriptForegroundColor, 1f, TextAlignment.CENTER);
                textSprite.Position = new Vector2(headerPos.X, headerPos.Y - pbSM.TextHeight(1, 2) * 0.5f);
                frame.Add(textSprite);

                textSprite          = MySprite.CreateText(status, "Debug", pbSurface.ScriptForegroundColor, 1f, TextAlignment.CENTER);
                textSprite.Position = new Vector2(headerPos.X, headerPos.Y + pbSM.Size.Y * 0.165f);
                frame.Add(textSprite);

                textSprite          = MySprite.CreateText(problems, "Debug", pbSurface.ScriptForegroundColor, 0.7f, TextAlignment.CENTER);
                textSprite.Position = new Vector2(headerPos.X, headerPos.Y + pbSM.Size.Y * 0.165f + pbSM.TextHeight(1, 1));
                frame.Add(textSprite);
            }
        }
            private void DrawDoorButtons(Airlock airlock, List <MySprite> doorButtonSpriteList)
            {
                Color internalColor = new Color(255, 255, 255);
                Color externalColor = new Color(255, 255, 255);

                if (airlock.OpenDoors.Equals("Both"))
                {
                    internalColor = Constants.COLOR_GREEN;
                    externalColor = Constants.COLOR_GREEN;
                }
                else if (airlock.OpenDoors.Equals("Internal"))
                {
                    internalColor = Constants.COLOR_GREEN;
                    externalColor = Constants.COLOR_RED;
                }
                else if (airlock.OpenDoors.Equals("External"))
                {
                    internalColor = Constants.COLOR_RED;
                    externalColor = Constants.COLOR_GREEN;
                }
                else
                {
                    internalColor = Constants.COLOR_RED;
                    externalColor = Constants.COLOR_RED;
                }

                Vector2 ldr_pos      = new Vector2(70, 150);
                Vector2 ldr_size     = new Vector2(60, 60);
                var     leftDoorRect = MySprite.CreateSprite("SquareSimple", ldr_pos, ldr_size);

                leftDoorRect.Color = Constants.COLOR_WHITE;

                Vector2 ldrm_pos         = new Vector2(70, 150);
                Vector2 ldrm_size        = new Vector2(56, 56);
                var     leftDoorRectMask = MySprite.CreateSprite("SquareSimple", ldrm_pos, ldrm_size);

                leftDoorRectMask.Color = Constants.COLOR_BACKGROUND;

                Vector2 lds_pos        = new Vector2(70, 187);
                Vector2 lds_size       = new Vector2(60, 10);
                var     leftDoorSignal = MySprite.CreateSprite("SquareSimple", lds_pos, lds_size);

                leftDoorSignal.Color = internalColor;

                var innerDoorText = MySprite.CreateText("INNER\nDOOR", "Debug", internalColor, 0.6f, TextAlignment.CENTER);

                innerDoorText.Position = new Vector2(70, 133);

                Vector2 rdr_pos       = new Vector2(437, 150);
                Vector2 rdr_size      = new Vector2(60, 60);
                var     rightDoorRect = MySprite.CreateSprite("SquareSimple", rdr_pos, rdr_size);

                rightDoorRect.Color = Constants.COLOR_WHITE;

                Vector2 rdrm_pos          = new Vector2(437, 150);
                Vector2 rdrm_size         = new Vector2(56, 56);
                var     rightDoorRectMask = MySprite.CreateSprite("SquareSimple", rdrm_pos, rdrm_size);

                rightDoorRectMask.Color = Constants.COLOR_BACKGROUND;

                Vector2 rds_pos         = new Vector2(437, 187);
                Vector2 rds_size        = new Vector2(60, 10);
                var     rightDoorSignal = MySprite.CreateSprite("SquareSimple", rds_pos, rds_size);

                rightDoorSignal.Color = externalColor;

                var outerDoorText = MySprite.CreateText("OUTER\nDOOR", "Debug", externalColor, 0.6f, TextAlignment.CENTER);

                outerDoorText.Position = new Vector2(437, 133);

                doorButtonSpriteList.Add(leftDoorRect);
                doorButtonSpriteList.Add(leftDoorRectMask);
                doorButtonSpriteList.Add(leftDoorSignal);
                doorButtonSpriteList.Add(innerDoorText);
                doorButtonSpriteList.Add(rightDoorRect);
                doorButtonSpriteList.Add(rightDoorRectMask);
                doorButtonSpriteList.Add(rightDoorSignal);
                doorButtonSpriteList.Add(outerDoorText);
            }