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

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

View File

@ -1690,7 +1690,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
trigo: U,
}
},
},
"drawItemDetail": function () {
/*
* 需要将 变量itemDetail改为true才可正常运行
@ -1896,7 +1896,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
}
}
function willLvUp(exp){
function willLvUp(exp) {
const nextExp = core.getNextLvUpNeed();
if (typeof exp === 'number' && typeof nextExp === 'number' && exp >= nextExp) return true;
return false;
@ -2115,7 +2115,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
flags.__forbidSave__ = before;
core.updateStatusBar();
};
},
},
"newBackpackLook": function () {
// 注:///// *** 裹起来的区域: 该区域内参数可以随意更改调整ui绘制 不会影响总体布局
// 请尽量修改该区域而不是其他区域 修改的时候最好可以对照现有ui修改
@ -3176,8 +3176,6 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
this.w = w;
this.h = h;
this.disable = false;
/** 按下此按钮后是否重绘所在Menu */
this.redraw = true;
/** 所在的Menu用于触发重绘等事件 */
this.menu;
@ -3194,14 +3192,11 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
this.btnList = new Map();
this.keyEvent = () => { };
this.clickEvent = (x, y, px, py) => {
let hasClick = false;
this.btnList.forEach((btn) => {
if (btn.disable) return;
if (px >= btn.x && px <= btn.x + btn.w && py > btn.y && py <= btn.y + btn.h) {
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 {
constructor(pageList, currPage, ctx) {
super(ctx);
/**
* 当前页面列表
* @type {Array<MenuBase>}
*/
this.pageList = pageList;
/**
* 当前页的序号
* @type {number}
*/
this.currPage = currPage | 0;
}
@ -3340,7 +3343,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
this.postComment = function (comment, tags) {
if (core.isReplaying()) return;
const isEmpty = /^\s*$/;
if (isEmpty.test(comment)){
if (isEmpty.test(comment)) {
core.drawTip('您输入的消息为空,请重发!');
core.playSound('error.mp3');
return;
@ -3469,10 +3472,10 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
}
}
},
},
"setting": function () {
// 设置界面绘制
// core.openSettings = ...
// 自绘设置界面
// 抽象的不好,很后悔,还是功底太差
const { ButtonBase, MenuBase, MenuPage } = this.MenuBase;
@ -3619,13 +3622,13 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
)],
['setHotKey', new Setting(
() => '',
function(num){
function (num) {
core.utils.myprompt('输入物品名。名称例如破墙镐或英文ID例如pickaxe均可。', null, (value) => {
const itemInfo = core.material.items;
if (itemInfo) {
const aimItem = Object.values(itemInfo).find((item) => item.name === value || item.id === value);
if (aimItem) {
if (['constants','tools'].includes(aimItem.cls)) {
if (['constants', 'tools'].includes(aimItem.cls)) {
core.setFlag('hotkey' + num, aimItem.id);
this.menu.drawContent();
}
@ -3644,7 +3647,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
let icon, itemName;
if (item && core.material.items.hasOwnProperty(item)) {
icon = item;
itemName = core.material.items.item.name;
itemName = core.material.items[item].name;
}
else {
switch (num) {
@ -3956,7 +3959,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
// 取消注释下面这一句将显示所有按钮的判定框
// core.strokeRect(ctx, this.x, this.y, this.w, this.h, 'yellow');
core.ui.fillText(ctx, this.setting.getName(),
this.x , this.y + this.h / 2 + 5, 'white', '16px Verdana');
this.x, this.y + this.h / 2 + 5, 'white', '16px Verdana');
const drawFunc = this.setting.draw;
if (drawFunc) drawFunc.apply(this, [ctx]);
}
@ -4020,21 +4023,76 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
constructor(name) {
super(name);
this.text = '';
this.selectedPos;
this.selectedBtn;
this.clickEvent = (x, y, px, py) => {
this.btnList.forEach((btn) => {
this.btnList.forEach((btn, pos) => {
if (btn.disable) return;
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);
else {
this.selectedBtn = btn;
this.text = btn.setting.text;
this.drawEventSelector();
this.drawContent();
this.focus(btn, pos);
}
}
});
}
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() {
@ -4091,6 +4149,31 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
class SettingMenu extends MenuPage {
constructor(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() {
@ -4099,6 +4182,14 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
super.drawButtonContent();
this.initOnePage();
}
changeBtn(aimBtn) {
this.btnList.forEach((btn) => {
if (btn instanceof ChoiceButton) {
btn.status = aimBtn === btn ? 'clicked' : 'pending';
}
})
}
}
class TextButton extends ButtonBase {
@ -4120,53 +4211,53 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
// 每个页面的按钮
const gamePlayMenu = new SettingOnePage('gamePlay');
gamePlayMenu.initBtnList([
['autoGet', new SettingButton(40, 180, 150, 30, 'autoGet')],
['autoBattle', new SettingButton(220, 180, 150, 30, 'autoBattle')],
['clickMove', new SettingButton(40, 230, 150, 30, 'clickMove')]
['1,1', new SettingButton(40, 180, 150, 30, 'autoGet')],
['2,1', new SettingButton(220, 180, 150, 30, 'autoBattle')],
['1,2', new SettingButton(40, 230, 150, 30, 'clickMove')]
]);
const gameViewMenu = new SettingOnePage('gameView');
gameViewMenu.initBtnList([
['itemDetail', new SettingButton(40, 180, 150, 25, 'itemDetail')],
['HDCanvas', new SettingButton(40, 205, 150, 25, 'HDCanvas')],
['displayEnemyDamage', new SettingButton(40, 230, 150, 25, 'displayEnemyDamage')],
['displayExtraDamage', new SettingButton(40, 255, 150, 25, 'displayExtraDamage')],
['bgm', new SettingButton(40, 300, 150, 25, 'bgm')],
['decreaseVolume', new SettingButton(40, 325, 25, 25, 'decreaseVolume')],
['increaseVolume', new SettingButton(140, 325, 25, 25, 'increaseVolume')],
['1,1', new SettingButton(40, 180, 150, 25, 'itemDetail')],
['1,2', new SettingButton(40, 205, 150, 25, 'HDCanvas')],
['1,3', new SettingButton(40, 230, 150, 25, 'displayEnemyDamage')],
['1,4', new SettingButton(40, 255, 150, 25, 'displayExtraDamage')],
['1,5', new SettingButton(40, 300, 150, 25, 'bgm')],
['1,6', new SettingButton(40, 325, 25, 25, 'decreaseVolume')],
['2,6', new SettingButton(140, 325, 25, 25, 'increaseVolume')],
['zoomIn', new SettingButton(220, 180, 25, 25, 'zoomIn')],
['zoomOut', new SettingButton(320, 180, 25, 25, 'zoomOut')],
['enableEnemyPoint', new SettingButton(220, 205, 150, 25, 'enableEnemyPoint')],
['displayCritical', new SettingButton(220, 230, 150, 25, 'displayCritical')],
['se', new SettingButton(220, 300, 150, 25, 'se')],
['2,1', new SettingButton(220, 180, 25, 25, 'zoomIn')],
['3,1', new SettingButton(320, 180, 25, 25, 'zoomOut')],
['2,2', new SettingButton(220, 205, 150, 25, 'enableEnemyPoint')],
['2,3', new SettingButton(220, 230, 150, 25, 'displayCritical')],
['2,5', new SettingButton(220, 300, 150, 25, 'se')],
]);
const keyMenu = new SettingOnePage('key');
keyMenu.initBtnList([
['leftHand', new SettingButton(40, 160, 150, 25, 'leftHand')],
['hotKey1', new SettingButton(40, 220, 150, 25, 'setHotKey', [1])],
['hotKey2', new SettingButton(220, 220, 150, 25, 'setHotKey', [2])],
['hotKey3', new SettingButton(40, 250, 150, 25, 'setHotKey', [3])],
['hotKey4', new SettingButton(220, 250, 150, 25, 'setHotKey', [4])],
['hotKey5', new SettingButton(40, 280, 150, 25, 'setHotKey', [5])],
['hotKey6', new SettingButton(220, 280, 150, 25, 'setHotKey', [6])],
['hotKey7', new SettingButton(40, 310, 150, 25, 'setHotKey', [7])],
['clearHotKeys', new SettingButton(300, 350, 42, 25, 'clearHotKeys')],
['1,1', new SettingButton(40, 160, 150, 25, 'leftHand')],
['1,2', new SettingButton(40, 220, 150, 25, 'setHotKey', [1])],
['2,2', new SettingButton(220, 220, 150, 25, 'setHotKey', [2])],
['1,3', new SettingButton(40, 250, 150, 25, 'setHotKey', [3])],
['2,3', new SettingButton(220, 250, 150, 25, 'setHotKey', [4])],
['1,4', new SettingButton(40, 280, 150, 25, 'setHotKey', [5])],
['2,4', new SettingButton(220, 280, 150, 25, 'setHotKey', [6])],
['1,5', new SettingButton(40, 310, 150, 25, 'setHotKey', [7])],
['1,6', new SettingButton(300, 350, 42, 25, 'clearHotKeys')],
]);
const consoleMenu = new SettingOnePage('console');
consoleMenu.initBtnList([
['wallHacking', new SettingButton(40, 220, 150, 25, 'wallHacking')],
['debug_statusName', new SettingButton(80, 250, 80, 20, 'debug_statusName')],
['debug_statusValue', new SettingButton(210, 250, 80, 20, 'debug_statusValue')],
['debug_setStatus', new SettingButton(340, 250, 40, 20, 'debug_setStatus')],
['debug_itemName', new SettingButton(80, 276, 80, 20, 'debug_itemName')],
['debug_itemValue', new SettingButton(240, 276, 80, 20, 'debug_itemValue')],
['debug_setItem', new SettingButton(340, 276, 40, 20, 'debug_setItem')],
['debug_flagName', new SettingButton(80, 302, 80, 20, 'debug_flagName')],
['debug_flagValue', new SettingButton(210, 302, 80, 20, 'debug_flagValue')],
['debug_setFlag', new SettingButton(340, 302, 40, 20, 'debug_setFlag')],
['1,1', new SettingButton(40, 220, 150, 25, 'wallHacking')],
['1,2', new SettingButton(80, 250, 80, 20, 'debug_statusName')],
['2,2', new SettingButton(210, 250, 80, 20, 'debug_statusValue')],
['3,2', new SettingButton(340, 250, 40, 20, 'debug_setStatus')],
['1,3', new SettingButton(80, 276, 80, 20, 'debug_itemName')],
['2,3', new SettingButton(240, 276, 80, 20, 'debug_itemValue')],
['3,3', new SettingButton(340, 276, 40, 20, 'debug_setItem')],
['1,4', new SettingButton(80, 302, 80, 20, 'debug_flagName')],
['2,4', new SettingButton(210, 302, 80, 20, 'debug_flagValue')],
['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),
consoleBtn = new ChoiceButton(212, 40, 66, 24, '控制台', 3);
const quit = new TextButton(360, 10, 45, 25, '[退出]');
quit.redraw = false;
quit.event = () => {
settingMenu.clear();
setTimeout(core.unlockControl, 0); // 消抖,防止点击关闭按钮的一瞬间触发瞬移。
}
settingMenu.btnList = new Map([['gamePlayBtn', gamePlayBtn], ['gameViewBtn', gameViewBtn],
['keyBtn', keyBtn], ['consoleBtn', consoleBtn],
settingMenu.initBtnList([[0, gamePlayBtn], [1, gameViewBtn],
[2, keyBtn], [3, consoleBtn],
['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();
}
// todolist 自定义设置界面添加键盘支持
// todolist 剧情全skip功能 文字-文字+演出(跳跃)
// todolist 批量使用您当前选定了xxx。请勿选定不适合批量使用的道具请勿输入过大的数字。
// todolist 道具栏分页,可设定隐藏的道具,及自动查看显隐藏
// todolist 内置ATRI 解决连通性问题
// todolist 血瓶宝石显示数据 解决浏览地图和楼传显示错误 引入自动配置值的块
// todolist 存读档过程保存图块连通性(可选)
// todolist 清怪检测,重开杖,吸噬
// todolist 修复已知的插件bug
// todolist 添加鸽窝样板的快速读取撤回 和 优化美工
}
}