changeset 977:ac85898f5903

Слияние
author Ritor1
date Thu, 09 May 2013 01:33:54 +0600
parents 15c6b80caa3a (current diff) ec7568e13b24 (diff)
children 9334a8c59c8d
files UIPartyCreation.cpp mm7_5.cpp
diffstat 18 files changed, 230 insertions(+), 247 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/Actor.cpp	Thu May 09 01:33:54 2013 +0600
@@ -246,7 +246,7 @@
              || pNPCInfo->uProfession > 38 && (pNPCInfo->uProfession <= 43 || pNPCInfo->uProfession == 52)) )
         {
           pDialogueWindow->CreateButton(480, 250, 140, LOBYTE(pFontArrus->uFontHeight) - 3, 1, 0, UIMSG_SelectNPCDialogueOption, 9, 0, "", 0);
-          pDialogueWindow->_41D08F(4, 1, 0, 1);
+          pDialogueWindow->_41D08F_set_keyboard_control_group(4, 1, 0, 1);
         }
       }
     }
--- a/GUIWindow.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/GUIWindow.cpp	Thu May 09 01:33:54 2013 +0600
@@ -276,7 +276,7 @@
 }
 
 //----- (0041D08F) --------------------------------------------------------
-void GUIWindow::_41D08F(int a2, int a3, int a4, int a5)
+void GUIWindow::_41D08F_set_keyboard_control_group(int a2, int a3, int a4, int a5)
 {
   if ( a2 )
   {
@@ -285,7 +285,7 @@
     this->field_34 = a4;
     this->pCurrentPosActiveItem = a5;
     this->pStartingPosActiveItem = a5;
-    this->field_44 = 1;
+    this->receives_keyboard_input = true;
   }
   else
   {
@@ -294,7 +294,7 @@
     this->field_34 = a4;
     this->pCurrentPosActiveItem = 0;
     this->pStartingPosActiveItem = 0;
-    this->field_44 = 0;
+    this->receives_keyboard_input = false;
   }
 }
 
@@ -962,7 +962,7 @@
 
   CreateButton(0, 0, 0, 0, 1, 0, UIMSG_33, 0, '\t', "", 0);
   if ( a2 )
-    _41D08F(a2, 0, 0, 0);
+    _41D08F_set_keyboard_control_group(a2, 0, 0, 0);
 
   if (pPlayer->pActiveSkills[PLAYER_SKILL_FIRE])   CreateButton(399,  10, 50, 36, 1, 0, UIMSG_OpenSpellbookPage, 0, 0, aSpellSchoolNames[0], 0);
   if (pPlayer->pActiveSkills[PLAYER_SKILL_AIR])    CreateButton(399,  46, 50, 36, 1, 0, UIMSG_OpenSpellbookPage, 1, 0, aSpellSchoolNames[1], 0);
@@ -1755,7 +1755,7 @@
   pWindow->uFrameY = uY;
   pWindow->uFrameHeight = uHeight;
   pWindow->eWindowType = eWindowType;
-  pWindow->field_44 = 0;
+  pWindow->receives_keyboard_input = false;
   ++uNumVisibleWindows;
   pWindow->numVisibleWindows = uNumVisibleWindows;
   pVisibleWindowsIdxs[uNumVisibleWindows] = uNextFreeWindowID + 1;
@@ -1857,7 +1857,7 @@
                 num_menu_buttons = 2;
               }
             }
-            pWindow->_41D08F(num_menu_buttons, 1, 0, 1);
+            pWindow->_41D08F_set_keyboard_control_group(num_menu_buttons, 1, 0, 1);
           }
           break;
 
--- a/GUIWindow.h	Thu May 09 01:33:38 2013 +0600
+++ b/GUIWindow.h	Thu May 09 01:33:54 2013 +0600
@@ -330,7 +330,7 @@
   void DrawMessageBox(int arg0);
   GUIButton *GetControl(unsigned int uID);
   void Release();
-  void _41D08F(int a2, int a3, int a4, int a5);
+  void _41D08F_set_keyboard_control_group(int a2, int a3, int a4, int a5);
   void DrawQuickCharRecord();
   char _41D73D_draw_buff_tooltip();
 
@@ -356,7 +356,7 @@
   int pStartingPosActiveItem;
   int numVisibleWindows;
   int field_40;
-  int field_44;
+  int receives_keyboard_input;
   char *Hint;
   GUIButton *pControlsHead;
   GUIButton *pControlsTail;
--- a/Items.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/Items.cpp	Thu May 09 01:33:54 2013 +0600
@@ -2314,7 +2314,7 @@
 		++dword_F8B1DC;
 		CreateButtonInColumn(i+1, v29);
 		}
-	pDialogueWindow->_41D08F(i, 1, 0, 2);
+	pDialogueWindow->_41D08F_set_keyboard_control_group(i, 1, 0, 2);
 	dword_F8B1E0 = pDialogueWindow->pNumPresenceButton;
 	}
 
--- a/Mouse.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/Mouse.cpp	Thu May 09 01:33:54 2013 +0600
@@ -254,8 +254,8 @@
 //----- (00469C0D) --------------------------------------------------------
 void *Mouse::DoAllocCursorMem()
 {
-  return malloc(4 * (this->uCursorTextureID != -1 ? pIcons_LOD->pTextures[this->uCursorTextureID].uTextureWidth : 24)
-                  * (this->uCursorTextureID != -1 ? pIcons_LOD->pTextures[this->uCursorTextureID].uTextureHeight : 26));
+  auto tex = pIcons_LOD->GetTexture(uCursorTextureID);
+  return malloc(4 * tex->uTextureWidth * tex->uTextureHeight);
 }
 
 //----- (00469C39) --------------------------------------------------------
@@ -1331,7 +1331,7 @@
       {
         pGame->PickMouse(512.0, *v4, *(int *)(v2 + 16), 0, &a3, &a4);
         if ( GetCurrentMenuID() == 6 )
-          sub_41CD4F(0x29u);
+          UI_OnKeyDown(VK_SELECT);
         UI_OnMouseLeftClick((int *)(v2 + 12));
       }
       else
