-- @Author: Webster
-- @Date:   2015-06-06 13:17:37
-- @Last Modified by:   Webster
-- @Last Modified time: 2015-06-06 13:59:54


local UI = 	{
	["Lowest"] = {
		["ActionBar1"]         = "ݼ",
		["ActionBar2"]         = "ݼ",
		["ActionBar3"]         = "Զݼһ",
		["ActionBar4"]         = "Զݼ",
		["CombatTextWnd"]      = "սϢ",
		["FullScreenSFX"]      = "ȫЧ",
		["GlobalEventHandler"] = "GlobalEventHandler",
		["Hand"]               = "ƶ",
		["Scene"]              = "ϵͳϷ",
	},
	["Lowest1"] = {
		["ChatTitleBG"]  = "Ƶ౳",
		["MainBarPanel"] = "ݼ",
	},
	["Lowest2"] = {
		["ChatPanel1"] = "Ƶ1",
		["ChatPanel2"] = "Ƶ2",
		["ChatPanel3"] = "Ƶ3",
		["ChatPanel4"] = "Ƶ4",
		["ChatPanel5"] = "Ƶ5",
		["ChatPanel6"] = "Ƶ6",
		["EditBox"]    = "Ϣ",
	},
	["Normal"] = {
		["AnimationMgr"]        = "AnimationMgr",
		["BuffList"]            = "״̬б",
		["CampActiveTime"]      = "Ӫʱ",
		["CampPanel"]           = "Ӫʿ",
		["CharacterPanel"]      = "װ",
		["CraftPanel"]          = "",
		["DebuffList"]          = "״̬б",
		["DialoguePanel"]       = "NPCԻ",
		["DurabilityPanel"]     = "װ־ʾ",
		["ExpLine"]             = "ﾭ",
		["GuildMainPanel"]      = "Ϣ",
		["LootListExSingle"]    = "Ӳ_ʰȡ",
		["MainMessageLine"]     = "ĻϢ",
		["Matrix"]              = "Matrix",
		["Player"]              = "ͷ",
		["QuestAcceptPanel"]    = "ȡԻ",
		["QuestPanel"]          = "鿴",
		["ReputationIntroduce"] = "ϸ",
		["SprintPower"]         = "Ṧֵͼ",
		["Teammate"]            = "ٷŶ",
		["TopMenu"]             = "Ļͼ˵",
		["Minimap"]             = "Сͼ",
		["SystemMenu_Left"]     = "Ļͼ˵",
		["SystemMenu_Right"]    = "Ļͼ˵",
		["DBM"]                 = "DBM_Core",
		["DBM_UI"]              = "DBM",
		["GKP"]                 = "ż¼",
		["TargetTarget"]        = "ĿĿ",
	},
	["Normal1"] = {
		["GKP_Record"] = "GKP¼",
		["BL_UI"]      = "DBM_ͨBUFFб",
		["CA_UI"]      = "DBM_뱨",
	},
	["Normal2"] = {
		["ST_UI"] = "DBM_ʱ",
	},
	["Topmost"] = {
		["BreatheBar"]       = "BreatheBar",
		["LoginMotp"]        = "LoginMotp",

		["OTActionBar"]      = "ʾ",
		["TargetMark"]       = "ٷĿͷ",
	},
	["Topmost1"] = {
		["BattleTipPanel"]       = "սʾϢ",
		["PopupMenuPanel"]       = "Ϸе˵",
		["SceneCampTip"]         = "ӪʾϢ",
		["TipPanel_Normal"]      = "ĻұʾϢ",
		["TraceButton"]          = "ĻҲ˵ͼ",
	},
	["Topmost2"] = {
		["Announce"]        = "ϵͳʾ",
		["EnterAreaTip"]    = "EnterAreaTip",
		["GMAnnouncePanel"] = "ϵͳ",
		["LoadingPanel"]    = "Ϸؽ",
	}
}

local function GetMeun(ui)
	local menu, frames = { szOption = ui }, {}
	local frame = Station.Lookup(ui):GetFirstChild()
	while frame do
		table.insert(frames, { szName = frame:GetName() })
		frame = frame:GetNext()
	end
	table.sort(frames, function(a, b) return a.szName < b.szName end)
	for k, v in ipairs(frames) do
		local frame = Station.Lookup(ui .. "/" .. v.szName)
		table.insert(menu, {
			szOption = UI[ui][v.szName] and v.szName .. "" .. UI[ui][v.szName]  .. "" or  v.szName,
			bCheck = true,
			bChecked = frame:IsVisible(),
			rgb = frame:IsAddOn() and { 255, 255, 255 } or { 255, 255, 0 },
			fnAction = function()
				if frame:IsVisible() then
					frame:Hide()
				else
					frame:Show()
				end
				if IsCtrlKeyDown() then
					Wnd.CloseWindow(frame)
				end
			end
		})
	end
	return menu
end

TraceButton_AppendAddonMenu({function()
	local menu = { szOption = 'KG_UIManager' }
	for k, v in ipairs({ "Lowest", "Lowest1", "Lowest2", "Normal", "Normal1", "Normal2", "Topmost", "Topmost1", "Topmost2" })do
		table.insert(menu, GetMeun(v))
	end
	return {menu}
end})
