swwmgz_m/zscript/menu/swwm_inter.zsc

342 lines
11 KiB
Text

// Custom intermission screens
Class SWWMStatScreen : StatusScreen abstract
{
transient TextureID bgtex, arttex;
int whichart, whichtip;
double hs, hs2;
Vector2 ss, ss2, origin, origin2;
Font mSmallFont;
String tipstr;
transient BrokenLines tipl;
double bgfade;
bool bFade;
override void Start( wbstartstruct wbstartstruct )
{
Super.Start(wbstartstruct);
mSmallFont = Font.GetFont('TewiFont');
// support for old author text style
int iof;
for ( int i=0; i<=1; i++ )
{
if ( (iof = lnametexts[i].RightIndexOf(" - by: ")) != -1 ) // 20 heretics, spooktober
{
authortexts[i] = lnametexts[i].Mid(iof+7);
lnametexts[i].Truncate(iof);
}
else if ( (iof = lnametexts[i].RightIndexOf(" - by ")) != -1 ) // variation seen in DOOMIUM
{
authortexts[i] = lnametexts[i].Mid(iof+6);
lnametexts[i].Truncate(iof);
}
else if ( (iof = lnametexts[i].RightIndexOf(" - ")) != -1 ) // hexmas and many others (may cause false positives?)
{
authortexts[i] = lnametexts[i].Mid(iof+3);
lnametexts[i].Truncate(iof);
}
// level name may contain trailing whitespace due to DEHACKED nonsense, so strip it
lnametexts[i].StripRight();
}
}
override void StartMusic()
{
if ( swwm_intermusic ) Level.SetInterMusic(wbs.next);
else S_ChangeMusic("music/DRAGONY.XM");
}
private void drawSWWMBg()
{
let shnd = SWWMStaticHandler(StaticEventHandler.Find("SWWMStaticHandler"));
if ( !whichart && swwm_interart )
{
int no = StringTable.Localize("$SWWM_NFANART").ToInt();
Array<Int> ents;
ents.Clear();
int rno = 0;
for ( int i=1; i<=no; i++ )
{
if ( (swwm_interart == 2) && (StringTable.Localize("$SWWM_FANART"..i).Left(6) == "Marisa") )
continue;
else if ( (swwm_interart == 3) && (StringTable.Localize("$SWWM_FANART"..i).Left(6) != "Marisa") )
continue;
ents.Push(i);
rno++;
}
no = rno;
if ( shnd.lastart.Size() >= no )
{
// exclude last one, start over
int excludeme = shnd.lastart[shnd.lastart.Size()-1];
ents.Delete(excludeme-1);
shnd.lastart.Clear();
}
else
{
foreach ( la:shnd.lastart )
{
int f = ents.Find(la);
if ( f != ents.Size() )
ents.Delete(f);
}
}
whichart = ents[Random[InterArt](0,ents.Size()-1)];
shnd.lastart.Push(whichart);
}
double ar = Screen.GetAspectRatio(), sar;
Vector2 tsize, vsize;
if ( whichart ) Screen.Clear(0,0,Screen.GetWidth(),Screen.GetHeight(),"Black");
else
{
if ( !bgtex ) bgtex = TexMan.CheckForTexture("graphics/InterBG.png");
tsize = TexMan.GetScaledSize(bgtex);
sar = tsize.x/tsize.y;
if ( sar > ar ) vsize = (tsize.y*ar,tsize.y);
else if ( sar < ar ) vsize = (tsize.x,tsize.x/ar);
else vsize = tsize;
Screen.DrawTexture(bgtex,false,(vsize.x-tsize.x)/2,(vsize.y-tsize.y)/2,DTA_VirtualWidthF,vsize.x,DTA_VirtualHeightF,vsize.y,DTA_KeepRatio,true);
}
// background pics
if ( whichart )
{
String artstr = StringTable.Localize(String.Format("$SWWM_FANART%d",whichart));
int semic = artstr.IndexOf(";");
if ( !arttex ) arttex = TexMan.CheckForTexture(String.Format("graphics/Fanart/%s",(semic==-1)?artstr:artstr.Left(semic)));
tsize = TexMan.GetScaledSize(arttex);
sar = tsize.x/tsize.y;
if ( sar > ar ) vsize = (tsize.y*ar,tsize.y);
else if ( sar < ar ) vsize = (tsize.x,tsize.x/ar);
else vsize = tsize;
Screen.DrawTexture(arttex,false,(vsize.x-tsize.x)/2,(vsize.y-tsize.y)/2,DTA_VirtualWidthF,vsize.x,DTA_VirtualHeightF,vsize.y,DTA_KeepRatio,true);
if ( semic != -1 )
{
String bstr = String.Format("\cx%s\c- %s",StringTable.Localize("$SWWM_FANART"),artstr.Mid(semic+1));
int len = mSmallFont.StringWidth(bstr);
int bw = int((len+8)*hs), bh = int((mSmallFont.GetHeight()+4)*hs);
Screen.Dim("Black",.8,Screen.GetWidth()-bw,Screen.GetHeight()-bh,bw,bh);
Screen.DrawText(mSmallFont,Font.CR_GOLD,ss.x-(len+4),ss.y-(mSmallFont.GetHeight()+2),bstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
}
// intermission tips at the bottom
if ( !whichtip )
{
int maxtip = StringTable.Localize("$SWWM_NINTERTIP").ToInt();
Array<Int> ents;
ents.Clear();
for ( int i=1; i<=maxtip; i++ ) ents.Push(i);
if ( shnd.lasttip.Size() >= maxtip )
{
// exclude last one, start over
int excludeme = shnd.lasttip[shnd.lasttip.Size()-1];
ents.Delete(excludeme-1);
shnd.lasttip.Clear();
}
else
{
foreach ( lt:shnd.lasttip )
{
int f = ents.Find(lt);
if ( f != ents.Size() )
ents.Delete(f);
}
}
whichtip = ents[Random[InterArt](0,ents.Size()-1)];
tipstr = "\cd"..String.Format(StringTable.Localize("$SWWM_INTERTIP"),whichtip).."\c-\n"..StringTable.Localize(String.Format("$SWWM_INTERTIP%d",whichtip));
if ( tipl ) tipl.Destroy();
shnd.lasttip.Push(whichtip);
}
if ( swwm_nointertips ) return;
int lw = 0;
if ( !tipl ) tipl = mSmallFont.BreakLines(tipstr,400);
for ( int i=0; i<tipl.Count(); i++ )
if ( tipl.StringWidth(i) > lw )
lw = tipl.StringWidth(i);
int bw = int((lw+12)*hs), bh = int((mSmallFont.GetHeight()*tipl.Count()+8)*hs);
double xx = 8, yy = (ss.y-8)-(mSmallFont.GetHeight()*tipl.Count());
Screen.Dim("Black",.8,int((xx-4)*hs),int((yy-4)*hs),bw,bh);
for ( int i=0; i<tipl.Count(); i++ )
{
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx,yy,tipl.StringAt(i),DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
yy += mSmallFont.GetHeight();
xx = 12;
}
}
override int DrawLF()
{
int len[2];
len[0] = mSmallFont.StringWidth(lnametexts[0]);
len[1] = mSmallFont.StringWidth(authortexts[0]);
int dimlen = max(int((len[0]+8)*hs2),int((len[1]+8)*hs));
bool auth = (authortexts[0].Length()>0);
Screen.Dim("Black",.8,int((Screen.GetWidth()-dimlen)/2.),int(4*hs2),dimlen,int((mSmallFont.GetHeight()+(auth?2:4))*hs2));
Screen.DrawText(mSmallFont,Font.CR_GREEN,int((ss2.x-len[0])/2.),6,lnametexts[0],DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
double foy = mSmallFont.GetHeight()+(auth?6:8);
if ( auth )
{
double oy = foy*(hs2/hs);
Screen.Dim("Black",.8,int((Screen.GetWidth()-dimlen)/2.),int(oy*hs),dimlen,int((mSmallFont.GetHeight()+2)*hs));
Screen.DrawText(mSmallFont,Font.CR_WHITE,int((ss.x-len[1])/2.),oy,authortexts[0],DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
foy += (mSmallFont.GetHeight()+2)*(hs/hs2);
}
foy += 4.;
String str = StringTable.Localize("$WI_FINISHED");
len[0] = mSmallFont.StringWidth(str);
Screen.Dim("Black",.8,int((ss2.x-len[0]-8)/2*hs2),int(foy*hs2),int((len[0]+8)*hs2),int((mSmallFont.GetHeight()+4)*hs2));
Screen.DrawText(mSmallFont,Font.CR_FIRE,int((ss2.x-len[0])/2.),foy+2,str,DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
// return not used
return 0;
}
override void DrawEL()
{
String str = StringTable.Localize("$WI_ENTERING");
// remove trailing colon (usually appearing on Heretic)
if ( str.RightIndexOf(":") == (str.length()-1) ) str.Truncate(str.length()-1);
int len[2];
len[0] = mSmallFont.StringWidth(str);
Screen.Dim("Black",.8,int((ss2.x-len[0]-8)/2*hs2),int(4*hs2),int((len[0]+8)*hs2),int((mSmallFont.GetHeight()+4)*hs2));
Screen.DrawText(mSmallFont,Font.CR_FIRE,int((ss2.x-len[0])/2.),6,str,DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
double foy = mSmallFont.GetHeight()+12;
len[0] = mSmallFont.StringWidth(lnametexts[1]);
len[1] = mSmallFont.StringWidth(authortexts[1]);
int dimlen = max(int((len[0]+8)*hs2),int((len[1]+8)*hs));
bool auth = (authortexts[1].Length()>0);
Screen.Dim("Black",.8,int((Screen.GetWidth()-dimlen)/2.),int(foy*hs2),dimlen,int((mSmallFont.GetHeight()+(auth?2:4))*hs2));
Screen.DrawText(mSmallFont,Font.CR_GREEN,int((ss2.x-len[0])/2.),foy+2,lnametexts[1],DTA_VirtualWidthF,ss2.x,DTA_VirtualHeightF,ss2.y,DTA_KeepRatio,true);
if ( auth )
{
double oy = (foy+mSmallFont.GetHeight()+2)*(hs2/hs);
Screen.Dim("Black",.8,int((Screen.GetWidth()-dimlen)/2.),int(oy*hs),dimlen,int((mSmallFont.GetHeight()+2)*hs));
Screen.DrawText(mSmallFont,Font.CR_WHITE,int((ss.x-len[1])/2.),oy,authortexts[1],DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
}
override void drawShowNextLoc( void )
{
drawSWWMBg();
drawEL();
}
override void Drawer()
{
// nothing here
}
override void Draw( double smoothratio )
{
hs = max(min(floor(Screen.GetWidth()/640.),floor(Screen.GetHeight()/400.)),1.);
hs2 = max(min(floor(Screen.GetWidth()/320.),floor(Screen.GetHeight()/200.)),1.);
ss = (Screen.GetWidth(),Screen.GetHeight())/hs;
ss2 = (Screen.GetWidth(),Screen.GetHeight())/hs2;
origin = (ss.x-640,ss.y-400)/2.;
origin2 = (ss2.x-320,ss2.y-200)/2.;
switch ( CurState )
{
case StatCount:
drawSWWMBg();
drawStats();
break;
case ShowNextLoc:
case LeavingIntermission:
drawShowNextLoc();
break;
break;
default:
drawNoState();
break;
}
if ( bgfade <= 0. ) return;
double alph = bgfade;
if ( bFade ) alph = min(1.,bgfade+(3.*smoothratio)/GameTicRate);
else alph = max(0.,bgfade-(4.*smoothratio)/GameTicRate);
// redraw BG on top, hiding the rest of the ui
TextureID tx;
if ( whichart ) tx = arttex;
else tx = bgtex;
double ar = Screen.GetAspectRatio();
Vector2 tsize = TexMan.GetScaledSize(tx);
double sar = tsize.x/tsize.y;
Vector2 vsize;
if ( sar > ar ) vsize = (tsize.y*ar,tsize.y);
else if ( sar < ar ) vsize = (tsize.x,tsize.x/ar);
else vsize = tsize;
Screen.DrawTexture(tx,false,(vsize.x-tsize.x)/2,(vsize.y-tsize.y)/2,DTA_VirtualWidthF,vsize.x,DTA_VirtualHeightF,vsize.y,DTA_KeepRatio,true,DTA_Alpha,alph);
}
override void Ticker( void )
{
bcnt++;
if ( bcnt == 1 ) StartMusic();
switch (CurState)
{
case StatCount:
updateStats();
break;
case ShowNextLoc:
updateShowNextLoc();
break;
case NoState:
updateNoState();
break;
case LeavingIntermission:
// sorry nothing
break;
}
// check fade
if ( bFade ) bgfade = min(1.,bgfade+3./GameTicRate);
else bgfade = max(0.,bgfade-4./GameTicRate);
// force toggle
if ( !swwm_interart && (whichart != 0) )
{
whichart = 0;
arttex.SetNull();
}
}
protected String TimeStr( int secs )
{
secs = max(secs,0);
int h = secs/3600;
int m = (secs/60)%60;
int s = secs%60;
if ( h ) return String.Format("%02d\cu:\c-%02d\cu:\c-%02d",h,m,s);
return String.Format("%02d\cu:\c-%02d",m,s);
}
protected int GetPct( int a, int b, bool inv = false )
{
if ( a < 0 ) return 0;
if ( b <= 0 ) return inv?0:100; // for "missed" percentage
return (a*100)/b;
}
override bool OnEvent( InputEvent evt )
{
if ( evt.type == InputEvent.Type_KeyDown )
{
String cmd = Bindings.GetBinding(evt.KeyScan);
if ( (cmd ~== "+attack") || (cmd ~== "+use") || (evt.KeyScan == InputEvent.KEY_ENTER) ) // KEY_ENTER needed as fallback for Delta Touch compatibility
{
accelerateStage = 1;
return true;
}
if ( cmd ~== "+altattack" )
{
bFade = true;
return true;
}
if ( cmd ~== "+reload" )
{
if ( !swwm_nointertips ) PlaySound("menu/demoscroll");
whichtip = 0;
return true;
}
if ( cmd ~== "+zoom" )
{
if ( swwm_interart ) PlaySound("menu/demoscroll");
whichart = 0;
arttex.SetNull();
return true;
}
return false;
}
else if ( (evt.type == InputEvent.Type_KeyUp)
&& (Bindings.GetBinding(evt.KeyScan) ~== "+altattack") )
{
bFade = false;
return true;
}
return false;
}
}