swwmgz_m/zscript/menu/swwm_inter_sp.zsc
Marisa the Magician 208b0afd36 Small visual tweaks to stat screen:
- Show "N/A" for 0/0 cases.
 - Always show times in at least mm:ss format.
 - Account for potential trailing whitespace in map names
   (can becaused by DEHACKED string replacements).
2023-03-10 11:15:56 +01:00

287 lines
10 KiB
Text

// Single-player stats
Class SWWMStatScreen_SP : SWWMStatScreen
{
int intermissioncounter;
override void initStats()
{
intermissioncounter = gameinfo.intermissioncounter;
CurState = StatCount;
acceleratestage = 0;
sp_state = 1;
cnt_kills[0] = cnt_items[0] = cnt_secret[0] = -1;
cnt_time = cnt_par = -1;
cnt_pause = GameTicRate;
cnt_total_time = -1;
}
override void updateStats()
{
if ( acceleratestage && (sp_state != 10) )
{
acceleratestage = 0;
sp_state = 10;
PlaySound("menu/buyinv");
cnt_kills[0] = Plrs[me].skills;
cnt_items[0] = Plrs[me].sitems;
cnt_secret[0] = Plrs[me].ssecret;
cnt_time = Thinker.Tics2Seconds(Plrs[me].stime);
cnt_par = wbs.partime/GameTicRate;
cnt_total_time = Thinker.Tics2Seconds(wbs.totaltime);
}
if ( sp_state == 2 )
{
if ( intermissioncounter )
{
cnt_kills[0] += max((Plrs[me].skills-cnt_kills[0])/10,2);
if ( !(bcnt%2) ) PlaySound("menu/demoscroll");
}
if ( !intermissioncounter || (cnt_kills[0] >= Plrs[me].skills) )
{
cnt_kills[0] = Plrs[me].skills;
PlaySound("menu/buyinv");
sp_state++;
}
}
else if ( sp_state == 4 )
{
if ( intermissioncounter )
{
cnt_items[0] += max((Plrs[me].sitems-cnt_items[0])/10,2);
if ( !(bcnt%2) ) PlaySound("menu/demoscroll");
}
if ( !intermissioncounter || (cnt_items[0] >= Plrs[me].sitems) )
{
cnt_items[0] = Plrs[me].sitems;
PlaySound("menu/buyinv");
sp_state++;
}
}
else if ( sp_state == 6 )
{
if ( intermissioncounter )
{
cnt_secret[0] += max((Plrs[me].ssecret-cnt_secret[0])/10,2);
if ( !(bcnt%2) ) PlaySound("menu/demoscroll");
}
if ( !intermissioncounter || (cnt_secret[0] >= Plrs[me].ssecret) )
{
cnt_secret[0] = Plrs[me].ssecret;
PlaySound("menu/buyinv");
sp_state++;
}
}
else if ( sp_state == 8 )
{
int sec = Thinker.Tics2Seconds(Plrs[me].stime);
int tsec = Thinker.Tics2Seconds(wbs.totaltime);
int psec = wbs.partime/GameTicRate;
if ( intermissioncounter )
{
if ( !(bcnt%2) ) PlaySound("menu/demoscroll");
cnt_time += max((sec-cnt_time)/10,3);
cnt_par += max((psec-cnt_par)/10,3);
cnt_total_time += max((tsec-cnt_total_time)/10,3);
}
if ( !intermissioncounter || (cnt_time >= sec) )
cnt_time = sec;
if ( !intermissioncounter || (cnt_total_time >= tsec) )
cnt_total_time = tsec;
if ( !intermissioncounter || (cnt_par >= psec) )
{
cnt_par = psec;
if ( cnt_time >= sec )
{
cnt_total_time = tsec;
PlaySound("menu/buyinv");
sp_state++;
}
}
}
else if ( sp_state == 10 )
{
if ( acceleratestage )
{
PlaySound("misc/w_pkup");
initShowNextLoc();
}
}
else if ( sp_state&1 )
{
if ( !--cnt_pause )
{
sp_state++;
cnt_pause = GameTicRate;
}
}
}
override void drawStats( void )
{
drawLF();
// estimate max width of the whole stat counter
int maxlen, maxlenl = 0, maxlenr = 0;
// left strings
String str = StringTable.Localize("$TXT_IMKILLS")..":";
int len = mSmallFont.StringWidth(str);
maxlenl = len;
str = StringTable.Localize("$TXT_IMITEMS")..":";
len = mSmallFont.StringWidth(str);
if ( len > maxlenl ) maxlenl = len;
str = StringTable.Localize("$TXT_IMSECRETS")..":";
len = mSmallFont.StringWidth(str);
if ( len > maxlenl ) maxlenl = len;
str = StringTable.Localize("$TXT_IMTIME")..":";
len = mSmallFont.StringWidth(str);
if ( len > maxlenl ) maxlenl = len;
if ( wbs.partime )
{
str = StringTable.Localize("$TXT_IMPAR")..":";
len = mSmallFont.StringWidth(str);
if ( len > maxlenl ) maxlenl = len;
}
if ( wi_showtotaltime && (Plrs[me].stime != wbs.totaltime) )
{
str = StringTable.Localize("$SCORE_TOTAL")..":"; // hey, as long as it works
len = mSmallFont.StringWidth(str);
if ( len > maxlenl ) maxlenl = len;
}
// right strings
if ( wi_percents )
{
str = (!wbs.maxkills)?"N/A":String.Format("%d%%",GetPct(Plrs[me].skills,wbs.maxkills));
len = mSmallFont.StringWidth(str);
maxlenr = len;
str = (!wbs.maxitems)?"N/A":String.Format("%d%%",GetPct(Plrs[me].sitems,wbs.maxitems));
len = mSmallFont.StringWidth(str);
if ( len > maxlenr ) maxlenr = len;
str = (!wbs.maxsecret)?"N/A":String.Format("%d%%",GetPct(Plrs[me].ssecret,wbs.maxsecret));
len = mSmallFont.StringWidth(str);
if ( len > maxlenr ) maxlenr = len;
}
else
{
str = (!wbs.maxkills)?"N/A":String.Format("%d / %d",Plrs[me].skills,wbs.maxkills);
len = mSmallFont.StringWidth(str);
maxlenr = len;
str = (!wbs.maxitems)?"N/A":String.Format("%d / %d",Plrs[me].sitems,wbs.maxitems);
len = mSmallFont.StringWidth(str);
if ( len > maxlenr ) maxlenr = len;
str = (!wbs.maxsecret)?"N/A":String.Format("%d / %d",Plrs[me].ssecret,wbs.maxsecret);
len = mSmallFont.StringWidth(str);
if ( len > maxlenr ) maxlenr = len;
}
str = TimeStr(Thinker.Tics2Seconds(Plrs[me].stime));
len = mSmallFont.StringWidth(str);
if ( len > maxlenr ) maxlenr = len;
if ( wbs.partime )
{
str = TimeStr(wbs.partime/GameTicRate);
len = mSmallFont.StringWidth(str);
if ( len > maxlenr ) maxlenr = len;
}
if ( wi_showtotaltime && (Plrs[me].stime != wbs.totaltime) )
{
str = TimeStr(Thinker.Tics2Seconds(wbs.totaltime));
len = mSmallFont.StringWidth(str);
if ( len > maxlenr ) maxlenr = len;
}
int step = mSmallFont.GetHeight()+1;
int nl = clamp(sp_state/2,0,4);
if ( (nl == 4) )
{
if ( wi_showtotaltime && (Plrs[me].stime != wbs.totaltime) ) nl++;
if ( wbs.partime ) nl++;
}
nl *= step;
maxlen = maxlenl+max(100,maxlenr);
// draw the whole damn thing
if ( sp_state >= 2 ) Screen.Dim("Black",.8,int((ss2.x-maxlen-8)*.5*hs2),int((ss2.y-nl-8)*.5*hs2),int((maxlen+8)*hs2),int((nl+8)*hs2));
int xx = int((ss2.x-maxlen)/2), yy = int((ss2.y-nl)/2);
if ( sp_state >= 2 ) Screen.DrawText(mSmallFont,Font.CR_GREEN,xx,yy,StringTable.Localize("$TXT_IMKILLS")..":",DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
yy += step;
if ( sp_state >= 4 ) Screen.DrawText(mSmallFont,Font.CR_GREEN,xx,yy,StringTable.Localize("$TXT_IMITEMS")..":",DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
yy += step;
if ( sp_state >= 6 ) Screen.DrawText(mSmallFont,Font.CR_GREEN,xx,yy,StringTable.Localize("$TXT_IMSECRETS")..":",DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
yy += step;
if ( sp_state >= 8 ) Screen.DrawText(mSmallFont,Font.CR_GREEN,xx,yy,StringTable.Localize("$TXT_IMTIME")..":",DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
yy += step;
if ( wbs.partime )
{
if ( sp_state >= 8 ) Screen.DrawText(mSmallFont,Font.CR_GREEN,xx,yy,StringTable.Localize("$TXT_IMPAR")..":",DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
yy += step;
}
if ( wi_showtotaltime && (Plrs[me].stime != wbs.totaltime) && (sp_state >= 8) )
Screen.DrawText(mSmallFont,Font.CR_GREEN,xx,yy,StringTable.Localize("$SCORE_TOTAL")..":",DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
xx = int((ss2.x+maxlen)/2);
yy = int((ss2.y-nl)/2);
if ( wi_percents )
{
if ( cnt_kills[0] >= 0 )
{
str = (!wbs.maxkills)?"\cuN/A\c-":String.Format("%d\cu%%\c-",GetPct(cnt_kills[0],wbs.maxkills));
len = mSmallFont.StringWidth(str);
Screen.DrawText(mSmallFont,(cnt_kills[0]>=wbs.maxkills)?Font.CR_GOLD:Font.CR_WHITE,xx-len,yy,str,DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
}
yy += step;
if ( cnt_items[0] >= 0 )
{
str = (!wbs.maxitems)?"\cuN/A\c-":String.Format("%d\cu%%\c-",GetPct(cnt_items[0],wbs.maxitems));
len = mSmallFont.StringWidth(str);
Screen.DrawText(mSmallFont,(cnt_items[0]>=wbs.maxitems)?Font.CR_GOLD:Font.CR_WHITE,xx-len,yy,str,DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
}
yy += step;
if ( cnt_secret[0] >= 0 )
{
str = (!wbs.maxsecret)?"\cuN/A\c-":String.Format("%d\cu%%\c-",GetPct(cnt_secret[0],wbs.maxsecret));
len = mSmallFont.StringWidth(str);
Screen.DrawText(mSmallFont,(cnt_secret[0]>=wbs.maxsecret)?Font.CR_GOLD:Font.CR_WHITE,xx-len,yy,str,DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
}
yy += step;
}
else
{
if ( cnt_kills[0] >= 0 )
{
str = (!wbs.maxkills)?"\cuN/A\c-":String.Format("%d \cu/\c- \cj%d\c-",max(cnt_kills[0],0),wbs.maxkills);
len = mSmallFont.StringWidth(str);
Screen.DrawText(mSmallFont,(cnt_kills[0]>=wbs.maxkills)?Font.CR_GOLD:Font.CR_WHITE,xx-len,yy,str,DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
}
yy += step;
if ( cnt_items[0] >= 0 )
{
str = (!wbs.maxitems)?"\cuN/A\c-":String.Format("%d \cu/\c- \cj%d\c-",max(cnt_items[0],0),wbs.maxitems);
len = mSmallFont.StringWidth(str);
Screen.DrawText(mSmallFont,(cnt_items[0]>=wbs.maxitems)?Font.CR_GOLD:Font.CR_WHITE,xx-len,yy,str,DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
}
yy += step;
if ( cnt_secret[0] >= 0 )
{
str = (!wbs.maxsecret)?"\cuN/A\c-":String.Format("%d \cu/\c- \cj%d\c-",max(cnt_secret[0],0),wbs.maxsecret);
len = mSmallFont.StringWidth(str);
Screen.DrawText(mSmallFont,(cnt_secret[0]>=wbs.maxsecret)?Font.CR_GOLD:Font.CR_WHITE,xx-len,yy,str,DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
}
yy += step;
}
if ( cnt_time >= 0 )
{
str = TimeStr(cnt_time);
len = mSmallFont.StringWidth(str);
Screen.DrawText(mSmallFont,(wbs.partime&&(cnt_time<=(wbs.partime/GameTicRate)))?Font.CR_GOLD:((wbs.sucktime>0)&&(cnt_time>(wbs.sucktime*3600)))?Font.CR_RED:Font.CR_WHITE,xx-len,yy,str,DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
}
yy += step;
if ( wbs.partime && (cnt_par >= 0) )
{
str = TimeStr(cnt_par);
len = mSmallFont.StringWidth(str);
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx-len,yy,str,DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
yy += step;
}
if ( wi_showtotaltime && (Plrs[me].stime != wbs.totaltime) && (cnt_total_time >= 0) )
{
str = TimeStr(cnt_total_time);
len = mSmallFont.StringWidth(str);
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx-len,yy,str,DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
}
}
}