diff --git a/godot/scenes/main.tscn b/godot/scenes/main.tscn index 9f38a26..503ce46 100644 --- a/godot/scenes/main.tscn +++ b/godot/scenes/main.tscn @@ -41,9 +41,11 @@ offset_right = -1.0 offset_bottom = 292.0 grow_horizontal = 2 -[node name="TextField" type="Label" parent="CommandLinePanel/ScrollContainer" unique_id=2111638471] -custom_minimum_size = Vector2(1150, 0) -custom_maximum_size = Vector2(1150, -1) +[node name="TextField" type="RichTextLabel" parent="CommandLinePanel/ScrollContainer" unique_id=676603670] +custom_minimum_size = Vector2(-1, -1) layout_mode = 2 -vertical_alignment = 2 -clip_text = true +bbcode_enabled = true +fit_content = true +scroll_active = false +autowrap_mode = 0 +shortcut_keys_enabled = false diff --git a/rust/src/ui/cmd.rs b/rust/src/ui/cli.rs similarity index 65% rename from rust/src/ui/cmd.rs rename to rust/src/ui/cli.rs index 7c7e63a..a5b2391 100644 --- a/rust/src/ui/cmd.rs +++ b/rust/src/ui/cli.rs @@ -1,20 +1,31 @@ -use godot::classes::ScrollContainer; +use godot::classes::{RichTextLabel, ScrollContainer}; use godot::prelude::*; use godot::{ - classes::{IPanel, Label, Panel, TextEdit}, - global::godot_print, + classes::{IPanel, Panel, TextEdit}, obj::Base, register::{GodotClass, godot_api}, }; +pub enum CliColor { + Command, +} + +impl CliColor { + pub fn as_str(&self) -> &str { + match self { + CliColor::Command => "#a2a2a2", + } + } +} + #[derive(GodotClass)] #[class(base=Panel)] struct CommandLinePanel { #[export] pub input_field: Option>, #[export] - pub text_field: Option>, + pub text_field: Option>, #[export] pub scroll_container: Option>, @@ -48,7 +59,7 @@ impl IPanel for CommandLinePanel { if text.contains("\n") { let parts = text.split("\n"); let first = parts.get(0).unwrap(); - self.publish_message(first.to_string()); + self.publish_message(format!("> {}", first.to_string()), CliColor::Command); self.input_field.as_mut().unwrap().clear(); self.scroll_next_update = true; } @@ -57,14 +68,14 @@ impl IPanel for CommandLinePanel { } impl CommandLinePanel { - pub fn publish_message(&mut self, message: String) { + pub fn publish_message(&mut self, message: String, color: CliColor) { if let Some(field) = &mut self.text_field { - let mut text = field.get_text().to_string(); - if !text.is_empty() { - text += "\n"; + if !field.get_parsed_text().is_empty() { + field.append_text("\n"); } - text += &message; - field.set_text(&text); + field.append_text(&format!("[color={}]", color.as_str())); + field.append_text(&message); + field.append_text("[/color]"); } } } diff --git a/rust/src/ui/mod.rs b/rust/src/ui/mod.rs index 287551a..26710c1 100644 --- a/rust/src/ui/mod.rs +++ b/rust/src/ui/mod.rs @@ -1 +1 @@ -mod cmd; +mod cli;