annotate ProspectMe_Tooltip.lua @ 42:35c84e420f4a Prospect Me 2

Further refinements to the tooltip text.
author Vynn <mischivin@gmail.com>
date Fri, 11 Nov 2016 13:26:19 -0500
parents 55da4d54a2de
children a35539b8e151
rev   line source
mischivin@39 1 local ORE = select(7,GetItemInfo(123918)) -- Get Ore Subclass from a known quantity (leystone ore)
mischivin@39 2 local HERB = select(7,GetItemInfo(128304)) -- Get Herb Subclass from a known quantity (yseralline seed)
mischivin@20 3
mischivin@36 4 local Quality = { [0] = "Junk", [1]= "Common", [2] = "Uncommon", [3] = "Rare", [4] = "Epic", }
Vynn@0 5
mischivin@36 6 local function Initialize()
mischivin@36 7 ProspectMe.FormatPrice = function (value)
Vynn@0 8
mischivin@36 9 local GSC_GOLD="ffffd100"
mischivin@36 10 local GSC_SILVER="ffe6e6e6"
mischivin@36 11 local GSC_COPPER="ffc8602c"
Vynn@0 12
mischivin@36 13 local g, s, c
mischivin@36 14 local digits = 0
mischivin@36 15 local gsc
Vynn@0 16
mischivin@36 17 g = math.floor(value/10000)
mischivin@36 18 s = math.fmod(math.floor(value/100),100)
mischivin@36 19 c = math.fmod(value,100)
Vynn@0 20
Vynn@0 21
mischivin@36 22 digits = math.floor(math.log10(value)+1)
Vynn@0 23
mischivin@36 24 if ( digits < 3 ) then
mischivin@36 25 gsc = string.format(" |c%s%2d|r", GSC_COPPER, c)
mischivin@36 26 elseif ( digits < 5 ) then
mischivin@36 27 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_SILVER, s, GSC_COPPER, c)
mischivin@36 28 elseif ( digits < 7 ) then
mischivin@36 29 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_GOLD, g, GSC_SILVER, s)
mischivin@36 30 elseif ( digits < 9 ) then
mischivin@36 31 gsc = string.format("|c%s%5d|r", GSC_GOLD, g)
mischivin@36 32 else
mischivin@36 33 gsc = string.format("|c%s%2.1fk|r", GSC_GOLD, g/1000)
mischivin@36 34 end
mischivin@36 35
mischivin@36 36 return gsc
Vynn@0 37 end
Vynn@0 38
mischivin@36 39 ProspectMe.GetReturn = function (containerID)
mischivin@36 40 local averageReturn = 0
mischivin@36 41 if ProspectMe.Results[containerID].TimesProspected > 0 then
mischivin@36 42 for itemID, num in pairs(ProspectMe.Results[containerID]) do
mischivin@36 43 if itemID ~= "TimesProspected" then
mischivin@36 44 averageReturn = averageReturn + ProspectMe.GetItemValue(itemID) * num
mischivin@36 45 end
Vynn@0 46 end
mischivin@36 47 averageReturn = averageReturn/ProspectMe.Results[containerID].TimesProspected
Vynn@0 48 end
mischivin@36 49 return tonumber(string.format("%.0f", averageReturn))
Vynn@0 50 end
Vynn@0 51 end
Vynn@0 52
Vynn@0 53 local cleared = true
Vynn@0 54 local function OnTooltipCleared(self)
Vynn@0 55 cleared = true
Vynn@0 56 end
Vynn@0 57
Vynn@0 58 local function OnTooltipSetItem(self)
Vynn@0 59 if cleared then
mischivin@39 60 local tooltipLink = select(2, self:GetItem())
mischivin@39 61 local spellid = select(3, self:GetSpell())
mischivin@39 62 local item = nil
mischivin@39 63 if spellid == 225902 then
mischivin@39 64 item = 123918
mischivin@39 65 elseif spellid == 225904 then
mischivin@39 66 item = 123919
mischivin@39 67 elseif spellid == 210116 then
mischivin@39 68 item = 128304
mischivin@39 69 elseif tooltipLink then
mischivin@39 70 item = tonumber(tooltipLink:match("Hitem:(%d+)"))
mischivin@39 71 spellid = nil
mischivin@39 72 else
mischivin@39 73 item = nil
mischivin@39 74 spellid = nil
mischivin@39 75 end
mischivin@39 76 if item then
mischivin@36 77 if ProspectMe.Results[item] then
mischivin@36 78 local price = ProspectMe.GetItemValue(item)
mischivin@36 79 local lifetimeReturn = ProspectMe.GetReturn(item)
mischivin@41 80 local subclass = select(7,GetItemInfo(item))
Vynn@0 81 --NumofEachQuality, Percent of Each Quality
Vynn@0 82 self:AddLine(" ")
Vynn@0 83 self:AddLine("Prospect Me",0.5,1,0.5)
mischivin@42 84 if spellid == 225902 or spellid == 225904 or subclass == ORE then
mischivin@42 85 self:AddLine("Times Prospected: " .. ProspectMe.Results[item].TimesProspected)
mischivin@42 86 elseif spellid == 210116 or subclass == HERB then
mischivin@42 87 self:AddLine("Times Milled: " .. ProspectMe.Results[item].TimesProspected)
mischivin@42 88 else
mischivin@42 89 self:AddLine("Times Processed: " .. ProspectMe.Results[item].TimesProspected)
mischivin@42 90 end
mischivin@39 91 if spellid then
mischivin@39 92 ctp = price * 20
mischivin@39 93 lifetimeReturn = lifetimeReturn * 4
mischivin@39 94 else
mischivin@39 95 ctp = price * 5
mischivin@39 96 end
mischivin@39 97 if spellid == 225902 or spellid == 225904 then
mischivin@39 98 self:AddDoubleLine("Cost to Mass Prospect: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
mischivin@39 99 elseif spellid == 210116 then
mischivin@39 100 self:AddDoubleLine("Cost to Mass Mill: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
mischivin@41 101 elseif subclass == ORE then
mischivin@39 102 self:AddDoubleLine("Cost to Prospect: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
mischivin@41 103 elseif subclass == HERB then
mischivin@39 104 self:AddDoubleLine("Cost to Mill: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
mischivin@39 105 else
mischivin@39 106 self:AddDoubleLine("Cost to Process: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
mischivin@39 107 end
mischivin@39 108 if lifetimeReturn-(ctp) > 0 then
mischivin@39 109 self:AddLine("Estimated Profit: " ..ProspectMe.FormatPrice(lifetimeReturn-(ctp)))
Vynn@0 110 self:AddLine(" ")
Vynn@0 111 else
Vynn@0 112 self:AddLine("No profit to be made",1,0,0)
Vynn@0 113 self:AddLine(" ")
Vynn@0 114 end
mischivin@36 115 local t
mischivin@36 116 if IsAltKeyDown() == ProspectMe.Config.PerSession then
mischivin@36 117 t = ProspectMe.Results
mischivin@36 118 self:AddDoubleLine("Lifetime Results","Hold/Release Alt to toggle",0.5,0.5,1,0.5,0.5,0.5)
mischivin@36 119 else
mischivin@36 120 t = ProspectMe.Session
mischivin@36 121 self:AddDoubleLine("Session Results","Hold/Release Alt to toggle",0.5,0.5,1,0.5,0.5,0.5)
mischivin@36 122 end
mischivin@36 123 if t[item] then
mischivin@36 124 for q = 7, 0, -1 do
mischivin@36 125 for result, num in pairs(t[item]) do
mischivin@36 126 if result ~= "TimesProspected" and select(3, GetItemInfo(result)) == q and ProspectMe.Config.ShowQualities[Quality[q]] then
mischivin@36 127 local p, n = "", ""
mischivin@36 128 if ProspectMe.Config.ShowPercent then
mischivin@36 129 p = num/t[item].TimesProspected*100
mischivin@36 130 if p < 10 then
mischivin@36 131 p = string.format("[%.1f%%]", p)
Vynn@0 132 else
mischivin@36 133 p = string.format("[%.0f%%]", p)
Vynn@0 134 end
mischivin@36 135 else
mischivin@36 136 p = ""
Vynn@0 137 end
mischivin@36 138 if ProspectMe.Config.ShowNumber then
mischivin@36 139 n = "[" .. num .. "]"
mischivin@36 140 else
mischivin@36 141 n = ""
mischivin@36 142 end
mischivin@36 143 self:AddDoubleLine(p .. select(2, GetItemInfo(result)) .. n, ProspectMe.FormatPrice(ProspectMe.GetItemValue(result)))
Vynn@0 144 end
Vynn@0 145 end
Vynn@0 146 end
mischivin@39 147 --self:AddLine(" ")
Vynn@0 148 end
Vynn@0 149 end
Vynn@0 150 cleared = true
Vynn@0 151 end
Vynn@0 152 end
Vynn@0 153 end
Vynn@0 154
Vynn@0 155 GameTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
mischivin@36 156 GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
mischivin@36 157 ItemRefTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
mischivin@36 158 ItemRefTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
mischivin@36 159
mischivin@36 160 local frame = CreateFrame("FRAME", "ProspectMe_Value")
mischivin@36 161 frame:RegisterEvent("VARIABLES_LOADED")
mischivin@36 162 --frame:SetScript("OnEvent", EventHandler)
mischivin@36 163 frame:SetScript("OnEvent", Initialize)