-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
TimerFrame.lua
216 lines (186 loc) · 7.78 KB
/
TimerFrame.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
215
216
--[[
* 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 KillTrackTimerFrame
local TF = {
Running = false
}
KT.TimerFrame = TF
local T = KT.Timer
local function Enabled(object, enabled)
if not object.Enable or not object.Disable then return end
if enabled then
object:Enable()
else
object:Disable()
end
end
local frame
local function SetupFrame()
if frame then return end
frame = CreateFrame("Frame", nil, UIParent, BackdropTemplateMixin and "BackdropTemplate")
frame:Hide()
frame:EnableMouse(true)
frame:SetMovable(true)
frame:SetWidth(200)
frame:SetHeight(93)
frame:SetPoint("CENTER")
local bd = {
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
edgeSize = 16,
tileSize = 32,
insets = {
left = 2.5,
right = 2.5,
top = 2.5,
bottom = 2.5
}
}
frame:SetBackdrop(bd)
frame:SetScript("OnMouseDown", function(f) f:StartMoving() end)
frame:SetScript("OnMouseUp", function(f) f:StopMovingOrSizing() end)
---@diagnostic disable-next-line: inject-field
frame.currentLabel = frame:CreateFontString(nil, "OVERLAY", nil)
frame.currentLabel:SetFont("Fonts\\FRIZQT__.TTF", 10, nil)
frame.currentLabel:SetPoint("TOPLEFT", frame, "TOPLEFT", 6, -6)
frame.currentLabel:SetText("Number of kills:")
---@diagnostic disable-next-line: inject-field
frame.currentCount = frame:CreateFontString(nil, "OVERLAY", nil)
frame.currentCount:SetFont("Fonts\\FRIZQT__.TTF", 10, nil)
frame.currentCount:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -6, -6)
frame.currentCount:SetText("0")
---@diagnostic disable-next-line: inject-field
frame.timeLabel = frame:CreateFontString(nil, "OVERLAY", nil)
frame.timeLabel:SetFont("Fonts\\FRIZQT__.TTF", 10, nil)
frame.timeLabel:SetPoint("TOPLEFT", frame.currentLabel, "BOTTOMLEFT", 0, -2)
frame.timeLabel:SetText("Time left:")
---@diagnostic disable-next-line: inject-field
frame.timeCount = frame:CreateFontString(nil, "OVERLAY", nil)
frame.timeCount:SetFont("Fonts\\FRIZQT__.TTF", 10, nil)
frame.timeCount:SetPoint("TOPRIGHT", frame.currentCount, "BOTTOMRIGHT", 0, -2)
frame.timeCount:SetText("00:00:00")
---@diagnostic disable-next-line: inject-field
frame.killsPerMinuteLabel = frame:CreateFontString(nil, "OVERLAY", nil)
frame.killsPerMinuteLabel:SetFont("Fonts\\FRIZQT__.TTF", 10, nil)
frame.killsPerMinuteLabel:SetPoint("TOPLEFT", frame.timeLabel, "BOTTOMLEFT", 0, -2)
frame.killsPerMinuteLabel:SetText("Kills Per Minute:")
---@diagnostic disable-next-line: inject-field
frame.killsPerMinuteCount = frame:CreateFontString(nil, "OVERLAY", nil)
frame.killsPerMinuteCount:SetFont("Fonts\\FRIZQT__.TTF", 10, nil)
frame.killsPerMinuteCount:SetPoint("TOPRIGHT", frame.timeCount, "BOTTOMRIGHT", 0, -2)
frame.killsPerMinuteCount:SetText("0")
---@diagnostic disable-next-line: inject-field
frame.killsPerSecondLabel = frame:CreateFontString(nil, "OVERLAY", nil)
frame.killsPerSecondLabel:SetFont("Fonts\\FRIZQT__.TTF", 10, nil)
frame.killsPerSecondLabel:SetPoint("TOPLEFT", frame.killsPerMinuteLabel, "BOTTOMLEFT", 0, -2)
frame.killsPerSecondLabel:SetText("Kills Per Second:")
---@diagnostic disable-next-line: inject-field
frame.killsPerSecondCount = frame:CreateFontString(nil, "OVERLAY", nil)
frame.killsPerSecondCount:SetFont("Fonts\\FRIZQT__.TTF", 10, nil)
frame.killsPerSecondCount:SetPoint("TOPRIGHT", frame.killsPerMinuteCount, "BOTTOMRIGHT", 0, -2)
frame.killsPerSecondCount:SetText("Kills Per Minute:")
---@diagnostic disable-next-line: inject-field
frame.cancelButton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
frame.cancelButton:SetSize(60, 16)
frame.cancelButton:SetPoint("BOTTOM", frame, "BOTTOM", -40, 7)
frame.cancelButton:SetScript("OnLoad", function(self) self:Disable() end)
frame.cancelButton:SetScript("OnClick", function() TF:Cancel() end)
frame.cancelButton:SetText("Stop")
---@diagnostic disable-next-line: inject-field
frame.closeButton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
frame.closeButton:SetSize(60, 16)
frame.closeButton:SetPoint("BOTTOM", frame, "BOTTOM", 40, 7)
frame.closeButton:SetScript("OnLoad", function(self) self:Disable() end)
frame.closeButton:SetScript("OnClick", function() TF:Close() end)
frame.closeButton:SetText("Close")
---@diagnostic disable-next-line: inject-field
frame.progressBar = CreateFrame("StatusBar", nil, frame)
frame.progressBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
frame.progressBar:SetStatusBarColor(0, 1, 0)
frame.progressBar:SetMinMaxValues(0, 1)
frame.progressBar:SetValue(0)
frame.progressBar:SetPoint("TOPLEFT", frame.killsPerSecondLabel, "BOTTOMLEFT", -1, -2)
frame.progressBar:SetPoint("RIGHT", frame.killsPerSecondCount, "RIGHT", 0, 0)
frame.progressBar:SetPoint("BOTTOM", frame.cancelButton, "TOP", 0, 2)
---@diagnostic disable-next-line: inject-field
frame.progressLabel = frame.progressBar:CreateFontString(nil, "OVERLAY", nil)
frame.progressLabel:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
frame.progressLabel:SetAllPoints(frame.progressBar)
frame.progressLabel:SetText("0%")
end
function TF:InitializeControls()
frame.currentCount:SetText("0")
frame.timeCount:SetText("00:00:00")
frame.progressLabel:SetText("0%")
frame.progressBar:SetValue(0)
self:UpdateControls()
end
function TF:UpdateControls()
Enabled(frame.cancelButton, self.Running)
Enabled(frame.closeButton, not self.Running)
end
function TF:UpdateData(data, state)
if state == T.State.START then
self:InitializeControls()
else
local kills = T:GetData("Kills", true)
local kpm, kps
if data.Current <= 0 then
kpm, kps = 0, 0
else
kpm = kills / (data.Current / 60)
kps = kills / data.Current
end
frame.currentCount:SetText(kills)
frame.timeCount:SetText(data.LeftFormat)
frame.progressLabel:SetText(floor(data.Progress*100) .. "%")
frame.progressBar:SetMinMaxValues(0, data.Total)
frame.progressBar:SetValue(data.Current)
frame.killsPerMinuteCount:SetText(("%.2f"):format(kpm))
frame.killsPerSecondCount:SetText(("%.2f"):format(kps))
if state == T.State.STOP then self:Stop() end
end
self:UpdateControls()
end
function TF:Start(s, m, h)
if self.Running then return end
self.Running = true
SetupFrame()
self:InitializeControls()
frame:Show()
if not T:Start(s, m, h, function(d, u) TF:UpdateData(d, u) end, nil) then
self:Stop()
frame:Hide()
end
end
function TF:Stop()
if not self.Running then return end
self.Running = false
end
function TF:Cancel()
T:Stop()
end
function TF:Close()
if not frame then return end
self:InitializeControls()
frame:Hide()
end