Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.50 KB | None | 0 0
  1. --[[
  2. frame.lua
  3. The base frame widget
  4. --]]
  5.  
  6. local ADDON, Addon = ...
  7. local L = LibStub('AceLocale-3.0'):GetLocale(ADDON)
  8. local Frame = Addon:NewClass('Frame', 'Frame')
  9. Frame.OpenSound = 'igBackPackOpen'
  10. Frame.CloseSound = 'igBackPackClose'
  11. Frame.ItemFrame = Addon.ItemFrame
  12. Frame.BagFrame = Addon.BagFrame
  13. Frame.MoneyFrame = Addon.MoneyFrame
  14.  
  15.  
  16. --[[ Constructor ]]--
  17.  
  18. function Frame:New(id)
  19. local f = self:Bind(CreateFrame('Frame', ADDON .. 'Frame' .. id, UIParent))
  20. f:SetClampedToScreen(true)
  21. f:SetMovable(true)
  22. f:EnableMouse(true)
  23. f:Hide()
  24.  
  25. f:SetBackdrop{
  26. bgFile = [[Interface\ChatFrame\ChatFrameBackground]],
  27. edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
  28. edgeSize = 16,
  29. tile = true, tileSize = 16,
  30. insets = {left = 4, right = 4, top = 4, bottom = 4}
  31. }
  32.  
  33. f.frameID = id
  34. f:SetScript('OnShow', f.OnShow)
  35. f:SetScript('OnHide', f.OnHide)
  36. f:Rescale()
  37. f:UpdateEverything()
  38.  
  39. tinsert(UISpecialFrames, f:GetName())
  40. return f
  41. end
  42.  
  43.  
  44. --[[ Frame Messages ]]--
  45.  
  46. function Frame:UpdateEvents()
  47. self:UnregisterAllMessages()
  48. self:RegisterMessage('FRAME_SHOW')
  49.  
  50. if self:IsVisible() then
  51. self:RegisterMessage('FRAME_HIDE')
  52. self:RegisterMessage('FRAME_LAYER_UPDATE')
  53. self:RegisterMessage('FRAME_MOVE_START')
  54. self:RegisterMessage('FRAME_MOVE_STOP')
  55. self:RegisterMessage('FRAME_POSITION_UPDATE')
  56. self:RegisterMessage('FRAME_OPACITY_UPDATE')
  57. self:RegisterMessage('FRAME_COLOR_UPDATE')
  58. self:RegisterMessage('FRAME_BORDER_COLOR_UPDATE')
  59. self:RegisterMessage('FRAME_SCALE_UPDATE')
  60. self:RegisterMessage('BAG_FRAME_UPDATE_SHOWN')
  61. self:RegisterMessage('BAG_FRAME_UPDATE_LAYOUT')
  62. self:RegisterMessage('ITEM_FRAME_SIZE_CHANGE')
  63.  
  64. self:RegisterMessage('BAG_FRAME_ENABLE_UPDATE')
  65. self:RegisterMessage('MONEY_FRAME_ENABLE_UPDATE')
  66. self:RegisterMessage('DATABROKER_FRAME_ENABLE_UPDATE')
  67. self:RegisterMessage('SEARCH_TOGGLE_ENABLE_UPDATE')
  68. self:RegisterMessage('OPTIONS_TOGGLE_ENABLE_UPDATE')
  69. self:RegisterMessage('SORT_ENABLE_UPDATE')
  70. end
  71. end
  72.  
  73. function Frame:FRAME_SHOW(msg, frameID)
  74. if self:GetFrameID() == frameID then
  75. self:FadeInFrame(self, self:GetFrameOpacity())
  76. end
  77. end
  78.  
  79. function Frame:FRAME_HIDE(msg, frameID)
  80. if self:GetFrameID() == frameID then
  81. self:Hide()
  82. end
  83. end
  84.  
  85. function Frame:FRAME_MOVE_START(msg, frameID)
  86. if self:GetFrameID() == frameID then
  87. self:StartMoving()
  88. end
  89. end
  90.  
  91. function Frame:FRAME_MOVE_STOP (msg, frameID)
  92. if self:GetFrameID() == frameID then
  93. self:StopMovingOrSizing()
  94. self:SavePosition()
  95. end
  96. end
  97.  
  98. function Frame:FRAME_POSITION_UPDATE (msg, frameID)
  99. if self:GetFrameID() == frameID then
  100. self:UpdatePosition()
  101. end
  102. end
  103.  
  104. function Frame:FRAME_SCALE_UPDATE (msg, frameID, scale)
  105. if self:GetFrameID() == frameID then
  106. self:UpdateScale()
  107. end
  108. end
  109.  
  110. function Frame:FRAME_OPACITY_UPDATE (msg, frameID, opacity)
  111. if self:GetFrameID() == frameID then
  112. self:UpdateOpacity()
  113. end
  114. end
  115.  
  116. function Frame:FRAME_COLOR_UPDATE (msg, frameID, r, g, b, a)
  117. if self:GetFrameID() == frameID then
  118. self:UpdateBackdrop()
  119. end
  120. end
  121.  
  122. function Frame:FRAME_BORDER_COLOR_UPDATE (msg, frameID, r, g, b, a)
  123. if self:GetFrameID() == frameID then
  124. self:UpdateBackdropBorder()
  125. end
  126. end
  127.  
  128. function Frame:FRAME_LAYER_UPDATE(msg, frameID, layer)
  129. if self:GetFrameID() == frameID then
  130. self:SetFrameLayer(layer)
  131. end
  132. end
  133.  
  134. do
  135. local function LayoutMessage (self, msg, frameID)
  136. if self:GetFrameID() == frameID then
  137. self:Layout()
  138. end
  139. end
  140.  
  141. local messages = {
  142. 'BAG_FRAME_UPDATE_LAYOUT',
  143. 'BAG_FRAME_UPDATE_SHOWN',
  144. 'ITEM_FRAME_SIZE_CHANGE',
  145. 'BAG_FRAME_ENABLE_UPDATE',
  146. 'MONEY_FRAME_ENABLE_UPDATE',
  147. 'DATABROKER_FRAME_ENABLE_UPDATE',
  148. 'SEARCH_TOGGLE_ENABLE_UPDATE',
  149. 'OPTIONS_TOGGLE_ENABLE_UPDATE',
  150. 'SORT_ENABLE_UPDATE'
  151. }
  152.  
  153. for _, msg in ipairs(messages) do
  154. Frame[msg] = LayoutMessage
  155. end
  156. end
  157.  
  158.  
  159. --[[
  160. Frame Events
  161. ]]--
  162.  
  163. function Frame:OnShow()
  164. PlaySound(self.OpenSound)
  165. self:UpdateEvents()
  166. self:UpdateLook()
  167. end
  168.  
  169. function Frame:OnHide()
  170. PlaySound(self.CloseSound)
  171. self:UpdateEvents()
  172.  
  173. -- fow when a frame is hidden not via bagnon
  174. if self:IsFrameShown() then
  175. self:HideFrame()
  176. end
  177. end
  178.  
  179.  
  180. --[[
  181. Update Methods
  182. ]]--
  183.  
  184. function Frame:UpdateEverything()
  185. self:UpdateEvents()
  186. self:UpdateLook()
  187. end
  188.  
  189. function Frame:UpdateLook()
  190. if not self:IsVisible() then
  191. return
  192. end
  193.  
  194. self:UpdatePosition()
  195. self:UpdateScale()
  196. self:UpdateOpacity()
  197. self:UpdateBackdrop()
  198. self:UpdateBackdropBorder()
  199. self:UpdateShown()
  200. self:UpdateFrameLayer()
  201. self:Layout()
  202. end
  203.  
  204.  
  205. --[[
  206. Frame Scale
  207. --]]
  208.  
  209. --alter the frame's cale, but maintain the same relative position of the frame
  210. function Frame:UpdateScale()
  211. local oldScale = self:GetScale()
  212. local newScale = self:GetFrameScale()
  213.  
  214. if oldScale ~= newScale then
  215. local point, x, y = self:GetFramePosition()
  216. local ratio = newScale / oldScale
  217.  
  218. self:SetScale(newScale)
  219. self:GetSettings():SetPosition(point, x/ratio, y/ratio)
  220. end
  221. end
  222.  
  223. function Frame:GetFrameScale()
  224. return self:GetSettings():GetScale()
  225. end
  226.  
  227. --rescale frame without altering position, needed when loading settins
  228. function Frame:Rescale()
  229. self:SetScale(self:GetFrameScale())
  230. end
  231.  
  232.  
  233. --[[
  234. Frame Opacity
  235. --]]
  236.  
  237. function Frame:UpdateOpacity()
  238. self:SetAlpha(self:GetFrameOpacity())
  239. end
  240.  
  241. function Frame:GetFrameOpacity()
  242. return self:GetSettings():GetOpacity()
  243. end
  244.  
  245. function Frame:FadeInFrame(frame, alpha)
  246. if Addon.Settings:IsFadingEnabled() then
  247. UIFrameFadeIn(frame, 0.2, 0, alpha or 1)
  248. end
  249.  
  250. frame:Show()
  251. end
  252.  
  253. function Frame:FadeOutFrame(frame)
  254. if frame then
  255. frame:Hide()
  256. end
  257. end
  258.  
  259.  
  260. --[[
  261. Frame Position
  262. --]]
  263.  
  264. function Frame:SavePosition()
  265. local x, y = self:GetCenter()
  266.  
  267. if x and y then
  268. local scale = self:GetScale()
  269. local h = UIParent:GetHeight() / scale
  270. local w = UIParent:GetWidth() / scale
  271. local xPoint, yPoint
  272.  
  273. if x > w/2 then
  274. x = self:GetRight() - w
  275. xPoint = 'RIGHT'
  276. else
  277. x = self:GetLeft()
  278. xPoint = 'LEFT'
  279. end
  280.  
  281. if x > w/2 then
  282. y = self:GetTop() - h
  283. yPoint = 'TOP'
  284. else
  285. y = self:GetBottom()
  286. yPoint = 'BOTTOM'
  287. end
  288.  
  289. self:GetSettings():SetPosition(yPoint..xPoint, x, y)
  290. end
  291. end
  292.  
  293. function Frame:UpdatePosition()
  294. self:ClearAllPoints()
  295. self:SetPoint(self:GetFramePosition())
  296. end
  297.  
  298. function Frame:GetFramePosition()
  299. return self:GetSettings():GetPosition()
  300. end
  301.  
  302.  
  303. --[[
  304. Frame Color
  305. --]]
  306.  
  307. --background
  308. function Frame:UpdateBackdrop()
  309. self:SetBackdropColor(self:GetFrameBackdropColor())
  310. end
  311.  
  312. function Frame:GetFrameBackdropColor()
  313. return self:GetSettings():GetColor()
  314. end
  315.  
  316. --border
  317. function Frame:UpdateBackdropBorder()
  318. self:SetBackdropBorderColor(self:GetFrameBackdropBorderColor())
  319. end
  320.  
  321. function Frame:GetFrameBackdropBorderColor()
  322. return self:GetSettings():GetBorderColor()
  323. end
  324.  
  325.  
  326. --[[
  327. Frame Visibility
  328. --]]
  329.  
  330. function Frame:UpdateShown()
  331. if self:IsFrameShown() then
  332. self:Show()
  333. else
  334. self:Hide()
  335. end
  336. end
  337.  
  338. function Frame:IsFrameShown()
  339. return self:GetSettings():IsShown()
  340. end
  341.  
  342. function Frame:HideFrame()
  343. self:GetSettings():Hide()
  344. end
  345.  
  346.  
  347. --[[
  348. Frame Layer/Strata
  349. --]]
  350.  
  351. function Frame:UpdateFrameLayer()
  352. self:SetFrameLayer(self:GetFrameLayer())
  353. end
  354.  
  355. function Frame:SetFrameLayer(layer)
  356. local topLevel, strata = true
  357.  
  358. if layer == 'TOPLEVEL' then
  359. strata = 'HIGH'
  360. elseif layer == 'MEDIUMLOW' then
  361. strata = 'LOW'
  362. elseif layer == 'MEDIUMHIGH' then
  363. strata = 'MEDIUM'
  364. else
  365. strata = layer
  366. topLevel = false
  367. end
  368.  
  369. self:SetFrameStrata(strata)
  370. self:SetToplevel(topLevel)
  371. end
  372.  
  373. function Frame:GetFrameLayer()
  374. return self:GetSettings():GetLayer()
  375. end
  376.  
  377.  
  378. --[[ Layout Methods ]]--
  379.  
  380. function Frame:Layout()
  381. if not self:IsVisible() then
  382. return
  383. end
  384.  
  385. local width, height = 24, 36
  386.  
  387. --place top menu frames
  388. width = width + self:PlaceMenuButtons()
  389. width = width + self:PlaceCloseButton()
  390. width = width + self:PlaceOptionsToggle()
  391. width = width + self:PlaceTitleFrame()
  392. self:PlaceSearchFrame()
  393.  
  394. --place middle frames
  395. local w, h = self:PlaceBagFrame()
  396. width = max(w, width)
  397. height = height + h
  398.  
  399. local w, h = self:PlaceItemFrame()
  400. width = max(w, width)
  401. height = height + h
  402.  
  403. --place bottom menu frames
  404. local w, h = self:PlaceMoneyFrame()
  405. width = max(w, width)
  406. height = height + h
  407.  
  408. local w, h = self:PlaceBrokerDisplayFrame()
  409. if not self:HasMoneyFrame() then
  410. height = height + h
  411. end
  412.  
  413. --adjust size
  414. self:SetWidth(max(width, 156) + 16)
  415. self:SetHeight(height)
  416. end
  417.  
  418.  
  419. --[[ Menu Button Placement ]]--
  420.  
  421. function Frame:PlaceMenuButtons()
  422. local menuButtons = self.menuButtons or {}
  423. self.menuButtons = menuButtons
  424.  
  425. --hide the old
  426. for i, button in pairs(menuButtons) do
  427. button:Hide()
  428. menuButtons[i] = nil
  429. end
  430.  
  431. --initiate new
  432. if self:HasPlayerSelector() then
  433. tinsert(menuButtons, self:GetPlayerSelector())
  434. end
  435. self:GetSpecificButtons(menuButtons)
  436.  
  437. if self:HasSearchToggle() then
  438. tinsert(menuButtons, self:GetSearchToggle() or self:CreateSearchToggle())
  439. end
  440.  
  441. --position them
  442. for i, button in ipairs(menuButtons) do
  443. button:ClearAllPoints()
  444. if i == 1 then
  445. button:SetPoint('TOPLEFT', self, 'TOPLEFT', 8, -8)
  446. else
  447. button:SetPoint('TOPLEFT', menuButtons[i-1], 'TOPRIGHT', 4, 0)
  448. end
  449. button:Show()
  450. end
  451.  
  452. --get used space
  453. local numButtons = #menuButtons
  454. if numButtons > 0 then
  455. return (menuButtons[1]:GetWidth() + 4 * numButtons - 4), menuButtons[1]:GetHeight()
  456. end
  457. return 0, 0
  458. end
  459.  
  460. function Frame:GetMenuButtons()
  461. if not self.menuButtons then
  462. self:PlaceMenuButtons()
  463. end
  464. return self.menuButtons
  465. end
  466.  
  467.  
  468. --[[ close button ]]--
  469.  
  470. local function CloseButton_OnClick(self)
  471. self:GetParent():GetSettings():Hide(true) --force hide the frame
  472. end
  473.  
  474. function Frame:CreateCloseButton()
  475. local b = CreateFrame('Button', self:GetName() .. 'CloseButton', self, 'UIPanelCloseButton')
  476. b:SetScript('OnClick', CloseButton_OnClick)
  477. self.closeButton = b
  478. return b
  479. end
  480.  
  481. function Frame:GetCloseButton()
  482. return self.closeButton
  483. end
  484.  
  485. function Frame:PlaceCloseButton()
  486. local b = self:GetCloseButton() or self:CreateCloseButton()
  487. b:ClearAllPoints()
  488. b:SetPoint('TOPRIGHT', -2, -2)
  489. b:Show()
  490.  
  491. return 20, 20 --make the same size as the other menu buttons
  492. end
  493.  
  494.  
  495. --[[ search frame ]]--
  496.  
  497. function Frame:CreateSearchFrame()
  498. local f = Addon.SearchFrame:New(self:GetFrameID(), self)
  499. self.searchFrame = f
  500. return f
  501. end
  502.  
  503. function Frame:GetSearchFrame()
  504. return self.searchFrame
  505. end
  506.  
  507. function Frame:PlaceSearchFrame()
  508. local menuButtons = self:GetMenuButtons()
  509. local frame = self:GetSearchFrame() or self:CreateSearchFrame()
  510. frame:ClearAllPoints()
  511.  
  512. if #menuButtons > 0 then
  513. frame:SetPoint('LEFT', menuButtons[#menuButtons], 'RIGHT', 2, 0)
  514. else
  515. frame:SetPoint('TOPLEFT', self, 'TOPLEFT', 8, -8)
  516. end
  517.  
  518. if self:HasOptionsToggle() then
  519. frame:SetPoint('RIGHT', self:GetOptionsToggle(), 'LEFT', -2, 0)
  520. else
  521. frame:SetPoint('RIGHT', self:GetCloseButton(), 'LEFT', -2, 0)
  522. end
  523.  
  524. frame:SetHeight(28)
  525.  
  526. return frame:GetWidth(), frame:GetHeight()
  527. end
  528.  
  529.  
  530. --[[ search toggle ]]--
  531.  
  532. function Frame:CreateSearchToggle()
  533. local toggle = Addon.SearchToggle:New(self:GetFrameID(), self)
  534. self.searchToggle = toggle
  535. return toggle
  536. end
  537.  
  538. function Frame:GetSearchToggle()
  539. return self.searchToggle
  540. end
  541.  
  542. function Frame:HasSearchToggle()
  543. return self:GetSettings():HasSearchToggle()
  544. end
  545.  
  546.  
  547. --[[ specific buttons ]]--
  548.  
  549. function Frame:GetSpecificButtons(list)
  550. if self:HasBagFrame() then
  551. tinsert(list, self.bagToggle or self:CreateBagToggle())
  552. end
  553.  
  554. if self:HasSortButton() then
  555. tinsert(list, self.sortButton or self:CreateSortButton())
  556. end
  557. end
  558.  
  559. function Frame:CreateBagToggle()
  560. local toggle = Addon.BagToggle:New(self:GetFrameID(), self)
  561. self.bagToggle = toggle
  562. return toggle
  563. end
  564.  
  565. function Frame:CreateSortButton()
  566. local button = Addon.SortButton:New(self)
  567. self.sortButton = button
  568. return button
  569. end
  570.  
  571.  
  572.  
  573. --[[ title frame ]]--
  574.  
  575. function Frame:GetTitleFrame()
  576. return self.titleFrame or self:CreateTitleFrame()
  577. end
  578.  
  579. function Frame:CreateTitleFrame()
  580. local f = Addon.TitleFrame:New(self:GetFrameID(), self.Title, self)
  581. self.titleFrame = f
  582. return f
  583. end
  584.  
  585. function Frame:PlaceTitleFrame()
  586. local menuButtons = self:GetMenuButtons()
  587. local frame = self:GetTitleFrame()
  588. local w, h = 0, 0
  589.  
  590. frame:ClearAllPoints()
  591. if #menuButtons > 0 then
  592. frame:SetPoint('LEFT', menuButtons[#menuButtons], 'RIGHT', 4, 0)
  593. w = frame:GetTextWidth() / 2 + 4
  594. h = 20
  595. else
  596. frame:SetPoint('TOPLEFT', self, 'TOPLEFT', 8, -8)
  597. w = frame:GetTextWidth() + 8
  598. h = 20
  599. end
  600.  
  601. if self:HasOptionsToggle() then
  602. frame:SetPoint('RIGHT', self:GetOptionsToggle(), 'LEFT', -4, 0)
  603. else
  604. frame:SetPoint('RIGHT', self:GetCloseButton(), 'LEFT', -4, 0)
  605. end
  606. frame:SetHeight(20)
  607.  
  608. return w, h
  609. end
  610.  
  611.  
  612. --[[ player selector ]]--
  613.  
  614. function Frame:GetPlayerSelector()
  615. return self.playerSelector or self:CreatePlayerSelector()
  616. end
  617.  
  618. function Frame:CreatePlayerSelector()
  619. local f = Addon.PlayerSelector:New(self:GetFrameID(), self)
  620. self.playerSelector = f
  621. return f
  622. end
  623.  
  624. function Frame:HasPlayerSelector()
  625. return LibStub('LibItemCache-1.1'):HasCache()
  626. end
  627.  
  628.  
  629. --[[ bag frame ]]--
  630.  
  631. function Frame:CreateBagFrame()
  632. local f = self.BagFrame:New(self)
  633. self.bagFrame = f
  634. return f
  635. end
  636.  
  637. function Frame:GetBagFrame()
  638. return self.bagFrame
  639. end
  640.  
  641. function Frame:HasBagFrame()
  642. return self:GetSettings():HasBagFrame()
  643. end
  644.  
  645. function Frame:HasSortButton()
  646. return self:GetSettings():HasSortButton()
  647. end
  648.  
  649. function Frame:IsBagFrameShown()
  650. return self:GetSettings():IsBagFrameShown()
  651. end
  652.  
  653. function Frame:PlaceBagFrame()
  654. if self:HasBagFrame() then
  655. --the bag frame has to be created here to respond to events
  656. local frame = self:GetBagFrame() or self:CreateBagFrame()
  657. if self:IsBagFrameShown() then
  658. frame:ClearAllPoints()
  659.  
  660. local menuButtons = self:GetMenuButtons()
  661. if #menuButtons > 0 then
  662. frame:SetPoint('TOPLEFT', menuButtons[1], 'BOTTOMLEFT', 0, -4)
  663. else
  664. frame:SetPoint('TOPLEFT', self:GetTitleFrame(), 'BOTTOMLEFT', 0, -4)
  665. end
  666.  
  667. frame:Show()
  668.  
  669. return frame:GetWidth(), frame:GetHeight() + 4
  670. else
  671. frame:Hide()
  672. return 0, 0
  673. end
  674. end
  675.  
  676. local frame = self:GetBagFrame()
  677. if frame then
  678. frame:Hide()
  679. end
  680. return 0, 0
  681. end
  682.  
  683.  
  684. --[[ item frame ]]--
  685.  
  686. function Frame:CreateItemFrame()
  687. local f = self.ItemFrame:New(self:GetFrameID(), self)
  688. self.itemFrame = f
  689. return f
  690. end
  691.  
  692. function Frame:GetItemFrame()
  693. return self.itemFrame
  694. end
  695.  
  696. function Frame:PlaceItemFrame()
  697. local frame = self:GetItemFrame() or self:CreateItemFrame()
  698. frame:ClearAllPoints()
  699.  
  700. if self:HasBagFrame() and self:IsBagFrameShown() then
  701. frame:SetPoint('TOPLEFT', self:GetBagFrame(), 'BOTTOMLEFT', 0, -4)
  702. else
  703. local menuButtons = self:GetMenuButtons()
  704. if #menuButtons > 0 then
  705. frame:SetPoint('TOPLEFT', menuButtons[1], 'BOTTOMLEFT', 0, -4)
  706. else
  707. frame:SetPoint('TOPLEFT', self:GetTitleFrame(), 'BOTTOMLEFT', 0, -4)
  708. end
  709. end
  710.  
  711. frame:Show()
  712. return frame:GetWidth() - 2, frame:GetHeight()
  713. end
  714.  
  715.  
  716. --[[ money frame ]]--
  717.  
  718. function Frame:CreateMoneyFrame()
  719. local f = self.MoneyFrame:New(self:GetFrameID(), self)
  720. self.moneyFrame = f
  721. return f
  722. end
  723.  
  724. function Frame:GetMoneyFrame()
  725. return self.moneyFrame
  726. end
  727.  
  728. function Frame:HasMoneyFrame()
  729. return self:GetSettings():HasMoneyFrame()
  730. end
  731.  
  732. function Frame:PlaceMoneyFrame()
  733. if self:HasMoneyFrame() then
  734. local frame = self:GetMoneyFrame() or self:CreateMoneyFrame()
  735. frame:ClearAllPoints()
  736. frame:SetPoint('BOTTOMRIGHT', self, 'BOTTOMRIGHT', -(frame.ICON_SIZE or 0) - (frame.ICON_OFF or 0), 4)
  737. frame:Show()
  738. return frame:GetSize()
  739. end
  740.  
  741. local frame = self:GetMoneyFrame()
  742. if frame then
  743. frame:Hide()
  744. end
  745. return 0, 0
  746. end
  747.  
  748.  
  749.  
  750. --[[ libdatabroker display ]]--
  751.  
  752. function Frame:GetBrokerDisplay()
  753. return self.brokerDisplay
  754. end
  755.  
  756. function Frame:CreateBrokerDisplay()
  757. local f = Addon.BrokerDisplay:New(1, self:GetFrameID(), self)
  758. self.brokerDisplay = f
  759. return f
  760. end
  761.  
  762. function Frame:HasBrokerDisplay()
  763. return self:GetSettings():HasDBOFrame()
  764. end
  765.  
  766. function Frame:PlaceBrokerDisplayFrame()
  767. if self:HasBrokerDisplay() then
  768. local frame = self:GetBrokerDisplay() or self:CreateBrokerDisplay()
  769. frame:ClearAllPoints()
  770. frame:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', 8, 10)
  771.  
  772. if self:HasMoneyFrame() then
  773. frame:SetPoint('RIGHT', self:GetMoneyFrame(), 'LEFT', -4, 10)
  774. else
  775. frame:SetPoint('BOTTOMRIGHT', self, 'BOTTOMRIGHT', -8, 10)
  776. end
  777.  
  778. frame:Show()
  779. return frame:GetWidth(), 24
  780. end
  781.  
  782. local frame = self:GetBrokerDisplay()
  783. if frame then
  784. frame:Hide()
  785. end
  786. return 0, 0
  787. end
  788.  
  789.  
  790. --[[ options toggle ]]--
  791.  
  792. function Frame:GetOptionsToggle()
  793. return self.optionsToggle
  794. end
  795.  
  796. function Frame:CreateOptionsToggle()
  797. local f = Addon.OptionsToggle:New(self:GetFrameID(), self)
  798. self.optionsToggle = f
  799. return f
  800. end
  801.  
  802. function Frame:PlaceOptionsToggle()
  803. if self:HasOptionsToggle() then
  804. local toggle = self:GetOptionsToggle() or self:CreateOptionsToggle()
  805. toggle:ClearAllPoints()
  806. toggle:SetPoint('TOPRIGHT', self, 'TOPRIGHT', -32, -8)
  807. toggle:Show()
  808.  
  809. return toggle:GetWidth(), toggle:GetHeight()
  810. end
  811.  
  812. local toggle = self:GetOptionsToggle()
  813. if toggle then
  814. toggle:Hide()
  815. end
  816. return 0, 0
  817. end
  818.  
  819. function Frame:HasOptionsToggle()
  820. return GetAddOnEnableState(UnitName('player'), ADDON .. '_Config') >= 2 and self:GetSettings():HasOptionsToggle()
  821. end
  822.  
  823.  
  824. --[[ Usual Acessor Functions ]]--
  825.  
  826. function Frame:GetFrameID()
  827. return self.frameID
  828. end
  829.  
  830. function Frame:GetSettings()
  831. return Addon.FrameSettings:Get(self:GetFrameID())
  832. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement