コード例 #1
0
ファイル: Airlock.cs プロジェクト: Helfima/SEIngame
            private void DrawNormalControl(IMyTextPanel block)
            {
                Drawing drawing = new Drawing(block);

                StyleGauge style = new StyleGauge()
                {
                    Orientation     = SpriteOrientation.Vertical,
                    Fullscreen      = false,
                    Width           = 80f,
                    Height          = 200f,
                    Padding         = new StylePadding(5),
                    RotationOrScale = 1f,
                    Percent         = false
                };

                Vector2 position = new Vector2(drawing.viewport.Width / 2 - 100 + style.Padding.X, drawing.viewport.Height / 2 - 50 + style.Padding.Y);

                drawing.AddSprite(new MySprite()
                {
                    Type            = SpriteType.TEXT,
                    Data            = $"Airlock",
                    Color           = Color.DimGray,
                    Position        = position + new Vector2(100f, 0f),
                    RotationOrScale = 2f,
                    Alignment       = TextAlignment.CENTER
                });

                position += new Vector2(0, 60);
                drawing.DrawGauge(position, OxygenRate, 100, style, true);

                string icon = "No Entry";

                if (OxygenRate < 1 - Epsilon)
                {
                    icon = "Danger";
                }
                drawing.AddSprite(new MySprite()
                {
                    Type      = SpriteType.TEXTURE,
                    Data      = $"{icon}",
                    Color     = Color.DimGray,
                    Position  = position + new Vector2(100f, 50f),
                    Size      = new Vector2(100, 100),
                    Alignment = TextAlignment.LEFT
                });

                if (Sleep > 0)
                {
                    drawing.AddSprite(new MySprite()
                    {
                        Type            = SpriteType.TEXT,
                        Data            = $"{Sleep}",
                        Color           = Color.DimGray,
                        Position        = position + new Vector2(150f, 120f),
                        RotationOrScale = 2f,
                        Alignment       = TextAlignment.CENTER
                    });
                }
                drawing.Dispose();
            }
コード例 #2
0
ファイル: Airlock.cs プロジェクト: Helfima/SEIngame
            private void DrawSmallControl(IMyTextPanel block)
            {
                Drawing drawing      = new Drawing(block);
                bool    horizontal   = drawing.viewport.Height < drawing.viewport.Width;
                float   gauge_width  = 60f;
                float   gauge_height = 300f;
                float   icon_size    = 80f;

                StyleGauge style = new StyleGauge()
                {
                    Orientation     = horizontal ? SpriteOrientation.Horizontal : SpriteOrientation.Vertical,
                    Fullscreen      = false,
                    Width           = horizontal ? gauge_height : gauge_width,
                    Height          = horizontal ? gauge_width : gauge_height,
                    Padding         = new StylePadding(2),
                    RotationOrScale = 1f,
                    Percent         = false
                };

                Vector2 position = new Vector2(style.Padding.X, style.Padding.Y);
                Vector2 delta    = horizontal ? new Vector2(10, icon_size - 18) : new Vector2(22, icon_size / 2);
                string  icon     = "No Entry";

                if (OxygenRate < 1 - Epsilon)
                {
                    icon = "Danger";
                }
                drawing.AddSprite(new MySprite()
                {
                    Type      = SpriteType.TEXTURE,
                    Data      = $"{icon}",
                    Color     = Color.DimGray,
                    Position  = position + delta,
                    Size      = new Vector2(icon_size, icon_size),
                    Alignment = TextAlignment.LEFT
                });

                delta = horizontal ? new Vector2((drawing.viewport.Width - gauge_height) / 2, 32) : new Vector2(32, (drawing.viewport.Height - gauge_height) / 2);
                drawing.DrawGauge(position + delta, OxygenRate, 100, style, true);


                delta = horizontal ? new Vector2(drawing.viewport.Width - 60, drawing.viewport.Height / 2) : new Vector2(22 + drawing.viewport.Width / 2, drawing.viewport.Height - 80);
                if (Sleep > 0)
                {
                    drawing.AddSprite(new MySprite()
                    {
                        Type            = SpriteType.TEXT,
                        Data            = $"{Sleep}",
                        Color           = Color.DimGray,
                        Position        = position + delta,
                        RotationOrScale = 2f,
                        Alignment       = TextAlignment.CENTER
                    });
                }
                drawing.Dispose();
            }
