-- 设置快捷键修饰符 (Modifier Key)
local function SetHotKey(self)
	SetModifiedClick(self.key, self.value)
	SaveBindings(1)
end

-- 通用设置值更新方法
local function DefaultSetValue(self)
	Settings.SetValue(self.key, self.value)
end

-- 12.0 新增的 CVarCallbackRegistry:SetCVarBitfieldMask 方法
local function SetCVarBitfieldMask(self)
	CVarCallbackRegistry:SetCVarBitfieldMask(self.key, self.value)
end

-- 设置控制台变量 (CVar)
local function DefaultSetCVar(self)
	SetCVar(self.key, self.value)
end

--[[
    功能：构建/初始化设置列表
    参数：list (一个包含多个配置项数据的表)
    逻辑：
    遍历配置表，检查每一项是否定义了具体的应用方法 (v.apply)。
    如果没有定义，则默认将其视为 CVar (控制台变量) 进行处理。
--]]
local function BuildSettings(list)	
	for _, v in ipairs(list) do
		v.apply = v.apply or DefaultSetCVar
	end
	return list
end

--[[
	控制
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/Controls.lua
--]]
local function Controls()

	local variable = {
		{
			name = "目标锁定",
			key = "deselectOnClick",
			value = true,
			apply = DefaultSetValue
		},
		{
			name = "自动取消飞行",
			key = "autoDismountFlying",
			value = 1,
		},
		{
			name = "自动解除离开状态",
			key = "autoClearAFK",
			value = 1,
		},
		{
			name = "左键点击操作",
			key = "interactOnLeftClick",
			value = 1,
		},
		{
			name = "鼠标位置打开拾取窗口",
			key = "lootUnderMouse",
			value = 1,
		},
		{
			name = "自动拾取",
			key = "autoLootDefault",
			value = 1,
		},
		{
			name = "自动拾取按键",
			doc = "ALT = ALT键, CTRL = CTRL键, SHIFT = SHIFT键, NONE = 无",
			key = "AUTOLOOTTOGGLE",
			value = "SHIFT",			
			apply = SetHotKey
		},
		{
			name = "组合背包",
			key = "combinedBags",
			value = 1,
		},
		{
			name = "开启交互按键",
			doc = "0 = 禁用, 1 = 手柄, 2 = 键鼠, 3 = 总是",
			key = "softTargetInteract",
			value = 3,			
		},
		{
			name = "与目标互动",
			key = "INTERACTTARGET",
			value = "BUTTON5",
			apply = function(self)
				SetBinding(self.value, self.key)
				SaveBindings(1)
			end
		},
		{
			name = "交互按键音效提示",
			key = "softTargettingInteractKeySound",
			value = 1,
		},
		{
			name = "将鼠标指针锁定在窗口内",
			key = "ClipCursor",
			value = 0,
		},
		{
			name = "反转鼠标",
			key = "mouseInvertPitch",
			value = 0,
		},
		{
			name = "鼠标观察速度",
			doc = "取值：90 - 270, 步长：10",
			value = 180,			
			apply = function(self)
				SetCVar("cameraYawMoveSpeed", self.value)
				SetCVar("cameraPitchMoveSpeed", self.value / 2)
			end
		},
		{
			name = "启用鼠标灵敏度",
			key = "enableMouseSpeed",
			value = 0,
		},
		{
			name = "鼠标灵敏度",
			doc = "取值：0.5 - 1.4, 步长：0.05",
			key = "mouseSpeed",
			value = 0.5,
		},
		{
			name = "点击移动",
			key = "autointeract",
			value = 0,
		},
		{
			name = "点击移动",
			doc = "0 = 从不调整镜头, 1 = 移动时只调整水平角度, 2 = 总是调整视角, 4 = 仅在移动时",
			key = "cameraSmoothTrackingStyle",
			value = 0,			
		},
		{
			name = "水体碰撞",
			key = "cameraWaterCollision",
			value = 1,
		},
		{
			name = "自动跟随速度",
			doc = "取值：90 - 270, 步长：10",
			value = 270,			
			apply = function(self)
				SetCVar("cameraYawSmoothSpeed", self.value)
				SetCVar("cameraPitchSmoothSpeed", self.value / 4)
			end
		},
		{
			name = "镜头跟随模式",
			doc = "0 = 从不调整镜头, 1 = 移动时只调整水平角度, 2 = 总是调整视角, 4 = 仅在移动时",
			key = "cameraSmoothStyle",
			value = 0,			
		}
	}
	
	return BuildSettings(variable)
end


--[[
	界面
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/Interface.lua
--]]
local function Interface()

	local variable = {
		{
			name = "游戏内导航",
			key = "showInGameNavigation",
			value = 1,
		},
		{
			name = "教程",
			key = "showTutorials",
			value = 0,
		},
		{
			name = "轮廓线模式",
			doc = "0 = 禁用, 1 = 仅限任务目标1, 2 = 任务目标和鼠标悬停(默认), 3 = 任务目标、鼠标悬停及目标",
			key = "Outline",
			value = 3,			
		},
		{
			name = "状态文字",
			value = 3,
			doc = "1 = 数字, 2 = 百分比, 3 = 同时显示, 4 = 无",
			apply = function(self)
				if self.value == 1 then
					SetCVar("statusTextDisplay", "NUMERIC")
					SetCVar("statusText", "1")
				elseif self.value == 2 then
					SetCVar("statusTextDisplay", "PERCENT")
					SetCVar("statusText", "1")
				elseif self.value == 3 then
					SetCVar("statusTextDisplay", "BOTH")
					SetCVar("statusText", "1")
				elseif self.value == 4 then
					SetCVar("statusTextDisplay", "NONE")
					SetCVar("statusText", "0")
				end
			end
		},
		{
			name = "聊天泡泡",
			key = "chatBubbles",
			value = 1,
		},
		{
			name = "组队聊天泡泡",
			key = "chatBubblesParty",
			value = 1,
		},
		{
			name = "团队聊天泡泡",
			key = "chatBubblesRaid",
			value = 1,
		},
		{
			name = "替换玩家框体头像",
			key = "ReplaceOtherPlayerPortraits",
			value = 0,
		},
		{
			name = "替换我的框体头像",
			key = "ReplaceMyPlayerPortrait",
			value = 0,
		},
		{
			name = "显示战团已完成的任务",
			key = "PROXY_ACCOUNT_COMPLETED_QUEST_FILTERING",
			value = false,
			apply = DefaultSetValue
		},
		{
			name = "显示低等级任务",
			key = "PROXY_TRIVIAL_QUEST_FILTERING",
			value = true,
			apply = DefaultSetValue
		},
		{
			name = "显示预计治疗",
			key = "raidFramesDisplayIncomingHeals",
			value = 1,
		},
		{
			name = "显示能量条",
			key = "raidFramesDisplayPowerBars",
			value = 1,
		},
		{
			name = "只显示治疗者能量条",
			key = "raidFramesDisplayOnlyHealerPowerBars",
			value = 1,
		},
		{
			name = "高亮显示仇恨目标",
			key = "raidFramesDisplayAggroHighlight",
			value = 1,
		},
		{
			name = "显示职业颜色",
			key = "raidFramesDisplayClassColor",
			value = 1,
		},
		{
			name = "显示宠物",
			key = "raidOptionDisplayPets",
			value = 1,
		},
		{
			name = "显示主坦克和主助理",
			key = "raidOptionDisplayMainTankAndAssist",
			value = 1,
		},
		{
			name = "显示负面效果",
			key = "raidFramesDisplayDebuffs",
			value = 1,
		},
		{
			name = "放大职责减益",
			key = "raidFramesDisplayLargerRoleSpecificDebuffs",
			value = 1,
		},
		{
			name = "只显示可供驱散的负面效果",
			key = "raidFramesDisplayOnlyDispellableDebuffs",
			value = 1,
		},
		{
			name = "重要防御技能居中",
			key = "raidFramesCenterBigDefensive",
			value = 1,
		},
		{
			name = "可驱散减益指示器",
			doc = "0 = 关闭, 1 = 我可驱散的, 2 = 显示全部",
			key = "raidFramesDispelIndicatorType",
			value = 1,
		},
		{
			name = "可驱散减益颜色",
			key = "raidFramesDispelIndicatorOverlay",
			value = 1,
		},
		{
			name = "显示生命值数值",
			doc = "none = 不显示, health = 剩余生命值, losthealth = 损失生命值, perc = 生命值百分比",
			key = "raidFramesHealthText",
			value = "none",			
		},
		{
			name = "显示能量条",
			key = "pvpFramesDisplayPowerBars",
			value = 1,
		},
		{
			name = "只显示治疗者能量条",
			key = "pvpFramesDisplayOnlyHealerPowerBars",
			value = 1,
		},
		{
			name = "显示职业颜色",
			key = "pvpFramesDisplayClassColor",
			value = 1,
		},
		{
			name = "显示宠物",
			key = "pvpOptionDisplayPets",
			value = 1,
		},
		{
			name = "显示生命值数值",
			doc = "none = 不显示, health = 剩余生命值, losthealth = 损失生命值, perc = 生命值百分比",
			key = "pvpFramesHealthText",
			value = "none",
		},
	}
	
	return BuildSettings(variable)
