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