diff --git a/src/hud/CMakeLists.txt b/src/hud/CMakeLists.txt index 629b708f4..fcdc823c6 100644 --- a/src/hud/CMakeLists.txt +++ b/src/hud/CMakeLists.txt @@ -3,4 +3,5 @@ target_sources(SRB2SDL2 PRIVATE spectator.cpp timer.cpp emerald-win.cpp + input-display.cpp ) diff --git a/src/hud/input-display.cpp b/src/hud/input-display.cpp new file mode 100644 index 000000000..99d3fe943 --- /dev/null +++ b/src/hud/input-display.cpp @@ -0,0 +1,88 @@ +// DR. ROBOTNIK'S RING RACERS +//----------------------------------------------------------------------------- +// Copyright (C) 2024 by Kart Krew +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- + +#include + +#include + +#include "../math/vec.hpp" + +#include "../g_input.h" +#include "../g_game.h" +#include "../i_joy.h" +#include "../k_hud.h" +#include "../v_draw.hpp" + +using srb2::Draw; +using srb2::math::Vec2; + +namespace +{ + +const char* dpad_suffix(const Vec2& v) +{ + if (v.y > 0) + { + if (v.x < 0) + return "UL"; + else if (v.x > 0) + return "UR"; + else + return "U"; + } + else if (v.y < 0) + { + if (v.x < 0) + return "DL"; + else if (v.x > 0) + return "DR"; + else + return "D"; + } + else + { + if (v.x < 0) + return "L"; + else if (v.x > 0) + return "R"; + else + return "N"; + } +} + +}; // namespace + +void K_DrawInputDisplay(INT32 x, INT32 y, UINT8 pid) +void K_DrawInputDisplay(INT32 x, INT32 y, INT32 flags, char mode, UINT8 pid, boolean local, boolean transparent) +{ + const menucmd_t& cmd = menucmd[pid]; + const std::string prefix = "PR_"; + auto gfx = [&](auto format, auto&&... args) { return prefix + fmt::format(format, args...); }; + auto but = [&](char key, INT32 gc) { return gfx(G_PlayerInputAnalog(pid, gc, 0) ? "BT{}B" : "BT{}", key); }; + + Draw box(x, y); + + box.patch(gfx("CONT")); + + Vec2 dpad = { + (G_PlayerInputAnalog(pid, gc_right, 0) - G_PlayerInputAnalog(pid, gc_left, 0)) / (float)JOYAXISRANGE, + (G_PlayerInputAnalog(pid, gc_up, 0) - G_PlayerInputAnalog(pid, gc_down, 0)) / (float)JOYAXISRANGE, + }; + + box.patch(gfx("PAD{}", dpad_suffix(dpad))); + box.patch(but('A', gc_a)); + box.patch(but('B', gc_b)); + box.patch(but('C', gc_c)); + box.patch(but('X', gc_x)); + box.patch(but('Y', gc_y)); + box.patch(but('Z', gc_z)); + box.patch(but('L', gc_l)); + box.patch(but('R', gc_r)); + box.patch(but('S', gc_start)); +} diff --git a/src/k_hud.h b/src/k_hud.h index 95fd79931..9a08843fa 100644 --- a/src/k_hud.h +++ b/src/k_hud.h @@ -63,6 +63,8 @@ void K_DrawKartPositionNumXY( boolean exit, boolean lastLap, boolean losing ); +void K_DrawInputDisplay(INT32 x, INT32 y, UINT8 pid); + extern patch_t *kp_capsuletarget_arrow[2][2]; extern patch_t *kp_capsuletarget_icon[2]; extern patch_t *kp_capsuletarget_far[2][2]; diff --git a/src/k_menudraw.c b/src/k_menudraw.c index 091149e25..3e58d825a 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -4742,52 +4742,6 @@ INT16 controlleroffsets[][2] = { {149, 187}, // gc_start }; -// Controller patches for button presses. -// reminder that lumpnames can only be 8 chars at most. (+1 for \0) - -static const char *controllerpresspatch[9][2] = { - {"PR_BTA", "PR_BTAB"}, // MBT_A - {"PR_BTB", "PR_BTBB"}, // MBT_B - {"PR_BTC", "PR_BTCB"}, // MBT_C - {"PR_BTX", "PR_BTXB"}, // MBT_X - {"PR_BTY", "PR_BTYB"}, // MBT_Y - {"PR_BTZ", "PR_BTZB"}, // MBT_Z - {"PR_BTL", "PR_BTLB"}, // MBT_L - {"PR_BTR", "PR_BTRB"}, // MBT_R - {"PR_BTS", "PR_BTSB"}, // MBT_START -}; - -static const char *M_GetDPadPatchName(SINT8 ud, SINT8 lr) -{ - if (ud < 0) - { - if (lr < 0) - return "PR_PADUL"; - else if (lr > 0) - return "PR_PADUR"; - else - return "PR_PADU"; - } - else if (ud > 0) - { - if (lr < 0) - return "PR_PADDL"; - else if (lr > 0) - return "PR_PADDR"; - else - return "PR_PADD"; - } - else - { - if (lr < 0) - return "PR_PADL"; - else if (lr > 0) - return "PR_PADR"; - else - return "PR_PADN"; - } -} - static void M_DrawBindBen(INT32 x, INT32 y, INT32 scroll_remaining) { // optionsmenu.bindben_swallow @@ -4896,26 +4850,7 @@ void M_DrawProfileControls(void) patch_t *hint = W_CachePatchName("MENUHINT", PU_CACHE); INT32 hintofs = 3; - V_DrawScaledPatch(BASEVIDWIDTH*2/3 - optionsmenu.contx, BASEVIDHEIGHT/2 -optionsmenu.conty, 0, W_CachePatchName("PR_CONT", PU_CACHE)); - - // Draw button presses... - V_DrawScaledPatch( - BASEVIDWIDTH*2/3 - optionsmenu.contx, - BASEVIDHEIGHT/2 - optionsmenu.conty, - 0, - W_CachePatchName(M_GetDPadPatchName(menucmd[pid].dpad_ud, menucmd[pid].dpad_lr), PU_CACHE) - ); - - for (i = 0; i < 9; i++) - { - INT32 bt = 1<