OneNightDuel/ONDClient/GUI/ReturnToMenuElement.cs

42 lines
1.5 KiB
C#
Raw Normal View History

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGameLibrary.Input;
using ONDClient.Net;
namespace ONDClient.GUI;
public class ReturnToMenuElement : TextUIElement{
private bool listening = false;
private InputListenerHook inputHook;
public ReturnToMenuElement(Point corner1, SpriteFont font, Alignment alignment = Alignment.CENTER) : base(corner1, font, alignment, false) {
Visible = false;
Text = "Press Space to return to main menu";
inputHook = new InputListenerHook(false);
InputManager.AddListener("return-to-menu",Keys.Space, () => {
UIManager.DisplayMainMenu();
listening = false;
Visible = false;
Client.Disconnect();
},
InputTiming.PRESS, inputHook);
}
public override void Update() {
if ((Client.State == Client.ConnectionState.IDLE || Client.State == Client.ConnectionState.DISCONNECTED || Client.State == Client.ConnectionState.ACCEPTED) &&
(Screen.CurrentScreen.Label == UIManager.ScreenTypes.LOADING || Screen.CurrentScreen.Label == UIManager.ScreenTypes.LOSE || Screen.CurrentScreen.Label == UIManager.ScreenTypes.WIN)){
if (!listening){
listening = true;
Visible = true;
inputHook.Enabled = true;
}
}
else {
Visible = false;
listening = false;
inputHook.Enabled = false;
}
}
}