Skip to content

Commit 956ca33

Browse files
committed
fix: selected map not always highlighted
1 parent ed9dd77 commit 956ca33

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/user_interface/common.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use bevy::{
44
};
55

66
use crate::{
7-
game_flow::states::{AppState, InGameState, MainMenuState},
7+
game_flow::{
8+
game_mode::GameModeState,
9+
states::{AppState, InGameState, MainMenuState},
10+
},
811
user_interface::map_selection::{MapSelectionButton, MapSelectionPlugin},
912
};
1013

@@ -34,6 +37,7 @@ fn handle_common_ui_button_press(
3437
mut next_app_state: ResMut<NextState<AppState>>,
3538
mut next_main_menu_state: ResMut<NextState<MainMenuState>>,
3639
mut next_in_game_stte: ResMut<NextState<InGameState>>,
40+
mut next_game_mode_state: ResMut<NextState<GameModeState>>,
3741
) {
3842
for (interaction, common_ui_button) in query {
3943
let Interaction::Pressed = interaction else {
@@ -47,6 +51,7 @@ fn handle_common_ui_button_press(
4751
next_app_state.set(AppState::MainMenu);
4852
next_main_menu_state.set(MainMenuState::Root);
4953
next_in_game_stte.set(InGameState::None);
54+
next_game_mode_state.set(GameModeState::None);
5055
}
5156
CommonUiButtonType::ToGameModeSelection => {
5257
next_main_menu_state.set(MainMenuState::GameModeSelection);

src/user_interface/map_selection.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ fn spawn_map_selection(
4242
mut commands: Commands,
4343
selected_map_state: Res<State<SelectedMapState>>,
4444
) {
45+
let selected_map_state = selected_map_state.get();
46+
4547
commands
4648
.spawn((
4749
Node {
@@ -56,7 +58,7 @@ fn spawn_map_selection(
5658
DespawnOnExit(MainMenuState::MapSelection),
5759
))
5860
.with_children(|parent| {
59-
let selected_map_preview_image = match *selected_map_state.get() {
61+
let selected_map_preview_image = match selected_map_state {
6062
SelectedMapState::TinyTown => "maps/tiny_town/preview.png",
6163
SelectedMapState::MediumPlastic => {
6264
"maps/medium_plastic/preview.png"
@@ -124,6 +126,10 @@ fn spawn_map_selection(
124126
font_size: DEFAULT_FONT_SIZE,
125127
..default()
126128
},
129+
TextColor(get_text_button_color_for_map_selection_button(
130+
&selected_map_state,
131+
MapSelectionButton(SelectedMapState::TinyTown),
132+
)),
127133
));
128134
parent
129135
.spawn((
@@ -139,6 +145,10 @@ fn spawn_map_selection(
139145
font_size: DEFAULT_FONT_SIZE,
140146
..default()
141147
},
148+
TextColor(get_text_button_color_for_map_selection_button(
149+
&selected_map_state,
150+
MapSelectionButton(SelectedMapState::MediumPlastic),
151+
)),
142152
));
143153
parent
144154
.spawn((
@@ -185,6 +195,17 @@ fn spawn_map_selection(
185195
});
186196
}
187197

198+
fn get_text_button_color_for_map_selection_button(
199+
selected_map_state: &SelectedMapState,
200+
button: MapSelectionButton,
201+
) -> Color {
202+
if button.0 == *selected_map_state {
203+
ORANGE_400.into()
204+
} else {
205+
WHITE.into()
206+
}
207+
}
208+
188209
fn update_selected_map_preview_image(
189210
asset_server: Res<AssetServer>,
190211
mut image_node: Single<&mut ImageNode, With<SelectedMapPreviewImage>>,

0 commit comments

Comments
 (0)