--- a/Player.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/Player.cpp	Thu May 09 01:33:54 2013 +0600
@@ -1360,20 +1360,18 @@
 //----- (00492528) --------------------------------------------------------
 bool Player::CanFitItem(unsigned int uSlot, unsigned int uItemID)
 {
-  unsigned int v3; // eax@1
+  //unsigned int v3; // eax@1
   Texture *v4; // esi@1
   unsigned int v5; // ebx@1
   signed int v6; // edi@5
   int *v7; // ecx@6
   signed int v8; // edx@7
   int *v9; // eax@8
-  Player *v11; // [sp+Ch] [bp-4h]@1
+  //Player *v11; // [sp+Ch] [bp-4h]@1
   unsigned int uItemIDa; // [sp+1Ch] [bp+Ch]@1
 
-  v11 = this;
-  v3 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
-  v4 = (Texture *)(v3 != -1 ? &pIcons_LOD->pTextures[v3] : 0);
-  v5 = GetSizeInInventorySlots(v3 != -1 ? pIcons_LOD->pTextures[v3].uTextureWidth : 24);
+  v4 = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
+  v5 = GetSizeInInventorySlots(v4->uTextureWidth);
   uItemIDa = GetSizeInInventorySlots(v4->uTextureHeight);
   if ( !areWeLoadingTexture )
   {
@@ -1385,7 +1383,7 @@
     v6 = 0;
     if ( (signed int)uItemIDa <= 0 )
       return 1;
-    v7 = &v11->pInventoryIndices[uSlot];
+    v7 = &pInventoryIndices[uSlot];
     while ( 1 )
     {
       v8 = 0;
@@ -1435,7 +1433,7 @@
   ItemGen *v4; // eax@1
   int result; // eax@8
   unsigned int v6; // ebx@10
-  unsigned int v7; // eax@10
+  //unsigned int v7; // eax@10
   Texture *v8; // esi@10
   void *v9; // esi@13
   unsigned int v10; // [sp+0h] [bp-Ch]@10
@@ -1467,9 +1465,8 @@
   else
   {
     v6 = uItemID;
-    v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
-    v8 = (Texture *)(v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0);
-    v10 = GetSizeInInventorySlots(v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24);
+    v8 = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
+    v10 = GetSizeInInventorySlots(v8->uTextureWidth);
     uItemIDa = GetSizeInInventorySlots(v8->uTextureHeight);
     if ( !areWeLoadingTexture )
     {
@@ -1523,6 +1520,8 @@
   char *v5; // eax@6
   char *v6; // esi@6
 
+  __debugbreak(); // sub is definetly broken
+
   v2 = 0;
   v3 = this->pInventoryItems;
   while ( v3->uItemID )
@@ -1647,7 +1646,7 @@
   signed int v3; // ebx@1
   ItemGen *v4; // eax@1
   int result; // eax@6
-  unsigned int v6; // eax@7
+  //unsigned int v6; // eax@7
   Texture *v7; // esi@7
   unsigned int v8; // edx@9
   void *v9; // esi@10
@@ -1675,11 +1674,8 @@
   }
   else
   {
-    v6 = pIcons_LOD->LoadTexture(
-           pItemsTable->pItems[Src->uItemID].pIconName,
-           TEXTURE_16BIT_PALETTE);
-    v7 = (Texture *)(v6 != -1 ? (int)&pIcons_LOD->pTextures[v6] : 0);
-    v10 = GetSizeInInventorySlots(v6 != -1 ? pIcons_LOD->pTextures[v6].uTextureWidth : 24);
+    v7 = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[Src->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
+    v10 = GetSizeInInventorySlots(v7->uTextureWidth);
     v11 = GetSizeInInventorySlots(v7->uTextureHeight);
     if ( !areWeLoadingTexture )
     {
@@ -1711,17 +1707,15 @@
 //----- (0049298B) --------------------------------------------------------
 bool Player::_49298B(ItemGen *a2, int a3, int a4)
 {
-  Player *v4; // ebx@1
-  unsigned int v5; // eax@1
+  //Player *v4; // ebx@1
+  //unsigned int v5; // eax@1
   Texture *v6; // esi@1
   void *v7; // esi@4
   unsigned int v9; // [sp+Ch] [bp-4h]@1
   unsigned int a2a; // [sp+18h] [bp+8h]@1
 
-  v4 = this;
-  v5 = pIcons_LOD->LoadTexture(pItemsTable->pItems[a2->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
-  v6 = (Texture *)(v5 != -1 ? (int)&pIcons_LOD->pTextures[v5] : 0);
-  v9 = GetSizeInInventorySlots(v5 != -1 ? pIcons_LOD->pTextures[v5].uTextureWidth : 24);
+  v6 = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[a2->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
+  v9 = GetSizeInInventorySlots(v6->uTextureWidth);
   a2a = GetSizeInInventorySlots(v6->uTextureHeight);
   if ( !areWeLoadingTexture )
   {
@@ -1730,7 +1724,7 @@
   }
   if ( (signed int)a2a > 0 )
   {
-    v7 = &v4->pInventoryIndices[a4];
+    v7 = &pInventoryIndices[a4];
     do
     {
       if ( (signed int)v9 > 0 )
@@ -1740,7 +1734,7 @@
     }
     while ( a2a );
   }
-  v4->pInventoryIndices[a4] = a3 + 1;
+  pInventoryIndices[a4] = a3 + 1;
   return 1;
 }
 
@@ -1752,7 +1746,7 @@
   int *pIndices; // edi@1
   ItemGen *v3; // ecx@1
   unsigned int v4; // esi@1
-  unsigned int v5; // eax@1
+  //unsigned int v5; // eax@1
   Texture *v6; // esi@1
   unsigned int result; // eax@1
   unsigned int v8; // ebp@1
@@ -1763,9 +1757,8 @@
   v3 = &this->pInventoryItems[*pIndices-1];
   v4 = v3->uItemID;
   v3->Reset();
-  v5 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v4].pIconName, TEXTURE_16BIT_PALETTE);
-  v6 = (Texture *)(v5 != -1 ? (int)&pIcons_LOD->pTextures[v5] : 0);
-  uSlota = GetSizeInInventorySlots(v5 != -1 ? pIcons_LOD->pTextures[v5].uTextureWidth : 24);
+  v6 = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[v4].pIconName, TEXTURE_16BIT_PALETTE);
+  uSlota = GetSizeInInventorySlots(v6->uTextureWidth);
   result = GetSizeInInventorySlots(v6->uTextureHeight);
   v8 = result;
   if ( !areWeLoadingTexture )
@@ -2380,7 +2373,7 @@
   unsigned int v3; // ecx@4
   signed int v4; // edx@4
   char *v5; // eax@8
-  unsigned int v6; // eax@10
+  //unsigned int v6; // eax@10
   Texture *v7; // ebx@10
   signed int v8; // esi@10
   Player *v9; // edi@11
@@ -2422,8 +2415,7 @@
   v5 = pItemsTable->pItems[v2].pIconName;
   if ( v5 )
   {
-    v6 = pIcons_LOD->LoadTexture(v5, TEXTURE_16BIT_PALETTE);
-    v7 = (Texture *)(v6 != -1 ? &pIcons_LOD->pTextures[v6] : 0);
+    v7 = pIcons_LOD->LoadTexturePtr(v5, TEXTURE_16BIT_PALETTE);
     v21 = areWeLoadingTexture;
     v8 = 0;
     while ( 1 )
--- a/Render.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/Render.cpp	Thu May 09 01:33:54 2013 +0600
@@ -208,7 +208,7 @@
 }
 
 //----- (00487389) --------------------------------------------------------
-__int16 Render::ExecOutdoorDrawSW()
+void Render::ExecOutdoorDrawSW()
 {
   unsigned __int16 *v0; // ebx@1
   unsigned int v1; // esi@1
@@ -227,7 +227,7 @@
   int v14; // ecx@37
   int v15; // eax@40
   Texture *v16; // ebp@51
-  unsigned int v17; // eax@51
+  //unsigned int v17; // eax@51
   int v18; // eax@54
   char v19; // al@56
   unsigned int v20; // eax@57
@@ -315,8 +315,7 @@
                     while ( 1 )
                     {
                       v16 = v4->pTexture;
-                      v17 = pBitmaps_LOD->LoadTexture("wtrtyl");
-                      v4->pTexture = (Texture *)(v17 != -1 ? (int)&pBitmaps_LOD->pTextures[v17] : 0);
+                      v4->pTexture = pBitmaps_LOD->LoadTexturePtr("wtrtyl");
                       if ( pOutdoorCamera->outdoor_no_wavy_water )
                         sr_sub_48408A_prolly_odm_water_no_waves(v3);
                       else
@@ -549,12 +548,19 @@
   }
   v9 = pOutdoorCamera->uNumSpans;
   unnamed_6BE060[0] = pOutdoorCamera->uNumSpans;
-  if ( pOutdoorCamera->numStru148s >= 1999
-    || (array_77EC08[1999]._48607B(&stru_8019C8),
-        array_77EC08[1999].ptr_38->_48694B(),
-        v2 = (stru148 *)&pBitmaps_LOD->pTextures[pOutdoor->uMainTile_BitmapID],
-        (array_77EC08[1999].pTexture = (Texture *)(pOutdoor->uMainTile_BitmapID != -1 ? (int)v2 : 0)) == 0) )
-    return (signed __int16)v2;
+  if (pOutdoorCamera->numStru148s >= 1999)
+    return;
+
+  array_77EC08[1999]._48607B(&stru_8019C8);
+  array_77EC08[1999].ptr_38->_48694B();
+
+  if (pOutdoor->uMainTile_BitmapID == -1)
+  {
+    array_77EC08[1999].pTexture = nullptr;
+    return;
+  }
+  else
+    array_77EC08[1999].pTexture = pBitmaps_LOD->GetTexture(pOutdoor->uMainTile_BitmapID);
   array_77EC08[1999].dimming_level = 23 - (-20 * pOutdoor->vSunlight.z >> 16);
   if ( array_77EC08[1999].dimming_level > 20 )
     array_77EC08[1999].dimming_level = 20;
@@ -570,10 +576,14 @@
   sin((double)pIndoorCamera->sRotationX * 0.0030664064);
   array_77EC08[1999]._48607B(&stru_8019C8);
   array_77EC08[1999].ptr_38->_48694B();
-  v2 = (stru148 *)&pBitmaps_LOD->pTextures[pOutdoor->uSky_TextureID];
-  array_77EC08[1999].pTexture = (Texture *)(pOutdoor->uSky_TextureID != -1 ? (int)v2 : 0);
-  if ( !(pOutdoor->uSky_TextureID != -1 ? (int)v2 : 0) )
-    return (signed __int16)v2;
+
+  if (pOutdoor->uSky_TextureID == -1)
+  {
+    array_77EC08[1999].pTexture = nullptr;
+    return;
+  }
+  else
+    array_77EC08[1999].pTexture = pBitmaps_LOD->GetTexture(pOutdoor->uSky_TextureID);
   array_77EC08[1999].dimming_level = 0;
   v11 = stru_5C6E00->Sin(pIndoorCamera->sRotationX + 16);
   array_77EC08[1999].v_18.y = 0;
@@ -591,7 +601,7 @@
     v2 = (stru148 *)*(short *)PaletteManager::Get_Mist_or_Red_LUT(array_77EC08[1999].pTexture->palette_id2, 31, 1);
     a1b = (unsigned int)v2;
     if ( (signed int)v9 <= 0 )
-      return (signed __int16)v2;
+      return;
     v29 = v9;
     while ( 1 )
     {
@@ -630,7 +640,7 @@
       --v29;
       --v9;
       if ( !v9 )
-        return (signed __int16)v2;
+        return;
     }
   }
   if ( (signed int)v9 > 0 )
@@ -675,7 +685,6 @@
     }
     while ( v9 );
   }
-  return (signed __int16)v2;
 }
 
 //----- (00485044) --------------------------------------------------------
--- a/Render.h	Thu May 09 01:33:38 2013 +0600
+++ b/Render.h	Thu May 09 01:33:54 2013 +0600
@@ -367,7 +367,7 @@
   void RenderTerrainD3D();
   void DrawTerrainD3D(int a1, int edx0, int a3);
   void DrawTerrainSW(int a1, int a2, int a3);
-  __int16 ExecOutdoorDrawSW();
+  void ExecOutdoorDrawSW();
   void ChangeBetweenWinFullscreenModes();
   void DrawBillboardList_BLV();
 
--- a/Texture.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/Texture.cpp	Thu May 09 01:33:54 2013 +0600
@@ -277,12 +277,12 @@
     for ( i = uIconID; ; ++i )
     {
       v3->pTextures[i].uTextureID = pBitmaps_LOD->LoadTexture(v3->pTextures[i].pTextureName, TEXTURE_DEFAULT);
-      auto pTex = (v3->pTextures[i].uTextureID != -1 ? &pBitmaps_LOD->pTextures[v3->pTextures[i].uTextureID] : 0);
-      if (pTex)
-        pTex->palette_id2 = pPaletteManager->LoadPalette(pTex->palette_id1);
+
+      if (v3->pTextures[i].uTextureID != -1);
+        pBitmaps_LOD->pTextures[v3->pTextures[i].uTextureID].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[v3->pTextures[i].uTextureID].palette_id1);
       //result = (unsigned int)v3->pTextures;
       //if ( !(*(char *)(result + i * 20 + 18) & 1) )
-      if( v3->pTextures[i].uFlags&1)
+      if( v3->pTextures[i].uFlags & 1)
         break;
     }
   }
--- a/UIBooks.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/UIBooks.cpp	Thu May 09 01:33:54 2013 +0600
@@ -208,7 +208,7 @@
   v0 = pPlayers[uActiveCharacter];
   v1 = 11 * v0->lastOpenedSpellbookPage;
   v2 = pIcons_LOD->FindTextureByName("Pending");
-  v3 = (Texture *)(v2 != -1 ? (int)&pIcons_LOD->pTextures[v2] : 0);
+  v3 = pIcons_LOD->GetTexture(v2);
   pRenderer->ClearZBuffer(0, 479);
   v4 = 1;
   if ( __OFSUB__(v1, v1 + 11) ^ 1 )
@@ -1379,7 +1379,7 @@
             else
                 v50 = 1;
             }
-        pRenderer->DrawTransparentRedShade(v47, v49, (Texture *)(pTextureIDs_pMapDirs[v50] != -1 ? (int)&pIcons_LOD->pTextures[pTextureIDs_pMapDirs[v50]] : 0));
+        pRenderer->DrawTransparentRedShade(v47, v49, pIcons_LOD->GetTexture(pTextureIDs_pMapDirs[v50]));
         }
     result = TargetColor(0xFFu, 0xFFu, 0xFFu);
     v95 = 0;
