forked from shagu/ShaguDPS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.lua
More file actions
369 lines (320 loc) · 13.3 KB
/
Copy pathsettings.lua
File metadata and controls
369 lines (320 loc) · 13.3 KB
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
-- load public variables into local
local settings = ShaguDPS.settings
local window = ShaguDPS.window
local parser = ShaguDPS.parser
local config = ShaguDPS.config
local textures = ShaguDPS.textures
local playerClasses = ShaguDPS.playerClasses
-- default backdrops
local backdrop = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 8,
insets = { left = 2, right = 2, top = 2, bottom = 2 }
}
local backdrop_window = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 3, right = 3, top = 3, bottom = 3 }
}
local backdrop_border = {
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 3, right = 3, top = 3, bottom = 3 }
}
local function CreateSelector(self, values)
local input = CreateFrame("Frame", nil, self)
input.values = values
input:Hide()
input:SetHeight(18)
input:SetWidth(values and 112 or 54)
input:SetPoint("TOPRIGHT", self, "TOPRIGHT", -8, -self.entries*18 - 4)
input:SetBackdrop(backdrop)
input:SetBackdropColor(.2,.2,.2,1)
input:SetBackdropBorderColor(.4,.4,.4,1)
input:SetScript("OnShow", function() input:change() end)
input.texture = input:CreateTexture()
input.texture:SetPoint("TOPLEFT", input, "TOPLEFT", 13, -3)
input.texture:SetPoint("BOTTOMRIGHT", input, "BOTTOMRIGHT", -13, 3)
input.texture:SetVertexColor(.8, .4, .2)
input.caption = input:CreateFontString(nil, "OVERLAY", "GameFontWhite")
input.caption:SetFont(STANDARD_TEXT_FONT, 10)
input.caption:SetText("Select")
input.caption:SetAllPoints()
input.left = CreateFrame("Button", nil, input)
input.left:SetPoint("LEFT", input, "LEFT", 1, 0)
input.left:SetWidth(12)
input.left:SetHeight(16)
input.left:SetBackdrop(backdrop)
input.left:SetBackdropColor(.2,.2,.2,1)
input.left:SetBackdropBorderColor(.4,.4,.4,1)
input.left:SetScript("OnEnter", function() this:SetBackdropBorderColor(1.0, 0.8, 0.0, 1) end)
input.left:SetScript("OnLeave", function() this:SetBackdropBorderColor(0.4, 0.4, 0.4, 1) end)
input.left:SetScript("OnClick", function() input:change(-1) end)
input.left.caption = input.left:CreateFontString(nil, "OVERLAY", "GameFontWhite")
input.left.caption:SetFont(STANDARD_TEXT_FONT, 10)
input.left.caption:SetText("<")
input.left.caption:SetAllPoints()
input.right = CreateFrame("Button", nil, input)
input.right:SetPoint("RIGHT", input, "RIGHT", -1, 0)
input.right:SetWidth(12)
input.right:SetHeight(16)
input.right:SetBackdrop(backdrop)
input.right:SetBackdropColor(.2,.2,.2,1)
input.right:SetBackdropBorderColor(.4,.4,.4,1)
input.right:SetScript("OnEnter", function() this:SetBackdropBorderColor(1.0, 0.8, 0.0, 1) end)
input.right:SetScript("OnLeave", function() this:SetBackdropBorderColor(0.4, 0.4, 0.4, 1) end)
input.right:SetScript("OnClick", function() input:change(1) end)
input.right.caption = input.right:CreateFontString(nil, "OVERLAY", "GameFontWhite")
input.right.caption:SetFont(STANDARD_TEXT_FONT, 10)
input.right.caption:SetText(">")
input.right.caption:SetAllPoints()
input.change = function(self, mod)
local id = config[self.entry] or 1
if mod and self.values and self.values[id + mod] then
config[self.entry] = math.ceil(config[self.entry] + mod)
elseif mod and not values then
config[self.entry] = math.ceil(config[self.entry] + mod)
end
if self.values and self.values[config[self.entry]] then
local _, _, clean = string.find(self.values[config[self.entry]], ".+\\(.+)")
self.caption:SetText(clean)
else
self.caption:SetText(config[self.entry])
end
if self.values and not self.values[config[self.entry]+1] then
self.right:SetAlpha(0.25)
else
self.right:SetAlpha(1.00)
end
if self.values and not self.values[config[self.entry]-1] then
self.left:SetAlpha(0.25)
else
self.left:SetAlpha(1.00)
end
window.Refresh(true)
-- todo
if self.entry == "texture" then
local texture = ShaguDPS.textures[config[self.entry]]
if texture then
self.texture:SetTexture(texture)
else
self.texture:SetTexture()
end
end
end
return input
end
local function CreateConfig(self, caption, entry, check)
self.entries = self.entries and self.entries + 1 or 1
local entry = entry
local text = self:CreateFontString(nil, "OVERLAY", "GameFontWhite")
text:SetPoint("TOPLEFT", self, "TOPLEFT", 10, -self.entries*18 - 4)
text:SetWidth(100)
text:SetHeight(18)
text:SetFont(STANDARD_TEXT_FONT, 10, "THINOUTLINE")
text:SetJustifyH("LEFT")
text:SetText(caption)
if check == "header" then
text:SetPoint("TOPLEFT", self, "TOPLEFT", 8, -self.entries*18 - 8)
text:SetFont(STANDARD_TEXT_FONT, 11, "OUTLINE")
text:SetTextColor(1, .8, 0)
end
if check == "boolean" then
local input = CreateFrame("CheckButton", nil, self, "OptionsCheckButtonTemplate")
input:Hide()
input:SetHeight(18)
input:SetWidth(18)
input:SetPoint("TOPRIGHT", self, "TOPRIGHT", -8, -self.entries*18 - 8)
input:SetScript("OnShow", function()
this:SetChecked(config[entry] == 1)
end)
input:SetScript("OnClick", function()
config[entry] = this:GetChecked() and 1 or 0
window.Refresh(true)
end)
input:Show()
end
if check == "number" or type(check) == "table" then
local values = type(check) == "table" and check or nil
local input = self:CreateSelector(values)
input.entry = entry
input:Show()
end
end
-- Load settings on Login
settings:RegisterEvent("PLAYER_ENTERING_WORLD")
settings:SetScript("OnEvent", function()
if ShaguDPS_Config then
for k, v in pairs(ShaguDPS_Config) do
config[k] = v
end
end
ShaguDPS_Config = config
window.Refresh(true)
end)
settings:Hide()
settings:SetPoint("CENTER", UIParent, "CENTER", 0, 32)
settings:SetWidth(192)
settings:SetHeight(216)
settings:SetMovable(true)
settings:EnableMouse(true)
settings:RegisterForDrag("LeftButton")
settings:SetScript("OnDragStart", function() this:StartMoving() end)
settings:SetScript("OnDragStop", function() this:StopMovingOrSizing() end)
settings:SetFrameStrata("DIALOG")
settings.CreateConfig = CreateConfig
settings.CreateSelector = CreateSelector
-- window background
settings:SetBackdrop(backdrop_window)
settings:SetBackdropColor(0.1,0.1,0.1,0.8)
-- window border
settings.border = CreateFrame("Frame", nil, settings)
settings.border:ClearAllPoints()
settings.border:SetPoint("TOPLEFT", settings, "TOPLEFT", -1,1)
settings.border:SetPoint("BOTTOMRIGHT", settings, "BOTTOMRIGHT", 1,-1)
settings.border:SetFrameLevel(100)
settings.border:SetBackdrop(backdrop_border)
settings.border:SetBackdropBorderColor(0.4,0.4,0.4,1)
settings.title = settings:CreateTexture(nil, "NORMAL")
settings.title:SetTexture(0,0,0,.6)
settings.title:SetHeight(20)
settings.title:SetPoint("TOPLEFT", 2, -2)
settings.title:SetPoint("TOPRIGHT", -2, -2)
settings.caption = settings:CreateFontString(nil, "OVERLAY", "GameFontWhite")
settings.caption:SetFont(STANDARD_TEXT_FONT, 10, "OUTLINE")
settings.caption:SetText("|cffffcc00Shagu|cffffffffDPS")
settings.caption:SetAllPoints(settings.title)
settings.btnClose = CreateFrame("Button", nil, settings)
settings.btnClose:SetPoint("RIGHT", settings.title, "RIGHT", -4, 0)
settings.btnClose:SetHeight(16)
settings.btnClose:SetWidth(16)
settings.btnClose:SetBackdrop(backdrop)
settings.btnClose:SetBackdropColor(.2,.2,.2,1)
settings.btnClose:SetBackdropBorderColor(.4,.4,.4,1)
settings.btnClose.caption = settings.btnClose:CreateFontString(nil, "OVERLAY", "GameFontWhite")
settings.btnClose.caption:SetFont(STANDARD_TEXT_FONT, 14)
settings.btnClose.caption:SetText("x")
settings.btnClose.caption:SetAllPoints()
settings.btnClose:SetScript("OnEnter", function() this:SetBackdropBorderColor(1.0, 0.8, 0.0, 1) end)
settings.btnClose:SetScript("OnLeave", function() this:SetBackdropBorderColor(0.4, 0.4, 0.4, 1) end)
settings.btnClose:SetScript("OnClick", function() settings:Hide() end)
settings:CreateConfig("Parser", nil, "header")
settings:CreateConfig("Track All Nearby Units", "track_all_units", "boolean")
settings:CreateConfig("Merge Pets With Owner", "merge_pets", "boolean")
settings:CreateConfig("Window", nil, "header")
settings:CreateConfig("Bar Texture", "texture", ShaguDPS.textures)
settings:CreateConfig("Bar Height", "height", "number")
settings:CreateConfig("Bar Spacing", "spacing", "number")
settings:CreateConfig("Pastel Colors", "pastel", "boolean")
settings:CreateConfig("Show Backdrops", "backdrop", "boolean")
settings:CreateConfig("Lock Windows", "lock", "boolean")
-- Provide Slash Commands
SLASH_SHAGUMETER1, SLASH_SHAGUMETER2, SLASH_SHAGUMETER3 = "/shagudps", "/sdps", "/sd"
SlashCmdList["SHAGUMETER"] = function(msg, editbox)
local function p(msg)
DEFAULT_CHAT_FRAME:AddMessage(msg)
end
if (msg == "" or msg == nil) then
p("|cffffcc00Shagu|cffffffffDPS:")
p(" /sdps visible " .. config.visible .. " |cffcccccc- Show main window")
p(" /sdps height " .. config.height .. " |cffcccccc- Bar height")
p(" /sdps spacing " .. config.spacing .. " |cffcccccc- Bar spacing")
p(" /sdps trackall " .. config.track_all_units .. " |cffcccccc- Track all nearby units")
p(" /sdps mergepet " .. config.merge_pets .. " |cffcccccc- Merge pets into owner data")
p(" /sdps texture " .. config.texture .. " |cffcccccc- Set the statusbar texture")
p(" /sdps pastel " .. config.pastel .. " |cffcccccc- Use pastel colors")
p(" /sdps backdrop " .. config.backdrop .. " |cffcccccc- Show window backdrop and border")
p(" /sdps lock " .. config.lock .. " |cffcccccc- Lock window")
p(" /sdps toggle |cffcccccc- Toggle window")
return
end
local _, _, cmd, args = string.find(msg, "%s?(%w+)%s?(.*)")
if strlower(cmd) == "visible" then
if tonumber(args) and (tonumber(args) == 1 or tonumber(args) == 0) then
config.visible = tonumber(args)
ShaguDPS_Config = config
window.Refresh(true)
p("|cffffcc00Shagu|cffffffffDPS:|cffffddcc Visible: " .. config.visible)
else
p("|cffffcc00Shagu|cffffffffDPS:|cffff5511 Valid Options are 0-1")
end
elseif strlower(cmd) == "lock" then
if tonumber(args) and (tonumber(args) == 1 or tonumber(args) == 0) then
config.lock = tonumber(args)
ShaguDPS_Config = config
window.Refresh(true)
p("|cffffcc00Shagu|cffffffffDPS:|cffffddcc Lock: " .. config.lock)
else
p("|cffffcc00Shagu|cffffffffDPS:|cffff5511 Valid Options are 0-1")
end
elseif strlower(cmd) == "toggle" then
config.visible = config.visible == 1 and 0 or 1
ShaguDPS_Config = config
window.Refresh(true)
p("|cffffcc00Shagu|cffffffffDPS:|cffffddcc Visible: " .. config.visible)
elseif strlower(cmd) == "height" then
if tonumber(args) then
config.height = tonumber(args)
ShaguDPS_Config = config
window.Refresh(true)
p("|cffffcc00Shagu|cffffffffDPS:|cffffddcc Bar height: " .. config.height)
else
p("|cffffcc00Shagu|cffffffffDPS:|cffff5511 Valid Options are 1-999")
end
elseif strlower(cmd) == "spacing" then
if tonumber(args) then
config.spacing = tonumber(args)
ShaguDPS_Config = config
window.Refresh(true)
p("|cffffcc00Shagu|cffffffffDPS:|cffffddcc Bar spacing: " .. config.spacing)
else
p("|cffffcc00Shagu|cffffffffDPS:|cffff5511 Valid Options are 0-" .. config.height)
end
elseif strlower(cmd) == "trackall" then
if tonumber(args) and (tonumber(args) == 1 or tonumber(args) == 0) then
config.track_all_units = tonumber(args)
ShaguDPS_Config = config
window.Refresh(true)
p("|cffffcc00Shagu|cffffffffDPS:|cffffddcc Track all units: " .. config.track_all_units)
else
p("|cffffcc00Shagu|cffffffffDPS:|cffff5511 Valid Options are 0-1")
end
elseif strlower(cmd) == "mergepet" then
if tonumber(args) and (tonumber(args) == 1 or tonumber(args) == 0) then
config.merge_pets = tonumber(args)
ShaguDPS_Config = config
window.Refresh(true)
p("|cffffcc00Shagu|cffffffffDPS:|cffffddcc Merge pet: " .. config.merge_pets)
else
p("|cffffcc00Shagu|cffffffffDPS:|cffff5511 Valid Options are 0-1")
end
elseif strlower(cmd) == "texture" then
if tonumber(args) and textures[tonumber(args)] then
config.texture = tonumber(args)
ShaguDPS_Config = config
window.Refresh(true)
p("|cffffcc00Shagu|cffffffffDPS:|cffffddcc Texture: " .. config.texture)
else
p("|cffffcc00Shagu|cffffffffDPS:|cffff5511 Valid Options are 1-" .. table.getn(textures))
end
elseif strlower(cmd) == "pastel" then
if tonumber(args) and (tonumber(args) == 1 or tonumber(args) == 0) then
config.pastel = tonumber(args)
ShaguDPS_Config = config
window.Refresh(true)
p("|cffffcc00Shagu|cffffffffDPS:|cffffddcc Use pastel colors: " .. config.pastel)
else
p("|cffffcc00Shagu|cffffffffDPS:|cffff5511 Valid Options are 0-1")
end
elseif strlower(cmd) == "backdrop" then
if tonumber(args) and (tonumber(args) == 1 or tonumber(args) == 0) then
config.backdrop = tonumber(args)
ShaguDPS_Config = config
window.Refresh(true)
p("|cffffcc00Shagu|cffffffffDPS:|cffffddcc Show window backdrop: " .. config.backdrop)
else
p("|cffffcc00Shagu|cffffffffDPS:|cffff5511 Valid Options are 0-1")
end
end
end