コード例 #3
0
            private Vector2 DisplayGauge(Drawing drawing, Vector2 position)
            {
                long volumes    = 0;
                long maxVolumes = 1;

                inventories.ForEach(delegate(IMyTerminalBlock block)
                {
                    for (int i = 0; i < block.InventoryCount; i++)
                    {
                        IMyInventory block_inventory = block.GetInventory(i);
                        long volume    = block_inventory.CurrentVolume.RawValue;
                        volumes       += volume;
                        long maxVolume = block_inventory.MaxVolume.RawValue;
                        maxVolumes    += maxVolume;
                        //drawingSurface.WriteText($"\nVolume:{volume}/{maxVolume}", true);
                    }
                });
                //drawingSurface.WriteText($"\nVolume:{volumes}/{maxVolumes}", true);
                StyleGauge style = new StyleGauge()
                {
                    Orientation = gaugeHorizontal ? SpriteOrientation.Horizontal : SpriteOrientation.Vertical,
                    Fullscreen  = gaugeFullscreen,
                    Width       = gaugeWidth,
                    Height      = gaugeHeight
                };

                drawing.DrawGauge(position, volumes, maxVolumes, style);
                if (gaugeHorizontal)
                {
                    position += new Vector2(0, gaugeHeight + topPadding);
                }
                else
                {
                    position += new Vector2(gaugeWidth + leftPadding, 0);
                }
                return(position);
            }
コード例 #4
0
            public void DrawGauge(Vector2 position, float amount, float limit, StyleGauge style, bool invert = false)
            {
                float width  = style.Width;
                float height = style.Height;

                if (style.Fullscreen && style.Orientation.Equals(SpriteOrientation.Horizontal))
                {
                    width = viewport.Width;
                }
                if (style.Fullscreen && style.Orientation.Equals(SpriteOrientation.Vertical))
                {
                    height = viewport.Height;
                }

                width  += -2 * style.Padding.X;
                height += -2 * style.Padding.X;
                Vector2 position2 = position + new Vector2(style.Padding.X, style.Padding.Y);

                // Gauge
                AddForm(position2, SpriteForm.SquareSimple, width, height, style.Color);
                // Gauge Interrior
                AddForm(position2 + new Vector2(style.Margin.X, style.Margin.Y), SpriteForm.SquareSimple, width - 2 * style.Margin.X, height - 2 * style.Margin.Y, new Color(20, 20, 20, 255));

                // Gauge quantity
                float percent = Math.Min(1f, amount / limit);
                Color color   = Color.Green;

                if (percent > 0.5 && !invert)
                {
                    color = new Color(180, 130, 0, 128);
                }
                if (percent > 0.75 && !invert)
                {
                    color = new Color(180, 0, 0, 128);
                }

                if (percent < 0.5 && invert)
                {
                    color = new Color(180, 130, 0, 128);
                }
                if (percent < 0.25 && invert)
                {
                    color = new Color(180, 0, 0, 128);
                }

                if (style.Orientation.Equals(SpriteOrientation.Horizontal))
                {
                    float width2  = width - 2 * style.Margin.X;
                    float height2 = height - 2 * style.Margin.Y;
                    float length  = width2 * percent;
                    AddForm(position2 + new Vector2(style.Margin.X, style.Margin.Y), SpriteForm.SquareSimple, length, height2, color);
                }
                else
                {
                    float width2  = width - 2 * style.Margin.X;
                    float height2 = height - 2 * style.Margin.Y;
                    float length  = height2 * percent;
                    AddForm(position2 + new Vector2(style.Margin.X, height2 - length + style.Margin.Y), SpriteForm.SquareSimple, width2, length, color);
                }
                if (style.Percent)
                {
                    string data = $"{percent:P0}";
                    if (percent < 0.999 && style.Round)
                    {
                        data = $"{percent:P1}";
                    }
                    // Tag
                    icon = new MySprite()
                    {
                        Type            = SpriteType.TEXT,
                        Data            = data,
                        Size            = new Vector2(width, width),
                        Color           = Color.Black,
                        Position        = position2 + new Vector2(2 * style.Margin.X, style.Margin.Y),
                        RotationOrScale = style.RotationOrScale,
                        FontId          = Font,
                        Alignment       = TextAlignment.LEFT
                    };
                    AddSprite(icon);
                }
            }
