I have this 'lobby' UI that spawns a few labels, and a button in a container.
When the Ready button is not spawned as a child of the container, it works fine and I get the "Ready" logs when I click.
Whenever I move it inside the container events no longer seem to work.
Spawning Code:
/// Polls for a GameLobby to be added to a client here, realistically this probably should be RPC based and not straight up replication
fn spawn_lobby_ui(mut cmds: Commands, replicated_lobby: Query<&GameLobby, Added<GameLobby>>, ui_assets: Res<UiAssets>){
//for each connected player in the lobby show a row
if replicated_lobby.is_empty() {
debug!("No Lobbies on client!");
return;
} else {
info!("Ok we should be good to spawn a lobby")
}
//Spawn UI + Ready box
cmds.spawn((Name::new("LobbyUI"), Node{
width: Val::Percent(50.0),
height: Val::Percent(80.0),
top: Val::Percent(10.0),
left: Val::Percent(25.0),
display: Display::Flex,
flex_direction: FlexDirection::Column,
..default()
})).with_children(|rs|{
//Spawn a label for each connected player
let lobby = replicated_lobby.single_inner().expect("God said we would have a lobby by now!");
for player in &lobby.player_data {
ui_assets.transmute_label_info(&mut rs.spawn(Name::new("Player Lobby Entry")), player.0.to_string());
}
//Ready Button
let mut btn = rs.spawn(Name::new("Ready Button"));
ui_assets.transmute_button(&mut btn, "Ready");
btn.observe(|_trigger: Trigger<Pointer<Click>>|{
info!("Ready");
});
});
}
TransmuteButton code:
fn transmute_button(&self, cmds: &'a mut EntityCommands<'w>, text: impl Into<String>) -> &'a mut EntityCommands<'w> {
cmds.insert((
Node {
width: Val::Px(200.0),
height: Val::Px(50.0),
border: UiRect::all(Val::Px(5.0)),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
BackgroundColor(css::GOLDENROD.into()),
Text::new(text.into()),
self.textfont.clone(),
self.primary_text_color,
Button,
TextLayout::new_with_justify(JustifyText::Center)
));
cmds
}
If anyone knows what I'm missing here I'd appreciate it. I can't recall having this particular problem before.