Skip to content

Commit

Permalink
add gamehud.patch
Browse files Browse the repository at this point in the history
  • Loading branch information
sauerbraten committed Apr 12, 2021
1 parent e5b1ef1 commit ce6ec27
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 88 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ apply-patches:
$(PATCH) < patches/zenmode.patch
$(PATCH) < patches/authservers.patch
$(PATCH) < patches/serverlogging.patch
$(PATCH) < patches/gamehud.patch
unix2dos src/vcpp/sauerbraten.nsi
unix2dos src/vcpp/sauerbraten.vcxproj
cd src && make depend
Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This repository contains the source for my client mod, as well as the patches ap
- [zenmode.patch](#zenmodepatch)
- [authservers.patch](#authserverspatch)
- [serverlogging.patch](#serverloggingpatch)
- [gamehud.patch](#gamehudpatch)
- [Installation](#installation)
- [Windows](#windows)
- [macOS](#macos)
Expand All @@ -38,7 +39,6 @@ a.k.a. Features

### [moviehud.patch](./patches/moviehud.patch)

- adds `hidespecfollow` toggle: when 1, hides the "SPECTATOR" and player name in the lower right of the screen when spectating
- adds `namesabovehead` toggle: when 0, hides the names above players' models (usually rendered as particle text), while keeping status icons for health boost, armor and quad

### [scoreboard.patch](./patches/scoreboard.patch)
Expand Down Expand Up @@ -79,14 +79,11 @@ a.k.a. Features

All of the new damage-related commands (as well as `getaccuracy`) default to showing `hudplayer`'s stats across all weapons. However, they all take two optional integer arguments to query stats of a certain player and optionally for a specific weapon: `/<cmd> [cn] [weapon]` (use -1 as CN to query specific weapon stats about `hudplayer`).

To show comed-like statistics in the lower right corner, run `/exec data/p1xbraten/gamehud.cfg.gz`.
To show comed-like statistics in the lower right corner, copy the contents of [`stats_gamehud.cfg`](./data/p1xbraten/stats_gamehud.cfg) into your `autoexec.cfg`.

### [hudfragmessages.patch](./patches/hudfragmessages.patch)

- enables frag messages showing the weapon used to complete the frag (on by default)

![fragmessages](https://i.imgur.com/K4GL6oB.png)

- adds the following variables:
- `hudfragmessages`: 0 disables all frag messages, 1 enables them for all modes, 2 enables them for non-insta modes only
- `maxhudfragmessages`: how many messages to show at most (between 1 and 10)
Expand All @@ -101,6 +98,8 @@ a.k.a. Features

You can easily configure the hud frag messages using the [improved menu](#menu) (options → hud → adjust hud frag messages).

![fragmessages](https://i.imgur.com/K4GL6oB.png)

### [fullconsole.patch](./patches/fullconsole.patch)

- removes the guiskin background of fullconsole in favor of a gradient background on the left
Expand Down Expand Up @@ -171,6 +170,14 @@ For example, you can put `addauthserver "p1x.pw" "p1x.pw" 28787 "m"` into your `
- logs a "join" message including CN and player name
- logs map changes

### [gamehud.patch](./patches/gamehud.patch)

- properly right-justifies gamehud, wallclock, showfps, and/or showfpsrange lines
- adds a useful playerlist showing who's alive vs. dead when spectating in the lower right corner
- adds `isdead <cn>` command to check if a player is currently dead (only works when you are spectating)

<div align="center"><img alt="gamehud with player state" src="https://i.imgur.com/eDzdrWp.png" /></div>

## Installation

The latest builds are always at https://github.com/sauerbraten/p1xbraten/releases/latest.
Expand Down
57 changes: 44 additions & 13 deletions data/p1xbraten/gamehud.cfg
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
gamehud = [
format "^f7SG: ^f1%1%% ^f7CG: ^f1%2%% ^f7RL: ^f1%3%% ^f7RI: ^f1%4%% ^f7GL: ^f1%5%% ^n^t^f7frags: ^f0%6 ^f7deaths: ^f3%7 ^f7acc: ^f2%8%% ^f7kpd: ^f5%9" (
round (getaccuracy -1 1) 0.1 )(
round (getaccuracy -1 2) 0.1 )(
round (getaccuracy -1 3) 0.1 )(
round (getaccuracy -1 4) 0.1 )(
round (getaccuracy -1 5) 0.1 )(
getfrags )(
getdeaths )(
round (getaccuracy) 0.1 )(
round (divf (getfrags) (max (getdeaths) 1)) 0.1
)
]
p1xbratengamehud = [
local playerstates
playerstates = [
local playerlist teamlist teams players
playerlist = [
local players playernamecolor
players = $arg1
looplistconcatword cn $players [
playernamecolor = (? (= $getfollow $cn) "^f2" (? (isdead $cn) "^f4" "^f7"))
concatword "^n^fs" $playernamecolor (getclientname $cn) "^fr"
]
]
teamlist = [
local teamname teamplayers teamnamecolor
teamname = $arg1
teamplayers = $arg2
if $teamname [
teamnamecolor = (? (=s $teamname "spectators") "^f2" (? (=s $teamname $getteam) "^f1" "^f3"))
]
concatword "^fs" $teamnamecolor $teamname ":^fr" (playerlist $teamplayers)
]
teams = (listteams 1 1 0)
if (listlen $teams) [
looplistconcatword teamname $teams [
players = (listclients 1 1 0 $teamname)
result (? (listlen $players) (concatword (teamlist $teamname $players) "^n^n") "")
]
] [
players = (listclients 1 1 0)
result (? (listlen $players) (concatword "^fs^f7players:^fr" (playerlist $players) "^n^n") "")
]
]

local specgamehud
if (isspectator $getclientnum) [
specgamehud = (concatword (playerstates) "^fs^f2SPECTATOR^fr^n")
]

if (> (strlen (getalias "gamehud")) 0) [
specgamehud = (concatword $specgamehud "^n" (gamehud))
]

result $specgamehud
]
59 changes: 40 additions & 19 deletions data/p1xbraten/gamehud.cfg.gz.xxd
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x8d, 0x90,
0xcd, 0x0a, 0x82, 0x40, 0x10, 0x80, 0xef, 0x3e, 0xc5, 0x20, 0x2c, 0xb8,
0x87, 0xc2, 0xf5, 0x27, 0x2b, 0xe8, 0xd4, 0x41, 0x82, 0x4e, 0x75, 0x8c,
0x84, 0xc5, 0x75, 0x35, 0x42, 0x8d, 0x6d, 0x8d, 0x7a, 0xfb, 0xf6, 0xc7,
0x0e, 0x91, 0xa1, 0x73, 0x59, 0xbe, 0x99, 0x6f, 0x67, 0x86, 0x29, 0x69,
0x5d, 0x54, 0x1d, 0x83, 0x0d, 0x9c, 0x1c, 0x50, 0xc1, 0x5b, 0x51, 0x53,
0x09, 0x6e, 0xc6, 0x93, 0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0xa3, 0x4d,
0xd5, 0x2d, 0x9e, 0x1f, 0xef, 0xef, 0x56, 0xb7, 0xab, 0x87, 0x27, 0x28,
0x0f, 0x6b, 0x88, 0xb9, 0x31, 0xd1, 0x35, 0x6b, 0x9c, 0xb7, 0xd8, 0x1e,
0x3e, 0x54, 0x42, 0x0d, 0xc2, 0x31, 0x9e, 0xac, 0x61, 0xd8, 0x80, 0xc6,
0x1f, 0x09, 0x6b, 0xba, 0x05, 0x2d, 0x42, 0xf7, 0x69, 0xd5, 0xa6, 0x34,
0x09, 0x25, 0x15, 0x56, 0x5d, 0xf5, 0x09, 0x2a, 0xc3, 0xa6, 0x1c, 0x0d,
0x05, 0x00, 0x00
13 changes: 13 additions & 0 deletions data/p1xbraten/stats_gamehud.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
gamehud = [
format "^f7SG: ^f1%1%% ^f7CG: ^f1%2%% ^f7RL: ^f1%3%% ^f7RI: ^f1%4%% ^f7GL: ^f1%5%% ^n^f7frags: ^f0%6 ^f7deaths: ^f3%7 ^f7acc: ^f2%8%% ^f7kpd: ^f5%9" (
round (getaccuracy -1 1) 0.1 )(
round (getaccuracy -1 2) 0.1 )(
round (getaccuracy -1 3) 0.1 )(
round (getaccuracy -1 4) 0.1 )(
round (getaccuracy -1 5) 0.1 )(
getfrags )(
getdeaths )(
round (getaccuracy) 0.1 )(
round (divf (getfrags) (max (getdeaths) 1)) 0.1
)
]
134 changes: 134 additions & 0 deletions patches/gamehud.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
Index: src/engine/main.cpp
===================================================================
--- src/engine/main.cpp (revision 6496)
+++ src/engine/main.cpp (working copy)
@@ -1299,3 +1299,4 @@
+ execfile("data/p1xbraten/gamehud.cfg.gz");

identflags |= IDF_PERSIST;

Index: src/engine/rendergl.cpp
===================================================================
--- src/engine/rendergl.cpp (revision 6496)
+++ src/engine/rendergl.cpp (working copy)
@@ -2256,8 +2256,12 @@
int nextfps[3];
getfps(nextfps[0], nextfps[1], nextfps[2]);
loopi(3) if(prevfps[i]==curfps[i]) curfps[i] = nextfps[i];
- if(showfpsrange) draw_textf("fps %d+%d-%d", conw-7*FONTH, conh-FONTH*3/2, curfps[0], curfps[1], curfps[2]);
- else draw_textf("fps %d", conw-5*FONTH, conh-FONTH*3/2, curfps[0]);
+ static string buf;
+ if(showfpsrange) formatstring(buf, "(+%d-%d) %d fps", curfps[1], curfps[2], curfps[0]);
+ else formatstring(buf, "%d fps", curfps[0]);
+ int tw, th;
+ text_bounds(buf, tw, th);
+ draw_text(buf, conw-tw-FONTH, conh-FONTH*3/2);
roffset += FONTH;
}

@@ -2267,7 +2271,7 @@
time_t walloffset = walltime + totalmillis/1000;
struct tm *localvals = localtime(&walloffset);
static string buf;
- if(localvals && strftime(buf, sizeof(buf), wallclocksecs ? (wallclock24 ? "%H:%M:%S" : "%I:%M:%S%p") : (wallclock24 ? "%H:%M" : "%I:%M%p"), localvals))
+ if(localvals && strftime(buf, sizeof(buf), wallclocksecs ? (wallclock24 ? "%H:%M:%S" : "%I:%M:%S %p") : (wallclock24 ? "%H:%M" : "%I:%M %p"), localvals))
{
// hack because not all platforms (windows) support %P lowercase option
// also strip leading 0 from 12 hour time
@@ -2274,12 +2278,14 @@
char *dst = buf;
const char *src = &buf[!wallclock24 && buf[0]=='0' ? 1 : 0];
while(*src) *dst++ = tolower(*src++);
- *dst++ = '\0';
- draw_text(buf, conw-5*FONTH, conh-FONTH*3/2-roffset);
+ *dst++ = '\0';
+ int tw, th;
+ text_bounds(buf, tw, th);
+ draw_text(buf, conw-tw-FONTH, conh-FONTH*3/2-roffset);
roffset += FONTH;
}
}
-
+
if(editmode || showeditstats)
{
static int laststats = 0, prevstats[8] = { 0, 0, 0, 0, 0, 0, 0 }, curstats[8] = { 0, 0, 0, 0, 0, 0, 0 };
@@ -2325,7 +2331,7 @@
DELETEA(editinfo);
}
}
- else if(char *gameinfo = execidentstr("gamehud"))
+ else if(char *gameinfo = execidentstr("p1xbratengamehud"))
{
if(gameinfo[0])
{
@@ -2333,8 +2339,21 @@
text_bounds(gameinfo, tw, th);
th += FONTH-1; th -= th%FONTH;
roffset += max(th, FONTH);
- draw_text(gameinfo, conw-max(5*FONTH, 2*FONTH+tw), conh-FONTH/2-roffset);
+ int thoffset = 0;
+ char *line = gameinfo, *lineend = line;
+ while(*line && *lineend)
+ {
+ while(*lineend && *lineend!='\n') lineend++;
+ bool atend = !*lineend;
+ *lineend = '\0';
+ int lw, lh;
+ text_bounds(line, lw, lh);
+ draw_text(line, conw-lw-FONTH, conh-FONTH/2-roffset+thoffset);
+ thoffset += max(lh, FONTH);
+ if(atend) break;
+ line = lineend = lineend+1;
}
+ }
DELETEA(gameinfo);
}

Index: src/fpsgame/client.cpp
===================================================================
--- src/fpsgame/client.cpp (revision 6496)
+++ src/fpsgame/client.cpp (working copy)
@@ -332,6 +332,14 @@
ICOMMAND(getmastermode, "", (), intret(mastermode));
ICOMMAND(mastermodename, "i", (int *mm), result(server::mastermodename(*mm, "")));

+ bool isdead(int cn)
+ {
+ if(player1->state != CS_SPECTATOR) return false;
+ fpsent *d = getclient(cn);
+ return d && d->state==CS_DEAD;
+ }
+ ICOMMAND(isdead, "i", (int *cn), intret(isdead(*cn) ? 1 : 0));
+
bool isspectator(int cn)
{
fpsent *d = getclient(cn);
Index: src/fpsgame/fps.cpp
===================================================================
--- src/fpsgame/fps.cpp (revision 6496)
+++ src/fpsgame/fps.cpp (working copy)
@@ -1056,23 +1056,6 @@
hudmatrix.scale(h/1800.0f, h/1800.0f, 1);
flushhudmatrix();

- if(player1->state==CS_SPECTATOR)
- {
- int pw, ph, tw, th, fw, fh;
- text_bounds(" ", pw, ph);
- text_bounds("SPECTATOR", tw, th);
- th = max(th, ph);
- fpsent *f = followingplayer();
- text_bounds(f ? colorname(f) : " ", fw, fh);
- fh = max(fh, ph);
- draw_text("SPECTATOR", w*1800/h - tw - pw, 1650 - th - fh);
- if(f)
- {
- int color = statuscolor(f, 0xFFFFFF);
- draw_text(colorname(f), w*1800/h - fw - pw, 1650 - fh, (color>>16)&0xFF, (color>>8)&0xFF, color&0xFF);
- }
- }
-
fpsent *d = hudplayer();
if(d->state!=CS_EDITING)
{
22 changes: 0 additions & 22 deletions patches/moviehud.patch
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
Index: src/fpsgame/fps.cpp
===================================================================
--- src/fpsgame/fps.cpp (revision 6291)
+++ src/fpsgame/fps.cpp (working copy)
@@ -1050,6 +1050,8 @@
pophudmatrix();
}

+ VARP(hidespecfollow, 0, 0, 1);
+
void gameplayhud(int w, int h)
{
pushhudmatrix();
@@ -1056,7 +1058,7 @@
hudmatrix.scale(h/1800.0f, h/1800.0f, 1);
flushhudmatrix();

- if(player1->state==CS_SPECTATOR)
+ if(player1->state==CS_SPECTATOR && !hidespecfollow)
{
int pw, ph, tw, th, fw, fh;
text_bounds(" ", pw, ph);
Index: src/fpsgame/render.cpp
===================================================================
--- src/fpsgame/render.cpp (revision 6291)
Expand Down
1 change: 1 addition & 0 deletions src/engine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,7 @@ int main(int argc, char **argv)
execfile(gamecfgname);
if(game::savedservers()) execfile(game::savedservers(), false);
game::writep1xbratencfgs();
execfile("data/p1xbraten/gamehud.cfg.gz");

identflags |= IDF_PERSIST;

Expand Down
Loading

0 comments on commit ce6ec27

Please sign in to comment.