
require "scripts/style"
require "scripts/widgets/inventorybar"
require "scripts/widgets/topbar"
require "scripts/characters/maggie"

LevelExitParams = {
  dominigame=false,
  minigame="jackpot",
  domovie=false,
  movieswf="",
  moviepic="",
};


-- The "Twodemos" game handles its messages in Lua, unlike the "TGame" game
-- which handles them in C++.
function SendGameMessage( msg )
 
	if msg=="returntoplan" then	    
    SendGameMsg("set-endgame","plan");        
	end
	if msg=="lostlife" then
    ResetCursor();
    DoModal('scripts/levelend.lua');
    SwapToModal("scripts/planmetamenu.lua");
		SetState( kGameMode, "planmenu" );    
	end
	if msg=="manualquit-plan" then
    ResetCursor();
    DoModal('scripts/levelend.lua');
    SwapToModal("scripts/planmetamenu.lua");
		SetState( kGameMode, "planmenu" );    
	end
	if msg=="manualquit" then
    ResetCursor();
    DoModal('scripts/levelend.lua');
    QuitToMainMenu();
	end
	if msg=="gameover" then
    ResetCursor();
    DoModal('scripts/levelend.lua');    
    SwapToModal("scripts/mapmenu.lua");
		SetState( kGameMode, "planmenu" );    
	end
	if msg=="endlevel" then		
    ResetCursor();
    ProcessLevelExit();
--		SwapToModal("scripts/planmetamenu.lua");
--		SetState( kGameMode, "planmenu" );
	end
	if msg=="quit" then
    SendGameMsg("set-endgame","quit");    
		QuitToMainMenu();
	end
	
	if msg=="levelwon" then
    ResetCursor();    
    DoModal('scripts/levelend.lua');
		SwapToModal("scripts/planmetamenu.lua");
		SetState( kGameMode, "planmenu" );
	end
	
end

SetState( kGameMode, "ingame" );

MakeDialog
{  
-- gamescreen is the collection of grid, sprites, timer, whatever
    Gamescreen 
    {
      w=800,h=600,x=0,y=0,
      
      Gameboard{
        name="gameboard",
        w=300, h=300, x=50, y=50,
        fallspeed=150, swapspeed=200,
        entrytime = 1000,
      },
      Text
			{
				font = StandardButtonFont,
				name = "timertext",
				x=20,y=20,w=100,h=60,
				flags = kHAlignCenter + kVAlignCenter,
			},			
      
      -- upgrade effects coverup
      UpgradeEffects
      {
        name="upgradeeffects",
        x=0, y=0,
        w=kMax, h=kMax,
        shade="upgrades/effects/shade", -- must be 80x60
      },
      
      Bitmap
      {
        name='pedestal',
        x=20, y=320,
        image='levels/pedestal'
      },
      MakeMaggie(95,350),
      
      
      Group {
--the side-bars which connect the inventory to the top bar
      Bitmap {
        image="widgets/misc/uiframe_left.png",
        x=0, y=24, h=489, w=8,
      },
      Bitmap {
        image="widgets/misc/uiframe_right.png",
        x=792, y=16, h=489, w=8,
      },
      MakeInventoryBar(),            
      MakeTopBar(),       

      },
--      MakeWidgetLives(0,30),
--      MakeWidgetTimer(110,30),
--      MakeWidgetScore(620, 80),

		},			
}

