local Option = baseClass(BaseUI)

local config = baseLoadLua('LzDaer/LzDaer_Public/LzDaer_Public_Scripts/Lzde_Config')

function Option:onCreate(use)
	self:setZOrder(100)
	UIHelper:setButtonEvent(self:getChild('Button_15'),function()
		config:uiAnim(self:getChild('Image_2'),config.animType._in,function()
			UIMgr:closeUI(self)
		end)
	end)
	local btnExit = self:getChild('Button_14')
	UIHelper:setButtonEnabled(btnExit,use)
	UIHelper:setButtonEvent(btnExit,function()
		config:uiAnim(self:getChild('Image_2'),config.animType._in,function()
			Pt_M_SendShengQingCloseRoom()
			UIMgr:closeUI(self)
		end)
	end)
	local saveVoice,saveEffect = Pt_GetSoundInfo()
	local voiceSlider = self:getChild('Slider_6')
	voiceSlider:setPercent(saveVoice * 100)
	voiceSlider:addEventListener(function(sender,event)
        if event == ccui.TouchEventType.ended then
            local percent = voiceSlider:getPercent()
            sys.setMusicVolume(percent / 100)
			Pt_SaveVoiceState(percent / 100)
        end
    end)
	local effectSlider = self:getChild('Slider_4')
	effectSlider:setPercent(saveEffect * 100)
	effectSlider:addEventListener(function(sender,event)
        if event == ccui.TouchEventType.ended then
            local percent = effectSlider:getPercent()
            sys.setSoundVolume(percent / 100)
			Pt_SaveEffectState(percent / 100)
        end
    end)
	self:changeSkin()

	config:uiAnim(self:getChild('Image_2'),config.animType._out)
end

function Option:changeSkin()
	self.deskIdx,self.skinIdx = config:loadOption()
	self.deskOrg = self.deskIdx
	self.skinOrg = self.skinIdx
	local btn = {self:getChild('Button_8'),self:getChild('Button_9'),self:getChild('Button_10')}
	UIHelper:createRadioGroup(btn,btn[self.deskIdx],function(ref)
		local tag = ref:getTag()
		if tag == 11 then
			self.deskIdx = 1
		elseif tag == 12 then
			self.deskIdx = 2
		elseif tag == 13 then
			self.deskIdx = 3
		end
		if self.deskOrg ~= self.deskIdx then
			self.deskOrg = self.deskIdx
			config:saveOption(self.deskIdx or 1,self.skinIdx or 1)
			Daer_ChangeDesk()
		end
	end)
	-- btn = {}
	-- btn = {self:getChild('Button_12'),self:getChild('Button_13')}
	-- UIHelper:createRadioGroup(btn,btn[self.skinIdx],function(ref)
	-- 	local tag = ref:getTag()
	-- 	if tag == 15 then
	-- 		self.skinIdx = 1
	-- 	elseif tag == 16 then
	-- 		self.skinIdx = 2
	-- 	end
	-- 	if self.skinOrg ~= self.skinIdx then
	-- 		self.skinOrg = self.skinIdx
	-- 		config:saveOption(self.deskIdx or 1,self.skinIdx or 1)
	-- 		ChangeSkin()
	-- 	end
	-- end)
end

return Option