end


--[[
	动作条
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/ActionBars.lua
--]]
local function ActionBars()

	local function UpdateActionBar()
		MultiActionBar_Update()
		StatusTrackingBarManager:UpdateBarTicks()
		EventRegistry:TriggerEvent("ActionBarShownSettingUpdated")
	end
	
	-- 检查动作条的启用状态
	local function CheckActionBarState()
		return  {
			[2] = Settings.GetValue("PROXY_SHOW_ACTIONBAR_2"),
			[3] = Settings.GetValue("PROXY_SHOW_ACTIONBAR_3"),
			[4] = Settings.GetValue("PROXY_SHOW_ACTIONBAR_4"),
			[5] = Settings.GetValue("PROXY_SHOW_ACTIONBAR_5"),
		--	[6] = Settings.GetValue("PROXY_SHOW_ACTIONBAR_6"),
		--	[7] = Settings.GetValue("PROXY_SHOW_ACTIONBAR_7"),
		--	[8] = Settings.GetValue("PROXY_SHOW_ACTIONBAR_8"),
		}
	end
	
	local variable = {
		{
			name = "启用动作条",
			value = true,
			apply = function(self)			
				for k, v in pairs( CheckActionBarState() ) do
					local bar = string.format("PROXY_SHOW_ACTIONBAR_%s", k)
					if v == false then			
						Settings.SetValue(bar, self.value)
						Settings.SetOnValueChangedCallback(bar, UpdateActionBar)
					end
				end
				
				UpdateActionBar()
			end
		},
		{
			name = "锁定动作条",
			key = "lockActionBars",
			value = 1,
		},
		{
			name = "锁定动作条",
			key = "PICKUPACTION",
			value = "SHIFT",
			apply = SetHotKey
		},
		{
			name = "显示冷却时间",
			key = "countdownForCooldowns",
			value = 1,
		},
	}
	
	return BuildSettings(variable)
end


--[[
	战斗
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/Combat.lua
--]]
local function Combat()

	local variable = {
		{
			name = "显示个人资源",
			key = "nameplateShowSelf",
			value = 0,
		},
		{	-- https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/Mainline/CombatOverrides.lua
			name = "自身高亮",
			doc = "1 = 圆环, 2 = 轮廓线, 3 = 图标, 4 = 圆环和轮廓线, 5 = 圆环和图标, 6 = 轮廓线和图标, 7 = 圆环、轮廓线和图标, 0 = 关",
			value = 7,			
			apply = function(self)
				local setting = {
					[1] = {
						["findYourselfAnywhere"] = 1,
						["findYourselfModeIcon"] = 0,
						["findYourselfModeOutline"] = 0,
						["findYourselfModeCircle"] = 1,
					},
					[2] = {
						["findYourselfAnywhere"] = 1,
						["findYourselfModeIcon"] = 0,
						["findYourselfModeOutline"] = 1,
						["findYourselfModeCircle"] = 0,
					},
					[3] = {
						["findYourselfAnywhere"] = 1,
						["findYourselfModeIcon"] = 1,
						["findYourselfModeOutline"] = 0,
						["findYourselfModeCircle"] = 0,
					},
					[4] = {
						["findYourselfAnywhere"] = 1,
						["findYourselfModeIcon"] = 0,
						["findYourselfModeOutline"] = 1,
						["findYourselfModeCircle"] = 1,
					},
					[5] = {
						["findYourselfAnywhere"] = 1,
						["findYourselfModeIcon"] = 1,
						["findYourselfModeOutline"] = 0,
						["findYourselfModeCircle"] = 1,
					},
					[6] = {
						["findYourselfAnywhere"] = 1,
						["findYourselfModeIcon"] = 1,
						["findYourselfModeOutline"] = 1,
						["findYourselfModeCircle"] = 0,
					},
					[7] = {
						["findYourselfAnywhere"] = 1,
						["findYourselfModeIcon"] = 1,
						["findYourselfModeOutline"] = 1,
						["findYourselfModeCircle"] = 1,
					},
					[0] = {
						["findYourselfAnywhere"] = 0,
						["findYourselfModeIcon"] = 0,
						["findYourselfModeOutline"] = 0,
						["findYourselfModeCircle"] = 0,
					},				
				}
			
				local v = setting[self.value]
				
				for k, v in pairs( v ) do
					SetCVar(k, v)
				end
			end
		},
		{
			name = "被遮蔽时显示轮廓",
			key = "occludedSilhouettePlayer",
			value = 1,
		},
		{
			name = "目标的目标",
			key = "showTargetOfTarget",
			value = 1,
		},
		{
			name = "生命值过低时不闪烁屏幕",
			key = "doNotFlashLowHealthWarning",
			value = 0,
		},
		{
			name = "失控警报",
			key = "lossOfControl",
			value = 1,
		},
		{
			name = "滚动战斗记录",
			key = "enableFloatingCombatText",
			value = 0,
		},
		{
			name = "鼠标悬停施法",
			key = "enableMouseoverCast",
			value = 0,
		},
		{	
			name = "鼠标悬停施法",
			doc = "ALT = ALT键, CTRL = CTRL键, SHIFT = SHIFT键, NONE = 无",
			key = "MOUSEOVERCAST",
			value = "NONE",
			apply = SetHotKey
		},
		{
			name = "自我施法",
			doc = "1 = 无, 2 = 自动, 3 = 按键, 4 = 自动和按键",
			key = "autoSelfCast",
			value = 2,			
			apply = function(self)
				local selfCastKeySetting = Settings.GetSetting("SELFCAST")

				local autoSelfCast = false
				local selfCastKey = selfCastKeySetting:GetValue()

				if self.value == 1 or self.value == 2 then
					selfCastKey = "NONE"
				else
					if selfCastKey == "NONE" then
						selfCastKey = "ALT"
					end
				end

				if self.value == 2 or self.value == 4 then
					autoSelfCast = true
				else
					autoSelfCast = false
				end

				SetCVar("autoSelfCast", autoSelfCast)
				selfCastKeySetting:SetValue(selfCastKey)
			end
		},
		{
			name = "自我施法",
			doc = "ALT = ALT键, CTRL = CTRL键, SHIFT = SHIFT键, NONE = 无",
			key = "SELFCAST",
			value = "ALT",
			apply = SetHotKey
		},
		{
			name = "焦点施法按键",
			doc = "ALT = ALT键, CTRL = CTRL键, SHIFT = SHIFT键, NONE = 无",
			key = "FOCUSCAST",
			value = "NONE",
			apply = SetHotKey
		},
		{
			name = "蓄力法术输入",
			doc = "0 = 按下后放开, 1 = 两次按键",
			key = "empowerTapControls",
			value = 0,			
		},
		{
			name = "法术警报不透明度",
			doc = "取值：0 - 1, 步长：0.05",
			key = "spellActivationOverlayOpacity",
			value = 0.65,			
		},
		{
			name = "按住施法",
			key = "ActionButtonUseKeyHeldSpell",
			value = 1,
		},
		{
			name = "开启动作瞄准",
			doc = "0 = 禁用, 1 = 手柄, 2 = 键盘, 3 = 总是",
			key = "softTargetEnemy",
			value = 0,			
		},
	}
	
	return BuildSettings(variable)
