
.namespace Areas_Settings

-- Ce script gère les boutons de la fenêtre d'option




function OnUpdate(dt)
end

function OnDisable()
end

function OnWbpMouseLUp()
	PlaySoundEffect("int_click")
	
	
	
	-- Bouton annuler
	if self.Name == "Settings_popup_quit_area" then
	
	-- Sauvegarde des options
		SaveManager.saveProfile()
		
		curseur.Flags_Visible = false
		
		-- Enlève la popup d'aide
		Settings_popup.Enabled = false
		
		-- Active les boutons du menus principal
		Menu_StartGame_Parent.Enabled = true
		
		
		
		
		
		
	-- Boutons du son
	elseif string.find(self.Name, "sound") then
		
		-- Augmente
		if string.find(self.Name, "plus") then
			if Settings.g_barreposx["sound"] < 9 then
				Settings.g_barreposx["sound"] = Settings.g_barreposx["sound"] + 1
			end
		
		-- Diminue
		else
			if Settings.g_barreposx["sound"] > 0 then
				Settings.g_barreposx["sound"] = Settings.g_barreposx["sound"] - 1
			end
		end
	
		--Settings_soundprogress.Position_X = BARREPOSX + (BARRESIZE/Settings.NBCURSORSTEPS) * Settings.g_barreposx["sound"]
		Settings_soundprogress.SetFrame(Settings.g_barreposx["sound"])
		-- Sauvegarde du volume du son
		ProfilConfig.Set("VolumeSound", (Settings.g_barreposx["sound"] * 10) )
	
	-- Boutons de la musique
	elseif string.find(self.Name, "music") then
	
		-- Augmente
		if string.find(self.Name, "plus") then
			if Settings.g_barreposx["music"] < 9 then
				Settings.g_barreposx["music"] = Settings.g_barreposx["music"] + 1
			end
		
		-- Diminue
		else
			if Settings.g_barreposx["music"] > 0 then
				Settings.g_barreposx["music"] = Settings.g_barreposx["music"] - 1
			end
		end
		
--		Settings_musicprogress.Position_X = BARREPOSX + (BARRESIZE/Settings.NBCURSORSTEPS) * Settings.g_barreposx["music"]
		Settings_musicprogress.SetFrame(Settings.g_barreposx["music"])
		-- Changement du volume de la musique direct
		MenuMusic.Volume = Settings.g_barreposx["music"]/10
		
		-- Sauvegarde du volume de la musique
		ProfilConfig.Set("VolumeMusic", (Settings.g_barreposx["music"] * 10) )
	
	-- Boutons du gamma
	elseif string.find(self.Name, "gamma") then
	
		-- Augmente
		if string.find(self.Name, "plus") then
			if Settings.g_barreposx["gamma"] < 9 then
				Settings.g_barreposx["gamma"] = Settings.g_barreposx["gamma"] + 1
			end
		
		-- Diminue
		else
			if Settings.g_barreposx["gamma"] > 0 then
				Settings.g_barreposx["gamma"] = Settings.g_barreposx["gamma"] - 1
			end
		end
		
		--Settings_gammaprogress.Position_X = BARREPOSX + (BARRESIZE/Settings.NBCURSORSTEPS) * Settings.g_barreposx["gamma"]
		Settings_gammaprogress.SetFrame(Settings.g_barreposx["gamma"])
		-- Sauvegarde du  gamma
		ProfilConfig.Set("GammaLevel2", (Settings.g_barreposx["gamma"] * (Settings.NBCURSORSTEPS / 2) + 100 ) )
	
		-- Changement du gamma direct
		if not OPCore.EditorMode() then
			OPGraphic.SetGamma(ProfilConfig.Get("GammaLevel2") / 100)
		end
	
		OPLog.Log("gamma = "..ProfilConfig.Get("GammaLevel2"))

	end
		-- Checkbox du fullscreen
	if self.Name == "Settings_windowed_chkbx" then
		Settings_windowed_chk.Flags_Visible = not Settings_windowed_chk.Flags_Visible
			OPGraphic.SetScreenMode({fullscreen=not Settings_windowed_chk.Flags_Visible}) 
			ProfilConfig.Set("Fullscreen",not Settings_windowed_chk.Flags_Visible)
			SaveManager.saveProfile()
	end
	
	if self.Name == "Settings_cursor_chkbx" then
			Settings_cursor_chk.Flags_Visible = not Settings_cursor_chk.Flags_Visible
			
			ProfilConfig.Set("HardwareCursor", Settings_cursor_chk.Flags_Visible)
			SaveManager.saveProfile()
		if ProfilConfig.Get("HardwareCursor") == true then
			OPWinCursor.ShowCursor(true)
			Cursor.Flags_Visible = false
		else
			OPWinCursor.ShowCursor(false)
			Cursor.Flags_Visible = true
		end
	end
	

	-- Boutons pour changer la langue du jeu
	return true
end

function progressbar_size()
end

function OnMouseOn()
	
	-- Décalages appliqués pour le rollover en fonction de l'area et de la langue
	-- local curseurshiftx = {
		-- Settings_popup_quit_area = {eng=26,fre=26},
		
	-- }
	if string.find(self.Name, "plus") or string.find(self.Name, "moins") --[[or self.Name == "Settings_windowed_chkbx"--]]  then
		self.SetFrame(1)
	end
	
	return true
end

function OnMouseOff()
	self.SetFrame(0)

	
end