qtc-net-client/qtc-net-client-2/Forms/TokenJackpotSpinner.cs
AlanMoonbase 88806e93a4 Implement Jackpot Win Animation (> 200)
Change Currency Name To "Q's" (i could probably come up with a better name here)
2025-06-23 14:03:57 -07:00

102 lines
3.0 KiB
C#

using qtc_net_client_2.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace qtc_net_client_2.Forms
{
public partial class TokenJackpotSpinner : Form
{
public int TokensWon { get; private set; }
private bool AllowClose = false;
private AudioService _audioService = new();
public TokenJackpotSpinner()
{
InitializeComponent();
}
private async void TokenJackpotSpinner_Load(object sender, EventArgs e)
{
btnClaim.Enabled = false;
AllowClose = false;
_audioService.OnSoundEnded += _audioService_OnSoundEnded;
await StartSpinAnimation(lblTokensWon);
}
private void TokenJackpotSpinner_FormClosed(object sender, FormClosedEventArgs e)
{
DialogResult = DialogResult.OK;
_audioService.Dispose();
Close();
}
private void TokenJackpotSpinner_FormClosing(object sender, FormClosingEventArgs e)
{
if (!AllowClose) e.Cancel = true;
}
private void btnClaim_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}
private void _audioService_OnSoundEnded(object? sender, SoundEndedEventArgs e)
{
switch(e.EventString)
{
case "sndTokenWin":
DetermineWinAnim();
break;
}
}
public async Task StartSpinAnimation(Label label)
{
if (label.IsHandleCreated)
{
Random rnd = new Random();
_audioService.PlaySoundEffect("sndTokenSpinLoop");
while (_audioService.OutputDevice?.PlaybackState == NAudio.Wave.PlaybackState.Playing)
{
label.BeginInvoke(delegate () { label.Text = $"{rnd.Next(0, 300)} Q's Won"; });
await Task.Delay(10);
}
var win = rnd.Next(0, 300);
label.BeginInvoke(delegate ()
{
label.Text = $"{win} Q's Won";
btnClaim.Enabled = true;
_audioService.PlaySoundEffectWithEventString("sndTokenWin", "sndTokenWin");
});
AllowClose = true;
TokensWon = win;
}
}
public void DetermineWinAnim()
{
switch(TokensWon)
{
case > 200:
pbHornLeft.BeginInvoke(delegate () { pbHornLeft.Visible = true; });
pbHornRight.BeginInvoke(delegate () { pbHornRight.Visible = true; });
_audioService.PlaySoundEffect("sndTokenJackpot");
break;
}
}
}
}