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