changeset 2550:fb42e2662c38

Chest UI refactored to a class
author a.parshin
date Tue, 12 May 2015 11:28:22 +0200
parents 3121fb54a110
children 4008b2f34be0
files Build/Visual Studio 2013/World of Might and Magic.vcxproj Build/Visual Studio 2013/World of Might and Magic.vcxproj.filters Engine/Objects/Chest.cpp Engine/Objects/Chest.h GUI/GUIWindow.cpp GUI/GUIWindow.h GUI/UI/Chest.cpp GUI/UI/Chest.h GUI/UI/UIPopup.cpp
diffstat 9 files changed, 152 insertions(+), 113 deletions(-) [+]
line wrap: on
line diff
--- a/Build/Visual Studio 2013/World of Might and Magic.vcxproj	Tue May 12 11:07:32 2015 +0200
+++ b/Build/Visual Studio 2013/World of Might and Magic.vcxproj	Tue May 12 11:28:22 2015 +0200
@@ -167,6 +167,7 @@
     <ClCompile Include="..\..\GUI\UI\Books\MapBook.cpp" />
     <ClCompile Include="..\..\GUI\UI\Books\QuestBook.cpp" />
     <ClCompile Include="..\..\GUI\UI\Books\TownPortalBook.cpp" />
+    <ClCompile Include="..\..\GUI\UI\Chest.cpp" />
     <ClCompile Include="..\..\GUI\UI\Spellbook.cpp" />
     <ClCompile Include="..\..\GUI\UI\UIArena.cpp" />
     <ClCompile Include="..\..\GUI\UI\UIBooks.cpp" />
@@ -345,6 +346,7 @@
     <ClInclude Include="..\..\GUI\UI\Books\MapBook.h" />
     <ClInclude Include="..\..\GUI\UI\Books\QuestBook.h" />
     <ClInclude Include="..\..\GUI\UI\Books\TownPortalBook.h" />
+    <ClInclude Include="..\..\GUI\UI\Chest.h" />
     <ClInclude Include="..\..\GUI\UI\Spellbook.h" />
     <ClInclude Include="..\..\GUI\UI\UIArena.h" />
     <ClInclude Include="..\..\GUI\UI\UIBooks.h" />
--- a/Build/Visual Studio 2013/World of Might and Magic.vcxproj.filters	Tue May 12 11:07:32 2015 +0200
+++ b/Build/Visual Studio 2013/World of Might and Magic.vcxproj.filters	Tue May 12 11:28:22 2015 +0200
@@ -598,6 +598,9 @@
     <ClCompile Include="..\..\GUI\UI\Spellbook.cpp">
       <Filter>GUI\UI</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\GUI\UI\Chest.cpp">
+      <Filter>GUI\UI</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\lib\libavcodec\avcodec.h">
@@ -1363,6 +1366,9 @@
     <ClInclude Include="..\..\GUI\UI\Spellbook.h">
       <Filter>GUI\UI</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\GUI\UI\Chest.h">
+      <Filter>GUI\UI</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\lib\OpenAL\lib\x86\avcodec-55.def">
--- a/Engine/Objects/Chest.cpp	Tue May 12 11:07:32 2015 +0200
+++ b/Engine/Objects/Chest.cpp	Tue May 12 11:28:22 2015 +0200
@@ -1,8 +1,7 @@
 #define _CRTDBG_MAP_ALLOC
+#define _CRT_SECURE_NO_WARNINGS
 #include <stdlib.h>
 #include <crtdbg.h>
-
-#define _CRT_SECURE_NO_WARNINGS
 #include <stdio.h>
 
 #include "Engine/Engine.h"
@@ -16,26 +15,29 @@
 #include "../Graphics/Outdoor.h"
 #include "../Graphics/DecorationList.h"
 #include "../Party.h"
-#include "Media/Audio/AudioPlayer.h"
 #include "../OurMath.h"
 #include "../Texts.h"
 #include "ObjectList.h"
-#include "GUI/GUIWindow.h"
 #include "../Timer.h"
 #include "SpriteObject.h"
-#include "IO/Mouse.h"
 #include "../Graphics/Viewport.h"
 #include "../Graphics/Level/Decoration.h"
 
