From 4c82b40778a5040c77fad58bd2438f219bf72a82 Mon Sep 17 00:00:00 2001 From: Sofia Date: Fri, 24 Jul 2026 04:25:55 +0300 Subject: [PATCH] Change a bunch of TextEdits into LineEdits --- godot/scenes/lobby.tscn | 4 ++-- godot/scenes/main.tscn | 2 +- godot/scenes/ui/command_line_panel.tscn | 2 +- rust/src/ui/chatbox.rs | 2 +- rust/src/ui/cli.rs | 20 ++++++++--------- rust/src/ui/lobby.rs | 30 +++++++++++-------------- rust/src/ui/main_menu.rs | 4 ++-- rust/src/ui/settings.rs | 14 ++++-------- 8 files changed, 33 insertions(+), 45 deletions(-) diff --git a/godot/scenes/lobby.tscn b/godot/scenes/lobby.tscn index cd4676a..7b790f3 100644 --- a/godot/scenes/lobby.tscn +++ b/godot/scenes/lobby.tscn @@ -11,7 +11,7 @@ bg_color = Color(0.30692267, 0.3069227, 0.30692264, 1) [node name="lobby" type="LobbyPanel" unique_id=915192272 node_paths=PackedStringArray("players_list", "name_field", "ready_button", "map_selection", "options_panel", "options_grid")] players_list = NodePath("v_box_container/players_list") -name_field = NodePath("v_box_container/h_box_container/text_edit") +name_field = NodePath("") player_listing_prefab = ExtResource("1_o1atq") ready_button = NodePath("v_box_container3/ready_button") map_selection = NodePath("v_box_container2/option_button") @@ -50,7 +50,7 @@ metadata/_edit_lock_ = true layout_mode = 2 text = "Name:" -[node name="text_edit" type="TextEdit" parent="v_box_container/h_box_container" unique_id=683714912] +[node name="text_edit" type="LineEdit" parent="v_box_container/h_box_container" unique_id=284528736] custom_minimum_size = Vector2(150, 0) layout_mode = 2 diff --git a/godot/scenes/main.tscn b/godot/scenes/main.tscn index 5ee48f3..e7412ee 100644 --- a/godot/scenes/main.tscn +++ b/godot/scenes/main.tscn @@ -163,7 +163,7 @@ layout_mode = 2 text = "Address" horizontal_alignment = 1 -[node name="address_text" type="TextEdit" parent="join_panel/v_box_container" unique_id=584304528] +[node name="address_text" type="LineEdit" parent="join_panel/v_box_container" unique_id=672176728] custom_minimum_size = Vector2(150, 30) layout_mode = 2 text = "127.0.0.1:8080" diff --git a/godot/scenes/ui/command_line_panel.tscn b/godot/scenes/ui/command_line_panel.tscn index 23f94c9..1e32ddc 100644 --- a/godot/scenes/ui/command_line_panel.tscn +++ b/godot/scenes/ui/command_line_panel.tscn @@ -15,7 +15,7 @@ offset_right = 1.0 offset_bottom = -233.0 grow_horizontal = 2 -[node name="input_field" type="TextEdit" parent="command_line_panel" unique_id=2095748573] +[node name="input_field" type="LineEdit" parent="command_line_panel" unique_id=33075135] layout_mode = 1 anchors_preset = 10 anchor_right = 1.0 diff --git a/rust/src/ui/chatbox.rs b/rust/src/ui/chatbox.rs index cbfc4a4..66060ea 100644 --- a/rust/src/ui/chatbox.rs +++ b/rust/src/ui/chatbox.rs @@ -3,7 +3,7 @@ use std::i32; use godot::{ classes::{ Engine, IVBoxContainer, InputEvent, LineEdit, Panel, RichTextLabel, ScrollContainer, - TextEdit, VBoxContainer, + VBoxContainer, }, prelude::*, }; diff --git a/rust/src/ui/cli.rs b/rust/src/ui/cli.rs index bd34c64..5c63a05 100644 --- a/rust/src/ui/cli.rs +++ b/rust/src/ui/cli.rs @@ -3,7 +3,7 @@ use std::net::SocketAddr; use std::rc::Rc; use godot::classes::{ - CanvasLayer, IPanel, InputEvent, Panel, RichTextLabel, ScrollContainer, TextEdit, + CanvasLayer, IPanel, InputEvent, LineEdit, Panel, RichTextLabel, ScrollContainer, }; use godot::prelude::*; use godot::tools::get_autoload_by_name; @@ -32,7 +32,7 @@ pub const CLI_GLOBAL_NAME: &str = "CommandLinePanelGlobal"; #[class(base=Panel)] pub struct CommandLinePanel { #[export] - pub input_field: Option>, + pub input_field: Option>, #[export] pub text_field: Option>, #[export] @@ -74,6 +74,13 @@ impl IPanel for CommandLinePanel { } fn ready(&mut self) { + if let Some(input_field) = self.input_field.clone() { + input_field + .signals() + .text_submitted() + .connect_other(self, |s, value| s.input_command(value.to_string())); + } + self.idle_y = self.base().get_position().y; } @@ -85,15 +92,6 @@ impl IPanel for CommandLinePanel { self.scroll_next_update = false; } - if let Some(input) = self.input_field.clone() { - let text = input.get_text(); - if text.contains("\n") { - let parts = text.split("\n"); - let first = parts.get(0).unwrap(); - self.input_command(first.to_string()); - } - } - let old_pos = self.base().get_position(); let mut target_pos = self.base().get_position(); if self.opened { diff --git a/rust/src/ui/lobby.rs b/rust/src/ui/lobby.rs index b6e4f5d..975818e 100644 --- a/rust/src/ui/lobby.rs +++ b/rust/src/ui/lobby.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; use godot::{ classes::{ - Button, CheckBox, Control, GridContainer, IPanel, Label, OptionButton, Panel, SpinBox, - TextEdit, VBoxContainer, + Button, CheckBox, Control, GridContainer, IPanel, Label, LineEdit, OptionButton, Panel, + SpinBox, VBoxContainer, }, prelude::*, }; @@ -20,7 +20,7 @@ pub struct LobbyPanel { #[export] players_list: Option>, #[export] - name_field: Option>, + name_field: Option>, #[export] player_listing_prefab: Option>, #[export] @@ -108,22 +108,18 @@ impl IPanel for LobbyPanel { name_field .signals() .text_changed() - .connect_other(self, |s| { - if let Some(name_field) = &s.name_field { - if let Some(game) = &mut Game::singleton() { - let player_id = game.bind().self_id; - if let Some(player_id) = player_id { - game.bind_mut().update_player_nick( - player_id, - name_field.get_text().to_string(), - ); - } + .connect_other(self, |_, value| { + if let Some(game) = &mut Game::singleton() { + let player_id = game.bind().self_id; + if let Some(player_id) = player_id { + game.bind_mut() + .update_player_nick(player_id, value.to_string()); } - - NetworkManager::singleton() - .bind_mut() - .update_nick(name_field.get_text().to_string()); } + + NetworkManager::singleton() + .bind_mut() + .update_nick(value.to_string()); }); } diff --git a/rust/src/ui/main_menu.rs b/rust/src/ui/main_menu.rs index cff94e3..6b0f50c 100644 --- a/rust/src/ui/main_menu.rs +++ b/rust/src/ui/main_menu.rs @@ -1,5 +1,5 @@ use godot::{ - classes::{Button, Camera3D, Label, Panel, SpinBox, TextEdit}, + classes::{Button, Camera3D, Label, LineEdit, Panel, SpinBox}, prelude::*, register::property::SimpleVar, }; @@ -41,7 +41,7 @@ pub struct MainMenu { #[export] host_port: Option>, #[export] - join_addr: Option>, + join_addr: Option>, #[export] popup_panel: Option>, diff --git a/rust/src/ui/settings.rs b/rust/src/ui/settings.rs index fa954de..7b77c38 100644 --- a/rust/src/ui/settings.rs +++ b/rust/src/ui/settings.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use godot::{ - classes::{Control, GridContainer, IPanel, Label, Panel, TextEdit, control::SizeFlags}, + classes::{Control, GridContainer, IPanel, Label, LineEdit, Panel, control::SizeFlags}, prelude::*, }; @@ -103,22 +103,16 @@ impl IPanel for SettingsPanel { slider.upcast::() } SettingValue::String(value) => { - let mut text_edit = TextEdit::new_alloc(); + let mut text_edit = LineEdit::new_alloc(); text_edit.set_custom_minimum_size(Vector2::new(100., -1.)); text_edit.set_text(value); let setting_clone = setting.clone(); - let text_edit_clone = text_edit.clone(); text_edit .signals() .text_changed() - .connect_other(self, move |s| { - s.on_change( - setting_clone, - SettingValue::String( - text_edit_clone.get_text().to_string(), - ), - ); + .connect_other(self, move |s, v| { + s.on_change(setting_clone, SettingValue::String(v.to_string())); }); text_edit.upcast()