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; } }
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; }
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; }
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; } }
/// <summary> /// Allows to register a new meter /// </summary> /// <param name="meterId">Meter identifier.</param> /// <param name="meterName">Meter name.</param> /// <param name="meterCategory">Meter category.</param> /// <param name="meterType">Meter type.</param> /// <param name="meterValue">Meter value.</param> public MeterDefinition RegisterMeter(String meterId, String meterName, String meterCategory, nMeterTypes meterType, Int32 meterDisplayOrder, Decimal meterValue) { // double check if (meterCache.ContainsKey(meterId)) { throw new Exception("Invalid MeterId, can't add the meter because the same meterid was used before for another meter"); } // add the meter var meterDefinition = new MeterDefinition() { MeterId = meterId, MeterName = meterName, MeterCategory = meterCategory, MeterDisplayOrder = meterDisplayOrder, MeterType = meterType, MeterValue = meterValue }; meterCache.Add(meterId, meterDefinition); // done return(meterDefinition); }
public void PostionInterpreter(MeterDefinition def) { //Position //vw vh, and vmin adjustments. switch (def.posType.X) { case VectorType.ViewWidth: def.position.X = Size.X * def.position.X * 0.01f; break; case VectorType.ViewHeight: def.position.X = Size.Y * def.position.X * 0.01f; break; case VectorType.ViewMin: def.position.X = SmallestSize * def.position.X * 0.01f; break; } switch (def.posType.Y) { case VectorType.ViewWidth: def.position.Y = Size.X * def.position.Y * 0.01f; break; case VectorType.ViewHeight: def.position.Y = Size.Y * def.position.Y * 0.01f; break; case VectorType.ViewMin: def.position.Y = SmallestSize * def.position.Y * 0.01f; break; } def.position.Y = def.position.Y * -1; //Invert Y //size if (def.type == Meter.Text || def.type == Meter.Value) { switch (def.sizeType.X) { case VectorType.ViewWidth: def.size.X = Size.X / 30.6f * def.size.X * 0.01f; break; case VectorType.ViewHeight: def.size.X = Size.Y / 30.6f * def.size.X * 0.01f; break; case VectorType.ViewMin: def.size.X = SmallestSize / 30.6f * def.size.X * 0.01f; break; } } else { switch (def.sizeType.X) { case VectorType.ViewWidth: def.size.X = Size.X * def.size.X * 0.01f; break; case VectorType.ViewHeight: def.size.X = Size.Y * def.size.X * 0.01f; break; case VectorType.ViewMin: def.size.X = SmallestSize * def.size.X * 0.01f; break; } switch (def.sizeType.Y) { case VectorType.ViewWidth: def.size.Y = Size.X * def.size.Y * 0.01f; break; case VectorType.ViewHeight: def.size.Y = Size.Y * def.size.Y * 0.01f; break; case VectorType.ViewMin: def.size.Y = SmallestSize * def.size.Y * 0.01f; break; } } }