-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.lua
210 lines (195 loc) · 5.71 KB
/
options.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
local AddonName, NS = ...
local CopyTable = CopyTable
local next = next
local IsFlying = IsFlying
local LibStub = LibStub
local AceConfig = LibStub("AceConfig-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local SharedMedia = LibStub("LibSharedMedia-3.0")
---@type DMS
local DMS = NS.DMS
local DMSFrame = NS.DMS.frame
local Options = {}
NS.Options = Options
NS.AceConfig = {
name = AddonName,
type = "group",
args = {
lock = {
name = "Lock the text into place",
type = "toggle",
width = "double",
order = 1,
set = function(_, val)
NS.db.global.lock = val
if val then
NS.Interface:Lock(NS.Interface.textFrame)
else
NS.Interface:Unlock(NS.Interface.textFrame)
end
end,
get = function(_)
return NS.db.global.lock
end,
},
round = {
name = "Round the percentage value",
type = "toggle",
width = "double",
order = 2,
set = function(_, val)
NS.db.global.round = val
NS.UpdateText(NS.Interface.text, NS.Interface.speed, NS.IsDragonriding() and IsFlying())
end,
get = function(_)
return NS.db.global.round
end,
},
showzero = {
name = "Show 0% when NOT moving, instead of run speed",
type = "toggle",
width = "double",
order = 3,
set = function(_, val)
NS.db.global.showzero = val
local currentSpeed, runSpeed = NS.GetSpeedInfo()
local staticSpeed = NS.db.global.showzero and 0 or runSpeed
local showSpeed = (currentSpeed == 0 or NS.Interface.speed == 0) and staticSpeed or NS.Interface.speed
NS.UpdateText(NS.Interface.text, showSpeed, NS.IsDragonriding() and IsFlying())
end,
get = function(_)
return NS.db.global.showzero
end,
},
showlabel = {
name = "Enable label text",
type = "toggle",
width = "double",
order = 4,
set = function(_, val)
NS.db.global.showlabel = val
NS.UpdateText(NS.Interface.text, NS.Interface.speed, NS.IsDragonriding() and IsFlying())
end,
get = function(_)
return NS.db.global.showlabel
end,
},
labeltext = {
type = "input",
name = "Label Text",
width = "double",
order = 5,
disabled = function()
return not NS.db.global.showlabel
end,
set = function(_, val)
NS.db.global.labeltext = val
NS.UpdateText(NS.Interface.text, NS.Interface.speed, NS.IsDragonriding() and IsFlying())
NS.Interface.textFrame:SetWidth(NS.Interface.text:GetStringWidth())
NS.Interface.textFrame:SetHeight(NS.Interface.text:GetStringHeight())
end,
get = function(_)
return NS.db.global.labeltext
end,
},
fontsize = {
type = "range",
name = "Font Size",
width = "double",
order = 6,
min = 2,
max = 64,
step = 1,
set = function(_, val)
NS.db.global.fontsize = val
NS.UpdateFont(NS.Interface.text)
NS.Interface.textFrame:SetWidth(NS.Interface.text:GetStringWidth())
NS.Interface.textFrame:SetHeight(NS.Interface.text:GetStringHeight())
end,
get = function(_)
return NS.db.global.fontsize
end,
},
font = {
type = "select",
name = "Font",
width = "double",
dialogControl = "LSM30_Font",
values = SharedMedia:HashTable("font"),
order = 7,
set = function(_, val)
NS.db.global.font = val
NS.UpdateFont(NS.Interface.text)
NS.Interface.textFrame:SetWidth(NS.Interface.text:GetStringWidth())
NS.Interface.textFrame:SetHeight(NS.Interface.text:GetStringHeight())
end,
get = function(_)
return NS.db.global.font
end,
},
color = {
type = "color",
name = "Color",
width = "double",
order = 8,
hasAlpha = true,
set = function(_, val1, val2, val3, val4)
NS.db.global.color.r = val1
NS.db.global.color.g = val2
NS.db.global.color.b = val3
NS.db.global.color.a = val4
NS.Interface.text:SetTextColor(val1, val2, val3, val4)
end,
get = function(_)
return NS.db.global.color.r, NS.db.global.color.g, NS.db.global.color.b, NS.db.global.color.a
end,
},
reset = {
name = "Reset Everything",
type = "execute",
width = "normal",
order = 100,
func = function()
DMSDB = CopyTable(NS.DefaultDatabase)
NS.db = CopyTable(NS.DefaultDatabase)
end,
},
},
}
function Options:SlashCommands(message)
if message == "toggle lock" then
if NS.db.global.lock == false then
NS.db.global.lock = true
NS.Interface:Lock(NS.Interface.textFrame)
else
NS.db.global.lock = false
NS.Interface:Unlock(NS.Interface.textFrame)
end
else
AceConfigDialog:Open(AddonName)
end
end
function Options:Setup()
AceConfig:RegisterOptionsTable(AddonName, NS.AceConfig)
AceConfigDialog:AddToBlizOptions(AddonName, AddonName)
SLASH_DMS1 = "/dynamicmovementspeed"
SLASH_DMS2 = "/dms"
function SlashCmdList.DMS(message)
self:SlashCommands(message)
end
end
function DMS:ADDON_LOADED(addon)
if addon == AddonName then
DMSFrame:UnregisterEvent("ADDON_LOADED")
DMSDB = DMSDB and next(DMSDB) ~= nil and DMSDB or {}
-- Copy any settings from default if they don't exist in current profile
NS.CopyDefaults(NS.DefaultDatabase, DMSDB)
-- Reference to active db profile
-- Always use this directly or reference will be invalid
NS.db = DMSDB
-- Remove table values no longer found in default settings
NS.CleanupDB(DMSDB, NS.DefaultDatabase)
Options:Setup()
end
end
DMSFrame:RegisterEvent("ADDON_LOADED")