-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathComparePowerReportListControl.lua
More file actions
161 lines (146 loc) · 4.42 KB
/
Copy pathComparePowerReportListControl.lua
File metadata and controls
161 lines (146 loc) · 4.42 KB
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
153
154
155
156
157
158
159
160
161
-- Path of Building
--
-- Class: Compare Power Report List
-- List control for the compare power report in the Summary tab.
--
local t_insert = table.insert
local t_sort = table.sort
local ComparePowerReportListClass = newClass("ComparePowerReportListControl", "ListControl", function(self, anchor, rect)
self.ListControl(anchor, rect, 18, "VERTICAL", false)
local width = rect[3]
self.impactColumn = { width = width * 0.22, label = "", sortable = true }
self.colList = {
{ width = width * 0.10, label = "Category", sortable = true },
{ width = width * 0.44, label = "Name" },
self.impactColumn,
{ width = width * 0.06, label = "Points", sortable = true },
{ width = width * 0.14, label = "Per Point", sortable = true },
}
self.colLabels = true
self.showRowSeparators = true
self.statusText = "Select a metric above to generate the power report."
end)
function ComparePowerReportListClass:SetReport(stat, report)
self.impactColumn.label = stat and stat.label or ""
self.reportData = report or {}
if stat and stat.stat then
if report and #report > 0 then
self.statusText = nil
else
self.statusText = "No differences found."
end
else
self.statusText = "Select a metric above to generate the power report."
end
self:ReList()
self:ReSort(3)
end
function ComparePowerReportListClass:SetProgress(progress)
if progress < 100 then
self.statusText = "Calculating... " .. progress .. "%"
self.list = {}
end
end
function ComparePowerReportListClass:Draw(viewPort, noTooltip)
if self.hoverIndex ~= self.lastTooltipIndex then
self.tooltip.updateParams = nil
end
self.lastTooltipIndex = self.hoverIndex
self.ListControl.Draw(self, viewPort, noTooltip)
-- Draw status text below column headers when the list is empty
if #self.list == 0 and self.statusText then
local x, y = self:GetPos()
local width, height = self:GetSize()
-- Column headers are 18px tall, plus 2px border = start at y+20
SetViewport(x + 2, y + 20, width - 20, height - 22)
SetDrawColor(1, 1, 1)
DrawString(4, 4, "LEFT", 14, "VAR", self.statusText)
SetViewport()
end
end
function ComparePowerReportListClass:ReSort(colIndex)
local compare = function(a, b) return a > b end
if colIndex == 1 then
t_sort(self.list, function(a, b)
if a.category == b.category then
return compare(math.abs(a.impact), math.abs(b.impact))
end
return a.category < b.category
end)
elseif colIndex == 3 then
t_sort(self.list, function(a, b)
return compare(a.impact, b.impact)
end)
elseif colIndex == 4 then
t_sort(self.list, function(a, b)
local aDist = a.pathDist or 99999
local bDist = b.pathDist or 99999
if aDist == bDist then
return compare(math.abs(a.impact), math.abs(b.impact))
end
return aDist < bDist
end)
elseif colIndex == 5 then
t_sort(self.list, function(a, b)
local aVal = a.perPoint or -99999
local bVal = b.perPoint or -99999
return compare(aVal, bVal)
end)
end
end
function ComparePowerReportListClass:ReList()
self.list = {}
if not self.reportData then
return
end
for _, entry in ipairs(self.reportData) do
t_insert(self.list, entry)
end
end
function ComparePowerReportListClass:AddValueTooltip(tooltip, index, entry)
if main.popups[1] then
tooltip:Clear()
return
end
local build = self.compareTab and self.compareTab.primaryBuild
if not build then
tooltip:Clear()
return
end
if entry.category == "Tree" and entry.nodeId then
local node = build.spec.nodes[entry.nodeId]
if node then
if tooltip:CheckForUpdate(node, IsKeyDown("SHIFT"), launch.devModeAlt, build.outputRevision) then
local viewer = build.treeTab and build.treeTab.viewer
if viewer then
viewer:AddNodeTooltip(tooltip, node, build)
end
end
else
tooltip:Clear()
end
elseif entry.category == "Item" and entry.itemObj then
if tooltip:CheckForUpdate(entry.itemObj, IsKeyDown("SHIFT"), launch.devModeAlt, build.outputRevision) then
build.itemsTab:AddItemTooltip(tooltip, entry.itemObj)
end
else
tooltip:Clear()
end
end
function ComparePowerReportListClass:GetRowValue(column, index, entry)
if column == 1 then
return (entry.categoryColor or "^7") .. entry.category
elseif column == 2 then
return (entry.nameColor or "^7") .. entry.name
elseif column == 3 then
return entry.combinedImpactStr or entry.impactStr or "0"
elseif column == 4 then
if entry.pathDist then
return tostring(entry.pathDist)
end
return ""
elseif column == 5 then
return entry.perPointStr or ""
end
return ""
end