102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
rendering.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
15#include "pcdogs/text/globals.h"
16#include "pcdogs/ui/functions.h"
17#include <math.h>
18#include <stdarg.h>
19#include <string.h>
20
21// Original pcdogs.exe: 0x4288d0
22// Draws the enabled confirmation prompt near the bottom-right edge when frame flags allow it. Its modulo-twenty timer does not gate drawing, so this routine does not blink the prompt.
23void Menu_RenderConfirmPrompt(int32_t right_edge_x)
24{
26 return;
27
28 uint32_t frame_flags = Game_FrameTransitionFlags;
29
30 if (frame_flags & GAME_TRANSITION_GAME_OVER)
31 return;
32
33 bool menu_active = (frame_flags & GAME_TRANSITION_MENU_ACTIVE) != 0;
34 char next_prompt_frame;
35
36 if (!menu_active)
37 {
38 next_prompt_frame = g_confirmPromptFrameCounter + 1;
39 g_confirmPromptFrameCounter = next_prompt_frame;
40 }
41
42 if (menu_active || next_prompt_frame == 0x14)
44
45 int32_t resolved_right_edge_x = right_edge_x;
46
47 if (resolved_right_edge_x < 0)
48 resolved_right_edge_x = Graphics_WindowWidth - 8;
49
50 if (menu_active)
51 return;
52
54 int32_t scan_remaining = UI_UNBOUNDED_SCAN_COUNT;
55 char *text = prompt_scan;
56
57 while (scan_remaining)
58 {
59 bool prompt_char_nonzero = 0 != *(uint8_t *)prompt_scan;
60
61 prompt_scan = &prompt_scan[1];
62 scan_remaining -= 1;
63
64 if (!prompt_char_nonzero)
65 break;
66 }
67
69 (uint32_t)(uint16_t)((uint16_t)resolved_right_edge_x - (int16_t)((~scan_remaining - 1) * 0x1e) - 8) | (Graphics_WindowHeight - 0x2e) << UI_PACKED_Y_SHIFT,
71}
72
73// Original pcdogs.exe: 0x42bc60
74// Renders a centered title and a highlighted Yes/No selection. Selection zero means Yes and selection one means No.
75void Menu_RenderYesNoPrompt(int32_t title_string_id, int32_t selected_index, uint32_t highlight_tint)
76{
77 char *text = String_GetByIndex(title_string_id);
78 int32_t title_window_height = Graphics_WindowHeight;
79 int32_t title_window_width = Graphics_WindowWidth;
80
82 ((title_window_height / 2) - 0x80) << UI_PACKED_Y_SHIFT | (uint32_t)(uint16_t)(title_window_width / 2), text,
84
85 int32_t option_index = 0;
86 int16_t option_string_ids[2] = {3, 4};
87 int32_t option_y_offset = 0;
88 int16_t *option_string_cursor = option_string_ids;
89
90 do
91 {
92 int32_t option_tint;
93
94 if (option_index != selected_index)
95 option_tint = 0;
96 else
97 {
98 uint32_t highlight_channel = (uint32_t)(uint8_t)highlight_tint;
99
100 option_tint = ((highlight_channel | UI_TEXT_PACKED_COLOR_PREFIX) << 8 | highlight_channel) << 8 | (highlight_tint & GRAPHICS_COLOR_RGB_MASK);
101 }
102
103 char *option_text = String_GetByIndex((int32_t)*option_string_cursor);
104 int32_t option_window_height = Graphics_WindowHeight;
105 int32_t option_window_width = Graphics_WindowWidth;
106
108 ((option_window_height / 2) + option_y_offset - 0x20) << UI_PACKED_Y_SHIFT | (uint32_t)(uint16_t)(option_window_width / 2),
109 option_text, option_tint | UI_TEXT_ALIGN_CENTER, NULL);
110 option_y_offset += 0x20;
111 option_index += 1;
112 option_string_cursor += 1;
113 } while (option_y_offset < 0x40);
114}
115
116// Original pcdogs.exe: 0x42c6d0
117// Measures and renders a localized control label and button name as one centered prompt row.
118void Menu_RenderFormattedText(uint32_t packed_xy, int32_t label_string_id, int32_t button_prompt_id)
119{
120 char *label_text = String_GetByIndex(label_string_id);
121 int32_t label_text_width = UI_ComputeStringWidth(label_text);
122 char button_name_buffer[0x100];
123
124 if (button_prompt_id == 5)
126 else if (button_prompt_id == 6)
127 String_FormatCRTString(button_name_buffer, "%s", String_GetByIndex(0xf4));
128 else if (button_prompt_id != 7)
129 String_FormatCRTString(button_name_buffer, "%s", String_GetByIndex(0xf5));
130 else
131 String_FormatCRTString(button_name_buffer, "%s",
132 g_inputButtonNameBuffers[button_prompt_id]);
133
134 char *button_text_scan = button_name_buffer;
135 int32_t scan_remaining = UI_UNBOUNDED_SCAN_COUNT;
136
137 while (scan_remaining)
138 {
139 bool button_char_nonzero = 0 != *(uint8_t *)button_text_scan;
140
141 button_text_scan += 1;
142 scan_remaining -= 1;
143
144 if (!button_char_nonzero)
145 break;
146 }
147
148 int32_t button_text_pixel_width = ~scan_remaining * 0x14;
149 int32_t centered_packed_xy = packed_xy - ((button_text_pixel_width + label_text_width) >> 1);
150
151 UI_RenderText(centered_packed_xy, button_name_buffer, (SPRITE_RENDER_EXPLICIT_COLOR | GRAPHICS_COLOR_RGB_MASK), NULL);
152 UI_RenderText(button_text_pixel_width + centered_packed_xy + 0x20000, label_text, 0, NULL);
153}
#define GAME_TRANSITION_GAME_OVER
Definition constants.h:28
#define GAME_TRANSITION_MENU_ACTIVE
Definition constants.h:7
#define Game_FrameTransitionFlags
Definition globals.h:47
#define SPRITE_RENDER_EXPLICIT_COLOR
Definition constants.h:33
#define GRAPHICS_COLOR_RGB_MASK
Definition constants.h:38
#define Graphics_WindowWidth
Definition globals.h:140
#define Graphics_WindowHeight
Definition globals.h:143
@ INPUT_BUTTON_NAME_ACTION_3
Definition constants.h:123
#define g_inputButtonNameBuffers
Definition globals.h:75
void Menu_RenderConfirmPrompt(int32_t right_edge_x)
Definition rendering.c:23
void Menu_RenderYesNoPrompt(int32_t title_string_id, int32_t selected_index, uint32_t highlight_tint)
Definition rendering.c:75
void Menu_RenderFormattedText(uint32_t packed_xy, int32_t label_string_id, int32_t button_prompt_id)
Definition rendering.c:118
int32_t String_FormatCRTString(char *buffer, char const *format,...)
Definition formatting.c:18
char * String_GetByIndex(int32_t string_id)
Definition strings.c:66
#define UI_TEXT_PACKED_COLOR_PREFIX
Definition constants.h:14
#define UI_TEXT_ALIGN_CENTER
Definition constants.h:6
#define UI_PACKED_Y_SHIFT
Definition constants.h:93
#define UI_UNBOUNDED_SCAN_COUNT
Definition constants.h:97
void UI_RenderText(uint32_t packed_xy, char const *text, uint32_t text_flags, void *font_context)
Definition text.c:226
int32_t UI_ComputeStringWidth(char const *text)
Definition text.c:152
#define g_confirmPromptFrameCounter
Definition values.h:390
#define g_confirmTextEnabled
Definition values.h:825