Skip to content

Commit e53212e

Browse files
committed
lobby ready / cancel buttons, some fixes
1 parent 7d6309d commit e53212e

File tree

16 files changed

+282
-38
lines changed

16 files changed

+282
-38
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
return {
2+
3+
validate: (e) => {
4+
if (e.game.is_started()) {
5+
return 'Game has already started';
6+
}
7+
},
8+
9+
apply: (e) => {
10+
const player = e.game.get_player(e.caller);
11+
const was_ready = player.is_ready();
12+
if (was_ready != e.data.ready) {
13+
player.set_ready(e.data.ready);
14+
return {
15+
was_ready: was_ready,
16+
};
17+
}
18+
},
19+
20+
rollback: (e) => {
21+
const player = e.game.get_player(e.caller);
22+
if (player.is_ready() != e.applied.was_ready) {
23+
player.set_ready(e.applied.was_ready);
24+
}
25+
},
26+
27+
};

GLSMAC_data/default/game/events.gls.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ return (game) => {
77
'define_unit',
88
'game_settings',
99
'select_faction',
10+
'ready_or_not',
1011
'spawn_unit',
1112
'despawn_unit',
1213
'move_unit',

GLSMAC_data/default/ui/parts/mainmenu/mainmenu.gls.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ return (m) => {
5353
'multiplayer_type',
5454
'multiplayer_role',
5555
'multiplayer_host',
56+
'multiplayer_join',
5657
'multiplayer_lobby',
5758
]) {
5859
i.steps[step] = #include('steps/' + step);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
return (i) => {
2+
let l_address = null;
3+
let l_yourname = null;
4+
let settings = i.glsmac.game.get_settings();
5+
i.popup.show({
6+
title: 'Join Multiplayer Game',
7+
width: 480,
8+
height: 130,
9+
generator: (body) => {
10+
body.text({
11+
class: 'popup-text',
12+
text: 'Enter address:',
13+
align: 'left',
14+
top: 13,
15+
left: 15,
16+
});
17+
l_address = body.input({
18+
class: 'popup-input',
19+
top: 12,
20+
left: 150,
21+
width: 310,
22+
value: settings.local.remote_address,
23+
});
24+
body.text({
25+
class: 'popup-text',
26+
text: 'Enter your name:',
27+
align: 'left',
28+
top: 40,
29+
left: 15,
30+
});
31+
l_yourname = body.input({
32+
class: 'popup-input',
33+
top: 39,
34+
left: 150,
35+
width: 310,
36+
value: settings.local.player_name,
37+
});
38+
},
39+
buttons: [
40+
{
41+
style: {
42+
text: 'OK',
43+
align: 'left',
44+
is_ok: true,
45+
},
46+
onclick: (x) => {
47+
settings.local.remote_address = #trim(l_address.value);
48+
settings.local.player_name = #trim(l_yourname.value);
49+
if (settings.local.remote_address == '') {
50+
i.popup.error('Enter address!');
51+
return true;
52+
}
53+
if (settings.local.player_name == '') {
54+
i.popup.error('Enter your name!');
55+
return true;
56+
}
57+
i.steps.multiplayer_lobby(i);
58+
return true;
59+
},
60+
},
61+
{
62+
style: {
63+
text: 'Cancel',
64+
align: 'right',
65+
is_cancel: true,
66+
},
67+
onclick: (x) => {
68+
i.popup.back();
69+
return true;
70+
},
71+
},
72+
],
73+
});
74+
};

GLSMAC_data/default/ui/parts/mainmenu/steps/multiplayer_lobby.gls.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ return (i) => {
22

33
let parts = {};
44

5+
const sections = [
6+
'game_settings',
7+
'players',
8+
'custom_game_options',
9+
];
10+
let cleanups = [];
11+
512
i.popup.show({
613
title: 'Multiplayer Setup',
714
width: 800,
@@ -41,7 +48,7 @@ return (i) => {
4148
i.connection.open(() => {
4249

4350
const ii = i + {
44-
make_section: (title, properties, generator) => {
51+
make_section: (title, properties, generator, cleanup) => {
4552
let section = body.panel({
4653
class: 'popup-panel',
4754
} + properties);
@@ -55,15 +62,14 @@ return (i) => {
5562
class: 'popup-panel-body',
5663
});
5764
generator(inner);
65+
if (#is_defined(cleanup)) {
66+
cleanups :+cleanup;
67+
}
5868
return section;
5969
},
6070
};
6171

62-
for (section of [
63-
'game_settings',
64-
'players',
65-
'custom_game_options',
66-
]) {
72+
for (section of sections) {
6773
parts[section] = #include('multiplayer_lobby/' + section)(ii);
6874
}
6975

@@ -73,6 +79,9 @@ return (i) => {
7379
if (#is_defined(i.connection)) {
7480
i.connection.close();
7581
i.connection = #undefined;
82+
for (cleanup of cleanups) {
83+
cleanup();
84+
}
7685
i.popup.back();
7786
}
7887
},

GLSMAC_data/default/ui/parts/mainmenu/steps/multiplayer_lobby/game_settings.gls.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ return (i) => {
143143
}
144144
top += line_height;
145145
}
146+
}, () => {
147+
const game = i.glsmac.game;
148+
game.off('game_settings');
146149
});
147150

148151
};

GLSMAC_data/default/ui/parts/mainmenu/steps/multiplayer_lobby/players.gls.js

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ return (i) => {
33
return i.make_section('Players', {
44
left: 301,
55
width: 490,
6-
height: 358,
6+
height: 202,
77
}, (body) => {
88

99
const game = i.glsmac.game;
@@ -22,11 +22,31 @@ return (i) => {
2222
}
2323

2424
let rows = {};
25+
const buttons = {
26+
ready: body.button({
27+
class: 'popup-button',
28+
align: 'bottom left',
29+
bottom: 4,
30+
left: 8,
31+
width: 234,
32+
height: 22,
33+
text: 'Ready',
34+
}),
35+
cancel: body.button({
36+
class: 'popup-button',
37+
align: 'bottom right',
38+
bottom: 4,
39+
right: 8,
40+
width: 234,
41+
height: 22,
42+
text: 'Cancel',
43+
}),
44+
};
2545

2646
const add_row = (player) => {
2747
const id = #to_string(player.id);
2848
if (!#is_defined(rows[id])) {
29-
const row = body.panel({
49+
const row_el = body.panel({
3050
class: 'lobby-player-row',
3151
top: player.id * 24 + 2,
3252
});
@@ -41,7 +61,7 @@ return (i) => {
4161
faction_id = faction.id;
4262
faction_color = faction.text_color;
4363
}
44-
const faction_select = row.select({
64+
const faction_select = row_el.select({
4565
class: 'lobby-player-faction',
4666
items: faction_choices,
4767
value: faction_id,
@@ -55,18 +75,16 @@ return (i) => {
5575
return true;
5676
});
5777

58-
rows[id] = {
59-
row: row,
60-
ready: row.panel({
61-
class: 'lobby-player-ready',
62-
}),
63-
name: row.button({
78+
let row = {
79+
row: row_el,
80+
ready: row_el.panel(),
81+
name: row_el.button({
6482
class: 'lobby-player-name',
6583
text: player.name,
6684
color: faction_color,
6785
}),
6886
faction: faction_select,
69-
difficulty: row.select({
87+
difficulty: row_el.select({
7088
class: 'lobby-player-difficulty',
7189
items: [
7290
['transcend', 'Transcend'],
@@ -77,15 +95,22 @@ return (i) => {
7795
}),
7896
};
7997

98+
rows[id] = row;
99+
100+
update_row(player);
80101
}
81102
};
82103

83104
const update_row = (player) => {
105+
84106
const id = #to_string(player.id);
85107
const row = rows[id];
86108

87109
if (#is_defined(row)) {
110+
111+
const is_me = player.id == me.id;
88112
const faction = player.get_faction();
113+
89114
let color = 'white';
90115
if (#is_defined(faction)) {
91116
row.faction.value = faction.id;
@@ -96,6 +121,17 @@ return (i) => {
96121
row.name.color = color;
97122
row.faction.color = color;
98123
row.difficulty.color = color;
124+
if (player.is_ready()) {
125+
row.ready.class = 'lobby-player-ready';
126+
if (is_me) {
127+
buttons.ready.text = 'Not ready';
128+
}
129+
} else {
130+
row.ready.class = 'lobby-player-notready';
131+
if (is_me) {
132+
buttons.ready.text = 'Ready';
133+
}
134+
}
99135
}
100136
};
101137

@@ -123,6 +159,26 @@ return (i) => {
123159
update_row(e.player);
124160
});
125161

162+
buttons.cancel.on('click', (e) => {
163+
i.popup.back();
164+
return true;
165+
});
166+
buttons.ready.on('click', (e) => {
167+
if (buttons.ready.text == 'Ready') {
168+
game.event('ready_or_not', {
169+
ready: true,
170+
});
171+
} else {
172+
game.event('ready_or_not', {
173+
ready: false,
174+
});
175+
}
176+
return true;
177+
});
178+
179+
}, () => {
180+
const game = i.glsmac.game;
181+
game.off('player_update');
126182
});
127183

128184
};

GLSMAC_data/default/ui/parts/mainmenu/steps/multiplayer_role.gls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ return (i) => {
3434
if (i.settings.local.network_role == 'server') {
3535
i.steps.multiplayer_host(i);
3636
} else {
37-
i.steps.notimpl(i);
37+
i.steps.multiplayer_join(i);
3838
}
3939
return true;
4040
},

GLSMAC_data/default/ui/styles/lobby.gls.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ return (ui) => {
1515
border: 'rgb(60, 82, 106),2',
1616
});
1717

18-
ui.class('lobby-player-ready').extend('lobby-player-block').set({
18+
ui.class('lobby-player-readyness').extend('lobby-player-block').set({
1919
left: 2,
2020
width: 16,
21+
});
22+
23+
ui.class('lobby-player-notready').extend('lobby-player-readyness').set({
2124
background: 'interface.pcx:crop(8, 860, 31, 883)',
2225
});
2326

27+
ui.class('lobby-player-ready').extend('lobby-player-readyness').set({
28+
background: 'interface.pcx:crop(86, 860, 109, 883)',
29+
});
30+
2431
ui.class('lobby-player-button').extend('lobby-player-block').set({
2532
textalign: 'left',
2633
textleft: 2,

src/game/backend/Player.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,32 @@ WRAPIMPL_BEGIN( Player )
117117
"name",
118118
VALUE( gse::value::String, , m_name )
119119
},
120+
{
121+
"is_ready",
122+
NATIVE_CALL( this ) {
123+
N_EXPECT_ARGS( 0 );
124+
return VALUE( gse::value::Bool, , m_slot->HasPlayerFlag( ::game::backend::slot::PF_READY ) );
125+
} )
126+
},
127+
{
128+
"set_ready",
129+
NATIVE_CALL( this, game ) {
130+
131+
game->CheckRW( GSE_CALL );
132+
133+
N_EXPECT_ARGS( 1 );
134+
N_GETVALUE( isready, 0, Bool );
135+
136+
if ( isready ) {
137+
m_slot->SetPlayerFlag( ::game::backend::slot::PF_READY );
138+
}
139+
else {
140+
m_slot->UnsetPlayerFlag( ::game::backend::slot::PF_READY );
141+
}
142+
143+
return VALUE( gse::value::Undefined );
144+
} )
145+
},
120146
{
121147
"get_faction",
122148
NATIVE_CALL( this ) {

0 commit comments

Comments
 (0)