Allow toggling cli

This commit is contained in:
Sofia 2026-07-17 19:09:14 +03:00
parent b93eded960
commit eaac940b98
4 changed files with 58 additions and 3 deletions

View File

@ -34,6 +34,15 @@ project/assembly_name="QuakeBall"
naming/node_name_casing=2
[input]
toggle_cli={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":167,"key_label":0,"unicode":167,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":92,"key_label":0,"unicode":39,"location":0,"echo":false,"script":null)
]
}
[physics]
3d/physics_engine="Jolt Physics"

View File

@ -1,6 +1,7 @@
[gd_scene format=3 uid="uid://bsb6asp5o35w3"]
[node name="canvas_layer" type="CanvasLayer" unique_id=1517655401]
layer = 10
[node name="command_line_panel" type="CommandLinePanel" parent="." unique_id=2077938969 node_paths=PackedStringArray("input_field", "text_field", "scroll_container")]
input_field = NodePath("input_field")
@ -8,7 +9,10 @@ text_field = NodePath("scroll_container/text_field")
scroll_container = NodePath("scroll_container")
anchors_preset = 10
anchor_right = 1.0
offset_bottom = 307.0
offset_left = 1.0
offset_top = -344.0
offset_right = 1.0
offset_bottom = -37.0
grow_horizontal = 2
[node name="input_field" type="TextEdit" parent="command_line_panel" unique_id=2095748573]
@ -18,6 +22,8 @@ anchor_right = 1.0
offset_top = 307.0
offset_bottom = 342.0
grow_horizontal = 2
editable = false
metadata/_edit_lock_ = true
[node name="scroll_container" type="ScrollContainer" parent="command_line_panel" unique_id=1922272461]
custom_minimum_size = Vector2(-1, 0)
@ -28,6 +34,7 @@ offset_left = 1.0
offset_right = -1.0
offset_bottom = 292.0
grow_horizontal = 2
metadata/_edit_lock_ = true
[node name="text_field" type="RichTextLabel" parent="command_line_panel/scroll_container" unique_id=591332585]
custom_minimum_size = Vector2(-1, -1)
@ -37,3 +44,4 @@ fit_content = true
scroll_active = false
autowrap_mode = 0
shortcut_keys_enabled = false
metadata/_edit_lock_ = true

View File

@ -4,7 +4,7 @@ use std::ops::DerefMut;
use std::rc::Rc;
use godot::classes::{
CanvasLayer, Engine, IPanel, Panel, RichTextLabel, ScrollContainer, TextEdit,
CanvasLayer, Engine, IPanel, InputEvent, Panel, RichTextLabel, ScrollContainer, TextEdit,
};
use godot::prelude::*;
use godot::tools::get_autoload_by_name;
@ -39,9 +39,14 @@ pub struct CommandLinePanel {
#[export]
pub scroll_container: Option<Gd<ScrollContainer>>,
#[export]
pub opened: bool,
scroll_next_update: bool,
commands: HashMap<String, Rc<Box<dyn Command>>>,
idle_y: f32,
base: Base<Panel>,
}
@ -61,12 +66,18 @@ impl IPanel for CommandLinePanel {
input_field: None,
text_field: None,
scroll_container: None,
opened: false,
scroll_next_update: false,
idle_y: 0.,
commands,
base,
}
}
fn ready(&mut self) {
self.idle_y = self.base().get_position().y;
}
fn process(&mut self, _delta: f64) {
if let Some(scroll) = &mut self.scroll_container
&& self.scroll_next_update
@ -83,6 +94,33 @@ impl IPanel for CommandLinePanel {
self.input_command(first.to_string());
}
}
let old_pos = self.base().get_position();
let mut target_pos = self.base().get_position();
if self.opened {
target_pos.y = 0.;
} else {
target_pos.y = self.idle_y;
}
let new_pos = old_pos.lerp(target_pos, 0.3);
self.base_mut().set_position(new_pos);
}
fn input(&mut self, event: Gd<InputEvent>) {
if event.is_action_pressed("toggle_cli") {
godot_print!("hello?");
self.opened = !self.opened;
if let Some(input_field) = &mut self.input_field {
if self.opened {
input_field.grab_focus();
input_field.set_editable(true);
self.run_deferred(|s| s.input_field.as_mut().unwrap().clear());
} else {
input_field.release_focus();
input_field.set_editable(false);
}
}
}
}
}

@ -1 +1 @@
Subproject commit 2721021f7b20831388d9ea7b3ea0797e3efdfdac
Subproject commit 4d843d2ccb5566a4bc7dc4f3af2bdf181ebf0c38