Beispiel #1
0
        public MeterBar(SurfaceMath sm, MeterDefinition def, Dictionary <Data, IData> shipData)
        {
            this.sm = sm;
            sm.PostionInterpreter(def);
            this.def      = def;
            this.shipData = shipData;
            def.position += sm.Center;

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

            sprite                 = new MySprite(SpriteType.TEXTURE, "SquareSimple", color: def.color);
            sprite.Position        = sm.AdjustToRotation(sm.AdjustToAnchor(def.anchor, def.position, def.size), def.position, def.rotation);
            spriteSize.Y           = def.size.Y;
            sprite.RotationOrScale = def.rotation;

            if (def.backgroundSet)
            {
                background                 = new MySprite(SpriteType.TEXTURE, "SquareSimple", color: def.background);
                background.Position        = sm.AdjustToRotation(sm.AdjustToAnchor(def.anchor, def.position, def.size), def.position, def.rotation);
                background.Size            = def.size;
                background.RotationOrScale = def.rotation;
            }
        }
Beispiel #2
0
        public MeterAction(SurfaceMath sm, MeterDefinition def, Dictionary <Data, IData> shipData, List <IMyTerminalBlock> blocks, IMyGridTerminalSystem gts, IMyProgrammableBlock me)
        {
            this.def      = def;
            this.shipData = shipData;

            if (def.textData == "")
            {
                def.textData = "OnOff";
            }

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

            foreach (string text in def.blocks)
            {
                if (text.StartsWith("*") && text.EndsWith("*"))
                {
                    //Group.
                    var group = gts.GetBlockGroupWithName(text.Trim('*'));
                    if (group != null)
                    {
                        var groupBlocks = new List <IMyTerminalBlock>();
                        group.GetBlocks(groupBlocks);
                        foreach (var block in groupBlocks)
                        {
                            if (block.IsSameConstructAs(me))
                            {
                                this.blocks.Add(block);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var block in blocks)
                    {
                        if (block.CustomName == text)
                        {
                            this.blocks.Add(block);
                            break;
                        }
                    }
                }
            }
        }
        public MeterThreeQuaterMeter(SurfaceMath sm, MeterDefinition def, Dictionary <Data, IData> shipData, Color background)
        {
            this.sm = sm;
            sm.PostionInterpreter(def);
            this.def        = def;
            this.shipData   = shipData;
            this.background = background;
            def.position   += sm.Center;


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

            float innerSize = MathHelper.Clamp(1 - def.stroke, 0, 1);

            def.size.Y = def.size.X;             //Make square. Y is used for cicle thickness.

            full     = new MySprite(SpriteType.TEXTURE, "Circle", def.position, color: def.color);
            semi     = new MySprite(SpriteType.TEXTURE, "SemiCircle", def.position, def.size);
            top      = new MySprite(SpriteType.TEXTURE, "SemiCircle", def.position, color: def.color);
            bottom   = new MySprite(SpriteType.TEXTURE, "SemiCircle", def.position, def.size);
            inner    = new MySprite(SpriteType.TEXTURE, "Circle", def.position, def.size * innerSize, color: background);
            triangle = new MySprite(SpriteType.TEXTURE, "RightTriangle", def.position, def.size * innerSize, color: background);

            triangle.RotationOrScale = MathHelper.ToRadians(135) + def.rotation;
            triangle.Position        = sm.AdjustToRotation(new Vector2(def.position.X, def.position.Y + def.size.Y * 0.51f), def.position, def.rotation);

            if (def.backgroundSet)
            {
                semi.Color   = def.background;
                bottom.Color = def.background;
                full.Size    = def.size;
                top.Size     = def.size;
            }
            else
            {
                semi.Color   = background;
                bottom.Color = background;
                full.Size    = def.size * 0.97f;              //Shrinking to prevent color shining through. Looks weird with background so skipping it there.
                top.Size     = def.size * 0.97f;
            }

            top.RotationOrScale    = def.rotation + MathHelper.ToRadians(-90);
            bottom.RotationOrScale = MathHelper.ToRadians(180 - 90) + def.rotation;
        }
Beispiel #4
0
        public Program()
        {
            if (Me.SurfaceCount > 0)
            {
                pbSurface = Me.GetSurface(0);
                pbSM = new SurfaceMath(pbSurface);
                pbSurface.ContentType = ContentType.SCRIPT;
                pbSurface.Script = "";
                if (pbSurface.ScriptBackgroundColor != problemBG) defaultBG = pbSurface.ScriptBackgroundColor;
            }

            MaxInstructionsPerTick = Runtime.MaxInstructionCount / 4; //Limit how much the script can do on a single tick
            Runtime.UpdateFrequency = UpdateFrequency.Update10 | UpdateFrequency.Update1;
            InitStateMachine = Init();

            // Write config to custom data
            // pit_diameter = 5
            // get count horizontal pistons
        }
Beispiel #5
0
        public Program()
        {
            if (Me.SurfaceCount > 0)
            {
                pbSurface             = Me.GetSurface(0);
                pbSM                  = new SurfaceMath(pbSurface);
                pbSurface.ContentType = ContentType.SCRIPT;
                pbSurface.Script      = "";
                if (pbSurface.ScriptBackgroundColor != problemBG)
                {
                    defaultBG = pbSurface.ScriptBackgroundColor;
                }
            }

            InitPreloads();

            MaxInstructionsPerTick  = Runtime.MaxInstructionCount / 4;            //Limit how much the script can do on a single tick
            Runtime.UpdateFrequency = UpdateFrequency.Update10 | UpdateFrequency.Update1;
            InitStateMachine        = Init();
        }
        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;
            }
        }
        public MeterSprite(SurfaceMath sm, MeterDefinition def, Dictionary <Data, IData> shipData)
        {
            sm.PostionInterpreter(def);
            this.def      = def;
            this.shipData = shipData;
            def.position += sm.Center;

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

            sprite                 = new MySprite(SpriteType.TEXTURE, def.textData, color: def.color);
            sprite.Size            = def.size;
            sprite.Position        = sm.AdjustToRotation(sm.AdjustToAnchor(def.anchor, def.position, def.size), def.position, def.rotation);
            sprite.RotationOrScale = def.rotation;
        }
