comparison Core.lua @ 36:58fb38f0b447

The list of possible commands when you write /im without any arguement will now include commands inserted by modules with their own descriptions. Clicking a command in this list will now execute it. The slash command handler function is now a global so you can invoke these through other methods. Added an optional event function to registering auction pricing addons, when defined this will be executed when the pricing addon gets selected. Removed the unused ?Override local item data? option. Added ?AuctionProfitMaster? and ?ZeroAuctions? pricing support. The pricing info displayed in the summary window will be used for this. Trying to queue without any items in the summary should no longer give an error.
author Zerotorescue
date Sat, 20 Nov 2010 17:24:16 +0100
parents 31e5da6a2b16
children abc824800387
comparison
equal deleted inserted replaced
35:31e5da6a2b16 36:58fb38f0b447
67 SLASH_IY1 = nil; 67 SLASH_IY1 = nil;
68 68
69 -- Register our own slash commands 69 -- Register our own slash commands
70 SLASH_INVENTORIUM1 = "/inventorium"; 70 SLASH_INVENTORIUM1 = "/inventorium";
71 SLASH_INVENTORIUM2 = "/im"; 71 SLASH_INVENTORIUM2 = "/im";
72 SlashCmdList["INVENTORIUM"] = function(msg) 72 SlashCmdList["INVENTORIUM"] = InventoriumCommandHandler;
73 self:CommandHandler(msg); 73
74 end 74 -- Config command handling
75 75 self:RegisterSlash(function(this)
76 -- We don't want any other windows open at this time.
77 for name, module in this:IterateModules() do
78 if module.CloseFrame then
79 module:CloseFrame();
80 end
81 end
82
83 this:Show();
84 end, { "c", "config", "conf", "option", "options", "opt", "setting", "settings" }, "|Hfunction:InventoriumCommandHandler:config|h|cff00fff7/im config|r|h (or /im c) - Open the config window to change the settings and manage groups.");
85
86 -- Debug command handling
87 self:RegisterSlash(function(this)
88 this.debugChannel = false;
89 for i = 1, NUM_CHAT_WINDOWS do
90 local name = GetChatWindowInfo(i);
91
92 if name:upper() == "DEBUG" then
93 this.debugChannel = _G["ChatFrame" .. i];
94
95 print("A debug channel already exists, used the old one. (" .. i .. ")");
96 return;
97 end
98 end
99
100 if not this.debugChannel then
101 -- Create a new debug channel
102 local chatFrame = FCF_OpenNewWindow('Debug');
103 ChatFrame_RemoveAllMessageGroups(chatFrame);
104 this.debugChannel = chatFrame;
105
106 print("New debug channel created.");
107 end
108 end, { "d", "debug" });
109
76 -- INTERFACE OPTIONS 110 -- INTERFACE OPTIONS
77 111
78 -- Attempt to remove the interface options added by AddonLoader (if enabled) 112 -- Attempt to remove the interface options added by AddonLoader (if enabled)
79 if AddonLoader and AddonLoader.RemoveInterfaceOptions then 113 if AddonLoader and AddonLoader.RemoveInterfaceOptions then
80 AddonLoader:RemoveInterfaceOptions("Inventorium"); 114 AddonLoader:RemoveInterfaceOptions("Inventorium");
194 end 228 end
195 end 229 end
196 end 230 end
197 231
198 232
199 local slashArgs = {};
200 function addon:RegisterSlash(func, ...)
201 for _, arg in pairs({ ... }) do
202 slashArgs[arg] = func;
203 end
204 end
205 233
206 function addon:MakeItemLinkButtonWidget() 234 function addon:MakeItemLinkButtonWidget()
207 --[[ 235 --[[
208 [ ItemLinkButton ] 236 [ ItemLinkButton ]
209 This custom widget has to show an icon with the item link next to it. 237 This custom widget has to show an icon with the item link next to it.
226 254
227 -- We overwrite the OnAcquire as we want to set our callbacks even 255 -- We overwrite the OnAcquire as we want to set our callbacks even
228 -- when the widget is re-used from the widget pool 256 -- when the widget is re-used from the widget pool
229 widget.originalOnAcquire = widget.OnAcquire; 257 widget.originalOnAcquire = widget.OnAcquire;
230 widget.OnAcquire = function(self, ...) 258 widget.OnAcquire = function(self, ...)
231 259
232 260
233 -- We overwrite the setcallback because we don't want anything else 261 -- We overwrite the setcallback because we don't want anything else
234 -- to overwrite our OnEnter, OnLeave and OnClick events 262 -- to overwrite our OnEnter, OnLeave and OnClick events
235 -- which would be done by the AceConfigDialog after a widget gets re-used 263 -- which would be done by the AceConfigDialog after a widget gets re-used
236 if not self.originalSetCallBack then 264 if not self.originalSetCallBack then
237 self.originalSetCallBack = self.SetCallback; 265 self.originalSetCallBack = self.SetCallback;
248 else 276 else
249 return this.originalSetCallBack(this, event, func, ...); 277 return this.originalSetCallBack(this, event, func, ...);
250 end 278 end
251 end; 279 end;
252 end 280 end
281
253 282
254 283
255 -- Set our own events, since we disabled the normal event-names, we'll call them our custom versions 284 -- Set our own events, since we disabled the normal event-names, we'll call them our custom versions
256 self:SetCallback("CustomOnEnter", function(this) 285 self:SetCallback("CustomOnEnter", function(this)
257 local itemId = this:GetUserData("itemId"); 286 local itemId = this:GetUserData("itemId");
354 end 383 end
355 384
356 AceGUI:RegisterWidgetType(widgetType, GetItemLinkButton, widgetVersion); 385 AceGUI:RegisterWidgetType(widgetType, GetItemLinkButton, widgetVersion);
357 end 386 end
358 387
359 function addon:CommandHandler(message) 388 local slashArgs = {};
389 local slashError = "Wrong arguement, the following arguements are available:";
390
391 function addon:RegisterSlash(func, args, description)
392 for _, arg in pairs(args) do
393 slashArgs[arg] = func;
394 end
395
396 if description then
397 slashError = slashError .. "\n" .. description;
398 end
399 end
400
401 function InventoriumCommandHandler(message)
360 local cmd, arg = string.split(" ", (message or ""), 2); 402 local cmd, arg = string.split(" ", (message or ""), 2);
361 cmd = string.lower(cmd); 403 cmd = string.lower(cmd);
362 404
363 if cmd == "c" or cmd == "config" or cmd == "conf" or cmd == "option" or cmd == "options" or cmd == "opt" or cmd == "setting" or cmd == "settings" then 405 if slashArgs[cmd] then
364 -- We don't want any other windows open at this time. 406 slashArgs[cmd](addon, arg);
365 for name, module in self:IterateModules() do
366 if module.CloseFrame then
367 module:CloseFrame();
368 end
369 end
370
371 self:Show();
372 elseif cmd == "d" or cmd == "debug" then
373 self.debugChannel = false;
374 for i = 1, NUM_CHAT_WINDOWS do
375 local name = GetChatWindowInfo(i);
376
377 if name:upper() == "DEBUG" then
378 self.debugChannel = _G["ChatFrame" .. i];
379
380 print("A debug channel already exists, used the old one. (" .. i .. ")");
381 return;
382 end
383 end
384
385 if not self.debugChannel then
386 -- Create a new debug channel
387 local chatFrame = FCF_OpenNewWindow('Debug');
388 ChatFrame_RemoveAllMessageGroups(chatFrame);
389 self.debugChannel = chatFrame;
390
391 print("New debug channel created.");
392 end
393 elseif slashArgs[cmd] then
394 slashArgs[cmd]();
395 else 407 else
396 print("Wrong command, available: /inventorium config (or /im c) and /inventorium summary (or /im s)"); 408 print(slashError);
397 end 409 end
398 end 410 end
399 411
400 function addon:Load() 412 function addon:Load()
401 if not AceConfigDialog and not AceConfigRegistry then 413 if not AceConfigDialog and not AceConfigRegistry then
572 end 584 end
573 585
574 return temp; 586 return temp;
575 end, 587 end,
576 get = function() return self.db.global.defaults.auctionPricingAddon; end, 588 get = function() return self.db.global.defaults.auctionPricingAddon; end,
577 set = function(i, v) self.db.global.defaults.auctionPricingAddon = v; end, 589 set = function(i, v)
590 self.db.global.defaults.auctionPricingAddon = v;
591
592 if self.supportedAddons.auctionPricing[v].OnSelect then
593 self.supportedAddons.auctionPricing[v].OnSelect();
594 end
595 end,
578 }, 596 },
579 itemCountAddon = { 597 itemCountAddon = {
580 order = 20, 598 order = 20,
581 type = "select", 599 type = "select",
582 name = "Prefered item count addon", 600 name = "Prefered item count addon",
606 return temp; 624 return temp;
607 end, 625 end,
608 get = function() return self.db.global.defaults.craftingAddon; end, 626 get = function() return self.db.global.defaults.craftingAddon; end,
609 set = function(i, v) self.db.global.defaults.craftingAddon = v; end, 627 set = function(i, v) self.db.global.defaults.craftingAddon = v; end,
610 }, 628 },
611 localItemData = { 629 --[[localItemData = {
612 order = 40, 630 order = 40,
613 type = "multiselect", 631 type = "multiselect",
614 name = "Include in local item data", 632 name = "Include in local item data",
615 desc = "Select which data should be included in the local item data.", 633 desc = "Select which data should be included in the local item data.",
616 values = { 634 values = {
620 ["Mailbox"] = "Mailbox", 638 ["Mailbox"] = "Mailbox",
621 }, 639 },
622 get = function(i, v) return self.db.global.defaults.localItemData and self.db.global.defaults.localItemData[v]; end, 640 get = function(i, v) return self.db.global.defaults.localItemData and self.db.global.defaults.localItemData[v]; end,
623 set = function(i, v, e) self.db.global.defaults.localItemData[v] = e or nil; end, 641 set = function(i, v, e) self.db.global.defaults.localItemData[v] = e or nil; end,
624 --dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead. 642 --dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead.
625 }, 643 },]]
626 }, 644 },
627 }, 645 },
628 minimumStock = { 646 minimumStock = {
629 order = 10, 647 order = 10,
630 type = "group", 648 type = "group",
1206 temp[name] = name; 1224 temp[name] = name;
1207 end 1225 end
1208 1226
1209 return temp; 1227 return temp;
1210 end, 1228 end,
1229 set = function(info, value)
1230 local groupName = groupIdToName[info[2]];
1231 local optionName = info[#info];
1232
1233 addon.db.global.groups[groupName][optionName] = value ~= "" and value;
1234
1235 if addon.supportedAddons.auctionPricing[value].OnSelect then
1236 addon.supportedAddons.auctionPricing[value].OnSelect();
1237 end
1238 end,
1211 arg = "overrideAuctionPricingAddon", 1239 arg = "overrideAuctionPricingAddon",
1212 }, 1240 },
1213 overrideItemCountAddon = { 1241 overrideItemCountAddon = {
1214 order = 19, 1242 order = 19,
1215 type = "toggle", 1243 type = "toggle",
1252 1280
1253 return temp; 1281 return temp;
1254 end, 1282 end,
1255 arg = "overrideCraftingAddon", 1283 arg = "overrideCraftingAddon",
1256 }, 1284 },
1257 overrideLocalItemData = { 1285 --[[overrideLocalItemData = {
1258 order = 39, 1286 order = 39,
1259 type = "toggle", 1287 type = "toggle",
1260 name = "Override local item data", 1288 name = "Override local item data",
1261 desc = "Allows you to override the local item data setting for this group.", 1289 desc = "Allows you to override the local item data setting for this group.",
1262 arg = "localItemData", 1290 arg = "localItemData",
1273 ["Mailbox"] = "Mailbox", 1301 ["Mailbox"] = "Mailbox",
1274 }, 1302 },
1275 get = GetMultiOption, 1303 get = GetMultiOption,
1276 --dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead. 1304 --dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead.
1277 arg = "overrideLocalItemData", 1305 arg = "overrideLocalItemData",
1278 }, 1306 },]]
1279 virtualGroup = { 1307 virtualGroup = {
1280 order = 50, 1308 order = 50,
1281 type = "select", 1309 type = "select",
1282 name = "Use virtual group settings", 1310 name = "Use virtual group settings",
1283 desc = "Use the settings from a virtual group before using the general defaults.\n\n|cffff9933This is an advanced option, you will probably not need it unless you manage a lot of groups.|r\n\n|cfffed000Off|r: Use the overridden options in this group and then the defaults.\n\n|cfffed000On|r: Use the overridden options in this group, then the ones in the selected virtual group and then the defaults.", 1311 desc = "Use the settings from a virtual group before using the general defaults.\n\n|cffff9933This is an advanced option, you will probably not need it unless you manage a lot of groups.|r\n\n|cfffed000Off|r: Use the overridden options in this group and then the defaults.\n\n|cfffed000On|r: Use the overridden options in this group, then the ones in the selected virtual group and then the defaults.",
2160 2188
2161 2189
2162 2190
2163 -- Public 2191 -- Public
2164 2192
2165 function IMRegisterPricingAddon(name, get, enabled) 2193 function IMRegisterPricingAddon(name, get, enabled, onSelect)
2166 addon.supportedAddons.auctionPricing[name] = { 2194 addon.supportedAddons.auctionPricing[name] = {
2167 GetValue = get, 2195 GetValue = get,
2168 IsEnabled = enabled, 2196 IsEnabled = enabled,
2197 OnSelect = onSelect,
2169 }; 2198 };
2170 end 2199 end
2171 2200
2172 function IMRegisterItemCountAddon(name, getTotal, getCharacter, enabled) 2201 function IMRegisterItemCountAddon(name, getTotal, getCharacter, enabled)
2173 addon.supportedAddons.itemCount[name] = { 2202 addon.supportedAddons.itemCount[name] = {