-
Notifications
You must be signed in to change notification settings - Fork 0
/
RetailBags.lua
256 lines (220 loc) · 7.87 KB
/
RetailBags.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
local addonName, addon = ...
local RB = LibStub("AceAddon-3.0"):NewAddon(addonName);
RetailBags = RB;
RB.consts = {
ENABLE_DEBUGGING = false
};
RB.defaults = {
profile = {
version = 1,
displaySearchBox = true,
displaySortButton = true,
sortBagsRightToLeft = true,
bagContainerScale = 1,
displayTooltipItemQuality = true,
displayTooltipItemLevel = true,
displayTooltipCraftingReagent = true,
displayMaxStackSize = true,
displayTooltipVendorPrice = true,
displayItemQualityBorders = true,
makeReagentBordersBlue = false,
displayBagsWithCharacterPane = true,
displayKeyringWithCharacterPane = false,
displayBagsWithAuctionPane = true,
makeConsumableBordersColored = false,
}
}
local Core = {};
RB.Core = Core;
local f = CreateFrame("Frame");
f:RegisterEvent('BANKFRAME_OPENED');
f:RegisterEvent('PLAYERBANKSLOTS_CHANGED');
f:RegisterEvent('INSPECT_READY');
f:RegisterEvent('UNIT_INVENTORY_CHANGED');
f:RegisterEvent('AUCTION_HOUSE_SHOW');
f:RegisterEvent('AUCTION_HOUSE_CLOSED');
f:RegisterEvent('AUCTION_ITEM_LIST_UPDATE');
f:RegisterEvent('AUCTION_OWNED_LIST_UPDATE');
f:RegisterEvent('AUCTION_BIDDER_LIST_UPDATE');
f:RegisterEvent("LOOT_OPENED");
f:RegisterEvent("LOOT_SLOT_CLEARED");
f:RegisterEvent("LOOT_SLOT_CHANGED");
f:RegisterEvent("QUEST_ACCEPTED");
f:RegisterEvent("QUEST_REMOVED");
f:RegisterEvent("QUEST_COMPLETE");
function RB:OnInitialize()
self.GUI = LibStub("AceGUI-3.0")
self.DB = LibStub("AceDB-3.0"):New("RetailBagsDB", RB.defaults, "Default")
self.BagItemSearchBox = BagItemSearchBox;
self.BagItemAutoSortButton = BagItemAutoSortButton;
SetSortBagsRightToLeft(self.DB.profile.sortBagsRightToLeft);
CONTAINER_SCALE = self.DB.profile.bagContainerScale;
end
hooksecurefunc("ContainerFrame_Update", function(frame)
RB:InitContainer(frame);
end)
f:SetScript("OnEvent", function(self, event, arg1, arg2)
Core:Debug(event);
if event == "BANKFRAME_OPENED" or event == "PLAYERBANKSLOTS_CHANGED" then
RB:InitBank();
elseif event == "INSPECT_READY" then
RB:InitInspectInventory();
elseif event == "UNIT_INVENTORY_CHANGED" then
if (CharacterFrame:IsShown()) then
RB:InitInventory(CharacterFrame);
else
RB:InitInspectInventory();
end
elseif event == "AUCTION_HOUSE_SHOW" then
AuctionFrame_VisibilityCallback(true);
elseif event == "AUCTION_HOUSE_CLOSED" then
AuctionFrame_VisibilityCallback(false);
elseif event == "AUCTION_ITEM_LIST_UPDATE" then
RB:InitAuctionBrowseItems();
elseif event == "AUCTION_OWNED_LIST_UPDATE" then
RB:InitAuctionOwnedItems();
elseif event == "AUCTION_BIDDER_LIST_UPDATE" then
RB:InitAuctionBidItems();
elseif event == "LOOT_OPENED" or event == "LOOT_SLOT_CHANGED" or event == "LOOT_SLOT_CLEARED" then
RB:InitLootFrame();
elseif event == "QUEST_ACCEPTED" or event == "QUEST_REMOVED" or event == "QUEST_COMPLETE" then
if (IsBagOpen(Enum.BagIndex.Bank)) then
RB:InitBank();
end
for i = 1, NUM_CONTAINER_FRAMES, 1 do
local containerFrame = _G["ContainerFrame" .. i];
if (containerFrame:IsShown()) then
RB:InitContainer(containerFrame);
end
end
end
end)
RB.Colors = {
yellow = "|cFFFFFF00",
white = "|cFFFFFFFF",
blue = "|cFF69CCF0",
gray = "|cff808080",
darkmagenta = "|cffA330C9",
common = "|cFFFFFFFF",
uncommon = "|cFF1EFF00",
rare = "|cFF0070DD",
epic = "|cFFA335EE",
legendary = "|cFFFF8000",
artifact = "|cFFE6CC80",
};
local function GameTooltip_OnTooltipSetItem(tooltip)
if not tooltip then return; end
local _, link = tooltip:GetItem()
if not link then return; end
local itemName, _, quality, itemLevel, _, _, _, stack, slot, _, sellPrice, classId, subClassId, bindType, expacID, setID, isCraftingReagent =
GetItemInfo(link);
if (itemName) then
--Core:Debug(GetMouseFocus():GetName());
if (RB.DB.profile.displayTooltipItemQuality) then
tooltip:AddLine(RB.Colors.white .. _G["ITEM_QUALITY" .. quality .. "_DESC"]);
end
if classId == Enum.ItemClass.Consumable then
if (RB.DB.profile.displayTooltipCraftingReagent) then
tooltip:AddLine(RB.Colors.darkmagenta .. BAG_FILTER_CONSUMABLES);
end
elseif isCraftingReagent or classId == Enum.ItemClass.Tradegoods then
if (RB.DB.profile.displayTooltipCraftingReagent) then
tooltip:AddLine(RB.Colors.blue .. PROFESSIONS_USED_IN_COOKING);
end
elseif itemLevel > 1 and (classId == Enum.ItemClass.Weapon or classId == Enum.ItemClass.Armor or classId == Enum.ItemClass.Projectile or classId == Enum.ItemClass.Quiver) then
if (RB.DB.profile.displayTooltipItemLevel) then
tooltip:AddLine(STAT_AVERAGE_ITEM_LEVEL .. " " .. itemLevel);
end
end
if (RB.DB.profile.displayMaxStackSize and stack > 1) then
local indent = string.rep(" ", 4);
tooltip:AddLine(MAXIMUM .. " " .. AUCTION_STACK_SIZE .. ":" .. indent .. stack);
end
end
end
GameTooltip:HookScript("OnTooltipSetItem", GameTooltip_OnTooltipSetItem);
ShoppingTooltip1:HookScript("OnTooltipSetItem", GameTooltip_OnTooltipSetItem);
ShoppingTooltip2:HookScript("OnTooltipSetItem", GameTooltip_OnTooltipSetItem);
ItemRefTooltip:HookScript("OnTooltipSetItem", GameTooltip_OnTooltipSetItem);
local function GameTooltip_OnSetBagItem(tooltip, bag, slot)
if RB.DB.profile.displayTooltipVendorPrice and not MerchantFrame:IsVisible() and tooltip and bag and slot then
local info = C_Container.GetContainerItemInfo(bag, slot);
if info then
local itemName, _, quality, itemLevel, _, _, _, stack, slot, _, sellPrice, classId, subClassId, bindType, expacID, setID, isCraftingReagent =
GetItemInfo(info.itemID);
if (itemName and sellPrice and sellPrice > 0) then
GameTooltip_OnTooltipAddMoney(tooltip, sellPrice * info.stackCount, nil);
tooltip:Show();
end
end
end
end
hooksecurefunc(GameTooltip, 'SetBagItem', GameTooltip_OnSetBagItem);
hooksecurefunc(WorldMapFrame, "Show", function(self)
if (CharacterFrame:IsShown()) then
HideUIPanel(CharacterFrame);
end
ShowUIPanel(WorldMapFrame);
end);
local function CharacterFrame_VisibilityCallback(frame)
if (RB.DB.profile.displayBagsWithCharacterPane or RB.DB.profile.displayKeyringWithCharacterPane) then
HideUIPanel(WorldMapFrame);
if (frame:IsShown()) then
if (RB.DB.profile.displayBagsWithCharacterPane) then
OpenAllBags();
end
if (RB.DB.profile.displayKeyringWithCharacterPane) then
CloseBag(Enum.BagIndex.Keyring);
ToggleBag(Enum.BagIndex.Keyring);
end
else
if (RB.DB.profile.displayBagsWithCharacterPane) then
CloseAllBags();
end
if (RB.DB.profile.displayKeyringWithCharacterPane) then
CloseBag(Enum.BagIndex.Keyring);
end
end
end
RB:InitInventory(frame);
end
hooksecurefunc(CharacterFrame, "Hide", CharacterFrame_VisibilityCallback);
hooksecurefunc(CharacterFrame, "Show", CharacterFrame_VisibilityCallback);
function AuctionFrame_VisibilityCallback(visible)
HideUIPanel(WorldMapFrame);
if (RB.DB.profile.displayBagsWithAuctionPane) then
if (visible) then
OpenAllBags();
else
CloseAllBags();
end
end
end
hooksecurefunc('MerchantFrame_UpdateMerchantInfo', function() RB:InitMerchantSell(); end);
hooksecurefunc('MerchantFrame_UpdateBuybackInfo', function() RB:InitMerchantBuyBackList(); end);
hooksecurefunc('FauxScrollFrame_OnVerticalScroll', function(frame)
if (frame == BrowseScrollFrame) then
RB:InitAuctionBrowseItems();
end
end);
function Core:Debug(msg)
if (msg and RB.consts.ENABLE_DEBUGGING) then
Core:PrintMessage(" [DEBUG] " .. msg);
end
end
function Core:PrintMessage(msg)
print(Core:GetColoredStringWithBranding("ffcc00", msg));
end
function Core:PrintSuccessMessage(msg)
print(Core:GetColoredStringWithBranding("00ff00", msg));
end
function Core:PrintErrorMessage(msg)
print(Core:GetColoredStringWithBranding("ff0000", msg));
end
function Core:GetColoredStringWithBranding(color, msg)
return Core:GetColoredString("00ff00", addonName .. ": ") .. Core:GetColoredString(color, msg);
end
function Core:GetColoredString(color, msg)
local colorString = "|cff";
return colorString .. color .. msg .. "|r";
end