Nick@113
|
1 --
|
Nick@113
|
2 -- Created by IntelliJ IDEA.
|
Nick@113
|
3 -- User: Nick
|
Nick@113
|
4 -- Date: 3/25/2017
|
Nick@113
|
5 -- Time: 7:07 PM
|
Nick@113
|
6 -- To change this template use File | Settings | File Templates.
|
Nick@113
|
7 --
|
Nick@113
|
8
|
Nick@113
|
9 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop
|
Nenue@115
|
10 local profileUpdate, needsUpdate
|
Nick@113
|
11
|
Nick@113
|
12 local zoneEvents = {
|
Nick@113
|
13 "ZONE_CHANGED_NEW_AREA", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED"
|
Nick@113
|
14 }
|
Nick@113
|
15 local currencyEvents = {
|
Nick@113
|
16 'CURRENCY_DISPLAY_UPDATE', 'CHAT_MSG_CURRENCY'
|
Nick@113
|
17 }
|
Nick@113
|
18 local itemEvents = {
|
Nick@113
|
19 'CHAT_MSG_LOOT', 'BAG_UPDATE'
|
Nick@113
|
20 }
|
Nick@113
|
21
|
Nick@113
|
22 local blocks = {
|
Nick@113
|
23 ["Ancient Mana"] = {
|
Nick@113
|
24 currencyID = 1155,
|
Nick@113
|
25 zones = {
|
Nick@113
|
26 ['Suramar'] = true,
|
Nick@113
|
27 ["Sashj'tar Ruins"] = true,
|
Nick@113
|
28 ["Faronaar Ruins"] = true
|
Nick@113
|
29 }
|
Nick@113
|
30 },
|
Nick@113
|
31 ["Blood of Sargeras"] = {
|
Nick@113
|
32 itemID = 124124,
|
Nick@113
|
33 }
|
Nick@113
|
34 }
|
Nenue@115
|
35 local items, currencies = {}, {}
|
Nick@113
|
36
|
Nick@113
|
37
|
Nenue@115
|
38 VeneerCurrencyMixin = {
|
Nenue@115
|
39 Blocks = {},
|
Nenue@115
|
40 HideCombat = true,
|
Nenue@115
|
41 EventList = {'PLAYER_ENTERING_WORLD'},
|
Nenue@115
|
42 moduleName = 'Currency Watch',
|
Nenue@115
|
43 anchorPoint = 'TOP',
|
Nenue@115
|
44 }
|
Nenue@115
|
45 VeneerCurrencyBlockMixin = {}
|
Nenue@115
|
46 local module = VeneerCurrencyMixin
|
Nenue@115
|
47 local block = VeneerCurrencyBlockMixin
|
Nick@113
|
48
|
Nick@113
|
49
|
Nick@113
|
50
|
Nick@113
|
51 local function RegisterEvents (frame, events)
|
Nick@113
|
52 for _, event in ipairs(events) do
|
Nick@113
|
53 print('|cFFFF0088'..(frame.name or frame:GetName())..'|r', 'listening to', event)
|
Nick@113
|
54 frame:RegisterEvent(event)
|
Nick@113
|
55 end
|
Nick@113
|
56 end
|
Nick@113
|
57
|
Nick@113
|
58 function module:OnLoad ()
|
Nenue@115
|
59 Veneer:AddHandler(self)
|
Nick@113
|
60
|
Nick@113
|
61 for name, info in pairs(blocks) do
|
Nick@113
|
62 local frame = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate')
|
Nick@113
|
63 frame.name = name
|
Nick@113
|
64 for k,v in pairs(info) do
|
Nick@113
|
65 print(name, k, '=', v)
|
Nick@113
|
66 frame[k] = v
|
Nick@113
|
67 end
|
Nick@113
|
68
|
Nick@113
|
69 local debug = function(...)
|
Nick@113
|
70 print('|cFF0088FF<'..frame.name..'>|r', ...)
|
Nick@113
|
71 end
|
Nick@113
|
72
|
Nick@113
|
73 if info.itemID then
|
Nick@113
|
74 local itemID = info.itemID
|
Nick@113
|
75 items[itemID] = {
|
Nick@113
|
76 count = 0,
|
Nick@113
|
77 frame = frame
|
Nick@113
|
78 }
|
Nick@113
|
79 frame.Update = function(block)
|
Nick@113
|
80 debug('Update [Item]')
|
Nick@113
|
81 if items[itemID].count >= 1 then
|
Nick@113
|
82 block.Icon:SetTexture(GetItemIcon(itemID))
|
Nick@113
|
83 block.Label:SetFormattedText("%d", items[itemID].count)
|
Nick@113
|
84 return true
|
Nick@113
|
85 end
|
Nick@113
|
86 end
|
Nick@113
|
87 RegisterEvents(self, itemEvents)
|
Nick@113
|
88 elseif info.currencyID then
|
Nick@113
|
89 local currencyID = info.currencyID
|
Nick@113
|
90 frame.Update = function (block)
|
Nick@113
|
91 debug('Update [Currency]')
|
Nick@113
|
92 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(currencyID)
|
Nick@114
|
93
|
Nick@113
|
94 block.Icon:SetTexture(texture)
|
Nick@113
|
95 block.Label:SetFormattedText("%d / %d", earned, totalMax)
|
Nick@113
|
96 block:SetWidth(block.Icon:GetWidth() + block.Label:GetStringWidth() + 6)
|
Nick@113
|
97 return true
|
Nick@113
|
98 end
|
Nick@113
|
99
|
Nick@113
|
100 RegisterEvents(frame, currencyEvents)
|
Nick@113
|
101 end
|
Nick@113
|
102 if info.zones then
|
Nick@113
|
103 RegisterEvents(frame, zoneEvents)
|
Nick@113
|
104 local zones = info.zones
|
Nick@113
|
105 local of = frame.Update
|
Nick@113
|
106 frame.Update = function(block)
|
Nick@113
|
107 debug('Update [Zone]')
|
Nick@113
|
108 local zone = self.zoneText
|
Nick@113
|
109 local canShow = (zone and block.zones[zone]) and true or false
|
Nick@113
|
110 if of then
|
Nick@113
|
111 canShow = canShow and of(frame)
|
Nick@113
|
112 end
|
Nick@113
|
113 return canShow
|
Nick@113
|
114 end
|
Nick@113
|
115 end
|
Nick@113
|
116 end
|
Nick@113
|
117 end
|
Nick@113
|
118
|
Nick@113
|
119 function module:OnEvent (event, arg)
|
Nick@113
|
120 print(self:GetName(), 'OnEvent', event, arg)
|
Nick@113
|
121 self:Update()
|
Nick@113
|
122 end
|
Nick@113
|
123 local toUpdate = {}
|
Nick@113
|
124 local wipe = table.wipe
|
Nick@113
|
125 function module:Update(isBatchUpdate)
|
Nick@113
|
126 print(self:GetName(), 'Update()')
|
Nick@113
|
127 if InCombatLockdown() then
|
Nick@113
|
128 self:SetShown(false)
|
Nick@113
|
129 return
|
Nick@113
|
130 end
|
Nick@113
|
131
|
Nick@113
|
132
|
Nick@113
|
133 for itemID in pairs(items) do
|
Nick@113
|
134 items[itemID].count = 0
|
Nick@113
|
135 end
|
Nick@113
|
136 self.zoneText = GetRealZoneText()
|
Nick@113
|
137 local canShow = false
|
Nick@113
|
138
|
Nick@113
|
139 for i = 0, NUM_BAG_SLOTS do
|
Nick@113
|
140 local numSlots = GetContainerNumSlots(i)
|
Nick@113
|
141 for j = 1, numSlots do
|
Nick@113
|
142 local itemID = GetContainerItemID(i, j)
|
Nick@113
|
143 local texture, count = GetContainerItemInfo(i,j)
|
Nick@113
|
144 if items[itemID] then
|
Nick@113
|
145 items[itemID].count = items[itemID].count + (count or 1)
|
Nenue@115
|
146 if not items[itemID].texture then
|
Nenue@115
|
147 items[itemID].texture = texture
|
Nenue@115
|
148 print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
|
Nenue@115
|
149 items[itemID].frame.Icon:SetTexture(texture)
|
Nenue@115
|
150 end
|
Nick@113
|
151 end
|
Nick@113
|
152 end
|
Nick@113
|
153 end
|
Nick@113
|
154
|
Nenue@115
|
155
|
Nick@113
|
156
|
Nick@113
|
157 local lastBlock
|
Nick@113
|
158 local totalWidth = 0
|
Nick@113
|
159 for _, block in ipairs(self.Blocks) do
|
Nick@113
|
160 local blockIsShown = block:Update() or false
|
Nick@113
|
161 block:SetShown(blockIsShown)
|
Nick@113
|
162 canShow = canShow or blockIsShown
|
Nick@113
|
163
|
Nick@113
|
164
|
Nick@113
|
165 if block:IsShown() then
|
Nick@113
|
166 block:ClearAllPoints()
|
Nick@113
|
167 if lastBlock then
|
Nick@113
|
168 block:SetPoint('TOPLEFT', lastBlock, 'TOPRIGHT')
|
Nick@113
|
169 else
|
Nick@113
|
170 block:SetPoint('TOPLEFT', self, 'TOPLEFT')
|
Nick@113
|
171 end
|
Nick@113
|
172 lastBlock = block
|
Nick@113
|
173
|
Nick@113
|
174 block:SetHeight(24)
|
Nick@113
|
175 block:SetWidth(block.Icon:GetWidth() + block.Label:GetWidth()+4)
|
Nick@113
|
176 totalWidth = totalWidth + block:GetWidth()
|
Nick@113
|
177 end
|
Nick@113
|
178 print(block:IsShown(), '|cFF0088FF'..block.name..'|r', block:GetSize())
|
Nick@113
|
179 end
|
Nick@113
|
180
|
Nenue@115
|
181 self:UpdateProfile()
|
Nick@113
|
182 self:SetWidth(totalWidth)
|
Nick@113
|
183
|
Nenue@115
|
184 needsUpdate = nil
|
Nick@113
|
185 print(self:IsShown(), '|cFF00FF88'..self:GetName()..'|r', self:GetSize())
|
Nick@113
|
186 self:SetShown(canShow)
|
Nenue@115
|
187 Veneer:DynamicReanchor()
|
Nenue@115
|
188 end
|
Nenue@115
|
189
|
Nenue@115
|
190 function module:UpdateProfile()
|
Nenue@115
|
191 if not self.profile then
|
Nenue@115
|
192 profileUpdate = true
|
Nenue@115
|
193 return
|
Nenue@115
|
194 end
|
Nenue@115
|
195
|
Nenue@115
|
196 for itemID, info in pairs(items) do
|
Nenue@115
|
197 self.profile.Items = self.profile.Items or {}
|
Nenue@115
|
198 self.profile.Items[itemID] = info
|
Nenue@115
|
199 end
|
Nick@113
|
200 end
|
Nick@113
|
201
|
Nick@113
|
202 function module:OnUpdate()
|
Nenue@115
|
203 if needsUpdate then
|
Nick@113
|
204 self:Update()
|
Nenue@115
|
205 elseif profileUpdate then
|
Nenue@115
|
206 self:UpdateProfile()
|
Nick@113
|
207 end
|
Nenue@115
|
208
|
Nick@113
|
209 end
|
Nick@113
|
210
|
Nick@114
|
211 function block:OnEnter()
|
Nick@114
|
212 if not InCombatLockdown() then
|
Nick@114
|
213 GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT");
|
Nick@114
|
214 if self.currencyID then
|
Nick@114
|
215 GameTooltip:SetCurrencyTokenByID(self.currencyID);
|
Nick@114
|
216 else
|
Nick@114
|
217 GameTooltip:SetItemByID(self.itemID);
|
Nick@114
|
218 end
|
Nick@114
|
219 GameTooltip:Show();
|
Nick@114
|
220 end
|
Nick@114
|
221 end
|
Nick@114
|
222 function block:OnLeave()
|
Nick@114
|
223 if GameTooltip:IsOwned(self) then
|
Nick@114
|
224 GameTooltip_Hide()
|
Nick@114
|
225 end
|
Nick@114
|
226 end
|
Nick@114
|
227
|
Nick@113
|
228 function block:OnEvent(event, ...)
|
Nick@113
|
229 print('|cFF0088FF<'..self.name..'>|r', 'OnEvent', event, ...)
|
Nick@113
|
230 self:Update()
|
Nick@113
|
231 end
|
Nick@113
|
232
|
Nick@113
|
233 function block:Setup()
|
Nick@113
|
234
|
Nick@113
|
235 end
|