annotate ProspectMe_Tooltip.lua @ 58:f9b6c0305908

Added an integrity check to incoming data to make sure the ItemID is a valid ore/herb Updated tooltips to allow hiding of the economics data (in addition to the existing toggles for granular results) Updated tooltips to give better hints when the player hasn't prospected/milled an item before
author Vynn <mischivin@gmail.com>
date Mon, 28 Nov 2016 12:09:11 -0500
parents 60f990099d03
children
rev   line source
mischivin@36 1 local Quality = { [0] = "Junk", [1]= "Common", [2] = "Uncommon", [3] = "Rare", [4] = "Epic", }
Vynn@0 2
mischivin@36 3 local function Initialize()
mischivin@36 4 ProspectMe.FormatPrice = function (value)
Vynn@0 5
mischivin@36 6 local GSC_GOLD="ffffd100"
mischivin@36 7 local GSC_SILVER="ffe6e6e6"
mischivin@36 8 local GSC_COPPER="ffc8602c"
Vynn@0 9
mischivin@36 10 local g, s, c
mischivin@36 11 local digits = 0
mischivin@36 12 local gsc
Vynn@0 13
mischivin@36 14 g = math.floor(value/10000)
mischivin@36 15 s = math.fmod(math.floor(value/100),100)
mischivin@36 16 c = math.fmod(value,100)
Vynn@0 17
Vynn@0 18
mischivin@36 19 digits = math.floor(math.log10(value)+1)
Vynn@0 20
mischivin@36 21 if ( digits < 3 ) then
mischivin@36 22 gsc = string.format(" |c%s%2d|r", GSC_COPPER, c)
mischivin@36 23 elseif ( digits < 5 ) then
mischivin@36 24 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_SILVER, s, GSC_COPPER, c)
mischivin@36 25 elseif ( digits < 7 ) then
mischivin@36 26 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_GOLD, g, GSC_SILVER, s)
mischivin@36 27 elseif ( digits < 9 ) then
mischivin@36 28 gsc = string.format("|c%s%5d|r", GSC_GOLD, g)
mischivin@36 29 else
mischivin@36 30 gsc = string.format("|c%s%2.1fk|r", GSC_GOLD, g/1000)
mischivin@36 31 end
mischivin@36 32
mischivin@36 33 return gsc
Vynn@0 34 end
Vynn@0 35
mischivin@36 36 ProspectMe.GetReturn = function (containerID)
mischivin@36 37 local averageReturn = 0
mischivin@36 38 if ProspectMe.Results[containerID].TimesProspected > 0 then
mischivin@36 39 for itemID, num in pairs(ProspectMe.Results[containerID]) do
mischivin@36 40 if itemID ~= "TimesProspected" then
mischivin@36 41 averageReturn = averageReturn + ProspectMe.GetItemValue(itemID) * num
mischivin@36 42 end
Vynn@0 43 end
mischivin@36 44 averageReturn = averageReturn/ProspectMe.Results[containerID].TimesProspected
Vynn@0 45 end
mischivin@36 46 return tonumber(string.format("%.0f", averageReturn))
Vynn@0 47 end
Vynn@0 48 end
Vynn@0 49
Vynn@0 50 local cleared = true
Vynn@0 51 local function OnTooltipCleared(self)
Vynn@0 52 cleared = true
Vynn@0 53 end
Vynn@0 54
Vynn@0 55 local function OnTooltipSetItem(self)
Vynn@0 56 if cleared then
mischivin@39 57 local tooltipLink = select(2, self:GetItem())
mischivin@39 58 local spellid = select(3, self:GetSpell())
mischivin@39 59 local item = nil
mischivin@39 60 if spellid == 225902 then
mischivin@39 61 item = 123918
mischivin@39 62 elseif spellid == 225904 then
mischivin@39 63 item = 123919
mischivin@39 64 elseif spellid == 210116 then
mischivin@39 65 item = 128304
mischivin@39 66 elseif tooltipLink then
mischivin@39 67 item = tonumber(tooltipLink:match("Hitem:(%d+)"))
mischivin@39 68 spellid = nil
mischivin@39 69 else
mischivin@39 70 item = nil
mischivin@39 71 spellid = nil
mischivin@39 72 end
mischivin@39 73 if item then
mischivin@36 74 if ProspectMe.Results[item] then
mischivin@36 75 local price = ProspectMe.GetItemValue(item)
mischivin@36 76 local lifetimeReturn = ProspectMe.GetReturn(item)
mischivin@41 77 local subclass = select(7,GetItemInfo(item))
mischivin@47 78 local ctp = price * 5
Vynn@0 79 --NumofEachQuality, Percent of Each Quality
Vynn@0 80 self:AddLine(" ")
mischivin@47 81 local color
mischivin@48 82 if ProspectMe.Results[item].TimesProspected < 100 then
mischivin@48 83 color = "|cffff0000"
mischivin@48 84 elseif ProspectMe.Results[item].TimesProspected < 200 then
mischivin@48 85 color = "|cffffff00"
mischivin@48 86 else
mischivin@48 87 color = "|cff00ff00"
mischivin@48 88 end
mischivin@48 89
mischivin@48 90 -- SKill Text Block ""
mischivin@48 91 local skilltext
mischivin@46 92 if spellid == 225902 or spellid == 225904 or subclass == ProspectMe.Vars.ORE then
mischivin@48 93 skilltext = "Prospected"
mischivin@46 94 elseif spellid == 210116 or subclass == ProspectMe.Vars.HERB then
mischivin@48 95 skilltext = "Milled"
mischivin@42 96 else
mischivin@48 97 skilltext = "Processed"
mischivin@48 98 end
mischivin@48 99 self:AddDoubleLine("Prospect Me","Times " .. skilltext .. ": " .. color .. ProspectMe.Results[item].TimesProspected,1,0.82,0,1,1,1)
mischivin@48 100 self:AddLine(" ")
mischivin@48 101
mischivin@48 102 -- Economics Text Block
mischivin@58 103 if ProspectMe.Config.ShowEconomics then
mischivin@58 104 local spelltext
mischivin@58 105 if spellid == 225902 or spellid == 225904 then
mischivin@58 106 spelltext = "Mass Prospect"
mischivin@58 107 elseif spellid == 210116 then
mischivin@58 108 spelltext = "Mass Mill"
mischivin@58 109 elseif subclass == ProspectMe.Vars.ORE then
mischivin@58 110 spelltext = "Prospect"
mischivin@58 111 elseif subclass == ProspectMe.Vars.HERB then
mischivin@58 112 spelltext = "Mill"
mischivin@58 113 else
mischivin@58 114 spelltext = "Process"
mischivin@58 115 end
mischivin@58 116 if spellid then
mischivin@58 117 ctp = price * 20
mischivin@58 118 lifetimeReturn = lifetimeReturn * 4
mischivin@58 119 end
mischivin@58 120 local profit = lifetimeReturn - ctp
mischivin@58 121 local margin = (lifetimeReturn / ctp * 100) - 100
mischivin@58 122 self:AddDoubleLine("Estimated Profit: " .. ProspectMe.FormatPrice(profit), "Cost to " .. spelltext .. ": " .. ProspectMe.FormatPrice(ctp),1,1,1,1,1,1)
mischivin@58 123 if margin < 15 then
mischivin@58 124 color = "|cffff0000"
mischivin@58 125 elseif margin < 30 then
mischivin@58 126 color = "|cffffff00"
mischivin@58 127 else
mischivin@58 128 color = "|cff00ff00"
mischivin@58 129 end
mischivin@58 130 self:AddDoubleLine("Margin: " .. color .. string.format("[%.1f%%]", margin), "Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn),1,1,1,1,1,1)
mischivin@58 131 self:AddLine(" ")
mischivin@42 132 end
mischivin@48 133
mischivin@48 134 -- Results Text Block
mischivin@58 135 local quals = ProspectMe.Config.ShowQualities
mischivin@58 136 if quals.Junk or quals.Common or quals.Uncommon or quals.Rare or quals.Epic then
mischivin@58 137 local hint = true
mischivin@58 138 local tab
mischivin@58 139 if IsAltKeyDown() == ProspectMe.Config.PerSession then
mischivin@58 140 tab = ProspectMe.Results
mischivin@58 141 self:AddDoubleLine("Lifetime Results","Hold Alt to display",1,0.82,0,0.5,0.5,0.5)
mischivin@58 142 else
mischivin@58 143 tab = ProspectMe.Session
mischivin@58 144 self:AddDoubleLine("Session Results","Hold Alt to display",1,0.82,0,0.5,0.5,0.5)
mischivin@58 145 end
mischivin@58 146 if tab[item] then
mischivin@58 147 for q = 7, 0, -1 do
mischivin@58 148 for result, num in pairs(tab[item]) do
mischivin@58 149 if result ~= "TimesProspected" and select(3, GetItemInfo(result)) == q and ProspectMe.Config.ShowQualities[Quality[q]] then
mischivin@58 150 hint = false
mischivin@58 151 local p, n = "", ""
mischivin@58 152 if ProspectMe.Config.ShowPercent then
mischivin@58 153 p = num/tab[item].TimesProspected*100
mischivin@58 154 if p < 10 then
mischivin@58 155 p = string.format("|cffffffff[%.1f%%] ", p)
mischivin@58 156 else
mischivin@58 157 p = string.format("|cffffffff[%.0f%%] ", p)
mischivin@58 158 end
Vynn@0 159 else
mischivin@58 160 p = ""
Vynn@0 161 end
mischivin@58 162 if ProspectMe.Config.ShowNumber then
mischivin@58 163 n = "|cffffffffx" .. num
mischivin@58 164 else
mischivin@58 165 n = ""
mischivin@58 166 end
mischivin@58 167 self:AddDoubleLine(p .. select(2, GetItemInfo(result)) .. n, ProspectMe.FormatPrice(ProspectMe.GetItemValue(result)))
Vynn@0 168 end
Vynn@0 169 end
Vynn@0 170 end
Vynn@0 171 end
mischivin@58 172 if hint then
mischivin@58 173 if spellid == 225902 or spellid == 225904 or subclass == ProspectMe.Vars.ORE then
mischivin@58 174 self:AddLine("|cffffffffTry Prospecting some ore to see your results!")
mischivin@58 175 elseif spellid == 210116 or subclass == ProspectMe.Vars.HERB then
mischivin@58 176 self:AddLine("|cffffffffTry Milling some plants to see your results!")
mischivin@58 177 else
mischivin@58 178 self:Addline("|cffffffffTry processing some material to see your results!")
mischivin@58 179 end
mischivin@58 180 end
mischivin@58 181
mischivin@39 182 --self:AddLine(" ")
Vynn@0 183 end
Vynn@0 184 end
Vynn@0 185 cleared = true
Vynn@0 186 end
Vynn@0 187 end
Vynn@0 188 end
Vynn@0 189
Vynn@0 190 GameTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
mischivin@36 191 GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
mischivin@36 192 ItemRefTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
mischivin@36 193 ItemRefTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
mischivin@36 194
mischivin@36 195 local frame = CreateFrame("FRAME", "ProspectMe_Value")
mischivin@36 196 frame:RegisterEvent("VARIABLES_LOADED")
mischivin@36 197 --frame:SetScript("OnEvent", EventHandler)
mischivin@36 198 frame:SetScript("OnEvent", Initialize)