amb-crawl/chara_select.gd

33 lines
901 B
GDScript
Executable File

extends Control
var children={}
func _ready():
for child in get_children(true): children[child]={'hover':false,'active':false}
for child in children.keys():
child.pressed.connect(focused.bind(child))
child.mouse_entered.connect(hover.bind(child,true))
child.mouse_exited.connect(hover.bind(child,false))
func _draw():
var colour=''
var childs=children.keys()
for i in range(len(children)):
for j in range(i,len(children)):
if darken([i,j],childs): colour='#444444'
else: colour='#aaaaaa'
draw_line(childs[i].position+(childs[i].size/2),childs[j].position+(childs[i].size/2),colour)
func focused(this):
children[this]['active']=!children[this]['active']
queue_redraw()
func hover(this,now):
children[this]['hover']=now
queue_redraw()
func darken(nums,keys):
for num in nums:
if children[keys[num]]['active'] or children[keys[num]]['hover']: return true
return false