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); } } }