Client LuaCsForBarotrauma
BarotraumaShared/SharedSource/PlayerInput.cs
1 using System.Collections.Generic;
2 
3 namespace Barotrauma
4 {
5  class Key
6  {
7  private bool hit, hitQueue;
8  private bool held, heldQueue;
9 
10 
11  private InputType inputType;
12 
13  public Key(InputType inputType)
14  {
15  this.inputType = inputType;
16  }
17 #if CLIENT
18  private KeyOrMouse binding
19  {
20  get { return GameSettings.CurrentConfig.KeyMap.Bindings[inputType]; }
21  }
22 
23  private static bool AllowOnGUI(InputType input)
24  {
25  switch (input)
26  {
27  case InputType.Attack:
28  case InputType.Shoot:
29  return GUI.MouseOn == null;
30  default:
31  return true;
32  }
33  }
34 
36  {
37  get { return binding; }
38  }
39 
40  public void SetState()
41  {
42  hit = binding.IsHit() && AllowOnGUI(inputType);
43  if (hit) hitQueue = true;
44 
45  held = binding.IsDown() && AllowOnGUI(inputType);
46  if (held) heldQueue = true;
47  }
48 #endif
49 
50  public bool Hit
51  {
52  get
53  {
54  return hit;
55  }
56  set
57  {
58  hit = value;
59  }
60  }
61 
62  public bool Held
63  {
64  get
65  {
66  return held;
67  }
68  set
69  {
70  held = value;
71  }
72  }
73 
74 
75  public void SetState(bool hit, bool held)
76  {
77  if (hit) hitQueue = true;
78  if (held) heldQueue = true;
79  }
80 
81  public bool DequeueHit()
82  {
83  bool value = hitQueue;
84  hitQueue = false;
85  return value;
86  }
87 
88  public bool DequeueHeld()
89  {
90  bool value = heldQueue;
91  heldQueue = false;
92  return value;
93  }
94 
95  public bool GetHeldQueue
96  {
97  get { return heldQueue; }
98  }
99 
100  public bool GetHitQueue
101  {
102  get { return hitQueue; }
103  }
104 
105  public void Reset()
106  {
107  hit = false;
108  held = false;
109  }
110 
111  public void ResetHit()
112  {
113  hit = false;
114  //stateQueue = false;
115  }
116 
117  public void ResetHeld()
118  {
119  held = false;
120  //stateQueue = false;
121  }
122  }
123 }