From 4466c457fdeaa3d6ecf0ce7be1bf11588659467d Mon Sep 17 00:00:00 2001 From: jasonchenwork Date: Tue, 27 May 2025 11:27:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=83=A8=E5=88=86SQL?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=AD=A3=E9=81=99=E6=8E=A7=E5=99=A8=E5=B7=B2?= =?UTF-8?q?=E9=BB=9E=E6=AD=8C=E6=9B=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CommandHandler.cs | 19 +++++++++++++-- DBObj/SongListManager.cs | 4 +-- OverlayFormObj/OverlayForm.cs | 46 +++++++++++++++++++++++++---------- 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/CommandHandler.cs b/CommandHandler.cs index 3163aa8..a2ed9c2 100644 --- a/CommandHandler.cs +++ b/CommandHandler.cs @@ -3,6 +3,7 @@ using System.Text.RegularExpressions; using System.Diagnostics; using DBObj; using OverlayFormObj; +using NAudio.Wave; namespace DualScreenDemo { public class CommandHandler @@ -83,6 +84,7 @@ namespace DualScreenDemo ToggleMute(); break; case "A274A4": + OverlayForm.MainForm.currentPage = 1; HandleArtistAnnouncements(); break; case "A2B3A4": @@ -589,12 +591,25 @@ namespace DualScreenDemo // 準備要傳給 UpdateHistoryLabel 的兩個清單:歌曲資料與播放狀態 List historySongs = new List(); List playStates = new List(); - + // 錨點 遙控器 // 從播放紀錄中取出當前頁面應顯示的歌曲與狀態 + int completedCount = PrimaryForm.currentSongIndexInHistory; for (int i = startIndex; i < endIndex; i++) { + historySongs.Add(PrimaryForm.playedSongsHistory[i]); // 加入歌曲 - playStates.Add(PrimaryForm.playStates[i]); // 加入狀態 (已播、播放中、未播) + if (i < completedCount) + { + playStates.Add(PlayState.Played); + } + else if (i == completedCount) + { + playStates.Add(PlayState.Playing); + } + else + { + playStates.Add(PlayState.NotPlayed); + } } diff --git a/DBObj/SongListManager.cs b/DBObj/SongListManager.cs index b9b8b9c..a480e29 100644 --- a/DBObj/SongListManager.cs +++ b/DBObj/SongListManager.cs @@ -55,14 +55,14 @@ namespace DBObj return PrimaryForm.Instance.SearchSongs_Mysql(query); } public List SearchHotSongs(){ - string query= $"SELECT * FROM song_library_cache WHERE language_name = '國語' ORDER BY add_date DESC LIMIT {PrimaryForm.ReadHotSongLimit()}"; + string query= $"SELECT * FROM song_library_cache WHERE language_name = '國語' ORDER BY song_conts DESC LIMIT {PrimaryForm.ReadHotSongLimit()}"; return PrimaryForm.Instance.SearchSongs_Mysql(query); } public List SearchSongsBySinger(string keyword) { Console.WriteLine("keyword : " + keyword); var keywordLower = keyword.ToLower(); - string query = $"SELECT * FROM song_library_cache WHERE artistA LIKE '%{keywordLower}%' OR artistB LIKE'%{keywordLower}%'"; + string query = $"SELECT * FROM song_library_cache WHERE artistA LIKE '%{keywordLower}%' OR artistB LIKE'%{keywordLower}% ORDER BY song_counts DESC;'"; return PrimaryForm.Instance.SearchSongs_Mysql(query); } public List SearchSongsByName(string keyword) diff --git a/OverlayFormObj/OverlayForm.cs b/OverlayFormObj/OverlayForm.cs index ace5534..b017a1b 100644 --- a/OverlayFormObj/OverlayForm.cs +++ b/OverlayFormObj/OverlayForm.cs @@ -1098,7 +1098,7 @@ private static void SongDisplayTimer_Elapsed(object sender, EventArgs e) selectedArtist = currentArtistList[artistIndex]; currentLanguage = selectedArtist.Name; SetUIState(UIState.SelectingSong); - string query = $"SELECT * FROM song_library_cache WHERE artistA ='{selectedArtist.Name}' OR artistB='{selectedArtist.Name}' "; + string query = $"SELECT * FROM song_library_cache WHERE artistA ='{selectedArtist.Name}' OR artistB='{selectedArtist.Name}' ORDER BY song_counts DESC;"; LanguageSongList = PrimaryForm.Instance.SearchSongs_Mysql(query); //LanguageSongList = SongListManager.Instance.GetSongsByArtist(selectedArtist.Name); currentPage = 1; @@ -1274,7 +1274,9 @@ private static void SongDisplayTimer_Elapsed(object sender, EventArgs e) } // 計算目前這首歌的 Y 座標位置 - int y = startY + i * (songBitmap.Height + verticalSpacing); + int fixedRowHeight = 80; + int y = startY + i * (fixedRowHeight + verticalSpacing); + //int y = startY + i * (songBitmap.Height + verticalSpacing); // 加入歌名圖片到畫面左側 AddPicture(songBitmap, leftMargin, y); @@ -1289,47 +1291,65 @@ private static void SongDisplayTimer_Elapsed(object sender, EventArgs e) } public void UpdateDisplayLabels(string[] messages)//新歌歌星排行首頁 { - // 清除舊的圖片控件 + // 移除畫面上現有的所有 PictureBox(舊的文字圖片) this.Controls.OfType().ToList().ForEach(p => this.Controls.Remove(p)); + // 如果沒有訊息內容,直接跳出,不進行後續繪製 if (messages.Length == 0) return; - int mainTitleFontSize = 60; - int optionFontSize = 50; - int lineSpacing = 15; - //int columnSpacing = 400; + // 設定主標題字體大小 + int mainTitleFontSize = 60; + // 設定選項字體大小 + int optionFontSize = 50; + // 每行之間的垂直間距(像素) + int lineSpacing = 15; - // 主標題 + // 取得主標題文字(第一行) string mainTitle = messages[0]; + // 建立主標題用的字型:微軟正黑體、粗體 Font mainTitleFont = new Font("Microsoft JhengHei", mainTitleFontSize, FontStyle.Bold); + // 使用自定義方法產生主標題的文字圖像(白色字+透明底) Bitmap mainTitleBitmap = GenerateTextImage(mainTitle, mainTitleFont, Color.White, Color.Transparent); + // 主標題起始的 Y 座標 int startY = 130; + // 將主標題圖片水平置中並加入畫面 AddCenteredPicture(mainTitleBitmap, startY); + // 更新 Y 座標位置,準備繪製下一區塊(選項),加上主標題高度與間距 startY += mainTitleBitmap.Height + lineSpacing; - // 選項 + // 取得剩下的訊息文字(第二行起):當作選項 string[] options = messages.Skip(1).ToArray(); + // 選項的起始 Y 座標 int optionsStartY = startY; + // 每欄最多可放幾個項目(以兩欄平均分配) int maxItemsPerColumn = (int)Math.Ceiling(options.Length / 2.0); - int leftColumnX = 200; + // 設定左右欄的 X 座標(用於放置圖片) + int leftColumnX = 200; int rightColumnX = this.Width / 2 + 150; + // 開始逐一處理每個選項 for (int i = 0; i < options.Length; i++) { + // 設定每個選項的字型 Font optionFont = new Font("Microsoft JhengHei", optionFontSize, FontStyle.Bold); + // 建立文字對應的圖像(白色字+透明底) Bitmap optionBitmap = GenerateTextImage(options[i], optionFont, Color.White, Color.Transparent); + // 根據目前索引,決定放在左欄還是右欄 int x = (i < maxItemsPerColumn) ? leftColumnX : rightColumnX; + // 決定目前這張圖的 Y 座標位置(依序向下排列) int currentY = optionsStartY + ((i % maxItemsPerColumn) * (optionBitmap.Height + lineSpacing)); + // 加入圖片到畫面上 AddPicture(optionBitmap, x, currentY); } + } private string strokeRange; private int totalArtists = 0; - private const int artistsPerPage = 10; + private const int artistsPerPage = 8; private List currentArtistList = new List(); private void ProcessStrokeCountSelection(int number) @@ -1387,7 +1407,7 @@ private void DisplayArtists(List artists, int page)//歌星點進去後 this.Controls.OfType().ToList().ForEach(p => this.Controls.Remove(p)); - int artistsPerColumn = 5; + int artistsPerColumn = 4; int startIndex = (page - 1) * artistsPerPage; int endIndex = Math.Min(startIndex + artistsPerPage, artists.Count); @@ -1637,7 +1657,7 @@ private void DisplayArtists(List artists, int page)//歌星點進去後 } - + // 測試 public int currentPage = 1; public int songsPerPage = 5; public int totalSongs = 0;