Beispiel #8
0
        public MeterLineGraph(SurfaceMath sm, MeterDefinition def, Dictionary <Data, IData> shipData)
        {
            this.sm = sm;
            sm.PostionInterpreter(def);
            this.def      = def;
            this.shipData = shipData;
            def.position += sm.Center;


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

            for (int i = 0; i < LINES; i++)
            {
                sprites[i] = new MySprite(SpriteType.TEXTURE, "SquareSimple", color: def.color);
            }

            pos = def.position;

            pos.X      -= def.size.X * 0.5f - (def.size.X * SECTION * 0.5f);
            pos.Y      += def.size.Y * 0.5f - (thickness * 0.5f);
            def.size.Y -= thickness;

            valueIndex = LINES - 1;

            if (def.backgroundSet)
            {
                background                 = new MySprite(SpriteType.TEXTURE, "SquareSimple", color: def.background);
                background.Position        = sm.AdjustToRotation(sm.AdjustToAnchor(def.anchor, def.position, def.size), def.position, def.rotation);
                background.Size            = def.size;
                background.RotationOrScale = def.rotation;
            }
        }
Beispiel #9
0
        public Skin(Program P, IMyTextSurface surface, SurfaceMath surfaceMath, IMyTerminalBlock block, SkinDefinition skinDefinition, List <IMeter> meters)
        {
            this.P  = P;
            Surface = surface;
            SM      = surfaceMath;
            Block   = block;
            SkinDef = skinDefinition;
            Meters  = meters;

            foreach (var meter in SkinDef.meters)
            {
                //This data could also be acceses if meters.def was public.
                DataInUse |= meter.data;
            }

            //These 3 could be run every interation, but why?
            //On setup should be enough.
            Surface.ContentType = ContentType.SCRIPT;
            Surface.Script      = "";
            if (skinDefinition.backgroundColorSet)
            {
                Surface.ScriptBackgroundColor = skinDefinition.backgroundColor;
            }
        }
