changeset 2201:34035536bbf5

Finishing keyboard.cpp stuff
author Grumpy7
date Mon, 03 Feb 2014 23:06:14 +0100
parents f0477fe92362
children 44d956d4f838
files Game.cpp Keyboard.cpp Keyboard.h OSWindow.cpp mm7_6.cpp
diffstat 5 files changed, 50 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/Game.cpp	Mon Feb 03 00:58:12 2014 +0100
+++ b/Game.cpp	Mon Feb 03 23:06:14 2014 +0100
@@ -2308,9 +2308,9 @@
                               }
                             }
                             if ( uAction && uAction != 2 && uAction != 3 && uAction != 1 && uAction != 25 && uAction != 26 )
-                              pKeyToggleType = (KeyToggleType)1;
+                              pKeyToggleType = TOGGLE_OneTimePress;
                             else
-                              pKeyToggleType = (KeyToggleType)0;
+                              pKeyToggleType = TOGGLE_Continuously;
                             pKeyActionMap->SetKeyMapping(uAction, pPrevVirtualCidesMapping[uAction], pKeyToggleType);
                             ++uAction;
                           }
--- a/Keyboard.cpp	Mon Feb 03 00:58:12 2014 +0100
+++ b/Keyboard.cpp	Mon Feb 03 23:06:14 2014 +0100
@@ -73,10 +73,10 @@
 {
   std::tuple<const char*, const unsigned __int8>("UP", VK_UP),
   std::tuple<const char*, const unsigned __int8>("DOWN", VK_DOWN),
+  std::tuple<const char*, const unsigned __int8>("LEFT", VK_LEFT),
   std::tuple<const char*, const unsigned __int8>("бкебн", VK_LEFT),
-  std::tuple<const char*, const unsigned __int8>("LEFT", VK_LEFT),
+  std::tuple<const char*, const unsigned __int8>("RIGHT", VK_RIGHT),
   std::tuple<const char*, const unsigned __int8>("бопюбн", VK_RIGHT),
-  std::tuple<const char*, const unsigned __int8>("RIGHT", VK_RIGHT),
   std::tuple<const char*, const unsigned __int8>("RETURN", VK_RETURN),
   std::tuple<const char*, const unsigned __int8>("SPACE", VK_SPACE),
   std::tuple<const char*, const unsigned __int8>("PAGE_DOWN", VK_NEXT),
@@ -170,68 +170,57 @@
 }
 
 //----- (00459F10) --------------------------------------------------------
-bool KeyboardActionMapping::_459F10(unsigned int a2)
+bool KeyboardActionMapping::ProcessTextInput(unsigned int a2)
 {
-  int v3; // [sp-4h] [bp-4h]@3
-
   pKeyActionMap->uLastKeyPressed = a2;
   if ( uGameMenuUI_CurentlySelectedKeyIdx == -1 )
   {
-    if ( pKeyActionMap->field_204 == 1 )
+    if ( pKeyActionMap->field_204 != 1 && pKeyActionMap->field_204 != 2 )
+      return 0;
+    if ( a2 == VK_BACK)
     {
-      if ( a2 != 8 )
+      if (pKeyActionMap->uNumKeysPressed > 0)
       {
-        if ( a2 == 9 )
-          return 1;
-        if ( a2 == 13 )
-          goto LABEL_3;
-        if ( a2 == 27 )
-          goto LABEL_15;
-        if ( this->uNumKeysPressed >= this->max_input_string_len )
-          return 1;
-        pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = a2;
-        ++pKeyActionMap->uNumKeysPressed;
-LABEL_24:
+        --pKeyActionMap->uNumKeysPressed;
         pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = 0;
-        return 1;
       }
     }
-    else
+    else if ( a2 == VK_RETURN )
+    {
+      pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_CONFIRMED);
+    }
+    else if ( a2 == VK_ESCAPE )
     {
-      if ( pKeyActionMap->field_204 != 2 )
-        return 0;
-      if ( a2 != 8 )
+      pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_CANCELLED);
+    }
+    else if (this->uNumKeysPressed < this->max_input_string_len)
+    {
+      if ( pKeyActionMap->field_204 == 1 )
       {
-        if ( a2 == 13 )
-          goto LABEL_3;
-        if ( a2 != 27 )
+        if ( a2 != VK_TAB )
         {
-          if ( (signed int)a2 >= 48 && (signed int)a2 <= 57 )
-          {
-            if ( pKeyActionMap->uNumKeysPressed < this->max_input_string_len )
-            {
-              pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = a2;
-              ++pKeyActionMap->uNumKeysPressed;
-            }
-          }
-          return 1;
+          pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = a2;
+          ++pKeyActionMap->uNumKeysPressed;
+          pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = 0;
         }
-LABEL_15:
-        pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_CANCELLED);
-        return 1;
+      }
+      else if (pKeyActionMap->field_204 == 2)
+      {
+        if ( isdigit(a2))
+        {
+          pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = a2;
+          ++pKeyActionMap->uNumKeysPressed;
+        }
       }
     }
-    if ( !pKeyActionMap->uNumKeysPressed )
-      return 1;
-    --pKeyActionMap->uNumKeysPressed;
-    goto LABEL_24;
   }
