From cd18aa57fa0c11bf455132d0c764d1340455eed1 Mon Sep 17 00:00:00 2001 From: tpart Date: Thu, 29 Aug 2024 15:28:04 +0200 Subject: Automatically scroll chat to bottom when opened --- client/menu/chat/chat_open.tscn | 6 ++++-- client/menu/scroll_container_custom.gd | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'client/menu') diff --git a/client/menu/chat/chat_open.tscn b/client/menu/chat/chat_open.tscn index edd9f679..6150272d 100644 --- a/client/menu/chat/chat_open.tscn +++ b/client/menu/chat/chat_open.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=5 format=3 uid="uid://dbd6k56l4p0ls"] +[gd_scene load_steps=6 format=3 uid="uid://dbd6k56l4p0ls"] [ext_resource type="Script" path="res://menu/chat/chat_open.gd" id="1_dsl4a"] [ext_resource type="Material" uid="uid://beea1pc5nt67r" path="res://menu/theme/dark_blur_material.tres" id="1_isqmk"] [ext_resource type="Script" path="res://menu/blur_setup.gd" id="2_urbd2"] [ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="3_v7xmg"] +[ext_resource type="Script" path="res://menu/scroll_container_custom.gd" id="5_3mths"] [node name="ChatOpen" type="Control"] layout_mode = 3 @@ -38,7 +39,8 @@ material = ExtResource("1_isqmk") layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 -script = ExtResource("2_urbd2") +script = ExtResource("5_3mths") +auto_scroll_to_bottom = true [node name="Messages" type="VBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/ScrollContainerCustom"] layout_mode = 2 diff --git a/client/menu/scroll_container_custom.gd b/client/menu/scroll_container_custom.gd index cc578bb1..a456f644 100644 --- a/client/menu/scroll_container_custom.gd +++ b/client/menu/scroll_container_custom.gd @@ -21,9 +21,18 @@ class_name ScrollContainerCustom const SCROLL_SPEED := 1000. var velocity := 0. +@export var auto_scroll_to_bottom := false + func _init(): follow_focus = true +func _ready(): + if auto_scroll_to_bottom: + call_deferred("scroll_to_bottom") + +func scroll_to_bottom(): + set_deferred("scroll_vertical", get_v_scroll_bar().max_value) + func _process(delta): velocity = G.interpolate(velocity, 0., delta * 5.) velocity = 0. if abs(velocity) < .001 else velocity -- cgit v1.2.3-70-g09d2