DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 25673a08e9dc6d669dc0278a0a7ca71f089e29ee deck-builder/client/src/plugins/game/ui/mod.rs -rw-r--r-- 2.7 KiB
25673a08 — skye feat(client): add needed functionality for log 1 year, 5 months ago
                                                                                
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
/*
 * 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;
            };
            let Some(status) = &game_data.game_status else {
                if game_data.parsing_data {
                    // early return if game_status is None, and we're parsing it
                    return;
                }
                // game data is None, but we're not parsing it...
                // should be unreachable, I think?
                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("Game")
                .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));

                    ui.label(format!("State: {:?}", game.state));
                });

            egui::CollapsingHeader::new("Supply Piles")
                .default_open(false)
                .show(ui, |ui| {
                    for pile in &status.supply_piles {
                        egui::CollapsingHeader::new(&pile.card.name)
                            .default_open(true)
                            .show(ui, |ui| {
                                ui.label(format!("Amount: {}", pile.amount));
                            });
                    }
                });

            egui::CollapsingHeader::new("Log")
                .default_open(false)
                .show(ui, |ui| {
                    for action in &status.actions {
                        ui.add(
                            egui::TextEdit::multiline(&mut serde_json::to_string_pretty(action).unwrap())
                                .code_editor()
                                .interactive(false)
                        );
                    }
                });
        });
}