Ace3 backport

This commit is contained in:
Pinya
2018-07-21 13:29:50 +03:00
parent 332d53e7f6
commit f0eac39bcd
43 changed files with 1071 additions and 846 deletions
@@ -9,7 +9,8 @@ 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
local tremove, unpack, tconcat, getn = table.remove, unpack, table.concat, getn
local format, split = string.format, string.split
-- WoW APIs
local CreateFrame, UIParent = CreateFrame, UIParent
@@ -80,11 +81,11 @@ local function UpdateButton(button, treeline, selected, canExpand, isExpanded)
local line = button.line
button.level = level
if ( level == 1 ) then
button:SetTextFontObject("GameFontNormal")
button.text:SetFontObject("GameFontNormal")
button:SetHighlightFontObject("GameFontHighlight")
button.text:SetPoint("LEFT", (icon and 16 or 0) + 8, 2)
else
button:SetTextFontObject("GameFontHighlightSmall")
button.text:SetFontObject("GameFontHighlightSmall")
button:SetHighlightFontObject("GameFontHighlightSmall")
button.text:SetPoint("LEFT", (icon and 16 or 0) + 8 * level, 2)
end
@@ -154,120 +155,115 @@ local function addLine(self, v, tree, level, parent)
else
line.hasChildren = nil
end
self.lines[#self.lines+1] = line
tinsert(self.lines, 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)
local function FirstFrameUpdate()
local self = this.obj
this:SetScript("OnUpdate", nil)
self:RefreshTree()
end
local function BuildUniqueValue(...)
local n = select('#', ...)
if n == 1 then
return ...
else
return (...).."\001"..BuildUniqueValue(select(2,...))
end
return tconcat(arg, "\001", 1, getn(arg))
end
--[[-----------------------------------------------------------------------------
Scripts
-------------------------------------------------------------------------------]]
local function Expand_OnClick(frame)
local button = frame.button
local function Expand_OnClick()
local button = this.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()
local function Button_OnClick()
local self = this.obj
self:Fire("OnClick", this.uniquevalue, this.selected)
if not this.selected then
self:SetSelected(this.uniquevalue)
this.selected = true
this:LockHighlight()
self:RefreshTree()
end
AceGUI:ClearFocus()
end
local function Button_OnDoubleClick(button)
local self = button.obj
local function Button_OnDoubleClick()
local self = this.obj
local status = self.status or self.localstatus
local status = (self.status or self.localstatus).groups
status[button.uniquevalue] = not status[button.uniquevalue]
status[this.uniquevalue] = not status[this.uniquevalue]
self:RefreshTree()
end
local function Button_OnEnter(frame)
local self = frame.obj
self:Fire("OnButtonEnter", frame.uniquevalue, frame)
local function Button_OnEnter()
local self = this.obj
self:Fire("OnButtonEnter", this.uniquevalue, this)
if self.enabletooltips then
GameTooltip:SetOwner(frame, "ANCHOR_NONE")
GameTooltip:SetPoint("LEFT",frame,"RIGHT")
GameTooltip:SetText(frame.text:GetText() or "", 1, .82, 0, 1)
GameTooltip:SetOwner(this, "ANCHOR_NONE")
GameTooltip:SetPoint("LEFT",this,"RIGHT")
GameTooltip:SetText(this.text:GetText() or "", 1, .82, 0, 1)
GameTooltip:Show()
end
end
local function Button_OnLeave(frame)
local self = frame.obj
self:Fire("OnButtonLeave", frame.uniquevalue, frame)
local function Button_OnLeave()
local self = this.obj
self:Fire("OnButtonLeave", this.uniquevalue, this)
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 function OnScrollValueChanged()
if this.obj.noupdate then return end
local self = this.obj
local status = self.status or self.localstatus
status.scrollvalue = value
status.scrollvalue = arg1
self:RefreshTree()
AceGUI:ClearFocus()
end
local function Tree_OnSizeChanged(frame)
frame.obj:RefreshTree()
local function Tree_OnSizeChanged()
this.obj:RefreshTree()
end
local function Tree_OnMouseWheel(frame, delta)
local self = frame.obj
local function Tree_OnMouseWheel()
local self = this.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))
local newvalue = math_min(max,math_max(min,value - arg1))
if value ~= newvalue then
scrollbar:SetValue(newvalue)
end
end
end
local function Dragger_OnLeave(frame)
frame:SetBackdropColor(1, 1, 1, 0)
local function Dragger_OnLeave()
this:SetBackdropColor(1, 1, 1, 0)
end
local function Dragger_OnEnter(frame)
frame:SetBackdropColor(1, 1, 1, 0.8)
local function Dragger_OnEnter()
this:SetBackdropColor(1, 1, 1, 0.8)
end
local function Dragger_OnMouseDown(frame)
local treeframe = frame:GetParent()
local function Dragger_OnMouseDown()
local treeframe = this:GetParent()
treeframe:StartSizing("RIGHT")
end
local function Dragger_OnMouseUp(frame)
local treeframe = frame:GetParent()
local function Dragger_OnMouseUp()
local treeframe = this:GetParent()
local self = treeframe.obj
local frame = treeframe:GetParent()
treeframe:StopMovingOrSizing()
@@ -319,9 +315,39 @@ local methods = {
["CreateButton"] = function(self)
local num = AceGUI:GetNextWidgetNum("TreeGroupButton")
local button = CreateFrame("Button", ("AceGUI30TreeButton%d"):format(num), self.treeframe, "InterfaceOptionsButtonTemplate")
local button = CreateFrame("Button", format("AceGUI30TreeButton%d", num), self.treeframe)
button.obj = self
button:SetWidth(175)
button:SetHeight(18)
local toggle = CreateFrame("Button", nil, button)
toggle:SetWidth(14)
toggle:SetHeight(14)
toggle:ClearAllPoints()
toggle:SetPoint("TOPRIGHT", button, "TOPRIGHT", -6, -1)
toggle:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-UP")
toggle:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-DOWN")
toggle:SetHighlightTexture("Interface\Buttons\UI-PlusButton-Hilight", "ADD")
toggle:SetScript("OnClick", Button_OnClick)
button.toggle = toggle
toggle.obj = button
local text = button:CreateFontString()
text:SetFontObject(GameFontNormal)
text:SetPoint("RIGHT", toggle, "LEFT", -2, 0)
text:SetJustifyH("LEFT")
button:SetHighlightFontObject(GameFontHighlight)
button.text = text
local highlight = button:CreateTexture(nil, "HIGHLIGHT")
highlight:SetPoint("TOPLEFT", 0, 1)
highlight:SetPoint("BOTTOMRIGHT", 0, 1)
highlight:SetTexture("Interface\\QuestFrame\\UI-QuestLogTitleHighlight")
highlight:SetBlendMode("ADD")
highlight:SetVertexColor(.196, .388, .8)
button.highlight = highlight
local icon = button:CreateTexture(nil, "OVERLAY")
icon:SetWidth(14)
icon:SetHeight(14)
@@ -414,7 +440,7 @@ local methods = {
self:BuildLevel(tree, 1)
local numlines = #lines
local numlines = getn(lines)
local maxlines = (floor(((self.treeframe:GetHeight()or 0) - 20 ) / 18))
if maxlines <= 0 then return end
@@ -511,9 +537,8 @@ local methods = {
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
for i = 1, getn(arg) do
groups[tconcat(arg, "\001", 1, i)] = true
end
status.selected = uniquevalue
self:RefreshTree(true)
@@ -521,11 +546,11 @@ local methods = {
end,
["SelectByPath"] = function(self, ...)
self:Select(BuildUniqueValue(...), ...)
self:Select(BuildUniqueValue(unpack(arg)), unpack(arg))
end,
["SelectByValue"] = function(self, uniquevalue)
self:Select(uniquevalue, ("\001"):split(uniquevalue))
self:Select(uniquevalue, split("\001", uniquevalue))
end,
["ShowScroll"] = function(self, show)
@@ -632,8 +657,8 @@ local function Constructor()
local frame = CreateFrame("Frame", nil, UIParent)
local treeframe = CreateFrame("Frame", nil, frame)
treeframe:SetPoint("TOPLEFT")
treeframe:SetPoint("BOTTOMLEFT")
treeframe:SetPoint("TOPLEFT", 0, 0)
treeframe:SetPoint("BOTTOMLEFT", 0, 0)
treeframe:SetWidth(DEFAULT_TREE_WIDTH)
treeframe:EnableMouseWheel(true)
treeframe:SetBackdrop(PaneBackdrop)
@@ -657,7 +682,7 @@ local function Constructor()
dragger:SetScript("OnMouseDown", Dragger_OnMouseDown)
dragger:SetScript("OnMouseUp", Dragger_OnMouseUp)
local scrollbar = CreateFrame("Slider", ("AceConfigDialogTreeGroup%dScrollBar"):format(num), treeframe, "UIPanelScrollBarTemplate")
local scrollbar = CreateFrame("Slider", format("AceConfigDialogTreeGroup%dScrollBar", num), treeframe, "UIPanelScrollBarTemplate")
scrollbar:SetScript("OnValueChanged", nil)
scrollbar:SetPoint("TOPRIGHT", -10, -26)
scrollbar:SetPoint("BOTTOMRIGHT", -10, 26)
@@ -673,7 +698,7 @@ local function Constructor()
local border = CreateFrame("Frame",nil,frame)
border:SetPoint("TOPLEFT", treeframe, "TOPRIGHT")
border:SetPoint("BOTTOMRIGHT")
border:SetPoint("BOTTOMRIGHT", 0, 0)
border:SetBackdrop(PaneBackdrop)
border:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
border:SetBackdropBorderColor(0.4, 0.4, 0.4)