end


--[[
	社交
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/Social.lua
--]]
local function Social()

	local variable = {
		{
			name = "关闭聊天",
			key = "PROXY_DISABLE_CHAT",
			value = false,
			apply = DefaultSetValue
		},
		{
			name = "实时聊天过滤",
			doc = "1 = 所有人, 2 = 朋友外的所有人, 3 = 朋友和公会成员外的所有人, 4 = 没有人",
			key = "excludedCensorSources",
			value = 3,			
		},
		{
			name = "语言过滤器",
			key = "profanityFilter",
			value = false,
			apply = DefaultSetValue
		},
		{
			name = "公会成员提示",
			key = "guildMemberNotify",
			value = 0,
		},
		{
			name = "阻止交易",
			key = "BlockTrades",
			value = 0,
		},
		{
			name = "阻止公会邀请",
			key = "PROXY_BLOCK_GUILD_INVITES",
			value = true,
			apply = DefaultSetValue
		},
		{
			name = "阻止住宅区邀请",
			key = "PROXY_BLOCK_NEIGHBORHOOD_INVITES",
			value = true,
			apply = DefaultSetValue
		},
		{
			name = "限制日历邀请",
			key = "restrictCalendarInvites",
			value = 1,
		},
		{
			name = "阻止聊天频道邀请",
			key = "blockChannelInvites",
			value = 1,
		},
		{
			name = "好友上线",
			key = "showToastOnline",
			value = 1,
		},
		{
			name = "好友下线",
			key = "showToastOffline",
			value = 1,
		},
		{
			name = "通告更新",
			key = "showToastBroadcast",
			value = 1,
		},
		{
			name = "位置显示",
			doc = "false = 好友与公会成员, true = 好友、近期往来与公会成员",
			key = "PROXY_SOCIAL_LOCATION_VISIBILITY",
			value = true,			
			apply = DefaultSetValue
		},
		{
			name = "实名和战网昵称好友请求",
			key = "showToastFriendRequest",
			value = 1,
		},
		{
			name = "显示浮窗",
			key = "showToastWindow",
			value = 1,
		},
		{
			name = "自动接受快速加入申请",
			key = "autoAcceptQuickJoinRequests",
			value = 0,
		},
		{
			name = "聊天风格",
			doc = "im = 即时通讯风格, classic = 经典风格",
			key = "chatStyle",
			value = "im",			
		},
		{
			name = "新的悄悄话",
			doc = "inline = 一致模式, popout = 新标签页, popout_and_inline = 同时",
			key = "whisperMode",
			value = "inline",			
		},
		{
			name = "聊天时间截",
			doc = "none = 不显示, %H:%M:%S = 其他格式",
			key = "showTimestamps",
			value = "%H:%M",		
		},
		{
			name = "重置聊天窗口位置",
			apply = function()
				-- 占位符
				-- 请在编辑模式中设置聊天窗口
				return
			end
		},
	}
	
	return BuildSettings(variable)
end


--[[
	信号系统
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/PingSystem.lua
--]]
local function PingSystem()

	local variable = {
		{
			name = "开启信号",
			key = "enablePings",
			value = 1,
		},
		{
			name = "信号模式",
			doc = "0 = 快速信号, 1 = 从容信号",
			key = "pingMode",
			value = 0,
			
		},
		{
			name = "信号音效",
			key = "Sound_EnablePingSounds",
			value = 1,
		},
		{
			name = "信号音量",
			doc = "取值：0 - 1, 步长：0.05",
			key = "Sound_PingVolume",
			value = 1,			
		},
		{
			name = "在聊天中显示信号",
			key = "showPingsInChat",
			value = 1,
		},
	}
	
	return BuildSettings(variable)
end


--[[
	游戏增强
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/AdvancedOptions.lua
--]]
local function AdvancedOptions()

	local variable = {
		{
			name = "辅助标亮",
			key = "assistedCombatHighlight",
			value = 1,
		},
		{
			name = "启用首领预警",
			key = "combatWarningsEnabled",
			value = 1,
		},
		{
			name = "启用文字预警",
			key = "encounterWarningsEnabled",
			value = 1,
		},
		{
			name = "启用文字预警",
			doc = "0 = 所有预警, 1 = 中等优先级, 2 = 关键优先级",
			key = "encounterWarningsLevel",
			value = 2,
		},
		{
			name = "未成为目标时隐藏",
			key = "encounterWarningsHideIfNotTargetingPlayer",
			value = 1,
		},	
		{
			name = "启用首领时间轴",
			key = "encounterTimelineEnabled",
			value = 1,
		},
		{
			name = "隐藏长倒计时",
			key = "encounterTimelineHideLongCountdowns",
			value = 0,
		},
		{
			name = "隐藏排队倒计时",
			key = "encounterTimelineHideQueuedCountdowns",
			value = 0,
		},
		{
			name = "隐藏其他职责的倒计时",
			key = "encounterTimelineHideForOtherRoles",
			value = 0,
		},
		{
			name = "法术辅助图标",
			key = "encounterTimelineIconographyEnabled",
			value = 1,
		},
		{
			name = "法术辅助图标",
			doc = "0 = 关闭, 1 = 坦克警报, 2 = 治疗者警报, 4 = 伤害输出警报, 8 = 灭团技, 16 = 可驱散, 32 = 激怒, value = 所有你想要显示的图标数值之和",
			key = "encounterTimelineIconographyHiddenMask",
			value = 62,
			apply = function(self)
				local function TransformValue(mask)
					local invertedMask = 0

					for iconSetIndex in pairs(EncounterTimelineIconSetMasks) do
						local iconSetBit = bit.lshift(1, (iconSetIndex - 1))

						if not FlagsUtil.IsSet(mask, iconSetBit) then
							invertedMask = bit.bor(invertedMask, iconSetBit)
						end
					end

					return invertedMask
				end
				
				local disabledIconSets = TransformValue(self.value)
				CVarCallbackRegistry:SetCVarBitfieldMask(self.key, disabledIconSets)
			end
		},
		{
			name = "启用冷却管理器",
			key = "cooldownViewerEnabled",
			value = 0,
		},
		{
			name = "启用外部防御技能",
			key = "externalDefensivesEnabled",
			value = 1,
		},
		{
			name = "启用伤害统计",
			key = "damageMeterEnabled",
			value = 1,
		},
		{
			name = "收益递减追踪",
			key = "spellDiminishPVPEnemiesEnabled",
			value = 1,
		},
		{
			name = "仅限我能施放的",
			key = "spellDiminishPVPOnlyTriggerableByMe",
			value = 1,
		},
	}
	
	return BuildSettings(variable)
end


--[[
	姓名版
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/Nameplates.lua
--]]
local function Nameplates()
	
	local variable = {
		{
			name = "我的名字",
			key = "UnitNameOwn",
			value = 0,
		},
		{
			name = "NPC姓名",
			doc = "1 = 任务NPC, 2 = 敌对及任务NPC, 3 = 敌对、任务及可互动的NPC, 4 = 所有NPC, 0 = 无",
			value = 3,			
			apply = function(self)
				if self.value == 1 then
					SetCVar("UnitNameFriendlySpecialNPCName", "1");
					SetCVar("UnitNameNPC", "0");
					SetCVar("UnitNameHostleNPC", "0");
					SetCVar("UnitNameInteractiveNPC", "0");
					SetCVar("ShowQuestUnitCircles", "0");
				elseif self.value == 2 then
					SetCVar("UnitNameFriendlySpecialNPCName", "1");
					SetCVar("UnitNameHostleNPC", "1");
					SetCVar("UnitNameInteractiveNPC", "0");
					SetCVar("UnitNameNPC", "0");
					SetCVar("ShowQuestUnitCircles", "1");
				elseif self.value == 3 then
					SetCVar("UnitNameFriendlySpecialNPCName", "1");
					SetCVar("UnitNameHostleNPC", "1");
					SetCVar("UnitNameInteractiveNPC", "1");
					SetCVar("UnitNameNPC", "0");
					SetCVar("ShowQuestUnitCircles", "1");
				elseif self.value == 4 then
					SetCVar("UnitNameFriendlySpecialNPCName", "0");
					SetCVar("UnitNameHostleNPC", "0");
					SetCVar("UnitNameInteractiveNPC", "0");
					SetCVar("UnitNameNPC", "1");
					SetCVar("ShowQuestUnitCircles", "1");
				else
					SetCVar("UnitNameFriendlySpecialNPCName", "0");
					SetCVar("UnitNameHostleNPC", "0");
					SetCVar("UnitNameInteractiveNPC", "0");
					SetCVar("UnitNameNPC", "0");
					SetCVar("ShowQuestUnitCircles", "1");
				end
			end
		},
		{
			name = "小动物和小伙伴",
			key = "UnitNameNonCombatCreatureName",
			value = 0,
		},
		{
			name = "友方玩家",
			key = "UnitNameFriendlyPlayerName",
			value = 1,
		},
		{
			name = "友方玩家：仆从",
			key = "UnitNameFriendlyMinionName",
			value = 0,
		},
		{
			name = "敌方玩家",
			key = "UnitNameEnemyPlayerName",
			value = 1,
		},
		{
			name = "敌方玩家：仆从",
			key = "UnitNameEnemyMinionName",
			value = 1,
		},
		{
			name = "显示所有姓名版",
			key = "nameplateShowAll",
			value = 1,
		},
		{
			name = "敌方单位姓名版",
			key = "nameplateShowEnemies",
			value = 1,
		},
		{
			name = "敌方单位姓名版：仆从",
			key = "nameplateShowEnemyMinions",
			value = 1,
		},
		{
			name = "敌方单位姓名版：杂兵",
			key = "nameplateShowEnemyMinus",
			value = 1,
		},
		{
			name = "友方玩家姓名版",
			key = "nameplateShowFriends",
			value = 1,
		},
		{
			name = "友方玩家姓名版仅名字",
			key = "nameplateShowOnlyNameForFriendlyPlayerUnits",
			value = 1,
		},
		{
			name = "友方玩家姓名版仅名字职业染色",
			key = "nameplateUseClassColorForFriendlyPlayerUnitNames",
			value = 1,
		},
		{
			name = "友方玩家姓名版：仆从",
			key = "nameplateShowFriendlyMinions",
			value = 0,
		},
		{
			name = "友方NPC姓名版",
			key = "nameplateShowFriendlyNpcs",
			value = 0,
		},
		{
			name = "显示屏幕外的姓名版",
			key = "nameplateShowOffscreen",
			value = 0,
		},
		{
			name = "堆叠姓名版",
			doc = "0 = 无, 1 = 敌方单位, 2 = 友方单位, value = 所有你想要显示的图标数值之和",
			key = "nameplateStackingTypes",
			value = 1,
			apply = SetCVarBitfieldMask
		},
		{
			name = "尺寸",
			doc = "取值：1 - 5, 步长：1",
			key = "nameplateSize",
			value = 1,
		},
		{
			name = "增益/减益尺寸",
			doc = "取值：0.7 - 1.4, 步长：0.1",
			key = "nameplateAuraScale",
			value = 1,
		},
		{
			name = "样式",
			doc = "0 = 现代, 1 = 细条, 2 = 块状条, 3 = 极简生命条, 4 = 块状施法条, 5 = 传统红",
			key = "nameplateStyle",
			value = 2,
		},
		{
			name = "姓名版信息",
			doc = "0 = 无, 1 = 生命值百分比, 2 = 生命值数值, 4 = 稀有度图标, value = 所有你想要显示的图标数值之和",
			key = "nameplateInfoDisplay",			
			value = 1,
			apply = SetCVarBitfieldMask
		},
		{	
			name = "施法条信息",
			doc = "0 = 无, 1 = 法术名, 2 = 法术图标, 4 = 法术目标, 8 = 标亮重要施法, 16 = 被敌方选为目标时高亮, value = 所有你想要显示的图标数值之和",
			key = "nameplateCastBarDisplay",			
			value = 3,
			apply = SetCVarBitfieldMask
		},
		{	
			name = "仇恨显示",
			doc = "0 = 无, 1 = 渐进式, 2 = 闪光, 4 = 生命条颜色亮, value = 所有你想要显示的图标数值之和",
			key = "nameplateThreatDisplay",			
			value = 4,
			apply = SetCVarBitfieldMask
		},
		{	
			name = "敌方NPC的增减益状态",
			doc = "0 = 无, 1 = 怪物增益, 2 = 个人减益, 4 = 共享控制, value = 所有你想要显示的图标数值之和",
			key = "nameplateEnemyNpcAuraDisplay",			
			value = 2,
			apply = SetCVarBitfieldMask
		},
		{	
			name = "敌方玩家的增减益状态",
			doc = "0 = 无, 1 = 敌方增益, 2 = 个人减益, 4 = 重要减益, value = 所有你想要显示的图标数值之和",
			key = "nameplateEnemyPlayerAuraDisplay",			
			value = 2,
			apply = SetCVarBitfieldMask
		},
		{	
			name = "友方玩家的增减益状态",
			doc = "0 = 无, 1 = 个人增益, 2 = 敌方减益, 4 = 重要减益, value = 所有你想要显示的图标数值之和",
			key = "nameplateFriendlyPlayerAuraDisplay",			
			value = 0,
			apply = SetCVarBitfieldMask
		},
		{
			name = "减益距离",
			doc = "取值：0 - 50, 步长：1",
			key = "nameplateDebuffPadding",
			value = 2,
		},
		{	
			name = "简化姓名版",
			doc = "0 = 无, 1 = 仆从, 2 = 次要, 4 = 友方玩家, 8 = 友方NPC, value = 所有你想要显示的图标数值之和",
			key = "nameplateSimplifiedTypes",			
			value = 7,
			apply = SetCVarBitfieldMask
		},
	}
	
	return BuildSettings(variable)
end



--[[
	界面
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Shared/Mainline/Text.lua
--]]
local function Text()
	local variable = {
		{
			name = "文字缩放比例",
			doc = "0.8571 = 小号, 1 = 中号, 1.1429 = 大号, 1.4286 = 特大, 1.7143 = 超大, 2 = 巨大",
			key = "userFontScale",
			value = 1,
		},
		{
			name = "任务文本颜色反差",
			doc = "0 = 默认, 1 = 棕色, 2 = 白色, 3 = 灰色, 4 = 黑色",
			key = "questTextContrast",
			value = 0,
			
		}	
	}
	
	return BuildSettings(variable)
end


