From 7ce88fae9680596019fc15be5ec510df7ea939b8 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Sun, 21 May 2023 19:06:21 +0300 Subject: [PATCH] feat(client): sorta finished log ui, remove old Though only one Command has a configured log format. --- client/src/plugins/game/ui/log.rs | 38 +++++++++++++++++++------------ client/src/plugins/game/ui/mod.rs | 25 +------------------- client/src/util/action_to_log.rs | 37 ++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/client/src/plugins/game/ui/log.rs b/client/src/plugins/game/ui/log.rs index eb9cbe4..db25584 100644 --- a/client/src/plugins/game/ui/log.rs +++ b/client/src/plugins/game/ui/log.rs @@ -96,7 +96,7 @@ fn setup_log(mut commands: Commands, asset_server: Res) { justify_content: JustifyContent::Center, align_items: AlignItems::Center, size: Size { - width: Val::Px(300.), + width: Val::Px(475.), height: Val::Percent(75.), }, position_type: PositionType::Absolute, @@ -118,8 +118,11 @@ fn setup_log(mut commands: Commands, asset_server: Res) { .spawn(NodeBundle { style: Style { flex_direction: FlexDirection::Column, - align_self: AlignSelf::Stretch, - size: Size::all(Val::Percent(95.)), + //align_self: AlignSelf::Stretch, + size: Size { + width: Val::Px(450.), + height: Val::Percent(95.), + }, overflow: Overflow::Hidden, ..Default::default() }, @@ -220,20 +223,27 @@ fn update_log( let index_spaces = status.actions.len().to_string().len(); for (i, action) in status.actions.iter().enumerate() { - let spaces = "".repeat(index_spaces - i.to_string().len()); + let spaces = " ".repeat(index_spaces - i.to_string().len()); + let index_text = TextSection { + value: format!("{}{}. ", spaces, i), + style: TextStyle { + font: font_bold.clone(), + ..style + }, + }; + + let mut sections = action_to_log(action, (font.clone(), font_bold.clone()), style.clone()); + sections.insert(0, index_text); commands.spawn(( - TextBundle::from_sections([[ - TextSection { - value: format!("{}{}. ", spaces, i), - style: TextStyle { - font: font_bold.clone(), - ..style - }, + TextBundle::from_sections(sections) + .with_style(Style { + max_size: Size { + width: Val::Px(450.), + height: Val::Undefined, }, - ], - action_to_log(action, font, style).into_iter() - ].concat()), + ..Default::default() + }), AccessibilityNode(NodeBuilder::new(bevy::a11y::accesskit::Role::ListItem)), LogListEntry, )) diff --git a/client/src/plugins/game/ui/mod.rs b/client/src/plugins/game/ui/mod.rs index 3c26788..dfa16ac 100644 --- a/client/src/plugins/game/ui/mod.rs +++ b/client/src/plugins/game/ui/mod.rs @@ -387,30 +387,7 @@ pub fn dev_details_ui( }); } }); - - egui::CollapsingHeader::new("Log") - .default_open(false) - .show(ui, |ui| { - egui::ScrollArea::vertical() - .max_width(f32::INFINITY) - .show(ui, |ui| { - for (i, action) in status.actions.iter().enumerate() { - egui::CollapsingHeader::new(format!("{}", i)) - .default_open(false) - .show(ui, |ui| { - ui.add( - egui::TextEdit::multiline( - &mut serde_json::to_string_pretty(action).unwrap(), - ) - .code_editor() - .interactive(false) - .desired_width(f32::INFINITY), - ); - }); - } - }); - }); - }); + }); } fn hardcoded_init(game: &Game, create_action_ev_w: &mut EventWriter) { diff --git a/client/src/util/action_to_log.rs b/client/src/util/action_to_log.rs index caeaf0a..974158c 100644 --- a/client/src/util/action_to_log.rs +++ b/client/src/util/action_to_log.rs @@ -8,14 +8,47 @@ use bevy::prelude::*; -use crate::api::game::Action; +use crate::api::game::{Action, Command}; + +macro_rules! section { + ($value:expr, $style:ident) => { + TextSection { + value: $value, + style: $style.clone(), + } + }; + + ($value:expr, $style:expr) => { + TextSection { + value: $value, + style: $style, + } + }; +} pub fn action_to_log( action: &Action, - font: Handle, + (font, font_bold): (Handle, Handle), style: TextStyle, ) -> Vec { match &action.command { + Command::InitSupplyPile { card, amount } => { + vec![ + section!(format!("Created supply pile of "), style), + section!(format!("{}", card.name), TextStyle { + font: font_bold.clone(), + ..style.clone() + }), + section!(format!(" with "), style), + section!(format!("{}", amount), TextStyle { + font: font_bold.clone(), + ..style.clone() + }), + section!(format!(" cards."), TextStyle { + ..style.clone() + }), + ] + } _ => { vec![ TextSection { -- 2.44.1