--- a/UICharacter.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/UICharacter.cpp	Thu May 09 01:33:54 2013 +0600
@@ -2589,7 +2589,7 @@
                     }
                     while ( v17 <= &pMiscSkills[11] );
                     if ( a2 )
-                        pGUIWindow_CurrentMenu->_41D08F(a2, 1, 0, a5);
+                        pGUIWindow_CurrentMenu->_41D08F_set_keyboard_control_group(a2, 1, 0, a5);
     }
 
 //----- (00418511) --------------------------------------------------------
--- a/UIPartyCreation.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/UIPartyCreation.cpp	Thu May 09 01:33:54 2013 +0600
@@ -132,7 +132,7 @@
         return result;
     }
 //----- (00495B39) --------------------------------------------------------
-void __cdecl PlayerCreationUI_Draw()
+void PlayerCreationUI_Draw()
 {
   int pTextCenter; // eax@3
   IconFrame *pFrame; // eax@3
@@ -185,7 +185,18 @@
   pRenderer->DrawTextureIndexed(uPlayerCreationUI_SkySliderPos, 2, pTexture_MAKESKY);
   pRenderer->DrawTextureIndexed(uPlayerCreationUI_SkySliderPos - 640, 2, pTexture_MAKESKY);
   pRenderer->DrawTextureTransparent(0, 0, pTexture_MAKETOP);
+
   uPlayerCreationUI_SelectedCharacter = (pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem) / 7;
+  switch (uPlayerCreationUI_SelectedCharacter)
+  {
+    case 0: pX = 12;  break;
+    case 1: pX = 171; break;
+    case 2: pX = 329; break;
+    case 3: pX = 488; break;
+    default:
+      assert(false && "Invalid selected character");
+  }
+
   pTextCenter = pFontCChar->AlignText_Center(640, pGlobalTXT_LocalizationStrings[51]);
   pGUIWindow_CurrentMenu->DrawText(pFontCChar, pTextCenter + 1, 0, 0, pGlobalTXT_LocalizationStrings[51], 0, 0, 0);
   pRenderer->DrawTextureTransparent(17, 35, pPlayerPortraits[pParty->pPlayers[0].uFace]);
@@ -193,31 +204,14 @@
   pRenderer->DrawTextureTransparent(335, 35, pPlayerPortraits[pParty->pPlayers[2].uFace]);
   pRenderer->DrawTextureTransparent(494, 35, pPlayerPortraits[pParty->pPlayers[3].uFace]);
   pFrame = pIconsFrameTable->GetFrame(uIconID_CharacterFrame, pEventTimer->uStartTime);
-  switch ( uPlayerCreationUI_SelectedCharacter )
-  {
-    case 0:
-      pX = 12;
-      break;
-    case 1:
-      pX = 171;
-      break;
-    case 2:
-      pX = 329;
-      break;
-    case 3:
-      pX = 488;
-      break;
-    default:
-      assert(false);//if click "Knight" crash
-      //pX = v123;
-      break;
-  }
+
 
   pRenderer->DrawTextureTransparent(pX, 29, &pIcons_LOD->pTextures[pFrame->uTextureID]);
   uPosActiveItem = pGUIWindow_CurrentMenu->GetControl(pGUIWindow_CurrentMenu->pCurrentPosActiveItem);
   uPlayerCreationUI_ArrowAnim = 19 - (GetTickCount() % 500) / 25;
   pRenderer->DrawTextureTransparent(uPosActiveItem->uZ - 4, uPosActiveItem->uY, pTextures_arrowl[uPlayerCreationUI_ArrowAnim]);
   pRenderer->DrawTextureTransparent(uPosActiveItem->uX - 12, uPosActiveItem->uY, pTextures_arrowr[uPlayerCreationUI_ArrowAnim]);
+
   memset(pText, 0, 200);
   strcpy(pText, pGlobalTXT_LocalizationStrings[205]);// "Skills"
   uNumLet = strlen(pText) - 1;
@@ -605,10 +599,10 @@
   }
   while ( (signed int)uXb < 640 );
 