--[[
	综合
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/Accessibility.lua
--]]
local function Accessibility()
	local variable = {
		{
			name = "显示移动框",
			key = "enableMovePad",
			value = 0,
		},
		{
			name = "开启光敏模式",
			key = "overrideScreenFlash",
			value = 0,
		},
		{
			name = "最小角色名尺寸",
			doc = "取值：0 - 64, 步长：2",
			key = "WorldTextMinSize",
			value = 0,			
		},
		{
			name = "动态眩晕",
			value = false,
			apply = function(self)
				SetCVar("CameraKeepCharacterCentered", not self.value)
				SetCVar("CameraReduceUnexpectedMovement", self.value)
			end
		},
		{
			name = "视角晃动",
			doc = "0 = 无, 0.25 = 低, 1 = 高",
			key = "ShakeStrengthCamera",
			value = 1,			
		},
		{
			name = "鼠标指针大小",
			doc = "-1 = 默认, 0 = 32x32, 1 = 48x48, 2 = 64x64, 3 = 96x96, 4 = 128x128",
			key = "cursorSizePreferred",
			value = -1,			
		},
		-- [[ 自身高亮 ]]
		-- [[ 被遮蔽时显示轮廓 ]]
		-- [[ 法术警报不透明度 ]]
		-- [[ 按住施法 ]]
		-- [[ 蓄力法术输入 ]]
		{
			name = "动作瞄准提示信息",
			value = false,
			apply = function(self)
				SetCVar("SoftTargetTooltipEnemy", self.value)
				SetCVar("SoftTargetTooltipInteract", self.value)
			end
		},
		{
			name = "交互按键图标",
			doc = "1 = 仅限NPC(默认), 2 = 显示全部, 3 = 全不显示",
			value = 2,			
			apply = function(self)
				if self.value == 1 then
					SetCVar("SoftTargetIconEnemy", "0")
					SetCVar("SoftTargetIconInteract", "1")
					SetCVar("SoftTargetIconGameObject", "0")
					SetCVar("SoftTargetLowPriorityIcons", "0")
				elseif self.value == 2 then
					SetCVar("SoftTargetIconEnemy", "1")
					SetCVar("SoftTargetIconInteract", "1")
					SetCVar("SoftTargetIconGameObject", "1")
					SetCVar("SoftTargetLowPriorityIcons", "1")
				elseif self.value == 3 then
					SetCVar("SoftTargetIconEnemy", "0")
					SetCVar("SoftTargetIconInteract", "0")
					SetCVar("SoftTargetIconGameObject", "0")
					SetCVar("SoftTargetLowPriorityIcons", "0")
				end
			end
		},
		{
			name = "蜘蛛恐惧症模式",
			key = "arachnophobiaMode",
			value = 0,
		},
	}
	
	return BuildSettings(variable)
end


--[[
	颜色
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/Colorblind.lua
--]]
local function Colorblind()	
	local variable = {
		{
			name = "开启色盲模式界面",
			key = "colorblindMode",
			value = 0,
		},
		{
			name = "色盲过滤器",
			doc = "0 = 无, 1 = 红色色盲模式, 2 = 绿色色盲模式, 3 = 蓝色色盲模式",
			key = "colorblindSimulator",
			value = 0,			
		},
		{
			name = "强度",
			doc = "取值：0 - 1, 步长：0.05",
			key = "colorblindWeaknessFactor",
			value = 0,			
		},
		-- [[ 物品品质 ]]
	}
	
	return BuildSettings(variable)
end


