annotate ObjectiveTracker/Achievements.lua @ 30:7583684becf4

- implement procedural block contents generation - redo anchor calculations to allow for transitional animation - attempt to sort out event handling quirks related to autopopup quest completion and turn-in - revise the data structures created by the different GetInfo's - start on trimming out redundant variables
author Nenue
date Thu, 14 Apr 2016 17:11:13 -0400
parents adcd7c328d07
children 9856ebc63fa4
rev   line source
Nenue@28 1 --- ${PACKAGE_NAME}
Nenue@28 2 -- @file-author@
Nenue@28 3 -- @project-revision@ @project-hash@
Nenue@28 4 -- @file-revision@ @file-hash@
Nenue@28 5 -- Created: 4/13/2016 7:48 PM
Nenue@28 6 local B = select(2,...).frame
Nenue@28 7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@29 8 local band = bit.band
Nenue@30 9 local RemoveTrackedAchievement, GetAchievementLink = RemoveTrackedAchievement, GetAchievementLink
Nenue@29 10 local AchievementFrame_ToggleAchievementFrame, AchievementFrame_SelectAchievement = AchievementFrame_ToggleAchievementFrame, AchievementFrame_SelectAchievement
Nenue@29 11 local GetTime, GetAchievementNumCriteria, GetAchievementCriteriaInfo = GetTime, GetAchievementNumCriteria, GetAchievementCriteriaInfo
Nenue@29 12 local GetNumTrackedAchievements, GetTrackedAchievements, GetAchievementInfo = GetNumTrackedAchievements, GetTrackedAchievements, GetAchievementInfo
Nenue@29 13 local Default, Cheevs = T.DefaultHandler, T.Cheevs
Nenue@28 14 local print = B.print('Tracker')
Nenue@28 15 local lprint = B.print('Line')
Nenue@28 16 local iprint = B.print('Info')
Nenue@28 17
Nenue@29 18 --- Data retrieval
Nenue@29 19 Cheevs.GetNumWatched = function(self)
Nenue@29 20 print('|cFF00FF00' .. GetTime())
Nenue@29 21 Cheevs.trackedCheevs = {GetTrackedAchievements()}
Nenue@29 22 return GetNumTrackedAchievements()
Nenue@29 23 end
Nenue@29 24 Cheevs.GetInfo = function(self, index)
Nenue@29 25 local cheevID = Cheevs.trackedCheevs[index]
Nenue@29 26 local id, name, points, completed, month, day, year, description, flags, icon, rewardText, isGuildAch, wasEarnedByMe, earnedBy = GetAchievementInfo(cheevID)
Nenue@28 27
Nenue@29 28 self.Info[cheevID] = {}
Nenue@29 29 local c = self.Info[cheevID]
Nenue@29 30 c.type = 'Cheevs'
Nenue@29 31 c.watchIndex = index
Nenue@30 32 c.id = cheevID
Nenue@29 33 c.cheevID = cheevID
Nenue@29 34 c.title = name
Nenue@29 35 c.points, c.completed, c.month, c.day, c.year, c.description, c.flags, c.icon, c.rewardText, c.isGuildAch, c.wasEarnedByMe, c.earnedBy =
Nenue@29 36 points, completed, month, day, year, description, flags, icon, rewardText, isGuildAch, wasEarnedByMe, earnedBy
Nenue@29 37 c.numObjectives = GetAchievementNumCriteria(cheevID)
Nenue@30 38
Nenue@30 39 local tagInfo = {}
Nenue@30 40
Nenue@30 41
Nenue@29 42 c.objectives = {}
Nenue@29 43 for i = 1, c.numObjectives do
Nenue@29 44 local description, type, completed, quantity, requiredQuantity, characterName, flags, assetID, quantityString, criteriaID = GetAchievementCriteriaInfo(cheevID, i)
Nenue@29 45 c.objectives[i] = {
Nenue@29 46 objectiveIndex = i,
Nenue@29 47 cheevID = cheevID,
Nenue@29 48 text = description,
Nenue@29 49 type = type,
Nenue@29 50 finished = completed,
Nenue@29 51 value = quantity,
Nenue@29 52 maxValue = requiredQuantity,
Nenue@29 53 characterName = characterName,
Nenue@29 54 flags = flags,
Nenue@29 55 assetID = assetID,
Nenue@29 56 quantityString = quantityString,
Nenue@29 57 criteriaID = criteriaID,
Nenue@29 58 }
Nenue@29 59 end
Nenue@29 60 print('Cheevs.|cFF0088FFGetInfo|r('..index..')', 'obj:', GetAchievementNumCriteria(cheevID), name, description)
Nenue@28 61
Nenue@30 62 c.tagInfo = tagInfo
Nenue@29 63 self.WatchInfo[index] = c
Nenue@29 64 return self.Info[cheevID]
Nenue@29 65 end
Nenue@29 66
Nenue@29 67 --- Content handlers
Nenue@28 68 Cheevs.UpdateLine = function(handler, block, line, data)
Nenue@28 69 local print = B.print('CheevsLine')
Nenue@30 70 local attachment
Nenue@28 71 line.progress = 0
Nenue@28 72 print(' ', data.objectiveIndex,'|cFF0088FF-|r', data.objectiveType, data.text)
Nenue@28 73 if data.flags then
Nenue@28 74 if band(data.flags, 0x00000001) > 0 then
Nenue@28 75 line.format = "%d/%d"
Nenue@28 76 line.widget = T.SetWidget(line, data, 'ProgressBar', data.criteriaID)
Nenue@28 77 line.height = line.widget.height
Nenue@28 78 elseif band(data.flags, 0x00000002) then
Nenue@28 79 line.widget = nil
Nenue@28 80 else
Nenue@28 81 line.widget = nil
Nenue@28 82 line.displayColor = 'FFFFFF'
Nenue@28 83 line.displayText = line.text
Nenue@28 84
Nenue@28 85 end
Nenue@28 86 else
Nenue@28 87
Nenue@28 88 line.displayText = data.text
Nenue@28 89 end
Nenue@28 90 print('line.type =', data.type)
Nenue@28 91 print(' ** qtyStr:', data.quantityString, 'qty:', data.quantity, 'assetID:', data.assetID)
Nenue@30 92 return line.displayText, line.widget
Nenue@28 93 end
Nenue@28 94
Nenue@30 95 Cheevs.Select = function(self, block)
Nenue@30 96 Cheevs.Link(self, block)
Nenue@28 97 end
Nenue@29 98
Nenue@30 99 Cheevs.Remove = function(self, block)
Nenue@28 100
Nenue@30 101 RemoveTrackedAchievement(block.info.cheevID)
Nenue@28 102 end
Nenue@28 103 Cheevs.OnMouseUp = function(self, button)
Nenue@28 104
Nenue@28 105 Default.OnMouseUp(self, button)
Nenue@28 106 end
Nenue@30 107 Cheevs.Link = function(self, block)
Nenue@30 108 local achievementLink = GetAchievementLink(block.info.cheevID);
Nenue@28 109 if ( achievementLink ) then
Nenue@30 110 _G.ChatEdit_InsertLink(achievementLink);
Nenue@28 111 end
Nenue@28 112 end
Nenue@28 113
Nenue@30 114 Cheevs.Open = function(self, block)
Nenue@28 115
Nenue@30 116 if ( not _G.AchievementFrame ) then
Nenue@30 117 _G.AchievementFrame_LoadUI();
Nenue@28 118 end
Nenue@30 119 if ( not _G.AchievementFrame:IsShown() ) then
Nenue@30 120 _G.AchievementFrame_ToggleAchievementFrame();
Nenue@28 121 end
Nenue@30 122 _G.AchievementFrame_SelectAchievement(block.info.cheevID);
Nenue@28 123 end