forked from tg123/RaidLedger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.lua
214 lines (174 loc) · 6.73 KB
/
cli.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
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
local _, ADDONSELF = ...
local L = ADDONSELF.L
local GUI = ADDONSELF.gui
local Database = ADDONSELF.db
local Print = ADDONSELF.print
local deformat = ADDONSELF.deformat
local RegEvent = ADDONSELF.regevent
hooksecurefunc("SetItemRef", function(link)
if GUI.mainframe:IsShown() and IsShiftKeyDown() then
local linkType, target = strsplit(":", link)
if linkType == "item" then
-- local _, itemLink = GetItemInfo(target)
-- if itemLink then
-- Print(L["Item added"] .. " " .. itemLink)
-- Database:AddLoot(itemLink, 1, "", 0, true)
-- end
elseif linkType == "player" then
local playerName = strsplit("-", target)
Print(L["Compensation added"] .. " " .. playerName)
local edit = GetCurrentKeyBoardFocus()
if edit and edit.raidledgerbeneficiary then
edit:SetText(playerName)
else
Database:AddDebit("", playerName)
end
end
ScrollFrame_OnVerticalScroll(GUI.lootLogFrame.scrollframe, 0)
end
end)
do
local lasttime = 0
local lastlink = nil
hooksecurefunc("HandleModifiedItemClick", function(link)
if lastlink == link then
if time() - lasttime < 2 then
return
end
end
if GUI.mainframe:IsShown() and not ChatEdit_GetActiveWindow() then
local _, itemLink = GetItemInfo(link)
if itemLink then
Print(L["Item added"] .. " " .. itemLink)
Database:AddLoot(itemLink, 1, "", 0, true)
end
lasttime = time()
lastlink = link
end
end)
end
local AUTOADDLOOT_TYPE_ALL = 0
-- local AUTOADDLOOT_TYPE_PARTY = 1
local AUTOADDLOOT_TYPE_RAID = 1
local AUTOADDLOOT_TYPE_DISABLE = 2
-- local AutoAddLoot = AUTOADDLOOT_TYPE_RAID
RegEvent("CHAT_MSG_LOOT", function(chatmsg)
local AutoAddLoot = Database:GetConfigOrDefault("autoaddloot", AUTOADDLOOT_TYPE_RAID)
if AutoAddLoot == AUTOADDLOOT_TYPE_DISABLE then
return
elseif AutoAddLoot == AUTOADDLOOT_TYPE_RAID and not IsInRaid() then
return
end
local playerName, itemLink, itemCount = deformat(chatmsg, LOOT_ITEM_MULTIPLE);
-- next try: somebody else received single loot
if (playerName == nil) then
itemCount = 1;
playerName, itemLink = deformat(chatmsg, LOOT_ITEM);
end
-- if player == nil, then next try: player received multiple loot
if (playerName == nil) then
playerName = UnitName("player");
itemLink, itemCount = deformat(chatmsg, LOOT_ITEM_SELF_MULTIPLE);
end
-- if itemLink == nil, then last try: player received single loot
if (itemLink == nil) then
itemCount = 1;
itemLink = deformat(chatmsg, LOOT_ITEM_SELF);
end
-- if itemLink == nil, then there was neither a LOOT_ITEM, nor a LOOT_ITEM_SELF message
if (itemLink == nil) then
-- MRT_Debug("No valid loot event received.");
return;
end
-- if code reaches this point, we should have a valid looter and a valid itemLink
-- print(itemLink)
Database:AddLoot(itemLink, itemCount, playerName, 0);
end)
RegEvent("ADDON_LOADED", function()
local ldb = LibStub("LibDataBroker-1.1")
local icon = LibStub("LibDBIcon-1.0")
local config = Database:GetConfigOrDefault("minimapicons", {})
config.hide = not Database:GetConfigOrDefault("minimapicon", true)
Database:SetConfig("minimapicons", config)
icon:Register("RaidLedger", ldb:NewDataObject("RaidLedger", {
icon = "Interface\\Icons\\inv_misc_note_03",
OnClick = function()
if GUI.mainframe:IsShown() then
GUI.mainframe:Hide()
else
GUI.mainframe:Show()
end
end,
OnTooltipShow = function(tooltip)
tooltip:AddLine(L["Raid Ledger"])
end,
}), config)
end)
local clearledger = function()
StaticPopup_Show("RAIDLEDGER_CLEARMSG")
end
do
-- some pharc addon overwrite AlertFrame
local frame = EnumerateFrames()
while frame do
if frame:GetName() == "AlertFrame" then
local cleartoast = frame:AddSimpleAlertFrameSubSystem("MoneyWonAlertFrameTemplate", function(frame, text)
frame.Icon:SetTexture("Interface\\Icons\\inv_misc_note_03")
frame.Label:SetText(L["Raid Ledger"])
frame.Amount:SetText(L["Click here to clear ledger"])
frame.Amount:SetWidth(180)
frame.Amount:SetFontObject(GameFontWhite)
frame:SetScript("OnClick", clearledger)
if not frame.closebtn then
b = CreateFrame("Button", nil, frame, "UIPanelCloseButton")
b:SetPoint("TOPRIGHT", frame, 0, 0);
frame.closebtn = b
end
end)
local lastzone = nil
C_Timer.NewTicker(5, function()
local zone = GetInstanceInfo()
if not zone then
return
end
if zone == "" then
return
end
local _, type = IsInInstance()
if type == "raid" then
if lastzone ~= zone then
if #Database:GetCurrentLedger()["items"] > 0 then
cleartoast:AddAlert()
end
end
end
lastzone = zone
end)
break
end
frame = EnumerateFrames(frame)
end
end
SlashCmdList["RAIDLEDGER"] = function(msg, editbox)
local cmd, what = msg:match("^(%S*)%s*(%S*)%s*$")
if cmd == "" then
GUI:Show()
Print(L["Shift + item/name to add to record"])
Print(L["Right click to remove record"])
-- Print(L["Shift + Right click to remove ALL SAME record"])
-- ShowCurrentAutoLootType()
-- Print("[".. L["/raidledger"] .. " toggle] " .. L["toggle Auto recording on/off"])
-- elseif cmd == "toggle" then
-- AutoAddLoot = (AutoAddLoot + 1) % 3
-- Database:SetConfig("autoaddloot", AutoAddLoot)
-- ShowCurrentAutoLootType()
else
local _, itemLink = GetItemInfo(strtrim(msg))
if itemLink then
Database:AddLoot(itemLink, 1, "", 0, true)
Print(L["Item added"] .. " " .. itemLink)
end
end
end
SLASH_RAIDLEDGER1 = "/GTUAN"
SLASH_RAIDLEDGER2 = "/RAIDLEDGER"