diff options
Diffstat (limited to 'Penguloon/Controls/UpgradeMenu.cs')
| -rw-r--r-- | Penguloon/Controls/UpgradeMenu.cs | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/Penguloon/Controls/UpgradeMenu.cs b/Penguloon/Controls/UpgradeMenu.cs new file mode 100644 index 0000000..6156018 --- /dev/null +++ b/Penguloon/Controls/UpgradeMenu.cs @@ -0,0 +1,166 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input.Touch; +using Penguloon.Levels; +using Penguloon.Objects; +using Penguloon.Scenes; +using System.Collections.Generic; +using System; +using Microsoft.Xna.Framework.Graphics; +namespace Penguloon.Controls +{ + public class UpgradeMenu : ControlBase + { + public LevelBase Level { get; set; } + + public ButtonUpgradeMenu UpgradeMenuSell { get; set; } + + public MessageBox SellConfirmationBox { get; set; } + + public UpgradeMenu(LevelBase level, SceneBase parentScene, Vector2 position, Vector2 size) : base(parentScene, position, size) + { + this.Level = level; + this.BackgroundIdle = ContentManager.GetTexture("UI/objectSelectionBackground"); + this.BackgroundPressed = ContentManager.GetTexture("UI/objectSelectionBackground"); + this.BackgroundDisabled = ContentManager.GetTexture("UI/objectSelectionBackground"); + + Vector2 MsgBoxSize = new Vector2(900, 550); + + UpgradeMenuSell = new ButtonUpgradeMenu(parentScene, + new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth, StaticUIValues.ScreenViewport.Y - StaticUIValues.IngameUIPlayButtonHeight), + new Vector2(StaticUIValues.ScreenViewport.X - (Level.Map.MapWidth + StaticUIValues.BorderWidth), StaticUIValues.IngameUIPlayButtonHeight), parentScene.Main.Resources.GetString(Resource.String.UpgradeMenuSell)); + + SellConfirmationBox = new MessageBox(parentScene, + new Vector2((StaticUIValues.ScreenViewport.X / 2) - (MsgBoxSize.X / 2), (StaticUIValues.ScreenViewport.Y / 2) - (MsgBoxSize.Y / 2)), + MsgBoxSize, parentScene.Main.Resources.GetString(Resource.String.IngameOptionsQuitConfirmation)); + + UpgradeMenuSell.OnClick += UpgradeMenuSell_OnClick; + } + + private void UpgradeMenuSell_OnClick(object sender, ClickArgs e) + { + SellConfirmationBox.State = IngameOptionsState.Show; + SellConfirmationBox.ShowTime = DateTime.Now; + } + + public override void Draw(float deltaTime) + { + //background + ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/objectSelectionBackground"), + destinationRectangle: new Rectangle(Level.Map.MapWidth + StaticUIValues.BorderWidth, + 0, (int)StaticUIValues.ScreenViewport.X - (Level.Map.MapWidth + StaticUIValues.BorderWidth), (int)StaticUIValues.ScreenViewport.Y)); + + if (Level.SelectedObject != null) + { + for (int i = 0; i < Level.SelectedObject.UpgradeList.Count; i++) + { + Level.SelectedObject.UpgradeList[i].Draw(ParentScene.Main.SpriteBatch, i); + } + } + + UpgradeMenuSell.Draw(deltaTime); + + //border + ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/border"), + destinationRectangle: new Rectangle(Level.Map.MapWidth, + 0, StaticUIValues.BorderWidth, (int)StaticUIValues.ScreenViewport.Y)); + + //border above button + ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/border-horizontal"), + destinationRectangle: new Rectangle(Level.Map.MapWidth + StaticUIValues.BorderWidth - 4, + (int)StaticUIValues.ScreenViewport.Y - StaticUIValues.IngameUIPlayButtonHeight - StaticUIValues.BorderWidth, + (int)StaticUIValues.ScreenViewport.X - (Level.Map.MapWidth + StaticUIValues.BorderWidth - 5), StaticUIValues.BorderWidth)); + + //border under text + ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/border-horizontal"), + destinationRectangle: new Rectangle(Level.Map.MapWidth + StaticUIValues.BorderWidth - 4, + StaticUIValues.IngameUITextAreaHeight, (int)StaticUIValues.ScreenViewport.X - (Level.Map.MapWidth + StaticUIValues.BorderWidth - 5), StaticUIValues.BorderWidth)); + + ParentScene.DrawText(ContentManager.GetFont(StaticUIValues.IngameFont), ParentScene.Main.Resources.GetString(Resource.String.IngameGold) + ": " + Level.Money, + new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth + 5, 10), + new Vector2(StaticUIValues.ScreenViewport.X - Level.Map.MapWidth - StaticUIValues.BorderWidth, StaticUIValues.IngameUITextAreaHeight), + TextAllignment.LeftTop, Color.White, Color.Black, 2); + + ParentScene.DrawText(ContentManager.GetFont(StaticUIValues.IngameFont), ParentScene.Main.Resources.GetString(Resource.String.IngameWave) + ": " + Level.Map.WaveManager.CurrentWave.ToString(), + new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth + 5, 0), + new Vector2(StaticUIValues.ScreenViewport.X - Level.Map.MapWidth - StaticUIValues.BorderWidth, StaticUIValues.IngameUITextAreaHeight), + TextAllignment.LeftMiddle, Color.White, Color.Black, 2); + + ParentScene.DrawText(ContentManager.GetFont(StaticUIValues.IngameFont), ParentScene.Main.Resources.GetString(Resource.String.IngameHealth) + ": " + Level.Health, + new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth + 5, 0), + new Vector2(StaticUIValues.ScreenViewport.X - Level.Map.MapWidth - StaticUIValues.BorderWidth, StaticUIValues.IngameUITextAreaHeight), + TextAllignment.LeftBottom, Color.White, Color.Black, 2); + + SellConfirmationBox.Draw(deltaTime); + } + + + public override void Update(float deltaTime, TouchLocation[] touchLocations) + { + UpgradeMenuSell.Update(deltaTime, touchLocations); + SellConfirmationBox.Update(deltaTime, touchLocations); + + int startY = StaticUIValues.IngameUITextAreaHeight + StaticUIValues.BorderWidth; + + if (Level.SelectedObject != null) + { + // for each available upgrade in selected object + for (int i = 0; i < Level.SelectedObject.UpgradeList.Count; i++) + { + Level.SelectedObject.UpgradeList[i].State = Objects.UpgradeState.Idle; + + Rectangle upgradeBox = new Rectangle( + (int)Level.Map.MapWidth, + startY + (int)StaticUIValues.UpgradePanelSize.Y * i, + (int)StaticUIValues.UpgradePanelSize.X, + (int)StaticUIValues.UpgradePanelSize.Y); + + for (int x = 0; x < touchLocations.Length; x++) + { + // if finger is released on upgrade box + if (touchLocations[x].State == TouchLocationState.Released) + { + if (upgradeBox.Contains(touchLocations[x].Position.ToPoint())) + { + // continue of we cant afford this upgrade + if (Level.SelectedObject.UpgradeList[i].Cost > Level.Money) + { + SoundManager.PlayUnavailableSound(); + continue; + } + + Level.SelectedObject.UpgradeList[i].Click(); + + // pay upgrade cost + Level.Money -= Level.SelectedObject.UpgradeList[i].Cost; + + // play buy sound here + SoundManager.PlayUpgradeSound(); + + // insert next upgrade if present + if (Level.SelectedObject.UpgradeList[i].NextUgrade != null) + { + Level.SelectedObject.UpgradeList.Insert(i, Level.SelectedObject.UpgradeList[i].NextUgrade); + + // remove clicked upgrade + if (Level.SelectedObject.UpgradeList.Count > i + 1) + Level.SelectedObject.UpgradeList.RemoveAt(i + 1); + } + else + // remove clicked upgrade + if (Level.SelectedObject.UpgradeList.Count > i) + Level.SelectedObject.UpgradeList.RemoveAt(i); + } + } + else + { + if (upgradeBox.Contains(touchLocations[x].Position.ToPoint())) + { + Level.SelectedObject.UpgradeList[i].State = Objects.UpgradeState.Pressed; + } + } + } + } + } + } + } +}
\ No newline at end of file |
