diff options
| author | aldrikboy <aldrikboy@gmail.com> | 2017-12-23 19:14:34 +0100 |
|---|---|---|
| committer | aldrikboy <aldrikboy@gmail.com> | 2017-12-23 19:14:34 +0100 |
| commit | ad0d29bf5d881ab619a90ffb8a1f3352eba21615 (patch) | |
| tree | c69fe6ea7212f2d839ca52e3adb523b27dc532b9 /Penguloon/Controls/MessageBox.cs | |
| parent | 1276593bfbbfcdbac24b48cf8b574da25945d763 (diff) | |
Communism
Diffstat (limited to 'Penguloon/Controls/MessageBox.cs')
| -rw-r--r-- | Penguloon/Controls/MessageBox.cs | 78 |
1 files changed, 78 insertions, 0 deletions
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 |
