Add handle_command

This commit is contained in:
Sofia 2026-07-15 20:03:26 +03:00
parent ae37115b37
commit fbb24ddd17
2 changed files with 12 additions and 4 deletions

View File

@ -29,7 +29,6 @@ anchor_right = 1.0
offset_top = 307.0
offset_bottom = 342.0
grow_horizontal = 2
text = "Hello there!"
[node name="ScrollContainer" type="ScrollContainer" parent="CommandLinePanel" unique_id=910897176]
custom_minimum_size = Vector2(-1, 0)

View File

@ -9,12 +9,14 @@ use godot::{
pub enum CliColor {
Command,
Regular,
}
impl CliColor {
pub fn as_str(&self) -> &str {
match self {
CliColor::Command => "#a2a2a2",
CliColor::Regular => "#fff",
}
}
}
@ -59,15 +61,22 @@ impl IPanel for CommandLinePanel {
if text.contains("\n") {
let parts = text.split("\n");
let first = parts.get(0).unwrap();
self.publish_message(format!("> {}", first.to_string()), CliColor::Command);
self.input_field.as_mut().unwrap().clear();
self.scroll_next_update = true;
self.handle_command(first.to_string());
}
}
}
}
impl CommandLinePanel {
pub fn handle_command(&mut self, command: String) {
self.publish_message(format!("> {}", command), CliColor::Command);
if let Some(input) = &mut self.input_field {
input.clear();
}
self.publish_message("Command registered!".to_owned(), CliColor::Regular);
self.scroll_next_update = true;
}
pub fn publish_message(&mut self, message: String, color: CliColor) {
if let Some(field) = &mut self.text_field {
if !field.get_parsed_text().is_empty() {