import 'core.txt'
import 'menu.txt'
import 'battle.txt'

LoadingBattle
{
	context 'LoadingBattle'
	leave on [sfm.goToDock cnxt.enterBalancer cnxt.failEnqueue]
	
	on cnxt.createdReallyAccount # reconnect when enterArena was called 
		send sfm.goToDock
	
	on sys.enter Wait [Wait]
	{
		leave on cnxt.bgLoaded
	}
	
	on cnxt.bgLoaded LoadingBattleWindow [Scene]
	{
		window 'LoadingBattle'
		leave on cnxt.showBattle
	}

	on sys.enter send sfm.battleLoadingStarted
	on sys.enter send cnxt.closeBrowser
	
	on sys.enter DynamicDivisions
	{
		context 'DynamicDivisions'
	}
}

LoadingOnlineBattle [LoadingBattle]
{
	on sys.enter BattleData
	{
		context 'BattleData'

		leave on cnxt.avatarLeavesWorld
	}

	on cnxt.enterBattle Battle [Battle]
}

#--------------------------------------------
PreBattle [Context]
{
	context 'PreBattle'
	
	consume sfm.showReplay
	
	on sys.enter WebBrowserEnabled
	{
		context 'WebBrowser'
	}
	
	on sys.enter SystemMessages
	{
		context 'SystemMessages'
	}

	on sys.enter Informer
	{
		context 'Informer'
		consume action.hideInformer
		consume action.showInformer
	}

	on sys.enter RankedBattles
	{
		context 'RankedBattles'
	}

	on sys.enter Waiting [WaitModal]
	{
		leave on [cnxt.createdReallyAccount cnxt.playerBecameAvatar cnxt.leaveBattleSession cnxt.SelectNation]
	}
	
	on sys.enter AccountLevelState
	{
		context 'AccountLeveling'
	}

	on sys.enter DivisionEntrance ### We should start listen for Account.enterDivision
	{
		context 'DivisionEntrance'
		on cnxt.enterDivision Division
		{
			leave on cnxt.leaveDivision
			context 'Division'
			on sys.enter send action.onEnterDivision
		}
	}
	
	on sys.enter PrimeTime
	{
		context 'PrimeTime'
	}
	
	on sys.enter VoiceChatEnabled
	{
		context 'VoiceChat'
	}
	
	on [cnxt.createdReallyAccount sfm.goToDock cnxt.leaveBattleSession] Lobby [Scene] # 1 usual from login 2 usual from battle 3 reconnect without entering arena
	{	

		context 'Dock'
		
		on gui.buttonWGFM ModalWindowWGFM [Modal]
		{
			window 'ModalWindowWGFM'
			leave on [gui.btn* key.ESCAPE.down]
		}

		on sys.enter XMPP
		{
			context 'XMPP'
		}
		
		on cnxt.startVehicleLoading WaitLoading [Wait]
		{
			leave on [cnxt.finishVehicleLoading cnxt.playerBecameAvatar]
		}
		
		on cnxt.startDockReloading WaitReload
		{
			window 'WaitingScreenDockReload'
			leave on [cnxt.finishVehicleLoading cnxt.playerBecameAvatar]
		}

		on action.openClansWindow ClansInset [WebBrowserNonModal]
		{
			data '{ "browserTextureName" : "BrowserRender1", "paddingTop": 60, "hideHeader": true }'
			leave on action.closeClansWindow
		}

		on sys.enter DockWindow
		{
			window 'Dock'
			inputHandler 'DockInputHandler'

			on gui.buttonQuestEnter send action.hideCarousel
			on sys.enter send dockState.dock
			on cnxt.leaveBalancer* send dockState.dock
			on action.LootboxProxy.moveFromBarge send dockState.dock
			on sfm.goToDock send dockState.dock
			
			on input.shipOverviewIn ShipOverview
			{
				inputHandler 'ShipOverviewInputHandler'
				leave on input.shipOverviewOut
			}
		}

		# Battle type and operation select windows - must be below all other modal windows
		on sys.enter ModalWindowBattleTypeChooser
		{
			window 'ModalWindowBattleTypeChooser'

			on request.modalSelectBattleType Visible
			{
				leave on	[key.ESCAPE.down gui.btn_cancel request.closeModalSelectBattleType request.modalSelectPVEOperation]
				consume		[key.ESCAPE.down gui.btn_cancel request.closeModalSelectBattleType]
				on [gui.btn_cancel key.ESCAPE.down request.closeModalSelectBattleType request.modalSelectPVEOperation] send action.hideBattleTypeChooser
			}
		}
		on sys.enter ModalWindowPVEOperationChooser
		{
			window 'ModalWindowPVEOperationChooser'

			on request.modalSelectPVEOperation Visible
			{
				leave on	[key.ESCAPE.down gui.btn_cancel request.closeModalPVEOperationChooser request.returnToBattleTypeChooserFromOperationChooser]
				consume		[key.ESCAPE.down gui.btn_cancel request.closeModalPVEOperationChooser request.returnToBattleTypeChooserFromOperationChooser]
				on [key.ESCAPE.down gui.btn_cancel request.returnToBattleTypeChooserFromOperationChooser] send request.modalSelectBattleType
				on [key.ESCAPE.down gui.btn_cancel request.returnToBattleTypeChooserFromOperationChooser request.closeModalPVEOperationChooser] send action.hideSelectPVEOperation
			}
		}

		on input.enterFreeCameraDev FreeCameraDock [FreeCamera]

		on sfm.showReplay ReplayPlaying [Scene]
		{
			window 'ReplayWindow'
			leave on sfm.hideReplay
		}

		
		on action.openChooseCampaignsWindow ChooseCampaignsWindow [Modal]
		{
			window 'ModalWindowCampaigns'
			on action.campaignState.campaigns CampaignState
			{
				leave on [action.campaignState.tasks action.campaignState.missions]
			}
			on action.campaignState.missions MissionState
			{
				#consume key.ESCAPE.down
				#on key.ESCAPE.down send action.campaignState.campaigns
				leave on [action.campaignState.tasks action.campaignState.campaigns]
			}
			on action.campaignState.tasks TaskState
			{
				#consume key.ESCAPE.down
				#on key.ESCAPE.down send action.campaignState.missions
				leave on [action.campaignState.missions action.campaignState.campaigns]
			}
			on [gui.btn_cancel key.ESCAPE.down] send action.campaignState.campaigns
			leave on [gui.btn_cancel key.ESCAPE.down cnxt.enterBalancer]
		}
		
		on cnxt.showCampaignDone ModalWindowCampaignDone [ModalWindowCampaignDone]

		on cnxt.enterBalancer RandomBattle [RandomBattle]
		{
			on sys.enter send dockState.balancer
		}

		on action.moveToBarge Barge [SubWindow]
		{
			on sys.enter send dockState.barge
			on sys.enter send action.LootboxProxy.moveToBarge
			on action.moveFromBarge send action.closeSubWindow
			on action.closeSubWindow send action.LootboxProxy.moveFromBarge

			on action.openPurchaseLootboxWindow PurchaseLootboxWindow [Modal]
			{
				window 'ModalWindowPurchaseLootbox'
				on request.openPurchaseLootboxWindowChance send action.openPurchaseLootboxWindowChance
				on request.LootboxProxy.buyLootbox send action.LootboxProxy.buyLootbox
				leave on [request.* gui.btn_cancel key.ESCAPE.down]
			}

			on action.openPurchaseLootboxWindowChance PurchaseLootboxWindowChance [Modal]
			{
				window 'ModalWindowPurchaseLootboxChance' 
				leave on [request.closeModalWindowChance]
			}

			on action.lockBargeControls BargeLockedState
			{
				consume [key.ESCAPE.down gui.btn_cancel gui.buttonClose action.closeSubWindow]
			    leave on action.unlockBargeControls
			}

			# [WWSD-80379] fix
			leave on cnxt.enterBalancer
		}

		on sys.enter ChatNotificationsPanelWindow
		{
			window 'ChatNotificationsPanel'
		}

		on request.modalPVEOperationInfo ModalWindowPVEOperationInfo [Modal]
		{
			window 'ModalWindowPVEOperationInfo'
			leave on [gui.btn_cancel key.ESCAPE.down request.closeModalPVEOperationInfo]
		}
		#PVE BATTLE

		##################### MODAL WINDOWS #######################

		on gui.buttonQuestEnter WindowQuest [CloseOnNavigation]
		{
			window 'QuestWindow'
			consume [gui.buttonQuestEnter key.ESCAPE.down]
			on [gui.btn_cancel key.ESCAPE.down gui.startRandom] send action.showCarousel
			leave on [gui.btn_cancel key.ESCAPE.down gui.startRandom]
			on gui.showExtendedQuest ExtendedWindowQuest [CloseOnNavigation]
			{
				window 'QuestWindowExtended'
				consume [gui.btn_cancel key.ESCAPE.down]
				leave on [gui.btn_cancel key.ESCAPE.down]
			}
		}

		on cnxt.postBattleSurveyDock PostBattleSurveyWindow [MessageBox]
		{
			window 'PostBattleSurveyWindow'
			leave on action.exit
		}

		on request.showExtendedSystemLog ExtendedSystemLogWindow [MessageBox]
		{
			window 'ExtendedSystemLogWindow'
			leave on [gui.btn_cancel key.ESCAPE.down]
		}

		on request.showUnavailableExtendedSystemLog UnavailableExtendedSystemLogWindow [MessageBox]
		{
			window 'UnavailableExtendedSystemLogWindow'
			leave on [gui.btn_cancel key.ESCAPE.down]
		}

		on request.pveBattlesShowStats ModalWindowPVEResults [MessageBox]
		{
			window 'ModalWindowPVEResults'
		}

		on gui.buttonResearchShip ModalWindowResearchShip [ModalWindowSpendResources]
		{
			window 'ModalWindowResearchShip'
			on request.doResearchShip send action.doResearchShip
		}

		on gui.buttonPurchaseShip ModalWindowPurchaseShip [WindowWithPricesAttention]
		{
			window 'ModalWindowPurchaseShip'
			on request.buyShip send action.buyShip
		}

		on gui.buttonResearchUserComponent ModalWindowResearchModule [ModalWindowSpendResources]
		{
			window 'ModalWindowResearchModule'
			on request.doResearchModule send action.doResearchModule
		}

		on gui.buttonPurchaseUserComponent ModalWindowPurchaseModule [ModalWindowSpendResources]
		{
			window 'ModalWindowPurchaseModule'
			on request.doBuyModule send action.doBuyModule
		}

		on gui.buttonPurchaseAndInstallUserComponent  ModalWindowPurchaseAndInstallModule [ModalWindowSpendResources]
		{
			window 'ModalWindowPurchaseAndInstallModule'
				on request.doBuyAndInstallModule send action.doBuyAndInstallModule
		}

		#on [gui.buttonPurchase* gui.buttonResearch*] ModalWindowSpendResources [ModalWindowSpendResources]

		on action.xpFreeExpWindow ModalWindowConvertExp [ModalWindowSpendResources]
		{
			window 'ModalWindowConvertExp'
			on request.convertEliteXP send action.DockProxy.exchangeEliteXP
			on request.convertShipXP send request.changeExpToFreeexp
			leave on [gui.btn* key.ESCAPE.down]
		}
		
		### Level/Rank/Season up
		on cnxt.showLevelUp ModalWindowAccountLelelUp [ModalWindowAccountLelelUp]

		# could be dispatched from PostBattleWindow
		# ToDo: use event filtering [WWSD-53180]
		on wait.rankedBattlesShowStats ModalWindowRankChanged [ModalWindowRankChanged]
		{
			data '{ "showToRanksButton" : true }'
		}

		on wait.showSeasonResults ModalWindowSeasonResults [ModalWindowRank]
		{
			window 'ModalWindowSeasonResults'
		}

		### Ship became elite dialog:
		on dock.shipBecameElite ModalWindowShipIsElite [MessageBox]
		{
			on [gui.btn_* key.ESCAPE.down] send ModalWindowShipIsElite.accepted
			window 'ModalWindowShipIsElite'
		}
		
		on gui.buttonBuySlots ModalWindowBuySlots [WindowWithPricesAttention]
		{
			window 'ModalWindowBuySlots'
			on request.buySlot send action.buySlot
		}

		on dock.sellShip ModalWindowSellShip [WindowWithPricesAttention]
		{ 
			window 'ModalWindowSellShip'
			on request.sellShip send action.sellShip
		}
		
		on gui.buttonShowPremium ModalWindowPremiumAccounts [MessageBox]
		{
			window 'ModalWindowPremiumAccount'
			on gui.btn_ok send action.buyPremiumAccount
		}
		
		on [action.creditsGoldWindow gui.buttonExchangeGold] ModalWindowConvertGold [WindowWithPricesAttention]
		{
			window 'ModalWindowConvertGold'
			data '{ "type" : "gold" }'
			on request.convertGold send action.convertGold
		}
		
		on request.crewFile CrewFile [MessageBox] 
		{
			window 'CrewFile'
			on [gui.btn_cancel key.ESCAPE.down sfm.crewFired] send action.crewFileClose
			leave on [gui.btn_cancel key.ESCAPE.down sfm.crewFired]
		}
		
		on request.hireCrew HireCrew [ModalWindowWithPricesAttention]
		{ 
			window 'ModalWindowHireCrew'
		}
		
		on request.retrainCrew RetrainCrew [ModalWindowWithPricesAttention]
		{ 
			window 'ModalWindowRetrainCrew'
		}

		on request.crewFastTraining CrewFastTraining [ModalWindowWithPricesAttention]
		{
			window 'ModalWindowCrewFastTraining'
			on request.trainFast send action.DockProxy.changeCrewLevel
		}

		on request.crewPenaltyCompensation CrewPenaltyCompensation [ModalWindowWithPricesAttention]
		{
			window 'ModalWindowCrewPenaltyCompensation'
		}
		
		on request.assignCrewToShip AssignCrewYesNo [MessageBox]
		{
			window 'ModalWindowAssignCrew'
			on gui.btn_ok resend action.*
		}

		on request.fireCrew FireCrewYesNo [MessageBox]
		{
			window 'ModalWindowFireCrew'
			on gui.btn_ok resend action.*
		}
		
		on request.learnSkill LearnSkill [MessageBox]
		{
			window 'ModalWindowLearnSkill'
			on gui.btn_ok resend action.*
		}
		
		on request.freeSkillPointsWindow FreeSkillPointsYesNo [ModalWindowWithPricesAttention]
		{ 
			window 'ModalWindowFreeSkillPoints'
			on request.freeSkillPoints send action.freeSkillPoints
		}
		
		on request.increaseBarracksCapacity IncreaseBarracksCapacityYesNo [ModalWindowWithPricesAttention]
		{ 
			window 'ModalWindowExpandBarracks'
			on gui.btn_ok resend action.*
		}
		
		on request.disassignCrew DisassignCrewYesNo [UnboundDialogYesNo]
		{ 
			data '{ "subtitle" : "IDS_QUESTION_CONFIRM_DISASSIGN_CREW", "type" : 0, "title" : "IDS_CONFIRM_DISASSIGN_CREW_HEADER", "instruction" : "IDS_INSTRUCTION_DISASSIGN_CREW" }'
			on gui.btn_ok resend action.*
		}
		
		on dock.showModernizationWindow ModalWindowModernizations [WindowWithPricesAttention]
		{
			window 'ModalWindowModernizations'
			on request.setModernizations send action.setModernizations
		}
		
		on request.leaveDivision leaveDivisionYesNo [UnboundDialogYesNo]
		{
			data '{"type" : 0}'
			on gui.btn_ok resend action.*
		}
		on request.dismissDivision dismissDivisionYesNo [UnboundDialogYesNo]
		{ 
			data '{"type" : 0 }'
			on gui.btn_ok resend action.*
		}
		on request.kickPlayerFromDivision kickPlayerFromDivisionYesNo [UnboundDialogYesNo]
		{ 
			data '{"type" : 2 }'
			on gui.btn_ok resend action.*
		}
		
		on request.buyAndInstallExteriorModal BuyExterior [WindowWithPricesAttention]
		{ 
			window 'ModalWindowBuyExterior'
			on request.buyAndInstallExterior send action.buyAndInstallExterior
		}

		on request.uninstallExterior UninstallExterior [MessageBox]
		{ 
			window 'ModalWindowUninstallExterior'
			on gui.btn_ok resend action.*
		}
		
		on action.createClubWindow CreateClub [Modal CloseOnNavigation]
		{ 
			window 'ModalWindowCreateClub'
			leave on [gui.btn_cancel key.ESCAPE.down action.closeClubWindow]
		}

		on request.openUnfreezeShipWindow UnfreezeShipWindow [Modal]
		{ 
			window 'ModalWindowUnfreezeShip'
			leave on [gui.btn_cancel key.ESCAPE.down action.DockProxy.cancelShipFreezeCooldown]
			on request.cancelShipFreezeCooldown send action.DockProxy.cancelShipFreezeCooldown
		}

		on action.renameClubWindow RenameClub [Modal CloseOnNavigation]
		{ 
			window 'ModalWindowRenameClub'
			leave on [gui.btn_cancel key.ESCAPE.down action.closeClubWindow]
		}

		on action.leaveClubWindow LeaveClub [Modal CloseOnNavigation]
		{ 
			window 'ModalWindowLeaveClub'
			leave on [gui.btn_cancel key.ESCAPE.down cnxt.leaveClub]
		}

		on action.changeClubLeaderWindow ChangeLeaderClub [Modal CloseOnNavigation]
		{ 
			window 'ModalWindowChangeClubLeader'
			leave on [gui.btn_cancel key.ESCAPE.down cnxt.changeClubLeader]
		}

		on [action.showIntro preConnect.showTutorial] ClubIntro [Modal]
		{ 
			window 'ModalWindowTutorial'
			leave on [action.finishIntro preConnect.hideTutorial]
		}
		
		on dock.showConsumeBuyWindow ModalWindowBuyConsume [WindowWithPricesAttention]
		{
			window 'ModalWindowBuyConsume'
			on request.buyConsumables send action.buyConsumables
			leave on [request.* gui.btn_cancel key.ESCAPE.down action.closeConsumeWindow]
		}


		on gui.buttonSelectPort ModalWindowSelectPort [MessageBox]
		{
			window 'ModalWindowSelectPort'
			
			on gui.buttonShowPremium ModalWindowPremiumAccounts [MessageBox]
			{
				window 'ModalWindowPremiumAccount'
				on gui.btn_ok send action.buyPremiumAccount
			}
		}

		on cnxt.showVoteWindow ModalWindowVote [MessageBox]
		{
			window 'ModalWindowVote'
		}

		on action.kickClubLeaderWindow KickClubLeaderWindow [MessageBox]
		{
			window 'ModalWindowKickClubLeader'
		}

		on request.buyObjectWindow BuyCollectionObjectWindow [Modal]
		{
			window 'ModalWindowBuyCollectionObject'
			leave on [gui.btn_cancel key.ESCAPE.down request.showPreviewWindow]
		}

		on request.showPreviewWindow ViewObjectWindow [Modal]
		{
			window 'ModalWindowViewCollectionObject'
			leave on [gui.btn_cancel key.ESCAPE.down]
		}

		on request.openModalCongratulationWindow ModalCongratulationWindow [Modal]
		{
			window 'ModalWindowCollectionFullyCollected'
			leave on [gui.btn_cancel key.ESCAPE.down]
		}

		on cnxt.rankBattlesStatsChanged ModalWindowRankChanged [ModalWindowRankChanged]
		{
			data '{ "showToRanksButton" : true }'
		}

		on dock.clubRateChanged ModalWindowClubRateChanged [MessageBox]
		{
			data '{ "showToClubsButton" : true }'
			window 'ModalWindowClubRate'
			on gui.btn_profile send ModalWindowClubRateChanged.showProfile
		}
		
		on cnxt.showNotReadyPlayers NotReadyPlayers [Modal]
		{
			window 'ModalWindowDivisionNotReady'
			on [gui.btn_cancel key.ESCAPE.down] send request.processCancelNotReady
			leave on [cnxt.hideNotReadyPlayers gui.startRandom]
			on cnxt.showNotFullBattleWindow NotFullBattleWindow
			{
				consume [gui.btn_cancel key.ESCAPE.down]
			}
		}
		
		on gui.btn_guide send up.showGuide
		on gui.btn_exit_game ConfirmExitGameModalWindow [ConfirmExitGameModalWindow]


		on cnxt.rankBattlesStatsChanged ModalWindowRankChanged [ModalWindowRankChanged]
		{
			data '{ "showToRanksButton" : true }'
		}



		on gui.startIntroMission SelectNation [Scene]
		{	
			window 'ModalWindowSelectNation'
			data '{ "cancellable" : true }'
			
			on action.startIntroMission Wait [WaitModal]
			{
				on cnxt.leaveBattleSession send up.inromissionQueue
				leave on cnxt.leaveBattleSession
			}
			
			on  up.inromissionQueue InromissionQueue [MessageBox]
			{
				window 'ModalWindowIntromissionQueue'
				
				on [gui.btn_cancel key.ESCAPE.down] send up.leaveIntromission
			}
			
			consume [up.inromissionQueue up.leaveIntromission]
			leave on [cnxt.bgLoaded gui.btn_cancel key.ESCAPE.down up.leaveIntromission]
		}	

		
			on request.CampaignsProxy.deactivateTask taskDeactivationYesNo [UnboundDialogYesNo]
			{
				data '{"type" : 0, "subtitle": "IDS_TASK_CANCEL_EXECUTION_QUESTION"}'
				on gui.btn_ok resend action.*
			}



		##################### MODAL WINDOWS #######################
		
		on [gui.buttonMenu key.ESCAPE.down up.openMenu] LobbyMenu [LobbyMenu]
		on up.openOptions Options [Options]

		on gui.btn_portal Portal [WebBrowser]
		{
			data '{ "browserTextureName" : "BrowserRender", "url": "portalInGame" }'
		}

		on cnxt.showBrowserOnLogin OnLoginBrowser [WebBrowser]
		{
			data '{ "browserTextureName" : "BrowserRender", "url": "newsInGame" }'
		}

		on up.showGuide GuideWindow [WebBrowser]
		{
			data '{ "browserTextureName" : "BrowserRender", "url": "guidesInGame" }'
		}

		on [cnxt.gotoClanInvites cnxt.gotoPRNPUrl request.webBrowser] WebBrowser [WebBrowser]
		{
			data '{ "browserTextureName" : "BrowserRender"}'
		}

		on cnxt.showCrosshairWindowPrebattle ModalWindowSelectCrosshair [ModalWindowSelectCrosshair]


		on up.showDisconnect ConfirmDisconnectModalWindow [ConfirmDisconnectModalWindow]
		
		on [sfm.hideReplay sfm.activateDock3D] Dock3D
		{
			leave on [cnxt.playerBecameAvatar sfm.showReplay]
			context 'Dock3D'
		}
		
		on gui.startRandom send action.setDockGoToBattle
		on gui.startRandom Wait [WaitModal]
		{ 
			leave on [cnxt.enterBalancer cnxt.failEnqueue]
		}

		on cnxt.openTrainingRooms ListRooms [ListRooms]

		on action.forceCreateAccount ForceCreateAccount [Modal CloseOnNavigation]
		{ 
			window 'ModalWindowForceCreateAccount'
			on action.serverDisconnect send up.disconnect
			leave on [gui.btn_cancel key.ESCAPE.down]
		}
	}
	
	on cnxt.active3dDock Dock3DActive
	{
		on sys.enter send sfm.activateDock3D
		on sfm.goToDock send sfm.activateDock3D
		on cnxt.leaveBalancer send sfm.activateDock3D
	}

	on sys.enter TrainingRooms
	{
		context 'TrainingRooms'
		
		on [cnxt.enterRoomAsHost cnxt.enterRoomAsGuest] CreatedRoom [CreatedRoom]
	}
	
	on  cnxt.enterArena LoadingBattle [LoadingOnlineBattle]

	on up.showHelp HelpModal [HelpWindow]
	{
		data '{ "showCloseButton" : true }'
		leave on [gui.closeHelpBtn input.hideHelp key.ESCAPE.up]
	}

	#on cnxt.battleResults BattleResults [Modal]
	#{
	#	window 'ResultsScreen'
	#	
	#	leave on [gui.buttonClose key.ESCAPE.down]
	#}
	
	on [sys.enter cnxt.leaveBalancer sfm.goToDock ] Autokick
	{
		context 'Autokick'
		
		leave on [cnxt.enterArena cnxt.enterBalancer]
	}

	on cnxt.showTransactionLockScreen TransactionGUILock [Modal]
	{
		window 'WaitingScreenTransaction'
		leave on cnxt.hideTransactionLockScreen
	}
	
	on cnxt.selectNation SelectNation [Modal]
	{	
		window 'ModalWindowSelectNation'
		data '{ "cancellable" : false }'
		
		on action.startIntroMission Wait [WaitModal]
		{
			leave on cnxt.leaveBattleSession
			on cnxt.leaveBattleSession send up.inromissionQueue
		}
		on  up.inromissionQueue InromissionQueue [MessageBox]
		{
			window 'ModalWindowIntromissionQueue'
			
			on [gui.btn_cancel key.ESCAPE.down] send up.leaveIntromission
		}
		leave on [cnxt.bgLoaded up.leaveIntromission]
	}
	
	on input.draggingFlashIn DraggingFlash
	{
		inputHandler 'FlashDraggingInputHandler'
		leave on input.draggingFlashOut
	}

	on cnxt.notifyBalancerLeave LeaveBalancerNotification [UnboundDialogYesNo]

	on cnxt.showNotification Notification [UnboundDialogYesNo]
}

