Add 2P and 3P/4P timer HUD variations

This commit is contained in:
James R 2023-06-29 19:09:00 -07:00
parent 8c0f7d5757
commit 299a8b707c
5 changed files with 69 additions and 20 deletions

View file

@ -581,6 +581,7 @@ add_subdirectory(menus)
if(SRB2_CONFIG_ENABLE_WEBM_MOVIES)
add_subdirectory(media)
endif()
add_subdirectory(hud)
# strip debug symbols into separate file when using gcc.
# to be consistent with Makefile, don't generate for OS X.

3
src/hud/CMakeLists.txt Normal file
View file

@ -0,0 +1,3 @@
target_sources(SRB2SDL2 PRIVATE
timer.cpp
)

52
src/hud/timer.cpp Normal file
View file

@ -0,0 +1,52 @@
#include <algorithm>
#include "../doomstat.h"
#include "../g_game.h"
#include "../k_hud.h"
#include "../p_local.h"
#include "../v_draw.hpp"
using srb2::Draw;
namespace
{
constexpr INT32 kHudFlags = V_HUDTRANS | V_SLIDEIN;
}; // namespace
void K_drawKart2PTimestamp(void)
{
auto get_row = []
{
if (stplyr == &players[displayplayers[0]])
{
return Draw(286, 31).flags(V_SNAPTOTOP);
}
else
{
return Draw(286, 163).flags(V_SNAPTOBOTTOM);
}
};
Draw row = get_row().flags(kHudFlags | V_SNAPTORIGHT).font(Draw::Font::kZVote);
row.patch("K_STTIMS");
row.xy(12, 2).text("{:03}", stplyr->realtime / TICRATE);
}
void K_drawKart4PTimestamp(void)
{
Draw row = Draw(154, 0).flags(kHudFlags).font(Draw::Font::kZVote).align(Draw::Align::kCenter);
auto draw = [](const Draw& row, tic_t time)
{
row.patch("K_STTIMS");
row.xy(5, 12).text("{:03}", time / TICRATE);
};
auto time_of = [](int k) -> tic_t { return k <= r_splitscreen ? players[displayplayers[k]].realtime : 0u; };
draw(row.y(1).flags(V_SNAPTOTOP), std::max(time_of(0), time_of(1)));
draw(row.y(178).flags(V_SNAPTOBOTTOM), std::max(time_of(2), time_of(3)));
}

View file

@ -5294,7 +5294,6 @@ void K_drawKartHUD(void)
boolean islonesome = false;
boolean battlefullscreen = false;
boolean freecam = demo.freecam; //disable some hud elements w/ freecam
UINT8 i;
UINT8 viewnum = R_GetViewNumber();
// Define the X and Y for each drawn object
@ -5376,27 +5375,19 @@ void K_drawKartHUD(void)
islonesome = K_drawKartPositionFaces();
}
else if (viewnum == r_splitscreen
&& (gametyperules & GTR_TIMELIMIT)
&& timelimitintics > 0)
else if (r_splitscreen == 1)
{
tic_t highestrealtime = players[displayplayers[1]].realtime;
// Uses the highest time across all players (handles paused timer on exiting)
for (i = 1; i <= r_splitscreen; i++)
{
if (players[displayplayers[i]].realtime <= highestrealtime)
continue;
highestrealtime = players[displayplayers[i]].realtime;
}
// Draw the timestamp (mostly) CENTERED
if (LUA_HudEnabled(hud_time))
K_drawKartTimestamp(highestrealtime,
(r_splitscreen == 1 ? TIME_X : ((BASEVIDWIDTH/2) - 69)),
TIME_Y,
V_HUDTRANS|V_SLIDEIN|V_SNAPTOTOP|(r_splitscreen == 1 ? V_SNAPTORIGHT : 0),
0);
{
K_drawKart2PTimestamp();
}
}
else if (viewnum == r_splitscreen)
{
if (LUA_HudEnabled(hud_time))
{
K_drawKart4PTimestamp();
}
}
if (!stplyr->spectator && !demo.freecam) // Bottom of the screen elements, don't need in spectate mode

View file

@ -41,6 +41,8 @@ void K_LoadKartHUDGraphics(void);
void K_drawKartHUD(void);
void K_drawKartFreePlay(void);
void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT32 splitflags, UINT8 mode);
void K_drawKart2PTimestamp(void);
void K_drawKart4PTimestamp(void);
void K_DrawMapThumbnail(fixed_t x, fixed_t y, fixed_t width, UINT32 flags, UINT16 map, const UINT8 *colormap);
void K_DrawLikeMapThumbnail(fixed_t x, fixed_t y, fixed_t width, UINT32 flags, patch_t *patch, const UINT8 *colormap);
void K_drawTargetHUD(const vector3_t *origin, player_t *player);