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 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 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; } }
public void Draw(MySpriteDrawFrame frame, Data dataChanged) { if (UseDataMinMax) { def.min = shipData[def.data].Min; def.max = shipData[def.data].Max; total = def.max - def.min; } val = Ini.AdjustToUnit(def, shipData, total, UseDataMinMax); //Check for hide condition. if (Ini.MeetsConditions(def.conditions, val, def.condVals)) { return; } if ((dataChanged & def.data) != 0) { spriteSize.X = (float)Math.Abs(MathHelper.Clamp(shipData[def.data].Value, def.min, def.max) / total * def.size.X); //_sprite.Position = sm.AdjustToAnchor(def.anchor, def.position, spriteSize); sprite.Position = sm.AdjustToRotation(sm.AdjustToAnchor(def.anchor, def.position, spriteSize), def.position, def.rotation); sprite.Size = spriteSize; if (def.backgroundSet) { frame.Add(background); } frame.Add(sprite); } else { sprite.Size = spriteSize; if (def.backgroundSet) { frame.Add(background); } frame.Add(sprite); } }
public void Draw(MySpriteDrawFrame frame, Data dataChanged) { if (UseDataMinMax) { def.min = shipData[def.data].Min; def.max = shipData[def.data].Max; total = def.max - def.min; } val = Ini.AdjustToUnit(def, shipData, total, UseDataMinMax); //Check for hide condition. if (Ini.MeetsConditions(def.conditions, val, def.condVals)) { return; } if ((dataChanged & def.data) != 0) { values[valueIndex] = shipData[def.data].Value; if (def.backgroundSet) { frame.Add(background); } int prev = LINES - 1; int value = (valueIndex + 1) % LINES; Vector2 prevPos = sm.AdjustToRotation(new Vector2((pos.X), (float)(pos.Y - values[value] / total * def.size.Y)), def.position, def.rotation); for (int i = 0; i < LINES; i++) { value = (valueIndex + i + 1) % LINES; //1. Calc distance between points, fow rect width. //2. Calc rotation between points, for rect rotation //3. Calc point between points, for rect position //4. Place rect there. Vector2 newPos = sm.AdjustToRotation(new Vector2((pos.X + def.size.X * SECTION * i), (float)(pos.Y - values[value] / total * def.size.Y)), def.position, def.rotation); sprites[i].Position = Vector2.Lerp(newPos, prevPos, 0.5f); sprites[i].Size = new Vector2(Vector2.Distance(prevPos, newPos), thickness); sprites[i].RotationOrScale = (float)Math.Atan2(newPos.Y - prevPos.Y, newPos.X - prevPos.X); if (values[value] <= def.max && value >= def.min) { frame.Add(sprites[i]); } prevPos = newPos; prev = i; } valueIndex++; if (valueIndex >= LINES) { valueIndex = 0; } } else { if (def.backgroundSet) { frame.Add(background); } for (int i = 0; i < LINES; i++) { frame.Add(sprites[i]); } } }