mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-02-28 17:37:07 +08:00
feat: 默认工具栏初始位置
This commit is contained in:
parent
b87a2b3e2f
commit
16b6337f2a
@ -106,14 +106,14 @@ let lastY = 0;
|
||||
|
||||
function clampX(x: number) {
|
||||
if (x < 16) x = 16;
|
||||
const mx = window.innerWidth - 16 - main.offsetWidth;
|
||||
const mx = window.innerWidth - 16 - width.value;
|
||||
if (x > mx) x = mx;
|
||||
return x;
|
||||
}
|
||||
|
||||
function clampY(y: number) {
|
||||
if (y < 16) y = 16;
|
||||
const my = window.innerHeight - 16 - main.offsetHeight;
|
||||
const my = window.innerHeight - 16 - height.value;
|
||||
if (y > my) y = my;
|
||||
return y;
|
||||
}
|
||||
@ -124,14 +124,14 @@ function clampPos(x: number, y: number) {
|
||||
|
||||
function clampWidth(w: number) {
|
||||
if (w < 16) w = 16;
|
||||
const mw = window.innerWidth - 16 - main.offsetLeft;
|
||||
const mw = window.innerWidth - 16 - left.value;
|
||||
if (w > mw) w = mw;
|
||||
return w;
|
||||
}
|
||||
|
||||
function clampHeight(h: number) {
|
||||
if (h < 16) h = 16;
|
||||
const mh = window.innerHeight - 16 - main.offsetTop;
|
||||
const mh = window.innerHeight - 16 - top.value;
|
||||
if (h > mh) h = mh;
|
||||
return h;
|
||||
}
|
||||
@ -205,15 +205,20 @@ function resize() {
|
||||
if (has(props.left)) left.value = props.left;
|
||||
if (has(props.top)) top.value = props.top;
|
||||
|
||||
width.value = clampWidth(width.value);
|
||||
height.value = clampHeight(height.value);
|
||||
main.style.width = `${width.value}px`;
|
||||
main.style.height = `${height.value}px`;
|
||||
const beforeWidth = width.value;
|
||||
const beforeHeight = height.value;
|
||||
width.value = 16;
|
||||
height.value = 16;
|
||||
|
||||
left.value = clampX(left.value);
|
||||
top.value = clampY(top.value);
|
||||
main.style.left = `${left.value}px`;
|
||||
main.style.top = `${top.value}px`;
|
||||
|
||||
width.value = clampWidth(beforeWidth);
|
||||
height.value = clampHeight(beforeHeight);
|
||||
main.style.width = `${width.value}px`;
|
||||
main.style.height = `${height.value}px`;
|
||||
}
|
||||
|
||||
onUpdated(resize);
|
||||
|
@ -389,7 +389,7 @@ Mota.require('var', 'hook').on('reset', () => {
|
||||
Mota.require('var', 'hook').once('reset', () => {
|
||||
const mainStorage = GameStorage.for(GameStorage.fromGame('main'));
|
||||
mainStorage.read();
|
||||
if (mainStorage.getValue('played', false)) {
|
||||
if (!mainStorage.getValue('played', false)) {
|
||||
mainStorage.setValue('played', true);
|
||||
let defaultsTool = CustomToolbar.list.find(v => v.id === '@defaults');
|
||||
const hasDefaults = !!defaultsTool;
|
||||
@ -420,22 +420,22 @@ Mota.require('var', 'hook').once('reset', () => {
|
||||
]
|
||||
});
|
||||
// 计算位置,显示在游戏画面下方
|
||||
// if (!hasDefaults) {
|
||||
// const gameGroup = core.dom.gameGroup;
|
||||
// const bottom = gameGroup.offsetTop + gameGroup.offsetHeight - 3;
|
||||
// const left = gameGroup.offsetLeft + 3;
|
||||
// const width = gameGroup.offsetWidth - 6;
|
||||
if (!hasDefaults) {
|
||||
const game = core.dom.gameDraw;
|
||||
const bottom = game.offsetTop + game.offsetHeight;
|
||||
const left = game.offsetLeft;
|
||||
const width = game.offsetWidth;
|
||||
|
||||
// if (isMobile) {
|
||||
// // 手机端显示在最下方
|
||||
// defaultsTool.setPos(16, window.innerHeight - 32);
|
||||
// defaultsTool.setSize(bottom, 35);
|
||||
// } else {
|
||||
// // 电脑显示在屏幕右方
|
||||
// defaultsTool.setPos(left, bottom);
|
||||
// defaultsTool.setSize(width, 70);
|
||||
// }
|
||||
// }
|
||||
if (isMobile) {
|
||||
// 手机端显示在最下方
|
||||
defaultsTool.setPos(16, bottom);
|
||||
defaultsTool.setSize(window.innerWidth - 32, 85);
|
||||
} else {
|
||||
// 电脑显示在屏幕右方
|
||||
defaultsTool.setPos(left, bottom);
|
||||
defaultsTool.setSize(width, 70);
|
||||
}
|
||||
}
|
||||
|
||||
defaultsTool.show();
|
||||
CustomToolbar.save();
|
||||
|
Loading…
Reference in New Issue
Block a user