102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
controls.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
16#include "pcdogs/menu/globals.h"
17#include "pcdogs/menu/types.h"
22#include "pcdogs/ui/functions.h"
23#include <math.h>
24#include <stdarg.h>
25#include <string.h>
26
27// Original pcdogs.exe: 0x429960
28// Finds the first raw-equality conflict between keyboard and joystick bindings and writes packed binding locations. The scans have asymmetric row bounds and do not exempt unbound values; no match clears only the two index bytes to 0xff.
29void Options_FindBindingConflict(struct Config_Data *settings, struct Options_BindingLocation *out_first_conflict, struct Options_BindingLocation *out_second_conflict)
30{
31 /* Native bounds are deliberately asymmetric: the first inner sweep has
32 eleven entries; all other sweeps have ten. Unbound values also compare. */
33 for (int i = 0; i < MENU_BINDING_GAMEPAD_COUNT; ++i)
34 {
35 for (int j = 0; j < MENU_BINDING_KEYBOARD_COUNT; ++j)
36 {
37 out_first_conflict->device_kind = MENU_BINDING_KEYBOARD;
38
39 if (i != j && settings->keyboard_bindings[i] == settings->keyboard_bindings[j])
40 {
41 out_first_conflict->binding_index = i;
42 *out_second_conflict = (struct Options_BindingLocation){MENU_BINDING_KEYBOARD, j};
43
44 return;
45 }
46
47 if (settings->keyboard_bindings[i] == settings->joystick_bindings[j])
48 {
49 out_first_conflict->binding_index = i;
50 *out_second_conflict = (struct Options_BindingLocation){MENU_BINDING_JOYSTICK, j};
51
52 return;
53 }
54 }
55 }
56
57 for (int i = 0; i < MENU_BINDING_GAMEPAD_COUNT; ++i)
58 {
59 for (int j = 0; j < MENU_BINDING_GAMEPAD_COUNT; ++j)
60 {
61 out_first_conflict->device_kind = MENU_BINDING_JOYSTICK;
62
63 if (i != j && settings->joystick_bindings[i] == settings->joystick_bindings[j])
64 {
65 out_first_conflict->binding_index = i;
66 *out_second_conflict = (struct Options_BindingLocation){MENU_BINDING_JOYSTICK, j};
67
68 return;
69 }
70
71 if (settings->joystick_bindings[i] == settings->keyboard_bindings[j])
72 {
73 out_first_conflict->binding_index = i;
74 *out_second_conflict = (struct Options_BindingLocation){MENU_BINDING_KEYBOARD, j};
75
76 return;
77 }
78 }
79 }
80
81 out_first_conflict->binding_index = MENU_BINDING_INDEX_NONE;
82 out_second_conflict->binding_index = MENU_BINDING_INDEX_NONE;
83}
84
85// Original pcdogs.exe: 0x42a1d0
86// Renders keyboard and joystick bindings, selection and conflict highlights, controller presets, and reset/accept/cancel controls. Keyboard row ten has no editable joystick counterpart, and selection styling takes priority over conflict styling.
88{
89 UI_RenderText(0xa0001, String_GetByIndex(0x76), 0, NULL);
91
92 char *keyboard_header_scan = Menu_ControlLabelBuffer;
93 int32_t keyboard_header_scan_remaining = UI_UNBOUNDED_SCAN_COUNT;
94
95 while (keyboard_header_scan_remaining)
96 {
97 bool keyboard_header_char_nonzero = 0 != *(uint8_t *)keyboard_header_scan;
98
99 keyboard_header_scan += 1;
100 keyboard_header_scan_remaining -= 1;
101
102 if (!keyboard_header_char_nonzero)
103 break;
104 }
105
106 uint32_t keyboard_header_half_length_times_three = ((~keyboard_header_scan_remaining - 1) >> 1) * 3;
107
108 UI_RenderText(((0x131 - keyboard_header_half_length_times_three * 5) & UI_PACKED_COORDINATE_LOW_MASK) | (10 << UI_PACKED_Y_SHIFT), Menu_ControlLabelBuffer, UI_TEXT_ALIGN_CENTER,
109 NULL);
111
112 char *joystick_header_scan = Menu_ControlLabelBuffer;
113 int32_t joystick_header_scan_remaining = UI_UNBOUNDED_SCAN_COUNT;
114
115 while (joystick_header_scan_remaining)
116 {
117 bool joystick_header_char_nonzero = 0 != *(uint8_t *)joystick_header_scan;
118
119 joystick_header_scan += 1;
120 joystick_header_scan_remaining -= 1;
121
122 if (!joystick_header_char_nonzero)
123 break;
124 }
125
126 int32_t joystick_header_length_times_three = (~joystick_header_scan_remaining - 1) * 3;
127
128 UI_RenderText(((0x262 - joystick_header_length_times_three * 5) & UI_PACKED_COORDINATE_LOW_MASK) | (10 << UI_PACKED_Y_SHIFT), Menu_ControlLabelBuffer, UI_TEXT_ALIGN_CENTER,
129 NULL);
131
132 char *text = String_GetByIndex(0x83);
133
135 0, NULL, 0xf);
138
139 char *first_combined_action_label = String_GetByIndex(0x84);
140
141 String_FormatCRTString(Menu_ControlLabelBuffer, "%s %s", String_GetByIndex(0x86), first_combined_action_label);
143
144 char *second_combined_action_label = String_GetByIndex(0x85);
145
146 String_FormatCRTString(Menu_ControlLabelBuffer, "%s %s", String_GetByIndex(0x86), second_combined_action_label);
153
154 int32_t presets_row_unselected = (uint8_t)(Options_MenuSelection != 0xb);
155
158 ((presets_row_unselected - 1) & (SPRITE_RENDER_EXPLICIT_COLOR | GRAPHICS_COLOR_RGB_MASK)) | UI_TEXT_ALIGN_CENTER, NULL, 0xf);
159
160 uint32_t reset_button_tint;
161
163 reset_button_tint = 0;
164 else
166
168 UI_RenderFixedAdvanceText(UI_PACK_POSITION(10, 400), Menu_ControlLabelBuffer, reset_button_tint, NULL, 0xf);
169
170 uint32_t accept_button_tint;
171
173 accept_button_tint = 0;
174 else
176
178 UI_RenderFixedAdvanceText(UI_PACK_POSITION(280, 400), Menu_ControlLabelBuffer, accept_button_tint, NULL, 0xf);
179
180 uint32_t cancel_button_tint;
181
183 cancel_button_tint = 0;
184 else
186
188 UI_RenderFixedAdvanceText(UI_PACK_POSITION(480, 400), Menu_ControlLabelBuffer, cancel_button_tint, NULL, 0xf);
189
190 int32_t string_id;
191 uint32_t text_flags;
192
193 if ((int8_t)(g_controlsMenuKeyIndex >> 8) > -1 && (int8_t)(g_controlsMenuButtonIndex >> 8) > -1)
194 {
196
198 string_id = 0x100;
199 }
201 {
203
204 text_flags = 0;
205 string_id = 0x80;
206 }
207 else
208 {
210
211 text_flags = 0;
212 string_id = 0x7e;
213 }
214
215 UI_RenderFixedAdvanceText(UI_PACK_POSITION(1, 460), String_GetByIndex(string_id), text_flags, NULL, 0xf);
216
217 int32_t binding_row_y = 0x32;
218
219 for (int32_t binding_index = 0; binding_index < MENU_BINDING_KEYBOARD_COUNT; binding_index += 1)
220 {
221 Input_GetButtonString(g_optionsMenuBackupData.keyboard_bindings[binding_index]);
222
223 int32_t keyboard_binding_tint;
224
225 if (g_optionsMenuColumn || Options_MenuSelection != binding_index)
226 {
227 int16_t keyboard_conflict_location = g_controlsMenuKeyIndex;
228
229 if ((int32_t)(char)((uint32_t)keyboard_conflict_location >> 8) != binding_index || (uint8_t)keyboard_conflict_location)
230 {
231 keyboard_conflict_location = g_controlsMenuButtonIndex;
232
233 keyboard_binding_tint = (int32_t)(char)((uint32_t)keyboard_conflict_location >> 8) != binding_index || (uint8_t)keyboard_conflict_location ? 0
235 }
236 else
237 keyboard_binding_tint = (SPRITE_RENDER_EXPLICIT_COLOR | UI_TEXT_ERROR_COLOR_RGB);
238 }
239 else
240 keyboard_binding_tint = (SPRITE_RENDER_EXPLICIT_COLOR | GRAPHICS_COLOR_RGB_MASK);
241
242 int16_t keyboard_binding_x = (0x131 - keyboard_header_half_length_times_three * 5);
243
244 if (binding_index == 0xa)
245 {
246 int32_t column_span = (int32_t)(0x262 - joystick_header_length_times_three * 5 - (0x131 - keyboard_header_half_length_times_three * 5));
247
248 keyboard_binding_x = (int16_t)(column_span >> 1) + (0x131 - keyboard_header_half_length_times_three * 5) - 0x28;
249 }
250
251 int32_t packed_binding_y = binding_row_y << UI_PACKED_Y_SHIFT;
252
253 UI_RenderFixedAdvanceText((uint32_t)keyboard_binding_x | packed_binding_y, (const char *)(uintptr_t)&g_controlsMenuButtonNameBuffer,
254 keyboard_binding_tint | UI_TEXT_ALIGN_CENTER, NULL, 0xf);
255
256 if (binding_index < MENU_BINDING_GAMEPAD_COUNT)
257 {
258 Input_GetButtonString(g_optionsMenuBackupData.joystick_bindings[binding_index]);
259
260 int32_t joystick_binding_tint;
261
262 if (g_optionsMenuColumn != 1 || Options_MenuSelection != binding_index)
263 {
264 int16_t joystick_conflict_location = g_controlsMenuKeyIndex;
265
266 if ((int32_t)(char)((uint32_t)joystick_conflict_location >> 8) != binding_index || (uint8_t)joystick_conflict_location != 1)
267 {
268 joystick_conflict_location = g_controlsMenuButtonIndex;
269
270 joystick_binding_tint = (int32_t)(char)((uint32_t)joystick_conflict_location >> 8) != binding_index || (uint8_t)joystick_conflict_location != 1
271 ? 0
273 }
274 else
275 joystick_binding_tint = (SPRITE_RENDER_EXPLICIT_COLOR | UI_TEXT_ERROR_COLOR_RGB);
276 }
277 else
278 joystick_binding_tint = (SPRITE_RENDER_EXPLICIT_COLOR | GRAPHICS_COLOR_RGB_MASK);
279
280 UI_RenderFixedAdvanceText((uint32_t)(0x262 - joystick_header_length_times_three * 5) | packed_binding_y,
281 (const char *)(uintptr_t)&g_controlsMenuButtonNameBuffer, joystick_binding_tint | UI_TEXT_ALIGN_CENTER, NULL, 0xf);
282 }
283
284 binding_row_y += 0x1e;
285 }
286}
287
288// Original pcdogs.exe: 0x42a740
289// Renders the four built-in controller preset names and highlights the selected preset.
291{
292 uint32_t highlight_tint = Color_UpdateGradient(&Menu_HighlightGradient);
293 int32_t option_y = 0xc8;
294
295 for (int32_t option_index = 0; option_index < (int32_t)(sizeof(g_controllerPresets) / sizeof(g_controllerPresets[0])); ++option_index)
296 {
297 int32_t option_tint;
298
299 if (option_index != Options_MenuSelection)
300 option_tint = 0;
301 else
302 {
303 uint32_t highlight_channel = (uint32_t)(uint8_t)highlight_tint;
304
305 option_tint = ((highlight_channel | UI_TEXT_PACKED_COLOR_PREFIX) << 8 | highlight_channel) << 8 | (highlight_tint & GRAPHICS_COLOR_RGB_MASK);
306 }
307
308 UI_RenderFixedAdvanceText(option_y << UI_PACKED_Y_SHIFT | 320, g_controllerPresets[option_index].name, option_tint | UI_TEXT_ALIGN_CENTER, NULL, 0xf);
309 option_y += 0x14;
310 }
311}
312
313// Original pcdogs.exe: 0x42a7d0
314// Renders the Yes/No confirmation for applying a controller preset. Choice zero is Yes and choice one is No.
316{
317 uint32_t highlight_tint = Color_UpdateGradient(&Menu_HighlightGradient);
318
320
321 int32_t option_y = 0xf0;
322 int32_t option_index = 0;
323
324 for (int32_t *option_string_cursor = (int32_t *)&g_difficultyOptionEasy; option_string_cursor < (int32_t *)&g_difficultyOptionEasy + 2;)
325 {
326 int32_t option_tint;
327
328 if (option_index != Options_MenuSelection)
329 option_tint = 0;
330 else
331 {
332 uint32_t highlight_channel = (uint32_t)(uint8_t)highlight_tint;
333
334 option_tint = ((highlight_channel | UI_TEXT_PACKED_COLOR_PREFIX) << 8 | highlight_channel) << 8 | (highlight_tint & GRAPHICS_COLOR_RGB_MASK);
335 }
336
337 UI_RenderFixedAdvanceText(option_y << UI_PACKED_Y_SHIFT | 320, String_GetByIndex(*(uint32_t *)option_string_cursor),
338 option_tint | UI_TEXT_ALIGN_CENTER, NULL, 0x14);
339 option_y += 0x28;
340 option_string_cursor = &option_string_cursor[1];
341 option_index += 1;
342 }
343}
void Menu_RenderControllerPresetSelection()
Definition controls.c:290
void Options_FindBindingConflict(struct Config_Data *settings, struct Options_BindingLocation *out_first_conflict, struct Options_BindingLocation *out_second_conflict)
Definition controls.c:29
void Menu_RenderControllerPresetConfirmation()
Definition controls.c:315
void Menu_RenderControlsConfiguration()
Definition controls.c:87
#define SPRITE_RENDER_EXPLICIT_COLOR
Definition constants.h:33
#define GRAPHICS_COLOR_RGB_MASK
Definition constants.h:38
uint32_t Color_UpdateGradient(struct Menu_ColorGradientState *gradient_state)
Definition effects.c:340
char * Input_GetButtonString(int32_t button_code)
Definition bindings.c:237
#define g_controllerPresets
Definition globals.h:126
#define MENU_BINDING_INDEX_NONE
Definition constants.h:65
#define MENU_BINDING_GAMEPAD_COUNT
Definition constants.h:67
#define MENU_BINDING_KEYBOARD_COUNT
Definition constants.h:66
@ MENU_BINDING_KEYBOARD
Definition constants.h:75
@ MENU_BINDING_JOYSTICK
Definition constants.h:76
#define g_optionsMenuBackupData
Definition globals.h:36
#define Menu_HighlightGradient
Definition globals.h:156
#define Menu_ControlLabelBuffer
Definition globals.h:173
#define g_controlsMenuButtonIndex
Definition globals.h:81
#define g_controlsMenuButtonNameBuffer
Definition globals.h:150
#define g_controlsMenuKeyIndex
Definition globals.h:78
#define Options_MenuSelection
Definition globals.h:123
#define g_optionsMenuColumn
Definition globals.h:120
int32_t String_FormatCRTString(char *buffer, char const *format,...)
Definition formatting.c:18
int32_t joystick_bindings[0xd]
Definition types.h:24
int32_t keyboard_bindings[0xd]
Definition types.h:23
char * String_GetByIndex(int32_t string_id)
Definition strings.c:66
#define UI_TEXT_PACKED_COLOR_PREFIX
Definition constants.h:14
#define UI_PACKED_COORDINATE_LOW_MASK
Definition constants.h:69
#define UI_TEXT_ALIGN_CENTER
Definition constants.h:6
#define UI_PACKED_Y_SHIFT
Definition constants.h:93
#define UI_PACK_POSITION(x, y)
Definition constants.h:94
#define UI_TEXT_ERROR_COLOR_RGB
Definition constants.h:17
#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
void UI_RenderFixedAdvanceText(uint32_t packed_xy, char const *text, uint32_t text_flags, void *font_context, uint32_t glyph_advance)
Definition text.c:232
#define g_buttonRemappingActive
Definition values.h:429
#define g_difficultyOptionEasy
Definition values.h:72