From f2af0141369d5ca4bb44f3f24d0b8402e1ac7e90 Mon Sep 17 00:00:00 2001 From: skye Date: Thu, 27 Apr 2023 17:58:04 +0300 Subject: [PATCH] feat(client): something to browse in browse --- client/src/api/game/mod.rs | 9 +++- client/src/api/user/mod.rs | 2 +- client/src/plugins/menu/ui/browse.rs | 62 +++++++++++++++++++++++++--- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/client/src/api/game/mod.rs b/client/src/api/game/mod.rs index a80716c..cea561b 100644 --- a/client/src/api/game/mod.rs +++ b/client/src/api/game/mod.rs @@ -38,7 +38,7 @@ pub enum Command { ShuffleDiscardToDeck { seed: u32 }, } -#[derive(Deserialize)] +#[derive(Deserialize, Clone)] pub struct Action { pub id: String, pub created_at: String, @@ -49,7 +49,7 @@ pub struct Action { pub command: Command, } -#[derive(Deserialize)] +#[derive(Deserialize, Clone)] pub struct Game { pub id: String, pub created_at: String, @@ -63,3 +63,8 @@ pub struct Game { pub turn: u8, pub actions: Option>, } + +pub const GAMESTATE_FORMING: u8 = 0; +pub const GAMESTATE_INPROGRESS: u8 = 1; +pub const GAMESTATE_FINISHED: u8 = 2; +pub const GAMESTATE_CANCELLED: u8 = 3; diff --git a/client/src/api/user/mod.rs b/client/src/api/user/mod.rs index 233b822..2ebcb50 100644 --- a/client/src/api/user/mod.rs +++ b/client/src/api/user/mod.rs @@ -14,7 +14,7 @@ pub use login::*; mod register; pub use register::*; -#[derive(Deserialize)] +#[derive(Deserialize, Clone)] pub struct User { pub id: String, pub created_at: String, diff --git a/client/src/plugins/menu/ui/browse.rs b/client/src/plugins/menu/ui/browse.rs index b7dabf5..1f65602 100644 --- a/client/src/plugins/menu/ui/browse.rs +++ b/client/src/plugins/menu/ui/browse.rs @@ -9,10 +9,10 @@ use bevy::prelude::*; use bevy_egui::egui; -use crate::plugins::{ +use crate::{plugins::{ GameCreateCallEvent, BrowseState, GameFormingCallEvent, GameMyGamesCallEvent -}; +}, api::game::{GAMESTATE_INPROGRESS, GAMESTATE_FINISHED}}; use super::{MenuData, MenuUIState}; @@ -73,9 +73,61 @@ pub fn view( }); ui.vertical_centered(|ui| { egui::ScrollArea::vertical().show(ui, |ui| match data.browse_state { - BrowseState::Forming => {} - BrowseState::InProgress => {} - BrowseState::Finished => {} + BrowseState::Forming => { + for game in &data.forming_games { + egui::Frame::none() + .fill(egui::Color32::BLACK) + .rounding(4.) + .outer_margin(4.) + .inner_margin(4.) + .show(ui, |ui| { + ui.horizontal(|ui| { + ui.label(format!( + "Host: {}", + game.host.as_ref().unwrap().username + )); + }); + }); + } + } + BrowseState::InProgress => { + let mut games = data.my_games.clone(); + games.retain(|g| g.state == GAMESTATE_INPROGRESS); + for game in &games { + egui::Frame::none() + .fill(egui::Color32::BLACK) + .rounding(4.) + .outer_margin(4.) + .inner_margin(4.) + .show(ui, |ui| { + ui.horizontal(|ui| { + ui.label(format!( + "Host: {}", + game.host.as_ref().unwrap().username + )); + }); + }); + } + } + BrowseState::Finished => { + let mut games = data.my_games.clone(); + games.retain(|g| g.state == GAMESTATE_FINISHED); + for game in &games { + egui::Frame::none() + .fill(egui::Color32::BLACK) + .rounding(4.) + .outer_margin(4.) + .inner_margin(4.) + .show(ui, |ui| { + ui.horizontal(|ui| { + ui.label(format!( + "Host: {}", + game.host.as_ref().unwrap().username + )); + }); + }); + } + } } ); }); -- 2.44.1