From e787918be80dfc6f9371dc4793bb91ae093f02d4 Mon Sep 17 00:00:00 2001 From: jasonchenwork Date: Wed, 6 Aug 2025 09:19:34 +0800 Subject: [PATCH] =?UTF-8?q?202508041725=20=E6=90=96=E6=8E=A7=E5=99=A8=20?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=AD=8C=E6=9B=B2=E5=85=88=E5=88=A4=E6=96=B7?= =?UTF-8?q?=E5=8C=85=E5=BB=82=E7=8B=80=E6=85=8B=20=E6=90=96=E6=8E=A7?= =?UTF-8?q?=E5=99=A8=20=E5=8A=A0=E5=85=A5=E5=BE=8C=E5=8F=AA=E9=A1=AF?= =?UTF-8?q?=E7=A4=BA=E6=AD=8C=E6=9B=B2=E5=90=8D=E7=A8=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CommandHandler.cs | 431 ++++++++-------------------------------------- DBObj/SongData.cs | 5 +- Program.cs | 2 +- 3 files changed, 70 insertions(+), 368 deletions(-) diff --git a/CommandHandler.cs b/CommandHandler.cs index 3caadfe..c43015c 100644 --- a/CommandHandler.cs +++ b/CommandHandler.cs @@ -13,9 +13,6 @@ namespace DualScreenDemo private readonly int _maxHistoryLength = 6; // 最多保留 6 筆 public static readonly Queue _indataHistory = new Queue(); /* 顯示按鈕設定 */ - private int _wrongInputCountfor62 = 0; // 錯誤輸入計數器 - private int _wrongInputCountfor61 = 0; // 錯誤輸入計數器 - private const int MaxWrongLimit = 3; // 錯誤輸入限制次數 private readonly SQLManager songListManager; public CommandHandler(SQLManager songListManager) @@ -33,15 +30,13 @@ namespace DualScreenDemo switch (indata) { case "A261A4": // 輸入 - HandleInputA(); + HandleInput("a"); break; case "A262A4": // 插播 - HandleInputB(); + HandleInput("b"); break; case "A263A4": ClearDisplay(); - _wrongInputCountfor62 = 0; // 重置計數器 - _wrongInputCountfor61 = 0; // 重置計數器 _indataHistory.Clear(); // 清空歷史紀錄 break; case "A268A4": @@ -199,7 +194,7 @@ namespace DualScreenDemo } } - void InvokeAction(Action action) + static void InvokeAction(Action action) { if (OverlayForm.MainForm.InvokeRequired) { @@ -213,39 +208,21 @@ namespace DualScreenDemo - private static void SkipToNextSong() + private void SkipToNextSong() { - if (PrimaryForm.Instance.InvokeRequired) - PrimaryForm.Instance.Invoke(new System.Action(() => PrimaryForm.Instance.videoPlayerForm.PlayNextSong())); - else - PrimaryForm.Instance.videoPlayerForm.PlayNextSong(); - - OverlayForm.MainForm.Invoke(new System.Action(() => { OverlayForm.MainForm.ShowTopRightEchoLabel("標準迴音"); } ) ); + InvokeAction(() => PrimaryForm.Instance.videoPlayerForm.PlayNextSong()); + InvokeAction(() => OverlayForm.MainForm.ShowTopRightEchoLabel("標準迴音")); } - private static void ReplayCurrentSong() + private void ReplayCurrentSong() { - if (PrimaryForm.Instance.InvokeRequired) - { - PrimaryForm.Instance.Invoke(new System.Action(() => PrimaryForm.Instance.videoPlayerForm.ReplayCurrentSong())); - } - else - { - PrimaryForm.Instance.videoPlayerForm.ReplayCurrentSong(); - } + InvokeAction(() => PrimaryForm.Instance.videoPlayerForm.ReplayCurrentSong()); } private static void PauseOrResumeSong() { - if (PrimaryForm.Instance.InvokeRequired) - { - PrimaryForm.Instance.Invoke(new System.Action(() => PrimaryForm.Instance.videoPlayerForm.PauseOrResumeSong())); - } - else - { - PrimaryForm.Instance.videoPlayerForm.PauseOrResumeSong(); - } + InvokeAction(() => PrimaryForm.Instance.videoPlayerForm.PauseOrResumeSong()); } public static void ToggleMute() @@ -277,205 +254,63 @@ namespace DualScreenDemo } - private void HandleInputA() + private void HandleInput(string input) { - - - OverlayForm.displayTimer.Stop(); - string input = "a"; - - // 輸入歌曲 - string songNumber = OverlayForm.ReadSongNumber(); - //Console.WriteLine("輸入A " + songNumber + " readyForSongListInput : " + readyForSongListInput); - var song = songListManager.SearchSongByNumber(songNumber); - - - if (readyForSongListInput) { - - if (OverlayForm.MainForm.InvokeRequired) + InvokeAction(() => { - OverlayForm.MainForm.Invoke(new System.Action(() => - { - Console.WriteLine("F sign for input :" + input); - OverlayForm.MainForm.OnUserInput(input); - })); - } - else - { - Console.WriteLine("A sign for input :" + input); + Console.WriteLine("F sign for input :" + input); OverlayForm.MainForm.OnUserInput(input); - } + }); } else { - if (OverlayForm.MainForm.InvokeRequired) - { - OverlayForm.MainForm.Invoke(new System.Action(() => + InvokeAction(() => + { + OverlayForm.displayTimer.Stop(); + string songNumber = OverlayForm.ReadSongNumber(); + var song = songListManager.SearchSongByNumber(songNumber); + ClearDisplay(); + if (song != null) { - if (song != null) + if (Program.room.IsOpen()) { - ClearDisplay(); - OverlayForm.MainForm.displayLabel.Text = String.Format("已點歌曲:{0}", song); - SongList.Add(song); - OverlayForm.MainForm.topLeftLabel.Visible = false; - OverlayForm.displayTimer.Start(); + if (input.Equals("a")) + { + OverlayForm.MainForm.displayLabel.Text = String.Format("已點歌曲:{0}", song); + SongList.Add(song); + } + else + { + OverlayForm.MainForm.displayLabel.Text = String.Format("插播歌曲:{0}", song); + SongList.Insert(song); + } } else { - ClearDisplay(); - _wrongInputCountfor61++; - if(_wrongInputCountfor61 <= MaxWrongLimit) - { - string old =""; - OverlayForm.MainForm.displayLabel.Text = check_control(old); - } - else - { - OverlayForm.MainForm.displayLabel.Text = "輸入錯誤!!!"; - _indataHistory.Clear(); // 清空歷史紀錄 - _wrongInputCountfor61 = 0; // 重置計數器 - } - OverlayForm.MainForm.topLeftLabel.Visible = false; - OverlayForm.displayTimer.Start(); + OverlayForm.MainForm.displayLabel.Text = "包廂己關閉"; } - })); - } - else - { - if (song != null) - { - ClearDisplay(); - OverlayForm.MainForm.displayLabel.Text = String.Format("{0}", song); - SongList.Add(song); - OverlayForm.MainForm.topLeftLabel.Visible = false; - OverlayForm.displayTimer.Start(); + + _indataHistory.Clear(); // 清空歷史紀錄 } else - { - ClearDisplay(); - _wrongInputCountfor61++; - if(_wrongInputCountfor61 <= MaxWrongLimit) - { - string old =""; - OverlayForm.MainForm.displayLabel.Text = check_control(old); - } - else - { - OverlayForm.MainForm.displayLabel.Text = "輸入錯誤!!!"; - _indataHistory.Clear(); // 清空歷史紀錄 - _wrongInputCountfor61 = 0; // 重置計數器 - } - OverlayForm.MainForm.topLeftLabel.Visible = false; - OverlayForm.displayTimer.Start(); - } - } + OverlayForm.MainForm.displayLabel.Text = check_control(); + OverlayForm.MainForm.topLeftLabel.Visible = false; + OverlayForm.displayTimer.Start(); + }); } } - private string check_control(string old){ - foreach(string item in _indataHistory) + private string check_control(){ + string str = ""; + foreach (string item in _indataHistory) { - if(item == "A261A4") - old += "#"; - else if(item == "A262A4") - old += "*"; - } - return old; - } - - - private void HandleInputB() - { - - OverlayForm.displayTimer.Stop(); - string input = "b"; - - - string songNumber = OverlayForm.ReadSongNumber(); - var song = songListManager.SearchSongByNumber(songNumber); - - - - if (readyForSongListInput) - { - - if (OverlayForm.MainForm.InvokeRequired) - { - OverlayForm.MainForm.Invoke(new System.Action(() => - { - Console.WriteLine("B sign for input :" + input); - OverlayForm.MainForm.OnUserInput(input); - })); - } - else - { - Console.WriteLine("C sign for input :" + input); - OverlayForm.MainForm.OnUserInput(input); - } - } - else - { - if (OverlayForm.MainForm.InvokeRequired) - { - OverlayForm.MainForm.Invoke(new System.Action(() => - { - if (song != null) - { - ClearDisplay(); - OverlayForm.MainForm.displayLabel.Text = String.Format("插播歌曲{0}", song); - SongList.Insert(song); - OverlayForm.MainForm.topLeftLabel.Visible = false; - OverlayForm.displayTimer.Start(); - } - else - { - ClearDisplay(); - _wrongInputCountfor62++; - if(_wrongInputCountfor62 <= MaxWrongLimit) - { - string old =""; - OverlayForm.MainForm.displayLabel.Text = check_control(old); - } - else - { - OverlayForm.MainForm.displayLabel.Text = "輸入錯誤!!!"; - _indataHistory.Clear(); // 清空歷史紀錄 - _wrongInputCountfor62 = 0; // 重置計數器 - } - OverlayForm.MainForm.topLeftLabel.Visible = false; - OverlayForm.displayTimer.Start(); - } - })); - } - else - { - if (song != null) - { - ClearDisplay(); - OverlayForm.MainForm.displayLabel.Text = String.Format("已點歌曲:{0}", song); - OverlayForm.MainForm.topLeftLabel.Visible = false; - } - else - { - ClearDisplay(); - _wrongInputCountfor62++; - if(_wrongInputCountfor62 <= MaxWrongLimit) - { - string old =""; - OverlayForm.MainForm.displayLabel.Text = check_control(old); - } - else - { - OverlayForm.MainForm.displayLabel.Text = "輸入錯誤!!!"; - _indataHistory.Clear(); // 清空歷史紀錄 - _wrongInputCountfor62 = 0; // 重置計數器 - } - OverlayForm.MainForm.topLeftLabel.Visible = false; - OverlayForm.displayTimer.Start(); - } - } + if (item == "A261A4") + str += "#"; + else if (item == "A262A4") + str += "*"; } + return str; } /// @@ -487,14 +322,7 @@ namespace DualScreenDemo OverlayForm.displayTimer.Stop(); // 判斷是否需要透過 Invoke 回 UI 執行緒執行 - if (OverlayForm.MainForm.InvokeRequired) - { - OverlayForm.MainForm.Invoke(new Action(ClearControlsAndReset)); - } - else - { - ClearControlsAndReset(); - } + InvokeAction(() => ClearControlsAndReset()); } /// @@ -562,28 +390,19 @@ namespace DualScreenDemo for (int i = startIndex; i < endIndex; i++) { historySongs.Add(history[i]); } - + // 錨點 遙控器 // 安全更新 UI:若非 UI 執行緒則使用 Invoke 切換 - if (OverlayForm.MainForm.InvokeRequired) + InvokeAction(() => { - OverlayForm.MainForm.Invoke(new System.Action(() => - { - // 更新主畫面的歷史播放顯示區 - OverlayForm.MainForm.UpdateHistoryLabel(historySongs, OverlayForm.MainForm.currentPage, totalPages); - - // 隱藏下一首提示 - OverlayForm.MainForm.topLeftLabel.Visible = false; - })); - } - else - { - // 若已在 UI 執行緒,直接操作 + // 更新主畫面的歷史播放顯示區 OverlayForm.MainForm.UpdateHistoryLabel(historySongs, OverlayForm.MainForm.currentPage, totalPages); - OverlayForm.MainForm.topLeftLabel.Visible = false; - } + // 隱藏下一首提示 + OverlayForm.MainForm.topLeftLabel.Visible = false; + }); + // 切換 UI 狀態為播放歷史模式(可做為內部狀態管理用途) OverlayForm.SetUIState(OverlayForm.UIState.PlayHistory); } @@ -595,55 +414,18 @@ namespace DualScreenDemo { if (OverlayForm.CurrentUIState == OverlayForm.UIState.SelectingSong) { - - if (OverlayForm.MainForm.InvokeRequired) - { - OverlayForm.MainForm.Invoke(new System.Action(() => - { - - OverlayForm.MainForm.PreviousPage(); - })); - } - else - { - - OverlayForm.MainForm.PreviousPage(); - } + InvokeAction(() =>OverlayForm.MainForm.PreviousPage()); } else if (OverlayForm.CurrentUIState == OverlayForm.UIState.SelectingArtist) { - - if (OverlayForm.MainForm.InvokeRequired) - { - OverlayForm.MainForm.Invoke(new System.Action(() => - { - - OverlayForm.MainForm.PreviousPage(); - })); - } - else - { - - OverlayForm.MainForm.PreviousPage(); - } + InvokeAction(() =>OverlayForm.MainForm.PreviousPage()); } else if (OverlayForm.CurrentUIState == OverlayForm.UIState.PlayHistory) { if (OverlayForm.MainForm.currentPage > 1) { OverlayForm.MainForm.currentPage--; - - if (OverlayForm.MainForm.InvokeRequired) - { - OverlayForm.MainForm.Invoke(new System.Action(() => - { - DisplaySongHistory(); - })); - } - else - { - DisplaySongHistory(); - } + InvokeAction(() => DisplaySongHistory()); } } else @@ -656,37 +438,11 @@ namespace DualScreenDemo { if (OverlayForm.CurrentUIState == OverlayForm.UIState.SelectingSong) { - - if (OverlayForm.MainForm.InvokeRequired) - { - OverlayForm.MainForm.Invoke(new System.Action(() => - { - - OverlayForm.MainForm.NextPage(); - })); - } - else - { - - OverlayForm.MainForm.NextPage(); - } + InvokeAction(() => OverlayForm.MainForm.NextPage()); } else if (OverlayForm.CurrentUIState == OverlayForm.UIState.SelectingArtist) { - - if (OverlayForm.MainForm.InvokeRequired) - { - OverlayForm.MainForm.Invoke(new System.Action(() => - { - - OverlayForm.MainForm.NextPage(); - })); - } - else - { - - OverlayForm.MainForm.NextPage(); - } + InvokeAction(() => OverlayForm.MainForm.NextPage() ); } else if (OverlayForm.CurrentUIState == OverlayForm.UIState.PlayHistory) { @@ -695,17 +451,7 @@ namespace DualScreenDemo OverlayForm.MainForm.currentPage++; if (OverlayForm.CurrentUIState == OverlayForm.UIState.PlayHistory) { - if (OverlayForm.MainForm.InvokeRequired) - { - OverlayForm.MainForm.Invoke(new System.Action(() => - { - DisplaySongHistory(); - })); - } - else - { - DisplaySongHistory(); - } + InvokeAction(() => DisplaySongHistory() ); } } } @@ -803,30 +549,8 @@ namespace DualScreenDemo private static void UpdateDisplayLabels(string[] messages) { - if (OverlayForm.MainForm.InvokeRequired) + InvokeAction(() => { - OverlayForm.MainForm.Invoke(new System.Action(() => - { - - foreach (var control in OverlayForm.MainForm.Controls.OfType().ToArray()) - { - if (control != OverlayForm.MainForm.displayLabel && - control != OverlayForm.MainForm.pauseLabel && - control != OverlayForm.MainForm.muteLabel && - control != OverlayForm.MainForm.topRightLabel && - control != OverlayForm.MainForm.blackBackgroundPanel && - control != OverlayForm.MainForm.topLeftLabel) - { - OverlayForm.MainForm.Controls.Remove(control); - control.Dispose(); - } - } - OverlayForm.MainForm.UpdateDisplayLabels(messages); - })); - } - else - { - foreach (var control in OverlayForm.MainForm.Controls.OfType().ToArray()) { if (control != OverlayForm.MainForm.displayLabel && @@ -841,7 +565,7 @@ namespace DualScreenDemo } } OverlayForm.MainForm.UpdateDisplayLabels(messages); - } + }); } private static void HandleNumberInput(string trimmedData) @@ -861,38 +585,19 @@ namespace DualScreenDemo if (readyForSongListInput) { - - if (OverlayForm.MainForm.InvokeRequired) + InvokeAction(() => { - OverlayForm.MainForm.Invoke(new System.Action(() => - { - Console.WriteLine("D sign for number :" + number); - OverlayForm.MainForm.OnUserInput(number); - })); - } - else - { - Console.WriteLine("E sign for number :" + number); - OverlayForm.MainForm.OnUserInput(number); - } - + Console.WriteLine("D sign for number :" + number); + OverlayForm.MainForm.OnUserInput(number); + }); } else { - - if (OverlayForm.MainForm.InvokeRequired) - { - OverlayForm.MainForm.Invoke(new System.Action(() => - { - OverlayForm.MainForm.HideTopRightLabels(); - OverlayForm.DisplayNumberAtTopLeft(number); - })); - } - else + InvokeAction(() => { OverlayForm.MainForm.HideTopRightLabels(); OverlayForm.DisplayNumberAtTopLeft(number); - } + }); } } diff --git a/DBObj/SongData.cs b/DBObj/SongData.cs index db72a72..a04b424 100644 --- a/DBObj/SongData.cs +++ b/DBObj/SongData.cs @@ -141,10 +141,7 @@ namespace DBObj public int getHumanVoice() { return basic.getHumanVoice(); } public override string ToString() { - - return B!=null - ? String.Format("{0} - {1} - {2} - {3}", state, A.getName(), B.getName(), basic.getName()) - : String.Format("{0} - {1} - {2}", state, A.getName(), basic.getName()); + return String.Format("{0} {1}", basic.getName(),state.GetDescription() ); } } } \ No newline at end of file diff --git a/Program.cs b/Program.cs index 6994ccb..6d9f035 100644 --- a/Program.cs +++ b/Program.cs @@ -13,7 +13,7 @@ namespace DualScreenDemo private static PrimaryForm primaryForm; // 儲存實例的參考 public static Room room = new Room(); - public static string verSion = "Server V2.7 202508041108"; + public static string verSion = "Server V2.7 202508041725"; [STAThread] static void Main()