コード例 #5
0
            public void DrawGaugeIcon(Vector2 position, string name, double amount, int limit, StyleIcon style_icon, int variance = 0)
            {
                Vector2 position2 = position + new Vector2(style_icon.Padding.X, style_icon.Padding.Y);
                // cadre info
                //AddForm(position2, SpriteForm.SquareSimple, style_icon.Width, style_icon.Height, new Color(40, 40, 40, 128));

                float width        = (style_icon.Width - 3 * style_icon.Margin.X) / 3;
                float fontTitle    = Math.Max(0.3f, (float)Math.Round(0.5f * (style_icon.Height / 80f), 1));
                float fontQuantity = Math.Max(0.5f, (float)Math.Round(1f * (style_icon.Height / 80f), 1));

                // Icon
                AddSprite(new MySprite()
                {
                    Type     = SpriteType.TEXTURE,
                    Data     = style_icon.path,
                    Size     = new Vector2(width, width),
                    Color    = style_icon.Color,
                    Position = position2 + new Vector2(0, width / 2)
                });

                StyleGauge style = new StyleGauge()
                {
                    Orientation     = SpriteOrientation.Horizontal,
                    Fullscreen      = false,
                    Width           = width * 2,
                    Height          = width / 3,
                    Padding         = new StylePadding(0),
                    RotationOrScale = Math.Max(0.3f, (float)Math.Round(0.6f * (style_icon.Height / 80f), 1))
                };

                DrawGauge(position2 + new Vector2(width + style_icon.Margin.X, style_icon.Height / 2), (float)amount, limit, style);

                // Element Name
                icon = new MySprite()
                {
                    Type            = SpriteType.TEXT,
                    Data            = name,
                    Size            = new Vector2(width, width),
                    Color           = Color.DimGray,
                    Position        = position2 + new Vector2(style_icon.Margin.X, -8),
                    RotationOrScale = fontTitle,
                    FontId          = Font,
                    Alignment       = TextAlignment.LEFT
                };
                AddSprite(icon);
                // Quantity
                icon = new MySprite()
                {
                    Type            = SpriteType.TEXT,
                    Data            = Util.GetKiloFormat(amount),
                    Size            = new Vector2(width, width),
                    Color           = Color.LightGray,
                    Position        = position2 + new Vector2(width + style_icon.Margin.X, style_icon.Margin.Y),
                    RotationOrScale = fontQuantity,
                    FontId          = Font
                };
                AddSprite(icon);

                float symbolSize = 20f;

                if (variance == 1)
                {
                    AddSprite(new MySprite()
                    {
                        Type            = SpriteType.TEXTURE,
                        Data            = SpriteForm.Triangle.ToString(),
                        Size            = new Vector2(symbolSize, symbolSize),
                        Color           = new Color(0, 100, 0, 255),
                        Position        = position2 + new Vector2(3 * width - 25, symbolSize - style_icon.Margin.Y),
                        RotationOrScale = 0
                    });
                }
                if (variance == 3)
                {
                    AddSprite(new MySprite()
                    {
                        Type            = SpriteType.TEXTURE,
                        Data            = SpriteForm.Triangle.ToString(),
                        Size            = new Vector2(symbolSize, symbolSize),
                        Color           = new Color(100, 0, 0, 255),
                        Position        = position2 + new Vector2(3 * width - 25, symbolSize + style_icon.Margin.Y),
                        RotationOrScale = (float)Math.PI
                    });
                }
            }
