Added bg_sound manager and according ESC command.

Started transitions scene.
This commit is contained in:
Julian Murgia
2021-03-24 14:12:40 +01:00
parent 4acb971d54
commit 40dd4a6718
79 changed files with 1240 additions and 456 deletions

View File

@@ -15,7 +15,7 @@ The scene MUST contain the 2 following nodes:
# Define the actual container node to add items as children of. Should be a Container.
export(NodePath) var items_container
export(NodePath) var inventory_ui_container
onready var all_items = $ESCORIA_ALL_ITEMS
var items_ids_in_inventory : Dictionary = {} # { item_id : TextureButton}
@@ -30,10 +30,10 @@ func _ready():
escoria.register_object(self)
if items_container == null or items_container.is_empty():
if inventory_ui_container == null or inventory_ui_container.is_empty():
escoria.logger.report_errors(self.get_path(), ["Items container is empty."])
return
for c in get_node(items_container).get_items():
for c in get_node(inventory_ui_container).get_items():
items_ids_in_inventory[c.item_id] = c
# c.connect("pressed", escoria.inputs_manager, "_on_inventory_item_pressed", [c.item_id])
@@ -55,7 +55,7 @@ func add_new_item_by_id(item_id : String) -> void:
"Check item's id in ESCORIA_ALL_ITEMS scene."])
var item_inventory_button = all_items.get_inventory_item(item_id).duplicate()
items_ids_in_inventory[item_id] = item_inventory_button
get_node(items_container).add_item(item_inventory_button)
get_node(inventory_ui_container).add_item(item_inventory_button)
# Add the item to inventory
if !escoria.esc_runner.objects.has(item_id):
@@ -90,7 +90,7 @@ func remove_item_by_id(item_id : String) -> void:
item_inventory_button.disconnect("inventory_item_unfocused",
escoria.inputs_manager, "_on_mouse_exited_inventory_item")
get_node(items_container).remove_item(item_inventory_button)
get_node(inventory_ui_container).remove_item(item_inventory_button)
item_inventory_button.queue_free()
items_ids_in_inventory.erase(item_id)

View File

@@ -0,0 +1,42 @@
extends Control
class_name ESCBackgroundMusic
func get_class():
return "ESCBackgroundMusic"
onready var stream = $AudioStreamPlayer
var state = "default"
export var global_id = "bg_music"
func game_cleared():
set_state("off", true)
self.disconnect("tree_exited", escoria.esc_runner, "object_exit_scene")
escoria.register_object(self)
func set_state(p_state, p_force = false):
# If already playing this stream, keep playing, unless p_force
if p_state == state and not p_force and stream.is_playing():
return
state = p_state
# If state is "off"/"default", turn off music
if state == "off" or state == "default":
stream.stream = null
return
var resource = load(p_state)
stream.stream = resource
if stream.stream:
resource.set_loop(true)
if ProjectSettings.has_setting("escoria/sound/music_volume"):
stream.volume_db = ProjectSettings.get_setting("escoria/sound/music_volume")
stream.play()
func _ready():
escoria.register_object(self)

View File

@@ -0,0 +1,16 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://addons/escoria-core/game/scenes/sound/bg_music.gd" type="Script" id=1]
[node name="bg_music" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -1680.0
margin_bottom = -1050.0
mouse_filter = 2
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]

View File

@@ -0,0 +1,41 @@
extends Control
class_name ESCBackgroundSound
func get_class():
return "ESCBackgroundSound"
onready var stream = $AudioStreamPlayer
var state = "default"
export var global_id = "bg_sound"
func game_cleared():
stream.stream = null
escoria.register_object(self)
func set_state(p_state, p_force = false):
# If already playing this stream, keep playing, unless p_force
if p_state == state and not p_force and stream.is_playing():
return
state = p_state
# If state is "off"/"default", turn off music
if state == "off" or state == "default":
stream.stream = null
return
var resource = load(p_state)
stream.stream = resource
if stream.stream:
resource.set_loop(false)
if ProjectSettings.has_setting("escoria/sound/sound_volume"):
stream.volume_db = ProjectSettings.get_setting("escoria/sound/sound_volume")
stream.play()
func _ready():
escoria.register_object(self)

View File

@@ -0,0 +1,16 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://addons/escoria-core/game/scenes/sound/bg_sound.gd" type="Script" id=1]
[node name="bg_sound" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -1680.0
margin_bottom = -1050.0
mouse_filter = 2
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

View File

@@ -0,0 +1,28 @@
extends ColorRect
export(String, "fade_black", "fade_white", "transition_in", "transition_out") var transition_name
# Reference to the _AnimationPlayer_ node
onready var _anim_player := $AnimationPlayer
signal transition_done
func _ready() -> void:
# Plays the animation backward to fade in
_anim_player.play_backwards(transition_name)
func fade_out() -> void:
# Plays the Fade animation and wait until it finishes
_anim_player.play(transition_name)
yield(_anim_player, "animation_finished")
emit_signal("transition_done")
func fade_in() -> void:
# Plays the Fade animation and wait until it finishes
_anim_player.play_backwards(transition_name)
yield(_anim_player, "animation_finished")
emit_signal("transition_done")

View File

@@ -0,0 +1,83 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://addons/escoria-core/game/scenes/transitions/transition.gd" type="Script" id=1]
[ext_resource path="res://addons/escoria-core/game/scenes/transitions/shaders/transition.material" type="Material" id=2]
[sub_resource type="Animation" id=1]
resource_name = "fade_black"
length = 0.5
tracks/0/type = "value"
tracks/0/path = NodePath(".:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.5 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Color( 0, 0, 0, 0 ), Color( 0, 0, 0, 1 ) ]
}
[sub_resource type="Animation" id=2]
resource_name = "fade_white"
length = 0.5
tracks/0/type = "value"
tracks/0/path = NodePath(".:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.5 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
}
[sub_resource type="Animation" id=3]
resource_name = "transition_in"
tracks/0/type = "value"
tracks/0/path = NodePath(".:material:shader_param/cutoff")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 1 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 0.0, 1.0 ]
}
[sub_resource type="Animation" id=4]
resource_name = "transition_out"
tracks/0/type = "value"
tracks/0/path = NodePath(".:material:shader_param/cutoff")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 1 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 1.0, 0.0 ]
}
[node name="scene_transition" type="ColorRect"]
material = ExtResource( 2 )
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
transition_name = "transition_out"
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/fade_black = SubResource( 1 )
anims/fade_white = SubResource( 2 )
anims/transition_in = SubResource( 3 )
anims/transition_out = SubResource( 4 )