1
0
Fork 0
forked from fte/fteqw

Fixed 2 warnings in plugin.c. Added magic fix for UI_DrawChar by TimeServ. Fixed hud_save and hud_load so you don't have to write the .hud file extension when saving/loading. Added partially working "tracking" hud element, it needs to be fixed so it doesn't show if the local player is a spectator, any ideas how to check that?

Also starting to implement a feature to modify hud elements from the console.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2589 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Molgrum 2007-08-11 15:20:35 +00:00
parent 8f285d7787
commit 55cf7068fd
2 changed files with 87 additions and 22 deletions

View file

@ -41,6 +41,13 @@ int K_PAGEDOWN;
#define STAT_MONSTERS 14 // bumped by svc_killedmonster #define STAT_MONSTERS 14 // bumped by svc_killedmonster
#define STAT_ITEMS 15 #define STAT_ITEMS 15
// context menus
#define CONTEXT_NONE 0
#define CONTEXT_MAIN 1
#define CONTEXT_NEW_ITEM 2
#define CONTEXT_NEW_ITEM_SUB 3
//some engines can use more. //some engines can use more.
//any mod specific ones should be 31 and downwards rather than upwards. //any mod specific ones should be 31 and downwards rather than upwards.
@ -87,13 +94,13 @@ int K_PAGEDOWN;
#define UI_NOFLASH "ui_nosbarflash" #define UI_NOFLASH "ui_nosbarflash"
static char *weaponabbreviation[] = { //the postfix for the weapon anims static char *weaponabbreviation[] = { //the postfix for the weapon anims
"shotgun", "shotgun", // shotgun
"sshotgun", "sshotgun", // super shotgun
"nailgun", "nailgun", // nailgun
"snailgun", "snailgun", // super nailgun
"rlaunch", //grenades actually. "rlaunch", // grenade launcher
"srlaunch", "srlaunch", // rocket launcher
"lightng" "lightng" // thunderbolt
}; };
#define numweaps (sizeof(weaponabbreviation) / sizeof(char *)) #define numweaps (sizeof(weaponabbreviation) / sizeof(char *))
@ -188,6 +195,7 @@ drawelementfnc_t Hud_ScoreName;
drawelementfnc_t Hud_Blackness; drawelementfnc_t Hud_Blackness;
drawelementfnc_t Hud_TeamScore; drawelementfnc_t Hud_TeamScore;
drawelementfnc_t Hud_TeamName; drawelementfnc_t Hud_TeamName;
drawelementfnc_t Hud_Tracking;
// TODO: more elements // TODO: more elements
// - generalized graphic elements // - generalized graphic elements
// - cvar controlled small and big numbers // - cvar controlled small and big numbers
@ -232,9 +240,9 @@ drawelement_t drawelement[] =
{Hud_Blackness, "Blackness", 16, 16, 9, {"10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"}}, {Hud_Blackness, "Blackness", 16, 16, 9, {"10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"}},
{Hud_ScoreCard, "Scorecard", 32, 8, 15, {"Player 0", "Player 1", "Player 2", "Player 3", "Player 4", "Player 5", "Player 6", "Player 7", "Player 8", "Player 9", "Player 10", "Player 11", "Player 12", "Player 13", "Player 14", "Player 15"}}, {Hud_ScoreCard, "Scorecard", 32, 8, 15, {"Player 0", "Player 1", "Player 2", "Player 3", "Player 4", "Player 5", "Player 6", "Player 7", "Player 8", "Player 9", "Player 10", "Player 11", "Player 12", "Player 13", "Player 14", "Player 15"}},
{Hud_ScoreName, "Scorename", 128, 8, 7, {"Player 0", "Player 1", "Player 2", "Player 3", "Player 4", "Player 5", "Player 6", "Player 7"}}, {Hud_ScoreName, "Scorename", 128, 8, 7, {"Player 0", "Player 1", "Player 2", "Player 3", "Player 4", "Player 5", "Player 6", "Player 7"}},
{Hud_TeamScore, "TeamScore", 32, 8, 7, {"Team 0", "Team 1", "Team 2", "Team 3", "Team 4", "Team 5", "Team 6", "Team 7"}}, {Hud_TeamScore, "TeamScore", 32, 8, 7, {"Team 0", "Team 1", "Team 2", "Team 3", "Team 4", "Team 5", "Team 6", "Team 7"}},
{Hud_TeamName, "TeamName", 128, 8, 7, {"Team 0", "Team 1", "Team 2", "Team 3", "Team 4", "Team 5", "Team 6", "Team 7"}} {Hud_TeamName, "TeamName", 128, 8, 7, {"Team 0", "Team 1", "Team 2", "Team 3", "Team 4", "Team 5", "Team 6", "Team 7"}},
{Hud_Tracking, "Tracking", 128, 8, 0}
}; };
huddefaultelement_t hedefaulttype[] = { huddefaultelement_t hedefaulttype[] = {
@ -437,6 +445,30 @@ qboolean mousedown, shiftdown;
float mouseofsx, mouseofsy; float mouseofsx, mouseofsy;
qboolean context; qboolean context;
/*
==================
COM_DefaultExtension
==================
*/
void COM_DefaultExtension (char *path, char *extension, int maxlen)
{
char *src;
//
// if path doesn't have a .EXT, append extension
// (extension should include the .)
//
src = path + strlen(path) - 1;
while (*src != '/' && src != path)
{
if (*src == '.')
return; // it has an extension
src--;
}
strlcpy (path+strlen(path), extension, maxlen);
}
void UI_DrawPic(qhandle_t pic, int x, int y, int width, int height) void UI_DrawPic(qhandle_t pic, int x, int y, int width, int height)
{ {
Draw_Image((float)x*sbarscalex+sbarminx, (float)y*sbarscaley+sbarminy, (float)width*sbarscalex, (float)height*sbarscaley, 0, 0, 1, 1, pic); Draw_Image((float)x*sbarscalex+sbarminx, (float)y*sbarscaley+sbarminy, (float)width*sbarscalex, (float)height*sbarscaley, 0, 0, 1, 1, pic);
@ -445,7 +477,7 @@ void UI_DrawChar(unsigned int c, int x, int y)
{ {
static float size = 1.0f/16.0f; static float size = 1.0f/16.0f;
float s1 = size * (c&15); float s1 = size * (c&15);
float t1 = size * (c>>4); float t1 = size * ((c>>4)&15);
Draw_Image((float)x*sbarscalex+sbarminx, (float)y*sbarscaley+sbarminy, 8*sbarscalex, 8*sbarscaley, s1, t1, s1+size, t1+size, con_chars); Draw_Image((float)x*sbarscalex+sbarminx, (float)y*sbarscaley+sbarminy, 8*sbarscalex, 8*sbarscaley, s1, t1, s1+size, t1+size, con_chars);
} }
void UI_DrawString(char *s, int x, int y) void UI_DrawString(char *s, int x, int y)
@ -897,7 +929,7 @@ float pc[16][3] =
}; };
int numsortedplayers; int numsortedplayers;
int playerlocal; int trackedplayer;
int sortedplayers[32]; int sortedplayers[32];
plugclientinfo_t players[32]; plugclientinfo_t players[32];
@ -907,11 +939,11 @@ void SortPlayers(void)
int temp; int temp;
numsortedplayers = 0; numsortedplayers = 0;
playerlocal = -1; trackedplayer = -1;
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
{ {
if (GetPlayerInfo(i, &players[i])>0) if (GetPlayerInfo(i, &players[i])>0)
playerlocal = i; trackedplayer = i;
if (players[i].spectator) if (players[i].spectator)
continue; continue;
if (*players[i].name != 0) if (*players[i].name != 0)
@ -947,11 +979,11 @@ void SortTeams(void)
int i, j; int i, j;
numsortedplayers = 0; numsortedplayers = 0;
playerlocal = -1; trackedplayer = -1;
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
{ {
if (GetPlayerInfo(i, &players[i])>0) if (GetPlayerInfo(i, &players[i])>0)
playerlocal = i; trackedplayer = i;
if (players[i].spectator) if (players[i].spectator)
continue; continue;
if (*players[i].name != 0) if (*players[i].name != 0)
@ -1009,7 +1041,7 @@ void Hud_ScoreCard(void)
bc = players[p].bottomcolour; bc = players[p].bottomcolour;
tc = players[p].topcolour; tc = players[p].topcolour;
frags = players[p].frags; frags = players[p].frags;
brackets = p==playerlocal; brackets = p==trackedplayer;
} }
Draw_Colour4f(pc[tc][0], pc[tc][1], pc[tc][2], sbaralpha); Draw_Colour4f(pc[tc][0], pc[tc][1], pc[tc][2], sbaralpha);
@ -1072,7 +1104,7 @@ void Hud_TeamScore(void)
bc = team[p].bc; bc = team[p].bc;
tc = team[p].tc; tc = team[p].tc;
frags = team[p].frags; frags = team[p].frags;
brackets = p==playerlocal; brackets = p==trackedplayer;
} }
Draw_Colour4f(pc[tc][0], pc[tc][1], pc[tc][2], sbaralpha); Draw_Colour4f(pc[tc][0], pc[tc][1], pc[tc][2], sbaralpha);
@ -1161,6 +1193,23 @@ void Hud_Blackness(void)
Draw_Colour4f(1,1,1,1); Draw_Colour4f(1,1,1,1);
} }
void Hud_Tracking(void)
{
qboolean flag = false;
char str[256];
if (hudedit)
{
UI_DrawString("Tracking ...", 0, 0);
return;
}
// FIXME: Need a check here to return if we are not spectating
// Print it
snprintf(str, sizeof(str), "Tracking %s", players[trackedplayer].name);
UI_DrawString(str, 0, 0);
}
void UI_DrawHandles(int *arg, int i) void UI_DrawHandles(int *arg, int i)
{ {
@ -1312,13 +1361,16 @@ void PutInteger(int i, char sep, qhandle_t handle)
void Hud_Save(char *fname) void Hud_Save(char *fname)
{ {
char name[256];
int i; int i;
qhandle_t handle; qhandle_t handle;
if (!fname || !*fname) if (!fname || !*fname)
fname = DEFAULTHUDNAME; fname = DEFAULTHUDNAME;
if (FS_Open(fname, &handle, 2)<0) snprintf(name, sizeof(name)-5, "huds/%s", fname);
COM_DefaultExtension(name, ".hud", sizeof(name));
if (FS_Open(name, &handle, 2)<0)
{ {
Con_Printf("Couldn't open %s\n", fname); Con_Printf("Couldn't open %s\n", name);
return; return;
} }
@ -1376,6 +1428,7 @@ int GetInteger(char **f, qhandle_t handle)
void Hud_Load(char *fname) void Hud_Load(char *fname)
{ {
char file[16384]; char file[16384];
char name[256];
char *p; char *p;
int len; int len;
int i; int i;
@ -1387,7 +1440,9 @@ void Hud_Load(char *fname)
if (!fname || !*fname) if (!fname || !*fname)
fname = DEFAULTHUDNAME; fname = DEFAULTHUDNAME;
len = FS_Open(fname, &handle, 1); snprintf(name, sizeof(name)-5, "huds/%s", fname);
COM_DefaultExtension(name, ".hud", sizeof(name));
len = FS_Open(name, &handle, 1);
if (len < 0) if (len < 0)
{ {
Con_Printf("Couldn't load file\n"); Con_Printf("Couldn't load file\n");
@ -2039,6 +2094,12 @@ int Plug_ExecuteCommand(int *args)
mousedown=false; mousedown=false;
return 1; return 1;
} }
// Modify a HUD element
if (!strcmp("sbar", cmd) || !strcmp("hud", cmd))
{
// FIXME: add this command
return 1;
}
return 0; return 0;
} }
@ -2080,6 +2141,10 @@ int Plug_Init(int *args)
Cmd_AddCommand("hud_defaults"); Cmd_AddCommand("hud_defaults");
Cmd_AddCommand("sbar_defaults"); Cmd_AddCommand("sbar_defaults");
// For modifying hud elements
Cmd_AddCommand("hud");
Cmd_AddCommand("sbar");
UI_SbarInit(); UI_SbarInit();
if (BUILTINISVALID(FS_Read)) if (BUILTINISVALID(FS_Read))

View file

@ -117,7 +117,7 @@ BUILTINR(int, Cvar_Update, (qhandle_t handle, int *modificationcount, char *stri
BUILTIN(void, CL_GetStats, (int pnum, unsigned int *stats, int maxstats)); BUILTIN(void, CL_GetStats, (int pnum, unsigned int *stats, int maxstats));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,pnum,info #define ARGNAMES ,pnum,info
BUILTIN(int, GetPlayerInfo, (int pnum, plugclientinfo_t *info)); BUILTINR(int, GetPlayerInfo, (int pnum, plugclientinfo_t *info));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,soundname #define ARGNAMES ,soundname
@ -132,7 +132,7 @@ BUILTIN(void, GetPluginName, (int plugnum, char *buffer, int bufsize));
BUILTINR(qhandle_t, Draw_LoadImage, (char *name, qboolean iswadimage)); //wad image is ONLY for loading out of q1 gfx.wad BUILTINR(qhandle_t, Draw_LoadImage, (char *name, qboolean iswadimage)); //wad image is ONLY for loading out of q1 gfx.wad
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,PASSFLOAT(x),PASSFLOAT(y),PASSFLOAT(w),PASSFLOAT(h),PASSFLOAT(s1),PASSFLOAT(t1),PASSFLOAT(s2),PASSFLOAT(t2),image #define ARGNAMES ,PASSFLOAT(x),PASSFLOAT(y),PASSFLOAT(w),PASSFLOAT(h),PASSFLOAT(s1),PASSFLOAT(t1),PASSFLOAT(s2),PASSFLOAT(t2),image
BUILTIN(int, Draw_Image, (float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t image)); BUILTINR(int, Draw_Image, (float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t image));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,PASSFLOAT(x1),PASSFLOAT(y1),PASSFLOAT(x2),PASSFLOAT(y2) #define ARGNAMES ,PASSFLOAT(x1),PASSFLOAT(y1),PASSFLOAT(x2),PASSFLOAT(y2)
BUILTIN(void, Draw_Line, (float x1, float y1, float x2, float y2)); BUILTIN(void, Draw_Line, (float x1, float y1, float x2, float y2));