-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonControl.cs
More file actions
104 lines (92 loc) · 3.82 KB
/
ButtonControl.cs
File metadata and controls
104 lines (92 loc) · 3.82 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using Microsoft.Xna.Framework.Input;
using System;
namespace ButtonMash
{
public class ButtonControl
{
public override void Update(double dt)
{
var keyboardState = Keyboard.GetState();
foreach(var buttonComponentEntity in ReadEntities<ButtonComponent>())
{
var buttonComponent = GetComponent<ButtonComponent>(buttonComponentEntity);
var playerIndex = Microsoft.Xna.Framework.PlayerIndex.One;
switch(buttonComponent.Player)
{
case Player.One:
playerIndex = Microsoft.Xna.Framework.PlayerIndex.One;
break;
case Player.Two:
playerIndex = Microsoft.Xna.Framework.PlayerIndex.Two;
break;
case Player.Three:
playerIndex = Microsoft.Xna.Framework.PlayerIndex.Three;
break;
}
var gamePadState = GamePad.GetState(playerIndex);
var new_ActionState = buttonComponent.ActionState;
var new_TimeHeld = buttonComponent.TimeHeld;
var buttonDown = false;
foreach(var button in buttonComponent.Buttons)
{
if (gamePadState.IsButtonDown(button))
{
buttonDown = true;
GamePad.SetVibration(playerIndex, 1, 1);
GamePad.SetLightBarEXT(playerIndex, new Microsoft.Xna.Framework.Color((float)MathHelper.RandomDouble(0, 1), (float)MathHelper.RandomDouble(0, 1), (float)MathHelper.RandomDouble(0, 1)));
}
}
foreach(var key in buttonComponent.Keys)
{
if (keyboardState.IsKeyDown(key))
{
buttonDown = true;
}
}
if (buttonDown)
{
new_ActionState = PressButton(new_ActionState);
new_TimeHeld += (float)dt;
}
else
{
new_ActionState = ReleaseButton(new_ActionState);
new_TimeHeld = 0;
}
if (new_ActionState != ActionState.None)
{
if(new_ActionState == ActionState.Pressed)
{
var datevalue = DateTime.Now;
//System.Console.WriteLine("{0} seconds input", datevalue.ToString("s.ffffff"));
}
//System.Console.WriteLine(ButtonName.ToString() + " is " + buttonState.ToString() + " " + TimeHeld);
SendMessage(new InputMessage(buttonComponent.Player, buttonComponent.ButtonName, new_ActionState, new_TimeHeld));
}
SetComponent(buttonComponentEntity, new ButtonComponent(buttonComponent.Player, buttonComponent.ButtonName, buttonComponent.Keys, buttonComponent.Buttons, new_TimeHeld, new_ActionState));
}
}
public ActionState PressButton(ActionState button)
{
switch(button)
{
case ActionState.Pressed:
case ActionState.Held:
return ActionState.Held;
default:
return ActionState.Pressed;
}
}
public ActionState ReleaseButton(ActionState button)
{
switch(button)
{
case ActionState.Released:
case ActionState.None:
return ActionState.None;
default:
return ActionState.Released;
}
}
}
}