// a game inside a game? Class DemolitionistGameTab : DemolitionistMenuTab { MadcatGame game; Array > gamelist; int sel; override DemolitionistMenuTab Init( DemolitionistMenu master ) { title = StringTable.Localize("$SWWM_GAMETAB"); foreach ( cls:AllClasses ) { if ( cls.isAbstract() || !(cls is 'MadcatGame') ) continue; gamelist.Push((Class)(cls)); } 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; foreach ( ent:lore.ent ) { if ( !(ent.tag ~== "$SWWM_LORETAG_MADCAT") ) continue; found = true; break; } if ( !found ) { EventHandler.SendNetworkEvent("swwmgamelore",consoleplayer); // notify master.tmsg = StringTable.Localize("$SWWM_NEWLORE"); master.tmsgtic = Menu.MenuTime()+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 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( double fractic ) { 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=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,((Menu.MenuTime()&8)>=4)?0x2727:0x2726,DTA_VirtualWidthF,master.ss.x,DTA_VirtualHeightF,master.ss.y,DTA_KeepRatio,true); } yy += 14; } } } }