@@ -3,28 +3,33 @@ import { useSnapshot } from 'valtio'
3
3
import { options } from '../optionsStorage'
4
4
import { activeModalStack } from '../globalState'
5
5
import { videoCursorInteraction } from '../customChannels'
6
- import PixelartIcon , { pixelartIcons } from './PixelartIcon'
6
+ // import PixelartIcon, { pixelartIcons } from './PixelartIcon'
7
7
import styles from './TouchInteractionHint.module.css'
8
8
import { useUsingTouch } from './utilsApp'
9
+ import Button from './Button'
9
10
10
11
export default ( ) => {
11
12
const usingTouch = useUsingTouch ( )
12
13
const modalStack = useSnapshot ( activeModalStack )
13
14
const { touchInteractionType } = useSnapshot ( options )
14
15
const [ hintText , setHintText ] = useState < string | null > ( null )
16
+ const [ entityName , setEntityName ] = useState < string | null > ( null )
15
17
16
18
useEffect ( ( ) => {
17
19
const update = ( ) => {
18
20
const videoInteraction = videoCursorInteraction ( )
19
21
if ( videoInteraction ) {
20
22
setHintText ( `Interact with video` )
23
+ setEntityName ( null )
21
24
} else {
22
25
const cursorState = bot . mouse . getCursorState ( )
23
26
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 )
26
30
} else {
27
31
setHintText ( null )
32
+ setEntityName ( null )
28
33
}
29
34
}
30
35
}
@@ -40,13 +45,30 @@ export default () => {
40
45
}
41
46
} , [ ] )
42
47
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
+
43
57
if ( ! usingTouch || touchInteractionType !== 'classic' || modalStack . length > 0 ) return null
44
- if ( ! hintText ) return null
58
+ if ( ! hintText && ! entityName ) return null
45
59
46
60
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 >
50
72
</ div >
51
73
)
52
74
}
0 commit comments