/*
* 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, EguiContexts};
use crate::{plugins::GameDetailsCallEvent, Global};
use super::GameData;
pub fn ui(
mut commands: Commands,
mut contexts: EguiContexts,
global: Res<Global>,
mut game_data: ResMut<GameData>,
mut details_ev_w: EventWriter<GameDetailsCallEvent>,
) {
egui::Window::new("Game Details")
.show(contexts.ctx_mut(), |ui| {
let Some(game) = &game_data.game else {
// early return if game is None
return;
};
if ui.button("Refresh").clicked() {
details_ev_w.send(GameDetailsCallEvent {
game_id: game_data.game.as_ref().unwrap().id.clone(),
});
}
ui.separator();
egui::CollapsingHeader::new("Users")
.default_open(true)
.show(ui, |ui| {
ui.label(format!("Host: {}", game.host.as_ref().unwrap().username));
ui.label(format!("Guest: {}", game.guest.as_ref().unwrap().username));
});
egui::CollapsingHeader::new("State")
.default_open(true)
.show(ui, |ui| {
ui.label(format!("Game: {:?}", game.state));
});
});
}