- ported the level stats display to be game independent.

This commit is contained in:
Christoph Oelckers 2020-07-02 23:56:22 +02:00
parent 21da0816c5
commit e833360b65
9 changed files with 119 additions and 58 deletions

View file

@ -798,3 +798,37 @@ void FormatNumber(int number, int minsize, int maxsize, int flags, const FString
else fmt.Format("%s%*d", prefix.GetChars(), minsize, number);
}
CVAR(Float, hud_statscale, 2, CVAR_ARCHIVE)
void DBaseStatusBar::PrintLevelStats(FLevelStats &stats)
{
BeginHUD(320, 200, 1.f, false);
double scale = stats.fontscale * hud_statscale;
if (stats.spacing <= 0) stats.spacing = stats.font->GetHeight() * stats.fontscale;
double spacing = stats.spacing * hud_statscale;
double y = (stats.screenbottomspace < 0 ? RelTop : screen->GetHeight() - stats.screenbottomspace * defaultScale.Y) - spacing;
FString text;
if (stats.maxsecrets > 0) // don't bother if there are no secrets.
{
text.Format(TEXTCOLOR_ESCAPESTR "%cS: " TEXTCOLOR_ESCAPESTR "%c%d/%d",
stats.letterColor + 'A', stats.secrets == stats.maxsecrets ? stats.completeColor + 'A' : stats.standardColor + 'A', stats.secrets, stats.maxsecrets);
DrawText(twod, stats.font, CR_UNTRANSLATED, 2 * hud_statscale, y, text, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
y -= spacing;
}
text = "";
if (stats.frags > -1) text.Format(TEXTCOLOR_ESCAPESTR "%cF: " TEXTCOLOR_ESCAPESTR "%c%d", stats.letterColor + 'A', stats.standardColor + 'A', stats.frags);
else if (stats.maxkills == -2) text.Format(TEXTCOLOR_ESCAPESTR "%cK: " TEXTCOLOR_ESCAPESTR "%c%d", stats.letterColor + 'A', stats.standardColor + 'A', stats.kills);
else if (stats.maxkills != -1) text.Format(TEXTCOLOR_ESCAPESTR "%cK: " TEXTCOLOR_ESCAPESTR "%c%d/%d",
stats.letterColor + 'A', stats.kills == stats.maxkills ? stats.completeColor + 'A' : stats.standardColor + 'A', stats.kills, stats.maxkills);
if (text.IsNotEmpty())
{
DrawText(twod, stats.font, CR_UNTRANSLATED, 2 * hud_statscale, y, text, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
y -= spacing;
}
text.Format(TEXTCOLOR_ESCAPESTR "%cT: " TEXTCOLOR_ESCAPESTR "%c%d:%02d", stats.letterColor+'A', stats.standardColor + 'A', stats.time / 60000, (stats.time % 60000) / 1000);
DrawText(twod, stats.font, CR_UNTRANSLATED, 2 * hud_statscale, y, text, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
}

View file

@ -68,6 +68,18 @@ enum
HUDMSGLayer_Default = HUDMSGLayer_OverHUD,
};
struct FLevelStats
{
int screenbottomspace;
int time; // in milliseconds
int frags;
int kills, maxkills; // set maxkills to -1 to ignore, or to -2 to only print kills
int secrets, maxsecrets; // set maxsecrets to -1 to ignore
int spacing; // uses fontheight if 0 or less.
EColorRange letterColor, standardColor, completeColor;
double fontscale;
FFont* font;
};
//============================================================================
//
@ -174,6 +186,7 @@ public:
void BeginHUD(int resW, int resH, double Alpha, bool forceScaled = false);
bool ForceHUDScale(bool on) { std::swap(ForcedScale, on); return on; } // This is for SBARINFO which should not use BeginStatusBar or BeginHUD.
void StatusbarToRealCoords(double &x, double &y, double &w, double &h) const;
void PrintLevelStats(FLevelStats& stats);
int GetTopOfStatusbar() const
{
return SBarTop;

View file

@ -35,6 +35,7 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
#include "m_argv.h"
#include "mapinfo.h"
#include "texturemanager.h"
#include "statusbar.h"
BEGIN_DUKE_NS

View file

@ -170,4 +170,54 @@ PalEntry DDukeCommonStatusBar::LightForShade(int shade)
return PalEntry(255, ll, ll, ll);
}
//==========================================================================
//
// Statistics output
//
//==========================================================================
void DDukeCommonStatusBar::PrintLevelStats(int bottomy)
{
// JBF 20040124: display level stats in screen corner
if (ud.overhead_on != 2 && hud_stats)
{
FLevelStats stats{};
auto pp = &ps[myconnectindex];
stats.fontscale = isRR() ? 0.5 : 1.;
stats.spacing = isRR() ? 10 : 7;
stats.screenbottomspace = bottomy;
stats.time = Scale(pp->player_par, 1000, REALGAMETICSPERSEC);
stats.kills = pp->actors_killed;
stats.maxkills = !isRR() && ud.player_skill > 3 ? -2 : pp->max_actors_killed;
stats.frags = ud.multimode > 1 && !ud.coop ? pp->frag - pp->fraggedself : -1;
stats.secrets = pp->secret_rooms;
stats.maxsecrets = pp->max_secret_rooms;
stats.font = SmallFont;
if (isNamWW2GI())
{
// The stock font of these games is totally unusable for this.
stats.font = ConFont;
stats.spacing = ConFont->GetHeight() + 2;
stats.letterColor = CR_ORANGE;
stats.standardColor = CR_YELLOW;
stats.completeColor = CR_FIRE;
}
else if (!isRR())
{
stats.letterColor = CR_ORANGE;
stats.standardColor = CR_CREAM;
stats.completeColor = CR_FIRE;
}
else
{
stats.letterColor = CR_ORANGE;
stats.standardColor =
stats.completeColor = CR_UNTRANSLATED;
}
DBaseStatusBar::PrintLevelStats(stats);
}
}
END_DUKE_NS

View file

@ -22,6 +22,9 @@ protected:
std::pair<const char*, EColorRange> ontext(DukePlayer_t *p);
void DrawInventory(const DukePlayer_t* p, double x, double y, int align);
PalEntry LightForShade(int shade);
public:
void PrintLevelStats(int bottomy);
};
END_DUKE_NS

View file

@ -114,7 +114,7 @@ public:
//
// Health
//
DrawGraphic(tileGetTexture(TILE_COLA), 2, -2, DI_ITEM_LEFT_BOTTOM, 1., -1, -1, 0.75, 0.75);
DrawGraphic(tileGetTexture(COLA), 2, -2, DI_ITEM_LEFT_BOTTOM, 1., -1, -1, 0.75, 0.75);
FString format;
if (!althud_flashing || p->last_extra > (max_player_health >> 2) || ((int)totalclock & 32) || (sprite[p->i].pal == 1 && p->last_extra < 2))
@ -131,7 +131,7 @@ public:
//
// Armor
//
DrawGraphic(tileGetTexture(TILE_SHIELD), 62, -2, DI_ITEM_LEFT_BOTTOM, 1., -1, -1, 0.75, 0.75);
DrawGraphic(tileGetTexture(SHIELD), 62, -2, DI_ITEM_LEFT_BOTTOM, 1., -1, -1, 0.75, 0.75);
format.Format("%d", GetMoraleOrShield(p, snum));
SBar_DrawString(this, &numberFont, format, 105, -numberFont.mFont->GetHeight() - 0.5, DI_TEXT_ALIGN_CENTER, CR_UNTRANSLATED, 1, 0, 0, 1, 1);
@ -181,9 +181,9 @@ public:
//
// keys
//
if (p->got_access & 1) DrawGraphic(tileGetTexture(TILE_ACCESSCARD), -29, -30, DI_ITEM_CENTER, 1, -1, -1, 0.5, 0.5, 0xffffffff, TRANSLATION(Translation_Remap, 0));
if (p->got_access & 4) DrawGraphic(tileGetTexture(TILE_ACCESSCARD), -24, -28, DI_ITEM_CENTER, 1, -1, -1, 0.5, 0.5, 0xffffffff, TRANSLATION(Translation_Remap, 23));
if (p->got_access & 2) DrawGraphic(tileGetTexture(TILE_ACCESSCARD), -19, -26, DI_ITEM_CENTER, 1, -1, -1, 0.5, 0.5, 0xffffffff, TRANSLATION(Translation_Remap, 21));
if (p->got_access & 1) DrawGraphic(tileGetTexture(ACCESSCARD), -29, -30, DI_ITEM_CENTER, 1, -1, -1, 0.5, 0.5, 0xffffffff, TRANSLATION(Translation_Remap, 0));
if (p->got_access & 4) DrawGraphic(tileGetTexture(ACCESSCARD), -24, -28, DI_ITEM_CENTER, 1, -1, -1, 0.5, 0.5, 0xffffffff, TRANSLATION(Translation_Remap, 23));
if (p->got_access & 2) DrawGraphic(tileGetTexture(ACCESSCARD), -19, -26, DI_ITEM_CENTER, 1, -1, -1, 0.5, 0.5, 0xffffffff, TRANSLATION(Translation_Remap, 21));
}
@ -198,7 +198,7 @@ public:
//
// health
//
DrawGraphic(tileGetTexture(TILE_HEALTHBOX), 5, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale);
DrawGraphic(tileGetTexture(HEALTHBOX), 5, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale);
int health = (sprite[p->i].pal == 1 && p->last_extra < 2) ? 1 : p->last_extra;
FStringf format("%d", health);
SBar_DrawString(this, &digiFont, format, 19, -digiFont.mFont->GetHeight() * scale - 7, DI_TEXT_ALIGN_CENTER, CR_UNTRANSLATED, 1, 0, 0, scale, scale);
@ -206,7 +206,7 @@ public:
//
// ammo
//
DrawGraphic(tileGetTexture(TILE_AMMOBOX), 37, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale);
DrawGraphic(tileGetTexture(AMMOBOX), 37, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale);
int wp = (p->curr_weapon == HANDREMOTE_WEAPON) ? HANDBOMB_WEAPON : p->curr_weapon;
format.Format("%d", p->ammo_amount[wp]);
SBar_DrawString(this, &digiFont, format, 53, -digiFont.mFont->GetHeight() * scale - 7, DI_TEXT_ALIGN_CENTER, CR_UNTRANSLATED, 1, 0, 0, scale, scale);
@ -218,7 +218,7 @@ public:
if (icon > 0)
{
int x = 73;
DrawGraphic(tileGetTexture(TILE_INVENTORYBOX), 69, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale);
DrawGraphic(tileGetTexture(INVENTORYBOX), 69, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale);
if (icon < ICON_MAX)
DrawGraphic(tileGetTexture(item_icons[icon]), x, -14, DI_ITEM_LEFT|DI_ITEM_VCENTER, 1, -1, -1, scale, scale);
@ -247,15 +247,18 @@ public:
{
DrawInventory(p, 0, -46, DI_SCREEN_CENTER_BOTTOM);
FullscreenHUD1(p, snum);
PrintLevelStats(tilesiz[BIGALPHANUM].y +10);
}
else if (style == 2)
{
DrawInventory(p, (ud.multimode > 1) ? 56 : 65, -28, DI_SCREEN_CENTER_BOTTOM);
FullscreenHUD2(p);
PrintLevelStats(tilesiz[HEALTHBOX].y + 2);
}
else
{
DrawInventory(p, 0, -28, DI_SCREEN_CENTER_BOTTOM);
PrintLevelStats(2);
}
}
@ -393,6 +396,7 @@ public:
auto text = ontext(p);
if (text.first) SBar_DrawString(this, &miniFont, text.first, x + 34, top + 14, DI_TEXT_ALIGN_RIGHT, text.second, 1, 0, 0, 1, 1);
}
PrintLevelStats(-1);
}

