seperate ui controls from gameplay controls, scrolling controls screen
This commit is contained in:
parent
3c69e4d14d
commit
ab094fd6ce
8 changed files with 273 additions and 71 deletions
39
objects/hud/scroll_follow_focus.gd
Normal file
39
objects/hud/scroll_follow_focus.gd
Normal file
|
@ -0,0 +1,39 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue