-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
474 lines (444 loc) · 16.2 KB
/
Core.lua
File metadata and controls
474 lines (444 loc) · 16.2 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
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
-- ConsoleBags Handheld Mode
-- ROG Ally X 优化伴侣插件
-- 使用Hook方式,不修改原插件任何文件
local addonName, addon = ...
local AceAddon = LibStub("AceAddon-3.0")
local AceDB = LibStub("AceDB-3.0")
local AceConfig = LibStub("AceConfig-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
-- 创建插件
local CBHandheld = AceAddon:NewAddon(addonName, "AceConsole-3.0")
addon.core = CBHandheld
-- 默认配置
local defaults = {
profile = {
preset = "handheld", -- normal, handheld, big, custom
sizes = {
listItemHeight = 56, -- 物品行高
iconSize = 56, -- 图标大小
filterBarHeight = 48, -- 肩键分类栏高度
headerHeight = 48, -- 头部高度
footerHeight = 48, -- 底部高度
windowWidth = 850, -- 窗口宽度
windowHeight = 650, -- 窗口高度
fontSize = 16, -- 字体大小
},
autoApply = true, -- 是否自动应用
}
}
-- 预设配置
local presets = {
normal = {
listItemHeight = 28,
iconSize = 32,
filterBarHeight = 32,
headerHeight = 32,
footerHeight = 32,
windowWidth = 600,
windowHeight = 436,
fontSize = 12,
},
handheld = {
listItemHeight = 56,
iconSize = 56,
filterBarHeight = 48,
headerHeight = 48,
footerHeight = 48,
windowWidth = 850,
windowHeight = 650,
fontSize = 16,
},
big = {
listItemHeight = 64,
iconSize = 64,
filterBarHeight = 56,
headerHeight = 56,
footerHeight = 56,
windowWidth = 950,
windowHeight = 750,
fontSize = 18,
},
}
-- 检查ConsoleBags是否加载
function CBHandheld:CheckConsoleBags()
local cb = AceAddon:GetAddon("ConsoleBags", true)
if not cb then
self:Print("|cffff0000错误:未检测到ConsoleBags插件!")
self:Print("|cffff0000本插件需要ConsoleBags作为依赖")
return false
end
return true
end
-- 获取ConsoleBags模块
function CBHandheld:GetCBModules()
local cb = AceAddon:GetAddon("ConsoleBags")
return {
addon = cb,
session = cb:GetModule("Session"),
database = cb:GetModule("Database"),
view = cb:GetModule("View"),
}
end
-- 应用配置到ConsoleBags
function CBHandheld:ApplyConfig()
if not self:CheckConsoleBags() then return end
local modules = self:GetCBModules()
local db = self.db.profile
local sizes = db.sizes
-- 修改Session设置 (防御性检查)
if modules.session and modules.session.Settings then
local settings = modules.session.Settings
if settings.Defaults then
if settings.Defaults.Sections then
settings.Defaults.Sections.ListItemHeight = sizes.listItemHeight
settings.Defaults.Sections.Header = sizes.headerHeight
settings.Defaults.Sections.Filters = sizes.filterBarHeight
settings.Defaults.Sections.Footer = sizes.footerHeight
end
if settings.Defaults.Columns then
settings.Defaults.Columns.Icon = sizes.iconSize
settings.Defaults.Columns.Name = math.max(320, sizes.iconSize * 7)
end
end
end
-- 修改数据库默认值 (防御性检查)
if modules.database and modules.database.internal and modules.database.internal.global then
local cbdb = modules.database.internal.global
if cbdb.InventoryFrame then
if cbdb.InventoryFrame.Size then
cbdb.InventoryFrame.Size.X = sizes.windowWidth
cbdb.InventoryFrame.Size.Y = sizes.windowHeight
end
cbdb.InventoryFrame.ItemHeight = sizes.listItemHeight
end
if cbdb.BankFrame then
if cbdb.BankFrame.Size then
cbdb.BankFrame.Size.X = sizes.windowWidth
cbdb.BankFrame.Size.Y = sizes.windowHeight
end
cbdb.BankFrame.ItemHeight = sizes.listItemHeight
end
if cbdb.Font then
cbdb.Font.Size = sizes.fontSize
end
end
-- 更新现有窗口
self:UpdateExistingWindows()
self:Print(string.format("|cff00ff00配置已应用:%s模式", db.preset))
end
-- 更新现有窗口
function CBHandheld:UpdateExistingWindows()
local modules = self:GetCBModules()
if modules.addon and modules.addon.bags then
-- 更新背包窗口
if modules.addon.bags.Inventory then
local inv = modules.addon.bags.Inventory
if inv.UpdateGUI then
inv:UpdateGUI()
end
end
-- 更新银行窗口
if modules.addon.bags.Bank then
local bank = modules.addon.bags.Bank
if bank.UpdateGUI then
bank:UpdateGUI()
end
end
end
end
-- 应用预设
function CBHandheld:ApplyPreset(presetName)
if not presets[presetName] then
self:Print("|cffff0000无效的预设:" .. tostring(presetName))
return
end
-- 复制预设值到配置
for key, value in pairs(presets[presetName]) do
self.db.profile.sizes[key] = value
end
self.db.profile.preset = presetName
-- 如果是自定义模式,保留当前值
if presetName == "custom" then
self:Print("|cff00ff00已切换到自定义模式 - 保留当前设置")
else
self:Print(string.format("|cff00ff00已应用%s预设", presetName))
end
-- 应用配置
self:ApplyConfig()
end
-- 创建配置界面
function CBHandheld:CreateConfig()
local options = {
name = "ConsoleBags 掌机模式",
type = "group",
args = {
desc = {
type = "description",
name = "为ROG Ally X等掌机设备优化ConsoleBags的UI尺寸\n",
fontSize = "medium",
order = 0,
},
preset = {
type = "select",
name = "预设方案",
desc = "选择预设的UI尺寸方案",
values = {
normal = "标准模式 (PC默认)",
handheld = "掌机模式 (ROG Ally X推荐)",
big = "超大模式 (远距离/躺着玩)",
custom = "自定义 (手动调整)",
},
get = function() return self.db.profile.preset end,
set = function(_, value)
self.db.profile.preset = value
self:ApplyPreset(value)
end,
order = 1,
},
applyBtn = {
type = "execute",
name = "立即应用",
desc = "将当前配置应用到ConsoleBags",
func = function() self:ApplyConfig() end,
order = 2,
},
sizesHeader = {
type = "header",
name = "尺寸设置 (自定义模式下可调)",
order = 10,
},
listItemHeight = {
type = "range",
name = "物品行高",
desc = "每行物品的高度",
min = 28,
max = 80,
step = 2,
get = function() return self.db.profile.sizes.listItemHeight end,
set = function(_, value)
self.db.profile.sizes.listItemHeight = value
if self.db.profile.preset ~= "custom" then
self.db.profile.preset = "custom"
end
-- 实时预览
if self.db.profile.autoApply then
self:ApplyConfig()
end
end,
order = 11,
},
iconSize = {
type = "range",
name = "图标大小",
desc = "物品图标的尺寸",
min = 32,
max = 80,
step = 2,
get = function() return self.db.profile.sizes.iconSize end,
set = function(_, value)
self.db.profile.sizes.iconSize = value
if self.db.profile.preset ~= "custom" then
self.db.profile.preset = "custom"
end
if self.db.profile.autoApply then
self:ApplyConfig()
end
end,
order = 12,
},
filterBarHeight = {
type = "range",
name = "分类栏高度",
desc = "肩键切换的物品类型栏高度 (R1/L1切换)",
min = 32,
max = 80,
step = 2,
get = function() return self.db.profile.sizes.filterBarHeight end,
set = function(_, value)
self.db.profile.sizes.filterBarHeight = value
if self.db.profile.preset ~= "custom" then
self.db.profile.preset = "custom"
end
if self.db.profile.autoApply then
self:ApplyConfig()
end
end,
order = 13,
},
headerHeight = {
type = "range",
name = "头部高度",
desc = "顶部标题栏的高度",
min = 32,
max = 80,
step = 2,
get = function() return self.db.profile.sizes.headerHeight end,
set = function(_, value)
self.db.profile.sizes.headerHeight = value
if self.db.profile.preset ~= "custom" then
self.db.profile.preset = "custom"
end
if self.db.profile.autoApply then
self:ApplyConfig()
end
end,
order = 14,
},
windowHeader = {
type = "header",
name = "窗口设置",
order = 20,
},
windowWidth = {
type = "range",
name = "窗口宽度",
desc = "背包和银行窗口的宽度",
min = 600,
max = 1200,
step = 10,
get = function() return self.db.profile.sizes.windowWidth end,
set = function(_, value)
self.db.profile.sizes.windowWidth = value
if self.db.profile.preset ~= "custom" then
self.db.profile.preset = "custom"
end
if self.db.profile.autoApply then
self:ApplyConfig()
end
end,
order = 21,
},
windowHeight = {
type = "range",
name = "窗口高度",
desc = "背包和银行窗口的高度",
min = 400,
max = 900,
step = 10,
get = function() return self.db.profile.sizes.windowHeight end,
set = function(_, value)
self.db.profile.sizes.windowHeight = value
if self.db.profile.preset ~= "custom" then
self.db.profile.preset = "custom"
end
if self.db.profile.autoApply then
self:ApplyConfig()
end
end,
order = 22,
},
fontSize = {
type = "range",
name = "字体大小",
desc = "文字字体的大小",
min = 12,
max = 24,
step = 1,
get = function() return self.db.profile.sizes.fontSize end,
set = function(_, value)
self.db.profile.sizes.fontSize = value
if self.db.profile.preset ~= "custom" then
self.db.profile.preset = "custom"
end
if self.db.profile.autoApply then
self:ApplyConfig()
end
end,
order = 23,
},
optionsHeader = {
type = "header",
name = "选项",
order = 30,
},
autoApply = {
type = "toggle",
name = "自动应用",
desc = "调整滑块时是否立即应用改动(否则需点击立即应用按钮)",
get = function() return self.db.profile.autoApply end,
set = function(_, value) self.db.profile.autoApply = value end,
order = 31,
},
status = {
type = "description",
name = function()
local sizes = self.db.profile.sizes
return string.format(
"\n|cff00ff00当前配置:|r\n" ..
" 物品行高: %dpx\n" ..
" 图标大小: %dpx\n" ..
" 分类栏高度: %dpx\n" ..
" 窗口尺寸: %dx%d\n" ..
" 字体大小: %dpx",
sizes.listItemHeight,
sizes.iconSize,
sizes.filterBarHeight,
sizes.windowWidth,
sizes.windowHeight,
sizes.fontSize
)
end,
order = 40,
},
},
}
AceConfig:RegisterOptionsTable("CBHandheld", options)
self.optionsFrame = AceConfigDialog:AddToBlizOptions("CBHandheld", "ConsoleBags Handheld")
end
-- 初始化
function CBHandheld:OnInitialize()
-- 初始化数据库
self.db = AceDB:New("CBHandheldDB", defaults, true)
-- 创建配置界面
self:CreateConfig()
-- 注册聊天命令
self:RegisterChatCommand("handheld", "ChatCommand")
self:RegisterChatCommand("hh", "ChatCommand")
self:Print("|cff00ff00ConsoleBags Handheld Mode 已加载")
self:Print("输入 |cffffff00/handheld|r 打开配置界面")
end
-- 启用时
function CBHandheld:OnEnable()
-- 延迟等待ConsoleBags完全加载
C_Timer.After(1, function()
if not self:CheckConsoleBags() then return end
-- 如果设置了自动应用,则应用当前预设
if self.db.profile.autoApply then
self:ApplyPreset(self.db.profile.preset)
end
end)
end
-- 聊天命令处理
function CBHandheld:ChatCommand(input)
if not input or input:trim() == "" then
-- 打开配置界面
if Settings and Settings.OpenToCategory then
Settings.OpenToCategory(self.optionsFrame)
else
-- 兼容旧版本
InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
end
return
end
local command, rest = input:match("^(%S*)%s*(.-)$")
command = command:lower()
if command == "apply" then
self:ApplyConfig()
elseif command == "preset" and rest ~= "" then
self:ApplyPreset(rest:lower())
elseif command == "status" then
local sizes = self.db.profile.sizes
self:Print("当前配置:")
self:Print(string.format(" 模式: %s", self.db.profile.preset))
self:Print(string.format(" 物品行高: %dpx", sizes.listItemHeight))
self:Print(string.format(" 分类栏高度: %dpx", sizes.filterBarHeight))
self:Print(string.format(" 窗口: %dx%d", sizes.windowWidth, sizes.windowHeight))
else
self:Print("用法:")
self:Print(" /handheld - 打开配置界面")
self:Print(" /handheld apply - 应用当前配置")
self:Print(" /handheld preset [normal/handheld/big] - 切换预设")
self:Print(" /handheld status - 查看状态")
end
end