World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
UIChest.cpp
См. документацию.
1 #include "Engine/Engine.h"
2 #include "Engine/LOD.h"
3 #include "Engine/Localization.h"
4 #include "Engine/Time.h"
5 
7 
8 #include "Engine/Objects/Chest.h"
9 
10 #include "GUI/GUIButton.h"
11 #include "GUI/UI/UIChest.h"
12 
13 #include "Platform/Api.h"
14 
15 int pChestPixelOffsetX[8] = {42, 18, 18, 42, 42, 42, 18, 42};
16 int pChestPixelOffsetY[8] = {34, 30, 30, 34, 34, 34, 30, 34};
17 int pChestWidthsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9};
18 int pChestHeightsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9};
19 
20 GUIWindow_Chest::GUIWindow_Chest(unsigned int chest_id)
21  : GUIWindow(WINDOW_Chest, 0, 0, window->GetWidth(), window->GetHeight(), chest_id) {
22  CreateButton(61, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 1, '1', "");
23  CreateButton(177, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 2, '2', "");
24  CreateButton(292, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 3, '3', "");
25  CreateButton(407, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 4, '4', "");
26  CreateButton(0, 0, 0, 0, 1, 0, UIMSG_CycleCharacters, 0, 9, "");
27 
29  CreateButton(471, 445, 169, 35, 1, 0, UIMSG_Escape, 0, 0,
31  {{ui_exit_cancel_button_background}}); // Exit
32  CreateButton(7, 8, 460, 343, 1, 0, UIMSG_CHEST_ClickItem, 0, 0, "");
34  pEventTimer->Pause();
35 }
36 
39  render->ClearZBuffer(0, 479);
40  draw_leather();
42  render->DrawTextureAlphaNew(pBtn_ExitCancel->uX / 640.0f,
43  pBtn_ExitCancel->uY / 480.0f,
46  auto uChestID = (unsigned int)ptr_1C;
47 
48  int *v16 = render->pActiveZBuffer;
49  render->ClearZBuffer(0, 479);
50  int chestBitmapId = vChests[uChestID].uChestBitmapID;
51  int chest_offs_x = pChestPixelOffsetX[chestBitmapId];
52  int chest_offs_y = pChestPixelOffsetY[chestBitmapId];
53  int chestWidthCells = pChestWidthsByType[chestBitmapId];
54  int chestHeghtCells = pChestHeightsByType[chestBitmapId];
55 
56  Image *chest_background = assets->GetImage_ColorKey(
57  StringPrintf("chest%02d", pChestList->vChests[chestBitmapId].uTextureID), 0x7FF);
58  render->DrawTextureAlphaNew(8 / 640.0f, 8 / 480.0f, chest_background);
59 
60  for (int item_counter = 0;
61  item_counter < chestWidthCells * chestHeghtCells; ++item_counter) {
62  int chest_item_index = vChests[uChestID].pInventoryIndices[item_counter];
63  if (chest_item_index > 0) {
64  auto item_texture = assets->GetImage_ColorKey(
65  vChests[uChestID].igChestItems[chest_item_index - 1].GetIconName(),
66  0x7FF);
67 
68  int itemPixelWidth = item_texture->GetWidth();
69  int itemPixelHeght = item_texture->GetHeight();
70  if (itemPixelWidth < 14) itemPixelWidth = 14;
71  if (itemPixelHeght < 14) itemPixelHeght = 14;
72  signed int X_offset = (((signed int)((itemPixelWidth - 14) & 0xFFFFFFE0) + 32) - itemPixelWidth) / 2;
73  signed int Y_offset = (((signed int)((itemPixelHeght - 14) & 0xFFFFFFE0) + 32) - itemPixelHeght) / 2;
74  int itemPixelPosX = chest_offs_x + 32 * (item_counter % chestWidthCells) + X_offset;
75  int itemPixelPosY = chest_offs_y + 32 * (item_counter / chestHeghtCells) + Y_offset;
76  render->DrawTextureAlphaNew(itemPixelPosX / 640.0f,
77  itemPixelPosY / 480.0f,
78  item_texture);
79  // ZBuffer_DoFill2(&v16[itemPixelPosX +
80  // pSRZBufferLineOffsets[itemPixelPosY]], item_texture,
81  // item_counter + 1);
82  }
83  }
84  render->DrawTextureAlphaNew(pBtn_ExitCancel->uX / 640.0f,
85  pBtn_ExitCancel->uY / 480.0f,
87  }
88 }
pChestList
ChestList * pChestList
Definition: Chest.cpp:38
Localization::GetString
const char * GetString(unsigned int index) const
Definition: Localization.cpp:13
pChestPixelOffsetY
int pChestPixelOffsetY[8]
Definition: UIChest.cpp:16
UIMSG_Escape
@ UIMSG_Escape
Definition: GUIWindow.h:96
LOD.h
Image::GetHeight
unsigned int GetHeight()
Definition: Image.cpp:230
UIMSG_CycleCharacters
@ UIMSG_CycleCharacters
Definition: GUIWindow.h:143
GUIWindow
Definition: GUIWindow.h:433
ui_exit_cancel_button_background
Image * ui_exit_cancel_button_background
Definition: GUIWindow.cpp:89
GUIWindow::CreateButton
GUIButton * CreateButton(int x, int y, int width, int height, int a6, int a7, UIMessageType msg, unsigned int msg_param, uint8_t hotkey, const String &label, const std::vector< Image * > &textures=std::vector< Image * >())
Definition: GUIWindow.cpp:717
CURRENT_SCREEN::SCREEN_CHEST
@ SCREEN_CHEST
UIChest.h
pChestPixelOffsetX
int pChestPixelOffsetX[8]
Definition: UIChest.cpp:15
localization
Localization * localization
Definition: Localization.cpp:11
UIMSG_SelectCharacter
@ UIMSG_SelectCharacter
Definition: GUIWindow.h:93
pChestWidthsByType
int pChestWidthsByType[8]
Definition: UIChest.cpp:17
pPlayers
NZIArray< struct Player *, 5 > pPlayers
Definition: Player.cpp:46
Chest.h
Engine.h
current_screen_type
enum CURRENT_SCREEN current_screen_type
Definition: GUIWindow.cpp:83
CharacterUI_InventoryTab_Draw
void CharacterUI_InventoryTab_Draw(Player *player, bool a2)
Definition: UICharacter.cpp:1829
GUIWindow_Chest::Update
virtual void Update()
Definition: UIChest.cpp:37
Localization.h
Image::GetWidth
unsigned int GetWidth()
Definition: Image.cpp:217
GUIButton.h
pBtn_ExitCancel
GUIButton * pBtn_ExitCancel
Definition: GUIButton.cpp:28
Image
Definition: Image.h:19
IRender.h
WINDOW_Chest
@ WINDOW_Chest
Definition: GUIWindow.h:305
AssetsManager::GetImage_ColorKey
Texture * GetImage_ColorKey(const String &name, uint16_t colorkey)
Definition: AssetsManager.cpp:34
window
EGLSurface EGLNativeWindowType * window
Definition: SDL_egl.h:1580
f
GLfloat f
Definition: SDL_opengl_glext.h:1873
UIMSG_CHEST_ClickItem
@ UIMSG_CHEST_ClickItem
Definition: GUIWindow.h:20
Timer::Pause
void Pause()
Definition: Time.cpp:19
GUIButton::uX
unsigned int uX
Definition: GUIButton.h:21
vChests
std::vector< Chest > vChests
Definition: Chest.cpp:39
draw_leather
void draw_leather()
Definition: UICharacter.cpp:925
GUIWindow_Chest::GUIWindow_Chest
GUIWindow_Chest(unsigned int chest_id)
Definition: UIChest.cpp:20
assets
AssetsManager * assets
Definition: AssetsManager.cpp:12
uActiveCharacter
unsigned int uActiveCharacter
Definition: mm7_data.cpp:555
pChestHeightsByType
int pChestHeightsByType[8]
Definition: UIChest.cpp:18
GUIButton::uY
unsigned int uY
Definition: GUIButton.h:22
GUIWindow::ptr_1C
void * ptr_1C
Definition: GUIWindow.h:476
StringPrintf
String StringPrintf(const char *fmt,...)
Definition: Strings.cpp:9
pEventTimer
Timer * pEventTimer
Definition: Time.cpp:8
Api.h
Time.h
CURRENT_SCREEN::SCREEN_CHEST_INVENTORY
@ SCREEN_CHEST_INVENTORY
ChestList::vChests
std::vector< ChestDesc > vChests
Definition: Chest.h:30
render
std::shared_ptr< IRender > render
Definition: RenderOpenGL.cpp:52