-  pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = a2;
-  ++pKeyActionMap->uNumKeysPressed;
-  pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = 0;
-
-LABEL_3:
-  pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_CONFIRMED);
+  else
+  {
+    pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = a2;
+    ++pKeyActionMap->uNumKeysPressed;
+    pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = 0;
+    pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_CONFIRMED);
+  }
   return 1;
 }
 // 506E68: using guessed type int uGameMenuUI_CurentlySelectedKeyIdx;
@@ -312,7 +301,7 @@
 
   for ( size_t i = 0; i < keyNameToCodeTranslationMap.size(); i++)
   {
-    if ( a1 = std::get<1>(keyNameToCodeTranslationMap[i]))
+    if ( a1 == std::get<1>(keyNameToCodeTranslationMap[i]))
     {
       const char* keyName =  std::get<0>(keyNameToCodeTranslationMap[i]);
       strcpy_s(static_sub_45AE2C_string_69ADE0_keyName, keyName);
@@ -351,7 +340,7 @@
 void OnPressSpace()
 {
   //SHORT v0; // ax@2
-  int *v1; // eax@2
+  /*int *v1; // eax@2
   char *v2; // ebx@5
   unsigned int v3; // esi@5
   signed int v4; // edi@7
@@ -371,11 +360,11 @@
   int v19; // [sp+10h] [bp-10h]@8
   int *v20; // [sp+14h] [bp-Ch]@5
   int *v21; // [sp+18h] [bp-8h]@7
-  int v22; // [sp+1Ch] [bp-4h]@4
+  int v22; // [sp+1Ch] [bp-4h]@4*/
 
   //if ( pRenderer->pRenderD3D )
   {
-    pGame->PickKeyboard(GetAsyncKeyState(VK_CONTROL) & 0x8001, &vis_sprite_filter_3, &vis_door_filter);
+    pGame->PickKeyboard(Keyboard::IsKeyBeingHeld(VK_CONTROL), &vis_sprite_filter_3, &vis_door_filter);
     int pid = pGame->pVisInstance->get_picked_object_zbuf_val();
     if ( pid != -1 )
       DoInteractionWithTopmostZObject(pid & 0xFFFF, PID_ID(pid));
--- a/Keyboard.h	Mon Feb 03 00:58:12 2014 +0100
+++ b/Keyboard.h	Mon Feb 03 23:06:14 2014 +0100
@@ -55,7 +55,7 @@
   const unsigned __int8 TranslateKeyNameToKeyCode(const char *Str);
   void ReadMappings();
   void StoreMappings();
-  bool _459F10(unsigned int a2);
+  bool ProcessTextInput(unsigned int a2);
   void SetWindowInputStatus(int a2);
   void EnterText(int a2, int max_string_len, struct GUIWindow *pWindow);
   void ResetKeys();
@@ -84,7 +84,7 @@
     bUsingAsynKeyboard(false)
   {}
   bool WasKeyPressed(int vKey);
-  bool IsKeyBeingHeld(int vKey);
+  static bool IsKeyBeingHeld(int vKey);
   bool IsShiftHeld();
   void EnterCriticalSection();
 
--- a/OSWindow.cpp	Mon Feb 03 00:58:12 2014 +0100
+++ b/OSWindow.cpp	Mon Feb 03 23:06:14 2014 +0100
@@ -81,7 +81,7 @@
       return false;
 
     case WM_CHAR:
-      if (!pKeyActionMap->_459F10(wparam) && !viewparams->field_4C)
+      if (!pKeyActionMap->ProcessTextInput(wparam) && !viewparams->field_4C)
         GUI_HandleHotkey(wparam);
       return false;
 
@@ -201,7 +201,7 @@
     case WM_KEYDOWN:
       if ( uGameMenuUI_CurentlySelectedKeyIdx != -1 )
       {
-        pKeyActionMap->_459F10(wparam);
+        pKeyActionMap->ProcessTextInput(wparam);
         return false;
       }
       if ( !pArcomageGame->bGameInProgress )
--- a/mm7_6.cpp	Mon Feb 03 00:58:12 2014 +0100
+++ b/mm7_6.cpp	Mon Feb 03 23:06:14 2014 +0100
@@ -894,10 +894,10 @@
     for ( uint i = 0; i < 30; ++i )
     {
       inputAction = (InputAction)i;
-      if ( pKeyActionMap->pToggleTypes[(InputAction)i] )
-        v4 = pKeyboard->WasKeyPressed(pKeyActionMap->pVirtualKeyCodesMapping[(InputAction)i]);
+      if ( pKeyActionMap->pToggleTypes[inputAction] )
+        v4 = pKeyboard->WasKeyPressed(pKeyActionMap->pVirtualKeyCodesMapping[inputAction]);
       else
-        v4 = pKeyboard->IsKeyBeingHeld(pKeyActionMap->pVirtualKeyCodesMapping[(InputAction)i]);
+        v4 = pKeyboard->IsKeyBeingHeld(pKeyActionMap->pVirtualKeyCodesMapping[inputAction]);
       if ( v4 )
       {
         switch ( inputAction )