Advertisement
Guest User

Untitled

a guest
Oct 28th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.42 KB | None | 0 0
  1. --[[
  2.  
  3. The traditional bar display used in some form by most damage meters.
  4.  
  5. --]]
  6.  
  7. local L = LibStub("AceLocale-3.0"):GetLocale("Skada", false)
  8.  
  9. local Skada = Skada
  10.  
  11. local mod = Skada:NewModule("BarDisplay", "SpecializedLibBars-1.0")
  12. local libwindow = LibStub("LibWindow-1.1")
  13. local media = LibStub("LibSharedMedia-3.0")
  14.  
  15. --
  16. -- Display implementation.
  17. --
  18.  
  19. -- Add to Skada's enormous list of display providers.
  20. mod.name = L["Bar display"]
  21. Skada.displays["bar"] = mod
  22.  
  23. -- Called when a Skada window starts using this display provider.
  24. function mod:Create(window)
  25. -- Re-use bargroup if it exists.
  26. window.bargroup = mod:GetBarGroup(window.db.name)
  27.  
  28. -- Save a reference to window in bar group. Needed for some nasty callbacks.
  29. if window.bargroup then
  30. -- Clear callbacks.
  31. window.bargroup.callbacks = LibStub:GetLibrary("CallbackHandler-1.0"):New(window.bargroup)
  32. else
  33. window.bargroup = mod:NewBarGroup(window.db.name, nil, window.db.background.height, window.db.barwidth, window.db.barheight, "SkadaBarWindow"..window.db.name)
  34. local bargroup = window.bargroup -- ticket 323
  35.  
  36. -- Add window buttons.
  37. window.bargroup:AddButton(L["Configure"], "Interface\\Buttons\\UI-OptionsButton", "Interface\\Buttons\\UI-OptionsButton", function() Skada:OpenMenu(bargroup.win) end)
  38. window.bargroup:AddButton(L["Reset"], "Interface\\Buttons\\UI-StopButton", "Interface\\Buttons\\UI-StopButton", function() Skada:ShowPopup() end)
  39. window.bargroup:AddButton(L["Segment"], "Interface\\Buttons\\UI-GuildButton-PublicNote-Up", "Interface\\Buttons\\UI-GuildButton-PublicNote-Up", function() Skada:SegmentMenu(bargroup.win) end)
  40. --window.bargroup:AddButton(L["Mode"], "Interface\\Buttons\\UI-GuildButton-OfficerNote-Up", "Interface\\Buttons\\UI-GuildButton-OfficerNote-Up", function() Skada:ModeMenu(bargroup.win) end)
  41. window.bargroup:AddButton(L["Mode"], "Interface\\Buttons\\UI-GuildButton-PublicNote-Up", "Interface\\Buttons\\UI-GuildButton-PublicNote-Up", function() Skada:ModeMenu(bargroup.win) end)
  42. window.bargroup:AddButton(L["Report"], "Interface\\Buttons\\UI-GuildButton-MOTD-Up", "Interface\\Buttons\\UI-GuildButton-MOTD-Up", function() Skada:OpenReportWindow(bargroup.win) end)
  43. end
  44. window.bargroup.win = window
  45. window.bargroup.RegisterCallback(mod, "AnchorMoved")
  46. window.bargroup.RegisterCallback(mod, "WindowResized")
  47. window.bargroup:EnableMouse(true)
  48. window.bargroup:SetScript("OnMouseDown", function(win, button) if IsShiftKeyDown() then Skada:OpenMenu(window) elseif button == "RightButton" then window:RightClick() end end)
  49. window.bargroup.button:SetScript("OnClick", function(win, button) if IsShiftKeyDown() then Skada:OpenMenu(window) elseif button == "RightButton" then window:RightClick() end end)
  50. window.bargroup:HideIcon()
  51.  
  52. window.bargroup.button:GetFontString():SetPoint("LEFT", window.bargroup.button, "LEFT", 5, 1)
  53. window.bargroup.button:GetFontString():SetJustifyH("LEFT")
  54. window.bargroup.button:SetHeight(window.db.title.height or 15)
  55.  
  56. -- Register with LibWindow-1.0.
  57. libwindow.RegisterConfig(window.bargroup, window.db)
  58.  
  59. -- Restore window position.
  60. libwindow.RestorePosition(window.bargroup)
  61.  
  62. if not mod.class_icon_tcoords then -- amortized class icon coordinate adjustment
  63. mod.class_icon_tcoords = {}
  64. for class, coords in pairs(CLASS_ICON_TCOORDS) do
  65. local l,r,t,b = unpack(coords)
  66. local adj = 0.02
  67. mod.class_icon_tcoords[class] = {(l+adj),(r-adj),(t+adj),(b-adj)}
  68. end
  69. end
  70. end
  71.  
  72. -- Called by Skada windows when the window is to be destroyed/cleared.
  73. function mod:Destroy(win)
  74. win.bargroup:Hide()
  75. win.bargroup = nil
  76. end
  77.  
  78. -- Called by Skada windows when the window is to be completely cleared and prepared for new data.
  79. function mod:Wipe(win)
  80. -- Reset sort function.
  81. win.bargroup:SetSortFunction(nil)
  82.  
  83. -- Reset scroll offset.
  84. win.bargroup:SetBarOffset(0)
  85.  
  86. -- Remove the bars.
  87. local bars = win.bargroup:GetBars()
  88. if bars then
  89. for i, bar in pairs(bars) do
  90. bar:Hide()
  91. win.bargroup:RemoveBar(bar)
  92. end
  93. end
  94.  
  95. -- Clean up.
  96. win.bargroup:SortBars()
  97. end
  98.  
  99. local function showmode(win, id, label, mode)
  100. -- Add current mode to window traversal history.
  101. if win.selectedmode then
  102. tinsert(win.history, win.selectedmode)
  103. end
  104. -- Call the Enter function on the mode.
  105. if mode.Enter then
  106. mode:Enter(win, id, label)
  107. end
  108. -- Display mode.
  109. win:DisplayMode(mode)
  110. end
  111.  
  112. local function BarClickIgnore(bar, button)
  113. local win = bar.win
  114. if button == "RightButton" then
  115. win:RightClick()
  116. end
  117. end
  118.  
  119. local function BarClick(bar, button)
  120. local win, id, label = bar.win, bar.id, bar.text
  121. local click1 = win.metadata.click1
  122. local click2 = win.metadata.click2
  123. local click3 = win.metadata.click3
  124.  
  125. if button == "RightButton" and IsShiftKeyDown() then
  126. Skada:OpenMenu(win)
  127. elseif win.metadata.click then
  128. win.metadata.click(win, id, label, button)
  129. elseif button == "RightButton" then
  130. win:RightClick()
  131. elseif click2 and IsShiftKeyDown() then
  132. showmode(win, id, label, click2)
  133. elseif click3 and IsControlKeyDown() then
  134. showmode(win, id, label, click3)
  135. elseif click1 then
  136. showmode(win, id, label, click1)
  137. end
  138. end
  139.  
  140. local ttactive = false
  141.  
  142. local function BarEnter(bar)
  143. local win, id, label = bar.win, bar.id, bar.text
  144. local t = GameTooltip
  145. if Skada.db.profile.tooltips and (win.metadata.click1 or win.metadata.click2 or win.metadata.click3 or win.metadata.tooltip) then
  146. ttactive = true
  147. Skada:SetTooltipPosition(t, win.bargroup)
  148. t:ClearLines()
  149.  
  150. local hasClick = win.metadata.click1 or win.metadata.click2 or win.metadata.click3
  151.  
  152. -- Current mode's own tooltips.
  153. if win.metadata.tooltip then
  154. local numLines = t:NumLines()
  155. win.metadata.tooltip(win, id, label, t)
  156.  
  157. -- Spacer
  158. if t:NumLines() ~= numLines and hasClick then
  159. t:AddLine(" ")
  160. end
  161. end
  162.  
  163. -- Generic informative tooltips.
  164. if Skada.db.profile.informativetooltips then
  165. if win.metadata.click1 then
  166. Skada:AddSubviewToTooltip(t, win, win.metadata.click1, id, label)
  167. end
  168. if win.metadata.click2 then
  169. Skada:AddSubviewToTooltip(t, win, win.metadata.click2, id, label)
  170. end
  171. if win.metadata.click3 then
  172. Skada:AddSubviewToTooltip(t, win, win.metadata.click3, id, label)
  173. end
  174. end
  175.  
  176. -- Current mode's own post-tooltips.
  177. if win.metadata.post_tooltip then
  178. local numLines = t:NumLines()
  179. win.metadata.post_tooltip(win, id, label, t)
  180.  
  181. -- Spacer
  182. if t:NumLines() ~= numLines and hasClick then
  183. t:AddLine(" ")
  184. end
  185. end
  186.  
  187. -- Click directions.
  188. if win.metadata.click1 then
  189. t:AddLine(L["Click for"].." "..win.metadata.click1:GetName()..".", 0.2, 1, 0.2)
  190. end
  191. if win.metadata.click2 then
  192. t:AddLine(L["Shift-Click for"].." "..win.metadata.click2:GetName()..".", 0.2, 1, 0.2)
  193. end
  194. if win.metadata.click3 then
  195. t:AddLine(L["Control-Click for"].." "..win.metadata.click3:GetName()..".", 0.2, 1, 0.2)
  196. end
  197.  
  198. t:Show()
  199. end
  200. end
  201.  
  202. local function BarLeave(bar)
  203. local win, id, label = bar.win, bar.id, bar.text
  204. if ttactive then
  205. GameTooltip:Hide()
  206. ttactive = false
  207. end
  208. end
  209.  
  210. local function BarResize(bar)
  211. if bar.bgwidth then
  212. bar.bgtexture:SetWidth(bar.bgwidth * bar:GetWidth())
  213. else
  214. bar:SetScript("OnSizeChanged",bar.OnSizeChanged)
  215. end
  216. bar:OnSizeChanged() -- call library version
  217. end
  218.  
  219. local function BarIconEnter(icon)
  220. local bar = icon.bar
  221. local win = bar.win
  222. if bar.link and win and win.bargroup then
  223. Skada:SetTooltipPosition(GameTooltip, win.bargroup);
  224. GameTooltip:SetHyperlink(bar.link);
  225. GameTooltip:Show();
  226. end
  227. end
  228.  
  229. local function BarIconMouseDown(icon) -- shift-click to link spell into chat
  230. local bar = icon.bar
  231. if not IsShiftKeyDown() or not bar.link then return end
  232. local activeEditBox = ChatEdit_GetActiveWindow()
  233. if activeEditBox then
  234. ChatEdit_InsertLink(bar.link)
  235. else
  236. ChatFrame_OpenChat(bar.link, DEFAULT_CHAT_FRAME)
  237. end
  238. end
  239.  
  240. local function value_sort(a,b)
  241. if not a or a.value == nil then
  242. return false
  243. elseif not b or b.value == nil then
  244. return true
  245. else
  246. return a.value > b.value
  247. end
  248. end
  249.  
  250. local function bar_order_sort(a,b)
  251. return a and b and a.order and b.order and a.order < b.order
  252. end
  253.  
  254. local function HideGameTooltip()
  255. GameTooltip:Hide()
  256. end
  257.  
  258. -- Called by Skada windows when title of window should change.
  259. function mod:SetTitle(win, title)
  260. -- Set title.
  261. win.bargroup.button:SetText(title)
  262. end
  263.  
  264. -- Called by Skada windows when the display should be updated to match the dataset.
  265. function mod:Update(win)
  266. -- Some modes may alter title continously.
  267. win.bargroup.button:SetText(win.metadata.title)
  268.  
  269. -- Sort if we are showing spots with "showspots".
  270. if win.metadata.showspots then
  271. table.sort(win.dataset, value_sort)
  272. end
  273.  
  274. -- Find out if we have icons in this update, and if so, adjust accordingly.
  275. local hasicon = false
  276. for i, data in ipairs(win.dataset) do
  277. if (data.icon and not data.ignore) or (data.class and win.db.classicons) then
  278. hasicon = true
  279. end
  280. end
  281.  
  282. if hasicon and not win.bargroup.showIcon then
  283. win.bargroup:ShowIcon()
  284. end
  285. if not hasicon and win.bargroup.showIcon then
  286. win.bargroup:HideIcon()
  287. end
  288.  
  289. -- If we are using "wipestale", we may have removed data
  290. -- and we need to remove unused bars.
  291. -- The Threat module uses this.
  292. -- For each bar, mark bar as unchecked.
  293. if win.metadata.wipestale then
  294. local bars = win.bargroup:GetBars()
  295. if bars then
  296. for name, bar in pairs(bars) do
  297. bar.checked = false
  298. end
  299. end
  300. end
  301.  
  302. local nr = 1
  303. for i, data in ipairs(win.dataset) do
  304. if data.id then
  305. local barid = data.id
  306. local barlabel = data.label
  307.  
  308. local bar = win.bargroup:GetBar(barid)
  309.  
  310. if bar and bar.missingclass and data.class and not data.ignore then
  311. -- fixup bar that was generated before class info was available
  312. bar:Hide()
  313. win.bargroup:RemoveBar(bar)
  314. bar.missingclass = nil
  315. bar = nil
  316. end
  317.  
  318. if bar then
  319. bar:SetValue(data.value)
  320. bar:SetMaxValue(win.metadata.maxvalue or 1) -- MUST come after SetValue
  321. else
  322. -- Initialization of bars.
  323. bar = mod:CreateBar(win, barid, barlabel, data.value, win.metadata.maxvalue or 1, data.icon, false)
  324. bar.id = barid
  325. bar.text = barlabel
  326. --- Adds border to Bars ---
  327. if not bar.bg then
  328. local frame = CreateFrame("Frame", nil, bar)
  329. frame:ClearAllPoints()
  330. frame:SetPoint("TOPLEFT", bar, "TOPLEFT", -1, 1)
  331. frame:SetPoint("BOTTOMRIGHT", bar, "BOTTOMRIGHT", 1, -1)
  332. frame:SetBackdrop({
  333. edgeFile = [=[Interface\ChatFrame\ChatFrameBackground]=], edgeSize = 1,
  334. bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=],
  335. insets = {left = 1, right = 1, top = 1, bottom = 1}})
  336. frame:SetFrameLevel(bar:GetFrameLevel())
  337. frame:SetBackdropColor(0, 0, 0, .3)
  338. frame:SetBackdropBorderColor(0, 0, 0)
  339. bar.bg = frame
  340. end
  341. if not data.ignore then
  342.  
  343. if data.icon then
  344. bar:ShowIcon()
  345.  
  346. bar.link = nil
  347. if data.spellid then
  348. local spell = data.spellid
  349. bar.link = GetSpellLink(spell)
  350. elseif data.hyperlink then
  351. bar.link = data.hyperlink
  352. end
  353. if bar.link then
  354. bar.iconFrame.bar = bar
  355. bar.iconFrame:EnableMouse(true)
  356. bar.iconFrame:SetScript("OnEnter", BarIconEnter)
  357. bar.iconFrame:SetScript("OnLeave", HideGameTooltip)
  358. bar.iconFrame:SetScript("OnMouseDown", BarIconMouseDown)
  359. end
  360. end
  361.  
  362. bar:EnableMouse(true)
  363. bar:SetScript("OnEnter", BarEnter)
  364. bar:SetScript("OnLeave", BarLeave)
  365. bar:SetScript("OnMouseDown", BarClick)
  366. else
  367. bar:SetScript("OnEnter", nil)
  368. bar:SetScript("OnLeave", nil)
  369. bar:SetScript("OnMouseDown", BarClickIgnore)
  370. end
  371. bar:SetValue(data.value)
  372.  
  373. if not data.class and
  374. (win.db.classicons or win.db.classcolorbars or win.db.classcolortext) then
  375. bar.missingclass = true
  376. else
  377. bar.missingclass = nil
  378. end
  379.  
  380. if data.class and win.db.classicons and mod.class_icon_tcoords[data.class] then
  381. bar:ShowIcon()
  382. bar:SetIconWithCoord("Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Classes", mod.class_icon_tcoords[data.class])
  383. end
  384.  
  385. if data.color then
  386. -- Explicit color from dataset.
  387. bar:SetColorAt(0, data.color.r, data.color.g, data.color.b, data.color.a or 1)
  388. elseif data.class and win.db.classcolorbars then
  389. -- Class color.
  390. local color = Skada.classcolors[data.class]
  391. if color then
  392. bar:SetColorAt(0, color.r, color.g, color.b, color.a or 1)
  393. end
  394. else
  395. -- Default color.
  396. local color = win.db.barcolor
  397. bar:SetColorAt(0, color.r, color.g, color.b, color.a or 1)
  398. end
  399.  
  400. if data.class and win.db.classcolortext then
  401. -- Class color text.
  402. local color = Skada.classcolors[data.class]
  403. if color then
  404. bar.label:SetTextColor(color.r, color.g, color.b, color.a or 1)
  405. bar.timerLabel:SetTextColor(color.r, color.g, color.b, color.a or 1)
  406. end
  407. else
  408. -- Default color text.
  409. bar.label:SetTextColor(1,1,1,1)
  410. bar.timerLabel:SetTextColor(1,1,1,1)
  411. end
  412. end
  413.  
  414. if win.metadata.ordersort then
  415. bar.order = i
  416. end
  417.  
  418. if win.metadata.showspots and Skada.db.profile.showranks and not data.ignore then
  419. bar:SetLabel(("%2u. %s"):format(nr, data.label))
  420. else
  421. bar:SetLabel(data.label)
  422. end
  423. bar:SetTimerLabel(data.valuetext)
  424.  
  425. if win.metadata.wipestale then
  426. bar.checked = true
  427. end
  428.  
  429. -- Emphathized items - cache a flag saying it is done so it is not done again.
  430. -- This is a little lame.
  431. if data.emphathize and bar.emphathize_set ~= true then
  432. bar:SetFont(nil,nil,"OUTLINE")
  433. bar.emphathize_set = true
  434. elseif not data.emphathize and bar.emphathize_set ~= false then
  435. bar:SetFont(nil,nil,"PLAIN")
  436. bar.emphathize_set = false
  437. end
  438.  
  439. -- Background texture color.
  440. if data.backgroundcolor then
  441. bar.bgtexture:SetVertexColor(data.backgroundcolor.r, data.backgroundcolor.g, data.backgroundcolor.b, data.backgroundcolor.a or 1)
  442. end
  443.  
  444. -- Background texture size (in percent, as the mode has no idea on actual widths).
  445. if data.backgroundwidth then
  446. bar.bgtexture:ClearAllPoints()
  447. bar.bgtexture:SetPoint("BOTTOMLEFT")
  448. bar.bgtexture:SetPoint("TOPLEFT")
  449. bar.bgwidth = data.backgroundwidth
  450. bar:SetScript("OnSizeChanged",BarResize) -- ticket 365: required to resize bgtexture
  451. BarResize(bar)
  452. else
  453. bar.bgwidth = nil
  454. end
  455.  
  456. if not data.ignore then
  457. nr = nr + 1
  458. end
  459. end
  460. end
  461.  
  462. -- If we are using "wipestale", remove all unchecked bars.
  463. if win.metadata.wipestale then
  464. local bars = win.bargroup:GetBars()
  465. for name, bar in pairs(bars) do
  466. if not bar.checked then
  467. win.bargroup:RemoveBar(bar)
  468. end
  469. end
  470. end
  471.  
  472. -- Sort by the order in the data table if we are using "ordersort".
  473. if win.metadata.ordersort then
  474. win.bargroup:SetSortFunction(bar_order_sort)
  475. win.bargroup:SortBars()
  476. else
  477. win.bargroup:SetSortFunction(nil)
  478. win.bargroup:SortBars()
  479. end
  480.  
  481. end
  482.  
  483. function mod:AnchorMoved(cbk, group, x, y)
  484. libwindow.SavePosition(group)
  485. end
  486.  
  487. function mod:WindowResized(cbk, group)
  488. libwindow.SavePosition(group)
  489.  
  490. -- Also save size.
  491. group.win.db.background.height = group:GetHeight()
  492. group.win.db.barwidth = group:GetWidth()
  493. end
  494.  
  495. function mod:Show(win)
  496. win.bargroup:Show()
  497. win.bargroup:SortBars()
  498. end
  499.  
  500. function mod:Hide(win)
  501. win.bargroup:Hide()
  502. end
  503.  
  504. function mod:IsShown(win)
  505. return win.bargroup:IsShown()
  506. end
  507.  
  508. local function getNumberOfBars(win)
  509. local bars = win.bargroup:GetBars()
  510. local n = 0
  511. for i, bar in pairs(bars) do n = n + 1 end
  512. return n
  513. end
  514.  
  515. local function OnMouseWheel(frame, direction)
  516. local win = frame.win
  517. local maxbars = win.db.background.height / (win.db.barheight + win.db.barspacing)
  518. if direction == 1 and win.bargroup:GetBarOffset() > 0 then
  519. win.bargroup:SetBarOffset(win.bargroup:GetBarOffset() - 1)
  520. elseif direction == -1 and ((getNumberOfBars(win) - maxbars - win.bargroup:GetBarOffset()) > 0) then
  521. win.bargroup:SetBarOffset(win.bargroup:GetBarOffset() + 1)
  522. end
  523. end
  524.  
  525. function mod:OnMouseWheel(win, frame, direction) -- external scrolling interface (SkadaScroll)
  526. if not frame then
  527. mod.framedummy = mod.framedummy or {}
  528. mod.framedummy.win = win
  529. frame = mod.framedummy
  530. end
  531. OnMouseWheel(frame, direction)
  532. end
  533.  
  534. function mod:CreateBar(win, name, label, value, maxvalue, icon, o)
  535. local bar = win.bargroup:NewCounterBar(name, label, value, maxvalue, icon)
  536. bar.win = win
  537. bar:EnableMouseWheel(true)
  538. bar:SetScript("OnMouseWheel", OnMouseWheel)
  539. bar.iconFrame:SetScript("OnEnter", nil)
  540. bar.iconFrame:SetScript("OnLeave", nil)
  541. bar.iconFrame:SetScript("OnMouseDown", nil)
  542. bar.iconFrame:EnableMouse(false)
  543. return bar
  544. end
  545.  
  546. local titlebackdrop = {}
  547. local windowbackdrop = {}
  548.  
  549. -- Called by Skada windows when window settings have changed.
  550. function mod:ApplySettings(win)
  551. local g = win.bargroup
  552. local p = win.db
  553. g:ReverseGrowth(p.reversegrowth)
  554. g:SetOrientation(p.barorientation)
  555. g:SetBarHeight(p.barheight)
  556. g:SetHeight(p.background.height)
  557. g:SetWidth(p.barwidth)
  558. g:SetLength(p.barwidth)
  559. g:SetTexture(p.bartexturepath or media:Fetch('statusbar', p.bartexture))
  560.  
  561. g:SetBarBackgroundColor(p.barbgcolor.r, p.barbgcolor.g, p.barbgcolor.b, p.barbgcolor.a or 0.6)
  562. g:SetFont(p.barfontpath or media:Fetch('font', p.barfont), p.barfontsize, p.barfontflags)
  563. g:SetSpacing(p.barspacing)
  564. g:UnsetAllColors()
  565. g:SetColorAt(0,p.barcolor.r,p.barcolor.g,p.barcolor.b, p.barcolor.a)
  566. if p.barslocked then
  567. g:Lock()
  568. else
  569. g:Unlock()
  570. end
  571.  
  572. -- Header
  573. local fo = CreateFont("TitleFont"..win.db.name)
  574. fo:SetFont(p.title.fontpath or media:Fetch('font', p.title.font), p.title.fontsize, p.title.fontflags)
  575. g.button:SetNormalFontObject(fo)
  576.  
  577. local inset = p.title.margin
  578. titlebackdrop.bgFile = media:Fetch("statusbar", p.title.texture)
  579. if p.title.borderthickness > 0 and p.title.bordertexture ~= "None" then
  580. titlebackdrop.edgeFile = media:Fetch("border", p.title.bordertexture)
  581. else
  582. titlebackdrop.edgeFile = nil
  583. end
  584. titlebackdrop.tile = false
  585. titlebackdrop.tileSize = 0
  586. titlebackdrop.edgeSize = p.title.borderthickness
  587. titlebackdrop.insets = {left = inset, right = inset, top = inset, bottom = inset}
  588. g.button:SetBackdrop(titlebackdrop)
  589. local color = p.title.color
  590. g.button:SetBackdropColor(color.r, color.g, color.b, color.a or 1)
  591. g.button:SetHeight(p.title.height or 15)
  592.  
  593. if p.enabletitle then
  594. g:ShowAnchor()
  595. else
  596. g:HideAnchor()
  597. end
  598.  
  599. -- Adjust button positions
  600. g:AdjustButtons()
  601.  
  602. -- Button visibility.
  603. g:ShowButton(L["Configure"], p.buttons.menu)
  604. g:ShowButton(L["Reset"], p.buttons.reset)
  605. g:ShowButton(L["Mode"], p.buttons.mode)
  606. g:ShowButton(L["Segment"], p.buttons.segment)
  607. g:ShowButton(L["Report"], p.buttons.report)
  608.  
  609. -- Window
  610. local inset = p.background.margin
  611. windowbackdrop.bgFile = p.background.texturepath or media:Fetch("background", p.background.texture)
  612. if p.background.borderthickness > 0 and p.background.bordertexture ~= "None" then
  613. windowbackdrop.edgeFile = media:Fetch("border", p.background.bordertexture)
  614. else
  615. windowbackdrop.edgeFile = nil
  616. end
  617. windowbackdrop.tile = false
  618. windowbackdrop.tileSize = 0
  619. windowbackdrop.edgeSize = p.background.borderthickness
  620. windowbackdrop.insets = {left = inset, right = inset, top = inset, bottom = inset}
  621. g:SetBackdrop(windowbackdrop)
  622. local color = p.background.color
  623. g:SetBackdropColor(color.r, color.g, color.b, color.a or 1)
  624.  
  625. -- Clickthrough
  626. g:SetEnableMouse(not p.clickthrough)
  627.  
  628. -- Scale
  629. g:SetScale(p.scale)
  630.  
  631. libwindow.SavePosition(g)
  632.  
  633. g:SortBars()
  634. end
  635.  
  636. --
  637. -- Options.
  638. --
  639.  
  640. function mod:AddDisplayOptions(win, options)
  641. local db = win.db
  642.  
  643. options.baroptions = {
  644. type = "group",
  645. name = L["Bars"],
  646. order=1,
  647. args = {
  648.  
  649. barfont = {
  650. type = 'select',
  651. dialogControl = 'LSM30_Font',
  652. name = L["Bar font"],
  653. desc = L["The font used by all bars."],
  654. values = AceGUIWidgetLSMlists.font,
  655. get = function() return db.barfont end,
  656. set = function(win,key)
  657. db.barfont = key
  658. Skada:ApplySettings()
  659. end,
  660. order=1,
  661. },
  662.  
  663. barfontsize = {
  664. type="range",
  665. name=L["Bar font size"],
  666. desc=L["The font size of all bars."],
  667. min=7,
  668. max=40,
  669. step=1,
  670. get=function() return db.barfontsize end,
  671. set=function(win, size)
  672. db.barfontsize = size
  673. Skada:ApplySettings()
  674. end,
  675. order=2,
  676. },
  677.  
  678. barfontflags = {
  679. type = 'select',
  680. name = L["Font flags"],
  681. desc = L["Sets the font flags."],
  682. values = {[""] = L["None"], ["OUTLINE"] = L["Outline"], ["THICKOUTLINE"] = L["Thick outline"], ["MONOCHROME"] = L["Monochrome"], ["OUTLINEMONOCHROME"] = L["Outlined monochrome"]},
  683. get = function() return db.barfontflags end,
  684. set = function(win,key)
  685. db.barfontflags = key
  686. Skada:ApplySettings()
  687. end,
  688. order=3,
  689. },
  690.  
  691. bartexture = {
  692. type = 'select',
  693. dialogControl = 'LSM30_Statusbar',
  694. name = L["Bar texture"],
  695. desc = L["The texture used by all bars."],
  696. values = AceGUIWidgetLSMlists.statusbar,
  697. get = function() return db.bartexture end,
  698. set = function(win,key)
  699. db.bartexture = key
  700. Skada:ApplySettings()
  701. end,
  702. order=12,
  703. },
  704.  
  705. barspacing = {
  706. type="range",
  707. name=L["Bar spacing"],
  708. desc=L["Distance between bars."],
  709. min=0,
  710. max=10,
  711. step=1,
  712. get=function() return db.barspacing end,
  713. set=function(win, spacing)
  714. db.barspacing = spacing
  715. Skada:ApplySettings()
  716. end,
  717. order=13,
  718. },
  719.  
  720. barheight = {
  721. type="range",
  722. name=L["Bar height"],
  723. desc=L["The height of the bars."],
  724. min=10,
  725. max=40,
  726. step=1,
  727. get=function() return db.barheight end,
  728. set=function(win, height)
  729. db.barheight = height
  730. Skada:ApplySettings()
  731. end,
  732. order=14,
  733. },
  734.  
  735. barorientation = {
  736. type="select",
  737. name=L["Bar orientation"],
  738. desc=L["The direction the bars are drawn in."],
  739. values= function() return {[1] = L["Left to right"], [3] = L["Right to left"]} end,
  740. get=function() return db.barorientation end,
  741. set=function(win, orientation)
  742. db.barorientation = orientation
  743. Skada:ApplySettings()
  744. end,
  745. order=17,
  746. },
  747.  
  748. reversegrowth = {
  749. type="toggle",
  750. name=L["Reverse bar growth"],
  751. desc=L["Bars will grow up instead of down."],
  752. order=19,
  753. get=function() return db.reversegrowth end,
  754. set=function()
  755. db.reversegrowth = not db.reversegrowth
  756. Skada:ApplySettings()
  757. end,
  758. },
  759.  
  760. color = {
  761. type="color",
  762. name=L["Bar color"],
  763. desc=L["Choose the default color of the bars."],
  764. hasAlpha=true,
  765. get=function(i)
  766. local c = db.barcolor
  767. return c.r, c.g, c.b, c.a
  768. end,
  769. set=function(i, r,g,b,a)
  770. db.barcolor = {["r"] = r, ["g"] = g, ["b"] = b, ["a"] = a}
  771. Skada:ApplySettings()
  772. end,
  773. order=21,
  774. },
  775.  
  776. bgcolor = {
  777. type="color",
  778. name=L["Background color"],
  779. desc=L["Choose the background color of the bars."],
  780. hasAlpha=true,
  781. get=function(i) return db.barbgcolor.r, db.barbgcolor.g, db.barbgcolor.b, db.barbgcolor.a end,
  782. set=function(i, r,g,b,a) db.barbgcolor = {["r"] = r, ["g"] = g, ["b"] = b, ["a"] = a}; Skada:ApplySettings() end,
  783. order=22,
  784. },
  785.  
  786. classcolorbars = {
  787. type="toggle",
  788. name=L["Class color bars"],
  789. desc=L["When possible, bars will be colored according to player class."],
  790. order=30,
  791. get=function() return db.classcolorbars end,
  792. set=function()
  793. db.classcolorbars = not db.classcolorbars
  794. Skada:ApplySettings()
  795. end,
  796. },
  797.  
  798. classcolortext = {
  799. type="toggle",
  800. name=L["Class color text"],
  801. desc=L["When possible, bar text will be colored according to player class."],
  802. order=31,
  803. get=function() return db.classcolortext end,
  804. set=function()
  805. db.classcolortext = not db.classcolortext
  806. Skada:ApplySettings()
  807. end,
  808. },
  809.  
  810. classicons = {
  811. type="toggle",
  812. name=L["Class icons"],
  813. desc=L["Use class icons where applicable."],
  814. order=32,
  815. get=function() return db.classicons end,
  816. set=function()
  817. db.classicons = not db.classicons
  818. Skada:ApplySettings()
  819. end,
  820. },
  821.  
  822. clickthrough = {
  823. type="toggle",
  824. name=L["Clickthrough"],
  825. desc=L["Disables mouse clicks on bars."],
  826. order=20,
  827. get=function() return db.clickthrough end,
  828. set=function()
  829. db.clickthrough = not db.clickthrough
  830. Skada:ApplySettings()
  831. end,
  832. },
  833.  
  834. }
  835. }
  836.  
  837. options.titleoptions = {
  838. type = "group",
  839. name = L["Title bar"],
  840. order=2,
  841. args = {
  842.  
  843. enable = {
  844. type="toggle",
  845. name=L["Enable"],
  846. desc=L["Enables the title bar."],
  847. order=0,
  848. get=function() return db.enabletitle end,
  849. set=function()
  850. db.enabletitle = not db.enabletitle
  851. Skada:ApplySettings()
  852. end,
  853. },
  854.  
  855. titleset = {
  856. type="toggle",
  857. name=L["Include set"],
  858. desc=L["Include set name in title bar"],
  859. order=0.5,
  860. get=function() return db.titleset end,
  861. set=function()
  862. db.titleset = not db.titleset
  863. Skada:ApplySettings()
  864. end,
  865. },
  866. height = {
  867. type="range",
  868. name=L["Title height"],
  869. desc=L["The height of the title frame."],
  870. order=1,
  871. min=10,
  872. max=50,
  873. step=1,
  874. get=function() return db.title.height end,
  875. set=function(win, val)
  876. db.title.height = val
  877. Skada:ApplySettings()
  878. end,
  879. },
  880.  
  881. font = {
  882. type = 'select',
  883. dialogControl = 'LSM30_Font',
  884. name = L["Bar font"],
  885. desc = L["The font used by all bars."],
  886. values = AceGUIWidgetLSMlists.font,
  887. order=2,
  888. get = function() return db.title.font end,
  889. set = function(win,key)
  890. db.title.font = key
  891. Skada:ApplySettings()
  892. end,
  893. order=2,
  894. },
  895.  
  896. fontsize = {
  897. type="range",
  898. name=L["Bar font size"],
  899. desc=L["The font size of all bars."],
  900. min=7,
  901. max=40,
  902. step=1,
  903. get=function() return db.title.fontsize end,
  904. set=function(win, size)
  905. db.title.fontsize = size
  906. Skada:ApplySettings()
  907. end,
  908. order=3,
  909. },
  910.  
  911. fontflags = {
  912. type = 'select',
  913. name = L["Font flags"],
  914. desc = L["Sets the font flags."],
  915. values = {[""] = L["None"], ["OUTLINE"] = L["Outline"], ["THICKOUTLINE"] = L["Thick outline"], ["MONOCHROME"] = L["Monochrome"], ["OUTLINEMONOCHROME"] = L["Outlined monochrome"]},
  916. get = function() return db.title.fontflags end,
  917. set = function(win,key)
  918. db.title.fontflags = key
  919. Skada:ApplySettings()
  920. end,
  921. order=4,
  922. },
  923.  
  924. texture = {
  925. type = 'select',
  926. dialogControl = 'LSM30_Statusbar',
  927. name = L["Background texture"],
  928. order=4,
  929. desc = L["The texture used as the background of the title."],
  930. values = AceGUIWidgetLSMlists.statusbar,
  931. get = function() return db.title.texture end,
  932. set = function(win,key)
  933. db.title.texture = key
  934. Skada:ApplySettings()
  935. end,
  936. order=5,
  937. },
  938.  
  939. bordertexture = {
  940. type = 'select',
  941. dialogControl = 'LSM30_Border',
  942. order=5,
  943. name = L["Border texture"],
  944. desc = L["The texture used for the border of the title."],
  945. values = AceGUIWidgetLSMlists.border,
  946. get = function() return db.title.bordertexture end,
  947. set = function(win,key)
  948. db.title.bordertexture = key
  949. Skada:ApplySettings()
  950. end,
  951. order=6,
  952. },
  953.  
  954. thickness = {
  955. type="range",
  956. name=L["Border thickness"],
  957. desc=L["The thickness of the borders."],
  958. order=6,
  959. min=0,
  960. max=50,
  961. step=0.5,
  962. get=function() return db.title.borderthickness end,
  963. set=function(win, val)
  964. db.title.borderthickness = val
  965. Skada:ApplySettings()
  966. end,
  967. order=7,
  968. },
  969.  
  970. margin = {
  971. type="range",
  972. name=L["Margin"],
  973. desc=L["The margin between the outer edge and the background texture."],
  974. order=7,
  975. min=0,
  976. max=50,
  977. step=0.5,
  978. get=function() return db.title.margin end,
  979. set=function(win, val)
  980. db.title.margin = val
  981. Skada:ApplySettings()
  982. end,
  983. order=8,
  984. },
  985.  
  986. color = {
  987. type="color",
  988. name=L["Background color"],
  989. desc=L["The background color of the title."],
  990. order=8,
  991. hasAlpha=true,
  992. get=function(i)
  993. local c = db.title.color
  994. return c.r, c.g, c.b, c.a
  995. end,
  996. set=function(i, r,g,b,a)
  997. db.title.color = {["r"] = r, ["g"] = g, ["b"] = b, ["a"] = a}
  998. Skada:ApplySettings()
  999. end,
  1000. order=9,
  1001. },
  1002.  
  1003. buttons = {
  1004. type = "group",
  1005. name = L["Buttons"],
  1006. order=20,
  1007. inline=true,
  1008. args = {
  1009. report = {
  1010. type="toggle",
  1011. name=L["Report"],
  1012. order=1,
  1013. get=function() return db.buttons.report == nil or db.buttons.report end,
  1014. set=function()
  1015. db.buttons.report = not db.buttons.report
  1016. Skada:ApplySettings()
  1017. end,
  1018. },
  1019. mode = {
  1020. type="toggle",
  1021. name=L["Mode"],
  1022. order=2,
  1023. get=function() return db.buttons.mode == nil or db.buttons.mode end,
  1024. set=function()
  1025. db.buttons.mode = not db.buttons.mode
  1026. Skada:ApplySettings()
  1027. end,
  1028. },
  1029. segment = {
  1030. type="toggle",
  1031. name=L["Segment"],
  1032. order=3,
  1033. get=function() return db.buttons.segment == nil or db.buttons.segment end,
  1034. set=function()
  1035. db.buttons.segment = not db.buttons.segment
  1036. Skada:ApplySettings()
  1037. end,
  1038. },
  1039. reset = {
  1040. type="toggle",
  1041. name=L["Reset"],
  1042. order=4,
  1043. get=function() return db.buttons.reset end,
  1044. set=function()
  1045. db.buttons.reset = not db.buttons.reset
  1046. Skada:ApplySettings()
  1047. end,
  1048. },
  1049. menu = {
  1050. type="toggle",
  1051. name=L["Configure"],
  1052. order=5,
  1053. get=function() return db.buttons.menu end,
  1054. set=function()
  1055. db.buttons.menu = not db.buttons.menu
  1056. Skada:ApplySettings()
  1057. end,
  1058. },
  1059. }
  1060. }
  1061. }
  1062. }
  1063.  
  1064. options.windowoptions = {
  1065. type = "group",
  1066. name = L["Window"],
  1067. order=2,
  1068. args = {
  1069.  
  1070. texture = {
  1071. type = 'select',
  1072. dialogControl = 'LSM30_Background',
  1073. name = L["Background texture"],
  1074. desc = L["The texture used as the background."],
  1075. values = AceGUIWidgetLSMlists.background,
  1076. get = function() return db.background.texture end,
  1077. set = function(win,key)
  1078. db.background.texture = key
  1079. Skada:ApplySettings()
  1080. end,
  1081. order=1,
  1082. },
  1083.  
  1084. bordertexture = {
  1085. type = 'select',
  1086. dialogControl = 'LSM30_Border',
  1087. name = L["Border texture"],
  1088. desc = L["The texture used for the borders."],
  1089. values = AceGUIWidgetLSMlists.border,
  1090. get = function() return db.background.bordertexture end,
  1091. set = function(win,key)
  1092. db.background.bordertexture = key
  1093. Skada:ApplySettings()
  1094. end,
  1095. order=2,
  1096. },
  1097.  
  1098. thickness = {
  1099. type="range",
  1100. name=L["Border thickness"],
  1101. desc=L["The thickness of the borders."],
  1102. min=0,
  1103. max=50,
  1104. step=0.5,
  1105. get=function() return db.background.borderthickness end,
  1106. set=function(win, val)
  1107. db.background.borderthickness = val
  1108. Skada:ApplySettings()
  1109. end,
  1110. order=3,
  1111. },
  1112.  
  1113. margin = {
  1114. type="range",
  1115. name=L["Margin"],
  1116. desc=L["The margin between the outer edge and the background texture."],
  1117. min=0,
  1118. max=50,
  1119. step=0.5,
  1120. get=function() return db.background.margin end,
  1121. set=function(win, val)
  1122. db.background.margin = val
  1123. Skada:ApplySettings()
  1124. end,
  1125. order=4,
  1126. },
  1127.  
  1128. scale = {
  1129. type="range",
  1130. name=L["Scale"],
  1131. desc=L["Sets the scale of the window."],
  1132. min=0.1,
  1133. max=3,
  1134. step=0.01,
  1135. get=function() return db.scale end,
  1136. set=function(win, val)
  1137. db.scale = val
  1138. Skada:ApplySettings()
  1139. end,
  1140. order=3,
  1141. },
  1142.  
  1143. color = {
  1144. type="color",
  1145. name=L["Background color"],
  1146. desc=L["The color of the background."],
  1147. hasAlpha=true,
  1148. get=function(i)
  1149. local c = db.background.color
  1150. return c.r, c.g, c.b, c.a
  1151. end,
  1152. set=function(i, r,g,b,a)
  1153. db.background.color = {["r"] = r, ["g"] = g, ["b"] = b, ["a"] = a}
  1154. Skada:ApplySettings()
  1155. end,
  1156. order=6,
  1157. },
  1158.  
  1159. }
  1160. }
  1161.  
  1162. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement