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 --- .../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 ++ 7 files changed, 486 insertions(+) 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/wizards/gameCreation') 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