DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 443c9b0c1e96aadaa1aff06953210c400b7fc0c9 deck-builder/client/src/plugins/game/ui/mod.rs -rw-r--r-- 1.2 KiB
443c9b0c — skye feat!(client): get in-game, and see some details 1 year, 5 months ago
                                                                                
443c9b0c skye
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
/*
 * 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();

            ui.collapsing("Details", |ui| {
                ui.label(format!("Host: {}", game.host.as_ref().unwrap().username));
                ui.label(format!("Guest: {}", game.guest.as_ref().unwrap().username));
            });
        });
}