+#include "IO/Mouse.h"
+
+#include "GUI/UI/Chest.h"
+
+#include "Media/Audio/AudioPlayer.h"
+
+
+
 size_t uNumChests; // idb
 struct ChestList *pChestList;
 std::array<Chest, 20> pChests;
 
+extern int pChestWidthsByType[8];
+extern int pChestHeightsByType[8];
 
-const int pChestPixelOffsetX[8]  = {42, 18, 18, 42, 42, 42, 18, 42};
-const int pChestPixelOffsetY[8]  = {34, 30, 30, 34, 34, 34, 30, 34};
-const int pChestWidthsByType[8]  = {9, 9, 9, 9, 9, 9, 9, 9};
-const int pChestHeightsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9};
 
 
 //----- (0042041E) --------------------------------------------------------
@@ -185,11 +187,7 @@
       pPlayers[uActiveCharacter]->PlaySound(SPEECH_4, 0);
   }
   OpenedTelekinesis = false;
-  pChestWindow = pGUIWindow_CurrentMenu = new GUIWindow_Chest(0, 0, window->GetWidth(), window->GetHeight(), uChestID, 0);
-  pBtn_ExitCancel = pChestWindow->CreateButton(471, 445, 169,  35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], pIcons_LOD->GetTexture(uExitCancelTextureId), 0);// Exit
-                    pChestWindow->CreateButton(  7,   8, 460, 343, 1, 0, UIMSG_CHEST_ClickItem, 0, 0, "", 0);
-  current_screen_type = SCREEN_CHEST;
-  pEventTimer->Pause();
+  pChestWindow = pGUIWindow_CurrentMenu = new GUIWindow_Chest(uChestID);
   return true;
 }
 
@@ -214,68 +212,6 @@
   }
 }
 
-//----- (0042092D) --------------------------------------------------------
-void Chest::DrawChestUI(signed int uChestID)
-    {
-
-    int chestBitmapId; // eax@1
-    unsigned int v5; // eax@1
-    int chest_item_index; // ecx@3
-    unsigned int item_texture_id; // eax@4
-    Texture *item_texture; // esi@4
-    signed int itemPixelWidth; // ecx@4
-    signed int itemPixelHeght; // edx@4
-//    signed int v11; // eax@4
-    int v12; // eax@6
-    int v13; // eax@6
-    unsigned int itemPixelPosX; // ST34_4@8
-    int itemPixelPosY; // edi@8
-    int *v16; // [sp+Ch] [bp-28h]@1
-//    int v17; // [sp+10h] [bp-24h]@4
-    int chest_offs_y; // [sp+14h] [bp-20h]@1
-    signed int chestHeghtCells; // [sp+18h] [bp-1Ch]@1
-    int chest_offs_x; // [sp+1Ch] [bp-18h]@1
-    signed int chestWidthCells; // [sp+20h] [bp-14h]@1
-    signed int item_counter; // [sp+30h] [bp-4h]@1
-
-    v16 = pRenderer->pActiveZBuffer;
-    pRenderer->ClearZBuffer(0, 479);
-    chestBitmapId = pChests[uChestID].uChestBitmapID;
-    chest_offs_x = pChestPixelOffsetX[chestBitmapId];
-    chest_offs_y = pChestPixelOffsetY[chestBitmapId];
-    chestWidthCells = pChestWidthsByType[chestBitmapId];
-    chestHeghtCells = pChestHeightsByType[chestBitmapId];
-    sprintfex(pTmpBuf.data(), "chest%02d", pChestList->pChests[chestBitmapId].uTextureID);
-    v5 = pIcons_LOD->LoadTexture(pTmpBuf.data(), TEXTURE_16BIT_PALETTE);
-    pRenderer->DrawTextureIndexed(8u, 8u, pIcons_LOD->GetTexture(v5));
-
-    for (item_counter = 0; item_counter < chestWidthCells * chestHeghtCells; ++item_counter)
-        {
-        chest_item_index = pChests[uChestID].pInventoryIndices[item_counter];
-        if ( chest_item_index > 0 )
-            {
-            item_texture_id = pIcons_LOD->LoadTexture(
-                //pItemsTable->pItems[*(int *)((char *)&pOtherOverlayList->pOverlays[49].field_4 + 36 * v6 + v3 * 5324)].pIconName,
-                pChests[uChestID].igChestItems[chest_item_index - 1].GetIconName(), TEXTURE_16BIT_PALETTE);
-            item_texture = pIcons_LOD->GetTexture(item_texture_id);
-            itemPixelWidth = item_texture->uTextureWidth;
-            itemPixelHeght = item_texture->uTextureHeight;
-            if ( itemPixelWidth < 14 )
-                itemPixelWidth = 14;
-            v12 = itemPixelWidth - 14;
-            v12 = v12 & 0xFFFFFFE0;
-            v13 = v12 + 32;
-            if ( itemPixelHeght < 14 )
-                itemPixelHeght = 14;
-            itemPixelPosX = chest_offs_x + 32 * (item_counter % chestWidthCells) + ((signed int)(v13 - itemPixelWidth)/2);
-            itemPixelPosY = chest_offs_y + 32 * (item_counter / chestHeghtCells) +
-                ((signed int)(((itemPixelHeght - 14) & 0xFFFFFFE0) + 32- item_texture->uTextureHeight ) /2);
-            pRenderer->DrawTextureIndexedAlpha(  itemPixelPosX,   itemPixelPosY,  item_texture);
-            ZBuffer_DoFill2(&v16[itemPixelPosX + pSRZBufferLineOffsets[itemPixelPosY]], item_texture, item_counter + 1);
-            }
-        }
-    pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId));
-    }
 
 
 //----- (0041FE71) --------------------------------------------------------
