From e32bf353e291ee93e5ce3438cbaf7d6140906bf6 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Fri, 31 Mar 2023 12:15:43 +0300 Subject: [PATCH] feat(client): swap cur_game to be in global, and set it --- client/src/main.rs | 4 ++++ client/src/plugins/menu/ui/play/mod.rs | 2 -- client/src/plugins/menu/ui/play/ui.rs | 16 ++++++++-------- .../networking/systems/events/receive/mod.rs | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/client/src/main.rs b/client/src/main.rs index a1de9e6..3fd0fd8 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -57,6 +57,8 @@ pub struct Global { pub users_cache_queue: Vec, pub games_cache: HashMap, pub games_cache_queue: Vec, + + pub cur_game: Option, } #[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)] @@ -113,6 +115,8 @@ fn main() { users_cache_queue: vec![], games_cache: HashMap::new(), games_cache_queue: vec![], + + cur_game: None, }) .insert_resource(cfg::CfgDirs( directories::ProjectDirs::from("com", "liljamo", "deckbuilder") diff --git a/client/src/plugins/menu/ui/play/mod.rs b/client/src/plugins/menu/ui/play/mod.rs index 8b1c9c8..d1e33d8 100644 --- a/client/src/plugins/menu/ui/play/mod.rs +++ b/client/src/plugins/menu/ui/play/mod.rs @@ -25,8 +25,6 @@ pub struct PlayScreenData { pub waiting_for_all_forming: bool, pub waiting_for_my_games: bool, - #[reflect(ignore)] - pub cur_game: Option, #[reflect(ignore)] pub all_forming: Vec, #[reflect(ignore)] diff --git a/client/src/plugins/menu/ui/play/ui.rs b/client/src/plugins/menu/ui/play/ui.rs index 6f77339..d6efc91 100644 --- a/client/src/plugins/menu/ui/play/ui.rs +++ b/client/src/plugins/menu/ui/play/ui.rs @@ -30,7 +30,7 @@ pub fn ui( mut egui_contexts: EguiContexts, mut data: ResMut, cfg_user: Res, - global: Res, + mut global: ResMut, mut creategame_ev_w: EventWriter, mut allforming_ev_w: EventWriter, mut mygames_ev_w: EventWriter, @@ -107,10 +107,10 @@ pub fn ui( ui.vertical_centered(|ui| { egui::ScrollArea::vertical().show(ui, |ui| match data.browse_state { PlayScreenBrowseState::Forming => { - browse_forming(ui, &mut data, &cfg_user, &global); + browse_forming(ui, &mut data, &cfg_user, &mut global); } PlayScreenBrowseState::InProgress => { - browse_inprogress(ui, &mut data, &global, &cfg_user); + browse_inprogress(ui, &mut data, &mut global, &cfg_user); } PlayScreenBrowseState::Finished => { browse_finished(ui, &mut data, &global, &cfg_user); @@ -159,7 +159,7 @@ fn browse_forming( ui: &mut egui::Ui, data: &mut PlayScreenData, cfg_user: &CfgUser, - global: &Global, + global: &mut Global, ) { if data.waiting_for_all_forming { ui.horizontal(|ui| { @@ -206,13 +206,13 @@ fn browse_forming( if game.guest_id.clone().unwrap_or_default() == cfg_user.id { ui.add_enabled(false, egui::Button::new("Joined")); if ui.button("Inspect").clicked() { - data.cur_game = Some(game.clone()); + global.cur_game = Some(game.clone()); data.state = PlayScreenState::InLobbyGuest; } } else if game.host_id == cfg_user.id { ui.add_enabled(false, egui::Button::new("Host")); if ui.button("Inspect").clicked() { - data.cur_game = Some(game.clone()); + global.cur_game = Some(game.clone()); data.state = PlayScreenState::InLobbyHost; } } else if ui.button("Join").clicked() { @@ -229,7 +229,7 @@ fn browse_forming( fn browse_inprogress( ui: &mut egui::Ui, data: &mut PlayScreenData, - global: &Global, + global: &mut Global, cfg_user: &CfgUser, ) { if data.waiting_for_my_games { @@ -279,7 +279,7 @@ fn browse_inprogress( )); ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { if ui.button("Resume").clicked() { - data.cur_game = Some(game.clone()); + global.cur_game = Some(game.clone()); //resumegame_ev_w.send(ResumeGameEvent); } }); diff --git a/client/src/plugins/networking/systems/events/receive/mod.rs b/client/src/plugins/networking/systems/events/receive/mod.rs index 61e7a1e..b5fb554 100644 --- a/client/src/plugins/networking/systems/events/receive/mod.rs +++ b/client/src/plugins/networking/systems/events/receive/mod.rs @@ -97,7 +97,7 @@ pub fn message_events( // and if the response data is an error) let game = serde_json::from_str(response.data.unwrap().get(0).unwrap()).unwrap(); - play_data.cur_game = Some(game); + global.cur_game = Some(game); play_data.state = PlayScreenState::InLobbyHost; } DataRequestType::GameAllForming => { -- 2.44.1