From 16b6337f2a8a549f06a962eded1950b035356b0c Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Tue, 19 Nov 2024 22:39:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=BB=98=E8=AE=A4=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=A0=8F=E5=88=9D=E5=A7=8B=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/box.vue | 21 +++++++++++++-------- src/core/main/custom/toolbar.ts | 32 ++++++++++++++++---------------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/components/box.vue b/src/components/box.vue index 010548e..ce36d76 100644 --- a/src/components/box.vue +++ b/src/components/box.vue @@ -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); diff --git a/src/core/main/custom/toolbar.ts b/src/core/main/custom/toolbar.ts index e3e40be..b539a40 100644 --- a/src/core/main/custom/toolbar.ts +++ b/src/core/main/custom/toolbar.ts @@ -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();