G

NewUIInventoryExtension.cpp

public
Guest Apr 06, 2026 Never 254
Clone
C++ NewUIInventoryExtension 395 lines (321 loc) | 10.15 KB
1
#include "stdafx.h"
2
#include "NewUIInventoryExtension.h"
3
4
#include "NewUISystem.h"
5
#include "wsclientinline.h"
6
extern int DisplayWinCDepthBox;
7
extern int DisplayWin;
8
extern int DisplayWinMid;
9
extern int DisplayWinExt;
10
extern int DisplayWinReal;
11
extern int DisplayHeightExt;
12
using namespace SEASON3B;
13
14
CNewUIInventoryExtension::CNewUIInventoryExtension()
15
{
16
Init();
17
}
18
19
CNewUIInventoryExtension::~CNewUIInventoryExtension()
20
{
21
Release();
22
}
23
24
void CNewUIInventoryExtension::Init()
25
{
26
27
m_pNewUIMng = nullptr;
28
m_Pos.x = m_Pos.y = 0;
29
}
30
31
bool CNewUIInventoryExtension::Create(CNewUIManager* pNewUIMng, int x, int y)
32
{
33
if (nullptr == pNewUIMng || nullptr == g_pNewItemMng)
34
return false;
35
36
m_pNewUIMng = pNewUIMng;
37
m_pNewUIMng->AddUIObj(INTERFACE_ExpandInventory, this);
38
39
// we have to create all 4 boxes here already, and just handle the ones
40
// which are available to the character...
41
int i = 0;
42
for (auto& m_extension : m_extensions)
43
{
44
m_extension = new CNewUIInventoryCtrl();
45
46
const int indexOffset = MAX_MY_INVENTORY_INDEX + i * MAX_INVENTORY_EXT_ONE;
47
if (false == m_extension->Create(STORAGE_TYPE::INVENTORY, g_pNewUI3DRenderMng, g_pNewItemMng, this, x + DisplayWinCDepthBox + 15, y + 45 + HEIGHT_PER_EXT * i, COLUMN_INVENTORY, ROW_INVENTORY_EXT, indexOffset))
48
{
49
SAFE_DELETE(m_extension);
50
return false;
51
}
52
53
if (m_extension)
54
{
55
m_extension->SetToolTipType(TOOLTIP_TYPE_INVENTORY);
56
}
57
58
i++;
59
}
60
61
SetPos(x, y);
62
LoadImages();
63
SetButtonInfo();
64
Show(false);
65
66
return true;
67
}
68
69
void CNewUIInventoryExtension::Release()
70
{
71
UnloadImages();
72
73
for (auto extension : m_extensions)
74
{
75
if (extension)
76
{
77
SAFE_DELETE(extension);
78
}
79
}
80
81
if (m_pNewUIMng)
82
{
83
m_pNewUIMng->RemoveUIObj(this);
84
m_pNewUIMng = nullptr;
85
}
86
}
87
88
void CNewUIInventoryExtension::SetPos(int x, int y)
89
{
90
x = x;
91
m_Pos.x = x;
92
m_Pos.y = y;
93
int i = 0;
94
for (auto& m_extension : m_extensions)
95
{
96
m_extension->SetPos(x + 15, y + 45 + HEIGHT_PER_EXT * i);
97
i++;
98
}
99
100
101
m_BtnExit.ChangeButtonInfo(m_Pos.x + 13, m_Pos.y + 391, 36, 29);
102
}
103
104
bool CNewUIInventoryExtension::UpdateMouseEvent()
105
{
106
for (int i = 0; i < CharacterAttribute->InventoryExtensions; i++)
107
{
108
if (const auto m_extension = m_extensions[i])
109
{
110
if (!m_extension->UpdateMouseEvent())
111
{
112
return false;
113
}
114
if (IsPress(VK_LBUTTON) && CheckMouseIn(m_Pos.x + 169, m_Pos.y + 7, 13, 12))
115
{
116
g_pNewUISystem->Hide(INTERFACE_ExpandInventory);
117
return false;
118
}
119
if (InventoryProcess())
120
{
121
return false;
122
}
123
124
}
125
}
126
127
if (m_BtnExit.UpdateMouseEvent())
128
{
129
g_pNewUISystem->Hide(INTERFACE_ExpandInventory);
130
return false;
131
}
132
133
if (CheckMouseIn(m_Pos.x, m_Pos.y, WIDTH, HEIGHT))
134
{
135
MouseOnWindow = true; //Block SelectNPC
136
if (IsPress(VK_RBUTTON))
137
{
138
MouseRButton = false;
139
MouseRButtonPop = false;
140
MouseRButtonPush = false;
141
return false;
142
}
143
144
if (IsNone(VK_LBUTTON) == false)
145
{
146
return false;
147
}
148
}
149
150
return true;
151
}
152
153
bool CNewUIInventoryExtension::InventoryProcess()
154
{
155
if (!CheckMouseIn(m_Pos.x, m_Pos.y, WIDTH, HEIGHT))
156
{
157
return false;
158
}
159
160
int targetExtensionIndex = 0;
161
CNewUIInventoryCtrl* target = nullptr;
162
for (auto* extension : m_extensions)
163
{
164
if (extension->CheckPtInRect(MouseX, MouseY))
165
{
166
//return 1;
167
return g_pMyInventory->HandleInventoryActions(extension);
168
}
169
170
targetExtensionIndex++;
171
}
172
173
return false;
174
}
175
176
bool CNewUIInventoryExtension::UpdateKeyEvent()
177
{
178
if (g_pNewUISystem->IsVisible(INTERFACE_ExpandInventory) == false)
179
{
180
return true;
181
}
182
183
return true;
184
}
185
186
bool CNewUIInventoryExtension::Update()
187
{
188
for (int i = 0; i < CharacterAttribute->InventoryExtensions; i++)
189
{
190
if (const auto& extension = m_extensions[i])
191
{
192
if (extension && !extension->Update())
193
{
194
return false;
195
}
196
}
197
}
198
199
return true;
200
}
201
202
bool CNewUIInventoryExtension::Render()
203
{
204
EnableAlphaTest();
205
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
206
RenderFrame();
207
RenderTexts();
208
209
for (int i = 0; i < CharacterAttribute->InventoryExtensions; i++)
210
{
211
if (const auto& m_extension = m_extensions[i])
212
{
213
m_extension->Render();
214
}
215
}
216
217
m_BtnExit.Render();
218
219
DisableAlphaBlend();
220
return true;
221
}
222
223
void CNewUIInventoryExtension::RenderFrame() const
224
{
225
const auto x = static_cast<float>(m_Pos.x);
226
const auto y = static_cast<float>(m_Pos.y);
227
228
RenderImage(IMAGE_NPCSHOP_BACK, x, y, WIDTH, HEIGHT);
229
RenderImage(IMAGE_NPCSHOP_TOP, x, y, WIDTH, 64.f);
230
RenderImage(IMAGE_NPCSHOP_LEFT, x, y + 64, 21.f, 320.f);
231
RenderImage(IMAGE_NPCSHOP_RIGHT, x + WIDTH - 21, y + 64, 21.f, 320.f);
232
RenderImage(IMAGE_NPCSHOP_BOTTOM, x, y + 429 - 45, WIDTH, 45.f);
233
234
for (int i = MAX_INVENTORY_EXT_COUNT - 1; i >= CharacterAttribute->InventoryExtensions; --i)
235
{
236
RenderImage(IMAGE_EXTENSION_TABLE, x + 11, y + 42 + i * HEIGHT_PER_EXT, 173, HEIGHT_PER_EXT);
237
RenderImage(IMAGE_EXTENSION_EMPTY, x + 15, y + 45 + i * HEIGHT_PER_EXT, 161, HEIGHT_PER_EXT - (EXT_BORDER * 2));
238
RenderImage(static_cast<GLuint>(IMAGE_EXTENSION_NO1 + i), x + 85, y + 71 + i * HEIGHT_PER_EXT, 25, 28);
239
}
240
}
241
242
void CNewUIInventoryExtension::RenderTexts() const
243
{
244
g_pRenderText->SetFont(g_hFontBold);
245
g_pRenderText->SetBgColor(0);
246
g_pRenderText->SetTextColor(220, 220, 220, 255);
247
248
g_pRenderText->RenderText(m_Pos.x, m_Pos.y + 12, GlobalText[3323], WIDTH, 0, RT3_SORT_CENTER);
249
}
250
251
float CNewUIInventoryExtension::GetLayerDepth()
252
{
253
return 4.55;
254
}
255
256
void CNewUIInventoryExtension::SetButtonInfo()
257
{
258
m_BtnExit.ChangeButtonImgState(true, IMAGE_INVENTORY_EXIT_BTN, false);
259
m_BtnExit.ChangeToolTipText(GlobalText[1002], true);
260
}
261
262
void CNewUIInventoryExtension::LoadImages()
263
{
264
LoadBitmap("Interface\\newui_msgbox_back.jpg", IMAGE_NPCSHOP_BACK, GL_LINEAR);
265
LoadBitmap("Interface\\newui_item_back04.tga", IMAGE_NPCSHOP_TOP, GL_LINEAR);
266
LoadBitmap("Interface\\newui_item_back02-L.tga", IMAGE_NPCSHOP_LEFT, GL_LINEAR);
267
LoadBitmap("Interface\\newui_item_back02-R.tga", IMAGE_NPCSHOP_RIGHT, GL_LINEAR);
268
LoadBitmap("Interface\\newui_item_back03.tga", IMAGE_NPCSHOP_BOTTOM, GL_LINEAR);
269
270
LoadBitmap("Interface\\newui_item_add_marking_non.jpg", IMAGE_EXTENSION_EMPTY, GL_LINEAR);
271
LoadBitmap("Interface\\newui_item_add_table.tga", IMAGE_EXTENSION_TABLE, GL_LINEAR);
272
LoadBitmap("Interface\\newui_item_add_marking_no01.tga", IMAGE_EXTENSION_NO1, GL_LINEAR);
273
LoadBitmap("Interface\\newui_item_add_marking_no02.tga", IMAGE_EXTENSION_NO2, GL_LINEAR);
274
LoadBitmap("Interface\\newui_item_add_marking_no03.tga", IMAGE_EXTENSION_NO3, GL_LINEAR);
275
LoadBitmap("Interface\\newui_item_add_marking_no04.tga", IMAGE_EXTENSION_NO4, GL_LINEAR);
276
}
277
278
void CNewUIInventoryExtension::UnloadImages()
279
{
280
DeleteBitmap(IMAGE_NPCSHOP_BACK);
281
DeleteBitmap(IMAGE_NPCSHOP_TOP);
282
DeleteBitmap(IMAGE_NPCSHOP_LEFT);
283
DeleteBitmap(IMAGE_NPCSHOP_LEFT);
284
DeleteBitmap(IMAGE_NPCSHOP_BOTTOM);
285
286
DeleteBitmap(IMAGE_EXTENSION_EMPTY);
287
DeleteBitmap(IMAGE_EXTENSION_TABLE);
288
DeleteBitmap(IMAGE_EXTENSION_NO1);
289
DeleteBitmap(IMAGE_EXTENSION_NO2);
290
DeleteBitmap(IMAGE_EXTENSION_NO3);
291
DeleteBitmap(IMAGE_EXTENSION_NO4);
292
}
293
294
CNewUIInventoryCtrl* CNewUIInventoryExtension::TryGetExtensionByInventoryIndex(int iIndex) const
295
{
296
const auto index = iIndex - MAX_MY_INVENTORY_INDEX;
297
const auto extensionIndex = index / MAX_INVENTORY_EXT_ONE;
298
if (extensionIndex >= 0 && extensionIndex < MAX_INVENTORY_EXT_COUNT)
299
{
300
301
return m_extensions[extensionIndex];
302
}
303
304
return nullptr;
305
}
306
307
308
CNewUIInventoryCtrl* SEASON3B::CNewUIInventoryExtension::GetInventoryCtrl(int i) const
309
{
310
if (i < 0 || i >= MAX_INVENTORY_EXT_COUNT)
311
return nullptr;
312
313
return m_extensions[i];
314
}
315
316
ITEM* CNewUIInventoryExtension::FindItem(int iIndex) const
317
318
{
319
320
if (const auto& extension = TryGetExtensionByInventoryIndex(iIndex))
321
322
323
{
324
325
return extension->FindItem(iIndex);
326
327
328
}
329
return nullptr;
330
331
}
332
333
334
bool CNewUIInventoryExtension::InsertItem(int iIndex, BYTE* pbyItemPacket) const
335
{
336
if (const auto& extension = TryGetExtensionByInventoryIndex(iIndex))
337
{
338
extension->AddItem(iIndex, pbyItemPacket);
339
}
340
341
return false;
342
}
343
344
345
void CNewUIInventoryExtension::DeleteItem(int iIndex) const
346
{
347
if (const auto& extension = TryGetExtensionByInventoryIndex(iIndex))
348
{
349
if (const auto& pItem = extension->FindItem(iIndex))
350
{
351
extension->RemoveItem(pItem);
352
return;
353
}
354
355
if (const auto pPickedItem = CNewUIInventoryCtrl::GetPickedItem())
356
{
357
if (GetOwnerOf(pPickedItem)
358
&& pPickedItem->GetSourceLinealPos() == iIndex)
359
{
360
CNewUIInventoryCtrl::DeletePickedItem();
361
}
362
}
363
}
364
}
365
366
void CNewUIInventoryExtension::DeleteAllItems() const
367
{
368
for (auto* extension : m_extensions)
369
{
370
if (extension)
371
{
372
extension->RemoveAllItems();
373
}
374
}
375
}
376
377
CNewUIInventoryCtrl* CNewUIInventoryExtension::GetOwnerOf(const CNewUIPickedItem* pPickedItem) const
378
{
379
if (!pPickedItem)
380
{
381
return nullptr;
382
}
383
384
const auto* ownerOfItem = pPickedItem->GetOwnerInventory();
385
386
for (auto* extension : m_extensions)
387
{
388
if (extension == ownerOfItem)
389
{
390
return extension;
391
}
392
}
393
394
return nullptr;
395
}