-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Clock.lua
267 lines (254 loc) · 7.66 KB
/
Clock.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
local _, sm = ...
sm.clock = {}
local mod = sm.clock
local L = sm.L
local media = LibStub("LibSharedMedia-3.0")
local options = {
type = "group",
name = L["Clock"],
args = {
xOffset = {
type = "range",
name = L["Horizontal Position"],
order = 1,
max = 2000,
softMax = 250,
min = -2000,
softMin = -250,
step = 1,
bigStep = 5,
get = function() return mod.db.xOffset end,
set = function(info, v) mod.db.xOffset = v mod:UpdateLayout() end
},
yOffset = {
type = "range",
name = L["Vertical Position"],
order = 2,
max = 2000,
softMax = 250,
min = -2000,
softMin = -250,
step = 1,
bigStep = 5,
get = function() return mod.db.yOffset end,
set = function(info, v) mod.db.yOffset = v mod:UpdateLayout() end
},
spacer1 = {
order = 3,
type = "description",
name = " ",
width = "full",
},
fontSize = {
type = "range",
name = L["Font Size"],
order = 4,
min = 4,
max = 30,
step = 1,
bigStep = 1,
get = function() return mod.db.fontsize or select(2, TimeManagerClockTicker:GetFont()) end,
set = function(info, v)
mod.db.fontsize = v
mod:UpdateLayout()
end
},
font = {
type = "select",
name = L["Font"],
order = 5,
values = media:List("font"),
itemControl = "DDI-Font",
get = function()
for i, v in next, media:List("font") do
if v == mod.db.font then return i end
end
end,
set = function(_, value)
local list = media:List("font")
local font = list[value]
mod.db.font = font
mod:UpdateLayout()
end,
},
spacer2 = {
order = 6,
type = "description",
name = " ",
width = "full",
},
fontColor = {
type = "color",
name = L["Font Color"],
order = 7,
hasAlpha = true,
get = function()
if mod.db.fontColor.r then
return mod.db.fontColor.r, mod.db.fontColor.g, mod.db.fontColor.b, mod.db.fontColor.a
else
return TimeManagerClockTicker:GetTextColor()
end
end,
set = function(info, r, g, b, a)
mod.db.fontColor.r, mod.db.fontColor.g, mod.db.fontColor.b, mod.db.fontColor.a = r, g, b, a
mod:UpdateLayout()
end
},
bgColor = {
type = "color",
name = L["Background Color"],
order = 8,
hasAlpha = true,
get = function()
return mod.db.bgColor.r, mod.db.bgColor.g, mod.db.bgColor.b, mod.db.bgColor.a
end,
set = function(info, r, g, b, a)
mod.db.bgColor.r, mod.db.bgColor.g, mod.db.bgColor.b, mod.db.bgColor.a = r, g, b, a
mod:UpdateLayout()
end
},
borderColor = {
type = "color",
name = L["Border Color"],
order = 9,
hasAlpha = true,
get = function()
return mod.db.borderColor.r, mod.db.borderColor.g, mod.db.borderColor.b, mod.db.borderColor.a
end,
set = function(info, r, g, b, a)
mod.db.borderColor.r, mod.db.borderColor.g, mod.db.borderColor.b, mod.db.borderColor.a = r, g, b, a
mod:UpdateLayout()
end
},
monochrome = {
type = "toggle",
name = L.monochrome,
desc = L.monochromeDesc,
order = 9.1,
get = function() return mod.db.monochrome end,
set = function(_, v)
mod.db.monochrome = v
mod:UpdateLayout()
end
},
outline = {
type = "select",
name = L.outline,
order = 9.2,
values = {
NONE = L.none,
OUTLINE = L.thin,
THICKOUTLINE = L.thick,
},
get = function() return mod.db.outline end,
set = function(_, v)
mod.db.outline = v
mod:UpdateLayout()
end
},
fade = {
type = "multiselect",
name = function()
if sm.buttons.db.controlVisibility then
return L["Show %s:"]:format(L["Clock"])
else
return L["Show %s:"]:format(L["Clock"]) .. " |cFF0276FD" .. L["(Requires button visibility control in the Buttons menu)"] .. "|r"
end
end,
order = 10,
values = {
["always"] = L["Always"],
["never"] = L["Never"],
["hover"] = L["On Hover"],
},
get = function(info, v)
return (sm.buttons.db.visibilitySettings.TimeManagerClockButton or "hover") == v
end,
set = function(info, v)
sm.buttons.db.visibilitySettings.TimeManagerClockButton = v
TimeManagerClockButton:SetParent(Minimap) -- Activate the hooksecurefunc we defined in Buttons.lua -- sm.buttons:ChangeFrameVisibility(TimeManagerClockButton, v)
end,
disabled = function()
return not sm.buttons.db.controlVisibility
end,
}
}
}
function mod:OnInitialize(profile)
if type(profile.clock) ~= "table" then
profile.clock = {
xOffset = 0,
yOffset = 0,
bgColor = {r = 0, g = 0, b = 0, a = 1},
borderColor = {r = 0, g = 0, b = 0, a = 1},
fontColor = {},
font = media:GetDefault("font"),
monochrome = false,
outline = "NONE",
}
end
-- XXX temp 10.1.0
if not profile.clock.monochrome then
profile.clock.monochrome = false
end
if not profile.clock.outline then
profile.clock.outline = "NONE"
end
self.db = profile.clock
end
-- Some objects are no longer being called directly using ":" to work around issues with other addons
-- messing with these Blizzard-created widgets (addon conflicts)
function mod:OnEnable()
sm.core:RegisterModuleOptions("Clock", options, L["Clock"])
sm.core.font.ClearAllPoints(TimeManagerClockTicker)
sm.core.font.SetAllPoints(TimeManagerClockTicker)
if MiniMapMailFrame then
local border = sm.core.button.GetRegions(TimeManagerClockButton)
border:Hide() -- Hide the clock border
end
Mixin(TimeManagerClockButton, BackdropTemplateMixin)
TimeManagerClockButton:SetBackdrop(sm.backdrop)
sm.core.button.SetFrameStrata(TimeManagerClockButton, "LOW")
sm.core.button.SetFixedFrameStrata(TimeManagerClockButton, true)
sm.core.button.SetFrameLevel(TimeManagerClockButton, 20) -- Above Questie minimap blips
sm.core.button.SetFixedFrameLevel(TimeManagerClockButton, true)
sm.core.button.SetClampedToScreen(TimeManagerClockButton, true)
sm.core.button.SetClampRectInsets(TimeManagerClockButton, 4,-4,-4,4) -- Allow kissing the edge of the screen when hiding the backdrop border (size 4)
sm.core.button.Show(TimeManagerClockButton)
do
local TimeManagerClockButton = TimeManagerClockButton -- Safety
hooksecurefunc(TimeManagerClockButton, "Hide", function()
sm.core.button.Show(TimeManagerClockButton)
end)
hooksecurefunc(TimeManagerClockButton, "SetPoint", function()
sm.core.button.ClearAllPoints(TimeManagerClockButton)
sm.core.button.SetPoint(TimeManagerClockButton, "TOP", Minimap, "BOTTOM", mod.db.xOffset, mod.db.yOffset)
end)
end
self:UpdateLayout()
end
function mod:OnLoadingScreenOver()
self:UpdateLayout()
end
function mod:UpdateLayout()
sm.core.button.ClearAllPoints(TimeManagerClockButton)
sm.core.button.SetPoint(TimeManagerClockButton, "TOP", Minimap, "BOTTOM", mod.db.xOffset, mod.db.yOffset)
TimeManagerClockButton:SetBackdropColor(mod.db.bgColor.r, mod.db.bgColor.g, mod.db.bgColor.b, mod.db.bgColor.a)
TimeManagerClockButton:SetBackdropBorderColor(mod.db.borderColor.r, mod.db.borderColor.g, mod.db.borderColor.b, mod.db.borderColor.a)
local a, b = GameFontHighlightSmall:GetFont()
local flags = nil
if mod.db.monochrome and mod.db.outline ~= "NONE" then
flags = "MONOCHROME," .. mod.db.outline
elseif mod.db.monochrome then
flags = "MONOCHROME"
elseif mod.db.outline ~= "NONE" then
flags = mod.db.outline
end
sm.core.font.SetFont(TimeManagerClockTicker, mod.db.font and media:Fetch("font", mod.db.font) or a, mod.db.fontsize or b, flags)
if mod.db.fontColor.r then
sm.core.font.SetTextColor(TimeManagerClockTicker, mod.db.fontColor.r, mod.db.fontColor.g, mod.db.fontColor.b, mod.db.fontColor.a)
end
sm.core.font.SetText(TimeManagerClockTicker, "44:44")
sm.core.button.SetWidth(TimeManagerClockButton, sm.core.font.GetUnboundedStringWidth(TimeManagerClockTicker) + 12)
sm.core.button.SetHeight(TimeManagerClockButton, sm.core.font.GetStringHeight(TimeManagerClockTicker) + 10)
end