-  pGUIWindow_CurrentMenu->CreateButton(  5, 21, 153, 365, 1, 0, UIMSG_PlayerCreation_SelectAttribute, 0, 0x31u, "", 0);
-  pGUIWindow_CurrentMenu->CreateButton(163, 21, 153, 365, 1, 0, UIMSG_PlayerCreation_SelectAttribute, 1, 0x32u, "", 0);
-  pGUIWindow_CurrentMenu->CreateButton(321, 21, 153, 365, 1, 0, UIMSG_PlayerCreation_SelectAttribute, 2, 0x33u, "", 0);
-  pGUIWindow_CurrentMenu->CreateButton(479, 21, 153, 365, 1, 0, UIMSG_PlayerCreation_SelectAttribute, 3, 0x34u, "", 0);
+  pGUIWindow_CurrentMenu->CreateButton(  5, 21, 153, 365, 1, 0, UIMSG_PlayerCreation_SelectAttribute, 0, '1', "", 0);
+  pGUIWindow_CurrentMenu->CreateButton(163, 21, 153, 365, 1, 0, UIMSG_PlayerCreation_SelectAttribute, 1, '2', "", 0);
+  pGUIWindow_CurrentMenu->CreateButton(321, 21, 153, 365, 1, 0, UIMSG_PlayerCreation_SelectAttribute, 2, '3', "", 0);
+  pGUIWindow_CurrentMenu->CreateButton(479, 21, 153, 365, 1, 0, UIMSG_PlayerCreation_SelectAttribute, 3, '4', "", 0);
 
   uXc = 23;
   uControlParamc = 2;
@@ -625,7 +619,8 @@
     uXc += 158;
   }
   while ( (signed int)uControlParamc < 30 );
-  pGUIWindow_CurrentMenu->_41D08F(28, 0, 7, 40);
+  pGUIWindow_CurrentMenu->_41D08F_set_keyboard_control_group(28, 0, 7, 40);
+
   pGUIWindow_CurrentMenu->CreateButton(323, 417,          65, v0, 1, 0, UIMSG_PlayerCreationSelectClass, 0,    0, "", 0);
   pGUIWindow_CurrentMenu->CreateButton(323, v0 + 417,     65, v0, 1, 0, UIMSG_PlayerCreationSelectClass, 0xC,  0, "", 0);
   pGUIWindow_CurrentMenu->CreateButton(323, 2 * v0 + 417, 65, v0, 1, 0, UIMSG_PlayerCreationSelectClass, 0x14, 0, "", 0);
@@ -635,6 +630,7 @@
   pGUIWindow_CurrentMenu->CreateButton(453, 417,          65, v0, 1, 0, UIMSG_PlayerCreationSelectClass, 0x10, 0, "", 0);
   pGUIWindow_CurrentMenu->CreateButton(453, v0 + 417,     65, v0, 1, 0, UIMSG_PlayerCreationSelectClass, 8,    0, "", 0);
   pGUIWindow_CurrentMenu->CreateButton(453, 2 * v0 + 417, 65, v0, 1, 0, UIMSG_PlayerCreationSelectClass, 4,    0, "", 0);
+
   uControlParamd = 0;
   do
   {
@@ -646,6 +642,7 @@
     ++uControlParamd;
   }
   while ( uControlParamd < 9 );
+
   pPlayerCreationUI_BtnOK    = pGUIWindow_CurrentMenu->CreateButton(580, 431, 51, 39, 1, 0, UIMSG_PlayerCreationClickOK, 0, 0xD, "", pIcons_LOD->GetTexture(uTextureID_BUTTMAKE), 0);
   pPlayerCreationUI_BtnReset = pGUIWindow_CurrentMenu->CreateButton(527, 431, 51, 39, 1, 0, UIMSG_PlayerCreationClickReset, 0, 0x43, "", pIcons_LOD->GetTexture(uTextureID_BUTTMAKE2), 0);
   pPlayerCreationUI_BtnMinus = pGUIWindow_CurrentMenu->CreateButton(523, 393, 20, 35, 1, 0, UIMSG_PlayerCreationClickMinus, 0, 0x2D, "", pTexture_buttminu, 0);
--- a/mm7_1.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/mm7_1.cpp	Thu May 09 01:33:54 2013 +0600
@@ -99,17 +99,17 @@
         j->uY = dword_506988;
         j->uZ = dword_506984;
         j->uW = dword_506980;
-        pGUIWindow_CurrentMenu->_41D08F(1, 0, 0, 0);
+        pGUIWindow_CurrentMenu->_41D08F_set_keyboard_control_group(1, 0, 0, 0);
       }
     }
   }
 }
 
 //----- (0041CD4F) --------------------------------------------------------
