private void AddUI(ShipEngineData shipEngineData) { Vector2 size = Vector2.Zero; // For now don't set the position of this label, because we do not know the size yet // However, with correct parenting we will only need to set this position at the very end when the size is calculated // And everything else will be correctly position Label name = new Label(shipEngineData.DisplayName, Vector2.Zero, Color.Yellow, this); size = name.TextDimensions; AddUIObject(name, "Engine Name"); ImageAndLabel health = new ImageAndLabel("Sprites\\UI\\Icons\\Health", "Health: " + shipEngineData.Health.ToString(), new Vector2(0, SpriteFont.LineSpacing + padding), Color.White, name); AddUIObject(health, "Engine Health", true); size = new Vector2(Math.Max(size.X, health.Dimensions.X), size.Y + SpriteFont.LineSpacing + padding); Label thrust = new Label("Thrust: " + shipEngineData.Thrust.ToString(), new Vector2(0, SpriteFont.LineSpacing + padding), Color.White, health); size = new Vector2(Math.Max(size.X, thrust.TextDimensions.X), size.Y + SpriteFont.LineSpacing + padding); AddUIObject(thrust, "Engine Thrust"); ImageAndLabel price = new ImageAndLabel("Sprites\\UI\\Icons\\MoneyIcon", shipEngineData.Price.ToString(), new Vector2(0, SpriteFont.LineSpacing + padding), thrust); size = new Vector2(Math.Max(size.X, price.Dimensions.X), size.Y + SpriteFont.LineSpacing + padding); AddUIObject(price, "Engine Price"); Size = size + new Vector2(padding, padding) * 2; LocalPosition += new Vector2(0, -Size.Y * 0.5f); // Position the first UI element correctly name.LocalPosition = new Vector2(0, -Size.Y * 0.5f + SpriteFont.LineSpacing * 0.5f + padding); }
public BuyShipEngineHoverInfo(ShipEngineData shipEngineData, Vector2 localPosition, BaseObject parent, float lifeTime = float.MaxValue) : base(shipEngineData, localPosition, parent, lifeTime) { AddUI(shipEngineData); }