View file

@ -229,15 +229,18 @@ public:
y -= 4;
DrawInventory(p, 0, y, DI_SCREEN_CENTER_BOTTOM);
FullscreenHUD1(p, snum);
PrintLevelStats(scale * tilesiz[BIGALPHANUM].y + 10);
}
else if (style == 2)
{
DrawInventory(p, 56, -20, DI_SCREEN_CENTER_BOTTOM);
FullscreenHUD2(p);
PrintLevelStats(scale * tilesiz[HEALTHBOX].y + 2);
}
else
{
DrawInventory(p, 0, -20, DI_SCREEN_CENTER_BOTTOM);
PrintLevelStats(2);
}
}
@ -379,6 +382,7 @@ public:
{
DrawGraphic(tileGetTexture(GUTMETER_LIGHT4), 302, top + 24, DI_ITEM_OFFSETS, 1, -1, -1, scale, scale);
}
PrintLevelStats(-1);
}
};

View file

@ -478,54 +478,6 @@ void G_DisplayRest(int32_t smoothratio)
mdpause = (ud.pause_on || (ud.recstat==2 && (g_demo_paused && g_demo_goalCnt==0)) || (g_player[myconnectindex].ps->gm&MODE_MENU && numplayers < 2));
// JBF 20040124: display level stats in screen corner
if (ud.overhead_on != 2 && hud_stats)
{
DukePlayer_t const * const myps = g_player[myconnectindex].ps;
int const sbarshift = RR ? 15 : 16;
int const ystep = RR ? (10<<16) : (7<<16);
i = 198<<16;
if (ud.screen_size == 4)
{
if (ud.althud == 0 || hud_position == 0)
i -= sbarsc(ud.althud ? ((tilesiz[TILE_BIGALPHANUM].y<<sbarshift)+(8<<16)) : tilesiz[TILE_INVENTORYBOX].y<<sbarshift);
}
else if (RR && ud.screen_size == 12)
{
i -= sbarsc((tilesiz[TILE_BOTTOMSTATUSBAR].y+tilesiz[TILE_WEAPONBAR].y)<<sbarshift);
}
else if (ud.screen_size > 2)
i -= sbarsc(tilesiz[TILE_BOTTOMSTATUSBAR].y<<sbarshift);
int32_t const xbetween = (tilesiz[MF_Bluefont.tilenum + 'A' - '!'].x<<16) + MF_Bluefont.between.x;
Bsprintf(tempbuf, "T:^15%d:%02d.%02d",
(myps->player_par/(REALGAMETICSPERSEC*60)),
(myps->player_par/REALGAMETICSPERSEC)%60,
((myps->player_par%REALGAMETICSPERSEC)*33)/10
);
G_ScreenText(MF_Bluefont.tilenum, 2<<16, i-gtextsc(ystep*3), gtextsc(MF_Bluefont.zoom), 0, 0, tempbuf, 0, 10, 2|8|16|256|ROTATESPRITE_FULL16, 0, MF_Bluefont.emptychar.x, MF_Bluefont.emptychar.y, xbetween, MF_Bluefont.between.y, MF_Bluefont.textflags|TEXT_XOFFSETZERO|TEXT_GAMETEXTNUMHACK, 0, 0, xdim-1, ydim-1);
if ((!RR && ud.player_skill > 3) || ((g_netServer || ud.multimode > 1) && !GTFLAGS(GAMETYPE_PLAYERSFRIENDLY)))
Bsprintf(tempbuf, "K:^15%d", (ud.multimode>1 &&!GTFLAGS(GAMETYPE_PLAYERSFRIENDLY)) ?
myps->frag-myps->fraggedself : myps->actors_killed);
else
{
if (myps->actors_killed >= myps->max_actors_killed)
Bsprintf(tempbuf, "K:%d/%d", myps->actors_killed, myps->actors_killed);
else
Bsprintf(tempbuf, "K:^15%d/%d", myps->actors_killed, myps->max_actors_killed);
}
G_ScreenText(MF_Bluefont.tilenum, 2<<16, i-gtextsc(ystep*2), gtextsc(MF_Bluefont.zoom), 0, 0, tempbuf, 0, 10, 2|8|16|256|ROTATESPRITE_FULL16, 0, MF_Bluefont.emptychar.x, MF_Bluefont.emptychar.y, xbetween, MF_Bluefont.between.y, MF_Bluefont.textflags|TEXT_XOFFSETZERO|TEXT_GAMETEXTNUMHACK, 0, 0, xdim-1, ydim-1);
if (myps->secret_rooms == myps->max_secret_rooms)
Bsprintf(tempbuf, "S:%d/%d", myps->secret_rooms, myps->max_secret_rooms);
else Bsprintf(tempbuf, "S:^15%d/%d", myps->secret_rooms, myps->max_secret_rooms);
G_ScreenText(MF_Bluefont.tilenum, 2<<16, i-gtextsc(ystep), gtextsc(MF_Bluefont.zoom), 0, 0, tempbuf, 0, 10, 2|8|16|256|ROTATESPRITE_FULL16, 0, MF_Bluefont.emptychar.x, MF_Bluefont.emptychar.y, xbetween, MF_Bluefont.between.y, MF_Bluefont.textflags|TEXT_XOFFSETZERO|TEXT_GAMETEXTNUMHACK, 0, 0, xdim-1, ydim-1);
}
Net_DisplaySyncMsg();
if (VOLUMEONE)

View file

@ -140,8 +140,8 @@ Flat:
Cream
{
#6B4727 #BF7B4B 0 94
#BF7B4B #FFBF9B 95 256
#18120a #BF7B4B 0 128
#BF7B4B #FFBF9B 129 256
Console:
#2B230F #BF7B4B 0 127
#FFB383 #FFFFFF 128 256