228 lines
8.8 KiB
Text
228 lines
8.8 KiB
Text
// Things for the titlemap
|
|
|
|
Struct TitleExplosion
|
|
{
|
|
bool bInit;
|
|
int frame;
|
|
Vector2 pos;
|
|
double scale;
|
|
bool flipx, flipy;
|
|
double angle;
|
|
}
|
|
|
|
Class SWWMTitleStuff : EventHandler
|
|
{
|
|
ui TextureID tex[4];
|
|
ui Array<String> scrolls;
|
|
ui int sline;
|
|
ui double sbase;
|
|
ui String lastlang;
|
|
ui TitleExplosion smk[64];
|
|
ui TextureID smk_frame[19];
|
|
int titletimer;
|
|
ui int rss;
|
|
ui int stopinit_t;
|
|
|
|
private ui int GetUIRandom()
|
|
{
|
|
return (rss = (rss<<1)*35447+(rss/87));
|
|
}
|
|
|
|
private ui double RandomShiver()
|
|
{
|
|
int sd = GetUIRandom();
|
|
return ((abs(sd)%11)-5)*.1;
|
|
}
|
|
|
|
private ui void TickExplosions()
|
|
{
|
|
if ( stopinit_t > 0 ) stopinit_t--;
|
|
bool stopinit = (stopinit_t>0);
|
|
for ( int i=0; i<64; i++ )
|
|
{
|
|
if ( (!smk[i].bInit && !stopinit) || (smk[i].frame > 18) )
|
|
{
|
|
smk[i].frame = Random[UIStuff](smk[i].bInit?-20:-4,0);
|
|
smk[i].pos = (FRandom[UIStuff](0.,1.),FRandom[UIStuff](0.,1.));
|
|
smk[i].scale = FRandom[UIStuff](3.,6.);
|
|
smk[i].angle = FRandom[UIStuff](0.,360.);
|
|
smk[i].flipx = Random[UIStuff](0,1);
|
|
smk[i].flipy = Random[UIStuff](0,1);
|
|
if ( !smk[i].bInit )
|
|
{
|
|
smk[i].bInit = true;
|
|
stopinit = true;
|
|
stopinit_t = 4;
|
|
}
|
|
}
|
|
if ( !smk[i].bInit ) continue;
|
|
if ( (smk[i].frame == 0) && (titletimer < -20 ) )
|
|
S_StartSound("title/explo",CHAN_WEAPON,CHANF_UI|CHANF_OVERLAP,1.,ATTN_NONE,FRandom[UIStuff](.95,1.05));
|
|
smk[i].frame++;
|
|
}
|
|
}
|
|
|
|
override void WorldTick()
|
|
{
|
|
if ( titletimer == -250 )
|
|
{
|
|
if ( gameinfo.gametype&GAME_Hexen ) S_ChangeMusic("HEXEN");
|
|
else if ( gameinfo.gametype&GAME_Heretic ) S_ChangeMusic("MUS_TITL");
|
|
else
|
|
{
|
|
// check if the doom 1 music exists
|
|
if ( Wads.FindLump("D_INTRO",ns:wads.ns_music) != -1 )
|
|
S_ChangeMusic("D_INTRO");
|
|
else S_ChangeMusic("D_DM2TTL");
|
|
}
|
|
}
|
|
if ( titletimer == -75 ) S_ChangeMusic("");
|
|
if ( titletimer == 0 ) S_ChangeMusic("music/TRAUMATI.XM");
|
|
titletimer++;
|
|
if ( menuactive && (titletimer < -80) ) titletimer = -80;
|
|
}
|
|
|
|
override void WorldLoaded( WorldEvent e )
|
|
{
|
|
titletimer = -300;
|
|
let shnd = SWWMStaticHandler(StaticEventHandler.Find("SWWMStaticHandler"));
|
|
if ( !shnd ) return;
|
|
if ( shnd.titlefirst )
|
|
{
|
|
titletimer = GameTicRate*26; // skip to logo
|
|
S_ChangeMusic("music/TRAUMATI.XM",2); // skip to order 2
|
|
}
|
|
shnd.titlefirst = true;
|
|
}
|
|
|
|
override void UiTick()
|
|
{
|
|
if ( (titletimer > -80) && (titletimer < -20) ) TickExplosions();
|
|
if ( gamestate != GS_LEVEL ) return;
|
|
// you're not supposed to be here
|
|
Menu.SetMenu('EndGameMenu');
|
|
let m = MessageBoxMenu(Menu.GetCurrentMenu());
|
|
if ( m ) m.HandleResult(true);
|
|
// special thanks to marrub for this absolute crime
|
|
}
|
|
|
|
private ui void RenderExplosions()
|
|
{
|
|
for ( int i=0; i<64; i++ )
|
|
{
|
|
int frm = smk[i].frame;
|
|
if ( (frm < 0) || (frm > 18) ) continue;
|
|
if ( !smk_frame[frm] ) smk_frame[frm] = TexMan.CheckForTexture(String.Format("XEX0%c0",0x41+frm),TexMan.Type_Sprite);
|
|
Vector2 vpos;
|
|
vpos.x = smk[i].pos.x*Screen.GetWidth();
|
|
vpos.y = smk[i].pos.y*Screen.GetHeight();
|
|
Screen.DrawTexture(smk_frame[frm],false,vpos.x,vpos.y,DTA_ScaleX,smk[i].scale*CleanXFac,DTA_ScaleY,smk[i].scale*CleanYFac,DTA_FlipX,smk[i].flipx,DTA_FlipY,smk[i].flipy,DTA_Rotate,smk[i].angle,DTA_LegacyRenderStyle,STYLE_Add);
|
|
}
|
|
}
|
|
|
|
override void RenderUnderlay( RenderEvent e )
|
|
{
|
|
if ( !tex[0] ) tex[0] = TexMan.CheckForTexture("graphics/UnSXLogo.png",TexMan.Type_Any);
|
|
if ( !tex[1] ) tex[1] = TexMan.CheckForTexture("graphics/SWWMGZLogo.png",TexMan.Type_Any);
|
|
if ( !tex[2] ) tex[2] = TexMan.CheckForTexture("graphics/tempbg.png",TexMan.Type_Any);
|
|
if ( !tex[3] ) tex[3] = TexMan.CheckForTexture((gameinfo.gametype&GAME_Raven)?"TITLE":"TITLEPIC",TexMan.Type_MiscPatch);
|
|
Vector2 tsize, vsize;
|
|
if ( titletimer < 0 )
|
|
{
|
|
Screen.Dim("Black",1.,0,0,Screen.GetWidth(),Screen.GetHeight());
|
|
if ( titletimer < -20 )
|
|
{
|
|
rss = int(MSTime()*(GameTicRate/1000.));
|
|
Vector2 ofs = (RandomShiver(),RandomShiver())*clamp((80+titletimer+e.FracTic)/50.,0.,1.);
|
|
tsize = TexMan.GetScaledSize(tex[3]);
|
|
ofs *= tsize.y/10.;
|
|
Screen.DrawTexture(tex[3],true,ofs.x,ofs.y,DTA_VirtualWidthF,tsize.x,DTA_VirtualHeightF,tsize.y,DTA_FullscreenScale,FSMode_ScaleToFit43);
|
|
RenderExplosions();
|
|
}
|
|
if ( titletimer > -20 ) Screen.Dim("White",1.-clamp((20+titletimer+e.FracTic)/20.,0.,1.),0,0,Screen.GetWidth(),Screen.GetHeight());
|
|
else if ( titletimer > -80 ) Screen.Dim("White",clamp((80+titletimer+e.FracTic)/50.,0.,1.),0,0,Screen.GetWidth(),Screen.GetHeight());
|
|
if ( titletimer <= -250 ) Screen.Dim("Black",1.-clamp((270+titletimer+e.FracTic)/20.,0.,1.),0,0,Screen.GetWidth(),Screen.GetHeight());
|
|
return;
|
|
}
|
|
if ( swwm_fuzz )
|
|
{
|
|
tsize = TexMan.GetScaledSize(tex[2]);
|
|
double zoom = max(ceil(Screen.GetWidth()/tsize.x),ceil(Screen.GetHeight()/tsize.y));
|
|
vsize = (Screen.GetWidth(),Screen.GetHeight())/zoom;
|
|
Screen.DrawTexture(tex[2],false,(vsize.x-tsize.x)/2,(vsize.y-tsize.y)/2,DTA_VirtualWidthF,vsize.x,DTA_VirtualHeightF,vsize.y,DTA_KeepRatio,true,DTA_ColorOverlay,Color(192,0,0,0));
|
|
Screen.Dim("Black",clamp(1.-((titletimer+e.FracTic)/GameTicRate)*.05,0.,1.),0,0,Screen.GetWidth(),Screen.GetHeight());
|
|
}
|
|
else Screen.Dim("Black",1.,0,0,Screen.GetWidth(),Screen.GetHeight());
|
|
double hs = max(min(floor(Screen.GetWidth()/320.),floor(Screen.GetHeight()/200.)),1.);
|
|
Vector2 ss = (Screen.GetWidth(),Screen.GetHeight())/hs;
|
|
double ar = Screen.GetAspectRatio();
|
|
tsize = TexMan.GetScaledSize(tex[0]);
|
|
double sar = tsize.x/tsize.y;
|
|
if ( sar > ar ) vsize = (tsize.x,tsize.x/ar);
|
|
else if ( sar < ar ) vsize = (tsize.y*ar,tsize.y);
|
|
else vsize = tsize;
|
|
double alf = clamp(((titletimer+e.FracTic)/GameTicRate)-2,0.,1.);
|
|
alf *= 1.-clamp(((titletimer+e.FracTic)/GameTicRate)-8,0.,1.);
|
|
Screen.DrawTexture(tex[0],false,(vsize.x-tsize.x)/2,(vsize.y-tsize.y)/2,DTA_VirtualWidthF,vsize.x,DTA_VirtualHeightF,vsize.y,DTA_KeepRatio,true,DTA_Alpha,alf);
|
|
String str = StringTable.Localize("$SWWM_TITLEPRESENTS");
|
|
alf = clamp(((titletimer+e.FracTic)/GameTicRate)-10,0.,1.);
|
|
alf *= 1.-clamp(((titletimer+e.FracTic)/GameTicRate)-16,0.,1.);
|
|
Screen.DrawText(smallfont,Font.CR_WHITE,(ss.x-smallfont.StringWidth(str))/2,(ss.y-smallfont.GetHeight())/2,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,alf);
|
|
str = StringTable.Localize("$SWWM_TITLEMODBY");
|
|
alf = clamp(((titletimer+e.FracTic)/GameTicRate)-18,0.,1.);
|
|
alf *= 1.-clamp(((titletimer+e.FracTic)/GameTicRate)-24,0.,1.);
|
|
Screen.DrawText(smallfont,Font.CR_WHITE,(ss.x-smallfont.StringWidth(str))/2,(ss.y-smallfont.GetHeight())/2,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,alf);
|
|
tsize = TexMan.GetScaledSize(tex[1]);
|
|
sar = tsize.x/tsize.y;
|
|
if ( sar > ar ) vsize = (tsize.x,tsize.x/ar);
|
|
else if ( sar < ar ) vsize = (tsize.y*ar,tsize.y);
|
|
else vsize = tsize;
|
|
alf = clamp(((titletimer+e.FracTic)/GameTicRate)-26,0.,2.)*.5;
|
|
Screen.DrawTexture(tex[1],false,(vsize.x-tsize.x)/2,(vsize.y-tsize.y)/2,DTA_VirtualWidthF,vsize.x,DTA_VirtualHeightF,vsize.y,DTA_KeepRatio,true,DTA_Alpha,alf);
|
|
if ( (titletimer/GameTicRate) < 30 ) return;
|
|
// scrolls
|
|
if ( (scrolls.Size() <= 0 ) || (lastlang != language) )
|
|
{
|
|
scrolls.Clear();
|
|
String sstr = StringTable.Localize("$SWWM_TITLESCROLL");
|
|
sstr.Split(scrolls,"\n");
|
|
sbase = (titletimer+e.FracTic)/GameTicRate;
|
|
if ( sline >= scrolls.Size() ) sline = 0;
|
|
}
|
|
lastlang = language;
|
|
// estimate scrool length
|
|
double llen = smallfont.StringWidth(scrolls[sline]);
|
|
double soffset = 40*((titletimer+e.FracTic)/GameTicRate-sbase);
|
|
if ( soffset > llen+ss.x )
|
|
{
|
|
sline++;
|
|
if ( sline >= scrolls.Size() ) sline = 0;
|
|
sbase = (titletimer+e.FracTic)/GameTicRate;
|
|
soffset = 0;
|
|
}
|
|
double xx = ss.x-soffset;
|
|
int tlen = scrolls[sline].CodePointCount();
|
|
for ( int i=0, pos=0; i<tlen; i++ )
|
|
{
|
|
int ch;
|
|
[ch, pos] = scrolls[sline].GetNextCodePoint(pos);
|
|
if ( (xx > -8) && (xx < ss.x) )
|
|
{
|
|
for ( double trl = .1; trl < 1.; trl += .04 )
|
|
{
|
|
double yy = (ss.y-40)+10*sin(15*i+160*(titletimer+e.FracTic)/GameTicRate-90.*(1.-trl));
|
|
alf = max(0,1.-abs((ss.x/2)-xx)/(ss.x/2))**.5;
|
|
alf *= .2*trl;
|
|
double xxofs = 5*sin(15*i+120*(titletimer+e.FracTic)/GameTicRate-90.*(1.-trl))-16*(1.-trl);
|
|
Screen.DrawChar(smallfont,Font.CR_BLUE,xx-xxofs,yy,ch,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,alf,DTA_LegacyRenderStyle,STYLE_Add);
|
|
}
|
|
double yy = (ss.y-40)+10*sin(15*i+160*(titletimer+e.FracTic)/GameTicRate);
|
|
alf = max(0,1.-abs((ss.x/2)-xx)/(ss.x/2))**.5;
|
|
double xxofs = 5*sin(15*i+120*(titletimer+e.FracTic)/GameTicRate);
|
|
Color c = Color(int(127.5+127.5*sin(10*i+80*(titletimer+e.FracTic)/GameTicRate)),0,0);
|
|
Screen.DrawChar(smallfont,Font.CR_SAPPHIRE,xx-xxofs,yy,ch,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,alf);
|
|
}
|
|
xx += smallfont.GetCharWidth(ch)+smallfont.GetDefaultKerning();
|
|
}
|
|
}
|
|
}
|