annotate Modules/Tooltip.lua @ 131:78c6d905c2e1

Ticket 41 - Fixed a bug that occured if you created items without ever opening /ia crafting.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 15 Sep 2010 20:45:26 -0700
parents 451d8a19edea
children 7f81764aa03a
rev   line source
Asa@63 1 local ItemAuditor = select(2, ...)
Asa@63 2 local Tooltip = ItemAuditor:NewModule("Tooltip")
Asa@3 3
Asa@128 4 local Crafting
Asa@128 5 local Utils = ItemAuditor:GetModule("Utils")
Asa@128 6
Asa@3 7 local function ShowTipWithPricing(tip, link, num)
Asa@3 8 if (link == nil) then
Asa@3 9 return;
Asa@3 10 end
Asa@128 11 if not Crafting then
Asa@128 12 Crafting = ItemAuditor:GetModule("Crafting")
Asa@128 13 end
Asa@3 14
Asa@8 15 -- local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, _, _, _, _, itemVendorPrice = GetItemInfo (link);
Asa@3 16 -- local _, _, Color, Ltype, Id, Enchant, Gem1, Gem2, Gem3, Gem4, Suffix, Unique, LinkLvl, Name = string.find(link, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
Asa@3 17
Asa@8 18 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link)
Asa@3 19
Asa@63 20 local keep = 1 - ItemAuditor:GetAHCut()
Asa@12 21 local show = false
Asa@3 22
Asa@3 23 if investedTotal > 0 then
Asa@34 24 local suggestColor
Asa@63 25 local ap = ItemAuditor:GetAuctionPrice(link)
Asa@34 26 if ap == nil then
Asa@34 27 suggestColor = nil
Asa@76 28 elseif ap >= ceil(investedPerItem/keep) then
Asa@34 29 suggestColor = "|cFF00FF00" -- green
Asa@34 30 else
Asa@34 31 suggestColor = "|cFFFF0000" -- red
Asa@34 32 end
Asa@34 33
Asa@34 34
Asa@63 35 tip:AddDoubleLine("\124cffffffffIA: Total Invested", ItemAuditor:FormatMoney(investedTotal));
Asa@63 36 tip:AddDoubleLine("\124cffffffffIA: Invested per Item (own: " .. count .. ")", ItemAuditor:FormatMoney(ceil(investedPerItem)));
Asa@63 37 tip:AddDoubleLine("\124cffffffffIA: Minimum " .. ItemAuditor:GetAHFaction() .. " AH Price: ", ItemAuditor:FormatMoney(ceil(investedPerItem/keep), suggestColor))
Asa@12 38 show = true
Asa@12 39
Asa@12 40 end
Asa@13 41
Asa@115 42 if ItemAuditor:IsQACompatible() then
Asa@13 43 local groupName = QAAPI:GetItemGroup(link)
Asa@13 44 if groupName then
Asa@62 45 local threshold = QAAPI:GetGroupConfig(groupName)
Asa@63 46 tip:AddDoubleLine("\124cffffffffIA: QA Threshold: ", ItemAuditor:FormatMoney(threshold))
Asa@13 47 show = true
Asa@13 48 end
Asa@12 49 end
Asa@128 50
Asa@128 51
Asa@128 52 shoppingList = Crafting.GetShoppingList(Utils.GetItemID(link))
Asa@128 53 if shoppingList then
Asa@128 54 tip:AddDoubleLine("\124cffffffffIA Queue", "\124cffffffffhave/total")
Asa@128 55 for character, recipes in pairs(shoppingList.characters) do
Asa@128 56 local count = 0
Asa@128 57 local need = 0
Asa@128 58 local color = '\124cff00ff00' -- green
Asa@128 59 for link, data in pairs(recipes) do
Asa@128 60 need = need + data.need
Asa@128 61 count = count + data.count
Asa@128 62 end
Asa@128 63 if need > 0 then
Asa@128 64 color = '\124cffff0000' -- red
Asa@128 65 end
Asa@128 66 tip:AddDoubleLine("\124cffffffff"..character, format("%s%s/%s", color, count-need, count))
Asa@128 67 if true then -- show details
Asa@128 68 for link, data in pairs(recipes) do
Asa@128 69 if data.need > 0 then
Asa@128 70 tip:AddDoubleLine("\124cffffffff"..link, format("\124cffffffff%s/%s", data.count-data.need, data.count))
Asa@128 71 end
Asa@128 72 end
Asa@128 73 end
Asa@128 74
Asa@128 75 end
Asa@128 76 show = true
Asa@128 77 end
Asa@12 78
Asa@12 79 if show then
Asa@3 80 tip:Show()
Asa@3 81 end
Asa@3 82 end
Asa@3 83
Asa@3 84 hooksecurefunc (GameTooltip, "SetBagItem",
Asa@3 85 function(tip, bag, slot)
Asa@3 86 local _, num = GetContainerItemInfo(bag, slot);
Asa@3 87 ShowTipWithPricing (tip, GetContainerItemLink(bag, slot), num);
Asa@3 88 end
Asa@3 89 );
Asa@3 90
Asa@3 91 hooksecurefunc (GameTooltip, "SetAuctionItem",
Asa@3 92 function (tip, type, index)
Asa@3 93 ShowTipWithPricing (tip, GetAuctionItemLink(type, index));
Asa@3 94 end
Asa@3 95 );
Asa@3 96
Asa@3 97 hooksecurefunc (GameTooltip, "SetAuctionSellItem",
Asa@3 98 function (tip)
Asa@3 99 local name, _, count = GetAuctionSellItemInfo();
Asa@3 100 local __, link = GetItemInfo(name);
Asa@3 101 ShowTipWithPricing (tip, link, num);
Asa@3 102 end
Asa@3 103 );
Asa@3 104
Asa@3 105
Asa@3 106 hooksecurefunc (GameTooltip, "SetLootItem",
Asa@3 107 function (tip, slot)
Asa@3 108 if LootSlotIsItem(slot) then
Asa@3 109 local link, _, num = GetLootSlotLink(slot);
Asa@3 110 ShowTipWithPricing (tip, link, num);
Asa@3 111 end
Asa@3 112 end
Asa@3 113 );
Asa@3 114
Asa@3 115 hooksecurefunc (GameTooltip, "SetLootRollItem",
Asa@3 116 function (tip, slot)
Asa@3 117 local _, _, num = GetLootRollItemInfo(slot);
Asa@3 118 ShowTipWithPricing (tip, GetLootRollItemLink(slot), num);
Asa@3 119 end
Asa@3 120 );
Asa@3 121
Asa@3 122
Asa@3 123 hooksecurefunc (GameTooltip, "SetInventoryItem",
Asa@3 124 function (tip, unit, slot)
Asa@3 125 ShowTipWithPricing (tip, GetInventoryItemLink(unit, slot), GetInventoryItemCount(unit, slot));
Asa@3 126 end
Asa@3 127 );
Asa@3 128
Asa@3 129 hooksecurefunc (GameTooltip, "SetGuildBankItem",
Asa@3 130 function (tip, tab, slot)
Asa@3 131 local _, num = GetGuildBankItemInfo(tab, slot);
Asa@3 132 ShowTipWithPricing (tip, GetGuildBankItemLink(tab, slot), num);
Asa@3 133 end
Asa@3 134 );
Asa@3 135
Asa@3 136 hooksecurefunc (GameTooltip, "SetTradeSkillItem",
Asa@3 137 function (tip, skill, id)
Asa@3 138 local link = GetTradeSkillItemLink(skill);
Asa@3 139 local num = GetTradeSkillNumMade(skill);
Asa@3 140 if id then
Asa@3 141 link = GetTradeSkillReagentItemLink(skill, id);
Asa@3 142 num = select (3, GetTradeSkillReagentInfo(skill, id));
Asa@3 143 end
Asa@3 144
Asa@3 145 ShowTipWithPricing (tip, link, num);
Asa@3 146 end
Asa@3 147 );
Asa@3 148
Asa@3 149 hooksecurefunc (GameTooltip, "SetTradePlayerItem",
Asa@3 150 function (tip, id)
Asa@3 151 local _, _, num = GetTradePlayerItemInfo(id);
Asa@3 152 ShowTipWithPricing (tip, GetTradePlayerItemLink(id), num);
Asa@3 153 end
Asa@3 154 );
Asa@3 155
Asa@3 156 hooksecurefunc (GameTooltip, "SetTradeTargetItem",
Asa@3 157 function (tip, id)
Asa@3 158 local _, _, num = GetTradeTargetItemInfo(id);
Asa@3 159 ShowTipWithPricing (tip, GetTradeTargetItemLink(id), num);
Asa@3 160 end
Asa@3 161 );
Asa@3 162
Asa@3 163 hooksecurefunc (GameTooltip, "SetQuestItem",
Asa@3 164 function (tip, type, index)
Asa@3 165 local _, _, num = GetQuestItemInfo(type, index);
Asa@3 166 ShowTipWithPricing (tip, GetQuestItemLink(type, index), num);
Asa@3 167 end
Asa@3 168 );
Asa@3 169
Asa@3 170 hooksecurefunc (GameTooltip, "SetQuestLogItem",
Asa@3 171 function (tip, type, index)
Asa@3 172 local num, _;
Asa@3 173 if type == "choice" then
Asa@3 174 _, _, num = GetQuestLogChoiceInfo(index);
Asa@3 175 else
Asa@3 176 _, _, num = GetQuestLogRewardInfo(index)
Asa@3 177 end
Asa@3 178
Asa@3 179 ShowTipWithPricing (tip, GetQuestLogItemLink(type, index), num);
Asa@3 180 end
Asa@3 181 );
Asa@3 182
Asa@3 183 hooksecurefunc (GameTooltip, "SetInboxItem",
Asa@3 184 function (tip, index, attachIndex)
Asa@3 185 local _, _, num = GetInboxItem(index, attachIndex);
Asa@3 186 ShowTipWithPricing (tip, GetInboxItemLink(index, attachIndex), num);
Asa@3 187 end
Asa@3 188 );
Asa@3 189
Asa@3 190 hooksecurefunc (GameTooltip, "SetSendMailItem",
Asa@3 191 function (tip, id)
Asa@3 192 local name, _, num = GetSendMailItem(id)
Asa@3 193 local name, link = GetItemInfo(name);
Asa@3 194 ShowTipWithPricing (tip, link, num);
Asa@3 195 end
Asa@3 196 );
Asa@3 197
Asa@3 198 hooksecurefunc (GameTooltip, "SetHyperlink",
Asa@3 199 function (tip, itemstring, num)
Asa@3 200 local name, link = GetItemInfo (itemstring);
Asa@3 201 ShowTipWithPricing (tip, link, num);
Asa@3 202 end
Asa@3 203 );
Asa@3 204
Asa@3 205 hooksecurefunc (ItemRefTooltip, "SetHyperlink",
Asa@3 206 function (tip, itemstring)
Asa@3 207 local name, link = GetItemInfo (itemstring);
Asa@3 208 ShowTipWithPricing (tip, link);
Asa@3 209 end
Asa@3 210 );