/trunk/Libs/AceGUI-3.0/widgets
--[[----------------------------------------------------------------------------- |
TabGroup Container |
Container that uses tabs on top to switch between groups. |
-------------------------------------------------------------------------------]] |
local Type, Version = "TabGroup", 35 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
-- Lua APIs |
local pairs, ipairs, assert, type, wipe = pairs, ipairs, assert, type, wipe |
-- WoW APIs |
local PlaySound = PlaySound |
local CreateFrame, UIParent = CreateFrame, UIParent |
local _G = _G |
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded |
-- List them here for Mikk's FindGlobals script |
-- GLOBALS: PanelTemplates_TabResize, PanelTemplates_SetDisabledTabState, PanelTemplates_SelectTab, PanelTemplates_DeselectTab |
-- local upvalue storage used by BuildTabs |
local widths = {} |
local rowwidths = {} |
local rowends = {} |
--[[----------------------------------------------------------------------------- |
Support functions |
-------------------------------------------------------------------------------]] |
local function UpdateTabLook(frame) |
if frame.disabled then |
PanelTemplates_SetDisabledTabState(frame) |
elseif frame.selected then |
PanelTemplates_SelectTab(frame) |
else |
PanelTemplates_DeselectTab(frame) |
end |
end |
local function Tab_SetText(frame, text) |
frame:_SetText(text) |
local width = frame.obj.frame.width or frame.obj.frame:GetWidth() or 0 |
PanelTemplates_TabResize(frame, 0, nil, nil, width, frame:GetFontString():GetStringWidth()) |
end |
local function Tab_SetSelected(frame, selected) |
frame.selected = selected |
UpdateTabLook(frame) |
end |
local function Tab_SetDisabled(frame, disabled) |
frame.disabled = disabled |
UpdateTabLook(frame) |
end |
local function BuildTabsOnUpdate(frame) |
local self = frame.obj |
self:BuildTabs() |
frame:SetScript("OnUpdate", nil) |
end |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function Tab_OnClick(frame) |
if not (frame.selected or frame.disabled) then |
PlaySound("igCharacterInfoTab") |
frame.obj:SelectTab(frame.value) |
end |
end |
local function Tab_OnEnter(frame) |
local self = frame.obj |
self:Fire("OnTabEnter", self.tabs[frame.id].value, frame) |
end |
local function Tab_OnLeave(frame) |
local self = frame.obj |
self:Fire("OnTabLeave", self.tabs[frame.id].value, frame) |
end |
local function Tab_OnShow(frame) |
_G[frame:GetName().."HighlightTexture"]:SetWidth(frame:GetTextWidth() + 30) |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self:SetTitle() |
end, |
["OnRelease"] = function(self) |
self.status = nil |
for k in pairs(self.localstatus) do |
self.localstatus[k] = nil |
end |
self.tablist = nil |
for _, tab in pairs(self.tabs) do |
tab:Hide() |
end |
end, |
["CreateTab"] = function(self, id) |
local tabname = ("AceGUITabGroup%dTab%d"):format(self.num, id) |
local tab = CreateFrame("Button", tabname, self.border, "OptionsFrameTabButtonTemplate") |
tab.obj = self |
tab.id = id |
tab.text = _G[tabname .. "Text"] |
tab.text:ClearAllPoints() |
tab.text:SetPoint("LEFT", 14, -3) |
tab.text:SetPoint("RIGHT", -12, -3) |
tab:SetScript("OnClick", Tab_OnClick) |
tab:SetScript("OnEnter", Tab_OnEnter) |
tab:SetScript("OnLeave", Tab_OnLeave) |
tab:SetScript("OnShow", Tab_OnShow) |
tab._SetText = tab.SetText |
tab.SetText = Tab_SetText |
tab.SetSelected = Tab_SetSelected |
tab.SetDisabled = Tab_SetDisabled |
return tab |
end, |
["SetTitle"] = function(self, text) |
self.titletext:SetText(text or "") |
if text and text ~= "" then |
self.alignoffset = 25 |
else |
self.alignoffset = 18 |
end |
self:BuildTabs() |
end, |
["SetStatusTable"] = function(self, status) |
assert(type(status) == "table") |
self.status = status |
end, |
["SelectTab"] = function(self, value) |
local status = self.status or self.localstatus |
local found |
for i, v in ipairs(self.tabs) do |
if v.value == value then |
v:SetSelected(true) |
found = true |
else |
v:SetSelected(false) |
end |
end |
status.selected = value |
if found then |
self:Fire("OnGroupSelected",value) |
end |
end, |
["SetTabs"] = function(self, tabs) |
self.tablist = tabs |
self:BuildTabs() |
end, |
["BuildTabs"] = function(self) |
local hastitle = (self.titletext:GetText() and self.titletext:GetText() ~= "") |
local status = self.status or self.localstatus |
local tablist = self.tablist |
local tabs = self.tabs |
if not tablist then return end |
local width = self.frame.width or self.frame:GetWidth() or 0 |
wipe(widths) |
wipe(rowwidths) |
wipe(rowends) |
--Place Text into tabs and get thier initial width |
for i, v in ipairs(tablist) do |
local tab = tabs[i] |
if not tab then |
tab = self:CreateTab(i) |
tabs[i] = tab |
end |
tab:Show() |
tab:SetText(v.text) |
tab:SetDisabled(v.disabled) |
tab.value = v.value |
widths[i] = tab:GetWidth() - 6 --tabs are anchored 10 pixels from the right side of the previous one to reduce spacing, but add a fixed 4px padding for the text |
end |
for i = (#tablist)+1, #tabs, 1 do |
tabs[i]:Hide() |
end |
--First pass, find the minimum number of rows needed to hold all tabs and the initial tab layout |
local numtabs = #tablist |
local numrows = 1 |
local usedwidth = 0 |
for i = 1, #tablist do |
--If this is not the first tab of a row and there isn't room for it |
if usedwidth ~= 0 and (width - usedwidth - widths[i]) < 0 then |
rowwidths[numrows] = usedwidth + 10 --first tab in each row takes up an extra 10px |
rowends[numrows] = i - 1 |
numrows = numrows + 1 |
usedwidth = 0 |
end |
usedwidth = usedwidth + widths[i] |
end |
rowwidths[numrows] = usedwidth + 10 --first tab in each row takes up an extra 10px |
rowends[numrows] = #tablist |
--Fix for single tabs being left on the last row, move a tab from the row above if applicable |
if numrows > 1 then |
--if the last row has only one tab |
if rowends[numrows-1] == numtabs-1 then |
--if there are more than 2 tabs in the 2nd last row |
if (numrows == 2 and rowends[numrows-1] > 2) or (rowends[numrows] - rowends[numrows-1] > 2) then |
--move 1 tab from the second last row to the last, if there is enough space |
if (rowwidths[numrows] + widths[numtabs-1]) <= width then |
rowends[numrows-1] = rowends[numrows-1] - 1 |
rowwidths[numrows] = rowwidths[numrows] + widths[numtabs-1] |
rowwidths[numrows-1] = rowwidths[numrows-1] - widths[numtabs-1] |
end |
end |
end |
end |
--anchor the rows as defined and resize tabs to fill thier row |
local starttab = 1 |
for row, endtab in ipairs(rowends) do |
local first = true |
for tabno = starttab, endtab do |
local tab = tabs[tabno] |
tab:ClearAllPoints() |
if first then |
tab:SetPoint("TOPLEFT", self.frame, "TOPLEFT", 0, -(hastitle and 14 or 7)-(row-1)*20 ) |
first = false |
else |
tab:SetPoint("LEFT", tabs[tabno-1], "RIGHT", -10, 0) |
end |
end |
-- equal padding for each tab to fill the available width, |
-- if the used space is above 75% already |
-- the 18 pixel is the typical width of a scrollbar, so we can have a tab group inside a scrolling frame, |
-- and not have the tabs jump around funny when switching between tabs that need scrolling and those that don't |
local padding = 0 |
if not (numrows == 1 and rowwidths[1] < width*0.75 - 18) then |
padding = (width - rowwidths[row]) / (endtab - starttab+1) |
end |
for i = starttab, endtab do |
PanelTemplates_TabResize(tabs[i], padding + 4, nil, nil, width, tabs[i]:GetFontString():GetStringWidth()) |
end |
starttab = endtab + 1 |
end |
self.borderoffset = (hastitle and 17 or 10)+((numrows)*20) |
self.border:SetPoint("TOPLEFT", 1, -self.borderoffset) |
end, |
["OnWidthSet"] = function(self, width) |
local content = self.content |
local contentwidth = width - 60 |
if contentwidth < 0 then |
contentwidth = 0 |
end |
content:SetWidth(contentwidth) |
content.width = contentwidth |
self:BuildTabs(self) |
self.frame:SetScript("OnUpdate", BuildTabsOnUpdate) |
end, |
["OnHeightSet"] = function(self, height) |
local content = self.content |
local contentheight = height - (self.borderoffset + 23) |
if contentheight < 0 then |
contentheight = 0 |
end |
content:SetHeight(contentheight) |
content.height = contentheight |
end, |
["LayoutFinished"] = function(self, width, height) |
if self.noAutoHeight then return end |
self:SetHeight((height or 0) + (self.borderoffset + 23)) |
end |
} |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local PaneBackdrop = { |
bgFile = "Interface\\ChatFrame\\ChatFrameBackground", |
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", |
tile = true, tileSize = 16, edgeSize = 16, |
insets = { left = 3, right = 3, top = 5, bottom = 3 } |
} |
local function Constructor() |
local num = AceGUI:GetNextWidgetNum(Type) |
local frame = CreateFrame("Frame",nil,UIParent) |
frame:SetHeight(100) |
frame:SetWidth(100) |
frame:SetFrameStrata("FULLSCREEN_DIALOG") |
local titletext = frame:CreateFontString(nil,"OVERLAY","GameFontNormal") |
titletext:SetPoint("TOPLEFT", 14, 0) |
titletext:SetPoint("TOPRIGHT", -14, 0) |
titletext:SetJustifyH("LEFT") |
titletext:SetHeight(18) |
titletext:SetText("") |
local border = CreateFrame("Frame", nil, frame) |
border:SetPoint("TOPLEFT", 1, -27) |
border:SetPoint("BOTTOMRIGHT", -1, 3) |
border:SetBackdrop(PaneBackdrop) |
border:SetBackdropColor(0.1, 0.1, 0.1, 0.5) |
border:SetBackdropBorderColor(0.4, 0.4, 0.4) |
local content = CreateFrame("Frame", nil, border) |
content:SetPoint("TOPLEFT", 10, -7) |
content:SetPoint("BOTTOMRIGHT", -10, 7) |
local widget = { |
num = num, |
frame = frame, |
localstatus = {}, |
alignoffset = 18, |
titletext = titletext, |
border = border, |
borderoffset = 27, |
tabs = {}, |
content = content, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
end |
return AceGUI:RegisterAsContainer(widget) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[----------------------------------------------------------------------------- |
BlizOptionsGroup Container |
Simple container widget for the integration of AceGUI into the Blizzard Interface Options |
-------------------------------------------------------------------------------]] |
local Type, Version = "BlizOptionsGroup", 21 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
-- Lua APIs |
local pairs = pairs |
-- WoW APIs |
local CreateFrame = CreateFrame |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function OnShow(frame) |
frame.obj:Fire("OnShow") |
end |
local function OnHide(frame) |
frame.obj:Fire("OnHide") |
end |
--[[----------------------------------------------------------------------------- |
Support functions |
-------------------------------------------------------------------------------]] |
local function okay(frame) |
frame.obj:Fire("okay") |
end |
local function cancel(frame) |
frame.obj:Fire("cancel") |
end |
local function default(frame) |
frame.obj:Fire("default") |
end |
local function refresh(frame) |
frame.obj:Fire("refresh") |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self:SetName() |
self:SetTitle() |
end, |
-- ["OnRelease"] = nil, |
["OnWidthSet"] = function(self, width) |
local content = self.content |
local contentwidth = width - 63 |
if contentwidth < 0 then |
contentwidth = 0 |
end |
content:SetWidth(contentwidth) |
content.width = contentwidth |
end, |
["OnHeightSet"] = function(self, height) |
local content = self.content |
local contentheight = height - 26 |
if contentheight < 0 then |
contentheight = 0 |
end |
content:SetHeight(contentheight) |
content.height = contentheight |
end, |
["SetName"] = function(self, name, parent) |
self.frame.name = name |
self.frame.parent = parent |
end, |
["SetTitle"] = function(self, title) |
local content = self.content |
content:ClearAllPoints() |
if not title or title == "" then |
content:SetPoint("TOPLEFT", 10, -10) |
self.label:SetText("") |
else |
content:SetPoint("TOPLEFT", 10, -40) |
self.label:SetText(title) |
end |
content:SetPoint("BOTTOMRIGHT", -10, 10) |
end |
} |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local function Constructor() |
local frame = CreateFrame("Frame") |
frame:Hide() |
-- support functions for the Blizzard Interface Options |
frame.okay = okay |
frame.cancel = cancel |
frame.default = default |
frame.refresh = refresh |
frame:SetScript("OnHide", OnHide) |
frame:SetScript("OnShow", OnShow) |
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge") |
label:SetPoint("TOPLEFT", 10, -15) |
label:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", 10, -45) |
label:SetJustifyH("LEFT") |
label:SetJustifyV("TOP") |
--Container Support |
local content = CreateFrame("Frame", nil, frame) |
content:SetPoint("TOPLEFT", 10, -10) |
content:SetPoint("BOTTOMRIGHT", -10, 10) |
local widget = { |
label = label, |
frame = frame, |
content = content, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
end |
return AceGUI:RegisterAsContainer(widget) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[----------------------------------------------------------------------------- |
Frame Container |
-------------------------------------------------------------------------------]] |
local Type, Version = "Frame", 24 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
-- Lua APIs |
local pairs, assert, type = pairs, assert, type |
local wipe = table.wipe |
-- WoW APIs |
local PlaySound = PlaySound |
local CreateFrame, UIParent = CreateFrame, UIParent |
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded |
-- List them here for Mikk's FindGlobals script |
-- GLOBALS: CLOSE |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function Button_OnClick(frame) |
PlaySound("gsTitleOptionExit") |
frame.obj:Hide() |
end |
local function Frame_OnClose(frame) |
frame.obj:Fire("OnClose") |
end |
local function Frame_OnMouseDown(frame) |
AceGUI:ClearFocus() |
end |
local function Title_OnMouseDown(frame) |
frame:GetParent():StartMoving() |
AceGUI:ClearFocus() |
end |
local function MoverSizer_OnMouseUp(mover) |
local frame = mover:GetParent() |
frame:StopMovingOrSizing() |
local self = frame.obj |
local status = self.status or self.localstatus |
status.width = frame:GetWidth() |
status.height = frame:GetHeight() |
status.top = frame:GetTop() |
status.left = frame:GetLeft() |
end |
local function SizerSE_OnMouseDown(frame) |
frame:GetParent():StartSizing("BOTTOMRIGHT") |
AceGUI:ClearFocus() |
end |
local function SizerS_OnMouseDown(frame) |
frame:GetParent():StartSizing("BOTTOM") |
AceGUI:ClearFocus() |
end |
local function SizerE_OnMouseDown(frame) |
frame:GetParent():StartSizing("RIGHT") |
AceGUI:ClearFocus() |
end |
local function StatusBar_OnEnter(frame) |
frame.obj:Fire("OnEnterStatusBar") |
end |
local function StatusBar_OnLeave(frame) |
frame.obj:Fire("OnLeaveStatusBar") |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self.frame:SetParent(UIParent) |
self.frame:SetFrameStrata("FULLSCREEN_DIALOG") |
self:SetTitle() |
self:SetStatusText() |
self:ApplyStatus() |
self:Show() |
self:EnableResize(true) |
end, |
["OnRelease"] = function(self) |
self.status = nil |
wipe(self.localstatus) |
end, |
["OnWidthSet"] = function(self, width) |
local content = self.content |
local contentwidth = width - 34 |
if contentwidth < 0 then |
contentwidth = 0 |
end |
content:SetWidth(contentwidth) |
content.width = contentwidth |
end, |
["OnHeightSet"] = function(self, height) |
local content = self.content |
local contentheight = height - 57 |
if contentheight < 0 then |
contentheight = 0 |
end |
content:SetHeight(contentheight) |
content.height = contentheight |
end, |
["SetTitle"] = function(self, title) |
self.titletext:SetText(title) |
self.titlebg:SetWidth((self.titletext:GetWidth() or 0) + 10) |
end, |
["SetStatusText"] = function(self, text) |
self.statustext:SetText(text) |
end, |
["Hide"] = function(self) |
self.frame:Hide() |
end, |
["Show"] = function(self) |
self.frame:Show() |
end, |
["EnableResize"] = function(self, state) |
local func = state and "Show" or "Hide" |
self.sizer_se[func](self.sizer_se) |
self.sizer_s[func](self.sizer_s) |
self.sizer_e[func](self.sizer_e) |
end, |
-- called to set an external table to store status in |
["SetStatusTable"] = function(self, status) |
assert(type(status) == "table") |
self.status = status |
self:ApplyStatus() |
end, |
["ApplyStatus"] = function(self) |
local status = self.status or self.localstatus |
local frame = self.frame |
self:SetWidth(status.width or 700) |
self:SetHeight(status.height or 500) |
frame:ClearAllPoints() |
if status.top and status.left then |
frame:SetPoint("TOP", UIParent, "BOTTOM", 0, status.top) |
frame:SetPoint("LEFT", UIParent, "LEFT", status.left, 0) |
else |
frame:SetPoint("CENTER") |
end |
end |
} |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local FrameBackdrop = { |
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", |
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", |
tile = true, tileSize = 32, edgeSize = 32, |
insets = { left = 8, right = 8, top = 8, bottom = 8 } |
} |
local PaneBackdrop = { |
bgFile = "Interface\\ChatFrame\\ChatFrameBackground", |
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", |
tile = true, tileSize = 16, edgeSize = 16, |
insets = { left = 3, right = 3, top = 5, bottom = 3 } |
} |
local function Constructor() |
local frame = CreateFrame("Frame", nil, UIParent) |
frame:Hide() |
frame:EnableMouse(true) |
frame:SetMovable(true) |
frame:SetResizable(true) |
frame:SetFrameStrata("FULLSCREEN_DIALOG") |
frame:SetBackdrop(FrameBackdrop) |
frame:SetBackdropColor(0, 0, 0, 1) |
frame:SetMinResize(400, 200) |
frame:SetToplevel(true) |
frame:SetScript("OnHide", Frame_OnClose) |
frame:SetScript("OnMouseDown", Frame_OnMouseDown) |
local closebutton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate") |
closebutton:SetScript("OnClick", Button_OnClick) |
closebutton:SetPoint("BOTTOMRIGHT", -27, 17) |
closebutton:SetHeight(20) |
closebutton:SetWidth(100) |
closebutton:SetText(CLOSE) |
local statusbg = CreateFrame("Button", nil, frame) |
statusbg:SetPoint("BOTTOMLEFT", 15, 15) |
statusbg:SetPoint("BOTTOMRIGHT", -132, 15) |
statusbg:SetHeight(24) |
statusbg:SetBackdrop(PaneBackdrop) |
statusbg:SetBackdropColor(0.1,0.1,0.1) |
statusbg:SetBackdropBorderColor(0.4,0.4,0.4) |
statusbg:SetScript("OnEnter", StatusBar_OnEnter) |
statusbg:SetScript("OnLeave", StatusBar_OnLeave) |
local statustext = statusbg:CreateFontString(nil, "OVERLAY", "GameFontNormal") |
statustext:SetPoint("TOPLEFT", 7, -2) |
statustext:SetPoint("BOTTOMRIGHT", -7, 2) |
statustext:SetHeight(20) |
statustext:SetJustifyH("LEFT") |
statustext:SetText("") |
local titlebg = frame:CreateTexture(nil, "OVERLAY") |
titlebg:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header") |
titlebg:SetTexCoord(0.31, 0.67, 0, 0.63) |
titlebg:SetPoint("TOP", 0, 12) |
titlebg:SetWidth(100) |
titlebg:SetHeight(40) |
local title = CreateFrame("Frame", nil, frame) |
title:EnableMouse(true) |
title:SetScript("OnMouseDown", Title_OnMouseDown) |
title:SetScript("OnMouseUp", MoverSizer_OnMouseUp) |
title:SetAllPoints(titlebg) |
local titletext = title:CreateFontString(nil, "OVERLAY", "GameFontNormal") |
titletext:SetPoint("TOP", titlebg, "TOP", 0, -14) |
local titlebg_l = frame:CreateTexture(nil, "OVERLAY") |
titlebg_l:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header") |
titlebg_l:SetTexCoord(0.21, 0.31, 0, 0.63) |
titlebg_l:SetPoint("RIGHT", titlebg, "LEFT") |
titlebg_l:SetWidth(30) |
titlebg_l:SetHeight(40) |
local titlebg_r = frame:CreateTexture(nil, "OVERLAY") |
titlebg_r:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header") |
titlebg_r:SetTexCoord(0.67, 0.77, 0, 0.63) |
titlebg_r:SetPoint("LEFT", titlebg, "RIGHT") |
titlebg_r:SetWidth(30) |
titlebg_r:SetHeight(40) |
local sizer_se = CreateFrame("Frame", nil, frame) |
sizer_se:SetPoint("BOTTOMRIGHT") |
sizer_se:SetWidth(25) |
sizer_se:SetHeight(25) |
sizer_se:EnableMouse() |
sizer_se:SetScript("OnMouseDown",SizerSE_OnMouseDown) |
sizer_se:SetScript("OnMouseUp", MoverSizer_OnMouseUp) |
local line1 = sizer_se:CreateTexture(nil, "BACKGROUND") |
line1:SetWidth(14) |
line1:SetHeight(14) |
line1:SetPoint("BOTTOMRIGHT", -8, 8) |
line1:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") |
local x = 0.1 * 14/17 |
line1:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5) |
local line2 = sizer_se:CreateTexture(nil, "BACKGROUND") |
line2:SetWidth(8) |
line2:SetHeight(8) |
line2:SetPoint("BOTTOMRIGHT", -8, 8) |
line2:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") |
local x = 0.1 * 8/17 |
line2:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5) |
local sizer_s = CreateFrame("Frame", nil, frame) |
sizer_s:SetPoint("BOTTOMRIGHT", -25, 0) |
sizer_s:SetPoint("BOTTOMLEFT") |
sizer_s:SetHeight(25) |
sizer_s:EnableMouse(true) |
sizer_s:SetScript("OnMouseDown", SizerS_OnMouseDown) |
sizer_s:SetScript("OnMouseUp", MoverSizer_OnMouseUp) |
local sizer_e = CreateFrame("Frame", nil, frame) |
sizer_e:SetPoint("BOTTOMRIGHT", 0, 25) |
sizer_e:SetPoint("TOPRIGHT") |
sizer_e:SetWidth(25) |
sizer_e:EnableMouse(true) |
sizer_e:SetScript("OnMouseDown", SizerE_OnMouseDown) |
sizer_e:SetScript("OnMouseUp", MoverSizer_OnMouseUp) |
--Container Support |
local content = CreateFrame("Frame", nil, frame) |
content:SetPoint("TOPLEFT", 17, -27) |
content:SetPoint("BOTTOMRIGHT", -17, 40) |
local widget = { |
localstatus = {}, |
titletext = titletext, |
statustext = statustext, |
titlebg = titlebg, |
sizer_se = sizer_se, |
sizer_s = sizer_s, |
sizer_e = sizer_e, |
content = content, |
frame = frame, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
end |
closebutton.obj, statusbg.obj = widget, widget |
return AceGUI:RegisterAsContainer(widget) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[----------------------------------------------------------------------------- |
InlineGroup Container |
Simple container widget that creates a visible "box" with an optional title. |
-------------------------------------------------------------------------------]] |
local Type, Version = "InlineGroup", 21 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
-- Lua APIs |
local pairs = pairs |
-- WoW APIs |
local CreateFrame, UIParent = CreateFrame, UIParent |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self:SetWidth(300) |
self:SetHeight(100) |
self:SetTitle("") |
end, |
-- ["OnRelease"] = nil, |
["SetTitle"] = function(self,title) |
self.titletext:SetText(title) |
end, |
["LayoutFinished"] = function(self, width, height) |
if self.noAutoHeight then return end |
self:SetHeight((height or 0) + 40) |
end, |
["OnWidthSet"] = function(self, width) |
local content = self.content |
local contentwidth = width - 20 |
if contentwidth < 0 then |
contentwidth = 0 |
end |
content:SetWidth(contentwidth) |
content.width = contentwidth |
end, |
["OnHeightSet"] = function(self, height) |
local content = self.content |
local contentheight = height - 20 |
if contentheight < 0 then |
contentheight = 0 |
end |
content:SetHeight(contentheight) |
content.height = contentheight |
end |
} |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local PaneBackdrop = { |
bgFile = "Interface\\ChatFrame\\ChatFrameBackground", |
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", |
tile = true, tileSize = 16, edgeSize = 16, |
insets = { left = 3, right = 3, top = 5, bottom = 3 } |
} |
local function Constructor() |
local frame = CreateFrame("Frame", nil, UIParent) |
frame:SetFrameStrata("FULLSCREEN_DIALOG") |
local titletext = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal") |
titletext:SetPoint("TOPLEFT", 14, 0) |
titletext:SetPoint("TOPRIGHT", -14, 0) |
titletext:SetJustifyH("LEFT") |
titletext:SetHeight(18) |
local border = CreateFrame("Frame", nil, frame) |
border:SetPoint("TOPLEFT", 0, -17) |
border:SetPoint("BOTTOMRIGHT", -1, 3) |
border:SetBackdrop(PaneBackdrop) |
border:SetBackdropColor(0.1, 0.1, 0.1, 0.5) |
border:SetBackdropBorderColor(0.4, 0.4, 0.4) |
--Container Support |
local content = CreateFrame("Frame", nil, border) |
content:SetPoint("TOPLEFT", 10, -10) |
content:SetPoint("BOTTOMRIGHT", -10, 10) |
local widget = { |
frame = frame, |
content = content, |
titletext = titletext, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
end |
return AceGUI:RegisterAsContainer(widget) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[----------------------------------------------------------------------------- |
SimpleGroup Container |
Simple container widget that just groups widgets. |
-------------------------------------------------------------------------------]] |
local Type, Version = "SimpleGroup", 20 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
-- Lua APIs |
local pairs = pairs |
-- WoW APIs |
local CreateFrame, UIParent = CreateFrame, UIParent |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self:SetWidth(300) |
self:SetHeight(100) |
end, |
-- ["OnRelease"] = nil, |
["LayoutFinished"] = function(self, width, height) |
if self.noAutoHeight then return end |
self:SetHeight(height or 0) |
end, |
["OnWidthSet"] = function(self, width) |
local content = self.content |
content:SetWidth(width) |
content.width = width |
end, |
["OnHeightSet"] = function(self, height) |
local content = self.content |
content:SetHeight(height) |
content.height = height |
end |
} |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local function Constructor() |
local frame = CreateFrame("Frame", nil, UIParent) |
frame:SetFrameStrata("FULLSCREEN_DIALOG") |
--Container Support |
local content = CreateFrame("Frame", nil, frame) |
content:SetPoint("TOPLEFT") |
content:SetPoint("BOTTOMRIGHT") |
local widget = { |
frame = frame, |
content = content, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
end |
return AceGUI:RegisterAsContainer(widget) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
local AceGUI = LibStub("AceGUI-3.0") |
-- Lua APIs |
local pairs, assert, type = pairs, assert, type |
-- WoW APIs |
local PlaySound = PlaySound |
local CreateFrame, UIParent = CreateFrame, UIParent |
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded |
-- List them here for Mikk's FindGlobals script |
-- GLOBALS: GameFontNormal |
---------------- |
-- Main Frame -- |
---------------- |
--[[ |
Events : |
OnClose |
]] |
do |
local Type = "Window" |
local Version = 4 |
local function frameOnClose(this) |
this.obj:Fire("OnClose") |
end |
local function closeOnClick(this) |
PlaySound("gsTitleOptionExit") |
this.obj:Hide() |
end |
local function frameOnMouseDown(this) |
AceGUI:ClearFocus() |
end |
local function titleOnMouseDown(this) |
this:GetParent():StartMoving() |
AceGUI:ClearFocus() |
end |
local function frameOnMouseUp(this) |
local frame = this:GetParent() |
frame:StopMovingOrSizing() |
local self = frame.obj |
local status = self.status or self.localstatus |
status.width = frame:GetWidth() |
status.height = frame:GetHeight() |
status.top = frame:GetTop() |
status.left = frame:GetLeft() |
end |
local function sizerseOnMouseDown(this) |
this:GetParent():StartSizing("BOTTOMRIGHT") |
AceGUI:ClearFocus() |
end |
local function sizersOnMouseDown(this) |
this:GetParent():StartSizing("BOTTOM") |
AceGUI:ClearFocus() |
end |
local function sizereOnMouseDown(this) |
this:GetParent():StartSizing("RIGHT") |
AceGUI:ClearFocus() |
end |
local function sizerOnMouseUp(this) |
this:GetParent():StopMovingOrSizing() |
end |
local function SetTitle(self,title) |
self.titletext:SetText(title) |
end |
local function SetStatusText(self,text) |
-- self.statustext:SetText(text) |
end |
local function Hide(self) |
self.frame:Hide() |
end |
local function Show(self) |
self.frame:Show() |
end |
local function OnAcquire(self) |
self.frame:SetParent(UIParent) |
self.frame:SetFrameStrata("FULLSCREEN_DIALOG") |
self:ApplyStatus() |
self:EnableResize(true) |
self:Show() |
end |
local function OnRelease(self) |
self.status = nil |
for k in pairs(self.localstatus) do |
self.localstatus[k] = nil |
end |
end |
-- called to set an external table to store status in |
local function SetStatusTable(self, status) |
assert(type(status) == "table") |
self.status = status |
self:ApplyStatus() |
end |
local function ApplyStatus(self) |
local status = self.status or self.localstatus |
local frame = self.frame |
self:SetWidth(status.width or 700) |
self:SetHeight(status.height or 500) |
if status.top and status.left then |
frame:SetPoint("TOP",UIParent,"BOTTOM",0,status.top) |
frame:SetPoint("LEFT",UIParent,"LEFT",status.left,0) |
else |
frame:SetPoint("CENTER",UIParent,"CENTER") |
end |
end |
local function OnWidthSet(self, width) |
local content = self.content |
local contentwidth = width - 34 |
if contentwidth < 0 then |
contentwidth = 0 |
end |
content:SetWidth(contentwidth) |
content.width = contentwidth |
end |
local function OnHeightSet(self, height) |
local content = self.content |
local contentheight = height - 57 |
if contentheight < 0 then |
contentheight = 0 |
end |
content:SetHeight(contentheight) |
content.height = contentheight |
end |
local function EnableResize(self, state) |
local func = state and "Show" or "Hide" |
self.sizer_se[func](self.sizer_se) |
self.sizer_s[func](self.sizer_s) |
self.sizer_e[func](self.sizer_e) |
end |
local function Constructor() |
local frame = CreateFrame("Frame",nil,UIParent) |
local self = {} |
self.type = "Window" |
self.Hide = Hide |
self.Show = Show |
self.SetTitle = SetTitle |
self.OnRelease = OnRelease |
self.OnAcquire = OnAcquire |
self.SetStatusText = SetStatusText |
self.SetStatusTable = SetStatusTable |
self.ApplyStatus = ApplyStatus |
self.OnWidthSet = OnWidthSet |
self.OnHeightSet = OnHeightSet |
self.EnableResize = EnableResize |
self.localstatus = {} |
self.frame = frame |
frame.obj = self |
frame:SetWidth(700) |
frame:SetHeight(500) |
frame:SetPoint("CENTER",UIParent,"CENTER",0,0) |
frame:EnableMouse() |
frame:SetMovable(true) |
frame:SetResizable(true) |
frame:SetFrameStrata("FULLSCREEN_DIALOG") |
frame:SetScript("OnMouseDown", frameOnMouseDown) |
frame:SetScript("OnHide",frameOnClose) |
frame:SetMinResize(240,240) |
frame:SetToplevel(true) |
local titlebg = frame:CreateTexture(nil, "BACKGROUND") |
titlebg:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Title-Background]]) |
titlebg:SetPoint("TOPLEFT", 9, -6) |
titlebg:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", -28, -24) |
local dialogbg = frame:CreateTexture(nil, "BACKGROUND") |
dialogbg:SetTexture([[Interface\Tooltips\UI-Tooltip-Background]]) |
dialogbg:SetPoint("TOPLEFT", 8, -24) |
dialogbg:SetPoint("BOTTOMRIGHT", -6, 8) |
dialogbg:SetVertexColor(0, 0, 0, .75) |
local topleft = frame:CreateTexture(nil, "BORDER") |
topleft:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]]) |
topleft:SetWidth(64) |
topleft:SetHeight(64) |
topleft:SetPoint("TOPLEFT") |
topleft:SetTexCoord(0.501953125, 0.625, 0, 1) |
local topright = frame:CreateTexture(nil, "BORDER") |
topright:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]]) |
topright:SetWidth(64) |
topright:SetHeight(64) |
topright:SetPoint("TOPRIGHT") |
topright:SetTexCoord(0.625, 0.75, 0, 1) |
local top = frame:CreateTexture(nil, "BORDER") |
top:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]]) |
top:SetHeight(64) |
top:SetPoint("TOPLEFT", topleft, "TOPRIGHT") |
top:SetPoint("TOPRIGHT", topright, "TOPLEFT") |
top:SetTexCoord(0.25, 0.369140625, 0, 1) |
local bottomleft = frame:CreateTexture(nil, "BORDER") |
bottomleft:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]]) |
bottomleft:SetWidth(64) |
bottomleft:SetHeight(64) |
bottomleft:SetPoint("BOTTOMLEFT") |
bottomleft:SetTexCoord(0.751953125, 0.875, 0, 1) |
local bottomright = frame:CreateTexture(nil, "BORDER") |
bottomright:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]]) |
bottomright:SetWidth(64) |
bottomright:SetHeight(64) |
bottomright:SetPoint("BOTTOMRIGHT") |
bottomright:SetTexCoord(0.875, 1, 0, 1) |
local bottom = frame:CreateTexture(nil, "BORDER") |
bottom:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]]) |
bottom:SetHeight(64) |
bottom:SetPoint("BOTTOMLEFT", bottomleft, "BOTTOMRIGHT") |
bottom:SetPoint("BOTTOMRIGHT", bottomright, "BOTTOMLEFT") |
bottom:SetTexCoord(0.376953125, 0.498046875, 0, 1) |
local left = frame:CreateTexture(nil, "BORDER") |
left:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]]) |
left:SetWidth(64) |
left:SetPoint("TOPLEFT", topleft, "BOTTOMLEFT") |
left:SetPoint("BOTTOMLEFT", bottomleft, "TOPLEFT") |
left:SetTexCoord(0.001953125, 0.125, 0, 1) |
local right = frame:CreateTexture(nil, "BORDER") |
right:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]]) |
right:SetWidth(64) |
right:SetPoint("TOPRIGHT", topright, "BOTTOMRIGHT") |
right:SetPoint("BOTTOMRIGHT", bottomright, "TOPRIGHT") |
right:SetTexCoord(0.1171875, 0.2421875, 0, 1) |
local close = CreateFrame("Button", nil, frame, "UIPanelCloseButton") |
close:SetPoint("TOPRIGHT", 2, 1) |
close:SetScript("OnClick", closeOnClick) |
self.closebutton = close |
close.obj = self |
local titletext = frame:CreateFontString(nil, "ARTWORK") |
titletext:SetFontObject(GameFontNormal) |
titletext:SetPoint("TOPLEFT", 12, -8) |
titletext:SetPoint("TOPRIGHT", -32, -8) |
self.titletext = titletext |
local title = CreateFrame("Button", nil, frame) |
title:SetPoint("TOPLEFT", titlebg) |
title:SetPoint("BOTTOMRIGHT", titlebg) |
title:EnableMouse() |
title:SetScript("OnMouseDown",titleOnMouseDown) |
title:SetScript("OnMouseUp", frameOnMouseUp) |
self.title = title |
local sizer_se = CreateFrame("Frame",nil,frame) |
sizer_se:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,0) |
sizer_se:SetWidth(25) |
sizer_se:SetHeight(25) |
sizer_se:EnableMouse() |
sizer_se:SetScript("OnMouseDown",sizerseOnMouseDown) |
sizer_se:SetScript("OnMouseUp", sizerOnMouseUp) |
self.sizer_se = sizer_se |
local line1 = sizer_se:CreateTexture(nil, "BACKGROUND") |
self.line1 = line1 |
line1:SetWidth(14) |
line1:SetHeight(14) |
line1:SetPoint("BOTTOMRIGHT", -8, 8) |
line1:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") |
local x = 0.1 * 14/17 |
line1:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5) |
local line2 = sizer_se:CreateTexture(nil, "BACKGROUND") |
self.line2 = line2 |
line2:SetWidth(8) |
line2:SetHeight(8) |
line2:SetPoint("BOTTOMRIGHT", -8, 8) |
line2:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") |
local x = 0.1 * 8/17 |
line2:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5) |
local sizer_s = CreateFrame("Frame",nil,frame) |
sizer_s:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-25,0) |
sizer_s:SetPoint("BOTTOMLEFT",frame,"BOTTOMLEFT",0,0) |
sizer_s:SetHeight(25) |
sizer_s:EnableMouse() |
sizer_s:SetScript("OnMouseDown",sizersOnMouseDown) |
sizer_s:SetScript("OnMouseUp", sizerOnMouseUp) |
self.sizer_s = sizer_s |
local sizer_e = CreateFrame("Frame",nil,frame) |
sizer_e:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,25) |
sizer_e:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,0) |
sizer_e:SetWidth(25) |
sizer_e:EnableMouse() |
sizer_e:SetScript("OnMouseDown",sizereOnMouseDown) |
sizer_e:SetScript("OnMouseUp", sizerOnMouseUp) |
self.sizer_e = sizer_e |
--Container Support |
local content = CreateFrame("Frame",nil,frame) |
self.content = content |
content.obj = self |
content:SetPoint("TOPLEFT",frame,"TOPLEFT",12,-32) |
content:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-12,13) |
AceGUI:RegisterAsContainer(self) |
return self |
end |
AceGUI:RegisterWidgetType(Type,Constructor,Version) |
end |
--[[----------------------------------------------------------------------------- |
ScrollFrame Container |
Plain container that scrolls its content and doesn't grow in height. |
-------------------------------------------------------------------------------]] |
local Type, Version = "ScrollFrame", 23 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
-- Lua APIs |
local pairs, assert, type = pairs, assert, type |
local min, max, floor, abs = math.min, math.max, math.floor, math.abs |
-- WoW APIs |
local CreateFrame, UIParent = CreateFrame, UIParent |
--[[----------------------------------------------------------------------------- |
Support functions |
-------------------------------------------------------------------------------]] |
local function FixScrollOnUpdate(frame) |
frame:SetScript("OnUpdate", nil) |
frame.obj:FixScroll() |
end |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function ScrollFrame_OnMouseWheel(frame, value) |
frame.obj:MoveScroll(value) |
end |
local function ScrollFrame_OnSizeChanged(frame) |
frame:SetScript("OnUpdate", FixScrollOnUpdate) |
end |
local function ScrollBar_OnScrollValueChanged(frame, value) |
frame.obj:SetScroll(value) |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self:SetScroll(0) |
self.scrollframe:SetScript("OnUpdate", FixScrollOnUpdate) |
end, |
["OnRelease"] = function(self) |
self.status = nil |
for k in pairs(self.localstatus) do |
self.localstatus[k] = nil |
end |
self.scrollframe:SetPoint("BOTTOMRIGHT") |
self.scrollbar:Hide() |
self.scrollBarShown = nil |
self.content.height, self.content.width = nil, nil |
end, |
["SetScroll"] = function(self, value) |
local status = self.status or self.localstatus |
local viewheight = self.scrollframe:GetHeight() |
local height = self.content:GetHeight() |
local offset |
if viewheight > height then |
offset = 0 |
else |
offset = floor((height - viewheight) / 1000.0 * value) |
end |
self.content:ClearAllPoints() |
self.content:SetPoint("TOPLEFT", 0, offset) |
self.content:SetPoint("TOPRIGHT", 0, offset) |
status.offset = offset |
status.scrollvalue = value |
end, |
["MoveScroll"] = function(self, value) |
local status = self.status or self.localstatus |
local height, viewheight = self.scrollframe:GetHeight(), self.content:GetHeight() |
if self.scrollBarShown then |
local diff = height - viewheight |
local delta = 1 |
if value < 0 then |
delta = -1 |
end |
self.scrollbar:SetValue(min(max(status.scrollvalue + delta*(1000/(diff/45)),0), 1000)) |
end |
end, |
["FixScroll"] = function(self) |
if self.updateLock then return end |
self.updateLock = true |
local status = self.status or self.localstatus |
local height, viewheight = self.scrollframe:GetHeight(), self.content:GetHeight() |
local offset = status.offset or 0 |
local curvalue = self.scrollbar:GetValue() |
-- Give us a margin of error of 2 pixels to stop some conditions that i would blame on floating point inaccuracys |
-- No-one is going to miss 2 pixels at the bottom of the frame, anyhow! |
if viewheight < height + 2 then |
if self.scrollBarShown then |
self.scrollBarShown = nil |
self.scrollbar:Hide() |
self.scrollbar:SetValue(0) |
self.scrollframe:SetPoint("BOTTOMRIGHT") |
self:DoLayout() |
end |
else |
if not self.scrollBarShown then |
self.scrollBarShown = true |
self.scrollbar:Show() |
self.scrollframe:SetPoint("BOTTOMRIGHT", -20, 0) |
self:DoLayout() |
end |
local value = (offset / (viewheight - height) * 1000) |
if value > 1000 then value = 1000 end |
self.scrollbar:SetValue(value) |
self:SetScroll(value) |
if value < 1000 then |
self.content:ClearAllPoints() |
self.content:SetPoint("TOPLEFT", 0, offset) |
self.content:SetPoint("TOPRIGHT", 0, offset) |
status.offset = offset |
end |
end |
self.updateLock = nil |
end, |
["LayoutFinished"] = function(self, width, height) |
self.content:SetHeight(height or 0 + 20) |
self.scrollframe:SetScript("OnUpdate", FixScrollOnUpdate) |
end, |
["SetStatusTable"] = function(self, status) |
assert(type(status) == "table") |
self.status = status |
if not status.scrollvalue then |
status.scrollvalue = 0 |
end |
end, |
["OnWidthSet"] = function(self, width) |
local content = self.content |
content.width = width |
end, |
["OnHeightSet"] = function(self, height) |
local content = self.content |
content.height = height |
end |
} |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local function Constructor() |
local frame = CreateFrame("Frame", nil, UIParent) |
local num = AceGUI:GetNextWidgetNum(Type) |
local scrollframe = CreateFrame("ScrollFrame", nil, frame) |
scrollframe:SetPoint("TOPLEFT") |
scrollframe:SetPoint("BOTTOMRIGHT") |
scrollframe:EnableMouseWheel(true) |
scrollframe:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel) |
scrollframe:SetScript("OnSizeChanged", ScrollFrame_OnSizeChanged) |
local scrollbar = CreateFrame("Slider", ("AceConfigDialogScrollFrame%dScrollBar"):format(num), scrollframe, "UIPanelScrollBarTemplate") |
scrollbar:SetPoint("TOPLEFT", scrollframe, "TOPRIGHT", 4, -16) |
scrollbar:SetPoint("BOTTOMLEFT", scrollframe, "BOTTOMRIGHT", 4, 16) |
scrollbar:SetMinMaxValues(0, 1000) |
scrollbar:SetValueStep(1) |
scrollbar:SetValue(0) |
scrollbar:SetWidth(16) |
scrollbar:Hide() |
-- set the script as the last step, so it doesn't fire yet |
scrollbar:SetScript("OnValueChanged", ScrollBar_OnScrollValueChanged) |
local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND") |
scrollbg:SetAllPoints(scrollbar) |
scrollbg:SetTexture(0, 0, 0, 0.4) |
--Container Support |
local content = CreateFrame("Frame", nil, scrollframe) |
content:SetPoint("TOPLEFT") |
content:SetPoint("TOPRIGHT") |
content:SetHeight(400) |
scrollframe:SetScrollChild(content) |
local widget = { |
localstatus = { scrollvalue = 0 }, |
scrollframe = scrollframe, |
scrollbar = scrollbar, |
content = content, |
frame = frame, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
end |
scrollframe.obj, scrollbar.obj = widget, widget |
return AceGUI:RegisterAsContainer(widget) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[----------------------------------------------------------------------------- |
DropdownGroup Container |
Container controlled by a dropdown on the top. |
-------------------------------------------------------------------------------]] |
local Type, Version = "DropdownGroup", 21 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
-- Lua APIs |
local assert, pairs, type = assert, pairs, type |
-- WoW APIs |
local CreateFrame = CreateFrame |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function SelectedGroup(self, event, value) |
local group = self.parentgroup |
local status = group.status or group.localstatus |
status.selected = value |
self.parentgroup:Fire("OnGroupSelected", value) |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self.dropdown:SetText("") |
self:SetDropdownWidth(200) |
self:SetTitle("") |
end, |
["OnRelease"] = function(self) |
self.dropdown.list = nil |
self.status = nil |
for k in pairs(self.localstatus) do |
self.localstatus[k] = nil |
end |
end, |
["SetTitle"] = function(self, title) |
self.titletext:SetText(title) |
self.dropdown.frame:ClearAllPoints() |
if title and title ~= "" then |
self.dropdown.frame:SetPoint("TOPRIGHT", -2, 0) |
else |
self.dropdown.frame:SetPoint("TOPLEFT", -1, 0) |
end |
end, |
["SetGroupList"] = function(self,list,order) |
self.dropdown:SetList(list,order) |
end, |
["SetStatusTable"] = function(self, status) |
assert(type(status) == "table") |
self.status = status |
end, |
["SetGroup"] = function(self,group) |
self.dropdown:SetValue(group) |
local status = self.status or self.localstatus |
status.selected = group |
self:Fire("OnGroupSelected", group) |
end, |
["OnWidthSet"] = function(self, width) |
local content = self.content |
local contentwidth = width - 26 |
if contentwidth < 0 then |
contentwidth = 0 |
end |
content:SetWidth(contentwidth) |
content.width = contentwidth |
end, |
["OnHeightSet"] = function(self, height) |
local content = self.content |
local contentheight = height - 63 |
if contentheight < 0 then |
contentheight = 0 |
end |
content:SetHeight(contentheight) |
content.height = contentheight |
end, |
["LayoutFinished"] = function(self, width, height) |
self:SetHeight((height or 0) + 63) |
end, |
["SetDropdownWidth"] = function(self, width) |
self.dropdown:SetWidth(width) |
end |
} |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local PaneBackdrop = { |
bgFile = "Interface\\ChatFrame\\ChatFrameBackground", |
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", |
tile = true, tileSize = 16, edgeSize = 16, |
insets = { left = 3, right = 3, top = 5, bottom = 3 } |
} |
local function Constructor() |
local frame = CreateFrame("Frame") |
frame:SetHeight(100) |
frame:SetWidth(100) |
frame:SetFrameStrata("FULLSCREEN_DIALOG") |
local titletext = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal") |
titletext:SetPoint("TOPLEFT", 4, -5) |
titletext:SetPoint("TOPRIGHT", -4, -5) |
titletext:SetJustifyH("LEFT") |
titletext:SetHeight(18) |
local dropdown = AceGUI:Create("Dropdown") |
dropdown.frame:SetParent(frame) |
dropdown.frame:SetFrameLevel(dropdown.frame:GetFrameLevel() + 2) |
dropdown:SetCallback("OnValueChanged", SelectedGroup) |
dropdown.frame:SetPoint("TOPLEFT", -1, 0) |
dropdown.frame:Show() |
dropdown:SetLabel("") |
local border = CreateFrame("Frame", nil, frame) |
border:SetPoint("TOPLEFT", 0, -26) |
border:SetPoint("BOTTOMRIGHT", 0, 3) |
border:SetBackdrop(PaneBackdrop) |
border:SetBackdropColor(0.1,0.1,0.1,0.5) |
border:SetBackdropBorderColor(0.4,0.4,0.4) |
--Container Support |
local content = CreateFrame("Frame", nil, border) |
content:SetPoint("TOPLEFT", 10, -10) |
content:SetPoint("BOTTOMRIGHT", -10, 10) |
local widget = { |
frame = frame, |
localstatus = {}, |
titletext = titletext, |
dropdown = dropdown, |
border = border, |
content = content, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
end |
dropdown.parentgroup = widget |
return AceGUI:RegisterAsContainer(widget) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[----------------------------------------------------------------------------- |
TreeGroup Container |
Container that uses a tree control to switch between groups. |
-------------------------------------------------------------------------------]] |
local Type, Version = "TreeGroup", 37 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
-- Lua APIs |
local next, pairs, ipairs, assert, type = next, pairs, ipairs, assert, type |
local math_min, math_max, floor = math.min, math.max, floor |
local select, tremove, unpack, tconcat = select, table.remove, unpack, table.concat |
-- WoW APIs |
local CreateFrame, UIParent = CreateFrame, UIParent |
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded |
-- List them here for Mikk's FindGlobals script |
-- GLOBALS: GameTooltip, FONT_COLOR_CODE_CLOSE |
-- Recycling functions |
local new, del |
do |
local pool = setmetatable({},{__mode='k'}) |
function new() |
local t = next(pool) |
if t then |
pool[t] = nil |
return t |
else |
return {} |
end |
end |
function del(t) |
for k in pairs(t) do |
t[k] = nil |
end |
pool[t] = true |
end |
end |
local DEFAULT_TREE_WIDTH = 175 |
local DEFAULT_TREE_SIZABLE = true |
--[[----------------------------------------------------------------------------- |
Support functions |
-------------------------------------------------------------------------------]] |
local function GetButtonUniqueValue(line) |
local parent = line.parent |
if parent and parent.value then |
return GetButtonUniqueValue(parent).."\001"..line.value |
else |
return line.value |
end |
end |
local function UpdateButton(button, treeline, selected, canExpand, isExpanded) |
local self = button.obj |
local toggle = button.toggle |
local frame = self.frame |
local text = treeline.text or "" |
local icon = treeline.icon |
local iconCoords = treeline.iconCoords |
local level = treeline.level |
local value = treeline.value |
local uniquevalue = treeline.uniquevalue |
local disabled = treeline.disabled |
button.treeline = treeline |
button.value = value |
button.uniquevalue = uniquevalue |
if selected then |
button:LockHighlight() |
button.selected = true |
else |
button:UnlockHighlight() |
button.selected = false |
end |
local normalTexture = button:GetNormalTexture() |
local line = button.line |
button.level = level |
if ( level == 1 ) then |
button:SetNormalFontObject("GameFontNormal") |
button:SetHighlightFontObject("GameFontHighlight") |
button.text:SetPoint("LEFT", (icon and 16 or 0) + 8, 2) |
else |
button:SetNormalFontObject("GameFontHighlightSmall") |
button:SetHighlightFontObject("GameFontHighlightSmall") |
button.text:SetPoint("LEFT", (icon and 16 or 0) + 8 * level, 2) |
end |
if disabled then |
button:EnableMouse(false) |
button.text:SetText("|cff808080"..text..FONT_COLOR_CODE_CLOSE) |
else |
button.text:SetText(text) |
button:EnableMouse(true) |
end |
if icon then |
button.icon:SetTexture(icon) |
button.icon:SetPoint("LEFT", 8 * level, (level == 1) and 0 or 1) |
else |
button.icon:SetTexture(nil) |
end |
if iconCoords then |
button.icon:SetTexCoord(unpack(iconCoords)) |
else |
button.icon:SetTexCoord(0, 1, 0, 1) |
end |
if canExpand then |
if not isExpanded then |
toggle:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-UP") |
toggle:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-DOWN") |
else |
toggle:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-UP") |
toggle:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-DOWN") |
end |
toggle:Show() |
else |
toggle:Hide() |
end |
end |
local function ShouldDisplayLevel(tree) |
local result = false |
for k, v in ipairs(tree) do |
if v.children == nil and v.visible ~= false then |
result = true |
elseif v.children then |
result = result or ShouldDisplayLevel(v.children) |
end |
if result then return result end |
end |
return false |
end |
local function addLine(self, v, tree, level, parent) |
local line = new() |
line.value = v.value |
line.text = v.text |
line.icon = v.icon |
line.iconCoords = v.iconCoords |
line.disabled = v.disabled |
line.tree = tree |
line.level = level |
line.parent = parent |
line.visible = v.visible |
line.uniquevalue = GetButtonUniqueValue(line) |
if v.children then |
line.hasChildren = true |
else |
line.hasChildren = nil |
end |
self.lines[#self.lines+1] = line |
return line |
end |
--fire an update after one frame to catch the treeframes height |
local function FirstFrameUpdate(frame) |
local self = frame.obj |
frame:SetScript("OnUpdate", nil) |
self:RefreshTree() |
end |
local function BuildUniqueValue(...) |
local n = select('#', ...) |
if n == 1 then |
return ... |
else |
return (...).."\001"..BuildUniqueValue(select(2,...)) |
end |
end |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function Expand_OnClick(frame) |
local button = frame.button |
local self = button.obj |
local status = (self.status or self.localstatus).groups |
status[button.uniquevalue] = not status[button.uniquevalue] |
self:RefreshTree() |
end |
local function Button_OnClick(frame) |
local self = frame.obj |
self:Fire("OnClick", frame.uniquevalue, frame.selected) |
if not frame.selected then |
self:SetSelected(frame.uniquevalue) |
frame.selected = true |
frame:LockHighlight() |
self:RefreshTree() |
end |
AceGUI:ClearFocus() |
end |
local function Button_OnDoubleClick(button) |
local self = button.obj |
local status = self.status or self.localstatus |
local status = (self.status or self.localstatus).groups |
status[button.uniquevalue] = not status[button.uniquevalue] |
self:RefreshTree() |
end |
local function Button_OnEnter(frame) |
local self = frame.obj |
self:Fire("OnButtonEnter", frame.uniquevalue, frame) |
if self.enabletooltips then |
GameTooltip:SetOwner(frame, "ANCHOR_NONE") |
GameTooltip:SetPoint("LEFT",frame,"RIGHT") |
GameTooltip:SetText(frame.text:GetText() or "", 1, .82, 0, true) |
GameTooltip:Show() |
end |
end |
local function Button_OnLeave(frame) |
local self = frame.obj |
self:Fire("OnButtonLeave", frame.uniquevalue, frame) |
if self.enabletooltips then |
GameTooltip:Hide() |
end |
end |
local function OnScrollValueChanged(frame, value) |
if frame.obj.noupdate then return end |
local self = frame.obj |
local status = self.status or self.localstatus |
status.scrollvalue = floor(value + 0.5) |
self:RefreshTree() |
AceGUI:ClearFocus() |
end |
local function Tree_OnSizeChanged(frame) |
frame.obj:RefreshTree() |
end |
local function Tree_OnMouseWheel(frame, delta) |
local self = frame.obj |
if self.showscroll then |
local scrollbar = self.scrollbar |
local min, max = scrollbar:GetMinMaxValues() |
local value = scrollbar:GetValue() |
local newvalue = math_min(max,math_max(min,value - delta)) |
if value ~= newvalue then |
scrollbar:SetValue(newvalue) |
end |
end |
end |
local function Dragger_OnLeave(frame) |
frame:SetBackdropColor(1, 1, 1, 0) |
end |
local function Dragger_OnEnter(frame) |
frame:SetBackdropColor(1, 1, 1, 0.8) |
end |
local function Dragger_OnMouseDown(frame) |
local treeframe = frame:GetParent() |
treeframe:StartSizing("RIGHT") |
end |
local function Dragger_OnMouseUp(frame) |
local treeframe = frame:GetParent() |
local self = treeframe.obj |
local frame = treeframe:GetParent() |
treeframe:StopMovingOrSizing() |
--treeframe:SetScript("OnUpdate", nil) |
treeframe:SetUserPlaced(false) |
--Without this :GetHeight will get stuck on the current height, causing the tree contents to not resize |
treeframe:SetHeight(0) |
treeframe:SetPoint("TOPLEFT", frame, "TOPLEFT",0,0) |
treeframe:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT",0,0) |
local status = self.status or self.localstatus |
status.treewidth = treeframe:GetWidth() |
treeframe.obj:Fire("OnTreeResize",treeframe:GetWidth()) |
-- recalculate the content width |
treeframe.obj:OnWidthSet(status.fullwidth) |
-- update the layout of the content |
treeframe.obj:DoLayout() |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self:SetTreeWidth(DEFAULT_TREE_WIDTH, DEFAULT_TREE_SIZABLE) |
self:EnableButtonTooltips(true) |
end, |
["OnRelease"] = function(self) |
self.status = nil |
for k, v in pairs(self.localstatus) do |
if k == "groups" then |
for k2 in pairs(v) do |
v[k2] = nil |
end |
else |
self.localstatus[k] = nil |
end |
end |
self.localstatus.scrollvalue = 0 |
self.localstatus.treewidth = DEFAULT_TREE_WIDTH |
self.localstatus.treesizable = DEFAULT_TREE_SIZABLE |
end, |
["EnableButtonTooltips"] = function(self, enable) |
self.enabletooltips = enable |
end, |
["CreateButton"] = function(self) |
local num = AceGUI:GetNextWidgetNum("TreeGroupButton") |
local button = CreateFrame("Button", ("AceGUI30TreeButton%d"):format(num), self.treeframe, "OptionsListButtonTemplate") |
button.obj = self |
local icon = button:CreateTexture(nil, "OVERLAY") |
icon:SetWidth(14) |
icon:SetHeight(14) |
button.icon = icon |
button:SetScript("OnClick",Button_OnClick) |
button:SetScript("OnDoubleClick", Button_OnDoubleClick) |
button:SetScript("OnEnter",Button_OnEnter) |
button:SetScript("OnLeave",Button_OnLeave) |
button.toggle.button = button |
button.toggle:SetScript("OnClick",Expand_OnClick) |
return button |
end, |
["SetStatusTable"] = function(self, status) |
assert(type(status) == "table") |
self.status = status |
if not status.groups then |
status.groups = {} |
end |
if not status.scrollvalue then |
status.scrollvalue = 0 |
end |
if not status.treewidth then |
status.treewidth = DEFAULT_TREE_WIDTH |
end |
if status.treesizable == nil then |
status.treesizable = DEFAULT_TREE_SIZABLE |
end |
self:SetTreeWidth(status.treewidth,status.treesizable) |
self:RefreshTree() |
end, |
--sets the tree to be displayed |
["SetTree"] = function(self, tree, filter) |
self.filter = filter |
if tree then |
assert(type(tree) == "table") |
end |
self.tree = tree |
self:RefreshTree() |
end, |
["BuildLevel"] = function(self, tree, level, parent) |
local groups = (self.status or self.localstatus).groups |
local hasChildren = self.hasChildren |
for i, v in ipairs(tree) do |
if v.children then |
if not self.filter or ShouldDisplayLevel(v.children) then |
local line = addLine(self, v, tree, level, parent) |
if groups[line.uniquevalue] then |
self:BuildLevel(v.children, level+1, line) |
end |
end |
elseif v.visible ~= false or not self.filter then |
addLine(self, v, tree, level, parent) |
end |
end |
end, |
["RefreshTree"] = function(self,scrollToSelection) |
local buttons = self.buttons |
local lines = self.lines |
for i, v in ipairs(buttons) do |
v:Hide() |
end |
while lines[1] do |
local t = tremove(lines) |
for k in pairs(t) do |
t[k] = nil |
end |
del(t) |
end |
if not self.tree then return end |
--Build the list of visible entries from the tree and status tables |
local status = self.status or self.localstatus |
local groupstatus = status.groups |
local tree = self.tree |
local treeframe = self.treeframe |
status.scrollToSelection = status.scrollToSelection or scrollToSelection -- needs to be cached in case the control hasn't been drawn yet (code bails out below) |
self:BuildLevel(tree, 1) |
local numlines = #lines |
local maxlines = (floor(((self.treeframe:GetHeight()or 0) - 20 ) / 18)) |
if maxlines <= 0 then return end |
local first, last |
scrollToSelection = status.scrollToSelection |
status.scrollToSelection = nil |
if numlines <= maxlines then |
--the whole tree fits in the frame |
status.scrollvalue = 0 |
self:ShowScroll(false) |
first, last = 1, numlines |
else |
self:ShowScroll(true) |
--scrolling will be needed |
self.noupdate = true |
self.scrollbar:SetMinMaxValues(0, numlines - maxlines) |
--check if we are scrolled down too far |
if numlines - status.scrollvalue < maxlines then |
status.scrollvalue = numlines - maxlines |
end |
self.noupdate = nil |
first, last = status.scrollvalue+1, status.scrollvalue + maxlines |
--show selection? |
if scrollToSelection and status.selected then |
local show |
for i,line in ipairs(lines) do -- find the line number |
if line.uniquevalue==status.selected then |
show=i |
end |
end |
if not show then |
-- selection was deleted or something? |
elseif show>=first and show<=last then |
-- all good |
else |
-- scrolling needed! |
if show<first then |
status.scrollvalue = show-1 |
else |
status.scrollvalue = show-maxlines |
end |
first, last = status.scrollvalue+1, status.scrollvalue + maxlines |
end |
end |
if self.scrollbar:GetValue() ~= status.scrollvalue then |
self.scrollbar:SetValue(status.scrollvalue) |
end |
end |
local buttonnum = 1 |
for i = first, last do |
local line = lines[i] |
local button = buttons[buttonnum] |
if not button then |
button = self:CreateButton() |
buttons[buttonnum] = button |
button:SetParent(treeframe) |
button:SetFrameLevel(treeframe:GetFrameLevel()+1) |
button:ClearAllPoints() |
if buttonnum == 1 then |
if self.showscroll then |
button:SetPoint("TOPRIGHT", -22, -10) |
button:SetPoint("TOPLEFT", 0, -10) |
else |
button:SetPoint("TOPRIGHT", 0, -10) |
button:SetPoint("TOPLEFT", 0, -10) |
end |
else |
button:SetPoint("TOPRIGHT", buttons[buttonnum-1], "BOTTOMRIGHT",0,0) |
button:SetPoint("TOPLEFT", buttons[buttonnum-1], "BOTTOMLEFT",0,0) |
end |
end |
UpdateButton(button, line, status.selected == line.uniquevalue, line.hasChildren, groupstatus[line.uniquevalue] ) |
button:Show() |
buttonnum = buttonnum + 1 |
end |
end, |
["SetSelected"] = function(self, value) |
local status = self.status or self.localstatus |
if status.selected ~= value then |
status.selected = value |
self:Fire("OnGroupSelected", value) |
end |
end, |
["Select"] = function(self, uniquevalue, ...) |
self.filter = false |
local status = self.status or self.localstatus |
local groups = status.groups |
local path = {...} |
for i = 1, #path do |
groups[tconcat(path, "\001", 1, i)] = true |
end |
status.selected = uniquevalue |
self:RefreshTree(true) |
self:Fire("OnGroupSelected", uniquevalue) |
end, |
["SelectByPath"] = function(self, ...) |
self:Select(BuildUniqueValue(...), ...) |
end, |
["SelectByValue"] = function(self, uniquevalue) |
self:Select(uniquevalue, ("\001"):split(uniquevalue)) |
end, |
["ShowScroll"] = function(self, show) |
self.showscroll = show |
if show then |
self.scrollbar:Show() |
if self.buttons[1] then |
self.buttons[1]:SetPoint("TOPRIGHT", self.treeframe,"TOPRIGHT",-22,-10) |
end |
else |
self.scrollbar:Hide() |
if self.buttons[1] then |
self.buttons[1]:SetPoint("TOPRIGHT", self.treeframe,"TOPRIGHT",0,-10) |
end |
end |
end, |
["OnWidthSet"] = function(self, width) |
local content = self.content |
local treeframe = self.treeframe |
local status = self.status or self.localstatus |
status.fullwidth = width |
local contentwidth = width - status.treewidth - 20 |
if contentwidth < 0 then |
contentwidth = 0 |
end |
content:SetWidth(contentwidth) |
content.width = contentwidth |
local maxtreewidth = math_min(400, width - 50) |
if maxtreewidth > 100 and status.treewidth > maxtreewidth then |
self:SetTreeWidth(maxtreewidth, status.treesizable) |
end |
treeframe:SetMaxResize(maxtreewidth, 1600) |
end, |
["OnHeightSet"] = function(self, height) |
local content = self.content |
local contentheight = height - 20 |
if contentheight < 0 then |
contentheight = 0 |
end |
content:SetHeight(contentheight) |
content.height = contentheight |
end, |
["SetTreeWidth"] = function(self, treewidth, resizable) |
if not resizable then |
if type(treewidth) == 'number' then |
resizable = false |
elseif type(treewidth) == 'boolean' then |
resizable = treewidth |
treewidth = DEFAULT_TREE_WIDTH |
else |
resizable = false |
treewidth = DEFAULT_TREE_WIDTH |
end |
end |
self.treeframe:SetWidth(treewidth) |
self.dragger:EnableMouse(resizable) |
local status = self.status or self.localstatus |
status.treewidth = treewidth |
status.treesizable = resizable |
-- recalculate the content width |
if status.fullwidth then |
self:OnWidthSet(status.fullwidth) |
end |
end, |
["GetTreeWidth"] = function(self) |
local status = self.status or self.localstatus |
return status.treewidth or DEFAULT_TREE_WIDTH |
end, |
["LayoutFinished"] = function(self, width, height) |
if self.noAutoHeight then return end |
self:SetHeight((height or 0) + 20) |
end |
} |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local PaneBackdrop = { |
bgFile = "Interface\\ChatFrame\\ChatFrameBackground", |
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", |
tile = true, tileSize = 16, edgeSize = 16, |
insets = { left = 3, right = 3, top = 5, bottom = 3 } |
} |
local DraggerBackdrop = { |
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", |
edgeFile = nil, |
tile = true, tileSize = 16, edgeSize = 0, |
insets = { left = 3, right = 3, top = 7, bottom = 7 } |
} |
local function Constructor() |
local num = AceGUI:GetNextWidgetNum(Type) |
local frame = CreateFrame("Frame", nil, UIParent) |
local treeframe = CreateFrame("Frame", nil, frame) |
treeframe:SetPoint("TOPLEFT") |
treeframe:SetPoint("BOTTOMLEFT") |
treeframe:SetWidth(DEFAULT_TREE_WIDTH) |
treeframe:EnableMouseWheel(true) |
treeframe:SetBackdrop(PaneBackdrop) |
treeframe:SetBackdropColor(0.1, 0.1, 0.1, 0.5) |
treeframe:SetBackdropBorderColor(0.4, 0.4, 0.4) |
treeframe:SetResizable(true) |
treeframe:SetMinResize(100, 1) |
treeframe:SetMaxResize(400, 1600) |
treeframe:SetScript("OnUpdate", FirstFrameUpdate) |
treeframe:SetScript("OnSizeChanged", Tree_OnSizeChanged) |
treeframe:SetScript("OnMouseWheel", Tree_OnMouseWheel) |
local dragger = CreateFrame("Frame", nil, treeframe) |
dragger:SetWidth(8) |
dragger:SetPoint("TOP", treeframe, "TOPRIGHT") |
dragger:SetPoint("BOTTOM", treeframe, "BOTTOMRIGHT") |
dragger:SetBackdrop(DraggerBackdrop) |
dragger:SetBackdropColor(1, 1, 1, 0) |
dragger:SetScript("OnEnter", Dragger_OnEnter) |
dragger:SetScript("OnLeave", Dragger_OnLeave) |
dragger:SetScript("OnMouseDown", Dragger_OnMouseDown) |
dragger:SetScript("OnMouseUp", Dragger_OnMouseUp) |
local scrollbar = CreateFrame("Slider", ("AceConfigDialogTreeGroup%dScrollBar"):format(num), treeframe, "UIPanelScrollBarTemplate") |
scrollbar:SetScript("OnValueChanged", nil) |
scrollbar:SetPoint("TOPRIGHT", -10, -26) |
scrollbar:SetPoint("BOTTOMRIGHT", -10, 26) |
scrollbar:SetMinMaxValues(0,0) |
scrollbar:SetValueStep(1) |
scrollbar:SetValue(0) |
scrollbar:SetWidth(16) |
scrollbar:SetScript("OnValueChanged", OnScrollValueChanged) |
local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND") |
scrollbg:SetAllPoints(scrollbar) |
scrollbg:SetTexture(0,0,0,0.4) |
local border = CreateFrame("Frame",nil,frame) |
border:SetPoint("TOPLEFT", treeframe, "TOPRIGHT") |
border:SetPoint("BOTTOMRIGHT") |
border:SetBackdrop(PaneBackdrop) |
border:SetBackdropColor(0.1, 0.1, 0.1, 0.5) |
border:SetBackdropBorderColor(0.4, 0.4, 0.4) |
--Container Support |
local content = CreateFrame("Frame", nil, border) |
content:SetPoint("TOPLEFT", 10, -10) |
content:SetPoint("BOTTOMRIGHT", -10, 10) |
local widget = { |
frame = frame, |
lines = {}, |
levels = {}, |
buttons = {}, |
hasChildren = {}, |
localstatus = { groups = {}, scrollvalue = 0 }, |
filter = false, |
treeframe = treeframe, |
dragger = dragger, |
scrollbar = scrollbar, |
border = border, |
content = content, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
end |
treeframe.obj, dragger.obj, scrollbar.obj = widget, widget, widget |
return AceGUI:RegisterAsContainer(widget) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |