extends Node2D var inst_buttons = [] var sfx_buttons = [] func _create_sfx_buttons(): var disable_btn := !SoundLoader.has_loaded_audio_samples for i in SoundLoader.INST_NUM: var btn = Button.new() btn.text = 'Inst #%02X' % i btn.align = Button.ALIGN_CENTER btn.set_position(Vector2((i%7)*50, (i/7)*24)) btn.rect_min_size.x = 48 add_child(btn) btn.connect('pressed', SoundLoader, 'play_sample', [i]) inst_buttons.append(btn) btn.disabled = disable_btn for i in SoundLoader.SFX_NUM: var btn = Button.new() btn.text = 'SFX #%02X' % i btn.align = Button.ALIGN_CENTER btn.set_position(Vector2((i%4)*50, 156 + (i/4)*24)) btn.rect_min_size.x = 48 add_child(btn) btn.connect('pressed', SoundLoader, 'play_sfx', [i]) sfx_buttons.append(btn) btn.disabled = disable_btn if disable_btn: SoundLoader.connect('audio_samples_loaded', self, '_enable_sfx_buttons') SoundLoader.connect('audio_inst_sample_loaded', self, '_enable_inst_button') SoundLoader.connect('audio_sfx_sample_loaded', self, '_enable_sfx_button') func _enable_sfx_buttons(): for btn in sfx_buttons: btn.disabled = false for btn in inst_buttons: btn.disabled = false func _enable_sfx_button(id: int): # NB: This assumes sequential loading (may change, probably won't) for i in id+1: sfx_buttons[i].disabled = false func _enable_inst_button(id: int): # NB: This assumes sequential loading (may change, probably won't) for i in id+1: inst_buttons[i].disabled = false # Called when the node enters the scene tree for the first time. func _ready() -> void: _create_sfx_buttons()