168 lines
5.3 KiB
Text
168 lines
5.3 KiB
Text
// a game inside a game?
|
|
|
|
Class DemolitionistGameTab : DemolitionistMenuTab
|
|
{
|
|
MadcatGame game;
|
|
Array<Class<MadcatGame> > gamelist;
|
|
int sel;
|
|
|
|
override DemolitionistMenuTab Init( DemolitionistMenu master )
|
|
{
|
|
title = StringTable.Localize("$SWWM_GAMETAB");
|
|
for ( int i=0; i<AllClasses.Size(); i++ )
|
|
{
|
|
if ( AllClasses[i].isAbstract() || !(AllClasses[i] is 'MadcatGame') ) continue;
|
|
gamelist.Push((Class<MadcatGame>)(AllClasses[i]));
|
|
}
|
|
bDirectInput = true;
|
|
return Super.Init(master);
|
|
}
|
|
|
|
override void OnDestroy()
|
|
{
|
|
Super.OnDestroy();
|
|
if ( game ) game.Destroy();
|
|
}
|
|
|
|
override void OnSelect()
|
|
{
|
|
sel = master.shnd.menustate.At("LastGame").ToInt();
|
|
// auto-add lore for kris
|
|
let lore = SWWMLoreLibrary.Find(players[consoleplayer]);
|
|
bool found = false;
|
|
for ( int i=0; i<lore.ent.Size(); i++ )
|
|
{
|
|
if ( !(lore.ent[i].tag ~== "$SWWM_LORETAG_MADCAT") ) continue;
|
|
found = true;
|
|
break;
|
|
}
|
|
if ( !found )
|
|
{
|
|
EventHandler.SendNetworkEvent("swwmgamelore",consoleplayer);
|
|
// notify
|
|
master.tmsg = StringTable.Localize("$SWWM_NEWLORE");
|
|
master.tmsgtic = gametic+70;
|
|
}
|
|
}
|
|
override void OnDeselect()
|
|
{
|
|
master.shnd.menustate.Insert("LastGame",String.Format("%d",sel));
|
|
if ( game ) game.Destroy();
|
|
}
|
|
|
|
override void MenuInput( int key )
|
|
{
|
|
// while a game is running, only the back button can be used
|
|
if ( game )
|
|
{
|
|
if ( key == MK_BACK )
|
|
{
|
|
game.Destroy();
|
|
master.MenuSound("menu/democlose");
|
|
}
|
|
return;
|
|
}
|
|
switch ( key )
|
|
{
|
|
case MK_DOWN:
|
|
if ( sel > 0 )
|
|
{
|
|
sel--;
|
|
master.MenuSound("menu/demoscroll");
|
|
}
|
|
break;
|
|
case MK_UP:
|
|
if ( sel < gamelist.Size()-1 )
|
|
{
|
|
sel++;
|
|
master.MenuSound("menu/demoscroll");
|
|
}
|
|
break;
|
|
case MK_ENTER:
|
|
master.MenuSound("menu/demosel");
|
|
game = MadcatGame(new(gamelist[sel]));
|
|
game.Init();
|
|
break;
|
|
}
|
|
}
|
|
|
|
override void MouseInput( Vector2 pos, int btn )
|
|
{
|
|
if ( game ) return;
|
|
if ( btn != MB_LEFT ) return;
|
|
String str;
|
|
double xx, yy;
|
|
yy = int(master.ws.y-14*gamelist.Size())/2;
|
|
for ( int i=0; i<gamelist.Size(); i++, yy+=14 )
|
|
{
|
|
str = StringTable.Localize("$SWWM_GAMETITLE_"..gamelist[i].GetClassName());
|
|
int w = master.mSmallFont.StringWidth(str);
|
|
int h = master.mSmallFont.GetHeight();
|
|
xx = int(master.ws.y-w)/2;
|
|
if ( pos.x < xx ) continue;
|
|
if ( pos.x < xx+w ) continue;
|
|
if ( pos.y < yy ) continue;
|
|
if ( pos.y > yy+h ) continue;
|
|
sel = i;
|
|
MenuInput(MK_ENTER);
|
|
break;
|
|
}
|
|
}
|
|
|
|
override bool DirectInput( UIEvent ev )
|
|
{
|
|
if ( !game ) return false;
|
|
return game.ProcessInput(ev.keychar,ev.type==UIEvent.Type_KeyUp);
|
|
}
|
|
|
|
override void Ticker()
|
|
{
|
|
if ( game ) game.Tick();
|
|
}
|
|
|
|
override void Drawer()
|
|
{
|
|
if ( game )
|
|
{ // calculate res to fit
|
|
double scl = max(floor(((master.ws.y-120)*master.hs)/240.),1.);
|
|
Vector2 res = ((384,240)*scl)/master.hs;
|
|
String str = StringTable.Localize("$SWWM_GAMETITLE_"..game.GetClassName());
|
|
double xx = int(master.ws.x-master.mSmallFont.StringWidth(str))/2;
|
|
double yy = int(master.ws.y-res.y)/2;
|
|
Screen.DrawText(master.mSmallFont,Font.CR_FIRE,master.origin.x+xx,master.origin.y+yy-32,str,DTA_VirtualWidthF,master.ss.x,DTA_VirtualHeightF,master.ss.y,DTA_KeepRatio,true);
|
|
int cw = int(ceil((master.mSmallFont.StringWidth(str)+8)/6.))*6;
|
|
xx = int(master.ws.x-cw)/2;
|
|
for ( int i=0; i<cw; i+=6 )
|
|
Screen.DrawChar(master.mSmallFont,Font.CR_FIRE,master.origin.x+xx+i,master.origin.y+yy-26,0x5F,DTA_VirtualWidthF,master.ss.x,DTA_VirtualHeightF,master.ss.y,DTA_KeepRatio,true);
|
|
xx = int(master.ws.x-res.x)/2;
|
|
Screen.Dim("Black",1.,int((master.origin.x+xx-4)*master.hs),int((master.origin.y+yy-4)*master.hs),int((res.x+8)*master.hs),int((res.y+8)*master.hs));
|
|
master.DrawFrame(xx-4,yy-4,res.x+8,res.y+8);
|
|
game.Draw((master.origin.x+xx,master.origin.y+yy)*master.hs,scl);
|
|
}
|
|
else
|
|
{
|
|
// draw the game listing
|
|
String str = StringTable.Localize("$SWWM_PICKGAME");
|
|
double xx = int(master.ws.x-master.mSmallFont.StringWidth(str))/2;
|
|
double yy = int(master.ws.y-14*gamelist.Size())/2;
|
|
Screen.DrawText(master.mSmallFont,Font.CR_FIRE,master.origin.x+xx,master.origin.y+yy-32,str,DTA_VirtualWidthF,master.ss.x,DTA_VirtualHeightF,master.ss.y,DTA_KeepRatio,true);
|
|
int cw = int(ceil((master.mSmallFont.StringWidth(str)+8)/6.))*6;
|
|
xx = int(master.ws.x-cw)/2;
|
|
for ( int i=0; i<cw; i+=6 )
|
|
Screen.DrawChar(master.mSmallFont,Font.CR_FIRE,master.origin.x+xx+i,master.origin.y+yy-26,0x5F,DTA_VirtualWidthF,master.ss.x,DTA_VirtualHeightF,master.ss.y,DTA_KeepRatio,true);
|
|
for ( int i=0; i<gamelist.Size(); i++ )
|
|
{
|
|
str = StringTable.Localize("$SWWM_GAMETITLE_"..gamelist[i].GetClassName());
|
|
int w = master.mSmallFont.StringWidth(str);
|
|
xx = int(master.ws.x-w)/2;
|
|
Screen.DrawText(master.mSmallFont,(i==sel)?Font.CR_WHITE:Font.CR_DARKGRAY,master.origin.x+xx,master.origin.y+yy,str,DTA_VirtualWidthF,master.ss.x,DTA_VirtualHeightF,master.ss.y,DTA_KeepRatio,true);
|
|
if ( i == sel )
|
|
{
|
|
Screen.DrawChar(master.mSmallFont,Font.CR_GREEN,master.origin.x+xx-12,master.origin.y+yy,((gametic&8)>=4)?0x2727:0x2726,DTA_VirtualWidthF,master.ss.x,DTA_VirtualHeightF,master.ss.y,DTA_KeepRatio,true);
|
|
Screen.DrawChar(master.mSmallFont,Font.CR_GREEN,master.origin.x+xx+w+6,master.origin.y+yy,((gametic&8)>=4)?0x2727:0x2726,DTA_VirtualWidthF,master.ss.x,DTA_VirtualHeightF,master.ss.y,DTA_KeepRatio,true);
|
|
}
|
|
yy += 14;
|
|
}
|
|
}
|
|
}
|
|
}
|