-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcore.lua
More file actions
275 lines (243 loc) · 7.58 KB
/
core.lua
File metadata and controls
275 lines (243 loc) · 7.58 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
QuickLink = LibStub("AceAddon-3.0"):NewAddon("QuickLink", "AceConsole-3.0", "AceHook-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("QuickLink", true)
local AceConfig = LibStub("AceConfig-3.0")
local LRI = LibStub:GetLibrary("LibRealmInfo");
-- default config settings
local QuickLink_defaultPages = {
{ name = "Armory", url = "http://worldofwarcraft.com/{REGION_LANGUAGE}/character/{REALM}/{NAME}", enabled = true },
{ name = "Ask Mr. Robot", url = "http://www.askmrrobot.com/optimizer#{REGION}/{REALM}/{NAME}", enabled = true },
{ name = "raider.io", url = "https://raider.io/characters/{REGION}/{REALM}/{NAME}", enabled = true },
{ name = "WOW Progress", url = "http://www.wowprogress.com/character/{REGION}/{REALM}/{NAME}", enabled = true },
}
StaticPopupDialogs["QUICKLINK_DELETE"] = {
text = "" ,
button1 = L['YES'],
button2 = L['NO'],
OnAccept = function() end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3, -- avoid some UI taint, see http://www.wowace.com/announcements/how-to-avoid-some-ui-taint/
}
function table:get(t, key, default)
if t[key] ~= nil then
return t[key]
else
return default
end
end
local function urlEscape(url)
return string.gsub(url, "([^A-Za-z0-9_:/?&=.-])",
function(ch)
return string.format("%%%02x", string.byte(ch))
end)
end
local function getUrl(urltemplate, name, server)
local region = nil
local url = nil
if not name or name == "" then return end
if not server or server == "" then server = GetRealmName() end
local _,realm,_,_,_,_,region = LRI:GetRealmInfo(server)
region = string.lower(region)
if not region or region == "" then
QuickLink:Print(L['REGIONERROR'])
return;
end
if not realm or realm == "" then
QuickLink:Print(L['REALMERROR'])
return;
end
realm = realm:gsub("'","");
realm = realm:gsub(" ","-");
url,_ = string.gsub(urltemplate, "{REGION}", region)
if string.lower(L["LANGUAGE"]) == "en" and region == "eu" then
region_language = "en-gb"
elseif string.lower(L["LANGUAGE"]) == "en" and region == "us" then
region_language = "en-gb"
else
region_language = L["LANGUAGE"]
end
url,_ = string.gsub(url, "{REGION_LANGUAGE}", region_language)
url,_ = string.gsub(url, "{LANGUAGE}", L["LANGUAGE"])
url,_ = string.gsub(url, "{REALM}", realm)
url,_ = string.gsub(url, "{NAME}", name)
if url then
url = urlEscape(string.lower(url));
end
return url;
end
function QuickLink:ShowUrlFrame(pagename, pagetemplate, name, server)
if not server then
n = gsub(name, "%-[^|]+", "")
s = gsub(name, "[^|]+%-", "")
if n == s then
s = GetRealmName()
end
name, server = n, s
end
local url = getUrl(pagetemplate, name, server);
if url then
linkEditBox:SetText(url)
linkEditBox:HighlightText()
headlineString:SetText(pagename.." link for "..name)
QuickLinkFrame:Show()
end
end
function GenConfig()
local options = {
name = L["ADDONNAME"], handler = QuickLink, type = "group",
args = {
desc = {
order = 1,
type = "description",
name = L['OPTION_DESCRIPTION'],
},
}
}
for i, page in pairs(QuickLinkPages) do
local page_options = {
type = "group",
name = page.name,
order = 10+i,
args = {
page_name = {
order = 1,
type = "input",
name = L['OPTION_LABEL_NAME'],
desc = L['OPTION_HELP_NAME'],
set = function(info, val)
QuickLinkPages[i].name = val
ConfigChange()
end,
get = function() return table:get(QuickLinkPages[i], "name", "") end,
},
page_url = {
order = 2,
type = "input",
name = L['OPTION_LABEL_URL'],
desc = L['OPTION_HELP_URL'],
set = function(info, val)
QuickLinkPages[i].url = val
ConfigChange()
end,
get = function() return table:get(QuickLinkPages[i], "url", "") end,
width = "full",
multiline = 2
},
isEnabled = {
order = 10,
type = "toggle",
name = L['OPTION_LABEL_ENABLED'],
desc = L['OPTION_HELP_ENABLED'],
set = function(info, val)
QuickLinkPages[i].enabled = val
ConfigChange()
end,
get = function() return table:get(QuickLinkPages[i], "enabled", false) end
},
delete = {
type = "execute",
name = L['OPTION_BUTTON_DELETE'],
desc = L['OPTION_HELP_DELETE'],
func = function()
StaticPopupDialogs["QUICKLINK_DELETE"].text = L['POPUP_DELETECONFIRMATION_QUESTION'](QuickLinkPages[i].name)
StaticPopupDialogs["QUICKLINK_DELETE"].OnAccept = function()
QuickLinkPages[i] = nil
ConfigChange()
end
StaticPopup_Show ("QUICKLINK_DELETE")
end,
order = 20,
},
}
}
options.args["page_"..i] = page_options
end
-- add entry for a new site
local new_entry = {name = L['OPTION_DEFAULT_NAME'], url = L['OPTION_DEFAULT_URL'], enabled = false}
options.args["page_new"] = {
type = "group",
name = L['OPTION_LABEL_NEW'],
args = {
page_name = {
order = 1,
type = "input",
name = L['OPTION_LABEL_NAME'],
desc = L['OPTION_HELP_NAME'],
set = function(info, val)
new_entry.name = val
end,
get = function() return new_entry.name end,
},
page_url = {
order = 2,
type = "input",
name = L['OPTION_LABEL_URL'],
desc = L['OPTION_HELP_URL'],
set = function(info, val)
new_entry.url = val
end,
get = function() return new_entry.url end,
width = "full",
multiline = 2
},
isEnabled = {
order = 10,
type = "toggle",
name = L['OPTION_LABEL_ENABLED'],
desc = L['OPTION_HELP_ENABLED'],
set = function(info, val)
new_entry.enabled = val
end,
get = function() return new_entry.enabled end
},
add = {
type = "execute",
name = L['OPTION_BUTTON_ADD'],
desc = L['OPTION_HELP_ADD'],
func = function()
table.insert(QuickLinkPages, new_entry)
end,
order = 20
}
}
}
return options
end
------------------------------------------------------------------------
function ConfigChange()
QuickLink_UNIT_POPUP = QuickLink:GetModule("QuickLink_UNIT_POPUP")
if QuickLink_UNIT_POPUP and QuickLink_UNIT_POPUP:IsEnabled() then
QuickLink_UNIT_POPUP:updateContextMenu()
end
end
function QuickLink:OnInitialize()
if not QuickLinkPages then
QuickLinkPages = QuickLink_defaultPages
end
AceConfig:RegisterOptionsTable("QuickLink", GenConfig)
QuickLink.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("QuickLink", "QuickLink")
QuickLink:EnableModule("QuickLink_UNIT_POPUP")
QuickLink:EnableModule("QuickLink_LFG")
QuickLink:EnableModule("QuickLink_BNET")
ConfigChange()
SLASH_QUICKLINK1 = "/quicklink"
SlashCmdList["QUICKLINK"] = function(msg)
InterfaceOptionsFrame_OpenToCategory("QuickLink")
end
end
function hideDialog()
linkEditBox:SetText("")
linkEditBox:ClearFocus()
QuickLinkFrame:Hide()
end
------------------------------------------------------------------------
-- Frame Event handling
------------------------------------------------------------------------
function okButton1_OnClick()
hideDialog()
end
function linkEditBox_OnEscapePressed()
hideDialog()
end
---