Break out sound buttons to test scene
This commit is contained in:
parent
cbd624c53d
commit
f174092b7f
48
Node2D.gd
48
Node2D.gd
|
@ -2,8 +2,6 @@ extends Node2D
|
|||
|
||||
var PC = load('PC.tscn')
|
||||
var PCs = []
|
||||
var inst_buttons = []
|
||||
var sfx_buttons = []
|
||||
|
||||
func _ready():
|
||||
Engine.set_target_fps(60)
|
||||
|
@ -23,52 +21,6 @@ func _ready():
|
|||
# PCs[-1].material.set_shader_param('palette', SpriteLoader.character_battle_sprite_palette_textures[45])
|
||||
# PCs[-1].texture = SpriteLoader.weapon_textures['Fist']
|
||||
# add_child(PCs[-1])
|
||||
_create_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 = 'Play #%02X' % i
|
||||
btn.align = Button.ALIGN_CENTER
|
||||
btn.set_position(Vector2((i%8)*36, 200 + (i/8)*12))
|
||||
btn.set_scale(Vector2(0.5, 0.5))
|
||||
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%8)*36, 264 + (i/8)*12))
|
||||
btn.set_scale(Vector2(0.5, 0.5))
|
||||
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
|
||||
|
||||
|
||||
func _on_OptionButton_item_selected(ID):
|
||||
for pc in PCs:
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://palette_mat.tres" type="Material" id=1]
|
||||
[ext_resource path="res://Node2D.gd" type="Script" id=2]
|
||||
[ext_resource path="res://test/audio_system.tscn" type="PackedScene" id=3]
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
anchor_right = 1.0
|
||||
|
@ -23,4 +24,7 @@ text = "Stand"
|
|||
items = [ "Stand", null, false, 0, null, "Guard", null, false, 1, null, "Walk", null, false, 2, null, "Down", null, false, 3, null, "R_Swing", null, false, 4, null, "L_Swing", null, false, 5, null, "Cheer", null, false, 6, null, "Recoil", null, false, 7, null, "Chant", null, false, 8, null ]
|
||||
selected = 0
|
||||
|
||||
[node name="audio_system" parent="." instance=ExtResource( 3 )]
|
||||
position = Vector2( 0, 400 )
|
||||
|
||||
[connection signal="item_selected" from="Node2D/OptionButton" to="Node2D" method="_on_OptionButton_item_selected"]
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
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 = 'Play #%02X' % i
|
||||
btn.align = Button.ALIGN_CENTER
|
||||
btn.set_position(Vector2((i%8)*72, (i/8)*24))
|
||||
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%8)*72, 128 + (i/8)*24))
|
||||
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()
|
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://test/audio_system.gd" type="Script" id=1]
|
||||
|
||||
[node name="audio_system" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
Loading…
Reference in New Issue