From cb7aa8b333bd575166137f9550a4fce1e9a427eb Mon Sep 17 00:00:00 2001 From: Marisa Kirisame Date: Thu, 10 Mar 2022 13:33:37 +0100 Subject: [PATCH] "Niceify" usage of BrokenLines in many spots. --- language.version | 4 +- zscript/hud/swwm_hud.zsc | 64 +++++++++------ zscript/hud/swwm_hudextra.zsc | 33 ++++---- zscript/kbase/swwm_kbase_list.zsc | 17 +++- zscript/menu/swwm_help.zsc | 94 +++++++++++------------ zscript/menu/swwm_inter.zsc | 22 +++--- zscript/swwm_handler.zsc | 19 +++-- zscript/swwm_player.zsc | 2 +- zscript/weapons/swwm_baseweapon_melee.zsc | 4 +- zscript/weapons/swwm_cbt_ui.zsc | 22 +++--- 10 files changed, 161 insertions(+), 120 deletions(-) diff --git a/language.version b/language.version index 6c3fec31f..ba08d414f 100644 --- a/language.version +++ b/language.version @@ -1,3 +1,3 @@ [default] -SWWM_MODVER="\cyDEMOLITIONIST \cw1.2pre r184 \cu(Tue 8 Mar 14:54:32 CET 2022)\c-"; -SWWM_SHORTVER="\cw1.2pre r184 \cu(2022-03-08 14:54:32)\c-"; +SWWM_MODVER="\cyDEMOLITIONIST \cw1.2pre r185 \cu(Thu 10 Mar 13:33:37 CET 2022)\c-"; +SWWM_SHORTVER="\cw1.2pre r185 \cu(2022-03-10 13:33:37)\c-"; diff --git a/zscript/hud/swwm_hud.zsc b/zscript/hud/swwm_hud.zsc index 8bc09b30b..373fd9f7f 100644 --- a/zscript/hud/swwm_hud.zsc +++ b/zscript/hud/swwm_hud.zsc @@ -7,7 +7,24 @@ Class MsgLine { String str; + transient BrokenLines l, ls; int tic, type, rep; + int lastrep; + int lastsz; + + void UpdateText( int sz = 0 ) + { + bool mustupdate = (!l||!ls||(lastrep!=rep)||((type==PRINT_LOW)&&(sz!=lastsz))); + if ( !mustupdate ) return; + if ( l ) l.Destroy(); + if ( ls ) ls.Destroy(); + lastsz = sz; + lastrep = rep; + String nstr = str; + if ( rep > 1 ) nstr.AppendFormat(" (x%d)",rep); + l = SmallFont.BreakLines(nstr,(type==PRINT_LOW)?sz:361); + if ( type != PRINT_LOW ) ls = SmallFont.BreakLines(nstr,211); + } } Class SWWMStatusBar : BaseStatusBar @@ -64,6 +81,8 @@ Class SWWMStatusBar : BaseStatusBar String midstr; int midtic, midtype; + transient BrokenLines midl; + int midsz; bool koraxhack, mainframehack, bosshack; int puzzlecnt, realpuzzlecnt; @@ -698,17 +717,17 @@ Class SWWMStatusBar : BaseStatusBar // no need to attach name, these are done specifically for this printlevel = PRINT_CHAT; } + // append chat messages to full history + if ( (printlevel == PRINT_CHAT) || (printlevel == PRINT_TEAMCHAT) ) + EventHandler.SendNetworkEvent("swwmstoremessage."..outline.Left(outline.Length()-1),level.totaltime,printlevel,consoleplayer); + // ignore during intermission + if ( gamestate != GS_LEVEL ) return false; + if ( (printlevel < PRINT_LOW) || (printlevel > PRINT_TEAMCHAT) ) return true; // we couldn't care less about these let m = new("MsgLine"); m.str = outline.Left(outline.Length()-1); // strip newline m.type = printlevel; m.tic = level.totaltime; m.rep = 1; - // append chat messages to full history - if ( (printlevel == PRINT_CHAT) || (printlevel == PRINT_TEAMCHAT) ) - EventHandler.SendNetworkEvent("swwmstoremessage."..m.str,m.tic,m.type,consoleplayer); - // ignore during intermission - if ( gamestate != GS_LEVEL ) return false; - if ( (printlevel < PRINT_LOW) || (printlevel > PRINT_TEAMCHAT) ) return true; // we couldn't care less about these if ( printlevel == PRINT_LOW ) { // check if repeated @@ -720,6 +739,7 @@ Class SWWMStatusBar : BaseStatusBar PickupQueue.Delete(i); break; } + m.UpdateText(int(ss.x*.75)); PickupQueue.Push(m); } else @@ -733,6 +753,7 @@ Class SWWMStatusBar : BaseStatusBar MainQueue.Delete(i); break; } + m.UpdateText(); MainQueue.Push(m); } return true; @@ -2621,11 +2642,10 @@ Class SWWMStatusBar : BaseStatusBar if ( nalph > 0. ) yy -= int((smallfont.GetHeight()+6)*clamp(nalph*2.,0.,1.)); for ( int i=PickupQueue.Size()-1; i>=mend; i-- ) { - String cstr = PickupQueue[i].str; - if ( PickupQueue[i].rep > 1 ) cstr.AppendFormat(" (x%d)",PickupQueue[i].rep); + PickupQueue[i].UpdateText(int(ss.x*.75)); double curtime = (PickupQueue[i].tic+GameTicRate*swwm_pickduration)-(level.totaltime+fractic); double alph = clamp(curtime/20.,0.,1.); - BrokenLines l = smallfont.BreakLines(cstr,int(ss.x*.75)); + let l = PickupQueue[i].l; int maxlen = 0; for ( int j=0; j=gametic)?swwm_maxshownbig:swwm_maxshown)); @@ -2686,20 +2708,18 @@ Class SWWMStatusBar : BaseStatusBar if ( MainQueue[i].type == PRINT_MEDIUM ) col = msg1color; else if ( MainQueue[i].type == PRINT_CHAT ) col = msg3color; else if ( MainQueue[i].type == PRINT_TEAMCHAT ) col = msg4color; - String cstr = MainQueue[i].str; - if ( MainQueue[i].rep > 1 ) cstr.AppendFormat(" (x%d)",MainQueue[i].rep); + MainQueue[i].UpdateText(); + let l = smol?MainQueue[i].l:MainQueue[i].ls; double curtime = MainQueue[i].tic-(level.totaltime+fractic); if ( MainQueue[i].type < PRINT_CHAT ) curtime += GameTicRate*swwm_msgduration; else curtime += GameTicRate*swwm_chatduration; double alph = clamp(curtime/20.,0.,1.); - BrokenLines l = smallfont.BreakLines(cstr,smol?211:361); for ( int j=0; j= NUM_HELP_PAGES) ) return; - } - l = smallfont.BreakLines(txt,600); + let hdr = pagehdr[page]; + let l = pagetxt[page]; lh = l.Count()*h; Screen.DrawText(smallfont,Font.CR_FIRE,xofs+(Screen.GetWidth()-smallfont.StringWidth(hdr)*CleanXFac_1)/2,(Screen.GetHeight()-(h*3+lh)*CleanYFac_1)/2,hdr,DTA_CleanNoMove_1,true,DTA_Alpha,alpha); for ( int i=0; i lw ) - lw = l.StringWidth(i); - int bw = int((lw+12)*hs), bh = int((smallfont.GetHeight()*l.Count()+8)*hs); - double xx = 8, yy = (ss.y-8)-(smallfont.GetHeight()*l.Count()); + if ( !tipl ) tipl = smallfont.BreakLines(tipstr,400); + for ( int i=0; i lw ) + lw = tipl.StringWidth(i); + int bw = int((lw+12)*hs), bh = int((smallfont.GetHeight()*tipl.Count()+8)*hs); + double xx = 8, yy = (ss.y-8)-(smallfont.GetHeight()*tipl.Count()); Screen.Dim("Black",.8,int((xx-4)*hs),int((yy-4)*hs),bw,bh); - for ( int i=0; i boxw ) boxw = sw; } x = floor((ss.x-boxw)/2.); - Screen.Dim("Black",.8,int((x-2)*hs),int((y-2)*hs),int((boxw+4)*hs),int((9*l.Count()+2)*hs)); - for ( int i=0; i