--[[
	音频辅助
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/AudioAssist.lua
--]]
local function AudioAssist()
	
	-- 辅助函数：判断玩家是否拥有 "资源 2"
	local function GetResourceSettingFormattedString(formatString, primary)
		local _resource1PowerType, resource1PowerToken = UnitPowerType("player");
		resource1PowerName = resource1PowerToken and _G[resource1PowerToken];

		local _resource2PowerType, resource2PowerToken = GetUnitSecondaryPowerInfo("player");
		resource2PowerName = resource2PowerToken and _G[resource2PowerToken];

		local powerName = primary and resource1PowerName or resource2PowerName;
		if powerName then
			return formatString:format(powerName);
		end

		-- Important:
		-- This empty string return is what causes the resource settings to hide if the player's spec doesn't use a resource (see IsResource1Allowed and IsResource2Allowed)
		-- It must return a string (rather than nil) or ErrorIfInvalidSettingArguments will error
		return "";
	end

	local isPrimaryNo = false;
	local function GetResource2Label()
		return GetResourceSettingFormattedString(CAA_SAY_PLAYER_RESOURCE_LABEL, isPrimaryNo);
	end

	local function IsResource2Allowed()
		return GetResource2Label() ~= "";
	end

	local variable = {
		{
			name = "语音聊天文字转录",
			key = "speechToText",
			value = 0,
		},
		{
			name = "大声朗读聊天文本",
			key = "textToSpeech",
			value = 0,
		},
		{
			name = "启动战斗音频预警",
			key = "CAAEnabled",
			value = 0,
		},
		{
			name = "战斗播报语音",
			doc = "0 = 中文, 1 = 英文, 非固定 查询方法：/dump C_VoiceChat.GetTtsVoices()",
			key = "CAAVoice",
			value = 0,
		},
		{
			name = "战斗播报语速",
			doc = "取值：-10 - 10, 步长：1",
			key = "PROXY_CAA_SPEED",
			value = 1,
			apply = DefaultSetValue
		},
		{
			name = "战斗播报音量",
			doc = "取值：0 - 100, 步长：1",
			key = "PROXY_CAA_VOLUME",
			value = 1,
			apply = DefaultSetValue
		},
		{
			name = "播报战斗开始",
			doc = "0 = 关闭, 1 = 语音：战斗开始",
			key = "CAASayCombatStart",
			value = 0,
		},
		{
			name = "播报战斗结束",
			doc = "0 = 关闭, 1 = 语音：战斗结束",
			key = "CAASayCombatEnd",
			value = 0,
		},
		{
			name = "播报你的生命值",
			doc = "0 = 关闭, 1 = 每10%, 2 = 每20%, 3 = 每30%, 4 = 每40%, 5 = 每50%",
			key = "CAAPlayerHealthPercent",
			value = 0,
		},
		{
			name = "格式",
			doc = "0 = 生命值百分之20, 1 = 生命值20, 2 = 生命值2, 3 = 百分之20, 4 = 20, 5 = 2",
			key = "PROXY_CAA_PLAYER_HEALTH_FORMAT",
			value = 0,
			apply = DefaultSetValue
		},
		{
			name = "间隔",
			doc = "取值：0 - 5, 步长：1",
			key = "PROXY_CAA_PLAYER_HEALTH_THROTTLE",
			value = 0,
			apply = DefaultSetValue
		},
		{
			name = "播报目标名称",
			key = "CAASayTargetName",
			value = 0,
		},
		{
			name = "被选中时语音播报",
			doc = "0 = 关闭, 1 = 语音：威胁, 2 = 语音：你被选中了, 3 = 语音：被狗头选中了",
			key = "PROXY_CAA_SAY_IF_TARGETED",
			value = 0,
			apply = DefaultSetValue
		},
		{
			name = "播报目标生命值",
			doc = "0 = 关闭, 1 = 每10%, 2 = 每20%, 3 = 每30%, 4 = 每40%, 5 = 每50%",
			key = "CAATargetHealthPercent",
			value = 0,
		},
		{
			name = "格式",
			doc = "0 = 生命值百分之20, 1 = 生命值20, 2 = 生命值2, 3 = 百分之20, 4 = 20, 5 = 2, 6 = 目标百分之20, 7 = 目标20, 8 = 目标2",
			key = "PROXY_CAA_PLAYER_HEALTH_FORMAT",
			value = 0,
			apply = DefaultSetValue
		},
		{
			name = "目标死亡时",
			doc = "0 = 使用目标生命值格式, 1 = 语音：目标死亡",
			key = "CAATargetDeathBehavior",
			value = 0,
		},
		{
			name = "间隔",
			doc = "取值：0 - 5, 步长：1",
			key = "PROXY_CAA_TARGET_HEALTH_THROTTLE",
			value = 0,
			apply = DefaultSetValue
		},
		{
			name = "播报队伍生命值",
			doc = "0 = 关闭, 1 = 低于100%, 2 = 低于90%, 3 = 低于80%, 4 = 低于70%, 5 = 低于60%, 6 = 低于50%, 7 = 低于40%, 8 = 低于30%, 9 = 低于20%, 10 = 低于10%",
			key = "PROXY_CAA_PLAYER_HEALTH_FORMAT",
			value = 0,
			apply = DefaultSetValue
		},
		{
			name = "频率",
			doc = "取值：-10 - 10, 步长：1",
			key = "CAAPartyHealthFrequency",
			value = 1,
		},
		{	-- "资源 1" 根据职业专精而改变
			name = "播报你的资源 1",
			doc = "0 = 关闭, 1 = 每10%, 2 = 每20%, 3 = 每30%, 4 = 每40%, 5 = 每50%",
			key = "PROXY_CAA_PLAYER_RESOURCE_1_PERCENT",
			value = 1,
			apply = DefaultSetValue
		},
		{
			name = "格式",
			doc = "0 = 生命值百分之20, 1 = 生命值20, 2 = 生命值2, 3 = 百分之20, 4 = 20, 5 = 2",
			key = "PROXY_CAA_PLAYER_RESOURCE_1_FORMAT",
			value = 0,
			apply = DefaultSetValue
		},
		{
			name = "间隔",
			doc = "取值：0 - 5, 步长：1",
			key = "PROXY_CAA_PLAYER_RESOURCE_1_THROTTLE",
			value = 0,
			apply = DefaultSetValue
		},
		{	-- "资源 2" 根据职业专精而改变
			name = "播报你的资源 2",
			doc = "0 = 关闭, 1 = 每10%, 2 = 每20%, 3 = 每30%, 4 = 每40%, 5 = 每50%",
			key = "PROXY_CAA_PLAYER_RESOURCE_2_PERCENT",
			value = 0,
			apply = function(self)
			
				-- 如果存在 "资源 2"
				if ( IsResource2Allowed() ) then
					DefaultSetValue(self)
				end
			end
		},
		{
			name = "格式",
			doc = "0 = 生命值百分之20, 1 = 生命值20, 2 = 生命值2, 3 = 百分之20, 4 = 20, 5 = 2",
			key = "PROXY_CAA_PLAYER_RESOURCE_2_FORMAT",
			value = 0,
			apply = function(self)
			
				-- 如果存在 "资源 2"
				if ( IsResource2Allowed() ) then
					DefaultSetValue(self)
				end
			end
		},
		{
			name = "间隔",
			doc = "取值：0 - 5, 步长：1",
			key = "PROXY_CAA_PLAYER_RESOURCE_2_THROTTLE",
			value = 0,
			apply = function(self)
			
				-- 如果存在 "资源 2"
				if ( IsResource2Allowed() ) then
					DefaultSetValue(self)
				end
			end
		},
		{
			name = "播报你的施法",
			doc = "0 = 关闭, 1 = 施法开始时, 2 = 施法结束时",
			key = "CAAPlayerCastMode",
			value = 0,
		},
		{
			name = "格式",
			doc = "0 = 正在施放火球术, 1 = 施放火球术, 2 = 正在施放, 3 = 施放, 4 = 火球术",
			key = "PROXY_CAA_PLAYER_CAST_FORMAT",
			value = 0,
			apply = DefaultSetValue
		},
		{
			name = "最小施法时间",
			doc = "取值：0 - 5, 步长：0.5",
			key = "CAAPlayerCastMinTime",
			value = 0,
		},
		{
			name = "间隔",
			doc = "取值：0 - 5, 步长：1",
			key = "PROXY_CAA_PLAYER_CAST_THROTTLE",
			value = 0,
			apply = DefaultSetValue
		},
		{
			name = "播报目标施法",
			doc = "0 = 关闭, 1 = 施法开始时, 2 = 施法结束时",
			key = "CAATargetCastMode",
			value = 0,
		},
		{
			name = "格式",
			doc = "0 = 目标正在施放火球术, 1 = 目标施放火球术, 2 = 正在施放火球术, 3 = 施放火球术, 4 = 正在施放, 5 = 施放, 6 = 火球术",
			key = "PROXY_CAA_TARGET_CAST_FORMAT",
			value = 0,
			apply = DefaultSetValue
		},
		{
			name = "最小施法时间",
			doc = "取值：0 - 5, 步长：0.5",
			key = "CAATargetCastMinTime",
			value = 0,
		},
		{
			name = "间隔",
			doc = "取值：0 - 5, 步长：1",
			key = "PROXY_CAA_TARGET_CAST_THROTTLE",
			value = 0,
			apply = DefaultSetValue
		},
		{
			name = "可打断施法警报",
			doc = "0 = 关闭, 1 = 语音：可打断施法",
			key = "CAAInterruptCast",
			value = 0,
		},
		{
			name = "成功打断警报",
			doc = "0 = 关闭, 1 = 语音：目标已打断",
			key = "CAAInterruptCastSuccess",
			value = 1,
		},
	}
	
	return BuildSettings(variable)
end


--[[
	坐骑
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/Mounts.lua
--]]
local function Mounts()
	local variable = {
		{
			name = "眩晕症",
			doc = "4 = 默认, 3 = 变暗和圆环, 2 = 地表变暗, 1 = 聚焦圆环",
			value = 4,			
			apply = function(self)
				if self.value == 1 then
					SetCVar("motionSicknessFocalCircle", "1")
					SetCVar("motionSicknessLandscapeDarkening", "0")
				elseif self.value == 2 then
					SetCVar("motionSicknessFocalCircle", "0")
					SetCVar("motionSicknessLandscapeDarkening", "1")
				elseif self.value == 3 then
					SetCVar("motionSicknessFocalCircle", "1")
					SetCVar("motionSicknessLandscapeDarkening", "1")
				elseif self.value == 4 then
					SetCVar("motionSicknessFocalCircle", "0")
					SetCVar("motionSicknessLandscapeDarkening", "0")
				end
			end
		},
		{
			name = "驭空术屏幕效果",
			key = "DisableAdvancedFlyingFullScreenEffects",
			value = 1,
		},
		{
			name = "驭空术速度效果",
			key = "DisableAdvancedFlyingVelocityVFX",
			value = 1,
		},
		{
			name = "倾角控制",
			doc = "3 = 默认, 2 = 后/上, 1 = 前/上",
			key = "advFlyPitchControl",
			value = 3,			
		},
		{
			name = "防抖倾角输入",
			key = "advFlyPitchControlGroundDebounce",
			value = 0,			
		},
		{
			name = "键盘倾斜镜头跟随",
			doc = "取值：10 - 30, 步长：1",
			key = "advFlyPitchControlCameraChase",
			value = 20,
		},
		{
			name = "最低键盘倾斜速度",
			doc = "取值：1 - 10, 步长：0.5",
			key = "advFlyKeyboardMinPitchFactor",
			value = 2.5,
		},
		{
			name = "最高键盘倾斜速度",
			doc = "取值：1 - 10, 步长：0.5",
			key = "advFlyKeyboardMaxPitchFactor",
			value = 5,
		},
		{
			name = "最低键盘转向速度",
			doc = "取值：1 - 10, 步长：0.5",
			key = "advFlyKeyboardMinTurnFactor",
			value = 5,
		},
		{
			name = "最高键盘转向速度",
			doc = "取值：1 - 10, 步长：0.5",
			key = "advFlyKeyboardMaxTurnFactor",
			value = 8,			
		},
	}
	
	return BuildSettings(variable)
end