コード例 #6
0
ファイル: DisplayDrill.cs プロジェクト: Helfima/SEIngame
            public Vector2 Draw(Drawing drawing, Vector2 position)
            {
                if (!enable)
                {
                    return(position);
                }
                if (search)
                {
                    Search();
                }

                float      width          = drills_size;
                float      padding        = 4f;
                float      x_min          = 0f;
                float      x_max          = 0f;
                float      y_min          = 0f;
                float      y_max          = 0f;
                bool       first          = true;
                Vector2    padding_screen = new Vector2(drills_padding_x, drills_padding_y);
                StyleGauge style          = new StyleGauge()
                {
                    Orientation     = SpriteOrientation.Horizontal,
                    Fullscreen      = false,
                    Width           = width,
                    Height          = width,
                    Padding         = new StylePadding(0),
                    Round           = false,
                    RotationOrScale = 0.5f,
                    Percent         = drills_size > 49 ? true : false
                };

                if (drills_info)
                {
                    drawing.AddSprite(new MySprite()
                    {
                        Type            = SpriteType.TEXT,
                        Data            = $"Drill Number:{drill_inventories.List.Count} ({filter})",
                        Size            = new Vector2(width, width),
                        Color           = Color.DimGray,
                        Position        = position + new Vector2(0, 0),
                        RotationOrScale = 0.5f,
                        FontId          = drawing.Font,
                        Alignment       = TextAlignment.LEFT
                    });
                    position += new Vector2(0, 20);
                }
                drill_inventories.ForEach(delegate(IMyShipDrill drill)
                {
                    switch (drills_orientation)
                    {
                    case "x":
                        if (first || drill.Position.Y < x_min)
                        {
                            x_min = drill.Position.Y;
                        }
                        if (first || drill.Position.Y > x_max)
                        {
                            x_max = drill.Position.Y;
                        }
                        if (first || drill.Position.Z < y_min)
                        {
                            y_min = drill.Position.Z;
                        }
                        if (first || drill.Position.Z > y_max)
                        {
                            y_max = drill.Position.Z;
                        }
                        break;

                    case "y":
                        if (first || drill.Position.X < x_min)
                        {
                            x_min = drill.Position.X;
                        }
                        if (first || drill.Position.X > x_max)
                        {
                            x_max = drill.Position.X;
                        }
                        if (first || drill.Position.Z < y_min)
                        {
                            y_min = drill.Position.Z;
                        }
                        if (first || drill.Position.Z > y_max)
                        {
                            y_max = drill.Position.Z;
                        }
                        break;

                    default:
                        if (first || drill.Position.X < x_min)
                        {
                            x_min = drill.Position.X;
                        }
                        if (first || drill.Position.X > x_max)
                        {
                            x_max = drill.Position.X;
                        }
                        if (first || drill.Position.Y < y_min)
                        {
                            y_min = drill.Position.Y;
                        }
                        if (first || drill.Position.Y > y_max)
                        {
                            y_max = drill.Position.Y;
                        }
                        break;
                    }
                    first = false;
                });
                //drawingSurface.WriteText($"X min:{x_min} Y min:{y_min}\n", false);
                drill_inventories.ForEach(delegate(IMyShipDrill drill)
                {
                    IMyInventory block_inventory = drill.GetInventory(0);
                    long volume    = block_inventory.CurrentVolume.RawValue;
                    long maxVolume = block_inventory.MaxVolume.RawValue;
                    float x        = 0;
                    float y        = 0;
                    switch (drills_orientation)
                    {
                    case "x":
                        x = Math.Abs(drill.Position.Y - x_min);
                        y = Math.Abs(drill.Position.Z - y_min);
                        break;

                    case "y":
                        x = Math.Abs(drill.Position.X - x_min);
                        y = Math.Abs(drill.Position.Z - y_min);
                        break;

                    default:
                        x = Math.Abs(drill.Position.X - x_min);
                        y = Math.Abs(drill.Position.Y - y_min);
                        break;
                    }
                    //drawingSurface.WriteText($"X:{x} Y:{y}\n", true);
                    if (drills_flip_x)
                    {
                        x = Math.Abs(x_max - x_min) - x;
                    }
                    if (drills_flip_y)
                    {
                        y = Math.Abs(y_max - y_min) - y;
                    }
                    //drawingSurface.WriteText($"Volume [{x},{y}]:{volume}/{maxVolume}\n", true);
                    Vector2 position_relative = drills_rotate ? new Vector2(y * (width + padding), x * (width + padding)) : new Vector2(x * (width + padding), y * (width + padding));

                    drawing.DrawGauge(position + position_relative + padding_screen, volume, maxVolume, style);
                });

                return(position);
            }
