-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.lua
388 lines (329 loc) · 15 KB
/
Settings.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
380
381
382
383
384
385
386
387
388
-- ########################################################################################################
-- PantherXP
-- Author: Rynzaii
-- The MIT License
--
-- ########################################################################################################
-- ########################################################################################################
-- Initialize PantherXP Settings using LibAddonMenu2
-- Source: https://www.esoui.com/downloads/info7-LibAddonMenu.html
--
-- ########################################################################################################
function PXP.initSettings()
local LAM = LibAddonMenu2
if LAM == nil then return end
local Default = PXP.default
local Settings = PXP.sv
-- Get fonts (Local in-game fonts)
local FontsList = {}
for f in pairs(PXP.fontsList) do
table.insert(FontsList, f)
end
local panelName = "PXPPanel"
local panelData = {
type = "panel",
name = "PantherXP Settings",
author = PXP.author,
version = PXP.version,
feedback = PXP.feedback,
donation = PXP.donation
}
local panel = LAM:RegisterAddonPanel(panelName, panelData)
local optionsData = {
{
-- Reload UI Button
type = "button",
name = "ReloadUI",
tooltip = "Click to reload UI",
func = function() ReloadUI("ingame") end,
width = "half",
},
{
-- Reset Settings to Default Settings
type = "button",
name = "Reset Default",
tooltip = "Click to reset Settings to Default",
warning = "After reseting, you must reload the UI for changes to take effect.",
func = function() PXP.ResetDefaultSettings() end,
width = "half",
},
{
type = "header",
name = "XP Bar",
},
{
-- Check to display XP Bar
type = "checkbox",
name = "Show XP Bar",
tooltip = "Always display the XP Bar.",
getFunc = function() return Settings.showXPBar end,
setFunc = function(value) Settings.showXPBar = value PXP.UpdateSettings() end,
width = "full",
default = Default.showXPBar,
},
{
-- Check to show XP Label
type = "checkbox",
name = "Show XP Label [Player XP / Player MaxXP]",
tooltip = "Displays player's current and max XP values.",
getFunc = function() return Settings.showXPLabel end,
setFunc = function(value) Settings.showXPLabel = value PXP.UpdateSettings() end,
width = "full",
default = Default.showXPLabel,
},
{
-- Check to display XP Percentage beside the XP Label
type = "checkbox",
name = "Show XP Percentage [%]",
tooltip = "Display XP Percentage to the right of existing XP values.",
getFunc = function() return Settings.showXPPercentage end,
setFunc = function(value) Settings.showXPPercentage = value PXP.UpdateSettings() end,
width = "full",
default = Default.showXPPercentage,
},
{
-- Check formatting for XP Label
type = "dropdown",
name = "XP Label Formatting",
tooltip = "Select a format for displaying XP values.",
warning = "Note: Abbreviating Long XP values is a Champion only setting.",
choices = PXP.labelFormats,
getFunc = function() return Settings.XPLabelFormat end,
setFunc = function(value) Settings.XPLabelFormat = value end,
width = "full",
default = Default.XPLabelFormat
},
{
-- Check placement for XP Label
type = "dropdown",
name = "XP Label Placement",
tooltip = "Select where on the XP Bar to display the XP Label.",
warning = "Note: Top placement cannot be set for Champion XP due to overlapping with pre-existing text.\nWill resort to displaying below the XP Bar.",
choices = PXP.labelPlacements,
getFunc = function() return Settings.XPLabelPlacement end,
setFunc = function(value) Settings.XPLabelPlacement = value PXP.UpdateSettings() end,
width = "full",
default = Default.XPLabelPlacement
},
{
-- Check selected Font Size
type = "slider",
name = "Font Size",
tooltip = "Set size of XP Label.",
min = 10, max = 30, step = 1,
getFunc = function() return Settings.defaultFontSize end,
setFunc = function(value) Settings.defaultFontSize = value PXP.SetSeletedFont() end,
width = "full",
default = Default.defaultFontSize,
},
{
-- Check selected Font Type
type = "dropdown",
scrollable = true,
name = "Font",
tooltip = "Select a font from a list of in-game fonts.",
choices = FontsList,
sort = "name-up",
getFunc = function() return Settings.defaultFontName end,
setFunc = function(var) Settings.defaultFontName = var PXP.SetSeletedFont() end,
width = "full",
default = Default.defaultFontName,
}
}
-- Register settings with option data above
LAM:RegisterOptionControls(panelName, optionsData)
end
-- Setting Functions
-- ########################################################################################################
-- Display XP Bar
-- - Takes a true or false value
--
-- ########################################################################################################
function PXP.ShowXPBar()
if PXPSV.Default[GetDisplayName()]['$AccountWide'].showXPBar == true then
SCENE_MANAGER:GetScene("hud"):AddFragment(PLAYER_PROGRESS_BAR_FRAGMENT)
SCENE_MANAGER:GetScene("hudui"):AddFragment(PLAYER_PROGRESS_BAR_FRAGMENT)
SCENE_MANAGER:GetScene("hud"):AddFragment(PLAYER_PROGRESS_BAR_CURRENT_FRAGMENT)
SCENE_MANAGER:GetScene("hudui"):AddFragment(PLAYER_PROGRESS_BAR_CURRENT_FRAGMENT)
else
SCENE_MANAGER:GetScene("hud"):RemoveFragment(PLAYER_PROGRESS_BAR_FRAGMENT)
SCENE_MANAGER:GetScene("hudui"):RemoveFragment(PLAYER_PROGRESS_BAR_FRAGMENT)
SCENE_MANAGER:GetScene("hud"):RemoveFragment(PLAYER_PROGRESS_BAR_CURRENT_FRAGMENT)
SCENE_MANAGER:GetScene("hudui"):RemoveFragment(PLAYER_PROGRESS_BAR_CURRENT_FRAGMENT)
end
end
-- ########################################################################################################
-- Get Player's Current XP
--
-- ########################################################################################################
function PXP.GetPlayerXP()
-- If player is champion, get champion point current XP
if IsUnitChampion("player") then
return GetPlayerChampionXP()
-- If not champion, get normal player current XP
else
return GetUnitXP("player")
end
end
-- ########################################################################################################
-- Get Player's Max XP
--
-- ########################################################################################################
function PXP.GetPlayerXPMax()
-- If player is champion, get champion point max XP
if IsUnitChampion("player") then
local cp = GetUnitChampionPoints("player")
if cp < GetChampionPointsPlayerProgressionCap() then
cp = GetChampionPointsPlayerProgressionCap()
end
return GetNumChampionXPInChampionPoint(cp)
-- If not champion, get normal player max XP
else
return GetUnitXPMax("player")
end
end
-- ########################################################################################################
-- Calculate XP Percentage
-- - 100 * (Player_CurrentXP / Player_MaxXP) = Player_PercentageXP
--
-- ########################################################################################################
function PXP.GetPlayerXPPercent(currXP, maxXP)
local percXP = 0
if maxXP > 0 then
percXP = 100 * (currXP / maxXP)
else
maxXP = "MAX"
end
return percXP
end
-- ########################################################################################################
-- Create XP Label
-- - Clear all existing anchors (will be set during RefreshLabelOnUpdate function)
-- - Draw controls, then set font based on selected font from settings
--
-- ########################################################################################################
function PXP.CreateXPLabel(font)
if PXPSV.Default[GetDisplayName()]['$AccountWide'].showXPLabel then
PantherXPText:ClearAnchors()
PantherXP:SetDrawTier(DT_HIGH)
PantherXP:SetDrawLayer(DL_OVERLAY)
-- Check selected font face and font size
if font == "Default" then
PantherXPText:SetFont(PXP.fontsList[font] .. "|" .. PXPSV.Default[GetDisplayName()]['$AccountWide'].defaultFontSize .. "|soft-shadow-thin")
elseif font == "Univers 67" or font == "Trajan Pro" then
PantherXPText:SetFont(PXP.fontsList[font] .. "|" .. PXPSV.Default[GetDisplayName()]['$AccountWide'].defaultFontSize .. "|soft-shadow-thick")
else
PantherXPText:SetFont(PXP.fontsList[font] .. "|" .. PXPSV.Default[GetDisplayName()]['$AccountWide'].defaultFontSize)
end
end
end
-- ########################################################################################################
-- Determine XP Label's Anchor
-- - Depending on saved placement variable, the XP Label will be placed relative to the XP Bar
-- - Options: Top, Center, Bottom
--
-- ########################################################################################################
function PXP.DetermineAnchor()
-- Place on top of the XP Bar
-- - Not possible for Champion due to pre-existing Champion text above XP Bar
if IsUnitChampion("player") == false and PXPSV.Default[GetDisplayName()]['$AccountWide'].XPLabelPlacement == "Top [Excludes Champion]" then
PantherXPText:SetAnchor(RIGHT, ZO_PlayerProgressBar, RIGHT, 0, -25)
-- Place in the center of the XP Bar
elseif PXPSV.Default[GetDisplayName()]['$AccountWide'].XPLabelPlacement == "Center" then
PantherXPText:SetAnchor(CENTER, ZO_PlayerProgressBar, CENTER, 0, -1)
-- Place below the XP Bar
else
PantherXPText:SetAnchor(RIGHT, ZO_PlayerProgressBar, RIGHT, 0, 25)
-- If XP Label is below XP Bar, hide on hover so it doesn't overlap the tooltip
ZO_PlayerProgressBar:SetHandler("OnMouseEnter", function(self)
PantherXPText:SetHidden(true)
ZO_PlayerProgressBar_OnMouseEnter(self)
end)
ZO_PlayerProgressBar:SetHandler("OnMouseExit", function(self)
PantherXPText:SetHidden(false)
ZO_PlayerProgressBar_OnMouseExit(self)
end)
end
end
-- ########################################################################################################
-- Refresh XP text label to reflect updated values when XP Bar updates
--
-- ########################################################################################################
function PXP.RefreshLabelOnUpdate()
-- Local variables to get player's current XP, max XP, and XP percent values
local playerPercent = PXP.GetPlayerXPPercent(PXP.GetPlayerXP(), PXP.GetPlayerXPMax()) --PXP.commaSplitter()
local playerCurrXP
local playerMaxXP
-- Check if XP Label should be abbreviated (only available for Champion and if XP Label is not formatted)
if IsUnitChampion("player") and PXPSV.Default[GetDisplayName()]['$AccountWide'].XPLabelFormat == "Abbreviate Long XP values [Champion only]" then
-- Gets XP value rounded to the tenths place
playerCurrXP = math.floor(PXP.GetPlayerXP() / 100) * 0.1 .. "k"
playerMaxXP = math.floor(PXP.GetPlayerXPMax() / 100) * 0.1 .. "k"
elseif PXPSV.Default[GetDisplayName()]['$AccountWide'].XPLabelFormat == "Format with commas" then
playerCurrXP = PXP.commaSplitter(PXP.GetPlayerXP())
playerMaxXP = PXP.commaSplitter(PXP.GetPlayerXPMax())
else
playerCurrXP = PXP.GetPlayerXP()
playerMaxXP = PXP.GetPlayerXPMax()
end
-- Check if XP Label should be displayed
if PXPSV.Default[GetDisplayName()]['$AccountWide'].showXPLabel == true then
-- Check if XP percent should be displayed
if PXPSV.Default[GetDisplayName()]['$AccountWide'].showXPPercentage == true then
--PantherXPText:SetAnchor(CENTER, ZO_PlayerProgressBar, CENTER, 0, -1)
PXP.DetermineAnchor()
PantherXPText:SetText(zo_strformat("<<1>> / <<2>> XP [<<3>>%]", playerCurrXP, playerMaxXP, playerPercent))
-- If XP Percentage setting is to not be displayed, do:
else
--PantherXPText:SetAnchor(CENTER, ZO_PlayerProgressBar, CENTER, 0, -1)
PXP.DetermineAnchor()
PantherXPText:SetText(zo_strformat("<<1>> / <<2>> XP", playerCurrXP, playerMaxXP))
end
else
PantherXPText:SetHidden(true)
end
end
-- ########################################################################################################
-- Update PantherXP Settings on change
--
-- ########################################################################################################
function PXP.UpdateSettings()
PXP.ShowXPBar()
PXP.CreateXPLabel(PXPSV.Default[GetDisplayName()]['$AccountWide'].defaultFontName)
PXP.RefreshLabelOnUpdate()
end
-- ########################################################################################################
-- Reset PantherXP to the Default Settings
--
-- ########################################################################################################
function PXP.SetSeletedFont()
-- First try setting player's selected font
local fontName = PXP.fontsList[PXP.defaultFontName]
-- If font cannot be set, set to default font
if not fontName or fontName == "" then
fontName = "Default" -- ZoFontGameBold
end
PXP.UpdateSettings()
end
-- ########################################################################################################
-- Reset PantherXP to the Default Settings
--
-- ########################################################################################################
function PXP.ResetDefaultSettings()
PXP.sv = ZO_SavedVars:NewAccountWide(PXP.svName, PXP.svVersion - 1, nil, PXP.default)
end
-- ########################################################################################################
-- Format numbers with commas as needed.
-- - Anything passed 1000 --> 1,000
--
-- ########################################################################################################
function PXP.commaSplitter(amount)
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then
break
end
end
return formatted
end