Advertisement
Guest User

Menus.lua

a guest
Oct 30th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.83 KB | None | 0 0
  1. local L = LibStub("AceLocale-3.0"):GetLocale("Skada", false)
  2. local AceGUI = LibStub("AceGUI-3.0")
  3.  
  4. -- Configuration menu.
  5. function Skada:OpenMenu(window)
  6. if not self.skadamenu then
  7. self.skadamenu = CreateFrame("Frame", "SkadaMenu")
  8. end
  9. local skadamenu = self.skadamenu
  10.  
  11. skadamenu.displayMode = "MENU"
  12. local info = {}
  13. skadamenu.initialize = function(self, level)
  14. if not level then return end
  15. wipe(info)
  16. if level == 1 then
  17. -- Create the title of the menu
  18. info.isTitle = 1
  19. info.text = L["Skada Menu"]
  20. info.notCheckable = 1
  21. UIDropDownMenu_AddButton(info, level)
  22.  
  23. for i, win in ipairs(Skada:GetWindows()) do
  24. wipe(info)
  25. info.text = win.db.name
  26. info.hasArrow = 1
  27. info.value = win
  28. info.notCheckable = 1
  29. UIDropDownMenu_AddButton(info, level)
  30. end
  31.  
  32. -- Add a blank separator
  33. wipe(info)
  34. info.disabled = 1
  35. info.notCheckable = 1
  36. UIDropDownMenu_AddButton(info, level)
  37.  
  38. -- Can't report if we are not in a mode.
  39. if not window or (window and window.selectedmode) then
  40. wipe(info)
  41. info.text = L["Report"]
  42. info.func = function() Skada:OpenReportWindow(window) end
  43. info.value = "report"
  44. info.notCheckable = 1
  45. UIDropDownMenu_AddButton(info, level)
  46. end
  47.  
  48. wipe(info)
  49. info.text = L["Delete segment"]
  50. info.hasArrow = 1
  51. info.notCheckable = 1
  52. info.value = "delete"
  53. UIDropDownMenu_AddButton(info, level)
  54.  
  55. wipe(info)
  56. info.text = L["Keep segment"]
  57. info.notCheckable = 1
  58. info.hasArrow = 1
  59. info.value = "keep"
  60. UIDropDownMenu_AddButton(info, level)
  61.  
  62. -- Add a blank separator
  63. wipe(info)
  64. info.disabled = 1
  65. info.notCheckable = 1
  66. UIDropDownMenu_AddButton(info, level)
  67.  
  68. wipe(info)
  69. info.text = L["Toggle window"]
  70. info.func = function() Skada:ToggleWindow() end
  71. info.notCheckable = 1
  72. UIDropDownMenu_AddButton(info, level)
  73.  
  74. wipe(info)
  75. info.text = L["Reset"]
  76. info.func = function() Skada:Reset() end
  77. info.notCheckable = 1
  78. UIDropDownMenu_AddButton(info, level)
  79.  
  80. wipe(info)
  81. info.text = L["Start new segment"]
  82. info.func = function() Skada:NewSegment() end
  83. info.notCheckable = 1
  84. UIDropDownMenu_AddButton(info, level)
  85.  
  86.  
  87. wipe(info)
  88. info.text = L["Configure"]
  89. info.func = function() InterfaceOptionsFrame_OpenToCategory("Skada") InterfaceOptionsFrame_OpenToCategory("Skada") end
  90. info.notCheckable = 1
  91. UIDropDownMenu_AddButton(info, level)
  92.  
  93. -- Close menu item
  94. wipe(info)
  95. info.text = CLOSE
  96. info.func = function() CloseDropDownMenus() end
  97. info.checked = nil
  98. info.notCheckable = 1
  99. UIDropDownMenu_AddButton(info, level)
  100. elseif level == 2 then
  101. if type(UIDROPDOWNMENU_MENU_VALUE) == "table" then
  102. local window = UIDROPDOWNMENU_MENU_VALUE
  103. -- Display list of modes with current ticked; let user switch mode by checking one.
  104. wipe(info)
  105. info.isTitle = 1
  106. info.text = L["Mode"]
  107. UIDropDownMenu_AddButton(info, level)
  108.  
  109. for i, module in ipairs(Skada:GetModes()) do
  110. wipe(info)
  111. info.text = module:GetName()
  112. info.func = function() window:DisplayMode(module) end
  113. info.checked = (window.selectedmode == module)
  114. UIDropDownMenu_AddButton(info, level)
  115. end
  116.  
  117. -- Separator
  118. wipe(info)
  119. info.disabled = 1
  120. info.notCheckable = 1
  121. UIDropDownMenu_AddButton(info, level)
  122.  
  123. -- Display list of sets with current ticked; let user switch set by checking one.
  124. wipe(info)
  125. info.isTitle = 1
  126. info.text = L["Segment"]
  127. UIDropDownMenu_AddButton(info, level)
  128.  
  129. wipe(info)
  130. info.text = L["Total"]
  131. info.func = function()
  132. window.selectedset = "total"
  133. Skada:Wipe()
  134. Skada:UpdateDisplay(true)
  135. end
  136. info.checked = (window.selectedset == "total")
  137. UIDropDownMenu_AddButton(info, level)
  138. wipe(info)
  139. info.text = L["Current"]
  140. info.func = function()
  141. window.selectedset = "current"
  142. Skada:Wipe()
  143. Skada:UpdateDisplay(true)
  144. end
  145. info.checked = (window.selectedset == "current")
  146. UIDropDownMenu_AddButton(info, level)
  147.  
  148. for i, set in ipairs(Skada:GetSets()) do
  149. wipe(info)
  150. info.text = Skada:GetSetLabel(set)
  151. info.func = function()
  152. window.selectedset = i
  153. Skada:Wipe()
  154. Skada:UpdateDisplay(true)
  155. end
  156. info.checked = (window.selectedset == set.starttime)
  157. UIDropDownMenu_AddButton(info, level)
  158. end
  159.  
  160. -- Add a blank separator
  161. wipe(info)
  162. info.disabled = 1
  163. info.notCheckable = 1
  164. UIDropDownMenu_AddButton(info, level)
  165.  
  166. wipe(info)
  167. info.text = L["Lock window"]
  168. info.func = function()
  169. window.db.barslocked = not window.db.barslocked
  170. Skada:ApplySettings()
  171. end
  172. info.checked = window.db.barslocked
  173. UIDropDownMenu_AddButton(info, level)
  174.  
  175. wipe(info)
  176. info.text = L["Hide window"]
  177. info.func = function() if window:IsShown() then window.db.hidden = true; window:Hide() else window.db.hidden = false; window:Show() end end
  178. info.checked = not window:IsShown()
  179. UIDropDownMenu_AddButton(info, level)
  180.  
  181. elseif UIDROPDOWNMENU_MENU_VALUE == "delete" then
  182. for i, set in ipairs(Skada:GetSets()) do
  183. wipe(info)
  184. info.text = Skada:GetSetLabel(set)
  185. info.func = function() Skada:DeleteSet(set) end
  186. info.notCheckable = 1
  187. UIDropDownMenu_AddButton(info, level)
  188. end
  189. elseif UIDROPDOWNMENU_MENU_VALUE == "keep" then
  190. for i, set in ipairs(Skada:GetSets()) do
  191. wipe(info)
  192. info.text = Skada:GetSetLabel(set)
  193. info.func = function()
  194. set.keep = not set.keep
  195. Skada:Wipe()
  196. Skada:UpdateDisplay(true)
  197. end
  198. info.checked = set.keep
  199. UIDropDownMenu_AddButton(info, level)
  200. end
  201. end
  202. elseif level == 3 then
  203. if UIDROPDOWNMENU_MENU_VALUE == "modes" then
  204.  
  205. for i, module in ipairs(Skada:GetModes()) do
  206. wipe(info)
  207. info.text = module:GetName()
  208. info.checked = (Skada.db.profile.report.mode == module:GetName())
  209. info.func = function() Skada.db.profile.report.mode = module:GetName() end
  210. UIDropDownMenu_AddButton(info, level)
  211. end
  212. elseif UIDROPDOWNMENU_MENU_VALUE == "segment" then
  213. wipe(info)
  214. info.text = L["Total"]
  215. info.func = function() Skada.db.profile.report.set = "total" end
  216. info.checked = (Skada.db.profile.report.set == "total")
  217. UIDropDownMenu_AddButton(info, level)
  218.  
  219. info.text = L["Current"]
  220. info.func = function() Skada.db.profile.report.set = "current" end
  221. info.checked = (Skada.db.profile.report.set == "current")
  222. UIDropDownMenu_AddButton(info, level)
  223.  
  224. for i, set in ipairs(Skada:GetSets()) do
  225. info.text = Skada:GetSetLabel(set)
  226. info.func = function() Skada.db.profile.report.set = i end
  227. info.checked = (Skada.db.profile.report.set == i)
  228. UIDropDownMenu_AddButton(info, level)
  229. end
  230. elseif UIDROPDOWNMENU_MENU_VALUE == "number" then
  231. for i = 1,25 do
  232. wipe(info)
  233. info.text = i
  234. info.checked = (Skada.db.profile.report.number == i)
  235. info.func = function() Skada.db.profile.report.number = i end
  236. UIDropDownMenu_AddButton(info, level)
  237. end
  238. elseif UIDROPDOWNMENU_MENU_VALUE == "channel" then
  239. wipe(info)
  240. info.text = L["Whisper"]
  241. info.checked = (Skada.db.profile.report.chantype == "whisper")
  242. info.func = function() Skada.db.profile.report.channel = "Whisper"; Skada.db.profile.report.chantype = "whisper" end
  243. UIDropDownMenu_AddButton(info, level)
  244.  
  245. info.text = L["Say"]
  246. info.checked = (Skada.db.profile.report.channel == "Say")
  247. info.func = function() Skada.db.profile.report.channel = "Say"; Skada.db.profile.report.chantype = "preset" end
  248. UIDropDownMenu_AddButton(info, level)
  249.  
  250. info.text = L["Raid"]
  251. info.checked = (Skada.db.profile.report.channel == "Raid")
  252. info.func = function() Skada.db.profile.report.channel = "Raid"; Skada.db.profile.report.chantype = "preset" end
  253. UIDropDownMenu_AddButton(info, level)
  254.  
  255. info.text = L["Party"]
  256. info.checked = (Skada.db.profile.report.channel == "Party")
  257. info.func = function() Skada.db.profile.report.channel = "Party"; Skada.db.profile.report.chantype = "preset" end
  258. UIDropDownMenu_AddButton(info, level)
  259.  
  260. info.text = L["Instance"]
  261. info.checked = (Skada.db.profile.report.channel == "INSTANCE_CHAT")
  262. info.func = function() Skada.db.profile.report.channel = "INSTANCE_CHAT"; Skada.db.profile.report.chantype = "preset" end
  263. UIDropDownMenu_AddButton(info, level)
  264.  
  265. info.text = L["Guild"]
  266. info.checked = (Skada.db.profile.report.channel == "Guild")
  267. info.func = function() Skada.db.profile.report.channel = "Guild"; Skada.db.profile.report.chantype = "preset" end
  268. UIDropDownMenu_AddButton(info, level)
  269.  
  270. info.text = L["Officer"]
  271. info.checked = (Skada.db.profile.report.channel == "Officer")
  272. info.func = function() Skada.db.profile.report.channel = "Officer"; Skada.db.profile.report.chantype = "preset" end
  273. UIDropDownMenu_AddButton(info, level)
  274.  
  275. info.text = L["Self"]
  276. info.checked = (Skada.db.profile.report.chantype == "self")
  277. info.func = function() Skada.db.profile.report.channel = "Self"; Skada.db.profile.report.chantype = "self" end
  278. UIDropDownMenu_AddButton(info, level)
  279.  
  280. info.text = L["RealID"]
  281. info.checked = (Skada.db.profile.report.chantype == "realid")
  282. info.func = function() Skada.db.profile.report.channel = "RealID"; Skada.db.profile.report.chantype = "realid" end
  283. UIDropDownMenu_AddButton(info, level)
  284.  
  285. local list = {GetChannelList()}
  286. for i=1,table.getn(list)/2 do
  287. info.text = list[i*2]
  288. info.checked = (Skada.db.profile.report.channel == list[i*2])
  289. info.func = function() Skada.db.profile.report.channel = list[i*2]; Skada.db.profile.report.chantype = "channel" end
  290. UIDropDownMenu_AddButton(info, level)
  291. end
  292.  
  293. end
  294.  
  295. end
  296. end
  297.  
  298. local x,y = GetCursorPosition(UIParent);
  299. ToggleDropDownMenu(1, nil, skadamenu, "UIParent", x / UIParent:GetEffectiveScale() , y / UIParent:GetEffectiveScale())
  300. end
  301.  
  302. function Skada:SegmentMenu(window)
  303. if not self.segmentsmenu then
  304. self.segmentsmenu = CreateFrame("Frame", "SkadaWindowButtonsSegments")
  305. end
  306. local segmentsmenu = self.segmentsmenu
  307.  
  308. segmentsmenu.displayMode = "MENU"
  309. local info = {}
  310. segmentsmenu.initialize = function(self, level)
  311. if not level then return end
  312.  
  313. info.isTitle = 1
  314. info.text = L["Segment"]
  315. UIDropDownMenu_AddButton(info, level)
  316. info.isTitle = nil
  317.  
  318. wipe(info)
  319. info.text = L["Total"]
  320. info.func = function()
  321. window.selectedset = "total"
  322. Skada:Wipe()
  323. Skada:UpdateDisplay(true)
  324. end
  325. info.checked = (window.selectedset == "total")
  326. UIDropDownMenu_AddButton(info, level)
  327.  
  328. wipe(info)
  329. info.text = L["Current"]
  330. info.func = function()
  331. window.selectedset = "current"
  332. Skada:Wipe()
  333. Skada:UpdateDisplay(true)
  334. end
  335. info.checked = (window.selectedset == "current")
  336. UIDropDownMenu_AddButton(info, level)
  337.  
  338. for i, set in ipairs(Skada:GetSets()) do
  339. wipe(info)
  340. info.text = Skada:GetSetLabel(set)
  341. info.func = function()
  342. window.selectedset = i
  343. Skada:Wipe()
  344. Skada:UpdateDisplay(true)
  345. end
  346. info.checked = (window.selectedset == i)
  347. UIDropDownMenu_AddButton(info, level)
  348. end
  349. end
  350. local x,y = GetCursorPosition(UIParent);
  351. ToggleDropDownMenu(1, nil, segmentsmenu, "UIParent", x / UIParent:GetEffectiveScale() , y / UIParent:GetEffectiveScale())
  352. end
  353.  
  354. function Skada:ModeMenu(window)
  355. --Spew("window", window)
  356. if not self.modesmenu then
  357. self.modesmenu = CreateFrame("Frame", "SkadaWindowButtonsModes")
  358. end
  359. local modesmenu = self.modesmenu
  360.  
  361. modesmenu.displayMode = "MENU"
  362. local info = {}
  363. modesmenu.initialize = function(self, level)
  364. if not level then return end
  365.  
  366. info.isTitle = 1
  367. info.text = L["Mode"]
  368. UIDropDownMenu_AddButton(info, level)
  369.  
  370. for i, module in ipairs(Skada:GetModes()) do
  371. wipe(info)
  372. info.text = module:GetName()
  373. info.func = function() window:DisplayMode(module) end
  374. info.checked = (window.selectedmode == module)
  375. UIDropDownMenu_AddButton(info, level)
  376. end
  377. end
  378. local x,y = GetCursorPosition(UIParent);
  379. ToggleDropDownMenu(1, nil, modesmenu, "UIParent", x / UIParent:GetEffectiveScale() , y / UIParent:GetEffectiveScale())
  380. end
  381.  
  382. function Skada:OpenReportWindow(window)
  383. if self.ReportWindow==nil then
  384. self:CreateReportWindow(window)
  385. end
  386.  
  387. --self:UpdateReportWindow()
  388. self.ReportWindow:Show()
  389. end
  390.  
  391. local function destroywindow()
  392. if Skada.ReportWindow then
  393. Skada.ReportWindow:ReleaseChildren()
  394. Skada.ReportWindow:Hide()
  395. Skada.ReportWindow:Release()
  396. end
  397. Skada.ReportWindow = nil
  398. end
  399.  
  400. function Skada:CreateReportWindow(window)
  401. -- ASDF = window
  402. self.ReportWindow = AceGUI:Create("Window")
  403. local frame = self.ReportWindow
  404. frame:EnableResize(false)
  405. frame:SetWidth(250)
  406. frame:SetLayout("Flow")
  407. if window then
  408. frame:SetHeight(220)
  409. else
  410. frame:SetHeight(310)
  411. end
  412. frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  413. if window then
  414. frame:SetTitle(L["Report"] .. (" - %s"):format(window.db.name))
  415. else
  416. frame:SetTitle(L["Report"])
  417. end
  418. frame:SetCallback("OnClose", function(widget, callback) destroywindow() end)
  419.  
  420. if window then
  421. Skada.db.profile.report.set = window.selectedset
  422. Skada.db.profile.report.mode = window.db.mode
  423. else
  424. -- Mode, default last chosen or first available.
  425. local modebox = AceGUI:Create("Dropdown")
  426. modebox:SetLabel(L["Mode"])
  427. modebox:SetList({})
  428. for i, mode in ipairs(Skada:GetModes()) do
  429. modebox:AddItem(mode:GetName(), mode:GetName())
  430. end
  431. modebox:SetCallback("OnValueChanged", function(f, e, value) Skada.db.profile.report.mode = value end)
  432. modebox:SetValue(Skada.db.profile.report.mode or Skada:GetModes()[1])
  433. frame:AddChild(modebox)
  434.  
  435. -- Segment, default last chosen or last set.
  436. local setbox = AceGUI:Create("Dropdown")
  437. setbox:SetLabel(L["Segment"])
  438. setbox:SetList({total = L["Total"], current = L["Current"]})
  439. for i, set in ipairs(Skada:GetSets()) do
  440. setbox:AddItem(i, (Skada:GetSetLabel(set)))
  441. end
  442. setbox:SetCallback("OnValueChanged", function(f, e, value) Skada.db.profile.report.set = value end)
  443. setbox:SetValue(Skada.db.profile.report.set or Skada:GetSets()[1])
  444. frame:AddChild(setbox)
  445. end
  446.  
  447. local channellist = {
  448. whisper = { L["Whisper"], "whisper"},
  449. target = { "Whisper Target", "whisper"},
  450. say = { L["Say"], "preset"},
  451. raid = { L["Raid"], "preset"},
  452. party = { L["Party"], "preset"},
  453. instance_chat = { L["Instance"], "preset"},
  454. guild = { L["Guild"], "preset"},
  455. officer = { L["Officer"], "preset"},
  456. self = { L["Self"], "self"},
  457. realid = { L["RealID"], "RealID"},
  458. }
  459. local list = {GetChannelList()}
  460. for i=1,#list/2 do
  461. local chan = list[i*2]
  462. if chan ~= "Trade" and chan ~= "General" and chan ~= "LookingForGroup" then -- These should be localized.
  463. channellist[chan] = {chan, "channel"}
  464. end
  465. end
  466.  
  467. -- Channel, default last chosen or Say.
  468. local channelbox = AceGUI:Create("Dropdown")
  469. channelbox:SetLabel(L["Channel"])
  470. channelbox:SetList( {} )
  471. for chan, kind in pairs(channellist) do
  472. channelbox:AddItem(chan, kind[1])
  473. end
  474. channelbox:SetCallback("OnValueChanged",
  475. function(f, e, value)
  476. Skada.db.profile.report.channel = value
  477. Skada.db.profile.report.chantype = channellist[value][2]
  478. end
  479. )
  480. channelbox:SetValue(Skada.db.profile.report.channel or "say")
  481. frame:AddChild(channelbox)
  482.  
  483. local lines = AceGUI:Create("Slider")
  484. lines:SetLabel(L["Lines"])
  485. lines:SetValue(Skada.db.profile.report.number ~= nil and Skada.db.profile.report.number or 10)
  486. lines:SetSliderValues(1, 25, 1)
  487. lines:SetCallback("OnValueChanged", function(self, event, value) Skada.db.profile.report.number = value end)
  488. lines:SetFullWidth(true)
  489. frame:AddChild(lines)
  490.  
  491. local whisperbox = AceGUI:Create("EditBox")
  492. whisperbox:SetLabel("Whisper Target")
  493. whisperbox:SetText(Skada.db.profile.report.target)
  494. whisperbox:SetCallback("OnEnterPressed", function(box, event, text) Skada.db.profile.report.target = text; frame.button.frame:Click() end)
  495. whisperbox:SetCallback("OnTextChanged", function(box, event, text) Skada.db.profile.report.target = text end)
  496. whisperbox:SetFullWidth(true)
  497.  
  498. local report = AceGUI:Create("Button")
  499. frame.button = report
  500. report:SetText(L["Report"])
  501. report:SetCallback("OnClick", function()
  502. local mode, set, channel, chantype, number = Skada.db.profile.report.mode, Skada.db.profile.report.set, Skada.db.profile.report.channel, Skada.db.profile.report.chantype, Skada.db.profile.report.number
  503.  
  504. if channel == "whisper" then
  505. channel = Skada.db.profile.report.target
  506. elseif channel == "realid" then
  507. channel = BNet_GetPresenceID(Skada.db.profile.report.target)
  508. elseif channel == "target" then
  509. if UnitExists("target") then
  510. channel = UnitName("target")
  511. else
  512. channel = nil
  513. end
  514. end
  515. -- print(tostring(frame.channel), tostring(frame.chantype), tostring(window.db.mode))
  516.  
  517. if channel and chantype and mode and set and number then
  518. Skada:Report(channel, chantype, mode, set, number, window)
  519. frame:Hide()
  520. else
  521. Skada:Print("Error: No options selected")
  522. end
  523.  
  524. end)
  525. report:SetFullWidth(true)
  526. frame:AddChildren(whisperbox, report)
  527. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement