Skip to content

Commit

Permalink
SHUD: WarmupInfo, GameType
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandr Bushuev committed Dec 27, 2024
1 parent 9c46f67 commit e3ccb1f
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 147 deletions.
5 changes: 5 additions & 0 deletions assets/hud/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,9 @@ Obituary3 { rect 0 20 640 10; }
Obituary2 { rect 0 30 640 10; }
Obituary1 { rect 0 40 640 10; }

# Warmup
!default { fade 1 1 1 1; fontsize 8 10; textstyle 1; time 4800; fadedelay 200; color 1 1 1 1; alignh R; style 1; textalign R; }
gametype { rect 0 60 640 10; }
warmupinfo { rect 0 70 640 10; }


1 change: 1 addition & 0 deletions build/linux-qvm/srcs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ CG_SRC = \
cg_superhud_element_team \
cg_superhud_element_weaponlist \
cg_superhud_element_obituaries \
cg_superhud_element_warmupinfo cg_superhud_element_gametype \
l_crc \
cg_chatfilter cg_crosshair\

Expand Down
146 changes: 2 additions & 144 deletions code/cgame/cg_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ void CG_DrawWarmup(void)
}
}

void CG_DrawWarmupNew(void)
void CG_DrawWarmupShud(void)
{
int sec = cg.warmup;

Expand All @@ -2228,134 +2228,18 @@ void CG_DrawWarmupNew(void)
}
else if (sec < 0)
{
CG_OSPDrawString(SCREEN_WIDTH / 2.0f, 24,
cgs.gametype != GT_TOURNAMENT ? "^BWaiting for Players" : "^BWaiting for Opponent",
colorRed,
14, 14,
32, DS_HCENTER | DS_PROPORTIONAL);
cg.warmupCount = 0;
}
else // warmup > 0
{
if (cgs.gametype == GT_TOURNAMENT)
{
const char* player1Name = NULL;
const char* player2Name = NULL;
int i;

for (i = 0; i < cgs.maxclients; ++i)
{
if (cgs.clientinfo[i].name[0] && cgs.clientinfo[i].team == TEAM_FREE)
{
if (!player1Name)
{
player1Name = cgs.clientinfo[i].name;
}
else
{
player2Name = cgs.clientinfo[i].name;
break;
}
}
}
if (player1Name && player2Name)
{
int len;
int width;
const char* text;
text = va("%s^7 vs %s", player1Name, player2Name);

len = CG_DrawStrlen(text);

if (len > 20)
{
width = SCREEN_WIDTH / len;
}
else
{
width = 32;
}

CG_OSPDrawString(SCREEN_WIDTH / 2.0f, 20,
text,
colorWhite,
width, width * 1.5f,
128, DS_HCENTER | DS_PROPORTIONAL);
}
}
else
{
const char* text;
int len;
int width;

if (cgs.osp.clanBaseTeamDM)
{
text = "ClanBase TeamDM";
}
else if (cgs.gametype == GT_FFA)
{
text = "Free for all";
}
else if (cgs.gametype == GT_TEAM)
{
if (cgs.osp.gameTypeFreeze == 0)
{
text = "Team Deathmatch";
}
else if (cgs.osp.gameTypeFreeze == 2)
{

text = "FreezeTag TDM (Vanilla)";
}
else
{
text = "FreezeTag TDM";
}
}
else if (cgs.gametype == GT_CTF)
{
text = "Capture the Flag";
}
else if (cgs.gametype == GT_CA)
{
text = "Clan Arena";
}
else
{
text = "";
}

len = CG_DrawStrlen(text);
if (len > 0x14)
{
width = SCREEN_WIDTH / len;
}
else
{
width = 32;
}
CG_OSPDrawString(SCREEN_WIDTH / 2.0f, 25,
text,
colorLtGrey,
width, width * 1.1f,
128, DS_HCENTER | DS_PROPORTIONAL);
}

if (cg.showScores == 0)
{
int cw;
float* color = colorWhite;
const char* s;
int w;

sec = (sec - cg.time) / 1000;
if (sec < 0)
{
cg.warmup = 0;
sec = 0;
}
s = va("Starts in: %i", sec + 1);
if (sec != cg.warmupCount)
{
cg.warmupCount = sec;
Expand All @@ -2374,32 +2258,6 @@ void CG_DrawWarmupNew(void)
break;
}
}

switch (cg.warmupCount)
{
case 0:
cw = 28;
color = colorLtGrey;
break;
case 1:
cw = 24;
color = colorYellow;
break;
case 2:
cw = 20;
color = colorWhite;
break;
default:
cw = 16;
break;
}

w = CG_DrawStrlen(s);
CG_OSPDrawString(SCREEN_WIDTH / 2.0f, 70,
s,
color,
cw, cw * 1.5f,
128, DS_HCENTER | DS_PROPORTIONAL);
}
}
}
Expand Down Expand Up @@ -2453,7 +2311,7 @@ static void CG_Draw2D(void)
if (cg_shud.integer)
{
CG_SHUDRoutine();
CG_DrawWarmupNew();
CG_DrawWarmupShud();
return;
}

