vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --$Id: OneCore.lua 8409 2006-08-19 02:27:30Z kaelten $ |
2 | OneCore = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceModuleCore-2.0", "AceHook-2.0") |
||
3 | |||
4 | local L = AceLibrary("AceLocale-2.0"):new("OneBag") |
||
5 | |||
6 | function OneCore:OnInitialize() |
||
7 | self:Hook("BankFrame_OnEvent", function(event) |
||
8 | LoadAddOn("OneBank") |
||
9 | local module = self:HasModule("OneBank") and self:GetModule("OneBank") |
||
10 | if not module or not module:IsActive() then |
||
11 | self.hooks.BankFrame_OnEvent.orig(event) |
||
12 | end |
||
13 | end) |
||
14 | |||
15 | self.defaults = { |
||
16 | cols = 10, |
||
17 | scale = 1, |
||
18 | alpha = 1, |
||
19 | colors = { |
||
20 | mouseover = {r = 0, g = .7, b = 1}, |
||
21 | ammo = {r = 1, g = 1, b = 0}, |
||
22 | soul = {r = .5, g = .5, b = 1}, |
||
23 | prof = {r = 1, g = 0, b = 1}, |
||
24 | bground = {r = 0, g = 0, b = 0, a = .45}, |
||
25 | glow = false, |
||
26 | rarity = true, |
||
27 | }, |
||
28 | show = { |
||
29 | ['*'] = true |
||
30 | }, |
||
31 | strata = 2, |
||
32 | locked = false, |
||
33 | clamped = true, |
||
34 | bagBreak = false, |
||
35 | vAlign = L"Top", |
||
36 | } |
||
37 | |||
38 | |||
39 | self.modulePrototype.colWidth = 39 |
||
40 | self.modulePrototype.rowHeight = 39 |
||
41 | self.modulePrototype.topBorder = 2 |
||
42 | self.modulePrototype.bottomBorder = 24 |
||
43 | self.modulePrototype.rightBorder = 5 |
||
44 | self.modulePrototype.leftBorder = 8 |
||
45 | |||
46 | self.modulePrototype.stratas = { |
||
47 | "LOW", |
||
48 | "MEDIUM", |
||
49 | "HIGH", |
||
50 | "DIALOG", |
||
51 | "FULLSCREEN", |
||
52 | "FULLSCREEN_DIALOG", |
||
53 | "TOOLTIP", |
||
54 | } |
||
55 | |||
56 | end |
||
57 | |||
58 | function OneCore:GetFreshOptionsTable(module) |
||
59 | local self = module |
||
60 | return { |
||
61 | type="group", |
||
62 | args = { |
||
63 | frame = { |
||
64 | name = L"Frame", type = 'group', |
||
65 | desc = L"Frame Options", order = 2, |
||
66 | args = { |
||
67 | cols = { |
||
68 | name = L"Columns", type = "range", step = 1, |
||
69 | desc = L"Sets the number of columns to use", |
||
70 | get = function() return self.db.profile.cols end, |
||
71 | set = function(num) |
||
72 | self.db.profile.cols = num |
||
73 | self:OrganizeFrame(true) |
||
74 | end, |
||
75 | min = 5, max = 20, |
||
76 | }, |
||
77 | scale = { |
||
78 | name = L"Scale", type = "range", |
||
79 | desc = L"Sets the scale of the frame", |
||
80 | get = function() return self.db.profile.scale end, |
||
81 | set = function(num) |
||
82 | self.db.profile.scale = num |
||
83 | self.frame:SetScale(num) |
||
84 | if self.frame.bagFrame then |
||
85 | self.frame.bagFrame:SetScale(num) |
||
86 | local shownContainerID = IsBagOpen(KEYRING_CONTAINER) |
||
87 | if ( shownContainerID and not self.isBank) then |
||
88 | local frame = getglobal("ContainerFrame"..shownContainerID) |
||
89 | frame:SetScale(num) |
||
90 | end |
||
91 | end |
||
92 | end, |
||
93 | min = .2, max = 2, |
||
94 | isPercent = true, |
||
95 | }, |
||
96 | strata = { |
||
97 | name = L"Strata", type = "range", |
||
98 | desc = L"Sets the strata of the frame", |
||
99 | get = function() return self.db.profile.strata end, |
||
100 | set = function(num) |
||
101 | self.db.profile.strata = num |
||
102 | self.frame:SetFrameStrata(self.stratas[num]) |
||
103 | if self.frame.bagFrame then |
||
104 | self.frame.bagFrame:SetFrameStrata(self.stratas[num]) |
||
105 | end |
||
106 | StackSplitFrame:SetFrameStrata(self.stratas[num+1]) |
||
107 | end, |
||
108 | min = 1, max = 5, step = 1, |
||
109 | }, |
||
110 | bagbreak = { |
||
111 | name = L"Bag Break", type = "toggle", |
||
112 | desc = L"Sets wether to start a new row at the beginning of a bag.", |
||
113 | get = function() return self.db.profile.bagBreak end, |
||
114 | set = function(value) |
||
115 | self.db.profile.bagBreak = value |
||
116 | self:OrganizeFrame(true) |
||
117 | end, |
||
118 | }, |
||
119 | valign = { |
||
120 | name = L"Vertical Alignment", type = "text", |
||
121 | desc = L"Sets wether to have the extra spaces on the top or bottom.", |
||
122 | get = function() return self.db.profile.vAlign end, |
||
123 | set = function(value) |
||
124 | self.db.profile.vAlign = value |
||
125 | self:OrganizeFrame(true) |
||
126 | end, |
||
127 | validate = {L"Top", L"Bottom"} |
||
128 | }, |
||
129 | alpha = { |
||
130 | name = L"Alpha", type = "range", |
||
131 | desc = L"Sets the alpha of the frame", |
||
132 | get = function() return self.db.profile.alpha end, |
||
133 | set = function(num) |
||
134 | self.db.profile.alpha = num |
||
135 | self.frame:SetAlpha(num) |
||
136 | if self.frame.bagFrame then |
||
137 | self.frame.bagFrame:SetAlpha(num) |
||
138 | |||
139 | local shownContainerID = IsBagOpen(KEYRING_CONTAINER) |
||
140 | if ( shownContainerID and not self.isBank) then |
||
141 | local frame = getglobal("ContainerFrame"..shownContainerID) |
||
142 | frame:SetAlpha(num) |
||
143 | end |
||
144 | end |
||
145 | end, |
||
146 | min = .05, max = 1, |
||
147 | isPercent = true, |
||
148 | }, |
||
149 | locked = { |
||
150 | name = L"Locked", |
||
151 | type = 'toggle', |
||
152 | desc = L"Toggles the ability to move the frame", |
||
153 | get = function() return self.db.profile.locked end, |
||
154 | set = function(v) |
||
155 | self.db.profile.locked = v |
||
156 | end, |
||
157 | }, |
||
158 | clamped = { |
||
159 | name = L"Clamped", |
||
160 | type = 'toggle', |
||
161 | desc = L"Toggles the ability to drag the frame off screen.", |
||
162 | get = function() return self.db.profile.clamped end, |
||
163 | set = function(v) |
||
164 | self.db.profile.clamped = v |
||
165 | self.frame:SetClampedToScreen(v) |
||
166 | if self.frame.bagFrame then |
||
167 | self.frame.bagFrame:SetClampedToScreen(v) |
||
168 | end |
||
169 | end, |
||
170 | }, |
||
171 | } |
||
172 | }, |
||
173 | show = { |
||
174 | name = L"Show", type = 'group', order = 3, |
||
175 | desc = L"Various Display Options", |
||
176 | args = { |
||
177 | counts = { |
||
178 | name = L"Counts", |
||
179 | type = 'toggle', order = 1, |
||
180 | desc = L"Toggles showing the counts for special bags.", |
||
181 | get = function() return self.db.profile.show.counts end, |
||
182 | set = function(v) |
||
183 | self.db.profile.show.counts = v |
||
184 | if self.DoBankSlotCounts then |
||
185 | self:DoBankSlotCounts() |
||
186 | self:DoInventorySlotCounts() |
||
187 | else |
||
188 | self:DoSlotCounts() |
||
189 | end |
||
190 | end, |
||
191 | }, |
||
192 | direction = { |
||
193 | cmdName = L"Direction", guiName = L"Forward", |
||
194 | type = 'toggle', order = 2, |
||
195 | desc = L"Toggles direction the bags are shown", |
||
196 | get = function() return self.db.profile.show.direction end, |
||
197 | set = function(v) |
||
198 | self.db.profile.show.direction = v |
||
199 | self:OrganizeFrame(true) |
||
200 | end, |
||
201 | map = { [false] = L"|cffff0000Reverse|r", [true] = L"|cff00ff00Forward|r" } |
||
202 | }, |
||
203 | ammo = { |
||
204 | name = L"Ammo Bag", type = 'toggle', order = 3, |
||
205 | desc = L"Turns display of ammo bags on and off.", |
||
206 | get = function() return self.db.profile.show.ammo end, |
||
207 | set = function(v) |
||
208 | self.db.profile.show.ammo = v |
||
209 | self:OrganizeFrame(true) |
||
210 | end, |
||
211 | }, |
||
212 | soul = { |
||
213 | name = L"Soul Bag", type = 'toggle', order = 4, |
||
214 | desc = L"Turns display of soul bags on and off.", |
||
215 | get = function() return self.db.profile.show.soul end, |
||
216 | set = function(v) |
||
217 | self.db.profile.show.soul = v |
||
218 | self:OrganizeFrame(true) |
||
219 | end, |
||
220 | }, |
||
221 | prof = { |
||
222 | name = L"Profession Bag", type = 'toggle', order = 4.5, |
||
223 | desc = L"Turns display of profession bags on and off.", |
||
224 | get = function() return self.db.profile.show.prof end, |
||
225 | set = function(v) |
||
226 | self.db.profile.show.prof = v |
||
227 | self:OrganizeFrame(true) |
||
228 | end, |
||
229 | }, |
||
230 | } |
||
231 | }, |
||
232 | colors = { |
||
233 | name = L"Colors", type = 'group', order = 1, |
||
234 | desc = L"Different color code settings.", |
||
235 | args = { |
||
236 | mouseover = { |
||
237 | name = L"Mouseover Color", type = "color", order = 1, |
||
238 | desc = L"Changes the highlight color for when you mouseover a bag slot.", |
||
239 | get = function() |
||
240 | local color = self.db.profile.colors.mouseover |
||
241 | return color.r, color.g, color.b |
||
242 | end, |
||
243 | set = function(r, g, b) self.db.profile.colors.mouseover = {r = r, g = g, b = b} end, |
||
244 | }, |
||
245 | ammo = { |
||
246 | name = L"Ammo Bag Color", type = "color", order = 2, |
||
247 | desc = L"Changes the highlight color for Ammo Bags.", |
||
248 | get = function() |
||
249 | local color = self.db.profile.colors.ammo |
||
250 | return color.r, color.g, color.b |
||
251 | end, |
||
252 | set = function(r, g, b) |
||
253 | self.db.profile.colors.ammo = {r = r, g = g, b = b} |
||
254 | for k, bag in self.fBags do |
||
255 | if self.frame.bags[bag] then |
||
256 | for k, v in ipairs(self.frame.bags[bag]) do |
||
257 | self:SetBorderColor(v) |
||
258 | end |
||
259 | end |
||
260 | end |
||
261 | end, |
||
262 | }, |
||
263 | soul = { |
||
264 | name = L"Soul Bag Color", type = "color", order = 3, |
||
265 | desc = L"Changes the highlight color for Soul Bags.", |
||
266 | get = function() |
||
267 | local color = self.db.profile.colors.soul |
||
268 | return color.r, color.g, color.b |
||
269 | end, |
||
270 | set = function(r, g, b) |
||
271 | self.db.profile.colors.soul = {r = r, g = g, b = b} |
||
272 | for k, bag in self.fBags do |
||
273 | if self.frame.bags[bag] then |
||
274 | for k, v in ipairs(self.frame.bags[bag]) do |
||
275 | self:SetBorderColor(v) |
||
276 | end |
||
277 | end |
||
278 | end |
||
279 | end, |
||
280 | }, |
||
281 | prof = { |
||
282 | name = L"Profession Bag Color", type = "color", order = 4, |
||
283 | desc = L"Changes the highlight color for Profession Bags.", |
||
284 | get = function() |
||
285 | local color = self.db.profile.colors.prof |
||
286 | return color.r, color.g, color.b |
||
287 | end, |
||
288 | set = function(r, g, b) |
||
289 | self.db.profile.colors.prof = {r = r, g = g, b = b} |
||
290 | for k, bag in self.fBags do |
||
291 | if self.frame.bags[bag] then |
||
292 | for k, v in ipairs(self.frame.bags[bag]) do |
||
293 | self:SetBorderColor(v) |
||
294 | end |
||
295 | end |
||
296 | end |
||
297 | end, |
||
298 | }, |
||
299 | background = { |
||
300 | name = L"Background Color", type = "color", order = 5, |
||
301 | desc = L"Changes the background color for the frame.", |
||
302 | get = function() |
||
303 | local color = self.db.profile.colors.bground |
||
304 | return color.r, color.g, color.b, color.a |
||
305 | end, |
||
306 | set = function(r, g, b, a) |
||
307 | self.db.profile.colors.bground = {r = r, g = g, b = b, a = a} |
||
308 | self.frame:SetBackdropColor(r, g, b, a) |
||
309 | if self.frame.bagFrame then |
||
310 | self.frame.bagFrame:SetBackdropColor(r, g, b, a) |
||
311 | end |
||
312 | end, |
||
313 | hasAlpha = true, |
||
314 | }, |
||
315 | glow = { |
||
316 | name = L"Highlight Glow", type = 'toggle', order = 6, |
||
317 | desc = L"Turns hightlight glow on and off.", |
||
318 | get = function() return self.db.profile.colors.glow end, |
||
319 | set = function(v) |
||
320 | self.db.profile.colors.glow = v |
||
321 | for k, bag in self.fBags do |
||
322 | if self.frame.bags[bag] then |
||
323 | for k, v in ipairs(self.frame.bags[bag]) do |
||
324 | self:SetBorderColor(v) |
||
325 | end |
||
326 | end |
||
327 | end |
||
328 | end, |
||
329 | }, |
||
330 | rarity = { |
||
331 | name = L"Rarity Coloring", type = 'toggle', order = 7, |
||
332 | desc = L"Turns rarity coloring on and off.", |
||
333 | get = function() return self.db.profile.colors.rarity end, |
||
334 | set = function(v) |
||
335 | self.db.profile.colors.rarity = v |
||
336 | for k, bag in self.fBags do |
||
337 | if self.frame.bags[bag] then |
||
338 | for k, v in ipairs(self.frame.bags[bag]) do |
||
339 | self:SetBorderColor(v) |
||
340 | end |
||
341 | end |
||
342 | end |
||
343 | end, |
||
344 | }, |
||
345 | reset = { |
||
346 | name = L'Reset', type = 'group', order = -1, |
||
347 | desc = L"Reset the different colors.", |
||
348 | args = { |
||
349 | mouseover = { |
||
350 | name = L"Mouseover Color", type = "execute", |
||
351 | desc = L"Returns your mouseover color to the default.", |
||
352 | func = function() |
||
353 | self.db.profile.colors.mouseover = {r = 0, g = .7, b = 1} |
||
354 | end, |
||
355 | order = 1 |
||
356 | }, |
||
357 | ammo = { |
||
358 | name = L"Ammo Slot Color", type = "execute", |
||
359 | desc = L"Returns your ammo slot color to the default.", |
||
360 | func = function() |
||
361 | self.db.profile.colors.ammo = {r = 1, g = 1, b = 0} |
||
362 | for k, bag in self.fBags do |
||
363 | if self.frame.bags[bag] then |
||
364 | for k, v in ipairs(self.frame.bags[bag]) do |
||
365 | self:SetBorderColor(v) |
||
366 | end |
||
367 | end |
||
368 | end |
||
369 | end, |
||
370 | order = 2 |
||
371 | }, |
||
372 | soul = { |
||
373 | name = L"Soul Slot Color", type = "execute", |
||
374 | desc = L"Returns your soul slot color to the default.", |
||
375 | func = function() |
||
376 | self.db.profile.colors.soul = {r = .5, g = .5, b = 1} |
||
377 | for k, bag in self.fBags do |
||
378 | if self.frame.bags[bag] then |
||
379 | for k, v in ipairs(self.frame.bags[bag]) do |
||
380 | self:SetBorderColor(v) |
||
381 | end |
||
382 | end |
||
383 | end |
||
384 | end, |
||
385 | order = 3 |
||
386 | }, |
||
387 | prof = { |
||
388 | name = L"Profession Slot Color", type = "execute", |
||
389 | desc = L"Returns your profession slot color to the default.", |
||
390 | func = function() |
||
391 | self.db.profile.colors.prof = {r = 1, g = 0, b = 1} |
||
392 | for k, bag in self.fBags do |
||
393 | if self.frame.bags[bag] then |
||
394 | for k, v in ipairs(self.frame.bags[bag]) do |
||
395 | self:SetBorderColor(v) |
||
396 | end |
||
397 | end |
||
398 | end |
||
399 | end, |
||
400 | order = 4 |
||
401 | }, |
||
402 | background = { |
||
403 | name = L"Background", type = "execute", |
||
404 | desc = L"Returns your frame background to the default.", |
||
405 | func = function() |
||
406 | self.db.profile.colors.bground = {r = 0, g = 0, b = 0, a = .45} |
||
407 | self.frame:SetBackdropColor(0, 0, 0, .45) |
||
408 | if self.frame.bagFrame then |
||
409 | self.frame.bagFrame:SetBackdropColor(0, 0, 0, .45) |
||
410 | end |
||
411 | end, |
||
412 | order = 5 |
||
413 | } |
||
414 | } |
||
415 | } |
||
416 | } |
||
417 | } |
||
418 | } |
||
419 | } |
||
420 | end |
||
421 | |||
422 | function OneCore:LoadOptionalCommands(baseArgs, module) |
||
423 | local self = module |
||
424 | if IsAddOnLoaded("MrPlow") then |
||
425 | baseArgs.args.plow = { |
||
426 | name = L"Plow!", type = "execute", |
||
427 | desc = L"Organizes your bags.", |
||
428 | func = function() self:MrPlow() end, |
||
429 | order = -5, |
||
430 | notes = L"- Note: This option only appears if you have MrPlow installed" |
||
431 | } |
||
432 | end |
||
433 | end |
||
434 | |||
435 | function OneCore:CopyTable(from, into) |
||
436 | if type(into) ~= "table" then into = {} end |
||
437 | |||
438 | for key, val in from do |
||
439 | if( type(val) == "table" ) then |
||
440 | into[key] = self:CopyTable(val) |
||
441 | else |
||
442 | into[key] = val |
||
443 | end |
||
444 | end |
||
445 | |||
446 | if (getn(from)) then |
||
447 | table.setn(into, getn(from)) |
||
448 | end |
||
449 | |||
450 | return into |
||
451 | end |
||
452 | |||
453 | local module = OneCore.modulePrototype |
||
454 | |||
455 | function module:BuildFrame() |
||
456 | debugprofilestart() |
||
457 | if self.isBank then |
||
458 | if not self.frame.bags[BANK_CONTAINER] then |
||
459 | self.frame.bags[BANK_CONTAINER] = CreateFrame("Frame", "BBankFrame", self.frame) |
||
460 | self.frame.bags[BANK_CONTAINER]:SetID(BANK_CONTAINER) |
||
461 | self.frame.bags[BANK_CONTAINER].size = 24 |
||
462 | for slot = 1, 24 do |
||
463 | self.frame.bags[BANK_CONTAINER][slot] = CreateFrame("Button", self.frame.bags[BANK_CONTAINER]:GetName().."Item"..slot, self.frame.bags[BANK_CONTAINER], "OneBankItemButtonTemplate") |
||
464 | self.frame.bags[BANK_CONTAINER][slot]:SetID(slot) |
||
465 | end |
||
466 | self.needToOrganize = true |
||
467 | end |
||
468 | end |
||
469 | |||
470 | for k, bag in self.fBags do |
||
471 | local size = GetContainerNumSlots(bag) |
||
472 | for slot = 1, size do |
||
473 | if not self.frame.bags[bag] then |
||
474 | self.frame.bags[bag] = CreateFrame("Frame", tostring(self)..bag, self.frame) |
||
475 | self.frame.bags[bag]:SetID(bag) |
||
476 | end |
||
477 | if not self.frame.bags[bag][slot] then |
||
478 | self.frame.bags[bag][slot] = CreateFrame("Button", tostring(self)..bag.."Item"..slot, self.frame.bags[bag], "OneBagItemButtonTemplate") |
||
479 | self.frame.bags[bag][slot]:SetID(slot) |
||
480 | self.needToOrganize = true |
||
481 | end |
||
482 | end |
||
483 | if self.frame.bags[bag] then |
||
484 | local curBag = self.frame.bags[bag] |
||
485 | local isAmmo, isSoul, isProf = self:GetBagTypes(bag) |
||
486 | if curBag.size ~= size or curBag.isAmmo ~= isAmmo or curBag.isSoul ~= isSoul or curBag.isProf ~= isProf then |
||
487 | self.needToOrganize = true |
||
488 | end |
||
489 | curBag.size, curBag.isAmmo, curBag.isSoul, curBag.isProf = size, isAmmo, isSoul, isProf |
||
490 | end |
||
491 | end |
||
492 | self:Debug(L"%s ran in %s", "BuildFrame", debugprofilestop()) |
||
493 | end |
||
494 | |||
495 | function module:OrganizeFrame(needs) |
||
496 | debugprofilestart() |
||
497 | if not self.needToOrganize and not needs then return end |
||
498 | self.needToOrganize = false |
||
499 | |||
500 | local cols, curCol, curRow, justinc = self.db.profile.cols, 1, 1, false |
||
501 | |||
502 | self.soulSlots, self.ammoSlots, self.profSlots, self.slotCount, self.totalCount = 0, 0, 0, 0, 0 |
||
503 | |||
504 | for k, bag in self.fBags do |
||
505 | if self.frame.bags[bag] then |
||
506 | for k2, v2 in ipairs(self.frame.bags[bag]) do |
||
507 | v2:Hide() |
||
508 | end |
||
509 | self.totalCount = self.totalCount + (self.frame.bags[bag].size or 0) |
||
510 | end |
||
511 | end |
||
512 | |||
513 | if self.db.profile.vAlign == L"Bottom" then |
||
514 | curCol = math.mod(self.totalCount, cols) > 0 and cols - math.mod(self.totalCount, cols) + 1 or 1 |
||
515 | if self.db.profile.bagBreak then |
||
516 | for k, bag in self.fBags do |
||
517 | if self.frame.bags[bag] and self.frame.bags[bag].size then curCol = curCol - 1 end |
||
518 | end |
||
519 | curCol = curCol + 1 |
||
520 | end |
||
521 | end |
||
522 | |||
523 | |||
524 | for k, bag in (self.db.profile.show.direction and self.fBags or self.rBags) do |
||
525 | local curBag = self.frame.bags[bag] |
||
526 | |||
527 | if curBag and curBag.size and curBag.size > 0 then |
||
528 | if bag > 0 and math.mod(self.frame.bags[bag-1] and self.frame.bags[bag-1].size or 0, cols) ~= 0 and self.db.profile.bagBreak then |
||
529 | curCol = curCol + 1 |
||
530 | if curCol > cols then curCol, curRow, justinc = 1, curRow + 1, true end |
||
531 | end |
||
532 | if curBag.isAmmo then |
||
533 | self.ammoSlots = self.ammoSlots + curBag.size |
||
534 | elseif curBag.isSoul then |
||
535 | self.soulSlots = self.soulSlots + curBag.size |
||
536 | elseif curBag.isProf then |
||
537 | self.profSlots = self.profSlots + curBag.size |
||
538 | else |
||
539 | self.slotCount = self.slotCount + curBag.size |
||
540 | end |
||
541 | if self:ShouldShow(bag, curBag.isAmmo, curBag.isSoul, curBag.isProf) then |
||
542 | for slot = 1, curBag.size do |
||
543 | justinc = false |
||
544 | curBag[slot]:ClearAllPoints() |
||
545 | curBag[slot]:SetPoint("TOPLEFT", self.frame:GetName(), "TOPLEFT", self.leftBorder + (self.colWidth * (curCol - 1)) , 0 - self.topBorder - (self.rowHeight * curRow)) |
||
546 | curBag[slot]:Show() |
||
547 | curCol = curCol + 1 |
||
548 | if curCol > cols then curCol, curRow, justinc = 1, curRow + 1, true end |
||
549 | end |
||
550 | end |
||
551 | end |
||
552 | end |
||
553 | self:Debug("CurrentRow: %s", curRow) |
||
554 | |||
555 | if not justinc then curRow = curRow + 1 end |
||
556 | self.frame:SetHeight(curRow * self.rowHeight + self.bottomBorder + self.topBorder) |
||
557 | self.frame:SetWidth(cols * self.colWidth + self.leftBorder + self.rightBorder) |
||
558 | |||
559 | self:Debug(L"%s ran in %s", "OrganizeFrame", debugprofilestop()) |
||
560 | |||
561 | end |
||
562 | |||
563 | function module:SetBorderColor(slot) |
||
564 | local color = {r = 1, g = 1, b = 1} |
||
565 | |||
566 | local bag = slot:GetParent() |
||
567 | local special = false |
||
568 | |||
569 | if bag.isAmmo then |
||
570 | color = self.db.profile.colors.ammo |
||
571 | special = true |
||
572 | elseif bag.isSoul then |
||
573 | color = self.db.profile.colors.soul |
||
574 | special = true |
||
575 | elseif bag.isProf then |
||
576 | color = self.db.profile.colors.prof |
||
577 | special = true |
||
578 | elseif self.db.profile.colors.rarity then |
||
579 | local _, _, hex = strfind(GetContainerItemLink(bag:GetID(), slot:GetID()) or "", "(|cff%x%x%x%x%x%x)") |
||
580 | |||
581 | for k, v in ipairs(ITEM_QUALITY_COLORS) do |
||
582 | if hex == v.hex then |
||
583 | color = v |
||
584 | if k > 1 then |
||
585 | special = true |
||
586 | end |
||
587 | end |
||
588 | end |
||
589 | end |
||
590 | |||
591 | if special and self.db.profile.colors.glow then |
||
592 | slot:SetNormalTexture("Interface\\Buttons\\UI-ActionButton-Border") |
||
593 | slot:GetNormalTexture():SetBlendMode("ADD") |
||
594 | slot:GetNormalTexture():SetAlpha(.8) |
||
595 | slot:GetNormalTexture():SetPoint("CENTER", slot:GetName(), "CENTER", 0, 1) |
||
596 | elseif special then |
||
597 | slot:SetNormalTexture("Interface\\AddOns\\OneBag\\BagSlot2") |
||
598 | slot:GetNormalTexture():SetBlendMode("BLEND") |
||
599 | slot:GetNormalTexture():SetPoint("CENTER", slot:GetName(), "CENTER", 0, 0) |
||
600 | else |
||
601 | slot:SetNormalTexture("Interface\\AddOns\\OneBag\\BagSlot") |
||
602 | slot:GetNormalTexture():SetBlendMode("BLEND") |
||
603 | slot:GetNormalTexture():SetPoint("CENTER", slot:GetName(), "CENTER", 0, 0) |
||
604 | end |
||
605 | slot:GetNormalTexture():SetVertexColor(color.r, color.g, color.b) |
||
606 | end |
||
607 | |||
608 | function module:GetBagTypes(bag) |
||
609 | if( bag <= 0 ) then return end |
||
610 | |||
611 | local _, _, id = strfind(GetInventoryItemLink("player", ContainerIDToInventoryID(bag)) or "", "item:(%d+)"); |
||
612 | if id then |
||
613 | local _, _, _, _, itemType, subType = GetItemInfo(id); |
||
614 | return (itemType == L"Quiver" or false), (subType == L"Soul Bag" or false), (( itemType == L"Container" and not (subType == L"Bag" or subType == L"Soul Bag") ) or false) |
||
615 | end |
||
616 | end |
||
617 | |||
618 | function module:HighlightBagSlots(bag) |
||
619 | if not self.frame.bags[bag] then return end |
||
620 | |||
621 | local color = self.db.profile.colors.mouseover |
||
622 | for k, v in ipairs(self.frame.bags[bag]) do |
||
623 | |||
624 | if self.db.profile.colors.glow then |
||
625 | v:SetNormalTexture("Interface\\Buttons\\UI-ActionButton-Border") |
||
626 | v:GetNormalTexture():SetBlendMode("ADD") |
||
627 | v:GetNormalTexture():SetAlpha(.8) |
||
628 | else |
||
629 | v:SetNormalTexture("Interface\\AddOns\\OneBag\\BagSlot2") |
||
630 | v:GetNormalTexture():SetBlendMode("BLEND") |
||
631 | end |
||
632 | v:GetNormalTexture():SetVertexColor(color.r, color.g, color.b) |
||
633 | end |
||
634 | end |
||
635 | |||
636 | function module:UnhighlightBagSlots(bag) |
||
637 | if not self.frame.bags[bag] then return end |
||
638 | for k, v in ipairs(self.frame.bags[bag]) do |
||
639 | self:SetBorderColor(v) |
||
640 | end |
||
641 | end |
||
642 | |||
643 | function module:UpdateBag(bag) |
||
644 | debugprofilestart() |
||
645 | if not self.frame.bags[bag] then return end |
||
646 | |||
647 | self:BuildFrame() |
||
648 | self:OrganizeFrame() |
||
649 | |||
650 | if not self.frame.bags[bag].colorLocked then |
||
651 | for k, v in ipairs(self.frame.bags[bag]) do |
||
652 | self:SetBorderColor(v) |
||
653 | end |
||
654 | end |
||
655 | |||
656 | if self.frame.bags[bag].size and self.frame.bags[bag].size > 0 then |
||
657 | ContainerFrame_Update(self.frame.bags[bag]) |
||
658 | end |
||
659 | |||
660 | self:DoSlotCounts() |
||
661 | self:Debug(L"%s ran in %s", "UpdateBag", debugprofilestop()) |
||
662 | end |
||
663 | |||
664 | function module:DoSlotCounts() |
||
665 | local usedSlots, usedAmmoSlots, usedSoulSlots, usedProfSlots, ammoQuantity = 0, 0, 0, 0, 0 |
||
666 | |||
667 | for k, bag in self.fBags do |
||
668 | if self.frame.bags[bag] then |
||
669 | local tmp, qty = 0, 0 |
||
670 | for slot = 1, GetContainerNumSlots(bag) do |
||
671 | local texture, itemCount = GetContainerItemInfo(bag, slot); |
||
672 | if( texture) then |
||
673 | tmp = tmp + 1 |
||
674 | qty = qty + itemCount |
||
675 | end |
||
676 | end |
||
677 | |||
678 | if self.frame.bags[bag].isAmmo then |
||
679 | usedAmmoSlots = usedAmmoSlots + tmp |
||
680 | ammoQuantity = ammoQuantity + qty |
||
681 | elseif self.frame.bags[bag].isSoul then |
||
682 | usedSoulSlots = usedSoulSlots + tmp |
||
683 | elseif self.frame.bags[bag].isProf then |
||
684 | usedProfSlots = usedProfSlots + tmp |
||
685 | else |
||
686 | usedSlots = usedSlots + tmp |
||
687 | end |
||
688 | end |
||
689 | end |
||
690 | |||
691 | self:Debug(L"Normal used: %s, Soul used: %s, Prof used: %s, Ammo used %s, Ammo quantity %s.", usedSlots, usedSoulSlots, usedProfSlots, usedAmmoSlots, ammoQuantity) |
||
692 | |||
693 | local info = 1 |
||
694 | local name = self.frame:GetName() .. "Info" |
||
695 | |||
696 | |||
697 | getglobal(name .. info):SetText(format(L"%s/%s Slots", usedSlots, self.slotCount)) |
||
698 | |||
699 | info = info + 1 |
||
700 | |||
701 | for i = 2, 4 do |
||
702 | getglobal(name .. i):SetText("") |
||
703 | end |
||
704 | |||
705 | if self.db.profile.show.counts then |
||
706 | if self.ammoSlots > 0 then |
||
707 | getglobal(name .. info):SetText(format(L"%s/%s Ammo", ammoQuantity, self.ammoSlots * 200)) |
||
708 | info = info + 1 |
||
709 | end |
||
710 | if self.soulSlots > 0 then |
||
711 | getglobal(name .. info):SetText(format(L"%s/%s Soul Shards", usedSoulSlots, self.soulSlots)) |
||
712 | info = info + 1 |
||
713 | end |
||
714 | if self.profSlots > 0 then |
||
715 | getglobal(name .. info):SetText(format(L"%s/%s Profession Slots", usedProfSlots, self.profSlots)) |
||
716 | info = info + 1 |
||
717 | end |
||
718 | end |
||
719 | end |
||
720 | |||
721 | function module:ShouldShow(bag, isAmmo, isSoul, isProf) |
||
722 | local show = true |
||
723 | |||
724 | show = show and self.db.profile.show[bag] or false |
||
725 | |||
726 | if isAmmo then |
||
727 | show = show and self.db.profile.show.ammo or false |
||
728 | elseif isSoul then |
||
729 | show = show and self.db.profile.show.soul or false |
||
730 | elseif isProf then |
||
731 | show = show and self.db.profile.show.prof or false |
||
732 | end |
||
733 | return (show or self.frame.bags[bag].colorLocked ) |
||
734 | end |
||
735 | |||
736 | function module:OpenMenu() |
||
737 | if self.dewdrop:IsOpen(getglobal(self.frame:GetName() .. "ConfigButton")) then |
||
738 | self.dewdrop:Close() |
||
739 | else |
||
740 | self.dewdrop:Open(getglobal(self.frame:GetName() .. "ConfigButton"), self.frame) |
||
741 | end |
||
742 | end |
||
743 | |||
744 | function module:MrPlow() |
||
745 | MrPlow:Works(self.isBank and "bank" or nil) |
||
746 | end |
||
747 | |||
748 | function module:OnBaseShow() |
||
749 | this:SetScale(self.db.profile.scale) |
||
750 | this:SetAlpha(self.db.profile.alpha) |
||
751 | this:SetFrameStrata(self.stratas[self.db.profile.strata]) |
||
752 | StackSplitFrame:SetFrameStrata(self.stratas[self.db.profile.strata+1]) |
||
753 | |||
754 | local color = self.db.profile.colors.bground |
||
755 | this:SetBackdropColor(color.r, color.g, color.b, color.a) |
||
756 | |||
757 | self.frame:SetClampedToScreen(self.db.profile.clamped or false) |
||
758 | end |
||
759 | |||
760 | function module:OnShow() |
||
761 | self:OnBaseShow() |
||
762 | self:OnCustomShow() |
||
763 | PlaySound("igBackPackOpen") |
||
764 | |||
765 | if self.frame.bagFrame and self.frame.bagFrame.wasShown then |
||
766 | self.frame.bagFrame:Show() |
||
767 | self.frame.bagFrame.wasShown = false |
||
768 | end |
||
769 | |||
770 | self:BuildFrame() |
||
771 | self:OrganizeFrame() |
||
772 | for k, i in self.fBags do |
||
773 | self:UpdateBag(i) |
||
774 | end |
||
775 | |||
776 | if self.frame.bags[-1] and (not self.frame.bags[-1].colorLocked) then |
||
777 | for k, v in ipairs(self.frame.bags[-1]) do |
||
778 | self:SetBorderColor(v) |
||
779 | end |
||
780 | end |
||
781 | |||
782 | self:DoSlotCounts() |
||
783 | end |
||
784 | |||
785 | function module:OnCustomShow() end -- Meant to be overridden |
||
786 | |||
787 | function module:OnBaseHide() |
||
788 | if self.dewdrop and self.dewdrop:IsOpen(getglobal(self.frame:GetName() .. "ConfigButton")) then |
||
789 | self.dewdrop:Close() |
||
790 | end |
||
791 | end |
||
792 | |||
793 | function module:OnHide() |
||
794 | self:OnBaseHide() |
||
795 | self:OnCustomHide() |
||
796 | PlaySound("igBackPackClose") |
||
797 | if self.frame.bagFrame and self.frame.bagFrame:IsVisible() then |
||
798 | self.frame.bagFrame:Hide() |
||
799 | self.frame.bagFrame.wasShown = true |
||
800 | end |
||
801 | end |
||
802 | |||
803 | function module:OnCustomHide() end -- Meant to be overridden |
||
804 | |||
805 | |||
806 | function module:RegisterDewdrop(baseArgs) |
||
807 | self.dewdrop = AceLibrary("Dewdrop-2.0") |
||
808 | self.dewdrop:Register(self.frame, |
||
809 | 'children', baseArgs, |
||
810 | 'point', function(parent) |
||
811 | if parent:GetTop() < GetScreenHeight() / 2 then |
||
812 | return "BOTTOMRIGHT", "TOPRIGHT" |
||
813 | else |
||
814 | return "TOPRIGHT", "BOTTOMRIGHT" |
||
815 | end |
||
816 | end, |
||
817 | 'dontHook', true |
||
818 | ) |
||
819 | end |