using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Views; using Android.Widget; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework; using Penguloon.Levels; namespace Penguloon.Objects { public enum UpgradeType { Health, PopCount, Speed, Money, Range, } public enum UpgradeState { Idle, Pressed, } public class ObjectUpgrade { public int Cost { get; set; } public ObjectUpgrade NextUgrade { get; set; } public event EventHandler OnClick; public UpgradeType Type { get; set; } public string Text { get; set; } public UpgradeState State { get; set; } = UpgradeState.Idle; private Texture2D Background { get; set; } private Texture2D BackgroundPressed { get; set; } private Texture2D Icon { get; set; } public LevelBase ParentLevel { get; set; } public ObjectUpgrade(int Cost, UpgradeType Type, string Text, ObjectUpgrade NextUgrade, LevelBase parentLevel) { // something is fucked up in staticUiValues.IngameUIWidth but we can workaround that issue with this line StaticUIValues.UpgradePanelSize = new Vector2( StaticUIValues.ScreenViewport.X - parentLevel.Map.MapWidth, StaticUIValues.UpgradePanelSize.Y); this.Cost = Cost; this.Type = Type; this.Text = Text; this.NextUgrade = NextUgrade; this.ParentLevel = parentLevel; Background = ContentManager.GetTexture("UI/lightred"); BackgroundPressed = ContentManager.GetTexture("UI/objectSelectionBackground"); switch (Type) { case UpgradeType.Health: Icon = ContentManager.GetTexture("UI/heart"); break; case UpgradeType.Money: Icon = ContentManager.GetTexture("UI/money"); break; case UpgradeType.PopCount: Icon = ContentManager.GetTexture("UI/explosion"); break; case UpgradeType.Speed: Icon = ContentManager.GetTexture("UI/speed"); break; case UpgradeType.Range: Icon = ContentManager.GetTexture("UI/radar"); break; } } public void Click() { OnClick?.Invoke(this, EventArgs.Empty); } internal void Draw(SpriteBatch spriteBatch, int index) { int startY = StaticUIValues.IngameUITextAreaHeight + StaticUIValues.BorderWidth; SpriteFont font = ContentManager.GetFont(StaticUIValues.IngameFont); int textHeight = (int)font.MeasureString(Text).Y; int textWidth = (int)font.MeasureString(Text).X; int costHeight = (int)font.MeasureString("$" + Cost.ToString() + ",-").Y; int costWidth = (int)font.MeasureString("$" + Cost.ToString() + ",-").X; if (State == UpgradeState.Idle) spriteBatch.Draw(Background, destinationRectangle: new Rectangle( ParentLevel.Map.MapWidth + StaticUIValues.BorderWidth, startY + (int)StaticUIValues.UpgradePanelSize.Y * index, (int)StaticUIValues.UpgradePanelSize.X, (int)StaticUIValues.UpgradePanelSize.Y)); else spriteBatch.Draw(BackgroundPressed, destinationRectangle: new Rectangle( ParentLevel.Map.MapWidth + StaticUIValues.BorderWidth, startY + (int)StaticUIValues.UpgradePanelSize.Y * index, (int)StaticUIValues.UpgradePanelSize.X, (int)StaticUIValues.UpgradePanelSize.Y)); spriteBatch.Draw(Icon, destinationRectangle: new Rectangle( ParentLevel.Map.MapWidth + StaticUIValues.BorderWidth + 20, startY + ((int)StaticUIValues.UpgradePanelSize.Y * index) + (int)(StaticUIValues.UpgradePanelSize.Y / 4), (int)StaticUIValues.UpgradePanelSize.Y / 2, (int)StaticUIValues.UpgradePanelSize.Y / 2)); spriteBatch.DrawString(ContentManager.GetFont(StaticUIValues.IngameFont), Text, new Vector2(StaticUIValues.ScreenViewport.X - 20 - textWidth, startY + ((int)StaticUIValues.UpgradePanelSize.Y * index) + (int)(StaticUIValues.UpgradePanelSize.Y / 3) - textHeight / 2), Color.FromNonPremultiplied(20, 20, 20, 255)); spriteBatch.DrawString(ContentManager.GetFont(StaticUIValues.IngameFont), "$" + Cost.ToString() + ",-", new Vector2(StaticUIValues.ScreenViewport.X - 20 - costWidth, startY + ((int)StaticUIValues.UpgradePanelSize.Y * index) + (int)(StaticUIValues.UpgradePanelSize.Y / 2) + (int)(StaticUIValues.UpgradePanelSize.Y / 4) - costHeight / 2), Color.FromNonPremultiplied(20, 20, 20, 255)); spriteBatch.Draw(ContentManager.GetTexture("UI/objectSelectionBorder"), destinationRectangle: new Rectangle( ParentLevel.Map.MapWidth + StaticUIValues.BorderWidth, startY + (int)StaticUIValues.UpgradePanelSize.Y * index + (int)StaticUIValues.UpgradePanelSize.Y - 2, (int)StaticUIValues.UpgradePanelSize.X, 2)); } } }