Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
hud_element.c
Go to the documentation of this file.
1#include "common.h"
2#include "hud_element.h"
3#include "nu/nusys.h"
4#include "ld_addrs.h"
5
6#define MAX_HUD_CACHE_ENTRIES 192
7
13
16
20
22 { 8, 8, 32 },
23 { 16, 16, 128 },
24 { 24, 24, 288 },
25 { 32, 32, 512 },
26 { 48, 48, 1152 },
27 { 64, 64, 2048 },
28 { 8, 16, 64 },
29 { 16, 8, 64 },
30 { 16, 24, 192 },
31 { 16, 32, 256 },
32 { 64, 32, 1024 },
33 { 32, 16, 256 },
34 { 12, 12, 72 },
35 { 48, 24, 576 },
36 { 32, 8, 128 },
37 { 24, 8, 96 },
38 { 64, 16, 512 },
39 { 16, 64, 512 },
40 { 192, 32, 3072 },
41 { 40, 40, 800 },
42 { 24, 16, 192 },
43 { 32, 40, 640 },
44 { 40, 16, 320 },
45 { 40, 24, 480 },
46 { 32, 24, 384 },
47 { 20, 32, 0 }
48};
49
64
66 {
67 .v = {
68 .ob = { -12, 0, 0},
69 .flag = 0,
70 .tc = { 0x800, 0x800 },
71 .cn = { 0, 0, 0, 255}
72 }
73 },
74 {
75 .v = {
76 .ob = { 51, 0, 0},
77 .flag = 0,
78 .tc = { 0, 0x800 },
79 .cn = { 0, 0, 0, 255}
80 }
81 },
82 {
83 .v = {
84 .ob = { 51, 63, 0},
85 .flag = 0,
86 .tc = { 0, 0 },
87 .cn = { 0, 0, 0, 255}
88 }
89 },
90 {
91 .v = {
92 .ob = { -12, 63, 0},
93 .flag = 0,
94 .tc = { 0x800, 0 },
95 .cn = { 0, 0, 0, 255}
96 }
97 }
98};
99
100Lights1 HudElemLights = gdSPDefLights1(255, 255, 255, 0, 0, 0, 0, 0, 0);
101
107
120
121void hud_element_setup_cam(void);
122
124 s32* pos = (s32*)anim;
125 s32 raster;
126 s32 palette;
127 s32 preset;
129 s32 i;
130 s32 capacity;
131
132 if (pos == NULL) {
133 return;
134 }
135
136 preset = 0;
137
138 while (TRUE) {
139 switch (*pos++) {
141 return;
143 pos += 3;
144 break;
146 preset = *pos++;
147 hudElement->drawSizePreset = hudElement->tileSizePreset = preset;
148 break;
151 preset = *pos;
152 pos += 2;
153 hudElement->drawSizePreset = hudElement->tileSizePreset = preset;
154 break;
156 hudElement->customDrawSize.x = hudElement->customImageSize.x = *pos++;
157 hudElement->customDrawSize.y = hudElement->customImageSize.y = *pos++;
159 break;
169 pos++;
170 break;
176 pos += 2;
177 break;
179 pos++;
180 raster = *pos++;
181 palette = *pos++;
182
183 i = 0;
185 while (TRUE) {
186 if (entry->id == -1) {
187 entry->id = raster;
190 capacity = HudElemCacheCapacity;
191 } else {
192 capacity = HudElemCacheCapacity / 2;
193 }
194 ASSERT(capacity > *gHudElementCacheSize + HudElemSizes[preset].size);
198 *pos = i;
199 } else {
200 *pos = (u16)(*pos) | (i << 16);
201 }
202 i++;
203 break;
204 } else if (entry->id == raster) {
206 *pos = i;
207 } else {
208 *pos = (u16)(*pos) | (i << 16);
209 }
210 break;
211 }
212 entry++;
213 i++;
214 }
215
216 pos++;
218
220 i = 0;
221 while (TRUE) {
222 if (entry->id == -1) {
223 entry->id = palette;
226 capacity = HudElemCacheCapacity;
227 } else {
228 capacity = HudElemCacheCapacity / 2;
229 }
230 ASSERT(capacity > *gHudElementCacheSize + 32);
231 nuPiReadRom((s32)icon_ROM_START + palette, entry->data, 32);
234 *pos = i;
235 } else {
236 *pos = (u16)(*pos) | (i << 16);
237 }
238 i++;
239 break;
240 } else if (entry->id == palette) {
242 *pos = i;
243 } else {
244 *pos = (u16)(*pos) | (i << 16);
245 }
246 break;
247 }
248 entry++;
249 i++;
250 }
251
252 pos++;
254 break;
255 }
256 }
257}
258
259// render a basic rect for a non-transformed hud element
261 s16 offsetX, s16 offsetY, s32 clamp, s32 dropShadow) {
262 s32 flipX, flipY;
263 s32 fmt;
264 s32 widthScale, heightScale;
267 s32 uls, ult, lrs, lrt;
268 s32 uly, lry, ulx, lrx;
269 s32 masks, maskt;
271 IMG_PTR imageAddr;
272 PAL_PTR paletteAddr;
273 s16 baseX, baseY;
275 u16 renderPosX, renderPosY;
276
277 imageAddr = hudElement->imageAddr;
278 paletteAddr = hudElement->paletteAddr;
279
280 screenPosOffsetScaledX = hudElement->screenPosOffset.x * 1024;
281 screenPosOffsetScaledY = hudElement->screenPosOffset.y * 1024;
282 widthScale = hudElement->widthScale;
283 screenPosOffsetScaledX /= widthScale;
284 heightScale = hudElement->heightScale;
285 screenPosOffsetScaledY /= heightScale;
286
287 renderPosX = hudElement->worldPosOffset.x;
288 renderPosY = hudElement->worldPosOffset.y;
289 renderPosX += hudElement->renderPosX + screenPosOffsetScaledX;
290 renderPosY += hudElement->renderPosY + screenPosOffsetScaledY;
291
292 baseX = offsetX + renderPosX;
293 baseY = offsetY + renderPosY;
294
295 if (dropShadow) {
296 baseX += 2;
297 baseY += 2;
298 }
299
300 flipX = (hudElement->flags & HUD_ELEMENT_FLAG_FLIPX) != 0;
301 flipY = (hudElement->flags & HUD_ELEMENT_FLAG_FLIPY) != 0;
302
303 fmt = 0; // RGBA
305 fmt = 1; // CI
306 }
308 fmt = 2; // IA
309 }
310
311 masks = 6;
312 maskt = 5;
313 if (!(hudElement->flags & HUD_ELEMENT_FLAG_SCALED)) {
314 switch (drawSizeX) {
315 case 8:
316 masks = 3;
317 break;
318 case 16:
319 masks = 4;
320 break;
321 case 32:
322 masks = 5;
323 break;
324 }
325
326 switch (drawSizeY) {
327 case 8:
328 maskt = 3;
329 break;
330 case 16:
331 maskt = 4;
332 break;
333 case 32:
334 maskt = 5;
335 break;
336 }
337 }
338
339 switch (fmt) {
340 case 0:
343 break;
344 case 1:
348 } else {
350 }
351 } else {
354 } else {
356 }
357 }
359 gDPLoadTLUT_pal16(gMainGfxPos++, 0, paletteAddr);
360 break;
361 case 2:
364 break;
365 }
366
369 } else {
371 }
372
373 ult = 0;
375 uly = baseY;
376 while (TRUE) {
377 lry = uly + 1024.0 / heightScale * 32.0;
378 lrt = ult + 31;
379 if (flipY) {
381 } else {
382 texStartY = 0;
383 }
384
386 break;
387 }
388
389 if (lry >= SCREEN_HEIGHT) {
390 lrt = SCREEN_HEIGHT - baseY - 1;
391 lry = SCREEN_HEIGHT;
393 }
394
395 if (lrt + 1 >= texSizeY) {
396 lrt = texSizeY - 1;
397 if (texSizeY > 16) {
398 lry = baseY + drawSizeY - 1;
399 } else {
400 lry = baseY + drawSizeY;
401 }
403 }
404
406 uls = 0;
407 ulx = baseX;
408 while (TRUE) {
409 lrx = ulx + 1024.0 / widthScale * 64.0;
410 lrs = uls + 63;
411 if (flipX) {
413 } else {
414 texStartX = 0;
415 }
416
418 break;
419 }
420
421 if (lrx >= SCREEN_WIDTH) {
422 lrs = SCREEN_WIDTH - baseX - 1;
423 lrx = SCREEN_WIDTH;
425 }
426
427 if (lrs + 1 >= texSizeX) {
428 lrs = texSizeX - 1;
429 if (texSizeX > 16) {
430 lrx = baseX + drawSizeX - 1;
431 } else {
432 lrx = baseX + drawSizeX;
433 }
435 }
436
438
439 if (!isLastTileX && !isLastTileY) {
440 tileMode = 0; // middle tile
441 }
442 if (isLastTileX && !isLastTileY) {
443 tileMode = 1; // horizontal edge tile
444 }
445 if (!isLastTileX && isLastTileY) {
446 tileMode = 2; // vertical edge tile
447 }
448 if (isLastTileX && isLastTileY) {
449 tileMode = 3; // corner tile
450 }
451
452 switch (fmt) {
453 case 0:
456 } else {
458 }
459
461 gDPSetPrimColor(gMainGfxPos++, 0, 0, 0, 0, 0, hudElement->opacity);
462 }
463
464 if (!flipX && !flipY) {
467 } else {
470 }
471 break;
472 case 1:
473 if (!dropShadow) {
476 } else {
478 }
479
481 gDPSetPrimColor(gMainGfxPos++, 0, 0, hudElement->tint.r, hudElement->tint.g, hudElement->tint.b, hudElement->opacity);
482 } else {
483 gDPSetPrimColor(gMainGfxPos++, 0, 0, hudElement->tint.r, hudElement->tint.g, hudElement->tint.b, 255);
484 }
485 } else {
488 gDPSetPrimColor(gMainGfxPos++, 0, 0, 40, 40, 40, 72);
489 }
490
491 if (!flipX && !flipY) {
492 if (!clamp) {
495 } else {
496 switch (tileMode) {
497 case 0:
500 break;
501 case 1:
504 break;
505 case 2:
508 break;
509 case 3:
512 break;
513 }
514 }
515 } else {
518 }
519 break;
520 case 2:
522 gDPSetPrimColor(gMainGfxPos++, 0, 0, hudElement->tint.r, hudElement->tint.g, hudElement->tint.b, hudElement->opacity);
523
524 if (!flipX && !flipY) {
525 if (!clamp) {
526 switch (tileMode) {
527 case 0:
530 break;
531 case 1:
534 break;
535 case 2:
538 break;
539 case 3:
542 break;
543 }
544 } else {
547 }
548 } else {
551 }
552 break;
553 }
554
556 gSPScisTextureRectangle(gMainGfxPos++, ulx * 4, uly * 4, lrx * 4, lry * 4, 0, texStartX * 32 + 16, texStartY * 32 + 16, widthScale, heightScale);
557 } else {
558 gSPScisTextureRectangle(gMainGfxPos++, ulx * 4, uly * 4, lrx * 4, lry * 4, 0, texStartX * 32, texStartY * 32, widthScale, heightScale);
559 }
560 if (isLastTileX) {
561 break;
562 }
563 ulx += 1024.0 / widthScale * 64.0;
564 uls += 64;
565 }
566
567 if (isLastTileY) {
568 break;
569 }
570
571 ult += 32;
572 uly += 1024.0 / heightScale * 32.0;
573 }
574
576}
577
581 s32 i;
582
588 } else {
593 }
594
602 for (i = 0; i < MAX_HUD_CACHE_ENTRIES; i++) {
603 entryRaster[i].id = -1;
604 entryPalette[i].id = -1;
605 }
606 } else {
607 if (HudElemAuxCache == NULL) {
610 } else {
612 }
617 for (i = 0; i < MAX_HUD_CACHE_ENTRIES; i++) {
618 entryRaster[i].id = -1;
619 entryPalette[i].id = -1;
620 }
621 }
622
623 for (i = 0; i < ARRAY_COUNT(*gHudElements); i++) {
624 (*gHudElements)[i] = NULL;
625 }
626
627 HudElemCount = 0;
628 FrameQuadIndex = 0;
630}
631
632#if VERSION_PAL
633extern Addr D_80200000;
634#endif
635
665
689
692 s32 id;
693
694 for (id = 0; id < ARRAY_COUNT(*gHudElements); id++) {
695 if ((*gHudElements)[id] == NULL) {
696 break;
697 }
698 }
699
701
702 (*gHudElements)[id] = hudElement = heap_malloc(sizeof(*hudElement));
703 HudElemCount++;
704
706
708 hudElement->readPos = anim;
709 if (anim == NULL) {
710 hudElement->readPos = &HES_Empty;
711 }
712 hudElement->updateTimer = 1;
713 hudElement->drawSizePreset = -1;
714 hudElement->tileSizePreset = -1;
715 hudElement->renderPosX = 0;
716 hudElement->renderPosY = 0;
717 hudElement->loopStartPos = anim;
718 hudElement->widthScale = X10(1.0f);
719 hudElement->heightScale = X10(1.0f);
720 hudElement->anim = hudElement->readPos;
721 hudElement->uniformScale = 1.0f;
722 hudElement->screenPosOffset.x = 0;
723 hudElement->screenPosOffset.y = 0;
724 hudElement->worldPosOffset.x = 0;
725 hudElement->worldPosOffset.y = 0;
726 hudElement->worldPosOffset.z = 0;
727 hudElement->opacity = 255;
728 hudElement->tint.r = 255;
729 hudElement->tint.g = 255;
730 hudElement->tint.b = 255;
731
735 }
736
738 while (hud_element_update(hudElement) != 0);
739
740 return id;
741}
742
744 s32 i;
745
746 for (i = 0; i < ARRAY_COUNT(*gHudElements); i++) {
747 HudElement* elem = (*gHudElements)[i];
748
749 if (elem == NULL || elem->flags == 0 || elem->flags & HUD_ELEMENT_FLAG_DISABLED) {
750 continue;
751 }
752
753 if (elem->flags & HUD_ELEMENT_FLAG_DELETE) {
755 continue;
756 }
757
758 if (elem->readPos == NULL) {
759 // bail out and skip updating any subsequent elements
760 break;
761 }
762
763 // update the current element
764 elem->updateTimer--;
765 if (elem->updateTimer == 0) {
766 while (hud_element_update(elem) != 0);
767 }
768 if (elem->flags & HUD_ELEMENT_FLAG_RESIZING) {
769 elem->dynamicSize.x += elem->deltaSize.x;
770 elem->dynamicSize.y += elem->deltaSize.y;
771 }
772 }
773}
774
778 s32 i;
779 s32 drawSizePreset;
780 s32 tileSizePreset;
784 u32 flags;
785 s32 s1, s2;
786 s32 arg1, arg2;
787 f32 uniformScale;
789
790 HudTransform* hudTransform = hudElement->hudTransform;
791 s32* nextPos = (s32*)hudElement->readPos;
792
793 switch (*nextPos++) {
795 hudElement->updateTimer = 60;
796 flags = hudElement->flags;
798 break;
800 hudElement->updateTimer = 60;
802 break;
804 hudElement->readPos = (HudScript*)nextPos;
806 return TRUE;
808 hudElement->readPos = (HudScript*)nextPos;
810 return TRUE;
812 hudElement->readPos = (HudScript*)nextPos;
814 return TRUE;
816 s1 = *nextPos++;
817 hudElement->readPos = (HudScript*)nextPos;
818 hudElement->flags |= s1;
819 return TRUE;
821 s1 = *nextPos++;
822 hudElement->readPos = (HudScript*)nextPos;
823 hudElement->flags &= ~s1;
824 return TRUE;
826 hudElement->updateTimer = *nextPos++;
827 hudElement->imageAddr = (u8*)*nextPos++;
828 hudElement->readPos = (HudScript*)nextPos;
829
831 hudElement->imageAddr += hudElement->memOffset;
832 }
833
836 imageWidth = hudElement->customImageSize.x;
837 imageHeight = hudElement->customImageSize.y;
838 drawWidth = hudElement->customDrawSize.x;
839 drawHeight = hudElement->customDrawSize.y;
840 } else {
841 tileSizePreset = hudElement->tileSizePreset;
842 drawSizePreset = hudElement->drawSizePreset;
843 imageWidth = HudElemSizes[tileSizePreset].width;
844 imageHeight = HudElemSizes[tileSizePreset].height;
845 drawWidth = HudElemSizes[drawSizePreset].width;
846 drawHeight = HudElemSizes[drawSizePreset].height;
847 }
848
851 hudElement->dynamicSize.x = drawWidth;
852 hudElement->dynamicSize.y = drawHeight;
853 hudElement->deltaSize.x = ((f32)imageWidth - (f32)drawWidth) / (f32)hudElement->updateTimer;
854 hudElement->deltaSize.y = ((f32)imageHeight - (f32)drawHeight) / (f32)hudElement->updateTimer;
855 } else {
857 hudElement->dynamicSize.x = imageWidth;
858 hudElement->dynamicSize.y = imageHeight;
859 hudElement->deltaSize.x = ((f32)drawWidth - (f32)imageWidth) / (f32)hudElement->updateTimer;
860 hudElement->deltaSize.y = ((f32)drawHeight - (f32)imageHeight) / (f32)hudElement->updateTimer;
861 }
862 }
863 break;
865 hudElement->updateTimer = *nextPos++;
866 hudElement->imageAddr = (IMG_PTR)*nextPos++;
867 hudElement->paletteAddr = (PAL_PTR)*nextPos++;
868 hudElement->readPos = (HudScript*)nextPos;
869
871 hudElement->imageAddr += hudElement->memOffset;
872 hudElement->paletteAddr += hudElement->memOffset;
873 }
874
877 imageWidth = hudElement->customImageSize.x;
878 imageHeight = hudElement->customImageSize.y;
879 drawWidth = hudElement->customDrawSize.x;
880 drawHeight = hudElement->customDrawSize.y;
881 } else {
882 tileSizePreset = hudElement->tileSizePreset;
883 drawSizePreset = hudElement->drawSizePreset;
884 imageWidth = HudElemSizes[tileSizePreset].width;
885 imageHeight = HudElemSizes[tileSizePreset].height;
886 drawWidth = HudElemSizes[drawSizePreset].width;
887 drawHeight = HudElemSizes[drawSizePreset].height;
888 }
889
892 hudElement->dynamicSize.x = drawWidth;
893 hudElement->dynamicSize.y = drawHeight;
894 hudElement->deltaSize.x = ((f32)imageWidth - (f32)drawWidth) / (f32)hudElement->updateTimer;
895 hudElement->deltaSize.y = ((f32)imageHeight - (f32)drawHeight) / (f32)hudElement->updateTimer;
896 } else {
898 hudElement->dynamicSize.x = imageWidth;
899 hudElement->dynamicSize.y = imageHeight;
900 hudElement->deltaSize.x = ((f32)drawWidth - (f32)imageWidth) / (f32)hudElement->updateTimer;
901 hudElement->deltaSize.y = ((f32)drawHeight - (f32)imageHeight) / (f32)hudElement->updateTimer;
902 }
903 }
904 break;
906 hudElement->updateTimer = *nextPos++;
907
908 if (hudElement->flags & HUD_ELEMENT_FLAG_BATTLE) {
911 } else {
914 }
915
916 i = 0;
917 while (TRUE) {
918 if (entryRaster[i].id == *nextPos) {
919 break;
920 }
922 }
923
924 nextPos++;
925 hudElement->imageAddr = entryRaster[i].data;
926
927 i = 0;
928 while (TRUE) {
929 if (entryPalette[i].id == *nextPos) {
930 break;
931 }
933 }
934 hudElement->paletteAddr = entryPalette[i].data;
935 nextPos += 3;
936 hudElement->readPos = (HudScript*)nextPos;
937
940 imageWidth = hudElement->customImageSize.x;
941 imageHeight = hudElement->customImageSize.y;
942 drawWidth = hudElement->customDrawSize.x;
943 drawHeight = hudElement->customDrawSize.y;
944 } else {
945 tileSizePreset = hudElement->tileSizePreset;
946 drawSizePreset = hudElement->drawSizePreset;
947 imageWidth = HudElemSizes[tileSizePreset].width;
948 imageHeight = HudElemSizes[tileSizePreset].height;
949 drawWidth = HudElemSizes[drawSizePreset].width;
950 drawHeight = HudElemSizes[drawSizePreset].height;
951 }
952
955 hudElement->dynamicSize.x = drawWidth;
956 hudElement->dynamicSize.y = drawHeight;
957 hudElement->deltaSize.x = ((f32)imageWidth - (f32)drawWidth) / (f32)hudElement->updateTimer;
958 hudElement->deltaSize.y = ((f32)imageHeight - (f32)drawHeight) / (f32)hudElement->updateTimer;
959 } else {
961 hudElement->dynamicSize.x = imageWidth;
962 hudElement->dynamicSize.y = imageHeight;
963 hudElement->deltaSize.x = ((f32)drawWidth - (f32)imageWidth) / (f32)hudElement->updateTimer;
964 hudElement->deltaSize.y = ((f32)drawHeight - (f32)imageHeight) / (f32)hudElement->updateTimer;
965 }
966 }
967 break;
969 hudElement->readPos = hudElement->loopStartPos;
970 return TRUE;
972 hudElement->loopStartPos = (HudScript*)nextPos;
973 hudElement->readPos = (HudScript*)nextPos;
974 return TRUE;
976 s1 = *nextPos++;
977 s2 = *nextPos++;
978 if (rand_int(s1) < s2) {
979 hudElement->readPos = hudElement->loopStartPos;
980 } else {
981 hudElement->readPos = (HudScript*)nextPos;
982 }
983 return TRUE;
985 sizePreset = *nextPos++;
986 hudElement->widthScale = X10(1);
987 hudElement->heightScale = X10(1);
988 hudElement->readPos = (HudScript*)nextPos;
989 hudElement->drawSizePreset = sizePreset;
990 hudElement->tileSizePreset = sizePreset;
993 return TRUE;
995 tileSizePreset = *nextPos++;
996 drawSizePreset = *nextPos++;
997
998 hudElement->readPos = (HudScript*)nextPos;
999 hudElement->tileSizePreset = tileSizePreset;
1000 hudElement->drawSizePreset = drawSizePreset;
1001
1002 imageWidth = HudElemSizes[tileSizePreset].width;
1003 imageHeight = HudElemSizes[tileSizePreset].height;
1004 drawWidth = HudElemSizes[drawSizePreset].width;
1005 drawHeight = HudElemSizes[drawSizePreset].height;
1006
1009
1010 xScaled = 1.0f / xScaled;
1011 yScaled = 1.0f / yScaled;
1012
1013 hudElement->widthScale = X10(xScaled);
1014 hudElement->heightScale = X10(yScaled);
1015
1018 return TRUE;
1020 tileSizePreset = *nextPos++;
1021 drawSizePreset = *nextPos++;
1022
1023 hudElement->widthScale = X10(1);
1024 hudElement->heightScale = X10(1);
1025 hudElement->readPos = (HudScript*)nextPos;
1026 hudElement->tileSizePreset = tileSizePreset;
1027 hudElement->drawSizePreset = drawSizePreset;
1031 return TRUE;
1033 s1 = *nextPos++;
1034 hudElement->readPos = (HudScript*)nextPos;
1035 hudElement->screenPosOffset.x += s1;
1036 return TRUE;
1038 s2 = *nextPos++;
1039 if (hudElement->flags & HUD_ELEMENT_FLAG_FLIPY) {
1040 hudElement->screenPosOffset.y -= s2;
1041 } else {
1042 hudElement->screenPosOffset.y += s2;
1043 }
1044 hudElement->readPos = (HudScript*)nextPos;
1045 return TRUE;
1047 s1 = *nextPos++;
1048 s2 = *nextPos++;
1049 hudElement->screenPosOffset.x = s1;
1050 if (hudElement->flags & HUD_ELEMENT_FLAG_FLIPY) {
1051 hudElement->screenPosOffset.y = -s2;
1052 } else {
1053 hudElement->screenPosOffset.y = s2;
1054 }
1055 hudElement->readPos = (HudScript*)nextPos;
1056 return TRUE;
1058 uniformScale = (f32)*nextPos++;
1059 uniformScale /= 65536;
1060 hudElement->uniformScale = uniformScale;
1062 imageWidth = hudElement->customImageSize.x;
1063 imageHeight = hudElement->customImageSize.y;
1064 drawWidth = hudElement->customDrawSize.x;
1065 drawHeight = hudElement->customDrawSize.y;
1066 } else {
1067 imageWidth = HudElemSizes[hudElement->tileSizePreset].width;
1068 imageHeight = HudElemSizes[hudElement->tileSizePreset].height;
1069 drawWidth = HudElemSizes[hudElement->drawSizePreset].width;
1070 drawHeight = HudElemSizes[hudElement->drawSizePreset].height;
1071 }
1072
1073 hudElement->sizeX = drawWidth * uniformScale;
1074 hudElement->sizeY = drawHeight * uniformScale;
1075
1076 xScaled = (f32) drawWidth / (f32) imageWidth * uniformScale;
1077 yScaled = (f32) drawHeight / (f32) imageHeight * uniformScale;
1078
1079 xScaled = 1.0f / xScaled;
1080 yScaled = 1.0f / yScaled;
1081
1082 hudElement->widthScale = X10(xScaled);
1083 hudElement->heightScale = X10(yScaled);
1084
1085 hudElement->readPos = (HudScript*)nextPos;
1088 return TRUE;
1090 s1 = *nextPos++;
1091 hudElement->opacity = s1;
1093 if (hudElement->opacity == 255) {
1095 }
1096 hudElement->readPos = (HudScript*)nextPos;
1097 return TRUE;
1099 s1 = *nextPos++;
1100 s2 = *nextPos++;
1101 hudElement->updateTimer = rand_int(s2 - s1) + s1;
1102 hudElement->readPos = (HudScript*)nextPos;
1103 break;
1105 hudElement->customDrawSize.x = hudElement->customImageSize.x = *nextPos++;
1106 hudElement->customDrawSize.y = hudElement->customImageSize.y = *nextPos++;
1107 hudElement->readPos = (HudScript*)nextPos;
1108 hudElement->widthScale = X10(1);
1109 hudElement->heightScale = X10(1);
1110 hudElement->drawSizePreset = 0;
1111 hudElement->tileSizePreset = 0;
1115 return TRUE;
1117 s1 = *nextPos++;
1118 hudElement->readPos = (HudScript*)nextPos;
1120 hudElement->flags |= s1 << 24;
1121 return TRUE;
1123 s1 = *nextPos++;
1124 newReadPos = (HudScript*)nextPos[rand_int(s1 - 1)];
1125 hudElement->readPos = newReadPos;
1127 return TRUE;
1129 arg2 = *nextPos++;
1130 sfx_play_sound(arg2);
1131 hudElement->readPos = (HudScript*)nextPos;
1132 return TRUE;
1134 arg1 = *nextPos++;
1135 arg2 = *nextPos++;
1136 hudElement->readPos = (HudScript*)nextPos;
1138 hudTransform->pivot.x = arg1;
1139 hudTransform->pivot.y = arg2;
1140 }
1141 return TRUE;
1143 break;
1144 }
1145
1146 return FALSE;
1147}
1148
1150 s32 i, count, j;
1152 s32 el1, el2;
1154 s32 drawSizeX, drawSizeY, offsetX, offsetY;
1156
1158 if (FrameQuadIndex >= ARRAY_COUNT(elem->hudTransform->quadBuffers)) {
1159 FrameQuadIndex = 0;
1160 }
1162
1163 // gather appropriate hud elements
1164 count = 0;
1165 for (i = 0; i < ARRAY_COUNT(*gHudElements); i++) {
1166 elem = (*gHudElements)[i];
1167 if (elem == NULL) {
1168 continue;
1169 }
1170
1171 if (elem->flags == 0 || elem->flags & HUD_ELEMENT_FLAG_DISABLED) {
1172 continue;
1173 }
1174
1176 continue;
1177 }
1178
1179 if (elem->flags & HUD_ELEMENT_FLAG_MANUAL_RENDER) {
1180 continue;
1181 }
1182
1183 if (elem->flags & HUD_ELEMENT_FLAG_TRANSFORM) {
1184 continue;
1185 }
1186
1187 if (elem->flags & (HUD_ELEMENT_FLAG_BATTLE_CAM)) {
1188 continue;
1189 }
1190
1191 if (elem->flags & HUD_ELEMENT_FLAG_FRONTUI || elem->drawSizePreset < 0) {
1192 continue;
1193 }
1194
1195 // add element to list
1196 sortedElements[count++] = i;
1197 }
1198
1199 // sort elements by depth
1200 for (i = 0; i < count - 1; i++) {
1201 for (j = i + 1; j < count; j++) {
1202 el1 = sortedElements[i];
1203 el2 = sortedElements[j];
1204 if ((*gHudElements)[el1]->worldPosOffset.z < (*gHudElements)[el2]->worldPosOffset.z) {
1205 sortedElements[i] = el2;
1206 sortedElements[j] = el1;
1207 }
1208 }
1209 }
1210
1211 // render the sorted elements
1212 for (i = 0; i < count; i++) {
1213 elem = (*gHudElements)[sortedElements[i]];
1214
1215 if (elem->readPos == NULL) {
1216 break;
1217 }
1218
1219 if (!(elem->flags & HUD_ELEMENT_FLAG_RESIZING)) {
1220 if (elem->flags & HUD_ELEMENT_FLAG_CUSTOM_SIZE) {
1221 texSizeX = elem->customImageSize.x;
1222 texSizeY = elem->customImageSize.y;
1223 } else {
1224 texSizeX = HudElemSizes[elem->tileSizePreset].width;
1225 texSizeY = HudElemSizes[elem->tileSizePreset].height;
1226 }
1227
1228 if (elem->flags & HUD_ELEMENT_FLAG_SCALED) {
1229 drawSizeX = elem->sizeX;
1230 drawSizeY = elem->sizeY;
1231 } else if (elem->flags & HUD_ELEMENT_FLAG_CUSTOM_SIZE) {
1232 drawSizeX = elem->customDrawSize.x;
1233 drawSizeY = elem->customDrawSize.y;
1234 } else {
1235 drawSizeX = HudElemSizes[elem->drawSizePreset].width;
1236 drawSizeY = HudElemSizes[elem->drawSizePreset].height;
1237 }
1238
1239 offsetX = -drawSizeX / 2;
1240 offsetY = -drawSizeY / 2;
1241
1242 if (elem->flags & HUD_ELEMENT_FLAG_REPEATED) {
1243 if (elem->flags & HUD_ELEMENT_FLAG_DROP_SHADOW) {
1245 }
1247 } else {
1248 if (elem->flags & HUD_ELEMENT_FLAG_DROP_SHADOW) {
1250 }
1252 }
1253 } else {
1255
1256 if (elem->flags & HUD_ELEMENT_FLAG_CUSTOM_SIZE) {
1257 texSizeX = elem->customImageSize.x;
1258 texSizeY = elem->customImageSize.y;
1259 } else {
1260 texSizeX = HudElemSizes[elem->tileSizePreset].width;
1261 texSizeY = HudElemSizes[elem->tileSizePreset].height;
1262 }
1263
1264 drawSizeX = elem->dynamicSize.x;
1265 drawSizeY = elem->dynamicSize.y;
1266
1267 offsetX = -elem->dynamicSize.x / 2;
1268 offsetY = -elem->dynamicSize.y / 2;
1269
1272
1273 xScaled = 1.0f / xScaled;
1274 yScaled = 1.0f / yScaled;
1275
1276 elem->widthScale = X10(xScaled);
1277 elem->heightScale = X10(yScaled);
1278
1279 if (elem->flags & HUD_ELEMENT_FLAG_DROP_SHADOW) {
1281 }
1283 }
1284 }
1285}
1286
1288 s32 i, count, j;
1290 s32 el1, el2;
1292 s32 drawSizeX, drawSizeY, offsetX, offsetY;
1294
1296
1297 // gather appropriate hud elements
1298 count = 0;
1299 for (i = 0; i < ARRAY_COUNT(*gHudElements); i++) {
1300 elem = (*gHudElements)[i];
1301 if (elem == NULL) {
1302 continue;
1303 }
1304
1305 if (elem->flags == 0 || elem->flags & HUD_ELEMENT_FLAG_DISABLED) {
1306 continue;
1307 }
1308
1310 continue;
1311 }
1312
1313 if (elem->flags & HUD_ELEMENT_FLAG_MANUAL_RENDER) {
1314 continue;
1315 }
1316
1317 if (elem->flags & HUD_ELEMENT_FLAG_TRANSFORM) {
1318 continue;
1319 }
1320
1321 if (!(elem->flags & HUD_ELEMENT_FLAG_FRONTUI) || elem->drawSizePreset < 0) {
1322 continue;
1323 }
1324
1325 // add element to list
1326 sortedElements[count++] = i;
1327 }
1328
1329 // sort elements by depth
1330 for (i = 0; i < count - 1; i++) {
1331 for (j = i + 1; j < count; j++) {
1332 el1 = sortedElements[i];
1333 el2 = sortedElements[j];
1334 if ((*gHudElements)[el1]->worldPosOffset.z < (*gHudElements)[el2]->worldPosOffset.z) {
1335 sortedElements[i] = el2;
1336 sortedElements[j] = el1;
1337 }
1338 }
1339 }
1340
1341 // render the sorted elements
1342 for (i = 0; i < count; i++) {
1343 elem = (*gHudElements)[sortedElements[i]];
1344 if (!(elem->flags & HUD_ELEMENT_FLAG_RESIZING)) {
1345 if (elem->flags & HUD_ELEMENT_FLAG_CUSTOM_SIZE) {
1346 texSizeX = elem->customImageSize.x;
1347 texSizeY = elem->customImageSize.y;
1348 } else {
1349 texSizeX = HudElemSizes[elem->tileSizePreset].width;
1350 texSizeY = HudElemSizes[elem->tileSizePreset].height;
1351 }
1352
1353 if (elem->flags & HUD_ELEMENT_FLAG_SCALED) {
1354 drawSizeX = elem->sizeX;
1355 drawSizeY = elem->sizeY;
1356 offsetX = -drawSizeX / 2;
1357 offsetY = -drawSizeY / 2;
1358 } else if (elem->flags & HUD_ELEMENT_FLAG_CUSTOM_SIZE) {
1359 drawSizeX = elem->customDrawSize.x;
1360 drawSizeY = elem->customDrawSize.y;
1361 offsetX = -drawSizeX / 2;
1362 offsetY = -drawSizeY / 2;
1363 } else {
1364 drawSizeX = HudElemSizes[elem->drawSizePreset].width;
1365 drawSizeY = HudElemSizes[elem->drawSizePreset].height;
1366 offsetX = -drawSizeX / 2;
1367 offsetY = -drawSizeY / 2;
1368 }
1369
1370 if (elem->flags & HUD_ELEMENT_FLAG_REPEATED) {
1371 if (elem->flags & HUD_ELEMENT_FLAG_DROP_SHADOW) {
1373 }
1375 } else {
1376 if (elem->flags & HUD_ELEMENT_FLAG_DROP_SHADOW) {
1378 }
1380 }
1381 } else {
1383
1384 if (elem->flags & HUD_ELEMENT_FLAG_CUSTOM_SIZE) {
1385 texSizeX = elem->customImageSize.x;
1386 texSizeY = elem->customImageSize.y;
1387 } else {
1388 texSizeX = HudElemSizes[elem->drawSizePreset].width;
1389 texSizeY = HudElemSizes[elem->drawSizePreset].height;
1390 }
1391
1392 drawSizeX = elem->dynamicSize.x;
1393 drawSizeY = elem->dynamicSize.y;
1394
1395 offsetX = -elem->dynamicSize.x / 2;
1396 offsetY = -elem->dynamicSize.y / 2;
1397
1400
1401 xScaled = 1.0f / xScaled;
1402 yScaled = 1.0f / yScaled;
1403
1404 elem->widthScale = X10(xScaled);
1405 elem->heightScale = X10(yScaled);
1406
1407 if (elem->flags & HUD_ELEMENT_FLAG_DROP_SHADOW) {
1409 }
1411 }
1412 }
1413}
1414
1428 s32 height, width;
1429 HudTransform* transform;
1430 s32 mode;
1431 PAL_PTR palette;
1432 Vtx* vtx;
1433
1434 if (elem->flags & HUD_ELEMENT_FLAG_FILTER_TEX) {
1436 } else {
1438 }
1439
1440 if (elem->flags & HUD_ELEMENT_FLAG_RESIZING) {
1441 if (elem->flags & HUD_ELEMENT_FLAG_CUSTOM_SIZE) {
1442 xScaleFactor = elem->customImageSize.x;
1443 yScaleFactor = elem->customImageSize.y;
1444 } else {
1445 xScaleFactor = HudElemSizes[elem->tileSizePreset].width;
1446 yScaleFactor = HudElemSizes[elem->tileSizePreset].height;
1447 }
1448 xScaleFactor = elem->dynamicSize.x / xScaleFactor;
1449 yScaleFactor = elem->dynamicSize.y / yScaleFactor;
1450 } else {
1451 xScaleFactor = 1.0f;
1452 yScaleFactor = 1.0f;
1453 }
1454
1455 if (elem->flags & HUD_ELEMENT_FLAG_CUSTOM_SIZE) {
1456 width = elem->customImageSize.x;
1457 height = elem->customImageSize.y;
1458 } else {
1459 width = HudElemSizes[elem->tileSizePreset].width;
1460 height = HudElemSizes[elem->tileSizePreset].height;
1461 }
1462
1463 transform = elem->hudTransform;
1464
1465 guTranslateF(mtxPivotOn, transform->pivot.x, -transform->pivot.y, 0.0f);
1466 guTranslateF(mtxPivotOff, -transform->pivot.x, transform->pivot.y, 0.0f);
1468 mtxTrans,
1469 transform->pos.x + elem->worldPosOffset.x + elem->renderPosX + elem->screenPosOffset.x,
1470 transform->pos.y + elem->worldPosOffset.y - elem->renderPosY - elem->screenPosOffset.y,
1471 transform->pos.z - (elem->worldPosOffset.z / 10.0)
1472 );
1473 guScaleF(mtxScale, elem->uniformScale * xScaleFactor * transform->scale.x,
1474 elem->uniformScale * yScaleFactor * transform->scale.y,
1475 transform->scale.z);
1476 guRotateF(mtxRotX, transform->rot.x, 1.0f, 0.0f, 0.0f);
1477 guRotateF(mtxRotY, transform->rot.y, 0.0f, 1.0f, 0.0f);
1478 guRotateF(mtxRotZ, transform->rot.z, 0.0f, 0.0f, 1.0f);
1479 // combine rotations (possibly with pivot) and scale
1485 // add translation
1490
1491 mode = 0;
1492 if (elem->flags & HUD_ELEMENT_FLAG_FMT_CI4) {
1493 mode = 1;
1494 }
1495 if (elem->flags & HUD_ELEMENT_FLAG_FMT_IA8) {
1496 mode = 2;
1497 }
1498
1499 switch (mode) {
1500 case 1:
1501 if (elem->flags & HUD_ELEMENT_FLAG_NO_FOLD) {
1502 if (elem->flags & HUD_ELEMENT_FLAG_TRANSPARENT) {
1503 imgfx_update(0, IMGFX_SET_ALPHA, 255, 255, 255, elem->opacity, 0);
1504 } else {
1505 imgfx_update(0, IMGFX_CLEAR, 0, 0, 0, 0, 0);
1506 }
1507 } else {
1508 if (elem->flags & HUD_ELEMENT_FLAG_TRANSPARENT) {
1509 imgfx_update(transform->imgfxIdx, IMGFX_SET_ALPHA, 255, 255, 255, elem->opacity, 0);
1510 } else {
1511 imgfx_update(transform->imgfxIdx, IMGFX_CLEAR, 0, 0, 0, 0, 0);
1512 }
1513 }
1514
1515 ifxImg.raster = elem->imageAddr;
1516 palette = elem->paletteAddr;
1517 ifxImg.width = width;
1518 ifxImg.height = height;
1519 ifxImg.xOffset = -width / 2;
1520 ifxImg.yOffset = height / 2;
1521 ifxImg.alpha = 255;
1522 ifxImg.palette = palette;
1523
1524 if (elem->flags & HUD_ELEMENT_FLAG_NO_FOLD) {
1525 if (elem->flags & HUD_ELEMENT_FLAG_ANTIALIASING) {
1527 } else {
1529 }
1530 } else {
1532 }
1533 break;
1534 case 2:
1539
1540 vtx = transform->quadBuffers[FrameQuadIndex].vtx;
1541
1542 vtx[0].v.ob[0] = -width / 2;
1543 vtx[0].v.ob[1] = -height / 2;
1544 vtx[0].v.ob[2] = 0;
1545 vtx[0].v.tc[0] = 0;
1546 vtx[0].v.tc[1] = height * 32;
1547
1548 vtx[1].v.ob[0] = (width / 2) - 1;
1549 vtx[1].v.ob[1] = -height / 2;
1550 vtx[1].v.ob[2] = 0;
1551 vtx[1].v.tc[0] = width * 32;
1552 vtx[1].v.tc[1] = height * 32;
1553
1554 vtx[2].v.ob[0] = (width / 2) - 1;
1555 vtx[2].v.ob[1] = (height / 2) - 1;
1556 vtx[2].v.ob[2] = 0;
1557 vtx[2].v.tc[0] = width * 32;
1558 vtx[2].v.tc[1] = 0;
1559
1560 vtx[3].v.ob[0] = -width / 2;
1561 vtx[3].v.ob[1] = (height / 2) - 1;
1562 vtx[3].v.ob[2] = 0;
1563 vtx[3].v.tc[0] = 0;
1564 vtx[3].v.tc[1] = 0;
1565
1568 gDPSetPrimColor(gMainGfxPos++, 0, 0, elem->tint.r, elem->tint.g, elem->tint.b, elem->opacity);
1569
1570 if (elem->flags & HUD_ELEMENT_FLAG_TRANSPARENT) {
1571 if (elem->flags & HUD_ELEMENT_FLAG_ANTIALIASING) {
1573 } else {
1575 }
1576 } else {
1577 if (elem->flags & HUD_ELEMENT_FLAG_ANTIALIASING) {
1579 } else {
1581 }
1582 }
1583
1584 gDPLoadTextureBlock(gMainGfxPos++, elem->imageAddr, G_IM_FMT_IA, G_IM_SIZ_8b, width, height, 0,
1587
1589 gSPVertex(gMainGfxPos++, &transform->quadBuffers[FrameQuadIndex], 4, 0);
1590 gSP1Triangle(gMainGfxPos++, 0, 1, 2, 0);
1591 gSP1Triangle(gMainGfxPos++, 0, 2, 3, 0);
1592 break;
1593 }
1594
1597}
1598
1600{
1602 s32 el1, el2;
1603 s32 count;
1604 s32 i, j;
1605
1606 count = 0;
1607 for (i = 0; i < ARRAY_COUNT(*gHudElements); i++) {
1608 elem = (*gHudElements)[i];
1609 if (elem == NULL) {
1610 continue;
1611 }
1612
1613 if (elem->flags == 0 || elem->flags & HUD_ELEMENT_FLAG_DISABLED) {
1614 continue;
1615 }
1616
1618 continue;
1619 }
1620
1621 if (elem->flags & HUD_ELEMENT_FLAG_MANUAL_RENDER) {
1622 continue;
1623 }
1624
1625 if (!(elem->flags & HUD_ELEMENT_FLAG_TRANSFORM)) {
1626 continue;
1627 }
1628
1629 if (!isBattle) {
1630 if (elem->flags & HUD_ELEMENT_FLAG_BATTLE_CAM) {
1631 continue;
1632 }
1633 } else {
1634 if (!(elem->flags & HUD_ELEMENT_FLAG_BATTLE_CAM)) {
1635 continue;
1636 }
1637 }
1638
1639 if (elem->flags & HUD_ELEMENT_FLAG_FRONTUI || elem->drawSizePreset < 0) {
1640 continue;
1641 }
1642
1643 // add element to list
1644 sortedElements[count++] = i;
1645 }
1646
1647 // sort elements by depth
1648 if (count != 0) {
1649 for (i = 0; i < count - 1; i++) {
1650 for (j = i + 1; j < count; j++) {
1651 el1 = sortedElements[i];
1652 el2 = sortedElements[j];
1653
1654 if ((*gHudElements)[el1]->worldPosOffset.z < (*gHudElements)[el2]->worldPosOffset.z) {
1655 sortedElements[i] = el2;
1656 sortedElements[j] = el1;
1657 }
1658 }
1659 }
1660 }
1661
1662 return count;
1663}
1664
1668 s32 flags;
1669 s32 count, i;
1670
1671 if (gCurrentCamID == CAM_HUD) {
1673
1674 if (count != 0) {
1683
1684 for (i = 0; i < count; i++) {
1686 }
1687 }
1688 }
1689
1690 if (gCurrentCamID == CAM_BATTLE) {
1692
1693 if (count != 0) {
1702
1703 for (i = 0; i < count; i++) {
1705 }
1706 }
1707 }
1708}
1709
1712
1713 if (includeSetup) {
1714 if (camera->flags == 0 || (camera->flags & CAMERA_FLAG_DISABLED)) {
1715 return;
1716 }
1717
1719
1731 //clear Z buffer inside camera viewport
1735 gDPFillRectangle(gMainGfxPos++, camera->viewportStartX, camera->viewportStartY,
1736 camera->viewportStartX + camera->viewportW - 1,
1737 camera->viewportStartY + camera->viewportH - 1);
1739
1742
1743 guOrthoF(camera->mtxPerspective, 0.0f, 320.0f, -240.0f, 0.0f, -1000.0f, 1000.0f, 1.0f);
1745
1748 // scissor to insets
1764 }
1765
1766 if (elemID >= 0) {
1768
1770 elem = (*gHudElements)[elemID];
1771
1772 if (elem == NULL) {
1773 return;
1774 }
1775
1776 if (elem->flags == 0 || elem->flags & HUD_ELEMENT_FLAG_DISABLED) {
1777 return;
1778 }
1779
1781 return;
1782 }
1783
1784 if (!(elem->flags & HUD_ELEMENT_FLAG_MANUAL_RENDER)) {
1785 return;
1786 }
1787
1788 if (!(elem->flags & HUD_ELEMENT_FLAG_TRANSFORM)) {
1789 return;
1790 }
1791
1792 if (elem->flags & HUD_ELEMENT_FLAG_FRONTUI || elem->drawSizePreset < 0) {
1793 return;
1794 }
1795
1797 }
1798}
1799
1803
1807
1811
1815
1817 HudElement* elem = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
1820 s32 offsetX, offsetY;
1821
1822 if (elem->flags == 0 || elem->flags & HUD_ELEMENT_FLAG_DISABLED) {
1823 return;
1824 }
1825
1827 return;
1828 }
1829
1830 if (elem->drawSizePreset >= 0) {
1834 }
1847 }
1848
1849 if (!(elem->flags & HUD_ELEMENT_FLAG_RESIZING)) {
1850 if (elem->flags & HUD_ELEMENT_FLAG_CUSTOM_SIZE) {
1851 texSizeX = elem->customImageSize.x;
1852 texSizeY = elem->customImageSize.y;
1853 } else {
1854 texSizeX = HudElemSizes[elem->tileSizePreset].width;
1855 texSizeY = HudElemSizes[elem->tileSizePreset].height;
1856 }
1857
1858 if (elem->flags & HUD_ELEMENT_FLAG_SCALED) {
1859 drawSizeX = elem->sizeX;
1860 drawSizeY = elem->sizeY;
1861 } else if (elem->flags & HUD_ELEMENT_FLAG_CUSTOM_SIZE) {
1862 drawSizeX = elem->customDrawSize.x;
1863 drawSizeY = elem->customDrawSize.y;
1864 } else {
1865 drawSizeX = HudElemSizes[elem->drawSizePreset].width;
1866 drawSizeY = HudElemSizes[elem->drawSizePreset].height;
1867 }
1868
1869 offsetX = -drawSizeX / 2;
1870 offsetY = -drawSizeY / 2;
1871
1872 if (elem->flags & HUD_ELEMENT_FLAG_REPEATED) {
1873 if (elem->flags & HUD_ELEMENT_FLAG_DROP_SHADOW) {
1875 }
1877 } else {
1878 if (elem->flags & HUD_ELEMENT_FLAG_DROP_SHADOW) {
1880 }
1882 }
1883 } else {
1885
1886 if (elem->flags & HUD_ELEMENT_FLAG_CUSTOM_SIZE) {
1887 texSizeX = elem->customImageSize.x;
1888 texSizeY = elem->customImageSize.y;
1889 } else {
1890 texSizeX = HudElemSizes[elem->tileSizePreset].width;
1891 texSizeY = HudElemSizes[elem->tileSizePreset].height;
1892 }
1893
1894 drawSizeX = elem->dynamicSize.x;
1895 drawSizeY = elem->dynamicSize.y;
1896
1897 offsetX = -elem->dynamicSize.x / 2;
1898 offsetY = -elem->dynamicSize.y / 2;
1899
1902
1903 xScaled = 1.0f / xScaled;
1904 yScaled = 1.0f / yScaled;
1905
1906 elem->widthScale = X10(xScaled);
1907 elem->heightScale = X10(yScaled);
1908
1909 if (elem->flags & HUD_ELEMENT_FLAG_DROP_SHADOW) {
1911 }
1913 }
1914 }
1915}
1916
1920
1924
1928
1930 HudElement* hudElement = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
1931
1932 if (anim == NULL) {
1933 anim = &HES_Empty;
1934 }
1935
1937 hudElement->widthScale = X10(1.0f);
1938 hudElement->heightScale = X10(1.0f);
1939 hudElement->readPos = anim;
1940 hudElement->anim = anim;
1941 hudElement->loopStartPos = anim;
1942 hudElement->screenPosOffset.x = 0;
1943 hudElement->screenPosOffset.y = 0;
1944 hudElement->worldPosOffset.x = 0;
1945 hudElement->worldPosOffset.y = 0;
1947 hudElement->uniformScale = 1.0f;
1950
1951 while (hud_element_update(hudElement) != 0) {}
1952}
1953
1957
1961
1971
1973 HudElement* hudElement = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
1974
1976 hudElement->renderPosY = y;
1977}
1978
1980 HudElement* hudElement = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
1981
1982 *x = hudElement->renderPosX;
1983 *y = hudElement->renderPosY;
1984}
1985
1987 (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK]->worldPosOffset.z = z;
1988}
1989
1991 (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK]->flags |= flags;
1992}
1993
1995 (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK]->flags &= ~flags;
1996}
1997
1999 s32 i;
2000
2011
2012 for (i = 0; i < MAX_HUD_CACHE_ENTRIES; i++) {
2015 }
2016 } else {
2017 if (HudElemAuxCache == NULL) {
2021 } else {
2023 }
2030
2031 for (i = 0; i < MAX_HUD_CACHE_ENTRIES; i++) {
2034 }
2035 }
2036}
2037
2038void hud_element_set_scale(s32 index, f32 scale) {
2039 HudElement* elem = (*gHudElements)[index & ~HUD_ELEMENT_BATTLE_ID_MASK];
2040 s32 drawSizeX;
2041 s32 drawSizeY;
2042 s32 imgSizeX;
2043 s32 imgSizeY;
2045
2046 elem->uniformScale = scale;
2047 if (elem->flags & HUD_ELEMENT_FLAG_CUSTOM_SIZE) {
2048 imgSizeX = elem->customImageSize.x;
2049 imgSizeY = elem->customImageSize.y;
2050 drawSizeX = elem->customDrawSize.x;
2051 drawSizeY = elem->customDrawSize.y;
2052 } else {
2053 imgSizeX = HudElemSizes[elem->tileSizePreset].width;
2054 imgSizeY = HudElemSizes[elem->tileSizePreset].height;
2055 drawSizeX = HudElemSizes[elem->drawSizePreset].width;
2056 drawSizeY = HudElemSizes[elem->drawSizePreset].height;
2057 }
2058 elem->sizeX = drawSizeX * scale;
2059 elem->sizeY = drawSizeY * scale;
2062
2063 xScaled = ((f32) drawSizeX / (f32) imgSizeX) * scale;
2064 yScaled = ((f32) drawSizeY / (f32) imgSizeY) * scale;
2065
2066 xScaled = 1.0f / xScaled;
2067 yScaled = 1.0f / yScaled;
2068
2069 elem->widthScale = X10(xScaled);
2070 elem->heightScale = X10(yScaled);
2071}
2072
2074 HudElement* hudElement = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
2075
2076 hudElement->widthScale = X10(1.0f);
2077 hudElement->heightScale = X10(1.0f);
2078 hudElement->tileSizePreset = sizePreset;
2079 hudElement->drawSizePreset = sizePreset;
2080 hudElement->uniformScale = 1.0f;
2083}
2084
2086 return ((*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK]->flags >> 24) & 0xF;
2087}
2088
2090 HudElement* hudElement = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
2091
2093 hudElement->flags |= value << 24;
2094}
2095
2096void hud_element_set_alpha(s32 id, s32 opacity) {
2097 HudElement* hudElement = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
2098
2100 hudElement->opacity = opacity;
2101
2102 if (opacity == 255) {
2104 }
2105}
2106
2108 HudElement* hudElement = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
2109
2110 hudElement->tint.r = r;
2111 hudElement->tint.g = g;
2112 hudElement->tint.b = b;
2113}
2114
2116 HudElement* element = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
2117 HudTransform* transform = general_heap_malloc(sizeof(*transform));
2118
2119 element->hudTransform = transform;
2120 ASSERT(transform != NULL);
2122 transform->imgfxIdx = imgfx_get_free_instances(1);
2123 transform->pos.x = 0.0f;
2124 transform->pos.y = 0.0f;
2125 transform->pos.z = 0.0f;
2126 transform->rot.x = 0.0f;
2127 transform->rot.y = 0.0f;
2128 transform->rot.z = 0.0f;
2129 transform->scale.x = 1.0f;
2130 transform->scale.y = 1.0f;
2131 transform->scale.z = 1.0f;
2132 transform->pivot.x = 0;
2133 transform->pivot.y = 0;
2135}
2136
2138 HudElement* element = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
2139 HudTransform* transform = general_heap_malloc(sizeof(*transform));
2140
2141 element->hudTransform = transform;
2142 ASSERT(transform != NULL);
2144 transform->imgfxIdx = 0;
2145 transform->pos.x = 0.0f;
2146 transform->pos.y = 0.0f;
2147 transform->pos.z = 0.0f;
2148 transform->rot.x = 0.0f;
2149 transform->rot.y = 0.0f;
2150 transform->rot.z = 0.0f;
2151 transform->scale.x = 1.0f;
2152 transform->scale.y = 1.0f;
2153 transform->scale.z = 1.0f;
2155}
2156
2158 HudElement* element = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
2159 HudTransform* transform = general_heap_malloc(sizeof(*transform));
2160
2161 element->hudTransform = transform;
2162 ASSERT(transform != NULL);
2164 transform->imgfxIdx = 0;
2165 transform->pos.x = 0.0f;
2166 transform->pos.y = 0.0f;
2167 transform->pos.z = 0.0f;
2168 transform->rot.x = 0.0f;
2169 transform->rot.y = 0.0f;
2170 transform->rot.z = 0.0f;
2171 transform->scale.x = 1.0f;
2172 transform->scale.y = 1.0f;
2173 transform->scale.z = 1.0f;
2175}
2176
2178 HudElement* hudElement = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
2179 HudTransform* hudTransform = hudElement->hudTransform;
2180
2181 if (!(hudElement->flags & HUD_ELEMENT_FLAG_NO_FOLD)) {
2182 imgfx_release_instance(hudTransform->imgfxIdx);
2183 }
2184
2185 heap_free(hudElement->hudTransform);
2186 hudElement->hudTransform = NULL;
2188}
2189
2191 HudElement* element = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
2192 HudTransform* transform = element->hudTransform;
2193
2194 if (element->flags & HUD_ELEMENT_FLAG_TRANSFORM) {
2195 transform->pos.x = x;
2196 transform->pos.y = y;
2197 transform->pos.z = z;
2198 }
2199}
2200
2202 HudElement* element = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
2203 HudTransform* transform = element->hudTransform;
2204
2205 if (element->flags & HUD_ELEMENT_FLAG_TRANSFORM) {
2206 transform->scale.x = x;
2207 transform->scale.y = y;
2208 transform->scale.z = z;
2209 }
2210}
2211
2213 HudElement* element = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
2214 HudTransform* transform = element->hudTransform;
2215
2216 if (element->flags & HUD_ELEMENT_FLAG_TRANSFORM) {
2217 transform->rot.x = x;
2218 transform->rot.y = y;
2219 transform->rot.z = z;
2220 }
2221}
2222
2224 HudElement* element = (*gHudElements)[id & ~HUD_ELEMENT_BATTLE_ID_MASK];
2225 HudTransform* transform = element->hudTransform;
2226
2227 if (element->flags & HUD_ELEMENT_FLAG_TRANSFORM) {
2228 transform->pivot.x = dx;
2229 transform->pivot.y = dy;
2230 }
2231}
2232
2236
2237void hud_element_set_aux_cache(void* base, s32 size) {
2238 HudElemAuxCache = (u8*)base;
2239 if (base == NULL) {
2240 HudElemCacheCapacity = 0x11000;
2241 } else {
2242 HudElemCacheCapacity = size;
2243 }
2244}
BSS s32 PopupMenu_SelectedIndex
u16 * nuGfxCfb_ptr
Definition cam_main.c:13
Mtx matrixStack[0x200]
#define PAL_PTR
#define IMG_PTR
s32 b32
f32 Matrix4f[4][4]
s8 flags
Definition demo_api.c:15
Vec3s pos
Definition demo_api.c:17
#define general_heap_malloc
#define guRotateF
#define guOrthoF
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define rand_int
#define guScaleF
#define ASSERT(condition)
@ IMGFX_SET_ALPHA
Definition enums.h:4709
@ IMGFX_CLEAR
Definition enums.h:4702
@ CAMERA_FLAG_DISABLED
Definition enums.h:4306
@ CAMERA_FLAG_LEAD_PLAYER
Definition enums.h:4307
@ CAM_UPDATE_INTERP_POS
Definition enums.h:4332
@ CONTEXT_WORLD
Definition enums.h:3562
@ CAM_HUD
Definition enums.h:1829
@ CAM_BATTLE
Definition enums.h:1827
@ IMGFX_FLAG_40
Definition enums.h:4684
s32 imgfx_appendGfx_component(s32, ImgFXTexture *, u32, Matrix4f)
Definition imgfx.c:703
s32 imgfx_get_free_instances(s32)
Definition imgfx.c:337
s32 heap_free(void *ptr)
Definition heap.c:42
s32 general_heap_free(void *data)
Definition heap.c:18
void imgfx_release_instance(u32)
Definition imgfx.c:385
void imgfx_update(u32, ImgFXType, s32, s32, s32, s32, s32)
Definition imgfx.c:486
void * heap_malloc(s32 size)
Definition heap.c:34
void set_cam_viewport(s16 id, s16 x, s16 y, s16 width, s16 height)
Definition cam_main.c:372
BSS HudCacheEntry gHudElementCacheTablePaletteWorld[192]
void hud_element_draw_complex_hud_next(s32 hid)
void hud_element_setup_cam(void)
u8 * gHudElementCacheBuffer
void hud_element_create_transform_C(s32 id)
void hud_element_get_render_pos(s32 id, s32 *x, s32 *y)
void hud_element_set_aux_cache(void *base, s32 size)
HudCacheEntry * gHudElementCacheTablePalette
BSS HudCacheEntry gHudElementCacheTableRasterWorld[192]
void hud_element_draw_complex_battle_first(s32 hid)
void hud_element_create_transform_A(s32 id)
void hud_element_set_scale(s32 index, f32 scale)
void hud_element_set_alpha(s32 id, s32 opacity)
HudElementSize HudElemSizes[]
Definition hud_element.c:21
void render_hud_elements_frontUI(void)
BSS HudElementList * gHudElements
s32 hud_element_update(HudElement *hudElement)
s32 * gHudElementCacheSize
void hud_element_draw_without_clipping(s32 id)
void hud_element_set_script(s32 id, HudScript *anim)
void update_hud_elements(void)
void hud_element_set_variable(s32 id, s32 value)
Vtx HudElemTemplateQuad[]
Definition hud_element.c:65
void render_hud_elements_backUI(void)
HudCacheEntry * gHudElementCacheTableRaster
void hud_element_draw_complex_battle_next(s32 hid)
#define MAX_HUD_CACHE_ENTRIES
Definition hud_element.c:6
BSS u8 * gHudElementCacheBufferWorld
void hud_element_set_render_depth(s32 id, s32 z)
void hud_element_create_transform_B(s32 id)
void immediately_render_complex_hud_element(s32 elemID, b32 includeSetup, s32 camID)
HudScript * hud_element_get_script(s32 id)
Gfx HudElemFrontInitGfx[]
Definition hud_element.c:57
BSS HudElementList gHudElementsWorld
void hud_element_set_transform_pos(s32 id, f32 x, f32 y, f32 z)
void hud_element_clear_cache(void)
s32 HudElemCount
void hud_element_draw_rect(HudElement *hudElement, s16 texSizeX, s16 texSizeY, s16 drawSizeX, s16 drawSizeY, s16 offsetX, s16 offsetY, s32 clamp, s32 dropShadow)
BSS s32 gHudElementCacheSizeBattle
void hud_element_draw_next(s32 id)
void init_hud_element_list(void)
void hud_element_set_tint(s32 id, s32 r, s32 g, s32 b)
BSS HudElementList gHudElementsBattle
void render_complex_hud_element(HudElement *elem)
Gfx HudElemBackInitGfx[]
Definition hud_element.c:50
void hud_element_set_transform_rotation(s32 id, f32 x, f32 y, f32 z)
void hud_element_use_preset_size(s32 id, s8 sizePreset)
BSS s32 gHudElementCacheSizeWorld
BSS HudCacheEntry gHudElementCacheTableRasterBattle[192]
void hud_element_draw_complex_hud_first(s32 hid)
BSS u8 * gHudElementCacheBufferBattle
void hud_element_set_render_pos(s32 id, s32 x, s32 y)
void hud_element_set_transform_rotation_pivot(s32 id, s32 dx, s32 dy)
s32 hud_element_create(HudScript *anim)
Creates a new HUD element and returns its ID.
void hud_element_load_script(HudElement *hudElement, HudScript *anim)
BSS HudCacheEntry gHudElementCacheTablePaletteBattle[192]
HudElement * get_hud_element(s32 id)
void hud_element_set_flags(s32 id, s32 flags)
Turns on the given flags.
void hud_element_clear_flags(s32 id, s32 flags)
Turns off the given flags.
s32 HudElemCacheCapacity
Definition hud_element.c:15
s32 hud_element_get_variable(s32 id)
void hud_element_draw_clipped(s32 id)
void hud_element_set_transform_scale(s32 id, f32 x, f32 y, f32 z)
Lights1 HudElemLights
void hud_element_free(s32 id)
void render_transformed_hud_elements(void)
s32 gather_and_sort_hud_elements(s32 *sortedElements, b32 isBattle)
HudScript HES_Empty
Definition hud_element.c:17
void hud_element_free_transform(s32 id)
void copy_world_hud_element_ref_to_battle(s32 worldID, s32 battleID)
void draw_hud_element_internal(s32 id, s32 clipMode)
void ALT_clear_hud_element_cache(void)
BSS s32 FrameQuadIndex
u8 * HudElemAuxCache
Definition hud_element.c:14
Color_RGB8 tint
@ HUD_ELEMENT_DRAW_NEXT
@ HUD_ELEMENT_DRAW_FIRST_WITH_CLIPPING
@ HUD_ELEMENT_DRAW_FIRST_WITHOUT_CLIPPING
@ HUD_ELEMENT_OP_SetCI
Definition hud_element.h:14
@ HUD_ELEMENT_OP_Restart
Definition hud_element.h:15
@ HUD_ELEMENT_OP_End
Definition hud_element.h:12
@ HUD_ELEMENT_OP_SetPivot
Definition hud_element.h:39
@ HUD_ELEMENT_OP_op_16
Definition hud_element.h:34
@ HUD_ELEMENT_OP_SetVisible
Definition hud_element.h:20
@ HUD_ELEMENT_OP_AddTexelOffsetY
Definition hud_element.h:23
@ HUD_ELEMENT_OP_SetScale
Definition hud_element.h:26
@ HUD_ELEMENT_OP_SetImage
Definition hud_element.h:25
@ HUD_ELEMENT_OP_RandomBranch
Definition hud_element.h:35
@ HUD_ELEMENT_OP_PlaySound
Definition hud_element.h:38
@ HUD_ELEMENT_OP_SetSizesAutoScale
Definition hud_element.h:18
@ HUD_ELEMENT_OP_SetTexelOffset
Definition hud_element.h:24
@ HUD_ELEMENT_OP_RandomDelay
Definition hud_element.h:28
@ HUD_ELEMENT_OP_Loop
Definition hud_element.h:16
@ HUD_ELEMENT_OP_SetFlags
Definition hud_element.h:36
@ HUD_ELEMENT_OP_SetAlpha
Definition hud_element.h:27
@ HUD_ELEMENT_OP_SetTileSize
Definition hud_element.h:17
@ HUD_ELEMENT_OP_SetSizesFixedScale
Definition hud_element.h:19
@ HUD_ELEMENT_OP_RandomRestart
Definition hud_element.h:32
@ HUD_ELEMENT_OP_SetCustomSize
Definition hud_element.h:31
@ HUD_ELEMENT_OP_AddTexelOffsetX
Definition hud_element.h:22
@ HUD_ELEMENT_OP_SetRGBA
Definition hud_element.h:13
@ HUD_ELEMENT_OP_SetVariable
Definition hud_element.h:33
@ HUD_ELEMENT_OP_UseIA8
Definition hud_element.h:30
@ HUD_ELEMENT_OP_ClearFlags
Definition hud_element.h:37
@ HUD_ELEMENT_OP_SetHidden
Definition hud_element.h:21
@ HUD_ELEMENT_OP_Delete
Definition hud_element.h:29
#define HUD_ELEMENT_BATTLE_ID_MASK
Definition hud_element.h:7
HudElement * HudElementList[320]
#define hs_End
@ HUD_ELEMENT_FLAG_ANTIALIASING
Definition hud_element.h:94
@ HUD_ELEMENT_FLAG_DELETE
Definition hud_element.h:89
@ HUD_ELEMENT_FLAG_DISABLED
Definition hud_element.h:72
@ HUD_ELEMENT_FLAG_INVISIBLE
Definition hud_element.h:92
@ HUD_ELEMENT_FLAG_SCALED
Definition hud_element.h:75
@ HUD_ELEMENT_FLAG_FLIPX
Definition hud_element.h:83
@ HUD_ELEMENT_FLAG_MEMOFFSET
Definition hud_element.h:93
@ HUD_ELEMENT_FLAG_FMT_IA8
Definition hud_element.h:90
@ HUD_ELEMENT_FLAG_BATTLE_CAM
Definition hud_element.h:98
@ HUD_ELEMENT_FLAG_CUSTOM_SIZE
Definition hud_element.h:91
@ HUD_ELEMENT_FLAG_REPEATED
Definition hud_element.h:82
@ HUD_ELEMENT_FLAG_INITIALIZED
Definition hud_element.h:71
@ HUD_ELEMENT_FLAG_FLIPY
Definition hud_element.h:84
@ HUD_ELEMENT_FLAG_HIDDEN
Definition hud_element.h:96
@ HUD_ELEMENT_FLAG_DROP_SHADOW
Definition hud_element.h:97
@ HUD_ELEMENT_FLAG_RESIZING
Definition hud_element.h:79
@ HUD_ELEMENT_FLAG_MANUAL_RENDER
Definition hud_element.h:78
@ HUD_ELEMENT_FLAG_NO_FOLD
Definition hud_element.h:88
@ HUD_ELEMENT_FLAG_RESIZE_DIR
Definition hud_element.h:80
@ HUD_ELEMENT_FLAG_ANIMATION_FINISHED
Definition hud_element.h:73
@ HUD_ELEMENT_FLAG_BATTLE
Definition hud_element.h:81
@ HUD_ELEMENT_FLAG_FRONTUI
Definition hud_element.h:77
@ HUD_ELEMENT_FLAG_FMT_CI4
Definition hud_element.h:85
@ HUD_ELEMENT_FLAG_TRANSFORM
Definition hud_element.h:87
@ HUD_ELEMENT_FLAG_FILTER_TEX
Definition hud_element.h:86
@ HUD_ELEMENT_FLAG_TRANSPARENT
Definition hud_element.h:76
Vtx vtx[4]
VtxRect quadBuffers[3]
s32 widthScale
X10.
s32 HudScript[]
Definition hud_element.h:9
u16 * nuGfxZBuffer
Definition main.c:46
void sfx_play_sound(s32 soundID)
#define CAM_NEAR_CLIP
Definition macros.h:129
#define PM_CC_07
Definition macros.h:295
#define SCREEN_YMAX
Definition macros.h:118
#define SCREEN_WIDTH
Definition macros.h:109
#define BSS
Definition macros.h:7
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define PM_CC_01
Definition macros.h:288
#define SCREEN_HEIGHT
Definition macros.h:110
#define PM_CC_32
Definition macros.h:398
#define X10(f)
X.10 fixed-point literal.
Definition macros.h:186
#define SCREEN_YMIN
Definition macros.h:117
#define PM_CC_2F
Definition macros.h:397
#define PM_CC_47
Definition macros.h:487
#define SCREEN_XMIN
Definition macros.h:115
#define SCREEN_XMAX
Definition macros.h:116
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
#define PM_CC_02
Definition macros.h:289
s32 D_80200000
s16 bgColor[3]
Vec3f lookAt_obj_target
union Camera::@17 params
u8 Addr[]
Linker symbol address, as in ld_addrs.h.
Definition types.h:16
GameStatus * gGameStatusPtr
Definition main_loop.c:31
Camera gCameras[4]
Definition cam_main.c:16
Gfx * gMainGfxPos
Definition cam_main.c:14
u16 gMatrixListPos
Definition main_loop.c:44
DisplayContext * gDisplayContext
Definition cam_main.c:15
s16 gCurrentCamID
Definition cam_main.c:12