Changed message drawing code. Added map preview to callvote HUD.

This commit is contained in:
Andrei Drexler 2011-03-10 15:04:36 +00:00
parent 738aca928b
commit cca2db1cef
6 changed files with 230 additions and 192 deletions

View file

@ -1375,14 +1375,13 @@ static int CG_DrawPickupItem(int y)
return y;
}
y -= ICON_SIZE;
value = cg.itemPickup;
if (value) {
fadeColor = CG_FadeColor(cg.itemPickupTime, 3000);
if (fadeColor) {
CG_RegisterItemVisuals(value);
trap_R_SetColor(fadeColor);
y -= ICON_SIZE;
CG_DrawPic(cgs.screenXMin + 8, y, ICON_SIZE, ICON_SIZE, cg_items[value].icon);
CG_DrawBigString(cgs.screenXMin + ICON_SIZE + 16, y + (ICON_SIZE / 2 - BIGCHAR_HEIGHT / 2),
bg_itemlist[value].pickup_name, fadeColor[0]);
@ -1393,6 +1392,68 @@ static int CG_DrawPickupItem(int y)
return y;
}
/*
=================
CG_DrawMessageQueue
=================
*/
static float CG_DrawMessageQueue(float y)
{
int w, h;
int i, len;
vec4_t hcolor;
int chatHeight;
float div;
#define CHATLOC_Y y
#define CHATLOC_X cgs.screenXMin
if (!cg_messageQueue.integer || cg_messageQueueTime.integer <= 0)
return y;
chatHeight = MSGQUEUE_HEIGHT;
while (cgs.teamLastChatPos < cgs.teamChatPos && cg.time - cgs.teamChatMsgTimes[cgs.teamLastChatPos % chatHeight] > cg_messageQueueTime.integer)
cgs.teamLastChatPos++;
if (cgs.teamLastChatPos == cgs.teamChatPos)
return y;
y -= 32;
h = (cgs.teamChatPos - cgs.teamLastChatPos) * TINYCHAR_HEIGHT;
w = 0;
for (i = cgs.teamLastChatPos; i < cgs.teamChatPos; i++) {
len = CG_DrawStrlen(cgs.teamChatMsgs[i % chatHeight]);
if (len > w)
w = len;
}
w *= TINYCHAR_WIDTH;
w += TINYCHAR_WIDTH * 2;
div = 1.f / cg_messageQueueTime.integer;
hcolor[0] = hcolor[1] = hcolor[2] = 1.0f;
hcolor[3] = 1.0f;
for (i = cgs.teamChatPos - 1; i >= cgs.teamLastChatPos; i--) {
int index = i % chatHeight;
float frac = (cg.time - cgs.teamChatMsgTimes[index]) * div;
if (frac > 1.f)
continue;
hcolor[3] = frac > 0.875f ? (1.f - frac) * 8.f : 1.f;
CG_DrawStringExt(CHATLOC_X + TINYCHAR_WIDTH,
CHATLOC_Y,
cgs.teamChatMsgs[index], hcolor, qfalse, qtrue,
TINYCHAR_WIDTH, TINYCHAR_HEIGHT, 0);
y -= TINYCHAR_HEIGHT;
}
return y;
}
/*
=====================
CG_DrawLowerLeft
@ -1409,79 +1470,12 @@ static void CG_DrawLowerLeft(void)
y = CG_DrawTeamOverlay(y, qfalse, qfalse);
}
y = CG_DrawMessageQueue(y);
y = CG_DrawPickupItem(y);
}
//===========================================================================================
/*
=================
CG_DrawTeamInfo
=================
*/
static void CG_DrawTeamInfo(void)
{
int w, h;
int i, len;
vec4_t hcolor;
int chatHeight;
#define CHATLOC_Y 420 // bottom end
#define CHATLOC_X 0
if (cg_teamChatHeight.integer < TEAMCHAT_HEIGHT)
chatHeight = cg_teamChatHeight.integer;
else
chatHeight = TEAMCHAT_HEIGHT;
if (chatHeight <= 0)
return; // disabled
if (cgs.teamLastChatPos != cgs.teamChatPos) {
if (cg.time - cgs.teamChatMsgTimes[cgs.teamLastChatPos % chatHeight] > cg_teamChatTime.integer) {
cgs.teamLastChatPos++;
}
h = (cgs.teamChatPos - cgs.teamLastChatPos) * TINYCHAR_HEIGHT;
w = 0;
for (i = cgs.teamLastChatPos; i < cgs.teamChatPos; i++) {
len = CG_DrawStrlen(cgs.teamChatMsgs[i % chatHeight]);
if (len > w)
w = len;
}
w *= TINYCHAR_WIDTH;
w += TINYCHAR_WIDTH * 2;
if (cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED) {
CG_TeamColor(TEAM_RED, hcolor);
hcolor[3] = 0.33f;
} else if (cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE) {
CG_TeamColor(TEAM_RED, hcolor);
hcolor[3] = 0.33f;
} else {
hcolor[0] = 0.0f;
hcolor[1] = 1.0f;
hcolor[2] = 0.0f;
hcolor[3] = 0.33f;
}
trap_R_SetColor(hcolor);
CG_DrawPic(CHATLOC_X, CHATLOC_Y - h, 640, h, cgs.media.teamStatusBar);
trap_R_SetColor(NULL);
hcolor[0] = hcolor[1] = hcolor[2] = 1.0f;
hcolor[3] = 1.0f;
for (i = cgs.teamChatPos - 1; i >= cgs.teamLastChatPos; i--) {
CG_DrawStringExt(CHATLOC_X + TINYCHAR_WIDTH,
CHATLOC_Y - (cgs.teamChatPos - i) * TINYCHAR_HEIGHT,
cgs.teamChatMsgs[i % chatHeight], hcolor, qfalse, qfalse,
TINYCHAR_WIDTH, TINYCHAR_HEIGHT, 0);
}
}
}
/*
===================
CG_DrawHoldableItem
@ -2211,11 +2205,12 @@ CG_DrawVote
*/
static void CG_DrawVote(void)
{
char *s, *s2;
const char *s;
int len;
int sec, y = 58;
int line;
float Color1[4];
float xmin;
int lines = 3;
if (!cgs.voteTime) {
return;
@ -2232,13 +2227,17 @@ static void CG_DrawVote(void)
sec = 0;
}
s = va("Vote: %s (%d seconds left)", cgs.voteString, sec);
s2 = va("Yes(%d) No(%d)", cgs.voteYes, cgs.voteNo);
s = va( "Vote called: %s\n"
"Yes(%d) No(%d)\n"
"%d %s left\n",
cgs.voteString,
cgs.voteYes, cgs.voteNo,
sec, sec == 1 ? "second" : "seconds"
);
MAKERGBA(Color1, 0.0f, 0.0f, 0.0f, 0.4f);
xmin = cgs.screenXMin;
line = SMALLCHAR_HEIGHT + 5;
xmin = cgs.screenXMin + 4;
if (cgs.media.voteMapShader)
{
@ -2250,24 +2249,15 @@ static void CG_DrawVote(void)
CG_DrawPic(xmin + 3, y + 2, width, height, cgs.media.voteMapShader);
xmin += width + 4 + 4;
y += ((height + 4) - (line + line)) / 2;
//y += ((height + 4) - (SMALLCHAR_HEIGHT * lines + 4)) / 2;
}
CG_FillRect(xmin + 1, y, CG_DrawStrlen(s) * SMALLCHAR_WIDTH + 4,
SMALLCHAR_HEIGHT + 4, Color1);
CG_DrawCleanRect(xmin + 1, y, CG_DrawStrlen(s) * SMALLCHAR_WIDTH + 4,
SMALLCHAR_HEIGHT + 4, 1, colorBlack);
len = CG_DrawStrlen(s) * SMALLCHAR_WIDTH;
CG_FillRect(xmin + 1, y, len + 4, SMALLCHAR_HEIGHT * lines + 4, Color1);
CG_DrawCleanRect(xmin + 1, y, len + 4, SMALLCHAR_HEIGHT * lines + 4, 1, colorBlack);
CG_DrawStringExt(xmin + 3, y+2, s, colorWhite, qtrue, qfalse,
SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 100);
y += line;
CG_FillRect(xmin + 1, y, CG_DrawStrlen(s2) * SMALLCHAR_WIDTH + 4,
SMALLCHAR_HEIGHT + 4, Color1);
CG_DrawCleanRect(xmin + 1, y, CG_DrawStrlen(s2) * SMALLCHAR_WIDTH + 4,
SMALLCHAR_HEIGHT + 4, 1, colorBlack);
CG_DrawStringExt(xmin + 3, y + 2, s2, colorWhite, qtrue, qfalse,
SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 100);
y += line;
SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 100);
}
/*
@ -2629,10 +2619,6 @@ static void CG_Draw2D(void)
CG_DrawHoldableItem();
CG_DrawReward();
}
if (cgs.gametype >= GT_TEAM) {
CG_DrawTeamInfo();
}
}
CG_DrawVote();

View file

@ -184,7 +184,7 @@ void CG_DrawChar(int x, int y, int width, int height, int ch)
ch &= 255;
if (ch == ' ') {
if (ch == ' ' || ch == '\t' || ch == '\n') {
return;
}
@ -241,7 +241,15 @@ void CG_DrawStringExt(int x, int y, const char *string, const float *setColor,
s += 2;
continue;
}
CG_DrawChar(xx + 2, y + 2, charWidth, charHeight, *s);
if (*s == '\n')
{
xx = x;
y += charHeight;
yoffset += charHeight;
++s;
continue;
}
CG_DrawChar(xx + 1, y + 1, charWidth, charHeight, *s);
cnt++;
xx += charWidth;
s++;
@ -272,6 +280,14 @@ void CG_DrawStringExt(int x, int y, const char *string, const float *setColor,
s += 2;
continue;
}
if (*s == '\n')
{
xx = x;
y += charHeight;
yoffset += charHeight;
++s;
continue;
}
CG_DrawChar(xx, y, charWidth, charHeight, *s);
if (underlined)
{
@ -323,17 +339,27 @@ int CG_DrawStrlen(const char *str)
{
const char *s = str;
int count = 0;
int max = 0;
while (*s) {
if (Q_IsColorString(s)) {
s += 2;
} else {
if (*s == '\n')
{
max = count > max ? count : max;
count = 0;
++s;
continue;
}
count++;
s++;
}
}
max = count > max ? count : max;
return count;
return max;
}
/*

View file

@ -459,8 +459,8 @@
#define CHAR_HEIGHT 48
#define TEXT_ICON_SPACE 4
#define TEAMCHAT_WIDTH 80
#define TEAMCHAT_HEIGHT 8
#define MSGQUEUE_WIDTH 80
#define MSGQUEUE_HEIGHT 8
// very large characters
#define GIANT_WIDTH 32
@ -1733,8 +1733,8 @@ typedef struct {
clientInfo_t clientinfo[MAX_CLIENTS];
// teamchat width is *3 because of embedded color codes
char teamChatMsgs[TEAMCHAT_HEIGHT][TEAMCHAT_WIDTH * 3 + 1];
int teamChatMsgTimes[TEAMCHAT_HEIGHT];
char teamChatMsgs[MSGQUEUE_HEIGHT][MSGQUEUE_WIDTH * 3 + 1];
int teamChatMsgTimes[MSGQUEUE_HEIGHT];
int teamChatPos;
int teamLastChatPos;
@ -1850,8 +1850,8 @@ extern vmCvar_t cg_lagometer;
extern vmCvar_t cg_drawAttacker;
extern vmCvar_t cg_synchronousClients;
extern vmCvar_t cg_gravity;
extern vmCvar_t cg_teamChatTime;
extern vmCvar_t cg_teamChatHeight;
extern vmCvar_t cg_messageQueueTime;
extern vmCvar_t cg_messageQueue;
extern vmCvar_t cg_stats;
extern vmCvar_t cg_forceModel;
extern vmCvar_t cg_buildScript;
@ -2065,6 +2065,10 @@ qboolean CG_Cvar_ClampInt(const char *name, vmCvar_t *vmCvar, int min, int max);
const char *CG_ConfigString(int index);
const char *CG_Argv(int arg);
void CG_InitMessageQueue(void);
void CG_UpdateMessageQueue(void);
void CG_AddMessage(const char* msg);
void QDECL CG_Printf(const char *msg, ...);
void QDECL CG_Error(const char *msg, ...);

View file

@ -512,8 +512,8 @@ vmCvar_t cg_thirdPersonAngle;
vmCvar_t cg_lagometer;
vmCvar_t cg_drawAttacker;
vmCvar_t cg_synchronousClients;
vmCvar_t cg_teamChatTime;
vmCvar_t cg_teamChatHeight;
vmCvar_t cg_messageQueueTime;
vmCvar_t cg_messageQueue;
vmCvar_t cg_stats;
vmCvar_t cg_buildScript;
vmCvar_t cg_forceModel;
@ -799,8 +799,8 @@ static cvarTable_t cvarTable[] = { // bk001129
{&cg_thirdPersonAngle, "cg_thirdPersonAngle", "0", CVAR_CHEAT},
//Makro - changing from CVAR_ROM (why was it like that ?) to CVAR_CHEAT
{&cg_thirdPerson, "cg_thirdPerson", "0", CVAR_CHEAT},
{&cg_teamChatTime, "cg_teamChatTime", "3000", CVAR_ARCHIVE},
{&cg_teamChatHeight, "cg_teamChatHeight", "0", CVAR_ARCHIVE},
{&cg_messageQueueTime, "cg_messageQueueTime", "3000", CVAR_ARCHIVE},
{&cg_messageQueue, "cg_messageQueue", "8", CVAR_ARCHIVE},
{&cg_forceModel, "cg_forceModel", "0", CVAR_ARCHIVE},
{&cg_predictItems, "cg_predictItems", "1", CVAR_ARCHIVE},
{&cg_deferPlayers, "cg_deferPlayers", "1", CVAR_ARCHIVE},
@ -1187,6 +1187,102 @@ int CG_LastAttacker(void)
return cg.snap->ps.persistant[PERS_ATTACKER];
}
void CG_AddMessage(const char* str)
{
int len;
char *p, *ls;
int lastcolor;
int chatHeight;
if (!cg_messageQueue.integer || cg_messageQueueTime.integer <= 0) {
// team chat disabled, dump into normal chat
cgs.teamChatPos = cgs.teamLastChatPos = 0;
trap_Print(str);
return;
}
chatHeight = MSGQUEUE_HEIGHT;
len = 0;
p = cgs.teamChatMsgs[cgs.teamChatPos % chatHeight];
*p = 0;
lastcolor = '7';
ls = NULL;
while (*str) {
if (len > MSGQUEUE_WIDTH - 1) {
if (ls) {
str -= (p - ls);
str++;
p -= (p - ls);
}
*p = 0;
cgs.teamChatMsgTimes[cgs.teamChatPos % chatHeight] = cg.time;
cgs.teamChatPos++;
p = cgs.teamChatMsgs[cgs.teamChatPos % chatHeight];
*p = 0;
*p++ = Q_COLOR_ESCAPE;
*p++ = lastcolor;
len = 2;
ls = NULL;
}
if (Q_IsColorString(str)) {
*p++ = *str++;
lastcolor = *str;
*p++ = *str++;
len += 2;
continue;
}
if (*str == ' ') {
ls = p;
}
if (*str == '\n')
{
// skip last '\n'
if (!str[1])
break;
++str;
*p = 0;
cgs.teamChatMsgTimes[cgs.teamChatPos % chatHeight] = cg.time;
cgs.teamChatPos++;
p = cgs.teamChatMsgs[cgs.teamChatPos % chatHeight];
*p = 0;
*p++ = Q_COLOR_ESCAPE;
*p++ = lastcolor;
len = 2;
ls = NULL;
continue;
}
*p++ = *str++;
len++;
}
*p = 0;
cgs.teamChatMsgTimes[cgs.teamChatPos % chatHeight] = cg.time;
cgs.teamChatPos++;
if (cgs.teamChatPos - cgs.teamLastChatPos > chatHeight)
cgs.teamLastChatPos = cgs.teamChatPos - chatHeight;
// integer overflow is very unlikely, but still...
if (cgs.teamLastChatPos > chatHeight)
{
int extra = cgs.teamLastChatPos - cgs.teamLastChatPos % chatHeight;
cgs.teamLastChatPos -= extra;
cgs.teamChatPos -= extra;
}
}
void QDECL CG_Printf(const char *msg, ...)
{
va_list argptr;

View file

@ -546,13 +546,13 @@ void CG_TransitionPlayerState(playerState_t * ps, playerState_t * ops)
if (ps->weapon == WP_GRENADE && ps->weaponstate == WEAPON_COCKED && ops->weaponstate != WEAPON_COCKED) {
switch (CG_RQ3_GetGrenadeMode()) {
case RQ3_GRENSHORT | RQ3_GRENMED:
CG_Printf("Pin pulled. Ready to make a long range throw.\n");
CG_AddMessage("Pin pulled. Ready to make a long range throw.\n");
break;
case RQ3_GRENMED:
CG_Printf("Pin pulled. Ready to make a medium range throw.\n");
CG_AddMessage("Pin pulled. Ready to make a medium range throw.\n");
break;
case RQ3_GRENSHORT:
CG_Printf("Pin pulled. Ready to make a short range throw.\n");
CG_AddMessage("Pin pulled. Ready to make a short range throw.\n");
break;
}
}

View file

@ -753,80 +753,6 @@ static void CG_ConfigStringModified(void)
}
/*
=======================
CG_AddToTeamChat
=======================
*/
static void CG_AddToTeamChat(const char *str)
{
int len;
char *p, *ls;
int lastcolor;
int chatHeight;
if (cg_teamChatHeight.integer < TEAMCHAT_HEIGHT) {
chatHeight = cg_teamChatHeight.integer;
} else {
chatHeight = TEAMCHAT_HEIGHT;
}
if (chatHeight <= 0 || cg_teamChatTime.integer <= 0) {
// team chat disabled, dump into normal chat
cgs.teamChatPos = cgs.teamLastChatPos = 0;
return;
}
len = 0;
p = cgs.teamChatMsgs[cgs.teamChatPos % chatHeight];
*p = 0;
lastcolor = '7';
ls = NULL;
while (*str) {
if (len > TEAMCHAT_WIDTH - 1) {
if (ls) {
str -= (p - ls);
str++;
p -= (p - ls);
}
*p = 0;
cgs.teamChatMsgTimes[cgs.teamChatPos % chatHeight] = cg.time;
cgs.teamChatPos++;
p = cgs.teamChatMsgs[cgs.teamChatPos % chatHeight];
*p = 0;
*p++ = Q_COLOR_ESCAPE;
*p++ = lastcolor;
len = 0;
ls = NULL;
}
if (Q_IsColorString(str)) {
*p++ = *str++;
lastcolor = *str;
*p++ = *str++;
continue;
}
if (*str == ' ') {
ls = p;
}
*p++ = *str++;
len++;
}
*p = 0;
cgs.teamChatMsgTimes[cgs.teamChatPos % chatHeight] = cg.time;
cgs.teamChatPos++;
if (cgs.teamChatPos - cgs.teamLastChatPos > chatHeight)
cgs.teamLastChatPos = cgs.teamChatPos - chatHeight;
}
/*
===============
CG_MapRestart
@ -1424,12 +1350,12 @@ void CG_RQ3_Cmd( void )
cg.showScores = qfalse;
cg.scoreTPMode = 0;
CG_CenterPrint("LIGHTS...", SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH);
CG_Printf("\nLIGHTS...\n");
CG_AddMessage("\nLIGHTS...\n");
CG_AddBufferedSound(cgs.media.lightsSound);
break;
case CAMERA:
CG_CenterPrint("CAMERA...", SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH);
CG_Printf("\nCAMERA...\n");
CG_AddMessage("\nCAMERA...\n");
CG_AddBufferedSound(cgs.media.cameraSound);
break;
case TPCOUNTDOWN:
@ -1437,7 +1363,7 @@ void CG_RQ3_Cmd( void )
break;
case ACTION:
CG_CenterPrint("ACTION!", SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH);
CG_Printf("\nACTION!\n");
CG_AddMessage("\nACTION!\n");
cg.lca = 0;
// trap_Cvar_Set("cg_RQ3_lca", "0");
CG_AddBufferedSound(cgs.media.actionSound);
@ -1609,7 +1535,8 @@ static void CG_ServerCommand(void)
}
if (!strcmp(cmd, "print")) {
CG_Printf("%s", CG_Argv(1));
//CG_Printf("%s", CG_Argv(1));
CG_AddMessage(CG_Argv(1));
return;
}
@ -1618,7 +1545,7 @@ static void CG_ServerCommand(void)
trap_S_StartLocalSound(cgs.media.talkSound, CHAN_LOCAL_SOUND);
Q_strncpyz(text, CG_Argv(1), MAX_SAY_TEXT);
CG_RemoveChatEscapeChar(text);
CG_Printf("%s\n", text);
CG_AddMessage(text);
}
return;
}
@ -1627,8 +1554,7 @@ static void CG_ServerCommand(void)
trap_S_StartLocalSound(cgs.media.talkSound, CHAN_LOCAL_SOUND);
Q_strncpyz(text, CG_Argv(1), MAX_SAY_TEXT);
CG_RemoveChatEscapeChar(text);
CG_AddToTeamChat(text);
CG_Printf("%s\n", text);
CG_AddMessage(text);
return;
}
if (!strcmp(cmd, "vchat")) {