-bool __thiscall sub_41CD4F(unsigned int _this)
+bool UI_OnKeyDown(unsigned int vkKey)
 {
-  unsigned int v1; // edi@1
-  unsigned int v2; // eax@2
+  //unsigned int v1; // edi@1
+  //unsigned int v2; // eax@2
   int v3; // esi@3
   int v4; // ecx@10
   GUIButton *v5; // eax@11
@@ -132,25 +132,26 @@
   int v23; // edx@59
   int v24; // ecx@60
   int v25; // esi@63
-  unsigned int v26; // [sp+Ch] [bp-14h]@1
-  int v27; // [sp+10h] [bp-10h]@1
+  //unsigned int v26; // [sp+Ch] [bp-14h]@1
+  //int v27; // [sp+10h] [bp-10h]@1
   int v28; // [sp+14h] [bp-Ch]@10
   int v29; // [sp+14h] [bp-Ch]@36
   unsigned int uClickX; // [sp+18h] [bp-8h]@10
   unsigned int uClickY; // [sp+1Ch] [bp-4h]@10
 
-  v1 = 0;
-  v26 = _this;
-  v27 = uNumVisibleWindows;
+  //v1 = 0;
+  //v27 = uNumVisibleWindows;
   if ( uNumVisibleWindows < 0 )
     return 0;
-  v2 = pMessageQueue_50CBD0->uNumMessages;
-  while ( 1 )
+  //v2 = pMessageQueue_50CBD0->uNumMessages;
+  for (int i = uNumVisibleWindows; i >= 0; --i)
+  //while ( 1 )
   {
-    v3 = pVisibleWindowsIdxs[v27] - 1;
-    if ( pWindowList[v3].field_44 != v1 )
-	{
-		switch(v26)
+    v3 = pVisibleWindowsIdxs[i] - 1;
+    if (!pWindowList[v3].receives_keyboard_input)
+      continue;
+
+		switch (vkKey)
 		{
 			case VK_LEFT:
 				{
@@ -161,17 +162,17 @@
 				  pWindowList[v3].pCurrentPosActiveItem -= v12;
 				  if ( v8 )
 				  {
-					pAudioPlayer->PlaySound(SOUND_Button, v1, v1, -1, v1, v1, v1, v1);
-					v2 = pMessageQueue_50CBD0->uNumMessages;
+					pAudioPlayer->PlaySound(SOUND_Button, 0, 0, -1, 0, 0, 0, 0);
+					//v2 = pMessageQueue_50CBD0->uNumMessages;
 				  }
 				}
-				if ( pWindowList[v3].field_30 != v1 )
+				if ( pWindowList[v3].field_30 != 0 )
 				{
 					break;
 				}
 				v9 = pWindowList[v3].pControlsHead;
 				v13 = pWindowList[v3].pCurrentPosActiveItem;
-				if ( v13 > (signed int)v1 )
+				if ( v13 > 0)
 				{
 				  do
 				  {
@@ -181,7 +182,7 @@
 				  while ( v13 );
 				}
 
-                pMessageQueue_50CBD0->AddMessage(v9->msg, v9->msg_param, v1);
+                pMessageQueue_50CBD0->AddMessage(v9->msg, v9->msg_param, 0);
 				break;
 				}
 			case VK_RIGHT:
@@ -193,17 +194,17 @@
 					pWindowList[v3].pCurrentPosActiveItem = v7;
 					if ( v8 )
 					{
-						pAudioPlayer->PlaySound(SOUND_Button, v1, v1, -1, v1, v1, v1, v1);
-						v2 = pMessageQueue_50CBD0->uNumMessages;
+						pAudioPlayer->PlaySound(SOUND_Button, 0, 0, -1, 0, 0, 0, 0);
+						//v2 = pMessageQueue_50CBD0->uNumMessages;
 					}
 				}
-				if ( pWindowList[v3].field_30 != v1 )
+				if ( pWindowList[v3].field_30 != 0 )
 				{
 					break;
 				}
 				v9 = pWindowList[v3].pControlsHead;
 				v10 = pWindowList[v3].pCurrentPosActiveItem;
-				if ( v10 > (signed int)v1 )
+				if ( v10 > 0)
 				{
 					do
 					{
@@ -212,7 +213,7 @@
 					}
 					while ( v10 );
 				}
-				pMessageQueue_50CBD0->AddMessage(v9->msg, v9->msg_param, v1);
+				pMessageQueue_50CBD0->AddMessage(v9->msg, v9->msg_param, 0);
 				break;				
 				}
 			case VK_DOWN:
@@ -223,11 +224,11 @@
 					pWindowList[v3].pCurrentPosActiveItem = v17;
 				else
 					pWindowList[v3].pCurrentPosActiveItem = v18 + 1;
-				if ( pWindowList[v3].field_30 != v1 )
+				if ( pWindowList[v3].field_30 != 0 )
 					return 1;
 				v19 = pWindowList[v3].pControlsHead;
 				v20 = pWindowList[v3].pCurrentPosActiveItem;
-				if ( v20 > (signed int)v1 )
+				if ( v20 > 0)
 				{
 					do
 					{
@@ -236,7 +237,7 @@
 					}
 					while ( v20 );
 				}
-				pMessageQueue_50CBD0->AddMessage(v19->msg, v19->msg_param, v1);
+				pMessageQueue_50CBD0->AddMessage(v19->msg, v19->msg_param, 0);
 				return 1;
 				}
 			case VK_SELECT:
@@ -267,10 +268,10 @@
 						++v4;
 						if ( v4 >= v28 )
 						{
-							v1 = 0;
-							v2 = pMessageQueue_50CBD0->uNumMessages;
-							--v27;
-							if ( v27 < 0 )
+							//v1 = 0;
+							//v2 = pMessageQueue_50CBD0->uNumMessages;
+							--i;
+							if ( i < 0 )
   								return 0;
 							continue;
 						}
@@ -278,7 +279,7 @@
 					pWindowList[v3].pCurrentPosActiveItem = v4;
 					return 1;
 				}
-				v2 = pMessageQueue_50CBD0->uNumMessages;
+				//v2 = pMessageQueue_50CBD0->uNumMessages;
 				break;
 				}
 			case VK_UP:
@@ -289,13 +290,13 @@
 					v24 = pWindowList[v3].pNumPresenceButton + v23 - 1;
 				else
 					v24 = v22 - 1;
-				v8 = pWindowList[v3].field_30 == v1;
+				v8 = pWindowList[v3].field_30 == 0;
 				pWindowList[v3].pCurrentPosActiveItem = v24;
 				if ( !v8 )
 					return 1;
 				v19 = pWindowList[v3].pControlsHead;
 				v25 = pWindowList[v3].pCurrentPosActiveItem;
-				if ( v25 > (signed int)v1 )
+				if ( v25 > 0)
 				{
 					do
 					{
@@ -305,12 +306,12 @@
 					while ( v25 );
 				}
 
-				pMessageQueue_50CBD0->AddMessage(v19->msg, v19->msg_param, v1);
+				pMessageQueue_50CBD0->AddMessage(v19->msg, v19->msg_param, 0);
 				return 1;
 				}
 			case VK_NEXT:
 				{
-				if ( pWindowList[v3].field_30 != v1 )
+				if ( pWindowList[v3].field_30 != 0 )
 				{
 					pMouse->GetClickPos(&uClickX, &uClickY);
 					v4 = pWindowList[v3].pStartingPosActiveItem;
@@ -341,15 +342,15 @@
 							++v4;
 							if ( v4 >= v29 )
 							{
-								v1 = 0;
-								v2 = pMessageQueue_50CBD0->uNumMessages;
+								//v1 = 0;
+								//v2 = pMessageQueue_50CBD0->uNumMessages;
 								break;
 							}
 						}
 					}
 					else
 					{
-						v2 = pMessageQueue_50CBD0->uNumMessages;
+						//v2 = pMessageQueue_50CBD0->uNumMessages;
 					}
 				}
 				break;
@@ -359,11 +360,7 @@
 				break;
 				}
 			
-		}
-	}
-    --v27;
-    if ( v27 < 0 )
-      return 0;
+        }
   }
 
 }
--- a/mm7_2.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/mm7_2.cpp	Thu May 09 01:33:54 2013 +0600
@@ -293,7 +293,7 @@
                  pIcons_LOD->GetTexture(uExitCancelTextureId), 0);
   pDialogueWindow->CreateButton(0, 0, 0, 0, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "", 0);
   pDialogueWindow->CreateButton(480u, 160u, 140u, 30u, 1, 0, UIMSG_0, 0x53u, 0, "", 0);
-  pDialogueWindow->_41D08F(1, 1, 0, 2);
+  pDialogueWindow->_41D08F_set_keyboard_control_group(1, 1, 0, 2);
   dialog_menu_id = HOUSE_DIALOGUE_OTHER;
   v0 = (int)((char *)window_SpeakInHouse->ptr_1C - 102);
   if ( (signed __int64)__PAIR__(pParty->field_3C.field_0[2 * v0 + 1], pParty->field_3C.field_0[2 * v0]) < (signed __int64)pParty->uTimePlayed )
@@ -438,7 +438,7 @@
     pDialogueWindow->CreateButton(0x1E0u, 0xBEu, 0x8Cu, 0x1Eu, 1, 0, UIMSG_SelectNPCDialogueOption, 0x56u, 0, "", 0);
     pDialogueWindow->CreateButton(0x1E0u, 0xDCu, 0x8Cu, 0x1Eu, 1, 0, UIMSG_SelectNPCDialogueOption, 0x57u, 0, "", 0);
     pDialogueWindow->CreateButton(0x1E0u, 0xFAu, 0x8Cu, 0x1Eu, 1, 0, UIMSG_SelectNPCDialogueOption, 0x58u, 0, "", 0);
-    pDialogueWindow->_41D08F(4, 1, 0, 1);
+    pDialogueWindow->_41D08F_set_keyboard_control_group(4, 1, 0, 1);
   }
 }
 // F8B1B4: using guessed type int dword_F8B1B4;
@@ -6792,7 +6792,7 @@
   int v25; // eax@171
   int v26; // eax@172
   char v27; // al@174
-  bool v28; // ebx@201
+  //bool v28; // ebx@201
   char v29; // dl@209
   char v30; // cl@210
   bool v31; // ebx@211
@@ -7014,7 +7014,6 @@
       case WM_SIZING:
         return 1;
       case WM_LBUTTONDOWN:
-        v28 = 0;
         if ( pArcomageGame->bGameInProgress )
         {
           if (pAsyncMouse)
@@ -7023,13 +7022,8 @@
           ArcomageGame::OnMouseClick(0, 1);
           return DefWindowProcA(hWnd, Msg, wParam, lParam);
         }
