Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_LogitechLedManager.c
Go to the documentation of this file.
2{
3 static ELogitechLEDState m_CurrentState = ELogitechLEDState.DEFAULT;
4 static string s_sReloadKey;
5 static string s_sVONDirectKey;
6 static string s_sVONChannelKey;
7
8 //------------------------------------------------------------------------------------------------
9 static void ActivateState(ELogitechLEDState state)
10 {
11 if (state == m_CurrentState)
12 return;
13
14 bool isLogiLEDEnabled;
15 BaseContainer settings = GetGame().GetGameUserSettings().GetModule("SCR_GameplaySettings");
16 if (settings)
17 settings.Get("m_bLogitechSupport", isLogiLEDEnabled);
18
19 if (!isLogiLEDEnabled)
20 return;
21
22 switch (state)
23 {
24 case ELogitechLEDState.DEFAULT:
25 SetDefault();
26 break;
27 case ELogitechLEDState.BLEEDING:
28 SetEffectBleeding();
29 break;
30 case ELogitechLEDState.UNCONSCIOUS:
31 SetEffectUnconscious();
32 case ELogitechLEDState.RELOAD:
33 SetEffectReload();
34 break;
35 case ELogitechLEDState.COMMS:
36 SetEffectComms();
37 break;
38 }
39 }
40
41 //------------------------------------------------------------------------------------------------
43 static void SetFactionColor(Faction currentFaction)
44 {
45 if (!currentFaction)
46 return;
47
48 bool isLogiLEDEnabled;
49 BaseContainer settings = GetGame().GetGameUserSettings().GetModule("SCR_GameplaySettings");
50 if (settings)
51 settings.Get("m_bLogitechSupport", isLogiLEDEnabled);
52
53 if (!isLogiLEDEnabled)
54 return;
55
56 LogitechLED logiLed = LogitechLED.Get();
57 if (!logiLed)
58 return;
59
60 int r,g,b;
61 //colors are hardcoded coz our representation of colors in WB produces very different colors on logitech HW
62 switch (currentFaction.GetFactionKey())
63 {
64 case "FIA":
65 g = 30;
66 break;
67 case "US":
68 b = 30;
69 break;
70 case "USSR":
71 r = 30;
72 break;
73 case "CIV":
74 r = 33;
75 g = 15;
76 b = 30;
77 break;
78 }
79
80 logiLed.SetLighting(r, g, b);
81 }
82
83 //------------------------------------------------------------------------------------------------
84 private static void SetEffectBleeding()
85 {
86 if (m_CurrentState == ELogitechLEDState.UNCONSCIOUS)
87 return;
88
89 LogitechLED logiLed = LogitechLED.Get();
90 if (!logiLed)
91 return;
92
93 IEntity character = GetGame().GetPlayerManager().GetPlayerControlledEntity(SCR_PlayerController.GetLocalPlayerId());
94 if (!character)
95 return;
96
98 if (!storageManager)
99 return;
100
101 int slotIndex = storageManager.GetFirstSlotIndexOf(ECommonItemType.BANDAGE);
102 string quicksSlotActionName;
103
104 //yes, has to be done painfully because someone thought its good idea to name actions based on their typical keybinds and not indexes
105 switch (slotIndex)
106 {
107 case 0:
108 quicksSlotActionName = "SwitchWeaponCategory1";
109 break;
110 case 1:
111 quicksSlotActionName = "SwitchWeaponCategory2";
112 break;
113 case 2:
114 quicksSlotActionName = "SwitchWeaponCategory3";
115 break;
116 case 3:
117 quicksSlotActionName = "SwitchWeaponCategory4";
118 break;
119 case 4:
120 quicksSlotActionName = "SwitchWeaponCategory5";
121 break;
122 case 5:
123 quicksSlotActionName = "SwitchWeaponCategory6";
124 break;
125 case 6:
126 quicksSlotActionName = "SwitchWeaponCategory7";
127 break;
128 case 7:
129 quicksSlotActionName = "SwitchWeaponCategory8";
130 break;
131 case 8:
132 quicksSlotActionName = "SwitchWeaponCategory9";
133 break;
134 case 9:
135 quicksSlotActionName = "SwitchWeaponCategory0";
136 break;
137 }
138
139 InputBinding binding = GetGame().GetInputManager().CreateUserBinding();
140 array<string> bindings = {};
141
142 binding.GetBindings(quicksSlotActionName, bindings, EInputDeviceType.KEYBOARD, "click", false);
143
144
145
146 //setdefault to reset everything first, to override low prio things like reloading
147 SetDefault();
148 logiLed.SaveCurrentLighting();
149
150 if (!bindings.IsEmpty())
151 logiLed.FlashSingleKey(bindings[0], 0, 50, 0, 0, 500);
152
153 logiLed.PulseLighting(100, 0, 0, 0, 1000);
154
155 m_CurrentState = ELogitechLEDState.BLEEDING;
156 }
157
158 //------------------------------------------------------------------------------------------------
159 private static void SetDefault()
160 {
161 LogitechLED logiLed = LogitechLED.Get();
162 if (!logiLed)
163 return;
164
165 if (m_CurrentState == ELogitechLEDState.RELOAD)
166 {
167 EndEffectReload();
168 GetGame().GetCallqueue().Remove(EndEffectReload);
169 }
170 else if (m_CurrentState == ELogitechLEDState.COMMS)
171 {
172 EndEffectComms();
173 GetGame().GetCallqueue().Remove(EndEffectComms);
174 }
175
176 logiLed.StopEffects();
177 logiLed.RestoreLighting();
178 m_CurrentState = ELogitechLEDState.DEFAULT;
179 }
180
181 //------------------------------------------------------------------------------------------------
182 private static void SetEffectUnconscious()
183 {
184 LogitechLED logiLed = LogitechLED.Get();
185 if (!logiLed)
186 return;
187
188 //setdefault to reset everything first, to override low prio things like reloading
189 SetDefault();
190
191 //every temporary effect needs to save current state before they change it so default can retutrn to it
192 logiLed.SaveCurrentLighting();
193 logiLed.SetLighting(15, 15, 15);
194 m_CurrentState = ELogitechLEDState.UNCONSCIOUS;
195 }
196
197 //------------------------------------------------------------------------------------------------
198 private static void SetEffectReload()
199 {
200 if (m_CurrentState == ELogitechLEDState.BLEEDING || m_CurrentState == ELogitechLEDState.UNCONSCIOUS)
201 return;
202
203 LogitechLED logiLed = LogitechLED.Get();
204 if (!logiLed)
205 return;
206
207 InputBinding binding = GetGame().GetInputManager().CreateUserBinding();
208 array<string> bindings = {};
209
210 binding.GetBindings("CharacterReload", bindings, EInputDeviceType.KEYBOARD, "click", false);
211
212 if (bindings.IsEmpty())
213 return;
214
215 s_sReloadKey = bindings[0];
216
217 //hardcode for text, change when cimopet responds
218 logiLed.SaveCurrentLighting();
219 logiLed.FlashSingleKey(s_sReloadKey, 65, 47, 2, 0, 500);
220 m_CurrentState = ELogitechLEDState.RELOAD;
221
222 GetGame().GetCallqueue().CallLater(EndEffectReload, 3000);
223 }
224
225 //------------------------------------------------------------------------------------------------
226 private static void EndEffectReload()
227 {
228 if (m_CurrentState != ELogitechLEDState.RELOAD )
229 return;
230
231 LogitechLED logiLed = LogitechLED.Get();
232 if (!logiLed)
233 return;
234
235 logiLed.StopEffectsOnKey(s_sReloadKey);
236 logiLed.RestoreLighting();
237
238 m_CurrentState = ELogitechLEDState.DEFAULT;
239 }
240
241 //------------------------------------------------------------------------------------------------
242 private static void SetEffectComms()
243 {
244 if (m_CurrentState == ELogitechLEDState.BLEEDING || m_CurrentState == ELogitechLEDState.UNCONSCIOUS)
245 return;
246
247 LogitechLED logiLed = LogitechLED.Get();
248 if (!logiLed)
249 return;
250
251
252 InputBinding binding = GetGame().GetInputManager().CreateUserBinding();
253 array<string> bindingsDirect = {};
254 array<string> bindingsChannel = {};
255
256 binding.GetBindings("VONDirect", bindingsDirect, EInputDeviceType.KEYBOARD, "hold", false);
257 binding.GetBindings("VONChannel", bindingsChannel, EInputDeviceType.KEYBOARD, "hold", false);
258
259 if (!bindingsDirect.IsEmpty())
260 s_sVONDirectKey = bindingsDirect[0];
261
262 if (!bindingsChannel.IsEmpty())
263 s_sVONChannelKey = bindingsChannel[0];
264
265 logiLed.SaveCurrentLighting();
266
267 logiLed.FlashSingleKey(s_sVONDirectKey, 65, 47, 2, 0, 500);
268 logiLed.FlashSingleKey(s_sVONChannelKey, 65, 47, 2, 0, 500);
269
270 m_CurrentState = ELogitechLEDState.COMMS;
271
272 GetGame().GetCallqueue().CallLater(EndEffectComms, 3000);
273 }
274
275 //------------------------------------------------------------------------------------------------
276 private static void EndEffectComms()
277 {
278 if (m_CurrentState != ELogitechLEDState.COMMS )
279 return;
280
281 LogitechLED logiLed = LogitechLED.Get();
282 if (!logiLed)
283 return;
284
285 logiLed.StopEffectsOnKey(s_sVONDirectKey);
286 logiLed.StopEffectsOnKey(s_sVONChannelKey);
287 logiLed.RestoreLighting();
288
289 m_CurrentState = ELogitechLEDState.DEFAULT;
290 }
291}
292
293
294//in order of priority top to bottom!
295enum ELogitechLEDState
296{
301 COMMS
302}
ArmaReforgerScripted GetGame()
Definition game.c:1398
ECommonItemType
@ UNCONSCIOUS
class SCR_LogitechLEDManager RELOAD
proto external Managed FindComponent(typename typeName)
Manages input key bindings, presets, contexts, and device calibration. Provides functions for creatin...
Controls the RGB lighting of Logitech keyboards and other peripherals.
Definition LogitechLED.c:3
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
@ DEFAULT
Use currently set main RT format (based on game options).
@ BLEEDING
Definition EDamageType.c:24