diff --git a/src/scripts/Autoloads/console.gd b/src/scripts/Autoloads/console.gd index 9954abe..2585ffc 100644 --- a/src/scripts/Autoloads/console.gd +++ b/src/scripts/Autoloads/console.gd @@ -1,8 +1,12 @@ extends Node2D +var auto_scroll_enabled := true +@onready var lbl_text = $CanvasLayer/ColorRectBG/VBoxContainer/ScrollContainer/LabelText +@onready var sb = null # Called when the node enters the scene tree for the first time. func _ready() -> void: + sb = lbl_text.get_v_scroll_bar() pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -14,6 +18,7 @@ func _process(delta: float) -> void: #tween console to -y 240 target_y = -$CanvasLayer/ColorRectBG.size.y tween.tween_property($CanvasLayer/ColorRectBG, "position:y", target_y, 0.13).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT) + pass func isOpen() -> bool: @@ -26,4 +31,18 @@ func print(...args) -> void: print(line) # append to your console label - $CanvasLayer/ColorRectBG/VBoxContainer/ScrollContainer/LabelText.text += "\n" + line + lbl_text.text += "\n" + line + + if auto_scroll_enabled: + lbl_text.scroll_to_line(lbl_text.get_line_count() - 1) + + +func _on_label_text_gui_input(event: InputEvent) -> void: + if event is InputEventMouseButton and event.button_index in [MOUSE_BUTTON_WHEEL_UP, MOUSE_BUTTON_WHEEL_DOWN]: + auto_scroll_enabled = sb.value + sb.page >= sb.max_value - 10.0 + elif event is InputEventMouseButton and event.is_pressed(): + auto_scroll_enabled = sb.value + sb.page >= sb.max_value - 10.0 + elif event is InputEventMouseMotion and (event.button_mask & MOUSE_BUTTON_LEFT): + # Only update when dragging with left mouse button + auto_scroll_enabled = sb.value + sb.page >= sb.max_value - 10.0 + pass # Replace with function body. diff --git a/src/scripts/Autoloads/console.tscn b/src/scripts/Autoloads/console.tscn index 9932c7d..50070ab 100644 --- a/src/scripts/Autoloads/console.tscn +++ b/src/scripts/Autoloads/console.tscn @@ -50,3 +50,5 @@ layout_mode = 2 size_flags_horizontal = 3 caret_blink = true caret_force_displayed = true + +[connection signal="gui_input" from="CanvasLayer/ColorRectBG/VBoxContainer/ScrollContainer/LabelText" to="." method="_on_label_text_gui_input"]