--- a/Engine/Objects/Chest.h	Tue May 12 11:07:32 2015 +0200
+++ b/Engine/Objects/Chest.h	Tue May 12 11:28:22 2015 +0200
@@ -1,5 +1,5 @@
 #pragma once
-
+#include "Engine/Objects/Items.h"
 
 
 
@@ -54,11 +54,10 @@
 
   static bool CanPlaceItemAt(signed int a1, int a2, signed int uChestID);
   static int CountChestItems(signed int uChestID);
-  static int PutItemInChest(int a1, ItemGen *a2, signed int uChestID);
+  static int PutItemInChest(int a1, struct ItemGen *a2, signed int uChestID);
   static void PlaceItemAt(unsigned int put_cell_pos, unsigned int uItemIdx, signed int uChestID);
   static void PlaceItems(signed int uChestID);
   static bool Open(signed int uChestID);
-  static void DrawChestUI(signed int uChestID);
   static void ToggleFlag(signed int uChestID, unsigned __int16 uFlag, unsigned int bToggle);
   static void ChestUI_WritePointedObjectStatusString();
   static void OnChestLeftClick();
--- a/GUI/GUIWindow.cpp	Tue May 12 11:07:32 2015 +0200
+++ b/GUI/GUIWindow.cpp	Tue May 12 11:28:22 2015 +0200
@@ -1314,23 +1314,6 @@
     GameUI_DrawBranchlessDialogue();
 }
 
-void GUIWindow_Chest::Update()
-{
-// -----------------------------------
-// 004156F0 GUI_UpdateWindows --- part
-    if (current_screen_type == SCREEN_CHEST)
-    {
-        Chest::DrawChestUI(par1C);
-    }
-    else if (current_screen_type == SCREEN_CHEST_INVENTORY)
-    {
-        pRenderer->ClearZBuffer(0, 479);
-        draw_leather();
-        CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
-        pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId));
-    }
-}
-
 void GUIWindow_House::Update()
 {
 // -----------------------------------
--- a/GUI/GUIWindow.h	Tue May 12 11:07:32 2015 +0200
+++ b/GUI/GUIWindow.h	Tue May 12 11:28:22 2015 +0200
@@ -395,21 +395,6 @@
     virtual void Update();
     virtual void Release();
 };
