Advertisement
Guest User

DailyChecklist update 2

a guest
Sep 21st, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 76.39 KB | None | 0 0
  1. -- Create main object and load AceConsole so we can use console commands
  2. DailyChecklist = LibStub("AceAddon-3.0"):NewAddon("DailyChecklist", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
  3.  
  4. -- Create empty table for localization data
  5. DailyChecklist.localize = {}
  6. DailyChecklist.data = {}
  7.  
  8. -- Create our addon message prefix
  9. local PREFIX = "[DailyChecklist]"
  10.  
  11. -- Use variables for numberic weekdays, matches return from date(%w) + 1
  12. local SUNDAY = 1
  13. local MONDAY = 2
  14. local TUESDAY = 3
  15. local WEDNESDAY = 4
  16. local THURSDAY = 5
  17. local FRIDAY = 6
  18. local SATURDAY = 7
  19.  
  20. local expandNormalTexture = "Interface\\BUTTONS\\UI-PlusButton-Up.blp"
  21. local expandPushedTexture = "Interface\\BUTTONS\\UI-PlusButton-Down.blp"
  22. local contractNormalTexture = "Interface\\BUTTONS\\UI-MinusButton-Up.blp"
  23. local contractPushedTexture = "Interface\\BUTTONS\\UI-MinusButton-Down.blp"
  24. local expandHighlightTexture = "Interface\\BUTTONS\\UI-PlusButton-Hilight.png"
  25.  
  26. local intervalConverter = {600, 1200, 1800, 3600}
  27.  
  28. -- Create stack/pools for unused, previously created interface objects
  29. DailyChecklist.checklistFrameCheckboxPool = {}
  30. DailyChecklist.checklistFrameTextPool = {}
  31. DailyChecklist.checklistFrameHeaderExpandPool = {}
  32. DailyChecklist.checklistFrameHeaderTextPool = {}
  33. DailyChecklist.checklistFrameHeaderCheckboxPool = {}
  34.  
  35. -- Create color variables
  36. DailyChecklist.selectedEntryColor = "|cffFFB90F"
  37. DailyChecklist.managerPanelHeight = 300
  38.  
  39. DailyChecklist.timerId = nil
  40. DailyChecklist.currentDay = nil
  41. DailyChecklist.selectedManagerFrameText = nil
  42. DailyChecklist.selectedManagerFrameList = nil
  43.  
  44. -- Create our minimap icon
  45. DailyChecklist.DailyChecklistLDB = LibStub("LibDataBroker-1.1"):NewDataObject("DailyChecklistDO", {
  46. type = "data source",
  47. text = "DailyChecklist",
  48. icon = "Interface\\RAIDFRAME\\ReadyCheck-Ready.blp",
  49. OnTooltipShow = function(tt)
  50. tt:AddLine("DailyChecklist-1.0")
  51. tt:AddLine("|cffffff00" .. "Left Click to hide/show frame")
  52. tt:AddLine("|cffffff00" .. "Right Click to open options")
  53. end,
  54. OnClick = function(self, button) DailyChecklist:HandleIconClick(button) end,
  55. })
  56. DailyChecklist.icon = LibStub("LibDBIcon-1.0")
  57.  
  58. -- Set our database default values
  59. DailyChecklist.defaults = {
  60. profile = {
  61. version = "1.0",
  62. icon = {
  63. hide = false,
  64. },
  65. framePosition = {
  66. x = 0,
  67. y = 0,
  68. anchor = "CENTER",
  69. hidden = false,
  70. },
  71. locked = false,
  72. showListHeaders = true,
  73. hideCompleted = false,
  74. timestamp = nil,
  75. dailyResetTime = 1,
  76. weeklyResetDay = 3,
  77. resetPollInterval = 5,
  78. lists = {
  79. [1] = {
  80. name = "Default",
  81. expanded = true,
  82. entries = {
  83. --[[
  84. entryId index, maintains incremental
  85. [1] = {
  86. text = "Test",
  87. completed = false,
  88. checked = true,
  89. days = {
  90. [SUNDAY] = false,
  91. [MONDAY] = false,
  92. [TUESDAY] = true,
  93. [WEDNESDAY] = false,
  94. [THURSDAY] = false,
  95. [FRIDAY] = false,
  96. [SATURDAY] = false,
  97. },
  98. weekly = false
  99. }
  100. ]]
  101. },
  102. }
  103. },
  104. },
  105. }
  106.  
  107. -- Initialize addon, called directly after the addon is fully loaded
  108. function DailyChecklist:OnInitialize()
  109. -- Create our database with default values
  110. self.db = LibStub("AceDB-3.0"):New("DailyChecklistDB", self.defaults);
  111. self.db.RegisterCallback(self, "OnProfileChanged", "RefreshEverything")
  112. self.db.RegisterCallback(self, "OnProfileCopied", "RefreshEverything")
  113. self.db.RegisterCallback(self, "OnProfileReset", "RefreshEverything")
  114.  
  115. -- Register our minimap icon
  116. self.icon:Register("DailyChecklistDO", self.DailyChecklistLDB, self.db.profile.icon)
  117.  
  118. -- Register our addon message prefix
  119. RegisterAddonMessagePrefix(PREFIX)
  120.  
  121. -- Register chat commands
  122. self:RegisterChatCommand("dcl", "HandleChatMessageCommands")
  123. self:RegisterChatCommand("DailyChecklist", "HandleChatMessageCommands")
  124. end
  125.  
  126. function DailyChecklist:HandleChatMessageCommands(msg)
  127. local command, text = msg:match("(%S+)%s*(%S*)")
  128. if command == "show" then
  129. self.checklistFrame:Show()
  130. WatchFrame:Hide()
  131.  
  132. if text == "icon" then
  133. self.db.profile.icon.hide = false
  134. else
  135. if text == "completed" then
  136. self.db.profile.hideCompleted = false
  137. self:UpdateVisibilityOnChecklistFrame(false)
  138. self:UpdateEntryPositionsOnChecklistFrame()
  139. else
  140. self:ShowChecklistFrame()
  141. end
  142. end
  143. elseif command == "hide" then
  144. if text == "icon" then
  145. self.db.profile.icon.hide = true
  146. else
  147. if text == "completed" then
  148. self.db.profile.hideCompleted = true
  149. self:UpdateVisibilityOnChecklistFrame(true)
  150. self:UpdateEntryPositionsOnChecklistFrame()
  151. WatchFrame:Hide()
  152. else
  153. self:HideChecklistFrame()
  154. WatchFrame:Show()
  155. end
  156. end
  157. elseif command == "lock" then
  158. self.db.profile.locked = true
  159. elseif command == "unlock" then
  160. self.db.profile.locked = false
  161. elseif command == "check" and text == "time" then
  162. self:UpdateForNewDateAndTime()
  163. elseif command == "options" then
  164. InterfaceOptionsFrame_OpenToCategory(self.checklistOptionsFrame)
  165. elseif command == "manager" then
  166. InterfaceOptionsFrame_OpenToCategory(self.checklistManagerFrame)
  167. elseif command == "profiles" then
  168. InterfaceOptionsFrame_OpenToCategory(self.checklistProfilesFrame)
  169. elseif command == "help" then
  170. self:Print("\"/dcl show\" : shows checklist")
  171. self:Print("\"/dcl hide\" : hides checklist")
  172. self:Print("\"/dcl show icon\" : shows minimap icon (requires ui restart to take effect)")
  173. self:Print("\"/dcl hide icon\" : hides minimap icon (requires ui restart to take effect)")
  174. self:Print("\"/dcl lock\" : locks checklist position")
  175. self:Print("\"/dcl unlock\" : unlocks checklist position")
  176. self:Print("\"/dcl check time\" : check if entries should be reset")
  177. self:Print("\"/dcl show completed\" : show completed entries")
  178. self:Print("\"/dcl hide completed\" : hide completed entries")
  179. self:Print("\"/dcl options\" : opens options dialog")
  180. self:Print("\"/dcl profiles\" : opens profiles dialog")
  181. self:Print("\"/dcl manager\" : opens manager dialog")
  182. else
  183. self:Print("Usage: \"/dcl <command> <identifier>\"")
  184. self:Print("Type: \"/dcl help\" for a list of commands")
  185. end
  186. end
  187.  
  188. -- Called when the addon is enabled
  189. function DailyChecklist:OnEnable()
  190.  
  191. -- Notify user that DailyChecklist is enabled, give config command
  192. self:Print("Daily Checklist enabled. Use '/dcl' to open the manager.")
  193.  
  194. self:CheckCurrentDateAndTime(true)
  195.  
  196. self:ResetTimer()
  197.  
  198. -- Initialize number of entries that will fit in interface options panel
  199. self.maxEntries = math.floor((InterfaceOptionsFramePanelContainer:GetHeight() - self.managerPanelHeight) / 20)
  200.  
  201. -- Create options frame
  202. self:CreateManagerFrame()
  203.  
  204. -- Create checklist frame
  205. self:CreateChecklistFrame()
  206. end
  207.  
  208. -- Called when timer interval changes
  209. function DailyChecklist:ResetTimer()
  210. -- Remove old timer
  211. if self.timerId then
  212. self:CancelTimer(self.timerId)
  213. self.timerId = nil
  214. end
  215.  
  216. if self.db.profile.resetPollInterval ~= 1 then
  217. self.timerId = self:ScheduleRepeatingTimer("UpdateForNewDateAndTime", intervalConverter[self.db.profile.resetPollInterval - 1])
  218. end
  219. end
  220.  
  221. -- Updates checklist entries based on new time and/or day
  222. function DailyChecklist:UpdateForNewDateAndTime()
  223. if DailyChecklist:CheckCurrentDateAndTime(false) then
  224. DailyChecklist:UpdateEntryPositionsOnChecklistFrame()
  225. end
  226. DailyChecklist:UpdateEntryCompletedOnChecklistFrame()
  227. DailyChecklist:UpdateVisibilityOnChecklistFrame(self.db.profile.hideCompleted)
  228. end
  229.  
  230. -- Resets completed quests given the current day and time
  231. function DailyChecklist:CheckCurrentDateAndTime(firstTime)
  232. -- Save current weekday
  233. local oldDay = self.currentDay
  234. local entriesChanged = false
  235. self.currentDay = tonumber(date("%w")) + 1
  236. local currentListReset = false
  237. local currentTime = tonumber(date("%Y%m%d%H%M%S"))
  238.  
  239. -- If first time starting application
  240. if not self.db.profile.timestamp then
  241. self.db.profile.timestamp = tonumber(date("%Y%m%d")) * 1000000
  242. end
  243.  
  244. -- Set reset time to user selected time on current day
  245. local resetTime = tonumber(date("%Y%m%d")) * 1000000 + (self.db.profile.dailyResetTime - 1) * 10000
  246.  
  247. -- Check if we have completed quests for the current day on this character
  248. if self.db.profile.timestamp < resetTime and (currentTime > resetTime or (currentTime - 1000000) > self.db.profile.timestamp) then
  249. -- Has not been opened yet today, should reset completed quests
  250. for listId, list in ipairs(self.db.profile.lists) do
  251. for entryId, entry in ipairs(list.entries) do
  252. if not entry.manual then
  253. if not entry.weekly then
  254. entry.completed = false
  255. if not firstTime and self.checklistFrame.lists[listId] and self.checklistFrame.lists[listId].entries[entryId] and self.checklistFrame.lists[listId].entries[entryId].checkbox then
  256. self.checklistFrame.lists[listId].entries[entryId].checkbox:SetChecked(false)
  257. end
  258. currentListReset = true
  259. else
  260. if self.db.profile.weeklyResetDay == self.currentDay then
  261. entry.completed = false
  262. if not firstTime and self.checklistFrame.lists[listId] and self.checklistFrame.lists[listId].entries[entryId] and self.checklistFrame.lists[listId].entries[entryId].checkbox then
  263. self.checklistFrame.lists[listId].entries[entryId].checkbox:SetChecked(false)
  264. end
  265. currentListReset = true
  266. end
  267. end
  268. end
  269. end
  270. if currentListReset then
  271. list.completed = false
  272. if not firstTime and self.checklistFrame.lists[listId] and self.checklistFrame.lists[listId].checkbox then
  273. self.checklistFrame.lists[listId].checkbox:SetChecked(false)
  274. end
  275. currentListReset = false
  276. end
  277. end
  278. -- Update timestamp to future, we already updated today
  279. self.db.profile.timestamp = resetTime
  280. end
  281.  
  282. -- Check if entries should be removed or added due to day change
  283. if not firstTime and oldDay ~= self.currentDay then
  284. for listId, list in ipairs(self.db.profile.lists) do
  285. for entryId, entry in ipairs(list.entries) do
  286. if entry.days[oldDay] ~= entry.days[self.currentDay] then
  287. self:UpdateEntryOnChecklistFrame(listId, entryId, entry.checked)
  288. entriesChanged = true
  289. end
  290. end
  291. end
  292. end
  293.  
  294. return entriesChanged
  295. end
  296.  
  297. -- Create the main checklist frame
  298. function DailyChecklist:CreateChecklistFrame()
  299. self.checklistFrame = CreateFrame("Frame","ChecklistFrame",UIParent)
  300. self.checklistFrame:SetMovable(true)
  301. self.checklistFrame:EnableMouse(true)
  302. self.checklistFrame:SetClampedToScreen(true)
  303. self.checklistFrame:RegisterForDrag("LeftButton")
  304. self.checklistFrame:SetScript("OnDragStart", function(frame)
  305. if not DailyChecklist.db.profile.locked then
  306. frame:StartMoving()
  307. end
  308. end)
  309. self.checklistFrame:SetScript("OnDragStop", function(frame)
  310. frame:StopMovingOrSizing()
  311. DailyChecklist.db.profile.framePosition.anchor, _, _, DailyChecklist.db.profile.framePosition.x, DailyChecklist.db.profile.framePosition.y = frame:GetPoint()
  312. end)
  313. self.checklistFrame:SetBackdropColor(0,0,0,1);
  314. self.checklistFrame:SetHeight(200)
  315. self.checklistFrame:SetWidth(200)
  316. self.checklistFrame:SetAlpha(1.0)
  317.  
  318. if self.db.profile.framePosition.hidden then
  319. self.checklistFrame:Hide()
  320. WatchFrame:Show()
  321. else
  322. self.checklistFrame:Show()
  323. WatchFrame:Hide()
  324. end
  325.  
  326. -- Create empty array to store quest list buttons
  327. self.checklistFrame.lists = {}
  328.  
  329. -- Create the title text
  330. local title = self.checklistFrame:CreateFontString("TitleText", nil, "GameFontNormalLarge")
  331. title:SetText("|cffFFB90FDo Eeet!|r")
  332. title:SetPoint("TOPLEFT", self.checklistFrame, "TOPLEFT", -4, 0)
  333. title:Show()
  334.  
  335. self:CreateChecklistFrameElements()
  336.  
  337. self.checklistFrame:SetHeight(32)
  338. self.checklistFrame:SetPoint(self.db.profile.framePosition.anchor, nil, self.db.profile.framePosition.anchor, self.db.profile.framePosition.x, self.db.profile.framePosition.y-16)
  339.  
  340. end
  341.  
  342. function DailyChecklist:RemoveChecklistFrameElements()
  343. local listId = table.getn(self.checklistFrame.lists)
  344. while listId > 0 do
  345. self:RemoveListFromChecklistFrame(listId)
  346. listId = listId - 1
  347. end
  348. end
  349.  
  350. function DailyChecklist:CreateChecklistFrameElements()
  351.  
  352. -- Adjust offset for beginning of list
  353. local offset = 18
  354. local hasAny = false
  355.  
  356. -- Create entry tracking frame contents
  357. for listId, list in pairs(self.db.profile.lists) do
  358.  
  359. -- Create empty table for list
  360. self.checklistFrame.lists[listId] = {}
  361. self.checklistFrame.lists[listId].entries = {}
  362.  
  363. -- Determine if we should show list elements
  364. local show = true
  365.  
  366. if self.db.profile.showListHeaders then
  367.  
  368. if not list.completed or not self.db.profile.hideCompleted then
  369. hasAny = true
  370.  
  371. -- Create header expand button
  372. if table.getn(self.checklistFrameHeaderExpandPool) > 0 then
  373. self.checklistFrame.lists[listId].expand = self.checklistFrameHeaderExpandPool[1]
  374. table.remove(self.checklistFrameHeaderExpandPool, 1)
  375. else
  376. self.checklistFrame.lists[listId].expand = CreateFrame("Button", nil, self.checklistFrame, "UICheckButtonTemplate")
  377. self.checklistFrame.lists[listId].expand:SetWidth(12)
  378. self.checklistFrame.lists[listId].expand:SetHeight(12)
  379. self.checklistFrame.lists[listId].expand:SetScript("OnClick", function(self)
  380. DailyChecklist:ToggleChecklistFrameListExpand(self)
  381. end)
  382. self.checklistFrame.lists[listId].expand:SetHighlightTexture(expandHighlightTexture)
  383. end
  384.  
  385. if self.db.profile.lists[listId].expanded then
  386. self.checklistFrame.lists[listId].expand:SetNormalTexture(contractNormalTexture)
  387. self.checklistFrame.lists[listId].expand:SetPushedTexture(contractPushedTexture)
  388. else
  389. self.checklistFrame.lists[listId].expand:SetNormalTexture(expandNormalTexture)
  390. self.checklistFrame.lists[listId].expand:SetPushedTexture(expandPushedTexture)
  391. end
  392.  
  393. self.checklistFrame.lists[listId].expand:SetPoint("TOPLEFT", 1, -offset - 1)
  394. self.checklistFrame.lists[listId].expand.listId = listId
  395. self.checklistFrame.lists[listId].expand:Show()
  396.  
  397. -- Create header checkbox
  398. if table.getn(self.checklistFrameHeaderCheckboxPool) > 0 then
  399. self.checklistFrame.lists[listId].checkbox = self.checklistFrameHeaderCheckboxPool[1]
  400. table.remove(self.checklistFrameHeaderCheckboxPool, 1)
  401. else
  402. -- Create checkbox for list
  403. self.checklistFrame.lists[listId].checkbox = CreateFrame("CheckButton", nil, self.checklistFrame, "UICheckButtonTemplate")
  404. self.checklistFrame.lists[listId].checkbox:SetWidth(16)
  405. self.checklistFrame.lists[listId].checkbox:SetHeight(16)
  406. self.checklistFrame.lists[listId].checkbox:SetChecked(false)
  407. self.checklistFrame.lists[listId].checkbox:SetScript("OnClick", function(self)
  408. DailyChecklist:ToggleChecklistFrameListCheckbox(self)
  409. end)
  410. end
  411.  
  412. -- Change checkbox properties to match the new list
  413. self.checklistFrame.lists[listId].checkbox:SetPoint("TOPLEFT", 12, -offset + 1)
  414. self.checklistFrame.lists[listId].checkbox.listId = listId
  415. self.checklistFrame.lists[listId].checkbox:SetChecked(self.db.profile.lists[listId].completed)
  416. self.checklistFrame.lists[listId].checkbox:Show()
  417.  
  418. -- Check if we can reuse a label
  419. if table.getn(self.checklistFrameHeaderTextPool) > 0 then
  420. self.checklistFrame.lists[listId].headerText = self.checklistFrameHeaderTextPool[1]
  421. table.remove(self.checklistFrameHeaderTextPool, 1)
  422. else
  423. self.checklistFrame.lists[listId].headerText = self.checklistFrame:CreateFontString("ListHeader"..listId, nil, "GameFontNormal")
  424. end
  425.  
  426. -- Change header text for new entry
  427. self.checklistFrame.lists[listId].headerText:SetText(self.db.profile.lists[listId].name)
  428. self.checklistFrame.lists[listId].headerText:SetPoint("TOPLEFT", self.checklistFrame, "TOPLEFT", 30, -offset - 1)
  429. self.checklistFrame.lists[listId].headerText:Show()
  430.  
  431. hasAny = true
  432. offset = offset + 18
  433.  
  434. local playerName = UnitName("player");
  435. local listName = self.db.profile.lists[listId].name;
  436.  
  437. if playerName == listName or playerName == "Mohawkofdoom" and listName == "Mohawk o Doom" or playerName == "Lutze" and listName == "Lu Tze" or playerName == "Ghenghiz" and listName == "Ghenghiz Cohen" or playerName == "Cp" and listName == "cP" then
  438. self.db.profile.lists[listId].expanded = true
  439. else
  440. self.db.profile.lists[listId].expanded = false
  441. end
  442.  
  443. if not self.db.profile.lists[listId].expanded then
  444. show = false
  445. end
  446. else
  447. show = false
  448. end
  449. end
  450.  
  451. for entryId, entry in pairs(list.entries) do
  452.  
  453. --if entry.checked and entry.days[self.currentDay] then
  454. self:CreateEntryInChecklistFrame(listId, entryId, offset)
  455.  
  456. if not show or (entry.completed and self.db.profile.hideCompleted) then
  457. self.checklistFrame.lists[listId].entries[entryId].checkbox:Hide()
  458. self.checklistFrame.lists[listId].entries[entryId].headerText:Hide()
  459. else
  460. hasAny = true
  461. offset = offset + 16
  462. end
  463. --end
  464. end
  465. end
  466. end
  467.  
  468. function DailyChecklist:CreateEntryInChecklistFrame(listId, entryId, offset)
  469. -- Create empty table for new entry
  470. self.checklistFrame.lists[listId].entries[entryId] = {}
  471.  
  472. local horizontalOffset = 7
  473.  
  474. if self.db.profile.showListHeaders then
  475. horizontalOffset = horizontalOffset + 12
  476. end
  477.  
  478. -- Check if we can reuse a checkbox
  479. if table.getn(self.checklistFrameCheckboxPool) > 0 then
  480. self.checklistFrame.lists[listId].entries[entryId].checkbox = self.checklistFrameCheckboxPool[1]
  481. table.remove(self.checklistFrameCheckboxPool, 1)
  482. else
  483. -- Create checkbox for quest
  484. self.checklistFrame.lists[listId].entries[entryId].checkbox = CreateFrame("CheckButton", nil, self.checklistFrame, "UICheckButtonTemplate")
  485. self.checklistFrame.lists[listId].entries[entryId].checkbox:SetWidth(16)
  486. self.checklistFrame.lists[listId].entries[entryId].checkbox:SetHeight(16)
  487. self.checklistFrame.lists[listId].entries[entryId].checkbox:SetChecked(false)
  488. self.checklistFrame.lists[listId].entries[entryId].checkbox:SetScript("OnClick", function(self)
  489. DailyChecklist:ToggleSingleChecklistFrameCheckbox(self)
  490. end)
  491. end
  492.  
  493. -- Change checkbox properties to match the new quest
  494. self.checklistFrame.lists[listId].entries[entryId].checkbox:SetPoint("TOPLEFT", horizontalOffset, -offset + 1)
  495. self.checklistFrame.lists[listId].entries[entryId].checkbox.entryId = entryId
  496. self.checklistFrame.lists[listId].entries[entryId].checkbox.listId = listId
  497. self.checklistFrame.lists[listId].entries[entryId].checkbox:SetChecked(self.db.profile.lists[listId].entries[entryId].completed)
  498. self.checklistFrame.lists[listId].entries[entryId].checkbox:Show()
  499.  
  500. -- Check if we can reuse a label
  501. if table.getn(self.checklistFrameTextPool) > 0 then
  502. self.checklistFrame.lists[listId].entries[entryId].headerText = self.checklistFrameTextPool[1]
  503. table.remove(self.checklistFrameTextPool, 1)
  504. else
  505. self.checklistFrame.lists[listId].entries[entryId].headerText = self.checklistFrame:CreateFontString("QuestHeader"..entryId, nil, "ChatFontNormal")
  506. end
  507.  
  508. -- Change header text for new entry
  509. self.checklistFrame.lists[listId].entries[entryId].headerText:SetText(self.db.profile.lists[listId].entries[entryId].text)
  510. self.checklistFrame.lists[listId].entries[entryId].headerText:SetPoint("TOPLEFT", self.checklistFrame, "TOPLEFT", horizontalOffset + 16, -offset)
  511. self.checklistFrame.lists[listId].entries[entryId].headerText:Show()
  512.  
  513. end
  514.  
  515. -- Creates the UI elements of a list on the Checklist Frame
  516. function DailyChecklist:CreateListOnChecklistFrame(listId, offset)
  517. -- Create header expand button
  518. --if table.getn(self.checklistFrameHeaderExpandPool) > 0 then
  519. --self.checklistFrame.lists[listId].expand = self.checklistFrameHeaderExpandPool[1]
  520. --table.remove(self.checklistFrameHeaderExpandPool, 1)
  521. --else
  522. self.checklistFrame.lists[listId].expand = CreateFrame("Button", nil, self.checklistFrame, "UICheckButtonTemplate")
  523. self.checklistFrame.lists[listId].expand:SetWidth(12)
  524. self.checklistFrame.lists[listId].expand:SetHeight(12)
  525. self.checklistFrame.lists[listId].expand:SetScript("OnClick", function(self)
  526. DailyChecklist:ToggleChecklistFrameListExpand(self)
  527. end)
  528. self.checklistFrame.lists[listId].expand:SetHighlightTexture(expandHighlightTexture)
  529. --end
  530.  
  531. if self.db.profile.lists[listId].expanded then
  532. self.checklistFrame.lists[listId].expand:SetNormalTexture(contractNormalTexture)
  533. self.checklistFrame.lists[listId].expand:SetPushedTexture(contractPushedTexture)
  534. else
  535. self.checklistFrame.lists[listId].expand:SetNormalTexture(expandNormalTexture)
  536. self.checklistFrame.lists[listId].expand:SetPushedTexture(expandPushedTexture)
  537. end
  538.  
  539. self.checklistFrame.lists[listId].expand:SetPoint("TOPLEFT", 1, -offset - 1)
  540. self.checklistFrame.lists[listId].expand.listId = listId
  541. self.checklistFrame.lists[listId].expand:Show()
  542.  
  543. -- Create header checkbox
  544. if table.getn(self.checklistFrameHeaderCheckboxPool) > 0 then
  545. self.checklistFrame.lists[listId].checkbox = self.checklistFrameHeaderCheckboxPool[1]
  546. table.remove(self.checklistFrameHeaderCheckboxPool, 1)
  547. else
  548. -- Create checkbox for list
  549. self.checklistFrame.lists[listId].checkbox = CreateFrame("CheckButton", nil, self.checklistFrame, "UICheckButtonTemplate")
  550. self.checklistFrame.lists[listId].checkbox:SetWidth(16)
  551. self.checklistFrame.lists[listId].checkbox:SetHeight(16)
  552. self.checklistFrame.lists[listId].checkbox:SetChecked(false)
  553. self.checklistFrame.lists[listId].checkbox:SetScript("OnClick", function(self)
  554. DailyChecklist:ToggleChecklistFrameListCheckbox(self)
  555. end)
  556. end
  557.  
  558. -- Change checkbox properties to match the new list
  559. self.checklistFrame.lists[listId].checkbox:SetPoint("TOPLEFT", 12, -offset + 1)
  560. self.checklistFrame.lists[listId].checkbox.listId = listId
  561. self.checklistFrame.lists[listId].checkbox:SetChecked(self.db.profile.lists[listId].completed)
  562. self.checklistFrame.lists[listId].checkbox:Show()
  563.  
  564. -- Check if we can reuse a label
  565. if table.getn(self.checklistFrameHeaderTextPool) > 0 then
  566. self.checklistFrame.lists[listId].headerText = self.checklistFrameHeaderTextPool[1]
  567. table.remove(self.checklistFrameHeaderTextPool, 1)
  568. else
  569. self.checklistFrame.lists[listId].headerText = self.checklistFrame:CreateFontString("ListHeader"..listId, nil, "GameFontNormal")
  570. end
  571.  
  572. -- Change header text for new entry
  573. self.checklistFrame.lists[listId].headerText:SetText(self.db.profile.lists[listId].name)
  574. self.checklistFrame.lists[listId].headerText:SetPoint("TOPLEFT", self.checklistFrame, "TOPLEFT", 30, -offset - 1)
  575. self.checklistFrame.lists[listId].headerText:Show()
  576. end
  577.  
  578. -- Updates a list header in the Checklist Frame
  579. function DailyChecklist:UpdateListOnChecklistFrame(listId)
  580. -- Check if list is already represented on checklist frame, if not, create it
  581. if not self.checklistFrame.lists[listId] then
  582. self.checklistFrame.lists[listId] = {}
  583. self.checklistFrame.lists[listId].entries = {}
  584. end
  585.  
  586. -- Check if UI elements have been created on checklist frame, if not, create them
  587. if not self.checklistFrame.lists[listId].checkbox then
  588. self:CreateListOnChecklistFrame(listId, 0)
  589. end
  590.  
  591. self.checklistFrame.lists[listId].checkbox:Show()
  592. self.checklistFrame.lists[listId].headerText:Show()
  593. self.checklistFrame.lists[listId].expand:Show()
  594. end
  595.  
  596. -- Updates a single entry in the Checklist Frame
  597. function DailyChecklist:UpdateEntryOnChecklistFrame(listId, entryId, checked)
  598.  
  599. -- Show the requested entry if it is checked
  600. if checked and self.db.profile.lists[listId].entries[entryId].days[self.currentDay] then
  601. -- Check if list is already represented on checklist frame, if not, create it
  602. if not self.checklistFrame.lists[listId] then
  603. self.checklistFrame.lists[listId] = {}
  604. self.checklistFrame.lists[listId].entries = {}
  605. end
  606.  
  607. -- Check if entry has been created on checklist frame, if not, create it
  608. if not self.checklistFrame.lists[listId].entries[entryId] then
  609. self:CreateEntryInChecklistFrame(listId, entryId, 0)
  610. end
  611.  
  612. self.checklistFrame.lists[listId].entries[entryId].checkbox:Show()
  613. self.checklistFrame.lists[listId].entries[entryId].headerText:Show()
  614. else
  615. -- If it is unchecked, hide the entry if it exists
  616. --if not checked then
  617. if self.checklistFrame.lists[listId] and self.checklistFrame.lists[listId].entries[entryId] then
  618. self.checklistFrame.lists[listId].entries[entryId].checkbox:Hide()
  619. self.checklistFrame.lists[listId].entries[entryId].headerText:Hide()
  620. end
  621. --todo: hide list if all are hidden
  622. --[[elseif self.db.profile.lists[listId].entries[entryId].days[self.currentDay] then
  623. if self.checklistFrame.lists[listId] and self.checklistFrame.lists[listId].entries[entryId] then
  624. self.checklistFrame.lists[listId].entries[entryId].checkbox:Hide()
  625. self.checklistFrame.lists[listId].entries[entryId].headerText:Hide()
  626. end]]
  627. --end
  628. end
  629. end
  630.  
  631. -- Moves all entries to their correct position in the checklist frame
  632. function DailyChecklist:UpdateEntryPositionsOnChecklistFrame()
  633.  
  634. -- Calculate offset
  635. local offset = 18
  636.  
  637. local horizontalOffset = 7
  638.  
  639. if self.db.profile.showListHeaders then
  640. horizontalOffset = horizontalOffset + 12
  641. end
  642.  
  643. -- Move all remaining entries to the new correct position
  644. for listId, list in pairs(self.checklistFrame.lists) do
  645. if self.db.profile.showListHeaders then
  646. if not self.db.profile.lists[listId].completed or not self.db.profile.hideCompleted then
  647. if not list.expand then
  648. self:CreateListOnChecklistFrame(listId, offset)
  649. else
  650. list.checkbox:SetPoint("TOPLEFT", self.checklistFrame, "TOPLEFT", 12, -offset + 1)
  651. list.checkbox.listId = listId
  652. list.expand:SetPoint("TOPLEFT", self.checklistFrame, "TOPLEFT", 1, -offset - 1)
  653. list.expand.listId = listId
  654. list.headerText:SetPoint("TOPLEFT", self.checklistFrame, "TOPLEFT", 30, -offset - 1)
  655. end
  656. offset = offset + 18
  657. else
  658. if list.expand then
  659. list.expand:Hide()
  660. list.checkbox:Hide()
  661. list.headerText:Hide()
  662. end
  663. end
  664. end
  665. if not self.db.profile.showListHeaders or self.db.profile.lists[listId].expanded then
  666. for entryId, entry in pairs(list.entries) do
  667. if entry and (self.db.profile.lists[listId].entries[entryId].checked and self.db.profile.lists[listId].expanded) and (not self.db.profile.lists[listId].entries[entryId].completed or not self.db.profile.hideCompleted) then
  668. entry.checkbox:SetPoint("TOPLEFT", self.checklistFrame, "TOPLEFT", horizontalOffset, -offset + 1)
  669. entry.checkbox.listId = listId
  670. entry.checkbox.entryId = entryId
  671. entry.checkbox:Show()
  672. entry.headerText:SetPoint("TOPLEFT", self.checklistFrame, "TOPLEFT", horizontalOffset + 16, -offset)
  673. entry.headerText:Show()
  674. offset = offset + 16
  675. else
  676. if entry.checkbox then
  677. entry.checkbox:Hide()
  678. entry.headerText:Hide()
  679. end
  680. end
  681. end
  682. else
  683. for entryId, entry in pairs(list.entries) do
  684. if entry then
  685. entry.checkbox:Hide()
  686. entry.headerText:Hide()
  687. end
  688. end
  689. end
  690. end
  691.  
  692. if offset == 18 then
  693. self.checklistFrame:Hide()
  694. WatchFrame:Show()
  695. end
  696. end
  697.  
  698. -- Updates all checkboxes on the checklist frame
  699. function DailyChecklist:UpdateEntryCompletedOnChecklistFrame()
  700. local allCompleted = true
  701. for listId, list in pairs(self.checklistFrame.lists) do
  702. for entryId, entry in pairs(list.entries) do
  703. if self.db.profile.lists[listId].entries[entryId].completed then
  704. entry.checkbox:SetChecked(true)
  705. else
  706. allCompleted = false
  707. end
  708. end
  709. if self.db.profile.lists[listId].completed ~= allCompleted then
  710. self.db.profile.lists[listId].completed = allCompleted
  711. end
  712. if list.checkbox then
  713. list.checkbox:SetChecked(allCompleted)
  714. end
  715. end
  716.  
  717. if allCompleted then
  718. self.checklistFrame:Hide()
  719. WatchFrame:Show()
  720. else
  721. WatchFrame:Hide()
  722. end
  723. end
  724.  
  725. -- Removes only the list header from the Checklist Frame
  726. function DailyChecklist:RemoveListHeaderFromChecklistFrame(listId)
  727. -- Check if list exists
  728. if not self.checklistFrame.lists[listId] then
  729. return
  730. end
  731.  
  732. -- Check if UI objects exist, if they do, recycle them
  733. if self.checklistFrame.lists[listId].checkbox then
  734. self.checklistFrame.lists[listId].checkbox:Hide()
  735. self.checklistFrame.lists[listId].headerText:Hide()
  736. self.checklistFrame.lists[listId].expand:Hide()
  737.  
  738. -- Store interface elements in respective pools for potential reuse
  739. table.insert(self.checklistFrameHeaderCheckboxPool, self.checklistFrame.lists[listId].checkbox)
  740. table.insert(self.checklistFrameHeaderTextPool, self.checklistFrame.lists[listId].headerText)
  741. table.insert(self.checklistFrameHeaderExpandPool, self.checklistFrame.lists[listId].expand)
  742.  
  743. -- Nil out entries so they no longer exist in the frame
  744. self.checklistFrame.lists[listId].checkbox = nil
  745. self.checklistFrame.lists[listId].headerText = nil
  746. self.checklistFrame.lists[listId].expand = nil
  747. end
  748. end
  749.  
  750. -- Removes a whole list from the Checklist Frame
  751. function DailyChecklist:RemoveListFromChecklistFrame(listId)
  752.  
  753. -- Check if list has been created on checklist frame, if not, do nothing
  754. if not self.checklistFrame.lists[listId] then
  755. return
  756. end
  757.  
  758. -- Remove all list entries from checklist frame
  759. local entryId = table.getn(self.checklistFrame.lists[listId].entries)
  760. while entryId > 0 do
  761. self:RemoveEntryFromChecklistFrame(listId, entryId)
  762. entryId = entryId - 1
  763. end
  764.  
  765. -- Remove the header UI elements if they exist
  766. self:RemoveListHeaderFromChecklistFrame(listId)
  767.  
  768. -- Remove list from table
  769. table.remove(self.checklistFrame.lists, listId)
  770. end
  771.  
  772. -- Removes a single entry from the Checklist Frame
  773. function DailyChecklist:RemoveEntryFromChecklistFrame(listId, entryId)
  774. -- Check if entry has been created on checklist frame, if not, do nothing
  775. if not self.checklistFrame.lists[listId] or not self.checklistFrame.lists[listId].entries[entryId] then
  776. return
  777. end
  778.  
  779. -- Hide interface elements for entry
  780. --DEBUG self:Print("Hiding and removing quest: "..entryId)
  781. self.checklistFrame.lists[listId].entries[entryId].checkbox:Hide()
  782. self.checklistFrame.lists[listId].entries[entryId].headerText:Hide()
  783.  
  784. -- Store interface elements in respective pools for potential reuse
  785. table.insert(self.checklistFrameCheckboxPool, self.checklistFrame.lists[listId].entries[entryId].checkbox)
  786. table.insert(self.checklistFrameTextPool, self.checklistFrame.lists[listId].entries[entryId].headerText)
  787.  
  788. -- Nil out entries so they no longer exist in the frame
  789. self.checklistFrame.lists[listId].entries[entryId].checkbox = nil
  790. self.checklistFrame.lists[listId].entries[entryId].headerText = nil
  791.  
  792. table.remove(self.checklistFrame.lists[listId].entries, entryId)
  793.  
  794. if table.getn(self.checklistFrame.lists[listId].entries) <= 0 and not self.db.profile.showListHeaders then
  795. self:RemoveListHeaderFromChecklistFrame(listId)
  796. -- Remove list from table
  797. table.remove(self.checklistFrame.lists, listId)
  798. end
  799. --DEBUG self:Print("Frame table size: "..table.getn(self.checklistFrame.quests))
  800. end
  801.  
  802. -- Create the options frame under the WoW interface->addons menu
  803. function DailyChecklist:CreateManagerFrame()
  804. -- Create addon options frame
  805. self.checklistManagerFrame = CreateFrame("Frame", "ChecklistManagerFrame", InterfaceOptionsFramePanelContainer)
  806. self.checklistManagerFrame.name = "DailyChecklist"
  807. self.checklistManagerFrame:SetAllPoints(InterfaceOptionsFramePanelContainer)
  808. self.checklistManagerFrame:Hide()
  809. InterfaceOptions_AddCategory(self.checklistManagerFrame)
  810.  
  811. -- Create addon profiles options frame
  812. self.checklistProfilesOptions = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
  813. LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("DailyChecklist: "..self.checklistProfilesOptions.name, self.checklistProfilesOptions)
  814. self.checklistProfilesFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("DailyChecklist: "..self.checklistProfilesOptions.name, self.checklistProfilesOptions.name, "DailyChecklist")
  815.  
  816. local function getOpt(info)
  817. return DailyChecklist.db.profile[info[#info]]
  818. end
  819.  
  820. local function setOpt(info, value)
  821. DailyChecklist.db.profile[info[#info]] = value
  822. return DailyChecklist.db.profile[info[#info]]
  823. end
  824.  
  825. -- Create options frame
  826. LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("DailyChecklist: Options", {
  827. type = "group",
  828. name = "Options",
  829. args = {
  830. general = {
  831. type = "group",
  832. inline = true,
  833. name = "",
  834. args = {
  835. all = {
  836. type = "group",
  837. inline = true,
  838. name = "Resets",
  839. order = 10,
  840. args = {
  841. weeklyResetDayLabel = {
  842. type = "description",
  843. name = "Weekly reset day:",
  844. order = 10
  845. },
  846. weeklyResetDay = {
  847. type = "select",
  848. name = "",
  849. values = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
  850. order = 20,
  851. style = "dropdown",
  852. get = getOpt,
  853. set = function(info, value)
  854. DailyChecklist.db.profile.weeklyResetDay = value
  855. DailyChecklist:UpdateForNewDateAndTime()
  856. end,
  857. },
  858. dailyResetTimeLabel = {
  859. type = "description",
  860. name = "Daily reset time (in local time):",
  861. order = 30
  862. },
  863. dailyResetTime = {
  864. type = "select",
  865. name = "",
  866. values = {"00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00",
  867. "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00"},
  868. order = 40,
  869. width = "half",
  870. get = getOpt,
  871. set = function(info, value)
  872. DailyChecklist.db.profile.dailyResetTime = value
  873. DailyChecklist:UpdateForNewDateAndTime()
  874. end,
  875. },
  876. resetPollIntervalLabel = {
  877. type = "description",
  878. name = "Interval for checking if entries should be reset due to new time or day",
  879. order = 50,
  880. },
  881. resetPollInterval = {
  882. type = "select",
  883. name = "",
  884. values = {"Never", "10 Minutes", "20 Minutes", "30 Minutes", "1 Hour"},
  885. order = 60,
  886. get = getOpt,
  887. set = function(info, value)
  888. DailyChecklist.db.profile.resetPollInterval = value
  889. DailyChecklist:ResetTimer()
  890. end,
  891. },
  892. checkTimeLabel = {
  893. type = "description",
  894. order = 70,
  895. name = "Use this to manually check if entries should be reset"
  896. },
  897. checkTime = {
  898. type = "execute",
  899. order = 80,
  900. name = "Check Time",
  901. func = function()
  902. DailyChecklist:UpdateForNewDateAndTime()
  903. end,
  904. }
  905. },
  906. },
  907. frames = {
  908. type = "group",
  909. inline = true,
  910. name = "Checklist Frame Options",
  911. order = 20,
  912. args = {
  913. locked = {
  914. type = "toggle",
  915. name = "Lock Frame",
  916. order = 10,
  917. get = getOpt,
  918. set = setOpt,
  919. },
  920. hidden = {
  921. type = "toggle",
  922. name = "Hide Frame",
  923. order = 20,
  924. get = function(info) return DailyChecklist.db.profile.framePosition.hidden end,
  925. set = function(info, value)
  926. DailyChecklist.db.profile.framePosition.hidden = value
  927. if value then
  928. DailyChecklist.checklistFrame:Hide()
  929. WatchFrame:Show()
  930. else
  931. DailyChecklist.checklistFrame:Show()
  932. WatchFrame:Hide()
  933. end
  934. end,
  935. },
  936. showListHeaders = {
  937. type = "toggle",
  938. name = "Show list headers",
  939. order = 30,
  940. get = getOpt,
  941. set = function(info, value)
  942. DailyChecklist.db.profile.showListHeaders = value
  943. if value then
  944. for listId, _ in pairs(DailyChecklist.db.profile.lists) do
  945. DailyChecklist:UpdateListOnChecklistFrame(listId)
  946. end
  947. else
  948. for listId, _ in pairs(DailyChecklist.db.profile.lists) do
  949. DailyChecklist:RemoveListHeaderFromChecklistFrame(listId)
  950. end
  951. end
  952. -- Update positions because of visibility change
  953. DailyChecklist:UpdateEntryPositionsOnChecklistFrame()
  954. end,
  955. },
  956. hideCompleted = {
  957. type = "toggle",
  958. name = "Hide Completed",
  959. order = 40,
  960. get = getOpt,
  961. set = function(info, value)
  962. DailyChecklist.db.profile.hideCompleted = value
  963. DailyChecklist:UpdateVisibilityOnChecklistFrame(value)
  964. DailyChecklist:UpdateEntryPositionsOnChecklistFrame()
  965. end,
  966. },
  967. },
  968. },
  969. minimap = {
  970. type = "group",
  971. inline = true,
  972. name = "Minimap Icon",
  973. order = 30,
  974. args = {
  975. iconLabel = {
  976. type = "description",
  977. name = "Requires UI restart to take effect",
  978. order = 10
  979. },
  980. icon = {
  981. type = "toggle",
  982. name = "Hide Minimap Icon",
  983. order = 20,
  984. get = function(info) return DailyChecklist.db.profile.icon.hide end,
  985. set = function(info, value)
  986. DailyChecklist.db.profile.icon.hide = value
  987. end,
  988. }
  989. },
  990. },
  991. utilities = {
  992. type = "group",
  993. inline = true,
  994. name = "Utilities",
  995. order = 40,
  996. args = {
  997. resetLabel = {
  998. type = "description",
  999. name = "Requires UI restart to take effect",
  1000. order = 10
  1001. },
  1002. resetPosition = {
  1003. type = "execute",
  1004. order = 20,
  1005. name = "Reset Position",
  1006. func = function()
  1007. DailyChecklist.db.profile.framePosition = DailyChecklist.defaults.profile.framePosition
  1008. DailyChecklist.checklistFrame:SetPoint(DailyChecklist.db.profile.framePosition.anchor, nil, DailyChecklist.db.profile.framePosition.anchor, DailyChecklist.db.profile.framePosition.x, DailyChecklist.db.profile.framePosition.y-16)
  1009. end,
  1010. },
  1011. memoryLabel = {
  1012. type = "description",
  1013. name = "Use this when you have significantly changed the daily checklist to free up memory",
  1014. order = 30,
  1015. },
  1016. memory = {
  1017. type = "execute",
  1018. order = 40,
  1019. name = "Clear Trash",
  1020. func = function() collectgarbage("collect") end,
  1021. }
  1022. }
  1023. }
  1024. },
  1025. },
  1026. },
  1027. })
  1028. self.checklistOptionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("DailyChecklist: Options", "Options", "DailyChecklist")
  1029.  
  1030. local checklistManagerListLabel = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
  1031. checklistManagerListLabel:SetPoint("TOPLEFT", 10, -10)
  1032. checklistManagerListLabel:SetPoint("TOPRIGHT", 0, -10)
  1033. checklistManagerListLabel:SetJustifyH("LEFT")
  1034. checklistManagerListLabel:SetHeight(18)
  1035. checklistManagerListLabel:SetText("New List")
  1036.  
  1037. local checklistManagerListTextFieldLabel = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  1038. checklistManagerListTextFieldLabel:SetPoint("TOPLEFT", 10, -30)
  1039. checklistManagerListTextFieldLabel:SetPoint("TOPRIGHT", 0, -30)
  1040. checklistManagerListTextFieldLabel:SetJustifyH("LEFT")
  1041. checklistManagerListTextFieldLabel:SetHeight(18)
  1042. checklistManagerListTextFieldLabel:SetText("Create a new checklist by typing the list name in the editbox")
  1043.  
  1044. -- Add entry creation form to options frame
  1045. self.checklistManagerListTextField = CreateFrame("EditBox", "ChecklistManagerListTextField", self.checklistManagerFrame, "InputBoxTemplate")
  1046. self.checklistManagerListTextField:SetSize(450, 28)
  1047. self.checklistManagerListTextField:SetPoint("TOPLEFT", 20, -44)
  1048. self.checklistManagerListTextField:SetMaxLetters(255)
  1049. self.checklistManagerListTextField:SetMultiLine(false)
  1050. self.checklistManagerListTextField:SetAutoFocus(false)
  1051. self.checklistManagerListTextField:SetScript("OnEnterPressed", function(self)
  1052. DailyChecklist:CreateChecklistList()
  1053. end)
  1054.  
  1055. self.checklistManagerListTextFieldButton = CreateFrame("Button", nil, self.checklistManagerFrame, "UIPanelButtonTemplate")
  1056. self.checklistManagerListTextFieldButton:SetSize(100, 24)
  1057. self.checklistManagerListTextFieldButton:SetPoint("TOPLEFT", 500, -46)
  1058. self.checklistManagerListTextFieldButton:SetText("Create")
  1059. self.checklistManagerListTextFieldButton:SetScript("OnClick", function(frame)
  1060. DailyChecklist:CreateChecklistList()
  1061. end)
  1062.  
  1063. local checklistManagerEntryLabel = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
  1064. checklistManagerEntryLabel:SetPoint("TOPLEFT", 10, -76)
  1065. checklistManagerEntryLabel:SetPoint("TOPRIGHT", 0, -76)
  1066. checklistManagerEntryLabel:SetJustifyH("LEFT")
  1067. checklistManagerEntryLabel:SetHeight(18)
  1068. checklistManagerEntryLabel:SetText("New Entry")
  1069.  
  1070. local checklistManagerTextFieldLabel = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  1071. checklistManagerTextFieldLabel:SetPoint("TOPLEFT", 10, -95)
  1072. checklistManagerTextFieldLabel:SetPoint("TOPRIGHT", 0, -95)
  1073. checklistManagerTextFieldLabel:SetJustifyH("LEFT")
  1074. checklistManagerTextFieldLabel:SetHeight(18)
  1075. checklistManagerTextFieldLabel:SetText("Create a new checklist entry and add it to the currently selected list")
  1076.  
  1077. -- Add entry creation form to options frame
  1078. self.checklistManagerTextField = CreateFrame("EditBox", "ChecklistManagerTextField", self.checklistManagerFrame, "InputBoxTemplate")
  1079. self.checklistManagerTextField:SetSize(355, 28)
  1080. self.checklistManagerTextField:SetPoint("TOPLEFT", 20, -109)
  1081. self.checklistManagerTextField:SetMaxLetters(255)
  1082. self.checklistManagerTextField:SetMultiLine(false)
  1083. self.checklistManagerTextField:SetAutoFocus(false)
  1084. self.checklistManagerTextField:SetScript("OnEnterPressed", function(self)
  1085. DailyChecklist:CreateChecklistEntry()
  1086. end)
  1087.  
  1088. self.checklistManagerTextFieldButton = CreateFrame("Button", nil, self.checklistManagerFrame, "UIPanelButtonTemplate")
  1089. self.checklistManagerTextFieldButton:SetSize(100, 24)
  1090. self.checklistManagerTextFieldButton:SetPoint("TOPLEFT", 500, -175)
  1091. self.checklistManagerTextFieldButton:SetText("Create")
  1092. self.checklistManagerTextFieldButton:SetScript("OnClick", function(frame)
  1093. DailyChecklist:CreateChecklistEntry()
  1094. end)
  1095.  
  1096. local checklistManagerWeeklyLabel = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  1097. checklistManagerWeeklyLabel:SetPoint("TOPLEFT", 425, -95)
  1098. checklistManagerWeeklyLabel:SetPoint("TOPRIGHT", 0, -95)
  1099. checklistManagerWeeklyLabel:SetJustifyH("LEFT")
  1100. checklistManagerWeeklyLabel:SetHeight(18)
  1101. checklistManagerWeeklyLabel:SetText("Reset interval, defaults to daily")
  1102.  
  1103. self.checklistManagerWeeklyCheckbox = CreateFrame("CheckButton", nil, self.checklistManagerFrame, "UICheckButtonTemplate")
  1104. self.checklistManagerWeeklyCheckbox:SetPoint("TOPLEFT", 425, -110)
  1105. self.checklistManagerWeeklyCheckbox:SetWidth(25)
  1106. self.checklistManagerWeeklyCheckbox:SetHeight(25)
  1107. self.checklistManagerWeeklyCheckbox:SetScript("OnClick", function(frame)
  1108. DailyChecklist.checklistManagerManualCheckbox:SetChecked(false)
  1109. end)
  1110.  
  1111. local checklistManagerWeeklyText = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "ChatFontNormal")
  1112. checklistManagerWeeklyText:SetPoint("TOPLEFT", 450, -115)
  1113. checklistManagerWeeklyText:SetHeight(18)
  1114. checklistManagerWeeklyText:SetText("Weekly")
  1115.  
  1116. self.checklistManagerManualCheckbox = CreateFrame("CheckButton", nil, self.checklistManagerFrame, "UICheckButtonTemplate")
  1117. self.checklistManagerManualCheckbox:SetPoint("TOPLEFT", 525, -110)
  1118. self.checklistManagerManualCheckbox:SetWidth(25)
  1119. self.checklistManagerManualCheckbox:SetHeight(25)
  1120. self.checklistManagerManualCheckbox:SetScript("OnClick", function(frame)
  1121. DailyChecklist.checklistManagerWeeklyCheckbox:SetChecked(false)
  1122. end)
  1123.  
  1124. local checklistManagerManualText = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "ChatFontNormal")
  1125. checklistManagerManualText:SetPoint("TOPLEFT", 550, -115)
  1126. checklistManagerManualText:SetHeight(18)
  1127. checklistManagerManualText:SetText("Manual")
  1128.  
  1129. local checklistManagerCheckboxesLabel = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  1130. checklistManagerCheckboxesLabel:SetPoint("TOPLEFT", 10, -140)
  1131. checklistManagerCheckboxesLabel:SetPoint("TOPRIGHT", 0, -140)
  1132. checklistManagerCheckboxesLabel:SetJustifyH("LEFT")
  1133. checklistManagerCheckboxesLabel:SetHeight(18)
  1134. checklistManagerCheckboxesLabel:SetText("Choose which days you would like the new entry to appear, defaults to all")
  1135.  
  1136. -- Make checkboxes for entry reset properties
  1137. self.checklistManagerSundayCheckbox = CreateFrame("CheckButton", nil, self.checklistManagerFrame, "UICheckButtonTemplate")
  1138. self.checklistManagerSundayCheckbox:SetPoint("TOPLEFT", 10, -155)
  1139. self.checklistManagerSundayCheckbox:SetWidth(25)
  1140. self.checklistManagerSundayCheckbox:SetHeight(25)
  1141.  
  1142. local checklistManagerSundayText = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "ChatFontNormal")
  1143. checklistManagerSundayText:SetPoint("TOPLEFT", 35, -160)
  1144. checklistManagerSundayText:SetHeight(18)
  1145. checklistManagerSundayText:SetText("Sunday")
  1146.  
  1147. self.checklistManagerMondayCheckbox = CreateFrame("CheckButton", nil, self.checklistManagerFrame, "UICheckButtonTemplate")
  1148. self.checklistManagerMondayCheckbox:SetPoint("TOPLEFT", 125, -155)
  1149. self.checklistManagerMondayCheckbox:SetWidth(25)
  1150. self.checklistManagerMondayCheckbox:SetHeight(25)
  1151.  
  1152. local checklistManagerMondayText = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "ChatFontNormal")
  1153. checklistManagerMondayText:SetPoint("TOPLEFT", 150, -160)
  1154. checklistManagerMondayText:SetHeight(18)
  1155. checklistManagerMondayText:SetText("Monday")
  1156.  
  1157. self.checklistManagerTuesdayCheckbox = CreateFrame("CheckButton", nil, self.checklistManagerFrame, "UICheckButtonTemplate")
  1158. self.checklistManagerTuesdayCheckbox:SetPoint("TOPLEFT", 250, -155)
  1159. self.checklistManagerTuesdayCheckbox:SetWidth(25)
  1160. self.checklistManagerTuesdayCheckbox:SetHeight(25)
  1161.  
  1162. local checklistManagerTuesdayText = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "ChatFontNormal")
  1163. checklistManagerTuesdayText:SetPoint("TOPLEFT", 275, -160)
  1164. checklistManagerTuesdayText:SetHeight(18)
  1165. checklistManagerTuesdayText:SetText("Tuesday")
  1166.  
  1167. self.checklistManagerWednesdayCheckbox = CreateFrame("CheckButton", nil, self.checklistManagerFrame, "UICheckButtonTemplate")
  1168. self.checklistManagerWednesdayCheckbox:SetPoint("TOPLEFT", 375, -155)
  1169. self.checklistManagerWednesdayCheckbox:SetWidth(25)
  1170. self.checklistManagerWednesdayCheckbox:SetHeight(25)
  1171.  
  1172. local checklistManagerWednesdayText = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "ChatFontNormal")
  1173. checklistManagerWednesdayText:SetPoint("TOPLEFT", 400, -160)
  1174. checklistManagerWednesdayText:SetHeight(18)
  1175. checklistManagerWednesdayText:SetText("Wednesday")
  1176.  
  1177. self.checklistManagerThursdayCheckbox = CreateFrame("CheckButton", nil, self.checklistManagerFrame, "UICheckButtonTemplate")
  1178. self.checklistManagerThursdayCheckbox:SetPoint("TOPLEFT", 10, -175)
  1179. self.checklistManagerThursdayCheckbox:SetWidth(25)
  1180. self.checklistManagerThursdayCheckbox:SetHeight(25)
  1181.  
  1182. local checklistManagerThursdayText = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "ChatFontNormal")
  1183. checklistManagerThursdayText:SetPoint("TOPLEFT", 35, -180)
  1184. checklistManagerThursdayText:SetHeight(18)
  1185. checklistManagerThursdayText:SetText("Thursday")
  1186.  
  1187. self.checklistManagerFridayCheckbox = CreateFrame("CheckButton", nil, self.checklistManagerFrame, "UICheckButtonTemplate")
  1188. self.checklistManagerFridayCheckbox:SetPoint("TOPLEFT", 125, -175)
  1189. self.checklistManagerFridayCheckbox:SetWidth(25)
  1190. self.checklistManagerFridayCheckbox:SetHeight(25)
  1191.  
  1192. local checklistManagerFridayText = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "ChatFontNormal")
  1193. checklistManagerFridayText:SetPoint("TOPLEFT", 150, -180)
  1194. checklistManagerFridayText:SetHeight(18)
  1195. checklistManagerFridayText:SetText("Friday")
  1196.  
  1197. self.checklistManagerSaturdayCheckbox = CreateFrame("CheckButton", nil, self.checklistManagerFrame, "UICheckButtonTemplate")
  1198. self.checklistManagerSaturdayCheckbox:SetPoint("TOPLEFT", 250, -175)
  1199. self.checklistManagerSaturdayCheckbox:SetWidth(25)
  1200. self.checklistManagerSaturdayCheckbox:SetHeight(25)
  1201.  
  1202. local checklistManagerSaturdayText = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "ChatFontNormal")
  1203. checklistManagerSaturdayText:SetPoint("TOPLEFT", 275, -180)
  1204. checklistManagerSaturdayText:SetHeight(18)
  1205. checklistManagerSaturdayText:SetText("Saturday")
  1206.  
  1207. -- Add checklist title
  1208. local checklistManagerTitle = self.checklistManagerFrame:CreateFontString("ManagerTitleText", nil, "GameFontNormalLarge")
  1209. checklistManagerTitle:SetText("|cffFFB90FDaily Checklist Manager -|r")
  1210. checklistManagerTitle:SetPoint("TOPLEFT", self.checklistManagerFrame, "TOPLEFT", 10, -215)
  1211. checklistManagerTitle:Show()
  1212.  
  1213. -- Add checklist list dropdown
  1214. self.checklistManagerListDropDown = CreateFrame("Button", "ChecklistManagerListDropDown", self.checklistManagerFrame, "UIDropDownMenuTemplate")
  1215. self.checklistManagerListDropDown:SetPoint("TOPLEFT", self.checklistManagerFrame, "TOPLEFT", 220, -210)
  1216. self.checklistManagerListDropDown:Show()
  1217.  
  1218. -- Initialize drop down
  1219. UIDropDownMenu_Initialize(self.checklistManagerListDropDown,
  1220. function(self, level)
  1221. -- Gather list of names
  1222. local listNames = {}
  1223.  
  1224. for _, list in pairs(DailyChecklist.db.profile.lists) do
  1225. table.insert(listNames, list.name)
  1226. end
  1227.  
  1228. local info = UIDropDownMenu_CreateInfo()
  1229. for k,v in pairs(listNames) do
  1230. info = UIDropDownMenu_CreateInfo()
  1231. info.text = v
  1232. info.value = v
  1233. info.func = function(self)
  1234. DailyChecklist.selectedManagerFrameList = self:GetID()
  1235. UIDropDownMenu_SetSelectedID(DailyChecklist.checklistManagerListDropDown, self:GetID())
  1236. DailyChecklist:UpdateEntriesForScrollFrame()
  1237. end
  1238. UIDropDownMenu_AddButton(info, level)
  1239. end
  1240. end
  1241. )
  1242. UIDropDownMenu_SetWidth(self.checklistManagerListDropDown, 200);
  1243. UIDropDownMenu_SetButtonWidth(self.checklistManagerListDropDown, 224)
  1244. UIDropDownMenu_SetSelectedID(self.checklistManagerListDropDown, 1)
  1245. UIDropDownMenu_JustifyText(self.checklistManagerListDropDown, "LEFT")
  1246.  
  1247. -- Set initial selected list
  1248. if table.getn(self.db.profile.lists) > 0 then
  1249. self.selectedManagerFrameList = self.selectedManagerFrameList or 1
  1250. end
  1251.  
  1252. local checklistManagerTitleLabel = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  1253. checklistManagerTitleLabel:SetPoint("TOPLEFT", 40, -235)
  1254. checklistManagerTitleLabel:SetPoint("TOPRIGHT", 0, -235)
  1255. checklistManagerTitleLabel:SetJustifyH("LEFT")
  1256. checklistManagerTitleLabel:SetHeight(18)
  1257. checklistManagerTitleLabel:SetText("Check the entries that you would like to appear in your UI checklist")
  1258.  
  1259. -- Create scrollable frame
  1260. self.checklistManagerFrameScroll = CreateFrame("ScrollFrame", "checklistManagerFrameScroll", self.checklistManagerFrame, "FauxScrollFrameTemplate")
  1261. local sizeX, sizeY = self.checklistManagerFrame:GetSize()
  1262. self.checklistManagerFrameScroll:SetSize(sizeX, sizeY - self.managerPanelHeight )
  1263. self.checklistManagerFrameScroll:SetPoint("CENTER", -30, -95)
  1264. self.checklistManagerFrameScroll:SetScript("OnVerticalScroll", function(self, offset) FauxScrollFrame_OnVerticalScroll(self, offset, 20, function()
  1265. DailyChecklist:UpdateEntriesForScrollFrame()
  1266. end)
  1267. end)
  1268. self.checklistManagerFrameScroll:SetScript("OnShow", function()
  1269. DailyChecklist:UpdateEntriesForScrollFrame()
  1270. end)
  1271.  
  1272. -- Create empty tables
  1273. self.checklistManagerFrameCheckboxes = {}
  1274. self.checklistManagerFrameText = {}
  1275. self.checklistManagerFrameClickable = {}
  1276.  
  1277. -- Set up vertical offset for checkbox list
  1278. local offset = self.managerPanelHeight - 50
  1279.  
  1280. -- Create a set amount of checkboxes and labels for reuse on the scrollable frame
  1281. for i=1,self.maxEntries do
  1282. self.checklistManagerFrameCheckboxes[i] = CreateFrame("CheckButton", nil, self.checklistManagerFrame, "UICheckButtonTemplate")
  1283. self.checklistManagerFrameCheckboxes[i]:SetPoint("TOPLEFT", 40, -offset)
  1284. self.checklistManagerFrameCheckboxes[i]:SetWidth(25)
  1285. self.checklistManagerFrameCheckboxes[i]:SetHeight(25)
  1286. self.checklistManagerFrameCheckboxes[i]:SetChecked(false)
  1287. self.checklistManagerFrameCheckboxes[i]:SetScript("OnClick", function(self)
  1288. DailyChecklist:ToggleSingleChecklistManagerCheckbox(self)
  1289. end)
  1290. self.checklistManagerFrameCheckboxes[i]:Hide()
  1291.  
  1292. self.checklistManagerFrameClickable[i] = CreateFrame("Frame", "ClickableFrame"..i, self.checklistManagerFrame)
  1293. self.checklistManagerFrameClickable[i]:SetPoint("TOPLEFT", 70, -offset)
  1294. self.checklistManagerFrameClickable[i]:SetWidth(255)
  1295. self.checklistManagerFrameClickable[i]:SetHeight(25)
  1296. self.checklistManagerFrameClickable[i]:SetScript("OnEnter", function(self)
  1297. self.inside = true
  1298. end)
  1299. self.checklistManagerFrameClickable[i]:SetScript("OnLeave", function(self)
  1300. self.inside = false
  1301. end)
  1302. self.checklistManagerFrameClickable[i]:SetScript("OnMouseUp", function(self)
  1303. if self.inside then
  1304. if DailyChecklist.checklistManagerFrameText[i]:IsShown() then
  1305. DailyChecklist.checklistManagerFrameText[i]:SetText(DailyChecklist.selectedEntryColor..DailyChecklist.checklistManagerFrameText[i]:GetText())
  1306. DailyChecklist:ResetSelectedManagerFrameText()
  1307. DailyChecklist.selectedManagerFrameText = i
  1308. end
  1309. end
  1310. end)
  1311.  
  1312. self.checklistManagerFrameText[i] = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "ChatFontNormal")
  1313. self.checklistManagerFrameText[i]:SetPoint("TOPLEFT", 70, -offset - 5)
  1314. self.checklistManagerFrameText[i]:SetText("")
  1315. self.checklistManagerFrameText[i]:Hide()
  1316.  
  1317. offset = offset + 20
  1318. end
  1319.  
  1320. local checklistManagerDeleteLabel = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  1321. checklistManagerDeleteLabel:SetPoint("BOTTOMLEFT", 40, 35)
  1322. checklistManagerDeleteLabel:SetPoint("BOTTOMRIGHT", 0, 35)
  1323. checklistManagerDeleteLabel:SetJustifyH("LEFT")
  1324. checklistManagerDeleteLabel:SetHeight(18)
  1325. checklistManagerDeleteLabel:SetText("Select an entry from the list by clicking the white text and use the corresponding button to delete or move it")
  1326.  
  1327. -- Lock checkbox
  1328. self.checklistManagerDeleteListButton = CreateFrame("Button", nil, self.checklistManagerFrame, "UIPanelButtonTemplate")
  1329. self.checklistManagerDeleteListButton:SetPoint("BOTTOMLEFT", 10, 10)
  1330. self.checklistManagerDeleteListButton:SetSize(100, 24)
  1331. self.checklistManagerDeleteListButton:SetText("Delete List")
  1332. self.checklistManagerDeleteListButton:SetScript("OnClick", function(self)
  1333. DailyChecklist:DeleteSelectedList()
  1334. end)
  1335.  
  1336. -- Lock frame text
  1337. self.checklistManagerLockText = self.checklistManagerFrame:CreateFontString(nil, "OVERLAY", "ChatFontNormal")
  1338. self.checklistManagerLockText:SetPoint("BOTTOMLEFT", 35, 12)
  1339. self.checklistManagerLockText:SetJustifyH("LEFT")
  1340. self.checklistManagerLockText:SetHeight(18)
  1341. self.checklistManagerLockText:SetText("Lock Frame")
  1342.  
  1343. -- Create delete button
  1344. self.checklistManagerFrameDelete = CreateFrame("Button", nil, self.checklistManagerFrame, "UIPanelButtonTemplate")
  1345. self.checklistManagerFrameDelete:SetPoint("BOTTOMRIGHT", -160, 10)
  1346. self.checklistManagerFrameDelete:SetSize(70, 24)
  1347. self.checklistManagerFrameDelete:SetText("Delete")
  1348. self.checklistManagerFrameDelete:SetScript("OnClick", function(self)
  1349. DailyChecklist:DeleteSelectedEntry()
  1350. end)
  1351.  
  1352. -- Create move up button
  1353. self.checklistManagerFrameUp = CreateFrame("Button", nil, self.checklistManagerFrame, "UIPanelButtonTemplate")
  1354. self.checklistManagerFrameUp:SetPoint("BOTTOMRIGHT", -70, 10)
  1355. self.checklistManagerFrameUp:SetSize(60, 24)
  1356. self.checklistManagerFrameUp:SetText("Up")
  1357. self.checklistManagerFrameUp:SetScript("OnClick", function(self)
  1358. DailyChecklist:MoveSelectedEntryUp()
  1359. end)
  1360.  
  1361. -- Create move down button
  1362. self.checklistManagerFrameDown = CreateFrame("Button", nil, self.checklistManagerFrame, "UIPanelButtonTemplate")
  1363. self.checklistManagerFrameDown:SetPoint("BOTTOMRIGHT", -10, 10)
  1364. self.checklistManagerFrameDown:SetSize(60, 24)
  1365. self.checklistManagerFrameDown:SetText("Down")
  1366. self.checklistManagerFrameDown:SetScript("OnClick", function(self)
  1367. DailyChecklist:MoveSelectedEntryDown()
  1368. end)
  1369. end
  1370.  
  1371. -- Removes the selected list from the manager frame and database
  1372. function DailyChecklist:DeleteSelectedList()
  1373.  
  1374. local listId = self.selectedManagerFrameList
  1375.  
  1376. -- If nothing is selected, do nothing
  1377. if not listId then
  1378. return
  1379. end
  1380.  
  1381. -- Remove all entries from checklist frame
  1382. self:RemoveListFromChecklistFrame(listId)
  1383.  
  1384. -- Remove list from database
  1385. table.remove(self.db.profile.lists, listId)
  1386.  
  1387. -- Add default list if we deleted all others
  1388. if table.getn(self.db.profile.lists) <= 0 then
  1389. self.db.profile.lists[1] = {
  1390. name = "Default",
  1391. entries = {},
  1392. }
  1393. if self.db.profile.showListHeaders then
  1394. self:UpdateListOnChecklistFrame(1)
  1395. end
  1396. end
  1397.  
  1398. -- Reload list dropdown
  1399. ToggleDropDownMenu(1, nil, self.checklistManagerListDropDown)
  1400.  
  1401. CloseDropDownMenus()
  1402.  
  1403. -- Reset dropdown selection
  1404. UIDropDownMenu_SetSelectedID(self.checklistManagerListDropDown, 1)
  1405. self.selectedManagerFrameList = 1
  1406.  
  1407. -- Reload list manager
  1408. self:UpdateEntriesForScrollFrame()
  1409.  
  1410. self:UpdateEntryPositionsOnChecklistFrame()
  1411. end
  1412.  
  1413. -- Removes the selected entry from the manager frame and database
  1414. function DailyChecklist:DeleteSelectedEntry()
  1415.  
  1416. -- If nothing is selected, do nothing
  1417. if not self.selectedManagerFrameList or not self.selectedManagerFrameText then
  1418. return
  1419. end
  1420.  
  1421. local listId = self.selectedManagerFrameList
  1422. local entryId = self.checklistManagerFrameCheckboxes[self.selectedManagerFrameText].entryId
  1423. --DEBUG self:Print("Deleted entry: "..entryId)
  1424. --local allTableSize = table.getn(self.db.profile.lists[listId].entries)
  1425. --DEBUG self:Print("All Quests Table Size: "..allTableSize)
  1426.  
  1427. self:RemoveEntryFromChecklistFrame(listId, entryId)
  1428.  
  1429. table.remove(self.db.profile.lists[listId].entries, entryId)
  1430.  
  1431. self:UpdateEntriesForScrollFrame()
  1432. self:UpdateEntryPositionsOnChecklistFrame()
  1433. end
  1434.  
  1435. -- Moves the selected entry up in the options frame and database
  1436. function DailyChecklist:MoveSelectedEntryUp()
  1437.  
  1438. -- If nothing is selected, do nothing
  1439. if not self.selectedManagerFrameList or not self.selectedManagerFrameText then
  1440. return
  1441. end
  1442.  
  1443. local listId = self.selectedManagerFrameList
  1444. local entryId = self.checklistManagerFrameCheckboxes[self.selectedManagerFrameText].entryId
  1445. --DEBUG self:Print("Moving up entry: "..entryId)
  1446. --local tableSize = table.getn(self.db.profile.lists[listId].entries)
  1447. --DEBUG self:Print("All Quests Table Size: "..tableSize)
  1448.  
  1449. -- If the selected entry is already at the top of the list, do nothing
  1450. if entryId <= 1 then
  1451. return
  1452. end
  1453.  
  1454. -- Swap the selected entry and the one directly above
  1455. local prevQuest = self.db.profile.lists[listId].entries[entryId-1]
  1456. self.db.profile.lists[listId].entries[entryId-1] = self.db.profile.lists[listId].entries[entryId]
  1457. self.db.profile.lists[listId].entries[entryId] = prevQuest
  1458.  
  1459. if self.checklistFrame.lists[listId] then
  1460. prevQuest = self.checklistFrame.lists[listId].entries[entryId-1]
  1461. self.checklistFrame.lists[listId].entries[entryId-1] = self.checklistFrame.lists[listId].entries[entryId]
  1462. self.checklistFrame.lists[listId].entries[entryId] = prevQuest
  1463. end
  1464.  
  1465. self:UpdateEntriesForScrollFrame()
  1466. self:UpdateEntryPositionsOnChecklistFrame()
  1467.  
  1468. self.checklistManagerFrameText[entryId-1]:SetText(self.selectedEntryColor..self.checklistManagerFrameText[entryId-1]:GetText())
  1469. self.selectedManagerFrameText = entryId-1
  1470. end
  1471.  
  1472. -- Moves the selected entry down in the options frame and database
  1473. function DailyChecklist:MoveSelectedEntryDown()
  1474.  
  1475. -- If nothing is selected, do nothing
  1476. if not self.selectedManagerFrameList or not self.selectedManagerFrameText then
  1477. return
  1478. end
  1479.  
  1480. local listId = self.selectedManagerFrameList
  1481. local entryId = self.checklistManagerFrameCheckboxes[self.selectedManagerFrameText].entryId
  1482. --DEBUG self:Print("Moving down entry: "..entryId)
  1483. local tableSize = table.getn(self.db.profile.lists[listId].entries)
  1484. --DEBUG self:Print("All Quests Table Size: "..tableSize)
  1485.  
  1486. -- If the selected entry is already at the bottom of the list, do nothing
  1487. if entryId >= tableSize then
  1488. return
  1489. end
  1490.  
  1491. -- Swap the selected entry and the one directly above
  1492. local nextQuest = self.db.profile.lists[listId].entries[entryId+1]
  1493. self.db.profile.lists[listId].entries[entryId+1] = self.db.profile.lists[listId].entries[entryId]
  1494. self.db.profile.lists[listId].entries[entryId] = nextQuest
  1495.  
  1496. if self.checklistFrame.lists[listId] then
  1497. nextQuest = self.checklistFrame.lists[listId].entries[entryId+1]
  1498. self.checklistFrame.lists[listId].entries[entryId+1] = self.checklistFrame.lists[listId].entries[entryId]
  1499. self.checklistFrame.lists[listId].entries[entryId] = nextQuest
  1500. end
  1501.  
  1502. self:UpdateEntriesForScrollFrame()
  1503. self:UpdateEntryPositionsOnChecklistFrame()
  1504.  
  1505. self.checklistManagerFrameText[entryId+1]:SetText(self.selectedEntryColor..self.checklistManagerFrameText[entryId+1]:GetText())
  1506. self.selectedManagerFrameText = entryId+1
  1507. end
  1508.  
  1509. -- Resets the color of the previously selected options text
  1510. function DailyChecklist:ResetSelectedManagerFrameText()
  1511. if self.selectedManagerFrameText then
  1512. local text = self.checklistManagerFrameText[self.selectedManagerFrameText]:GetText()
  1513. if string.find(text, self.selectedEntryColor) then
  1514. self.checklistManagerFrameText[self.selectedManagerFrameText]:SetText(string.sub(text, 11))
  1515. end
  1516. end
  1517. self.selectedManagerFrameText = nil
  1518. end
  1519.  
  1520. -- Create new list if it does not exist and update checklist frame
  1521. function DailyChecklist:CreateChecklistList()
  1522.  
  1523. -- Grab text from editbox
  1524. local newList = strtrim(self.checklistManagerListTextField:GetText())
  1525.  
  1526. -- Discard if text was empty
  1527. if newList == "" then
  1528. return
  1529. end
  1530.  
  1531. -- Check if list exists already
  1532. for listId, list in ipairs(self.db.profile.lists) do
  1533. if list.name == newList then
  1534. return
  1535. end
  1536. end
  1537.  
  1538. -- Add new quest to database
  1539. local tableSize = table.getn(self.db.profile.lists)+1
  1540. self.db.profile.lists[tableSize] = {}
  1541. self.db.profile.lists[tableSize].name = newList
  1542. self.db.profile.lists[tableSize].entries = {}
  1543. self.db.profile.lists[tableSize].expanded = true
  1544.  
  1545. -- Update selected list
  1546. self.selectedManagerFrameList = tableSize
  1547.  
  1548. ToggleDropDownMenu(1, nil, self.checklistManagerListDropDown)
  1549.  
  1550. CloseDropDownMenus()
  1551.  
  1552. UIDropDownMenu_SetSelectedID(self.checklistManagerListDropDown, tableSize)
  1553.  
  1554. -- Update scroll frame
  1555. self:UpdateEntriesForScrollFrame()
  1556.  
  1557. -- Update UI Checklist
  1558. if self.db.profile.showListHeaders then
  1559. self:UpdateListOnChecklistFrame(tableSize)
  1560. -- Update positions because of visibility change
  1561. self:UpdateEntryPositionsOnChecklistFrame()
  1562. end
  1563.  
  1564. -- Reset text for editbox
  1565. self.checklistManagerListTextField:SetText("")
  1566.  
  1567. end
  1568.  
  1569. -- Create new entry if it does not exist and update checklist frame
  1570. function DailyChecklist:CreateChecklistEntry()
  1571.  
  1572. if not self.selectedManagerFrameList then
  1573. return
  1574. end
  1575.  
  1576. local listId = self.selectedManagerFrameList
  1577.  
  1578. -- Grab text from editbox
  1579. local newEntry = strtrim(self.checklistManagerTextField:GetText())
  1580.  
  1581. -- Discard if text was empty
  1582. if newEntry == "" then
  1583. return
  1584. end
  1585.  
  1586. -- Keep track if we are creating a new entry or overwriting an old
  1587. local overwrite = false
  1588.  
  1589. -- Keep track of index of existing or new
  1590. local index = 0
  1591.  
  1592. -- Check if entry exists already, if so overwrite
  1593. for entryId, entry in ipairs(self.db.profile.lists[listId].entries) do
  1594. if entry.text == newEntry then
  1595. overwrite = true
  1596. index = entryId
  1597. self.db.profile.lists[listId].entries[index] = self:CreateDatabaseEntry(newEntry)
  1598. break
  1599. end
  1600. end
  1601.  
  1602. if not overwrite then
  1603. -- Add new entry to database
  1604. index = table.getn(self.db.profile.lists[listId].entries)+1
  1605. self.db.profile.lists[listId].entries[index] = self:CreateDatabaseEntry(newEntry)
  1606. end
  1607.  
  1608. self.db.profile.lists[listId].completed = false
  1609. if self.checklistFrame.lists[listId] and self.checklistFrame.lists[listId].checkbox then
  1610. self.checklistFrame.lists[listId].checkbox:SetChecked(false)
  1611. end
  1612.  
  1613. -- Update scroll frame
  1614. self:UpdateEntriesForScrollFrame()
  1615.  
  1616. -- Update UI Checklist
  1617. self:UpdateEntryOnChecklistFrame(listId, index, true)
  1618.  
  1619. -- Update positions because of visibility change
  1620. self:UpdateEntryPositionsOnChecklistFrame()
  1621.  
  1622. -- Update visibility change
  1623. self:UpdateVisibilityForListOnChecklistFrame(listId, self.db.profile.hideCompleted)
  1624.  
  1625. -- Reset text for editbox
  1626. self.checklistManagerTextField:SetText("")
  1627.  
  1628. -- Reset checkboxes
  1629. self.checklistManagerSundayCheckbox:SetChecked(false)
  1630. self.checklistManagerMondayCheckbox:SetChecked(false)
  1631. self.checklistManagerTuesdayCheckbox:SetChecked(false)
  1632. self.checklistManagerWednesdayCheckbox:SetChecked(false)
  1633. self.checklistManagerThursdayCheckbox:SetChecked(false)
  1634. self.checklistManagerFridayCheckbox:SetChecked(false)
  1635. self.checklistManagerSaturdayCheckbox:SetChecked(false)
  1636. self.checklistManagerWeeklyCheckbox:SetChecked(false)
  1637. self.checklistManagerManualCheckbox:SetChecked(false)
  1638. end
  1639.  
  1640. -- Creates a new list entry in the database using the current fields
  1641. function DailyChecklist:CreateDatabaseEntry(text)
  1642. local noneChecked = false
  1643. if not self.checklistManagerSundayCheckbox:GetChecked() and
  1644. not self.checklistManagerMondayCheckbox:GetChecked() and
  1645. not self.checklistManagerTuesdayCheckbox:GetChecked() and
  1646. not self.checklistManagerWednesdayCheckbox:GetChecked() and
  1647. not self.checklistManagerThursdayCheckbox:GetChecked() and
  1648. not self.checklistManagerFridayCheckbox:GetChecked() and
  1649. not self.checklistManagerSaturdayCheckbox:GetChecked() then
  1650. noneChecked = true
  1651. end
  1652. local entry = {
  1653. text = text,
  1654. checked = true,
  1655. completed = false,
  1656. days = {
  1657. [SUNDAY] = noneChecked or self.checklistManagerSundayCheckbox:GetChecked(),
  1658. [MONDAY] = noneChecked or self.checklistManagerMondayCheckbox:GetChecked(),
  1659. [TUESDAY] = noneChecked or self.checklistManagerTuesdayCheckbox:GetChecked(),
  1660. [WEDNESDAY] = noneChecked or self.checklistManagerWednesdayCheckbox:GetChecked(),
  1661. [THURSDAY] = noneChecked or self.checklistManagerThursdayCheckbox:GetChecked(),
  1662. [FRIDAY] = noneChecked or self.checklistManagerFridayCheckbox:GetChecked(),
  1663. [SATURDAY] = noneChecked or self.checklistManagerSaturdayCheckbox:GetChecked(),
  1664. },
  1665. weekly = self.checklistManagerWeeklyCheckbox:GetChecked(),
  1666. manual = self.checklistManagerManualCheckbox:GetChecked(),
  1667. }
  1668. return entry
  1669. end
  1670.  
  1671. -- Change database value
  1672. function DailyChecklist:ToggleSingleChecklistManagerCheckbox(currentBox)
  1673. self.db.profile.lists[currentBox.listId].entries[currentBox.entryId].checked = currentBox:GetChecked()
  1674.  
  1675. self:UpdateEntryOnChecklistFrame(currentBox.listId, currentBox.entryId, currentBox:GetChecked())
  1676.  
  1677. -- Update positions because of visibility change
  1678. self:UpdateEntryPositionsOnChecklistFrame()
  1679. end
  1680.  
  1681. -- Change database values, images, and checklist positions
  1682. function DailyChecklist:ToggleChecklistFrameListExpand(currentExpand)
  1683. local listId = currentExpand.listId
  1684. local expanded = not self.db.profile.lists[listId].expanded
  1685. self.db.profile.lists[listId].expanded = expanded
  1686.  
  1687. if expanded then
  1688. currentExpand:SetNormalTexture(contractNormalTexture)
  1689. currentExpand:SetPushedTexture(contractPushedTexture)
  1690.  
  1691. for entryId, entry in pairs(self.checklistFrame.lists[listId].entries) do
  1692. if self.db.profile.lists[listId].entries[entryId].checked then
  1693. entry.checkbox:Show()
  1694. entry.headerText:Show()
  1695. end
  1696. end
  1697. else
  1698. currentExpand:SetNormalTexture(expandNormalTexture)
  1699. currentExpand:SetPushedTexture(expandPushedTexture)
  1700.  
  1701. for entryId, entry in pairs(self.checklistFrame.lists[listId].entries) do
  1702. entry.checkbox:Hide()
  1703. entry.headerText:Hide()
  1704. end
  1705. end
  1706.  
  1707. self:UpdateEntryPositionsOnChecklistFrame()
  1708. end
  1709.  
  1710. -- Change database values
  1711. function DailyChecklist:ToggleChecklistFrameListCheckbox(currentBox)
  1712. self.db.profile.lists[currentBox.listId].completed = currentBox:GetChecked()
  1713.  
  1714. for entryId, entry in pairs(self.db.profile.lists[currentBox.listId].entries) do
  1715. self.db.profile.lists[currentBox.listId].entries[entryId].completed = currentBox:GetChecked()
  1716. if self.checklistFrame.lists[currentBox.listId].entries[entryId] then
  1717. self.checklistFrame.lists[currentBox.listId].entries[entryId].checkbox:SetChecked(currentBox:GetChecked())
  1718. end
  1719. end
  1720.  
  1721. if self.db.profile.hideCompleted then
  1722. self:UpdateVisibilityForListOnChecklistFrame(currentBox.listId, self.db.profile.hideCompleted)
  1723. end
  1724.  
  1725. self:UpdateEntryPositionsOnChecklistFrame()
  1726. end
  1727.  
  1728. -- Change database values
  1729. function DailyChecklist:ToggleSingleChecklistFrameCheckbox(currentBox)
  1730. self.db.profile.lists[currentBox.listId].entries[currentBox.entryId].completed = currentBox:GetChecked()
  1731. self:UpdateVisibilityForEntryOnChecklistFrame(currentBox.listId, currentBox.entryId, self.db.profile.hideCompleted)
  1732.  
  1733. if currentBox:GetChecked() then
  1734. local allChecked = true
  1735. for _, entry in pairs(self.db.profile.lists[currentBox.listId].entries) do
  1736. if not entry.completed and entry.checked then
  1737. allChecked = false
  1738. end
  1739. end
  1740. if allChecked then
  1741. self.db.profile.lists[currentBox.listId].completed = true
  1742. if self.checklistFrame.lists[currentBox.listId] then
  1743. self.checklistFrame.lists[currentBox.listId].checkbox:SetChecked(true)
  1744. if self.db.profile.hideCompleted then
  1745. self.checklistFrame.lists[currentBox.listId].expand:Hide()
  1746. self.checklistFrame.lists[currentBox.listId].checkbox:Hide()
  1747. self.checklistFrame.lists[currentBox.listId].headerText:Hide()
  1748. end
  1749. end
  1750. end
  1751. else
  1752. if self.checklistFrame.lists[currentBox.listId] and self.checklistFrame.lists[currentBox.listId].checkbox:GetChecked() then
  1753. self.db.profile.lists[currentBox.listId].completed = false
  1754. self.checklistFrame.lists[currentBox.listId].checkbox:SetChecked(false)
  1755. self.checklistFrame.lists[currentBox.listId].expand:Show()
  1756. self.checklistFrame.lists[currentBox.listId].checkbox:Show()
  1757. self.checklistFrame.lists[currentBox.listId].headerText:Show()
  1758. end
  1759. end
  1760.  
  1761. self:UpdateEntryPositionsOnChecklistFrame()
  1762. end
  1763.  
  1764. -- Update entries in entries scroll frame when scrollbar moves
  1765. function DailyChecklist:UpdateEntriesForScrollFrame()
  1766.  
  1767. -- Remove highlight from selected entry, if any
  1768. self:ResetSelectedManagerFrameText()
  1769.  
  1770. -- Save selected listId
  1771. local listId = self.selectedManagerFrameList
  1772.  
  1773. -- Save number of checkboxes used
  1774. local numberOfRows = 1
  1775.  
  1776. -- Save number of entries in entries
  1777. local numberOfEntries = 0
  1778.  
  1779. if listId and self.db.profile.lists and self.db.profile.lists[listId] then
  1780. numberOfEntries = table.getn(self.db.profile.lists[listId].entries)
  1781. for entryId, entry in ipairs(self.db.profile.lists[listId].entries) do
  1782. if numberOfRows <= self.maxEntries then
  1783. if entryId > self.checklistManagerFrameScroll.offset then
  1784. local checkbox = self.checklistManagerFrameCheckboxes[numberOfRows]
  1785. checkbox:SetChecked(entry.checked)
  1786. checkbox.entryId = entryId
  1787. checkbox.listId = listId
  1788. checkbox:Show()
  1789.  
  1790. local label = self.checklistManagerFrameText[numberOfRows]
  1791. label:SetText(entry.text)
  1792. label:Show()
  1793.  
  1794. numberOfRows = numberOfRows + 1
  1795. end
  1796. end
  1797. end
  1798. end
  1799.  
  1800. for i = numberOfRows, self.maxEntries do
  1801. self.checklistManagerFrameCheckboxes[i]:Hide()
  1802. self.checklistManagerFrameText[i]:Hide()
  1803. end
  1804.  
  1805. -- Execute scroll bar update
  1806. FauxScrollFrame_Update(self.checklistManagerFrameScroll, numberOfEntries, self.maxEntries, 20, nil, nil, nil, nil, nil, nil, true)
  1807. end
  1808.  
  1809. -- Called when profile changes, reloads options, list dropdown, manager, and checklist
  1810. function DailyChecklist:RefreshEverything()
  1811. -- Reload list dropdown
  1812. ToggleDropDownMenu(1, nil, self.checklistManagerListDropDown)
  1813.  
  1814. CloseDropDownMenus()
  1815.  
  1816. UIDropDownMenu_SetSelectedID(self.checklistManagerListDropDown, 1)
  1817. self.selectedManagerFrameList = 1
  1818.  
  1819. -- Reload list manager
  1820. self:UpdateEntriesForScrollFrame()
  1821.  
  1822. -- Delete existing checklist frame elements, save ui elements
  1823. self:RemoveChecklistFrameElements()
  1824.  
  1825. -- Reconstruct checklist frame
  1826. self:CreateChecklistFrameElements()
  1827.  
  1828. -- Move checklist frame
  1829. self.checklistFrame:SetPoint(self.db.profile.framePosition.anchor, nil, self.db.profile.framePosition.anchor, self.db.profile.framePosition.x, self.db.profile.framePosition.y-16)
  1830.  
  1831. end
  1832.  
  1833. -- Called when minimap icon is clicked
  1834. function DailyChecklist:HandleIconClick(button)
  1835. if button == "LeftButton" then
  1836. if self.db.profile.framePosition.hidden then
  1837. self:ShowChecklistFrame();
  1838. else
  1839. self:HideChecklistFrame();
  1840. end
  1841. elseif button == "RightButton" then
  1842. -- Open options menu in interface->addon menu
  1843. InterfaceOptionsFrame_OpenToCategory(self.checklistManagerFrame)
  1844. end
  1845. end
  1846.  
  1847. -- Called when chat command is executed to hide the checklist frame
  1848. function DailyChecklist:HideChecklistFrame()
  1849. self.db.profile.framePosition.hidden = true
  1850. self.checklistFrame:Hide()
  1851. end
  1852.  
  1853. -- Called when chat command is executed to hide the checklist frame
  1854. function DailyChecklist:ShowChecklistFrame()
  1855. self.db.profile.framePosition.hidden = false
  1856. self.checklistFrame:Show()
  1857. end
  1858.  
  1859. function DailyChecklist:UpdateVisibilityForEntryOnChecklistFrame(listId, entryId, hidden)
  1860. local entry = self.db.profile.lists[listId].entries[entryId]
  1861. if hidden then
  1862. if self.checklistFrame.lists[listId].entries[entryId] then
  1863. if entry.completed then
  1864. self.checklistFrame.lists[listId].entries[entryId].checkbox:Hide()
  1865. self.checklistFrame.lists[listId].entries[entryId].headerText:Hide()
  1866. else
  1867. self.checklistFrame.lists[listId].entries[entryId].checkbox:Show()
  1868. self.checklistFrame.lists[listId].entries[entryId].headerText:Show()
  1869. end
  1870. end
  1871. else
  1872. if not self.checklistFrame.lists[listId].entries[entryId] then
  1873. if entry.checked then
  1874. self:CreateEntryInChecklistFrame(listId, entryId, 0)
  1875. end
  1876. else
  1877. self.checklistFrame.lists[listId].entries[entryId].checkbox:Show()
  1878. self.checklistFrame.lists[listId].entries[entryId].headerText:Show()
  1879. end
  1880. end
  1881. end
  1882.  
  1883. function DailyChecklist:UpdateVisibilityForListOnChecklistFrame(listId, hidden)
  1884. local list = self.db.profile.lists[listId]
  1885. if hidden then
  1886. if self.checklistFrame.lists[listId] then
  1887. if self.checklistFrame.lists[listId].entries then
  1888. for entryId, entry in pairs(list.entries) do
  1889. if self.checklistFrame.lists[listId].entries[entryId] then
  1890. if entry.completed then
  1891. self.checklistFrame.lists[listId].entries[entryId].checkbox:Hide()
  1892. self.checklistFrame.lists[listId].entries[entryId].headerText:Hide()
  1893. else
  1894. self.checklistFrame.lists[listId].entries[entryId].checkbox:Show()
  1895. self.checklistFrame.lists[listId].entries[entryId].headerText:Show()
  1896. end
  1897. end
  1898. end
  1899. end
  1900. if self.checklistFrame.lists[listId].expand then
  1901. if list.completed then
  1902. self.checklistFrame.lists[listId].expand:Hide()
  1903. self.checklistFrame.lists[listId].checkbox:Hide()
  1904. self.checklistFrame.lists[listId].headerText:Hide()
  1905. else
  1906. self.checklistFrame.lists[listId].expand:Show()
  1907. self.checklistFrame.lists[listId].checkbox:Show()
  1908. self.checklistFrame.lists[listId].headerText:Show()
  1909. end
  1910. end
  1911. end
  1912. else
  1913. if not self.checklistFrame.lists[listId] or not self.checklistFrame.lists[listId].entries then
  1914. self:CreateListOnChecklistFrame(listId, 0)
  1915. else
  1916. for entryId, entry in pairs(list.entries) do
  1917. if not self.checklistFrame.lists[listId].entries[entryId] then
  1918. if entry.checked then
  1919. self:CreateEntryInChecklistFrame(listId, entryId, 0)
  1920. else
  1921. self.checklistFrame.lists[listId].entries[entryId].checkbox:Show()
  1922. self.checklistFrame.lists[listId].entries[entryId].headerText:Show()
  1923. end
  1924. end
  1925. end
  1926. if self.checklistFrame.lists[listId].expand then
  1927. self.checklistFrame.lists[listId].expand:Show()
  1928. self.checklistFrame.lists[listId].checkbox:Show()
  1929. self.checklistFrame.lists[listId].headerText:Show()
  1930. end
  1931. end
  1932. end
  1933. end
  1934.  
  1935. function DailyChecklist:UpdateVisibilityOnChecklistFrame(hidden)
  1936. for listId, _ in pairs(self.db.profile.lists) do
  1937. self:UpdateVisibilityForListOnChecklistFrame(listId, hidden)
  1938. end
  1939. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement