extends HFlowContainer var button_prefix="btn_map_" var disabled_mod_color=Color(0.3,0.3,0.3,1.0) signal map_changed # 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 else: if Gamestate.automatic_map_change_after>0: Gamestate.automatic_map_change_in-=1 if Gamestate.automatic_map_change_after>0 and Gamestate.automatic_map_change_in<=0: #do automatic mapchange Gamestate.automatic_map_change_in=Gamestate.automatic_map_change_after #reset var next_map_pick=null while next_map_pick==null: next_map_pick=get_children().pick_random() print("Selected random map="+str(next_map_pick.get_name())) if next_map_pick.name==button_prefix+Gamestate.getSelectedMap(): #picked the last map next_map_pick=null #force selecting another var saved_automatic_map_change_in=Gamestate.automatic_map_change_in #save number, to restore after simulated map button press next_map_pick.emit_signal("pressed") Gamestate.automatic_map_change_in=saved_automatic_map_change_in else: #no automatic mapchange for c in get_children(): if c.name==button_prefix+Gamestate.getSelectedMap(): var saved_automatic_map_change_in=Gamestate.automatic_map_change_in #save number, to restore after simulated map button press c.emit_signal("pressed") #select last map Gamestate.automatic_map_change_in=saved_automatic_map_change_in break func _on_btn_map(btn): map_changed.emit() 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) Gamestate.automatic_map_change_in=Gamestate.automatic_map_change_after #rest number if button pressed manually