class 'PlayingModeScreenBase' (BaseScreen)

--[[
 * Класс PlayingModeScreenBase описывает скрин выбора сложности игры.
 * Поля:
 *	- self.checkboxes	- таблица checkbox-ов выбора сложности
 *	- self.tag			- раздел игры, для которого устанавливается сложность
 *	- self.mode			- выбранная сложность игры
--]]
function PlayingModeScreenBase:__init(name, tag)
	BaseScreen.__init(self, name)

	self.checkboxes	= nil
	self.tag		= tag or getDefaultGameStateTag()
	self.mode		= HasGameState(PLAY_MODE, nil, self.tag) and GetGameState(PLAY_MODE, self.tag):get(0)
															  or EPlayMode.CASUAL
	if self.mode == EPlayMode.CUSTOM then
		if HasGameState(PLAY_MODE_PARAMETERS, nil, self.tag) then
			self.modeParameters = Helpers.RestoreObjectFromGameState(PLAY_MODE_PARAMETERS, self.tag)
		else
			self.modeParameters = table.copy(EPlayModeDefaultParameters[EPlayMode.CASUAL])
		end
	else
		self.modeParameters = table.copy(EPlayModeDefaultParameters[self.mode])
	end
	 														  
	self:setupButtons()
	self:setupCheckboxes()
end
-------------------------------------------------------------------------------

function PlayingModeScreenBase:__finalize()
end
-------------------------------------------------------------------------------

--[[
 * Настройка кнопок скрина.
--]]
function PlayingModeScreenBase:setupButtons()
	local bttn_ok       = self:getEntityNamed('bttn_ok')
	local bttn_cancel   = self:getEntityNamed('bttn_cancel')

	bttn_ok.onPress:add(bind(self.onOkButtonClick, self))
	bttn_cancel.onPress:add(bind(self.onCancelButtonClick, self))
	
	bttn_ok:setSFXTrackOnPress( getCommonSoundEntity('ButtonClick') )
	bttn_cancel:setSFXTrackOnPress( getCommonSoundEntity('ButtonClick') )
end
-------------------------------------------------------------------------------

--[[
 * Создание переключателей (CheckBoxEntity) сложности игры и помещение их в таблицу.
--]]
function PlayingModeScreenBase:setupCheckboxes()
	self.checkboxes =
	{
		[EPlayMode.CASUAL]	 = self:createCheckBox( Vector2f(667, 273),			EPlayMode.CASUAL	),
		[EPlayMode.ADVANCED] = self:createCheckBox( Vector2f(667, 273 + 155),	EPlayMode.ADVANCED	),
		[EPlayMode.HARD]	 = self:createCheckBox( Vector2f(667, 273 + 155*2),	EPlayMode.HARD		)
	}
end
-------------------------------------------------------------------------------

--[[
 * Создание CheckBoxEntity, отвечающего за установку указзаной сложности игры.
 * @param	pos		Позиция переключателя.
 * @param	mode	Сложность игры, которая установится при выборе создаваемого CheckBoxEntity.
--]]
function PlayingModeScreenBase:createCheckBox(pos, mode)
	local spriteCheck = CreateSpriteEntity('Data/Textures/Screens/Options/CheckboxTick.png')

	local checkBox = createCheckBoxEntity(nil, spriteCheck)
	checkBox:attachTo( self:getMainEntity() )
	checkBox:setXY(pos.x, pos.y)
	checkBox:setOrder(70)
	checkBox:setChecked( mode == self.mode )
	checkBox:setActiveRectSize(45, 45)
	checkBox.onCheck:add( bind(self.selectMode, self, mode) )
	
	return checkBox
end
-------------------------------------------------------------------------------

--[[
 * Выбор режима игры.
--]]
function PlayingModeScreenBase:selectMode(mode)
	for theMode, checkbox in pairs(self.checkboxes) do
		checkbox:setChecked(theMode == mode)
	end

	self.mode = mode
	self.modeParameters = table.copy(EPlayModeDefaultParameters[self.mode])
	playCommonSound('CheckBoxClick')
end
-------------------------------------------------------------------------------

function PlayingModeScreenBase:setData(ok_callback)
	self.ok_callback = ok_callback
end
-------------------------------------------------------------------------------

function PlayingModeScreenBase:onOkButtonClick()
	SetGameState(PLAY_MODE, self.mode, self.tag)
	Helpers.SaveObjectToGameState(PLAY_MODE_PARAMETERS, self.modeParameters, self.tag)

	if current_scene then
		current_scene:getPanel():getControlsPanel():getHintAnimationLogic():setupFillDuration()

		if current_scene:getPanel():getMode() == EPanelMode.MINIGAME then
			-- skip
			if self.modeParameters.skipEnabled then
				current_scene:getPanel():getControlsPanel():getEntityNamed('bttn_skip'):setVisible(true)
				if not current_scene:getPanel():getControlsPanel():getHintAnimationLogic().is_skip_fill then
					current_scene:getPanel():getControlsPanel():getEntityNamed('bttn_skip'):setRespondable(true)
				end
			else
				current_scene:getPanel():getControlsPanel():getEntityNamed('bttn_skip'):hide()
			end
		else
			-- hint
			if self.modeParameters.hintEnabled then
				current_scene:getPanel():getControlsPanel():getEntityNamed('bttn_hint'):setVisible(true)
				if not current_scene:getPanel():getControlsPanel():getHintAnimationLogic().is_hint_fill then
					current_scene:getPanel():getControlsPanel():getEntityNamed('bttn_hint'):setRespondable(true)
				end
			else
				current_scene:getPanel():getControlsPanel():getEntityNamed('bttn_hint'):hide()
			end
		end
		if current_scene:getPanel():getControlsPanel():getHintAnimationLogic().resetHintFillSpeed then
			current_scene:getPanel():getControlsPanel():getHintAnimationLogic():resetHintFillSpeed()
		end
	end -- current_scene

	self:onScreenDestroy()

	if self.ok_callback then
		self.ok_callback()
	end
end
-------------------------------------------------------------------------------

function PlayingModeScreenBase:onCancelButtonClick()
	self:onScreenDestroy()
end
-------------------------------------------------------------------------------

function PlayingModeScreenBase:onScreenDestroy()
	 PopUpScreensMgr:pop()
end
-------------------------------------------------------------------------------