
-- Предыстория

local numOfHistoryPages = 1
local numOfCompletePages = 1

function HistoryEndHandler()
	gameInfo:setMenuParam1(0)
	GUI:getLayer("Menu"):getWidget("1_MenuEffect"):AcceptMessage(Message("GemEffect"))
end

function UploadCompleteScreen()
	UploadResource("fish0")
	UploadResource("fish1")
	UploadResource("fish2")
	UploadResource("fish3")
	UploadResource("fish4")
	UploadResourceGroup("History")
end

function ReleaseCompleteScreen()
	ReleaseResource("fish0")
	ReleaseResource("fish1")
	ReleaseResource("fish2")
	ReleaseResource("fish3")
	ReleaseResource("fish4")
	ReleaseResourceGroup("History")
end

function CompleteScreenReset()
	local textWidget = GUI:getLayer("CompleteScreen"):getWidget("CompleteScreen")
	currentCompletePage = 0
	textWidget:AcceptMessage(Message("SetPage", currentCompletePage))
	textWidget:AcceptMessage(Message("Show", 1))
end

function CompleteEndHandler()
	GUI:getLayer("Map"):getWidget("Map"):AcceptMessage(Message("RiseOfAtlantis"))
	--GUI:getLayer("Map"):getWidget("Map"):AcceptMessage(Message("DestroyCountryProgress"))

end

function HistoryFunc(message)

	if message:is("Next", "press") then

		historyWidget = GUI:getLayer("History"):getWidget("History")
		currentHistoryPage = currentHistoryPage+1

		--if currentHistoryPage == numOfHistoryPages then
                --	historyButton = GUI:getLayer("History"):getWidget("Next")
                --	historyButton:AcceptMessage(Message("SetText", "Start"))
		--end

		if currentHistoryPage > numOfHistoryPages then
			currentHistoryPage = 0
			historyWidget:AcceptMessage(Message("Show", 0))
			--StartGame()

			param = VariableSet()
			param:setString("Layer1", "Menu");
			param:setString("EndHandler", "HistoryEndHandler");
			kernel:addController(controlFactory:Create("CrossFade", param))

			SetHiscoreActive(1)
		end

		historyWidget:AcceptMessage(Message("SetPage", currentHistoryPage))

	end

end

-- Экран поздравлений с окончанием

function CompleteGameFunc(message)

	local historyWidget = GUI:getLayer("History"):getWidget("History")

	if message:is("Next", "press") then

		local textWidget = GUI:getLayer("CompleteScreen"):getWidget("CompleteScreen")
		currentCompletePage = currentCompletePage+1

		--if currentCompletePage > numOfCompletePages then
		--	local nextButton = GUI:getLayer("CompleteScreen"):getWidget("Next")
			--nextButton:AcceptMessage(Message("SetText", "Play"))
		--end

		if currentCompletePage > numOfCompletePages then

			currentCompletePage = 0
			historyWidget:AcceptMessage(Message("Show", 0))

			param = VariableSet()
			param:setString("Layer1", "Map");
			param:setString("CrossHandler", "ReleaseCompleteScreen")
			param:setString("EndHandler", "CompleteEndHandler")
			kernel:addController(controlFactory:Create("CrossFade", param))
		end

		GUI:getLayer("CompleteScreen"):getWidget("CompleteScreen"):AcceptMessage(Message("SetPage", currentCompletePage))
	end

end