DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

7aa867680ada363acd704bce409a201d1e1e75de — Jonni Liljamo 1 year, 10 months ago 5e9a1b4
feat(sdbclient): tabbed browse page
2 files changed, 60 insertions(+), 25 deletions(-)

M sdbclient/src/plugins/menu/play/ui.rs
M sdbclient/src/runtime/menu/mod.rs
M sdbclient/src/plugins/menu/play/ui.rs => sdbclient/src/plugins/menu/play/ui.rs +51 -25
@@ 11,8 11,9 @@ use bevy_inspector_egui::bevy_egui::{egui, EguiContext};
use iyes_loopless::prelude::*;

use crate::{
    cfg::CfgUser,
    plugins::menu::MenuState,
    runtime::menu::{PlayMenuUIState, RTDMenu}, cfg::CfgUser,
    runtime::menu::{BrowseMenuTab, PlayMenuUIState, RTDMenu},
};

use super::{AllFormingEvent, CreateGameEvent, JoinGameEvent, PlayMenuState};


@@ 69,12 70,6 @@ pub(super) fn show(
                                    rtdmenu.play_menu_ui_state = PlayMenuUIState::CreateGame
                                }

                                ui.add_enabled_ui(!rtdmenu.waiting_for_all_forming_call, |ui| {
                                    if ui.button("Refresh Browse").clicked() {
                                        allforming_ev_w.send(AllFormingEvent);
                                    }
                                });

                                if ui.button("Back").clicked() {
                                    commands.insert_resource(NextState(PlayMenuState::None));
                                    commands.insert_resource(NextState(MenuState::Main));


@@ 82,21 77,46 @@ pub(super) fn show(
                            });
                        });

                    match rtdmenu.waiting_for_all_forming_call {
                        true => {
                            ui.horizontal(|ui| {
                                ui.spinner();
                                ui.label("loading...");
                            });
                        }
                        false => {
                            ui.vertical_centered(|ui| {
                                egui::ScrollArea::vertical().show(ui, |ui| {
                                    match rtdmenu.all_forming_games.is_empty() {
                                        true => {
                                            ui.label("No games found.");
                    egui::TopBottomPanel::top("play_top_panel").resizable(false).show_inside(ui, |ui| {
                        ui.horizontal(|ui| {
                            ui.label(egui::RichText::new("Browse: ").size(24.));

                            ui.selectable_value(&mut rtdmenu.browse_tab, BrowseMenuTab::Forming, "Forming");
                            ui.selectable_value(&mut rtdmenu.browse_tab, BrowseMenuTab::InProgress, "In Progress");
                            ui.selectable_value(&mut rtdmenu.browse_tab, BrowseMenuTab::Finished, "Finished");

                            ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
                                if ui.button("Refresh").clicked() {
                                    // refresh the current tab
                                    // oh and also, if the tab content in rtdmenu is empty, should
                                    // fetch when switching to it
                                    match rtdmenu.browse_tab {
                                        BrowseMenuTab::Forming => {
                                            if !rtdmenu.waiting_for_all_forming_call {
                                                allforming_ev_w.send(AllFormingEvent);
                                            }
                                        }
                                        false => {
                                        BrowseMenuTab::InProgress => todo!(),
                                        BrowseMenuTab::Finished => todo!(),
                                    }
                                }
                            });
                        });
                    });

                    ui.vertical_centered(|ui| {
                        egui::ScrollArea::vertical().show(ui, |ui| {
                            match rtdmenu.browse_tab {
                                BrowseMenuTab::Forming => {
                                    if rtdmenu.waiting_for_all_forming_call {
                                        ui.horizontal(|ui| {
                                            ui.spinner();
                                            ui.label("loading...");
                                        });
                                    } else {
                                        if rtdmenu.all_forming_games.is_empty() {
                                            ui.label("No forming games found.");
                                        } else {
                                            for game in rtdmenu.all_forming_games.clone() {
                                                egui::Frame::none()
                                                    .fill(egui::Color32::BLACK)


@@ 139,10 159,16 @@ pub(super) fn show(
                                            }
                                        }
                                    }
                                });
                            });
                        }
                    }
                                }
                                BrowseMenuTab::InProgress => {

                                }
                                BrowseMenuTab::Finished => {

                                }
                            }
                        });
                    });
                }
                PlayMenuUIState::CreateGame => {
                    ui.vertical_centered(|ui| {

M sdbclient/src/runtime/menu/mod.rs => sdbclient/src/runtime/menu/mod.rs +9 -0
@@ 14,6 14,7 @@ use crate::api::game::types::Game;
#[derive(Resource)]
pub(crate) struct RTDMenu {
    pub play_menu_ui_state: PlayMenuUIState,
    pub browse_tab: BrowseMenuTab,
    pub waiting_for_create_game_call: bool,
    /// Current game
    pub cur_game: Option<Game>,


@@ 27,6 28,7 @@ impl Default for RTDMenu {
    fn default() -> Self {
        Self {
            play_menu_ui_state: PlayMenuUIState::Main,
            browse_tab: BrowseMenuTab::Forming,
            waiting_for_create_game_call: false,
            cur_game: None,
            all_forming_games: vec![],


@@ 53,3 55,10 @@ impl PlayMenuUIState {
        }
    }
}

#[derive(PartialEq)]
pub(crate) enum BrowseMenuTab {
    Forming,
    InProgress,
    Finished,
}