-        if ( pVideoPlayer->pVideoFrame.pPixels )
-          pVideoPlayer->bStopBeforeSchedule = 1;
-        if ( !pAsyncMouse )
-          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-        if (GetCurrentMenuID() != MENU_CREATEPARTY)
-          goto LABEL_230;
-        goto LABEL_229;
+        goto __handle_mouse_click;
+
       case WM_RBUTTONDOWN:
         v31 = 0;
         if ( !pArcomageGame->bGameInProgress )
@@ -7097,8 +7091,8 @@
         v30 = 1;
         ArcomageGame::OnMouseClick(v30, v29);
         return DefWindowProcA(hWnd, Msg, wParam, lParam);
+
       case WM_LBUTTONDBLCLK:
-        v28 = 0;
         if ( pArcomageGame->bGameInProgress )
         {
           if (pAsyncMouse)
@@ -7107,34 +7101,31 @@
           pArcomageGame->stru1.field_0 = 7;
           return DefWindowProcA(hWnd, Msg, wParam, lParam);
         }
+        
+__handle_mouse_click:
         if ( pVideoPlayer->pVideoFrame.pPixels )
           pVideoPlayer->bStopBeforeSchedule = 1;
+
         if ( !pAsyncMouse )
           pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-        if ( uCurrentMenuID != 6 )
-          goto LABEL_230;
-        if ( !pAsyncMouse )
-        {
-LABEL_229:
-          sub_41CD4F(0x29u);
-LABEL_230:
-          if ( pAsyncMouse == (void *)v28 )
-            pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-        }
-        if ( pGame != (Game *)v28 )
-        {
-          if ( pAsyncMouse != (void *)v28 )
-            //goto _def_wnd_proc;
-            return DefWindowProcA(hWnd, Msg, wParam, lParam);
-          pGame->PickMouse(512.0, (unsigned __int16)lParam, lParam >> 16, v28, &vis_sprite_filter_3, &vis_door_filter);
-        }
-        if ( pAsyncMouse == (void *)v28 )
-        {
+
+        if (GetCurrentMenuID() != MENU_CREATEPARTY)
+          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
+        else
+        {
+          UI_OnKeyDown(VK_SELECT);
+          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
+        }
+
+        if (!pAsyncMouse)
+        {
+          if (pGame)
+            pGame->PickMouse(512.0, (unsigned __int16)lParam, lParam >> 16, false, &vis_sprite_filter_3, &vis_door_filter);
+
           UI_OnMouseLeftClick(0);
-          return DefWindowProcA(hWnd, Msg, wParam, lParam);
-        }
-        //goto _def_wnd_proc;
+        }
         return DefWindowProcA(hWnd, Msg, wParam, lParam);
+
       case WM_RBUTTONDBLCLK:
         v31 = 0;
         if ( !pArcomageGame->bGameInProgress )
@@ -7292,7 +7283,7 @@
           return 0;
       }
       if ( !viewparams->field_4C )
-        sub_41CD4F(wParam);
+        UI_OnKeyDown(wParam);
       return 0;
     }
     pArcomageGame->stru1.field_0 = 1;
--- a/mm7_3.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/mm7_3.cpp	Thu May 09 01:33:54 2013 +0600
@@ -12873,7 +12873,7 @@
       while ( (signed int)v41 < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem );
     }
   }
-  pRenderer->DrawTextureIndexed(471, 445, (Texture *)(uExitCancelTextureId != -1 ? &pIcons_LOD->pTextures[uExitCancelTextureId] : 0));
+  pRenderer->DrawTextureIndexed(471, 445, pIcons_LOD->GetTexture(uExitCancelTextureId));
 }
 
 //----- (00445C8B) --------------------------------------------------------
--- a/mm7_4.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/mm7_4.cpp	Thu May 09 01:33:54 2013 +0600
@@ -7351,11 +7351,9 @@
         pInString = (char *)*(&pNPCStats->field_17884 + ((v10 & 3) == 2) + 2 * v9);
         v11 = pFontArrus->CalcTextHeight(pInString, &a1, 13, 0);
         v12 = v11 + 7;
-        pRenderer->_4A6A68(
-          8u,
-          352 - (v11 + 7),
-          (Texture *)(uTextureID_Leather != -1 ? &pIcons_LOD->pTextures[uTextureID_Leather] : 0),
-          (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - (v11 + 7));
+        pRenderer->_4A6A68(8, 352 - (v11 + 7),
+          pIcons_LOD->GetTexture(uTextureID_Leather),
+          pIcons_LOD->GetTexture(uTextureID_Leather)->uTextureHeight - (v11 + 7));
         pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
         v13 = FitTextInAWindow(pInString, pFontArrus, &a1, 0xDu, 0);
         pDialogueWindow->DrawText(pFontArrus, 13, 354 - v12, 0, v13, 0, 0, 0);
@@ -7556,11 +7554,9 @@
       v47 = pFontCreate;
       v48 = pFontCreate->CalcTextHeight(current_npc_text, &w, 13, 0) + 7;
     }
-    pRenderer->_4A6A68(
-      8u,
-      352 - v48,
-      (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
-      (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v48);
+    pRenderer->_4A6A68(8, 352 - v48,
+      pIcons_LOD->GetTexture(uTextureID_Leather),
+      pIcons_LOD->GetTexture(uTextureID_Leather)->uTextureHeight - v48);
     pRenderer->DrawTextureIndexed(8u, 347 - v48, pTexture_591428);
     v49 = FitTextInAWindow(current_npc_text, v47, &w, 0xDu, 0);
     a1.DrawText(v47, 13, 354 - v48, 0, v49, 0, 0, 0);
@@ -7590,7 +7586,7 @@
       CreateButtonInColumn(2, 0x68u);
     }
   }
-  pDialogueWindow->_41D08F(num_buttons, 1, 0, 2);
+  pDialogueWindow->_41D08F_set_keyboard_control_group(num_buttons, 1, 0, 2);
   dword_F8B1E0 = pDialogueWindow->pNumPresenceButton;
 }
 // F8B1E0: using guessed type int dword_F8B1E0;
@@ -7605,13 +7601,13 @@
       CreateButtonInColumn(0, 3u);
       CreateButtonInColumn(1, 4u);
       CreateButtonInColumn(2, 5u);
-       pDialogueWindow->_41D08F(3, 1, 0, 2);
+       pDialogueWindow->_41D08F_set_keyboard_control_group(3, 1, 0, 2);
     }
     if ( a1 == 4 )
     {
       CreateButtonInColumn(0, 3u);
       CreateButtonInColumn(1, 4u);
-      pDialogueWindow->_41D08F(2, 1, 0, 2);
+      pDialogueWindow->_41D08F_set_keyboard_control_group(2, 1, 0, 2);
     }
   }
   dword_F8B1E0 = pDialogueWindow->pNumPresenceButton;
@@ -7724,7 +7720,7 @@
             v10 = 1;
             v9 = v4;
 LABEL_42:
-            pDialogueWindow->_41D08F(v9, v10, v11, v17);
+            pDialogueWindow->_41D08F_set_keyboard_control_group(v9, v10, v11, v17);
             goto LABEL_43;
           }
           v4 = 2;
@@ -7835,7 +7831,7 @@
     v1 = 1;
   }
   pDialogueWindow->CreateButton(480, 30 * v1 + 160, 140, 30, 1, 0, UIMSG_SelectNPCDialogueOption, 76, 0, pGlobalTXT_LocalizationStrings[406], 0);//
-  pDialogueWindow->_41D08F(v1 + 1, 1, 0, 1);
+  pDialogueWindow->_41D08F_set_keyboard_control_group(v1 + 1, 1, 0, 1);
 }
 
 //----- (004B3EF0) --------------------------------------------------------