#--------------------------------------------
RandomBattle [Scene]
{
	window 'RandomBattle'

	#hack. need state tree refactoring
	on sys.enter send action.clearInset

	on [sys.enter cnxt.enterBalancer] Balancer
	{
		leave on [cnxt.leaveBalancer* sfm.goToDock]
		context 'Balancer'
	}
	
	on cnxt.enterRandomBattleAsDivisionMember CantEscape [Modal]
	{
		# don't allow user input while waiting for battle in Division
	}

	consume cnxt.leaveBattleSession
	
	leave on [cnxt.leaveBalancer cnxt.bgLoaded sfm.goToDock]
	
	on cnxt.leaveBattleSession send cnxt.showNotification '{ "title": "IDS_BATTLE_SESSION_LEAVE_REASON_ARENA_FAILED", "type": 1 }'
	on cnxt.leaveBattleSession send sfm.goToDock

	on [gui.buttonLeave gui.buttonClose key.ESCAPE.down] send action.exit

	on [action.exit cnxt.prepareForBattle] Wait [WaitModal]
	{
		leave on cnxt.leaveBattleSession
	}
}

#--------------------------------------------
ListRooms [Scene]
{
	window 'ListRooms'

	#hack. need state tree refactoring
	on sys.enter send action.clearInset

	leave on [key.ESCAPE.down gui.closeBtn cnxt.enterBattle up.roomCreationFailedByLimit sfm.goToDock]
	on gui.roomSelected Wait [WaitModal]
	{	
		leave on [cnxt.enterRoom*]
	}
	on gui.btn_create_room CreateRoom [Scene]
	{
		context 'RoomHost'
		window 'CreateRoom'
		leave on [cnxt.enterRoom* gui.closeBtn key.ESCAPE.down]
		
		on cnxt.roomCreationFailedByLimit RoomCreationFailedByLimitAlert [RoomCreationFailedByLimitAlert]
		
		on cnxt.selectedMapDeleted DialogOk [DialogOk]
		{	
			data '{ "title" : "IDS_MAP_DELETED" }'
			
			consume cnxt.selectedMapDeleted
		}
	}
}

