Files

113 lines
3.3 KiB
C#
Raw Permalink Normal View History

2021-04-22 23:03:05 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EvilSatellites.Menu;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using DavyKager;
namespace EvilSatellites.Screens
{
public class MenuScreen : IScreen
{
public MenuContainer MenuOptions;
public int CursorPosition;
public ScreenManager _Manager;
public ScreenState _State;
public InputManager Inputs = new InputManager();
2021-04-24 02:47:17 +02:00
private double DescWaitTime;
private bool DescRead;
2021-04-23 15:07:50 +02:00
public ScreenManager Manager { get => _Manager; set => _Manager = value; }
public ScreenState State { get => _State; set => _State = value; }
public virtual void Activate()
2021-04-22 23:03:05 +02:00
{
CursorPosition = 0;
2021-04-25 02:07:37 +02:00
Tolk.Output(MenuOptions.Title, false);
2021-04-22 23:03:05 +02:00
Tolk.Output(MenuOptions.Description, false);
Tolk.Output(MenuOptions.Entries[CursorPosition].Name);
2021-04-23 15:07:50 +02:00
Manager.Sound.PlayOneshot(@"sfx/ui/menuOpen.wav");
2021-04-23 20:28:06 +02:00
Manager.Music.Play("menu1");
2021-04-24 02:47:17 +02:00
DescWaitTime = 0;
DescRead = false;
2021-04-22 23:03:05 +02:00
}
2021-04-23 15:07:50 +02:00
public virtual void Deactivate()
2021-04-22 23:03:05 +02:00
{
return;
}
2021-04-23 15:07:50 +02:00
public void HandleInput(GameTime gameTime, KeyboardState inputs)
2021-04-22 23:03:05 +02:00
{
Inputs.Update();
2021-04-24 02:47:17 +02:00
if (Inputs.IsJustPressed(Keys.Down) || Inputs.IsJustPressed(Buttons.DPadDown))
2021-04-22 23:03:05 +02:00
{
NextItem();
}
2021-04-24 02:47:17 +02:00
if (Inputs.IsJustPressed(Keys.Up) || Inputs.IsJustPressed(Buttons.DPadUp))
2021-04-22 23:03:05 +02:00
{
PreviousItem();
}
2021-04-24 02:47:17 +02:00
if (Inputs.IsJustPressed(Keys.Enter) || Inputs.IsJustPressed(Buttons.A))
2021-04-22 23:03:05 +02:00
{
SelectItem();
}
}
2021-04-23 15:07:50 +02:00
public virtual void Update(GameTime gameTime)
2021-04-22 23:03:05 +02:00
{
2021-04-23 15:07:50 +02:00
Manager.Sound.Update();
2021-04-24 02:47:17 +02:00
DescWaitTime += gameTime.ElapsedGameTime.TotalMilliseconds;
if (DescWaitTime > 2000 && DescRead == false)
{
Tolk.Output(MenuOptions.Entries[CursorPosition].Description, false);
DescRead = true;
}
2021-04-22 23:03:05 +02:00
}
public void PreviousItem()
{
2021-04-23 15:07:50 +02:00
CursorPosition -= 1;
2021-04-22 23:03:05 +02:00
CheckMenuBounds();
ReadMenuItem();
}
public void NextItem()
{
2021-04-23 15:07:50 +02:00
CursorPosition += 1;
2021-04-22 23:03:05 +02:00
CheckMenuBounds();
ReadMenuItem();
}
public void CheckMenuBounds()
{
if (CursorPosition > MenuOptions.Entries.Count-1)
{
CursorPosition = 0;
2021-04-23 15:07:50 +02:00
Manager.Sound.PlayOneshot(@"sfx/ui/menuBoundary.wav");
2021-04-22 23:03:05 +02:00
}
if (CursorPosition < 0)
{
2021-04-23 15:07:50 +02:00
CursorPosition = MenuOptions.Entries.Count-1;
Manager.Sound.PlayOneshot(@"sfx/ui/menuBoundary.wav");
2021-04-22 23:03:05 +02:00
}
}
public void ReadMenuItem()
{
2021-04-23 15:07:50 +02:00
Manager.Sound.PlayOneshot(@"sfx/ui/menuMove.wav");
2021-04-22 23:03:05 +02:00
Tolk.Output(MenuOptions.Entries[CursorPosition].Name, true);
2021-04-24 02:47:17 +02:00
DescRead = false;
DescWaitTime = 0;
2021-04-22 23:03:05 +02:00
}
2021-04-23 15:07:50 +02:00
public virtual void SelectItem()
2021-04-22 23:03:05 +02:00
{
2021-04-23 21:08:37 +02:00
Manager.Sound.PlayOneshot(@"sfx/ui/menuChoose.wav");
2021-04-22 23:03:05 +02:00
return;
}
}
}