Char select grid upgrade

This commit is contained in:
2025-12-30 23:09:15 +11:00
parent ec813331f9
commit 36df70e6b2
3 changed files with 37 additions and 22 deletions

View File

@@ -1,32 +1,47 @@
extends Control
var children={}
var binds=[[],[],[],[],[],[]]
const maps=[[0,1,2],[2,3,4],[4,5,0],[1,3,5]] # Can you, mathematically, select 3 numbers from 1 input number such that each output number is selected by a unique pair of inputs?
# I can't.
func _ready():
for child in get_children(true): children[child]={'hover':false,'active':false}
for child in children.keys():
var i=0
for child in get_children(true):
children[child]=0
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)
child.mouse_entered.connect(hover.bind(child,1))
child.mouse_exited.connect(hover.bind(child,-1))
for n in maps[i]: binds[n].append(child)
i+=1
func focused(this):
children[this]['active']=!children[this]['active']
var adjust=int(children[this]>2)*2-1 # >0 means "is selected", ie. deselection event, ie. this down, others up.
children[this]-=25*adjust
for child in children.keys():
children[child]+=10*adjust
child.visible=children[child]>-15
queue_redraw()
func hover(this,now):
children[this]['hover']=now
children[this]+=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
func _draw():
for pair in binds:
calc_draw(pair)
func calc_draw(pair):
var colour=''
var score=children[pair[0]]+children[pair[1]]
if score<-10: return # Hidden by other selections
var p0=pair[0].position; var p1=pair[1].position; var s0=pair[0].size; var s1=pair[1].size; var dist=p1-p0
colour='#444444' # Unselected
if score>0: # Selected
colour='#aaaaaa'
# These need to be turned into buttons that show/hide instead.
draw_circle(p0+(s0/2)+dist/2+Vector2(-dist.y,dist.x).normalized()*15,10,colour) # rotated left
draw_circle(p0+(s0/2)+dist/2+Vector2(dist.y,-dist.x).normalized()*15,10,colour) # rotated right
if score>6: # Detail view, should also be buttons.
pass
draw_line(p0+(s0/2),p1+(s1/2),colour) # This depends on selected/unselected state so it can't occur until after that, at least.

View File

@@ -28,12 +28,12 @@ M
F
HL
Healer, Medic
Healer, Packrat
M
F cute (healer)
HM
Servant, Acrobat, Botanist
Maid/Butler, Botanist
M
F

View File

@@ -12,7 +12,7 @@ config_version=5
config/name="amb-crawl"
run/main_scene="res://ui.tscn"
config/features=PackedStringArray("4.4", "GL Compatibility")
config/features=PackedStringArray("4.5", "GL Compatibility")
config/icon="res://icon.svg"
[autoload]