Skip to content

Commit d793cf8

Browse files
committed
[ui] Disable more buttons when they are not allowed
1 parent 8d57067 commit d793cf8

File tree

4 files changed

+100
-16
lines changed

4 files changed

+100
-16
lines changed

ui/src/components/control/ControlGeneral.vue

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
<template>
22
<span class="control-general">
3-
<b-button v-hotkey="keymapHalt" v-on:click="send('halt')">Halt</b-button>
4-
<b-button v-hotkey="keymapStop" v-on:click="send('stop')">Stop</b-button>
5-
<b-button v-hotkey="keymapForceStart" v-on:click="send('forceStart')">Force Start</b-button>
6-
<b-button v-hotkey="keymapNormalStart" v-on:click="send('normalStart')">Normal Start</b-button>
3+
<b-button v-hotkey="keymapHalt"
4+
v-on:click="send('halt')"
5+
v-bind:disabled="halted">
6+
Halt
7+
</b-button>
8+
<b-button v-hotkey="keymapStop"
9+
v-on:click="send('stop')"
10+
v-bind:disabled="stopped || !inNormalHalf">
11+
Stop
12+
</b-button>
13+
<b-button v-hotkey="keymapForceStart"
14+
v-on:click="send('forceStart')"
15+
v-bind:disabled="!stopped || !inNormalHalf">
16+
Force Start
17+
</b-button>
18+
<b-button v-hotkey="keymapNormalStart"
19+
v-on:click="send('normalStart')"
20+
v-bind:disabled="!prepareSth || !inNormalHalf">
21+
Normal Start
22+
</b-button>
723
</span>
824
</template>
925

1026
<script>
27+
import {isInNormalHalf} from "../../main";
28+
1129
export default {
1230
name: "ControlGeneral",
1331
methods: {
@@ -28,6 +46,21 @@
2846
keymapNormalStart() {
2947
return {'numpad +': () => this.send('normalStart')}
3048
},
49+
state() {
50+
return this.$store.state.refBoxState
51+
},
52+
halted() {
53+
return this.state.gameState === 'Halted';
54+
},
55+
stopped() {
56+
return this.state.gameState === 'Stopped';
57+
},
58+
prepareSth() {
59+
return this.state.gameState.startsWith('Prepare');
60+
},
61+
inNormalHalf() {
62+
return isInNormalHalf(this.state);
63+
},
3164
}
3265
}
3366
</script>

ui/src/components/control/ControlTeam.vue

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
11
<template>
22
<div class="control-team">
33
<h2>Team {{teamColor}}</h2>
4-
<b-button v-hotkey="keymapKickoff" v-on:click="send('kickoff')">Kickoff</b-button>
5-
<b-button v-hotkey="keymapDirect" v-on:click="send('direct')">Direct</b-button>
6-
<b-button v-hotkey="keymapIndirect" v-on:click="send('indirect')">Indirect</b-button>
7-
<b-button v-on:click="send('penalty')">Penalty</b-button>
4+
<b-button v-hotkey="keymapKickoff"
5+
v-on:click="send('kickoff')"
6+
v-bind:disabled="halted || running || preparing">
7+
Kickoff
8+
</b-button>
9+
<b-button v-hotkey="keymapDirect"
10+
v-on:click="send('direct')"
11+
v-bind:disabled="halted || running || preparing">
12+
Direct
13+
</b-button>
14+
<b-button v-hotkey="keymapIndirect"
15+
v-on:click="send('indirect')"
16+
v-bind:disabled="halted || running || preparing">
17+
Indirect
18+
</b-button>
19+
<b-button v-on:click="send('penalty')"
20+
v-bind:disabled="halted || running || preparing">
21+
Penalty
22+
</b-button>
823

924
<br/>
1025

1126
<ControlTeamTimeout :team-color="teamColor"/>
12-
<b-button v-on:click="send('goal')">Goal</b-button>
13-
<b-button v-on:click="addYellowCard" v-hotkey="keymapYellowCard">Yellow Card</b-button>
27+
<b-button v-on:click="send('goal')">
28+
Goal
29+
</b-button>
30+
<b-button v-on:click="addYellowCard"
31+
v-hotkey="keymapYellowCard">
32+
Yellow Card
33+
</b-button>
1434

1535
<br/>
1636

17-
<b-button v-on:click="revokeYellowCard" v-if="teamState.yellowCardTimes.length>0">Revoke Yellow Card</b-button>
37+
<b-button v-on:click="revokeYellowCard"
38+
v-bind:disabled="teamState.yellowCardTimes.length===0">
39+
Revoke Yellow Card
40+
</b-button>
1841
</div>
1942
</template>
2043

@@ -72,7 +95,19 @@
7295
case 'Blue':
7396
return {'numpad 6': this.addYellowCard};
7497
}
75-
}
98+
},
99+
state() {
100+
return this.$store.state.refBoxState
101+
},
102+
halted() {
103+
return this.state.gameState === 'Halted';
104+
},
105+
running() {
106+
return this.state.gameState === 'Running';
107+
},
108+
preparing() {
109+
return this.state.gameState.startsWith('Prepare');
110+
},
76111
}
77112
}
78113
</script>

ui/src/components/control/ControlTeamTimeout.vue

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
<template>
22
<span>
3-
<b-button v-show="!timeoutRunning" v-on:click="startTimeout">Start Timeout</b-button>
4-
<b-button v-show="timeoutRunning" v-on:click="stopTimeout">Stop Timeout</b-button>
3+
<b-button v-show="!timeoutRunning"
4+
v-on:click="startTimeout"
5+
v-bind:disabled="!inNormalHalf">
6+
Start Timeout
7+
</b-button>
8+
<b-button v-show="timeoutRunning"
9+
v-on:click="stopTimeout">
10+
Stop Timeout
11+
</b-button>
512
</span>
613
</template>
714

815
<script>
16+
import {isInNormalHalf} from "../../main";
17+
918
export default {
1019
name: "ControlTeamTimeout",
1120
props: {
@@ -17,15 +26,18 @@
1726
},
1827
timeoutRunning: function () {
1928
return this.gameState === "Timeout" && this.$store.state.refBoxState.gameStateForTeam === this.teamColor
20-
}
29+
},
30+
inNormalHalf() {
31+
return isInNormalHalf(this.$store.state.refBoxState);
32+
},
2133
},
2234
methods: {
2335
startTimeout: function () {
2436
this.$socket.sendObj({'command': {'commandType': 'timeout', 'forTeam': this.teamColor}})
2537
},
2638
stopTimeout: function () {
2739
this.$socket.sendObj({'command': {'commandType': 'stop'}})
28-
}
40+
},
2941
}
3042
}
3143
</script>

ui/src/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export class RefBoxState {
3737
teamState = {'Yellow': new TeamState(), 'Blue': new TeamState()};
3838
}
3939

40+
export let isInNormalHalf = function (state) {
41+
return state.stage === 'First Half';
42+
};
43+
4044
Vue.use(TimestampFormatter);
4145

4246
// use Vuex for state management with the Vuex.Store

0 commit comments

Comments
 (0)