From 449b95e036bc97ed275e60de80965b83875dc07e Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Fri, 22 Jul 2022 00:51:12 +0800 Subject: [PATCH] fix scrollcontainer keep bottom feature --- scripts/stages/ConsolePanel.cs | 11 +++++++---- scripts/user_interface/LabelConsole.cs | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/stages/ConsolePanel.cs b/scripts/stages/ConsolePanel.cs index 593f0cb..7e304ea 100644 --- a/scripts/stages/ConsolePanel.cs +++ b/scripts/stages/ConsolePanel.cs @@ -11,6 +11,7 @@ public enum LabelConsoleMessageType { public class ConsolePanel : Control { private LineEdit mCmdInput; private ScrollContainer mScrollbar; + private VScrollBar mScrollbarVChild; private VBoxContainer mMessageContainer; private PackedScene mTemplateLabelConsole; private Queue mMessageQueue = new Queue(); @@ -21,8 +22,10 @@ public class ConsolePanel : Control { mCmdInput = GetNode("CommandInput"); mScrollbar = GetNode("ScrollSet/Scrollbar"); + mScrollbarVChild = mScrollbar.GetVScrollbar(); mMessageContainer = GetNode("ScrollSet/Scrollbar/MessageContainer"); mCmdInput.Connect("text_entered", this, nameof(Proc_LineEdit_TextEntered)); + mScrollbarVChild.Connect("changed", this, nameof(Proc_ScrollbarVChild_Changed)); BallanceStalkerCore.StalkerManager.Singleton.EventControllerChanged += Proc_StalkerManager_EventControllerChanged; } @@ -73,10 +76,6 @@ public class ConsolePanel : Control { // set text target.SetText(strl, t); - // scroll to bottom - //var bar = mScrollbar.GetVScrollbar(); - //bar.Value = bar.MaxValue; - mScrollbar.ScrollVertical = (int)mScrollbar.GetVScrollbar().MaxValue; } private void Proc_LineEdit_TextEntered(string new_strl) { @@ -95,4 +94,8 @@ public class ConsolePanel : Control { } } + private void Proc_ScrollbarVChild_Changed() { + mScrollbar.ScrollVertical = (int)mScrollbarVChild.MaxValue; + } + } diff --git a/scripts/user_interface/LabelConsole.cs b/scripts/user_interface/LabelConsole.cs index 2dffbb6..7e38849 100644 --- a/scripts/user_interface/LabelConsole.cs +++ b/scripts/user_interface/LabelConsole.cs @@ -24,6 +24,7 @@ public class LabelConsole : Control { mRealLabel.Modulate = Colors.OrangeRed; break; } + this.RectMinSize = new Vector2(0, (mRealLabel.GetLineHeight() + mRealLabel.GetConstant("line_spacing")) * mRealLabel.GetLineCount()); } private void Proc_Label_ItemRectChanged() {