class 'l_PlayingModeScreen' (BaseScreen)

function l_PlayingModeScreen:__init(name, screen)
	BaseScreen.__init(self, name, screen)
	
	local UsualModeY = 330
    local HadrModeY  = 490
    local playModeTextX = 325
    local playModeCheckBoxX = 635
    
	-- create button
	do
	    local bttn_cancel = self:CreateButton('bttn_cancel')
	    bttn_cancel:SetAction('OnCancelButtonClick', self)
	    bttn_cancel:SetActionSound("Menu_button_click")
	    bttn_cancel:SetKeyEquivalent(KEY_ESCAPE)
	    
	    local bttn_ok = self:CreateButton('bttn_ok')
	    bttn_ok:SetAction('OnOkButtonClick', self)
	    bttn_ok:SetActionSound("Menu_button_click")
	    bttn_ok:SetKeyEquivalent(KEY_ENTER)
	end
	
	local zOffset = 250
	-- create checkboxs
	do
	    local checkBoxsX = 657
	    
	    self.casualModeCheckbox = CreateCheckBox()
	    self.casualModeCheckbox:SetRect(checkBoxsX, 235, 50, 50)
	    self.casualModeCheckbox:SetZ(zOffset)
	    self.casualModeCheckbox:SetOnTexture('data/Texture/GUI/Options/CheckboxTick.png')
	    self.casualModeCheckbox:AttachTo(screen)
	    self.casualModeCheckbox:SetState(1)
	    self.casualModeCheckbox:SetAction('CasualModeSetting', self)
	    
	    self.advancedModeCheckbox = CreateCheckBox()
	    self.advancedModeCheckbox:SetRect(checkBoxsX, 391, 50, 50)
	    self.advancedModeCheckbox:SetZ(zOffset)
	    self.advancedModeCheckbox:SetOnTexture('data/Texture/GUI/Options/CheckboxTick.png')
	    self.advancedModeCheckbox:AttachTo(screen)
	    self.advancedModeCheckbox:SetState(0)
	    self.advancedModeCheckbox:SetAction('AdvancedModeSetting', self)
	    
	    self.hardModeCheckbox = CreateCheckBox()
	    self.hardModeCheckbox:SetRect(checkBoxsX, 543, 50, 50)
	    self.hardModeCheckbox:SetZ(zOffset)
	    self.hardModeCheckbox:SetOnTexture('data/Texture/GUI/Options/CheckboxTick.png')
	    self.hardModeCheckbox:AttachTo(screen)
	    self.hardModeCheckbox:SetState(0)
	    self.hardModeCheckbox:SetAction('HardModeSetting', self)
	end
	
	-- create title
	do
	    local title = self:CreateTextEntity('PLAY_MODE_TITLE', 512, 140)
        title:SetScale(0.8)
        title:SetBorderSize(450, 100)
        title:SetTextAlignment(HGETEXT_TOP + HGETEXT_CENTER)
	end

    local y  = 209
	local dy = 155
	
	self:CreateTextEntity('PLAY_MODE_CASUAL_HEADER',	295, y)
	self:CreateTextEntity('PLAY_MODE_ADVANCED_HEADER',	295, y+dy)
	self:CreateTextEntity('PLAY_MODE_HARD_HEADER',		295, y+2*dy)
	
	y  = y + 30
	self:CreateTextEntity('PLAY_MODE_CASUAL_NOTE',		295, y,         0.45)
	self:CreateTextEntity('PLAY_MODE_ADVANCED_NOTE',	295, y+dy,      0.45)
	self:CreateTextEntity('PLAY_MODE_HARD_NOTE',		295, y+2*dy,    0.45)
end
--------------------------------------------------------------------------------

function l_PlayingModeScreen:CreateTextEntity(text, x, y, scale)
    local textEntity = CreateTextEntity(MENU_FONT, text)
    local scale = scale or 0.6
    textEntity:AttachTo(self.screen)
	textEntity:SetXY(x, y)
	textEntity:SetScale(scale)
	textEntity:SetZ(180)
	textEntity:SetTracking(-1)
	textEntity:SetSpacing(0.9)
	textEntity:SetBorderSize(360, 100)
	textEntity:SetTextAlignment(HGETEXT_TOP + HGETEXT_LEFT)
	return textEntity
end
--------------------------------------------------------------------------------

function l_PlayingModeScreen:SetStartGame(start)
	self.start_game = start
end
--------------------------------------------------------------------------------

function l_PlayingModeScreen:SetTag(tag)
    self.tag = tag
    
    local state = GM:GetCurrPlayer().gameState
    if state:HasState(PLAY_MODE, self.tag) then
		self.currentPlayingMode = state:GetState(PLAY_MODE, self.tag):Get(0)
	else
		self.currentPlayingMode = CASUAL_MODE
	end
end
--------------------------------------------------------------------------------

