comparison ProspectMe_Tooltip.lua @ 36:5cbaaee1e7db Prospect Me 2

Updated Tooltips to support V2
author Vynn <mischivin@gmail.com>
date Thu, 10 Nov 2016 12:26:14 -0500
parents 4a10e5d1618c
children b9c2260bf1b4
comparison
equal deleted inserted replaced
35:705d0595006a 36:5cbaaee1e7db
1 --PM_HERBSUBCLASS = select(6, GetAuctionItemSubClasses(6)) 1 --PM_HERBSUBCLASS = select(6, GetAuctionItemSubClasses(6))
2 --PM_ORESUBCLASS = select(4, GetAuctionItemSubClasses(6)) 2 --PM_ORESUBCLASS = select(4, GetAuctionItemSubClasses(6))
3 3
4 --Hardcoded until I find a better solution now that GetAuctionItemSubClass() has changed 4 local Quality = { [0] = "Junk", [1]= "Common", [2] = "Uncommon", [3] = "Rare", [4] = "Epic", }
5 PM_HERBSUBCLASS = "Herb"
6 PM_ORESUBCLASS = "Metal & Stone"
7 5
8 function PM_FormatPrice(value) 6 local function Initialize()
7 ProspectMe.FormatPrice = function (value)
9 8
10 local GSC_GOLD="ffffd100" 9 local GSC_GOLD="ffffd100"
11 local GSC_SILVER="ffe6e6e6" 10 local GSC_SILVER="ffe6e6e6"
12 local GSC_COPPER="ffc8602c" 11 local GSC_COPPER="ffc8602c"
13 12
14 local g, s, c 13 local g, s, c
15 local digits = 0 14 local digits = 0
16 local gsc 15 local gsc
17 16
18 g = math.floor(value/10000) 17 g = math.floor(value/10000)
19 s = math.fmod(math.floor(value/100),100) 18 s = math.fmod(math.floor(value/100),100)
20 c = math.fmod(value,100) 19 c = math.fmod(value,100)
21 20
22 21
23 digits = math.floor(math.log10(value)+1) 22 digits = math.floor(math.log10(value)+1)
24 23
25 if ( digits < 3 ) then 24 if ( digits < 3 ) then
26 gsc = string.format(" |c%s%2d|r", GSC_COPPER, c) 25 gsc = string.format(" |c%s%2d|r", GSC_COPPER, c)
27 elseif ( digits < 5 ) then 26 elseif ( digits < 5 ) then
28 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_SILVER, s, GSC_COPPER, c) 27 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_SILVER, s, GSC_COPPER, c)
29 elseif ( digits < 7 ) then 28 elseif ( digits < 7 ) then
30 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_GOLD, g, GSC_SILVER, s) 29 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_GOLD, g, GSC_SILVER, s)
31 elseif ( digits < 9 ) then 30 elseif ( digits < 9 ) then
32 gsc = string.format("|c%s%5d|r", GSC_GOLD, g) 31 gsc = string.format("|c%s%5d|r", GSC_GOLD, g)
33 else 32 else
34 gsc = string.format("|c%s%2.1fk|r", GSC_GOLD, g/1000) 33 gsc = string.format("|c%s%2.1fk|r", GSC_GOLD, g/1000)
34 end
35
36 return gsc
35 end 37 end
36 38
37 return gsc 39 ProspectMe.GetReturn = function (containerID)
38 end 40 local averageReturn = 0
39 41 if ProspectMe.Results[containerID].TimesProspected > 0 then
40 function PM_GetReturn(containerID) 42 for itemID, num in pairs(ProspectMe.Results[containerID]) do
41 local averageReturn = 0 43 if itemID ~= "TimesProspected" then
42 if PM_ResultsTable[containerID].timesProspected > 0 then 44 averageReturn = averageReturn + ProspectMe.GetItemValue(itemID) * num
43 for itemID, num in pairs(PM_ResultsTable[containerID]) do 45 end
44 if itemID ~= "timesProspected" then
45 averageReturn = averageReturn + PM_ItemTable[itemID].price * num
46 end 46 end
47 averageReturn = averageReturn/ProspectMe.Results[containerID].TimesProspected
47 end 48 end
48 averageReturn = averageReturn/PM_ResultsTable[containerID].timesProspected 49 return tonumber(string.format("%.0f", averageReturn))
49 end 50 end
50 return tonumber(string.format("%.0f", averageReturn))
51 end 51 end
52 52
53 local cleared = true 53 local cleared = true
54 local function OnTooltipCleared(self) 54 local function OnTooltipCleared(self)
55 cleared = true 55 cleared = true
57 57
58 local function OnTooltipSetItem(self) 58 local function OnTooltipSetItem(self)
59 if cleared then 59 if cleared then
60 local name, tooltipLink = self:GetItem() 60 local name, tooltipLink = self:GetItem()
61 if tooltipLink then 61 if tooltipLink then
62 local item = tooltipLink:match("Hitem:(%d+)") 62 local item = tonumber(tooltipLink:match("Hitem:(%d+)"))
63 if PM_ResultsTable[item] then 63 if ProspectMe.Results[item] then
64 local lifetimeReturn = PM_GetReturn(item) 64 local price = ProspectMe.GetItemValue(item)
65 local lifetimeReturn = ProspectMe.GetReturn(item)
65 --NumofEachQuality, Percent of Each Quality 66 --NumofEachQuality, Percent of Each Quality
66 self:AddLine(" ") 67 self:AddLine(" ")
67 self:AddLine("Prospect Me",0.5,1,0.5) 68 self:AddLine("Prospect Me",0.5,1,0.5)
68 -- Subclass Detection is broken in Legion - may need to hard-code this or find another way of getting locatlizes subclass names. 69 self:AddLine("Times Processed: " .. ProspectMe.Results[item].TimesProspected)
69 if PM_ItemTable[item].subclass == PM_ORESUBCLASS then 70 self:AddDoubleLine("Cost to Process: " .. ProspectMe.FormatPrice(5 * price), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
70 self:AddLine("Times Prospected: " .. PM_ResultsTable[item].timesProspected) 71 if lifetimeReturn-(5 * price) > 0 then
71 self:AddDoubleLine("Cost to Prospect: " .. PM_FormatPrice(5 * PM_ItemTable[item].price), " Average Return: " .. PM_FormatPrice(PM_GetReturn(item))) 72 self:AddLine("Estimated Profit: " ..ProspectMe.FormatPrice(lifetimeReturn-(5 * price)))
72 elseif PM_ItemTable[item].subclass == PM_HERBSUBCLASS then
73 self:AddLine("Times Milled: " .. PM_ResultsTable[item].timesProspected)
74 self:AddDoubleLine("Cost to Mill: " .. PM_FormatPrice(5 * PM_ItemTable[item].price), " Average Return: " .. PM_FormatPrice(PM_GetReturn(item)))
75
76 end
77 if lifetimeReturn-(5 * PM_ItemTable[item].price) > 0 then
78 self:AddLine("Estimated Profit: " .. PM_FormatPrice(lifetimeReturn-(5 * PM_ItemTable[item].price)))
79 self:AddLine(" ") 73 self:AddLine(" ")
80 else 74 else
81 self:AddLine("No profit to be made",1,0,0) 75 self:AddLine("No profit to be made",1,0,0)
82 self:AddLine(" ") 76 self:AddLine(" ")
83 end 77 end
84 if PM_Config.results then 78 local t
85 local t 79 if IsAltKeyDown() == ProspectMe.Config.PerSession then
86 if IsAltKeyDown() == PM_Config.session then 80 t = ProspectMe.Results
87 t = PM_ResultsTable 81 self:AddDoubleLine("Lifetime Results","Hold/Release Alt to toggle",0.5,0.5,1,0.5,0.5,0.5)
88 self:AddDoubleLine("Lifetime Results","Hold/Release Alt to toggle",0.5,0.5,1,0.5,0.5,0.5) 82 else
89 else 83 t = ProspectMe.Session
90 t = PM_SessionTable 84 self:AddDoubleLine("Session Results","Hold/Release Alt to toggle",0.5,0.5,1,0.5,0.5,0.5)
91 self:AddDoubleLine("Session Results","Hold/Release Alt to toggle",0.5,0.5,1,0.5,0.5,0.5) 85 end
92 end 86 if t[item] then
93 if t[item] then 87 for q = 7, 0, -1 do
94 for q = 7, 0, -1 do 88 for result, num in pairs(t[item]) do
95 for result, num in pairs(t[item]) do 89 if result ~= "TimesProspected" and select(3, GetItemInfo(result)) == q and ProspectMe.Config.ShowQualities[Quality[q]] then
96 if result ~= "timesProspected" and PM_ItemTable[result].quality == q and PM_Config.qualities[q] then 90 local p, n = "", ""
97 local p, n = "", "" 91 if ProspectMe.Config.ShowPercent then
98 if PM_Config.percent then 92 p = num/t[item].TimesProspected*100
99 p = num/t[item].timesProspected*100 93 if p < 10 then
100 if p < 10 then 94 p = string.format("[%.1f%%]", p)
101 p = string.format("[%.1f%%]", p)
102 else
103 p = string.format("[%.0f%%]", p)
104 end
105 else 95 else
106 p = "" 96 p = string.format("[%.0f%%]", p)
107 end 97 end
108 if PM_Config.number then 98 else
109 n = "[" .. num .. "]" 99 p = ""
110 else
111 n = ""
112 end
113 self:AddDoubleLine(p .. PM_ItemTable[result].link .. n, PM_FormatPrice(PM_ItemTable[result].price))
114 end 100 end
101 if ProspectMe.Config.ShowNumber then
102 n = "[" .. num .. "]"
103 else
104 n = ""
105 end
106 self:AddDoubleLine(p .. select(2, GetItemInfo(result)) .. n, ProspectMe.FormatPrice(ProspectMe.GetItemValue(result)))
115 end 107 end
116 end 108 end
117 end 109 end
118 self:AddLine(" ") 110 self:AddLine(" ")
119 end 111 end
123 end 115 end
124 end 116 end
125 117
126 GameTooltip:HookScript("OnTooltipCleared", OnTooltipCleared) 118 GameTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
127 GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem) 119 GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
120 ItemRefTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
121 ItemRefTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
122
123 local frame = CreateFrame("FRAME", "ProspectMe_Value")
124 frame:RegisterEvent("VARIABLES_LOADED")
125 --frame:SetScript("OnEvent", EventHandler)
126 frame:SetScript("OnEvent", Initialize)