-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from dragoni7/save-loadout-in-game-menu
Save loadout in game menu
- Loading branch information
Showing
13 changed files
with
317 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import { | ||
Button, | ||
Drawer, | ||
Grid, | ||
Box, | ||
Autocomplete, | ||
TextField, | ||
Select, | ||
FormControl, | ||
InputLabel, | ||
ImageList, | ||
styled, | ||
} from '@mui/material'; | ||
import { useState } from 'react'; | ||
import useLoadoutIdentifiers from '../hooks/use-loadout-identifiers'; | ||
import { | ||
ManifestLoadoutColor, | ||
ManifestLoadoutIcon, | ||
ManifestLoadoutName, | ||
} from '../../../types/manifest-types'; | ||
import useSelectedCharacterLoadouts from '../hooks/use-selected-character-loadouts'; | ||
import { snapShotLoadoutRequest } from '../../../lib/bungie_api/requests'; | ||
import { store } from '../../../store'; | ||
|
||
const LoadoutSlot = styled('img')(({ theme }) => ({ | ||
backgroundSize: 'cover', | ||
backgroundPosition: 'center', | ||
width: '51%', | ||
height: 'auto', | ||
border: '2px outset transparent', | ||
'&:hover': { border: '2px solid blue' }, | ||
})); | ||
|
||
export default function SaveLoadout() { | ||
const [loadoutDrawerOpen, setLoadoutDrawerOpen] = useState<boolean>(false); | ||
const [loadoutName, setLoadoutName] = useState<ManifestLoadoutName | null>(null); | ||
const [loadoutColor, setLoadoutColor] = useState<ManifestLoadoutColor | null>(null); | ||
const [loadoutIcon, setLoadoutIcon] = useState<ManifestLoadoutIcon | null>(null); | ||
const [identifiersSet, setIdentifiersSet] = useState<boolean>(false); | ||
|
||
const loadoutIdentifiers = useLoadoutIdentifiers(); | ||
const loadouts = useSelectedCharacterLoadouts(); | ||
|
||
function handleBackClick() { | ||
setLoadoutDrawerOpen(false); | ||
setLoadoutName(null); | ||
setLoadoutColor(null); | ||
setLoadoutIcon(null); | ||
} | ||
|
||
const SetIdentifiersDrawer = ( | ||
<Grid container alignItems="center" textAlign="center" rowGap={3} paddingX={4} paddingY={3}> | ||
<Grid item md={12}> | ||
SET IDENTIFIERS | ||
</Grid> | ||
<Grid item md={12}> | ||
<Autocomplete | ||
disablePortal | ||
id="loadout-names" | ||
value={loadoutName} | ||
onChange={(event, newValue) => setLoadoutName(newValue)} | ||
options={loadoutIdentifiers.loadoutNames} | ||
getOptionLabel={(option) => option.name} | ||
renderInput={(params) => <TextField {...params} label="NAME" />} | ||
/> | ||
</Grid> | ||
<Grid item md={12}> | ||
<FormControl fullWidth> | ||
<InputLabel id="loadout-colors-label">COLOR</InputLabel> | ||
<Select | ||
labelId="loadout-colors-label" | ||
id="loadout-colors" | ||
label="COLOR" | ||
value={loadoutColor} | ||
renderValue={(selected) => <img src={selected?.imagePath} width="20%" height="auto" />} | ||
> | ||
<ImageList cols={4}> | ||
{loadoutIdentifiers.loadoutColors.map((color) => ( | ||
<img | ||
src={color.imagePath} | ||
width="60%" | ||
height="auto" | ||
onClick={() => setLoadoutColor(color)} | ||
/> | ||
))} | ||
</ImageList> | ||
</Select> | ||
</FormControl> | ||
</Grid> | ||
<Grid item md={12}> | ||
<FormControl fullWidth> | ||
<InputLabel id="loadout-icons-label">ICON</InputLabel> | ||
<Select | ||
labelId="loadout-icons-label" | ||
id="loadout-icons" | ||
label="ICON" | ||
value={loadoutIcon} | ||
renderValue={(selected) => <img src={selected?.imagePath} width="20%" height="auto" />} | ||
> | ||
<ImageList cols={4}> | ||
{loadoutIdentifiers.loadoutIcons.map((icon) => ( | ||
<img | ||
src={icon.imagePath} | ||
width="60%" | ||
height="auto" | ||
onClick={() => setLoadoutIcon(icon)} | ||
/> | ||
))} | ||
</ImageList> | ||
</Select> | ||
</FormControl> | ||
</Grid> | ||
<Grid item md={6}> | ||
<Button onClick={handleBackClick}>BACK</Button> | ||
</Grid> | ||
<Grid item md={6}> | ||
<Button | ||
disabled={loadoutName === null && loadoutColor === null && loadoutIcon === null} | ||
onClick={() => setIdentifiersSet(true)} | ||
> | ||
NEXT | ||
</Button> | ||
</Grid> | ||
</Grid> | ||
); | ||
|
||
const SelectLoadoutSlotDrawer = ( | ||
<Grid container alignItems="center" textAlign="center" rowGap={2} paddingX={4} paddingY={3}> | ||
<Grid item md={12}> | ||
SELECT SLOT TO OVERWRITE | ||
</Grid> | ||
{loadouts?.map((loadout, index) => ( | ||
<Grid item md={6}> | ||
<LoadoutSlot | ||
onClick={async () => { | ||
const characterId = store.getState().profile.selectedCharacter?.id; | ||
|
||
if (characterId && loadoutColor && loadoutIcon && loadoutName) | ||
await snapShotLoadoutRequest( | ||
String(characterId), | ||
loadoutColor?.hash, | ||
loadoutIcon?.hash, | ||
index, | ||
loadoutName?.hash | ||
); | ||
|
||
setIdentifiersSet(false); | ||
setLoadoutDrawerOpen(false); | ||
}} | ||
src={ | ||
loadoutIdentifiers.loadoutIcons.find((icon) => icon.hash === loadout.iconHash) | ||
?.imagePath | ||
} | ||
style={{ | ||
backgroundImage: `url(${ | ||
loadoutIdentifiers.loadoutColors.find((color) => color.hash === loadout.colorHash) | ||
?.imagePath | ||
})`, | ||
}} | ||
/> | ||
</Grid> | ||
))} | ||
<Grid item md={6}> | ||
<Button onClick={() => setIdentifiersSet(false)}>BACK</Button> | ||
</Grid> | ||
</Grid> | ||
); | ||
|
||
return ( | ||
<> | ||
<Button onClick={() => setLoadoutDrawerOpen(true)}>SAVE IN-GAME</Button> | ||
<Drawer open={loadoutDrawerOpen} anchor="right"> | ||
<Box sx={{ width: '24vw' }}> | ||
{identifiersSet ? SelectLoadoutSlotDrawer : SetIdentifiersDrawer} | ||
</Box> | ||
</Drawer> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { db } from '../../../store/db'; | ||
import { | ||
ManifestLoadoutColor, | ||
ManifestLoadoutIcon, | ||
ManifestLoadoutName, | ||
} from '../../../types/manifest-types'; | ||
|
||
export default function useLoadoutIdentifiers() { | ||
const [loadoutColors, setLoadoutColors] = useState<ManifestLoadoutColor[]>([]); | ||
const [loadoutNames, setLoadoutNames] = useState<ManifestLoadoutName[]>([]); | ||
const [loadoutIcons, setLoadoutIcons] = useState<ManifestLoadoutIcon[]>([]); | ||
|
||
useEffect(() => { | ||
const gatherIdentifiers = async () => { | ||
setLoadoutColors(await db.manifestLoadoutColorDef.toArray()); | ||
setLoadoutIcons(await db.manifestLoadoutIconDef.toArray()); | ||
setLoadoutNames(await db.manifestLoadoutNameDef.toArray()); | ||
}; | ||
gatherIdentifiers().catch(console.error); | ||
}, []); | ||
|
||
return { loadoutNames, loadoutColors, loadoutIcons }; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/features/loadouts/hooks/use-selected-character-loadouts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { DestinyLoadout } from '../../../types/d2l-types'; | ||
import { store } from '../../../store'; | ||
|
||
export default function useSelectedCharacterLoadouts() { | ||
const [loadouts, setLoadouts] = useState<DestinyLoadout[] | undefined>(undefined); | ||
|
||
useEffect(() => { | ||
setLoadouts(store.getState().profile.selectedCharacter?.loadouts); | ||
}, []); | ||
|
||
return loadouts; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.