hud messages

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1440 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
driAn
2007-11-25 10:03:04 +00:00
parent e39e1cf8eb
commit d2a331fd4a
6 changed files with 119 additions and 69 deletions
+6 -5
View File
@@ -400,19 +400,20 @@ void dokill(playerent *pl, playerent *act, bool gib)
s_strcpy(pname, pl==player1 ? "you" : colorname(pl));
s_strcpy(aname, act==player1 ? "you" : colorname(act));
s_strcpy(death, gib ? "gibbed" : "fragged");
void (*outf)(const char *s, ...) = (pl == player1 || act == player1) ? hudoutf : conoutf;
if(pl==act)
conoutf("\f2%s suicided%s", pname, pl==player1 ? "!" : "");
outf("\f2%s suicided%s", pname, pl==player1 ? "!" : "");
else if(isteam(pl->team, act->team))
{
if(pl==player1) conoutf("\f2you got %s by a teammate (%s)", death, aname);
else conoutf("\f2%s %s %s teammate (%s)", aname, death, act==player1 ? "a" : "his", pname);
if(pl==player1) outf("\f2you got %s by a teammate (%s)", death, aname);
else outf("\f2%s %s %s teammate (%s)", aname, death, act==player1 ? "a" : "his", pname);
if(act==player1) showteamkill();
}
else
{
if(pl==player1) conoutf("\f2you got %s by %s", death, aname);
else conoutf("\f2%s %s %s", aname, death, pname);
if(pl==player1) outf("\f2you got %s by %s", death, aname);
else outf("\f2%s %s %s", aname, death, pname);
}
pl->state = CS_DEAD;
+50 -57
View File
@@ -2,45 +2,65 @@
#include "cube.h"
struct cline { char *cref; int outtime; };
vector<cline> conlines;
#define CONSPAD (FONTH/3)
const int ndraw = 6;
const int WORDWRAP = 80;
int conskip = 0;
struct console : consolebuffer
{
static const int ndraw = 6;
int conskip;
void setconskip(int n)
{
conskip += n;
if(conskip<0) conskip = 0;
}
static const int WORDWRAP = 80;
bool fullconsole;
void toggleconsole() { fullconsole = !fullconsole; }
void addline(const char *sf, bool highlight) { consolebuffer::addline(sf, highlight, lastmillis); }
void render()
{
if(fullconsole)
{
int w = VIRTW*2, h = VIRTH*2;
int numl = (h*2/5)/(FONTH*5/4);
int offset = min(conskip, max(conlines.length() - numl, 0));
blendbox(CONSPAD, CONSPAD, w-CONSPAD, 2*CONSPAD+numl*FONTH*5/4+2*FONTH/3, true);
loopi(numl) draw_text(offset+i>=conlines.length() ? "" : conlines[offset+i].cref, CONSPAD+FONTH/3, CONSPAD+(FONTH*5/4)*(numl-i-1)+FONTH/3);
}
else
{
int nd = 0;
char *refs[ndraw];
loopv(conlines) if(conskip ? i>=conskip-1 || i>=conlines.length()-ndraw : lastmillis-conlines[i].millis<20000)
{
refs[nd++] = conlines[i].cref;
if(nd==ndraw) break;
}
loopj(nd) draw_text(refs[j], CONSPAD+FONTH/3, CONSPAD+(FONTH*5/4)*(nd-j-1)+FONTH/3);
}
}
console() : fullconsole(false) {}
};
console con;
bool saycommandon = false;
string commandbuf;
int commandpos = -1;
void setconskip(int n)
{
conskip += n;
if(conskip<0) conskip = 0;
}
void setconskip(int n) { con.setconskip(n); }
COMMANDN(conskip, setconskip, ARG_1INT);
void conline(const char *sf, bool highlight) // add a line to the console buffer
{
cline cl;
cl.cref = conlines.length()>100 ? conlines.pop().cref : newstringbuf(""); // constrain the buffer size
cl.outtime = lastmillis; // for how long to keep line on screen
conlines.insert(0,cl);
if(highlight) // show line in a different colour, for chat etc.
{
cl.cref[0] = '\f';
cl.cref[1] = '0';
cl.cref[2] = 0;
s_strcat(cl.cref, sf);
}
else
{
s_strcpy(cl.cref, sf);
}
}
void toggleconsole() { con.toggleconsole(); }
COMMANDN(toggleconsole, toggleconsole, ARG_NONE);
#define CONSPAD (FONTH/3)
void renderconsole() { con.render(); }
void conoutf(const char *s, ...)
{
@@ -51,14 +71,10 @@ void conoutf(const char *s, ...)
s = sf;
vector<char *> lines;
text_block(s, curfont ? VIRTW*2-2*CONSPAD-2*FONTH/3 : 0, lines);
loopv(lines) conline(lines[i], i!=0);
loopv(lines) con.addline(lines[i], i!=0);
lines.deletecontentsa();
}
bool fullconsole = false;
void toggleconsole() { fullconsole = !fullconsole; }
COMMAND(toggleconsole, ARG_NONE);
void rendercommand(int x, int y)
{
s_sprintfd(s)("> %s", commandbuf);
@@ -67,29 +83,6 @@ void rendercommand(int x, int y)
draw_text(s, x, y);
}
void renderconsole() // render buffer taking into account time & scrolling
{
if(fullconsole)
{
int w = VIRTW*2, h = VIRTH*2;
int numl = (h*2/5)/(FONTH*5/4);
int offset = min(conskip, max(conlines.length() - numl, 0));
blendbox(CONSPAD, CONSPAD, w-CONSPAD, 2*CONSPAD+numl*FONTH*5/4+2*FONTH/3, true);
loopi(numl) draw_text(offset+i>=conlines.length() ? "" : conlines[offset+i].cref, CONSPAD+FONTH/3, CONSPAD+(FONTH*5/4)*(numl-i-1)+FONTH/3);
}
else
{
int nd = 0;
char *refs[ndraw];
loopv(conlines) if(conskip ? i>=conskip-1 || i>=conlines.length()-ndraw : lastmillis-conlines[i].outtime<20000)
{
refs[nd++] = conlines[i].cref;
if(nd==ndraw) break;
}
loopj(nd) draw_text(refs[j], CONSPAD+FONTH/3, CONSPAD+(FONTH*5/4)*(nd-j-1)+FONTH/3);
}
}
// keymap is defined externally in keymap.cfg
struct keym
+27
View File
@@ -0,0 +1,27 @@
struct cline { char *cref; int millis; };
struct consolebuffer
{
vector<cline> conlines;
void addline(const char *sf, bool highlight, int millis) // add a line to the console buffer
{
cline cl;
cl.cref = conlines.length()>100 ? conlines.pop().cref : newstringbuf(""); // constrain the buffer size
cl.millis = millis; // for how long to keep line on screen
conlines.insert(0,cl);
if(highlight) // show line in a different colour, for chat etc.
{
cl.cref[0] = '\f';
cl.cref[1] = '0';
cl.cref[2] = 0;
s_strcat(cl.cref, sf);
}
else
{
s_strcpy(cl.cref, sf);
}
}
virtual void render() = 0;
};
+1
View File
@@ -59,6 +59,7 @@
#include "entity.h"
#include "command.h"
#include "vote.h"
#include "console.h"
typedef vector<char *> cvector;
typedef vector<int> ivector;
+1
View File
@@ -306,6 +306,7 @@ extern void pruneundos(int maxremain = 0);
extern void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater);
extern void damageblend(int n);
extern void loadingscreen(const char *fmt = NULL, ...);
extern void hudoutf(const char *s, ...);
extern void show_out_of_renderloop_progress(float bar1, const char *text1, float bar2 = 0, const char *text2 = NULL);
// renderparticles
+34 -7
View File
@@ -162,6 +162,37 @@ void drawradarent(float x, float y, float yaw, int col, int row, float iconsize,
}
}
struct hudmessages : consolebuffer
{
void addline(const char *sf) { consolebuffer::addline(sf, false, lastmillis); }
void render()
{
if(!conlines.length()) return;
glLoadIdentity();
glOrtho(0, VIRTW*0.8f, VIRTH*0.8f, 0, -1, 1);
int dispmillis = 3000;
loopi(min(conlines.length, 3)) if(lastmillis-conlines[i].millis<dispmillis)
{
cline &c = conlines[i];
int tw = text_width(c.cref);
draw_text(c.cref, tw > VIRTW*0.8f ? 0 : (VIRTW*0.8f-tw)/2, ((VIRTH*0.8f)/4*3)+FONTH*i+pow((lastmillis-c.millis)/(float)dispmillis, 4)*VIRTH*0.8f/4.0f);
}
}
};
hudmessages hudmsgs;
void hudoutf(const char *s, ...)
{
s_sprintfdv(sf, s);
string sp;
filtertext(sp, sf);
puts(sp);
s = sf;
hudmsgs.addline(s);
conoutf(s);
}
bool insideradar(const vec &centerpos, float radius, const vec &o)
{
if(showmap) return !o.reject(centerpos, radius);
@@ -363,6 +394,9 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat
}
}
}
hudmsgs.render();
if(player1->state==CS_ALIVE)
{
glLoadIdentity();
@@ -377,13 +411,6 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat
draw_text(gunstats, 690, 827);
}
if(didteamkill)
{
glLoadIdentity();
glOrtho(0, VIRTW/3, VIRTH/3, 0, -1, 1);
draw_text("\f3you killed a teammate", VIRTW/3/40, VIRTH/3/2);
}
if(m_ctf && !hidectfhud)
{
glLoadIdentity();