import 'lobby.txt'
import 'core.txt'

#--------------------------------------------
Login [Scene Context]
{
	context 'PreConnect'
	window 'Login'

	leave on sfm.showReplay

	on sys.enter ExternalWebBrowserEnabled
	{
		context 'ExternalWebBrowser'
	}
	
	on gui.buttonWGFM ModalWindowWGFM [Modal]
	{
		window 'ModalWindowWGFM'
		leave on [gui.btn* key.ESCAPE.down]
	}

	on [gui.buttonClose key.ESCAPE.down] send sys.exitGame
	on gui.loginButtonSettings Options [Options]
    on cnxt.showCrosshairWindowPrebattle ModalWindowSelectCrosshair [ModalWindowSelectCrosshair]

	on gui.buttonConnect send sfm.doConnect
	on gui.buttonSteamConnect send sfm.doSteamConnect

	on [gui.buttonConnect action.confirmEULA gui.demoConnect gui.buttonSteamConnect action.beginAccountInitialization action.joinSteamWithWGAcc] Wait [WaitModal]
	{
		leave on [cnxt.createdAccount cnxt.playerInQueue cnxt.errorConnection sfm.disconnectedFromLogin cnxt.gotToken1 action.accountInitializationFinished]
	}

	on [cnxt.eulaDemoNotConfirmed] EULADemoNotConfirmed 
	{
		consume gui.demoConnect
		
		on [gui.demoConnect] EULAConfirmation [Modal]
		{
			window 'EULAConfirmation'
			on action.confirmEULA send sfm.demoConnect '+STATE_DATA'
			on [action.rejectEULA] send up.exitGame
			on [gui.btn_cancel key.ESCAPE.down] send up.exitEulaWindow
		}
		
		leave on [action.confirmEULA up.exitEulaWindow]
	}	
	
	on [cnxt.eulaNotConfirmed] EULANotConfirmed 
	{
		consume gui.buttonConnect
		
		on [gui.buttonConnect]	EULAConfirmation [Modal]
		{
			window 'EULAConfirmation'
			on action.confirmEULA send sfm.doConnect '+STATE_DATA'
			on [action.rejectEULA] send up.exitGame
			
			on [gui.btn_cancel key.ESCAPE.down] send up.exitEulaWindow
		}
		
		leave on [action.confirmEULA up.exitEulaWindow]
	}

	
	on cnxt.errorConnection send sfm.clearLoginWaitingState
	
	
	on cnxt.createdAdmin 	Admin [Scene Context]
	{
		window 'Admin'
		leave on gui.buttonExit
	}
		
	on cnxt.createdLogin 	LoginQueue
	{ 
		context 'LoginQueue'
		
		on cnxt.playerInQueue	PlayerInQueue [Modal]
		{
			window 'LoginQueue'
			
			leave on [gui.btn_ok key.ESCAPE.down]
			on [gui.btn_ok key.ESCAPE.down] send action.leaveQueue
			on [gui.btn_ok key.ESCAPE.down] send sfm.clearLoginWaitingState
		}
		
		on ex.disconnected send sfm.disconnectedFromLogin
		on sfm.disconnectedFromLogin send action.showErrorOnDisconnect
		on sfm.disconnectedFromLogin send sfm.clearLoginWaitingState
		
		leave on [cnxt.createdAccount sfm.disconnectedFromLogin]
	}
	
	on [gui.buttonLegal]	LegalInfo [Modal]
	{
		window 'LegalInfo'
		leave on [gui.btn_cancel key.ESCAPE.down]
	}
	
	on [cnxt.createdAccount] PreBattle [PreBattle]
	{
		on [ex.disconnected up.disconnect] send sfm.clearLoginWaitingState
		leave on [ex.disconnected up.disconnect]
	}

	on cnxt.createdMasterChanger MasterChanger
	{
		context 'MasterChanger'

		on cnxt.loginShown LoginMasterChanger [Modal]
		{
			window 'MasterChanger'

			on [gui.btn_cancel key.ESCAPE.down] send up.disconnect
		}
		leave on [ex.disconnected cnxt.createdAccount up.disconnect]
	}
	
}
