From 48ee1a065debde5027fc17e49144d348258dc5e4 Mon Sep 17 00:00:00 2001 From: notoraptor Date: Thu, 25 Jul 2019 10:59:36 -0400 Subject: [Web] Added game creation interface - Replaced fancybox with react-confirm-alert + dialog box - Removed unused code - Default map can be selected with 1-click - Added ability to select map variants --- diplomacy/web/src/gui/components/fancyBox.js | 47 +++++++++ diplomacy/web/src/gui/components/fancybox.jsx | 59 ----------- diplomacy/web/src/gui/components/help.jsx | 30 ++++-- diplomacy/web/src/gui/components/navigation.jsx | 2 +- diplomacy/web/src/gui/forms/create_form.jsx | 95 ----------------- .../web/src/gui/forms/select_location_form.jsx | 19 ++-- diplomacy/web/src/gui/forms/select_via_form.jsx | 16 ++- diplomacy/web/src/gui/pages/content_game.jsx | 74 +++++--------- diplomacy/web/src/gui/pages/content_games.jsx | 53 +++++----- diplomacy/web/src/gui/pages/page.jsx | 33 +++--- .../gui/wizards/gameCreation/gameCreationWizard.js | 109 ++++++++++++++++++++ .../web/src/gui/wizards/gameCreation/mapList.js | 41 ++++++++ .../src/gui/wizards/gameCreation/panelChooseMap.js | 94 +++++++++++++++++ .../gui/wizards/gameCreation/panelChoosePlayers.js | 61 +++++++++++ .../gui/wizards/gameCreation/panelChoosePower.js | 62 +++++++++++ .../wizards/gameCreation/panelChooseSettings.js | 113 +++++++++++++++++++++ .../web/src/gui/wizards/gameCreation/panelList.js | 6 ++ 17 files changed, 648 insertions(+), 266 deletions(-) create mode 100644 diplomacy/web/src/gui/components/fancyBox.js delete mode 100644 diplomacy/web/src/gui/components/fancybox.jsx delete mode 100644 diplomacy/web/src/gui/forms/create_form.jsx create mode 100644 diplomacy/web/src/gui/wizards/gameCreation/gameCreationWizard.js create mode 100644 diplomacy/web/src/gui/wizards/gameCreation/mapList.js create mode 100644 diplomacy/web/src/gui/wizards/gameCreation/panelChooseMap.js create mode 100644 diplomacy/web/src/gui/wizards/gameCreation/panelChoosePlayers.js create mode 100644 diplomacy/web/src/gui/wizards/gameCreation/panelChoosePower.js create mode 100644 diplomacy/web/src/gui/wizards/gameCreation/panelChooseSettings.js create mode 100644 diplomacy/web/src/gui/wizards/gameCreation/panelList.js (limited to 'diplomacy/web/src/gui') diff --git a/diplomacy/web/src/gui/components/fancyBox.js b/diplomacy/web/src/gui/components/fancyBox.js new file mode 100644 index 0000000..1e8c07c --- /dev/null +++ b/diplomacy/web/src/gui/components/fancyBox.js @@ -0,0 +1,47 @@ +// ============================================================================== +// Copyright (C) 2019 - Philip Paquette, Steven Bocco +// +// This program is free software: you can redistribute it and/or modify it under +// the terms of the GNU Affero General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) any +// later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +// details. +// +// You should have received a copy of the GNU Affero General Public License along +// with this program. If not, see . +// ============================================================================== +import React from 'react'; +import PropTypes from 'prop-types'; +import {Button} from "./button"; + +const TIMES = '\u00D7'; + +export class FancyBox extends React.Component { + render() { + return ( +
+
+
{this.props.title}
+
+
+
+
+
{this.props.children}
+
+
+ ); + } +} + + +FancyBox.propTypes = { + title: PropTypes.string.isRequired, + onClose: PropTypes.func.isRequired, + children: PropTypes.any.isRequired +}; diff --git a/diplomacy/web/src/gui/components/fancybox.jsx b/diplomacy/web/src/gui/components/fancybox.jsx deleted file mode 100644 index 66a1efe..0000000 --- a/diplomacy/web/src/gui/components/fancybox.jsx +++ /dev/null @@ -1,59 +0,0 @@ -// ============================================================================== -// Copyright (C) 2019 - Philip Paquette, Steven Bocco -// -// This program is free software: you can redistribute it and/or modify it under -// the terms of the GNU Affero General Public License as published by the Free -// Software Foundation, either version 3 of the License, or (at your option) any -// later version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -// details. -// -// You should have received a copy of the GNU Affero General Public License along -// with this program. If not, see . -// ============================================================================== -import React from 'react'; -import PropTypes from 'prop-types'; -import {Button} from "./button"; - -const TIMES = '\u00D7'; - -export class FancyBox extends React.Component { - // open-tag () - // PROPERTIES - // title - // onClose - render() { - return ( -
-
{ - if (!event) - event = window.event; - if (event.hasOwnProperty('cancelBubble')) - event.cancelBubble = true; - if (event.stopPropagation) - event.stopPropagation(); - }}> -
-
{this.props.title}
-
-
-
-
-
{this.props.children}
-
-
-
- ); - } -} - - -FancyBox.propTypes = { - title: PropTypes.string.isRequired, - onClose: PropTypes.func.isRequired, - children: PropTypes.oneOfType([PropTypes.array, PropTypes.object]) -}; diff --git a/diplomacy/web/src/gui/components/help.jsx b/diplomacy/web/src/gui/components/help.jsx index 1ec1a54..f3f469f 100644 --- a/diplomacy/web/src/gui/components/help.jsx +++ b/diplomacy/web/src/gui/components/help.jsx @@ -1,13 +1,23 @@ import React from "react"; +import PropTypes from 'prop-types'; +import {FancyBox} from "./fancyBox"; -export function Help() { - return ( -
-

When building an order, press ESC to reset build.

-

Press letter associated to an order type to start building an order of this type. -
Order type letter is indicated in order type name after order type radio button. -

-

In Phase History tab, use keyboard left and right arrows to navigate in past phases.

-
- ); +export class Help extends React.Component { + render() { + return ( + +
+

When building an order, press ESC to reset build.

+

Press letter associated to an order type to start building an order of this type. +
Order type letter is indicated in order type name after order type radio button. +

+

In Phase History tab, use keyboard left and right arrows to navigate in past phases.

+
+
+ ); + } } + +Help.propTypes = { + onClose: PropTypes.func.isRequired +}; diff --git a/diplomacy/web/src/gui/components/navigation.jsx b/diplomacy/web/src/gui/components/navigation.jsx index 5d961bc..051f8ea 100644 --- a/diplomacy/web/src/gui/components/navigation.jsx +++ b/diplomacy/web/src/gui/components/navigation.jsx @@ -1,5 +1,5 @@ import React from "react"; -import Octicon, {Person} from "@githubprimer/octicons-react"; +import Octicon, {Person} from "@primer/octicons-react"; import PropTypes from "prop-types"; export class Navigation extends React.Component { diff --git a/diplomacy/web/src/gui/forms/create_form.jsx b/diplomacy/web/src/gui/forms/create_form.jsx deleted file mode 100644 index 6753519..0000000 --- a/diplomacy/web/src/gui/forms/create_form.jsx +++ /dev/null @@ -1,95 +0,0 @@ -// ============================================================================== -// Copyright (C) 2019 - Philip Paquette, Steven Bocco -// -// This program is free software: you can redistribute it and/or modify it under -// the terms of the GNU Affero General Public License as published by the Free -// Software Foundation, either version 3 of the License, or (at your option) any -// later version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -// details. -// -// You should have received a copy of the GNU Affero General Public License along -// with this program. If not, see . -// ============================================================================== -import React from 'react'; -import {Forms} from "../components/forms"; -import {STRINGS} from "../../diplomacy/utils/strings"; -import PropTypes from "prop-types"; - -export class CreateForm extends React.Component { - constructor(props) { - super(props); - this.state = this.initState(); - } - - initState() { - const state = { - game_id: '', - power_name: '', - n_controls: 7, - deadline: 300, - registration_password: '' - }; - for (let rule of STRINGS.PUBLIC_RULES) - state[`rule_${rule.toLowerCase()}`] = false; - return state; - } - - render() { - const onChange = Forms.createOnChangeCallback(this, this.props.onChange); - const onSubmit = Forms.createOnSubmitCallback(this, this.props.onSubmit); - return ( -
- {Forms.createRow( - Forms.createColLabel('game_id', 'Game ID (optional)'), - - )} - {Forms.createRow( - Forms.createColLabel('power_name', 'power:'), - - )} - {Forms.createRow( - Forms.createColLabel('n_controls', 'number of required players:'), - - )} - {Forms.createRow( - Forms.createColLabel('deadline', 'deadline (in seconds)'), - - )} - {Forms.createRow( - Forms.createColLabel('registration_password', 'registration password'), - - )} -
RULES:
-
- {STRINGS.PUBLIC_RULES.map((rule, index) => ( -
- {Forms.createCheckbox( - `rule_${rule.toLowerCase()}`, - rule, - Forms.getValue(this.state, `rule_${rule.toLowerCase()}`), - onChange)} -
- ))} -
- {Forms.createRow('', Forms.createSubmit('create a game', true, onSubmit))} -
- ); - } -} - -CreateForm.propTypes = { - onChange: PropTypes.func, - onSubmit: PropTypes.func -}; diff --git a/diplomacy/web/src/gui/forms/select_location_form.jsx b/diplomacy/web/src/gui/forms/select_location_form.jsx index ca7be09..1725c9b 100644 --- a/diplomacy/web/src/gui/forms/select_location_form.jsx +++ b/diplomacy/web/src/gui/forms/select_location_form.jsx @@ -17,20 +17,27 @@ import React from "react"; import PropTypes from "prop-types"; import {Button} from "../components/button"; +import {FancyBox} from "../components/fancyBox"; export class SelectLocationForm extends React.Component { render() { + const title = `Select location to continue building order: ${this.props.path.join(' ')}`; return ( -
- {this.props.locations.map((location, index) => ( -
+ +
+ {this.props.locations.map((location, index) => ( +
+
); } } SelectLocationForm.propTypes = { locations: PropTypes.arrayOf(PropTypes.string).isRequired, - onSelect: PropTypes.func.isRequired // onSelect(location) + onSelect: PropTypes.func.isRequired, // onSelect(location) + onClose: PropTypes.func.isRequired, + path: PropTypes.array.isRequired }; diff --git a/diplomacy/web/src/gui/forms/select_via_form.jsx b/diplomacy/web/src/gui/forms/select_via_form.jsx index b779b8d..8b340af 100644 --- a/diplomacy/web/src/gui/forms/select_via_form.jsx +++ b/diplomacy/web/src/gui/forms/select_via_form.jsx @@ -17,19 +17,25 @@ import React from "react"; import PropTypes from "prop-types"; import {Button} from "../components/button"; +import {FancyBox} from "../components/fancyBox"; export class SelectViaForm extends React.Component { render() { return ( -
-
+ +
+
+
); } } SelectViaForm.propTypes = { - onSelect: PropTypes.func.isRequired + path: PropTypes.array.isRequired, + onSelect: PropTypes.func.isRequired, + onClose: PropTypes.func.isRequired }; diff --git a/diplomacy/web/src/gui/pages/content_game.jsx b/diplomacy/web/src/gui/pages/content_game.jsx index f37bdca..457d901 100644 --- a/diplomacy/web/src/gui/pages/content_game.jsx +++ b/diplomacy/web/src/gui/pages/content_game.jsx @@ -33,7 +33,6 @@ import {STRINGS} from "../../diplomacy/utils/strings"; import {Diplog} from "../../diplomacy/utils/diplog"; import {Table} from "../components/table"; import {PowerView} from "../utils/power_view"; -import {FancyBox} from "../components/fancybox"; import {DipStorage} from "../utils/dipStorage"; import Helmet from 'react-helmet'; import {Navigation} from "../components/navigation"; @@ -116,14 +115,11 @@ export class ContentGame extends React.Component { orders: orders, // {power name => {loc => {local: bool, order: str}}} power: null, orderBuildingType: null, - orderBuildingPath: [], - fancy_title: null, - fancy_function: null, - on_fancy_close: null, + orderBuildingPath: [] }; // Bind some class methods to this instance. - this.closeFancyBox = this.closeFancyBox.bind(this); + this.clearOrderBuildingPath = this.clearOrderBuildingPath.bind(this); this.displayFirstPastPhase = this.displayFirstPastPhase.bind(this); this.displayLastPastPhase = this.displayLastPastPhase.bind(this); this.displayLocationOrders = this.displayLocationOrders.bind(this); @@ -202,11 +198,8 @@ export class ContentGame extends React.Component { return this.context; } - closeFancyBox() { + clearOrderBuildingPath() { this.setState({ - fancy_title: null, - fancy_function: null, - on_fancy_close: null, orderBuildingPath: [] }); } @@ -220,11 +213,6 @@ export class ContentGame extends React.Component { powerName, orderType, orderPath, location, this.onOrderBuilding, this.onOrderBuilt, this.getPage().error ); - this.setState({ - fancy_title: null, - fancy_function: null, - on_fancy_close: null - }); } setSelectedVia(moveType, powerName, orderPath, location) { @@ -234,33 +222,35 @@ export class ContentGame extends React.Component { powerName, moveType, orderPath, location, this.onOrderBuilding, this.onOrderBuilt, this.getPage().error ); - this.setState({ - fancy_title: null, - fancy_function: null, - on_fancy_close: null - }); } onSelectLocation(possibleLocations, powerName, orderType, orderPath) { - const title = `Select location to continue building order: ${orderPath.join(' ')} ... (press ESC or close button to cancel building)`; - const func = () => ( this.setSelectedLocation(location, powerName, orderType, orderPath)}/>); - this.setState({ - fancy_title: title, - fancy_function: func, - on_fancy_close: this.closeFancyBox - }); + this.getPage().dialog(onClose => ( + { + this.setSelectedLocation(location, powerName, orderType, orderPath); + onClose(); + }} + onClose={() => { + this.clearOrderBuildingPath(); + onClose(); + }}/> + )); } onSelectVia(location, powerName, orderPath) { - const title = `Select move type for move order: ${orderPath.join(' ')}`; - const func = () => ( - this.setSelectedVia(moveType, powerName, orderPath, location)}/>); - this.setState({ - fancy_title: title, - fancy_function: func, - on_fancy_close: this.closeFancyBox - }); + this.getPage().dialog(onClose => ( + { + this.setSelectedVia(moveType, powerName, orderPath, location); + onClose(); + }} + onClose={() => { + this.clearOrderBuildingPath(); + onClose(); + }}/> + )); } // ] @@ -682,9 +672,6 @@ export class ContentGame extends React.Component { onOrderBuilt(powerName, orderString) { const state = Object.assign({}, this.state); state.orderBuildingPath = []; - state.fancy_title = null; - state.fancy_function = null; - state.on_fancy_close = null; if (!orderString) { Diplog.warn('No order built.'); this.setState(state); @@ -712,9 +699,6 @@ export class ContentGame extends React.Component { this.setState({ orderBuildingType: form.order_type, orderBuildingPath: [], - fancy_title: null, - fancy_function: null, - on_fancy_close: null }); } @@ -1162,7 +1146,7 @@ export class ContentGame extends React.Component { const engine = this.props.data; const title = ContentGame.gameTitle(engine); const navigation = [ - ['Help', () => page.loadFancyBox('Help', () => )], + ['Help', () => page.dialog(onClose => )], ['Load a game from disk', page.loadGameFromDisk], ['Save game to disk', () => saveGameToDisk(engine, page.error)], [`${UTILS.html.UNICODE_SMALL_LEFT_ARROW} Games`, () => page.loadGames()], @@ -1292,10 +1276,6 @@ export class ContentGame extends React.Component { currentTabOrderCreation )) || ''} - {this.state.fancy_title && ( - - {this.state.fancy_function()} - )} ); } diff --git a/diplomacy/web/src/gui/pages/content_games.jsx b/diplomacy/web/src/gui/pages/content_games.jsx index 31bd1af..5250f03 100644 --- a/diplomacy/web/src/gui/pages/content_games.jsx +++ b/diplomacy/web/src/gui/pages/content_games.jsx @@ -18,15 +18,15 @@ import React from "react"; import {Tabs} from "../components/tabs"; import {Table} from "../components/table"; import {FindForm} from "../forms/find_form"; -import {CreateForm} from "../forms/create_form"; import {InlineGameView} from "../utils/inline_game_view"; -import {STRINGS} from "../../diplomacy/utils/strings"; import {Helmet} from "react-helmet"; import {Navigation} from "../components/navigation"; import {PageContext} from "../components/page_context"; import {ContentGame} from "./content_game"; import PropTypes from 'prop-types'; import {Tab} from "../components/tab"; +import {GameCreationWizard} from "../wizards/gameCreation/gameCreationWizard"; +import {Diplog} from "../../diplomacy/utils/diplog"; const TABLE_LOCAL_GAMES = { game_id: ['Game ID', 0], @@ -71,23 +71,6 @@ export class ContentGames extends React.Component { } onCreate(form) { - for (let key of Object.keys(form)) { - if (form[key] === '') - form[key] = null; - } - if (form.n_controls !== null) - form.n_controls = parseInt(form.n_controls, 10); - if (form.deadline !== null) - form.deadline = parseInt(form.deadline, 10); - form.rules = ['POWER_CHOICE']; - for (let rule of STRINGS.PUBLIC_RULES) { - const rule_id = `rule_${rule.toLowerCase()}`; - if (form.hasOwnProperty(rule_id)) { - if (form[rule_id]) - form.rules.push(rule); - delete form[rule_id]; - } - } let networkGame = null; this.getPage().channel.createGame(form) .then((game) => { @@ -116,6 +99,28 @@ export class ContentGames extends React.Component { return new InlineGameView(this.getPage(), gameData); } + gameCreationButton() { + return ( + + ); + } + render() { const title = 'Games'; const page = this.getPage(); @@ -133,14 +138,10 @@ export class ContentGames extends React.Component { {title} | Diplomacy - - + - {tab === 'create' ? ( - - - - ) : ''} {tab === 'find' ? ( diff --git a/diplomacy/web/src/gui/pages/page.jsx b/diplomacy/web/src/gui/pages/page.jsx index cd36f6c..a9ff9ac 100644 --- a/diplomacy/web/src/gui/pages/page.jsx +++ b/diplomacy/web/src/gui/pages/page.jsx @@ -20,12 +20,13 @@ import React from "react"; import {ContentConnection} from "./content_connection"; import {UTILS} from "../../diplomacy/utils/utils"; import {Diplog} from "../../diplomacy/utils/diplog"; -import {FancyBox} from "../components/fancybox"; import {DipStorage} from "../utils/dipStorage"; import {PageContext} from "../components/page_context"; import {ContentGames} from "./content_games"; import {loadGameFromDisk} from "../utils/load_game_from_disk"; import {ContentGame} from "./content_game"; +import {confirmAlert} from 'react-confirm-alert'; +import 'react-confirm-alert/src/react-confirm-alert.css'; export class Page extends React.Component { @@ -35,9 +36,6 @@ export class Page extends React.Component { this.channel = null; this.availableMaps = null; this.state = { - // fancybox, - fancyTitle: null, - onFancyBox: null, // Page messages error: null, info: null, @@ -54,7 +52,6 @@ export class Page extends React.Component { this.success = this.success.bind(this); this.logout = this.logout.bind(this); this.loadGameFromDisk = this.loadGameFromDisk.bind(this); - this.unloadFancyBox = this.unloadFancyBox.bind(this); this._post_remove = this._post_remove.bind(this); this._add_to_my_games = this._add_to_my_games.bind(this); this._remove_from_my_games = this._remove_from_my_games.bind(this); @@ -80,14 +77,22 @@ export class Page extends React.Component { this.__disconnect(error); } - //// Methods to load a global fancybox. + /** + * @callback OnClose + */ - loadFancyBox(title, callback) { - this.setState({fancyTitle: title, onFancyBox: callback}); - } + /** + * @callback DialogBuilder + * @param {OnClose} onClose + */ - unloadFancyBox() { - this.setState({fancyTitle: null, onFancyBox: null}); + /** + * open a dialog box + * @param {DialogBuilder} builder - a callback to generate dialog GUI. Will be executed with a `onClose` callback + * parameter to call when dialog must be closed: `builder(onClose)`. + */ + dialog(builder) { + confirmAlert({customUI: ({onClose}) => builder(onClose)}); } //// Methods to load a page. @@ -275,7 +280,6 @@ export class Page extends React.Component { } } - disconnectGame(gameID) { const game = this.getGame(gameID); if (game) { @@ -363,11 +367,6 @@ export class Page extends React.Component { {this.state.body || Page.defaultPage()} - {this.state.onFancyBox && ( - - {this.state.onFancyBox()} - - )} ); diff --git a/diplomacy/web/src/gui/wizards/gameCreation/gameCreationWizard.js b/diplomacy/web/src/gui/wizards/gameCreation/gameCreationWizard.js new file mode 100644 index 0000000..daaa461 --- /dev/null +++ b/diplomacy/web/src/gui/wizards/gameCreation/gameCreationWizard.js @@ -0,0 +1,109 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import {Panels} from "./panelList"; +import {PanelChooseMap} from "./panelChooseMap"; +import {PanelChoosePlayers} from "./panelChoosePlayers"; +import {PanelChoosePower} from "./panelChoosePower"; +import {PanelChooseSettings} from "./panelChooseSettings"; +import {Maps} from "./mapList"; +import {UTILS} from "../../../diplomacy/utils/utils"; + +export class GameCreationWizard extends React.Component { + constructor(props) { + super(props); + this.state = { + panel: Panels.CHOOSE_MAP, + game_id: UTILS.createGameID(this.props.username), + power_name: null, + n_controls: -1, + deadline: 0, + registration_password: '', + + map: Maps[0], + no_press: false + }; + this.backward = this.backward.bind(this); + this.forward = this.forward.bind(this); + this.updateParams = this.updateParams.bind(this); + } + + updateParams(params) { + this.setState(params); + } + + goToPanel(panelID) { + if (panelID < Panels.CHOOSE_MAP) + this.props.onCancel(); + else if (panelID > Panels.CHOOSE_SETTINGS) { + const rules = ['POWER_CHOICE']; + if (this.state.no_press) + rules.push('NO_PRESS'); + if (!this.state.deadline) { + rules.push('NO_DEADLINE'); + rules.push('REAL_TIME'); + } + this.props.onSubmit({ + game_id: this.state.game_id, + map_name: this.state.map.name, + power_name: this.state.power_name, + n_controls: this.state.n_controls, + deadline: this.state.deadline, + registration_password: this.state.registration_password || null, + rules: rules + }); + } else + this.setState({panel: panelID, registration_password: ''}); + } + + backward(step) { + this.goToPanel(this.state.panel - (step ? step : 1)); + } + + forward(step) { + this.goToPanel(this.state.panel + (step ? step : 1)); + } + + renderPanel() { + switch (this.state.panel) { + case Panels.CHOOSE_MAP: + return ; + case Panels.CHOOSE_PLAYERS: + return ; + case Panels.CHOOSE_POWER: + return ; + case Panels.CHOOSE_SETTINGS: + return ; + default: + return ''; + } + } + + render() { + return ( +
{this.renderPanel()}
+ ); + } +} + +GameCreationWizard.propTypes = { + onCancel: PropTypes.func.isRequired, + onSubmit: PropTypes.func.isRequired, + availableMaps: PropTypes.object.isRequired, + username: PropTypes.string.isRequired +}; diff --git a/diplomacy/web/src/gui/wizards/gameCreation/mapList.js b/diplomacy/web/src/gui/wizards/gameCreation/mapList.js new file mode 100644 index 0000000..5d2c00a --- /dev/null +++ b/diplomacy/web/src/gui/wizards/gameCreation/mapList.js @@ -0,0 +1,41 @@ +class VariantInfo { + constructor(variantName, variantTitle) { + this.name = variantName; + this.title = variantTitle; + this.map = null; + } + + svgName() { + return this.map.name; + } +} + +class MapInfo { + constructor(mapName, mapTitle, variants) { + this.name = mapName; + this.title = mapTitle; + this.variants = null; + if (variants) { + this.variants = []; + for (let variant of variants) { + variant.map = this; + this.variants.push(variant); + } + } + } + + svgName() { + return this.name; + } +} + +export const Maps = [ + new MapInfo('standard', 'Standard', [ + new VariantInfo('standard', 'Default'), + new VariantInfo('standard_age_of_empires', 'Age of empires'), + new VariantInfo('standard_age_of_empires_2', 'Age of empires II'), + new VariantInfo('standard_fleet_rome', 'Fleet at Rome'), + new VariantInfo('standard_france_austria', 'France VS Austria'), + new VariantInfo('standard_germany_italy', 'Germany VS Italy') + ]), +]; diff --git a/diplomacy/web/src/gui/wizards/gameCreation/panelChooseMap.js b/diplomacy/web/src/gui/wizards/gameCreation/panelChooseMap.js new file mode 100644 index 0000000..5c40f1c --- /dev/null +++ b/diplomacy/web/src/gui/wizards/gameCreation/panelChooseMap.js @@ -0,0 +1,94 @@ +import React from "react"; +import {Maps} from "./mapList"; +import {FancyBox} from "../../components/fancyBox"; +import PropTypes from "prop-types"; + +export class PanelChooseMap extends React.Component { + render() { + const mapImg = require(`../../../maps/svg/${this.props.params.map.svgName()}.svg`); + const mapEntries = []; + let count = 0; + for (let mapInfo of Maps) { + ++count; + if (!mapInfo.variants) { + mapEntries.push( +
+ +
+ ); + } else { + const dropDownID = `collapse-${count}-${mapInfo.name}`; + const variants = mapInfo.variants.slice(); + const defaultVariant = variants[0]; + mapEntries.push( +
+
+ + +
+
+
+ {(() => { + const views = []; + for (let i = 1; i < variants.length; ++i) { + const variantInfo = variants[i]; + views.push( +
+ +
+ ); + } + return views; + })()} +
+
+
+ ); + } + } + return ( + +
+
+
+ {mapEntries} +
+
+
+ {this.props.params.map.title}/ +
+
+
+ ); + } +} + +PanelChooseMap.propTypes = { + forward: PropTypes.func.isRequired, + cancel: PropTypes.func.isRequired, + params: PropTypes.object.isRequired, + onUpdateParams: PropTypes.func.isRequired +}; diff --git a/diplomacy/web/src/gui/wizards/gameCreation/panelChoosePlayers.js b/diplomacy/web/src/gui/wizards/gameCreation/panelChoosePlayers.js new file mode 100644 index 0000000..84a47a0 --- /dev/null +++ b/diplomacy/web/src/gui/wizards/gameCreation/panelChoosePlayers.js @@ -0,0 +1,61 @@ +import React from "react"; +import {FancyBox} from "../../components/fancyBox"; +import PropTypes from "prop-types"; +import Octicon, {ArrowLeft} from "@primer/octicons-react"; + +export class PanelChoosePlayers extends React.Component { + render() { + return ( + +
+
+ +
+
+ +
+
+
+ {(() => { + const choice = []; + for (let i = 0; i < this.props.nbPowers; ++i) { + choice.push( + + ); + } + return choice; + })()} +
+
+ +
+
+ ); + } +} + +PanelChoosePlayers.propTypes = { + backward: PropTypes.func.isRequired, + forward: PropTypes.func.isRequired, + cancel: PropTypes.func.isRequired, + onUpdateParams: PropTypes.func.isRequired, + nbPowers: PropTypes.number.isRequired +}; diff --git a/diplomacy/web/src/gui/wizards/gameCreation/panelChoosePower.js b/diplomacy/web/src/gui/wizards/gameCreation/panelChoosePower.js new file mode 100644 index 0000000..dc400bd --- /dev/null +++ b/diplomacy/web/src/gui/wizards/gameCreation/panelChoosePower.js @@ -0,0 +1,62 @@ +import React from "react"; +import {FancyBox} from "../../components/fancyBox"; +import PropTypes from "prop-types"; +import Octicon, {ArrowLeft} from "@primer/octicons-react"; + +export class PanelChoosePower extends React.Component { + render() { + return ( + +
+
+ +
+
+ +
+
+
+ {(() => { + const choice = []; + for (let i = 0; i < this.props.powers.length; ++i) { + choice.push( + + ); + } + return choice; + })()} +
+
+ +
+
+ ); + } +} + +PanelChoosePower.propTypes = { + backward: PropTypes.func.isRequired, + forward: PropTypes.func.isRequired, + cancel: PropTypes.func.isRequired, + onUpdateParams: PropTypes.func.isRequired, + powers: PropTypes.arrayOf(PropTypes.string).isRequired +}; diff --git a/diplomacy/web/src/gui/wizards/gameCreation/panelChooseSettings.js b/diplomacy/web/src/gui/wizards/gameCreation/panelChooseSettings.js new file mode 100644 index 0000000..e509158 --- /dev/null +++ b/diplomacy/web/src/gui/wizards/gameCreation/panelChooseSettings.js @@ -0,0 +1,113 @@ +import React from "react"; +import {FancyBox} from "../../components/fancyBox"; +import PropTypes from "prop-types"; +import {UTILS} from "../../../diplomacy/utils/utils"; +import Octicon, {ArrowLeft} from "@primer/octicons-react"; + +const DEADLINES = [ + [0, '(no deadline)'], + [60, '1 min'], + [60 * 5, '5 min'], + [60 * 30, '30 min'], + [60 * 60 * 2, '2 hrs'], + [60 * 60 * 24, '24 hrs'], +]; + +export class PanelChooseSettings extends React.Component { + constructor(props) { + super(props); + this.onCheckNoPress = this.onCheckNoPress.bind(this); + this.onSelectDeadline = this.onSelectDeadline.bind(this); + this.onSetRegistrationPassword = this.onSetRegistrationPassword.bind(this); + this.onSetGameID = this.onSetGameID.bind(this); + } + + onCheckNoPress(event) { + this.props.onUpdateParams({no_press: event.target.checked}); + } + + onSelectDeadline(event) { + this.props.onUpdateParams({deadline: parseInt(event.target.value)}); + } + + onSetRegistrationPassword(event) { + this.props.onUpdateParams({registration_password: event.target.value}); + } + + onSetGameID(event) { + let gameID = event.target.value; + if (!gameID) + gameID = UTILS.createGameID(this.props.username); + this.props.onUpdateParams({game_id: gameID}); + } + + render() { + return ( + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ + +
+
+
+
+
+ +
+
+ +
+
+
+ ); + } +} + +PanelChooseSettings.propTypes = { + backward: PropTypes.func.isRequired, + forward: PropTypes.func.isRequired, + cancel: PropTypes.func.isRequired, + params: PropTypes.object.isRequired, + onUpdateParams: PropTypes.func.isRequired, + username: PropTypes.string.isRequired +}; diff --git a/diplomacy/web/src/gui/wizards/gameCreation/panelList.js b/diplomacy/web/src/gui/wizards/gameCreation/panelList.js new file mode 100644 index 0000000..0b6100c --- /dev/null +++ b/diplomacy/web/src/gui/wizards/gameCreation/panelList.js @@ -0,0 +1,6 @@ +export const Panels = { + CHOOSE_MAP: 0, + CHOOSE_PLAYERS: 1, + CHOOSE_POWER: 2, + CHOOSE_SETTINGS: 3 +}; -- cgit v1.2.3