]> git.localhorst.tv Git - alttp.git/commitdiff
simple tracker config dialog
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 26 Mar 2024 14:44:39 +0000 (15:44 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 26 Mar 2024 14:44:39 +0000 (15:44 +0100)
resources/js/components/tracker/ConfigDialog.js [new file with mode: 0644]
resources/js/components/tracker/CountDisplay.js
resources/js/components/tracker/Dungeons.js
resources/js/components/tracker/Toolbar.js
resources/js/helpers/tracker.js
resources/js/i18n/de.js
resources/js/i18n/en.js
resources/sass/tracker.scss

diff --git a/resources/js/components/tracker/ConfigDialog.js b/resources/js/components/tracker/ConfigDialog.js
new file mode 100644 (file)
index 0000000..88c6d73
--- /dev/null
@@ -0,0 +1,180 @@
+import PropTypes from 'prop-types';
+import React from 'react';
+import { Col, Form, Modal, Row } from 'react-bootstrap';
+import { useTranslation } from 'react-i18next';
+
+import LargeCheck from '../common/LargeCheck';
+import { useTracker } from '../../hooks/tracker';
+
+const ConfigDialog = ({
+       onHide,
+       show,
+}) => {
+       const { config, saveConfig } = useTracker();
+       const { t } = useTranslation();
+
+       const handleChange = React.useCallback(({ target: { name, value } }) => {
+               saveConfig({ [name]: value });
+       }, [saveConfig]);
+
+       return <Modal className="tracker-config-dialog" onHide={onHide} show={show} size="lg">
+               <Modal.Header closeButton>
+                       <Modal.Title>
+                               {t('tracker.config.title')}
+                       </Modal.Title>
+               </Modal.Header>
+               <Modal.Body>
+                       <Row>
+                               <Col sm={6}>
+                                       <h3>{t('tracker.config.wildItems')}</h3>
+                                       <Form.Group
+                                               className="d-flex justify-content-between my-2"
+                                               controlId="tracker.wildMap"
+                                       >
+                                               <Form.Label>{t('tracker.config.wildMap')}</Form.Label>
+                                               <Form.Control
+                                                       as={LargeCheck}
+                                                       name="wildMap"
+                                                       onChange={handleChange}
+                                                       value={!!config.wildMap}
+                                               />
+                                       </Form.Group>
+                                       <Form.Group
+                                               className="d-flex justify-content-between my-2"
+                                               controlId="tracker.wildCompass"
+                                       >
+                                               <Form.Label>{t('tracker.config.wildCompass')}</Form.Label>
+                                               <Form.Control
+                                                       as={LargeCheck}
+                                                       name="wildCompass"
+                                                       onChange={handleChange}
+                                                       value={!!config.wildCompass}
+                                               />
+                                       </Form.Group>
+                                       <Form.Group
+                                               className="d-flex justify-content-between my-2"
+                                               controlId="tracker.wildSmall"
+                                       >
+                                               <Form.Label>{t('tracker.config.wildSmall')}</Form.Label>
+                                               <Form.Control
+                                                       as={LargeCheck}
+                                                       name="wildSmall"
+                                                       onChange={handleChange}
+                                                       value={!!config.wildSmall}
+                                               />
+                                       </Form.Group>
+                                       <Form.Group
+                                               className="d-flex justify-content-between my-2"
+                                               controlId="tracker.wildBig"
+                                       >
+                                               <Form.Label>{t('tracker.config.wildBig')}</Form.Label>
+                                               <Form.Control
+                                                       as={LargeCheck}
+                                                       name="wildBig"
+                                                       onChange={handleChange}
+                                                       value={!!config.wildBig}
+                                               />
+                                       </Form.Group>
+                               </Col>
+                               <Col sm={6}>
+                                       <h3>{t('tracker.config.showItems')}</h3>
+                                       <Form.Group
+                                               className="d-flex justify-content-between my-2"
+                                               controlId="tracker.showMap"
+                                       >
+                                               <Form.Label>{t('tracker.config.showMap')}</Form.Label>
+                                               <Form.Select
+                                                       className="w-auto"
+                                                       name="showMap"
+                                                       onChange={handleChange}
+                                                       value={config.showMap || 'always'}
+                                               >
+                                                       <option value="never">
+                                                               {t('tracker.config.showItemOptions.never')}
+                                                       </option>
+                                                       <option value="situational">
+                                                               {t('tracker.config.showItemOptions.situational')}
+                                                       </option>
+                                                       <option value="always">
+                                                               {t('tracker.config.showItemOptions.always')}
+                                                       </option>
+                                               </Form.Select>
+                                       </Form.Group>
+                                       <Form.Group
+                                               className="d-flex justify-content-between my-2"
+                                               controlId="tracker.showCompass"
+                                       >
+                                               <Form.Label>{t('tracker.config.showCompass')}</Form.Label>
+                                               <Form.Select
+                                                       className="w-auto"
+                                                       name="showCompass"
+                                                       onChange={handleChange}
+                                                       value={config.showCompass || 'always'}
+                                               >
+                                                       <option value="never">
+                                                               {t('tracker.config.showItemOptions.never')}
+                                                       </option>
+                                                       <option value="situational">
+                                                               {t('tracker.config.showItemOptions.situational')}
+                                                       </option>
+                                                       <option value="always">
+                                                               {t('tracker.config.showItemOptions.always')}
+                                                       </option>
+                                               </Form.Select>
+                                       </Form.Group>
+                                       <Form.Group
+                                               className="d-flex justify-content-between my-2"
+                                               controlId="tracker.showSmall"
+                                       >
+                                               <Form.Label>{t('tracker.config.showSmall')}</Form.Label>
+                                               <Form.Select
+                                                       className="w-auto"
+                                                       name="showSmall"
+                                                       onChange={handleChange}
+                                                       value={config.showSmall || 'always'}
+                                               >
+                                                       <option value="never">
+                                                               {t('tracker.config.showItemOptions.never')}
+                                                       </option>
+                                                       <option value="situational">
+                                                               {t('tracker.config.showItemOptions.situational')}
+                                                       </option>
+                                                       <option value="always">
+                                                               {t('tracker.config.showItemOptions.always')}
+                                                       </option>
+                                               </Form.Select>
+                                       </Form.Group>
+                                       <Form.Group
+                                               className="d-flex justify-content-between my-2"
+                                               controlId="tracker.showBig"
+                                       >
+                                               <Form.Label>{t('tracker.config.showBig')}</Form.Label>
+                                               <Form.Select
+                                                       className="w-auto"
+                                                       name="showBig"
+                                                       onChange={handleChange}
+                                                       value={config.showBig || 'always'}
+                                               >
+                                                       <option value="never">
+                                                               {t('tracker.config.showItemOptions.never')}
+                                                       </option>
+                                                       <option value="situational">
+                                                               {t('tracker.config.showItemOptions.situational')}
+                                                       </option>
+                                                       <option value="always">
+                                                               {t('tracker.config.showItemOptions.always')}
+                                                       </option>
+                                               </Form.Select>
+                                       </Form.Group>
+                               </Col>
+                       </Row>
+               </Modal.Body>
+       </Modal>;
+};
+
+ConfigDialog.propTypes = {
+       onHide: PropTypes.func,
+       show: PropTypes.bool,
+};
+
+export default ConfigDialog;
index ed9b91fc5efbd63955f67bc273d4aa88b246a358..8282422486c92059f574a70f7ea0715e2bf37f53 100644 (file)
@@ -1,7 +1,7 @@
 import PropTypes from 'prop-types';
 import React from 'react';
 
-const CountDisplay = ({ className, count }) => {
+const CountDisplay = ({ className, count, full }) => {
        const classNames = ['count-display'];
        if (className) {
                classNames.push(className);
@@ -9,6 +9,9 @@ const CountDisplay = ({ className, count }) => {
        if (!count) {
                classNames.push('is-zero');
        }
+       if (full && count >= full) {
+               classNames.push('is-full');
+       }
        return <span className={classNames.join(' ')}>
                {count}
        </span>;
@@ -17,6 +20,7 @@ const CountDisplay = ({ className, count }) => {
 CountDisplay.propTypes = {
        className: PropTypes.string,
        count: PropTypes.number,
+       full: PropTypes.number,
 };
 
 export default CountDisplay;
index 08a581f209a1428bbf12f0cf002239f14a0be28c..b997e754fb8c3b31b62c36b7c8e1ad40d5b33863 100644 (file)
@@ -5,35 +5,47 @@ import ToggleIcon from './ToggleIcon';
 import {
        getDungeonAcquiredSKs,
        getDungeonRemainingItems,
+       shouldShowDungeonItem,
 } from '../../helpers/tracker';
 import { useTracker } from '../../hooks/tracker';
 
 const Dungeons = () => {
-       const { dungeons, state } = useTracker();
+       const { config, dungeons, state } = useTracker();
 
        return <div className="dungeons">
                {dungeons.map(dungeon =>
                        <div className={`dungeon dungeon-${dungeon.id}`} key={dungeon.id}>
                                <span className="dungeon-tag">{dungeon.id.toUpperCase()}</span>
-                               <ToggleIcon
-                                       controller={ToggleIcon.dungeonController(dungeon)}
-                                       icons={['map']}
-                               />
-                               <ToggleIcon
-                                       controller={ToggleIcon.dungeonController(dungeon)}
-                                       icons={['compass']}
-                               />
-                               <span className="dungeon-smalls">
+                               {shouldShowDungeonItem(config, 'Map') ?
                                        <ToggleIcon
-                                               controller={ToggleIcon.dungeonCountController(dungeon, dungeon.sk)}
-                                               icons={['small-key']}
+                                               controller={ToggleIcon.dungeonController(dungeon)}
+                                               icons={['map']}
                                        />
-                                       <CountDisplay count={getDungeonAcquiredSKs(state, dungeon)} />
-                               </span>
-                               <ToggleIcon
-                                       controller={ToggleIcon.dungeonController(dungeon)}
-                                       icons={['big-key']}
-                               />
+                               : null}
+                               {shouldShowDungeonItem(config, 'Compass') ?
+                                       <ToggleIcon
+                                               controller={ToggleIcon.dungeonController(dungeon)}
+                                               icons={['compass']}
+                                       />
+                               : null}
+                               {shouldShowDungeonItem(config, 'Small') ?
+                                       <span className="dungeon-smalls">
+                                               <ToggleIcon
+                                                       controller={ToggleIcon.dungeonCountController(dungeon, dungeon.sk)}
+                                                       icons={['small-key']}
+                                               />
+                                               <CountDisplay
+                                                       count={getDungeonAcquiredSKs(state, dungeon)}
+                                                       full={dungeon.sk}
+                                               />
+                                       </span>
+                               : null}
+                               {shouldShowDungeonItem(config, 'Big') ?
+                                       <ToggleIcon
+                                               controller={ToggleIcon.dungeonController(dungeon)}
+                                               icons={['big-key']}
+                                       />
+                               : null}
                                <span className="dungeon-checks">
                                        <ToggleIcon
                                                controller={ToggleIcon.dungeonCheckController(dungeon)}
index c7545b3106c0898afe0ed8224a78fe7b91ce4c85..020826635a65a215fa89bf452c81d5af58734a61 100644 (file)
@@ -1,8 +1,10 @@
 import React from 'react';
-import { Container, Navbar } from 'react-bootstrap';
+import { Button, Container, Navbar } from 'react-bootstrap';
 
 import AutoTracking from './AutoTracking';
+import ConfigDialog from './ConfigDialog';
 import ToggleIcon from './ToggleIcon';
+import Icon from '../common/Icon';
 import { useTracker } from '../../hooks/tracker';
 
 const mapWild = {
@@ -13,6 +15,7 @@ const mapWild = {
 };
 
 const Toolbar = () => {
+       const [showConfigDialog, setShowConfigDialog] = React.useState(false);
        const { config, saveConfig } = useTracker();
 
        const controller = React.useMemo(() => ({
@@ -28,6 +31,13 @@ const Toolbar = () => {
        return <Navbar bg="dark" className="tracker-toolbar" variant="dark">
                <Container fluid>
                        <div className="button-bar">
+                               <Button
+                                       className="me-3"
+                                       onClick={() => setShowConfigDialog(true)}
+                                       variant="outline-secondary"
+                               >
+                                       <Icon.SETTINGS />
+                               </Button>
                                <ToggleIcon controller={controller} icons={['map']} />
                                <ToggleIcon controller={controller} icons={['compass']} />
                                <ToggleIcon controller={controller} icons={['small-key']} />
@@ -35,6 +45,7 @@ const Toolbar = () => {
                        </div>
                        <AutoTracking />
                </Container>
+               <ConfigDialog onHide={() => setShowConfigDialog(false)} show={showConfigDialog} />
        </Navbar>;
 };
 
index 2bc477bff1b632813829f7d4a3ee944d62e6fb57..e4b0ebe9f765a33d497ff2d994537a64168860ae 100644 (file)
@@ -68,6 +68,10 @@ export const BOSSES = [
 ];
 
 export const CONFIG = {
+       showMap: 'situational',
+       showCompass: 'situational',
+       showSmall: 'always',
+       showBig: 'always',
        wildMap: false,
        wildCompass: false,
        wildSmall: false,
@@ -1552,6 +1556,20 @@ export const UNDERWORLD_LOCATIONS = [
        },
 ];
 
+export const shouldShowDungeonItem = (config, which) => {
+       const show = config[`show${which}`] || 'always';
+       const wild = config[`wild${which}`] || false;
+       switch (show) {
+               default:
+               case 'always':
+                       return true;
+               case 'situational':
+                       return wild;
+               case 'never':
+                       return false;
+       }
+};
+
 export const toggleBoolean = name => state => ({
        ...state,
        [name]: !state[name],
index 7232e2d199bda91631b26172c26df45f063a53c3..87b6198469a421d2b6da332ea858f1a7274adb2e 100644 (file)
@@ -501,6 +501,24 @@ export default {
                        seeAlso: 'Siehe auch',
                },
                tracker: {
+                       config: {
+                               showBig: 'Big Keys',
+                               showCompass: 'Kompanden',
+                               showItemOptions: {
+                                       always: 'Immer',
+                                       never: 'Nie',
+                                       situational: 'Situationsbedingt',
+                               },
+                               showItems: 'Zeige Dungeon Items',
+                               showMap: 'Maps',
+                               showSmall: 'Small Keys',
+                               title: 'Konfiguration',
+                               wildBig: 'Big Keys',
+                               wildCompass: 'Kompanden',
+                               wildItems: 'Wild Dungeon Items',
+                               wildMap: 'Maps',
+                               wildSmall: 'Small Keys',
+                       },
                        location: {
                                aginah: 'Aginah',
                                blacksmith: 'Blacksmith',
index a76dd6c1cbb528d7cf22b2c861536f64cb2159d1..9ca7a6b9148a9fea5f0eeeec09c8504427133798 100644 (file)
@@ -501,6 +501,24 @@ export default {
                        seeAlso: 'See also',
                },
                tracker: {
+                       config: {
+                               showBig: 'Big Keys',
+                               showCompass: 'Compasses',
+                               showItemOptions: {
+                                       always: 'Always',
+                                       never: 'Never',
+                                       situational: 'Situational',
+                               },
+                               showItems: 'Show Dungeon Items',
+                               showMap: 'Maps',
+                               showSmall: 'Small Keys',
+                               title: 'Configuration',
+                               wildBig: 'Big Keys',
+                               wildCompass: 'Compasses',
+                               wildItems: 'Wild Dungeon Items',
+                               wildMap: 'Maps',
+                               wildSmall: 'Small Keys',
+                       },
                        location: {
                                aginah: 'Aginah',
                                blacksmith: 'Blacksmith',
index eae60c3586d0992746148feee5adababa5dc7cec..48575576a0fe879b8cc66519dd40fed12b537b91 100644 (file)
@@ -41,6 +41,9 @@
                                &.is-zero {
                                        display: none;
                                }
+                               &.is-full {
+                                       color: green;
+                               }
                        }
                }
        }