Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Add sound To confirm button of new user
Browse files Browse the repository at this point in the history
    - Add sound to assets folder
    - Add soundplayer to new user menu
  • Loading branch information
Phoenixfirewingz committed Jun 16, 2023
1 parent 393144c commit 2c2447b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions SquareSmash.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<EmbeddedResource Include="assets\**" />
</ItemGroup>

<ItemGroup>
<None Remove="assets\sounds\click.wav" />
</ItemGroup>

<ItemGroup>
<Compile Update="renderer\Windows\PopUpWindow.axaml.cs">
<DependentUpon>PopUpWindow.axaml</DependentUpon>
Expand Down
Binary file added assets/sounds/click.wav
Binary file not shown.
7 changes: 3 additions & 4 deletions renderer/Windows/DiscWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Media;
using Avalonia.Threading;
Expand Down Expand Up @@ -110,8 +109,8 @@ public override void Render(DrawingContext context)
LastScore = Level.GetBall().GetScore();
if (LastScore > ScoreBoard.entry[0].Score)
{
Action<int,string> callback = FinishNewUser;
var popupWindow = new PopUpWindow(LastScore,callback);
Action<int, string> callback = FinishNewUser;
var popupWindow = new PopUpWindow(LastScore, callback);
var task = popupWindow.ShowDialog(this);
}
GameRestart = true;
Expand All @@ -121,7 +120,7 @@ public override void Render(DrawingContext context)
Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Render);
}

protected void FinishNewUser(int LastScoreData,string UserNameData)
protected void FinishNewUser(int LastScoreData, string UserNameData)
{
ScoreBoard.addScore(new(UserNameData, LastScoreData));
ScoreBoard.Save(ScoreBoard);
Expand Down
10 changes: 10 additions & 0 deletions renderer/Windows/PopUpWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using NAudio.Wave;
using SquareSmash.utils;
using System;

namespace SquareSmash.renderer.Windows
Expand All @@ -9,6 +11,13 @@ public partial class PopUpWindow : Window
private readonly Action<int, string> Callback;
private readonly int Score;

private void Play()
{
WaveOutEvent beepPlayer = new();
beepPlayer.Init(new WaveFileReader(AssetUtil.OpenEmbeddedFile("assets.sounds.click.wav")));
beepPlayer.Play();
}

public PopUpWindow()
{
Score = 0;
Expand All @@ -25,6 +34,7 @@ public PopUpWindow(int score, Action<int, string> callback)

private void OnButtonClick(object sender, RoutedEventArgs e)
{
Play();
if (TextInput.Text.Length >= 1 && TextInput.Text.Length <= 10)
{
Callback.Invoke(Score, TextInput.Text);
Expand Down

0 comments on commit 2c2447b

Please sign in to comment.