changeset 2398:79e750ba00b9

some polishing on GameUI_WritePointedObjectStatusString
author Grumpy7
date Thu, 10 Jul 2014 01:34:57 +0200
parents eff78dab2142
children aad4f31aa297
files UI/UiGame.cpp
diffstat 1 files changed, 115 insertions(+), 245 deletions(-) [+]
line wrap: on
line diff
--- a/UI/UiGame.cpp	Thu Jul 10 00:58:45 2014 +0200
+++ b/UI/UiGame.cpp	Thu Jul 10 01:34:57 2014 +0200
@@ -1147,55 +1147,48 @@
 //----- (00420EFF) --------------------------------------------------------
 void GameUI_WritePointedObjectStatusString()
 {
-  int v1; // ebx@6
   GUIWindow *pWindow; // edi@7
   GUIButton *pButton; // ecx@11
-  int v7; // ecx@19
+  int requiredSkillpoints; // ecx@19
   enum UIMessageType pMessageType1; // esi@24
   int v14; // eax@41
   ItemGen *pItemGen; // ecx@44
   int v16; // ecx@46
-  signed int v18; // eax@55
+  signed int pickedObjectPID; // eax@55
   signed int v18b;
-  signed int v19; // ecx@63
+  signed int pickedObjectID; // ecx@63
   BLVFace *pFace; // eax@69
   const char *pText; // ecx@79
-  char *v28; // esi@82
   enum UIMessageType pMessageType2; // esi@110
   enum UIMessageType pMessageType3; // edx@117
   char Str1[200]; // [sp+Ch] [bp-D4h]@129
   unsigned int pX; // [sp+D4h] [bp-Ch]@1
   unsigned int pY; // [sp+D8h] [bp-8h]@1
-  unsigned int v45; // [sp+DCh] [bp-4h]@21
 
   int interaction_distance_limit = 512;
 
   pMouse->uPointingObjectID = 0;
   pMouse->GetClickPos(&pX, &pY);
-  if ( pX < 0 || pX > 639 || pY < 0 || pY > 479 )
+  if ( pX < 0 || pX > window->GetWidth() - 1 || pY < 0 || pY > window->GetHeight() - 1 )
     return;
   if ( pCurrentScreen == SCREEN_GAME )
   {
-    if ( pX <= 467 && pY <= 351 ) 
+    if ( pX <= (window->GetWidth() - 1) * 0.73125 && pY <= (window->GetHeight() - 1) * 0.73125 ) 
     {
       //if ( pRenderer->pRenderD3D )  // inlined mm8::4C1E01
       {
-        v18 = pGame->pVisInstance->get_picked_object_zbuf_val();
+        pickedObjectPID = pGame->pVisInstance->get_picked_object_zbuf_val();
         if ( pX < (unsigned int)pViewport->uScreen_TL_X || pX > (unsigned int)pViewport->uScreen_BR_X
           || pY < (unsigned int)pViewport->uScreen_TL_Y || pY > (unsigned int)pViewport->uScreen_BR_Y )
-          v18 = -1;
-        if ( v18 == -1 )
+          pickedObjectPID = -1;
+        if ( pickedObjectPID == -1 )
         {
-          pMouse->uPointingObjectID = 0;
-          if ( pMouse->uPointingObjectID == 0 )
+          if ( uLastPointedObjectID != 0 )
           {
-            if ( uLastPointedObjectID != 0 )
-            {
-              pFooterString[0] = 0;
-              bForceDrawFooter = 1;
-            }
+            pFooterString[0] = 0;
+            bForceDrawFooter = 1;
           }
-          uLastPointedObjectID = pMouse->uPointingObjectID;
+          uLastPointedObjectID = 0;
           return;
         }
       }
@@ -1203,217 +1196,116 @@
       {
         v18 = pRenderer->pActiveZBuffer[pX + pSRZBufferLineOffsets[pY]];
       }*/
-      pMouse->uPointingObjectID = (unsigned __int16)v18;
-      v19 = (signed)PID_ID(v18);
-      if ( PID_TYPE(v18) == OBJECT_Item )
+      pMouse->uPointingObjectID = (unsigned __int16)pickedObjectPID;
+      pickedObjectID = (signed)PID_ID(pickedObjectPID);
+      if ( PID_TYPE(pickedObjectPID) == OBJECT_Item )
       {
-        if ( pObjectList->pObjects[pSpriteObjects[v19].uObjectDescID].uFlags & 0x10 )
+        if ( pObjectList->pObjects[pSpriteObjects[pickedObjectID].uObjectDescID].uFlags & 0x10 )
         {
           pMouse->uPointingObjectID = 0;
-          uLastPointedObjectID = 1;
-          if ( pMouse->uPointingObjectID == 0 )
-          {
-            if ( uLastPointedObjectID != 0 )
-            {
-              pFooterString[0] = 0;
-              bForceDrawFooter = 1;
-            }
-          }
-          uLastPointedObjectID = pMouse->uPointingObjectID;
-          return;
-        }
-        if ( v18 >= 0x2000000u || pParty->pPickedItem.uItemID )
-        {
-          GameUI_SetFooterString(pSpriteObjects[v19].stru_24.GetDisplayName());
-          if ( pMouse->uPointingObjectID == 0 )
-          {
-            if ( uLastPointedObjectID != 0 )
-            {
-              pFooterString[0] = 0;
-              bForceDrawFooter = 1;
-            }
-          }
-          uLastPointedObjectID = pMouse->uPointingObjectID;
-          return;
-        }
-        sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[470], pSpriteObjects[v19].stru_24.GetDisplayName());// "Get %s"
-        GameUI_SetFooterString(pTmpBuf.data());
-        if ( pMouse->uPointingObjectID == 0 )
-        {
           if ( uLastPointedObjectID != 0 )
           {
             pFooterString[0] = 0;
             bForceDrawFooter = 1;
           }
+          uLastPointedObjectID = 0;
+          return;
         }
-        uLastPointedObjectID = pMouse->uPointingObjectID;
-        return;
+        if ( pickedObjectPID >= 0x2000000u || pParty->pPickedItem.uItemID )
+        {
+          GameUI_SetFooterString(pSpriteObjects[pickedObjectID].stru_24.GetDisplayName());
+        }
+        else
+        {
+          sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[470], pSpriteObjects[pickedObjectID].stru_24.GetDisplayName());// "Get %s"
+          GameUI_SetFooterString(pTmpBuf.data());
+        } //intentional fallthrough
       }
-      else if ( PID_TYPE(v18) == OBJECT_Decoration )
+      else if ( PID_TYPE(pickedObjectPID) == OBJECT_Decoration )
       {
-        if ( !pLevelDecorations[v19].uEventID )
+        if ( !pLevelDecorations[pickedObjectID].uEventID )
         {
-          if ( pLevelDecorations[v19].IsInteractive() )
-            pText = pNPCTopics[stru_5E4C90_MapPersistVars._decor_events[pLevelDecorations[v19]._idx_in_stru123 - 75] + 379].pTopic;//неверно для костра
+          if ( pLevelDecorations[pickedObjectID].IsInteractive() )
+            pText = pNPCTopics[stru_5E4C90_MapPersistVars._decor_events[pLevelDecorations[pickedObjectID]._idx_in_stru123 - 75] + 379].pTopic;//неверно для костра
           else
-            pText = pDecorationList->pDecorations[pLevelDecorations[v19].uDecorationDescID].field_20;
+            pText = pDecorationList->pDecorations[pLevelDecorations[pickedObjectID].uDecorationDescID].field_20;
           GameUI_SetFooterString(pText);
-          if ( pMouse->uPointingObjectID == 0 )
+        }
+        else
+        {
+          char* hintString = GetEventHintString(pLevelDecorations[pickedObjectID].uEventID);
+          if (  hintString != '\0' )
           {
-            if ( uLastPointedObjectID != 0 )
+            GameUI_SetFooterString(hintString);
+          }
+        } //intentional fallthrough
+      }
+      else if ( PID_TYPE(pickedObjectPID) == OBJECT_BModel )
+      {
+        if ( pickedObjectPID < 0x2000000u )
+        {
+          char* newString = nullptr;
+          if ( uCurrentlyLoadedLevelType != LEVEL_Indoor )
+          {
+            v18b = (signed int)(unsigned __int16)pickedObjectPID >> 9;
+            short triggeredId = pOutdoor->pBModels[v18b].pFaces[pickedObjectID & 0x3F].sCogTriggeredID;
+            if (triggeredId != 0)
             {
-              pFooterString[0] = 0;
-              bForceDrawFooter = 1;
+              newString = GetEventHintString(pOutdoor->pBModels[v18b].pFaces[pickedObjectID & 0x3F].sCogTriggeredID);
             }
           }
-          uLastPointedObjectID = pMouse->uPointingObjectID;
-          return;
-        }
-        if (  !GetEventHintString(pLevelDecorations[v19].uEventID) )
-        {
-          if ( pMouse->uPointingObjectID == 0 )
+          else
           {
-            if ( uLastPointedObjectID != 0 )
+            pFace = &pIndoor->pFaces[pickedObjectID];
+            if ( BYTE3(pFace->uAttributes) & 6 )
+            {
+              unsigned short eventId = pIndoor->pFaceExtras[pFace->uFaceExtraID].uEventID;
+              if (eventId != 0)
+              {
+                newString = GetEventHintString(pIndoor->pFaceExtras[pFace->uFaceExtraID].uEventID);
+              }
+            }
+          }
+          if (newString)
+          {
+            if ( pMouse->uPointingObjectID == 0 && uLastPointedObjectID != 0)
             {
               pFooterString[0] = 0;
               bForceDrawFooter = 1;
             }
-          }
-          uLastPointedObjectID = pMouse->uPointingObjectID;
-          return;
-        }
-        GameUI_SetFooterString(GetEventHintString(pLevelDecorations[v19].uEventID));
-        if ( pMouse->uPointingObjectID == 0 )
-        {
-          if ( uLastPointedObjectID != 0 )
-          {
-            pFooterString[0] = 0;
-            bForceDrawFooter = 1;
-          }
-        }
-        uLastPointedObjectID = pMouse->uPointingObjectID;
-        return;
-      }
-      else if ( PID_TYPE(v18) == OBJECT_BModel )
-      {
-        if ( v18 < 0x2000000u )
-        {
-          if ( uCurrentlyLoadedLevelType != LEVEL_Indoor )
-          {
-            v18b = (signed int)(unsigned __int16)v18 >> 9;
-            if ( !pOutdoor->pBModels[v18b].pFaces[v19 & 0x3F].sCogTriggeredID
-              || !GetEventHintString(pOutdoor->pBModels[v18b].pFaces[v19 & 0x3F].sCogTriggeredID) )
-            {
-              pMouse->uPointingObjectID = 0;
-              uLastPointedObjectID = 1;
-              if ( pMouse->uPointingObjectID == 0 )
-              {
-                if ( uLastPointedObjectID != 0 )
-                {
-                  pFooterString[0] = 0;
-                  bForceDrawFooter = 1;
-                }
-              }
-              uLastPointedObjectID = pMouse->uPointingObjectID;
-              return;
-            }
-            GameUI_SetFooterString(GetEventHintString(pOutdoor->pBModels[v18b].pFaces[v19 & 0x3F].sCogTriggeredID));
-            if ( pMouse->uPointingObjectID == 0 )
-            {
-              if ( uLastPointedObjectID != 0 )
-              {
-                pFooterString[0] = 0;
-                bForceDrawFooter = 1;
-              }
-            }
-            uLastPointedObjectID = pMouse->uPointingObjectID;
-            return;
-          }
-          pFace = &pIndoor->pFaces[v19];
-          if ( BYTE3(pFace->uAttributes) & 6 )
-          {
-            if ( !pIndoor->pFaceExtras[pFace->uFaceExtraID].uEventID
-              || !GetEventHintString(pIndoor->pFaceExtras[pFace->uFaceExtraID].uEventID) )
-            {
-              pMouse->uPointingObjectID = 0;
-              uLastPointedObjectID = 1;
-              if ( pMouse->uPointingObjectID == 0 )
-              {
-                if ( uLastPointedObjectID != 0 )
-                {
-                  pFooterString[0] = 0;
-                  bForceDrawFooter = 1;
-                }
-              }
-              uLastPointedObjectID = pMouse->uPointingObjectID;
-              return;
-            }
-            GameUI_SetFooterString(GetEventHintString(pIndoor->pFaceExtras[pFace->uFaceExtraID].uEventID));
-            if ( pMouse->uPointingObjectID == 0 )
-            {
-              if ( uLastPointedObjectID != 0 )
-              {
-                pFooterString[0] = 0;
-                bForceDrawFooter = 1;
-              }
-            }
             uLastPointedObjectID = pMouse->uPointingObjectID;
             return;
           }
         }
         pMouse->uPointingObjectID = 0;
-        uLastPointedObjectID = 1;
-        if ( pMouse->uPointingObjectID == 0 )
+        pFooterString[0] = 0;
+        bForceDrawFooter = 1;
+        uLastPointedObjectID = 0;
+        return;
+      }
+      else if ( PID_TYPE(pickedObjectPID) == OBJECT_Actor )
+      {          
+        if ( pickedObjectPID >= 0x2000000u )
         {
+          pMouse->uPointingObjectID = 0;
           if ( uLastPointedObjectID != 0 )
           {
             pFooterString[0] = 0;
             bForceDrawFooter = 1;
           }
-        }
-        uLastPointedObjectID = pMouse->uPointingObjectID;
-        return;
-      }
-      else if ( PID_TYPE(v18) == OBJECT_Actor )
-      {          
-        if ( v18 >= 0x2000000u )
-        {
-          pMouse->uPointingObjectID = 0;
-          if ( pMouse->uPointingObjectID == 0 )
-          {
-            if ( uLastPointedObjectID != 0 )
-            {
-              pFooterString[0] = 0;
-              bForceDrawFooter = 1;
-            }
-          }
-          uLastPointedObjectID = pMouse->uPointingObjectID;
+          uLastPointedObjectID = 0;
           return;
         }
-        if ( pActors[v19].dword_000334_unique_name )
-          pText = pMonsterStats->pPlaceStrings[pActors[v19].dword_000334_unique_name];
+        if ( pActors[pickedObjectID].dword_000334_unique_name )
+          pText = pMonsterStats->pPlaceStrings[pActors[pickedObjectID].dword_000334_unique_name];
         else
-          pText = pMonsterStats->pInfos[pActors[v19].pMonsterInfo.uID].pName;
-        GameUI_SetFooterString(pText);
-        if ( pMouse->uPointingObjectID == 0 )
-        {
-          if ( uLastPointedObjectID != 0 )
-          {
-            pFooterString[0] = 0;
-            bForceDrawFooter = 1;
-          }
-        }
-        uLastPointedObjectID = pMouse->uPointingObjectID;
-        return;
+          pText = pMonsterStats->pInfos[pActors[pickedObjectID].pMonsterInfo.uID].pName;
+        GameUI_SetFooterString(pText); //intentional fallthrough
       }
-      pMouse->uPointingObjectID = 0;
-      if ( pMouse->uPointingObjectID == 0 )
+      if ( pMouse->uPointingObjectID == 0 && uLastPointedObjectID != 0)
       {
-        if ( uLastPointedObjectID != 0 )
-        {
-          pFooterString[0] = 0;
-          bForceDrawFooter = 1;
-        }
+        pFooterString[0] = 0;
+        bForceDrawFooter = 1;
       }
       uLastPointedObjectID = pMouse->uPointingObjectID;
       return;
@@ -1421,9 +1313,9 @@
   }
   else
   {    
-    for (v1 = uNumVisibleWindows; v1 > 0; --v1)
+    for (int i = uNumVisibleWindows; i > 0; --i)
     {
-      pWindow = &pWindowList[pVisibleWindowsIdxs[v1] - 1];
+      pWindow = &pWindowList[pVisibleWindowsIdxs[i] - 1];
       if ( (signed int)pX >= (signed int)pWindow->uFrameX && (signed int)pX <= (signed int)pWindow->uFrameZ
         && (signed int)pY >= (signed int)pWindow->uFrameY && (signed int)pY <= (signed int)pWindow->uFrameW )
       {
@@ -1467,11 +1359,11 @@
             if ( pX >= pButton->uX && pX <= pButton->uZ
               && pY >= pButton->uY && pY <= pButton->uW )
             {
-              v7 = (LOBYTE(pPlayers[uActiveCharacter]->pActiveSkills[pButton->msg_param]) & 0x3F) + 1;
-              if ( pPlayers[uActiveCharacter]->uSkillPoints < v7 )
-                sprintf(Str1, pGlobalTXT_LocalizationStrings[469], v7 - pPlayers[uActiveCharacter]->uSkillPoints);// "You need %d more Skill Points to advance here"
+              requiredSkillpoints = (LOBYTE(pPlayers[uActiveCharacter]->pActiveSkills[pButton->msg_param]) & 0x3F) + 1;
+              if ( pPlayers[uActiveCharacter]->uSkillPoints < requiredSkillpoints )
+                sprintf(Str1, pGlobalTXT_LocalizationStrings[469], requiredSkillpoints - pPlayers[uActiveCharacter]->uSkillPoints);// "You need %d more Skill Points to advance here"
               else
-                sprintf(Str1, pGlobalTXT_LocalizationStrings[468], v7);// "Clicking here will spend %d Skill Points"
+                sprintf(Str1, pGlobalTXT_LocalizationStrings[468], requiredSkillpoints);// "Clicking here will spend %d Skill Points"
               GameUI_SetFooterString(Str1);
               uLastPointedObjectID = 1;
               return;
@@ -1491,15 +1383,12 @@
     if ( pCurrentScreen == SCREEN_CHEST )
     {
       Chest::ChestUI_WritePointedObjectStatusString();
-      if ( pMouse->uPointingObjectID == 0 )
+      if ( uLastPointedObjectID != 0 )
       {
-        if ( uLastPointedObjectID != 0 )
-        {
-          pFooterString[0] = 0;
-          bForceDrawFooter = 1;
-        }
+        pFooterString[0] = 0;
+        bForceDrawFooter = 1;
       }
-      uLastPointedObjectID = pMouse->uPointingObjectID;
+      uLastPointedObjectID = 0;
       return;
     }
     else if ( pCurrentScreen == SCREEN_HOUSE )
@@ -1508,29 +1397,19 @@
         || (v16 = pRenderer->pActiveZBuffer[pX + pSRZBufferLineOffsets[pY]], v16 == 0)
         || v16 == -65536 )
       {
-        if ( pMouse->uPointingObjectID == 0 )
-        {
-          if ( uLastPointedObjectID != 0 )
-          {
-            pFooterString[0] = 0;
-            bForceDrawFooter = 1;
-          }
-        }
-        uLastPointedObjectID = pMouse->uPointingObjectID;
-        return;
-      }
-      pItemGen = (ItemGen *)((char *)&pParty->pPickedItem + 36 * (v16 + 12 * (unsigned int)window_SpeakInHouse->ptr_1C) + 4);
-      GameUI_SetFooterString(pItemGen->GetDisplayName());
-      uLastPointedObjectID = 1;
-      if ( pMouse->uPointingObjectID == 0 )
-      {
         if ( uLastPointedObjectID != 0 )
         {
           pFooterString[0] = 0;
           bForceDrawFooter = 1;
         }
+        uLastPointedObjectID = 0;
+        return;
       }
-      uLastPointedObjectID = pMouse->uPointingObjectID;
+      pItemGen = (ItemGen *)((char *)&pParty->pPickedItem + 36 * (v16 + 12 * (unsigned int)window_SpeakInHouse->ptr_1C) + 4);
+      GameUI_SetFooterString(pItemGen->GetDisplayName());
+      pFooterString[0] = 0;
+      bForceDrawFooter = 1;
+      uLastPointedObjectID = 0;
       return;
     }
     if ( pY < 350 )
@@ -1551,16 +1430,9 @@
       }
       pItemGen = (ItemGen *)&pPlayers[uActiveCharacter]->pInventoryItemList[v14-1];
       GameUI_SetFooterString(pItemGen->GetDisplayName());
-      uLastPointedObjectID = 1;
-      if ( pMouse->uPointingObjectID == 0 )
-      {
-        if ( uLastPointedObjectID != 0 )
-        {
-          pFooterString[0] = 0;
-          bForceDrawFooter = 1;
-        }
-      }
-      uLastPointedObjectID = pMouse->uPointingObjectID;
+      pFooterString[0] = 0;
+      bForceDrawFooter = 1;
+      uLastPointedObjectID = 0;
       return;
     }
   }
