teststrecke-game/scripts/map_selection.gd

32 lines
897 B
GDScript3
Raw Permalink Normal View History

2024-11-09 12:47:13 +00:00
extends HFlowContainer
var button_prefix="btn_map_"
var disabled_mod_color=Color(0.3,0.3,0.3,1.0)
2024-11-09 23:23:08 +00:00
signal map_changed
2024-11-09 12:47:13 +00:00
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
for btn in get_children():
btn.pressed.connect(_on_btn_map.bind(btn))
if len(Gamestate.getSelectedMap())<=0: #no map selected (ie on startup)
get_children()[0].emit_signal("pressed") #preselect first map in list
2024-11-09 23:45:22 +00:00
else:
for c in get_children():
if c.name==button_prefix+Gamestate.getSelectedMap():
c.emit_signal("pressed")
break
2024-11-09 12:47:13 +00:00
func _on_btn_map(btn):
2024-11-09 23:23:08 +00:00
map_changed.emit()
2024-11-09 12:47:13 +00:00
for b in get_children():
b.self_modulate=disabled_mod_color #show all others disabled
btn.self_modulate=Color(1,1,1,1) #show selected enabled
var btn_name=btn.name
var mapname=btn_name.erase(0,len(button_prefix))
print("Selected Map="+str(mapname))
Gamestate.setSelectedMap(mapname)