-
Notifications
You must be signed in to change notification settings - Fork 2
/
pawn_integration.lua
153 lines (133 loc) · 4.67 KB
/
pawn_integration.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
--[[
Pawn integration for Ludwig. It shows Pawn values in LW list and sorts by them.
Install:
1. Ludwig and Pawn addons required.
2. Copy pawn_integration.lua and pawn_integration.xml files to "WoW\Interface\AddOns\Ludwig" directory.
3. Append line "pawn_integration.xml" (without quotes) to the end of "WoW\Interface\AddOns\Ludwig\Ludwig.toc"
file using any text editor.
Tested with Ludwig 1.6.0 and Pawn 1.1.2 for WoW 2.4.3.
Author: Dawer
Version: 0.2.0-beta
Commands:
/lw --pawn|Scale name
Sorts by Pawn's scale values.
/lw --pawn
Disables sorting.
]]
local lwSlashHandler = SlashCmdList["LudwigSlashCOMMAND"]
local getItems = Ludwig.GetItems
local pawnTooltipAnnotation = "|cff8ec3e6(*)|r "
local pawnCache, underestimatedCache = {}, {}
local function LMsg(msg)
ChatFrame1:AddMessage(format("|cFF00EE00Ludwig|r: %s", tostring(msg)))
end
--[[ Override functions ]]
SlashCmdList["LudwigSlashCOMMAND"] = function(msg)
if msg and msg:lower():match("%-%-pawn") then
if not PawnGetItemData then
LMsg("Pawn is not available")
return
end
local scale_name = msg:match("||(.*)")
if scale_name then
if not PawnOptions.Scales[scale_name] then
Ludwig.pawnSort = false
LMsg("Pawn scale not found: " .. scale_name)
else
Ludwig.pawnSort = true
Ludwig.pawnScaleName = scale_name
LMsg("Pawn sorting enabled (" .. scale_name .. ")")
end
else
Ludwig.pawnSort = false
LMsg("Pawn sorting disabled")
end
LudwigUI_UpdateList(true)
else
lwSlashHandler(msg)
end
end
-- Add right justified label to items
do
local function setID(button, id)
if PawnGetItemData and Ludwig.pawnSort then
local text = ''
local pval = pawnCache[id]
if pval then
pval = string.format("%." .. PawnOptions.Digits .. "f", pval)
text = pval or ''
end
if underestimatedCache[id] then
text = pawnTooltipAnnotation .. text
end
button.RightText:SetText(text)
else
button.RightText:SetText('')
end
end
local rtext
for _, button in ipairs(LudwigFrame.items) do
rtext = button:CreateFontString(button:GetName() .. 'RightText')
rtext:SetPoint('RIGHT', -4, 0);
rtext:SetJustifyH('RIGHT')
rtext:SetFont(button:GetFont())
button.RightText = rtext
hooksecurefunc(button, 'SetID', setID)
end
end
--[[
Checks the class allowed to use current item.
The current item is set to PawnPrivateTooltip after PawnGetItemData(...) call
even the item was in cache (cache miss bug in Pawn).
Suppose cache miss bug is not fixed.
Parameters:
className: Class name in English.
]]
local function isAllowedForClass(className)
local tooltip = PawnPrivateTooltip
local leftLineText
for i = 1, tooltip:NumLines() do
leftLineText = getglobal('PawnPrivateTooltipTextLeft' .. i):GetText()
if string.match(leftLineText, "^Classes:") then
return string.match(leftLineText, className) ~= nil
end
end
-- If not specified allow by default.
return true
end
function Ludwig:GetItems(name, quality, typefilters, minLevel, maxLevel)
-- disable sorting if no filter set
if not (name or quality or (typefilters and next(typefilters) ~= nil) or minLevel or maxLevel) then
Ludwig.pawnSort = false
end
local items = getItems(self, name, quality, typefilters, minLevel, maxLevel)
if PawnGetItemData and Ludwig.pawnSort then
-- cache Pawn values
local itemData, pval
local playerClass = UnitClass('player')
pawnCache = {}
underestimatedCache = {}
for _, id in pairs(items) do
itemData = PawnGetItemData(Ludwig:GetItemLink(id))
pval = PawnGetSingleValueFromItem(itemData, Ludwig.pawnScaleName)
if not isAllowedForClass(playerClass) then
pval = nil
end
if pval then
pawnCache[id] = pval
end
if itemData.UnknownLines then
underestimatedCache[id] = itemData.UnknownLines
end
end
table.sort(items, function(id1, id2)
local pval1 = pawnCache[id1]
local pval2 = pawnCache[id2]
if pval1 == pval2 then
return Ludwig.SortByEverything(id1, id2)
end
return (pval1 or 0) > (pval2 or 0)
end)
end
return items
end