Skip to content

Commit

Permalink
feat(ui): add back, close buttons in settings for mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Jan 31, 2025
1 parent 317b849 commit 28f0546
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
19 changes: 6 additions & 13 deletions src/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ControMax } from 'contro-max/build/controMax'
import { CommandEventArgument, SchemaCommandInput } from 'contro-max/build/types'
import { stringStartsWith } from 'contro-max/build/stringUtils'
import { UserOverrideCommand, UserOverridesConfig } from 'contro-max/build/types/store'
import { isGameActive, showModal, gameAdditionalState, activeModalStack, hideCurrentModal, miscUiState, loadedGameState, hideModal } from './globalState'
import { isGameActive, showModal, gameAdditionalState, activeModalStack, hideCurrentModal, miscUiState, loadedGameState, hideModal, hideAllModals } from './globalState'
import { goFullscreen, pointerLock, reloadChunks } from './utils'
import { options } from './optionsStorage'
import { openPlayerInventory } from './inventoryWindows'
Expand Down Expand Up @@ -740,19 +740,12 @@ window.addEventListener('keydown', (e) => {
if (activeModalStack.length) {
const hideAll = e.ctrlKey || e.metaKey
if (hideAll) {
while (activeModalStack.length > 0) {
hideCurrentModal(undefined, () => {
if (!activeModalStack.length) {
pointerLock.justHitEscape = true
}
})
}
hideAllModals()
} else {
hideCurrentModal(undefined, () => {
if (!activeModalStack.length) {
pointerLock.justHitEscape = true
}
})
hideCurrentModal()
}
if (activeModalStack.length === 0) {
pointerLock.justHitEscape = true
}
} else if (pointerLock.hasPointerLock) {
document.exitPointerLock?.()
Expand Down
7 changes: 7 additions & 0 deletions src/globalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ export const hideCurrentModal = (_data?, onHide?: () => void) => {
}
}

export const hideAllModals = () => {
while (activeModalStack.length > 0) {
if (!hideModal()) break
}
return activeModalStack.length === 0
}

export const openOptionsMenu = (group: OptionsGroupType) => {
showModal({ reactType: `options-${group}` })
}
Expand Down
10 changes: 9 additions & 1 deletion src/react/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface Props extends React.ComponentProps<'button'> {
children?: React.ReactNode
inScreen?: boolean
rootRef?: Ref<HTMLButtonElement>
overlayColor?: string
}

const ButtonContext = createContext({
Expand All @@ -23,7 +24,7 @@ export const ButtonProvider: FC<{ children, onClick }> = ({ children, onClick })
return <ButtonContext.Provider value={{ onClick }}>{children}</ButtonContext.Provider>
}

export default (({ label, icon, children, inScreen, rootRef, type = 'button', postLabel, ...args }) => {
export default (({ label, icon, children, inScreen, rootRef, type = 'button', postLabel, overlayColor, ...args }) => {
const ctx = useContext(ButtonContext)

const onClick = (e) => {
Expand All @@ -45,6 +46,13 @@ export default (({ label, icon, children, inScreen, rootRef, type = 'button', po
{label}
{postLabel}
{children}
{overlayColor && <div style={{
position: 'absolute',
inset: 0,
backgroundColor: overlayColor,
opacity: 0.5,
pointerEvents: 'none'
}} />}
</button>
</SharedHudVars>
}) satisfies FC<Props>
11 changes: 10 additions & 1 deletion src/react/OptionsItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { noCase } from 'change-case'
import { titleCase } from 'title-case'
import { useMemo } from 'react'
import { options, qsOptions } from '../optionsStorage'
import { miscUiState } from '../globalState'
import { hideAllModals, miscUiState } from '../globalState'
import Button from './Button'
import Slider from './Slider'
import Screen from './Screen'
import { showOptionsModal } from './SelectOption'
import PixelartIcon, { pixelartIcons } from './PixelartIcon'

type GeneralItem<T extends string | number | boolean> = {
id?: string
Expand Down Expand Up @@ -188,10 +189,18 @@ interface Props {
}

export default ({ items, title, backButtonAction }: Props) => {
const { currentTouch } = useSnapshot(miscUiState)

return <Screen
title={title}
>
<div className='screen-items'>
{currentTouch && (
<div style={{ position: 'fixed', marginLeft: '-30px', display: 'flex', flexDirection: 'column', gap: 1, }}>
<Button icon={pixelartIcons['close']} onClick={hideAllModals} style={{ color: '#ff5d5d', }} />
<Button icon={pixelartIcons['chevron-left']} onClick={backButtonAction} style={{ color: 'yellow', }} />
</div>
)}
{items.map((element, i) => {
// make sure its unique!
return <RenderOption key={element.id ?? `${title}-${i}`} item={element} />
Expand Down

0 comments on commit 28f0546

Please sign in to comment.