@@ 0,0 1,117 @@
+/*
+ * 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 crate::AppState;
+
+pub struct LogPlugin;
+
+impl Plugin for LogPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_event::<UpdateLogEvent>()
+ .add_system(setup_log.in_schedule(OnEnter(AppState::InGame)))
+ .add_system(update_log_button)
+ .add_system(toggle_log.run_if(on_event::<ToggleLogEvent>()))
+ .add_system(update_log.run_if(on_event::<UpdateLogEvent>()));
+ }
+}
+
+pub struct ToggleLogEvent;
+pub struct UpdateLogEvent;
+
+const NORMAL_BUTTON: Color = Color::rgb(0.15, 0.15, 0.15);
+const HOVERED_BUTTON: Color = Color::rgb(0.25, 0.25, 0.25);
+const PRESSED_BUTTON: Color = Color::rgb(0.35, 0.75, 0.35);
+
+#[derive(Component)]
+struct LogButton;
+#[derive(Component)]
+struct LogList;
+
+fn setup_log(mut commands: Commands, asset_server: Res<AssetServer>) {
+ // setup a button for log toggle
+ // setup the log ui itself, with hidden visibility
+
+ let font = asset_server.load("fonts/FiraMono-Bold.ttf");
+
+ commands
+ .spawn((NodeBundle {
+ style: Style {
+ position_type: PositionType::Absolute,
+ position: UiRect {
+ top: Val::Px(20.),
+ right: Val::Px(20.),
+ ..Default::default()
+ },
+ ..Default::default()
+ },
+ ..Default::default()
+ },))
+ .with_children(|parent| {
+ parent
+ .spawn((
+ ButtonBundle {
+ style: Style {
+ size: Size::new(Val::Px(75.), Val::Px(35.)),
+ // center child text
+ justify_content: JustifyContent::Center,
+ align_items: AlignItems::Center,
+ ..Default::default()
+ },
+ background_color: NORMAL_BUTTON.into(),
+ ..Default::default()
+ },
+ LogButton,
+ ))
+ .with_children(|parent| {
+ parent.spawn((
+ TextBundle::from_section(
+ "Log",
+ TextStyle {
+ font: font.clone(),
+ font_size: 20.,
+ color: Color::WHITE,
+ },
+ ),
+ ));
+ });
+ });
+}
+
+fn update_log_button(
+ mut interaction_query: Query<
+ (&Interaction, &mut BackgroundColor),
+ (Changed<Interaction>, With<LogButton>),
+ >,
+ mut ul_ev_w: EventWriter<UpdateLogEvent>,
+) {
+ for (interaction, mut color) in &mut interaction_query {
+ match interaction {
+ Interaction::Clicked => {
+ *color = PRESSED_BUTTON.into();
+ ul_ev_w.send(UpdateLogEvent);
+ }
+ Interaction::Hovered => {
+ *color = HOVERED_BUTTON.into();
+ }
+ Interaction::None => {
+ *color = NORMAL_BUTTON.into();
+ }
+ }
+ }
+}
+
+fn toggle_log() {
+ // toggle the node visibility, see the state button for e.g
+}
+
+fn update_log() {
+ // despawn the children ui nodes, and create new ones.
+ // update log ui scrolling items with... log items
+}
@@ 18,13 18,15 @@ use crate::{
use super::{GameData, RefreshGameEvent};
+mod log;
mod state_button;
pub struct GameUIPlugin;
impl Plugin for GameUIPlugin {
fn build(&self, app: &mut App) {
- app.add_plugin(state_button::StateButtonPlugin)
+ app.add_plugin(log::LogPlugin)
+ .add_plugin(state_button::StateButtonPlugin)
.add_system(dev_details_ui.run_if(in_state(AppState::InGame)))
.add_system(setup_details.in_schedule(OnEnter(AppState::InGame)))
.add_systems((