annotate GUI/UI/Chest.cpp @ 2553:48708da03b7f

Party Creation UI logic separated from MainMenu
author a.parshin
date Wed, 13 May 2015 02:20:05 +0200
parents fb42e2662c38
children 0c67be4ec900
rev   line source
2550
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
1 #include "Engine/Engine.h"
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
2 #include "Engine/Timer.h"
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
3 #include "Engine/LOD.h"
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
4 #include "Engine/texts.h"
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
5 #include "Engine/Graphics/IRender.h"
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
6 #include "Engine/Objects/Chest.h"
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
7
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
8 #include "GUI/UI/Chest.h"
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
9
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
10
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
11
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
12 int pChestPixelOffsetX[8] = { 42, 18, 18, 42, 42, 42, 18, 42 };
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
13 int pChestPixelOffsetY[8] = { 34, 30, 30, 34, 34, 34, 30, 34 };
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
14 int pChestWidthsByType[8] = { 9, 9, 9, 9, 9, 9, 9, 9 };
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
15 int pChestHeightsByType[8] = { 9, 9, 9, 9, 9, 9, 9, 9 };
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
16
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
17
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
18
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
19 GUIWindow_Chest::GUIWindow_Chest(unsigned int chest_id) :
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
20 GUIWindow(0, 0, window->GetWidth(), window->GetHeight(), chest_id, nullptr)
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
21 {
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
22 // --------------------------------------
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
23 // 0041C432 GUIWindow::GUIWindow --- part
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
24 CreateButton(61, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 1, '1', "", 0);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
25 CreateButton(177, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 2, '2', "", 0);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
26 CreateButton(292, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 3, '3', "", 0);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
27 CreateButton(407, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 4, '4', "", 0);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
28 CreateButton(0, 0, 0, 0, 1, 0, UIMSG_CycleCharacters, 0, 9, "", 0);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
29
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
30 // --------------------------------------------------------
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
31 // 0042041E bool Chest::Open( signed int uChestID ) -- part
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
32 pBtn_ExitCancel = CreateButton(471, 445, 169, 35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], pIcons_LOD->GetTexture(uExitCancelTextureId), 0);// Exit
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
33 CreateButton(7, 8, 460, 343, 1, 0, UIMSG_CHEST_ClickItem, 0, 0, "", 0);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
34 current_screen_type = SCREEN_CHEST;
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
35 pEventTimer->Pause();
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
36 }
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
37
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
38
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
39
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
40 void GUIWindow_Chest::Update()
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
41 {
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
42 // -----------------------------------
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
43 // 004156F0 GUI_UpdateWindows --- part
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
44 if (current_screen_type == SCREEN_CHEST_INVENTORY)
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
45 {
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
46 pRenderer->ClearZBuffer(0, 479);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
47 draw_leather();
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
48 CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
49 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId));
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
50 }
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
51 else if (current_screen_type == SCREEN_CHEST)
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
52 {
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
53 //Chest::DrawChestUI(par1C);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
54
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
55 // -----------------------------------------------------
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
56 // 0042092D void Chest::DrawChestUI(signed int uChestID)
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
57 auto uChestID = (unsigned int)ptr_1C;
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
58
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
59 int chestBitmapId; // eax@1
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
60 unsigned int v5; // eax@1
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
61 int chest_item_index; // ecx@3
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
62 unsigned int item_texture_id; // eax@4
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
63 Texture *item_texture; // esi@4
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
64 signed int itemPixelWidth; // ecx@4
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
65 signed int itemPixelHeght; // edx@4
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
66 // signed int v11; // eax@4
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
67 int v12; // eax@6
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
68 int v13; // eax@6
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
69 unsigned int itemPixelPosX; // ST34_4@8
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
70 int itemPixelPosY; // edi@8
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
71 int *v16; // [sp+Ch] [bp-28h]@1
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
72 // int v17; // [sp+10h] [bp-24h]@4
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
73 int chest_offs_y; // [sp+14h] [bp-20h]@1
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
74 signed int chestHeghtCells; // [sp+18h] [bp-1Ch]@1
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
75 int chest_offs_x; // [sp+1Ch] [bp-18h]@1
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
76 signed int chestWidthCells; // [sp+20h] [bp-14h]@1
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
77 signed int item_counter; // [sp+30h] [bp-4h]@1
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
78
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
79 v16 = pRenderer->pActiveZBuffer;
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
80 pRenderer->ClearZBuffer(0, 479);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
81 chestBitmapId = pChests[uChestID].uChestBitmapID;
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
82 chest_offs_x = pChestPixelOffsetX[chestBitmapId];
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
83 chest_offs_y = pChestPixelOffsetY[chestBitmapId];
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
84 chestWidthCells = pChestWidthsByType[chestBitmapId];
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
85 chestHeghtCells = pChestHeightsByType[chestBitmapId];
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
86 sprintfex(pTmpBuf.data(), "chest%02d", pChestList->pChests[chestBitmapId].uTextureID);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
87 v5 = pIcons_LOD->LoadTexture(pTmpBuf.data(), TEXTURE_16BIT_PALETTE);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
88 pRenderer->DrawTextureIndexed(8u, 8u, pIcons_LOD->GetTexture(v5));
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
89
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
90 for (item_counter = 0; item_counter < chestWidthCells * chestHeghtCells; ++item_counter)
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
91 {
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
92 chest_item_index = pChests[uChestID].pInventoryIndices[item_counter];
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
93 if (chest_item_index > 0)
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
94 {
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
95 item_texture_id = pIcons_LOD->LoadTexture(
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
96 //pItemsTable->pItems[*(int *)((char *)&pOtherOverlayList->pOverlays[49].field_4 + 36 * v6 + v3 * 5324)].pIconName,
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
97 pChests[uChestID].igChestItems[chest_item_index - 1].GetIconName(), TEXTURE_16BIT_PALETTE);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
98 item_texture = pIcons_LOD->GetTexture(item_texture_id);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
99 itemPixelWidth = item_texture->uTextureWidth;
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
100 itemPixelHeght = item_texture->uTextureHeight;
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
101 if (itemPixelWidth < 14)
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
102 itemPixelWidth = 14;
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
103 v12 = itemPixelWidth - 14;
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
104 v12 = v12 & 0xFFFFFFE0;
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
105 v13 = v12 + 32;
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
106 if (itemPixelHeght < 14)
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
107 itemPixelHeght = 14;
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
108 itemPixelPosX = chest_offs_x + 32 * (item_counter % chestWidthCells) + ((signed int)(v13 - itemPixelWidth) / 2);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
109 itemPixelPosY = chest_offs_y + 32 * (item_counter / chestHeghtCells) +
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
110 ((signed int)(((itemPixelHeght - 14) & 0xFFFFFFE0) + 32 - item_texture->uTextureHeight) / 2);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
111 pRenderer->DrawTextureIndexedAlpha(itemPixelPosX, itemPixelPosY, item_texture);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
112 ZBuffer_DoFill2(&v16[itemPixelPosX + pSRZBufferLineOffsets[itemPixelPosY]], item_texture, item_counter + 1);
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
113 }
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
114 }
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
115 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId));
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
116 }
fb42e2662c38 Chest UI refactored to a class
a.parshin
parents:
diff changeset
117 }