Improve chat
This commit is contained in:
parent
fa5e4517d1
commit
305c9e334a
@ -123,6 +123,8 @@ layout_mode = 2
|
||||
columns = 2
|
||||
|
||||
[node name="chat_box" parent="." unique_id=1125601400 instance=ExtResource("2_5gu6x")]
|
||||
custom_minimum_size = Vector2(400, 300)
|
||||
custom_maximum_size = Vector2(400, 300)
|
||||
layout_mode = 1
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_61vwu"]
|
||||
bg_color = Color(0.6, 0.6, 0.6, 0)
|
||||
|
||||
[node name="chat_box" type="ChatBox" unique_id=1125601400 node_paths=PackedStringArray("messages", "line_edit")]
|
||||
[node name="chat_box" type="ChatBox" unique_id=1125601400 node_paths=PackedStringArray("scroll", "messages", "line_edit")]
|
||||
scroll = NodePath("panel/scroll_container")
|
||||
messages = NodePath("panel/scroll_container/v_box_container")
|
||||
line_edit = NodePath("line_edit")
|
||||
custom_minimum_size = Vector2(500, 300)
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
use std::i32;
|
||||
|
||||
use godot::{
|
||||
classes::{
|
||||
Engine, IVBoxContainer, InputEvent, LineEdit, Panel, RichTextLabel, ScrollContainer,
|
||||
@ -24,6 +26,8 @@ pub struct ChatBox {
|
||||
#[export]
|
||||
pub in_game: bool,
|
||||
|
||||
scroll_on_next_update: bool,
|
||||
|
||||
base: Base<VBoxContainer>,
|
||||
}
|
||||
|
||||
@ -57,6 +61,15 @@ impl IVBoxContainer for ChatBox {
|
||||
}
|
||||
}
|
||||
|
||||
fn process(&mut self, _: f64) {
|
||||
if self.scroll_on_next_update
|
||||
&& let Some(scroll) = &mut self.scroll
|
||||
{
|
||||
scroll.set_v_scroll(i32::MAX);
|
||||
self.scroll_on_next_update = false;
|
||||
}
|
||||
}
|
||||
|
||||
fn input(&mut self, event: Gd<InputEvent>) {
|
||||
if self.in_game && event.is_action_pressed("open_chat") {
|
||||
if let Some(line_edit) = &mut self.line_edit {
|
||||
@ -88,12 +101,7 @@ impl ChatBox {
|
||||
if let Some(messages) = &mut self.messages {
|
||||
messages.add_child(&message);
|
||||
}
|
||||
self.run_deferred(|s| {
|
||||
if let Some(scroll) = &mut s.scroll {
|
||||
scroll.set_h_scroll(i32::MAX);
|
||||
scroll.set_v_scroll(i32::MAX);
|
||||
}
|
||||
});
|
||||
self.scroll_on_next_update = true;
|
||||
}
|
||||
|
||||
pub fn on_submit(&mut self, message: GString) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user