-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.cs
80 lines (71 loc) · 2.58 KB
/
Menu.cs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
namespace numBlock
{
class Menu
{
public int menuOptionIndex;
public int[] indexes;
int x = 0;
int mouseDownInitPos = 0;
public bool dragged = false;
public Menu(int x_offset,int[] optionIndexes)
{
x = x_offset;
menuOptionIndex = 0;
indexes = optionIndexes;
}
public bool HandleMenuInput(MouseState mouseState, MouseState prevMouseState, KeyboardState keyState, KeyboardState prevKeyState)
{
bool playPing = false;
int MAX_MENU_INDEX = indexes.Count() - 1;
if (mouseState.LeftButton == ButtonState.Pressed)
{
/*
* Check the drag height
*/
if (prevMouseState.LeftButton == ButtonState.Released)
{
dragged = false;
mouseDownInitPos = mouseState.Y;
}
else
{
int indexChangeAmount = (int)((mouseState.Y - mouseDownInitPos) / 45);
int newIndex = menuOptionIndex + indexChangeAmount;
if (newIndex < 0)
newIndex = 0;
else if (newIndex > MAX_MENU_INDEX)
newIndex = MAX_MENU_INDEX;
if (newIndex != menuOptionIndex)
{
dragged = true;
mouseDownInitPos = mouseState.Y;
menuOptionIndex = newIndex;
playPing = true;
}
}
} else {
if ((keyState.IsKeyDown(Keys.Up) && prevKeyState.IsKeyDown(Keys.Up) == false || mouseState.ScrollWheelValue > prevMouseState.ScrollWheelValue) && menuOptionIndex > 0)
{
menuOptionIndex--;
playPing = true;
}
if ((keyState.IsKeyDown(Keys.Down) && prevKeyState.IsKeyDown(Keys.Down) == false || mouseState.ScrollWheelValue < prevMouseState.ScrollWheelValue) && menuOptionIndex < MAX_MENU_INDEX)
{
menuOptionIndex++;
playPing = true;
}
}
return playPing;
}
public Vector2 GetMenuIndexVector()
{
return new Vector2(this.x, this.indexes[menuOptionIndex]);
}
}
}