-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMetricsOptionsPanel.lua
379 lines (341 loc) · 13.9 KB
/
MetricsOptionsPanel.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
--------------------------------------------------------------------------------------
-- MetricsOptionsPanel.lua
-- AUTHOR: Michael Peterson
-- ORIGINAL DATE: 11 Nov, 2019
--------------------------------------------------------------------------------------
local _, Metrics = ...
Metrics.OptionsPanel = {}
local core = Metrics.MetricsCore
local target = Metrics.MetricsTargetDummy
local panel = Metrics.OptionsPanel
local display = Metrics.Display
local utils = LibStub:GetLibrary("UtilsLib")
local L = Metrics.Locales.L
local EMPTY_STR = ""
------------------------------------------------------------
-- SAVED GLOBALS
------------------------------------------------------------
local optionsPanel = nil
local defaultTargetHealth = UnitHealthMax("Player")
METRICS_CHECKBOX_SAVED_VARS = {}
local dmg = 1
local heal = 2
local aura = 3
local miss = 4
local dmgScrollButton = nil
local healScrollButton = nil
local auraScrollButton = nil
local missScrollButton = nil
-- Option Menu Settings
local FRAME_WIDTH = 590
local FRAME_HEIGHT = FRAME_WIDTH
local WIDTH_TITLE_BAR = 500
local HEIGHT_TITLE_BAR = 45
local LINE_SEGMENT_LENGTH = 575
local X_START_POINT = 10
local Y_START_POINT = X_START_POINT
local function drawLine( yPos, f)
local lineFrame = CreateFrame("FRAME", nil, f )
lineFrame:SetPoint("CENTER", -10, yPos )
lineFrame:SetSize(LINE_SEGMENT_LENGTH, LINE_SEGMENT_LENGTH)
local line = lineFrame:CreateLine(1)
line:SetColorTexture(.5, .5, .5, 1) -- Grey per https://wow.gamepedia.com/Power_colors
line:SetThickness(2)
line:SetStartPoint("LEFT",X_START_POINT, Y_START_POINT)
line:SetEndPoint("RIGHT", X_START_POINT, Y_START_POINT)
lineFrame:Show()
end
-- CHECK BOXES
local function scrollingDamageCheckBtn( frame, xPos, yPos )
dmgScrollButton = CreateFrame("CheckButton", "DPSTRACKER_dmgScrollButton", frame, "ChatConfigCheckButtonTemplate" )
dmgScrollButton:SetPoint("TOPLEFT", xPos, yPos )
dmgScrollButton.tooltip = string.format("Damage values (red) are scrolled across your screen. Crit values will be in a larger font.")
dmgScrollButton.Text:SetFontObject(GameFontNormal)
_G[dmgScrollButton:GetName().."Text"]:SetText("Check To Scroll Damage Values." )
dmgScrollButton:SetChecked( METRICS_CHECKBOX_SAVED_VARS[dmg] )
dmgScrollButton:SetScript("OnClick",
function(self)
local isChecked = self:GetChecked() and true or false
if isChecked then
display:enableScrollingDmg()
else
display:disableScrollingDmg()
end
METRICS_CHECKBOX_SAVED_VARS[dmg] = isChecked
end)
end
local function scrollingHealsCheckBtn( frame, xPos, yPos )
healScrollButton = CreateFrame("CheckButton", "DPSTRACKER_healScrollButton", frame, "ChatConfigCheckButtonTemplate")
healScrollButton:SetPoint("TOPLEFT", xPos, yPos )
healScrollButton.tooltip = string.format("Heal values (Green) are scrolled across your screen. Crit values will be in a larger font.")
healScrollButton.Text:SetFontObject(GameFontNormal)
_G[healScrollButton:GetName().."Text"]:SetText("Check To Scroll Heal Values." )
healScrollButton:SetChecked( METRICS_CHECKBOX_SAVED_VARS[heal] )
healScrollButton:SetScript("OnClick",
function(self)
local isChecked = self:GetChecked() and true or false
if isChecked then
display:enableScrollingHeals()
else
display:disableScrollingHeals()
end
METRICS_CHECKBOX_SAVED_VARS[heal] = isChecked
end)
end
local function scrollingAurasCheckBtn( frame, xPos, yPos )
auraScrollButton = CreateFrame("CheckButton", "DPSTRACKER_auraScrollButton", frame, "ChatConfigCheckButtonTemplate")
auraScrollButton:SetPoint("TOPLEFT", xPos, yPos )
auraScrollButton.tooltip = string.format("Auras (Buffs and Debuffs) are scrolled across your screen. WARNING: Checking this box can cause your screen to be cluttered.")
auraScrollButton.Text:SetFontObject(GameFontNormal)
_G[auraScrollButton:GetName().."Text"]:SetText("Check To Scroll Auras." )
auraScrollButton:SetChecked( METRICS_CHECKBOX_SAVED_VARS[aura])
auraScrollButton:SetScript("OnClick",
function(self)
local isChecked = self:GetChecked() and true or false
if isChecked then
display:enableScrollingAuras()
else
display:disableScrollingAuras()
end
METRICS_CHECKBOX_SAVED_VARS[aura] = isChecked
end)
end
local function scrollingMissCheckBtn( frame, xPos, yPos )
missScrollButton = CreateFrame("CheckButton", "DPSTRACKER_missScrollButton", frame,"ChatConfigCheckButtonTemplate")
missScrollButton:SetPoint("TOPLEFT", xPos, yPos )
missScrollButton.tooltip = string.format("Miss types (e.g., RESISTS, BLOCKS, PARRIES, DODGES, etc.,) are scrolled across your screen.")
missScrollButton.Text:SetFontObject(GameFontNormal)
_G[missScrollButton:GetName().."Text"]:SetText("Check To Scroll Miss Types." )
missScrollButton:SetChecked( METRICS_CHECKBOX_SAVED_VARS[miss] )
missScrollButton:SetScript("OnClick",
function(self)
local isChecked = self:GetChecked() and true or false
if isChecked then
display:enableScrollingMisses()
else
display:disableScrollingMisses()
end
METRICS_CHECKBOX_SAVED_VARS[miss] = isChecked
end)
end
---- DEFAULT and ACCEPT BUTTONS
local function createDefaultsButton(f, width, height) -- creates Default button
f.hide = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
f.hide:SetText("Defaults")
f.hide:SetHeight(height) -- original value 20
f.hide:SetWidth(width) -- original value 80
f.hide:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 8, 8)
f.hide:SetScript("OnClick",
function( self )
dmgScrollButton:SetChecked( false)
healScrollButton:SetChecked( false )
auraScrollButton:SetChecked( false)
missScrollButton:SetChecked( false )
METRICS_CHECKBOX_SAVED_VARS = {false, false, false, false }
f:Hide()
end)
end
local function createAcceptButton(f, width, height) -- creates Accept button
-- -- Accept buttom, bottom right
f.hide = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
f.hide:SetText("Accept")
f.hide:SetHeight(height) -- Original value = 20
f.hide:SetWidth(width) -- Original value = 80
f.hide:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -8, 8)
f.hide:SetScript("OnClick",
function( self )
METRICS_CHECKBOX_SAVED_VARS[dmg] = dmgScrollButton:GetChecked()
print( METRICS_CHECKBOX_SAVED_VARS[dmg])
METRICS_CHECKBOX_SAVED_VARS[heal] = healScrollButton:GetChecked()
METRICS_CHECKBOX_SAVED_VARS[aura] = auraScrollButton:GetChecked()
METRICS_CHECKBOX_SAVED_VARS[miss] = missScrollButton:GetChecked()
f:Hide()
end)
end
---- INPUT DIALOG BOX
local function createInputDialogBox(frame, title, xPos, yPos) -- creates the input Dialog box
local str = string.upper( title )
local DescrSubHeader = frame:CreateFontString(nil, "ARTWORK","GameFontNormal")
DescrSubHeader:SetPoint("LEFT", xPos, yPos + 20)
DescrSubHeader:SetText( title )
local f = CreateFrame("EditBox", "InputEditBox", frame, "InputBoxTemplate")
f:SetFrameStrata("DIALOG")
f:SetSize(200,75)
f:SetAutoFocus(false)
f:SetPoint("LEFT", xPos, yPos)
f:SetScript("OnEnterPressed",
function(self,button)
local targetHealth = f:GetText()
if targetHealth == EMPTY_STR then
targetHealth = defaultTargetHealth
else
targetHealth = tonumber( targetHealth )
end
target:setTargetDummyHealth( targetHealth)
-- this clears the edit box
ClearCursor()
f:SetText("")
optionsPanel:Hide()
end)
end
-- ******************** CREATE THE OPTIONS/SETTINGS PANEL **********************
local function createOptionsPanel()
if optionsPanel ~= nil then
return optionsPanel
end
local frame = CreateFrame("Frame", "DPS_Tracer Settings", UIParent, BackdropTemplateMixin and "BackdropTemplate")
frame:SetFrameStrata("HIGH")
frame:SetToplevel(true)
frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
frame:EnableMouse(true)
frame:EnableMouseWheel(true)
frame:SetMovable(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
frame:SetBackdrop({
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
edgeSize = 26,
insets = {left = 9, right = 9, top = 9, bottom = 9},
})
frame:SetBackdropColor(0.0, 0.0, 0.0, 0.50)
-- The Title Bar & Title
frame.titleBar = frame:CreateTexture(nil, "ARTWORK")
frame.titleBar:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
frame.titleBar:SetPoint("TOP", 0, 12)
frame.titleBar:SetSize( WIDTH_TITLE_BAR, HEIGHT_TITLE_BAR)
frame.title = frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
frame.title:SetPoint("TOP", 0, 4)
frame.title:SetText("Metrics Options")
-- Title text
frame.text = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
frame.text:SetPoint("TOPLEFT", 12, -22)
frame.text:SetWidth(frame:GetWidth() - 20)
frame.text:SetJustifyH("LEFT")
frame:SetHeight(frame.text:GetHeight() + 70)
tinsert( UISpecialFrames, frame:GetName() )
frame:SetSize( FRAME_WIDTH, FRAME_HEIGHT )
local buttonWidth = 80
local buttonHeight = 20
createAcceptButton(frame, buttonWidth, buttonHeight)
createDefaultsButton(frame, buttonWidth, buttonHeight)
-------------------- INTRO HEADER -----------------------------------------
local subTitle = frame:CreateFontString(nil, "ARTWORK","GameFontNormalLarge")
local msgText = frame:CreateFontString(nil, "ARTWORK","GameFontNormalLarge")
local displayString = string.format("%s", L["ADDON_AND_VERSION"])
msgText:SetPoint("TOP", 0, -20)
msgText:SetText(displayString)
-------------------- WARNING DESCRIPTION ---------------------------------------
local DescrSubHeader = frame:CreateFontString(nil, "ARTWORK","GameFontNormalLarge")
local messageText = frame:CreateFontString(nil, "ARTWORK","GameFontNormal")
messageText:SetJustifyH("LEFT")
local str1 = "Metrics"
local line = string.format(" ")
local str2 = string.format(" Metrics is designed to be used with target dummies, although")
local str3 = string.format("its use while questing or running dungeons is fully supported.")
local str4 = string.format("Metrics allows you to specify the health of a target dummy.")
local str5 = string.format("When your attacks have reduced the target's health to zero ")
local str6 = string.format("combat data recording will cease and you can call up a summary ")
local str7 = string.format("of the encounter.")
local str8 = string.format(" In addition to total Damage output and your DPS, Metrics")
local str9 = string.format("will report the following metrics:")
local str10 = string.format(" - Total damage and DPS per spell/attack.")
local str11 = string.format(" - The number of times your attacks missed, were blocked, parried, etc.")
local messageText = frame:CreateFontString(nil, "ARTWORK","GameFontNormal")
messageText:SetJustifyH("LEFT")
messageText:SetPoint("TOP", 0, -70)
messageText:SetText(string.format("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s",
str1, line, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11 ))
-- drawLine( 220, frame )
drawLine( 50, frame )
-- coords for line
local xPos = 20
local yPos = -250
local yOffset = -20
xPos = 40
yPos = yPos + yOffset
-- create and display the check boxes
scrollingDamageCheckBtn( frame, xPos, yPos )
yPos = yPos + yOffset
scrollingHealsCheckBtn( frame, xPos, yPos )
yPos = yPos + yOffset
scrollingAurasCheckBtn( frame, xPos, yPos )
yPos = yPos + yOffset
scrollingMissCheckBtn( frame, xPos, yPos )
yPos = yPos + yOffset
-- create and display the input dialog box for specifying the dummy target's health
createInputDialogBox(frame, "Press <Enter> To Set Target Dummy Health", 150, -100)
frame:Show()
return frame
end
optionsPanel = createOptionsPanel()
function panel:isVisible()
return optionsPanel:IsVisible()
end
function panel:show()
if not optionsPanel:IsVisible() then
optionsPanel:Show()
end
end
function panel:hide()
if optionsPanel:IsVisible() then
optionsPanel:Hide()
end
end
local eventFrame = CreateFrame("Frame" )
eventFrame:RegisterEvent( "PLAYER_LOGIN")
eventFrame:SetScript("OnEvent",
function( self, event, ... )
if event == "PLAYER_LOGIN" then
-- set the default scrolling values. Players must deliberately
-- enable scrolling (true means scolling is disabled)
if METRICS_CHECKBOX_SAVED_VARS == nil then
METRICS_CHECKBOX_SAVED_VARS = {true, true, true, true }
display:disableScrollingDmg()
display:disableScrollingHeals()
display:disableScrollingAuras()
display:disableScrollingMisses()
end
if METRICS_CHECKBOX_SAVED_VARS[dmg] then
local checked = METRICS_CHECKBOX_SAVED_VARS[dmg]
dmgScrollButton:SetChecked( checked )
if checked then
display:enableScrollingDmg()
else
display:disableScrollingDmg()
end
end
if METRICS_CHECKBOX_SAVED_VARS[heal] then
local checked = METRICS_CHECKBOX_SAVED_VARS[heal]
healScrollButton:SetChecked( checked )
if checked then
display:enableScrollingHeals()
else
display:disableScrollingHeals()
end
end
if METRICS_CHECKBOX_SAVED_VARS[aura] then
local checked = METRICS_CHECKBOX_SAVED_VARS[aura]
auraScrollButton:SetChecked( checked )
if checked then
display:enableScrollingAuras()
else
display:disableScrollingAuras()
end
end
if METRICS_CHECKBOX_SAVED_VARS[miss] then
local checked = METRICS_CHECKBOX_SAVED_VARS[miss]
missScrollButton:SetChecked( checked )
if checked then
display:enableScrollingMisses()
else
display:disableScrollingMisses()
end
end
end
end)
local fileName = "MetricsOptions.lua"
if core:debuggingIsEnabled() then
DEFAULT_CHAT_FRAME:AddMessage( fileName .. " " .. "loaded.", 0.0, 1.0, 1.0 )
end