Attach auxiliary HUD elements (centered text, pickups, oneliners, etc.) to hudscale zero.

This commit is contained in:
Mari the Deer 2024-01-25 15:53:57 +01:00
commit f5694bc630
6 changed files with 59 additions and 56 deletions

View file

@ -105,6 +105,7 @@ Class SWWMStatusBar : BaseStatusBar
double hs, hs0, hs1, hs2;
Vector2 ss, ss0, ss1, ss2;
int ymargin, xmargin;
int ymargin0; // for pickups/oneliners
double FracTic;
double FrameTime;
double PrevFrame;
@ -434,7 +435,7 @@ Class SWWMStatusBar : BaseStatusBar
override void DrawMyPos()
{
String str = String.Format("(%d,%d,%d)",CPlayer.mo.pos.X,CPlayer.mo.pos.Y,CPlayer.mo.pos.Z);
Screen.DrawText(mTinyFontOutline,Font.CR_GREEN,(ss.x-mTinyFontOutline.StringWidth(str))/2,4,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
Screen.DrawText(mTinyFontOutline,Font.CR_GREEN,(ss0.x-mTinyFontOutline.StringWidth(str))/2,4,str,DTA_VirtualWidthF,ss0.x,DTA_VirtualHeightF,ss0.y,DTA_KeepRatio,true);
}
override bool DrawChat( String txt )
@ -443,24 +444,24 @@ Class SWWMStatusBar : BaseStatusBar
if ( gamestate != GS_LEVEL ) return false;
chatopen = gametic+1; // have to add 1 because DrawChat is called after everything else
double xx = 2;
double yy = ss.y-14;
Screen.Dim("Black",.8,0,Screen.GetHeight()-int(15*hs),Screen.GetWidth(),int(15*hs));
double yy = ss0.y-14;
Screen.Dim("Black",.8,0,Screen.GetHeight()-int(15*hs0),Screen.GetWidth(),int(15*hs0));
String pname = players[consoleplayer].GetUserName();
// strip colors
SWWMUtility.StripColor(pname);
String fullstr = String.Format("\cq%s\cd@\cqdemolitionist%d\cn ~ \cd% \c-wall %s_",pname,consoleplayer+1,txt);
// cut out to fit
int w = mSmallFont.StringWidth(fullstr);
if ( w > ss.x-4 )
if ( w > ss0.x-4 )
{
// draw trailing dots
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx,yy,"...",DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx,yy,"...",DTA_VirtualWidthF,ss0.x,DTA_VirtualHeightF,ss0.y,DTA_KeepRatio,true);
// shift back
xx -= w-(ss.x-4);
xx -= w-(ss0.x-4);
// draw trimmed
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx,yy,fullstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_ClipLeft,int(26*hs));
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx,yy,fullstr,DTA_VirtualWidthF,ss0.x,DTA_VirtualHeightF,ss0.y,DTA_KeepRatio,true,DTA_ClipLeft,int(26*hs0));
}
else Screen.DrawText(mSmallFont,Font.CR_WHITE,xx,yy,fullstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
else Screen.DrawText(mSmallFont,Font.CR_WHITE,xx,yy,fullstr,DTA_VirtualWidthF,ss0.x,DTA_VirtualHeightF,ss0.y,DTA_KeepRatio,true);
return true;
}
@ -553,50 +554,50 @@ Class SWWMStatusBar : BaseStatusBar
Screen.Dim("Red",clamp((demo.revivefail-(level.maptime+fractic))/60.,0.,.2),0,0,Screen.GetWidth(),Screen.GetHeight());
str = StringTable.Localize("$SWWM_REFAIL");
len = mSmallFont.StringWidth(str);
xx = int((ss.x-len)/2.);
yy = ss.y-48;
xx = int((ss0.x-len)/2.);
yy = ss0.y-48;
if ( ((demo.revivefail-level.maptime)%16) < 8 )
Screen.DrawText(mSmallFont,Font.CR_RED,xx,yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
Screen.DrawText(mSmallFont,Font.CR_RED,xx,yy,str,DTA_VirtualWidthF,ss0.x,DTA_VirtualHeightF,ss0.y,DTA_KeepRatio,true);
}
alph = clamp((deadtimer-60)/60.,0.,1.);
String nam = CPlayer.GetUserName();
if ( !multiplayer || (nam == "Player") ) str = StringTable.Localize("$SWWM_URDED_GEN");
else str = String.Format(StringTable.Localize("$SWWM_URDED"),nam);
len = mSmallFont.StringWidth(str);
xx = int((ss.x-len)/2.);
yy = (ss.y-mSmallFont.GetHeight()*4)/2.;
xx = int((ss0.x-len)/2.);
yy = (ss0.y-mSmallFont.GetHeight()*4)/2.;
// shift down if scoreboard is shown
if ( (deathmatch && sb_deathmatch_enable && (!teamplay || sb_teamdeathmatch_enable)) || (multiplayer && sb_cooperative_enable) )
yy += ss.y/3.+mSmallFont.GetHeight();
Screen.DrawText(mSmallFont,Font.CR_RED,xx,yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,alph);
yy += ss0.y/3.+mSmallFont.GetHeight();
Screen.DrawText(mSmallFont,Font.CR_RED,xx,yy,str,DTA_VirtualWidthF,ss0.x,DTA_VirtualHeightF,ss0.y,DTA_KeepRatio,true,DTA_Alpha,alph);
if ( multiplayer || level.AllowRespawn || sv_singleplayerrespawn || G_SkillPropertyInt(SKILLP_PlayerRespawn) )
{
if ( sv_norespawn ) return (1.-dimalph);
alph = clamp((deadtimer-90)/60.,0.,1.);
str = String.Format(StringTable.Localize("$SWWM_URDEDMP"));
len = mSmallFont.StringWidth(str);
xx = int((ss.x-len)/2.);
yy = ss.y/2.;
xx = int((ss0.x-len)/2.);
yy = ss0.y/2.;
// shift down if scoreboard is shown
if ( (deathmatch && sb_deathmatch_enable && (!teamplay || sb_teamdeathmatch_enable)) || (multiplayer && sb_cooperative_enable) )
yy += ss.y/3.;
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx,yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,alph);
yy += ss0.y/3.;
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx,yy,str,DTA_VirtualWidthF,ss0.x,DTA_VirtualHeightF,ss0.y,DTA_KeepRatio,true,DTA_Alpha,alph);
return (1.-dimalph);
}
alph = clamp((deadtimer-140)/60.,0.,1.);
str = String.Format(StringTable.Localize("$SWWM_URDED2"));
len = mSmallFont.StringWidth(str);
xx = int((ss.x-len)/2.);
yy = ss.y/2.;
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx,yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,alph);
xx = int((ss0.x-len)/2.);
yy = ss0.y/2.;
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx,yy,str,DTA_VirtualWidthF,ss0.x,DTA_VirtualHeightF,ss0.y,DTA_KeepRatio,true,DTA_Alpha,alph);
if ( goner || hnd.gdat.disablerevive || !swwm_revive )
return (1.-dimalph);
alph = clamp((deadtimer-160)/60.,0.,1.);
str = String.Format(StringTable.Localize("$SWWM_URDED3"));
len = mSmallFont.StringWidth(str);
xx = int((ss.x-len)/2.);
yy = (ss.y+mSmallFont.GetHeight()*2)/2.;
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx,yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,alph);
xx = int((ss0.x-len)/2.);
yy = (ss0.y+mSmallFont.GetHeight()*2)/2.;
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx,yy,str,DTA_VirtualWidthF,ss0.x,DTA_VirtualHeightF,ss0.y,DTA_KeepRatio,true,DTA_Alpha,alph);
return (1.-dimalph);
}
return 1.;
@ -656,6 +657,8 @@ Class SWWMStatusBar : BaseStatusBar
// calculate margin for ultrawide screens, mostly so hud
// elements don't get too spread out
xmargin = ymargin+max(int(ss.x-ss.y/.5625)/2,0);
// calculate vertical margin for hudscale0 (relative to base hudscale)
ymargin0 = int(ymargin*(hs/hs0));
FracTic = TicFrac;
if ( (players[consoleplayer].Camera is 'Demolitionist') && (state <= HUD_Fullscreen) )
{
@ -672,7 +675,7 @@ Class SWWMStatusBar : BaseStatusBar
if ( state == HUD_AltHud )
{
String str = StringTable.Localize("$SWWM_WARNALTHUD");
Screen.DrawText(NewSmallFont,Font.CR_RED,(ss.x-NewSmallFont.StringWidth(str))/2,ymargin,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
Screen.DrawText(NewSmallFont,Font.CR_RED,(ss0.x-NewSmallFont.StringWidth(str))/2,ymargin0,str,DTA_VirtualWidthF,ss0.x,DTA_VirtualHeightF,ss0.y,DTA_KeepRatio,true);
}
PrevFrame = CurFrame;
}

View file

@ -288,21 +288,21 @@ extend Class SWWMStatusBar
if ( (ntagstr != "") && (tagtime > 0) )
{
nalph = clamp(tagtime/20.,0.,1.);
yy = ss.y-(ymargin+50);
yy = ss0.y-(ymargin0+50);
int len = mSmallFont.StringWidth(ntagstr);
double xx = (ss.x-len)/2.;
Screen.Dim("Black",.8*nalph,int((xx-6)*hs),int(yy*hs),int((len+12)*hs),int((h+4)*hs));
Screen.DrawText(mSmallFont,ntagcol,int(xx),yy+2,ntagstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,nalph);
double xx = (ss0.x-len)/2.;
Screen.Dim("Black",.8*nalph,int((xx-6)*hs0),int(yy*hs0),int((len+12)*hs0),int((h+4)*hs0));
Screen.DrawText(mSmallFont,ntagcol,int(xx),yy+2,ntagstr,DTA_VirtualWidthF,ss0.x,DTA_VirtualHeightF,ss0.y,DTA_KeepRatio,true,DTA_Alpha,nalph);
}
if ( PickupQueue.Size() <= 0 ) return;
// reverse order since they're drawn bottom to top
int mend = max(0,PickupQueue.Size()-MAXPICKUP);
yy = ss.y-(ymargin+50);
yy = ss0.y-(ymargin0+50);
// shift up if nametag is present
if ( nalph > 0. ) yy -= int((mSmallFont.GetHeight()+6)*clamp(nalph*2.,0.,1.));
for ( int i=PickupQueue.Size()-1; i>=mend; i-- )
{
PickupQueue[i].UpdateText(int(min(ss.x,ss.y/.5625)*.75));
PickupQueue[i].UpdateText(int(min(ss0.x,ss0.y/.5625)*.75));
double curtime = (PickupQueue[i].tic+GameTicRate*PICKDURATION)-(level.totaltime+fractic);
double alph = clamp(curtime/20.,0.,1.);
let l = PickupQueue[i].l;
@ -312,13 +312,13 @@ extend Class SWWMStatusBar
int len = mSmallFont.StringWidth(l.StringAt(j));
if ( len > maxlen ) maxlen = len;
}
double xx = (ss.x-maxlen)/2.;
Screen.Dim("Black",.8*alph,int((xx-6)*hs),int((yy-h*(l.Count()-1))*hs),int((maxlen+12)*hs),int((h*l.Count()+4)*hs));
double xx = (ss0.x-maxlen)/2.;
Screen.Dim("Black",.8*alph,int((xx-6)*hs0),int((yy-h*(l.Count()-1))*hs0),int((maxlen+12)*hs0),int((h*l.Count()+4)*hs0));
for ( int j=l.Count()-1; j>=0; j-- )
{
int len = mSmallFont.StringWidth(l.StringAt(j));
xx = int((ss.x-len)/2.);
Screen.DrawText(mSmallFont,msg0color,xx,yy+2,l.StringAt(j),DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,alph);
xx = int((ss0.x-len)/2.);
Screen.DrawText(mSmallFont,msg0color,xx,yy+2,l.StringAt(j),DTA_VirtualWidthF,ss0.x,DTA_VirtualHeightF,ss0.y,DTA_KeepRatio,true,DTA_Alpha,alph);
yy -= h;
}
yy -= 6;
@ -335,23 +335,23 @@ extend Class SWWMStatusBar
int col = (midtype&2)?msgmidcolor2:msgmidcolor;
double curtime = (midtic+int(GameTicRate*con_midtime))-(level.totaltime+fractic);
double alph = clamp(curtime/20.,0.,1.);
if ( !midl || (midsz != int(ss.x*ssp)) )
if ( !midl || (midsz != int(ss0.x*ssp)) )
{
if ( midl ) midl.Destroy();
midl = mSmallFont.BreakLines(midstr,int(min(ss.x,ss.y/.5625)*ssp));
midl = mSmallFont.BreakLines(midstr,int(min(ss0.x,ss0.y/.5625)*ssp));
}
int h = mSmallFont.GetHeight();
int maxlen = 0;
for ( int i=0; i<midl.Count(); i++ ) maxlen = max(maxlen,mSmallFont.StringWidth(midl.StringAt(i)));
xx = int((ss.x*ssp-maxlen)/2.);
yy = int(ss.y*ssp*.375);
xx = int((ss0.x*ssp-maxlen)/2.);
yy = int(ss0.y*ssp*.375);
yy -= (h*midl.Count()+4)/2; // center
Screen.Dim("Black",.8*alph,int((xx-6)*hs*hsp),int(yy*hs*hsp),int((maxlen+12)*hs*hsp),int((h*midl.Count()+4)*hs*hsp));
Screen.Dim("Black",.8*alph,int((xx-6)*hs0*hsp),int(yy*hs0*hsp),int((maxlen+12)*hs0*hsp),int((h*midl.Count()+4)*hs0*hsp));
for ( int i=0; i<midl.Count(); i++ )
{
int len = mSmallFont.StringWidth(midl.StringAt(i));
xx = int((ss.x*ssp-len)/2.);
Screen.DrawText(mSmallFont,col,int(xx),yy+2,midl.StringAt(i),DTA_VirtualWidthF,ss.x*ssp,DTA_VirtualHeightF,ss.y*ssp,DTA_KeepRatio,true,DTA_Alpha,alph);
xx = int((ss0.x*ssp-len)/2.);
Screen.DrawText(mSmallFont,col,int(xx),yy+2,midl.StringAt(i),DTA_VirtualWidthF,ss0.x*ssp,DTA_VirtualHeightF,ss0.y*ssp,DTA_KeepRatio,true,DTA_Alpha,alph);
yy += h;
}
}