@@ -7849,7 +7845,7 @@
   pBtn_ExitCancel = pDialogueWindow->CreateButton(471, 445, 169, 35, 1, 0, UIMSG_Escape,                    0, 0, pGlobalTXT_LocalizationStrings[34], pIcons_LOD->GetTexture(uExitCancelTextureId), 0); // Cancel
                     pDialogueWindow->CreateButton(  0,   0,   0,  0, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "", 0);
                     pDialogueWindow->CreateButton(480, 160, 140, 30, 1, 0, UIMSG_ClickNPCTopic,             0x52u, 0, pGlobalTXT_LocalizationStrings[122], 0);
-  pDialogueWindow->_41D08F(1, 1, 0, 2);
+  pDialogueWindow->_41D08F_set_keyboard_control_group(1, 1, 0, 2);
   dialog_menu_id = HOUSE_DIALOGUE_OTHER;
 }
 // F8B19C: using guessed type int dword_F8B19C;
@@ -7873,7 +7869,7 @@
   if ( contract_approved )
     v2 = pGlobalTXT_LocalizationStrings[535];
   pDialogueWindow->CreateButton(0x1E0u, 0xA0u, 0x8Cu, 0x1Eu, 1, 0, UIMSG_ClickNPCTopic, 0x4Fu, 0, v2, 0);
-  pDialogueWindow->_41D08F(1, 1, 0, 2);
+  pDialogueWindow->_41D08F_set_keyboard_control_group(1, 1, 0, 2);
   dialog_menu_id = HOUSE_DIALOGUE_OTHER;
 }
 // F8B19C: using guessed type int dword_F8B19C;
@@ -7902,7 +7898,7 @@
   }
   pDialogueWindow->CreateButton(  0x1E0u,  30 * v0 + 160,  0x8Cu,  0x1Eu,  1,  0,  UIMSG_ClickNPCTopic,  0x4Cu,  0,
     pGlobalTXT_LocalizationStrings[406],  0); //"Hire"
-  pDialogueWindow->_41D08F(v0 + 1, 1, 0, 2);
+  pDialogueWindow->_41D08F_set_keyboard_control_group(v0 + 1, 1, 0, 2);
   dialog_menu_id = HOUSE_DIALOGUE_OTHER;
 }
 
@@ -8015,7 +8011,7 @@
             pDialogueWindow->CreateButton( 0x1E0u, 30 * num_menu_buttons++ + 160,  0x8Cu,  0x1Eu, 1, 0, UIMSG_ClickNPCTopic, 0x18u, 0, "",  0);
         }
       }
-      pDialogueWindow->_41D08F(num_menu_buttons, 1, 0, 2);
+      pDialogueWindow->_41D08F_set_keyboard_control_group(num_menu_buttons, 1, 0, 2);
       dword_F8B1E0 = pDialogueWindow->pNumPresenceButton;
     }
     dialog_menu_id = HOUSE_DIALOGUE_MAIN;
--- a/mm7_5.cpp	Thu May 09 01:33:38 2013 +0600
+++ b/mm7_5.cpp	Thu May 09 01:33:54 2013 +0600
@@ -1501,7 +1501,7 @@
               pBtn_Resume = pGUIWindow_CurrentMenu->CreateButton(241, 263, 214, 40, v0, 0, UIMSG_GameMenu_ReturnToGame, 0, 0x52u,
                              pGlobalTXT_LocalizationStrings[619],// "Return to Game"
                              pIcons_LOD->GetTexture(uTextureID_Resume1), 0);
-              pGUIWindow_CurrentMenu->_41D08F(6, v0, 0, 0);
+              pGUIWindow_CurrentMenu->_41D08F_set_keyboard_control_group(6, v0, 0, 0);
               viewparams->field_48 = v0;
               stru_506E40.Release();
               uNumSeconds = (unsigned int)MakeScreenshot(155, 117);
@@ -2864,7 +2864,7 @@
           papredoll_dbrds[2] = pIcons_LOD->LoadTexture("BUTTEXI1", TEXTURE_16BIT_PALETTE);
           pBtn_ExitCancel = pGUIWindow_CurrentMenu->CreateButton(0x187u, 0x13Cu, 0x4Bu, 0x21u, v0, 0, UIMSG_Escape, 0, 0,
                          pGlobalTXT_LocalizationStrings[79],// "Exit"
-                         (Texture *)(uTextureID_BUTTDESC2 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTDESC2] : 0), 0); //, v179);
+                         pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0); //, v179);
           continue;
         case UIMSG_GameMenuButton:
           if ( pCurrentScreen )
@@ -2909,8 +2909,8 @@
           pCharacterScreen_DollBtn->Release();
           if ( bRingsShownInCharScreen )
           {
-            v128 = (uTextureID_detaliz_close_button != -1 ? pIcons_LOD->pTextures[uTextureID_detaliz_close_button].uTextureHeight : 26);
-            v125 = (uTextureID_detaliz_close_button != -1 ? pIcons_LOD->pTextures[uTextureID_detaliz_close_button].uTextureWidth : 24);
+            v128 = pIcons_LOD->GetTexture(uTextureID_detaliz_close_button)->uTextureHeight;
+            v125 = pIcons_LOD->GetTexture(uTextureID_detaliz_close_button)->uTextureWidth;
             v123 = 445;
             v121 = 470;
           }
@@ -9450,7 +9450,8 @@
 //----- (0040F82D) --------------------------------------------------------
 void __fastcall ZBuffer_Fill(int *pZBuffer, int uTextureId, int iZValue)
 {
-  ZBuffer_DoFill(pZBuffer, (Texture *)(uTextureId != -1 ? (int)&pIcons_LOD->pTextures[uTextureId] : 0), iZValue);
+  assert(uTextureId != -1);
+  ZBuffer_DoFill(pZBuffer, pIcons_LOD->GetTexture(uTextureId), iZValue);
 }
 
 //----- (0040F845) --------------------------------------------------------
@@ -10201,17 +10202,18 @@
   int v39; // eax@129
   unsigned int pNumMessages; // eax@142
   GUIButton *pGUIButton; // ebp@146
-  unsigned int pX; // [sp-1Ch] [bp-124h]@17
-  unsigned int pY; // [sp-18h] [bp-120h]@17
-  Texture *pTexture; // [sp-14h] [bp-11Ch]@17
-  Texture *pTexture2; // [sp-14h] [bp-11Ch]@86
+  //unsigned int pX; // [sp-1Ch] [bp-124h]@17
+  //unsigned int pY; // [sp-18h] [bp-120h]@17
+  //Texture *pTexture; // [sp-14h] [bp-11Ch]@17
+  //Texture *pTexture2; // [sp-14h] [bp-11Ch]@86
   int i; // [sp+0h] [bp-108h]@3
   ItemGen pItemGen; // [sp+4h] [bp-104h]@98
   GUIButton GUIButton2; // [sp+28h] [bp-E0h]@133
   ItemGen ItemGen2; // [sp+E4h] [bp-24h]@129
 
   if (GetCurrentMenuID() != MENU_CREATEPARTY)
-    sub_41CD4F(34);
+    UI_OnKeyDown(VK_NEXT);
+
   for ( i = 1; i <= uNumVisibleWindows; ++i )
   {
     pWindow = &pWindowList[pVisibleWindowsIdxs[i] - 1];
@@ -10220,10 +10222,8 @@
     {
       case WINDOW_OptionsButtons:
       {
-        pTexture = (Texture *)(uTextureID_Options != -1 ? &pIcons_LOD->pTextures[uTextureID_Options] : 0);
-        pY = pViewport->uViewportTL_Y;
-        pX = pViewport->uViewportTL_X;
-        pRenderer->DrawTextureIndexed(pX, pY, pTexture);
+        pRenderer->DrawTextureIndexed(pViewport->uViewportTL_Y,
+                                      pViewport->uViewportTL_X, pIcons_LOD->GetTexture(uTextureID_Options));
         viewparams->bRedrawGameUI = 1;
         continue;
       }
@@ -10283,8 +10283,7 @@
           pRenderer->ClearZBuffer(0, 479);
           draw_leather();
           CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
-          pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY,
-             (Texture *)(uExitCancelTextureId != -1 ? (int)&pIcons_LOD->pTextures[uExitCancelTextureId] : 0));
+          pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId));
         }
         continue;
       }
