Zerotorescue@11
|
1 -- You can access this addon's object through: LibStub("AceAddon-3.0"):GetAddon("Inventorium")
|
Zerotorescue@17
|
2 local addon = select(2, ...);
|
Zerotorescue@17
|
3 addon = LibStub("AceAddon-3.0"):NewAddon(addon, "Inventorium", "AceEvent-3.0");
|
Zerotorescue@1
|
4
|
Zerotorescue@122
|
5 local _G = _G;
|
Zerotorescue@122
|
6 local sformat, ssplit, slower, strim, smatch = _G.string.format, _G.string.split, _G.string.lower, _G.string.trim, _G.string.match;
|
Zerotorescue@128
|
7 local floor, print, pairs, tonumber = _G.floor, _G.print, _G.pairs, _G.tonumber;
|
Zerotorescue@122
|
8
|
Zerotorescue@61
|
9 --@debug@
|
Zerotorescue@180
|
10 local addonRevision = 1; -- used to update the database whenever required
|
Zerotorescue@61
|
11 --@end-debug@
|
Zerotorescue@61
|
12 --[===[@non-debug@
|
Zerotorescue@61
|
13 local addonRevision = @project-revision@;
|
Zerotorescue@61
|
14 --@end-non-debug@]===]
|
Zerotorescue@61
|
15
|
Zerotorescue@62
|
16 -- All modules must be able to retrieve our supported addons database, thus keep it a part of the addon object rather than local
|
Zerotorescue@13
|
17 addon.supportedAddons = {};
|
Zerotorescue@13
|
18 addon.supportedAddons.auctionPricing = {};
|
Zerotorescue@13
|
19 addon.supportedAddons.itemCount = {};
|
Zerotorescue@13
|
20 addon.supportedAddons.crafting = {};
|
Zerotorescue@0
|
21
|
Zerotorescue@120
|
22 addon.Locations = {
|
Zerotorescue@120
|
23 ["Bag"] = "Bag",
|
Zerotorescue@120
|
24 ["Bank"] = "Bank",
|
Zerotorescue@120
|
25 ["Guild"] = "Guild",
|
Zerotorescue@120
|
26 ["Mailbox"] = "Mailbox",
|
Zerotorescue@120
|
27 ["Merchant"] = "Merchant",
|
Zerotorescue@120
|
28 };
|
Zerotorescue@120
|
29
|
Zerotorescue@0
|
30 function addon:OnInitialize()
|
Zerotorescue@0
|
31 -- SAVED VARIABLES
|
Zerotorescue@0
|
32
|
Zerotorescue@0
|
33 local defaults = {
|
Zerotorescue@0
|
34 global = {
|
Zerotorescue@61
|
35 version = nil,
|
Zerotorescue@61
|
36 },
|
Zerotorescue@61
|
37 profile = {
|
Zerotorescue@0
|
38 defaults = {
|
Zerotorescue@157
|
39 -- General
|
Zerotorescue@13
|
40 auctionPricingAddon = "Auctioneer",
|
Zerotorescue@192
|
41 itemCountAddon = "DataStore (with guilds)",
|
Zerotorescue@13
|
42 craftingAddon = "AdvancedTradeSkillWindow",
|
Zerotorescue@157
|
43 trackAtCharacters = { },
|
Zerotorescue@176
|
44 dontAlertAtCharacters = { },
|
Zerotorescue@157
|
45 localItemData = {
|
Zerotorescue@157
|
46 ["Bag"] = true,
|
Zerotorescue@157
|
47 ["Auction House"] = true,
|
Zerotorescue@157
|
48 },
|
Zerotorescue@157
|
49
|
Zerotorescue@157
|
50 -- Minimumm stock
|
Zerotorescue@61
|
51 minLocalStock = 20,
|
Zerotorescue@57
|
52 alertBelowLocalMinimum = true,
|
Zerotorescue@82
|
53 autoRefill = true,
|
Zerotorescue@101
|
54 autoRefillSkipConfirm = false,
|
Zerotorescue@193
|
55 minGlobalStock = 40,
|
Zerotorescue@61
|
56 alertBelowGlobalMinimum = true,
|
Zerotorescue@157
|
57
|
Zerotorescue@157
|
58 -- Queueing
|
Zerotorescue@193
|
59 restockTarget = 40,
|
Zerotorescue@0
|
60 minCraftingQueue = 0.05,
|
Zerotorescue@193
|
61 bonusQueue = 100, -- 10.000%
|
Zerotorescue@0
|
62 priceThreshold = 0,
|
Zerotorescue@157
|
63
|
Zerotorescue@157
|
64 -- Summary
|
Zerotorescue@157
|
65 summaryThresholdShow = 10,
|
Zerotorescue@13
|
66 summaryHidePriceThreshold = false,
|
Zerotorescue@157
|
67
|
Zerotorescue@157
|
68 -- Global (can't be overridden)
|
Zerotorescue@210
|
69 minimapIcon = true,
|
Zerotorescue@106
|
70 hideHelp = false,
|
Zerotorescue@176
|
71 scanInterval = "0.1", -- string because the associated select requires it to be
|
Zerotorescue@13
|
72 summary = {
|
Zerotorescue@193
|
73 speed = 20,
|
Zerotorescue@74
|
74 width = 700,
|
Zerotorescue@13
|
75 height = 600,
|
Zerotorescue@13
|
76 },
|
Zerotorescue@0
|
77 colors = {
|
Zerotorescue@17
|
78 red = 0,
|
Zerotorescue@17
|
79 orange = 0.3,
|
Zerotorescue@17
|
80 yellow = 0.6,
|
Zerotorescue@17
|
81 green = 0.95,
|
Zerotorescue@0
|
82 },
|
Zerotorescue@157
|
83 itemCountGuildsExcluded = { },
|
Zerotorescue@0
|
84 },
|
Zerotorescue@61
|
85 groups = {
|
Zerotorescue@140
|
86 -- items = {},
|
Zerotorescue@140
|
87 -- isVirtual = nil,
|
Zerotorescue@61
|
88 },
|
Zerotorescue@0
|
89 },
|
Zerotorescue@0
|
90 factionrealm = {
|
Zerotorescue@40
|
91 characters = {
|
Zerotorescue@40
|
92 },
|
Zerotorescue@0
|
93 },
|
Zerotorescue@0
|
94 };
|
Zerotorescue@0
|
95
|
Zerotorescue@0
|
96 -- Register our saved variables database
|
Zerotorescue@11
|
97 self.db = LibStub("AceDB-3.0"):New("InventoriumDB", defaults, true);
|
Zerotorescue@61
|
98
|
Zerotorescue@62
|
99 -- SLASH COMMANDS
|
Zerotorescue@62
|
100
|
Zerotorescue@62
|
101 -- Disable the AddonLoader slash commands
|
Zerotorescue@62
|
102 SLASH_INVENTORIUM1 = nil;
|
Zerotorescue@62
|
103 SLASH_IM1 = nil;
|
Zerotorescue@62
|
104
|
Zerotorescue@62
|
105 -- Register our own slash commands
|
Zerotorescue@62
|
106 SLASH_INVENTORIUM1 = "/inventorium";
|
Zerotorescue@62
|
107 SLASH_INVENTORIUM2 = "/im";
|
Zerotorescue@62
|
108 SlashCmdList["INVENTORIUM"] = function(msg)
|
Zerotorescue@62
|
109 addon:CommandHandler(msg);
|
Zerotorescue@62
|
110 end;
|
Zerotorescue@62
|
111
|
Zerotorescue@62
|
112 -- Debug command handling
|
Zerotorescue@62
|
113 self:RegisterSlash(function(this)
|
Zerotorescue@62
|
114 this.debugChannel = false;
|
Zerotorescue@62
|
115 for i = 1, NUM_CHAT_WINDOWS do
|
Zerotorescue@62
|
116 local name = GetChatWindowInfo(i);
|
Zerotorescue@62
|
117
|
Zerotorescue@176
|
118 if string.upper(name) == "IMDEBUG" then
|
Zerotorescue@128
|
119 addon:Print("A debug channel already exists, removing the old one... (" .. i .. ")");
|
Zerotorescue@128
|
120 FCF_Close(_G["ChatFrame" .. i]);
|
Zerotorescue@62
|
121 end
|
Zerotorescue@62
|
122 end
|
Zerotorescue@62
|
123
|
Zerotorescue@62
|
124 if not this.debugChannel then
|
Zerotorescue@62
|
125 -- Create a new debug channel
|
Zerotorescue@176
|
126 local chatFrame = FCF_OpenNewWindow('IMDebug');
|
Zerotorescue@62
|
127 ChatFrame_RemoveAllMessageGroups(chatFrame);
|
Zerotorescue@62
|
128 this.debugChannel = chatFrame;
|
Zerotorescue@62
|
129
|
Zerotorescue@98
|
130 addon:Print("New debug channel created.");
|
Zerotorescue@62
|
131 end
|
Zerotorescue@176
|
132 end, { "d", "debug", "imdebug" });
|
Zerotorescue@62
|
133
|
Zerotorescue@62
|
134 -- Remember this character is on this account
|
Zerotorescue@62
|
135 local playerName = UnitName("player");
|
Zerotorescue@62
|
136 if not self.db.factionrealm.characters[playerName] then
|
Zerotorescue@62
|
137 self.db.factionrealm.characters[playerName] = true;
|
Zerotorescue@62
|
138
|
Zerotorescue@62
|
139 -- Default to tracking on all chars, untracking is a convenience, not tracking by default would probably get multiple issue reports.
|
Zerotorescue@62
|
140 self.db.profile.defaults.trackAtCharacters[playerName] = true;
|
Zerotorescue@62
|
141 end
|
Zerotorescue@66
|
142
|
Zerotorescue@66
|
143 self:UpdateDatabase();
|
Zerotorescue@62
|
144 end
|
Zerotorescue@62
|
145
|
Zerotorescue@65
|
146
|
Zerotorescue@65
|
147
|
Zerotorescue@65
|
148
|
Zerotorescue@65
|
149
|
Zerotorescue@65
|
150 -- Database patching after new revisions
|
Zerotorescue@65
|
151
|
Zerotorescue@62
|
152 function addon:UpdateDatabase()
|
Zerotorescue@61
|
153 if not self.db.global.version or self.db.global.version < addonRevision then
|
Zerotorescue@61
|
154 -- Is our database outdated? Then patch it.
|
Zerotorescue@61
|
155
|
Zerotorescue@61
|
156 if not self.db.global.version then
|
Zerotorescue@61
|
157 -- Old version was before version was saved, many changes were done in that revision
|
Zerotorescue@61
|
158
|
Zerotorescue@98
|
159 addon:Print("Updating Inventorium database from version " .. (self.db.global.version or "Unknown") .. " to version " .. addonRevision .. "...");
|
Zerotorescue@61
|
160
|
Zerotorescue@61
|
161 if self.db.global and self.db.global.defaults then
|
Zerotorescue@98
|
162 addon:Print("Moving all global data into your current profile...");
|
Zerotorescue@61
|
163
|
Zerotorescue@61
|
164 -- All data mustn't be global but profile-based
|
Zerotorescue@61
|
165 self.db.profile.defaults = CopyTable(self.db.global.defaults);
|
Zerotorescue@61
|
166 self.db.profile.groups = CopyTable(self.db.global.groups);
|
Zerotorescue@61
|
167
|
Zerotorescue@61
|
168 self.db.global.defaults = nil;
|
Zerotorescue@61
|
169 self.db.global.groups = nil;
|
Zerotorescue@61
|
170
|
Zerotorescue@62
|
171 self.CommandHandler = function()
|
Zerotorescue@62
|
172 message("You must /reload once to finalize the Inventorium database updates. This will only be required once during the BETA.");
|
Zerotorescue@61
|
173 end;
|
Zerotorescue@62
|
174 self:CommandHandler();
|
Zerotorescue@61
|
175 end
|
Zerotorescue@61
|
176
|
Zerotorescue@61
|
177 if self.db.profile.defaults.minimumStock then
|
Zerotorescue@98
|
178 addon:Print("Copying the minimum stock value into the minimum global stock...");
|
Zerotorescue@61
|
179
|
Zerotorescue@61
|
180 -- We added another stock option and renamed the old to be more obvious about what it means
|
Zerotorescue@61
|
181 self.db.profile.defaults.minGlobalStock = self.db.profile.defaults.minimumStock;
|
Zerotorescue@61
|
182 self.db.profile.defaults.minimumStock = nil;
|
Zerotorescue@61
|
183 end
|
Zerotorescue@61
|
184
|
Zerotorescue@61
|
185 if self.db.profile.defaults.minimumLocalStock then
|
Zerotorescue@98
|
186 addon:Print("Renaming the minimum local stock property...");
|
Zerotorescue@61
|
187
|
Zerotorescue@61
|
188 -- We added another stock option and then renamed it
|
Zerotorescue@61
|
189 self.db.profile.defaults.minLocalStock = self.db.profile.defaults.minimumLocalStock;
|
Zerotorescue@61
|
190 self.db.profile.defaults.minimumLocalStock = nil;
|
Zerotorescue@61
|
191 end
|
Zerotorescue@61
|
192
|
Zerotorescue@61
|
193 if self.db.profile.defaults.alertBelowMinimum then
|
Zerotorescue@98
|
194 addon:Print("Copying the alert below minimum value into the alert below global minimum value...");
|
Zerotorescue@61
|
195
|
Zerotorescue@61
|
196 -- We added another stock option and then renamed it
|
Zerotorescue@61
|
197 self.db.profile.defaults.alertBelowGlobalMinimum = self.db.profile.defaults.alertBelowMinimum;
|
Zerotorescue@61
|
198 self.db.profile.defaults.alertBelowMinimum = nil;
|
Zerotorescue@61
|
199 end
|
Zerotorescue@61
|
200
|
Zerotorescue@61
|
201 -- Go through all groups to see if there's one with the above two renamed variables
|
Zerotorescue@61
|
202 for groupName, values in pairs(self.db.profile.groups) do
|
Zerotorescue@61
|
203 if values.minimumStock then
|
Zerotorescue@61
|
204 values.minGlobalStock = values.minimumStock;
|
Zerotorescue@61
|
205 values.minimumStock = nil;
|
Zerotorescue@61
|
206 end
|
Zerotorescue@61
|
207 end
|
Zerotorescue@180
|
208 -- end of old version which didn't have version numbers recorded
|
Zerotorescue@61
|
209 end
|
Zerotorescue@61
|
210
|
Zerotorescue@61
|
211 -- Remember the version of our database
|
Zerotorescue@61
|
212 self.db.global.version = addonRevision;
|
Zerotorescue@61
|
213 end
|
Zerotorescue@46
|
214 end
|
Zerotorescue@46
|
215
|
Zerotorescue@62
|
216 function addon:GetOptionByKey(groupName, optionName, noDefault)
|
Zerotorescue@62
|
217 if groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName][optionName] ~= nil then
|
Zerotorescue@62
|
218 -- If this option exists within the settings of this group
|
Zerotorescue@62
|
219
|
Zerotorescue@62
|
220 return addon.db.profile.groups[groupName][optionName];
|
Zerotorescue@62
|
221 elseif groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName].virtualGroup ~= "" and not noDefault then
|
Zerotorescue@62
|
222 -- If a virtual group was selected
|
Zerotorescue@62
|
223
|
Zerotorescue@62
|
224 return self:GetOptionByKey(addon.db.profile.groups[groupName].virtualGroup, optionName, noDefault);
|
Zerotorescue@62
|
225 elseif addon.db.profile.defaults[optionName] and not noDefault then
|
Zerotorescue@62
|
226 return addon.db.profile.defaults[optionName];
|
Zerotorescue@62
|
227 else
|
Zerotorescue@62
|
228 return nil;
|
Zerotorescue@0
|
229 end
|
Zerotorescue@0
|
230 end
|
Zerotorescue@0
|
231
|
Zerotorescue@35
|
232 function addon:GetItemCountAddon(group)
|
Zerotorescue@35
|
233 local selectedExternalAddon = self:GetOptionByKey(group, "itemCountAddon");
|
Zerotorescue@35
|
234
|
Zerotorescue@35
|
235 if self.supportedAddons.itemCount[selectedExternalAddon] and self.supportedAddons.itemCount[selectedExternalAddon].IsEnabled() then
|
Zerotorescue@35
|
236 -- Try to use the default item count addon
|
Zerotorescue@35
|
237
|
Zerotorescue@157
|
238 if self.supportedAddons.itemCount[selectedExternalAddon].SetGuildState then
|
Zerotorescue@157
|
239 self.supportedAddons.itemCount[selectedExternalAddon].SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded);
|
Zerotorescue@157
|
240 end
|
Zerotorescue@157
|
241
|
Zerotorescue@35
|
242 return self.supportedAddons.itemCount[selectedExternalAddon], selectedExternalAddon;
|
Zerotorescue@35
|
243 else
|
Zerotorescue@35
|
244 -- Default not available, get the first one then
|
Zerotorescue@35
|
245
|
Zerotorescue@35
|
246 for name, value in pairs(self.supportedAddons.itemCount) do
|
Zerotorescue@35
|
247 if value.IsEnabled() then
|
Zerotorescue@157
|
248 if value.SetGuildState then
|
Zerotorescue@157
|
249 value.SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded);
|
Zerotorescue@157
|
250 end
|
Zerotorescue@157
|
251
|
Zerotorescue@35
|
252 return value, name;
|
Zerotorescue@35
|
253 end
|
Zerotorescue@35
|
254 end
|
Zerotorescue@35
|
255 end
|
Zerotorescue@35
|
256
|
Zerotorescue@35
|
257 return;
|
Zerotorescue@35
|
258 end
|
Zerotorescue@35
|
259
|
Zerotorescue@23
|
260 function addon:GetItemCount(itemId, group)
|
Zerotorescue@13
|
261 itemId = tonumber(itemId);
|
Zerotorescue@13
|
262
|
Zerotorescue@13
|
263 if not itemId then return; end
|
Zerotorescue@13
|
264
|
Zerotorescue@35
|
265 local itemCountAddon = self:GetItemCountAddon(group);
|
Zerotorescue@23
|
266
|
Zerotorescue@35
|
267 return (itemCountAddon and itemCountAddon.GetTotalCount(itemId)) or -1;
|
Zerotorescue@0
|
268 end
|
Zerotorescue@0
|
269
|
Zerotorescue@50
|
270 function addon:GetLocalItemCount(itemId, group)
|
Zerotorescue@50
|
271 itemId = tonumber(itemId);
|
Zerotorescue@50
|
272
|
Zerotorescue@50
|
273 if not itemId then return; end
|
Zerotorescue@50
|
274
|
Zerotorescue@50
|
275 local itemCountAddon = self:GetItemCountAddon(group);
|
Zerotorescue@50
|
276
|
Zerotorescue@50
|
277 local currentItemCount;
|
Zerotorescue@50
|
278
|
Zerotorescue@50
|
279 if itemCountAddon and itemCountAddon.GetCharacterCount then
|
Zerotorescue@50
|
280 local bag, bank, auctionHouse, mail = itemCountAddon.GetCharacterCount(itemId);
|
Zerotorescue@50
|
281
|
Zerotorescue@50
|
282 local selectedLocalItemCountSources = self:GetOptionByKey(group, "localItemData");
|
Zerotorescue@50
|
283
|
Zerotorescue@50
|
284 currentItemCount = 0;
|
Zerotorescue@50
|
285 if selectedLocalItemCountSources["Bag"] then
|
Zerotorescue@50
|
286 currentItemCount = currentItemCount + bag;
|
Zerotorescue@50
|
287 end
|
Zerotorescue@50
|
288 if selectedLocalItemCountSources["Bank"] then
|
Zerotorescue@50
|
289 currentItemCount = currentItemCount + bank;
|
Zerotorescue@50
|
290 end
|
Zerotorescue@50
|
291 if selectedLocalItemCountSources["Auction House"] then
|
Zerotorescue@50
|
292 currentItemCount = currentItemCount + auctionHouse;
|
Zerotorescue@50
|
293 end
|
Zerotorescue@50
|
294 if selectedLocalItemCountSources["Mailbox"] then
|
Zerotorescue@50
|
295 currentItemCount = currentItemCount + mail;
|
Zerotorescue@50
|
296 end
|
Zerotorescue@50
|
297 end
|
Zerotorescue@50
|
298
|
Zerotorescue@50
|
299 return currentItemCount or -1;
|
Zerotorescue@50
|
300 end
|
Zerotorescue@50
|
301
|
Zerotorescue@23
|
302 function addon:GetAuctionValue(itemLink, group)
|
Zerotorescue@23
|
303 if not itemLink then return -5; end
|
Zerotorescue@13
|
304
|
Zerotorescue@23
|
305 local selectedExternalAddon = self:GetOptionByKey(group, "auctionPricingAddon");
|
Zerotorescue@23
|
306
|
Zerotorescue@23
|
307 if self.supportedAddons.auctionPricing[selectedExternalAddon] and self.supportedAddons.auctionPricing[selectedExternalAddon].IsEnabled() then
|
Zerotorescue@13
|
308 -- Try to use the default auction pricing addon
|
Zerotorescue@1
|
309
|
Zerotorescue@23
|
310 return self.supportedAddons.auctionPricing[selectedExternalAddon].GetValue(itemLink);
|
Zerotorescue@13
|
311 else
|
Zerotorescue@13
|
312 -- Default not available, get the first one then
|
Zerotorescue@1
|
313
|
Zerotorescue@13
|
314 for name, value in pairs(self.supportedAddons.auctionPricing) do
|
Zerotorescue@13
|
315 if value.IsEnabled() then
|
Zerotorescue@13
|
316 return value.GetValue(itemLink);
|
Zerotorescue@13
|
317 end
|
Zerotorescue@1
|
318 end
|
Zerotorescue@1
|
319 end
|
Zerotorescue@7
|
320
|
Zerotorescue@7
|
321 return -2;
|
Zerotorescue@1
|
322 end
|
Zerotorescue@1
|
323
|
Zerotorescue@65
|
324
|
Zerotorescue@65
|
325
|
Zerotorescue@65
|
326
|
Zerotorescue@65
|
327
|
Zerotorescue@62
|
328 -- Slash commands
|
Zerotorescue@62
|
329
|
Zerotorescue@62
|
330 local slashArgs = {};
|
Zerotorescue@62
|
331 local slashError = "Wrong argument, the following arguments are available:";
|
Zerotorescue@62
|
332
|
Zerotorescue@62
|
333 function addon:CommandHandler(message)
|
Zerotorescue@122
|
334 local cmd, arg = ssplit(" ", (message or ""), 2);
|
Zerotorescue@122
|
335 cmd = slower(cmd);
|
Zerotorescue@62
|
336
|
Zerotorescue@62
|
337 if slashArgs[cmd] then
|
Zerotorescue@62
|
338 -- Pass a reference to the addon (to be used as "self") and the provided arg
|
Zerotorescue@62
|
339 slashArgs[cmd](addon, arg);
|
Zerotorescue@62
|
340 else
|
Zerotorescue@98
|
341 addon:Print(slashError);
|
Zerotorescue@62
|
342 end
|
Zerotorescue@62
|
343 end
|
Zerotorescue@62
|
344
|
Zerotorescue@62
|
345 function addon:RegisterSlash(func, args, description)
|
Zerotorescue@62
|
346 for _, arg in pairs(args) do
|
Zerotorescue@62
|
347 slashArgs[arg] = func;
|
Zerotorescue@62
|
348 end
|
Zerotorescue@62
|
349
|
Zerotorescue@62
|
350 if description then
|
Zerotorescue@62
|
351 slashError = slashError .. "\n" .. description;
|
Zerotorescue@62
|
352 end
|
Zerotorescue@62
|
353 end
|
Zerotorescue@62
|
354
|
Zerotorescue@65
|
355
|
Zerotorescue@65
|
356
|
Zerotorescue@65
|
357
|
Zerotorescue@65
|
358
|
Zerotorescue@106
|
359 function addon:ColorCode(num, required)
|
Zerotorescue@106
|
360 local percentage = ( num / required );
|
Zerotorescue@106
|
361
|
Zerotorescue@106
|
362 if percentage >= addon.db.profile.defaults.colors.green then
|
Zerotorescue@106
|
363 return sformat("|cff00ff00%d|r", num);
|
Zerotorescue@106
|
364 elseif percentage >= addon.db.profile.defaults.colors.yellow then
|
Zerotorescue@106
|
365 return sformat("|cffffff00%d|r", num);
|
Zerotorescue@106
|
366 elseif percentage >= addon.db.profile.defaults.colors.orange then
|
Zerotorescue@106
|
367 return sformat("|cffff9933%d|r", num);
|
Zerotorescue@106
|
368 elseif percentage >= addon.db.profile.defaults.colors.red then
|
Zerotorescue@106
|
369 return sformat("|cffff0000%d|r", num);
|
Zerotorescue@106
|
370 else
|
Zerotorescue@106
|
371 return num;
|
Zerotorescue@106
|
372 end
|
Zerotorescue@106
|
373 end
|
Zerotorescue@106
|
374
|
Zerotorescue@106
|
375 function addon:DisplayItemCount(value, minimumStock)
|
Zerotorescue@106
|
376 if value == -1 then
|
Zerotorescue@106
|
377 return "|cffffff00Unknown|r";
|
Zerotorescue@188
|
378 elseif value == -2 then
|
Zerotorescue@188
|
379 return "|cffffff00-|r";
|
Zerotorescue@106
|
380 elseif value == -3 then
|
Zerotorescue@106
|
381 return "|cffffff00Unknown|r";
|
Zerotorescue@106
|
382 else
|
Zerotorescue@106
|
383 return sformat("%s / %d", self:ColorCode(value, minimumStock), minimumStock);
|
Zerotorescue@106
|
384 end
|
Zerotorescue@106
|
385 end
|
Zerotorescue@106
|
386
|
Zerotorescue@62
|
387 -- Readable money
|
Zerotorescue@62
|
388
|
Zerotorescue@62
|
389 local goldText = "%s%d|cffffd700g|r ";
|
Zerotorescue@62
|
390 local silverText = "%s%d|cffc7c7cfs|r ";
|
Zerotorescue@62
|
391 local copperText = "%s%d|cffeda55fc|r";
|
Zerotorescue@62
|
392
|
Zerotorescue@62
|
393 function addon:ReadableMoney(copper, clean)
|
Zerotorescue@62
|
394 local text = "";
|
Zerotorescue@62
|
395
|
Zerotorescue@128
|
396 local gold = floor( copper / COPPER_PER_GOLD );
|
Zerotorescue@62
|
397 if gold > 0 then
|
Zerotorescue@106
|
398 text = sformat(goldText, text, gold);
|
Zerotorescue@62
|
399 end
|
Zerotorescue@62
|
400
|
Zerotorescue@62
|
401 if not clean or (not gold or gold < 10) then
|
Zerotorescue@128
|
402 local silver = floor( ( copper % COPPER_PER_GOLD ) / COPPER_PER_SILVER );
|
Zerotorescue@62
|
403 if silver > 0 then
|
Zerotorescue@106
|
404 text = sformat(silverText, text, silver);
|
Zerotorescue@62
|
405 end
|
Zerotorescue@62
|
406
|
Zerotorescue@62
|
407 if not clean or (not gold or gold < 1) then
|
Zerotorescue@128
|
408 local copper = floor( copper % COPPER_PER_SILVER );
|
Zerotorescue@62
|
409 if copper > 0 or text == "" then
|
Zerotorescue@106
|
410 text = sformat(copperText, text, copper);
|
Zerotorescue@62
|
411 end
|
Zerotorescue@62
|
412 end
|
Zerotorescue@62
|
413 end
|
Zerotorescue@62
|
414
|
Zerotorescue@62
|
415
|
Zerotorescue@122
|
416 return strim(text);
|
Zerotorescue@62
|
417 end
|
Zerotorescue@62
|
418
|
Zerotorescue@62
|
419 function addon:ReadableMoneyToCopper(value)
|
Zerotorescue@62
|
420 -- If a player enters a value it will be filled without color codes
|
Zerotorescue@62
|
421 -- If it is retrieved from the database, it will be colored coded
|
Zerotorescue@62
|
422 -- Thus we look for both
|
Zerotorescue@122
|
423 local gold = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+g|r") or smatch(value, "(%d+)g"));
|
Zerotorescue@122
|
424 local silver = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+s|r") or smatch(value, "(%d+)s"));
|
Zerotorescue@122
|
425 local copper = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+c|r") or smatch(value, "(%d+)c"));
|
Zerotorescue@62
|
426
|
Zerotorescue@62
|
427 return ( (gold or 0) * COPPER_PER_GOLD ) + ( (silver or 0) * COPPER_PER_SILVER ) + (copper or 0);
|
Zerotorescue@62
|
428 end
|
Zerotorescue@62
|
429
|
Zerotorescue@62
|
430 function addon:ValidateReadableMoney(info, value)
|
Zerotorescue@62
|
431 -- If a player enters a value it will be filled without color codes
|
Zerotorescue@62
|
432 -- If it is retrieved from the database, it will be colored coded
|
Zerotorescue@62
|
433 -- Thus we look for both
|
Zerotorescue@122
|
434 local gold = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+g|r") or smatch(value, "(%d+)g"));
|
Zerotorescue@122
|
435 local silver = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+s|r") or smatch(value, "(%d+)s"));
|
Zerotorescue@122
|
436 local copper = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+c|r") or smatch(value, "(%d+)c"));
|
Zerotorescue@62
|
437
|
Zerotorescue@62
|
438 if not gold and not silver and not copper then
|
Zerotorescue@62
|
439 return "The provided amount of money is invalid. Please provide the amount of money as #g#s#c, e.g. 591617g24s43c.";
|
Zerotorescue@62
|
440 else
|
Zerotorescue@62
|
441 return true;
|
Zerotorescue@62
|
442 end
|
Zerotorescue@62
|
443 end
|
Zerotorescue@62
|
444
|
Zerotorescue@0
|
445
|
Zerotorescue@0
|
446
|
Zerotorescue@65
|
447
|
Zerotorescue@65
|
448
|
Zerotorescue@13
|
449 -- Public
|
Zerotorescue@13
|
450
|
Zerotorescue@36
|
451 function IMRegisterPricingAddon(name, get, enabled, onSelect)
|
Zerotorescue@13
|
452 addon.supportedAddons.auctionPricing[name] = {
|
Zerotorescue@156
|
453 ["GetValue"] = get,
|
Zerotorescue@156
|
454 ["IsEnabled"] = enabled,
|
Zerotorescue@156
|
455 ["OnSelect"] = onSelect,
|
Zerotorescue@13
|
456 };
|
Zerotorescue@13
|
457 end
|
Zerotorescue@13
|
458
|
Zerotorescue@156
|
459 function IMRegisterItemCountAddon(name, getTotal, getCharacter, enabled, onSelect, getGuildNames, setGuildState)
|
Zerotorescue@13
|
460 addon.supportedAddons.itemCount[name] = {
|
Zerotorescue@156
|
461 ["GetTotalCount"] = getTotal,
|
Zerotorescue@156
|
462 ["GetCharacterCount"] = getCharacter,
|
Zerotorescue@156
|
463 ["IsEnabled"] = enabled,
|
Zerotorescue@156
|
464 ["OnSelect"] = onSelect,
|
Zerotorescue@156
|
465 ["GetGuildNames"] = getGuildNames,
|
Zerotorescue@156
|
466 ["SetGuildState"] = setGuildState,
|
Zerotorescue@13
|
467 };
|
Zerotorescue@13
|
468 end
|
Zerotorescue@13
|
469
|
Zerotorescue@50
|
470 function IMRegisterCraftingAddon(name, queue, enabled, onSelect)
|
Zerotorescue@13
|
471 addon.supportedAddons.crafting[name] = {
|
Zerotorescue@156
|
472 ["Queue"] = queue,
|
Zerotorescue@156
|
473 ["IsEnabled"] = enabled,
|
Zerotorescue@156
|
474 ["OnSelect"] = onSelect,
|
Zerotorescue@13
|
475 };
|
Zerotorescue@13
|
476 end
|
Zerotorescue@13
|
477
|
Zerotorescue@62
|
478 -- We need a global command handler for our chat-links
|
Zerotorescue@62
|
479 function InventoriumCommandHandler(msg)
|
Zerotorescue@62
|
480 addon:CommandHandler(msg);
|
Zerotorescue@62
|
481 end
|
Zerotorescue@62
|
482
|
Zerotorescue@13
|
483
|
Zerotorescue@13
|
484
|
Zerotorescue@65
|
485
|
Zerotorescue@65
|
486
|
Zerotorescue@76
|
487 -- General
|
Zerotorescue@76
|
488
|
Zerotorescue@76
|
489 addon.Colors = {
|
Zerotorescue@157
|
490 ["Red"] = { 1, 0, 0 },
|
Zerotorescue@157
|
491 ["Orange"] = { 1, .46, .1 },
|
Zerotorescue@157
|
492 ["Green"] = { 0, 1, 0 },
|
Zerotorescue@157
|
493 ["Blue"] = { 0, 0, 1 },
|
Zerotorescue@157
|
494 ["Yellow"] = { 1, 1, 0 },
|
Zerotorescue@157
|
495 ["Cyan"] = { 0, 1, 1 },
|
Zerotorescue@76
|
496 }; -- easy to extend if more colors are needed
|
Zerotorescue@76
|
497 function addon:Print(text, color)
|
Zerotorescue@76
|
498 local red, green, blue;
|
Zerotorescue@76
|
499
|
Zerotorescue@76
|
500 if color then
|
Zerotorescue@76
|
501 red, green, blue = color[1], color[2], color[3];
|
Zerotorescue@76
|
502 end
|
Zerotorescue@76
|
503
|
Zerotorescue@76
|
504 DEFAULT_CHAT_FRAME:AddMessage(text or "", red, green, blue, nil, 5);
|
Zerotorescue@76
|
505 end
|
Zerotorescue@76
|
506
|
Zerotorescue@95
|
507 function addon:GetItemId(itemLink)
|
Zerotorescue@84
|
508 itemLink = itemLink and itemLink:match("|Hitem:([-0-9]+):"); -- if itemLink is nil, it won't execute the second part
|
Zerotorescue@84
|
509 itemLink = itemLink and tonumber(itemLink);
|
Zerotorescue@84
|
510
|
Zerotorescue@84
|
511 return itemLink;
|
Zerotorescue@84
|
512 end
|
Zerotorescue@84
|
513
|
Zerotorescue@13
|
514 -- Debug
|
Zerotorescue@0
|
515
|
Zerotorescue@176
|
516 local function ReadableTable(t, includeKeys, jumps)
|
Zerotorescue@176
|
517 local tabs = "";
|
Zerotorescue@176
|
518 for i = 1, (jumps or 0) do
|
Zerotorescue@176
|
519 tabs = tabs .. " ";
|
Zerotorescue@176
|
520 end
|
Zerotorescue@176
|
521
|
Zerotorescue@176
|
522 local temp = "{\n";
|
Zerotorescue@176
|
523
|
Zerotorescue@169
|
524 for i, v in pairs(t) do
|
Zerotorescue@169
|
525 if type(v) == "table" then
|
Zerotorescue@176
|
526 if includeKeys then
|
Zerotorescue@188
|
527 local key = (type(i) == "number" and tostring(i)) or sformat("\"%s\"", tostring(i));
|
Zerotorescue@176
|
528
|
Zerotorescue@188
|
529 temp = sformat("%s%s [%s] => %s,\n", temp, tabs, key, ReadableTable(v, includeKeys, (jumps or 0) + 1));
|
Zerotorescue@176
|
530 else
|
Zerotorescue@188
|
531 temp = sformat("%s%s %s,\n", temp, tabs, ReadableTable(v, includeKeys, (jumps or 0) + 1));
|
Zerotorescue@176
|
532 end
|
Zerotorescue@169
|
533 else
|
Zerotorescue@176
|
534 if includeKeys then
|
Zerotorescue@188
|
535 local key = (type(i) == "number" and tostring(i)) or sformat("\"%s\"", tostring(i));
|
Zerotorescue@188
|
536 local value = (type(v) == "number" and tostring(v)) or sformat("\"%s\"", tostring(v));
|
Zerotorescue@176
|
537
|
Zerotorescue@188
|
538 temp = sformat("%s%s [%s] => %s,\n", temp, tabs, key, value);
|
Zerotorescue@176
|
539 else
|
Zerotorescue@188
|
540 local value = (type(v) == "number" and tostring(v)) or sformat("\"%s\"", tostring(v));
|
Zerotorescue@176
|
541
|
Zerotorescue@188
|
542 temp = sformat("%s%s %s,\n", temp, tabs, value);
|
Zerotorescue@176
|
543 end
|
Zerotorescue@169
|
544 end
|
Zerotorescue@169
|
545 end
|
Zerotorescue@176
|
546 temp = temp .. tabs .. "}";
|
Zerotorescue@176
|
547
|
Zerotorescue@169
|
548 return temp;
|
Zerotorescue@169
|
549 end
|
Zerotorescue@169
|
550
|
Zerotorescue@89
|
551 function addon:Debug(t, ...)
|
Zerotorescue@0
|
552 if not self.debugChannel and self.debugChannel ~= false then
|
Zerotorescue@0
|
553 -- We want to check just once, so if you add a debug channel later just do a /reload (registering an event for this is wasted resources)
|
Zerotorescue@0
|
554 self.debugChannel = false;
|
Zerotorescue@0
|
555
|
Zerotorescue@0
|
556 for i = 1, NUM_CHAT_WINDOWS do
|
Zerotorescue@0
|
557 local name = GetChatWindowInfo(i);
|
Zerotorescue@0
|
558
|
Zerotorescue@176
|
559 if name:upper() == "IMDEBUG" then
|
Zerotorescue@0
|
560 self.debugChannel = _G["ChatFrame" .. i];
|
Zerotorescue@0
|
561 end
|
Zerotorescue@0
|
562 end
|
Zerotorescue@0
|
563 end
|
Zerotorescue@0
|
564
|
Zerotorescue@0
|
565 if self.debugChannel then
|
Zerotorescue@169
|
566 if type(t) == "table" then
|
Zerotorescue@176
|
567 t = ReadableTable(t, true);
|
Zerotorescue@169
|
568 end
|
Zerotorescue@169
|
569
|
Zerotorescue@110
|
570 self.debugChannel:AddMessage("|cffffff00Inventorium|r:" .. sformat(t, ...));
|
Zerotorescue@0
|
571 end
|
Zerotorescue@0
|
572 end
|