-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.lua
375 lines (356 loc) · 10.5 KB
/
core.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
-- 作者:houshuu
---------------------------------------------------
-- 插件创建声明
---------------------------------------------------
local E, L, V, P, G = unpack(ElvUI)
local LSM = E.Libs.LSM
local WT = E:NewModule('WindTools', 'AceHook-3.0', 'AceEvent-3.0', 'AceTimer-3.0')
local EP = LibStub("LibElvUIPlugin-1.0")
local addonName, addonTable = ...
---------------------------------------------------
-- 缓存及提高代码可读性
---------------------------------------------------
local linebreak = "\n"
local format = format
local gsub = string.gsub
---------------------------------------------------
-- 初始化
---------------------------------------------------
-- 获取版本信息
WT.Version = GetAddOnMetadata(addonName, "Version")
-- 根据语言获取插件名
WT.Title = L["WindTools"]
-- 初始化设定
WT.ToolConfigs = {}
WT.UpdateAll = {}
P["WindTools"] = {}
---------------------------------------------------
-- 常用函数
---------------------------------------------------
-- 此处 r, g, b 各值均为 0~1 之间
local function RGBToHex(r, g, b)
r = r <= 1 and r >= 0 and r or 0
g = g <= 1 and g >= 0 and g or 0
b = b <= 1 and b >= 0 and b or 0
return format("%02x%02x%02x", r*255, g*255, b*255)
end
-- 为字符串添加自定义颜色
function WT:ColorStr(str, r, g, b)
local hex = r and g and b and RGBToHex(r, g, b) or RGBToHex(52/255, 152/255, 219/255)
return "|cff"..hex..str.."|r"
end
-- 为字符串添加自定义颜色(适合数据库形式的上色)
function WT:ColorStrWithPack(str, colorPack)
if not colorPack then return str end
local r, g, b = colorPack.r, colorPack.g, colorPack.b
if not r or not g or not b then return str end
return WT:ColorStr(str, r, g, b)
end
-- 保持宽高比函数
function WT:GetTexCoord(width, height, keepAspectRatio)
local left, right, top, bottom = unpack(E.TexCoords)
if width > height and keepAspectRatio then
local aspectRatio = height / width
top = 0.5 - (0.5 - top) * aspectRatio
bottom = 0.5 + (bottom - 0.5) * aspectRatio
elseif height > width and keepAspectRatio then
local aspectRatio = width / height
left = 0.5 - (0.5 - left) * aspectRatio
right = 0.5 + (right - 0.5) * aspectRatio
end
return left, right, top, bottom
end
function WT.ClearTextShadow(text)
text:SetShadowColor(0, 0, 0, 0)
text.SetShadowColor = E.noop
end
function WT.SetFont(text, styleDB)
text:FontTemplate(LSM:Fetch('font', styleDB.font), styleDB.fontSize, styleDB.fontFlag)
end
-- TODO: 刷新全部设定
-- 或许可以添加到 staggerTable
-- https://git.tukui.org/elvui/elvui/blob/development/ElvUI/Core/Core.lua#L1267
-- 功能列表
local ToolsOrder = {
["Interface"] = 1,
["Trade"] = 2,
["Chat"] = 3,
["Quest"] = 4,
["More Tools"] = 5,
}
-- E.PopupDialogs["WIND_UPDATE_RL"] = {
-- text = L["ElvUI WindTools has been updated and the data structure of the stored config has also been greatly changed. In order to make these changes take effect, you may have to reload your User Interface."],
-- button1 = ACCEPT,
-- button2 = CANCEL,
-- OnAccept = ReloadUI,
-- timeout = 0,
-- whileDead = 1,
-- hideOnEscape = false,
-- }
E.PopupDialogs["WIND_RESET"] = {
text = L["|cffff0000If you click Accept, it will reset your Windtools.|r"],
button1 = ACCEPT,
button2 = CANCEL,
OnAccept = function()
E.db.WindTools = P["WindTools"]
E.db.WindTools.InstalledVersion = WT.Version
ReloadUI()
end,
timeout = 0,
whileDead = 1,
hideOnEscape = false,
}
E.PopupDialogs["WIND_MODULE_RESET"] = {
text = L["|cffff0000If you click Accept, it will reset this module."],
button1 = ACCEPT,
button2 = CANCEL,
OnAccept = function(self)
if self.data and self.data.cata and self.data.wind_mod then
E.db.WindTools[self.data.cata][self.data.wind_mod] = P.WindTools[self.data.cata][self.data.wind_mod]
ReloadUI()
else
print(L["Reset is failed."])
end
end,
timeout = 0,
whileDead = 1,
hideOnEscape = false,
}
E.PopupDialogs["WIND_RL"] = {
text = L["WindTools will reload your user interface to apply the change."],
button1 = ACCEPT,
button2 = CANCEL,
OnAccept = ReloadUI,
timeout = 0,
whileDead = 1,
hideOnEscape = true,
}
tinsert(E.ConfigModeLayouts, 'WINDTOOLS')
E.ConfigModeLocalizedStrings['WINDTOOLS'] = L["WindTools"]
function WT:InsertOptions()
-- 标题添加
E.Options.name = E.Options.name .. " + " .. L["WindTools"] .. " " .. WT.Version
-- 感谢名单
local WindToolsCreditList = {
"Awbee",
"Azilroka",
"Benik",
"Blazeflack",
"Elv",
"Feraldin",
"Leatrix",
"Marcel Menzel",
"Permok",
"Selias2k",
"Simca",
"Sinaris",
"StormFX",
"Xruptor",
"ahak",
"cadcamzy",
"icw82",
"jjsheets",
"jokair9",
"kagaro",
"loudsoul",
"siweia",
"wandercga",
}
E.Options.args.WindTools = {
-- 插件基本信息
order = 2,
type = "group",
name = WT.Title,
args = {
titleimage = {
order = 1,
type = "description",
name = "",
image = function(info) return "Interface\\Addons\\ElvUI_WindTools\\Texture\\WindTools.blp", 512, 128 end,
},
header1 = {
order = 2,
type = "header",
name = format(L["%s version: %s"], WT.Title, WT.Version),
},
-- description1 = {
-- order = 3,
-- type = "description",
-- name = format(L["%s is a collection of useful tools."], WT.Title),
-- },
-- spacer1 = {
-- order = 4,
-- type = "description",
-- name = "\n",
-- },
-- header2 = {
-- order = 5,
-- type = "header",
-- name = L["Release / Update Link"],
-- },
-- ngapage = {
-- order = 6,
-- type = "input",
-- width = "full",
-- name = L["You can use the following link to get more information (in Chinese)"],
-- get = function(info) return "http://bbs.ngacn.cc/read.php?tid=12142815" end,
-- set = function(info) return "http://bbs.ngacn.cc/read.php?tid=12142815" end,
-- },
-- spacer2 = {
-- order = 7,
-- type = "description",
-- name = "\n",
-- },
-- header3 = {
-- order = 8,
-- type = "header",
-- name = WT:ColorStr(L["Author"]),
-- },
-- author = {
-- order = 9,
-- type = "description",
-- name = "|cffC79C6Ehoushuu @ NGA|r (|cff00FF96Tabimonk|r @ TW-暗影之月)\nSomeBlu @ Github"
-- },
reset_button = {
order = 10,
type = "execute",
name = L["Reset"],
func = function() E:StaticPopup_Show("WIND_RESET") end,
},
credit = {
order = -1,
type = "group",
name = L["Credit List"],
args = {},
},
},
}
-- 生成感谢名单
for i = 1, #WindToolsCreditList do
local cname = WindToolsCreditList[i]
E.Options.args.WindTools.args.credit.args[cname] = {
order = i,
type = "description",
name = WindToolsCreditList[i],
}
end
local function check_attributes(feature) -- check type and guiInline attributes
for arg_name, arg in pairs(feature) do
if arg.args then
arg.type = arg.type or "group"
if arg.type == "group" then arg.guiInline = true end
check_attributes(arg.args)
else
arg.type = arg.type or "toggle"
end
end
end
-- local rl_popup = false
for module_name, module in pairs(WT.ToolConfigs) do
E.Options.args.WindTools.args[module_name] = {
order = ToolsOrder[module_name],
type = "group",
name = L[module_name],
childGroups = "tab",
args = {}
}
local n = 0
for feature_name, feature in pairs(module) do
n = n + 1
-- 生成功能相关设定列表
if feature.tDesc then
E.Options.args.WindTools.args[module_name].args[feature_name] = {
order = n,
type = "group",
name = L[feature_name],
args = {
header1 = {
order = 0,
type = "header",
name = L["Module Information"],
},
oriauthor = {
order = 1,
type = "description",
name = format(L["Author: %s, Edited by %s"], feature.oAuthor, feature.cAuthor)
},
tooldesc = {
order = 2,
type = "description",
name = feature.tDesc
},
header2 = {
order = 3,
type = "header",
name = L["Setting"],
},
enablebtn = {
order = 4,
type = "toggle",
width = "normal",
name = WT:ColorStr(L["Enable"]),
get = function(info) return E.db.WindTools[module_name][feature_name]["enabled"] end,
set = function(info, value) E.db.WindTools[module_name][feature_name]["enabled"] = value; E:StaticPopup_Show("PRIVATE_RL") end,
},
resetbtn = {
order = 4,
type = "execute",
width = "normal",
name = L["Reset"],
func = function() E:StaticPopup_Show("WIND_MODULE_RESET", nil, nil, {cata=module_name, wind_mod=feature_name}) end,
}
}
}
feature.tDesc, feature.oAuthor, feature.cAuthor = nil, nil, nil
-- 加载功能内部函数设定
if feature.func then
feature.func()
feature.func = nil
end
check_attributes(feature)
for arg_name, arg in pairs(feature) do
local disabled = arg.disabled
E.Options.args.WindTools.args[module_name].args[feature_name].args[arg_name] = arg
E.Options.args.WindTools.args[module_name].args[feature_name].args[arg_name].disabled = function(info)
if disabled then
return disabled(info) or not E.db.WindTools[module_name][feature_name]["enabled"]
else
return not E.db.WindTools[module_name][feature_name]["enabled"]
end
end
end
-- 通告系统的设定项太多了还是分开选择好点
if feature_name == "Announce System" then
for arg_name, arg in pairs(E.Options.args.WindTools.args[module_name].args[feature_name].args) do
if arg.order > 4 then arg.guiInline = false end
end
end
end
end
end
-- if rl_popup then E:StaticPopup_Show("WIND_UPDATE_RL") end
-- 版本更新需要重置设置的时候使用
-- if not E.db.WindTools.InstalledVersion then
-- E.db.WindTools["More Tools"]["Announce System"] = P["WindTools"]["More Tools"]["Announce System"]
-- E.db.WindTools.InstalledVersion = WT.Version
-- E:StaticPopup_Show("WIND_UPDATE_RL")
-- end
end
---------------------------------------------------
-- ElvUI 设定部分初始化
---------------------------------------------------
function WT:Initialize()
EP:RegisterPlugin(addonName, WT.InsertOptions)
hooksecurefunc(E, "UpdateEnd", function()
for _,update in ipairs(WT.UpdateAll) do
update()
end
end)
end
---------------------------------------------------
-- 注册 ElvUI 模块
---------------------------------------------------
local function InitializeCallback()
WT:Initialize()
end
E:RegisterModule(WT:GetName(), InitializeCallback)