summaryrefslogtreecommitdiff
path: root/Penguloon/Controls
diff options
context:
space:
mode:
authoraldrikboy <aldrikboy@gmail.com>2017-12-23 19:14:34 +0100
committeraldrikboy <aldrikboy@gmail.com>2017-12-23 19:14:34 +0100
commitad0d29bf5d881ab619a90ffb8a1f3352eba21615 (patch)
treec69fe6ea7212f2d839ca52e3adb523b27dc532b9 /Penguloon/Controls
parent1276593bfbbfcdbac24b48cf8b574da25945d763 (diff)
Communism
Diffstat (limited to 'Penguloon/Controls')
-rw-r--r--Penguloon/Controls/ControlBase.cs13
-rw-r--r--Penguloon/Controls/IngameOptions.cs110
-rw-r--r--Penguloon/Controls/LevelSelector.cs1
-rw-r--r--Penguloon/Controls/MessageBox.cs78
-rw-r--r--Penguloon/Controls/ObjectSelector.cs2
5 files changed, 201 insertions, 3 deletions
diff --git a/Penguloon/Controls/ControlBase.cs b/Penguloon/Controls/ControlBase.cs
index dea0bd7..42c729e 100644
--- a/Penguloon/Controls/ControlBase.cs
+++ b/Penguloon/Controls/ControlBase.cs
@@ -24,9 +24,13 @@ namespace Penguloon.Controls
public Texture2D BackgroundPressed { get; set; }
public Texture2D BackgroundDisabled { get; set; }
+ public event EventHandler OnMissClick;
public event EventHandler<ClickArgs> OnClick;
public event EventHandler<MoveArgs> OnMove;
+ public TextAllignment TextAllignment { get; set; } = TextAllignment.CenterMiddle;
+ public int PaddingTop { get; set; } = 0;
+
/// <summary>
/// Base constructor.
/// </summary>
@@ -65,7 +69,7 @@ namespace Penguloon.Controls
if (Font == null) return;
if (string.IsNullOrWhiteSpace(Text)) return;
- ParentScene.DrawText(Font, Text, Position, Size, TextAllignment.CenterMiddle, ForeColor, BorderColor, BorderWidth);
+ ParentScene.DrawText(Font, Text, new Vector2(Position.X, Position.Y + PaddingTop), Size, TextAllignment, ForeColor, BorderColor, BorderWidth);
}
/// <summary>
@@ -105,7 +109,12 @@ namespace Penguloon.Controls
return;
}
else
- this.ControlState = ControlState.Idle;
+ {
+ this.ControlState = ControlState.Idle;
+
+ if (touchLocations[i].State == TouchLocationState.Released)
+ OnMissClick?.Invoke(this, EventArgs.Empty);
+ }
}
}
}
diff --git a/Penguloon/Controls/IngameOptions.cs b/Penguloon/Controls/IngameOptions.cs
new file mode 100644
index 0000000..a7f1f00
--- /dev/null
+++ b/Penguloon/Controls/IngameOptions.cs
@@ -0,0 +1,110 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Input.Touch;
+using Penguloon.Scenes;
+using System;
+
+namespace Penguloon.Controls
+{
+ public enum IngameOptionsState
+ {
+ Show,
+ Hide
+ }
+
+ public class IngameOptions : ControlBase
+ {
+ public IngameOptionsState State { get; set; } = IngameOptionsState.Hide;
+
+ public DateTime ShowTime { get; set; }
+
+ public Button BtnContinue { get; set; }
+ public Button BtnQuit { get; set; }
+
+ public MessageBox QuitConfirmationBox { get; set; }
+ public DateTime ShowTimeMsgBox { get; set; }
+
+ public IngameOptions(SceneBase parentScene, Vector2 position, Vector2 size) : base(parentScene, position, size)
+ {
+ this.BackgroundIdle = ContentManager.GetTexture("UI/optionsMenuBackground");
+ this.BackgroundPressed = ContentManager.GetTexture("UI/optionsMenuBackground");
+ this.BackgroundDisabled = ContentManager.GetTexture("UI/optionsMenuBackground");
+
+ Vector2 BtnSize = new Vector2(Size.X - 90, StaticUIValues.IngameUIPlayButtonHeight);
+ Vector2 MsgBoxSize = new Vector2(900, 300);
+
+ BtnContinue = new Button(parentScene,
+ new Vector2(position.X + (Size.X / 2) - (BtnSize.X / 2), Position.Y + 50),
+ BtnSize, parentScene.Main.Resources.GetString(Resource.String.IngameOptionsContinue));
+
+ BtnQuit = new Button(parentScene,
+ new Vector2(position.X + (Size.X / 2) - (BtnSize.X / 2), Position.Y + Size.Y - 50 - BtnSize.Y),
+ BtnSize, parentScene.Main.Resources.GetString(Resource.String.IngameOptionsQuit));
+
+ QuitConfirmationBox = 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));
+
+ BtnContinue.OnClick += BtnContinue_OnClick;
+ BtnQuit.OnClick += BtnQuit_OnClick;
+
+ OnMissClick += IngameOptions_OnMissClick;
+ QuitConfirmationBox.OnMissClick += QuitConfirmationBox_OnMissClick;
+ QuitConfirmationBox.OnYes += QuitConfirmationBox_OnYes;
+ }
+
+ private void QuitConfirmationBox_OnYes(object sender, EventArgs e)
+ {
+ SceneManager.SelectedScene = SelectedScene.Menu;
+ }
+
+ private void QuitConfirmationBox_OnMissClick(object sender, EventArgs e)
+ {
+ ShowTimeMsgBox = DateTime.Now;
+ }
+
+ private void BtnQuit_OnClick(object sender, ClickArgs e)
+ {
+ QuitConfirmationBox.State = IngameOptionsState.Show;
+ }
+
+ private void BtnContinue_OnClick(object sender, ClickArgs e)
+ {
+ this.State = IngameOptionsState.Hide;
+ }
+
+ private void IngameOptions_OnMissClick(object sender, System.EventArgs e)
+ {
+ if((DateTime.Now - ShowTime).TotalMilliseconds > 200)
+ {
+ State = IngameOptionsState.Hide;
+ }
+ }
+
+ public override void Draw(float deltaTime)
+ {
+ if (State == IngameOptionsState.Hide) return;
+
+ base.Draw(deltaTime);
+
+ BtnContinue.Draw(deltaTime);
+ BtnQuit.Draw(deltaTime);
+ QuitConfirmationBox.Draw(deltaTime);
+ }
+
+ public override void Update(float deltaTime, TouchLocation[] touchLocations)
+ {
+ if (State == IngameOptionsState.Hide) return;
+
+ QuitConfirmationBox.Update(deltaTime, touchLocations);
+
+ if (QuitConfirmationBox.State == IngameOptionsState.Show) return;
+
+ if ((DateTime.Now - ShowTimeMsgBox).TotalMilliseconds <= 200) return;
+
+ base.Update(deltaTime, touchLocations);
+
+ BtnContinue.Update(deltaTime, touchLocations);
+ BtnQuit.Update(deltaTime, touchLocations);
+ }
+ }
+} \ No newline at end of file
diff --git a/Penguloon/Controls/LevelSelector.cs b/Penguloon/Controls/LevelSelector.cs
index 1e26fcc..6437773 100644
--- a/Penguloon/Controls/LevelSelector.cs
+++ b/Penguloon/Controls/LevelSelector.cs
@@ -55,6 +55,7 @@ namespace Penguloon.Controls
if (Panel2.Intersects(fingerRec))
{
+ SoundManager.PlayClickSound();
SceneManager.GameScene = new GameScene(ParentScene.Main, Levels[selectedMap]);
SceneManager.SelectedScene = SelectedScene.Ingame;
}
diff --git a/Penguloon/Controls/MessageBox.cs b/Penguloon/Controls/MessageBox.cs
new file mode 100644
index 0000000..48ba992
--- /dev/null
+++ b/Penguloon/Controls/MessageBox.cs
@@ -0,0 +1,78 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Input.Touch;
+using Penguloon.Scenes;
+using System;
+
+namespace Penguloon.Controls
+{
+ public class MessageBox : ControlBase
+ {
+ public IngameOptionsState State { get; set; } = IngameOptionsState.Hide;
+
+ public DateTime ShowTime { get; set; }
+
+ public Button BtnYes { get; set; }
+ public Button BtnNo { get; set; }
+
+ public event EventHandler OnYes;
+ public event EventHandler OnNo;
+
+ public MessageBox(SceneBase parentScene, Vector2 position, Vector2 size, string text) : base(parentScene, position, size)
+ {
+ this.BackgroundIdle = ContentManager.GetTexture("UI/msgBoxBackground");
+ this.BackgroundPressed = ContentManager.GetTexture("UI/msgBoxBackground");
+ this.BackgroundDisabled = ContentManager.GetTexture("UI/msgBoxBackground");
+
+ this.Text = text;
+ this.Font = ContentManager.GetFont("Fonts/GWENT/36");
+ this.ForeColor = Color.White;
+ this.BorderColor = Color.Black;
+ this.BorderWidth = 2;
+ this.TextAllignment = TextAllignment.CenterTop;
+ this.PaddingTop = 35;
+
+ Vector2 BtnSize = new Vector2((Size.X - 135) / 2, StaticUIValues.IngameUIPlayButtonHeight);
+
+ BtnYes = new Button(parentScene,
+ new Vector2(position.X + 45, Position.Y + Size.Y - BtnSize.Y - 45),
+ BtnSize, parentScene.Main.Resources.GetString(Resource.String.IngameYes));
+
+ BtnNo = new Button(parentScene,
+ new Vector2(position.X + Size.X - BtnSize.X - 45, Position.Y + Size.Y - BtnSize.Y - 45),
+ BtnSize, parentScene.Main.Resources.GetString(Resource.String.IngameNo));
+
+ OnMissClick += IngameOptions_OnMissClick;
+
+ BtnYes.OnClick += delegate { OnYes?.Invoke(this, EventArgs.Empty); this.State = IngameOptionsState.Hide; };
+ BtnNo.OnClick += delegate { OnNo?.Invoke(this, EventArgs.Empty); this.State = IngameOptionsState.Hide; };
+ }
+
+ private void IngameOptions_OnMissClick(object sender, System.EventArgs e)
+ {
+ if ((DateTime.Now - ShowTime).TotalMilliseconds > 200)
+ {
+ State = IngameOptionsState.Hide;
+ }
+ }
+
+ public override void Draw(float deltaTime)
+ {
+ if (State == IngameOptionsState.Hide) return;
+
+ base.Draw(deltaTime);
+
+ BtnYes.Draw(deltaTime);
+ BtnNo.Draw(deltaTime);
+ }
+
+ public override void Update(float deltaTime, TouchLocation[] touchLocations)
+ {
+ if (State == IngameOptionsState.Hide) return;
+
+ base.Update(deltaTime, touchLocations);
+
+ BtnYes.Update(deltaTime, touchLocations);
+ BtnNo.Update(deltaTime, touchLocations);
+ }
+ }
+} \ No newline at end of file
diff --git a/Penguloon/Controls/ObjectSelector.cs b/Penguloon/Controls/ObjectSelector.cs
index 44b68c3..a155601 100644
--- a/Penguloon/Controls/ObjectSelector.cs
+++ b/Penguloon/Controls/ObjectSelector.cs
@@ -117,7 +117,7 @@ namespace Penguloon.Controls
if(State == State.Selected && i == SelectedObjectIndex)
{
- ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/red"),
+ ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/lightred"),
destinationRectangle: new Rectangle(posX, (int)Position.Y + posY, width, height));
}