function l_PlayingModeScreen:RestoreMode()
	local state = GM:GetCurrPlayer().gameState
	
	if state:HasState(PLAY_MODE, self.tag) then
		 local mode = state:GetState(PLAY_MODE, self.tag):Get(0)
    
		if mode == CASUAL_MODE then
			self:CasualModeSetting()
		elseif mode == ADVANCED_MODE then
			self:AdvancedModeSetting()
		elseif mode == HARD_MODE then
			self:HardModeSetting()
		end
	end
end
--------------------------------------------------------------------------------

function l_PlayingModeScreen:CasualModeSetting()
    self.casualModeCheckbox:SetState(1)
    self.advancedModeCheckbox:SetState(0)
    self.hardModeCheckbox:SetState(0)
end
--------------------------------------------------------------------------------

function l_PlayingModeScreen:AdvancedModeSetting()
    self.casualModeCheckbox:SetState(0)
    self.advancedModeCheckbox:SetState(1)
    self.hardModeCheckbox:SetState(0)
end
--------------------------------------------------------------------------------

function l_PlayingModeScreen:HardModeSetting()
    self.casualModeCheckbox:SetState(0)
    self.advancedModeCheckbox:SetState(0)
    self.hardModeCheckbox:SetState(1)
end
--------------------------------------------------------------------------------

function l_PlayingModeScreen:OnCancelButtonClick()
    PopUpScreensMgr:Pop()
end
--------------------------------------------------------------------------------

function l_PlayingModeScreen:OnOkButtonClick()
    local state = GM:GetCurrPlayer().gameState
    local oldPlayMode = nil
    
    if state:HasState(PLAY_MODE, self.tag) then
        oldPlayMode = state:GetState(PLAY_MODE, self.tag):Get(0)
        
	    state:RemoveState(PLAY_MODE, self.tag)
    end
    
    if self.casualModeCheckbox:GetState() == 1 then
        state:SetState(PLAY_MODE, CASUAL_MODE, self.tag)
        self.newPlayingMode = CASUAL_MODE
    elseif self.advancedModeCheckbox:GetState() == 1 then
        state:SetState(PLAY_MODE, ADVANCED_MODE, self.tag)
        self.newPlayingMode = ADVANCED_MODE
        
        state:SetState(InteractiveHelp.States.HELP_ACTIVE, 'false', self.tag)
    elseif self.hardModeCheckbox:GetState() == 1 then
        state:SetState(PLAY_MODE, HARD_MODE, self.tag)
        self.newPlayingMode = HARD_MODE
        
        state:SetState(InteractiveHelp.States.HELP_ACTIVE, 'false', self.tag)
    end
    
	PopUpScreensMgr:Pop()
    
    if self.start_game then
        local function on_click_ok()
            PopUpScreensMgr:Pop()
            mainMenu:OnPlayButtonClick()
        end
        
        CreateOKScreen(GetString('PLAY_MODE_CHANGE_NOTE'), on_click_ok, false)
    else
        if play_field then
            local level = GetCurrentLevel()
            level:GetPanelLuaObject():UpdateHintTimeByMode(self.newPlayingMode, self.currentPlayingMode)
        end
    end
end
--------------------------------------------------------------------------------

function CreatePlayingModeScreen(tag, start_game)
    tag = tag or DEFAULT_TAG_NAME

    local screen = CreateScriptedScreen('data/Scripts/screens/PlayingModeScreen.lua', 'l_PlayingModeScreen')
    local mode_screen = screen:GetAssociatedLuaObject()
    
    mode_screen:SetTag(tag)
    mode_screen:RestoreMode()
    mode_screen:SetStartGame(start_game)
    PopUpScreensMgr:Push(screen, false, nil)
end
--------------------------------------------------------------------------------

function IsRegularPlayMode()
    return HasGameState(PLAY_MODE, CASUAL_MODE) or false
end
--------------------------------------------------------------------------------

function IsAdvancedPlayMode()
    return HasGameState(PLAY_MODE, ADVANCED_MODE) or false
end
--------------------------------------------------------------------------------

function IsHardPlayMode()
    return HasGameState(PLAY_MODE, HARD_MODE) or false
end
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function l_PlayingModeScreen:LoadData(screen)
	local anim
	anim = CreateAnimation('data/Texture/GUI/PlayingMode/PlayingModeBackground.png',0,0,634,617,1,0)
	anim:SetHotSpot(317,308)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('PlayingModeBackground',anim,512,384,150,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Buttons/bttn_ok.png',0,0,162,104,3,0)
	anim:SetHotSpot(81,52)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_ok',anim,432,660,180,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Buttons/bttn_cancel.png',0,0,162,104,3,0)
	anim:SetHotSpot(81,52)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_cancel',anim,592,660,180,0,1,1)
	
end
-- CLEAR_ON_SAVE_END
