Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 129 lines (118 sloc) 5.391 kb
c951672 [T4NET] Implémentation de toutes les règles de base, schéma de contrô…
Erhune authored
1 using System;
2 using System.Collections.Generic;
3 using Microsoft.Xna.Framework.Input;
4
5 namespace T4NET
6 {
7 public class ContolsState
8 {
9 private static readonly Buttons[] ALL_BUTTONS = new[]
10 {
11 Buttons.A,
12 Buttons.B,
13 Buttons.Back,
14 Buttons.BigButton,
15 Buttons.DPadDown,
16 Buttons.DPadLeft,
17 Buttons.DPadRight,
18 Buttons.DPadUp,
19 Buttons.LeftShoulder,
20 Buttons.LeftStick,
21 Buttons.LeftThumbstickDown,
22 Buttons.LeftThumbstickLeft,
23 Buttons.LeftThumbstickRight,
24 Buttons.LeftThumbstickUp,
25 Buttons.LeftTrigger,
26 Buttons.RightShoulder,
27 Buttons.RightStick,
28 Buttons.RightThumbstickDown,
29 Buttons.RightThumbstickLeft,
30 Buttons.RightThumbstickRight,
31 Buttons.RightThumbstickUp,
32 Buttons.RightTrigger,
33 Buttons.Start,
34 Buttons.X,
35 Buttons.Y
36 };
37
38 private readonly List<Buttons> m_pressedButtons = new List<Buttons>();
39
40 private readonly List<Keys> m_pressedKeys = new List<Keys>();
41 private readonly List<Buttons> m_previouslyPressedButtons = new List<Buttons>();
42 private readonly List<Keys> m_previouslyPressedKeys = new List<Keys>();
43 private readonly List<Buttons> m_releasedButtons = new List<Buttons>();
44 private readonly List<Keys> m_releasedKeys = new List<Keys>();
45 private KeyboardState m_keyboardState;
46 private GamePadState m_padState;
47
48 public KeyboardState KeyboardState
49 {
50 get { return m_keyboardState; }
51 }
52
53 public List<Keys> PressedKeys
54 {
55 get { return m_pressedKeys; }
56 }
57
58 public List<Keys> ReleasedKeys
59 {
60 get { return m_releasedKeys; }
61 }
62
63 public GamePadState PadState
64 {
65 get { return m_padState; }
66 }
67
68 public List<Buttons> PressedButtons
69 {
70 get { return m_pressedButtons; }
71 }
72
73 public List<Buttons> ReleasedButtons
74 {
75 get { return m_releasedButtons; }
76 }
77
78 public void ComputeState(KeyboardState keyboardState, GamePadState padState)
79 {
80 // Compute newly pressed & relased key set
81 m_keyboardState = keyboardState;
82 m_pressedKeys.Clear();
83 m_releasedKeys.Clear();
84 foreach (Keys key in keyboardState.GetPressedKeys())
85 {
86 if (!m_previouslyPressedKeys.Contains(key))
87 {
88 m_pressedKeys.Add(key);
89 }
90 }
91 foreach (Keys key in m_previouslyPressedKeys)
92 {
93 if (keyboardState.IsKeyUp(key))
94 {
95 m_releasedKeys.Add(key);
96 }
97 }
98 m_previouslyPressedKeys.Clear();
99 m_previouslyPressedKeys.AddRange(keyboardState.GetPressedKeys());
100
101 // Compute pad state
102 m_padState = padState;
103 m_pressedButtons.Clear();
104 m_releasedButtons.Clear();
105 if (padState.IsConnected)
106 {
107 foreach (Buttons button in ALL_BUTTONS)
108 {
109 if (padState.IsButtonDown(button) && !m_previouslyPressedButtons.Contains(button))
110 {
111 m_pressedButtons.Add(button);
112 }
113 else if (padState.IsButtonUp(button) && m_previouslyPressedButtons.Contains(button))
114 {
115 m_releasedButtons.Add(button);
116 }
117 }
118 m_previouslyPressedButtons.Clear();
119 foreach (Buttons button in ALL_BUTTONS)
120 {
121 if (padState.IsButtonDown(button))
122 {
123 m_previouslyPressedButtons.Add(button);
124 }
125 }
126 }
127 }
128 }
129 }
Something went wrong with that request. Please try again.