superstar_v2/DBObj/SongList.cs

173 lines
4.9 KiB
C#
Raw Normal View History

using DualScreenDemo;
using System;
using System.IO;
2025-08-08 16:31:26 +08:00
using System.Numerics;
using System.Windows.Navigation;
namespace DBObj
{
public class SongList
{
2025-07-17 18:08:22 +08:00
private static bool isWelcome = true;
public static SongData welcome;
2025-08-08 16:32:54 +08:00
public static SongData close;
private static SongData publicPlaying = null;
private static List<SongData> publicSong = new();
2025-08-08 16:32:54 +08:00
private static SongData playing = null;
private static List<SongData> not_played = new List<SongData>();
private static List<SongData> played = new List<SongData>();
public static List<SongData> PublicSong() => publicSong;
public static SongData Current()
{
Console.WriteLine(not_played.Count + " Current " + playing);
2025-08-08 16:32:54 +08:00
return (playing == null) ? publicPlaying : playing;
}
public static SongData Next()
{
if (playing != null)
{
playing.SetState(PlayState.Played);
played.Add(playing);
playing = null;
}
if (not_played.Count <= 0)
return NextPublicSong();
else
return NextUserSong();
}
private static SongData NextUserSong()
{
playing = not_played[0];
not_played.RemoveAt(0);
if (!playing.FileExistsInServers())
{
playing.SetState(PlayState.NoFile);
played.Add(playing);
playing = null;
if (not_played.Count <= 0)
return NextPublicSong();
else
return NextUserSong();
}
playing.SetState(PlayState.Playing);
UpdateNextSongLabel();
return playing;
}
private static SongData NextPublicSong()
{
2025-08-08 16:32:54 +08:00
if (Program.room.IsClose())
{
2025-07-17 18:08:22 +08:00
publicPlaying = close;
2025-08-08 16:32:54 +08:00
}
else if (Program.room.IsOpen() && isWelcome)
{
2025-07-17 18:08:22 +08:00
isWelcome = false;
publicPlaying = welcome;
2025-08-08 16:32:54 +08:00
}
else
{
2025-07-17 18:08:22 +08:00
publicPlaying = publicSong[0];
publicSong.RemoveAt(0);
publicSong.Add(publicPlaying);
}
2025-08-08 16:32:54 +08:00
return publicPlaying;
}
public static List<SongData> GetHistory()
{
List<SongData> History = [.. played];
if (playing != null) History.Add(playing);
History.AddRange(not_played);
return History;
}
public static void Add(SongData song)
{
if (song.FileExistsInServers())
{
not_played.Add(new SongData(song, PlayState.NotPlayed));
// PrimaryForm.Instance.AddSongCount(songData.Number);
chkCut();
}
else
{
played.Add(new SongData(song, PlayState.NoFile));
}
2025-08-08 16:32:54 +08:00
}
2025-08-08 16:31:26 +08:00
2025-08-08 16:32:54 +08:00
public static void Cancel(SongData song)
2025-08-08 16:31:26 +08:00
{
2025-08-08 16:32:54 +08:00
not_played.Remove(song);
played.Remove(song);
chkCut();
2025-08-08 16:31:26 +08:00
}
public static void Insert(SongData song)
{
2025-08-08 16:32:54 +08:00
if (song.FileExistsInServers())
{
not_played.Insert(0, new SongData(song, PlayState.InsertPlayback));
chkCut();
}
else
{
played.Add(new SongData(song, PlayState.NoFile));
}
2025-08-08 16:32:54 +08:00
}
private static void chkCut()
{
if (playing == null)
{
if (PrimaryForm.Instance.InvokeRequired)
PrimaryForm.Instance.Invoke(new System.Action(() => PrimaryForm.Instance.videoPlayerForm.PlayNextSong()));
else
PrimaryForm.Instance.videoPlayerForm.PlayNextSong();
2025-08-08 16:32:54 +08:00
}
else
{
UpdateNextSongLabel();
}
}
2025-08-08 16:32:54 +08:00
public static void UpdateNextSongLabel()
{
2025-08-08 16:32:54 +08:00
if (Program.room.IsClose())
{
VideoPlayerForm.overlayForm.UpdateTopLeftLabel(" ");
2025-08-08 16:32:54 +08:00
}
else
{
VideoPlayerForm.overlayForm.UpdateTopLeftLabel(
(not_played.Count > 0) ? not_played[0].next_song_text() : "目前沒有下一首,請踴躍點歌!!!"
);
}
2025-08-08 16:32:54 +08:00
}
public static void roomClose()
{
SongData song;
while (not_played.Count > 0)
{
song = not_played[0];
not_played.RemoveAt(0);
song.SetState(PlayState.Skipped);
played.Add(song);
}
}
public static void clearSong()
{
2025-07-17 18:08:22 +08:00
isWelcome = true;
not_played.Clear();
played.Clear();
}
2025-08-08 16:32:54 +08:00
}
}