feat:自定义设置界面添加键盘支持

This commit is contained in:
lizhuoyuan 2025-02-07 17:09:06 +08:00
parent b7f4283378
commit fbb28f8c69

View File

@ -3176,8 +3176,6 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
this.w = w; this.w = w;
this.h = h; this.h = h;
this.disable = false; this.disable = false;
/** 按下此按钮后是否重绘所在Menu */
this.redraw = true;
/** 所在的Menu用于触发重绘等事件 */ /** 所在的Menu用于触发重绘等事件 */
this.menu; this.menu;
@ -3194,14 +3192,11 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
this.btnList = new Map(); this.btnList = new Map();
this.keyEvent = () => { }; this.keyEvent = () => { };
this.clickEvent = (x, y, px, py) => { this.clickEvent = (x, y, px, py) => {
let hasClick = false;
this.btnList.forEach((btn) => { this.btnList.forEach((btn) => {
if (btn.disable) return; if (btn.disable) return;
if (px >= btn.x && px <= btn.x + btn.w && py > btn.y && py <= btn.y + btn.h) { if (px >= btn.x && px <= btn.x + btn.w && py > btn.y && py <= btn.y + btn.h) {
btn.event(x, y, px, py); btn.event(x, y, px, py);
if (btn.redraw) hasClick = true;
} }
if (hasClick) this.drawContent();
}); });
} }
} }
@ -3248,7 +3243,15 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
class MenuPage extends MenuBase { class MenuPage extends MenuBase {
constructor(pageList, currPage, ctx) { constructor(pageList, currPage, ctx) {
super(ctx); super(ctx);
/**
* 当前页面列表
* @type {Array<MenuBase>}
*/
this.pageList = pageList; this.pageList = pageList;
/**
* 当前页的序号
* @type {number}
*/
this.currPage = currPage | 0; this.currPage = currPage | 0;
} }
@ -3471,8 +3474,8 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
}, },
"setting": function () { "setting": function () {
// 设置界面绘制 // 自绘设置界面
// core.openSettings = ... // 抽象的不好,很后悔,还是功底太差
const { ButtonBase, MenuBase, MenuPage } = this.MenuBase; const { ButtonBase, MenuBase, MenuPage } = this.MenuBase;
@ -3644,7 +3647,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
let icon, itemName; let icon, itemName;
if (item && core.material.items.hasOwnProperty(item)) { if (item && core.material.items.hasOwnProperty(item)) {
icon = item; icon = item;
itemName = core.material.items.item.name; itemName = core.material.items[item].name;
} }
else { else {
switch (num) { switch (num) {
@ -4020,21 +4023,76 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
constructor(name) { constructor(name) {
super(name); super(name);
this.text = ''; this.text = '';
this.selectedPos;
this.selectedBtn; this.selectedBtn;
this.clickEvent = (x, y, px, py) => { this.clickEvent = (x, y, px, py) => {
this.btnList.forEach((btn) => { this.btnList.forEach((btn, pos) => {
if (btn.disable) return; if (btn.disable) return;
if (px >= btn.x && px <= btn.x + btn.w && py > btn.y && py <= btn.y + btn.h) { if (px >= btn.x && px <= btn.x + btn.w && py > btn.y && py <= btn.y + btn.h) {
if (this.selectedBtn === btn) btn.event(x, y, px, py); if (this.selectedBtn === btn) btn.event(x, y, px, py);
else { else {
this.selectedBtn = btn; this.focus(btn, pos);
this.text = btn.setting.text;
this.drawEventSelector();
this.drawContent();
} }
} }
}); });
} }
this.keyEvent = (keyCode) => {
let x, y;
const changePos = (newPos) => {
if (this.btnList.has(newPos)) {
const button = this.btnList.get(newPos);
this.focus(button, newPos);
}
}
if ([37, 38, 39, 40].includes(keyCode)) {
if (!this.selectedBtn) {
const button = this.btnList.get('1,1');
if (button) this.focus(button, '1,1');
return;
}
else {
[x, y] = this.selectedPos.split(',').map((x) => parseInt(x));
if (keyCode === 37) x--;
if (keyCode === 38) y--;
if (keyCode === 39) x++;
if (keyCode === 40) y++;
let newPos = x + ',' + y;
// 逻辑:左右,查找不到对应坐标就不动。
// 上下,查找不到对应坐标,只要该列存在第一个元素,就会移到该列。
if (keyCode === 37 || keyCode === 39) {
changePos(newPos);
}
if (keyCode === 38 || keyCode === 40) {
if (this.btnList.has(newPos)) {
const button = this.btnList.get(newPos);
this.focus(button, newPos);
}
else {
newPos = '1,' + y;
changePos(newPos);
}
}
}
}
else {
switch (keyCode) {
case 13:
case 32: // Enter/Space
if (this.selectedBtn) this.selectedBtn.event();
break;
}
}
}
}
focus(button, pos) {
this.selectedPos = pos;
this.selectedBtn = button;
this.text = button.setting.text;
this.drawEventSelector();
this.drawContent();
} }
drawEventSelector() { drawEventSelector() {
@ -4091,6 +4149,31 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
class SettingMenu extends MenuPage { class SettingMenu extends MenuPage {
constructor(pageList, currPage, name) { constructor(pageList, currPage, name) {
super(pageList, currPage, name); super(pageList, currPage, name);
this.keyEvent = (keyCode) => {
if (keyCode === 33) this.pageUp();
if (keyCode === 34) this.pageDown();
if ([33, 34].includes(keyCode)) {
const btn = this.btnList.get(this.currPage);
this.changeBtn(btn);
this.drawContent();
}
if (keyCode === 27) {
this.btnList.get('quit').event();
}
}
}
initBtnList(arr) {
super.initBtnList(arr);
this.btnList.forEach((btn) => {
if (btn instanceof ChoiceButton) {
btn.event = function () {
this.menu.changePage(this.index);
this.menu.changeBtn(this);
this.menu.drawContent();
}
}
});
} }
drawContent() { drawContent() {
@ -4099,6 +4182,14 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
super.drawButtonContent(); super.drawButtonContent();
this.initOnePage(); this.initOnePage();
} }
changeBtn(aimBtn) {
this.btnList.forEach((btn) => {
if (btn instanceof ChoiceButton) {
btn.status = aimBtn === btn ? 'clicked' : 'pending';
}
})
}
} }
class TextButton extends ButtonBase { class TextButton extends ButtonBase {
@ -4120,53 +4211,53 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
// 每个页面的按钮 // 每个页面的按钮
const gamePlayMenu = new SettingOnePage('gamePlay'); const gamePlayMenu = new SettingOnePage('gamePlay');
gamePlayMenu.initBtnList([ gamePlayMenu.initBtnList([
['autoGet', new SettingButton(40, 180, 150, 30, 'autoGet')], ['1,1', new SettingButton(40, 180, 150, 30, 'autoGet')],
['autoBattle', new SettingButton(220, 180, 150, 30, 'autoBattle')], ['2,1', new SettingButton(220, 180, 150, 30, 'autoBattle')],
['clickMove', new SettingButton(40, 230, 150, 30, 'clickMove')] ['1,2', new SettingButton(40, 230, 150, 30, 'clickMove')]
]); ]);
const gameViewMenu = new SettingOnePage('gameView'); const gameViewMenu = new SettingOnePage('gameView');
gameViewMenu.initBtnList([ gameViewMenu.initBtnList([
['itemDetail', new SettingButton(40, 180, 150, 25, 'itemDetail')], ['1,1', new SettingButton(40, 180, 150, 25, 'itemDetail')],
['HDCanvas', new SettingButton(40, 205, 150, 25, 'HDCanvas')], ['1,2', new SettingButton(40, 205, 150, 25, 'HDCanvas')],
['displayEnemyDamage', new SettingButton(40, 230, 150, 25, 'displayEnemyDamage')], ['1,3', new SettingButton(40, 230, 150, 25, 'displayEnemyDamage')],
['displayExtraDamage', new SettingButton(40, 255, 150, 25, 'displayExtraDamage')], ['1,4', new SettingButton(40, 255, 150, 25, 'displayExtraDamage')],
['bgm', new SettingButton(40, 300, 150, 25, 'bgm')], ['1,5', new SettingButton(40, 300, 150, 25, 'bgm')],
['decreaseVolume', new SettingButton(40, 325, 25, 25, 'decreaseVolume')], ['1,6', new SettingButton(40, 325, 25, 25, 'decreaseVolume')],
['increaseVolume', new SettingButton(140, 325, 25, 25, 'increaseVolume')], ['2,6', new SettingButton(140, 325, 25, 25, 'increaseVolume')],
['zoomIn', new SettingButton(220, 180, 25, 25, 'zoomIn')], ['2,1', new SettingButton(220, 180, 25, 25, 'zoomIn')],
['zoomOut', new SettingButton(320, 180, 25, 25, 'zoomOut')], ['3,1', new SettingButton(320, 180, 25, 25, 'zoomOut')],
['enableEnemyPoint', new SettingButton(220, 205, 150, 25, 'enableEnemyPoint')], ['2,2', new SettingButton(220, 205, 150, 25, 'enableEnemyPoint')],
['displayCritical', new SettingButton(220, 230, 150, 25, 'displayCritical')], ['2,3', new SettingButton(220, 230, 150, 25, 'displayCritical')],
['se', new SettingButton(220, 300, 150, 25, 'se')], ['2,5', new SettingButton(220, 300, 150, 25, 'se')],
]); ]);
const keyMenu = new SettingOnePage('key'); const keyMenu = new SettingOnePage('key');
keyMenu.initBtnList([ keyMenu.initBtnList([
['leftHand', new SettingButton(40, 160, 150, 25, 'leftHand')], ['1,1', new SettingButton(40, 160, 150, 25, 'leftHand')],
['hotKey1', new SettingButton(40, 220, 150, 25, 'setHotKey', [1])], ['1,2', new SettingButton(40, 220, 150, 25, 'setHotKey', [1])],
['hotKey2', new SettingButton(220, 220, 150, 25, 'setHotKey', [2])], ['2,2', new SettingButton(220, 220, 150, 25, 'setHotKey', [2])],
['hotKey3', new SettingButton(40, 250, 150, 25, 'setHotKey', [3])], ['1,3', new SettingButton(40, 250, 150, 25, 'setHotKey', [3])],
['hotKey4', new SettingButton(220, 250, 150, 25, 'setHotKey', [4])], ['2,3', new SettingButton(220, 250, 150, 25, 'setHotKey', [4])],
['hotKey5', new SettingButton(40, 280, 150, 25, 'setHotKey', [5])], ['1,4', new SettingButton(40, 280, 150, 25, 'setHotKey', [5])],
['hotKey6', new SettingButton(220, 280, 150, 25, 'setHotKey', [6])], ['2,4', new SettingButton(220, 280, 150, 25, 'setHotKey', [6])],
['hotKey7', new SettingButton(40, 310, 150, 25, 'setHotKey', [7])], ['1,5', new SettingButton(40, 310, 150, 25, 'setHotKey', [7])],
['clearHotKeys', new SettingButton(300, 350, 42, 25, 'clearHotKeys')], ['1,6', new SettingButton(300, 350, 42, 25, 'clearHotKeys')],
]); ]);
const consoleMenu = new SettingOnePage('console'); const consoleMenu = new SettingOnePage('console');
consoleMenu.initBtnList([ consoleMenu.initBtnList([
['wallHacking', new SettingButton(40, 220, 150, 25, 'wallHacking')], ['1,1', new SettingButton(40, 220, 150, 25, 'wallHacking')],
['debug_statusName', new SettingButton(80, 250, 80, 20, 'debug_statusName')], ['1,2', new SettingButton(80, 250, 80, 20, 'debug_statusName')],
['debug_statusValue', new SettingButton(210, 250, 80, 20, 'debug_statusValue')], ['2,2', new SettingButton(210, 250, 80, 20, 'debug_statusValue')],
['debug_setStatus', new SettingButton(340, 250, 40, 20, 'debug_setStatus')], ['3,2', new SettingButton(340, 250, 40, 20, 'debug_setStatus')],
['debug_itemName', new SettingButton(80, 276, 80, 20, 'debug_itemName')], ['1,3', new SettingButton(80, 276, 80, 20, 'debug_itemName')],
['debug_itemValue', new SettingButton(240, 276, 80, 20, 'debug_itemValue')], ['2,3', new SettingButton(240, 276, 80, 20, 'debug_itemValue')],
['debug_setItem', new SettingButton(340, 276, 40, 20, 'debug_setItem')], ['3,3', new SettingButton(340, 276, 40, 20, 'debug_setItem')],
['debug_flagName', new SettingButton(80, 302, 80, 20, 'debug_flagName')], ['1,4', new SettingButton(80, 302, 80, 20, 'debug_flagName')],
['debug_flagValue', new SettingButton(210, 302, 80, 20, 'debug_flagValue')], ['2,4', new SettingButton(210, 302, 80, 20, 'debug_flagValue')],
['debug_setFlag', new SettingButton(340, 302, 40, 20, 'debug_setFlag')], ['3,4', new SettingButton(340, 302, 40, 20, 'debug_setFlag')],
]); ]);
// 在此处添加新的菜单页面 // 在此处添加新的菜单页面
@ -4178,37 +4269,30 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
keyBtn = new ChoiceButton(152, 40, 46, 24, '按键', 2), keyBtn = new ChoiceButton(152, 40, 46, 24, '按键', 2),
consoleBtn = new ChoiceButton(212, 40, 66, 24, '控制台', 3); consoleBtn = new ChoiceButton(212, 40, 66, 24, '控制台', 3);
const quit = new TextButton(360, 10, 45, 25, '[退出]'); const quit = new TextButton(360, 10, 45, 25, '[退出]');
quit.redraw = false;
quit.event = () => { quit.event = () => {
settingMenu.clear(); settingMenu.clear();
setTimeout(core.unlockControl, 0); // 消抖,防止点击关闭按钮的一瞬间触发瞬移。 setTimeout(core.unlockControl, 0); // 消抖,防止点击关闭按钮的一瞬间触发瞬移。
} }
settingMenu.btnList = new Map([['gamePlayBtn', gamePlayBtn], ['gameViewBtn', gameViewBtn], settingMenu.initBtnList([[0, gamePlayBtn], [1, gameViewBtn],
['keyBtn', keyBtn], ['consoleBtn', consoleBtn], [2, keyBtn], [3, consoleBtn],
['quit', quit]]); ['quit', quit]]);
function changeBtn(aimBtn) {
settingMenu.btnList.forEach((btn) => {
if (btn instanceof ChoiceButton) {
btn.status = aimBtn === btn ? 'clicked' : 'pending';
}
})
}
settingMenu.btnList.forEach((btn) => {
if (btn instanceof ChoiceButton) {
btn.event = function () {
changeBtn(this);
settingMenu.changePage(this.index);
}
}
});
// 设置初始时选中的按键为第一个按键 // 设置初始时选中的按键为第一个按键
changeBtn(gamePlayBtn); settingMenu.changeBtn(gamePlayBtn);
settingMenu.init(); settingMenu.init();
} }
// todolist 自定义设置界面添加键盘支持
// todolist 剧情全skip功能 文字-文字+演出(跳跃)
// todolist 批量使用您当前选定了xxx。请勿选定不适合批量使用的道具请勿输入过大的数字。 // todolist 批量使用您当前选定了xxx。请勿选定不适合批量使用的道具请勿输入过大的数字。
// todolist 道具栏分页,可设定隐藏的道具,及自动查看显隐藏
// todolist 内置ATRI 解决连通性问题
// todolist 血瓶宝石显示数据 解决浏览地图和楼传显示错误 引入自动配置值的块
// todolist 存读档过程保存图块连通性(可选)
// todolist 清怪检测,重开杖,吸噬
// todolist 修复已知的插件bug
// todolist 添加鸽窝样板的快速读取撤回 和 优化美工
} }
} }