Mercurial > mm7
annotate Mouse.cpp @ 2415:f4af3b203f65
LOD.cpp cleaned and search memory corrupt
author | Ritor1 |
---|---|
date | Sun, 20 Jul 2014 22:38:31 +0600 |
parents | 8cee51ce4382 |
children | 0313c761d203 |
rev | line source |
---|---|
2415 | 1 #define _CRTDBG_MAP_ALLOC |
2 #include <stdlib.h> | |
3 #include <crtdbg.h> | |
4 | |
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
2242
diff
changeset
|
5 #define _CRT_SECURE_NO_WARNINGS |
2336 | 6 #include "mm7_unsorted_subs.h" |
1262 | 7 #include "Texture.h" |
8 #include "mm7_data.h" | |
1253 | 9 #include "Render.h" |
0 | 10 #include "Mouse.h" |
11 #include "Items.h" | |
12 #include "Party.h" | |
13 #include "LOD.h" | |
14 #include "Game.h" | |
15 | |
1296 | 16 #include "TurnEngine.h" |
17 #include "Viewport.h" | |
18 #include "GUIWindow.h" | |
19 #include "Vis.h" | |
20 #include "Actor.h" | |
21 #include "MM7.h" | |
1297 | 22 #include "AudioPlayer.h" |
0 | 23 |
24 | |
25 Mouse *pMouse; | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 //----- (00469860) -------------------------------------------------------- | |
32 void Mouse::GetClickPos(unsigned int *pX, unsigned int *pY) | |
33 { | |
2223 | 34 *pX = uMouseClickX; |
35 *pY = uMouseClickY; | |
0 | 36 } |
37 | |
38 //----- (004698A6) -------------------------------------------------------- | |
39 void Mouse::RemoveHoldingItem() | |
40 { | |
41 pParty->pPickedItem.Reset(); | |
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
42 if (_stricmp(pCurrentCursorName, "MICON2")) |
0 | 43 SetCursorBitmap("MICON1"); |
44 } | |
45 | |
46 //----- (004698D8) -------------------------------------------------------- | |
47 void Mouse::SetCursorBitmapFromItemID(unsigned int uItemID) | |
48 { | |
49 pMouse->SetCursorBitmap(pItemsTable->pItems[uItemID].pIconName); | |
50 } | |
51 | |
52 //----- (004698F6) -------------------------------------------------------- | |
53 void Mouse::SetCurrentCursorBitmap() | |
54 { | |
55 SetCursorBitmap(pCurrentCursorName); | |
56 } | |
57 | |
58 //----- (00469903) -------------------------------------------------------- | |
59 void Mouse::SetCursorBitmap(const char *pName) | |
60 { | |
2334 | 61 // DDSURFACEDESC2 Dst; |
2219 | 62 |
0 | 63 if ( !this->bInitialized || !pName ) |
64 return; | |
2217 | 65 if ( _stricmp("MICON2", pName) )//если кусор не мишень |
2219 | 66 pGame->uFlags2 &= 0xFFFFFFEF; |
0 | 67 else |
2216 | 68 pGame->uFlags2 |= 0x10; |
1429
c7489dd19f88
BuildingType_Tavern and CastSpellInfo_PushCastSpellInfo fix
Ritor1
parents:
1391
diff
changeset
|
69 if ( _stricmp(this->pCurrentCursorName, pName) ) |
c7489dd19f88
BuildingType_Tavern and CastSpellInfo_PushCastSpellInfo fix
Ritor1
parents:
1391
diff
changeset
|
70 strcpy(this->pCurrentCursorName, pName); |
0 | 71 ClearCursor(); |
2219 | 72 if ( _strnicmp(pName, "MICON1", 5) )//for click to item / если курсор с вещью |
0 | 73 { |
1429
c7489dd19f88
BuildingType_Tavern and CastSpellInfo_PushCastSpellInfo fix
Ritor1
parents:
1391
diff
changeset
|
74 this->uCursorTextureID = pIcons_LOD->LoadTexture(pName, TEXTURE_16BIT_PALETTE); |
c7489dd19f88
BuildingType_Tavern and CastSpellInfo_PushCastSpellInfo fix
Ritor1
parents:
1391
diff
changeset
|
75 this->uCursorTextureID_2 = pIcons_LOD->LoadTexture(pName, TEXTURE_16BIT_PALETTE); |
c7489dd19f88
BuildingType_Tavern and CastSpellInfo_PushCastSpellInfo fix
Ritor1
parents:
1391
diff
changeset
|
76 this->AllocCursorSystemMem(); |
c7489dd19f88
BuildingType_Tavern and CastSpellInfo_PushCastSpellInfo fix
Ritor1
parents:
1391
diff
changeset
|
77 this->field_C = 0; |
2219 | 78 this->bRedraw = true; |
79 this->bActive = true; | |
0 | 80 if ( !areWeLoadingTexture ) |
81 { | |
82 if (uCursorTextureID != -1) | |
83 pIcons_LOD->pTextures[uCursorTextureID].Release(); | |
1006 | 84 pIcons_LOD->SyncLoadedFilesCount(); |
0 | 85 } |
86 return; | |
87 } | |
1802 | 88 this->bActive = false; |
1429
c7489dd19f88
BuildingType_Tavern and CastSpellInfo_PushCastSpellInfo fix
Ritor1
parents:
1391
diff
changeset
|
89 this->field_C = 1; |
1802 | 90 window->SetCursor(pName); |
0 | 91 } |
92 // 506128: using guessed type int areWeLoadingTexture; | |
93 | |
94 //----- (00469AE4) -------------------------------------------------------- | |
95 LONG Mouse::_469AE4() | |
96 { | |
97 LONG v2; // ecx@2 | |
98 LONG result; // eax@2 | |
99 struct tagPOINT Point; // [sp+Ch] [bp-8h]@2 | |
100 | |
101 this->field_8 = 1; | |
1038 | 102 /*if (pAsyncMouse) |
0 | 103 { |
104 v2 = *((int *)pAsyncMouse + 6); | |
105 Point.x = *((int *)pAsyncMouse + 6); | |
106 result = *((int *)pAsyncMouse + 7); | |
107 } | |
108 else | |
1038 | 109 {*/ |
0 | 110 GetCursorPos(&Point); |
2153 | 111 //if ( pRenderer->bWindowMode ) |
1802 | 112 ScreenToClient(window->GetApiHandle(), &Point); |
0 | 113 result = Point.y; |
114 v2 = Point.x; | |
1038 | 115 //} |
2216 | 116 this->uMouseClickX = v2; |
117 this->uMouseClickY = result; | |
2155 | 118 if ( true/*pRenderer->bWindowMode*/) |
0 | 119 goto LABEL_16; |
1038 | 120 //if (pAsyncMouse) |
121 // goto LABEL_24; | |
0 | 122 if ( v2 < 0 ) |
123 v2 = 0; | |
124 if ( result < 0 ) | |
125 result = 0; | |
2216 | 126 if ( v2 > window->GetWidth() - 1 ) |
127 v2 = window->GetWidth() - 1; | |
128 if ( result > window->GetHeight() - 1 ) | |
0 | 129 { |
2216 | 130 result = window->GetHeight() - 1; |
0 | 131 LABEL_16: |
1038 | 132 //if (pAsyncMouse) |
133 // goto LABEL_24; | |
2216 | 134 if (true/*pRenderer->bWindowMode*/ && (v2 < 0 || result < 0 || v2 > window->GetWidth() -1 || result > window->GetHeight() - 1) ) |
0 | 135 goto LABEL_23; |
136 } | |
2216 | 137 if ( this->field_C ) |
0 | 138 LABEL_23: |
2219 | 139 this->bActive = false; |
2334 | 140 //LABEL_24: |
2216 | 141 this->field_8 = 0; |
0 | 142 return result; |
143 } | |
144 | |
145 //----- (00469BA3) -------------------------------------------------------- | |
146 void Mouse::ClearCursor() | |
147 { | |
2219 | 148 this->bActive = false; |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2339
diff
changeset
|
149 free(this->pCursorBitmap_sysmem); |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2339
diff
changeset
|
150 this->pCursorBitmap_sysmem = nullptr; |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2339
diff
changeset
|
151 free(this->pCursorBitmap2_sysmem); |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2339
diff
changeset
|
152 this->pCursorBitmap2_sysmem = nullptr; |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2339
diff
changeset
|
153 free(this->ptr_90); |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2339
diff
changeset
|
154 this->ptr_90 = nullptr; |
0 | 155 } |
156 | |
157 //----- (00469BE6) -------------------------------------------------------- | |
158 void Mouse::AllocCursorSystemMem() | |
159 { | |
2219 | 160 bActive = false; |
0 | 161 if (!pCursorBitmap_sysmem) |
162 pCursorBitmap_sysmem = (unsigned __int16 *)DoAllocCursorMem(); | |
163 if (!pCursorBitmap2_sysmem) | |
164 pCursorBitmap2_sysmem = (unsigned __int8 *)DoAllocCursorMem(); | |
165 } | |
166 | |
167 //----- (00469C0D) -------------------------------------------------------- | |
168 void *Mouse::DoAllocCursorMem() | |
169 { | |
1980 | 170 Texture* tex = pIcons_LOD->GetTexture(uCursorTextureID); |
973 | 171 return malloc(4 * tex->uTextureWidth * tex->uTextureHeight); |
0 | 172 } |
173 | |
174 //----- (00469C39) -------------------------------------------------------- | |
175 POINT *Mouse::GetCursorPos(POINT *a2) | |
176 { | |
1038 | 177 a2->x = this->uMouseClickX; |
178 a2->y = this->uMouseClickY; | |
179 return a2; | |
0 | 180 } |
181 | |
182 //----- (00469C65) -------------------------------------------------------- | |
1802 | 183 void Mouse::Initialize(OSWindow *window) |
0 | 184 { |
1802 | 185 this->window = window; |
186 this->bActive = false; | |
187 this->bInitialized = true; | |
2216 | 188 |
189 //this->field_8 = 0;//Ritor1: result incorrect uMouseClickX, this->uMouseClickY in _469AE4() | |
190 this->uCursorBitmapPitch = 0;//Ritor1: it's include | |
191 for ( uint i = 0; i < 13; i++ ) | |
192 this->field_5C[i] = 0; | |
193 | |
0 | 194 this->pCursorBitmapPos.x = 0; |
195 this->pCursorBitmapPos.y = 0; | |
196 this->uMouseClickX = 0; | |
197 this->uMouseClickY = 0; | |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2339
diff
changeset
|
198 this->pCursorBitmap_sysmem = nullptr; |
0 | 199 this->field_34 = 0; |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2339
diff
changeset
|
200 this->pCursorBitmap2_sysmem = nullptr; |
0 | 201 |
202 SetCursorBitmap("MICON3"); | |
203 SetCursorBitmap("MICON2"); | |
204 SetCursorBitmap("MICON1"); | |
205 } | |
206 | |
762 | 207 // inlined |
208 //----- (0045FE00) mm6 chinese -------------------------------------------- | |
209 void Mouse::SetActive(bool active) | |
210 { | |
211 bActive = active; | |
212 } | |
213 | |
0 | 214 //----- (00469CC2) -------------------------------------------------------- |
215 void Mouse::Deactivate() | |
216 { | |
217 if (bInitialized) | |
762 | 218 SetActive(false); |
0 | 219 } |
220 | |
221 //----- (00469CCD) -------------------------------------------------------- | |
222 void Mouse::DrawCursor() | |
223 { | |
224 unsigned int v9; // eax@31 | |
225 | |
226 if ( this->bInitialized ) | |
227 { | |
228 if ( !this->field_8 && this->bActive && !this->field_C ) | |
2216 | 229 pMouse->_469AE4();//Ritor1: странная, непонятная функция |
2093 | 230 this->field_F4 = 1; |
231 if ( this->field_C ) | |
232 { | |
233 this->field_F4 = 0; | |
234 return; | |
235 } | |
2155 | 236 |
237 //if ( pRenderer->bWindowMode ) | |
0 | 238 { |
2215
e9625ad08541
fog fix and change 640,480 - window->GetWidth(), window->GetHeight()
Ritor1
parents:
2155
diff
changeset
|
239 if ( this->uMouseClickX < 0 || this->uMouseClickY < 0 || this->uMouseClickX > window->GetWidth() - 1 || this->uMouseClickY > window->GetHeight() - 1 ) |
0 | 240 { |
2093 | 241 this->field_F4 = 0; |
0 | 242 return; |
243 } | |
244 } | |
2155 | 245 /*else |
0 | 246 { |
2093 | 247 if ( this->uMouseClickX < 0 ) |
248 this->uMouseClickX = 0; | |
249 if ( this->uMouseClickY < 0 ) | |
250 this->uMouseClickY = 0; | |
251 if ( this->uMouseClickX > 639 ) | |
252 this->uMouseClickX = 639; | |
253 if ( this->uMouseClickY > 479 ) | |
254 this->uMouseClickY = 479; | |
2155 | 255 }*/ |
2093 | 256 this->pCursorBitmapRect.x = this->uMouseClickX; |
2216 | 257 this->pCursorBitmapRect.w = this->uMouseClickY + this->field_5C[0]; //Ritor1: Maybe this->field_5C[0] - cursor width |
2093 | 258 this->pCursorBitmapRect.y = this->uMouseClickY; |
2216 | 259 this->pCursorBitmapRect.z = this->uMouseClickX + this->uCursorBitmapPitch; //Ritor1: Maybe this->uCursorBitmapPitch - cursor height |
2093 | 260 if ( this->uMouseClickX < 0 ) |
261 this->pCursorBitmapRect.x = 0; | |
262 if ( this->uMouseClickY < 0 ) | |
263 this->pCursorBitmapRect.y = 0; | |
2215
e9625ad08541
fog fix and change 640,480 - window->GetWidth(), window->GetHeight()
Ritor1
parents:
2155
diff
changeset
|
264 if ( this->pCursorBitmapRect.z > window->GetWidth() ) |
e9625ad08541
fog fix and change 640,480 - window->GetWidth(), window->GetHeight()
Ritor1
parents:
2155
diff
changeset
|
265 this->pCursorBitmapRect.z = window->GetWidth(); |
e9625ad08541
fog fix and change 640,480 - window->GetWidth(), window->GetHeight()
Ritor1
parents:
2155
diff
changeset
|
266 if ( this->pCursorBitmapRect.w > window->GetHeight() ) |
e9625ad08541
fog fix and change 640,480 - window->GetWidth(), window->GetHeight()
Ritor1
parents:
2155
diff
changeset
|
267 this->pCursorBitmapRect.w = window->GetHeight(); |
2219 | 268 this->bActive = false; |
2093 | 269 this->uCursorBitmapWidth = this->pCursorBitmapRect.z - this->pCursorBitmapRect.x; |
270 this->uCursorBitmapHeight = this->pCursorBitmapRect.w - this->pCursorBitmapRect.y; | |
271 if ( this->bRedraw ) | |
0 | 272 { |
273 if ( pMouse->ptr_90 ) | |
274 v9 = 2 * pMouse->uCursorBitmapPitch; | |
275 else | |
276 v9 = 0; | |
2093 | 277 pRenderer->_4A6DF5( this->pCursorBitmap_sysmem, v9, &this->pCursorBitmapPos, pRenderer->pTargetSurface, pRenderer->uTargetSurfacePitch, |
278 &this->pCursorBitmapRect);//срабатывает когда берём курсором вещь в инвенторе | |
279 this->bRedraw = false; | |
0 | 280 } |
281 } | |
282 } | |
283 | |
284 //----- (00469E1C) -------------------------------------------------------- | |
2216 | 285 void Mouse::Activate() |
0 | 286 { |
287 bActive = true; | |
288 } | |
289 | |
290 //----- (00469E24) -------------------------------------------------------- | |
291 void Mouse::_469E24() | |
292 { | |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2339
diff
changeset
|
293 free(pCursorBitmap3_sysmembits_16bit); |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2339
diff
changeset
|
294 pCursorBitmap3_sysmembits_16bit = nullptr; |
0 | 295 } |
296 | |
297 //----- (00469E3B) -------------------------------------------------------- | |
2223 | 298 void Mouse::DrawCursorToTarget()//??? DrawCursorWithItem |
0 | 299 { |
300 if (!pCursorBitmap3_sysmembits_16bit) | |
301 return; | |
2219 | 302 //пишем на экран курсор с вещью |
1980 | 303 ushort* pSrc = pCursorBitmap3_sysmembits_16bit; |
2335 | 304 for (int y = uCursorWithItemY; y < uCursorWithItemZ; ++y) |
305 for (int x = uCursorWithItemX; x < uCursorWithItemW; ++x) | |
2069 | 306 //pRenderer->pTargetSurface[y * pRenderer->uTargetSurfacePitch + x] = *pSrc++; |
307 pRenderer->WritePixel16(x, y, *pSrc++); | |
0 | 308 } |
309 | |
310 //----- (00469EA4) -------------------------------------------------------- | |
2216 | 311 void Mouse::ReadCursorWithItem() |
0 | 312 { |
920 | 313 unsigned int pTextureID; // eax@2 |
314 Texture *pTexture; // edi@2 | |
2334 | 315 // int v8; // ecx@25 |
316 // int v9; // ebx@26 | |
317 // unsigned int v10; // eax@26 | |
318 // int v11; // edx@27 | |
2216 | 319 int pTextureHeight; // [sp+20h] [bp-8h]@15 |
2334 | 320 // unsigned __int16 *v20; // [sp+20h] [bp-8h]@28 |
920 | 321 int pTextureWidth; // [sp+24h] [bp-4h]@12 |
0 | 322 unsigned __int16 *v22; // [sp+24h] [bp-4h]@25 |
323 | |
324 if ( pParty->pPickedItem.uItemID ) | |
325 { | |
1709
8251e59fd7c1
ITEM_ENCHANTED to ITEM_HARDENED, created helper functions to get params from itemtable for ItemGens
Grumpy7
parents:
1687
diff
changeset
|
326 pTextureID = pIcons_LOD->LoadTexture(pParty->pPickedItem.GetIconName(), TEXTURE_16BIT_PALETTE); |
920 | 327 pTexture = (Texture *)(pTextureID != -1 ? (int)&pIcons_LOD->pTextures[pTextureID] : 0); |
1038 | 328 |
2216 | 329 if ( (signed int)pMouse->uMouseClickX <= window->GetWidth() - 1 && (signed int)pMouse->uMouseClickY <= window->GetHeight() - 1 ) |
0 | 330 { |
2216 | 331 /*if ( (v4 & 0x80000000u) != 0 ) |
0 | 332 a2 = 0; |
333 if ( (v5 & 0x80000000u) != 0 ) | |
334 { | |
2216 | 335 //v6 = 0; |
0 | 336 v15 = 0; |
2216 | 337 } */ |
338 if ( (signed int)(pTexture->uTextureWidth + pMouse->uMouseClickX) <= window->GetWidth() ) | |
920 | 339 pTextureWidth = pTexture->uTextureWidth; |
0 | 340 else |
2216 | 341 pTextureWidth = window->GetWidth() - pMouse->uMouseClickX; |
342 if ( (signed int)(pTexture->uTextureHeight + pMouse->uMouseClickY) <= window->GetHeight() ) | |
343 pTextureHeight = pTexture->uTextureHeight; | |
0 | 344 else |
2216 | 345 pTextureHeight = window->GetHeight() - pMouse->uMouseClickY; |
920 | 346 if ( !this->pCursorBitmap3_sysmembits_16bit |
2216 | 347 || pMouse->uMouseClickX != this->uCursorWithItemX |
348 || pMouse->uMouseClickY != this->uCursorWithItemY | |
349 || pMouse->uMouseClickX + pTextureWidth != this->uCursorWithItemW | |
350 || pMouse->uMouseClickY + pTextureHeight != this->uCursorWithItemZ ) | |
0 | 351 { |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2339
diff
changeset
|
352 free(this->pCursorBitmap3_sysmembits_16bit); |
1631 | 353 this->pCursorBitmap3_sysmembits_16bit = (unsigned __int16 *)malloc(2 * pTexture->uTextureHeight * pTexture->uTextureWidth); |
2216 | 354 this->uCursorWithItemX = pMouse->uMouseClickX; |
355 this->uCursorWithItemW = pMouse->uMouseClickX + pTextureWidth; | |
356 this->uCursorWithItemY = pMouse->uMouseClickY; | |
357 this->uCursorWithItemZ = pMouse->uMouseClickY + pTextureHeight; | |
0 | 358 } |
920 | 359 v22 = this->pCursorBitmap3_sysmembits_16bit; |
2216 | 360 |
361 for (int y = this->uCursorWithItemY; y < this->uCursorWithItemZ; ++y) | |
2069 | 362 { |
2216 | 363 for (int x = this->uCursorWithItemX; x < this->uCursorWithItemW; ++x) |
2069 | 364 { |
2216 | 365 *v22++ = pRenderer->ReadPixel16(x, y); |
2069 | 366 } |
367 } | |
368 /*if ( v8 < this->field_4C ) | |
0 | 369 { |
920 | 370 v9 = this->field_48; |
0 | 371 v10 = pRenderer->uTargetSurfacePitch * v8; |
372 do | |
373 { | |
920 | 374 v11 = this->field_40; |
375 v18 = this->field_40; | |
0 | 376 if ( v11 < v9 ) |
377 { | |
378 v20 = &v17[v10 + v11]; | |
379 do | |
380 { | |
2069 | 381 //v12 = v20; |
0 | 382 ++v18; |
2069 | 383 //++v20; |
384 *v22++ = *v20++; | |
0 | 385 } |
386 while ( v18 < v9 ); | |
387 } | |
388 v10 += v16; | |
389 ++v8; | |
390 } | |
920 | 391 while ( v8 < this->field_4C ); |
0 | 392 v6 = v15; |
2069 | 393 }*/ |
394 | |
1567
9f8b3e904e14
Player::ReceiveDamage, very small edits; prepended "Is" to item functions returning bool values (broken, indetified, stolen)
Grumpy7
parents:
1458
diff
changeset
|
395 if (pParty->pPickedItem.IsBroken()) |
2216 | 396 pRenderer->DrawTransparentRedShade(pMouse->uMouseClickX, pMouse->uMouseClickY, pTexture); |
1567
9f8b3e904e14
Player::ReceiveDamage, very small edits; prepended "Is" to item functions returning bool values (broken, indetified, stolen)
Grumpy7
parents:
1458
diff
changeset
|
397 else if (!pParty->pPickedItem.IsIdentified()) |
2216 | 398 pRenderer->DrawTransparentGreenShade(pMouse->uMouseClickX, pMouse->uMouseClickY, pTexture); |
0 | 399 else |
2216 | 400 pRenderer->DrawTextureTransparent(pMouse->uMouseClickX, pMouse->uMouseClickY, pTexture); |
0 | 401 } |
402 } | |
403 else | |
404 { | |
2369
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2339
diff
changeset
|
405 free(this->pCursorBitmap3_sysmembits_16bit); |
bddcaf5d5db2
removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
Grumpy7
parents:
2339
diff
changeset
|
406 this->pCursorBitmap3_sysmembits_16bit = nullptr; |
0 | 407 } |
408 } | |
409 | |
410 //----- (0046A080) -------------------------------------------------------- | |
2216 | 411 void Mouse::ChangeActivation(int a1) |
0 | 412 { |
2216 | 413 this->bActive = a1; |
0 | 414 } |
415 | |
416 //----- (0046A08A) -------------------------------------------------------- | |
417 void Mouse::SetMouseClick(int x, int y) | |
418 { | |
419 uMouseClickX = x; | |
420 uMouseClickY = y; | |
421 } | |
1296 | 422 //----- (004175C0) -------------------------------------------------------- |
2339 | 423 void Mouse::UI_OnMouseLeftClick(int *pXY) |
1296 | 424 { |
425 signed int y; // eax@7 | |
426 signed int x; // ecx@7 | |
427 signed int v5; // eax@17 | |
2098 | 428 GUIButton *control; // esi@37 |
1296 | 429 signed int v10; // eax@50 |
2334 | 430 // int v11; // ecx@52 |
1296 | 431 unsigned int pX; // [sp+14h] [bp-8h]@7 |
432 unsigned int pY; // [sp+18h] [bp-4h]@7 | |
0 | 433 |
2098 | 434 if ( pCurrentScreen == SCREEN_VIDEO || sub_4637E0_is_there_popup_onscreen() ) |
1296 | 435 return; |
436 if ( pGUIWindow2 && pGUIWindow2->ptr_1C == (void *)33 ) | |
437 { | |
438 sub_4452BB(); | |
439 return; | |
440 } | |
2098 | 441 if ( pXY ) |
1296 | 442 { |
2098 | 443 x = *pXY; |
444 y = pXY[1]; | |
445 pX = *pXY; | |
1296 | 446 pY = y; |
447 } | |
448 else | |
449 { | |
450 pMouse->GetClickPos(&pX, &pY); | |
451 y = pY; | |
452 x = pX; | |
453 } | |
1830 | 454 |
455 extern bool _507B98_ctrl_pressed; | |
1296 | 456 x = pX; |
2098 | 457 if ( GetCurrentMenuID() != -1 || pCurrentScreen != SCREEN_GAME || !_507B98_ctrl_pressed // stealing cursor |
458 || (signed int)pX < (signed int)pViewport->uViewportTL_X || (signed int)pX > (signed int)pViewport->uViewportBR_X | |
459 || (signed int)pY < (signed int)pViewport->uViewportTL_Y || (signed int)pY > (signed int)pViewport->uViewportBR_Y) | |
1296 | 460 { |
461 y = pY; | |
2098 | 462 for ( int i = uNumVisibleWindows; i >= 0; --i ) |
1296 | 463 { |
2098 | 464 if ( x >= (signed int)pWindowList[pVisibleWindowsIdxs[i] - 1].uFrameX && x <= (signed int)pWindowList[pVisibleWindowsIdxs[i] - 1].uFrameZ |
465 && y >= (signed int)pWindowList[pVisibleWindowsIdxs[i] - 1].uFrameY && y <= (signed int)pWindowList[pVisibleWindowsIdxs[i] - 1].uFrameW ) | |
466 { | |
467 for ( control = pWindowList[pVisibleWindowsIdxs[i] - 1].pControlsHead; control; control = control->pNext ) | |
468 { | |
469 if ( control->uButtonType == 1 ) | |
470 { | |
471 if ( x >= (signed int)control->uX && x <= (signed int)control->uZ && y >= (signed int)control->uY && y <= (signed int)control->uW ) | |
472 { | |
473 control->field_2C_is_pushed = 1; | |
474 v10 = pMessageQueue_50CBD0->uNumMessages; | |
475 if ( pMessageQueue_50CBD0->uNumMessages ) | |
476 { | |
477 v10 = pMessageQueue_50CBD0->pMessages[0].field_8 != 0; | |
478 pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0; | |
479 } | |
2402 | 480 pMessageQueue_50CBD0->AddGUIMessage(control->msg, control->msg_param, 0); |
2098 | 481 return; |
482 } | |
483 continue; | |
484 } | |
485 if ( control->uButtonType == 2 )//когда нажимаешь на партреты персов | |
486 { | |
487 if ( (signed int)(signed __int64)sqrt((double)((x - control->uX) * (x - control->uX) + (y - control->uY) * (y - control->uY))) < (signed int)control->uWidth ) | |
488 { | |
489 control->field_2C_is_pushed = 1; | |
490 v10 = pMessageQueue_50CBD0->uNumMessages; | |
491 if ( pMessageQueue_50CBD0->uNumMessages ) | |
492 { | |
493 v10 = pMessageQueue_50CBD0->pMessages[0].field_8 != 0; | |
494 pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0; | |
495 } | |
2402 | 496 pMessageQueue_50CBD0->AddGUIMessage(control->msg, control->msg_param, 0); |
2098 | 497 return; |
498 } | |
499 continue; | |
500 } | |
501 if ( control->uButtonType == 3 )//когда нажимаешь на скиллы | |
502 { | |
503 if ( x >= (signed int)control->uX && x <= (signed int)control->uZ && y >= (signed int)control->uY && y <= (signed int)control->uW ) | |
504 { | |
505 control->field_2C_is_pushed = 1; | |
506 v10 = pMessageQueue_50CBD0->uNumMessages; | |
507 if ( pMessageQueue_50CBD0->uNumMessages ) | |
508 { | |
509 v10 = pMessageQueue_50CBD0->pMessages[0].field_8 != 0; | |
510 pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0; | |
511 } | |
2402 | 512 pMessageQueue_50CBD0->AddGUIMessage(control->msg, control->msg_param, 0); |
2098 | 513 return; |
514 } | |
515 continue; | |
516 } | |
517 y = pY; | |
518 x = pX; | |
519 } | |
520 } | |
1296 | 521 } |
2098 | 522 return; |
1296 | 523 } |
524 y = pY; | |
2154 | 525 //if ( pRenderer->pRenderD3D ) |
1296 | 526 v5 = pGame->pVisInstance->get_picked_object_zbuf_val(); |
2154 | 527 /*else |
528 v5 = pRenderer->pActiveZBuffer[pX + pSRZBufferLineOffsets[pY]];*/ | |
1830 | 529 |
2098 | 530 uint type = PID_TYPE((unsigned __int16)v5); |
531 if (type == OBJECT_Actor && uActiveCharacter && v5 < 0x2000000 | |
532 && pPlayers[uActiveCharacter]->CanAct() && pPlayers[uActiveCharacter]->CanSteal() ) | |
1296 | 533 { |
534 /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 ) | |
535 { | |
536 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_1B; | |
537 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v6 >> 3; | |
538 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0; | |
539 ++pMessageQueue_50CBD0->uNumMessages; | |
540 }*/ | |
2402 | 541 pMessageQueue_50CBD0->AddGUIMessage(UIMSG_STEALFROMACTOR, PID_ID((unsigned __int16)v5), 0); |
1296 | 542 |
543 if ( pParty->bTurnBasedModeOn == 1 ) | |
544 { | |
2242 | 545 if ( pTurnEngine->turn_stage == TE_MOVEMENT ) |
1332 | 546 pTurnEngine->field_18 |= TE_FLAG_8; |
1296 | 547 } |
548 } | |
549 } | |
550 | |
551 | |
1297 | 552 //----- (0041CD4F) -------------------------------------------------------- |
2339 | 553 bool Mouse::UI_OnKeyDown(unsigned int vkKey) |
1297 | 554 { |
555 //unsigned int v1; // edi@1 | |
556 //unsigned int v2; // eax@2 | |
557 int v3; // esi@3 | |
558 int v4; // ecx@10 | |
559 GUIButton *pButton; // eax@11 | |
560 int v6; // edx@12 | |
561 int v7; // ecx@20 | |
562 char v8; // zf@21 | |
563 //GUIButton *v9; // ecx@24 | |
564 int v10; // esi@24 | |
565 //int v11; // edx@26 | |
566 int v12; // edx@28 | |
567 int v13; // esi@32 | |
568 //GUIButton *v14; // eax@37 | |
569 int v15; // edx@38 | |
570 int v17; // ecx@50 | |
571 int v18; // edx@50 | |
572 //GUIButton *v19; // ecx@54 | |
573 int v20; // esi@54 | |
574 //int v21; // edx@56 | |
575 int v22; // ecx@59 | |
576 int v23; // edx@59 | |
577 int v24; // ecx@60 | |
578 int v25; // esi@63 | |
579 //unsigned int v26; // [sp+Ch] [bp-14h]@1 | |
580 //int v27; // [sp+10h] [bp-10h]@1 | |
581 int v28; // [sp+14h] [bp-Ch]@10 | |
582 int v29; // [sp+14h] [bp-Ch]@36 | |
583 unsigned int uClickX; // [sp+18h] [bp-8h]@10 | |
584 unsigned int uClickY; // [sp+1Ch] [bp-4h]@10 | |
585 | |
586 //v1 = 0; | |
587 //v27 = uNumVisibleWindows; | |
588 if ( uNumVisibleWindows < 0 ) | |
589 return false; | |
590 //v2 = pMessageQueue_50CBD0->uNumMessages; | |
591 for (int i = uNumVisibleWindows; i >= 0; --i) | |
592 //while ( 1 ) | |
593 { | |
594 v3 = pVisibleWindowsIdxs[i] - 1; | |
595 if (!pWindowList[v3].receives_keyboard_input) | |
596 continue; | |
597 | |
598 switch (vkKey) | |
599 { | |
600 case VK_LEFT: | |
601 { | |
602 v12 = pWindowList[v3].field_34; | |
603 if ( pWindowList[v3].pCurrentPosActiveItem - pWindowList[v3].pStartingPosActiveItem - v12 >= 0 ) | |
604 { | |
605 v8 = pCurrentScreen == SCREEN_PARTY_CREATION; | |
606 pWindowList[v3].pCurrentPosActiveItem -= v12; | |
607 if ( v8 ) | |
608 { | |
609 pAudioPlayer->PlaySound(SOUND_Button, 0, 0, -1, 0, 0, 0, 0); | |
610 //v2 = pMessageQueue_50CBD0->uNumMessages; | |
611 } | |
612 } | |
613 if ( pWindowList[v3].field_30 != 0 ) | |
614 { | |
615 break; | |
616 } | |
617 pButton = pWindowList[v3].pControlsHead; | |
618 v13 = pWindowList[v3].pCurrentPosActiveItem; | |
619 if ( v13 > 0) | |
620 { | |
621 do | |
622 { | |
623 pButton = pButton->pNext; | |
624 --v13; | |
625 } | |
626 while ( v13 ); | |
627 } | |
2402 | 628 pMessageQueue_50CBD0->AddGUIMessage(pButton->msg, pButton->msg_param, 0); |
1297 | 629 break; |
630 } | |
631 case VK_RIGHT: | |
632 { | |
633 v7 = pWindowList[v3].pCurrentPosActiveItem + pWindowList[v3].field_34; | |
634 if ( v7 < pWindowList[v3].pNumPresenceButton + pWindowList[v3].pStartingPosActiveItem ) | |
635 { | |
636 v8 = pCurrentScreen == SCREEN_PARTY_CREATION; | |
637 pWindowList[v3].pCurrentPosActiveItem = v7; | |
638 if ( v8 ) | |
639 { | |
640 pAudioPlayer->PlaySound(SOUND_Button, 0, 0, -1, 0, 0, 0, 0); | |
641 //v2 = pMessageQueue_50CBD0->uNumMessages; | |
642 } | |
643 } | |
644 if ( pWindowList[v3].field_30 != 0 ) | |
645 { | |
646 break; | |
647 } | |
648 pButton = pWindowList[v3].pControlsHead; | |
649 v10 = pWindowList[v3].pCurrentPosActiveItem; | |
650 if ( v10 > 0) | |
651 { | |
652 do | |
653 { | |
654 pButton = pButton->pNext; | |
655 --v10; | |
656 } | |
657 while ( v10 ); | |
658 } | |
2402 | 659 pMessageQueue_50CBD0->AddGUIMessage(pButton->msg, pButton->msg_param, 0); |
1297 | 660 break; |
661 } | |
662 case VK_DOWN: | |
663 { | |
664 v17 = pWindowList[v3].pStartingPosActiveItem; | |
665 v18 = pWindowList[v3].pCurrentPosActiveItem; | |
666 if ( v18 >= pWindowList[v3].pNumPresenceButton + v17 - 1 ) | |
667 pWindowList[v3].pCurrentPosActiveItem = v17; | |
668 else | |
669 pWindowList[v3].pCurrentPosActiveItem = v18 + 1; | |
670 if ( pWindowList[v3].field_30 != 0 ) | |
671 return true; | |
672 pButton = pWindowList[v3].pControlsHead; | |
673 v20 = pWindowList[v3].pCurrentPosActiveItem; | |
674 if ( v20 > 0) | |
675 { | |
676 do | |
677 { | |
678 pButton = pButton->pNext; | |
679 --v20; | |
680 } | |
681 while ( v20 ); | |
682 } | |
2402 | 683 pMessageQueue_50CBD0->AddGUIMessage(pButton->msg, pButton->msg_param, 0); |
1297 | 684 return true; |
685 } | |
686 case VK_SELECT: | |
687 { | |
688 pMouse->GetClickPos(&uClickX, &uClickY); | |
689 v4 = pWindowList[v3].pStartingPosActiveItem; | |
690 v28 = v4 + pWindowList[v3].pNumPresenceButton; | |
691 if ( v4 < v4 + pWindowList[v3].pNumPresenceButton ) | |
692 { | |
693 while ( 1 ) | |
694 { | |
695 pButton = pWindowList[v3].pControlsHead; | |
696 if ( v4 > 0 ) | |
697 { | |
698 v6 = v4; | |
699 do | |
700 { | |
701 pButton = pButton->pNext; | |
702 --v6; | |
703 } | |
704 while ( v6 ); | |
705 } | |
706 if ( (signed int)uClickX >= (signed int)pButton->uX//test for StatsTab in PlayerCreation Window | |
707 && (signed int)uClickX <= (signed int)pButton->uZ | |
708 && (signed int)uClickY >= (signed int)pButton->uY | |
709 && (signed int)uClickY <= (signed int)pButton->uW ) | |
710 break; | |
711 ++v4; | |
712 if ( v4 >= v28 ) | |
713 { | |
714 //v1 = 0; | |
715 //v2 = pMessageQueue_50CBD0->uNumMessages; | |
716 //--i; | |
717 //if ( i < 0 ) | |
718 return false; | |
719 //continue; | |
720 } | |
721 } | |
722 pWindowList[v3].pCurrentPosActiveItem = v4; | |
723 return true; | |
724 } | |
725 //v2 = pMessageQueue_50CBD0->uNumMessages; | |
726 break; | |
727 } | |
728 case VK_UP: | |
729 { | |
730 v22 = pWindowList[v3].pCurrentPosActiveItem; | |
731 v23 = pWindowList[v3].pStartingPosActiveItem; | |
732 if ( v22 <= v23 ) | |
733 v24 = pWindowList[v3].pNumPresenceButton + v23 - 1; | |
734 else | |
735 v24 = v22 - 1; | |
736 v8 = pWindowList[v3].field_30 == 0; | |
737 pWindowList[v3].pCurrentPosActiveItem = v24; | |
738 if ( !v8 ) | |
739 return true; | |
740 pButton = pWindowList[v3].pControlsHead; | |
741 v25 = pWindowList[v3].pCurrentPosActiveItem; | |
742 if ( v25 > 0) | |
743 { | |
744 do | |
745 { | |
746 pButton = pButton->pNext; | |
747 --v25; | |
748 } | |
749 while ( v25 ); | |
750 } | |
2402 | 751 pMessageQueue_50CBD0->AddGUIMessage(pButton->msg, pButton->msg_param, 0); |
1297 | 752 return true; |
753 } | |
754 case VK_NEXT: | |
755 { | |
2099 | 756 if ( pWindowList[v3].field_30 != 0 ) //crashed at skill draw |
757 { | |
758 pMouse->GetClickPos(&uClickX, &uClickY); | |
759 v29 = pWindowList[v3].pStartingPosActiveItem + pWindowList[v3].pNumPresenceButton; //num buttons more than buttons | |
760 for ( v4 = pWindowList[v3].pStartingPosActiveItem; v4 < v29; ++v4 ) | |
761 { | |
762 pButton = pWindowList[v3].pControlsHead; | |
763 if ( v4 > 0 ) | |
764 { | |
765 for ( v15 = v4; v15; --v15 ) | |
766 pButton = pButton->pNext; | |
767 } | |
768 if ( (signed int)uClickX >= (signed int)pButton->uX && (signed int)uClickX <= (signed int)pButton->uZ | |
769 && (signed int)uClickY >= (signed int)pButton->uY && (signed int)uClickY <= (signed int)pButton->uW ) | |
770 { | |
771 pWindowList[v3].pCurrentPosActiveItem = v4; | |
772 return true; | |
773 } | |
774 } | |
775 } | |
1297 | 776 break; |
777 } | |
778 default: | |
779 break; | |
780 } | |
781 } | |
2219 | 782 } |