Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tooltip for loot #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 36 additions & 72 deletions SellValue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ local function hooksecurefunc(arg1, arg2, arg3)
end
end

function SellValue_SetTooltip(itemID, stackCount)
local price = SellValues[itemID];

if price then
if price == 0 then
GameTooltip:AddLine(ITEM_UNSELLABLE, 1.0, 1.0, 1.0);
else
SetTooltipMoney(GameTooltip, price * stackCount);

end -- if price > 0

-- Adjust width and height to account for new lines
GameTooltip:SetHeight(GameTooltip:GetHeight() + 14);
if GameTooltip:GetWidth() < 120 then
GameTooltip:SetWidth(120);
end
end -- if price
end

function SellValue_OnLoad()

-- Get initial prices from database
Expand All @@ -25,29 +44,25 @@ function SellValue_OnLoad()

SellValue_Tooltip:SetScript("OnTooltipAddMoney", SellValue_OnTooltipAddMoney);

-- Hook loot tooltip
hooksecurefunc (GameTooltip, "SetLootItem",
function(tip, lootIndex)
if SellValues then
local _, _, stackCount = GetLootSlotInfo(lootIndex);
if stackCount ~= 0 then
local link = GetLootSlotLink(lootIndex);
SellValue_SetTooltip(SellValue_IDFromLink(link), stackCount);
end
end
end
);

-- Hook bag tooltip
hooksecurefunc (GameTooltip, "SetBagItem",
function(tip, bag, slot)
if SellValues and not MerchantFrame:IsVisible() then
local _, stackCount = GetContainerItemInfo(bag, slot);
local itemID = SellValue_GetItemID(bag, slot);

local price = SellValues[itemID];

if price then
if price == 0 then
GameTooltip:AddLine(ITEM_UNSELLABLE, 1.0, 1.0, 1.0);
else
SetTooltipMoney(GameTooltip, price * stackCount);

end -- if price > 0

-- Adjust width and height to account for new lines
GameTooltip:SetHeight(GameTooltip:GetHeight() + 14);
if GameTooltip:GetWidth() < 120 then
GameTooltip:SetWidth(120);
end
end -- if price
SellValue_SetTooltip(SellValue_GetItemID(bag, slot), stackCount);
end
end
);
Expand All @@ -58,24 +73,7 @@ function SellValue_OnLoad()
function(tip, unit, slot)
if SellValues and not MerchantFrame:IsVisible() and slot > 19 then
local stackCount = GetInventoryItemCount(unit, slot);
local itemID = SellValue_GetItemID(-1, slot);

local price = SellValues[itemID];

if price then
if price == 0 then
GameTooltip:AddLine(ITEM_UNSELLABLE, 1.0, 1.0, 1.0);
else
SetTooltipMoney(GameTooltip, price * stackCount);

end -- if price > 0

-- Adjust width and height to account for new lines
GameTooltip:SetHeight(GameTooltip:GetHeight() + 14);
if GameTooltip:GetWidth() < 120 then
GameTooltip:SetWidth(120);
end
end -- if price
SellValue_SetTooltip(SellValue_GetItemID(-1, slot), stackCount);
end
end
);
Expand All @@ -86,24 +84,7 @@ function SellValue_OnLoad()
if SellValues and (qtype == "reward" or qtype == "choice") then
local link = GetQuestItemLink(qtype, slot);
local _,_,stackCount = GetQuestItemInfo(qtype, slot);
local itemID = SellValue_IDFromLink(link);

local price = SellValues[itemID];

if price then
if price == 0 then
GameTooltip:AddLine(ITEM_UNSELLABLE, 1.0, 1.0, 1.0);
else
SetTooltipMoney(GameTooltip, price * stackCount);

end -- if price > 0

-- Adjust width and height to account for new lines
GameTooltip:SetHeight(GameTooltip:GetHeight() + 14);
if GameTooltip:GetWidth() < 120 then
GameTooltip:SetWidth(120);
end
end -- if price
SellValue_SetTooltip(SellValue_IDFromLink(link), stackCount);
end
end
);
Expand All @@ -124,24 +105,7 @@ function SellValue_OnLoad()
end

local link = GetQuestLogItemLink(qtype, slot);
local itemID = SellValue_IDFromLink(link);

local price = SellValues[itemID];

if price then
if price == 0 then
GameTooltip:AddLine(ITEM_UNSELLABLE, 1.0, 1.0, 1.0);
else
SetTooltipMoney(GameTooltip, price * stackCount);

end -- if price > 0

-- Adjust width and height to account for new lines
GameTooltip:SetHeight(GameTooltip:GetHeight() + 14);
if GameTooltip:GetWidth() < 120 then
GameTooltip:SetWidth(120);
end
end -- if price
SellValue_SetTooltip(SellValue_IDFromLink(link), stackCount);
end
end
);
Expand Down