Skip to content

Commit

Permalink
[ui] Disable more buttons when they are not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
g3force committed Aug 6, 2018
1 parent 8d57067 commit d793cf8
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 16 deletions.
41 changes: 37 additions & 4 deletions ui/src/components/control/ControlGeneral.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
<template>
<span class="control-general">
<b-button v-hotkey="keymapHalt" v-on:click="send('halt')">Halt</b-button>
<b-button v-hotkey="keymapStop" v-on:click="send('stop')">Stop</b-button>
<b-button v-hotkey="keymapForceStart" v-on:click="send('forceStart')">Force Start</b-button>
<b-button v-hotkey="keymapNormalStart" v-on:click="send('normalStart')">Normal Start</b-button>
<b-button v-hotkey="keymapHalt"
v-on:click="send('halt')"
v-bind:disabled="halted">
Halt
</b-button>
<b-button v-hotkey="keymapStop"
v-on:click="send('stop')"
v-bind:disabled="stopped || !inNormalHalf">
Stop
</b-button>
<b-button v-hotkey="keymapForceStart"
v-on:click="send('forceStart')"
v-bind:disabled="!stopped || !inNormalHalf">
Force Start
</b-button>
<b-button v-hotkey="keymapNormalStart"
v-on:click="send('normalStart')"
v-bind:disabled="!prepareSth || !inNormalHalf">
Normal Start
</b-button>
</span>
</template>

<script>
import {isInNormalHalf} from "../../main";
export default {
name: "ControlGeneral",
methods: {
Expand All @@ -28,6 +46,21 @@
keymapNormalStart() {
return {'numpad +': () => this.send('normalStart')}
},
state() {
return this.$store.state.refBoxState
},
halted() {
return this.state.gameState === 'Halted';
},
stopped() {
return this.state.gameState === 'Stopped';
},
prepareSth() {
return this.state.gameState.startsWith('Prepare');
},
inNormalHalf() {
return isInNormalHalf(this.state);
},
}
}
</script>
Expand Down
51 changes: 43 additions & 8 deletions ui/src/components/control/ControlTeam.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
<template>
<div class="control-team">
<h2>Team {{teamColor}}</h2>
<b-button v-hotkey="keymapKickoff" v-on:click="send('kickoff')">Kickoff</b-button>
<b-button v-hotkey="keymapDirect" v-on:click="send('direct')">Direct</b-button>
<b-button v-hotkey="keymapIndirect" v-on:click="send('indirect')">Indirect</b-button>
<b-button v-on:click="send('penalty')">Penalty</b-button>
<b-button v-hotkey="keymapKickoff"
v-on:click="send('kickoff')"
v-bind:disabled="halted || running || preparing">
Kickoff
</b-button>
<b-button v-hotkey="keymapDirect"
v-on:click="send('direct')"
v-bind:disabled="halted || running || preparing">
Direct
</b-button>
<b-button v-hotkey="keymapIndirect"
v-on:click="send('indirect')"
v-bind:disabled="halted || running || preparing">
Indirect
</b-button>
<b-button v-on:click="send('penalty')"
v-bind:disabled="halted || running || preparing">
Penalty
</b-button>

<br/>

<ControlTeamTimeout :team-color="teamColor"/>
<b-button v-on:click="send('goal')">Goal</b-button>
<b-button v-on:click="addYellowCard" v-hotkey="keymapYellowCard">Yellow Card</b-button>
<b-button v-on:click="send('goal')">
Goal
</b-button>
<b-button v-on:click="addYellowCard"
v-hotkey="keymapYellowCard">
Yellow Card
</b-button>

<br/>

<b-button v-on:click="revokeYellowCard" v-if="teamState.yellowCardTimes.length>0">Revoke Yellow Card</b-button>
<b-button v-on:click="revokeYellowCard"
v-bind:disabled="teamState.yellowCardTimes.length===0">
Revoke Yellow Card
</b-button>
</div>
</template>

Expand Down Expand Up @@ -72,7 +95,19 @@
case 'Blue':
return {'numpad 6': this.addYellowCard};
}
}
},
state() {
return this.$store.state.refBoxState
},
halted() {
return this.state.gameState === 'Halted';
},
running() {
return this.state.gameState === 'Running';
},
preparing() {
return this.state.gameState.startsWith('Prepare');
},
}
}
</script>
Expand Down
20 changes: 16 additions & 4 deletions ui/src/components/control/ControlTeamTimeout.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<template>
<span>
<b-button v-show="!timeoutRunning" v-on:click="startTimeout">Start Timeout</b-button>
<b-button v-show="timeoutRunning" v-on:click="stopTimeout">Stop Timeout</b-button>
<b-button v-show="!timeoutRunning"
v-on:click="startTimeout"
v-bind:disabled="!inNormalHalf">
Start Timeout
</b-button>
<b-button v-show="timeoutRunning"
v-on:click="stopTimeout">
Stop Timeout
</b-button>
</span>
</template>

<script>
import {isInNormalHalf} from "../../main";
export default {
name: "ControlTeamTimeout",
props: {
Expand All @@ -17,15 +26,18 @@
},
timeoutRunning: function () {
return this.gameState === "Timeout" && this.$store.state.refBoxState.gameStateForTeam === this.teamColor
}
},
inNormalHalf() {
return isInNormalHalf(this.$store.state.refBoxState);
},
},
methods: {
startTimeout: function () {
this.$socket.sendObj({'command': {'commandType': 'timeout', 'forTeam': this.teamColor}})
},
stopTimeout: function () {
this.$socket.sendObj({'command': {'commandType': 'stop'}})
}
},
}
}
</script>
Expand Down
4 changes: 4 additions & 0 deletions ui/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export class RefBoxState {
teamState = {'Yellow': new TeamState(), 'Blue': new TeamState()};
}

export let isInNormalHalf = function (state) {
return state.stage === 'First Half';
};

Vue.use(TimestampFormatter);

// use Vuex for state management with the Vuex.Store
Expand Down

0 comments on commit d793cf8

Please sign in to comment.