1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
/*
* This file is part of laurelin_client
* Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
*
* Licensed under GPL-3.0-only.
* See LICENSE for licensing information.
*/
use bevy::prelude::*;
use bevy_egui::egui;
use crate::{plugins::{
GameCreateCallEvent, BrowseState,
GameFormingCallEvent, GameMyGamesCallEvent
}, api::game::{GAMESTATE_INPROGRESS, GAMESTATE_FINISHED}};
use super::{MenuData, MenuUIState};
pub fn view(
ui: &mut egui::Ui,
data: &mut MenuData,
create_ev_w: &mut EventWriter<GameCreateCallEvent>,
forming_ev_w: &mut EventWriter<GameFormingCallEvent>,
mygames_ev_w: &mut EventWriter<GameMyGamesCallEvent>,
) {
egui::SidePanel::left("browse_side_panel")
.resizable(false)
.show_inside(ui, |ui| {
ui.vertical_centered(|ui| {
ui.add_enabled_ui(!data.waiting, |ui| {
if ui.button("Create").clicked() {
create_ev_w.send(GameCreateCallEvent);
}
if ui.button("Back").clicked() {
data.ui_state = MenuUIState::Main;
}
});
});
});
egui::TopBottomPanel::top("browse_top_panel")
.resizable(false)
.show_inside(ui, |ui| {
ui.horizontal(|ui| {
ui.selectable_value(&mut data.browse_state, BrowseState::Forming, "Forming");
ui.selectable_value(&mut data.browse_state, BrowseState::InProgress, "In Progress");
ui.selectable_value(&mut data.browse_state, BrowseState::Finished, "Finished");
ui.with_layout(
egui::Layout::right_to_left(egui::Align::Center),
|ui| {
if ui.button("Refresh").clicked() {
match data.browse_state {
BrowseState::Forming => {
if !data.waiting {
forming_ev_w.send(GameFormingCallEvent);
}
}
BrowseState::InProgress => {
if !data.waiting {
mygames_ev_w.send(GameMyGamesCallEvent);
}
}
BrowseState::Finished => {
if !data.waiting {
mygames_ev_w.send(GameMyGamesCallEvent);
}
}
}
}
},
);
});
});
ui.vertical_centered(|ui| {
egui::ScrollArea::vertical().show(ui, |ui| match data.browse_state {
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
));
});
});
}
}
}
);
});
}