From d57de0b61624e381f978fdf11934246648670f98 Mon Sep 17 00:00:00 2001 From: jasonchenwork Date: Thu, 10 Apr 2025 14:16:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E9=8C=A8=E9=BB=9E+=E9=81=99?= =?UTF-8?q?=E6=8E=A7=E9=97=9C=E6=A9=9F+=E8=B2=BC=E5=9C=96=E8=AA=BF?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CommandHandler.cs | 33 ++++++++++++++++++++++++++++++--- HttpServer.cs | 2 -- OverlayFormObj/OverlayForm.cs | 23 ++--------------------- PrimaryFormParts/PrimaryForm.cs | 1 - 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/CommandHandler.cs b/CommandHandler.cs index b771ad9..63ab20f 100644 --- a/CommandHandler.cs +++ b/CommandHandler.cs @@ -8,7 +8,8 @@ namespace DualScreenDemo public class CommandHandler { public static bool readyForSongListInput = false; - + private readonly int _maxHistoryLength = 6; // 最多保留 100 筆 + private readonly Queue _indataHistory = new Queue(); private readonly SongListManager songListManager; public CommandHandler(SongListManager songListManager) @@ -18,7 +19,7 @@ namespace DualScreenDemo public async Task ProcessData(string indata) { //關機錨點 - string filePath = Path.Combine(Application.StartupPath, "dataLog.txt"); + /*string filePath = Path.Combine(Application.StartupPath, "dataLog.txt"); // 使用 Path.Combine 方法安全地將應用程式的啟動路徑與 "dataLog.txt" 檔案名結合, // 建立完整的檔案路徑。Application.StartupPath 通常指向應用程式的可執行檔所在的目錄。 @@ -31,7 +32,10 @@ namespace DualScreenDemo // 在控制台輸出訊息,告知使用者已滿足關機條件,應用程式即將關閉。 ShutdownComputer(); // 呼叫 ShutdownComputer 方法,這個方法預期會執行關閉電腦的操作。 - } + }*/ + + AddToHistory(indata); + switch (indata) { case "A261A4": @@ -188,6 +192,29 @@ namespace DualScreenDemo } } + private void AddToHistory(string indata) + { + if (_indataHistory.Count >= _maxHistoryLength) + { + _indataHistory.Dequeue(); // 移除最舊的項目 + } + _indataHistory.Enqueue(indata); // 添加新的項目 + CheckSequenceforClose(); // 每次更新完 queue 後檢查 + } + private void CheckSequenceforClose() + { + string[] targetSequence = { "A262A4", "A262A4", "A262A4", "A261A4", "A261A4", "A261A4" }; + + if (_indataHistory.Count == targetSequence.Length && + _indataHistory.SequenceEqual(targetSequence)) + { + // 👇 這裡就是條件符合時要做的事情 + Console.WriteLine("Shutdown condition met. Application will now close."); + ShutdownComputer(); + // 你可以呼叫其他方法、觸發事件、改狀態等等 + } + } + void InvokeAction(Action action) { if (OverlayForm.MainForm.InvokeRequired) diff --git a/HttpServer.cs b/HttpServer.cs index fc9e464..8a5470f 100644 --- a/HttpServer.cs +++ b/HttpServer.cs @@ -67,8 +67,6 @@ namespace DualScreenDemo // 如果有外网地址,也添加外网地址前缀 if (!string.IsNullOrEmpty(externalAddress)) { - // 錨點 2 - // 外網 IP 和 port 調整 string[] parts = externalAddress.Split(':'); string host = parts[0]; diff --git a/OverlayFormObj/OverlayForm.cs b/OverlayFormObj/OverlayForm.cs index 35dc75f..6202265 100644 --- a/OverlayFormObj/OverlayForm.cs +++ b/OverlayFormObj/OverlayForm.cs @@ -69,9 +69,9 @@ namespace OverlayFormObj MainForm = this; InitializeFormSettings(); ConfigureTimers(); - ConfigureImageDisplay(); InitializeLabels(); ConfigureSegmentTimer(); + imageYPos = (screenHeight / 3) - 1024 / 6; } private void ConfigureSegmentTimer() { @@ -525,25 +525,6 @@ private static void SongDisplayTimer_Elapsed(object sender, EventArgs e) unifiedTimer.Start(); } - private void ConfigureImageDisplay() - { - try - { - firstStickerImage = Image.FromFile(Path.Combine(Application.StartupPath, "superstar-pic/1-1.png")); - firstStickerXPos = this.Width / 2; - imageYPos = (screenHeight / 3) - firstStickerImage.Height / 6; - - - - - stickerTimer1.Start(); - } - catch (Exception ex) - { - Console.WriteLine("Error loading initial sticker image: " + ex.Message); - firstStickerImage = null; - } - } private void HideImages() { @@ -771,7 +752,7 @@ private static void SongDisplayTimer_Elapsed(object sender, EventArgs e) Console.WriteLine("Form Height: " + this.Height); - string imagePath = String.Format("{0}\\superstar-pic\\{1}.png", Application.StartupPath, stickerId); + string imagePath = String.Format("{0}\\themes\\superstar\\superstar-pic\\{1}.png", Application.StartupPath, stickerId); Console.WriteLine("Image path: " + imagePath); try { diff --git a/PrimaryFormParts/PrimaryForm.cs b/PrimaryFormParts/PrimaryForm.cs index f5441be..cae117f 100644 --- a/PrimaryFormParts/PrimaryForm.cs +++ b/PrimaryFormParts/PrimaryForm.cs @@ -250,7 +250,6 @@ namespace DualScreenDemo public Timer micControlTimer; private SequenceManager sequenceManager = new SequenceManager(); - /* 關機圖片調整區域 錨點3 */ private PictureBox buttonMiddle; private PictureBox buttonTopRight; private PictureBox buttonTopLeft;