Skip to content

Commit

Permalink
fix: Always display a default fish for online player even if selectio…
Browse files Browse the repository at this point in the history
…n not made
  • Loading branch information
MaxCWhitehead committed Nov 2, 2024
1 parent aa5b451 commit 9d54e95
Showing 1 changed file with 55 additions and 42 deletions.
97 changes: 55 additions & 42 deletions src/ui/main_menu/player_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ fn player_select_panel(
None => (None, is_next_open_slot),
};

let slot_is_network_local_player = Some(slot_id) == network_local_player_slot;

//
// React to user inputs
//
Expand Down Expand Up @@ -829,20 +831,51 @@ fn player_select_panel(
let heading_font = &meta.theme.font_styles.heading.with_color(panel.font_color);

// Marker for current player in online matches
#[cfg(not(target_arch = "wasm32"))]
match network_socket {
Some(socket) if socket.player_idx() == slot_id => {
ui.vertical_centered(|ui| {
ui.label(normal_font.rich(localization.get("you-marker")));
});
}
_ => ui.add_space(normal_font.size),
if slot_is_network_local_player {
ui.vertical_centered(|ui| {
ui.label(normal_font.rich(localization.get("you-marker")));
});
} else {
ui.add_space(normal_font.size);
}

ui.add_space(normal_font.size);

let slot = state.slots[slot_id as usize];

let display_fish =
|ui: &mut egui::Ui,
player_meta_handle: Handle<PlayerMeta>,
hat_meta_handle: Option<Handle<HatMeta>>| {
let player_meta = asset_server.get(player_meta_handle);
let hat_meta = hat_meta_handle.map(|h| asset_server.get(h));

ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
ui.label(if slot.is_selecting_player() {
normal_font.rich(format!("< {} >", player_meta.name))
} else {
normal_font.rich(player_meta.name.as_str())
});

let hat_label = match slot {
PlayerSlot::Empty
| PlayerSlot::SelectingLocalControlSource
| PlayerSlot::SelectingPlayer { .. } => String::new(),
PlayerSlot::SelectingHat { .. } => match hat_meta.as_ref() {
Some(hat) => format!("< {} >", hat.name),
None => format!("< {} >", localization.get("no-hat")),
},
PlayerSlot::Ready { .. } => match hat_meta.as_ref() {
Some(hat) => hat.name.to_string(),
None => localization.get("no-hat").to_string(),
},
};
ui.label(smaller_font.rich(hat_label));

world.run_system(player_image, (ui, &player_meta, hat_meta.as_deref()));
});
};

if let Some(selected_player) = slot.selected_player() {
let confirm_binding = match slot.user_control_source() {
Some(source) => mapping.map_control_source(source).menu_confirm.to_string(),
Expand All @@ -862,9 +895,6 @@ fn player_select_panel(
.join("/"),
};
ui.vertical_centered(|ui| {
let player_meta = asset_server.get(selected_player);
let hat_meta = slot.selected_hat().map(|h| asset_server.get(h));

if !slot.is_ready() {
if slot.is_user() {
if slot.is_selecting_hat() {
Expand Down Expand Up @@ -941,33 +971,10 @@ fn player_select_panel(
}
});

ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
ui.label(if slot.is_selecting_player() {
normal_font.rich(format!("< {} >", player_meta.name))
} else {
normal_font.rich(player_meta.name.as_str())
});

let hat_label = match slot {
PlayerSlot::Empty
| PlayerSlot::SelectingLocalControlSource
| PlayerSlot::SelectingPlayer { .. } => String::new(),
PlayerSlot::SelectingHat { .. } => match hat_meta.as_ref() {
Some(hat) => format!("< {} >", hat.name),
None => format!("< {} >", localization.get("no-hat")),
},
PlayerSlot::Ready { .. } => match hat_meta.as_ref() {
Some(hat) => hat.name.to_string(),
None => localization.get("no-hat").to_string(),
},
};
ui.label(smaller_font.rich(hat_label));

world.run_system(player_image, (ui, &player_meta, hat_meta.as_deref()));
});
display_fish(ui, selected_player, slot.selected_hat());
});

// If this slot is empty
// If this slot has not selected player
} else {
let bindings = available_input_sources
.iter()
Expand All @@ -976,12 +983,14 @@ fn player_select_panel(
.join("/");

ui.vertical_centered(|ui| {
ui.label(normal_font.rich(localization.get_with(
"press-button-to-join",
&fluent_args! {
"button" => bindings
},
)));
if !is_network || slot_is_network_local_player {
ui.label(normal_font.rich(localization.get_with(
"press-button-to-join",
&fluent_args! {
"button" => bindings
},
)));
}

if !is_network {
ui.add_space(meta.theme.font_styles.bigger.size);
Expand All @@ -1001,6 +1010,10 @@ fn player_select_panel(
selected_hat: None,
});
}
} else {
// In network play, display default fish/hat for player if not yet selected.
let default_player_meta_handle = state.players[0];
display_fish(ui, default_player_meta_handle, None);
}
});
}
Expand Down

0 comments on commit 9d54e95

Please sign in to comment.