From ec7d8c3eecbb07151f4d4bfa4d5b930caeadb661 Mon Sep 17 00:00:00 2001 From: Arceveti Date: Wed, 1 Mar 2023 21:26:15 -0500 Subject: [PATCH] Autogenerate button combo string from the combo define --- src/game/area.c | 53 +++++++++++++++++++++++++++++++++++++++++-- src/game/game_input.h | 10 ++++---- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/game/area.c b/src/game/area.c index 584c36624..d5597e821 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -1,4 +1,5 @@ #include +#include #include "config.h" #include "area.h" @@ -97,6 +98,27 @@ ALIGNED4 static const struct ControllerIcon gControllerIcons[] = { { .type = CONT_TYPE_GCN_DANCEPAD, .texture = texture_controller_gcn_dancepad }, }; +#if (NUM_SUPPORTED_CONTROLLERS > 1) +static const char* sButtonStr[16] = { + "A", // A_BUTTON + "B", // B_BUTTON + "Z", // Z_TRIG + "START", // START_BUTTON + "D UP", // U_JPAD + "D DOWN", // D_JPAD + "D LEFT", // L_JPAD + "D RIGHT", // R_JPAD + "X", // X_BUTTON + "Y", // Y_BUTTON + "L", // L_TRIG + "R", // R_TRIG + "C UP", // U_CBUTTONS + "C DOWN", // D_CBUTTONS + "C LEFT", // L_CBUTTONS + "C RIGHT", // R_CBUTTONS +}; +#endif + Vp gViewport = { .vp = { .vscale = { (SCREEN_WIDTH * 2), (SCREEN_HEIGHT * 2), (G_MAXZ / 2), 0 }, @@ -395,6 +417,29 @@ static const Gfx dl_controller_icons_end[] = { gsSPEndDisplayList(), }; +#if (NUM_SUPPORTED_CONTROLLERS > 1) +/** + * Creates a string from a combination of buttons and adds it to 'strp'. + */ +static u32 button_combo_to_string(char *strp, u16 buttons) { + u32 count = 0; + + for (int i = 0; i < ARRAY_COUNT(sButtonStr); i++) { + if (buttons & ((1 << (ARRAY_COUNT(sButtonStr) - 1)) >> i)) { // 0x8000 >> i + if (count) { + strcat(strp, "+"); + count += strlen("+"); + } + + strcat(strp, sButtonStr[i]); + count += strlen(sButtonStr[i]); + } + } + + return count; +} +#endif + /** * Displays controller info (eg. type and player number) while polling for controller statuses. */ @@ -407,7 +452,7 @@ void render_controllers_overlay(void) { const s32 texH = 32; Texture *texture_controller = texture_controller_unknown; OSPortInfo *portInfo = NULL; - char text_buffer[32]; + char text_buffer[32] = ""; int port; if (!gContStatusPolling) { @@ -468,7 +513,11 @@ void render_controllers_overlay(void) { sprintf(text_buffer, "PRESS BUTTON TO ASSIGN P%d", gNumPlayers); drawSmallStringCol(&dlHead, (SCREEN_CENTER_X - 77), (SCREEN_CENTER_Y - 28), text_buffer, col, col, col); #if (NUM_SUPPORTED_CONTROLLERS > 1) - drawSmallStringCol(&dlHead, (SCREEN_CENTER_X - 62), (SCREEN_CENTER_Y + 28), "OR A+B+START TO EXIT", col, col, col); + char comboStr[32] = ""; + u32 count = button_combo_to_string(comboStr, TOGGLE_CONT_STATUS_POLLING_COMBO); + sprintf(text_buffer, "OR %s TO EXIT", comboStr); + s32 xOffset = ((strlen("ORTOEXIT") + 1 + count) / 2) * 7; // Center the text based on char count. + drawSmallStringCol(&dlHead, (SCREEN_CENTER_X - xOffset), (SCREEN_CENTER_Y + 28), text_buffer, col, col, col); #endif } else { drawSmallStringCol(&dlHead, (SCREEN_CENTER_X - 84), (SCREEN_CENTER_Y - 28), "RELEASE ALL INPUTS TO START", col, col, col); diff --git a/src/game/game_input.h b/src/game/game_input.h index c6e0ceb00..07443ea83 100644 --- a/src/game/game_input.h +++ b/src/game/game_input.h @@ -20,11 +20,11 @@ #define CONT_STATUS_POLLING_TIME 15 struct DemoInput { - u8 timer; // time until next input. if this value is 0, it means the demo is over - s8 rawStickX; - s8 rawStickY; - u8 buttonMask; -}; + /*0x00*/ u8 timer; // time until next input. if this value is 0, it means the demo is over + /*0x01*/ s8 rawStickX; + /*0x02*/ s8 rawStickY; + /*0x03*/ u8 buttonMask; +}; /*0x04*/ // Player Controllers extern struct Controller gControllers[MAXCONTROLLERS];