View file

@ -91,9 +91,9 @@ Class SWWMOneLiner : HUDMessageBase
Vector2 ss;
if ( SWWMStatusBar(StatusBar) )
{
ymargin = SWWMStatusBar(StatusBar).ymargin;
hs = SWWMStatusBar(StatusBar).hs;
ss = SWWMStatusBar(StatusBar).ss;
ymargin = SWWMStatusBar(StatusBar).ymargin0;
hs = SWWMStatusBar(StatusBar).hs0;
ss = SWWMStatusBar(StatusBar).ss0;
}
else
{
@ -263,9 +263,9 @@ Class SWWMWeaponTooltip : HUDMessageBase
Vector2 ss;
if ( SWWMStatusBar(StatusBar) )
{
ymargin = SWWMStatusBar(StatusBar).ymargin;
hs = SWWMStatusBar(StatusBar).hs;
ss = SWWMStatusBar(StatusBar).ss;
ymargin = SWWMStatusBar(StatusBar).ymargin0;
hs = SWWMStatusBar(StatusBar).hs0;
ss = SWWMStatusBar(StatusBar).ss0;
}
else
{
@ -1299,7 +1299,7 @@ Class SWWMWeaponSelect : HUDMessageBase
olsmoothY = smoothY;
smoothY = smoothY*.8+curY*.2;
double hs;
if ( SWWMStatusBar(StatusBar) ) hs = SWWMStatusBar(StatusBar).hs;
if ( SWWMStatusBar(StatusBar) ) hs = SWWMStatusBar(StatusBar).hs0;
else hs = max(min(floor(Screen.GetWidth()/640.),floor(Screen.GetHeight()/360.)),1.);
if ( abs(smoothY-curY) < (1./hs) ) smoothY = curY;
return false;
@ -1315,8 +1315,8 @@ Class SWWMWeaponSelect : HUDMessageBase
Vector2 ss;
if ( SWWMStatusBar(StatusBar) )
{
hs = SWWMStatusBar(StatusBar).hs;
ss = SWWMStatusBar(StatusBar).ss;
hs = SWWMStatusBar(StatusBar).hs0;
ss = SWWMStatusBar(StatusBar).ss0;
}
else
{