-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLootExport.lua
More file actions
227 lines (191 loc) · 7.65 KB
/
Copy pathLootExport.lua
File metadata and controls
227 lines (191 loc) · 7.65 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
local ROLL_STATES = {
[-1] = "Won",
[0] = "NeedMainSpec",
[1] = "NeedOffSpec",
[2] = "Transmog",
[3] = "Greed",
[4] = "NoRoll",
[5] = "Pass"
}
local addon = {}
local mode_all = false
local mode_format = "spreadsheet"
local function Compare(a, b)
if a[-1] ~= b[-1] then return a[-1] > b[-1] end
return a.playerName < b.playerName
end
function addon:BuildLootString(all, format)
local summary = {}
local str = {}
local warn = false
local delimiter = "\t"
local link = true
if format == "chat" then
delimiter = " "
link = false
end
local encounters = C_LootHistory.GetAllEncounterInfos()
--DevTools_Dump(encounters)
for _, encounter in ipairs(encounters) do
local _, _, _, difficulty = GetInstanceInfo()
local stamp = date("%b %d %H:%M", time() - GetTime() + (encounter.startTime / 1000))
local boss = encounter.encounterName .. " - " .. (difficulty or "?") .. " (" .. stamp .. ")\n"
table.insert(str, boss)
local drops = C_LootHistory.GetSortedDropsForEncounter(encounter.encounterID)
--DevTools_Dump(drops)
for _, drop in ipairs(drops) do
table.insert(str, drop.itemHyperlink)
if link then
table.insert(str, delimiter .. drop.itemHyperlink:gsub('\124','\124\124')) -- better way to print item info? wowhead link?
end
for _, roll in ipairs(drop.rollInfos) do
if roll.state == 4 then
warn = true
else
local rollstr = ""
if roll.roll then
rollstr = " " .. tostring(roll.roll)
end
table.insert(str, delimiter .. roll.playerName .. " (" .. ROLL_STATES[roll.state] .. rollstr .. ")")
-- track summary
if not summary[roll.playerName] then
summary[roll.playerName] = { [-1]=0, [0]=0, [1]=0, [2]=0, [3]=0, [4]=0, [5]=0 }
end
summary[roll.playerName][roll.state] = summary[roll.playerName][roll.state] + 1
if roll.isWinner then
summary[roll.playerName][-1] = summary[roll.playerName][-1] + 1
end
end
end
table.insert(str, "\n")
end
if not all then break end
table.insert(str, "\n")
end
if format == "summary" then
str = {}
-- sort
local sorted = {}
for playerName, rolls in pairs(summary) do
rolls.playerName = playerName
table.insert(sorted, rolls)
end
table.sort(sorted, Compare)
-- headers
table.insert(str, "Name")
for i = -1, 5 do
table.insert(str, delimiter .. ROLL_STATES[i])
end
table.insert(str, "\n")
-- rows
for _, row in ipairs(sorted) do
table.insert(str, row.playerName)
for i = -1, 5 do
table.insert(str, delimiter .. row[i])
end
table.insert(str, "\n")
end
end
return table.concat(str), warn
end
function addon:ShowLootExportClipboard(text, warn)
if not LootExportClipboard then
local f = CreateFrame("Frame", "LootExportClipboard", UIParent, "PortraitFrameTemplate")
f:SetPoint("CENTER")
f:SetSize(600, 500)
f:SetTitle("Loot Export")
f:SetPortraitToAsset("Interface\\Icons\\inv_misc_coin_17")
-- Movable
f:SetMovable(true)
f:SetClampedToScreen(true)
f.TitleContainer:EnableMouse(true)
f.TitleContainer:SetScript("OnMouseDown", function() f:StartMoving() end)
f.TitleContainer:SetScript("OnMouseUp", function()
f:StopMovingOrSizing()
end)
-- Resizable
f:SetResizable(true)
f:SetResizeBounds(300, 200, 2000, 2000)
f.resizeButton = CreateFrame("Button", nil, f)
f.resizeButton:SetPoint("BOTTOMRIGHT", -6, 7)
f.resizeButton:SetSize(16, 16)
f.resizeButton:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
f.resizeButton:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
f.resizeButton:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
f.resizeButton:SetScript("OnMouseDown", function() f:StartSizing("BOTTOMRIGHT") end)
f.resizeButton:SetScript("OnMouseUp", function()
f:StopMovingOrSizing()
end)
-- Context Menu
f.menu = CreateFrame("Frame", nil, f, "UIDropDownMenuTemplate")
-- Header Text
f.header = f:CreateFontString(nil, "OVERLAY", "GameTooltipText")
f.header:SetPoint("LEFT", f, "TOPLEFT", 60, -38)
-- Buttons
f.bossButton = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
f.bossButton:SetSize(80, 22)
f.bossButton:SetText("Bosses")
f.bossButton:SetPoint("RIGHT", f, "TOPRIGHT", -96, -38)
f.bossButton:SetScript("OnClick", function()
UIDropDownMenu_Initialize(f.menu, function(frame, level, menuList)
UIDropDownMenu_AddButton({ text = "Last Boss", arg1 = false, func = addon.ModeBoss })
UIDropDownMenu_AddButton({ text = "All Bosses", arg1 = true, func = addon.ModeBoss })
end, "MENU")
ToggleDropDownMenu(1, nil, f.menu, f.bossButton, 0, 0)
end)
f.formatButton = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
f.formatButton:SetSize(80, 22)
f.formatButton:SetText("Format")
f.formatButton:SetPoint("RIGHT", f, "TOPRIGHT", -8, -38)
f.formatButton:SetScript("OnClick", function()
UIDropDownMenu_Initialize(f.menu, function(frame, level, menuList)
UIDropDownMenu_AddButton({ text = "Spreadsheet", arg1 = "spreadsheet", func = addon.ModeFormat })
UIDropDownMenu_AddButton({ text = "Discord", arg1 = "chat", func = addon.ModeFormat })
UIDropDownMenu_AddButton({ text = "Summary", arg1 = "summary", func = addon.ModeFormat })
end, "MENU")
ToggleDropDownMenu(1, nil, f.menu, f.formatButton, 0, 0)
end)
-- Scroll Frame
f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "ScrollFrameTemplate")
f.scrollFrame:SetPoint("TOPLEFT", 16, -60)
f.scrollFrame:SetPoint("BOTTOMRIGHT", -27, 24)
-- EditBox
local eb = CreateFrame("EditBox", "LootExportClipboardEditBox", f)
eb:SetWidth(f.scrollFrame:GetWidth())
eb:SetMultiLine(true)
eb:SetFontObject("ChatFontNormal")
eb:SetScript("OnEscapePressed", function() f:Hide() end)
f.scrollFrame:SetScrollChild(eb)
f.scrollFrame:SetScript("OnSizeChanged", function()
eb:SetWidth(f.scrollFrame:GetWidth())
end)
end
if text then
LootExportClipboardEditBox:SetText(text)
end
if warn then
LootExportClipboard.header:SetText("WARNING: ROLL STILL IN PROGRESS")
else
LootExportClipboard.header:SetText("")
end
LootExportClipboard:Show()
LootExportClipboardEditBox:HighlightText()
LootExportClipboardEditBox:SetFocus()
end
function addon:ModeBoss(all)
mode_all = all
addon:ShowLootExport()
end
function addon:ModeFormat(format)
mode_format = format
addon:ShowLootExport()
end
function addon:ShowLootExport()
local text, warn = addon:BuildLootString(mode_all, mode_format)
addon:ShowLootExportClipboard(text, warn)
end
SLASH_LOOTEXPORT1 = "/lootexport"
SLASH_LOOTEXPORT2 = "/le"
SlashCmdList.LOOTEXPORT = function(msg)
addon:ShowLootExport()
end