-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Broker.lua
174 lines (154 loc) · 5.53 KB
/
Broker.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
--[[
* Copyright (c) 2011-2020 by Adam Hellberg.
*
* This file is part of KillTrack.
*
* KillTrack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KillTrack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KillTrack. If not, see <http://www.gnu.org/licenses/>.
--]]
---@class KillTrack
local KT = select(2, ...)
---@class KillTrackBroker
local KTB = {
Text = {
Short = "KPM: %.2f",
Long = "Kills Per Minute: %.2f"
}
}
KT.Broker = KTB
local KTT = KT.Tools
local UPDATE = 1
local t = 0
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local icon = LibStub:GetLibrary("LibDBIcon-1.0")
local frame = CreateFrame("Frame")
local tooltipVisible = false
local data = {
type = "data source",
label = KT.Name,
icon = "Interface\\AddOns\\KillTrack\\icon.tga",
tocname = KT.Name
}
local clickFunctions = {
none = {
LeftButton = function() KT.MobList:Toggle() end,
MiddleButton = function() KTB:ToggleTextMode() end,
RightButton = function() KT:ResetSession() end
},
ctrl = {
LeftButton = function() KT:Announce("GROUP") end, -- Announce to group/say
MiddleButton = function() KT.Immediate:Toggle() end, -- Show the immediate frame
RightButton = function() KT:Announce("GUILD") end -- Announce to guild
},
shift = {
LeftButton = function() KT.Options:Open() end
}
}
local obj = ldb:NewDataObject("Broker_KillTrack", data) --[[@as LibDataBroker.DataDisplay]]
---@param self GameTooltip
function obj.OnTooltipShow(self)
self:AddLine(("%s |cff00FF00(%s)|r"):format(KT.Name, KT.Version), 1, 1, 1)
self:AddLine(" ")
local _, kpm, kph, length = KT:GetSessionStats()
self:AddDoubleLine("Session Length", ("|cffFFFFFF%s|r"):format(KTT:FormatSeconds(length)))
self:AddDoubleLine("Kills Per Minute", ("|cffFFFFFF%.2f|r"):format(kpm))
self:AddDoubleLine("Kills Per Hour", ("|cffFFFFFF%.2f|r"):format(kph))
self:AddLine(" ")
self:AddDoubleLine("Kills this session", ("|cffFFFFFF%d|r"):format(KT.Session.Count), 1, 1, 0)
local added = 0
for _, v in pairs(KT:GetSortedSessionKills()) do
self:AddDoubleLine(v.Name, ("|cffFFFFFF%d|r"):format(v.Kills))
added = added + 1
end
if added <= 0 then
self:AddLine("No kills this session", 1, 0, 0)
end
self:AddLine(" ")
self:AddDoubleLine("Kills in total", ("|cffFFFFFF%d|r"):format(KT:GetTotalKills()), 1, 1, 0)
added = 0
for _, v in pairs(KT:GetSortedMobTable()) do
self:AddDoubleLine(v.Name, ("|cffFFFFFF%d (%d)|r"):format(v.cKills, v.gKills))
added = added + 1
if added >= 3 then break end
end
if added <= 0 then
self:AddLine("No kills recorded yet", 1, 0, 0)
end
self:AddLine(" ")
self:AddDoubleLine("Left Click", "Open mob database", 0, 1, 0, 0, 1, 0)
self:AddDoubleLine("Middle Click", "Toggle short/long text", 0, 1, 0, 0, 1, 0)
self:AddDoubleLine("Right Click", "Reset session statistics", 0, 1, 0, 0, 1, 0)
self:AddDoubleLine("Ctrl + Left Click", "Announce to group/say", 0, 1, 0, 0, 1, 0)
self:AddDoubleLine("Ctrl + Middle Click", "Toggle immediate frame", 0, 1, 0, 0, 1, 0)
self:AddDoubleLine("Ctrl + Right Click", "Announce to guild", 0, 1, 0, 0, 1, 0)
self:AddDoubleLine("Shift + Left Click", "Open options panel", 0, 1, 0, 0, 1, 0)
end
function obj:OnClick(button)
local mod = ((IsControlKeyDown() and "ctrl") or (IsShiftKeyDown() and "shift")) or "none"
if not clickFunctions[mod] then return end
local func = clickFunctions[mod][button]
if func then func() end
end
function obj:OnEnter()
KT:DebugMsg("Broker OnEnter")
GameTooltip:SetOwner(self --[[@as Frame]], "ANCHOR_NONE")
GameTooltip:SetPoint("TOPLEFT", self, "BOTTOMLEFT")
KTB:UpdateTooltip()
tooltipVisible = true
end
function obj:OnLeave()
KT:DebugMsg("Broker OnLeave")
tooltipVisible = false
GameTooltip:Hide()
end
function KTB:UpdateText()
local text = KT.Global.BROKER.SHORT_TEXT and self.Text.Short or self.Text.Long
obj.text = text:format(select(2, KT:GetSessionStats()))
end
function KTB:UpdateTooltip()
KT:DebugMsg("Broker UpdateTooltip")
GameTooltip:ClearLines()
obj.OnTooltipShow(GameTooltip)
GameTooltip:Show()
end
---@param _ Frame
---@param elapsed number
function KTB:OnUpdate(_, elapsed)
t = t + elapsed
if t >= UPDATE then
self:UpdateText()
if tooltipVisible then self:UpdateTooltip() end
t = 0
end
end
function KTB:ToggleTextMode()
KT.Global.BROKER.SHORT_TEXT = not KT.Global.BROKER.SHORT_TEXT
self:UpdateText()
end
function KTB:OnLoad()
if type(KT.Global.BROKER.MINIMAP.hide) ~= "boolean" then
KT.Global.BROKER.MINIMAP.hide = true
end
icon:Register(KT.Name, obj, KT.Global.BROKER.MINIMAP)
frame:SetScript("OnUpdate", function(f, elapsed) KTB:OnUpdate(f, elapsed) end)
self:UpdateText()
end
---@param enabled boolean
function KTB:SetMinimap(enabled)
KT.Global.BROKER.MINIMAP.hide = not enabled
if enabled then
icon:Show(KT.Name)
else
icon:Hide(KT.Name)
end
end