forked from funkydude/SexyMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Coordinates.lua
303 lines (285 loc) · 6.91 KB
/
Coordinates.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
local _, sm = ...
sm.coordinates = {}
local mod = sm.coordinates
local L = sm.L
local media = LibStub("LibSharedMedia-3.0")
local coordFrame, coordsText
local options = {
type = "group",
name = L["Coordinates"],
childGroups = "tab",
disabled = function() return not mod.db.enabled end,
args = {
enabled = {
type = "toggle",
name = L["Enable Coordinates"],
order = 1,
width = "full",
get = function()
return mod.db.enabled
end,
set = function(info, v)
mod.db.enabled = v
if v then
mod:CreateFrame()
else
if coordFrame then
coordFrame:Hide()
end
end
end,
disabled = false,
},
xOffset = {
type = "range",
name = L["Horizontal Position"],
order = 2,
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:Update() end
},
yOffset = {
type = "range",
name = L["Vertical Position"],
order = 3,
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:Update() end
},
spacer1 = {
order = 4,
type = "description",
name = " ",
},
fontSize = {
type = "range",
name = L["Font Size"],
order = 5,
min = 8,
max = 30,
step = 1,
bigStep = 1,
get = function()
return mod.db.fontSize or 12
end,
set = function(info, v)
mod.db.fontSize = v
mod:Update()
end
},
font = {
type = "select",
name = L["Font"],
order = 6,
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:Update()
end,
},
spacer2 = {
order = 7,
type = "description",
name = " ",
},
fontColor = {
type = "color",
name = L["Font Color"],
order = 8,
hasAlpha = true,
get = function()
local c = mod.db.fontColor
local r, g, b, a = c.r or 1, c.g or 1, c.b or 1, c.a or 1
return r, g, b, a
end,
set = function(info, r, g, b, a)
local c = mod.db.fontColor
c.r, c.g, c.b, c.a = r, g, b, a
mod:Update()
end
},
backgroundColor = {
type = "color",
name = L["Backdrop Color"],
order = 9,
hasAlpha = true,
get = function()
local c = mod.db.backgroundColor
local r, g, b, a = c.r or 0, c.g or 0, c.b or 0, c.a or 1
return r, g, b, a
end,
set = function(info, r, g, b, a)
local c = mod.db.backgroundColor
c.r, c.g, c.b, c.a = r, g, b, a
mod:Update()
end
},
borderColor = {
type = "color",
name = L["Border Color"],
order = 10,
hasAlpha = true,
get = function()
local c = mod.db.borderColor
local r, g, b, a = c.r or 0, c.g or 0, c.b or 0, c.a or 1
return r, g, b, a
end,
set = function(info, r, g, b, a)
local c = mod.db.borderColor
c.r, c.g, c.b, c.a = r, g, b, a
mod:Update()
end
},
updateRate = {
type = "range",
name = L.updateRate,
desc = L.updateRateDesc,
order = 11,
width = "full",
min = 0.1,
max = 1,
step = 0.1,
get = function()
return mod.db.updateRate
end,
set = function(info, v)
mod.db.updateRate = v
end
},
coordPrecision = {
type = "multiselect",
name = L.Precision,
order = 12,
values = {"70,70", "70.1, 70.1", "70.11, 70.11"},
get = function(info, v)
if v == 1 and mod.db.coordPrecision == "%d,%d" then
return true
elseif v == 2 and mod.db.coordPrecision == "%.1f, %.1f" then
return true
elseif v == 3 and mod.db.coordPrecision == "%.2f, %.2f" then
return true
end
end,
set = function(info, v)
if v == 1 then
mod.db.coordPrecision = "%d,%d"
elseif v == 2 then
mod.db.coordPrecision = "%.1f, %.1f"
elseif v == 3 then
mod.db.coordPrecision = "%.2f, %.2f"
end
mod:Update()
end,
}
}
}
function mod:OnInitialize(profile)
if type(profile.coordinates) ~= "table" then
profile.coordinates = {
borderColor = {},
backgroundColor = {},
fontColor = {},
enabled = true,
coordPrecision = "%d,%d",
updateRate = 1,
xOffset = 0,
yOffset = 10,
font = media:GetDefault("font"),
}
end
self.db = profile.coordinates
-- XXX temp 9.0.1
if not profile.coordinates.coordPrecision then
profile.coordinates.enabled = true
profile.coordinates.coordPrecision = "%d,%d"
end
end
function mod:OnEnable()
sm.core:RegisterModuleOptions("Coordinates", options, L["Coordinates"])
if mod.db.enabled then
self:CreateFrame()
end
end
function mod:OnLoadingScreenOver()
if mod.db.enabled then
self:Update()
end
end
function mod:CreateFrame()
if not coordFrame then
coordFrame = CreateFrame("Frame", "SexyMapCoordFrame", Minimap, "BackdropTemplate")
coordFrame:SetBackdrop(sm.backdrop)
coordsText = coordFrame:CreateFontString(nil, nil, "GameFontNormalSmall")
coordsText:SetPoint("CENTER", coordFrame, "CENTER")
coordsText:SetJustifyH("CENTER")
coordsText:SetText("0,0")
coordFrame:SetClampedToScreen(true)
coordFrame:SetClampRectInsets(4,-4,-4,4) -- Allow kissing the edge of the screen when hiding the backdrop border (size 4)
local GetPlayerMapPosition = C_Map.GetPlayerMapPosition
local GetBestMapForUnit = C_Map.GetBestMapForUnit
local CTimerAfter = C_Timer.After
local function updateCoords()
local uiMapID = GetBestMapForUnit"player"
if uiMapID then
local tbl = GetPlayerMapPosition(uiMapID, "player")
if tbl then
CTimerAfter(mod.db.updateRate, updateCoords)
coordsText:SetFormattedText(mod.db.coordPrecision, tbl.x*100, tbl.y*100)
else
CTimerAfter(5, updateCoords)
coordsText:SetText("0,0")
end
else
CTimerAfter(5, updateCoords)
coordsText:SetText("0,0")
end
end
updateCoords()
end
coordFrame:Show()
self:Update()
end
function mod:Update()
coordFrame:SetPoint("CENTER", Minimap, "BOTTOM", mod.db.xOffset, mod.db.yOffset)
if mod.db.borderColor then
local c = mod.db.borderColor
coordFrame:SetBackdropBorderColor(c.r or 0, c.g or 0, c.b or 0, c.a or 1)
end
if mod.db.backgroundColor then
local c = mod.db.backgroundColor
coordFrame:SetBackdropColor(c.r or 0, c.g or 0, c.b or 0, c.a or 1)
end
if mod.db.fontColor then
local c = mod.db.fontColor
coordsText:SetTextColor(c.r or 1, c.g or 1, c.b or 1, c.a or 1)
end
local _, b, c = coordsText:GetFont()
coordsText:SetFont(media:Fetch("font", mod.db.font), mod.db.fontSize or b, c)
if mod.db.coordPrecision == "%.2f, %.2f" then
coordsText:SetText("99.99, 99.99")
elseif mod.db.coordPrecision == "%.1f, %.1f" then
coordsText:SetText("99.9, 99.9")
else
coordsText:SetText("99, 99")
end
coordFrame:SetWidth(coordsText:GetUnboundedStringWidth() + 12)
coordFrame:SetHeight(coordsText:GetStringHeight() + 10)
end