From bc479321d00c0c29f5c543b139786f08e56a3999 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 24 Feb 2024 21:26:35 -0800 Subject: [PATCH] Replace in-map input display with new graphics --- src/hud/input-display.cpp | 59 +++++++++++++++--------- src/k_hud.cpp | 97 ++++++++------------------------------- src/k_hud.h | 2 +- src/k_menudraw.c | 2 +- 4 files changed, 60 insertions(+), 100 deletions(-) diff --git a/src/hud/input-display.cpp b/src/hud/input-display.cpp index 99d3fe943..abc66752b 100644 --- a/src/hud/input-display.cpp +++ b/src/hud/input-display.cpp @@ -17,6 +17,7 @@ #include "../g_game.h" #include "../i_joy.h" #include "../k_hud.h" +#include "../k_kart.h" #include "../v_draw.hpp" using srb2::Draw; @@ -58,31 +59,47 @@ const char* dpad_suffix(const Vec2& v) }; // 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_"; + const ticcmd_t& cmd = players[displayplayers[pid]].cmd; + const std::string prefix = fmt::format("PR{}", mode); 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, + auto but = [&](char key, INT32 gc, UINT32 bt) + { + bool press = local ? G_PlayerInputAnalog(pid, gc, 0) : ((cmd.buttons & bt) == bt); + return gfx(press ? "BT{}B" : "BT{}", key); }; + Draw box = Draw(x, y).flags(flags); + + box.flags(transparent ? V_TRANSLUCENT : 0).patch(gfx("CONT")); + + Vec2 dpad = local ? + Vec2 { + (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, + } : + Vec2 { + -cmd.turning / (float)KART_FULLTURN, + (float)cmd.throwdir, + }; + 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)); + box.patch(but('A', gc_a, BT_ACCELERATE)); + box.patch(but('B', gc_b, BT_LOOKBACK)); + box.patch(but('C', gc_c, BT_SPINDASHMASK)); + box.patch(but('X', gc_x, BT_BRAKE)); + box.patch(but('Y', gc_y, BT_RESPAWN)); + box.patch(but('Z', gc_z, BT_VOTE)); + box.patch(but('L', gc_l, BT_ATTACK)); + box.patch(but('R', gc_r, BT_DRIFT)); + box.patch(but('S', gc_start, 0xFFFFFFFF)); + + if (mode == '4' || mode == '5') // Saturn 3D + { + float dist = (mode == '4') ? 3.f : 2.f; + + box.patch(gfx("JOY1")); + box.xy(dpad.x * dist, -dpad.y * dist).patch(gfx("JOY2")); + } } diff --git a/src/k_hud.cpp b/src/k_hud.cpp index 7eb39841f..16901f3f0 100644 --- a/src/k_hud.cpp +++ b/src/k_hud.cpp @@ -50,6 +50,7 @@ #include "k_rank.h" #include "g_party.h" #include "k_hitlag.h" +#include "g_input.h" //{ Patch Definitions static patch_t *kp_nodraw; @@ -5160,85 +5161,27 @@ static void K_drawKartFirstPerson(void) } } -// doesn't need to ever support 4p static void K_drawInput(void) { - static INT32 pn = 0; - INT32 target = 0, splitflags = (V_SNAPTOBOTTOM|V_SNAPTORIGHT); - INT32 x = BASEVIDWIDTH - 32, y = BASEVIDHEIGHT-24, offs, col; - const INT32 accent1 = splitflags | skincolors[stplyr->skincolor].ramp[5]; - const INT32 accent2 = splitflags | skincolors[stplyr->skincolor].ramp[9]; - ticcmd_t *cmd = &stplyr->cmd; - -#define BUTTW 8 -#define BUTTH 11 - -#define drawbutt(xoffs, butt, symb)\ - if (!stplyr->exiting && (cmd->buttons & butt))\ - {\ - offs = 2;\ - col = accent1;\ - }\ - else\ - {\ - offs = 0;\ - col = accent2;\ - V_DrawFill(x+(xoffs), y+BUTTH, BUTTW-1, 2, splitflags|31);\ - }\ - V_DrawFill(x+(xoffs), y+offs, BUTTW-1, BUTTH, col);\ - V_DrawFixedPatch((x+1+(xoffs))<exiting || !stplyr->steering) // no turn - target = 0; - else // turning of multiple strengths! - { - target = ((abs(stplyr->steering) - 1)/125)+1; - if (target > 4) - target = 4; - if (stplyr->steering < 0) - target = -target; - } - - if (pn != target) - { - if (abs(pn - target) == 1) - pn = target; - else if (pn < target) - pn += 2; - else //if (pn > target) - pn -= 2; - } - - if (pn < 0) - { - splitflags |= V_FLIP; // right turn - x--; - } - - target = abs(pn); - if (target > 4) - target = 4; - - if (!stplyr->skincolor) - V_DrawFixedPatch(x<(stplyr->skincolor), GTC_CACHE); - V_DrawFixedPatch(x<pflags & PF_ANALOGSTICK) ? '4' : '2') + (r_splitscreen > 1); + bool local = !demo.playback && P_IsMachineLocalPlayer(stplyr); + K_DrawInputDisplay( + def[k][0], + def[k][1], + flags, + mode, + (local ? G_LocalSplitscreenPartyPosition : G_PartyPosition)(stplyr - players), + local, + stplyr->speed > 0 + ); } static void K_drawChallengerScreen(void) diff --git a/src/k_hud.h b/src/k_hud.h index 9a08843fa..422f3559f 100644 --- a/src/k_hud.h +++ b/src/k_hud.h @@ -63,7 +63,7 @@ void K_DrawKartPositionNumXY( boolean exit, boolean lastLap, boolean losing ); -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); extern patch_t *kp_capsuletarget_arrow[2][2]; extern patch_t *kp_capsuletarget_icon[2]; diff --git a/src/k_menudraw.c b/src/k_menudraw.c index 3e58d825a..fcca6aad0 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -4850,7 +4850,7 @@ void M_DrawProfileControls(void) patch_t *hint = W_CachePatchName("MENUHINT", PU_CACHE); INT32 hintofs = 3; - K_DrawInputDisplay(BASEVIDWIDTH*2/3 - optionsmenu.contx, BASEVIDHEIGHT/2 - optionsmenu.conty, pid); + K_DrawInputDisplay(BASEVIDWIDTH*2/3 - optionsmenu.contx, BASEVIDHEIGHT/2 - optionsmenu.conty, 0, '_', pid, true, false); if (optionsmenu.trycontroller) {