superstar_v2/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.cs

154 lines
7.4 KiB
C#
Raw Normal View History

2025-08-06 10:47:43 +08:00
using System.IO;
2025-04-07 16:54:10 +08:00
namespace DualScreenDemo
{
/*
* (PrimaryForm)
* UI
*/
public partial class PrimaryForm
{
// 各種歌曲搜尋按鈕及其對應的背景圖片 (一般狀態 / 啟動狀態)
private Button zhuyinSearchSongButton;
2025-08-07 13:09:10 +08:00
private Bitmap zhuyinSearchSongNormalBackground;
private Bitmap zhuyinSearchSongActiveBackground;
2025-04-07 16:54:10 +08:00
private Button englishSearchSongButton;
2025-08-07 13:09:10 +08:00
private Bitmap englishSearchSongNormalBackground;
private Bitmap englishSearchSongActiveBackground;
2025-04-07 16:54:10 +08:00
private Button wordCountSearchSongButton;
2025-08-07 13:09:10 +08:00
private Bitmap wordCountSearchSongNormalBackground;
private Bitmap wordCountSearchSongActiveBackground;
2025-04-07 16:54:10 +08:00
private Button pinyinSearchSongButton;
2025-08-07 13:09:10 +08:00
private Bitmap pinyinSearchSongNormalBackground;
private Bitmap pinyinSearchSongActiveBackground;
2025-04-07 16:54:10 +08:00
private Button handWritingSearchSongButton;
2025-08-07 13:09:10 +08:00
private Bitmap handWritingSearchSongNormalBackground;
private Bitmap handWritingSearchSongActiveBackground;
2025-04-07 16:54:10 +08:00
private Button numberSearchSongButton;
2025-08-07 13:09:10 +08:00
private Bitmap numberSearchSongNormalBackground;
private Bitmap numberSearchSongActiveBackground;
2025-04-07 16:54:10 +08:00
private void UpdateSongSearchBtn(Button activeButton, Image activeBackground)
{
zhuyinSearchSongButton.BackgroundImage = zhuyinSearchSongNormalBackground;
englishSearchSongButton.BackgroundImage = englishSearchSongNormalBackground;
pinyinSearchSongButton.BackgroundImage = pinyinSearchSongNormalBackground;
wordCountSearchSongButton.BackgroundImage = wordCountSearchSongNormalBackground;
handWritingSearchSongButton.BackgroundImage = handWritingSearchSongNormalBackground;
numberSearchSongButton.BackgroundImage = numberSearchSongNormalBackground;
activeButton.BackgroundImage = activeBackground;
}
2025-04-07 16:54:10 +08:00
/// <summary>
/// 點擊「歌曲搜尋」按鈕時的事件處理函式
/// 1. 更新導航按鈕的背景圖片,使「歌曲搜尋」按鈕顯示為啟動狀態
/// 2. 隱藏其他搜尋/分類 UI僅顯示歌曲搜尋選單
/// 3. 若有 QR Code 顯示,則將其隱藏
/// </summary>
private void SongSearchButton_Click(object sender, EventArgs e)
{
isOnOrderedSongsPage = false;
UpdateButtonBackgrounds(songSearchButton, songSearchActiveBackground);
ResetinputBox();
2025-08-06 10:47:43 +08:00
string query = $"SELECT * FROM song_library_cache WHERE language_name = '國語' LIMIT 1000;";
var searchResult = SearchSongs_Mysql(query);
2025-08-07 13:09:10 +08:00
currentPage = 0;
totalPages = (int)Math.Ceiling((double)searchResult.Count / itemsPerPage);
2025-08-07 13:09:10 +08:00
multiPagePanel.currentPageIndex = 0;
multiPagePanel.LoadSongs(searchResult);
2025-04-07 16:54:10 +08:00
// 隱藏其他 UI
SetHotSongButtonsVisibility(false);
SetNewSongButtonsVisibility(false);
SetSongSearchButtonsVisibility(false);
2025-04-07 16:54:10 +08:00
SetPictureBoxLanguageButtonsVisibility(false);
SetGroupButtonsVisibility(false);
SetPictureBoxCategoryAndButtonsVisibility(false);
SetZhuYinSingersAndButtonsVisibility(false);
SetZhuYinSongsAndButtonsVisibility(false);
SetEnglishSingersAndButtonsVisibility(false);
SetPinYinSingersAndButtonsVisibility(false);
SetPinYinSongsAndButtonsVisibility(false);
SetPictureBoxToggleLightAndButtonsVisibility(false);
2025-08-13 16:42:22 +08:00
SetHandWritingForSongsAndButtonsVisibility(false);
2025-04-07 16:54:10 +08:00
SetPictureBoxSceneSoundEffectsAndButtonsVisibility(false);
2025-08-13 16:42:22 +08:00
SetWordCountSongsAndButtonsVisibility(false);
SetSongIDSearchAndButtonsVisibility(false);
SetHandWritingForSingersAndButtonsVisibility(false);
SetWordCountSingersAndButtonsVisibility(false);
2025-04-07 16:54:10 +08:00
// 顯示歌曲搜尋選單按鈕
SetSongSearchButtonsVisibility(true);
// 隱藏 QR Code (若有)
if (pictureBoxQRCode != null)
{
pictureBoxQRCode.Visible = false;
closeQRCodeButton.Visible = false;
}
}
2025-08-07 13:09:10 +08:00
2025-04-07 16:54:10 +08:00
/// <summary>
/// 設定「歌曲搜尋」相關按鈕的可見性
/// </summary>
/// <param name="isVisible">是否顯示</param>
private void SetSongSearchButtonsVisibility(bool isVisible)
{
pictureBox4.Visible = isVisible; // 控制搜尋 UI 背景的可見性
// 歌曲搜尋的按鈕陣列
2025-08-07 13:09:10 +08:00
Button[] songSearchButtons = {
zhuyinSearchSongButton,
englishSearchSongButton,
wordCountSearchSongButton,
pinyinSearchSongButton,
handWritingSearchSongButton,
numberSearchSongButton
2025-04-07 16:54:10 +08:00
};
// 設定按鈕可見性,若顯示則移至最前
foreach (var button in songSearchButtons)
{
button.Visible = isVisible;
if (isVisible)
{
button.BringToFront();
}
}
}
/// <summary>
/// 初始化所有「歌曲搜尋」按鈕
/// 依據不同的搜尋方式 (注音、英文、拼音、筆劃、手寫、數字) 建立對應按鈕
/// </summary>
private void InitializeButtonsForSongSearch()
{
var data = LoadBtnConfigData();
InitializeButton(ref zhuyinSearchSongButton, ref zhuyinSearchSongNormalBackground, ref zhuyinSearchSongActiveBackground, "zhuyinSearchSongButton", 1197, 225, 225, 50, data["SongSearch"]["ZhuYinSongNormal"], data["SongSearch"]["ZhuYinSongActive"], ZhuyinSearchSongsButton_Click);
InitializeButton(ref englishSearchSongButton, ref englishSearchSongNormalBackground, ref englishSearchSongActiveBackground, "englishSearchSongButton", 1197, 280, 225, 50, data["SongSearch"]["EngSongNormal"], data["SongSearch"]["EngSongActive"], EnglishSearchSongsButton_Click);
InitializeButton(ref pinyinSearchSongButton, ref pinyinSearchSongNormalBackground, ref pinyinSearchSongActiveBackground, "pinyinSearchSongButton", 1197, 335, 225, 50, data["SongSearch"]["PinYingNormal"], data["SongSearch"]["PinYingActive"], PinyinSearchSongsButton_Click);
InitializeButton(ref wordCountSearchSongButton, ref wordCountSearchSongNormalBackground, ref wordCountSearchSongActiveBackground, "wordCountSearchSongButton", 1197, 390, 225, 50, data["SongSearch"]["WordCntSongNormal"], data["SongSearch"]["WordCntSongActive"], WordCountSearchSongsButton_Click);
InitializeButton(ref handWritingSearchSongButton, ref handWritingSearchSongNormalBackground, ref handWritingSearchSongActiveBackground, "handWritingSearchSongButton", 1197, 445, 225, 50, data["SongSearch"]["HWritingSongNormal"], data["SongSearch"]["HWritingSongActive"], HandWritingSearchButtonForSongs_Click);
InitializeButton(ref numberSearchSongButton, ref numberSearchSongNormalBackground, ref numberSearchSongActiveBackground, "numberSearchSongButton", 1197, 500, 225, 50, data["SongSearch"]["IDSearchNormal"], data["SongSearch"]["IDSearchActive"], SongIDSearchSongsButton_Click);
2025-04-07 16:54:10 +08:00
}
}
}