Change a bunch of TextEdits into LineEdits

This commit is contained in:
Sofia 2026-07-24 04:25:55 +03:00
parent 3db08f6c86
commit a29273bced
8 changed files with 33 additions and 45 deletions

View File

@ -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")] [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") 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") player_listing_prefab = ExtResource("1_o1atq")
ready_button = NodePath("v_box_container3/ready_button") ready_button = NodePath("v_box_container3/ready_button")
map_selection = NodePath("v_box_container2/option_button") map_selection = NodePath("v_box_container2/option_button")
@ -50,7 +50,7 @@ metadata/_edit_lock_ = true
layout_mode = 2 layout_mode = 2
text = "Name:" 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) custom_minimum_size = Vector2(150, 0)
layout_mode = 2 layout_mode = 2

View File

@ -163,7 +163,7 @@ layout_mode = 2
text = "Address" text = "Address"
horizontal_alignment = 1 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) custom_minimum_size = Vector2(150, 30)
layout_mode = 2 layout_mode = 2
text = "127.0.0.1:8080" text = "127.0.0.1:8080"

View File

@ -15,7 +15,7 @@ offset_right = 1.0
offset_bottom = -233.0 offset_bottom = -233.0
grow_horizontal = 2 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 layout_mode = 1
anchors_preset = 10 anchors_preset = 10
anchor_right = 1.0 anchor_right = 1.0

View File

@ -3,7 +3,7 @@ use std::i32;
use godot::{ use godot::{
classes::{ classes::{
Engine, IVBoxContainer, InputEvent, LineEdit, Panel, RichTextLabel, ScrollContainer, Engine, IVBoxContainer, InputEvent, LineEdit, Panel, RichTextLabel, ScrollContainer,
TextEdit, VBoxContainer, VBoxContainer,
}, },
prelude::*, prelude::*,
}; };

View File

@ -3,7 +3,7 @@ use std::net::SocketAddr;
use std::rc::Rc; use std::rc::Rc;
use godot::classes::{ use godot::classes::{
CanvasLayer, IPanel, InputEvent, Panel, RichTextLabel, ScrollContainer, TextEdit, CanvasLayer, IPanel, InputEvent, LineEdit, Panel, RichTextLabel, ScrollContainer,
}; };
use godot::prelude::*; use godot::prelude::*;
use godot::tools::get_autoload_by_name; use godot::tools::get_autoload_by_name;
@ -32,7 +32,7 @@ pub const CLI_GLOBAL_NAME: &str = "CommandLinePanelGlobal";
#[class(base=Panel)] #[class(base=Panel)]
pub struct CommandLinePanel { pub struct CommandLinePanel {
#[export] #[export]
pub input_field: Option<Gd<TextEdit>>, pub input_field: Option<Gd<LineEdit>>,
#[export] #[export]
pub text_field: Option<Gd<RichTextLabel>>, pub text_field: Option<Gd<RichTextLabel>>,
#[export] #[export]
@ -74,6 +74,13 @@ impl IPanel for CommandLinePanel {
} }
fn ready(&mut self) { 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; self.idle_y = self.base().get_position().y;
} }
@ -85,15 +92,6 @@ impl IPanel for CommandLinePanel {
self.scroll_next_update = false; 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 old_pos = self.base().get_position();
let mut target_pos = self.base().get_position(); let mut target_pos = self.base().get_position();
if self.opened { if self.opened {

View File

@ -2,8 +2,8 @@ use std::collections::HashMap;
use godot::{ use godot::{
classes::{ classes::{
Button, CheckBox, Control, GridContainer, IPanel, Label, OptionButton, Panel, SpinBox, Button, CheckBox, Control, GridContainer, IPanel, Label, LineEdit, OptionButton, Panel,
TextEdit, VBoxContainer, SpinBox, VBoxContainer,
}, },
prelude::*, prelude::*,
}; };
@ -20,7 +20,7 @@ pub struct LobbyPanel {
#[export] #[export]
players_list: Option<Gd<VBoxContainer>>, players_list: Option<Gd<VBoxContainer>>,
#[export] #[export]
name_field: Option<Gd<TextEdit>>, name_field: Option<Gd<LineEdit>>,
#[export] #[export]
player_listing_prefab: Option<Gd<PackedScene>>, player_listing_prefab: Option<Gd<PackedScene>>,
#[export] #[export]
@ -108,22 +108,18 @@ impl IPanel for LobbyPanel {
name_field name_field
.signals() .signals()
.text_changed() .text_changed()
.connect_other(self, |s| { .connect_other(self, |_, value| {
if let Some(name_field) = &s.name_field {
if let Some(game) = &mut Game::singleton() { if let Some(game) = &mut Game::singleton() {
let player_id = game.bind().self_id; let player_id = game.bind().self_id;
if let Some(player_id) = player_id { if let Some(player_id) = player_id {
game.bind_mut().update_player_nick( game.bind_mut()
player_id, .update_player_nick(player_id, value.to_string());
name_field.get_text().to_string(),
);
} }
} }
NetworkManager::singleton() NetworkManager::singleton()
.bind_mut() .bind_mut()
.update_nick(name_field.get_text().to_string()); .update_nick(value.to_string());
}
}); });
} }

View File

@ -1,5 +1,5 @@
use godot::{ use godot::{
classes::{Button, Camera3D, Label, Panel, SpinBox, TextEdit}, classes::{Button, Camera3D, Label, LineEdit, Panel, SpinBox},
prelude::*, prelude::*,
register::property::SimpleVar, register::property::SimpleVar,
}; };
@ -41,7 +41,7 @@ pub struct MainMenu {
#[export] #[export]
host_port: Option<Gd<SpinBox>>, host_port: Option<Gd<SpinBox>>,
#[export] #[export]
join_addr: Option<Gd<TextEdit>>, join_addr: Option<Gd<LineEdit>>,
#[export] #[export]
popup_panel: Option<Gd<Panel>>, popup_panel: Option<Gd<Panel>>,

View File

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use godot::{ use godot::{
classes::{Control, GridContainer, IPanel, Label, Panel, TextEdit, control::SizeFlags}, classes::{Control, GridContainer, IPanel, Label, LineEdit, Panel, control::SizeFlags},
prelude::*, prelude::*,
}; };
@ -103,22 +103,16 @@ impl IPanel for SettingsPanel {
slider.upcast::<Control>() slider.upcast::<Control>()
} }
SettingValue::String(value) => { 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_custom_minimum_size(Vector2::new(100., -1.));
text_edit.set_text(value); text_edit.set_text(value);
let setting_clone = setting.clone(); let setting_clone = setting.clone();
let text_edit_clone = text_edit.clone();
text_edit text_edit
.signals() .signals()
.text_changed() .text_changed()
.connect_other(self, move |s| { .connect_other(self, move |s, v| {
s.on_change( s.on_change(setting_clone, SettingValue::String(v.to_string()));
setting_clone,
SettingValue::String(
text_edit_clone.get_text().to_string(),
),
);
}); });
text_edit.upcast() text_edit.upcast()