Skip to content

Commit

Permalink
🔇 Implement mute button
Browse files Browse the repository at this point in the history
  • Loading branch information
tomrijnbeek committed Oct 1, 2023
1 parent 95865b3 commit a45c5bf
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
1 change: 1 addition & 0 deletions entities/item/HoveringItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public override void _Input(InputEvent @event)
{
result.Commit(inventory, item);
EmitSignal(nameof(ItemPlaced), this);
GetTree().SetInputAsHandled();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions entities/itemselect/ItemSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public override void _Input(InputEvent @event)
inventory.TryFindItem(mouseEvent.Position, out var item))
{
EmitSignal(nameof(ItemChosen), item);
GetTree().SetInputAsHandled();
}
}

Expand Down
50 changes: 50 additions & 0 deletions scenes/main/AudioButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Godot;

public sealed class AudioButton : TextureRect
{
private AudioStreamPlayer? audio;
private AnimationPlayer? animation;

private bool muted;

[Export]
public bool Muted
{
get => muted;
set
{
if (muted == value) return;
muted = value;
if (muted)
{
audio?.Stop();
animation?.Play("default");
}
else
{
audio?.Play();
animation?.PlayBackwards("default");
}
}
}

public override void _Ready()
{
audio = GetNode<AudioStreamPlayer>("AudioStreamPlayer");
animation = GetNode<AnimationPlayer>("AnimationPlayer");
if (muted)
{
audio?.Stop();
}
}

public override void _GuiInput(InputEvent @event)
{
base._GuiInput(@event);
if (@event is InputEventMouseButton { Pressed: true, ButtonIndex: (int) ButtonList.Left })
{
Muted = !Muted;
GetTree().SetInputAsHandled();
}
}
}
9 changes: 5 additions & 4 deletions scenes/main/TopHud.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=2]
[gd_scene load_steps=18 format=2]

[ext_resource path="res://assets/images/health_fill.png" type="Texture" id=1]
[ext_resource path="res://assets/images/backpack.png" type="Texture" id=2]
Expand All @@ -7,6 +7,7 @@
[ext_resource path="res://scenes/main/TopHud.cs" type="Script" id=5]
[ext_resource path="res://scenes/main/audio_button.png" type="Texture" id=6]
[ext_resource path="res://assets/audio/dungeon_banger.wav" type="AudioStream" id=7]
[ext_resource path="res://scenes/main/AudioButton.cs" type="Script" id=8]

[sub_resource type="AtlasTexture" id=1]
atlas = ExtResource( 6 )
Expand Down Expand Up @@ -50,7 +51,6 @@ filter_clip = true

[sub_resource type="Animation" id=9]
length = 0.8
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath(".:visible")
tracks/0/interp = 1
Expand Down Expand Up @@ -123,10 +123,11 @@ __meta__ = {
}

[node name="AudioButton" type="TextureRect" parent="."]
margin_left = 158.0
margin_right = 174.0
margin_left = 166.0
margin_right = 182.0
margin_bottom = 16.0
texture = SubResource( 1 )
script = ExtResource( 8 )
__meta__ = {
"_aseprite_wizard_config_": {
"layer": "",
Expand Down
2 changes: 1 addition & 1 deletion scenes/story/Dialogue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void _Process(float delta)
text.PercentVisible = Math.Min(text.PercentVisible + 0.5f * delta, 1.0f);
}

public override void _Input(InputEvent @event)
public override void _UnhandledInput(InputEvent @event)
{
if (!Visible)
{
Expand Down

0 comments on commit a45c5bf

Please sign in to comment.