102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
hud.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
14#include "pcdogs/game/globals.h"
26#include "pcdogs/menu/globals.h"
34#include "pcdogs/ui/functions.h"
35#include "pcdogs/ui/globals.h"
36#include "pcdogs/ui/types.h"
37#include <math.h>
38#include <stdarg.h>
39#include <string.h>
40
41// Original pcdogs.exe: 0x427b90
42// Animates and renders the bone counter, catching up to larger totals one increment every three updates. A smaller total does not trigger a decrement.
43void UI_UpdateBoneCounter(int32_t bone_count)
44{
45 int16_t animation_frame_or_displayed_count = UI_BoneCounterAnimState;
46
47 if (animation_frame_or_displayed_count >= UI_COUNTER_ANIMATION_FINISHED)
48 return;
49
50 struct Graphics_Render_SpriteContext *sprite = (struct Graphics_Render_SpriteContext *)Shared_FontDataCursor[3].material_table_entry;
51
52 // Frames 0-2: Fade in (slide from left)
53 UI_BoneCounterAnimState = animation_frame_or_displayed_count + 1;
54
55 int16_t slide_offset_x;
56
57 if (animation_frame_or_displayed_count + 1 < UI_COUNTER_SLIDE_FRAMES)
58 {
59 struct Material_RuntimeDescriptor *slide_in_descriptor;
60
61 if (sprite)
62 slide_in_descriptor = sprite->textureDescriptor;
63
64 int32_t slide_in_width;
65
66 if (!sprite || !slide_in_descriptor)
67 slide_in_width = 1;
68 else
69 {
70 int32_t slide_in_width_minus_one = (uint8_t)(slide_in_descriptor->dimensions_minus_1.width);
71
72 slide_in_width = slide_in_width_minus_one + 1;
73 }
74
75 slide_offset_x = (int16_t)(((int32_t)(animation_frame_or_displayed_count + 1) - UI_COUNTER_SLIDE_FRAMES) * slide_in_width / UI_COUNTER_SLIDE_FRAMES);
76 }
77 else if (animation_frame_or_displayed_count + 1 >= UI_COUNTER_SLIDE_OUT_FRAME)
78 {
79 struct Material_RuntimeDescriptor *slide_out_descriptor;
80
81 if (sprite)
82 slide_out_descriptor = sprite->textureDescriptor;
83
84 int32_t slide_out_width;
85
86 if (!sprite || !slide_out_descriptor)
87 slide_out_width = 1;
88 else
89 {
90 int32_t slide_out_width_minus_one = (uint8_t)(slide_out_descriptor->dimensions_minus_1.width);
91
92 slide_out_width = slide_out_width_minus_one + 1;
93 }
94
95 slide_offset_x = (int16_t)((UI_COUNTER_SLIDE_OUT_FRAME - (int32_t)(animation_frame_or_displayed_count + 1)) * slide_out_width / UI_COUNTER_SLIDE_FRAMES);
96
97 if (bone_count > (int32_t)g_boneCounterUIState)
99 }
100 else
101 {
102 slide_offset_x = 0;
103
104 if (animation_frame_or_displayed_count == UI_COUNTER_INCREMENT_FRAME)
105 {
106 animation_frame_or_displayed_count = g_boneCounterUIState;
107
108 if (bone_count > (int32_t)animation_frame_or_displayed_count)
109 {
110 g_boneCounterUIState = animation_frame_or_displayed_count + 1;
111
112 if ((int32_t)(int16_t)(animation_frame_or_displayed_count + 1) != bone_count)
114 }
115 }
116 else if (animation_frame_or_displayed_count + 1 > UI_COUNTER_INCREMENT_CYCLE_END_FRAME && bone_count > (int32_t)g_boneCounterUIState)
118 }
119
120 int32_t icon_window_width = Graphics_WindowWidth;
121 int32_t icon_window_height = Graphics_WindowHeight;
122 uint32_t left_margin_x =
123 (uint32_t)(uint16_t)((int64_t)(icon_window_width * 0x14) / icon_window_width);
124 int16_t icon_draw_x = slide_offset_x + (uint16_t)left_margin_x;
125
127 ((int64_t)(icon_window_height * 0x24) / icon_window_height) << UI_PACKED_Y_SHIFT | (left_margin_x & UI_PACKED_COORDINATE_HIGH_MASK) | (uint32_t)(uint16_t)icon_draw_x,
128 0, sprite, 0, 0, 0);
129
130 struct Material_RuntimeDescriptor *texture_descriptor;
131
132 if (sprite)
133 texture_descriptor = sprite->textureDescriptor;
134
135 int32_t icon_width;
136
137 if (!sprite || !texture_descriptor)
138 icon_width = 1;
139 else
140 {
141 int32_t icon_width_minus_one = (uint8_t)(texture_descriptor->dimensions_minus_1.width);
142
143 icon_width = icon_width_minus_one + 1;
144 }
145
146 int32_t number_window_width = Graphics_WindowWidth;
147 int32_t number_window_height = Graphics_WindowHeight;
148
150 ((uint32_t)(uint16_t)((int64_t)(number_window_width * 0x14) / number_window_width) & UI_PACKED_COORDINATE_HIGH_MASK) | (uint32_t)(uint16_t)((int16_t)(icon_width >> 1) + icon_draw_x) | ((int64_t)(number_window_height * 0x24) / number_window_height) << UI_PACKED_Y_SHIFT,
151 (int32_t)g_boneCounterUIState);
152}
153
154// Original pcdogs.exe: 0x427f10
155// Animates and renders the rescued-puppy counter, catching up to larger totals one increment every three updates. A smaller total does not trigger a decrement.
156void UI_UpdatePuppyCounter(int32_t puppy_count)
157{
158 int16_t animation_frame_or_displayed_count = UI_PuppyCounterAnimState;
159
160 if (animation_frame_or_displayed_count >= UI_COUNTER_ANIMATION_FINISHED)
161 return;
162
163 struct Graphics_Render_SpriteContext *sprite = (struct Graphics_Render_SpriteContext *)Shared_FontDataCursor[2].material_table_entry;
164
165 UI_PuppyCounterAnimState = animation_frame_or_displayed_count + 1;
166
167 int16_t slide_offset_x;
168
169 if (animation_frame_or_displayed_count + 1 < UI_COUNTER_SLIDE_FRAMES)
170 {
171 struct Material_RuntimeDescriptor *slide_in_descriptor;
172
173 if (sprite)
174 slide_in_descriptor = sprite->textureDescriptor;
175
176 int32_t slide_in_width;
177
178 if (!sprite || !slide_in_descriptor)
179 slide_in_width = 1;
180 else
181 {
182 int32_t slide_in_width_minus_one = (uint8_t)(slide_in_descriptor->dimensions_minus_1.width);
183
184 slide_in_width = slide_in_width_minus_one + 1;
185 }
186
187 slide_offset_x = (int16_t)(((int32_t)(animation_frame_or_displayed_count + 1) - UI_COUNTER_SLIDE_FRAMES) * slide_in_width / UI_COUNTER_SLIDE_FRAMES);
188 }
189 else if (animation_frame_or_displayed_count + 1 >= UI_COUNTER_SLIDE_OUT_FRAME)
190 {
191 struct Material_RuntimeDescriptor *slide_out_descriptor;
192
193 if (sprite)
194 slide_out_descriptor = sprite->textureDescriptor;
195
196 int32_t slide_out_width;
197
198 if (!sprite || !slide_out_descriptor)
199 slide_out_width = 1;
200 else
201 {
202 int32_t slide_out_width_minus_one = (uint8_t)(slide_out_descriptor->dimensions_minus_1.width);
203
204 slide_out_width = slide_out_width_minus_one + 1;
205 }
206
207 slide_offset_x = (int16_t)((UI_COUNTER_SLIDE_OUT_FRAME - (int32_t)(animation_frame_or_displayed_count + 1)) * slide_out_width / UI_COUNTER_SLIDE_FRAMES);
208
209 if (puppy_count > (int32_t)g_puppyCounterUIState)
211 }
212 else
213 {
214 slide_offset_x = 0;
215
216 if (animation_frame_or_displayed_count == UI_COUNTER_INCREMENT_FRAME)
217 {
218 animation_frame_or_displayed_count = g_puppyCounterUIState;
219
220 if (puppy_count > (int32_t)animation_frame_or_displayed_count)
221 {
222 g_puppyCounterUIState = animation_frame_or_displayed_count + 1;
223
224 if ((int32_t)(int16_t)(animation_frame_or_displayed_count + 1) != puppy_count)
226 }
227 }
228 else if (animation_frame_or_displayed_count + 1 > UI_COUNTER_INCREMENT_CYCLE_END_FRAME && puppy_count > (int32_t)g_puppyCounterUIState)
230 }
231
232 struct Material_RuntimeDescriptor *texture_descriptor;
233
234 if (sprite)
235 texture_descriptor = sprite->textureDescriptor;
236
237 int16_t icon_width;
238
239 if (!sprite || !texture_descriptor)
240 icon_width = 1;
241 else
242 {
243 int16_t icon_width_minus_one = (uint8_t)(texture_descriptor->dimensions_minus_1.width);
244
245 icon_width = icon_width_minus_one + 1;
246 }
247
248 int32_t icon_window_width = Graphics_WindowWidth;
249 uint32_t right_margin_x =
250 (uint32_t)(uint16_t)((int64_t)(icon_window_width * 0x14) / icon_window_width);
251 int16_t icon_draw_x = (uint16_t)icon_window_width - (uint16_t)right_margin_x - icon_width - slide_offset_x;
252 int32_t icon_window_height = Graphics_WindowHeight;
253
255 ((int64_t)(icon_window_height * 0x24) / icon_window_height) << UI_PACKED_Y_SHIFT | (right_margin_x & UI_PACKED_COORDINATE_HIGH_MASK) | (uint32_t)(uint16_t)icon_draw_x,
256 0, sprite, 0, 0, 0);
257
258 int32_t number_center_width = sprite && sprite->textureDescriptor
260 : 1;
261
262 int32_t number_window_width = Graphics_WindowWidth;
263 int32_t number_window_height = Graphics_WindowHeight;
264
266 ((uint32_t)(uint16_t)((int64_t)(number_window_width * 0x14) / number_window_width) & UI_PACKED_COORDINATE_HIGH_MASK) | (uint32_t)(uint16_t)((int16_t)(number_center_width >> 1) + icon_draw_x) | ((int64_t)(number_window_height * 0x24) / number_window_height) << UI_PACKED_Y_SHIFT,
267 (int32_t)g_puppyCounterUIState);
268}
269
270// Original pcdogs.exe: 0x428100
271// Animates up to four life icons and renders the lives count, returning the horizontal anchor used by prompts. It returns -1 outside the drawable state range or for negative lives.
272int32_t UI_UpdateLives(int32_t icon_count, int32_t lives)
273{
276
277 int32_t clamped_icon_count = icon_count;
278
279 if (clamped_icon_count < 0)
280 clamped_icon_count = 0;
281 else if (clamped_icon_count > 4)
282 clamped_icon_count = 4;
283
284 if ((uint16_t)g_livesUICurrentValue == 0xfffe)
285 {
286 int32_t remaining_initial_icons = (int32_t)(int16_t)clamped_icon_count;
287 int32_t initialized_icon_count = 0;
288
289 g_livesUICurrentValue = (uint16_t)clamped_icon_count;
290
291 if (remaining_initial_icons > 0)
292 {
293 struct UI_LifeIconAnim *present_icon_cursor = &UI_LifeIcons[0];
294
295 initialized_icon_count = remaining_initial_icons;
296
297 int32_t initial_count_before_decrement;
298
299 do
300 {
301 present_icon_cursor->frame = UI_LIFE_ICON_ANIMATION_FRAMES;
302 present_icon_cursor->animating = 0;
303 present_icon_cursor->target_present = 1;
304 present_icon_cursor->visible = 1;
305 present_icon_cursor = &present_icon_cursor[1];
306 initial_count_before_decrement = remaining_initial_icons;
307 remaining_initial_icons -= 1;
308 } while (initial_count_before_decrement != 1);
309 }
310
311 if (initialized_icon_count < 4)
312 {
313 struct UI_LifeIconAnim *empty_icon_cursor = &UI_LifeIcons[initialized_icon_count];
314
315 do
316 {
317 empty_icon_cursor->frame = UI_LIFE_ICON_ANIMATION_FRAMES;
318 empty_icon_cursor->animating = 0;
319 empty_icon_cursor->target_present = 0;
320 empty_icon_cursor->visible = 0;
321 empty_icon_cursor = &empty_icon_cursor[1];
322 } while ((uintptr_t)empty_icon_cursor < (uintptr_t)&UI_LifeIcons[4]);
323 }
324 }
325
326 struct Graphics_Render_SpriteContext *icon_sprite;
327
329
330 int16_t animation_frame = UI_LivesCounterAnimState + 1;
331
332 UI_LivesCounterAnimState = animation_frame;
333
334 int32_t slide_offset_x;
335 struct Graphics_Render_SpriteContext *sprite;
336
337 if (animation_frame < UI_COUNTER_SLIDE_FRAMES)
338 {
339 sprite = icon_sprite;
340
341 struct Material_RuntimeDescriptor *slide_in_descriptor;
342
343 if (sprite)
344 slide_in_descriptor = sprite->textureDescriptor;
345
346 int32_t slide_in_width;
347
348 if (!sprite || !slide_in_descriptor)
349 slide_in_width = 1;
350 else
351 {
352 int32_t slide_in_width_minus_one = (uint8_t)(slide_in_descriptor->dimensions_minus_1.width);
353
354 slide_in_width = slide_in_width_minus_one + 1;
355 }
356
357 slide_offset_x = ((int32_t)animation_frame - UI_COUNTER_SLIDE_FRAMES) * slide_in_width / UI_COUNTER_SLIDE_FRAMES;
358 }
359 else if (animation_frame >= UI_COUNTER_SLIDE_OUT_FRAME)
360 {
361 sprite = icon_sprite;
362
363 struct Material_RuntimeDescriptor *slide_out_descriptor;
364
365 if (sprite)
366 slide_out_descriptor = sprite->textureDescriptor;
367
368 int32_t slide_out_width;
369
370 if (!sprite || !slide_out_descriptor)
371 slide_out_width = 1;
372 else
373 {
374 int32_t slide_out_width_minus_one = (uint8_t)(slide_out_descriptor->dimensions_minus_1.width);
375
376 slide_out_width = slide_out_width_minus_one + 1;
377 }
378
379 slide_offset_x = (UI_COUNTER_SLIDE_OUT_FRAME - (int32_t)animation_frame) * slide_out_width / UI_COUNTER_SLIDE_FRAMES;
380
381 if (clamped_icon_count != (int32_t)g_livesUICurrentValue)
383 }
384 else
385 {
386 slide_offset_x = 0;
387
388 if (animation_frame == UI_COUNTER_HOLD_FRAME)
389 {
390 int16_t displayed_count_or_animation_byte = g_livesUICurrentValue;
391 int32_t displayed_icon_count = (int32_t)displayed_count_or_animation_byte;
392 bool adding_icons = clamped_icon_count >= displayed_icon_count;
393
394 while (clamped_icon_count != displayed_icon_count)
395 {
396 struct UI_LifeIconAnim *changed_icon_state;
397
398 if (adding_icons)
399 {
400 changed_icon_state = &UI_LifeIcons[displayed_icon_count];
401 displayed_count_or_animation_byte += 1;
402 g_livesUICurrentValue = displayed_count_or_animation_byte;
403 changed_icon_state->target_present = 1;
404 }
405 else
406 {
407 displayed_count_or_animation_byte -= 1;
408 g_livesUICurrentValue = displayed_count_or_animation_byte;
409
410 int32_t removed_icon_index = (int32_t)displayed_count_or_animation_byte;
411
412 UI_LifeIcons[removed_icon_index].target_present = 0;
413 changed_icon_state = &UI_LifeIcons[removed_icon_index];
414 }
415
416 uint8_t was_visible = changed_icon_state->visible;
417
418 changed_icon_state->animating = 1;
419
420 if (!was_visible)
421 {
422 changed_icon_state->frame = 0;
423 changed_icon_state->visible = 1;
424 }
425 else
426 {
427 uint8_t previous_frame = changed_icon_state->frame;
428
429 changed_icon_state->frame = UI_LIFE_ICON_ANIMATION_FRAMES - previous_frame;
430 }
431
432 displayed_count_or_animation_byte = g_livesUICurrentValue;
433 displayed_icon_count = (int32_t)displayed_count_or_animation_byte;
434 adding_icons = clamped_icon_count >= displayed_icon_count;
435 }
436 }
437 else if (clamped_icon_count != (int32_t)g_livesUICurrentValue)
439
440 sprite = icon_sprite;
441 }
442
443 struct Material_RuntimeDescriptor *base_width_descriptor;
444
445 if (sprite)
446 base_width_descriptor = sprite->textureDescriptor;
447
448 int32_t base_width;
449
450 if (!sprite || !base_width_descriptor)
451 base_width = 1;
452 else
453 {
454 int32_t base_width_minus_one = (uint8_t)(base_width_descriptor->dimensions_minus_1.width);
455
456 base_width = base_width_minus_one + 1;
457 }
458
459 int32_t base_window_width = Graphics_WindowWidth;
460 int32_t base_draw_x = base_window_width - (uint32_t)(uint16_t)((int64_t)(base_window_width * 0x14) / base_window_width) - base_width - slide_offset_x;
461 struct Material_RuntimeDescriptor *base_height_descriptor;
462
463 if (sprite)
464 base_height_descriptor = sprite->textureDescriptor;
465
466 int32_t base_height;
467
468 if (!sprite || !base_height_descriptor)
469 base_height = 1;
470 else
471 {
472 int32_t base_height_minus_one = (uint8_t)(base_height_descriptor->dimensions_minus_1.height);
473
474 base_height = base_height_minus_one + 1;
475 }
476
477 int32_t base_draw_y = Graphics_WindowHeight - base_height - 0x10;
478
479 Graphics_RenderTexturedSprite(base_draw_y << UI_PACKED_Y_SHIFT | (uint32_t)(uint16_t)base_draw_x, 0, sprite, (GRAPHICS_BLEND_ADDITIVE << SPRITE_RENDER_BLEND_MODE_SHIFT),
480 0, 0);
481
482 struct Graphics_Render_SpriteContext *number_base_sprite = icon_sprite;
483 struct Material_RuntimeDescriptor *number_width_descriptor;
484
485 if (number_base_sprite)
486 number_width_descriptor = number_base_sprite->textureDescriptor;
487
488 int32_t number_center_width;
489
490 if (!number_base_sprite || !number_width_descriptor)
491 number_center_width = 1;
492 else
493 {
494 int32_t number_width_minus_one = (uint8_t)(number_width_descriptor->dimensions_minus_1.width);
495
496 number_center_width = number_width_minus_one + 1;
497 }
498
499 struct Material_RuntimeDescriptor *number_height_descriptor;
500
501 if (number_base_sprite)
502 number_height_descriptor = number_base_sprite->textureDescriptor;
503
504 int32_t number_center_height;
505
506 if (!number_base_sprite || !number_height_descriptor)
507 number_center_height = 1;
508 else
509 {
510 int32_t number_height_minus_one = (uint8_t)(number_height_descriptor->dimensions_minus_1.height);
511
512 number_center_height = number_height_minus_one + 1;
513 }
514
515 /* Native stack bytes [esp+0x28..0x33] form four {x,y,glyph} records. */
516 int8_t glyph_layout[4][3] = {{0, 0, 4}, {0, 0, 1}, {0, 0, 2}, {0, 0, 3}};
517 int8_t *glyph_layout_y_cursor = &glyph_layout[0][1];
518 struct UI_LifeIconAnim *life_icon = UI_LifeIcons;
519 struct UI_LifeIconAnim *active_life_icon;
520
521 do
522 {
523 int32_t layout_window_width = Graphics_WindowWidth;
524 int32_t layout_window_height = Graphics_WindowHeight;
525 int32_t scaled_icon_height = 0;
526 int32_t scaled_icon_width = 0;
527 int16_t icon_x_offset = 0;
528
529 glyph_layout[0][0] = (char)((int64_t)(layout_window_width << 2) / layout_window_width);
530 glyph_layout[0][1] = (char)((int64_t)(layout_window_height * 0x1f) / layout_window_height);
531 glyph_layout[1][0] = (char)((int64_t)(layout_window_width * 6) / layout_window_width);
532 glyph_layout[1][1] = (char)((int64_t)(layout_window_height * 0xa) / layout_window_height);
533 glyph_layout[2][0] = (char)((int64_t)(layout_window_width * 0x1b) / layout_window_width);
534 glyph_layout[2][1] = (char)((int64_t)(layout_window_height << 2) / layout_window_height);
535 glyph_layout[3][0] = (char)((int64_t)(layout_window_width * 0x2c) / layout_window_width);
536
537 int32_t icon_y_offset = 0;
538
539 glyph_layout[3][1] = (char)((int64_t)(layout_window_height * 0x14) / layout_window_height);
540 Material_FindTextureByFrame(&Shared_FontDataCursor[1], (int32_t)glyph_layout_y_cursor[1], &icon_sprite);
541
542 uint32_t render_flags = 0;
543
544 active_life_icon = life_icon;
545
546 if (life_icon->animating)
547 {
548 char next_icon_frame = active_life_icon->frame + 1;
549
550 active_life_icon->frame = next_icon_frame;
551
552 int32_t pulse_phase = (int32_t)next_icon_frame;
553
554 if (pulse_phase != UI_LIFE_ICON_ANIMATION_FRAMES)
555 {
556 if (pulse_phase < UI_LIFE_ICON_ANIMATION_FRAMES)
557 {
558 if (active_life_icon->target_present)
559 pulse_phase = UI_LIFE_ICON_ANIMATION_FRAMES - pulse_phase;
560
561 int32_t blue_channel;
562 char green_channel;
563 struct Graphics_Render_SpriteContext *pulse_sprite;
564 int32_t red_channel;
565
566 if (pulse_phase >= UI_LIFE_ICON_PULSE_HALF_FRAMES)
567 {
568 struct Graphics_Render_SpriteContext *shrink_width_sprite = icon_sprite;
569 struct Material_RuntimeDescriptor *shrink_width_descriptor;
570
571 if (shrink_width_sprite)
572 shrink_width_descriptor = shrink_width_sprite->textureDescriptor;
573
574 int32_t shrink_base_width;
575
576 if (!shrink_width_sprite || !shrink_width_descriptor)
577 shrink_base_width = 1;
578 else
579 {
580 int32_t shrink_width_minus_one = (uint8_t)(shrink_width_descriptor->dimensions_minus_1.width);
581
582 shrink_base_width = shrink_width_minus_one + 1;
583 }
584
585 int32_t shrink_width_numerator = shrink_base_width * (UI_LIFE_ICON_ANIMATION_FRAMES - pulse_phase);
586
587 scaled_icon_width = shrink_width_numerator / UI_LIFE_ICON_SHRINK_DIVISOR;
588
589 if ((uint32_t)shrink_width_numerator < UI_LIFE_ICON_SHRINK_DIVISOR)
590 scaled_icon_width = 1;
591
592 struct Graphics_Render_SpriteContext *shrink_height_sprite = icon_sprite;
593 struct Material_RuntimeDescriptor *shrink_height_descriptor;
594
595 if (shrink_height_sprite)
596 shrink_height_descriptor = shrink_height_sprite->textureDescriptor;
597
598 int32_t shrink_base_height;
599
600 if (!shrink_height_sprite || !shrink_height_descriptor)
601 shrink_base_height = 1;
602 else
603 {
604 int32_t shrink_height_minus_one = (uint8_t)(shrink_height_descriptor->dimensions_minus_1.height);
605
606 shrink_base_height = shrink_height_minus_one + 1;
607 }
608
609 int32_t shrink_height_numerator = shrink_base_height * (UI_LIFE_ICON_ANIMATION_FRAMES - pulse_phase);
610
611 scaled_icon_height = shrink_height_numerator / UI_LIFE_ICON_SHRINK_DIVISOR;
612
613 if ((uint32_t)shrink_height_numerator < UI_LIFE_ICON_SHRINK_DIVISOR)
614 scaled_icon_height = 1;
615
617
618 if (fade_channel > 0xff)
619 fade_channel = 0xff;
620
621 if (!life_icon->target_present)
622 {
623 red_channel = fade_channel;
624 green_channel = 0;
625 }
626 else
627 {
628 red_channel = 0;
629 green_channel = (uint8_t)fade_channel;
630 }
631
632 blue_channel = 0;
633 pulse_sprite = icon_sprite;
634 }
635 else
636 {
637 struct Graphics_Render_SpriteContext *grow_width_sprite = icon_sprite;
638 struct Material_RuntimeDescriptor *grow_width_descriptor;
639
640 if (grow_width_sprite)
641 grow_width_descriptor = grow_width_sprite->textureDescriptor;
642
643 int32_t grow_base_width;
644
645 if (!grow_width_sprite || !grow_width_descriptor)
646 grow_base_width = 1;
647 else
648 {
649 int32_t grow_width_minus_one = (uint8_t)(grow_width_descriptor->dimensions_minus_1.width);
650
651 grow_base_width = grow_width_minus_one + 1;
652 }
653
654 pulse_sprite = icon_sprite;
655 scaled_icon_width = grow_base_width + pulse_phase * grow_base_width / UI_LIFE_ICON_PULSE_HALF_FRAMES;
656
657 struct Material_RuntimeDescriptor *grow_height_descriptor;
658
659 if (pulse_sprite)
660 grow_height_descriptor = pulse_sprite->textureDescriptor;
661
662 int32_t grow_base_height;
663
664 if (!pulse_sprite || !grow_height_descriptor)
665 grow_base_height = 1;
666 else
667 {
668 int32_t grow_height_minus_one = (uint8_t)(grow_height_descriptor->dimensions_minus_1.height);
669
670 grow_base_height = grow_height_minus_one + 1;
671 }
672
673 scaled_icon_height = grow_base_height + pulse_phase * grow_base_height / UI_LIFE_ICON_PULSE_HALF_FRAMES;
674
675 if (!life_icon->target_present)
676 {
677 red_channel = 0xff;
679 green_channel = (uint8_t)blue_channel;
680 pulse_sprite = icon_sprite;
681 }
682 else
683 {
684 green_channel = -1;
686 red_channel = blue_channel;
687 }
688 }
689
690 render_flags = (((blue_channel & UI_COLOR_CHANNEL_MASK) | UI_TEXT_PACKED_COLOR_PREFIX) << 8 | (uint32_t)(uint8_t)green_channel) << 8 | (red_channel & GRAPHICS_COLOR_RGB_MASK);
691
692 struct Material_RuntimeDescriptor *center_width_descriptor;
693
694 if (pulse_sprite)
695 center_width_descriptor = pulse_sprite->textureDescriptor;
696
697 int32_t center_base_width;
698
699 if (!pulse_sprite || !center_width_descriptor)
700 center_base_width = 1;
701 else
702 {
703 int32_t center_width_minus_one = (uint8_t)(center_width_descriptor->dimensions_minus_1.width);
704
705 center_base_width = center_width_minus_one + 1;
706 }
707
708 icon_x_offset = (int16_t)((center_base_width - scaled_icon_width) >> 1);
709
710 struct Graphics_Render_SpriteContext *center_height_sprite = icon_sprite;
711 struct Material_RuntimeDescriptor *center_height_descriptor;
712
713 if (center_height_sprite)
714 center_height_descriptor = center_height_sprite->textureDescriptor;
715
716 int32_t center_base_height;
717
718 if (!center_height_sprite || !center_height_descriptor)
719 center_base_height = 1;
720 else
721 {
722 int32_t center_height_minus_one = (uint8_t)(center_height_descriptor->dimensions_minus_1.height);
723
724 center_base_height = center_height_minus_one + 1;
725 }
726
727 active_life_icon = life_icon;
728 icon_y_offset = (center_base_height - scaled_icon_height) >> 1;
729 }
730 }
731 else if (!active_life_icon->target_present)
732 {
733 active_life_icon->visible = 0;
734 active_life_icon->animating = 0;
735 }
736 else
737 {
738 active_life_icon->visible = 1;
739 active_life_icon->animating = 0;
740 }
741 }
742
743 if (active_life_icon->visible)
744 {
745 int16_t icon_x = glyph_layout_y_cursor[-1];
746
748 (uint32_t)((uint16_t)icon_x + icon_x_offset + (uint16_t)base_draw_x) | ((int32_t)*glyph_layout_y_cursor + icon_y_offset + base_draw_y) << UI_PACKED_Y_SHIFT,
749 scaled_icon_height << UI_PACKED_Y_SHIFT | (scaled_icon_width & UI_PACKED_COORDINATE_LOW_MASK), icon_sprite, render_flags, 0, 0);
750 active_life_icon = life_icon;
751 }
752
753 life_icon = &active_life_icon[1];
754 glyph_layout_y_cursor = &glyph_layout_y_cursor[3];
755 } while ((uintptr_t)&active_life_icon[1] < (uintptr_t)&UI_LifeIcons[4]);
756
757 UI_LivesCounterLastValue = (uint16_t)lives;
758
759 int32_t number = lives - 1;
760
761 if (number > 0)
763 ((number_center_height >> 1) + base_draw_y) << UI_PACKED_Y_SHIFT | (uint32_t)((int16_t)(number_center_width >> 1) + (uint16_t)base_draw_x),
764 number);
765
766 return base_draw_x;
767}
768
769// Original pcdogs.exe: 0x42c640
770// Renders the bottom button prompts selected by the button-set flags.
771void UI_RenderButtonPrompts(int32_t button_set)
772{
773 int32_t prompt_row_count = 0;
774 int32_t show_first_prompt = button_set & UI_PROMPT_BACK;
775
776 if (show_first_prompt)
777 prompt_row_count = 1;
778
779 if ((uint8_t)button_set & (UI_PROMPT_CONFIRM | UI_PROMPT_ALTERNATE_CONFIRM))
780 prompt_row_count += 1;
781
782 int32_t prompt_y = Graphics_WindowHeight - prompt_row_count * 0x24 - 0xc;
783
784 if (show_first_prompt)
785 {
786 int32_t first_window_width = Graphics_WindowWidth;
787
788 Menu_RenderFormattedText((uint32_t)(uint16_t)(first_window_width / 2) | prompt_y << UI_PACKED_Y_SHIFT, 0x30,
789 8);
790 prompt_y += 0x24;
791 }
792
793 int32_t second_window_width;
794
795 if ((uint8_t)button_set & UI_PROMPT_CONFIRM)
796 {
797 second_window_width = Graphics_WindowWidth;
798 Menu_RenderFormattedText((uint32_t)(uint16_t)(second_window_width / 2) | prompt_y << UI_PACKED_Y_SHIFT, 0x2d,
799 6);
800 }
801 else if ((uint8_t)button_set & UI_PROMPT_ALTERNATE_CONFIRM)
802 {
803 second_window_width = Graphics_WindowWidth;
804 Menu_RenderFormattedText((uint32_t)(uint16_t)(second_window_width / 2) | prompt_y << UI_PACKED_Y_SHIFT, 0xa,
805 6);
806 }
807}
808
809// Original pcdogs.exe: 0x42cef0
810// Advances UI load and transition states, handles cheat and replay paths and triggers pause and music fading when required. Shared countdown paths retain the native possibility of decrementing the delay twice in one call.
812{
813 uint8_t current_load_state = Menu_LoadState;
814 int32_t next_load_state = (int32_t)current_load_state;
815 int32_t fade_delay;
816
818 {
819 g_levelIndex = 5;
820 next_load_state = LEVEL_LOAD_STORY;
822 }
823 else if (current_load_state == LEVEL_LOAD_WORLD_HUB)
824 {
827
828 int8_t selected_level_id = (*(uint8_t *)&g_checkersMinigameState) + 7;
829 bool ui_ready = UI_InitializedFlag;
830
831 g_levelIndex = selected_level_id;
832
833 if (ui_ready)
834 next_load_state = LEVEL_LOAD_DIRECT;
835 else
836 Menu_LoadLevelProgressState((int32_t)selected_level_id);
837 }
838 else if (current_load_state == LEVEL_LOAD_DIRECT)
839 {
840 uint32_t frame_flags = Game_FrameTransitionFlags;
841
842 if (!(frame_flags & GAME_TRANSITION_BONUS_REPLAY))
843 {
845 {
848
851
853
854 return;
855 }
856 }
857 else if (UI_InitializedFlag || !((uint8_t)frame_flags & GAME_TRANSITION_REPLAY_PLAYBACK))
858 {
859 next_load_state = LEVEL_LOAD_TITLE;
862 }
863 }
864 else if (current_load_state == LEVEL_LOAD_STORY)
865 {
866 fade_delay = Menu_LoadingFadeDelay;
867
868 if (fade_delay)
869 {
870 fade_delay -= 1;
871 Menu_LoadingFadeDelay = fade_delay;
872 }
873
875 {
876 char menu_level_index = g_levelIndex;
877
878 if (menu_level_index == 5)
879 next_load_state = LEVEL_LOAD_SAVED_GAME;
880 else if (menu_level_index == 4)
881 {
882 g_levelIndex = 5;
883
886
888
889 return;
890 }
891 else if (fade_delay)
892 {
893 Menu_LoadingFadeDelay = fade_delay - 1;
894
895 return;
896 }
897 else if (menu_level_index)
898 {
900 next_load_state = LEVEL_LOAD_DIRECT;
901 }
902 else
903 {
905
908
910
911 return;
912 }
913 }
914 }
915
916 fade_delay = Menu_LoadingFadeDelay;
917 current_load_state = Menu_LoadState;
918
919 if (fade_delay)
920 Menu_LoadingFadeDelay = fade_delay - 1;
921
922 if (next_load_state == (int32_t)current_load_state)
923 return;
924
925 Menu_LoadState = (uint8_t)next_load_state;
926
929
931}
932
933// Original pcdogs.exe: 0x444c50
934// Formats and logs a confirmation message, hides and restores the main window and reports whether OK was selected. The 256-byte local has no formatting bound, so expanded messages must fit.
935BOOL UI_ShowConfirmDialog(char const *format, ...)
936{
937 char message_buffer[256];
938
939 va_list argument_cursor;
940 va_start(argument_cursor, format);
941 CRT_vsprintf(message_buffer, format, (uint8_t *)argument_cursor);
942 va_end(argument_cursor);
943 CRT_printf("%s\n", message_buffer);
945
947 ShowWindow(Window_GetMainHandle(), SW_HIDE);
948
949 enum MESSAGEBOX_RESULT dialog_result =
950 MessageBoxA(NULL, (LPCSTR)(&message_buffer), "Message From Programmer Dude", MB_OKCANCEL);
951
953 ShowWindow(Window_GetMainHandle(), SW_SHOWNORMAL);
954
955 int32_t result = (uint8_t)(dialog_result == IDOK);
956
957 return result;
958}
959
960// Original pcdogs.exe: 0x444d70
961// Formats and logs an error message, hides and restores the main window and displays an OK dialog. The 256-byte local has no formatting bound, so expanded messages must fit.
962void UI_ShowErrorMessage(char const *format, ...)
963{
964 char buffer[256];
965
966 va_list arguments;
967 va_start(arguments, format);
968 CRT_vsprintf(buffer, format, (uint8_t *)arguments);
969 va_end(arguments);
970 CRT_printf("%s\n", buffer);
972
974 ShowWindow(Window_GetMainHandle(), SW_HIDE);
975
976 MessageBoxA(NULL, buffer, "Message From Programmer Dude", MB_OK);
977
979 ShowWindow(Window_GetMainHandle(), SW_SHOWNORMAL);
980}
#define g_boneCounterUIState
Definition globals.h:28
int32_t Audio_SetMusicFadeTarget(int32_t target_volume, int16_t frame_count)
Definition music.c:194
#define g_checkersMinigameState
Definition globals.h:80
#define GAME_TRANSITION_SAVE_PROMPT_PENDING
Definition constants.h:10
#define GAME_TRANSITION_BONUS_REPLAY
Definition constants.h:27
#define GAME_TRANSITION_CHEAT_ENABLED
Definition constants.h:11
#define GAME_TRANSITION_REPLAY_PLAYBACK
Definition constants.h:21
void Replay_StopPlayback(void)
Definition replay.c:66
void Game_TriggerPause(int32_t pause_type)
Definition loop.c:61
#define Game_FrameTransitionFlags
Definition globals.h:47
#define SPRITE_RENDER_BLEND_MODE_SHIFT
Definition constants.h:36
@ GRAPHICS_BLEND_ADDITIVE
Definition constants.h:45
#define GRAPHICS_COLOR_RGB_MASK
Definition constants.h:38
void Graphics_RenderTexturedSprite(uint32_t packed_xy, uint32_t packed_wh, struct Graphics_Render_SpriteContext *sprite, uint32_t render_flags, uint32_t rotation_angle, uint32_t rotation_pivot_xy)
Definition sprites.c:43
#define Graphics_WindowWidth
Definition globals.h:140
#define Graphics_WindowHeight
Definition globals.h:143
int32_t UI_UpdateLives(int32_t icon_count, int32_t lives)
Definition hud.c:272
void UI_Update()
Definition hud.c:811
void UI_UpdatePuppyCounter(int32_t puppy_count)
Definition hud.c:156
BOOL UI_ShowConfirmDialog(char const *format,...)
Definition hud.c:935
void UI_UpdateBoneCounter(int32_t bone_count)
Definition hud.c:43
void UI_RenderButtonPrompts(int32_t button_set)
Definition hud.c:771
void UI_ShowErrorMessage(char const *format,...)
Definition hud.c:962
#define INPUT_BUTTON_CONFIRM
Definition constants.h:11
#define INPUT_BUTTON_CANCEL
Definition constants.h:17
bool Input_CheckCheatCodeSequence(void)
Definition bindings.c:19
#define g_inputStateCurrentP1
Definition globals.h:72
@ LEVEL_LOAD_WORLD_HUB
Definition constants.h:43
@ LEVEL_LOAD_DIRECT
Definition constants.h:44
@ LEVEL_LOAD_SAVED_GAME
Definition constants.h:36
@ LEVEL_LOAD_TITLE
Definition constants.h:37
@ LEVEL_LOAD_STORY
Definition constants.h:42
#define g_levelIndex
Definition globals.h:100
int32_t Material_FindTextureByFrame(struct Material_RefEntry *material_ref, int32_t frame_index, struct Graphics_Render_SpriteContext **out_sprite)
Definition textures.c:325
void Menu_LoadLevelProgressState(int32_t level_id)
Definition state.c:48
void Menu_RenderFormattedText(uint32_t packed_xy, int32_t label_string_id, int32_t button_prompt_id)
Definition rendering.c:118
#define Menu_LoadState
Definition globals.h:153
#define Menu_LoadingFadeDelay
Definition globals.h:147
#define Shared_FontDataCursor
Definition globals.h:111
HWND Window_GetMainHandle(void)
Definition window.c:94
int32_t CRT_printf(char const *format,...)
Definition formatting.c:63
int32_t CRT_vsprintf(char *buffer, char const *format, uint8_t *argument_cursor)
Definition formatting.c:79
int32_t CRT_fflush(struct File_Handle *stream)
Definition stdio.c:17
#define g_crtStaticStreams
Definition globals.h:336
int32_t Save_GetGameHighestWorld(void)
Definition progress.c:142
void Save_SaveGameLevelCompletion(uint8_t completion_flag)
Definition progress.c:34
struct Material_RuntimeDescriptor * textureDescriptor
Definition types.h:570
struct Math_SizeU8 dimensions_minus_1
Definition types.h:264
uint8_t width
Definition types.h:347
uint8_t height
Definition types.h:348
uint8_t visible
Definition types.h:61
uint8_t target_present
Definition types.h:59
uint8_t animating
Definition types.h:60
#define UI_PACKED_COORDINATE_HIGH_MASK
Definition constants.h:70
#define UI_TEXT_PACKED_COLOR_PREFIX
Definition constants.h:14
#define UI_HIDDEN_WIDGET_RIGHT_EDGE
Definition constants.h:98
#define UI_PACKED_COORDINATE_LOW_MASK
Definition constants.h:69
#define UI_PROMPT_ALTERNATE_CONFIRM
Definition constants.h:68
#define UI_COUNTER_INCREMENT_FRAME
Definition constants.h:78
#define UI_PROMPT_CONFIRM
Definition constants.h:67
#define UI_COUNTER_INCREMENT_CYCLE_END_FRAME
Definition constants.h:118
#define UI_COLOR_CHANNEL_MASK
Definition constants.h:73
#define UI_PACKED_Y_SHIFT
Definition constants.h:93
#define UI_COUNTER_REARM_FRAME
Definition constants.h:76
#define UI_LIFE_ICON_SHRINK_DIVISOR
Definition constants.h:121
#define UI_COUNTER_SLIDE_FRAMES
Definition constants.h:117
#define UI_LIFE_ICON_PULSE_HALF_FRAMES
Definition constants.h:120
#define UI_COUNTER_HOLD_FRAME
Definition constants.h:77
#define UI_LIFE_ICON_ANIMATION_FRAMES
Definition constants.h:119
#define UI_COUNTER_SLIDE_OUT_FRAME
Definition constants.h:75
#define UI_COUNTER_ANIMATION_FINISHED
Definition constants.h:74
#define UI_PROMPT_BACK
Definition constants.h:66
void UI_RenderCenteredNumber(uint32_t packed_center_xy, int32_t number)
Definition text.c:22
#define UI_PuppyCounterAnimState
Definition globals.h:23
#define UI_LivesCounterLastValue
Definition globals.h:44
#define UI_InitializedFlag
Definition globals.h:92
#define g_puppyCounterUIState
Definition globals.h:47
#define UI_LifeIcons
Definition globals.h:35
#define g_livesUICurrentValue
Definition globals.h:32
#define g_uiInitializedFlag
Definition globals.h:89
#define UI_BoneCounterAnimState
Definition globals.h:26
#define UI_LivesCounterAnimState
Definition globals.h:29
MESSAGEBOX_RESULT
Definition win32_window.h:7
@ IDOK
#define MB_OKCANCEL
@ SW_HIDE
@ SW_SHOWNORMAL
#define MB_OK