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