-struct GUIWindow_Chest : public GUIWindow
-{
-    GUIWindow_Chest(unsigned int x, unsigned int y, unsigned int width, unsigned int height, int button, const char *hint) :
-        GUIWindow(x, y, width, height, button, hint)
-    {
-        CreateButton(61, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 1, '1', "", 0);
-        CreateButton(177, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 2, '2', "", 0);
-        CreateButton(292, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 3, '3', "", 0);
-        CreateButton(407, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 4, '4', "", 0);
-        CreateButton(0, 0, 0, 0, 1, 0, UIMSG_CycleCharacters, 0, 9, "", 0);
-    }
-    virtual ~GUIWindow_Chest() {}
-
-    virtual void Update();
-};
 struct GUIWindow_House : public GUIWindow
 {
     GUIWindow_House(unsigned int x, unsigned int y, unsigned int width, unsigned int height, int button, const char *hint);
@@ -678,7 +663,6 @@
 
 
 
-// book ui
 void DrawSpellDescriptionPopup(int spell_index);
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GUI/UI/Chest.cpp	Tue May 12 11:28:22 2015 +0200
@@ -0,0 +1,117 @@
+#include "Engine/Engine.h"
+#include "Engine/Timer.h"
+#include "Engine/LOD.h"
+#include "Engine/texts.h"
+#include "Engine/Graphics/IRender.h"
+#include "Engine/Objects/Chest.h"
+
+#include "GUI/UI/Chest.h"
+
+
+
+int pChestPixelOffsetX[8] = { 42, 18, 18, 42, 42, 42, 18, 42 };
+int pChestPixelOffsetY[8] = { 34, 30, 30, 34, 34, 34, 30, 34 };
+int pChestWidthsByType[8] = { 9, 9, 9, 9, 9, 9, 9, 9 };
+int pChestHeightsByType[8] = { 9, 9, 9, 9, 9, 9, 9, 9 };
+
+
+
+GUIWindow_Chest::GUIWindow_Chest(unsigned int chest_id) :
+    GUIWindow(0, 0, window->GetWidth(), window->GetHeight(), chest_id, nullptr)
+{
+// --------------------------------------
+// 0041C432 GUIWindow::GUIWindow --- part
+    CreateButton(61, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 1, '1', "", 0);
+    CreateButton(177, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 2, '2', "", 0);
+    CreateButton(292, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 3, '3', "", 0);
+    CreateButton(407, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 4, '4', "", 0);
+    CreateButton(0, 0, 0, 0, 1, 0, UIMSG_CycleCharacters, 0, 9, "", 0);
+
+// --------------------------------------------------------
+// 0042041E bool Chest::Open( signed int uChestID ) -- part
+    pBtn_ExitCancel = CreateButton(471, 445, 169, 35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], pIcons_LOD->GetTexture(uExitCancelTextureId), 0);// Exit
+    CreateButton(7, 8, 460, 343, 1, 0, UIMSG_CHEST_ClickItem, 0, 0, "", 0);
+    current_screen_type = SCREEN_CHEST;
+    pEventTimer->Pause();
+}
+
+
+
+void GUIWindow_Chest::Update()
+{
+    // -----------------------------------
+    // 004156F0 GUI_UpdateWindows --- part
+    if (current_screen_type == SCREEN_CHEST_INVENTORY)
+    {
+        pRenderer->ClearZBuffer(0, 479);
+        draw_leather();
+        CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
+        pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId));
+    }
+    else if (current_screen_type == SCREEN_CHEST)
+    {
+        //Chest::DrawChestUI(par1C);
+
+        // -----------------------------------------------------
+        // 0042092D void Chest::DrawChestUI(signed int uChestID)
+        auto uChestID = (unsigned int)ptr_1C;
+
+        int chestBitmapId; // eax@1
+        unsigned int v5; // eax@1
+        int chest_item_index; // ecx@3
+        unsigned int item_texture_id; // eax@4
+        Texture *item_texture; // esi@4
+        signed int itemPixelWidth; // ecx@4
+        signed int itemPixelHeght; // edx@4
+        //    signed int v11; // eax@4
+        int v12; // eax@6
+        int v13; // eax@6
+        unsigned int itemPixelPosX; // ST34_4@8
+        int itemPixelPosY; // edi@8
+        int *v16; // [sp+Ch] [bp-28h]@1
+        //    int v17; // [sp+10h] [bp-24h]@4
+        int chest_offs_y; // [sp+14h] [bp-20h]@1
+        signed int chestHeghtCells; // [sp+18h] [bp-1Ch]@1
+        int chest_offs_x; // [sp+1Ch] [bp-18h]@1
+        signed int chestWidthCells; // [sp+20h] [bp-14h]@1
+        signed int item_counter; // [sp+30h] [bp-4h]@1
+
+        v16 = pRenderer->pActiveZBuffer;
+        pRenderer->ClearZBuffer(0, 479);
+        chestBitmapId = pChests[uChestID].uChestBitmapID;
+        chest_offs_x = pChestPixelOffsetX[chestBitmapId];
+        chest_offs_y = pChestPixelOffsetY[chestBitmapId];
+        chestWidthCells = pChestWidthsByType[chestBitmapId];
+        chestHeghtCells = pChestHeightsByType[chestBitmapId];
+        sprintfex(pTmpBuf.data(), "chest%02d", pChestList->pChests[chestBitmapId].uTextureID);
+        v5 = pIcons_LOD->LoadTexture(pTmpBuf.data(), TEXTURE_16BIT_PALETTE);
+        pRenderer->DrawTextureIndexed(8u, 8u, pIcons_LOD->GetTexture(v5));
+
+        for (item_counter = 0; item_counter < chestWidthCells * chestHeghtCells; ++item_counter)
+        {
+            chest_item_index = pChests[uChestID].pInventoryIndices[item_counter];
+            if (chest_item_index > 0)
+            {
+                item_texture_id = pIcons_LOD->LoadTexture(
+                    //pItemsTable->pItems[*(int *)((char *)&pOtherOverlayList->pOverlays[49].field_4 + 36 * v6 + v3 * 5324)].pIconName,
+                    pChests[uChestID].igChestItems[chest_item_index - 1].GetIconName(), TEXTURE_16BIT_PALETTE);
+                item_texture = pIcons_LOD->GetTexture(item_texture_id);
+                itemPixelWidth = item_texture->uTextureWidth;
+                itemPixelHeght = item_texture->uTextureHeight;
+                if (itemPixelWidth < 14)
+                    itemPixelWidth = 14;
+                v12 = itemPixelWidth - 14;
+                v12 = v12 & 0xFFFFFFE0;
+                v13 = v12 + 32;
+                if (itemPixelHeght < 14)
+                    itemPixelHeght = 14;
+                itemPixelPosX = chest_offs_x + 32 * (item_counter % chestWidthCells) + ((signed int)(v13 - itemPixelWidth) / 2);
+                itemPixelPosY = chest_offs_y + 32 * (item_counter / chestHeghtCells) +
+                    ((signed int)(((itemPixelHeght - 14) & 0xFFFFFFE0) + 32 - item_texture->uTextureHeight) / 2);
+                pRenderer->DrawTextureIndexedAlpha(itemPixelPosX, itemPixelPosY, item_texture);
+                ZBuffer_DoFill2(&v16[itemPixelPosX + pSRZBufferLineOffsets[itemPixelPosY]], item_texture, item_counter + 1);
+            }
+        }
+        pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId));
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GUI/UI/Chest.h	Tue May 12 11:28:22 2015 +0200
@@ -0,0 +1,12 @@
+#pragma once
+#include "GUI/GUIWindow.h"
+
+
+
+struct GUIWindow_Chest : public GUIWindow
+{
+             GUIWindow_Chest(unsigned int chest_id);
+    virtual ~GUIWindow_Chest() {}
+
+    virtual void Update();
+};
\ No newline at end of file
--- a/GUI/UI/UIPopup.cpp	Tue May 12 11:07:32 2015 +0200
+++ b/GUI/UI/UIPopup.cpp	Tue May 12 11:28:22 2015 +0200
@@ -1285,7 +1285,7 @@
   spell_info_window.DrawTitleText(pFontComic, 12, spell_info_window.uFrameHeight - LOBYTE(pFontComic->uFontHeight) - 16, 0, pTmpBuf.data(), 3);
   dword_507B00_spell_info_to_draw_in_popup = 0;
 }
-    // 507B00: using guessed type int dword_507B00_spell_info_to_draw_in_popup;
+
 
 //----- (00416D62) --------------------------------------------------------
 void UI_OnMouseRightClick(Vec2_int_ *_this)