コード例 #7
0
            public Vector2 Draw(Drawing drawing, Vector2 position)
            {
                if (!enable)
                {
                    return(position);
                }
                List <string> types = new List <string>();

                if (tank_h2)
                {
                    types.Add("Hydrogen");
                }
                if (tank_o2)
                {
                    types.Add("Oxygen");
                }
                if (types.Count > 0)
                {
                    foreach (string type in types)
                    {
                        BlockSystem <IMyGasTank> tanks = BlockSystem <IMyGasTank> .SearchBlocks(DisplayLcd.program, block => block.BlockDefinition.SubtypeName.Contains(type));

                        float      volumes  = 0f;
                        float      capacity = 0f;
                        float      width    = 50f;
                        StyleGauge style    = new StyleGauge()
                        {
                            Orientation     = SpriteOrientation.Horizontal,
                            Fullscreen      = true,
                            Width           = width,
                            Height          = width,
                            Padding         = new StylePadding(0),
                            Round           = false,
                            RotationOrScale = 0.5f
                        };

                        MySprite text = new MySprite()
                        {
                            Type            = SpriteType.TEXT,
                            Color           = Color.DimGray,
                            Position        = position + new Vector2(0, 0),
                            RotationOrScale = 1f,
                            FontId          = drawing.Font,
                            Alignment       = TextAlignment.LEFT
                        };

                        tanks.ForEach(delegate(IMyGasTank block)
                        {
                            volumes  += (float)block.FilledRatio * block.Capacity;
                            capacity += block.Capacity;
                        });

                        drawing.DrawGauge(position, volumes, capacity, style);
                        position += new Vector2(0, 60);
                        switch (type)
                        {
                        case "Hydrogen":
                            text.Data = $"H2: {Math.Round(volumes, 2)}L / {Math.Round(capacity, 2)}L";
                            break;

                        case "Oxygen":
                            text.Data = $"O2: {Math.Round(volumes, 2)}L / {Math.Round(capacity, 2)}L";
                            break;
                        }
                        text.Position = position;
                        drawing.AddSprite(text);
                        position += new Vector2(0, 60);
                    }
                }
                return(position);
            }
