From 9b71ae1a2467079b5fe5e8613defa2628888a30d Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Sun, 6 Apr 2025 00:23:17 +0300 Subject: [PATCH] feat: rework mobile button control sizes & joystick. Make size of every button and joystick configurable via configurator UI from settings! --- src/optionsStorage.ts | 6 +-- src/react/TouchAreasControls.tsx | 64 ++++++++++++++++++++++++++------ 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/optionsStorage.ts b/src/optionsStorage.ts index ba2baeec..3d021903 100644 --- a/src/optionsStorage.ts +++ b/src/optionsStorage.ts @@ -129,18 +129,18 @@ function getDefaultTouchControlsPositions () { ], break: [ 70, - 60 + 57 ], jump: [ 84, - 60 + 57 ], } as Record } function getTouchControlsSize () { return { - joystick: 60, + joystick: 55, action: 36, break: 36, jump: 36, diff --git a/src/react/TouchAreasControls.tsx b/src/react/TouchAreasControls.tsx index 6b34f9bc..ec9d201b 100644 --- a/src/react/TouchAreasControls.tsx +++ b/src/react/TouchAreasControls.tsx @@ -1,9 +1,10 @@ -import { CSSProperties, PointerEvent, useEffect, useRef } from 'react' +import { CSSProperties, PointerEvent, useEffect, useRef, useState } from 'react' import { proxy, ref, useSnapshot } from 'valtio' import { contro } from '../controls' import { options } from '../optionsStorage' import PixelartIcon from './PixelartIcon' import Button from './Button' +import Slider from './Slider' export type ButtonName = 'action' | 'sneak' | 'break' | 'jump' @@ -54,8 +55,9 @@ const Z_INDEX_INTERACTIBLE = 8 export default ({ setupActive, closeButtonsSetup, foregroundGameActive }: Props) => { const bot = window.bot as typeof __type_bot | undefined - const { touchControlsPositions, touchMovementType, touchInteractionType } = useSnapshot(options) + const { touchControlsPositions, touchMovementType, touchInteractionType, touchControlsSize } = useSnapshot(options) const buttonsPositions = touchControlsPositions as ButtonsPositions + const [selectedButton, setSelectedButton] = useState(null) const joystickOuter = useRef(null) const joystickInner = useRef(null) @@ -143,19 +145,23 @@ export default ({ setupActive, closeButtonsSetup, foregroundGameActive }: Props) left: `${buttonsPositions[name][0]}%`, top: `${buttonsPositions[name][1]}%`, borderRadius: '50%', - width: '32px', - height: '32px', + width: `${touchControlsSize[name]}px`, + height: `${touchControlsSize[name]}px`, background: active ? 'rgba(0, 0, 0, 0.8)' : 'rgba(0, 0, 0, 0.5)', display: 'flex', justifyContent: 'center', alignItems: 'center', transition: 'background 0.1s', zIndex: Z_INDEX_INTERACTIBLE, + ...(setupActive && selectedButton === name ? { + border: '2px solid white', + } : {}), } satisfies CSSProperties, onPointerDown (e: PType) { const elem = e.currentTarget as HTMLElement elem.setPointerCapture(e.pointerId) if (setupActive) { + setSelectedButton(name) setupPointer = { x: e.clientX, y: e.clientY } } else { holdDown[name]() @@ -188,33 +194,67 @@ export default ({ setupActive, closeButtonsSetup, foregroundGameActive }: Props) if (!foregroundGameActive && !setupActive) return null return
+ {setupActive && ( +
+ { + if (selectedButton) { + options.touchControlsSize[selectedButton] = value + } + }} + /> +
+ )} {touchMovementType === 'modern' && (
{ + if (setupActive) { + setSelectedButton('joystick') + } }} >