Expand Down
2 changes: 1 addition & 1 deletion code/cgame/cg_servercmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ static void CG_MapRestart(void)
if (cg.warmup == 0 /* && cgs.gametype == GT_TOURNAMENT */)
{
trap_S_StartLocalSound(cgs.media.countFightSound, CHAN_ANNOUNCER);
CG_CenterPrint("^1FIGHT!", 20, GIANTCHAR_WIDTH * 2);
if (!cg_shud.integer) CG_CenterPrint("^1FIGHT!", 20, GIANTCHAR_WIDTH * 2);
}
trap_Cvar_Set("cg_thirdPerson", "0");
}
Expand Down
126 changes: 126 additions & 0 deletions code/cgame/cg_superhud_element_gametype.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include "cg_local.h"
#include "cg_superhud_private.h"
#include "../qcommon/qcommon.h"

typedef struct
{
superhudConfig_t config;
int timePrev;
superhudTextContext_t ctx;
} shudElementGameType_t;

void* CG_SHUDElementGameTypeCreate(const superhudConfig_t* config)
{
shudElementGameType_t* element;

SHUD_ELEMENT_INIT(element, config);

CG_SHUDTextMakeContext(&element->config, &element->ctx);
element->ctx.maxchars = 9;

return element;
}

void CG_SHUDElementGameTypeRoutine(void* context)
{
shudElementGameType_t* element = (shudElementGameType_t*)context;
char str[512];

int sec = cg.warmup;

CG_SHUDFill(&element->config);

element->ctx.text = NULL;

if (sec > 0)
{
if (cgs.gametype == GT_TOURNAMENT)
{
const char* player1Name = NULL;
const char* player2Name = NULL;
int i;

for (i = 0; i < cgs.maxclients; ++i)
{
if (cgs.clientinfo[i].name[0] && cgs.clientinfo[i].team == TEAM_FREE)
{
if (!player1Name)
{
player1Name = cgs.clientinfo[i].name;
}
else
{
player2Name = cgs.clientinfo[i].name;
break;
}
}
}
if (player1Name && player2Name)
{
Com_sprintf(str, 512, "%s^7 vs %s", player1Name, player2Name);
element->ctx.text = str;
}
}
else
{
const char* text;
int len;
int width;

if (cgs.osp.clanBaseTeamDM)
{
text = "ClanBase TeamDM";
}
else if (cgs.gametype == GT_FFA)
{
text = "Free for all";
}
else if (cgs.gametype == GT_TEAM)
{
if (cgs.osp.gameTypeFreeze == 0)
{
text = "Team Deathmatch";
}
else if (cgs.osp.gameTypeFreeze == 2)
{

text = "FreezeTag TDM (Vanilla)";
}
else
{
text = "FreezeTag TDM";
}
}
else if (cgs.gametype == GT_CTF)
{
text = "Capture the Flag";
}
else if (cgs.gametype == GT_CA)
{
text = "Clan Arena";
}
else
{
text = "";
}
Com_sprintf(str, 512, "%s", text);
element->ctx.text = str;
}
}
if (!element->ctx.text)
{
return;
}
CG_SHUDFill(&element->config);

CG_SHUDTextPrint(&element->config, &element->ctx);
}

void CG_SHUDElementGameTypeDestroy(void* context)
{
if (context)
{
Z_Free(context);
}
}

Loading

0 comments on commit e3ccb1f

Please sign in to comment.