1 import React from 'react';
2 import { Button, Container, Form, Navbar } from 'react-bootstrap';
3 import { useTranslation } from 'react-i18next';
5 import AutoTracking from './AutoTracking';
6 import ConfigDialog from './ConfigDialog';
7 import ToggleIcon from './ToggleIcon';
8 import Icon from '../common/Icon';
9 import ZeldaIcon from '../common/ZeldaIcon';
10 import { getConfigValue } from '../../helpers/tracker';
11 import { useTracker } from '../../hooks/tracker';
15 compass: 'wildCompass',
16 'small-key': 'wildSmall',
20 const Toolbar = () => {
21 const [showConfigDialog, setShowConfigDialog] = React.useState(false);
22 const { config, saveConfig } = useTracker();
23 const { t } = useTranslation();
25 const handleConfigChange = React.useCallback(({ target: { name, value } }) => {
26 saveConfig({ [name]: value });
29 const bossController = React.useMemo(() => ({
30 getActive: (state, icons) => config.bossShuffle ? icons[0] : null,
31 getDefault: (state, icons) => icons[0],
32 handlePrimary: () => {
33 saveConfig({ bossShuffle: !config.bossShuffle});
35 handleSecondary: () => null,
36 }), [config, saveConfig]);
38 const wildController = React.useMemo(() => ({
39 getActive: (state, icons) => config[mapWild[icons[0]]] ? icons[0] : null,
40 getDefault: (state, icons) => icons[0],
41 handlePrimary: (state, setState, icons) => {
42 const prop = mapWild[icons[0]];
43 saveConfig({ [prop]: !config[prop] });
45 handleSecondary: () => null,
46 }), [config, saveConfig]);
48 const worldController = React.useMemo(() => ({
49 getActive: (state, icons) => config.worldState === 'inverted' ? icons[1] : icons[0],
50 getDefault: (state, icons) => icons[0],
51 handlePrimary: () => {
52 saveConfig({ worldState: config.worldState == 'inverted' ? 'open' : 'inverted' });
54 handleSecondary: () => null,
55 }), [config, saveConfig]);
57 return <Navbar bg="dark" className="tracker-toolbar" variant="dark">
59 <div className="button-bar">
62 onClick={() => setShowConfigDialog(true)}
63 title={t('button.settings')}
64 variant="outline-secondary"
66 <Icon.SETTINGS title="" />
69 controller={wildController}
71 title={t('tracker.config.shuffleMap')}
74 controller={wildController}
76 title={t('tracker.config.shuffleCompass')}
79 controller={wildController}
81 title={t('tracker.config.shuffleSmall')}
84 controller={wildController}
86 title={t('tracker.config.shuffleBig')}
90 controller={bossController}
92 title={t('tracker.config.bossShuffle')}
95 controller={worldController}
96 icons={['link-head', 'bunny-head']}
97 title={t('tracker.config.inverted')}
102 className="d-inline-flex align-items-center justify-content-between"
103 controlId="tracker.gtCrystals"
105 <Form.Label className="me-1">
106 <ZeldaIcon name="gt" title={t('tracker.config.gtCrystals')} />
109 className="w-auto bg-dark"
111 onChange={handleConfigChange}
112 value={getConfigValue(config, 'gt-crystals', 7)}
114 {['?', 0, 1, 2, 3, 4, 5, 6, 7].map(n =>
115 <option key={n} value={n}>
122 className="d-inline-flex align-items-center justify-content-between"
123 controlId="tracker.ganonCrystals"
125 <Form.Label className="me-1">
126 <ZeldaIcon name="ganon" title={t('tracker.config.ganonCrystals')} />
129 className="w-auto bg-dark"
130 name="ganon-crystals"
131 onChange={handleConfigChange}
132 value={getConfigValue(config, 'ganon-crystals', 7)}
134 {['?', 0, 1, 2, 3, 4, 5, 6, 7].map(n =>
135 <option key={n} value={n}>
142 className="d-inline-flex align-items-center justify-content-between"
143 controlId="tracker.goal"
145 <Form.Label className="me-1">
146 <ZeldaIcon name="triforce" title={t('tracker.config.goal')} />
149 className="w-auto bg-dark"
151 onChange={handleConfigChange}
152 value={getConfigValue(config, 'goal', 'ganon')}
154 {['ganon', 'fast', 'ad', 'ped', 'trinity', 'thunt', 'ghunt'].map(n =>
155 <option key={n} value={n}>
156 {t(`tracker.config.goals.${n}`)}
166 <ConfigDialog onHide={() => setShowConfigDialog(false)} show={showConfigDialog} />
170 export default Toolbar;