Improve command line interface
This commit is contained in:
parent
7b66a7afb9
commit
ae37115b37
@ -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
|
||||
|
||||
@ -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<Gd<TextEdit>>,
|
||||
#[export]
|
||||
pub text_field: Option<Gd<Label>>,
|
||||
pub text_field: Option<Gd<RichTextLabel>>,
|
||||
#[export]
|
||||
pub scroll_container: Option<Gd<ScrollContainer>>,
|
||||
|
||||
@ -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]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1 +1 @@
|
||||
mod cmd;
|
||||
mod cli;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user