@@ -10333,8 +10332,7 @@
         draw_leather();
         CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
         CharacterUI_DrawPaperdoll(uActiveCharacter);
-        pRenderer->DrawTextureTransparent(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY,
-            (Texture *)(uTextureID_x_x_u != -1 ? &pIcons_LOD->pTextures[uTextureID_x_x_u] : 0));
+        pRenderer->DrawTextureTransparent(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uTextureID_x_x_u));
         continue;
       }
       case WINDOW_FinalWindow:
@@ -10557,9 +10555,8 @@
       case WINDOW_BooksWindow:
       {
         pButton = (GUIButton *)pWindow->ptr_1C;
-        pY = pWindow->uFrameY;
-        pX = pWindow->uFrameX;
-        pRenderer->DrawTextureIndexed(pX, pY, pButton->pTextures[0]);
+        pRenderer->DrawTextureIndexed(pWindow->uFrameY,
+                                      pWindow->uFrameX, pButton->pTextures[0]);
         viewparams->bRedrawGameUI = 1;
         continue;
       }
@@ -11529,14 +11526,18 @@
         i->uX = 0;
       }
     }
-    pBtn_Up = pGUIWindow_CurrentMenu->CreateButton(438, 46, (uTextureID_ar_up_up != -1 ? pIcons_LOD->pTextures[uTextureID_ar_up_up].uTextureWidth : 24),
-                   (uTextureID_ar_up_up != -1 ? pIcons_LOD->pTextures[uTextureID_ar_up_up].uTextureHeight : 26),
-                   1, 0, UIMSG_ClickAwardsUpBtn, 0, 0, "", (Texture *)(uTextureID_ar_up_up != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_ar_up_up] : 0),
-                   uTextureID_ar_up_dn != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_ar_up_dn] : 0, 0);
-    pBtn_Down = pGUIWindow_CurrentMenu->CreateButton(438, 292, (uTextureID_ar_dn_up != -1 ? pIcons_LOD->pTextures[uTextureID_ar_dn_up].uTextureWidth : 24),
-                   (uTextureID_ar_dn_up != -1 ? pIcons_LOD->pTextures[uTextureID_ar_dn_up].uTextureHeight : 26),
-                   1, 0, UIMSG_ClickAwardsDownBtn, 0, 0, "", (Texture *)(uTextureID_ar_dn_up != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_ar_dn_up] : 0),
-                   uTextureID_ar_dn_dn != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_ar_dn_dn] : 0, 0);
+    pBtn_Up = pGUIWindow_CurrentMenu->CreateButton(438, 46,
+                   pIcons_LOD->GetTexture(uTextureID_ar_up_up)->uTextureWidth,
+                   pIcons_LOD->GetTexture(uTextureID_ar_up_up)->uTextureHeight,
+                   1, 0, UIMSG_ClickAwardsUpBtn, 0, 0, "",
+                   pIcons_LOD->GetTexture(uTextureID_ar_up_up),
+                   pIcons_LOD->GetTexture(uTextureID_ar_up_dn), 0);
+    pBtn_Down = pGUIWindow_CurrentMenu->CreateButton(438, 292,
+                   pIcons_LOD->GetTexture(uTextureID_ar_dn_up)->uTextureWidth,
+                   pIcons_LOD->GetTexture(uTextureID_ar_dn_up)->uTextureHeight,
+                   1, 0, UIMSG_ClickAwardsDownBtn, 0, 0, "",
+                   pIcons_LOD->GetTexture(uTextureID_ar_dn_up),
+                   pIcons_LOD->GetTexture(uTextureID_ar_dn_dn), 0);
     ptr_507BA4 = pGUIWindow_CurrentMenu->CreateButton(440, 62, 16, 232, 1, 0, UIMSG_C0, 0, 0, "", 0);
   }
 }
@@ -11564,10 +11565,10 @@
         pButton->uY = dword_506988;
         pButton->uZ = dword_506984;
         pButton->uW = dword_506980;
-        pGUIWindow_CurrentMenu->_41D08F(1, 0, 0, 0);
-      }
-    }
-  }
-}
-
-
+        pGUIWindow_CurrentMenu->_41D08F_set_keyboard_control_group(1, 0, 0, 0);
+      }
+    }
+  }
+}
+
+
--- a/mm7_data.h	Thu May 09 01:33:38 2013 +0600
+++ b/mm7_data.h	Thu May 09 01:33:54 2013 +0600
@@ -1616,7 +1616,7 @@
 void __cdecl GameUI_Footer_2();
 void __thiscall sub_41C0B8_set_status_string(const char *pStr); // idb
 void __cdecl GameUI_Footer();
-bool __thiscall sub_41CD4F(unsigned int _this);
+bool UI_OnKeyDown(unsigned int vkKey);
 char __fastcall sub_41D20D_buff_remaining_time_string(int ecx0, struct GUIWindow *edx0, __int64 a3, struct GUIFont *a2);
 void GameUI_DrawItemInfo(struct ItemGen* inspect_item); // idb
 void MonsterPopup_Draw(unsigned int uActorID, struct GUIWindow *edx0);
@@ -1956,33 +1956,33 @@
 int _48B561_mess_with_scaling_along_z(/*int a1, */float a2);
 signed int __cdecl PlayerCreation_Chose4Skills();
 signed int __cdecl PlayerCreation_ComputeAttributeBonus();
-void __cdecl LoadPlayerPortraintsAndVoices();
+void LoadPlayerPortraintsAndVoices();
 int __fastcall ReloadPlayerPortraits(int, int); // weak
-void __cdecl sub_491E3A();
-void __cdecl DrawHiredNPCs();
+void sub_491E3A();
+void DrawHiredNPCs();
 void __thiscall GameUI_DrawPortraits(unsigned int _this);
 signed int __thiscall CycleCharacter(unsigned int _this);
 void __fastcall Rest(unsigned int uHoursToSleep);
-int __cdecl _493938_regenerate();
+int _493938_regenerate();
 void sub_493F79(struct stru351_summoned_item *_this, __int64 a2);
-void __cdecl _494035_timed_effects__water_walking_damage__etc();
+void _494035_timed_effects__water_walking_damage__etc();
 unsigned int __fastcall _494820_training_time(unsigned int a1);
 char *__fastcall sub_495366(unsigned __int8 a1, unsigned __int8 a2);
 char * GetReputationString(signed int a1);
 char *BuilDialogueString(char *lpsz, unsigned __int8 uPlayerID, struct ItemGen *a3, char *a4, int a5, __int64 *a6);
-void __cdecl PlayerCreationUI_Draw();
-void __cdecl PlayerCreationUI_Initialize();
-void __cdecl DeleteCCharFont();
-bool __cdecl PlayerCreationUI_Loop();
-void __cdecl loc_49B785(); // idb
+void PlayerCreationUI_Draw();
+void PlayerCreationUI_Initialize();
+void DeleteCCharFont();
+bool PlayerCreationUI_Loop();
+void loc_49B785(); // idb
 unsigned int __fastcall GetMaxMipLevels(unsigned int uDim);
-bool __cdecl CheckTextureStages();
-bool __cdecl AreRenderSurfacesOk();
+bool CheckTextureStages();
+bool AreRenderSurfacesOk();
 unsigned int BlendColors(unsigned int c1, unsigned int c2); // weak
-void __cdecl DoRenderBillboards_D3D();
+void DoRenderBillboards_D3D();
 int __fastcall sr_4A46E6_draw_particle_segment(unsigned int x, signed int y, signed int z, int a4, unsigned int lightColor);
-void __cdecl Present_ColorKey();
-void __cdecl Present_NoColorKey();
+void Present_ColorKey();
+void Present_NoColorKey();
 int __thiscall sub_4A7063(unsigned int uDiffuse, float a2); // idb
 struct SoundHeader *__fastcall FindSound_BinSearch(unsigned int uStart, unsigned int uEnd, const char *pName);
 struct SoundData *LoadSound(const char *pSoundName, struct SoundData *pOutBuff, unsigned int uID);