diff --git a/config/font.cfg b/config/font.cfg index ac1a9fdd..b4022648 100644 --- a/config/font.cfg +++ b/config/font.cfg @@ -93,3 +93,17 @@ fontchar 200 448 41 64 //{ fontchar 241 448 29 64 //| fontchar 270 448 40 64 //} fontchar 310 448 53 64 //~ + +font huddigits "packages/misc/huddigits.png" 48 64 +fontskip 48 +fontchar 0 64 48 64 //0 +fontchar 48 64 48 64 //1 +fontchar 96 64 48 64 //2 +fontchar 144 64 48 64 //3 +fontchar 192 64 48 64 //4 +fontchar 240 64 48 64 //5 +fontchar 288 64 48 64 //6 +fontchar 336 64 48 64 //7 +fontchar 384 64 48 64 //8 +fontchar 432 64 48 64 //9 + diff --git a/source/src/protos.h b/source/src/protos.h index d3f0070f..e643de2f 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -458,8 +458,9 @@ struct font char *name; Texture *tex; vector chars; - short defaultw, defaulth; - short offsetx, offsety, offsetw, offseth; + int defaultw, defaulth; + int offsetx, offsety, offsetw, offseth; + int skip; }; #define VIRTH 1800 @@ -470,6 +471,8 @@ extern int VIRTW; // virtual screen size for text & HUD extern font *curfont; extern bool setfont(const char *name); +extern void pushfont(const char *name); +extern void popfont(); extern void draw_text(const char *str, int left, int top, int r = 255, int g = 255, int b = 255, int a = 255, int cursor = -1, int maxwidth = -1); extern void draw_textf(const char *fstr, int left, int top, ...); extern int text_width(const char *str); diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index a6fa3a86..eb406a09 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -657,9 +657,16 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat if(!hidehudequipment) { + pushfont("huddigits"); draw_textf("%d", 90, 827, p->health); if(p->armour) draw_textf("%d", 390, 827, p->armour); - if(p->weaponsel && p->weaponsel->type>=GUN_KNIFE && p->weaponsel->typeweaponsel->renderstats(); + if(p->weaponsel && p->weaponsel->type>=GUN_KNIFE && p->weaponsel->typeweaponsel->renderstats(); + glMatrixMode(GL_PROJECTION); + } + popfont(); } if(m_flags && !hidectfhud) diff --git a/source/src/rendertext.cpp b/source/src/rendertext.cpp index 1f54d615..53cf69c8 100644 --- a/source/src/rendertext.cpp +++ b/source/src/rendertext.cpp @@ -28,6 +28,7 @@ void newfont(char *name, char *tex, char *defaultw, char *defaulth, char *offset f->offsety = ATOI(offsety); f->offsetw = ATOI(offsetw); f->offseth = ATOI(offseth); + f->skip = 33; fontdef = f; } @@ -43,8 +44,16 @@ void fontchar(int x, int y, int w, int h) c.h = h ? h : fontdef->defaulth; } +void fontskip(int n) +{ + if(!fontdef) return; + + fontdef->skip = n; +} + COMMANDN(font, newfont, ARG_8STR); -COMMANDN(fontchar, fontchar, ARG_4INT); +COMMAND(fontchar, ARG_4INT); +COMMAND(fontskip, ARG_1INT); bool setfont(const char *name) { @@ -54,6 +63,19 @@ bool setfont(const char *name) return true; } +static vector fontstack; + +void pushfont(const char *name) +{ + fontstack.add(curfont); + setfont(name); +} + +void popfont() +{ + if(!fontstack.empty()) curfont = fontstack.pop(); +} + int text_width(const char *str) { int width, height; @@ -69,7 +91,7 @@ void draw_textf(const char *fstr, int left, int top, ...) static int draw_char(int c, int x, int y) { - font::charinfo &info = curfont->chars[c-33]; + font::charinfo &info = curfont->chars[c-curfont->skip]; float tc_left = (info.x + curfont->offsetx) / float(curfont->tex->xs); float tc_top = (info.y + curfont->offsety) / float(curfont->tex->ys); float tc_right = (info.x + info.w + curfont->offsetw) / float(curfont->tex->xs); @@ -159,19 +181,19 @@ void text_endcolumns() else if(c==' ') { x += curfont->defaultw; TEXTWHITE(i) }\ else if(c=='\n') { TEXTLINE(i) x = 0; y += FONTH; }\ else if(c=='\f') { if(str[i+1]) { i++; TEXTCOLOR(i) }}\ - else if(curfont->chars.inrange(c-33))\ + else if(curfont->chars.inrange(c-curfont->skip))\ {\ if(maxwidth != -1)\ {\ int j = i;\ - int w = curfont->chars[c-33].w;\ + int w = curfont->chars[c-curfont->skip].w;\ for(; str[i+1]; i++)\ {\ int c = str[i+1];\ if(c=='\f') { if(str[i+2]) i++; continue; }\ if(i-j > 16) break;\ - if(!curfont->chars.inrange(c-33)) break;\ - int cw = curfont->chars[c-33].w + 1;\ + if(!curfont->chars.inrange(c-curfont->skip)) break;\ + int cw = curfont->chars[c-curfont->skip].w + 1;\ if(w + cw >= maxwidth) break;\ w += cw;\ }\ @@ -200,7 +222,7 @@ int text_visible(const char *str, int hitx, int hity, int maxwidth) #define TEXTWHITE(idx) if(y+FONTH > hity && x >= hitx) return idx; #define TEXTLINE(idx) if(y+FONTH > hity) return idx; #define TEXTCOLOR(idx) - #define TEXTCHAR(idx) x += curfont->chars[c-33].w+1; TEXTWHITE(idx) + #define TEXTCHAR(idx) x += curfont->chars[c-curfont->skip].w+1; TEXTWHITE(idx) #define TEXTWORD TEXTWORDSKELETON TEXTSKELETON #undef TEXTINDEX @@ -221,7 +243,7 @@ void text_pos(const char *str, int cursor, int &cx, int &cy, int maxwidth) #define TEXTWHITE(idx) #define TEXTLINE(idx) #define TEXTCOLOR(idx) - #define TEXTCHAR(idx) x += curfont->chars[c-33].w + 1; + #define TEXTCHAR(idx) x += curfont->chars[c-curfont->skip].w + 1; #define TEXTWORD TEXTWORDSKELETON if(i >= cursor) break; cx = INT_MIN; cy = 0; @@ -243,7 +265,7 @@ void text_bounds(const char *str, int &width, int &height, int maxwidth) #define TEXTWHITE(idx) #define TEXTLINE(idx) if(x > width) width = x; #define TEXTCOLOR(idx) - #define TEXTCHAR(idx) x += curfont->chars[c-33].w + 1; + #define TEXTCHAR(idx) x += curfont->chars[c-curfont->skip].w + 1; #define TEXTWORD x += w + 1; width = 0; TEXTSKELETON @@ -281,7 +303,7 @@ void draw_text(const char *str, int left, int top, int r, int g, int b, int a, i { if(cx == INT_MIN) { cx = x; cy = y; } if(maxwidth != -1 && cx >= maxwidth) { cx = 0; cy += FONTH; } - int cw = curfont->chars.inrange(cc-33) ? curfont->chars[cc-33].w + 1 : curfont->defaultw; + int cw = curfont->chars.inrange(cc-curfont->skip) ? curfont->chars[cc-curfont->skip].w + 1 : curfont->defaultw; rendercursor(left+cx, top+cy, cw); } #undef TEXTINDEX diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index fb602f9f..f4662a45 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -579,8 +579,13 @@ bool weapon::reload() void weapon::renderstats() { char gunstats[64]; - sprintf(gunstats, "%i/%i", mag, ammo); + sprintf(gunstats, "%i", mag); ///%i", mag, ammo); draw_text(gunstats, 690, 827); + int offset = text_width(gunstats); + glScalef(0.5f, 0.5f, 1.0f); + sprintf(gunstats, "%i", ammo); + draw_text(gunstats, (690 + offset)*2, 830*2); + glLoadIdentity(); } //VAR(recoiltest, 0, 0, 1); // FIXME ON RELEASE