summaryrefslogtreecommitdiff
path: root/Penguloon/Controls
diff options
context:
space:
mode:
Diffstat (limited to 'Penguloon/Controls')
-rw-r--r--Penguloon/Controls/ButtonUpgradeMenu.cs28
-rw-r--r--Penguloon/Controls/UpgradeMenu.cs166
2 files changed, 194 insertions, 0 deletions
diff --git a/Penguloon/Controls/ButtonUpgradeMenu.cs b/Penguloon/Controls/ButtonUpgradeMenu.cs
new file mode 100644
index 0000000..c612ac6
--- /dev/null
+++ b/Penguloon/Controls/ButtonUpgradeMenu.cs
@@ -0,0 +1,28 @@
+using Microsoft.Xna.Framework;
+using Penguloon.Scenes;
+
+namespace Penguloon.Controls
+{
+ public class ButtonUpgradeMenu : ControlBase
+ {
+ public ButtonUpgradeMenu(SceneBase parentScene, Vector2 position, Vector2 size, string text) : base(parentScene, position, size)
+ {
+ this.BackgroundIdle = ContentManager.GetTexture("UI/darkred");
+ this.BackgroundPressed = ContentManager.GetTexture("UI/red");
+ this.BackgroundDisabled = ContentManager.GetTexture("UI/red");
+ this.Text = text;
+
+ this.ForeColor = Color.White;
+ this.BorderColor = Color.Black;
+ this.BorderWidth = 2;
+ this.Font = ContentManager.GetFont(StaticUIValues.MenuFont);
+
+ OnClick += Button_OnClick;
+ }
+
+ private void Button_OnClick(object sender, ClickArgs e)
+ {
+ SoundManager.PlayClickSound();
+ }
+ }
+} \ No newline at end of file
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