@@ -1579,10 +1451,11 @@
           if ( pMessageType3 == 0 ) // For books
           {
             GameUI_SetFooterString(pButton->pButtonName);
-            uLastPointedObjectID = 1;
-            return;
           }
-          pMessageQueue_50CBD0->AddMessage(pMessageType3, pButton->msg_param, 0);
+          else
+          {
+            pMessageQueue_50CBD0->AddMessage(pMessageType3, pButton->msg_param, 0);
+          }
           uLastPointedObjectID = 1;
           return;
         }
@@ -1611,11 +1484,11 @@
         if ( pX >= pButton->uX && pX <= pButton->uZ
           && pY >= pButton->uY && pY <= pButton->uW )
         {
-          v7 = (LOBYTE(pPlayers[uActiveCharacter]->pActiveSkills[pButton->msg_param]) & 0x3F) + 1;
-          if ( pPlayers[uActiveCharacter]->uSkillPoints < v7 )
-            sprintf(Str1, pGlobalTXT_LocalizationStrings[469], v7 - pPlayers[uActiveCharacter]->uSkillPoints);// "You need %d more Skill Points to advance here"
+          requiredSkillpoints = (LOBYTE(pPlayers[uActiveCharacter]->pActiveSkills[pButton->msg_param]) & 0x3F) + 1;
+          if ( pPlayers[uActiveCharacter]->uSkillPoints < requiredSkillpoints )
+            sprintf(Str1, pGlobalTXT_LocalizationStrings[469], requiredSkillpoints - pPlayers[uActiveCharacter]->uSkillPoints);// "You need %d more Skill Points to advance here"
           else
-            sprintf(Str1, pGlobalTXT_LocalizationStrings[468], v7);// "Clicking here will spend %d Skill Points"
+            sprintf(Str1, pGlobalTXT_LocalizationStrings[468], requiredSkillpoints);// "Clicking here will spend %d Skill Points"
           GameUI_SetFooterString(Str1);
           uLastPointedObjectID = 1;
           return;
@@ -1625,15 +1498,12 @@
     }
   }
   //pMouse->uPointingObjectID = sub_46A99B(); //for software
-  if ( pMouse->uPointingObjectID == 0 )
+  if ( uLastPointedObjectID != 0 )
   {
-    if ( uLastPointedObjectID != 0 )
-    {
-      pFooterString[0] = 0;
-      bForceDrawFooter = 1;
-    }
+    pFooterString[0] = 0;
+    bForceDrawFooter = 1;
   }
-  uLastPointedObjectID = pMouse->uPointingObjectID;
+  uLastPointedObjectID = 0;
   return;
 }