PageRenderTime 27ms CodeModel.GetById 19ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/extras/addonmanager.lua

http://github.com/Asphyxia/Tukui
Lua | 156 lines | 130 code | 21 blank | 5 comment | 5 complexity | 3c9a6d813c51ace7d972bde2902cb389 MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2local font, fontsize, fontstyle = C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE"
  3
  4local function ModifiedBackdrop(self)
  5	local color = RAID_CLASS_COLORS[T.myclass]
  6	self:SetBackdropColor(color.r*.15, color.g*.15, color.b*.15)
  7	self:SetBackdropBorderColor(color.r, color.g, color.b)
  8end
  9
 10local function OriginalBackdrop(self)
 11	self:SetTemplate("Default")
 12end
 13
 14-- Create BG
 15local addonBG = CreateFrame("Frame", "addonBG", UIParent)
 16addonBG:CreatePanel("Default", T.InfoLeftRightWidth, 500, "CENTER", UIParent, "CENTER", 0, 0)
 17addonBG:EnableMouse(true)
 18addonBG:SetMovable(true)
 19addonBG:SetUserPlaced(true)
 20addonBG:SetClampedToScreen(true)
 21addonBG:SetScript("OnMouseDown", function(self) self:StartMoving() end)
 22addonBG:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
 23addonBG:SetFrameStrata("HIGH")
 24addonBG:CreateShadow("Default")
 25T.fadeIn(addonBG)
 26addonBG:Hide()
 27
 28local addonHeader = CreateFrame("Frame", "addonHeader", addonBG)
 29addonHeader:CreatePanel("Transparent", addonBG:GetWidth(), 23, "BOTTOM", addonBG, "TOP", 0, 3, true)
 30addonHeader.Text = T.SetFontString(addonHeader, font, fontsize, fontstyle)
 31addonHeader.Text:SetPoint("LEFT", 5, 1)
 32addonHeader.Text:SetText(T.datacolor.."AddOns List"..": "..T.datacolor..T.myname)
 33
 34-- Create scroll frame
 35local scrollFrame = CreateFrame("ScrollFrame", "scrollFrame", addonBG, "UIPanelScrollFrameTemplate")
 36scrollFrame:SetPoint("TOPLEFT", addonBG, "TOPLEFT", 10, -10)
 37scrollFrame:SetPoint("BOTTOMRIGHT", addonBG, "BOTTOMRIGHT", -30, 40)
 38T.SkinScrollBar(scrollFrameScrollBar)
 39
 40-- Create inside BG (uses scroll frame)
 41local buttonsBG = CreateFrame("Frame", "buttonsBG", scrollFrame)
 42buttonsBG:SetPoint("TOPLEFT")
 43buttonsBG:SetWidth(scrollFrame:GetWidth())
 44buttonsBG:SetHeight(scrollFrame:GetHeight())
 45scrollFrame:SetScrollChild(buttonsBG)
 46
 47local saveButton = CreateFrame("Button", "saveButton", addonBG)
 48saveButton:CreatePanel("Default", 130, 20, "BOTTOMLEFT", addonBG, "BOTTOMLEFT", 10, 10, true)
 49saveButton:SetFrameStrata("TOOLTIP")
 50saveButton:CreateOverlay(saveButton)
 51saveButton.text:SetText(T.datacolor.."Save Changes")
 52saveButton:SetScript("OnClick", function() ReloadUI() end)
 53saveButton:HookScript("OnEnter", ModifiedBackdrop)
 54saveButton:HookScript("OnLeave", OriginalBackdrop)
 55
 56local closeButton = CreateFrame("Button", "closeButton", addonBG)
 57closeButton:CreatePanel("Default", 130, 20, "BOTTOMRIGHT", addonBG, "BOTTOMRIGHT", -10, 10, true)
 58closeButton.text:SetText(T.datacolor.."Cancel")
 59closeButton:SetFrameStrata("TOOLTIP")
 60closeButton:CreateOverlay(closeButton)
 61closeButton:SetScript("OnClick", function() T.fadeOut(addonBG) end)
 62closeButton:HookScript("OnEnter", ModifiedBackdrop)
 63closeButton:HookScript("OnLeave", OriginalBackdrop)
 64
 65local raid_addons = CreateFrame("Button", "TukuiEnableRaidButton", addonHeader)
 66raid_addons:CreatePanel("Transparent", 60, 17, "RIGHT", addonHeader, "RIGHT", -5, 0)
 67raid_addons:CreateShadow("Default")
 68raid_addons:CreateOverlay(raid_addons)
 69raid_addons:SetFrameStrata(addonHeader:GetFrameStrata())
 70raid_addons:SetFrameLevel(addonHeader:GetFrameLevel() + 1)
 71raid_addons:RegisterForClicks("AnyUp") raid_addons:SetScript("OnClick", function()
 72	EnableAddOn("DBM-Core")   -- change this to your bossmod "BigWigs"
 73	EnableAddOn("Recount")    -- change this to your damage meters "TinyDPS" "Skada"
 74	ReloadUI()
 75end)
 76
 77raid_addons:HookScript("OnEnter", ModifiedBackdrop)
 78raid_addons:HookScript("OnLeave", OriginalBackdrop)
 79
 80raid_addons.Text = T.SetFontString(raid_addons, C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 81raid_addons.Text:Point("CENTER", raid_addons, "CENTER", 1, 1)
 82raid_addons.Text:SetText(T.datacolor..RAID)
 83
 84local solo_addons = CreateFrame("Button", "TukuiEnableSoloButton", addonHeader)
 85solo_addons:CreatePanel("Transparent", 60, 17, "RIGHT", raid_addons, "LEFT", -3, 0)
 86solo_addons:CreateShadow("Default")
 87solo_addons:CreateOverlay(solo_addons)
 88solo_addons:SetFrameStrata(addonHeader:GetFrameStrata())
 89solo_addons:SetFrameLevel(addonHeader:GetFrameLevel() + 1)
 90solo_addons:RegisterForClicks("AnyUp") solo_addons:SetScript("OnClick", function()
 91	DisableAddOn("DBM-Core")     -- change this to your bossmod "BigWigs"
 92	DisableAddOn("Recount")      -- change this to your damage meters "TinyDPS" "Skada"
 93	ReloadUI()
 94end)
 95
 96solo_addons:HookScript("OnEnter", ModifiedBackdrop)
 97solo_addons:HookScript("OnLeave", OriginalBackdrop)
 98
 99solo_addons.Text = T.SetFontString(solo_addons, C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
100solo_addons.Text:Point("CENTER", solo_addons, "CENTER", 1, 1)
101solo_addons.Text:SetText(T.datacolor..SOLO)
102
103local function UpdateAddons()
104	local addons = {}
105	for i=1, GetNumAddOns() do
106		addons[i] = select(1, GetAddOnInfo(i))
107	end
108	table.sort(addons)
109	local oldb
110	for i,v in pairs(addons) do
111		local name, title, notes, enabled, loadable, reason, security = GetAddOnInfo(v)
112		local button = CreateFrame("Button", v.."_Button", buttonsBG, "SecureActionButtonTemplate")
113		button:SetFrameLevel(buttonsBG:GetFrameLevel() + 1)
114		button:Size(50, 16)
115		button:SetTemplate("Default")
116		button:CreateOverlay()
117
118		-- to make sure the border is colored the right color on reload 
119		if enabled then
120			button:SetBackdropBorderColor(0,1,0)
121		else
122			button:SetBackdropBorderColor(1,0,0)
123		end
124
125		if i==1 then
126			button:Point("TOPLEFT", buttonsBG, "TOPLEFT", 0, 0)
127		else
128			button:Point("TOP", oldb, "BOTTOM", 0, -7)
129		end
130		local text = T.SetFontString(button, C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
131		text:Point("LEFT", button, "RIGHT", 8, 0)
132		text:SetText(title)
133	
134		 button:SetScript("OnMouseDown", function()
135            if enabled then
136                button:SetBackdropBorderColor(1,0,0)
137                DisableAddOn(name)
138                enabled = false
139            else
140                button:SetBackdropBorderColor(0,1,0)
141                EnableAddOn(name)
142                enabled = true
143            end
144        end)
145	
146		oldb = button
147	end
148end
149
150UpdateAddons()
151
152-- Slash commands
153SLASH_ALOAD1 = "/am"
154SlashCmdList.ALOAD = function (msg)
155	addonBG:Show()
156end