Guest User

Untitled

a guest
Dec 11th, 2022
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.51 KB | None | 0 0
  1. --[[-----------------------------------------------------------------------------
  2. TreeGroup Container
  3. Container that uses a tree control to switch between groups.
  4. -------------------------------------------------------------------------------]]
  5. local Type, Version = "AngryTreeGroup", 2
  6. local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
  7. if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
  8.  
  9. local IsLegion = select(4, GetBuildInfo()) >= 70000
  10.  
  11. -- Lua APIs
  12. local next, pairs, ipairs, assert, type = next, pairs, ipairs, assert, type
  13. local math_min, math_max, floor = math.min, math.max, floor
  14. local select, tremove, unpack, tconcat = select, table.remove, unpack, table.concat
  15.  
  16. -- WoW APIs
  17. local CreateFrame, UIParent = CreateFrame, UIParent
  18.  
  19. -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
  20. -- List them here for Mikk's FindGlobals script
  21. -- GLOBALS: GameTooltip, FONT_COLOR_CODE_CLOSE
  22.  
  23. -- Recycling functions
  24. local new, del
  25. do
  26. local pool = setmetatable({},{__mode='k'})
  27. function new()
  28. local t = next(pool)
  29. if t then
  30. pool[t] = nil
  31. return t
  32. else
  33. return {}
  34. end
  35. end
  36. function del(t)
  37. for k in pairs(t) do
  38. t[k] = nil
  39. end
  40. pool[t] = true
  41. end
  42. end
  43.  
  44. local DEFAULT_TREE_WIDTH = 175
  45. local DEFAULT_TREE_SIZABLE = true
  46.  
  47. --[[-----------------------------------------------------------------------------
  48. Support functions
  49. -------------------------------------------------------------------------------]]
  50. local function GetButtonUniqueValue(line)
  51. local parent = line.parent
  52. if parent and parent.value then
  53. return GetButtonUniqueValue(parent).."\001"..line.value
  54. else
  55. return line.value
  56. end
  57. end
  58.  
  59. local function UpdateButton(button, treeline, selected, canExpand, isExpanded)
  60. local self = button.obj
  61. local toggle = button.toggle
  62. local frame = self.frame
  63. local text = treeline.text or ""
  64. local icon = treeline.icon
  65. local iconCoords = treeline.iconCoords
  66. local level = treeline.level
  67. local value = treeline.value
  68. local uniquevalue = treeline.uniquevalue
  69. local disabled = treeline.disabled
  70.  
  71. button.treeline = treeline
  72. button.value = value
  73. button.uniquevalue = uniquevalue
  74. if selected then
  75. button:LockHighlight()
  76. button.selected = true
  77. else
  78. button:UnlockHighlight()
  79. button.selected = false
  80. end
  81. local normalTexture = button:GetNormalTexture()
  82. local line = button.line
  83. button.level = level
  84. if ( level == 1 ) then
  85. button.text:SetPoint("LEFT", (icon and 16 or 0) + 8, 2)
  86. else
  87. button.text:SetPoint("LEFT", (icon and 16 or 0) + 8 * level, 2)
  88. end
  89.  
  90. if disabled then
  91. button:EnableMouse(false)
  92. button.text:SetText("|cff808080"..text..FONT_COLOR_CODE_CLOSE)
  93. else
  94. button.text:SetText(text)
  95. button:EnableMouse(true)
  96. end
  97.  
  98. if icon then
  99. button.icon:SetTexture(icon)
  100. button.icon:SetPoint("LEFT", 8 * level, (level == 1) and 0 or 1)
  101. else
  102. button.icon:SetTexture(nil)
  103. end
  104.  
  105. if iconCoords then
  106. button.icon:SetTexCoord(unpack(iconCoords))
  107. else
  108. button.icon:SetTexCoord(0, 1, 0, 1)
  109. end
  110.  
  111. if canExpand or level == 1 then
  112. button:SetNormalFontObject("GameFontNormal")
  113. button:SetHighlightFontObject("GameFontHighlight")
  114. else
  115. button:SetNormalFontObject("GameFontHighlight")
  116. button:SetHighlightFontObject("GameFontHighlight")
  117. end
  118.  
  119. if canExpand then
  120. if not isExpanded then
  121. toggle:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-UP")
  122. toggle:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-DOWN")
  123. else
  124. toggle:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-UP")
  125. toggle:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-DOWN")
  126. end
  127. toggle:Show()
  128. else
  129. toggle:Hide()
  130. end
  131. end
  132.  
  133. local function ShouldDisplayLevel(tree)
  134. local result = false
  135. for k, v in ipairs(tree) do
  136. if v.children == nil and v.visible ~= false then
  137. result = true
  138. elseif v.children then
  139. result = result or ShouldDisplayLevel(v.children)
  140. end
  141. if result then return result end
  142. end
  143. return false
  144. end
  145.  
  146. local function addLine(self, v, tree, level, parent)
  147. local line = new()
  148. line.value = v.value
  149. line.text = v.text
  150. line.icon = v.icon
  151. line.iconCoords = v.iconCoords
  152. line.disabled = v.disabled
  153. line.tree = tree
  154. line.level = level
  155. line.parent = parent
  156. line.visible = v.visible
  157. line.uniquevalue = GetButtonUniqueValue(line)
  158. if v.children then
  159. line.hasChildren = true
  160. else
  161. line.hasChildren = nil
  162. end
  163. self.lines[#self.lines+1] = line
  164. return line
  165. end
  166.  
  167. --fire an update after one frame to catch the treeframes height
  168. local function FirstFrameUpdate(frame)
  169. local self = frame.obj
  170. frame:SetScript("OnUpdate", nil)
  171. self:RefreshTree()
  172. end
  173.  
  174. local function BuildUniqueValue(...)
  175. local n = select('#', ...)
  176. if n == 1 then
  177. return ...
  178. else
  179. return (...).."\001"..BuildUniqueValue(select(2,...))
  180. end
  181. end
  182.  
  183. --[[-----------------------------------------------------------------------------
  184. Scripts
  185. -------------------------------------------------------------------------------]]
  186. local function Expand_OnClick(frame)
  187. local button = frame.button
  188. local self = button.obj
  189. local status = (self.status or self.localstatus).groups
  190. status[button.uniquevalue] = not status[button.uniquevalue]
  191. self:RefreshTree()
  192. end
  193.  
  194. local function Button_OnClick(frame, button)
  195. local self = frame.obj
  196. local result = self:Fire("OnClick", frame.uniquevalue, frame.selected, button)
  197. if result ~= false and not frame.selected then
  198. self:SetSelected(frame.uniquevalue)
  199. frame.selected = true
  200. frame:LockHighlight()
  201. self:RefreshTree()
  202. end
  203. AceGUI:ClearFocus()
  204. end
  205.  
  206. local function Button_OnDoubleClick(button)
  207. local self = button.obj
  208. local status = self.status or self.localstatus
  209. local status = (self.status or self.localstatus).groups
  210. status[button.uniquevalue] = not status[button.uniquevalue]
  211. self:RefreshTree()
  212. end
  213.  
  214. local function Button_OnEnter(frame)
  215. local self = frame.obj
  216. self:Fire("OnButtonEnter", frame.uniquevalue, frame)
  217.  
  218. if self.enabletooltips then
  219. GameTooltip:SetOwner(frame, "ANCHOR_NONE")
  220. GameTooltip:SetPoint("LEFT",frame,"RIGHT")
  221. GameTooltip:SetText(frame.text:GetText() or "", 1, .82, 0, true)
  222.  
  223. GameTooltip:Show()
  224. end
  225. end
  226.  
  227. local function Button_OnLeave(frame)
  228. local self = frame.obj
  229. self:Fire("OnButtonLeave", frame.uniquevalue, frame)
  230.  
  231. if self.enabletooltips then
  232. GameTooltip:Hide()
  233. end
  234. end
  235.  
  236. local function OnScrollValueChanged(frame, value)
  237. if frame.obj.noupdate then return end
  238. local self = frame.obj
  239. local status = self.status or self.localstatus
  240. status.scrollvalue = floor(value + 0.5)
  241. self:RefreshTree()
  242. AceGUI:ClearFocus()
  243. end
  244.  
  245. local function Tree_OnSizeChanged(frame)
  246. frame.obj:RefreshTree()
  247. end
  248.  
  249. local function Tree_OnMouseWheel(frame, delta)
  250. local self = frame.obj
  251. if self.showscroll then
  252. local scrollbar = self.scrollbar
  253. local min, max = scrollbar:GetMinMaxValues()
  254. local value = scrollbar:GetValue()
  255. local newvalue = math_min(max,math_max(min,value - delta))
  256. if value ~= newvalue then
  257. scrollbar:SetValue(newvalue)
  258. end
  259. end
  260. end
  261.  
  262. local function Dragger_OnLeave(frame)
  263. frame:SetBackdropColor(1, 1, 1, 0)
  264. end
  265.  
  266. local function Dragger_OnEnter(frame)
  267. frame:SetBackdropColor(1, 1, 1, 0.8)
  268. end
  269.  
  270. local function Dragger_OnMouseDown(frame)
  271. local treeframe = frame:GetParent()
  272. treeframe:StartSizing("RIGHT")
  273. end
  274.  
  275. local function Dragger_OnMouseUp(frame)
  276. local treeframe = frame:GetParent()
  277. local self = treeframe.obj
  278. local frame = treeframe:GetParent()
  279. treeframe:StopMovingOrSizing()
  280. --treeframe:SetScript("OnUpdate", nil)
  281. treeframe:SetUserPlaced(false)
  282. --Without this :GetHeight will get stuck on the current height, causing the tree contents to not resize
  283. treeframe:SetHeight(0)
  284. treeframe:SetPoint("TOPLEFT", frame, "TOPLEFT",0,0)
  285. treeframe:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT",0,0)
  286.  
  287. local status = self.status or self.localstatus
  288. status.treewidth = treeframe:GetWidth()
  289.  
  290. treeframe.obj:Fire("OnTreeResize",treeframe:GetWidth())
  291. -- recalculate the content width
  292. treeframe.obj:OnWidthSet(status.fullwidth)
  293. -- update the layout of the content
  294. treeframe.obj:DoLayout()
  295. end
  296.  
  297. --[[-----------------------------------------------------------------------------
  298. Methods
  299. -------------------------------------------------------------------------------]]
  300. local methods = {
  301. ["OnAcquire"] = function(self)
  302. self:SetTreeWidth(DEFAULT_TREE_WIDTH, DEFAULT_TREE_SIZABLE)
  303. self:EnableButtonTooltips(true)
  304. self.frame:SetScript("OnUpdate", FirstFrameUpdate)
  305. end,
  306.  
  307. ["OnRelease"] = function(self)
  308. self.status = nil
  309. for k, v in pairs(self.localstatus) do
  310. if k == "groups" then
  311. for k2 in pairs(v) do
  312. v[k2] = nil
  313. end
  314. else
  315. self.localstatus[k] = nil
  316. end
  317. end
  318. self.localstatus.scrollvalue = 0
  319. self.localstatus.treewidth = DEFAULT_TREE_WIDTH
  320. self.localstatus.treesizable = DEFAULT_TREE_SIZABLE
  321. end,
  322.  
  323. ["EnableButtonTooltips"] = function(self, enable)
  324. self.enabletooltips = enable
  325. end,
  326.  
  327. ["CreateButton"] = function(self)
  328. local num = AceGUI:GetNextWidgetNum("TreeGroupButton")
  329. local button = CreateFrame("Button", ("AceGUI30TreeButton%d"):format(num), self.treeframe, "OptionsListButtonTemplate")
  330. button.obj = self
  331.  
  332. local icon = button:CreateTexture(nil, "OVERLAY")
  333. icon:SetWidth(14)
  334. icon:SetHeight(14)
  335. button.icon = icon
  336.  
  337. button:SetScript("OnClick",Button_OnClick)
  338. --button:SetScript("OnDoubleClick", Button_OnDoubleClick)
  339. button:SetScript("OnEnter",Button_OnEnter)
  340. button:SetScript("OnLeave",Button_OnLeave)
  341.  
  342. button.toggle.button = button
  343. button.toggle:SetScript("OnClick",Expand_OnClick)
  344.  
  345. button.text:SetHeight(14) -- Prevents text wrapping
  346.  
  347. return button
  348. end,
  349.  
  350. ["SetStatusTable"] = function(self, status)
  351. assert(type(status) == "table")
  352. self.status = status
  353. if not status.groups then
  354. status.groups = {}
  355. end
  356. if not status.scrollvalue then
  357. status.scrollvalue = 0
  358. end
  359. if not status.treewidth then
  360. status.treewidth = DEFAULT_TREE_WIDTH
  361. end
  362. if status.treesizable == nil then
  363. status.treesizable = DEFAULT_TREE_SIZABLE
  364. end
  365. self:SetTreeWidth(status.treewidth,status.treesizable)
  366. self:RefreshTree()
  367. end,
  368.  
  369. --sets the tree to be displayed
  370. ["SetTree"] = function(self, tree, filter)
  371. self.filter = filter
  372. if tree then
  373. assert(type(tree) == "table")
  374. end
  375. self.tree = tree
  376. self:RefreshTree()
  377. end,
  378.  
  379. ["BuildLevel"] = function(self, tree, level, parent)
  380. local groups = (self.status or self.localstatus).groups
  381. local hasChildren = self.hasChildren
  382.  
  383. for i, v in ipairs(tree) do
  384. if v.children then
  385. if not self.filter or ShouldDisplayLevel(v.children) then
  386. local line = addLine(self, v, tree, level, parent)
  387. if groups[line.uniquevalue] then
  388. self:BuildLevel(v.children, level+1, line)
  389. end
  390. end
  391. elseif v.visible ~= false or not self.filter then
  392. addLine(self, v, tree, level, parent)
  393. end
  394. end
  395. end,
  396.  
  397. ["RefreshTree"] = function(self,scrollToSelection)
  398. local buttons = self.buttons
  399. local lines = self.lines
  400.  
  401. for i, v in ipairs(buttons) do
  402. v:Hide()
  403. end
  404. while lines[1] do
  405. local t = tremove(lines)
  406. for k in pairs(t) do
  407. t[k] = nil
  408. end
  409. del(t)
  410. end
  411.  
  412. if not self.tree then return end
  413. --Build the list of visible entries from the tree and status tables
  414. local status = self.status or self.localstatus
  415. local groupstatus = status.groups
  416. local tree = self.tree
  417.  
  418. local treeframe = self.treeframe
  419.  
  420. status.scrollToSelection = status.scrollToSelection or scrollToSelection -- needs to be cached in case the control hasn't been drawn yet (code bails out below)
  421.  
  422. self:BuildLevel(tree, 1)
  423.  
  424. local numlines = #lines
  425.  
  426. local maxlines = (floor(((self.treeframe:GetHeight()or 0) - 20 ) / 18))
  427. if maxlines <= 0 then return end
  428.  
  429. local first, last
  430.  
  431. scrollToSelection = status.scrollToSelection
  432. status.scrollToSelection = nil
  433.  
  434. if numlines <= maxlines then
  435. --the whole tree fits in the frame
  436. status.scrollvalue = 0
  437. self:ShowScroll(false)
  438. first, last = 1, numlines
  439. else
  440. self:ShowScroll(true)
  441. --scrolling will be needed
  442. self.noupdate = true
  443. self.scrollbar:SetMinMaxValues(0, numlines - maxlines)
  444. --check if we are scrolled down too far
  445. if numlines - status.scrollvalue < maxlines then
  446. status.scrollvalue = numlines - maxlines
  447. end
  448. self.noupdate = nil
  449. first, last = status.scrollvalue+1, status.scrollvalue + maxlines
  450. --show selection?
  451. if scrollToSelection and status.selected then
  452. local show
  453. for i,line in ipairs(lines) do -- find the line number
  454. if line.uniquevalue==status.selected then
  455. show=i
  456. end
  457. end
  458. if not show then
  459. -- selection was deleted or something?
  460. elseif show>=first and show<=last then
  461. -- all good
  462. else
  463. -- scrolling needed!
  464. if show<first then
  465. status.scrollvalue = show-1
  466. else
  467. status.scrollvalue = show-maxlines
  468. end
  469. first, last = status.scrollvalue+1, status.scrollvalue + maxlines
  470. end
  471. end
  472. if self.scrollbar:GetValue() ~= status.scrollvalue then
  473. self.scrollbar:SetValue(status.scrollvalue)
  474. end
  475. end
  476.  
  477. local buttonnum = 1
  478. for i = first, last do
  479. local line = lines[i]
  480. local button = buttons[buttonnum]
  481. if not button then
  482. button = self:CreateButton()
  483.  
  484. buttons[buttonnum] = button
  485. button:SetParent(treeframe)
  486. button:SetFrameLevel(treeframe:GetFrameLevel()+1)
  487. button:ClearAllPoints()
  488. if buttonnum == 1 then
  489. if self.showscroll then
  490. button:SetPoint("TOPRIGHT", -22, -10)
  491. button:SetPoint("TOPLEFT", 0, -10)
  492. else
  493. button:SetPoint("TOPRIGHT", 0, -10)
  494. button:SetPoint("TOPLEFT", 0, -10)
  495. end
  496. else
  497. button:SetPoint("TOPRIGHT", buttons[buttonnum-1], "BOTTOMRIGHT",0,0)
  498. button:SetPoint("TOPLEFT", buttons[buttonnum-1], "BOTTOMLEFT",0,0)
  499. end
  500. end
  501.  
  502. UpdateButton(button, line, status.selected == line.uniquevalue, line.hasChildren, groupstatus[line.uniquevalue] )
  503. button:Show()
  504. buttonnum = buttonnum + 1
  505. end
  506.  
  507. end,
  508.  
  509. ["SetSelected"] = function(self, value)
  510. local status = self.status or self.localstatus
  511. if status.selected ~= value then
  512. status.selected = value
  513. self:Fire("OnGroupSelected", value)
  514. end
  515. end,
  516.  
  517. ["Select"] = function(self, uniquevalue, ...)
  518. self.filter = false
  519. local status = self.status or self.localstatus
  520. local groups = status.groups
  521. local path = {...}
  522. for i = 1, #path do
  523. groups[tconcat(path, "\001", 1, i)] = true
  524. end
  525. status.selected = uniquevalue
  526. self:RefreshTree(true)
  527. self:Fire("OnGroupSelected", uniquevalue)
  528. end,
  529.  
  530. ["SelectByPath"] = function(self, ...)
  531. self:Select(BuildUniqueValue(...), ...)
  532. end,
  533.  
  534. ["SelectByValue"] = function(self, uniquevalue)
  535. self:Select(uniquevalue, ("\001"):split(uniquevalue))
  536. end,
  537.  
  538. ["ShowScroll"] = function(self, show)
  539. self.showscroll = show
  540. if show then
  541. self.scrollbar:Show()
  542. if self.buttons[1] then
  543. self.buttons[1]:SetPoint("TOPRIGHT", self.treeframe,"TOPRIGHT",-22,-10)
  544. end
  545. else
  546. self.scrollbar:Hide()
  547. if self.buttons[1] then
  548. self.buttons[1]:SetPoint("TOPRIGHT", self.treeframe,"TOPRIGHT",0,-10)
  549. end
  550. end
  551. end,
  552.  
  553. ["OnWidthSet"] = function(self, width)
  554. local content = self.content
  555. local treeframe = self.treeframe
  556. local status = self.status or self.localstatus
  557. status.fullwidth = width
  558.  
  559. local contentwidth = width - status.treewidth - 20
  560. if contentwidth < 0 then
  561. contentwidth = 0
  562. end
  563. content:SetWidth(contentwidth)
  564. content.width = contentwidth
  565.  
  566. local maxtreewidth = math_min(400, width - 50)
  567.  
  568. if maxtreewidth > 100 and status.treewidth > maxtreewidth then
  569. self:SetTreeWidth(maxtreewidth, status.treesizable)
  570. end
  571. treeframe:SetResizeBounds(100, 1, maxtreewidth, 1600)
  572. end,
  573.  
  574. ["OnHeightSet"] = function(self, height)
  575. local content = self.content
  576. local contentheight = height - 20
  577. if contentheight < 0 then
  578. contentheight = 0
  579. end
  580. content:SetHeight(contentheight)
  581. content.height = contentheight
  582. end,
  583.  
  584. ["SetTreeWidth"] = function(self, treewidth, resizable)
  585. if not resizable then
  586. if type(treewidth) == 'number' then
  587. resizable = false
  588. elseif type(treewidth) == 'boolean' then
  589. resizable = treewidth
  590. treewidth = DEFAULT_TREE_WIDTH
  591. else
  592. resizable = false
  593. treewidth = DEFAULT_TREE_WIDTH
  594. end
  595. end
  596. self.treeframe:SetWidth(treewidth)
  597. self.dragger:EnableMouse(resizable)
  598.  
  599. local status = self.status or self.localstatus
  600. status.treewidth = treewidth
  601. status.treesizable = resizable
  602.  
  603. -- recalculate the content width
  604. if status.fullwidth then
  605. self:OnWidthSet(status.fullwidth)
  606. end
  607. end,
  608.  
  609. ["GetTreeWidth"] = function(self)
  610. local status = self.status or self.localstatus
  611. return status.treewidth or DEFAULT_TREE_WIDTH
  612. end,
  613.  
  614. ["LayoutFinished"] = function(self, width, height)
  615. if self.noAutoHeight then return end
  616. self:SetHeight((height or 0) + 20)
  617. end
  618. }
  619.  
  620. --[[-----------------------------------------------------------------------------
  621. Constructor
  622. -------------------------------------------------------------------------------]]
  623. local PaneBackdrop = {
  624. bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
  625. edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  626. tile = true, tileSize = 16, edgeSize = 16,
  627. insets = { left = 3, right = 3, top = 5, bottom = 3 }
  628. }
  629.  
  630. local DraggerBackdrop = {
  631. bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  632. edgeFile = nil,
  633. tile = true, tileSize = 16, edgeSize = 0,
  634. insets = { left = 3, right = 3, top = 7, bottom = 7 }
  635. }
  636.  
  637. local function Constructor()
  638. local num = AceGUI:GetNextWidgetNum(Type)
  639. local frame = CreateFrame("Frame", nil, UIParent)
  640.  
  641. local treeframe = CreateFrame("Frame", nil, frame, BackdropTemplateMixin and "BackdropTemplate" or nil)
  642. treeframe:SetPoint("TOPLEFT")
  643. treeframe:SetPoint("BOTTOMLEFT")
  644. treeframe:SetWidth(DEFAULT_TREE_WIDTH)
  645. treeframe:EnableMouseWheel(true)
  646. treeframe:SetBackdrop(PaneBackdrop)
  647. treeframe:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
  648. treeframe:SetBackdropBorderColor(0.4, 0.4, 0.4)
  649. treeframe:SetResizable(true)
  650. treeframe:SetResizeBounds(100, 1, 400, 1600)
  651. treeframe:SetScript("OnUpdate", FirstFrameUpdate)
  652. treeframe:SetScript("OnSizeChanged", Tree_OnSizeChanged)
  653. treeframe:SetScript("OnMouseWheel", Tree_OnMouseWheel)
  654.  
  655. local dragger = CreateFrame("Frame", nil, treeframe, BackdropTemplateMixin and "BackdropTemplate" or nil)
  656. dragger:SetWidth(8)
  657. dragger:SetPoint("TOP", treeframe, "TOPRIGHT")
  658. dragger:SetPoint("BOTTOM", treeframe, "BOTTOMRIGHT")
  659. dragger:SetBackdrop(DraggerBackdrop)
  660. dragger:SetBackdropColor(1, 1, 1, 0)
  661. dragger:SetScript("OnEnter", Dragger_OnEnter)
  662. dragger:SetScript("OnLeave", Dragger_OnLeave)
  663. dragger:SetScript("OnMouseDown", Dragger_OnMouseDown)
  664. dragger:SetScript("OnMouseUp", Dragger_OnMouseUp)
  665.  
  666. local scrollbar = CreateFrame("Slider", ("AceConfigDialogTreeGroup%dScrollBar"):format(num), treeframe, "UIPanelScrollBarTemplate")
  667. scrollbar:SetScript("OnValueChanged", nil)
  668. scrollbar:SetPoint("TOPRIGHT", -10, -26)
  669. scrollbar:SetPoint("BOTTOMRIGHT", -10, 26)
  670. scrollbar:SetMinMaxValues(0,0)
  671. scrollbar:SetValueStep(1)
  672. scrollbar:SetValue(0)
  673. scrollbar:SetWidth(16)
  674. scrollbar:SetScript("OnValueChanged", OnScrollValueChanged)
  675.  
  676. local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND")
  677. scrollbg:SetAllPoints(scrollbar)
  678.  
  679. if IsLegion then
  680. scrollbg:SetColorTexture(0,0,0,0.4)
  681. else
  682. scrollbg:SetTexture(0,0,0,0.4)
  683. end
  684.  
  685. local border = CreateFrame("Frame",nil,frame, BackdropTemplateMixin and "BackdropTemplate" or nil)
  686. border:SetPoint("TOPLEFT", treeframe, "TOPRIGHT")
  687. border:SetPoint("BOTTOMRIGHT")
  688. border:SetBackdrop(PaneBackdrop)
  689. border:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
  690. border:SetBackdropBorderColor(0.4, 0.4, 0.4)
  691.  
  692. --Container Support
  693. local content = CreateFrame("Frame", nil, border)
  694. content:SetPoint("TOPLEFT", 10, -10)
  695. content:SetPoint("BOTTOMRIGHT", -10, 10)
  696.  
  697. local widget = {
  698. frame = frame,
  699. lines = {},
  700. levels = {},
  701. buttons = {},
  702. hasChildren = {},
  703. localstatus = { groups = {}, scrollvalue = 0 },
  704. filter = false,
  705. treeframe = treeframe,
  706. dragger = dragger,
  707. scrollbar = scrollbar,
  708. border = border,
  709. content = content,
  710. type = Type
  711. }
  712. for method, func in pairs(methods) do
  713. widget[method] = func
  714. end
  715. treeframe.obj, dragger.obj, scrollbar.obj = widget, widget, widget
  716.  
  717. return AceGUI:RegisterAsContainer(widget)
  718. end
  719.  
  720. AceGUI:RegisterWidgetType(Type, Constructor, Version)
  721.  
Advertisement
Add Comment
Please, Sign In to add comment