-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSellValue.lua
118 lines (93 loc) · 3.83 KB
/
SellValue.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
-- global SellValues = shortname -> price
function SellValue_OnLoad()
this:RegisterEvent("MERCHANT_SHOW");
SellValue_Saved_OnTooltipAddMoney = SellValue_Tooltip:GetScript("OnTooltipAddMoney");
SellValue_Tooltip:SetScript("OnTooltipAddMoney", SellValue_OnTooltipAddMoney);
end
function SellValue_OnEvent()
if event == "MERCHANT_SHOW" then
return SellValue_MerchantScan(this);
end
end
SellValue_Saved_GameTooltip_OnEvent = GameTooltip_OnEvent;
GameTooltip_OnEvent = function ()
if event ~= "CLEAR_TOOLTIP" then
return SellValue_Saved_GameTooltip_OnEvent();
end
end
function SellValue_OnTooltipAddMoney ()
-- call the original function first
SellValue_Saved_OnTooltipAddMoney();
-- The money in repair mode is the cost to repair, not sell
if InRepairMode() then return; end;
SellValue_LastItemMoney = arg1;
end
function SellValue_SaveFor(bag, slot, name, money)
if not (bag and slot and name and money) then return; end;
local _, stackCount = GetContainerItemInfo(bag, slot);
if stackCount and stackCount > 0 then
local costOfOne = money / stackCount;
if not SellValues then SellValues = {}; end
SellValues[name] = costOfOne;
if InvListFrame:IsVisible() then InvList_ForceUpdate(); end
end
end
function SellValue_AddMoneyToTooltip()
if SellValues and not MerchantFrame:IsVisible() then
local lbl = getglobal("GameTooltipTextLeft1");
if lbl then
local itemName = lbl:GetText();
local itemShortName = InvList_ShortenItemName(itemName);
-- Don't add a tooltip for hidden items
if not InvList_TooltipMode or
(InvList_TooltipMode == 1 and
InvList_HiddenItems and
InvList_HiddenItems[itemName]) then
return;
end
local price = SellValues[itemShortName];
if price then
local linesAdded = 0;
if price == 0 then
GameTooltip:AddLine(ITEM_UNSELLABLE, 1.0, 1.0, 0);
linesAdded = 1;
else
GameTooltip:AddLine(SELLVALUE_COST, 1.0, 1.0, 0);
SetTooltipMoney(GameTooltip, price);
linesAdded = 2;
if InvList_TooltipShowStackTotal then
MoneyFrame_Update("SellValueMoneyFrame", price * 2);
linesAdded = 3;
end -- if showstacktotal
end -- if price > 0
-- Adjust width and height to account for new lines
GameTooltip:SetHeight(GameTooltip:GetHeight()
+ (14 * linesAdded));
if GameTooltip:GetWidth() < 120 then
GameTooltip:SetWidth(120);
end
end -- if price
end
end
end
function SellValue_MerchantScan(frame)
for bag=0,NUM_BAG_FRAMES do
for slot=1,GetContainerNumSlots(bag) do
local itemName = InvList_GetShortItemName(bag, slot);
if itemName ~= "" then
SellValue_LastItemMoney = 0;
SellValue_Tooltip:SetBagItem(bag, slot);
SellValue_SaveFor(bag, slot, itemName, SellValue_LastItemMoney);
end -- if item name
end -- for slot
end -- for bag
end
function SellValue_OnShow()
return SellValue_AddMoneyToTooltip();
end
function SellValue_OnHide()
-- ClearMoney() expects this to point to the tooltip itself, and this here
-- points to us, a child of the tip
this = this:GetParent();
return GameTooltip_ClearMoney();
end