Skip to content

Commit b3392be

Browse files
authored
feat: Entity interaction button for mobile (#346)
1 parent bf3381c commit b3392be

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

src/react/TouchInteractionHint.module.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.hint_container {
22
position: fixed;
3-
top: 20%;
43
left: 0;
54
right: 0;
5+
bottom: calc(var(--safe-area-inset-bottom) + 55px);
66
margin: 0 auto;
77
width: fit-content;
88
display: flex;
@@ -13,6 +13,11 @@
1313
text-shadow: 1px 1px 8px rgba(0, 0, 0, 1);
1414
}
1515

16+
.hint_container > button {
17+
width: auto;
18+
padding: 0 10px;
19+
}
20+
1621
.hint_text {
1722
color: white;
1823
font-size: 10px;

src/react/TouchInteractionHint.tsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,33 @@ import { useSnapshot } from 'valtio'
33
import { options } from '../optionsStorage'
44
import { activeModalStack } from '../globalState'
55
import { videoCursorInteraction } from '../customChannels'
6-
import PixelartIcon, { pixelartIcons } from './PixelartIcon'
6+
// import PixelartIcon, { pixelartIcons } from './PixelartIcon'
77
import styles from './TouchInteractionHint.module.css'
88
import { useUsingTouch } from './utilsApp'
9+
import Button from './Button'
910

1011
export default () => {
1112
const usingTouch = useUsingTouch()
1213
const modalStack = useSnapshot(activeModalStack)
1314
const { touchInteractionType } = useSnapshot(options)
1415
const [hintText, setHintText] = useState<string | null>(null)
16+
const [entityName, setEntityName] = useState<string | null>(null)
1517

1618
useEffect(() => {
1719
const update = () => {
1820
const videoInteraction = videoCursorInteraction()
1921
if (videoInteraction) {
2022
setHintText(`Interact with video`)
23+
setEntityName(null)
2124
} else {
2225
const cursorState = bot.mouse.getCursorState()
2326
if (cursorState.entity) {
24-
const entityName = cursorState.entity.displayName ?? cursorState.entity.name
25-
setHintText(`Attack ${entityName}`)
27+
const name = cursorState.entity.displayName ?? cursorState.entity.name ?? 'Entity'
28+
setHintText(`Attack ${name}`)
29+
setEntityName(name)
2630
} else {
2731
setHintText(null)
32+
setEntityName(null)
2833
}
2934
}
3035
}
@@ -40,13 +45,30 @@ export default () => {
4045
}
4146
}, [])
4247

48+
const handleUseButtonClick = (e: React.MouseEvent) => {
49+
e.preventDefault()
50+
e.stopPropagation()
51+
52+
document.dispatchEvent(new MouseEvent('mousedown', { button: 2 }))
53+
bot.mouse.update()
54+
document.dispatchEvent(new MouseEvent('mouseup', { button: 2 }))
55+
}
56+
4357
if (!usingTouch || touchInteractionType !== 'classic' || modalStack.length > 0) return null
44-
if (!hintText) return null
58+
if (!hintText && !entityName) return null
4559

4660
return (
47-
<div className={`${styles.hint_container} interaction-hint`}>
48-
<PixelartIcon iconName={pixelartIcons['sun-alt']} width={14} />
49-
<span className={styles.hint_text}>{hintText}</span>
61+
<div
62+
className={`${styles.hint_container} interaction-hint`}
63+
>
64+
{/* temporary hide hint indicator and text */}
65+
{/* <PixelartIcon iconName={pixelartIcons['sun-alt']} width={14} />
66+
<span className={styles.hint_text}>{hintText || 'Attack entity'}</span> */}
67+
<Button
68+
onClick={handleUseButtonClick}
69+
>
70+
{`Use ${entityName}`}
71+
</Button>
5072
</div>
5173
)
5274
}

0 commit comments

Comments
 (0)