forked from Bad-Scientists/AF-Script-Packet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.d
591 lines (467 loc) · 14.5 KB
/
view.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
/*
* Some useful functions for LeGo Views & engine zCView
*
* Naming convention updated to match LeGo logic
*
* ViewPtr* functions - working with view pointers
* View* functions - working with handles
*/
// AFSP 'internal' constants for view intflags
// - engine is only using const int VIEW_I_TEXT = 1 << 0; //1
// - we will add our own constants to allow automated & easier view formatting
const int VIEW_AUTO_RESIZE = 1 << 1; //2
const int VIEW_AUTO_ALPHA = 1 << 2; //4
const int VIEW_TXT_VCENTER = 1 << 3; //8
const int VIEW_TXT_HCENTER = 1 << 4; //16
/*
* ViewPtr_SetIntFlags
*/
func void ViewPtr_SetIntFlags (var int viewPtr, var int intflags) {
if (!viewPtr) { return; };
var zCView v; v = _^ (viewPtr);
v.intflags = v.intflags | intflags;
};
/*
* View_SetIntFlags
*/
func void View_SetIntFlags (var int hndl, var int intflags) {
if (!Hlp_IsValidHandle (hndl)) { return; };
var int viewPtr; viewPtr = getPtr (hndl);
ViewPtr_SetIntFlags (viewPtr, intflags);
};
/*
* ViewPtr_AutoResize
*/
func void ViewPtr_AutoResize (var int viewPtr) {
if (!viewPtr) { return; };
var zCView v; v = _^ (viewPtr);
var zCList l;
var zCViewText vt;
//Loop through text lines - figure out overall sizeX & sizeY
var int psizeX; psizeX = 0;
var int psizeY; psizeY = 0;
var int width;
var int list; list = v.textLines_next;
while (list);
l = _^ (list);
if (l.data) {
vt = _^ (l.data);
psizeY += zCFont_GetFontY (vt.font);
width = Font_GetStringWidthPtr(vt.text, vt.font);
if (width > psizeX) {
psizeX = width;
};
};
list = l.next;
end;
if ((psizeX > v.psizeX) || (psizeY > v.psizeY)) {
if (psizeX < v.psizeX) { psizeX = v.psizeX; };
if (psizeY < v.psizeY) { psizeY = v.psizeY; };
psizeX = Print_ToVirtual (psizeX, PS_X);
psizeY = Print_ToVirtual (psizeY, PS_Y);
ViewPtr_Resize (viewPtr, psizeX, psizeY);
};
};
/*
* View_AutoResize
*/
func void View_AutoResize (var int hndl) {
if (!Hlp_IsValidHandle (hndl)) { return; };
var int viewPtr; viewPtr = getPtr (hndl);
ViewPtr_AutoResize (viewPtr);
};
/*
* Centers text lines vertically in view
*/
func void ViewPtr_CenterTextLines (var int viewPtr) {
if (!viewPtr) { return; };
var zCView v; v = _^ (viewPtr);
var zCList l;
var zCViewText vt;
//Loop through text lines - figure out overall sizeY
var int psizeY; psizeY = v.pposY;
var int list; list = v.textLines_next;
while (list);
l = _^ (list);
if (l.data) {
vt = _^ (l.data);
psizeY += zCFont_GetFontY (vt.font);
};
list = l.next;
end;
//Loop through text lines - update Y pos
var int pposY; pposY = (v.psizeY - psizeY) / 2;
list = v.textLines_next;
while (list);
l = _^ (list);
if (l.data) {
vt = _^ (l.data);
vt.posY = pposY;
pposY += zCFont_GetFontY (vt.font);
};
list = l.next;
end;
};
/*
* View_CenterTextLines
*/
func void View_CenterTextLines (var int hndl) {
if (!Hlp_IsValidHandle (hndl)) { return; };
var int viewPtr; viewPtr = getPtr (hndl);
ViewPtr_CenterTextLines (viewPtr);
};
/*
* zCView_Printwin
*/
func void zCView_Printwin (var int viewPtr, var string s) {
//0x00700D20 public: void __thiscall zCView::Printwin(class zSTRING const &)
const int zCView__Printwin_G1 = 7343392;
//0x007AA8D0 public: void __thiscall zCView::Printwin(class zSTRING const &)
const int zCView__Printwin_G2 = 8038608;
if (!viewPtr) { return; };
//CALL_zStringPtrParam cannot be used in recyclable call
CALL_zStringPtrParam (s);
CALL__thiscall (viewPtr, MEMINT_SwitchG1G2 (zCView__Printwin_G1, zCView__Printwin_G2));
};
/*
* zCView_SetPos
*/
func void zCView_SetPos (var int viewPtr, var int vposx, var int vposy) {
//0x006FDA10 public: void __thiscall zCView::SetPos(int,int)
const int zCView__SetPos_G1 = 7330320;
//0x007A75B0 public: void __thiscall zCView::SetPos(int,int)
const int zCView__SetPos_G2 = 8025520;
if (!viewPtr) { return; };
const int call = 0;
if (CALL_Begin (call)) {
CALL_IntParam (_@ (vposy));
CALL_IntParam (_@ (vposx));
CALL__thiscall (_@ (viewPtr), MEMINT_SwitchG1G2 (zCView__SetPos_G1, zCView__SetPos_G2));
call = CALL_End ();
};
};
/*
* zCView_CheckTimedText
*/
func void zCView_CheckTimedText (var int viewPtr) {
//0x006FE0E0 public: void __thiscall zCView::CheckTimedText(void)
const int zCView__CheckTimedText_G1 = 6753728;
//0x007A7C50 public: void __thiscall zCView::CheckTimedText(void)
const int zCView__CheckTimedText_G2 = 7410288;
if (!viewPtr) { return; };
const int call = 0;
if (CALL_Begin (call)) {
CALL__thiscall (_@ (viewPtr), MEMINT_SwitchG1G2 (zCView__CheckTimedText_G1, zCView__CheckTimedText_G2));
call = CALL_End ();
};
};
/*
* zCList_zCViewText_DeleteListDatas
*/
//Releases list.data
//Deletes list.next
func void zCList_zCViewText_DeleteListDatas (var int listPtr) {
//0x00702EA0 public: void __thiscall zCList<class zCViewText>::DeleteListDatas(void)
const int zCList_zCViewText__DeleteListDatas_G1 = 7351968;
//0x007ACAB0 public: void __thiscall zCList<class zCViewText>::DeleteListDatas(void)
const int zCList_zCViewText__DeleteListDatas_G2 = 8047280;
if (!listPtr) { return; };
const int call = 0;
if (CALL_Begin (call)) {
CALL__thiscall (_@ (listPtr), MEMINT_SwitchG1G2 (zCList_zCViewText__DeleteListDatas_G1, zCList_zCViewText__DeleteListDatas_G2));
call = CALL_End ();
};
};
/*
* zCView_DeleteText alternatives
*/
//Not sure why ... but when I tried this with some engine views - game crashed:
//23:710E016A (0x219BEE20 0x006E9208 0x008DCE50 0x00000000) MSVCR100.dll, free()+28 byte(s) .... <zError.cpp,#467>
//LeGo-devs informed, for now I will use this method ... we can change it if needed later :)
//https://forum.worldofplayers.de/forum/threads/1505251-Skriptpaket-LeGo-4/page27?p=27126692#post27126692
/*
* ViewPtr_DeleteText_Safe
*/
func void ViewPtr_DeleteText_Safe (var int viewPtr) {
if (!viewPtr) { return; };
var zCView v; v = _^ (viewPtr);
//Destroy list
zCList_zCViewText_DeleteListDatas (_@ (v.textLines_data));
};
/*
* View_DeleteText_Safe
*/
func void View_DeleteText_Safe (var int hndl) {
if (!Hlp_IsValidHandle (hndl)) { return; };
var int viewPtr; viewPtr = getPtr (hndl);
ViewPtr_DeleteText_Safe (viewPtr);
};
/*
* ViewPtr_AlignText_Fixed
*/
//TODO: remove and replace with ViewPtr_AlignText once it is fixed in LeGo
func void ViewPtr_AlignText_Fixed (var int viewPtr, var int margin) {
if (!viewPtr) { return; };
var zCView v; v = _^ (viewPtr);
var int lp; lp = v.textLines_next;
var zCList l;
var zCViewText vt;
var int width;
if(margin == 0) {
while(lp);
l = _^(lp);
vt = _^(l.data);
//When I tried to center some views created by engine vsizex was set to PS_VMAX, psizex contained correct value (these views are confusing ...)
//width = Print_ToVirtual(Font_GetStringWidthPtr(vt.text, vt.font), PS_X) * PS_VMAX / v.vsizex;
width = Print_ToVirtual(Font_GetStringWidthPtr(vt.text, vt.font), PS_X) * PS_VMAX / Print_ToVirtual (v.psizex, PS_X);
//vt.posx = (PS_VMAX / 2) - (width / 2);
vt.posx = (PS_VMAX - width) / 2;
lp = l.next;
end;
}
else if(margin > 0) {
while(lp);
l = _^(lp);
vt = _^(l.data);
vt.posx = margin;
lp = l.next;
end;
}
else {
while(lp);
l = _^(lp);
vt = _^(l.data);
//width = Print_ToVirtual(Font_GetStringWidthPtr(vt.text, vt.font), PS_X) * PS_VMAX / v.vsizex;
width = Print_ToVirtual(Font_GetStringWidthPtr(vt.text, vt.font), PS_X) * PS_VMAX / Print_ToVirtual (v.psizex, PS_X);
//LeGo bug - subtraction of negative number is addition ... so we need to add negative number ...
//vt.posx = PS_VMAX - width - margin;
vt.posx = PS_VMAX - width + margin;
lp = l.next;
end;
};
};
/*
* View_AlignText_Fixed
*/
func void View_AlignText_Fixed (var int hndl, var int margin) {
if (!Hlp_IsValidHandle (hndl)) { return; };
var int viewPtr; viewPtr = getPtr (hndl);
ViewPtr_AlignText_Fixed (viewPtr, margin);
};
/*
* ViewPtr_SetTextAndFontColor
*/
func void ViewPtr_SetTextAndFontColor (var int viewPtr, var string texts, var int color) {
if (!viewPtr) { return; };
var zCView v; v = _^ (viewPtr);
var string fontName; fontName = Print_GetFontName (v.font);
var int fontHeight; fontHeight = Print_ToVirtual (Print_GetFontHeight (fontName), v.psizey);
var int cnt; cnt = STR_SplitCount (texts, Print_LineSeperator);
var string text;
var zCList l;
var zCViewText vt;
var int vposX;
var int vposY;
vposX = v.vposX;
vposY = v.vposY;
//Update existing zCViewText objects
var int list; list = v.textLines_next;
var int i; i = 0;
var int flagListExtended; flagListExtended = FALSE;
var int flagTextsChanged; flagTextsChanged = FALSE;
if (list) {
l = _^ (list);
while (i < cnt);
text = STR_Split(texts, Print_LineSeperator, i);
if (list) {
//Update existing text view
l = _^ (list);
if (l.data) {
vt = _^ (l.data);
if (!Hlp_StrCmp (vt.text, text)) {
flagTextsChanged = TRUE;
vt.text = text;
};
if (color != -1) {
vt.color = color;
vt.colored = (color != -1);
};
//Calc Y pos for next line
var int vtFontHeight; vtFontHeight = Print_ToVirtual (zCFont_GetFontY (vt.font), v.psizey);
vposY = vt.posY + vtFontHeight;
};
list = l.next;
} else {
//Add new text view
ViewPtr_AddText (viewPtr, vposX, vposY, text, fontName, color);
vposY += fontHeight;
flagListExtended = TRUE;
flagTextsChanged = TRUE;
};
i += 1;
end;
//Remove extra text views
if (!flagListExtended) {
//Not sure why ... but when I tried this with some engine views - game crashed:
//23:710E016A (0x219BEE20 0x006E9208 0x008DCE50 0x00000000) MSVCR100.dll, free()+28 byte(s) .... <zError.cpp,#467>
//var int n; n = l.next;
//l.next = 0;
//while (n);
// var zCList del; del = _^ (n);
// n = del.next;
// MEM_Free (_@ (del));
//end;
if (l.next) {
flagTextsChanged = TRUE;
//Dettach list
var int n; n = l.next;
l.next = 0;
//Destroy the rest of the list
l = _^ (n);
zCList_zCViewText_DeleteListDatas (_@ (l.data));
};
};
} else {
//Or add texts - if they were not added yet
ViewPtr_AddText (viewPtr, vposX, vposY, texts, fontName, color);
flagTextsChanged = TRUE;
};
//-- Auto formatting
if (flagTextsChanged) {
if (v.intflags & VIEW_AUTO_ALPHA) {
ViewPtr_SetAlphaAll (viewPtr, v.alpha);
};
if (v.intflags & VIEW_AUTO_RESIZE) {
ViewPtr_AutoResize (viewPtr);
};
if (v.intflags & VIEW_TXT_HCENTER) {
ViewPtr_AlignText_Fixed (viewPtr, 0);
};
if (v.intflags & VIEW_TXT_VCENTER) {
ViewPtr_CenterTextLines (viewPtr);
};
};
};
func void ViewPtr_SetTextMarginAndFontColor (var int viewPtr, var string texts, var int color, var int margin) {
ViewPtr_SetTextAndFontColor (viewPtr, texts, color);
ViewPtr_AlignText_Fixed (viewPtr, margin);
};
//-- View_SetTextAndFontColor
func void View_SetTextAndFontColor (var int hndl, var string texts, var int color) {
if (!Hlp_IsValidHandle (hndl)) { return; };
var int viewPtr; viewPtr = getPtr (hndl);
ViewPtr_SetTextAndFontColor (viewPtr, texts, color);
};
func void View_SetTextMarginAndFontColor (var int hndl, var string texts, var int color, var int margin) {
if (!Hlp_IsValidHandle (hndl)) { return; };
var int viewPtr; viewPtr = getPtr (hndl);
ViewPtr_SetTextMarginAndFontColor (viewPtr, texts, color, margin);
};
//-- View_SetText
func void View_SetText (var int hndl, var string texts) {
ViewPtr_SetTextAndFontColor (hndl, texts, -1);
};
func void View_SetTextMargin (var int hndl, var string texts, var int margin) {
View_SetTextMarginAndFontColor (hndl, texts, -1, margin);
};
//--
func void ViewPtr_SetFontColor (var int viewPtr, var int color) {
if (!viewPtr) { return; };
var zCView view; view = _^ (viewPtr);
if (view.textLines_next) {
var zCList list; list = _^ (view.textLines_next);
var zCViewText viewT; viewT = _^ (list.data);
viewT.color = color;
viewT.colored = TRUE;
};
};
func void View_SetFontColor (var int hndl, var int color) {
if (!Hlp_IsValidHandle (hndl)) { return; };
var int viewPtr; viewPtr = getPtr (hndl);
ViewPtr_SetFontColor (viewPtr, color);
};
func int ViewPtr_OnDesk (var int viewPtr) {
if (!viewPtr) { return FALSE; };
var zCView view; view = _^ (viewPtr);
return view.onDesk;
};
func int View_OnDesk (var int hndl) {
if (!Hlp_IsValidHandle (hndl)) { return FALSE; };
var int viewPtr; viewPtr = getPtr (hndl);
return + ViewPtr_OnDesk (viewPtr);
};
func int ViewPtr_IsOpen (var int viewPtr) {
if (!viewPtr) { return FALSE; };
var zCView view; view = _^ (viewPtr);
return (view.IsOpen | view.continueOpen);
};
func int View_IsOpen (var int hndl) {
if (!Hlp_IsValidHandle (hndl)) { return FALSE; };
var int viewPtr; viewPtr = getPtr (hndl);
return + ViewPtr_IsOpen (viewPtr);
};
func int ViewPtr_IsClosed (var int viewPtr) {
if (!viewPtr) { return FALSE; };
var zCView view; view = _^ (viewPtr);
return (view.isClosed | view.continueClose);
};
func int View_IsClosed (var int hndl) {
if (!Hlp_IsValidHandle (hndl)) { return FALSE; };
var int viewPtr; viewPtr = getPtr (hndl);
return + ViewPtr_IsClosed (viewPtr);
};
func void ViewPtr_SetAlphaFunc (var int viewPtr, var int alphaFunc) {
if (!viewPtr) { return; };
var zCView view; view = _^ (viewPtr);
view.alphaFunc = alphaFunc;
};
func void View_SetAlphaFunc (var int hndl, var int alphaFunc) {
if (!Hlp_IsValidHandle (hndl)) { return; };
var int viewPtr; viewPtr = getPtr (hndl);
ViewPtr_SetAlphaFunc (viewPtr, alphaFunc);
};
//bruh ... LeGo does not have any safety checks
func void ViewPtr_Close_Safe(var int viewPtr) {
if (!viewPtr) { return; };
ViewPtr_Close (viewPtr);
};
func void View_Close_Safe (var int hndl) {
if (!Hlp_IsValidHandle (hndl)) { return; };
ViewPtr_Close_Safe (getPtr (hndl));
};
//--
func void ViewPtr_Open_Safe (var int viewPtr) {
if (!viewPtr) { return; };
ViewPtr_Open (viewPtr);
};
func void View_Open_Safe(var int hndl) {
if (!Hlp_IsValidHandle (hndl)) { return; };
ViewPtr_Open_Safe (getPtr( hndl));
};
//--
func void ViewPtr_MoveTo_Safe (var int viewPtr, var int x, var int y) {
if (!viewPtr) { return; };
ViewPtr_MoveTo (viewPtr, x, y);
};
func void View_MoveTo_Safe (var int hndl, var int x, var int y) {
if (!Hlp_IsValidHandle (hndl)) { return; };
View_MoveTo (hndl, x, y);
};
func void ViewPtr_Resize_Safe (var int viewPtr, var int x, var int y) {
if (!viewPtr) { return; };
ViewPtr_Resize (viewPtr, x, y);
};
func void View_Resize_Safe (var int hndl, var int x, var int y) {
if (!Hlp_IsValidHandle (hndl)) { return; };
View_Resize (hndl, x, y);
};
//-- engine stuff
func int zCView_Noise_IsActive () {
const int cGAME_VIEW_NOISE = 5;
var int ptr; ptr = MEM_Game.array_view [cGAME_VIEW_NOISE];
if (ptr) {
var zCView v; v = _^ (ptr);
return v.ondesk;
};
return FALSE;
};