39 lines
1 KiB
GDScript
39 lines
1 KiB
GDScript
extends ScrollContainer
|
|
|
|
|
|
onready var up_arrow: TextureRect = $"%UpArrow"
|
|
onready var down_arrow: TextureRect = $"%DownArrow"
|
|
onready var controls_v_box: VBoxContainer = $"%ControlsVBox"
|
|
|
|
|
|
func _ready() -> void:
|
|
yield(get_tree(), "idle_frame")
|
|
get_viewport().connect("gui_focus_changed", self, "_on_focus_changed")
|
|
connect("visibility_changed", self, "_on_visibility_changed")
|
|
|
|
|
|
func _exit_tree() -> void:
|
|
get_viewport().disconnect("gui_focus_changed", self, "_on_focus_changed")
|
|
|
|
|
|
func _on_focus_changed(focused: Control) -> void:
|
|
if is_a_parent_of(focused):
|
|
var foc_rect := focused.get_global_rect()
|
|
if not get_global_rect().encloses(foc_rect):
|
|
var direction := sign(foc_rect.position.y - get_global_rect().position.y)
|
|
scroll_vertical += direction * 14.0
|
|
|
|
if scroll_vertical < 1.0:
|
|
up_arrow.visible = false
|
|
else:
|
|
up_arrow.visible = true
|
|
|
|
if scroll_vertical > 35.0:
|
|
down_arrow.visible = false
|
|
else:
|
|
down_arrow.visible = true
|
|
|
|
|
|
func _on_visibility_changed() -> void:
|
|
scroll_vertical = 0.0
|
|
up_arrow.visible = false
|