-----------------------------------------------------------------------------
--
-- Обработчик справочной системы
--
-----------------------------------------------------------------------------

-- установка значений "показывания" окошка help-a индикоторов
-- т.к. индикаторы плавают в зависимости от состояния аквариума
-- возвращает: смещение по X и является ли кубок золотым

function setIndicatorsParam()
	local ver = PermanentStorage.GetGlobalStringOrDef("temp:Ver", "Full")
	local tank
	if ver == "Full" then
		tank = PermanentStorage.GetLocalStringOrDef("Current Tank", "1")
	else
		tank = PermanentStorage.GetLocalStringOrDef("Current Tank", ver)
	end
	local cup  = PermanentStorage.GetLocalStringOrDef(tank.." Cup", "None")
	local shiftX = 586 -- для None
	if cup == "Bronze" or cup == "Silver" then
	    shiftX = 543
	end
	return shiftX, cup == "Gold"
end

function HelpFunc(message)

	if message == "Mutable Help Control Clear" then
	    SendMessage("Mutable Help Control", "clear children list")
		if PermanentStorage.IsLocalNameDefined("temp:needHelpPhotoWindow") then
			PermanentStorage.UndefLocalName("temp:needHelpPhotoWindow")
		end
	
	elseif IsReceiver("BuyTank backgroung mover") then
		if message == "show" and not PermanentStorage.GetLocalBool("temp:NoContextHelp") then
			SendMessage("Mutable Help Control", "template BuyTankHelpTemplate")
			SendMessage("Mutable Help Control", "create top instance")
			SendMessage("Help alpha mover", "move to in")
			PermanentStorage.SetLocalBool("temp:NoContextHelp", true)
			
		elseif message == "hide" and PermanentStorage.GetLocalBool("temp:NoContextHelp") then
			PermanentStorage.SetLocalBool("temp:NoContextHelp", false)
			SendMessage("Help alpha mover", "report arrival to post:lua:HelpFunc")
			SendMessage("Help alpha mover", "set arrival message Mutable Help Control Clear")
			SendMessage("Help alpha mover", "move to out")
		
		end

 	elseif IsReceiver("Choose tank mover") then
		if message == "show" then
		    if SendMessageReply("ChooseTank scroll", "get state") == "preview" then
				SendMessage("Mutable Help Control", "template ChooseTankHelpPreviewTemplate")
			else
			    SendMessage("Mutable Help Control", "template ChooseTankHelpThumbsTemplate")
			end
			SendMessage("Mutable Help Control", "create top instance")
			SendMessage("Help alpha mover", "move to in")
			PermanentStorage.SetLocalBool("temp:NoContextHelp", true)
		
		elseif message == "hide" and PermanentStorage.GetLocalBool("temp:NoContextHelp") then
			PermanentStorage.SetLocalBool("temp:NoContextHelp", false)
			SendMessage("Help alpha mover", "report arrival to post:lua:HelpFunc")
			SendMessage("Help alpha mover", "set arrival message Mutable Help Control Clear")
			SendMessage("Help alpha mover", "move to out")
		
		end
		
	elseif IsReceiver("Photo album mover") then

		if (message == "show") then
		    if SendMessageReply("Photo album scroll", "get state") == "preview" then
		    	SendMessage("Mutable Help Control", "template PhotoAlbumHelpPreviewTemplate")
			else
				local needPhoto = SendMessageReply("Photo album scroll", "get count photo") ~= "0"
			    PermanentStorage.SetLocalBool("temp:needHelpPhotoWindow", needPhoto)
			    SendMessage("Mutable Help Control", "template PhotoAlbumHelpThumbsTemplate")
			    SendMessage("Mutable Help Control", "defineText [holePhoto] "..tostring(needPhoto))
			    SendMessage("Photo album scroll", "unset shiftY")
			end
			SendMessage("Mutable Help Control", "create top instance")
			SendMessage("Help alpha mover", "move to in")
			PermanentStorage.SetLocalBool("temp:NoContextHelp", true)

		elseif (message == "hide" and PermanentStorage.GetLocalBool("temp:NoContextHelp")) then
			PermanentStorage.SetLocalBool("temp:NoContextHelp", false)
			SendMessage("Help alpha mover", "report arrival to post:lua:HelpFunc")
			SendMessage("Help alpha mover", "set arrival message Mutable Help Control Clear")
			SendMessage("Help alpha mover", "move to out")
			SendMessage("Photo album scroll", "set shiftY")
		
		end
	
	elseif IsReceiver("Main screen modal dialog") then
		if message == "show" then
			SendMessage("Mutable Help Control", "template MainScreenHelpTemplate")
			local shiftX, cupIsGold = setIndicatorsParam()
			SendMessage("Mutable Help Control", "defineText [indicatorShiftX] "..shiftX)
			SendMessage("Mutable Help Control", "defineText [needIndicator] "..tostring((not cupIsGold)))
			SendMessage("Mutable Help Control", "create top instance")
			SendMessage("Help alpha mover", "move to in")
			PermanentStorage.SetLocalBool("temp:NoContextHelp", true)
		
		elseif message == "hide" and PermanentStorage.GetLocalBool("temp:NoContextHelp") then
			PermanentStorage.SetLocalBool("temp:NoContextHelp", false)
			SendMessage("Help alpha mover", "report arrival to post:lua:HelpFunc")
			SendMessage("Help alpha mover", "set arrival message Mutable Help Control Clear")
			SendMessage("Help alpha mover", "move to out")
		
		end
		
	elseif IsReceiver("Shop modal dialog") then
		if message == "show" then
			SendMessage("Mutable Help Control", "template ShopHelpTemplate")
			local shiftX, cupIsGold = setIndicatorsParam()
   			SendMessage("Mutable Help Control", "defineText [indicatorShiftX] "..shiftX)
			SendMessage("Mutable Help Control", "defineText [needIndicator] "..tostring((not cupIsGold)))
			SendMessage("Mutable Help Control", "create top instance")
			SendMessage("Help alpha mover", "move to in")
			PermanentStorage.SetLocalBool("temp:NoContextHelp", true)

		elseif message == "hide" and PermanentStorage.GetLocalBool("temp:NoContextHelp") then
			PermanentStorage.SetLocalBool("temp:NoContextHelp", false)
			SendMessage("Help alpha mover", "report arrival to post:lua:HelpFunc")
			SendMessage("Help alpha mover", "set arrival message Mutable Help Control Clear")
			SendMessage("Help alpha mover", "move to out")
		
		end
	
	elseif IsReceiver("Above game field modal dialog") then
		if message == "show" then
			SendMessage("Mutable Help Control", "template GameFieldHelpTemplate")
			SendMessage("Mutable Help Control", "create top instance")
			SendMessage("Help alpha mover", "move to in")
			PermanentStorage.SetLocalBool("temp:NoContextHelp", true)
			SendMessage("GameField", "Pause")
		
		elseif message == "hide" and PermanentStorage.GetLocalBool("temp:NoContextHelp") then
			PermanentStorage.SetLocalBool("temp:NoContextHelp", false)
			SendMessage("Help alpha mover", "report arrival to post:lua:HelpFunc")
			SendMessage("Help alpha mover", "set arrival message Mutable Help Control Clear")
			SendMessage("Help alpha mover", "move to out")
			SendMessage("GameField", "Continue")
		
		end
	
	end

end
