Skip to content

Commit

Permalink
[feature] Update disable states of buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
g3force committed Aug 25, 2018
1 parent d9f3d54 commit 49eafe3
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/components/GameState.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
{{state.stage}}
</span>
|
<span v-b-tooltip.hover title="Current command">
{{state.command}} <span v-if="state.commandForTeam !== ''">for {{state.commandForTeam}}</span>
</span>
|
<span v-format-ns-duration="state.stageTimeElapsed"
v-b-tooltip.hover
title="Total time elapsed in the current stage">
Expand All @@ -23,10 +27,6 @@
v-b-tooltip.hover
title="Total real time elapsed since the match has been started">
</span>
|
<span v-b-tooltip.hover title="Current command">
{{state.command}} <span v-if="state.commandForTeam !== ''">for {{state.commandForTeam}}</span>
</span>
</div>
</template>

Expand Down
19 changes: 13 additions & 6 deletions src/components/control/ControlGeneral.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
:title="'Robots have to keep distance to the ball (' + Object.keys(keymapStop)[0] + ')'">
<b-button v-hotkey="keymapStop"
v-on:click="send('stop')"
v-bind:disabled="stopped || !inNormalHalf">
v-bind:disabled="stopped || !stopAllowed">
Stop
</b-button>
</span>
<span v-b-tooltip.hover
:title="'Restart the game in draw situations (' + Object.keys(keymapForceStart)[0] + ')'">
<b-button v-hotkey="keymapForceStart"
v-on:click="send('forceStart')"
v-bind:disabled="!stopped || !inNormalHalf">
v-bind:disabled="!stopped || !forceStartAllowed">
Force Start
</b-button>
</span>
<span v-b-tooltip.hover
:title="'Continue game after a prepare state (' + Object.keys(keymapNormalStart)[0] + ')'">
<b-button v-hotkey="keymapNormalStart"
v-on:click="send('normalStart')"
v-bind:disabled="!prepareSth || !inNormalHalf">
v-bind:disabled="!prepareSth || !normalStartAllowed">
Normal Start
</b-button>
</span>
Expand All @@ -44,7 +44,7 @@
</template>

<script>
import {isInNormalHalf} from "../../main";
import {isNonPausedStage, isPreStage} from "../../refereeState";
export default {
name: "ControlGeneral",
Expand Down Expand Up @@ -84,8 +84,15 @@
prepareSth() {
return this.state.command === 'kickoff' || this.state.command === 'penalty';
},
inNormalHalf() {
return isInNormalHalf(this.state);
forceStartAllowed() {
return isNonPausedStage(this.state);
},
normalStartAllowed() {
return isNonPausedStage(this.state) || this.state.command === 'kickoff';
},
stopAllowed() {
return isNonPausedStage(this.$store.state.refBoxState)
|| isPreStage(this.$store.state.refBoxState);
},
gameEventPresent() {
return this.state.gameEvent !== 'none';
Expand Down
10 changes: 8 additions & 2 deletions src/components/control/ControlMatch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
</b-button>
<b-button v-b-tooltip.hover title="Change back to the previous stage (if something went wrong)"
v-on:click="previousStage"
:disabled="forbidMatchControls">
:disabled="forbidMatchControls || noPreviousStage">
Previous Stage
</b-button>
<b-button v-b-tooltip.hover title="Proceed to the next stage"
v-on:click="nextStage"
:disabled="forbidMatchControls">
:disabled="forbidMatchControls || noNextStage">
Next Stage
</b-button>
</div>
Expand Down Expand Up @@ -79,6 +79,12 @@
},
forbidMatchControls() {
return !this.stopped && !this.halted;
},
noPreviousStage() {
return this.state.stage === 'Pre-First Half';
},
noNextStage() {
return this.state.stage === 'End of Game';
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/components/control/ControlTeam.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
:title="'Perform direct kick (corner and goal kicks) (' + Object.keys(keymapDirect)[0] + ')'">
<b-button v-hotkey="keymapDirect"
v-on:click="send('direct')"
v-bind:disabled="halted || running || preparing">
v-bind:disabled="halted || running || preparing || !nonPausedStage">
Direct
</b-button>
</span>
<span v-b-tooltip.hover
:title="'Perform indirect kick (throw-in) (' + Object.keys(keymapIndirect)[0] + ')'">
<b-button v-hotkey="keymapIndirect"
v-on:click="send('indirect')"
v-bind:disabled="halted || running || preparing">
v-bind:disabled="halted || running || preparing || !nonPausedStage">
Indirect
</b-button>
</span>
<span v-b-tooltip.hover
title="Prepare for a penalty kick">
<b-button v-on:click="send('penalty')"
v-bind:disabled="halted || running || preparing">
v-bind:disabled="halted || running || preparing || !nonPausedStage">
Penalty
</b-button>
</span>
Expand All @@ -54,6 +54,7 @@

<script>
import ControlTeamTimeout from "./ControlTeamTimeout";
import {isNonPausedStage} from "../../refereeState";
export default {
name: "ControlTeam",
Expand Down Expand Up @@ -125,6 +126,9 @@
preparing() {
return this.state.command === 'kickoff' || this.state.command === 'penalty';
},
nonPausedStage() {
return isNonPausedStage(this.state);
},
}
}
</script>
Expand Down
9 changes: 5 additions & 4 deletions src/components/control/ControlTeamTimeout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<span>
<b-button v-show="!timeoutRunning"
v-on:click="startTimeout"
v-bind:disabled="!inNormalHalf">
v-bind:disabled="disableTimeoutButton">
Start Timeout
</b-button>
<b-button v-show="timeoutRunning"
Expand All @@ -13,7 +13,7 @@
</template>

<script>
import {isInNormalHalf} from "../../main";
import {isNonPausedStage, isPreStage} from "../../refereeState";
export default {
name: "ControlTeamTimeout",
Expand All @@ -27,8 +27,9 @@
timeoutRunning: function () {
return this.command === "timeout" && this.$store.state.refBoxState.commandForTeam === this.teamColor
},
inNormalHalf() {
return isInNormalHalf(this.$store.state.refBoxState);
disableTimeoutButton() {
return !isNonPausedStage(this.$store.state.refBoxState)
&& !isPreStage(this.$store.state.refBoxState);
},
},
methods: {
Expand Down
4 changes: 0 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ library.add(faCaretSquareDown);
library.add(faCaretSquareUp);
Vue.component('font-awesome-icon', FontAwesomeIcon);

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

let wsAddress;
if (process.env.NODE_ENV === 'development') {
// use the default backend port
Expand Down
15 changes: 15 additions & 0 deletions src/refereeState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export let isNonPausedStage = function (state) {
return state.stage === 'First Half'
|| state.stage === 'Second Half'
|| state.stage === 'Overtime First Half'
|| state.stage === 'Overtime Second Half'
|| state.stage === 'Shootout';
};

export let isPreStage = function (state) {
return state.stage === 'Pre-First Half'
|| state.stage === 'Pre-Second Half'
|| state.stage === 'Pre-Overtime First Half'
|| state.stage === 'Pre-Overtime Second Half'
|| state.stage === 'Shootout';
};

0 comments on commit 49eafe3

Please sign in to comment.