summaryrefslogtreecommitdiff
path: root/Penguloon/Controls
diff options
context:
space:
mode:
authoraldrikboy <aldrikboy@gmail.com>2017-12-22 20:30:25 +0100
committeraldrikboy <aldrikboy@gmail.com>2017-12-22 20:30:25 +0100
commit1276593bfbbfcdbac24b48cf8b574da25945d763 (patch)
tree3d9e8a4153b5b369184b7c7de55461bd1573d30a /Penguloon/Controls
parent12c565cbb7208b44bd7654289bbac2824901f118 (diff)
ZULUL
Diffstat (limited to 'Penguloon/Controls')
-rw-r--r--Penguloon/Controls/Button.cs2
-rw-r--r--Penguloon/Controls/ButtonIngame.cs28
-rw-r--r--Penguloon/Controls/ObjectSelector.cs145
-rw-r--r--Penguloon/Controls/SpeedButton.cs28
4 files changed, 202 insertions, 1 deletions
diff --git a/Penguloon/Controls/Button.cs b/Penguloon/Controls/Button.cs
index 121321c..757b87d 100644
--- a/Penguloon/Controls/Button.cs
+++ b/Penguloon/Controls/Button.cs
@@ -3,7 +3,7 @@ using Penguloon.Scenes;
namespace Penguloon.Controls
{
- class Button : ControlBase
+ public class Button : ControlBase
{
public Button(SceneBase parentScene, Vector2 position, Vector2 size, string text) : base(parentScene, position, size)
{
diff --git a/Penguloon/Controls/ButtonIngame.cs b/Penguloon/Controls/ButtonIngame.cs
new file mode 100644
index 0000000..acb05e0
--- /dev/null
+++ b/Penguloon/Controls/ButtonIngame.cs
@@ -0,0 +1,28 @@
+using Microsoft.Xna.Framework;
+using Penguloon.Scenes;
+
+namespace Penguloon.Controls
+{
+ public class ButtonIngame : ControlBase
+ {
+ public ButtonIngame(SceneBase parentScene, Vector2 position, Vector2 size, string text) : base(parentScene, position, size)
+ {
+ this.BackgroundIdle = ContentManager.GetTexture("UI/btnIdleIngame");
+ this.BackgroundPressed = ContentManager.GetTexture("UI/btnPressedIngame");
+ this.BackgroundDisabled = ContentManager.GetTexture("UI/btnDisabledIngame");
+ this.Text = text;
+
+ this.ForeColor = Color.Gray;
+ 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/ObjectSelector.cs b/Penguloon/Controls/ObjectSelector.cs
new file mode 100644
index 0000000..44b68c3
--- /dev/null
+++ b/Penguloon/Controls/ObjectSelector.cs
@@ -0,0 +1,145 @@
+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;
+
+namespace Penguloon.Controls
+{
+ public enum State
+ {
+ Selected,
+ Idle,
+ }
+
+ public class ObjectSelector : ControlBase
+ {
+ public State State { get; set; }
+
+ public int SelectedObjectIndex { get; set; } = -1;
+
+ public Map Map { get; set; }
+
+ public List<Tuple<ObjectBase, int>> Objects { get; set; } = new List<Tuple<ObjectBase, int>>();
+
+ public ObjectSelector(Map map, SceneBase parentScene, Vector2 position, Vector2 size) : base(parentScene, position, size)
+ {
+ this.Map = map;
+ this.BackgroundIdle = ContentManager.GetTexture("UI/objectSelectionBackground");
+ this.BackgroundPressed = ContentManager.GetTexture("UI/objectSelectionBackground");
+ this.BackgroundDisabled = ContentManager.GetTexture("UI/objectSelectionBackground");
+
+ this.OnClick += ObjectSelector_OnClick;
+
+ LoadObjects();
+ }
+
+ private void ObjectSelector_OnClick(object sender, ClickArgs e)
+ {
+ int rows = 4;
+
+ if (Objects.Count > 8)
+ {
+ rows = (int)Math.Ceiling((double)Objects.Count / 2);
+ }
+
+ int width = (int)Size.X / 2;
+ int height = (int)Size.Y / rows;
+
+ int oddX = (int)Position.X;
+ int evenX = (int)Position.X + width;
+
+ Rectangle fingerRec = new Rectangle((int)e.ClickPosition.X, (int)e.ClickPosition.Y, 1, 1);
+
+ for (int i = 0; i < Objects.Count; i++)
+ {
+ if (Objects[i].Item2 > Map.Level.Money) continue;
+
+ int posX = ((i + 1) % 2 != 0) ? oddX : evenX;
+ int posY = (i / 2) * height;
+
+ Rectangle rec = new Rectangle(posX, (int)Position.Y + posY, width, height);
+
+ if (fingerRec.Intersects(rec))
+ {
+ if (SelectedObjectIndex != i)
+ {
+ SelectedObjectIndex = i;
+ State = State.Selected;
+ }
+ else
+ {
+ SelectedObjectIndex = -1;
+ State = State.Idle;
+ }
+ return;
+ }
+ }
+ }
+
+ private void LoadObjects()
+ {
+ Objects.Add(new Tuple<ObjectBase,int>(new PenguinObject(Map), 250));
+ Objects.Add(new Tuple<ObjectBase, int>(new GoldPenguinObject(Map), 360));
+ Objects.Add(new Tuple<ObjectBase, int>(new CannonObject(Map), 650));
+ }
+
+ public override void Update(float deltaTime, TouchLocation[] touchLocations)
+ {
+ base.Update(deltaTime, touchLocations);
+ }
+
+ public override void Draw(float deltaTime)
+ {
+ base.Draw(deltaTime);
+
+ int rows = 4;
+
+ if(Objects.Count > 8)
+ {
+ rows = (int)Math.Ceiling((double)Objects.Count / 2);
+ }
+
+ int width = (int)Size.X / 2;
+ int height = (int)Size.Y / rows;
+
+ int oddX = (int)Position.X;
+ int evenX = (int)Position.X + width;
+
+ int padding = 15;
+
+ for (int i = 0; i < Objects.Count; i++)
+ {
+ int posX = ((i+1) % 2 != 0) ? oddX : evenX;
+ int posY = (i / 2) * height;
+
+ if(State == State.Selected && i == SelectedObjectIndex)
+ {
+ ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/red"),
+ destinationRectangle: new Rectangle(posX, (int)Position.Y + posY, width, height));
+ }
+
+ int widthToDraw = height - (padding * 2);
+
+ ParentScene.Main.SpriteBatch.Draw(Objects[i].Item1.Texture,
+ destinationRectangle: new Rectangle(posX + (width - widthToDraw) / 2, (int)Position.Y + posY + padding, widthToDraw, height - (padding * 2)));
+
+ ParentScene.DrawText(ContentManager.GetFont("Fonts/GWENT/36"), Objects[i].Item2.ToString(), new Vector2(posX, (int)Position.Y + posY),
+ new Vector2(width, height), TextAllignment.CenterBottom, Color.White, Color.Black, 2);
+ }
+
+ // Draw borders
+ ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/objectSelectionBorder"),
+ destinationRectangle: new Rectangle(evenX - 2, (int)Position.Y, 4, (int)Size.Y));
+
+ for(int x = 1; x < rows; x++)
+ {
+ // Draw borders
+ ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/objectSelectionBorder"),
+ destinationRectangle: new Rectangle(oddX, (int)Position.Y + (x * height), (int)Size.X, 4));
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Penguloon/Controls/SpeedButton.cs b/Penguloon/Controls/SpeedButton.cs
new file mode 100644
index 0000000..ee11d95
--- /dev/null
+++ b/Penguloon/Controls/SpeedButton.cs
@@ -0,0 +1,28 @@
+using Microsoft.Xna.Framework;
+using Penguloon.Scenes;
+
+namespace Penguloon.Controls
+{
+ public class SpeedButton : ControlBase
+ {
+ public SpeedButton(SceneBase parentScene, Vector2 position, Vector2 size, string text) : base(parentScene, position, size)
+ {
+ this.BackgroundIdle = ContentManager.GetTexture("");
+ this.BackgroundPressed = ContentManager.GetTexture("");
+ this.BackgroundDisabled = ContentManager.GetTexture("");
+ 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