comparison Engine/Objects/Chest.cpp @ 2550:fb42e2662c38

Chest UI refactored to a class
author a.parshin
date Tue, 12 May 2015 11:28:22 +0200
parents c674d547cc7c
children 30eb6dcac768
comparison
equal deleted inserted replaced
2549:3121fb54a110 2550:fb42e2662c38
1 #define _CRTDBG_MAP_ALLOC 1 #define _CRTDBG_MAP_ALLOC
2 #define _CRT_SECURE_NO_WARNINGS
2 #include <stdlib.h> 3 #include <stdlib.h>
3 #include <crtdbg.h> 4 #include <crtdbg.h>
4
5 #define _CRT_SECURE_NO_WARNINGS
6 #include <stdio.h> 5 #include <stdio.h>
7 6
8 #include "Engine/Engine.h" 7 #include "Engine/Engine.h"
9 8
10 #include "Items.h" 9 #include "Items.h"
14 #include "../MapInfo.h" 13 #include "../MapInfo.h"
15 #include "Actor.h" 14 #include "Actor.h"
16 #include "../Graphics/Outdoor.h" 15 #include "../Graphics/Outdoor.h"
17 #include "../Graphics/DecorationList.h" 16 #include "../Graphics/DecorationList.h"
18 #include "../Party.h" 17 #include "../Party.h"
19 #include "Media/Audio/AudioPlayer.h"
20 #include "../OurMath.h" 18 #include "../OurMath.h"
21 #include "../Texts.h" 19 #include "../Texts.h"
22 #include "ObjectList.h" 20 #include "ObjectList.h"
23 #include "GUI/GUIWindow.h"
24 #include "../Timer.h" 21 #include "../Timer.h"
25 #include "SpriteObject.h" 22 #include "SpriteObject.h"
26 #include "IO/Mouse.h"
27 #include "../Graphics/Viewport.h" 23 #include "../Graphics/Viewport.h"
28 #include "../Graphics/Level/Decoration.h" 24 #include "../Graphics/Level/Decoration.h"
25
26 #include "IO/Mouse.h"
27
28 #include "GUI/UI/Chest.h"
29
30 #include "Media/Audio/AudioPlayer.h"
31
32
29 33
30 size_t uNumChests; // idb 34 size_t uNumChests; // idb
31 struct ChestList *pChestList; 35 struct ChestList *pChestList;
32 std::array<Chest, 20> pChests; 36 std::array<Chest, 20> pChests;
33 37
34 38 extern int pChestWidthsByType[8];
35 const int pChestPixelOffsetX[8] = {42, 18, 18, 42, 42, 42, 18, 42}; 39 extern int pChestHeightsByType[8];
36 const int pChestPixelOffsetY[8] = {34, 30, 30, 34, 34, 34, 30, 34}; 40
37 const int pChestWidthsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9};
38 const int pChestHeightsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9};
39 41
40 42
41 //----- (0042041E) -------------------------------------------------------- 43 //----- (0042041E) --------------------------------------------------------
42 bool Chest::Open( signed int uChestID ) 44 bool Chest::Open( signed int uChestID )
43 { 45 {
183 { 185 {
184 if ( !OpenedTelekinesis ) 186 if ( !OpenedTelekinesis )
185 pPlayers[uActiveCharacter]->PlaySound(SPEECH_4, 0); 187 pPlayers[uActiveCharacter]->PlaySound(SPEECH_4, 0);
186 } 188 }
187 OpenedTelekinesis = false; 189 OpenedTelekinesis = false;
188 pChestWindow = pGUIWindow_CurrentMenu = new GUIWindow_Chest(0, 0, window->GetWidth(), window->GetHeight(), uChestID, 0); 190 pChestWindow = pGUIWindow_CurrentMenu = new GUIWindow_Chest(uChestID);
189 pBtn_ExitCancel = pChestWindow->CreateButton(471, 445, 169, 35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], pIcons_LOD->GetTexture(uExitCancelTextureId), 0);// Exit
190 pChestWindow->CreateButton( 7, 8, 460, 343, 1, 0, UIMSG_CHEST_ClickItem, 0, 0, "", 0);
191 current_screen_type = SCREEN_CHEST;
192 pEventTimer->Pause();
193 return true; 191 return true;
194 } 192 }
195 193
196 //----- (0042038D) -------------------------------------------------------- 194 //----- (0042038D) --------------------------------------------------------
197 void Chest::ChestUI_WritePointedObjectStatusString() 195 void Chest::ChestUI_WritePointedObjectStatusString()
212 } 210 }
213 } 211 }
214 } 212 }
215 } 213 }
216 214
217 //----- (0042092D) --------------------------------------------------------
218 void Chest::DrawChestUI(signed int uChestID)
219 {
220
221 int chestBitmapId; // eax@1
222 unsigned int v5; // eax@1
223 int chest_item_index; // ecx@3
224 unsigned int item_texture_id; // eax@4
225 Texture *item_texture; // esi@4
226 signed int itemPixelWidth; // ecx@4
227 signed int itemPixelHeght; // edx@4
228 // signed int v11; // eax@4
229 int v12; // eax@6
230 int v13; // eax@6
231 unsigned int itemPixelPosX; // ST34_4@8
232 int itemPixelPosY; // edi@8
233 int *v16; // [sp+Ch] [bp-28h]@1
234 // int v17; // [sp+10h] [bp-24h]@4
235 int chest_offs_y; // [sp+14h] [bp-20h]@1
236 signed int chestHeghtCells; // [sp+18h] [bp-1Ch]@1
237 int chest_offs_x; // [sp+1Ch] [bp-18h]@1
238 signed int chestWidthCells; // [sp+20h] [bp-14h]@1
239 signed int item_counter; // [sp+30h] [bp-4h]@1
240
241 v16 = pRenderer->pActiveZBuffer;
242 pRenderer->ClearZBuffer(0, 479);
243 chestBitmapId = pChests[uChestID].uChestBitmapID;
244 chest_offs_x = pChestPixelOffsetX[chestBitmapId];
245 chest_offs_y = pChestPixelOffsetY[chestBitmapId];
246 chestWidthCells = pChestWidthsByType[chestBitmapId];
247 chestHeghtCells = pChestHeightsByType[chestBitmapId];
248 sprintfex(pTmpBuf.data(), "chest%02d", pChestList->pChests[chestBitmapId].uTextureID);
249 v5 = pIcons_LOD->LoadTexture(pTmpBuf.data(), TEXTURE_16BIT_PALETTE);
250 pRenderer->DrawTextureIndexed(8u, 8u, pIcons_LOD->GetTexture(v5));
251
252 for (item_counter = 0; item_counter < chestWidthCells * chestHeghtCells; ++item_counter)
253 {
254 chest_item_index = pChests[uChestID].pInventoryIndices[item_counter];
255 if ( chest_item_index > 0 )
256 {
257 item_texture_id = pIcons_LOD->LoadTexture(
258 //pItemsTable->pItems[*(int *)((char *)&pOtherOverlayList->pOverlays[49].field_4 + 36 * v6 + v3 * 5324)].pIconName,
259 pChests[uChestID].igChestItems[chest_item_index - 1].GetIconName(), TEXTURE_16BIT_PALETTE);
260 item_texture = pIcons_LOD->GetTexture(item_texture_id);
261 itemPixelWidth = item_texture->uTextureWidth;
262 itemPixelHeght = item_texture->uTextureHeight;
263 if ( itemPixelWidth < 14 )
264 itemPixelWidth = 14;
265 v12 = itemPixelWidth - 14;
266 v12 = v12 & 0xFFFFFFE0;
267 v13 = v12 + 32;
268 if ( itemPixelHeght < 14 )
269 itemPixelHeght = 14;
270 itemPixelPosX = chest_offs_x + 32 * (item_counter % chestWidthCells) + ((signed int)(v13 - itemPixelWidth)/2);
271 itemPixelPosY = chest_offs_y + 32 * (item_counter / chestHeghtCells) +
272 ((signed int)(((itemPixelHeght - 14) & 0xFFFFFFE0) + 32- item_texture->uTextureHeight ) /2);
273 pRenderer->DrawTextureIndexedAlpha( itemPixelPosX, itemPixelPosY, item_texture);
274 ZBuffer_DoFill2(&v16[itemPixelPosX + pSRZBufferLineOffsets[itemPixelPosY]], item_texture, item_counter + 1);
275 }
276 }
277 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId));
278 }
279 215
280 216
281 //----- (0041FE71) -------------------------------------------------------- 217 //----- (0041FE71) --------------------------------------------------------
282 bool Chest::CanPlaceItemAt( signed int test_cell_position, int item_id, signed int uChestID ) 218 bool Chest::CanPlaceItemAt( signed int test_cell_position, int item_id, signed int uChestID )
283 { 219 {