forked from Road-block/Cartographer
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Cartographer.lua
353 lines (304 loc) · 10.1 KB
/
Cartographer.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
Cartographer = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceDB-2.0", "AceModuleCore-2.0", "AceHook-2.1")
Cartographer.revision = tonumber(string.sub("$Revision: 18624 $", 12, -3))
Cartographer.version = "r" .. Cartographer.revision
Cartographer.date = string.sub("$Date: 2006-12-02 16:07:22 +0300 (Сб, 02 дек 2006) $", 8, 17)
local Dewdrop = AceLibrary("Dewdrop-2.0")
local L = AceLibrary("AceLocale-2.2"):new("Cartographer")
Cartographer.L = L
local BZ = AceLibrary("Babble-Zone-2.2")
BINDING_HEADER_CARTOGRAPHER = "Cartographer"
BINDING_NAME_CARTOGRAPHER_OPENALTERNATEMAP = "Open alternate map"
-- Override continents list so they don't pollute map selection
function GetCustomMapContinents() return unpack({ 'Kalimdor', 'Eastern Kingdoms' }) end
L:RegisterTranslations("enUS", function() return {
["Active"] = true,
["Suspend/resume this module."] = true,
["Right-Click on map to zoom out"] = true,
["Left-Click on map to zoom in"] = true,
["Go to %s"] = true,
["Azeroth"] = true,
["Cosmic map"] = true,
} end)
L:RegisterTranslations("ruRU", function() return {
["Active"] = "Активен",
["Suspend/resume this module."] = "Отключить/Запустить данный модуль",
["Right-Click on map to zoom out"] = "Правое нажатие по карте - уменьшение масштаба",
["Left-Click on map to zoom in"] = "Левое нажатие по карте - увеличение масштаба",
["Go to %s"] = "Перейти на %s",
["Azeroth"] = "Азерот",
["Cosmic map"] = "Карта космоса",
} end)
L:RegisterTranslations("deDE", function() return {
-- ["Toggle"] = true,
-- ["Toggle the module on and off."] = true,
} end)
L:RegisterTranslations("frFR", function() return {
-- ["Toggle"] = true,
-- ["Toggle the module on and off."] = true,
} end)
L:RegisterTranslations("koKR", function() return {
["Active"] = "활성화",
["Suspend/resume this module."] = "모듈을 켜거나 끔니다.",
["Right-Click on map to zoom out"] = "오른쪽-클릭 : 축소",
["Left-Click on map to zoom in"] = "왼쪽-클릭 : 확대",
["Go to %s"] = "%s 바로가기",
["Azeroth"] = "아제로스",
["Cosmic map"] = "세계 지도",
} end)
L:RegisterTranslations("zhCN", function() return {
-- ["Toggle"] = true,
-- ["Toggle the module on and off."] = true,
} end)
L:RegisterTranslations("zhTW", function() return {
-- ["Toggle"] = true,
-- ["Toggle the module on and off."] = true,
} end)
Cartographer:RegisterDB("CartographerDB")
Cartographer.options = {
type = 'group',
args = {
},
}
Dewdrop:InjectAceOptionsTable(Cartographer, Cartographer.options)
Cartographer.options.args.standby = nil
function Cartographer:OnInitialize()
self.gotoOptions = {
type = 'group',
args = {
player = {
name = string.format(L["Go to %s"], GetRealZoneText()),
desc = string.format(L["Go to %s"], GetRealZoneText()),
type = 'execute',
func = function()
SetMapToCurrentZone()
end,
order = 1
}
},
}
for i,continent in ipairs { GetCustomMapContinents() } do
local i = i
local validate = { GetMapZones(i) }
self.gotoOptions.args[string.gsub(continent, " ", "-")] = {
name = continent,
desc = continent,
type = 'text',
validate = validate,
get = function() return self:GetCurrentInstance() or GetCurrentMapContinent() == i and validate[GetCurrentMapZone()] end,
set = function(text)
for j,v in ipairs(validate) do
if v == text then
SetMapZoom(i, j)
break
end
end
end,
}
end
if not GetBindingAction("ALT-M") and not GetBindingKey("CARTOGRAPHER_OPENALTERNATEMAP") then
SetBinding("ALT-M", "CARTOGRAPHER_OPENALTERNATEMAP")
end
end
local magnifyingGlassTexts = { L["Right-Click on map to zoom out"], L["Left-Click on map to zoom in"] }
function Cartographer:OnEnable()
WorldMapContinentDropDown:Hide()
WorldMapZoneDropDown:Hide()
local button = CreateFrame("Button", "CartographerOptionsButton", WorldMapFrame, "UIPanelButtonTemplate")
button:SetText("Cartographer")
local width = button:GetTextWidth() + 30
if width < 110 then
width = 110
end
button:SetWidth(width)
button:SetHeight(22)
WorldMapZoomOutButton:Hide()
button:SetPoint("BOTTOM", WorldMapZoomOutButton, "BOTTOM", 0, 0)
button:SetPoint("RIGHT", WorldMapDetailFrame, "RIGHT", -5, 0)
button:SetScript("OnClick", function()
Dewdrop:Register(this,
'children', self.options,
'dontHook', true,
'point', "TOPRIGHT",
'relativePoint', "BOTTOMRIGHT"
)
this:SetScript("OnClick", function()
if Dewdrop:IsOpen(this) then
Dewdrop:Close()
else
Dewdrop:Open(this)
end
end)
this:GetScript("OnClick")()
end)
local CartographerGoToButton = CreateFrame("Button", "CartographerGoToButton", WorldMapFrame, "UIPanelButtonTemplate")
CartographerGoToButton:SetText(UNKNOWN)
local width = CartographerGoToButton:GetTextWidth() + 30
if width < 220 then
width = 220
end
CartographerGoToButton:SetWidth(width)
CartographerGoToButton:SetHeight(22)
CartographerGoToButton:SetPoint("BOTTOM", WorldMapZoomOutButton, "BOTTOM", 0, 0)
CartographerGoToButton:SetPoint("LEFT", WorldMapDetailFrame, "LEFT", 5, 0)
CartographerGoToButton:SetScript("OnClick", function()
Dewdrop:Register(this,
'children', self.gotoOptions,
'dontHook', true,
'point', "TOPRIGHT",
'relativePoint', "BOTTOMRIGHT"
)
this:SetScript("OnClick", function()
if Dewdrop:IsOpen(this) then
Dewdrop:Close()
else
Dewdrop:Open(this)
end
end)
this:GetScript("OnClick")()
end)
self:Hook(WorldMapFrame, "Hide", "WorldMapFrame_Hide", true)
self:Hook(WorldMapFrame, "Show", "WorldMapFrame_Show", true)
self:RegisterEvent("Cartographer_MapClosed")
self:RegisterEvent("Cartographer_ChangeZone")
self:RegisterEvent("WORLD_MAP_UPDATE")
self:Cartographer_ChangeZone(self:GetCurrentEnglishZoneName(), self:GetCurrentLocalizedZoneName())
WorldMapMagnifyingGlassButton:SetText(table.concat(magnifyingGlassTexts, "\n"))
end
function Cartographer:WorldMapFrame_Hide(this)
local shown = WorldMapFrame:IsShown()
self.hooks[this].Hide(this)
if shown then
self:TriggerEvent("Cartographer_MapClosed")
end
end
function Cartographer:WorldMapFrame_Show(this)
local shown = WorldMapFrame:IsShown()
self.hooks[this].Show(this)
if not shown then
self:TriggerEvent("Cartographer_MapOpened")
end
end
function Cartographer:WORLD_MAP_UPDATE()
self:TriggerEvent("Cartographer_ChangeZone", self:GetCurrentEnglishZoneName(), self:GetCurrentLocalizedZoneName())
end
function Cartographer:Cartographer_MapClosed()
if Dewdrop:IsOpen(CartographerGoToButton) or Dewdrop:IsOpen(CartographerOptionsButton) then
Dewdrop:Close()
end
SetMapToCurrentZone()
end
local continents = { GetCustomMapContinents() }
continents[0] = L["Azeroth"]
continents[-1] = L["Cosmic map"]
function Cartographer:Cartographer_ChangeZone(zone, localZone)
if localZone then
CartographerGoToButton:SetText(localZone)
Cartographer.gotoOptions.args.player.name = string.format(L["Go to %s"], GetRealZoneText())
Cartographer.gotoOptions.args.player.desc = Cartographer.gotoOptions.args.player.name
else
CartographerGoToButton:SetText(continents[GetCurrentMapContinent()] or UNKNOWN)
end
end
function Cartographer:OnProfileEnable(alpha, bravo)
for _,module in self:IterateModules() do
if self:IsModuleActive(module) and type(module.OnProfileEnable) == "function" then
module:OnProfileEnable(alpha, bravo)
end
end
end
function Cartographer:AddToMagnifyingGlass(text)
for _,v in ipairs(magnifyingGlassTexts) do
if v == text then
error(string.format("Cannot add %q to magnifying glass, it already exists", text), 2)
end
end
table.insert(magnifyingGlassTexts, text)
WorldMapMagnifyingGlassButton:SetText(table.concat(magnifyingGlassTexts, "\n"))
end
function Cartographer:RemoveFromMagnifyingGlass(text)
local id
for i,v in ipairs(magnifyingGlassTexts) do
if v == text then
id = i
break
end
end
if not id then
error(string.format("Cannot remove %q from magnifying glass, it does not exist", text), 2)
end
table.remove(magnifyingGlassTexts, id)
WorldMapMagnifyingGlassButton:SetText(table.concat(magnifyingGlassTexts, "\n"))
end
local currentInstance
function Cartographer:SetCurrentInstance(zone)
if currentInstance ~= zone then
currentInstance = zone
self:TriggerEvent("Cartographer_SetCurrentInstance", zone)
self:TriggerEvent("Cartographer_ChangeZone", self:GetCurrentEnglishZoneName(), self:GetCurrentLocalizedZoneName())
end
end
function Cartographer:GetCurrentInstance()
return currentInstance
end
local instanceWorldMapButton
function Cartographer:RegisterInstanceWorldMapButton(frame)
instanceWorldMapButton = frame
self:TriggerEvent("Cartographer_RegisterInstanceWorldMapButton", frame)
end
function Cartographer:GetInstanceWorldMapButton()
return instanceWorldMapButton
end
local mapZones = setmetatable({}, {__index = function(self, key)
self[key] = { GetMapZones(key) }
return self[key]
end })
function Cartographer:GetCurrentLocalizedZoneName()
if currentInstance then
return BZ[currentInstance]
end
local z = mapZones[GetCurrentMapContinent()][GetCurrentMapZone()]
if z then
return z
else
local map = GetMapInfo()
if map == "WarsongGulch" then
return BZ["Warsong Gulch"]
elseif map == "ArathiBasin" then
return BZ["Arathi Basin"]
elseif map == "AlteracValley" then
return BZ["Alterac Valley"]
elseif map == "NetherstormArena" then
return BZ["Eye of the Storm"]
end
return nil
end
end
function Cartographer:GetCurrentEnglishZoneName()
if currentInstance then
return currentInstance
end
local z = mapZones[GetCurrentMapContinent()][GetCurrentMapZone()]
if z then
return BZ:GetReverseTranslation(z)
else
local map = GetMapInfo()
if map == "WarsongGulch" then
return "Warsong Gulch"
elseif map == "ArathiBasin" then
return "Arathi Basin"
elseif map == "AlteracValley" then
return "Alterac Valley"
elseif map == "NetherstormArena" then
return "Eye of the Storm"
end
return nil
end
end
function Cartographer:OpenAlternateMap()
if self:GetProfile() == "Default" or self:GetProfile() == "Alternate" then
self:SetProfile(self:GetProfile() == "Default" and "Alternate" or "Default")
end
if not WorldMapFrame:IsShown() then
ToggleWorldMap()
end
end