--[[
	字幕
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Frame/Subtitles.lua
--]]
local function Subtitles()
	local variable = {
		{
			name = "动画字幕",
			key = "movieSubtitle",
			value = 1,
		},
		{
			name = "字幕背景",
			doc = "1 = 无（默认）, 2 = 暗色, 3 = 浅色",
			key = "movieSubtitleBackground",
			value = 1,			
		},
		{
			name = "背景不透明度",
			doc = "取值：50 - 100, 步长：10",
			key = "movieSubtitleBackgroundAlpha",
			value = 100,			
		},
	}
	
	return BuildSettings(variable)
end


--[[
	图形
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Shared/Graphics.lua
--]]
local function Graphics()

    -- 【辅助函数】获取当前显示器的原生（最大）分辨率
    local function GetMonitorNativeResolution()
        local monitorIndex = tonumber(GetCVar("gxMonitor")) or 0
        -- 第二个参数 true 代表获取“全屏/最大化”模式下的支持分辨率列表
        -- 这样能拿到显示器支持的所有分辨率，不受当前窗口大小影响
        local sizes = C_VideoOptions.GetGameWindowSizes(monitorIndex, true)
        
        local maxWidth, maxHeight = 0, 0
        
        -- 遍历列表，找到宽度的最大值（即原生分辨率）
        if sizes then
            for _, size in ipairs(sizes) do
                if size.x > maxWidth then
                    maxWidth = size.x
                    maxHeight = size.y
                end
            end
        end
        
        -- 如果没取到（极少见），保底返回 1920x1080
        if maxWidth == 0 then return 1920, 1080 end
        
        return maxWidth, maxHeight
    end
	
	local variable = {
		{
			name = "显示器",
			key = "gxMonitor",
			value = 0,
		},
		{
			name = "显示模式",
			key = "gxMaximize",
			value = 1,
		},
		{
			name = "分辨率",
			apply = function()
				local width, height = GetMonitorNativeResolution()
				C_VideoOptions.SetGameWindowSize(width, height)
			end
		},
		{
			name = "渲染倍数",
			key = "RenderScale",
			value = 1,
		},
		{
			name = "使用UI缩放",
			key = "useUiScale",
			value = 0,
		},
		{
			name = "UI缩放",
			key = "uiscale",
			value = 1,
		},
		{
			name = "垂直同步",
			key = "vsync",
			value = 0,
		},
		{
			name = "低延迟模式",
			doc = "0 = 关闭, 1 = 内置, 2 = NVIDIA Reflex, 3 = NVIDIA Reflex + Boost",
			key = "LowLatencyMode",
			value = 3,			
		},
		{
			name = "抗锯齿",
			doc = [[
				0 = 无, 1 = 基于图像的技术, 2 = 多重采样技术, 3 = 高级
				ffxAntiAliasingMode = 基于图像的技术	0 = 无, 1 = FXAA低, 2 = FXAA高, 3 = CMAA, 4 = CMAA 2
				MSAAQuality = 多重采样技术	无：0	色彩 2x / 景深 2x：1	色彩 4x / 景深 4x：2	色彩 8x / 景深 8x：3
			]],
			value = 0,
			apply = function(self)
				if self.value == 0 then
					SetCVar("ffxAntiAliasingMode", 0)
					SetCVar("MSAAQuality", 0)
				elseif self.value == 1 then
					SetCVar("ffxAntiAliasingMode", 4)
					SetCVar("MSAAQuality", 0)
				elseif self.value == 2 then
					SetCVar("ffxAntiAliasingMode", 0)
					SetCVar("MSAAQuality", 1)
				elseif self.value == 3 then
					SetCVar("ffxAntiAliasingMode", 1)
					SetCVar("MSAAQuality", 1)
				end			
			end			
		},
		{
			name = "多重采样测试",
			doc = "仅限 多重采样技术 启用时设置才生效",
			key = "msaaAlphaTest",
			value = 1,			
		},
		{
			name = "镜头视野范围",
			doc = "取值：50 - 90, 步长：5",
			key = "cameraFov",
			value = 90,			
		},
		-- 基础
		{
			name = "阴影质量",
			doc = "0 = 低, 1 = 普通, 2 = 优良, 3 = 高, 4 = 极佳, 5 = 最高",
			key = "graphicsShadowQuality",
			value = 1,			
		},
		{
			name = "液体细节",
			doc = "0 = 低, 1 = 普通, 2 = 优良, 3 = 高",
			key = "graphicsLiquidDetail",
			value = 1,			
		},
		{
			name = "粒子密度",
			doc = "0 = 关闭, 1 = 低, 2 = 普通, 3 = 优良, 4 = 高, 5 = 极佳",
			key = "graphicsParticleDensity",
			value = 1,			
		},	
		{
			name = "SSAO",
			doc = "0 = 关闭, 1 = 低, 2 = 优良, 3 = 高, 4 = 极佳",
			key = "graphicsSSAO",
			value = 1,			
		},	
		{
			name = "景深效果",
			doc = "0 = 关闭, 1 = 低, 2 = 优良, 3 = 高",
			key = "graphicsDepthEffects",
			value = 1,			
		},	
		{
			name = "计算效果",
			doc = "0 = 关闭, 1 = 低, 2 = 优良, 3 = 高, 4 = 极佳",
			key = "graphicsComputeEffects",
			value = 1,			
		},
		{
			name = "轮廓线模式",
			doc = "关闭：0	优良：1	高：2",
			key = "graphicsOutlineMode",
			value = 2,			
		},
		{
			name = "材质分辨率",
			doc = "0 = 低, 1 = 普通, 2 = 高",
			key = "graphicsTextureResolution",
			value = 2,			
		},
		{
			name = "法术密度",
			doc = "0 = 重要, 1 = 减少, 2 = 所有",
			key = "graphicsSpellDensity",
			value = 1,			
		},
		{
			name = "材质投射",
			key = "graphicsProjectedTextures",
			value = 0,
		},
		{
			name = "视野距离",
			doc = "取值：0 - 9, 步长：1",
			key = "graphicsViewDistance",
			value = 10,			
		},
		{
			name = "环境细节",
			doc = "取值：0 - 9, 步长：1",
			key = "graphicsEnvironmentDetail",
			value = 6,
		},
		{
			name = "地表景观",
			doc = "取值：0 - 9, 步长：1",
			key = "graphicsGroundClutter",
			value = 6,
		},
		-- 团队副本和战场
		{
			name = "三倍缓冲",
			doc = "3 = 启用, 2 = 禁用",
			key = "gxMaxFrameLatency",
			value = 2,			
		},	
		{
			name = "材质过滤",
			doc = "0 = 双线性, 1 = 三线性, 2 = 2x各向异性, 3 = 4x各向异性, 4 = 8x各向异性, 5 = 16x各向异性",
			key = "textureFilteringMode",
			value = 1,			
		},	
		{
			name = "光线追踪阴影",
			doc = "0 = 关闭, 1 = 普通, 2 = 优良, 3 = 高",
			key = "shadowrt",
			value = 0,			
		},	
		{
			name = "重新采样品质",
			doc = "0 = 点, 1 = 双线性, 2 = 三线性, 3 = FidelityFX Super Resolution 1.0",
			key = "ResampleQuality",
			value = 1,			
		},
		{
			name = "VRS模式",
			doc = "0 = 关闭, 1 = 普通, 2 = 激进",
			key = "vrsValar",
			value = 0,			
		},
		{
			name = "图形接口",
			doc = "d3d11 = DirectX 11, d3d12 = DirectX 12, Auto = 自动检测",
			key = "gxapi",
			value = "d3d12",			
		},	
		{
			name = "物理交互",
			doc = "0 = 无, 1 = 仅限玩家, 2 = 玩家与NPC",
			key = "physicsLevel",
			value = 2,			
		},	
		{
			name = "显卡",
			doc = '"" = 自动检测, NVIDIA GeForce RTX 3060',
			key = "gxAdapter",
			value = "",
		},
		{
			name = "最高前台帧数",
			apply = function(self)
				SetCVar("useMaxFPS", 0)	
				SetCVar("maxFPS", 200)
			end	
		},	
		{
			name = "最高后台帧数",
			apply = function(self)
				SetCVar("useMaxFPSBk", 1)
				SetCVar("maxFPSBk", 60)
			end	
		},
		{
			name = "目标帧数",
			apply = function(self)
				SetCVar("useTargetFPS", 1)
				SetCVar("targetFPS", 60)
			end	
		},
		{
			name = "重新采样锐度",
			doc = "取值：0 - 2, 步长：0.1, 0 = 满强度, -1 = 禁用",
			key = "ResampleSharpness",
			value = 0.2,			
		},
		{
			name = "对比度",
			doc = "取值：0 - 100, 步长：1",
			key = "Contrast",
			value = 50,			
		},
		{
			name = "亮度",
			doc = "取值：0 - 100, 步长：1",
			key = "Brightness",
			value = 50,
		},
		{
			name = "伽马值",
			doc = "取值：0.3 - 2.8, 步长：0.1",
			key = "Gamma",
			value = 1,			
		},
		{
			name = "可选的GPU功能",
			key = "GxCompatOptionalGpuFeatures",
			value = 1,
		},
		{
			name = "异步资源生成",
			key = "GxCompatDeviceMultiThreading",
			value = 1,
		},
		{
			name = "多线程渲染",
			key = "GxCompatCommandListMultiThreading",
			value = 1,
		},
		{
			name = "进阶工作提交",
			key = "GxCompatWorkSubmitOptimizations",
			value = 1,
		},		
		{
			name = "重新启动图形引擎",
			apply = function()
				RestartGx()
			end
		},	
	}
	
	return BuildSettings(variable)