コード例 #8
0
            public Vector2 Draw(Drawing drawing, Vector2 position)
            {
                if (!enable)
                {
                    return(position);
                }
                BlockSystem <IMyTerminalBlock> producers = BlockSystem <IMyTerminalBlock> .SearchBlocks(DisplayLcd.program, block => block.Components.Has <MyResourceSourceComponent>());

                BlockSystem <IMyTerminalBlock> consummers = BlockSystem <IMyTerminalBlock> .SearchBlocks(DisplayLcd.program, block => block.Components.Has <MyResourceSinkComponent>());

                Dictionary <string, Power> outputs = new Dictionary <string, Power>();
                Power batteries_store = new Power()
                {
                    Type = "Batteries"
                };

                outputs.Add("all", new Power()
                {
                    Type = "All"
                });
                float      current_input = 0f;
                float      max_input     = 0f;
                float      width         = 30f;
                StyleGauge style         = new StyleGauge()
                {
                    Orientation     = SpriteOrientation.Horizontal,
                    Fullscreen      = true,
                    Width           = width,
                    Height          = width,
                    Padding         = new StylePadding(0),
                    Round           = false,
                    RotationOrScale = 0.5f
                };

                MySprite text = new MySprite()
                {
                    Type            = SpriteType.TEXT,
                    Color           = Color.DimGray,
                    Position        = position + new Vector2(0, 0),
                    RotationOrScale = .6f,
                    FontId          = drawing.Font,
                    Alignment       = TextAlignment.LEFT
                };

                producers.ForEach(delegate(IMyTerminalBlock block)
                {
                    string type = block.BlockDefinition.SubtypeName;
                    if (block is IMyBatteryBlock)
                    {
                        IMyBatteryBlock battery = (IMyBatteryBlock)block;
                        batteries_store.AddCurrent(battery.CurrentStoredPower);
                        batteries_store.AddMax(battery.MaxStoredPower);
                    }
                    else
                    {
                        MyResourceSourceComponent resourceSource;
                        block.Components.TryGet <MyResourceSourceComponent>(out resourceSource);
                        if (resourceSource != null)
                        {
                            ListReader <MyDefinitionId> myDefinitionIds = resourceSource.ResourceTypes;
                            if (myDefinitionIds.Contains(PowerDefinitionId))
                            {
                                Power global_output = outputs["all"];
                                global_output.AddCurrent(resourceSource.CurrentOutputByType(PowerDefinitionId));
                                global_output.AddMax(resourceSource.MaxOutputByType(PowerDefinitionId));

                                if (!outputs.ContainsKey(type))
                                {
                                    outputs.Add(type, new Power()
                                    {
                                        Type = type
                                    });
                                }
                                Power current_output = outputs[type];
                                current_output.AddCurrent(resourceSource.CurrentOutputByType(PowerDefinitionId));
                                current_output.AddMax(resourceSource.MaxOutputByType(PowerDefinitionId));
                            }
                        }
                    }
                });

                drawing.DrawGauge(position, outputs["all"].Current, outputs["all"].Max, style);

                foreach (KeyValuePair <string, Power> kvp in outputs)
                {
                    string title = kvp.Key;

                    position += new Vector2(0, 40);
                    if (kvp.Key.Equals("all"))
                    {
                        text.Data = $"Global Generator\n Out: {Math.Round(kvp.Value.Current, 2)}MW / {Math.Round(kvp.Value.Max, 2)}MW";
                    }
                    else
                    {
                        text.Data  = $"{title} (n={kvp.Value.Count})\n";
                        text.Data += $" Out: {Math.Round(kvp.Value.Current, 2)}MW / {Math.Round(kvp.Value.Max, 2)}MW";
                        text.Data += $" (Moy={kvp.Value.Moyen}MW)";
                    }
                    text.Position = position;
                    drawing.AddSprite(text);
                }

                position += new Vector2(0, 40);
                drawing.DrawGauge(position, batteries_store.Current, batteries_store.Max, style, true);
                position     += new Vector2(0, 40);
                text.Data     = $"Battery Store (n={batteries_store.Count})\n Store: {Math.Round(batteries_store.Current, 2)}MW / {Math.Round(batteries_store.Max, 2)}MW";
                text.Position = position;
                drawing.AddSprite(text);

                consummers.ForEach(delegate(IMyTerminalBlock block)
                {
                    if (block is IMyBatteryBlock)
                    {
                    }
                    else
                    {
                        MyResourceSinkComponent resourceSink;
                        block.Components.TryGet <MyResourceSinkComponent>(out resourceSink);
                        if (resourceSink != null)
                        {
                            ListReader <MyDefinitionId> myDefinitionIds = resourceSink.AcceptedResources;
                            if (myDefinitionIds.Contains(PowerDefinitionId))
                            {
                                max_input     += resourceSink.RequiredInputByType(PowerDefinitionId);
                                current_input += resourceSink.CurrentInputByType(PowerDefinitionId);
                            }
                        }
                    }
                });
                position += new Vector2(0, 40);
                drawing.DrawGauge(position, current_input, max_input, style, true);
                position     += new Vector2(0, 40);
                text.Data     = $"Power In: {Math.Round(current_input, 2)}MW / {Math.Round(max_input, 2)}MW";
                text.Position = position;
                drawing.AddSprite(text);

                return(position + new Vector2(0, 60));
            }