-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cs
More file actions
64 lines (58 loc) · 1.86 KB
/
Menu.cs
File metadata and controls
64 lines (58 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Microsoft.Xna.Framework;
using Dungeon_Delvers.Managers;
using Dungeon_Delvers.Data_Structures;
using Microsoft.Xna.Framework.Graphics;
namespace Dungeon_Delvers;
class Menu
{
Vector2 PADDING = new Vector2(30, 10);
LinkedList<string> options = new LinkedList<string>();
int hoveringOver = 0;
// Returns:
// * <Number> where <number> is index of menu option chosen
// * Null if menu should stay open
// * -1 if menu should close with no chosen option
public int? Update(string[] args)
{
options.Reset();
foreach (string s in args) options.Add(s);
switch (InputManager.PressedDirection)
{
case Directions.Up:
// Modulus is to enable wraparound
hoveringOver = System.Math.Abs((--hoveringOver) % args.Length);
break;
case Directions.Down:
// Modulus is to enable wraparound
hoveringOver = (++hoveringOver) % args.Length;
break;
default:
break;
}
if (InputManager.InteractPressed) return hoveringOver;
else if (InputManager.PressedKey(Microsoft.Xna.Framework.Input.Keys.Q))
{
return -1;
}
else return null;
}
public void Draw(SpriteFont font)
{
Vector2 pos = new Vector2(0, 0);
int convertedHover = options.Count - 1 - hoveringOver;
for (int i = options.Count - 1; i >= 0; i--)
{
if (i == convertedHover)
{
Globals.sprites.DrawString(font, options.Get(i), pos + PADDING,
Color.Yellow);
}
else
{
Globals.sprites.DrawString(font, options.Get(i), pos + PADDING,
Color.Black);
}
pos.Y += 25;
}
}
}