end


--[[
	音频
	
	https://github.com/Gethe/wow-ui-source/blob/live/Interface/AddOns/Blizzard_SettingsDefinitions_Shared/Audio.lua
--]]
local function Audio()
	
	local variable = {
		{
			name = "开启音效",
			key = "Sound_EnableAllSound",
			value = 1,
		},
		{
			name = "输出设备",
			doc = "默认：0",
			key = "Sound_OutputDriverIndex",
			value = 0,			
		},
		{
			name = "主音量",
			doc = "取值：0 - 1, 步长：0.05",
			key = "Sound_MasterVolume",
			value = 0.1,			
		},
		{
			name = "音乐",
			doc = "取值：0 - 1, 步长：0.05",
			key = "Sound_MusicVolume",
			value = 0.2,
		},
		{
			name = "效果",
			doc = "取值：0 - 1, 步长：0.05",
			key = "Sound_SFXVolume",
			value = 0.3,
		},
		{
			name = "环境音",
			doc = "取值：0 - 1, 步长：0.05",
			key = "Sound_AmbienceVolume",
			value = 0.2,
		},
		{
			name = "对话",
			doc = "取值：0 - 1, 步长：0.05",
			key = "Sound_DialogVolume",
			value = 0.2,
		},
		{
			name = "音乐",
			key = "Sound_EnableMusic",
			value = 0.3,
		},
		{
			name = "音乐循环",
			key = "Sound_ZoneMusicNoDelay",
			value = 1,
		},
		{
			name = "宠物对战音乐",
			key = "Sound_EnablePetBattleMusic",
			value = 1,
		},
		{
			name = "声音效果",
			key = "Sound_EnableSFX",
			value = 1,
		},
		{
			name = "启用宠物音效",
			key = "Sound_EnablePetSounds",
			value = 0,
		},
		{
			name = "表情音效",
			key = "Sound_EnableEmoteSounds",
			value = 1,
		},
		{
			name = "游戏音效",
			doc = "取值：0 - 1, 步长：0.05",
			key = "Sound_GameplaySFX",
			value = 1,
		},
		{
			name = "对话",
			key = "Sound_EnableDialog",
			value = 1,
		},
		{
			name = "错误提示",
			key = "Sound_EnableErrorSpeech",
			value = 0,
		},
		{
			name = "环境音效",
			key = "Sound_EnableAmbience",
			value = 1,
		},
		{
			name = "背景声音",
			key = "Sound_EnableSoundWhenGameIsInBG",
			value = 1,
		},
		{
			name = "启用混响",
			key = "Sound_EnableReverb",
			value = 1,
		},
		{
			name = "距离过滤",
			key = "Sound_EnablePositionalLowPassFilter",
			value = 1,
		},
		{
			name = "半音通道",
			doc = "取值：20 - 128, 步长：1",
			key = "Sound_NumChannels",
			value = 64,			
		},
		{
			name = "音频缓存大小",
			doc = "67108864 = 小（64MB）, 134217728 = 大（128MB）",
			key = "Sound_MaxCacheSizeInBytes",
			value = 134217728,			
		},
		{
			name = "首领预警音效",
			key = "Sound_EnableEncounterWarningsSounds ",
			value = 1,			
		},
		{
			name = "首领预警音量",
			doc = "取值：0 - 1, 步长：0.05",
			key = "Sound_EncounterWarningsVolume",
			value = 1,			
		},
		-- 语音聊天
	}
	
	return BuildSettings(variable)
end


local function InterfaceOptions()

	-- 默认设置
	-- SettingsPanel:SetAllSettingsToDefaults()
	
	-- 注册所有分类
	local variable = {
		Controls,			-- 控制
		Interface,			-- 界面
		ActionBars,			-- 动作条
		Combat,				-- 战斗
		Social,				-- 社交
		PingSystem,			-- 信号系统
		AdvancedOptions,	-- 游戏增强
		Nameplates,			-- 姓名版
		Text,				-- 界面
		Accessibility,		-- 综合
		Colorblind,			-- 颜色
		AudioAssist,		-- 音频辅助
		Mounts,				-- 坐骑
		Subtitles,			-- 字幕
		Graphics,			-- 图形
		Audio,				-- 音频
	}
	
	-- 合成一张大表
	local Settings = {}
	for _, factory in ipairs(variable) do
		for _, item in ipairs( factory() ) do
			table.insert(Settings, item)
		end
	end
	
	-- 遍历注册设置游戏界面选项
	for _, setting in ipairs(Settings) do
		local success, err = pcall(setting.apply, setting)
		if not success then
			DEFAULT_CHAT_FRAME:AddMessage(format("设置：%s 失败: %s", setting.name, err))
		end
	end
end


-- 定义第二个确认框（用于延迟重载）
StaticPopupDialogs.CONFIRM_RELOAD = {
    text = "设置已完成！\n请点击确定重载界面以生效。",
    button1 = "立即重载",
    button2 = "稍后手动",
    OnAccept = function()
        ReloadUI()
    end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = true,
    preferredIndex = 5,
}

-- 定义第一个设置框
StaticPopupDialogs.OPTIONS = {
    text = "是否应用推荐的游戏选项设置？",
    button1 = ACCEPT,
    button2 = CANCEL,
    OnAccept = function()
        InterfaceOptions()		
        C_Timer.After(2, function()
            StaticPopup_Show("CONFIRM_RELOAD")
        end)
    end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = true,
    preferredIndex = 5,
}

SlashCmdList["IFO"] = function()
    StaticPopup_Show("OPTIONS")
end
SLASH_IFO1 = "/ifo"

local UpdateCvarButton = CreateFrame("Button", nil, SettingsPanel, "UIPanelButtonTemplate")
UpdateCvarButton:SetPoint("BOTTOMLEFT", SettingsPanel, 550, 16)
UpdateCvarButton:SetSize(140, 22)
UpdateCvarButton:SetText("Cvar推荐设置")
UpdateCvarButton:SetScript("OnClick", function()
    StaticPopup_Show("OPTIONS")
end)