#--------------------------------------------
CreatedRoom
{
	context 'Room'
	
	on sys.enter resend
	leave on [cnxt.leftRoom cnxt.enterBattle]
	
	on sys.enter Switch
	{
		switch
		on [cnxt.enterRoomAsHost cnxt.becomeHost] HostCreatedRoom [Scene]
		{
			context 'RoomHost'
			window 'CreateRoom'
			
			on cnxt.teamsIncomplite DialogYesNo [DialogYesNo]
			{	
				data '{ "title" : "IDS_QUESTION_UNEQUAL_TEAMS" }'
				
				on gui.btn_ok send up.startBattleYes
			}
			
			on cnxt.selectedMapDeleted DialogOk [DialogOk]
			{	
				data '{ "title" : "IDS_MAP_DELETED" }'
				
				consume cnxt.selectedMapDeleted
			}
		}
		
		on [cnxt.enterRoomAsGuest cnxt.becomeGuest] GuestCreatedRoom [Scene]
		{
			window 'CreateRoom'
			on [cnxt.battleDefUpdated cnxt.descriptionUpdated] DialogOk [DialogOk]
			{
				data '{ "title" : "IDS_ROOM_CHANGED" }'
				
				consume cnxt.roomInfoChanged
			}
		}
	}
	on [gui.closeBtn key.ESCAPE.down cnxt.prepareForBattle] Wait [WaitModal]
}