Beispiel #10
0
        private IEnumerator <bool> Init()
        {
            Skins.Clear();
            ShipData.Clear();
            InitProblemBlockNames.Clear();

            blocks = new List <IMyTerminalBlock>();
            GridTerminalSystem.GetBlocksOfType(blocks, x => x.IsSameConstructAs(Me));


            var sprites = new List <string>();

            foreach (var block in blocks)
            {
                if (block is IMyShipController)
                {
                    var contr = block as IMyShipController;
                    if (contr.CanControlShip)
                    {
                        if (Controller == null)
                        {
                            //Take any controller just to have one.
                            Controller = contr;
                        }
                        if (contr.IsMainCockpit)
                        {
                            //If a main one is defined, use that.
                            Controller = contr;
                        }
                    }
                }
            }

            foreach (var block in blocks)
            {
                var surfaceProvider = block as IMyTextSurfaceProvider;
                if (surfaceProvider != null && surfaceProvider.SurfaceCount > 0)
                {
                    //Get all textures, might be needed in the ini parser
                    if (sprites.Count == 0)
                    {
                        surfaceProvider.GetSurface(0).GetSprites(sprites);
                    }

                    //Has Surface, check custom data

                    Ini ini = new Ini(block.CustomData, surfaceProvider.SurfaceCount, sprites, Preloads);
                    //Skins will be added to the Skins list in ParseIni

                    while (true)
                    {
                        if (ini.ParserDone() == true)
                        {
                            break;
                        }
                        else
                        {
                            if (OverInstructionLimit())
                            {
                                yield return(true);
                            }
                        }
                    }

                    if (!ini.NoErrors)
                    {
                        //TODO
                        InitProblemBlockNames.Add(block.CustomName);
                    }
                    block.CustomData = ini.Processed;

                    foreach (var skinDef in ini.SkinDataList)
                    {
                        if (skinDef.screenId < surfaceProvider.SurfaceCount)
                        {
                            var surface = surfaceProvider.GetSurface(skinDef.screenId);
                            var sm      = new SurfaceMath(surface);
                            var meters  = new List <IMeter>();
                            foreach (var meter in skinDef.meters)
                            {
                                if (meter.type == Meter.Text)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterText(sm, meter, ShipData));
                                }
                                else if (meter.type == Meter.Value)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterValue(sm, meter, ShipData));
                                }
                                else if (meter.type == Meter.Bar)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterBar(sm, meter, ShipData));
                                }
                                else if (meter.type == Meter.LineGraph)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterLineGraph(sm, meter, ShipData));
                                }
                                else if (meter.type == Meter.Meter)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterMeter(sm, meter, ShipData, (skinDef.backgroundColorSet ? skinDef.backgroundColor : surface.ScriptBackgroundColor)));
                                }
                                else if (meter.type == Meter.HalfMeter)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterHalfMeter(sm, meter, ShipData, (skinDef.backgroundColorSet ? skinDef.backgroundColor : surface.ScriptBackgroundColor)));
                                }
                                else if (meter.type == Meter.ThreeQuaterMeter)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterThreeQuaterMeter(sm, meter, ShipData, (skinDef.backgroundColorSet ? skinDef.backgroundColor : surface.ScriptBackgroundColor)));
                                }
                                else if (meter.type == Meter.Sprite)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterSprite(sm, meter, ShipData));
                                }
                                else if (meter.type == Meter.Action)
                                {
                                    RegisterDataPoint(meter.data);
                                    meters.Add(new MeterAction(sm, meter, ShipData, blocks, GridTerminalSystem, Me));
                                }
                            }
                            Skins.Add(new Skin(this, surface, sm, block, skinDef, meters));
                        }
                    }

                    /* Adding all isn't what we want.
                     * for (int i = 0; i < surfaceProvider.SurfaceCount; i++)
                     * {
                     *      Skins.Add(new Skin(this, surfaceProvider.GetSurface(i), i, block));
                     * }
                     */
                }
            }

            DrawStateMachine = Draw();
            Initialized++;
            yield return(false);
        }