Mercurial > mm7
annotate IO/Keyboard.cpp @ 2575:a76d408c5132 tip
DrawTranslucent -> DrawTextureGrayShade
Removed old texture drawing stuff
author | a.parshin |
---|---|
date | Wed, 09 Mar 2016 01:39:52 +0200 |
parents | 87e5590d034b |
children |
rev | line source |
---|---|
2502 | 1 #define _CRTDBG_MAP_ALLOC |
2548
87e5590d034b
All Books windows are refactored into respective classes
a.parshin
parents:
2541
diff
changeset
|
2 #define _CRT_SECURE_NO_WARNINGS |
2502 | 3 #include <stdlib.h> |
4 #include <crtdbg.h> | |
5 | |
2541 | 6 #include "Engine/Engine.h" |
2502 | 7 #include "Engine/Party.h" |
8 #include "Engine/Timer.h" | |
9 #include "Engine/TurnEngine/TurnEngine.h" | |
2548
87e5590d034b
All Books windows are refactored into respective classes
a.parshin
parents:
2541
diff
changeset
|
10 #include "Engine/Graphics/Vis.h" |
2502 | 11 #include "Engine/Graphics/Weather.h" |
2548
87e5590d034b
All Books windows are refactored into respective classes
a.parshin
parents:
2541
diff
changeset
|
12 #include "Engine/Graphics/Indoor.h" |
2502 | 13 #include "Engine/Spells/CastSpellInfo.h" |
2548
87e5590d034b
All Books windows are refactored into respective classes
a.parshin
parents:
2541
diff
changeset
|
14 #include "Engine/Objects/Actor.h" |
87e5590d034b
All Books windows are refactored into respective classes
a.parshin
parents:
2541
diff
changeset
|
15 |
87e5590d034b
All Books windows are refactored into respective classes
a.parshin
parents:
2541
diff
changeset
|
16 #include "IO/Keyboard.h" |
87e5590d034b
All Books windows are refactored into respective classes
a.parshin
parents:
2541
diff
changeset
|
17 |
87e5590d034b
All Books windows are refactored into respective classes
a.parshin
parents:
2541
diff
changeset
|
18 #include "GUI/GUIWindow.h" |
2502 | 19 |
20 #include <tuple> | |
21 #include <vector> | |
22 #include <string> | |
23 | |
24 struct KeyboardActionMapping *pKeyActionMap; | |
25 | |
26 | |
27 class CKeyListElement | |
28 { | |
29 public: | |
30 std::string m_keyName; | |
31 unsigned char m_keyDefaultCode; | |
32 unsigned short m_cmdId; | |
33 KeyToggleType m_toggType; | |
34 CKeyListElement(std::string keyName, unsigned char keyDefaultCode, unsigned short cmdId, KeyToggleType toggType): | |
35 m_keyName(keyName), | |
36 m_keyDefaultCode(keyDefaultCode), | |
37 m_cmdId(cmdId), | |
38 m_toggType(toggType) | |
39 { | |
40 | |
41 } | |
42 }; | |
43 | |
44 std::array<CKeyListElement, 30>keyMappingParams = { | |
45 CKeyListElement("KEY_FORWARD", VK_UP, INPUT_MoveForward, TOGGLE_Continuously), | |
46 CKeyListElement("KEY_BACKWARD", VK_DOWN, INPUT_MoveBackwards, TOGGLE_Continuously), | |
47 CKeyListElement("KEY_LEFT", VK_LEFT, INPUT_TurnLeft, TOGGLE_Continuously), | |
48 CKeyListElement("KEY_RIGHT", VK_RIGHT, INPUT_TurnRight, TOGGLE_Continuously), | |
49 CKeyListElement("KEY_ATTACK", 'A', INPUT_Attack, TOGGLE_OneTimePress), | |
50 CKeyListElement("KEY_CASTREADY", 'S', INPUT_CastReady, TOGGLE_OneTimePress), | |
51 CKeyListElement("KEY_YELL", 'Y', INPUT_Yell, TOGGLE_OneTimePress), | |
52 CKeyListElement("KEY_JUMP", 'X', INPUT_Jump, TOGGLE_OneTimePress), | |
53 CKeyListElement("KEY_COMBAT", VK_RETURN, INPUT_Combat, TOGGLE_OneTimePress), | |
54 CKeyListElement("KEY_EVENTTRIGGER", VK_SPACE, INPUT_EventTrigger, TOGGLE_OneTimePress), | |
55 CKeyListElement("KEY_CAST", 'C', INPUT_Cast, TOGGLE_OneTimePress), | |
56 CKeyListElement("KEY_PASS", 'B', INPUT_Pass, TOGGLE_OneTimePress), | |
57 CKeyListElement("KEY_CHARCYCLE", VK_TAB, INPUT_CharCycle, TOGGLE_OneTimePress), | |
58 CKeyListElement("KEY_QUEST", 'Q', INPUT_Quest, TOGGLE_OneTimePress), | |
59 CKeyListElement("KEY_QUICKREF", 'Z', INPUT_QuickRef, TOGGLE_OneTimePress), | |
60 CKeyListElement("KEY_REST", 'R', INPUT_Rest, TOGGLE_OneTimePress), | |
61 CKeyListElement("KEY_TIMECAL", 'T', INPUT_TimeCal, TOGGLE_OneTimePress), | |
62 CKeyListElement("KEY_AUTONOTES", 'N', INPUT_Autonotes, TOGGLE_OneTimePress), | |
63 CKeyListElement("KEY_MAPBOOK", 'M', INPUT_Mapbook, TOGGLE_OneTimePress), | |
64 CKeyListElement("KEY_LOOKUP", VK_NEXT, INPUT_LookUp, TOGGLE_OneTimePress), | |
65 CKeyListElement("KEY_LOOKDOWN", VK_DELETE, INPUT_LookDown, TOGGLE_OneTimePress), | |
66 CKeyListElement("KEY_CENTERVIEWPT", VK_END, INPUT_CenterView, TOGGLE_OneTimePress), | |
67 CKeyListElement("KEY_ZOOMIN", VK_ADD, INPUT_ZoomIn, TOGGLE_OneTimePress), | |
68 CKeyListElement("KEY_ZOOMOUT", VK_SUBTRACT, INPUT_ZoomOut, TOGGLE_OneTimePress), | |
69 CKeyListElement("KEY_FLYUP", VK_PRIOR, INPUT_FlyUp, TOGGLE_Continuously), | |
70 CKeyListElement("KEY_FLYDOWN", VK_INSERT, INPUT_FlyDown, TOGGLE_Continuously), | |
71 CKeyListElement("KEY_LAND", VK_HOME, INPUT_Land, TOGGLE_OneTimePress), | |
72 CKeyListElement("KEY_ALWAYSRUN", 'U', INPUT_AlwaysRun, TOGGLE_OneTimePress), | |
73 CKeyListElement("KEY_STEPLEFT", VK_OEM_4, INPUT_StrafeLeft, TOGGLE_Continuously), | |
74 CKeyListElement("KEY_STEPRIGHT", VK_OEM_6, INPUT_StrafeRight, TOGGLE_Continuously) | |
75 }; | |
76 | |
77 std::array<std::tuple<const char*, const unsigned __int8>, 26> keyNameToCodeTranslationMap = | |
78 { | |
79 std::tuple<const char*, const unsigned __int8>("UP", VK_UP), | |
80 std::tuple<const char*, const unsigned __int8>("DOWN", VK_DOWN), | |
81 std::tuple<const char*, const unsigned __int8>("LEFT", VK_LEFT), | |
82 std::tuple<const char*, const unsigned __int8>("бкебн", VK_LEFT), | |
83 std::tuple<const char*, const unsigned __int8>("RIGHT", VK_RIGHT), | |
84 std::tuple<const char*, const unsigned __int8>("бопюбн", VK_RIGHT), | |
85 std::tuple<const char*, const unsigned __int8>("RETURN", VK_RETURN), | |
86 std::tuple<const char*, const unsigned __int8>("SPACE", VK_SPACE), | |
87 std::tuple<const char*, const unsigned __int8>("PAGE_DOWN", VK_NEXT), | |
88 std::tuple<const char*, const unsigned __int8>("PAGE_UP", VK_PRIOR), | |
89 std::tuple<const char*, const unsigned __int8>("TAB", VK_TAB), | |
90 std::tuple<const char*, const unsigned __int8>("SUBTRACT", VK_SUBTRACT), | |
91 std::tuple<const char*, const unsigned __int8>("ADD", VK_ADD), | |
92 std::tuple<const char*, const unsigned __int8>("END", VK_END), | |
93 std::tuple<const char*, const unsigned __int8>("DELETE", VK_DELETE), | |
94 std::tuple<const char*, const unsigned __int8>("HOME", VK_HOME), | |
95 std::tuple<const char*, const unsigned __int8>("INSERT", VK_INSERT), | |
96 std::tuple<const char*, const unsigned __int8>("COMMA", VK_OEM_COMMA), | |
97 std::tuple<const char*, const unsigned __int8>("DECIMAL", VK_DECIMAL), | |
98 std::tuple<const char*, const unsigned __int8>("SEMICOLON", VK_OEM_1), | |
99 std::tuple<const char*, const unsigned __int8>("PERIOD", VK_OEM_PERIOD), | |
100 std::tuple<const char*, const unsigned __int8>("SLASH", VK_OEM_2), | |
101 std::tuple<const char*, const unsigned __int8>("SQUOTE", VK_OEM_7), | |
102 std::tuple<const char*, const unsigned __int8>("BACKSLASH", VK_OEM_5), | |
103 std::tuple<const char*, const unsigned __int8>("BACKSPACE", VK_BACK), | |
104 std::tuple<const char*, const unsigned __int8>("CONTROL", VK_CONTROL), | |
105 }; | |
106 | |
107 //----- (00459C68) -------------------------------------------------------- | |
108 void KeyboardActionMapping::SetKeyMapping(int uAction, int vKey, KeyToggleType type) | |
109 { | |
110 pVirtualKeyCodesMapping[uAction] = vKey; | |
111 pToggleTypes[uAction] = type; | |
112 } | |
113 | |
114 //----- (00459C82) -------------------------------------------------------- | |
115 unsigned int KeyboardActionMapping::GetActionVKey(enum InputAction eAction) | |
116 { | |
117 return this->pVirtualKeyCodesMapping[eAction]; | |
118 } | |
119 | |
120 //----- (00459C8D) -------------------------------------------------------- | |
121 KeyboardActionMapping::KeyboardActionMapping() | |
122 { | |
123 uLastKeyPressed = 0; | |
124 field_204 = 0; | |
125 pWindow = nullptr; | |
126 | |
127 SetDefaultMapping(); | |
128 ReadMappings(); | |
129 | |
130 ResetKeys(); | |
131 | |
132 uNumKeysPressed = 0; | |
133 | |
134 uGameMenuUI_CurentlySelectedKeyIdx = -1; | |
135 } | |
136 // 506E68: using guessed type int uGameMenuUI_CurentlySelectedKeyIdx; | |
137 | |
138 //----- (00459CC4) -------------------------------------------------------- | |
139 void KeyboardActionMapping::SetDefaultMapping() | |
140 { | |
141 for ( size_t i = 0; i < keyMappingParams.size(); i++) | |
142 { | |
143 SetKeyMapping(keyMappingParams[i].m_cmdId, keyMappingParams[i].m_keyDefaultCode, keyMappingParams[i].m_toggType); | |
144 } | |
145 } | |
146 | |
147 //----- (00459E3F) -------------------------------------------------------- | |
148 void KeyboardActionMapping::ResetKeys() | |
149 { | |
150 for (uint i = 0; i < 30; ++i) | |
151 GetAsyncKeyState(pVirtualKeyCodesMapping[i]); | |
152 } | |
153 | |
154 //----- (00459E5A) -------------------------------------------------------- | |
155 void KeyboardActionMapping::EnterText(int a2, int max_string_len, GUIWindow *pWindow) | |
156 { | |
157 memset(this->pPressedKeysBuffer, 0, 0x101u); | |
158 this->uNumKeysPressed = 0; | |
159 if ( a2 ) | |
160 this->field_204 = 2; | |
161 else | |
162 this->field_204 = 1; | |
163 this->max_input_string_len = max_string_len; | |
164 this->pWindow = pWindow; | |
165 pWindow->receives_keyboard_input_2 = WINDOW_INPUT_IN_PROGRESS; | |
166 } | |
167 | |
168 //----- (00459ED1) -------------------------------------------------------- | |
169 void KeyboardActionMapping::SetWindowInputStatus(int a2) | |
170 { | |
171 field_204 = 0; | |
172 if ( pWindow ) | |
173 pWindow->receives_keyboard_input_2 = a2; | |
174 } | |
175 | |
176 //----- (00459F10) -------------------------------------------------------- | |
177 bool KeyboardActionMapping::ProcessTextInput(unsigned int a2) | |
178 { | |
179 pKeyActionMap->uLastKeyPressed = a2; | |
180 if ( uGameMenuUI_CurentlySelectedKeyIdx == -1 ) | |
181 { | |
182 if ( pKeyActionMap->field_204 != 1 && pKeyActionMap->field_204 != 2 ) | |
183 return 0; | |
184 if ( a2 == VK_BACK) | |
185 { | |
186 if (pKeyActionMap->uNumKeysPressed > 0) | |
187 { | |
188 --pKeyActionMap->uNumKeysPressed; | |
189 pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = 0; | |
190 } | |
191 } | |
192 else if ( a2 == VK_RETURN ) | |
193 pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_CONFIRMED); | |
194 else if ( a2 == VK_ESCAPE ) | |
195 pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_CANCELLED); | |
196 else if (this->uNumKeysPressed < this->max_input_string_len) | |
197 { | |
198 if ( pKeyActionMap->field_204 == 1 ) | |
199 { | |
200 if ( a2 != VK_TAB ) | |
201 { | |
202 pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = a2; | |
203 ++pKeyActionMap->uNumKeysPressed; | |
204 pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = 0; | |
205 } | |
206 } | |
207 else if (pKeyActionMap->field_204 == 2) | |
208 { | |
209 if ( isdigit(a2)) | |
210 { | |
211 pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = a2; | |
212 ++pKeyActionMap->uNumKeysPressed; | |
213 } | |
214 } | |
215 } | |
216 } | |
217 else | |
218 { | |
219 pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = a2; | |
220 ++pKeyActionMap->uNumKeysPressed; | |
221 pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = 0; | |
222 pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_CONFIRMED); | |
223 } | |
224 return 1; | |
225 } | |
226 // 506E68: using guessed type int uGameMenuUI_CurentlySelectedKeyIdx; | |
227 | |
228 //----- (00459FFC) -------------------------------------------------------- | |
229 void KeyboardActionMapping::ReadMappings() | |
230 { | |
231 char str[32]; | |
232 | |
233 for (size_t i = 0; i < keyMappingParams.size(); i++) | |
234 { | |
235 const char* keyName = keyMappingParams[i].m_keyName.c_str(); | |
236 short commandDefaultKeyCode = keyMappingParams[i].m_keyDefaultCode; | |
237 short commandId = keyMappingParams[i].m_cmdId; | |
238 KeyToggleType toggType = keyMappingParams[i].m_toggType; | |
239 | |
240 ReadWindowsRegistryString(keyName, str, 32, "DEFAULT"); | |
241 if ( strcmp(str, "DEFAULT") && ( TranslateKeyNameToKeyCode(str) != -1) ) | |
242 pVirtualKeyCodesMapping[commandId] = TranslateKeyNameToKeyCode(str); | |
243 else | |
244 pVirtualKeyCodesMapping[commandId] = commandDefaultKeyCode; | |
245 pToggleTypes[commandId] = toggType; | |
246 } | |
247 | |
248 bAlwaysRun = ReadWindowsRegistryInt("valAlwaysRun", 0) != 0; | |
249 bFlipOnExit = ReadWindowsRegistryInt("FlipOnExit", 0) != 0; | |
250 } | |
251 | |
252 //----- (0045A960) -------------------------------------------------------- | |
253 void KeyboardActionMapping::StoreMappings() | |
254 { | |
255 | |
256 const char *v2; // eax@1 | |
257 | |
258 for ( size_t i = 0; i < keyMappingParams.size(); i++) | |
259 { | |
260 v2 = GetVKeyDisplayName(pVirtualKeyCodesMapping[keyMappingParams[i].m_cmdId]); | |
261 WriteWindowsRegistryString(keyMappingParams[i].m_keyName.c_str(), v2); | |
262 } | |
263 } | |
264 | |
265 //----- (0045ABCA) -------------------------------------------------------- | |
266 const unsigned __int8 KeyboardActionMapping::TranslateKeyNameToKeyCode(const char *Str) | |
267 { | |
268 if (strlen(Str) == 1) | |
269 { | |
270 if( Str[0] >= 65 && Str[0] <= 90 ) | |
271 return *Str; | |
272 else | |
273 return 0xFF; | |
274 } | |
275 | |
276 for ( size_t i = 0; i < keyNameToCodeTranslationMap.size(); i++) | |
277 { | |
278 if (!strcmp(Str, std::get<0>(keyNameToCodeTranslationMap[i]))) | |
279 return std::get<1>(keyNameToCodeTranslationMap[i]); | |
280 } | |
281 return 0xFF; | |
282 } | |
283 | |
284 //----- (0045AE2C) -------------------------------------------------------- | |
285 const char * KeyboardActionMapping::GetVKeyDisplayName(unsigned char a1) | |
286 { | |
287 static char static_sub_45AE2C_string_69ADE0_keyName[32]; | |
288 | |
289 if ( a1 >= 65 && a1 <= 90 ) | |
290 { | |
291 static_sub_45AE2C_string_69ADE0_keyName[0] = a1; | |
292 static_sub_45AE2C_string_69ADE0_keyName[1] = '\0'; | |
293 return static_sub_45AE2C_string_69ADE0_keyName; | |
294 } | |
295 | |
296 for ( size_t i = 0; i < keyNameToCodeTranslationMap.size(); i++) | |
297 { | |
298 if ( a1 == std::get<1>(keyNameToCodeTranslationMap[i])) | |
299 { | |
300 const char* keyName = std::get<0>(keyNameToCodeTranslationMap[i]); | |
301 strcpy_s(static_sub_45AE2C_string_69ADE0_keyName, keyName); | |
302 return static_sub_45AE2C_string_69ADE0_keyName; | |
303 } | |
304 } | |
305 | |
306 strcpy_s(static_sub_45AE2C_string_69ADE0_keyName, "-мер -"); | |
307 return static_sub_45AE2C_string_69ADE0_keyName; | |
308 } | |
309 | |
310 | |
311 //----- (0045B019) -------------------------------------------------------- | |
312 void Keyboard::EnterCriticalSection() | |
313 { | |
314 } | |
315 | |
316 //----- (0045B06E) -------------------------------------------------------- | |
317 bool Keyboard::IsShiftHeld() | |
318 { | |
319 return (GetAsyncKeyState(VK_SHIFT) & 0x8001) != 0; | |
320 } | |
321 | |
322 //----- (0045B0A9) -------------------------------------------------------- | |
323 bool Keyboard::IsKeyBeingHeld(int vKey) | |
324 { | |
325 return (GetAsyncKeyState(vKey) & 0x8001) != 0; | |
326 } | |
327 | |
328 //----- (0045B0CE) -------------------------------------------------------- | |
329 bool Keyboard::WasKeyPressed(int vKey) | |
330 { | |
331 return (GetAsyncKeyState(vKey) & 1) != 0; | |
332 } | |
333 //----- (0046A14B) -------------------------------------------------------- | |
334 void OnPressSpace() | |
335 { | |
336 | |
337 //if ( pRenderer->pRenderD3D ) | |
338 { | |
2541 | 339 pEngine->PickKeyboard(Keyboard::IsKeyBeingHeld(VK_CONTROL), &vis_sprite_filter_3, &vis_door_filter); |
340 int pid = pEngine->pVisInstance->get_picked_object_zbuf_val(); | |
2502 | 341 if ( pid != -1 ) |
342 DoInteractionWithTopmostZObject(pid & 0xFFFF, PID_ID(pid)); | |
343 return; | |
344 } | |
345 | |
346 | |
347 // software render stuff following | |
348 /* | |
349 static int dword_720660[100]; // 720660 | |
350 static int dword_7207F0[100]; // 7207F0 | |
351 | |
352 v22 = 0; | |
353 v1 = (int *)((signed int)(viewparams->uScreen_BttmR_X + viewparams->uScreen_topL_X) >> 1);//wrong pointer | |
354 if ( (signed int)viewparams->uScreen_topL_Y < (signed int)viewparams->uScreen_BttmR_Y ) | |
355 { | |
356 v2 = (char *)v1 - 50; | |
357 v1 = (int *)((char *)v1 + 50); | |
358 v3 = 640 * viewparams->uScreen_topL_Y; | |
359 v17 = v2; | |
360 v20 = v1; | |
361 v18 = ((viewparams->uScreen_BttmR_Y - viewparams->uScreen_topL_Y - 1) >> 1) + 1; | |
362 do | |
363 { | |
364 if ( (signed int)v2 < (signed int)v20 ) | |
365 { | |
366 v1 = &pRenderer->pActiveZBuffer[(int)&v2[v3]]; | |
367 v21 = &pRenderer->pActiveZBuffer[(int)&v2[v3]]; | |
368 v4 = v22; | |
369 v5 = (((char *)v20 - v2 - 1) >> 1) + 1; | |
370 do | |
371 { | |
372 v6 = 0; | |
373 v7 = *v1 & 0xFFFF; | |
374 v19 = 0; | |
375 if ( v4 > 0 ) | |
376 { | |
377 do | |
378 { | |
379 if ( dword_7207F0[v6] == v7 ) | |
380 break; | |
381 ++v6; | |
382 v19 = v6; | |
383 } | |
384 while ( v6 < v22 ); | |
385 } | |
386 if ( PID_TYPE(v7) == OBJECT_Decoration) | |
387 { | |
388 v16 = (unsigned int)PID_ID(v7); | |
389 if ( (signed int)(((unsigned int)*v21 >> 16) | |
390 - pDecorationList->pDecorations[pLevelDecorations[(unsigned int)PID_ID(v7)].uDecorationDescID].uRadius) <= 512 ) | |
391 if ( v19 == v22 && v4 < 100 ) | |
392 { | |
393 ++v22; | |
394 ++v4; | |
395 v8 = *v21; | |
396 dword_7207F0[v4 - 1] = v7; | |
397 dword_720660[v4 - 1] = v8; | |
398 } | |
399 } | |
400 else if ( (unsigned int)*v21 <= 0x2000000 ) | |
401 { | |
402 if ( v19 == v22 && v4 < 100 ) | |
403 { | |
404 ++v22; | |
405 ++v4; | |
406 v8 = *v21; | |
407 dword_7207F0[v4 - 1] = v7; | |
408 dword_720660[v4 - 1] = v8; | |
409 } | |
410 } | |
411 v1 = v21 + 2; | |
412 --v5; | |
413 v21 += 2; | |
414 } | |
415 while ( v5 ); | |
416 v2 = v17; | |
417 } | |
418 v3 += 1280; | |
419 --v18; | |
420 } | |
421 while ( v18 ); | |
422 } | |
423 if ( v22 > 0 ) | |
424 { | |
425 v9 = dword_720660; | |
426 v10 = 1; | |
427 do | |
428 { | |
429 for ( i = v10; i < v22; ++i ) | |
430 { | |
431 v12 = *v9; | |
432 v13 = dword_720660[i]; | |
433 if ( v13 < *v9 ) | |
434 { | |
435 *v9 = v13; | |
436 dword_720660[i] = v12; | |
437 } | |
438 } | |
439 ++v10; | |
440 ++v9; | |
441 LOBYTE(v1) = v10 - 1; | |
442 } | |
443 while ( v10 - 1 < v22 ); | |
444 } | |
445 for ( j = 0; j < v22; ++j ) | |
446 { | |
447 LOBYTE(v1) = DoInteractionWithTopmostZObject(dword_720660[j] & 0xFFFF, v16); | |
448 if ( !(char)v1 ) | |
449 break; | |
450 }*/ | |
451 } | |
452 | |
453 | |
454 //----- (0042FC4E) -------------------------------------------------------- | |
455 void Keyboard::ProcessInputActions() | |
456 { | |
457 char v4; // al@9 | |
458 unsigned __int16 v9; // ax@102 | |
459 int spell_price; // eax@103 | |
460 PartyAction partyAction; // [sp-14h] [bp-1Ch]@20 | |
461 InputAction inputAction; // [sp+0h] [bp-8h]@7 | |
462 | |
2541 | 463 pEngine->pKeyboardInstance->EnterCriticalSection(); |
464 Keyboard* pKeyboard = pEngine->pKeyboardInstance; | |
2502 | 465 if (!bAlwaysRun) |
466 { | |
467 if (pKeyboard->IsShiftHeld()) | |
468 pParty->uFlags2 |= PARTY_FLAGS_2_RUNNING; | |
469 else | |
470 pParty->uFlags2 &= ~PARTY_FLAGS_2_RUNNING; | |
471 } | |
472 else | |
473 { | |
474 if (pKeyboard->IsShiftHeld()) | |
475 pParty->uFlags2 &= ~PARTY_FLAGS_2_RUNNING; | |
476 else | |
477 pParty->uFlags2 |= PARTY_FLAGS_2_RUNNING; | |
478 } | |
479 | |
480 //pParty->uFlags2 |= PARTY_FLAGS_2_RUNNING; | |
481 | |
482 | |
483 // WUT? double event trigger | |
484 /*for ( uint i = 0; i < 30; ++i ) | |
485 { | |
486 if ( pKeyActionMap->pToggleTypes[i] ) | |
2541 | 487 v14 = pEngine->pKeyboardInstance->WasKeyPressed(pKeyActionMap->pVirtualKeyCodesMapping[i]); |
2502 | 488 else |
2541 | 489 v14 = pEngine->pKeyboardInstance->IsKeyBeingHeld(pKeyActionMap->pVirtualKeyCodesMapping[i]); |
2502 | 490 if ( v14 ) |
491 { | |
2541 | 492 if (current_screen_type == SCREEN_GAME) |
2502 | 493 { |
494 pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Game_Action, 0, 0); | |
495 continue; | |
496 } | |
2541 | 497 if ( current_screen_type == SCREEN_NPC_DIALOGUE || current_screen_type == SCREEN_BRANCHLESS_NPC_DIALOG ) |
2502 | 498 { |
499 v15 = pMessageQueue_50CBD0->uNumMessages; | |
500 if ( pMessageQueue_50CBD0->uNumMessages ) | |
501 { | |
502 v15 = 0; | |
503 if ( pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].field_8 ) | |
504 { | |
505 v15 = 1; | |
506 pMessageQueue_50CBD0->uNumMessages = 0; | |
507 pMessageQueue_50CBD0->pMessages[v15].eType = UIMSG_Escape; | |
508 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0; | |
509 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0; | |
510 ++pMessageQueue_50CBD0->uNumMessages; | |
511 continue; | |
512 } | |
513 pMessageQueue_50CBD0->uNumMessages = 0; | |
514 } | |
515 //pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 0, 0); | |
516 } | |
517 } | |
518 }*/ | |
519 if ( !pEventTimer->bPaused ) | |
520 { | |
521 for ( uint i = 0; i < 30; ++i ) | |
522 { | |
523 inputAction = (InputAction)i; | |
524 if ( pKeyActionMap->pToggleTypes[inputAction] ) | |
525 v4 = pKeyboard->WasKeyPressed(pKeyActionMap->pVirtualKeyCodesMapping[inputAction]); | |
526 else | |
527 v4 = pKeyboard->IsKeyBeingHeld(pKeyActionMap->pVirtualKeyCodesMapping[inputAction]); | |
528 if ( v4 ) | |
529 { | |
530 switch ( inputAction ) | |
531 { | |
532 case INPUT_MoveForward: | |
2541 | 533 if (current_screen_type != SCREEN_GAME) |
2502 | 534 break; |
535 if (!pParty->bTurnBasedModeOn) | |
536 { | |
537 if ( pParty->uFlags2 & PARTY_FLAGS_2_RUNNING) | |
538 partyAction = PARTY_RunForward; | |
539 else | |
540 partyAction = PARTY_WalkForward; | |
541 pPartyActionQueue->Add(partyAction); | |
542 break; | |
543 } | |
544 if (pTurnEngine->turn_stage != TE_WAIT && pTurnEngine->turn_stage != TE_ATTACK && pTurnEngine->uActionPointsLeft > 0 ) | |
545 { | |
546 pTurnEngine->uActionPointsLeft -= 26; | |
547 if ( pParty->uFlags2 & PARTY_FLAGS_2_RUNNING) | |
548 partyAction = PARTY_RunForward; | |
549 else | |
550 partyAction = PARTY_WalkForward; | |
551 pPartyActionQueue->Add(partyAction); | |
552 break; | |
553 } | |
554 break; | |
555 case INPUT_MoveBackwards: | |
2541 | 556 if (current_screen_type != SCREEN_GAME) |
2502 | 557 break; |
558 if (!pParty->bTurnBasedModeOn) | |
559 { | |
560 if ( pParty->uFlags2 & 2 ) | |
561 partyAction = PARTY_RunBackward; | |
562 else | |
563 partyAction = PARTY_WalkBackward; | |
564 pPartyActionQueue->Add(partyAction); | |
565 break; | |
566 } | |
567 if ( pTurnEngine->turn_stage != TE_WAIT && pTurnEngine->turn_stage != TE_ATTACK && pTurnEngine->uActionPointsLeft > 0 ) | |
568 { | |
569 pTurnEngine->uActionPointsLeft -= 26; | |
570 if ( pParty->uFlags2 & 2 ) | |
571 partyAction = PARTY_RunBackward; | |
572 else | |
573 partyAction = PARTY_WalkBackward; | |
574 pPartyActionQueue->Add(partyAction); | |
575 break; | |
576 } | |
577 break; | |
578 case INPUT_StrafeLeft: | |
2541 | 579 if (current_screen_type != SCREEN_GAME) |
2502 | 580 break; |
581 if (!pParty->bTurnBasedModeOn) | |
582 { | |
583 partyAction = PARTY_StrafeLeft; | |
584 pPartyActionQueue->Add(partyAction); | |
585 break; | |
586 } | |
587 if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->uActionPointsLeft <= 0 ) | |
588 break; | |
589 pTurnEngine->uActionPointsLeft -= 26; | |
590 partyAction = PARTY_StrafeLeft; | |
591 pPartyActionQueue->Add(partyAction); | |
592 break; | |
593 case INPUT_StrafeRight: | |
2541 | 594 if (current_screen_type != SCREEN_GAME) |
2502 | 595 break; |
596 if (!pParty->bTurnBasedModeOn) | |
597 { | |
598 partyAction = PARTY_StrafeRight; | |
599 pPartyActionQueue->Add(partyAction); | |
600 break; | |
601 } | |
602 if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->uActionPointsLeft <= 0 ) | |
603 break; | |
604 pTurnEngine->uActionPointsLeft -= 26; | |
605 partyAction = PARTY_StrafeRight; | |
606 pPartyActionQueue->Add(partyAction); | |
607 break; | |
608 case INPUT_TurnLeft: | |
2541 | 609 if (current_screen_type != SCREEN_GAME) |
2502 | 610 break; |
611 if ( GetAsyncKeyState(VK_CONTROL) ) // strafing | |
612 { | |
613 if (pParty->bTurnBasedModeOn) | |
614 { | |
615 if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->uActionPointsLeft <= 0 ) | |
616 break; | |
617 pTurnEngine->uActionPointsLeft -= 26; | |
618 } | |
619 partyAction = PARTY_StrafeLeft; | |
620 } | |
621 else | |
622 { | |
623 if ( pParty->uFlags2 & 2 ) | |
624 partyAction = PARTY_FastTurnLeft; | |
625 else | |
626 partyAction = PARTY_TurnLeft; | |
627 } | |
628 pPartyActionQueue->Add(partyAction); | |
629 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor && pWeather->bRenderSnow) | |
630 pWeather->OnPlayerTurn(10); | |
631 break; | |
632 case INPUT_TurnRight: | |
2541 | 633 if (current_screen_type != SCREEN_GAME) |
2502 | 634 break; |
635 if ( GetAsyncKeyState(VK_CONTROL) ) // strafing | |
636 { | |
637 if (pParty->bTurnBasedModeOn) | |
638 { | |
639 if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->uActionPointsLeft <= 0 ) | |
640 break; | |
641 pTurnEngine->uActionPointsLeft -= 26; | |
642 } | |
643 partyAction = PARTY_StrafeRight; | |
644 } | |
645 else | |
646 { | |
647 if ( pParty->uFlags2 & 2 ) | |
648 partyAction = PARTY_FastTurnRight; | |
649 else | |
650 partyAction = PARTY_TurnRight; | |
651 } | |
652 pPartyActionQueue->Add(partyAction); | |
653 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor && pWeather->bRenderSnow) | |
654 pWeather->OnPlayerTurn(-10); | |
655 break; | |
656 case INPUT_Jump: | |
2541 | 657 if (current_screen_type != SCREEN_GAME || pParty->bTurnBasedModeOn) |
2502 | 658 break; |
659 partyAction = (PartyAction)12; | |
660 pPartyActionQueue->Add(partyAction); | |
661 break; | |
662 case INPUT_Yell: | |
2541 | 663 if (!current_screen_type && uActiveCharacter) |
2502 | 664 { |
665 pParty->Yell(); | |
666 pPlayers[uActiveCharacter]->PlaySound(SPEECH_Yell, 0); | |
667 } | |
668 break; | |
669 case INPUT_Pass: | |
2541 | 670 if ( current_screen_type ) |
2502 | 671 break; |
672 if (pParty->bTurnBasedModeOn && pTurnEngine->turn_stage == TE_MOVEMENT) | |
673 { | |
674 pTurnEngine->field_18 |= TE_FLAG_8; | |
675 break; | |
676 } | |
677 if ( uActiveCharacter ) | |
678 { | |
679 if ( !pPlayers[uActiveCharacter]->uTimeToRecovery ) | |
680 { | |
681 if ( !pParty->bTurnBasedModeOn ) | |
682 pPlayers[uActiveCharacter]->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)pPlayers[uActiveCharacter]->GetAttackRecoveryTime(false) * 2.133333333333333)); | |
683 CastSpellInfoHelpers::_427D48(); | |
684 pTurnEngine->ApplyPlayerAction(); | |
685 } | |
686 } | |
687 break; | |
688 case INPUT_Combat://if press ENTER | |
2541 | 689 if (current_screen_type == SCREEN_GAME) |
2502 | 690 { |
691 if (pParty->bTurnBasedModeOn) | |
692 { | |
693 if (pTurnEngine->turn_stage == TE_MOVEMENT || PID_TYPE(pTurnEngine->pQueue[0].uPackedID) == OBJECT_Player) | |
694 { | |
695 pParty->bTurnBasedModeOn = 0; | |
696 pTurnEngine->End(true); | |
697 } | |
698 } | |
699 else | |
700 { | |
701 pTurnEngine->Start(); | |
702 pParty->bTurnBasedModeOn = true; | |
703 } | |
704 } | |
705 break; | |
706 case INPUT_CastReady: | |
707 { | |
2541 | 708 if (current_screen_type != SCREEN_GAME) |
2502 | 709 break; |
710 if (pParty->bTurnBasedModeOn && pTurnEngine->turn_stage == TE_MOVEMENT) | |
711 { | |
712 pTurnEngine->field_18 |= TE_FLAG_8; | |
713 break; | |
714 } | |
715 if ( !uActiveCharacter ) | |
716 break; | |
717 uchar quickSpellNumber = pPlayers[uActiveCharacter]->uQuickSpell; | |
718 v9 = pPlayers[uActiveCharacter]->pActiveSkills[quickSpellNumber / 11 + 12]; | |
719 bool enoughMana = false; | |
720 if ((v9 & 0x100) != 0) | |
721 { | |
722 enoughMana = pSpellDatas[quickSpellNumber].uMagisterLevelMana < pPlayers[uActiveCharacter]->sMana; | |
723 } | |
724 else if ((v9 & 0x80) != 0) | |
725 { | |
726 enoughMana = pSpellDatas[quickSpellNumber].uMasterLevelMana < pPlayers[uActiveCharacter]->sMana; | |
727 } | |
728 else if ((v9 & 0x40) != 0) | |
729 { | |
730 enoughMana = pSpellDatas[quickSpellNumber].uExpertLevelMana < pPlayers[uActiveCharacter]->sMana; | |
731 } | |
732 else | |
733 { | |
734 enoughMana = pSpellDatas[quickSpellNumber].uNormalLevelMana < pPlayers[uActiveCharacter]->sMana; | |
735 } | |
736 if ( !pPlayers[uActiveCharacter]->uQuickSpell || bUnderwater || !enoughMana) | |
737 { | |
738 pPartyActionQueue = pPartyActionQueue; | |
739 pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Attack, 0, 0); | |
740 break; | |
741 } | |
742 else | |
743 pMessageQueue_50C9E8->AddGUIMessage(UIMSG_CastQuickSpell, 0, 0); | |
744 } | |
745 break; | |
746 case INPUT_Attack: | |
2541 | 747 if (current_screen_type != SCREEN_GAME) |
2502 | 748 break; |
749 if (pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == TE_MOVEMENT) | |
750 { | |
751 pTurnEngine->field_18 |= TE_FLAG_8; | |
752 break; | |
753 } | |
754 pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Attack, 0, 0); | |
755 break; | |
756 case INPUT_EventTrigger: | |
2541 | 757 if (current_screen_type == SCREEN_GAME) |
2502 | 758 { |
759 pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Game_Action, 0, 0); | |
760 break; | |
761 } | |
2541 | 762 if ( current_screen_type == SCREEN_NPC_DIALOGUE ) |
2502 | 763 { |
764 if ( pMessageQueue_50CBD0->uNumMessages ) | |
765 { | |
766 pMessageQueue_50CBD0->uNumMessages = 0; | |
767 if ( pMessageQueue_50CBD0->pMessages[0].field_8 ) | |
768 { | |
769 pMessageQueue_50CBD0->uNumMessages = 1; | |
770 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape; | |
771 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0; | |
772 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].field_8 = 0; | |
773 ++pMessageQueue_50CBD0->uNumMessages; | |
774 break; | |
775 } | |
776 break; | |
777 } | |
778 pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 0, 0); | |
779 } | |
780 break; | |
781 case INPUT_CharCycle: | |
2541 | 782 if ( current_screen_type == SCREEN_SPELL_BOOK ) |
2502 | 783 break; |
784 | |
785 pMessageQueue_50C9E8->AddGUIMessage(UIMSG_CycleCharacters, 0, 0); | |
786 break; | |
787 case INPUT_LookUp: | |
788 if ( pEventTimer->bPaused ) | |
789 break; | |
790 partyAction = (PartyAction)7; | |
791 pPartyActionQueue->Add(partyAction); | |
792 break; | |
793 case INPUT_CenterView: | |
794 if ( pEventTimer->bPaused ) | |
795 break; | |
796 partyAction = (PartyAction)9; | |
797 pPartyActionQueue->Add(partyAction); | |
798 break; | |
799 case INPUT_LookDown: | |
800 if ( pEventTimer->bPaused ) | |
801 break; | |
802 partyAction = (PartyAction)8; | |
803 pPartyActionQueue->Add(partyAction); | |
804 break; | |
805 case INPUT_FlyUp: | |
2541 | 806 if ( current_screen_type || pEventTimer->bPaused ) |
2502 | 807 break; |
808 partyAction = (PartyAction)13; | |
809 pPartyActionQueue->Add(partyAction); | |
810 break; | |
811 case INPUT_Land: | |
2541 | 812 if ( current_screen_type || pEventTimer->bPaused ) |
2502 | 813 break; |
814 partyAction = (PartyAction)15; | |
815 pPartyActionQueue->Add(partyAction); | |
816 break; | |
817 case INPUT_FlyDown: | |
2541 | 818 if ( !current_screen_type && !pEventTimer->bPaused ) |
2502 | 819 { |
820 partyAction = (PartyAction)14; | |
821 pPartyActionQueue->Add(partyAction); | |
822 } | |
823 break; | |
824 case INPUT_ZoomIn: | |
825 pMessageQueue_50C9E8->AddGUIMessage(UIMSG_ClickZoomOutBtn, 0, 0); | |
826 break; | |
827 case INPUT_ZoomOut: | |
828 pMessageQueue_50C9E8->AddGUIMessage(UIMSG_ClickZoomInBtn, 0, 0); | |
829 break; | |
830 case INPUT_AlwaysRun: | |
831 bAlwaysRun = bAlwaysRun == 0; | |
832 break; | |
833 default: | |
834 break; | |
835 } | |
836 } | |
837 } | |
838 } | |
839 } |