2025-08-08 17:33:19 +08:00

2370 lines
98 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.IO;
using System.Runtime.InteropServices;
using NAudio.Wave;
using Microsoft.Ink;
using System.Text.RegularExpressions;
using DBObj;
using OverlayFormObj;
using Timer = System.Windows.Forms.Timer;
using IniParser.Model;
using IniParser;
using System.Text;
namespace DualScreenDemo
{
public partial class PrimaryForm : Form
{
#region
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
#endregion
public static PrimaryForm Instance { get; private set; }
public bool isOnOrderedSongsPage = false;
private ProgressBar progressBar;
private PictureBox pictureBox1;
private PictureBox pictureBox2;
private PictureBox pictureBox3;
private PictureBox pictureBox4;
private PictureBox pictureBox5;
private PictureBox pictureBox6;
private PictureBox pictureBoxArtistSearch;
private Button singerSearchButton;
private Bitmap singerSearchNormalBackground;
private Bitmap singerSearchActiveBackground;
private Button songSearchButton;
private Bitmap songSearchNormalBackground;
private Bitmap songSearchActiveBackground;
private Button serviceBellButton;
private Button deliciousFoodButton;
private Bitmap deliciousFoodNormalBackground;
private Bitmap deliciousFoodActiveBackground;
private Button mobileSongRequestButton;
private Button qieGeButton;
private Button musicUpButton;
private Button musicDownButton;
private Button micUpButton;
private Button micDownButton;
private Button originalSongButton;
private Button replayButton;
public Button pauseButton;
public Button playButton;
private Button muteButton;
private Button maleKeyButton;
private Button femaleKeyButton;
private Button standardKeyButton;
private Button soundEffectButton;
private Button pitchUpButton;
private Button pitchDownButton;
private Button syncScreenButton;
private Button toggleLightButton;
private PictureBox promotionsPictureBox;
private List<Image> promotions;
private List<Image> menu;
private PictureBox VodScreenPictureBox;
private Panel overlayPanel;
private Button btnPreviousPage;
private Button btnReturn;
private Button btnNextPage;
private Button btnApplause;
private Button btnSimplifiedChinese;
private Button btnTraditionalChinese;
private Button exitButton;
private static Bitmap normalStateImage;
private static Bitmap mouseOverImage;
private static Bitmap mouseDownImage;
private static Bitmap resizedNormalStateImage;
private static Bitmap resizedMouseOverImage;
private static Bitmap resizedMouseDownImage;
private static Bitmap normalStateImageNewSongAlert;
private static Bitmap mouseOverImageNewSongAlert;
private static Bitmap mouseDownImageNewSongAlert;
private static Bitmap resizedNormalStateImageForNewSongAlert;
private static Bitmap resizedMouseOverImageForNewSongAlert;
private static Bitmap resizedMouseDownImageForNewSongAlert;
private static Bitmap normalStateImageArtistQuery;
private static Bitmap mouseOverImageArtistQuery;
private static Bitmap mouseDownImageArtistQuery;
private static Bitmap resizedNormalStateImageForArtistQuery;
private static Bitmap resizedMouseOverImageForArtistQuery;
private static Bitmap resizedMouseDownImageForArtistQuery;
private static Bitmap normalStateImageSongQuery;
private static Bitmap mouseOverImageSongQuery;
private static Bitmap mouseDownImageSongQuery;
private static Bitmap resizedNormalStateImageForSongQuery;
private static Bitmap resizedMouseOverImageForSongQuery;
private static Bitmap resizedMouseDownImageForSongQuery;
private static Bitmap normalStateImageLanguageQuery;
private static Bitmap mouseOverImageLanguageQuery;
private static Bitmap mouseDownImageLanguageQuery;
private static Bitmap resizedNormalStateImageForLanguageQuery;
private static Bitmap resizedMouseOverImageForLanguageQuery;
private static Bitmap resizedMouseDownImageForLanguageQuery;
private static Bitmap normalStateImageCategoryQuery;
private static Bitmap mouseOverImageCategoryQuery;
private static Bitmap mouseDownImageCategoryQuery;
private static Bitmap resizedNormalStateImageForCategoryQuery;
private static Bitmap resizedMouseOverImageForCategoryQuery;
private static Bitmap resizedMouseDownImageForCategoryQuery;
private static Bitmap normalStateImageForPromotionsAndMenu;
private static Bitmap resizedNormalStateImageForPromotionsAndMenu;
private static Bitmap normalStateImageForSyncScreen;
private static Bitmap resizedNormalStateImageForSyncScreen;
private static Bitmap normalStateImageForSceneSoundEffects;
private static Bitmap resizedNormalStateImageForSceneSoundEffects;
private static Bitmap normalStateImageForLightControl;
private static Bitmap resizedNormalStateImageForLightControl;
public VideoPlayerForm videoPlayerForm;
public List<Artist> currentArtistList;
public MultiPagePanel multiPagePanel;
private List<Label> songLabels = new List<Label>();
private int _currentPage { get; set; } = 0;
private int _totalPages { get; set; }
string serverPath = Utils.Env.GetPath("", "");
public int currentPage
{
get { return _currentPage; }
set { _currentPage = value; }
}
public int totalPages
{
get { return _totalPages; }
set { _totalPages = value; }
}
private void HandlePageChanged()
{
this.Invalidate(); // 重新繪製界面
}
public const int itemsPerPage = 18;
private WaveInEvent waveIn;
private WaveFileWriter waveWriter;
private const int PanelStartLeft = 25; // 修改為實際需要的左邊距
private const int PanelStartTop = 227; // 修改為實際需要的上邊距
private const int PanelEndLeft = 1175; // 修改為實際需要的右邊界
private const int PanelEndTop = 739; // 修改為實際需要的下邊界
private Timer lightControlTimer;
private SequenceManager sequenceManager = new SequenceManager();
private PictureBox buttonMiddle;
private PictureBox buttonTopRight;
private PictureBox buttonTopLeft;
private PictureBox buttonThanks;
private Dictionary<Control, (Point Location, bool Visible)> initialControlStates = new Dictionary<Control, (Point Location, bool Visible)>();
private Panel sendOffPanel;
private static Bitmap normalStateImageHotSong;
private static Bitmap mouseDownImageHotSong;
private static Bitmap resizedNormalStateImageForHotSong;
private static Bitmap resizedMouseDownImageForHotSong;
private PictureBox serviceBellPictureBox; // 添加为类成员变量
private Timer autoRefreshTimer;
private TimeSpan remainingTime;
private Timer timerCountdown;
string Rtime;
//private Label pageNumberLabel; // 添加頁碼標籤
public PrimaryForm()
{
Instance = this;
// 添加 DPI 感知支持
if (Environment.OSVersion.Version.Major >= 6)
{
SetProcessDPIAware();
}
this.DoubleBuffered = true;
InitializeProgressBar();
// 初始化自动刷新Timer
autoRefreshTimer = new Timer();
autoRefreshTimer.Interval = 1000; // 1秒
autoRefreshTimer.Tick += AutoRefreshTimer_Tick;
// 設置窗體屬性
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.None;
lightControlTimer = new Timer();
lightControlTimer.Interval = 5;
lightControlTimer.Tick += LightControlTimer_Tick;
InitializeRecording();
InitializeMediaPlayer();
LoadImages();
InitializeFormAndControls();
InitializeMultiPagePanel();
OverlayQRCodeOnImage(HttpServer.randomFolderPath);
InitializeHandWritingForSingers();
InitializeHandWritingForSongs();
InitializeSendOffPanel();
InitializePromotionsAndMenuPanel();
SaveInitialControlStates(this);
// 包廂 + port 名稱
this.Paint += PrimaryForm_Paint;
this.Paint += User_Paint;
// 註冊多頁面面板的頁碼改變事件處理
multiPagePanel.PageIndexChanged += HandlePageChanged;
// 添加 Load 事件處理
this.Load += PrimaryForm_Load;
timerCountdown = new Timer();
timerCountdown.Interval = 1000; // 1 second
timerCountdown.Tick += TimerCountdown_Tick;
}
// 添加 DPI 感知支持
[DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
private void SaveInitialControlStates(Control parent)
{
foreach (Control control in parent.Controls)
{
initialControlStates[control] = (control.Location, control.Visible);
if (control.HasChildren)
{
SaveInitialControlStates(control);
}
}
}
public void RoomTimeStart()
{
//DateTime now = DateTime.Now;
//DateTime tenMinutesLater = now.AddMinutes(120);
//remainingTime = tenMinutesLater - now;
remainingTime = Program.room.timePeriod;
timerCountdown.Start();
}
private async void TimerCountdown_Tick(object sender, EventArgs e)
{
if (remainingTime.TotalSeconds > 0)
{
remainingTime = remainingTime.Subtract(TimeSpan.FromSeconds(1));
Rtime = remainingTime.ToString(@"hh\:mm\:ss");
this.Invalidate();
}
else
{
timerCountdown.Stop();
await Task.Delay(10000);
Program.room.setDB("closed");
Program.room.set("");
}
}
private void PrimaryForm_Paint(object sender, PaintEventArgs e)
{
// 取得本機電腦的主機名稱 (hostname)
string hostName = System.Net.Dns.GetHostName();
string version = Program.verSion;
// 顯示包廂名稱
// 取主機名稱的最後 20 個字元 (如果長度不足 20則取全部)
string displayName = "包廂" + hostName.Substring(Math.Max(0, hostName.Length - 3)) + " " + Rtime;
string totalPages = multiPagePanel.totalPages.ToString() == "0" ? "1" : multiPagePanel.totalPages.ToString();
string pageNumber = (multiPagePanel.currentPageIndex + 1).ToString() + "/" + totalPages;
// 基準解析度(你目前的設計基準)
float baseWidth = 1920f;
float baseHeight = 1080f;
// 實際螢幕解析度
float actualWidth = Screen.PrimaryScreen.Bounds.Width;
float actualHeight = Screen.PrimaryScreen.Bounds.Height;
// 計算縮放比例
float scaleX = actualWidth / baseWidth;
float scaleY = actualHeight / baseHeight;
// 設定字型:
// "微軟正黑體",大小 24粗體 (Bold)
float fontSize = 24 * scaleY;
Font font = new Font("微軟正黑體", fontSize, FontStyle.Bold);
// 設定畫刷 (Brush)
// 使用紅色 (Red) 來繪製文字
Brush brush = new SolidBrush(Color.Red);
// 設定繪製文字的位置 (X=500, Y=30)
PointF point_PCName = new PointF(450 * scaleX, 30 * scaleY);
PointF point_PageNumber = new PointF(1390 * scaleX, 30 * scaleY);
PointF point_verSion = new PointF(1800 * scaleX, 30 * scaleY);
// 繪製文字:
// `DrawString(要繪製的文字, 字型, 畫刷, 位置)`
e.Graphics.DrawString(displayName, font, brush, point_PCName);
e.Graphics.DrawString(pageNumber, font, brush, point_PageNumber);
e.Graphics.DrawString(version.Substring(version.IndexOf("V"), 4), font, brush, point_verSion);
}
private void User_Paint(object sender, PaintEventArgs e)
{
if (!string.IsNullOrWhiteSpace(userPhone) && isLoggedIn)
{
string displayName = "歡迎貴賓 :" + userPhone;
float baseWidth = 1920f;
float baseHeight = 1080f;
// 實際螢幕解析度
float actualWidth = Screen.PrimaryScreen.Bounds.Width;
float actualHeight = Screen.PrimaryScreen.Bounds.Height;
// 計算縮放比例
float scaleX = actualWidth / baseWidth;
float scaleY = actualHeight / baseHeight;
// 設定字型:
// "微軟正黑體",大小 20粗體 (Bold)
float fontSize = 18 * scaleY;
Font font = new Font("微軟正黑體", fontSize, FontStyle.Bold);
// 設定畫刷 (Brush)
// 使用紅色 (Red) 來繪製文字
Brush brush = new SolidBrush(Color.Red);
// 設定繪製文字的位置 (X=800, Y=30)
PointF point_user = new PointF(800 * scaleX, 30 * scaleY);
e.Graphics.DrawString(displayName, font, brush, point_user);
}
}
private void buttonMiddle_Click(object sender, EventArgs e)
{
Console.WriteLine("巨");
sequenceManager.ProcessClick("巨");
}
private void buttonTopRight_Click(object sender, EventArgs e)
{
Console.WriteLine("級");
sequenceManager.ProcessClick("級");
}
private void buttonTopLeft_Click(object sender, EventArgs e)
{
Console.WriteLine("超");
sequenceManager.ProcessClick("超");
}
private void buttonThanks_Click(object sender, EventArgs e)
{
Console.WriteLine("星");
sequenceManager.ProcessClick("星");
}
public void ShowSendOffScreen()
{
sendOffPanel.BringToFront();
sendOffPanel.Visible = true;
// 確保按鈕可見並在最上層
buttonMiddle.Visible = true;
buttonTopRight.Visible = true;
buttonTopLeft.Visible = true;
buttonThanks.Visible = true;
buttonMiddle.BringToFront();
buttonTopRight.BringToFront();
buttonTopLeft.BringToFront();
buttonThanks.BringToFront();
}
// 修正螢幕初始化關鍵
public void HideSendOffScreen()
{
sendOffPanel.Visible = false;
foreach (Control ctrl in this.Controls)
{
ctrl.Enabled = true;
}
}
private void HideControlsRecursively(Control parent)
{
foreach (Control control in parent.Controls)
{
if (control is Button)
{
control.Visible = false;
}
else if (control.HasChildren)
{
HideControlsRecursively(control);
}
}
}
private void InitializeProgressBar()
{
progressBar = new ProgressBar();
progressBar.Location = new System.Drawing.Point(10, 10);
progressBar.Size = new System.Drawing.Size(300, 30);
progressBar.Minimum = 0;
progressBar.Maximum = 100;
progressBar.Value = 0;
this.Controls.Add(progressBar);
}
private void EnableDoubleBuffering(Control control)
{
if (control != null)
{
var doubleBufferedProperty = control.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
if (doubleBufferedProperty != null)
{
doubleBufferedProperty.SetValue(control, true, null);
}
}
}
private void InitializeRecording()
{
for (int n = 0; n < WaveIn.DeviceCount; n++)
{
var caps = WaveIn.GetCapabilities(n);
Console.WriteLine(String.Format("{0}: {1}", n, caps.ProductName));
}
waveIn = new WaveInEvent();
waveIn.DataAvailable += OnDataAvailable;
waveIn.RecordingStopped += OnRecordingStopped;
waveIn.WaveFormat = new WaveFormat(44100, 1);
}
private void OnDataAvailable(object sender, WaveInEventArgs e)
{
if (waveWriter != null)
{
waveWriter.Write(e.Buffer, 0, e.BytesRecorded);
waveWriter.Flush();
}
}
private void OnRecordingStopped(object sender, StoppedEventArgs e)
{
if (waveIn != null)
{
waveIn.Dispose();
waveIn = null;
}
if (waveWriter != null)
{
waveWriter.Dispose();
waveWriter = null;
}
}
private void InitializeFormAndControls()
{
this.SuspendLayout();
// 獲取螢幕尺寸
Screen screen = Screen.PrimaryScreen;
int screenWidth = screen.Bounds.Width;
int screenHeight = screen.Bounds.Height;
// 設置窗體大小
this.Size = new Size(screenWidth, screenHeight);
this.Location = new Point(0, 0);
// 調整背景圖片
string selectedTheme = ReadSelectedThemePath();
if (!string.IsNullOrEmpty(selectedTheme))
{
var data = LoadConfigData();
string backgroundImagePath = Path.Combine(serverPath, "themes\\superstar\\主畫面\\0.下方選單_主畫面.jpg");
try
{
using (Image originalImage = Image.FromFile(backgroundImagePath))
{
this.BackgroundImage = new Bitmap(originalImage);
this.BackgroundImageLayout = ImageLayout.Stretch;
}
}
catch (Exception ex)
{
Console.WriteLine($"加載背景圖片時發生錯誤: {ex.Message}");
}
}
InitializePictureBox();
InitializeButtonsForHotSong();
InitializeButtonsForNewSong();
InitializeButtonsForSingerSearch();
InitializeButtonsForSongSearch();
InitializeButtonsForPictureBoxLanguageQuery();
InitializeButtonsForGroupPictureBox();
InitializeCategorySearchButtons();
InitializeButtonsForZhuYinSingers();
InitializeButtonsForZhuYinSongs();
InitializeButtonsForEnglishSingers();
InitializeButtonsForEnglishSongs();
InitializeButtonsForWordCountSongs();
InitializeButtonsForWordCountSingers();
InitializeButtonsForPinYinSingers();
InitializeButtonsForPinYinSongs();
InitializeButtonsForSongIDSearch();
InitializeButtonsForFavoritePictureBox();
InitializePromotionsButton();
InitializeButtonsForPictureBoxToggleLight();
//InitializeButtonsForVodScreenPictureBox();
InitializeSoundEffectButtons();
InitializeSyncScreen();
InitializeButtonsForSongIDSearch();
InitializeOtherControls();
pictureBox1.BringToFront();
pictureBox2.BringToFront();
pictureBox3.BringToFront();
pictureBox4.BringToFront();
pictureBoxQRCode.BringToFront();
pictureBoxZhuYinSingers.BringToFront();
pictureBoxZhuYinSongs.BringToFront();
pictureBoxEnglishSingers.BringToFront();
pictureBoxEnglishSongs.BringToFront();
pictureBoxWordCountSongs.BringToFront();
FavoritePictureBox.BringToFront();
promotionsPictureBox.BringToFront();
pictureBoxToggleLight.BringToFront();
overlayPanel.BringToFront();
VodScreenPictureBox.BringToFront();
newSongAlertButton.BringToFront();
hotPlayButton.BringToFront();
singerSearchButton.BringToFront();
songSearchButton.BringToFront();
languageSearchButton.BringToFront();
groupSearchButton.BringToFront();
categorySearchButton.BringToFront();
serviceBellButton.BringToFront();
orderedSongsButton.BringToFront();
myFavoritesButton.BringToFront();
deliciousFoodButton.BringToFront();
promotionsButton.BringToFront();
mobileSongRequestButton.BringToFront();
qieGeButton.BringToFront();
musicUpButton.BringToFront();
musicDownButton.BringToFront();
micUpButton.BringToFront();
micDownButton.BringToFront();
originalSongButton.BringToFront();
replayButton.BringToFront();
pauseButton.BringToFront();
playButton.BringToFront();
muteButton.BringToFront();
maleKeyButton.BringToFront();
femaleKeyButton.BringToFront();
standardKeyButton.BringToFront();
soundEffectButton.BringToFront();
pitchUpButton.BringToFront();
pitchDownButton.BringToFront();
syncScreenButton.BringToFront();
toggleLightButton.BringToFront();
btnPreviousPage.BringToFront();
btnReturn.BringToFront();
btnNextPage.BringToFront();
btnApplause.BringToFront();
btnSimplifiedChinese.BringToFront();
btnTraditionalChinese.BringToFront();
exitButton.BringToFront();
this.ResumeLayout(false);
this.PerformLayout();
}
private string ReadSelectedThemePath()
{
string configFilePath = Path.Combine(Application.StartupPath, "txt", "theme_description.txt");
try
{
string[] lines = File.ReadAllLines(configFilePath);
foreach (string line in lines)
{
if (line.StartsWith("Selected Theme: "))
{
string themePath = line.Substring("Selected Theme: ".Length).Trim();
return themePath;
}
}
}
catch (Exception ex)
{
Console.WriteLine(String.Format("讀取文件時發生錯誤: {0}", ex.Message));
}
return string.Empty;
}
private void InitializePictureBox()
{
pictureBox1 = new PictureBox
{
Dock = DockStyle.Fill,
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage
};
pictureBox2 = new PictureBox
{
Dock = DockStyle.Fill,
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBox3 = new PictureBox
{
Dock = DockStyle.Fill,
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBox4 = new PictureBox
{
Dock = DockStyle.Fill,
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBox5 = new PictureBox
{
Dock = DockStyle.Fill,
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBox6 = new PictureBox
{
Dock = DockStyle.Fill,
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxZhuYinSingers = new PictureBox
{
Name = "pictureBoxZhuYinSingers",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxZhuYinSongs = new PictureBox
{
Name = "pictureBoxZhuYinSongs",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxEnglishSingers = new PictureBox
{
Name = "pictureBoxEnglishSingers",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxEnglishSongs = new PictureBox
{
Name = "pictureBoxEnglishSongs",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxArtistSearch = new PictureBox
{
Name = "pictureBoxArtistSearch",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxWordCountSongs = new PictureBox
{
Name = "pictureBoxWordCountSongs",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxWordCountSingers = new PictureBox
{
Name = "pictureBoxWordCountSingers",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxPinYinSingers = new PictureBox
{
Name = "pictureBoxPinYinSingers",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxPinYinSongs = new PictureBox
{
Name = "pictureBoxPinYinSongs",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxSongIDSearch = new PictureBox
{
Name = "pictureBoxSongIDSearch",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxHandWritingSingers = new PictureBox
{
Name = "pictureBoxHandWritingSingers",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxHandWritingSongs = new PictureBox
{
Name = "pictureBoxHandWritingSongs",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
FavoritePictureBox = new PictureBox
{
Name = "FavoritePictureBox",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
FavoritePictureBox.Paint += new PaintEventHandler(FavoritePictureBox_Paint);
promotionsPictureBox = new PictureBox
{
Name = "promotionsPictureBox",
Dock = DockStyle.Fill,
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxToggleLight = new PictureBox
{
Name = "pictureBoxToggleLight",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
VodScreenPictureBox = new PictureBox
{
Name = "VodScreenPictureBox",
BackColor = Color.FromArgb(128, 0, 0, 0),
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
overlayPanel = new Panel
{
Name = "overlayPanel",
Dock = DockStyle.Fill,
BackColor = Color.FromArgb(128, 0, 0, 0),
Visible = false
};
pictureBoxQRCode = new PictureBox
{
Name = "pictureBoxQRCode",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
pictureBoxSceneSoundEffects = new PictureBox
{
Name = "pictureBoxSceneSoundEffects",
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Visible = false
};
this.Controls.Add(pictureBox1);
this.Controls.Add(pictureBox2);
this.Controls.Add(pictureBox3);
this.Controls.Add(pictureBox4);
this.Controls.Add(pictureBox5);
this.Controls.Add(pictureBox6);
this.Controls.Add(pictureBoxQRCode);
this.Controls.Add(pictureBoxZhuYinSingers);
this.Controls.Add(pictureBoxWordCountSongs);
this.Controls.Add(pictureBoxZhuYinSongs);
this.Controls.Add(pictureBoxEnglishSingers);
this.Controls.Add(pictureBoxEnglishSongs);
this.Controls.Add(pictureBoxArtistSearch);
this.Controls.Add(pictureBoxWordCountSingers);
this.Controls.Add(pictureBoxPinYinSingers);
this.Controls.Add(pictureBoxPinYinSongs);
this.Controls.Add(pictureBoxHandWritingSingers);
this.Controls.Add(pictureBoxHandWritingSongs);
this.Controls.Add(pictureBoxSongIDSearch);
this.Controls.Add(FavoritePictureBox);
this.Controls.Add(promotionsPictureBox);
this.Controls.Add(pictureBoxToggleLight);
this.Controls.Add(VodScreenPictureBox);
this.Controls.Add(overlayPanel);
this.Controls.Add(pictureBoxSceneSoundEffects);
}
private void PhoneticButton_Click(object sender, EventArgs e)
{
var button = sender as Button;
if (button != null && button.Tag != null)
{
if (inputBoxZhuYinSingers.Visible)
{
inputBoxZhuYinSingers.Text += button.Tag.ToString();
}
else if (inputBoxZhuYinSongs.Visible)
{
inputBoxZhuYinSongs.Text += button.Tag.ToString();
}
}
}
private void LightControlTimer_Tick(object sender, EventArgs e)
{
if (lightControlTimer.Tag != null)
{
SendCommandThroughSerialPort(lightControlTimer.Tag.ToString());
}
}
public static void SendCommandThroughSerialPort(string command)
{
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{
try
{
byte[] commandBytes = HexStringToByteArray(command);
SerialPortManager.mySerialPort.Write(commandBytes, 0, commandBytes.Length);
}
catch (Exception ex)
{
Console.WriteLine("Failed to send command: " + ex.Message);
}
}
else
{
Console.WriteLine("Serial port is not open.");
}
}
public static byte[] HexStringToByteArray(string hex)
{
hex = hex.Replace(" ", "");
byte[] bytes = new byte[hex.Length / 2];
for (int i = 0; i < hex.Length; i += 2)
{
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}
return bytes;
}
private void RecognizeInk(InkOverlay inkOverlay, ListBox candidateListBox)
{
if (inkOverlay.Ink.Strokes.Count > 0)
{
using (RecognizerContext context = new RecognizerContext())
{
context.Strokes = inkOverlay.Ink.Strokes;
RecognitionStatus status;
RecognitionResult result = context.Recognize(out status);
if (status == RecognitionStatus.NoError)
{
List<string> candidates = new List<string>();
foreach (RecognitionAlternate alternate in result.GetAlternatesFromSelection())
{
candidates.Add(alternate.ToString());
}
ShowCandidates(candidates, candidateListBox);
}
else
{
candidateListBox.Visible = false;
}
}
}
else
{
candidateListBox.Visible = false;
}
}
private void ShowCandidates(List<string> candidates, ListBox candidateListBox)
{
candidateListBox.Items.Clear();
foreach (var candidate in candidates)
{
candidateListBox.Items.Add(candidate);
}
candidateListBox.Visible = true;
}
//按鈕設定,游標移開後恢復預設圖案
private void ConfigureButton(Button button, int posX, int posY, int width, int height,
Bitmap normalStateImage, Bitmap mouseOverImage, Bitmap mouseDownImage,
EventHandler clickEventHandler)
{
ResizeAndPositionButton(button, posX, posY, width, height);
Rectangle cropArea = new Rectangle(button.Location.X, button.Location.Y, button.Size.Width, button.Size.Height);
//button.BackgroundImage = normalStateImage.Clone(cropArea, normalStateImage.PixelFormat);
button.BackgroundImage = normalStateImage;
button.BackgroundImageLayout = ImageLayout.Stretch;
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderSize = 0;
button.FlatAppearance.MouseDownBackColor = Color.Transparent;
button.FlatAppearance.MouseOverBackColor = Color.Transparent;
//button.MouseEnter += (sender, e) => button.BackgroundImage = mouseOverImage.Clone(cropArea, mouseOverImage.PixelFormat);
//button.MouseLeave += (sender, e) => button.BackgroundImage = normalStateImage.Clone(cropArea, normalStateImage.PixelFormat);
//button.MouseDown += (sender, e) => button.BackgroundImage = mouseDownImage.Clone(cropArea, mouseDownImage.PixelFormat);
//button.MouseUp += (sender, e) => button.BackgroundImage = normalStateImage.Clone(cropArea, normalStateImage.PixelFormat);
button.MouseEnter += (sender, e) => button.BackgroundImage = mouseOverImage;
button.MouseLeave += (sender, e) => button.BackgroundImage = normalStateImage;
button.MouseDown += (sender, e) => button.BackgroundImage = mouseDownImage;
button.MouseUp += (sender, e) => button.BackgroundImage = normalStateImage;
if (clickEventHandler != null)
{
button.Click += clickEventHandler;
}
button.AutoSize = true;
this.Controls.Add(button);
}
//設定透明按鈕
private void ConfigureTransButton(Button button, int posX, int posY, int width, int height,
EventHandler clickEventHandler)
{
ResizeAndPositionButton(button, posX, posY, width, height);
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderSize = 0;
button.FlatAppearance.MouseOverBackColor = Color.Transparent;
button.FlatAppearance.MouseDownBackColor = Color.Transparent;
button.BackColor = Color.Transparent;
if (clickEventHandler != null)
{
button.Click += clickEventHandler;
}
this.Controls.Add(button);
}
#region
private void InitializeOtherControls()
{
var data = LoadBtnConfigData();
InitializeButton(ref newSongAlertButton, ref newSongAlertNormalBackground, ref newSongAlertActiveBackground, "newSongAlertButton", 20, 98, 105, 120, data["PrimaryFormBtn"]["AlertNormal"], data["PrimaryFormBtn"]["AlertActive"], NewSongAlertButton_Click);
InitializeButton(ref hotPlayButton, ref hotPlayNormalBackground, ref hotPlayActiveBackground, "hotPlayButton", 137, 98, 106, 120, data["PrimaryFormBtn"]["HotNormal"], data["PrimaryFormBtn"]["HotActive"], HotPlayButton_Click);
InitializeButton(ref singerSearchButton, ref singerSearchNormalBackground, ref singerSearchActiveBackground, "singerSearchButton", 255, 98, 106, 120, data["PrimaryFormBtn"]["SingerNormal"], data["PrimaryFormBtn"]["SingerActive"], SingerSearchButton_Click);
InitializeButton(ref songSearchButton, ref songSearchNormalBackground, ref songSearchActiveBackground, "songSearchButton", 373, 98, 106, 120, data["PrimaryFormBtn"]["SongNormal"], data["PrimaryFormBtn"]["SongActive"], SongSearchButton_Click);
InitializeButton(ref languageSearchButton, ref languageSearchNormalBackground, ref languageSearchActiveBackground, "languageSearchButton", 491, 98, 106, 120, data["PrimaryFormBtn"]["LangNormal"], data["PrimaryFormBtn"]["LangActive"], LanguageSongSelectionButton_Click);
InitializeButton(ref groupSearchButton, ref groupSearchNormalBackground, ref groupSearchActiveBackground, "groupSearchButton", 608, 98, 106, 120, data["PrimaryFormBtn"]["GroupNormal"], data["PrimaryFormBtn"]["GroupActive"], GroupSongSelectionButton_Click);
InitializeButton(ref categorySearchButton, ref categorySearchNormalBackground, ref categorySearchActiveBackground, "categorySearchButton", 726, 98, 106, 120, data["PrimaryFormBtn"]["CategNormal"], data["PrimaryFormBtn"]["CategActive"], CategorySearchButton_Click);
serviceBellButton = new Button { Text = "" };
ConfigureButton(serviceBellButton, 843, 98, 107, 120,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別上方_服務鈴(未按).png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別上方_服務鈴(已按).png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別上方_服務鈴(已按).png")),
(sender, e) => OnServiceBellButtonClick(sender, e));
InitializeButton(ref orderedSongsButton, ref orderedSongsNormalBackground, ref orderedSongsActiveBackground, "orderedSongsButton", 961, 98, 107, 120, data["PrimaryFormBtn"]["OrderSongNormal"], data["PrimaryFormBtn"]["OrderSongActive"], OrderedSongsButton_Click);
InitializeButton(ref myFavoritesButton, ref myFavoritesNormalBackground, ref myFavoritesActiveBackground, "myFavoritesButton", 1079, 98, 107, 120, data["PrimaryFormBtn"]["FavoriteNormal"], data["PrimaryFormBtn"]["FavoriteActive"], MyFavoritesButton_Click);
InitializeButton(ref promotionsButton, ref promotionsNormalBackground, ref promotionsActiveBackground, "promotionsButton", 1197, 98, 107, 120, data["PrimaryFormBtn"]["PromotNormal"], data["PrimaryFormBtn"]["PromotActive"], promotionsButton_Click);
InitializeButton(ref deliciousFoodButton, ref deliciousFoodNormalBackground, ref deliciousFoodActiveBackground, "deliciousFoodButton", 1315, 98, 107, 120, data["PrimaryFormBtn"]["FoodNormal"], data["PrimaryFormBtn"]["FoodActive"], DeliciousFoodButton_Click);
mobileSongRequestButton = new Button { Text = "" };
mobileSongRequestButton.Name = "mobileSongRequestButton";
ConfigureButton(mobileSongRequestButton, 1198, 629, 223, 88,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別上方_手機點歌.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別上方_手機點歌.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別上方_手機點歌.png")),
MobileSongRequestButton_Click);
qieGeButton = new Button { Text = "" };
qieGeButton.Name = "qieGeButton";
ConfigureButton(qieGeButton, 20, 738, 92, 147,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_切歌.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_切歌.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_切歌.png")),
(sender, e) => videoPlayerForm.PlayNextSong());
musicUpButton = new Button { Text = "" };
musicUpButton.Name = "musicUpButton";
ConfigureButton(musicUpButton, 128, 738, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_音樂+.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_音樂+.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\音樂及麥克風icon_音樂++.png")),
(sender, e) => { OverlayForm.MainForm.ShowTopRightLabel("音量 ↑", "a2 b3 a4"); });
musicDownButton = new Button { Text = "" };
musicDownButton.Name = "musicDownButton";
ConfigureButton(musicDownButton, 128, 823, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_音樂-.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_音樂-.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\音樂及麥克風icon_音樂--.png")),
(sender, e) => { OverlayForm.MainForm.ShowTopRightLabel("音量 ↓", "a2 b4 a4"); });
micUpButton = new Button { Text = "" };
micUpButton.Name = "micUpButton";
ConfigureButton(micUpButton, 238, 738, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_麥克風+.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_麥克風+.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\音樂及麥克風icon_麥克風++.png")),
(sender, e) => { OverlayForm.MainForm.ShowTopRightLabel("麥克風 ↑", "a2 b5 a4"); });
micDownButton = new Button { Text = "" };
micDownButton.Name = "micDownButton";
ConfigureButton(micDownButton, 238, 823, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_麥克風-.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_麥克風-.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\音樂及麥克風icon_麥克風--.png")),
(sender, e) => { OverlayForm.MainForm.ShowTopRightLabel("麥克風 ↓", "a2 b6 a4"); });
originalSongButton = new Button { Text = "" };
originalSongButton.Name = "originalSongButton";
ConfigureButton(originalSongButton, 347, 738, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_原唱.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_原唱.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_原唱.png")),
OriginalSongButton_Click);
replayButton = new Button { Text = "" };
replayButton.Name = "replayButton";
ConfigureButton(replayButton, 347, 823, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_重唱.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_重唱.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_重唱.png")),
ReplayButton_Click);
pauseButton = new Button
{
Text = "",
Name = "pauseButton"
};
ConfigureButton(pauseButton, 456, 738, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_暫停.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_暫停.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_暫停.png")),
PauseButton_Click);
playButton = new Button
{
Text = "",
Name = "playButton",
Visible = false
};
ConfigureButton(playButton, 456, 738, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_暫停.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_暫停.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_暫停.png")),
PlayButton_Click);
muteButton = new Button { Text = "" };
muteButton.Name = "muteButton";
ConfigureButton(muteButton, 456, 823, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_靜音.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_靜音.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_靜音.png")),
MuteUnmuteButton_Click);
maleKeyButton = new Button { Text = "" };
maleKeyButton.Name = "maleKeyButton";
ConfigureButton(maleKeyButton, 564, 738, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_男調.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_男調.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_男調.png")),
MaleKeyButton_Click);
femaleKeyButton = new Button { Text = "" };
femaleKeyButton.Name = "femaleKeyButton";
ConfigureButton(femaleKeyButton, 565, 823, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_女調.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_女調.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_女調.png")),
FemaleKeyButton_Click);
standardKeyButton = new Button { Text = "" };
standardKeyButton.Name = "standardKeyButton";
ConfigureButton(standardKeyButton, 674, 738, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_標準調.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_標準調.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_標準調.png")),
StandardKeyButton_Click);
soundEffectButton = new Button { Text = "" };
soundEffectButton.Name = "soundEffectButton";
ConfigureButton(soundEffectButton, 674, 823, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_音效.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_音效.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_音效.png")),
SoundEffectButton_Click);
pitchUpButton = new Button { Text = "" };
pitchUpButton.Name = "pitchUpButton";
ConfigureButton(pitchUpButton, 784, 738, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_升調.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_升調.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_升調.png")),
PitchUpButton_Click);
pitchDownButton = new Button { Text = "" };
pitchDownButton.Name = "pitchDownButton";
ConfigureButton(pitchDownButton, 784, 823, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_降調.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_降調.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_降調.png")),
PitchDownButton_Click);
syncScreenButton = new Button { Text = "" };
syncScreenButton.Name = "syncScreenButton";
ConfigureButton(syncScreenButton, 893, 736, 92, 149,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_同步畫面.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_同步畫面.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_同步畫面.png")),
SyncScreenButton_Click);
toggleLightButton = new Button { Text = "" };
toggleLightButton.Name = "toggleLightButton";
ConfigureButton(toggleLightButton, 1002, 736, 92, 149,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_燈光控制.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_燈光控制.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_燈光控制.png")),
ToggleLightButton_Click);
btnPreviousPage = new Button { Text = "" };
btnPreviousPage.Name = "btnPreviousPageButton";
ConfigureButton(btnPreviousPage, 1110, 738, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_上一頁.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_上一頁.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_上一頁.png")),
PreviousPageButton_Click);
btnReturn = new Button { Text = "" };
btnReturn.Name = "btnReturn";
ConfigureButton(btnReturn, 1220, 738, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_退出.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_退出.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_退出.png")),
ShouYeButton_Click);
btnNextPage = new Button { Text = "" };
btnNextPage.Name = "btnNextPage";
ConfigureButton(btnNextPage, 1330, 738, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_下一頁.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_下一頁.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_下一頁.png")),
NextPageButton_Click);
btnApplause = new Button { Text = "" };
btnApplause.Name = "btnApplause";
ConfigureButton(btnApplause, 1110, 823, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_掌聲.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_掌聲.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_掌聲.png")),
ApplauseButton_Click);
btnSimplifiedChinese = new Button { Text = "" };
btnSimplifiedChinese.Name = "btnSimplifiedChinese";
ConfigureButton(btnSimplifiedChinese, 1330, 823, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_簡體.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_簡體.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_簡體.png")),
SimplifiedChineseButton_Click);
btnTraditionalChinese = new Button { Text = "" };
btnTraditionalChinese.Name = "btnTraditionalChinese";
ConfigureButton(btnTraditionalChinese, 1220, 823, 93, 62,
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_繁體.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_繁體.png")),
new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別下方_繁體.png")),
TraditionalChineseButton_Click);
/* 關閉應用程式按鈕*/
exitButton = new Button { };
/*exitButton.Name = "exitButton";
ConfigureButton(exitButton, 1394, 2, 1428 - 1394, 37 - 2,
resizedNormalStateImage, resizedMouseOverImage, resizedMouseDownImage,
(sender, e) => Application.Exit());*/
}
#endregion
private void InitializeButton(ref Button button, ref Bitmap normalBackground, ref Bitmap activeBackground, string buttonName, int x, int y, int width, int height, string imagePath, string imagePathb, EventHandler clickEventHandler)
{
var data = LoadConfigData();
button = new Button { Text = "", Name = buttonName };
ResizeAndPositionButton(button, x, y, width, height);
normalBackground = new Bitmap(Path.Combine(serverPath, imagePath));
activeBackground = new Bitmap(Path.Combine(serverPath, imagePathb));
button.BackgroundImage = normalBackground;
button.BackgroundImageLayout = ImageLayout.Stretch;
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderSize = 0;
if (clickEventHandler != null)
{
button.Click += clickEventHandler;
}
this.Controls.Add(button);
}
private void InitializeMultiPagePanel()
{
// 獲取螢幕尺寸
Screen screen = Screen.PrimaryScreen;
int screenWidth = screen.Bounds.Width;
int screenHeight = screen.Bounds.Height;
// 計算縮放比例
float widthRatio = screenWidth / 1440f;
float heightRatio = screenHeight / 900f;
multiPagePanel = new MultiPagePanel();
// 計算面板位置和大小
int panelX = (int)(PanelStartLeft * widthRatio);
int panelY = (int)(PanelStartTop * heightRatio);
int panelWidth = (int)((PanelEndLeft - PanelStartLeft) * widthRatio);
int panelHeight = (int)((PanelEndTop - PanelStartTop) * heightRatio);
multiPagePanel.Location = new Point(panelX, panelY);
multiPagePanel.Size = new Size(panelWidth, panelHeight);
this.Controls.Add(multiPagePanel);
multiPagePanel.BringToFront();
}
private SongData currentSelectedSong;
public void Label_Click(object sender, EventArgs e)
{
InitializeButtonsForVodScreenPictureBox();
var data = LoadConfigData();
var label = sender as Label;
if (label != null && label.Tag is SongData)
{
currentSelectedSong = label.Tag as SongData;
this.DoubleBuffered = true;
this.SuspendLayout();
DrawTextOnVodScreenPictureBox(Path.Combine(serverPath, @"themes\superstar\button\3.介面\歌曲點播_空白介面.png"), currentSelectedSong);
SetVodScreenPictureBoxAndButtonsVisibility(true);
this.ResumeLayout(true);
}
}
public static void WriteLog(string message)
{
string logFilePath = Path.Combine(Application.StartupPath, "txt", "logfile.txt");
using (StreamWriter sw = new StreamWriter(logFilePath, true))
{
sw.WriteLine(String.Format("{0}: {1}", DateTime.Now, message));
}
}
private void NextPageButton_Click(object sender, EventArgs e)
{
multiPagePanel.LoadNextPage();
}
private void SimplifiedChineseButton_Click(object sender, EventArgs e)
{
Console.WriteLine("切換到簡體顯示"); // 添加日誌
if (multiPagePanel != null)
{
multiPagePanel.IsSimplified = true;
btnSimplifiedChinese.Enabled = false;
btnTraditionalChinese.Enabled = true;
}
}
private void TraditionalChineseButton_Click(object sender, EventArgs e)
{
Console.WriteLine("切換到繁體顯示"); // 添加日誌
if (multiPagePanel != null)
{
multiPagePanel.IsSimplified = false;
btnSimplifiedChinese.Enabled = true;
btnTraditionalChinese.Enabled = false;
}
}
private void PreviousPageButton_Click(object sender, EventArgs e)
{
multiPagePanel.LoadPreviousPage();
}
private Bitmap ResizeImage(Image image, int width, int height)
{
var destRect = new Rectangle(0, 0, width, height);
var destImage = new Bitmap(width, height);
destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
using (var graphics = Graphics.FromImage(destImage))
{
graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
using (var wrapMode = new System.Drawing.Imaging.ImageAttributes())
{
wrapMode.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);
graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
}
}
return destImage;
}
private void LoadImages()
{
var data = LoadConfigData();
string selectedThemePath = ReadSelectedThemePath();
string basePath = Path.Combine(serverPath, selectedThemePath);
int targetWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
int targetHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
normalStateImage = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\0.下方選單_主畫面.jpg"));
resizedNormalStateImage = ResizeImage(normalStateImage, targetWidth, targetHeight);
mouseOverImage = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\0.主選單_已按.jpg"));
resizedMouseOverImage = ResizeImage(mouseOverImage, targetWidth, targetHeight);
mouseDownImage = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\0.主選單_已按.jpg"));
resizedMouseDownImage = ResizeImage(mouseDownImage, targetWidth, targetHeight);
normalStateImageNewSongAlert = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\1.新歌快報_未按.jpg"));
resizedNormalStateImageForNewSongAlert = ResizeImage(normalStateImageNewSongAlert, targetWidth, targetHeight);
mouseOverImageNewSongAlert = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\1.新歌快報_已按.jpg"));
resizedMouseOverImageForNewSongAlert = ResizeImage(mouseOverImageNewSongAlert, targetWidth, targetHeight);
mouseDownImageNewSongAlert = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\1.新歌快報_已按.jpg"));
resizedMouseDownImageForNewSongAlert = ResizeImage(mouseDownImageNewSongAlert, targetWidth, targetHeight);
normalStateImageArtistQuery = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\3.歌星查詢_未按.jpg"));
resizedNormalStateImageForArtistQuery = ResizeImage(normalStateImageArtistQuery, targetWidth, targetHeight);
mouseOverImageArtistQuery = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\3.歌星查詢_已按.jpg"));
resizedMouseOverImageForArtistQuery = ResizeImage(mouseOverImageArtistQuery, targetWidth, targetHeight);
mouseDownImageArtistQuery = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\3.歌星查詢_已按.jpg"));
resizedMouseDownImageForArtistQuery = ResizeImage(mouseDownImageArtistQuery, targetWidth, targetHeight);
normalStateImageSongQuery = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\4.歌名查詢_未按.jpg"));
resizedNormalStateImageForSongQuery = ResizeImage(normalStateImageSongQuery, targetWidth, targetHeight);
mouseOverImageSongQuery = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\4.歌名查詢_已按.jpg"));
resizedMouseOverImageForSongQuery = ResizeImage(mouseOverImageSongQuery, targetWidth, targetHeight);
mouseDownImageSongQuery = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\4.歌名查詢_已按.jpg"));
resizedMouseDownImageForSongQuery = ResizeImage(mouseDownImageSongQuery, targetWidth, targetHeight);
normalStateImageLanguageQuery = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\5.語別查詢_未按.jpg"));
resizedNormalStateImageForLanguageQuery = ResizeImage(normalStateImageLanguageQuery, targetWidth, targetHeight);
mouseOverImageLanguageQuery = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\5.語別查詢_已按.jpg"));
resizedMouseOverImageForLanguageQuery = ResizeImage(mouseOverImageLanguageQuery, targetWidth, targetHeight);
mouseDownImageLanguageQuery = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\5.語別查詢_已按.jpg"));
resizedMouseDownImageForLanguageQuery = ResizeImage(mouseDownImageLanguageQuery, targetWidth, targetHeight);
normalStateImageCategoryQuery = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\7.類別查詢_未按.jpg"));
resizedNormalStateImageForCategoryQuery = ResizeImage(normalStateImageCategoryQuery, targetWidth, targetHeight);
mouseOverImageCategoryQuery = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\7.類別查詢_已按.jpg"));
resizedMouseOverImageForCategoryQuery = ResizeImage(mouseOverImageCategoryQuery, targetWidth, targetHeight);
mouseDownImageCategoryQuery = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\7.類別查詢_已按.jpg"));
resizedMouseDownImageForCategoryQuery = ResizeImage(mouseDownImageCategoryQuery, targetWidth, targetHeight);
normalStateImageForPromotionsAndMenu = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\555021.jpg"));
resizedNormalStateImageForPromotionsAndMenu = ResizeImage(normalStateImageForPromotionsAndMenu, targetWidth, targetHeight);
try
{
string imagePath = Path.Combine(serverPath, "themes\\superstar\\主畫面\\選單內介面_同步畫面.jpg");
if (File.Exists(imagePath))
{
normalStateImageForSyncScreen = new Bitmap(imagePath);
resizedNormalStateImageForSyncScreen = ResizeImage(normalStateImageForSyncScreen, targetWidth, targetHeight);
Console.WriteLine("Image loaded successfully.");
}
else
{
Console.WriteLine("Image file does not exist: " + imagePath);
}
}
catch (Exception ex)
{
Console.WriteLine("Failed to load image: " + ex.Message);
}
normalStateImageForSceneSoundEffects = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\555022.jpg"));
resizedNormalStateImageForSceneSoundEffects = ResizeImage(normalStateImageForSceneSoundEffects, targetWidth, targetHeight);
normalStateImageHotSong = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\2.熱門排行_未按.jpg"));
resizedNormalStateImageForHotSong = ResizeImage(normalStateImageHotSong, targetWidth, targetHeight);
mouseDownImageHotSong = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\2.熱門排行_已按.jpg"));
resizedMouseDownImageForHotSong = ResizeImage(mouseDownImageHotSong, targetWidth, targetHeight);
normalStateImageForLightControl = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\主畫面\\選單內介面_燈光控制.jpg"));
resizedNormalStateImageForLightControl = ResizeImage(normalStateImageForLightControl, targetWidth, targetHeight);
}
private Bitmap CropImage(Bitmap source, Rectangle section)
{
Bitmap bmp = new Bitmap(section.Width, section.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel);
}
return bmp;
}
private void DrawTextOnVodScreenPictureBox(string imagePath, SongData SongDetail)
{
Bitmap originalImage = new Bitmap(imagePath);
VodScreenPictureBox.Image = originalImage;
int screenWidth = 1440;
int screenHeight = 900;
int pictureBoxWidth = (int)(938 * 0.8f);
int pictureBoxHeight = (int)(209 * 0.8f);
int xPosition = (screenWidth - pictureBoxWidth) / 2;
int yPosition = (screenHeight - pictureBoxHeight) / 2;
using (Graphics g = Graphics.FromImage(originalImage))
{
// 計算文字寬度
float dpiX = g.DpiX;
float points = 25;
float pixels = points * (dpiX / 72);
Font font = new Font("微軟正黑體", points, FontStyle.Bold);
// 根據文字長度設置字體大小
if (SongDetail.getNameLength() > 18)
{
font = new Font("微軟正黑體", 17, FontStyle.Bold);
}
else if (SongDetail.getNameLength() > 13)
{
font = new Font("微軟正黑體", 21, FontStyle.Bold);
}
else
{
font = new Font("微軟正黑體", 25, FontStyle.Bold);
}
Brush textBrush = Brushes.Black;
string songInfo = SongDetail.getName() ?? "未提供歌曲信息";
g.DrawString(songInfo, font, textBrush, new PointF(121, 18));
}
ResizeAndPositionPictureBox(VodScreenPictureBox, xPosition, yPosition, pictureBoxWidth, pictureBoxHeight);
VodScreenPictureBox.Visible = true;
}
public static void ResizeAndPositionButton(Button button, int x, int y, int width, int height)
{
// 獲取螢幕尺寸
Screen screen = Screen.PrimaryScreen;
int screenWidth = screen.Bounds.Width;
int screenHeight = screen.Bounds.Height;
// 計算縮放比例
float widthRatio = screenWidth / 1440f;
float heightRatio = screenHeight / 900f;
// 調整按鈕位置和大小
button.Location = new Point(
(int)(x * widthRatio),
(int)(y * heightRatio)
);
button.Size = new Size(
(int)(width * widthRatio),
(int)(height * heightRatio)
);
}
private static void ResizeAndPositionPictureBox(PictureBox pictureBox, int originalX, int originalY, int originalWidth, int originalHeight)
{
int screenW = Screen.PrimaryScreen.Bounds.Width;
int screenH = Screen.PrimaryScreen.Bounds.Height;
float widthRatio = screenW / (float)1440;
float heightRatio = screenH / (float)900;
pictureBox.Location = new Point(
(int)(originalX * widthRatio),
(int)(originalY * heightRatio)
);
pictureBox.Size = new Size(
(int)(originalWidth * widthRatio),
(int)(originalHeight * heightRatio)
);
}
public static void ResizeAndPositionControl(Control control, int x, int y, int width, int height)
{
// 獲取螢幕尺寸
Screen screen = Screen.PrimaryScreen;
int screenWidth = screen.Bounds.Width;
int screenHeight = screen.Bounds.Height;
// 計算縮放比例
float widthRatio = screenWidth / 1440f;
float heightRatio = screenHeight / 900f;
// 調整控件位置和大小
control.Location = new Point(
(int)(x * widthRatio),
(int)(y * heightRatio)
);
control.Size = new Size(
(int)(width * widthRatio),
(int)(height * heightRatio)
);
}
private void DeliciousFoodButton_Click(object sender, EventArgs e)
{
var data = LoadConfigData();
ResetPrimaryBtnStatus();
deliciousFoodButton.BackgroundImage = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別上方_美味菜單(已按).png"));
isOnOrderedSongsPage = false;
SetHotSongButtonsVisibility(false);
SetNewSongButtonsVisibility(false);
SetSingerSearchButtonsVisibility(false);
SetSongSearchButtonsVisibility(false);
SetPictureBoxLanguageButtonsVisibility(false);
SetGroupButtonsVisibility(false);
SetZhuYinSingersAndButtonsVisibility(false);
SetZhuYinSongsAndButtonsVisibility(false);
SetEnglishSingersAndButtonsVisibility(false);
SetEnglishSongsAndButtonsVisibility(false);
SetPinYinSingersAndButtonsVisibility(false);
SetPinYinSongsAndButtonsVisibility(false);
SetPictureBoxCategoryAndButtonsVisibility(false);
promotionsAndMenuPanel.currentPageIndex = 0;
promotionsAndMenuPanel.LoadImages(menu);
promotionsAndMenuPanel.Visible = true;
promotionsAndMenuPanel.BringToFront();
previousPromotionButton.Visible = true;
previousPromotionButton.BringToFront();
nextPromotionButton.Visible = true;
nextPromotionButton.BringToFront();
closePromotionsButton.Visible = true;
closePromotionsButton.BringToFront();
if (pictureBoxQRCode != null)
{
pictureBoxQRCode.Visible = false;
closeQRCodeButton.Visible = false;
}
}
private void MobileSongRequestButton_Click(object sender, EventArgs e)
{
SetHotSongButtonsVisibility(false);
SetNewSongButtonsVisibility(false);
SetSingerSearchButtonsVisibility(false);
SetSongSearchButtonsVisibility(false);
SetPictureBoxLanguageButtonsVisibility(false);
SetZhuYinSingersAndButtonsVisibility(false);
SetZhuYinSongsAndButtonsVisibility(false);
SetEnglishSingersAndButtonsVisibility(false);
SetEnglishSongsAndButtonsVisibility(false);
SetPinYinSingersAndButtonsVisibility(false);
SetPinYinSongsAndButtonsVisibility(false);
SetGroupButtonsVisibility(false);
if (pictureBoxQRCode != null)
{
pictureBoxQRCode.Visible = true;
pictureBoxQRCode.BringToFront();
closeQRCodeButton.Visible = true;
closeQRCodeButton.BringToFront();
}
else
{
Console.WriteLine("pictureBoxQRCode is not initialized!");
}
}
public void OriginalSongButton_Click(object sender, EventArgs e)
{
videoPlayerForm.ToggleVocalRemoval();
}
private void ReplayButton_Click(object sender, EventArgs e)
{
videoPlayerForm.ReplayCurrentSong();
}
public void PauseButton_Click(object sender, EventArgs e)
{
videoPlayerForm.Pause();
pauseButton.Visible = false;
playButton.Visible = true;
}
public void PlayButton_Click(object sender, EventArgs e)
{
videoPlayerForm.Play();
playButton.Visible = false;
pauseButton.Visible = true;
}
/// <summary>
/// 右下角關閉按鈕事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ShouYeButton_Click(object sender, EventArgs e)
{ /*Console.WriteLine("playedSongsHistory");
foreach(var song in playedSongsHistory){
Console.WriteLine(song.ToString());
}
Console.WriteLine("userRequestedSongs");
foreach(var song in userRequestedSongs){
Console.WriteLine(song.ToString());
}*/
if (multiPagePanel.get_currentSongList() == SongList.GetHistory())
return;
autoRefreshTimer.Stop(); // 停止自动刷新
FindFirstNonEmptyText(inputBoxZhuYinSingers
, inputBoxZhuYinSongs
, inputBoxEnglishSingers
, inputBoxEnglishSongs
, inputBoxPinYinSingers
, inputBoxPinYinSongs
, inputBoxWordCountSingers
, inputBoxWordCountSongs
, inputBoxSongIDSearch
, handwritingInputBoxForSongs
, handwritingInputBoxForSingers);
foreach (var label in songLabels)
{
this.Controls.Remove(label);
label.Dispose();
}
songLabels.Clear();
}
/// <summary>
/// 查詢空字串,將第一個不為空的字串,重新刷新
/// </summary>
/// <param name="controls"></param>
private void FindFirstNonEmptyText(params Control[] controls)
{
var searchActions = new Dictionary<Control, Action>
{
{ inputBoxZhuYinSingers, FindZhuYiSingers },
{ inputBoxZhuYinSongs, FindZhuYiSongs },
{ inputBoxEnglishSingers, FindEnglishSingers },
{ inputBoxEnglishSongs, FindEnglishSongs },
{ inputBoxPinYinSingers, FindPinYinSingers },
{ inputBoxPinYinSongs, FindPinYinSongs },
{ inputBoxWordCountSingers, FindWordCountSingers },
{ inputBoxWordCountSongs, FindWordCountSongs },
{ inputBoxSongIDSearch, FindNumberSongs },
{ handwritingInputBoxForSongs, FindHandwritingSongs },
{ handwritingInputBoxForSingers, FindHandwritingSingers },
};
foreach (var control in controls)
{
if (!string.IsNullOrEmpty(control.Text))
{
var temp = control.Text;
ResetinputBox(); // 清除所有輸入框
control.Text = temp; // 還原唯一有內容的那個
if (searchActions.TryGetValue(control, out var action))
{
action.Invoke(); // 執行對應的查詢方法
}
break; // 只處理第一個有文字的輸入框
}
}
}
/// <summary>
/// 重置所有輸入框
/// </summary>
private void ResetinputBox()
{
inputBoxZhuYinSingers?.Clear();
inputBoxZhuYinSongs?.Clear();
inputBoxEnglishSingers?.Clear();
inputBoxEnglishSongs?.Clear();
inputBoxPinYinSingers?.Clear();
inputBoxPinYinSongs?.Clear();
inputBoxWordCountSingers?.Clear();
inputBoxWordCountSongs?.Clear();
inputBoxSongIDSearch?.Clear();
handwritingInputBoxForSongs?.Clear();
handwritingInputBoxForSingers?.Clear();
}
#region
private void MuteUnmuteButton_Click(object sender, EventArgs e)
{
//SetHotSongButtonsVisibility(false);
//SetNewSongButtonsVisibility(false);
//SetSingerSearchButtonsVisibility(false);
//SetSongSearchButtonsVisibility(false);
//SetPictureBoxToggleLightAndButtonsVisibility(false);
if (videoPlayerForm.isMuted)
{
videoPlayerForm.SetVolume(videoPlayerForm.previousVolume);
videoPlayerForm.isMuted = false;
OverlayForm.MainForm.HideMuteLabel();
}
else
{
videoPlayerForm.previousVolume = videoPlayerForm.GetVolume();
videoPlayerForm.SetVolume(-10000);
videoPlayerForm.isMuted = true;
OverlayForm.MainForm.ShowMuteLabel();
}
}
private void MaleKeyButton_Click(object sender, EventArgs e)
{
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{
byte[] commandBytesIncreasePitch1 = new byte[] { 0xA2, 0x7F, 0xA4 };
SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch1, 0, commandBytesIncreasePitch1.Length);
byte[] commandBytesDecreasePitch = new byte[] { 0xA2, 0xB2, 0xA4 };
SerialPortManager.mySerialPort.Write(commandBytesDecreasePitch, 0, commandBytesDecreasePitch.Length);
SerialPortManager.mySerialPort.Write(commandBytesDecreasePitch, 0, commandBytesDecreasePitch.Length);
}
else
{
MessageBox.Show("串口未開啟,無法發送降調指令。");
}
}
private void FemaleKeyButton_Click(object sender, EventArgs e)
{
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{
byte[] commandBytesIncreasePitch1 = new byte[] { 0xA2, 0x7F, 0xA4 };
SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch1, 0, commandBytesIncreasePitch1.Length);
byte[] commandBytesIncreasePitch = new byte[] { 0xA2, 0xB1, 0xA4 };
SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch, 0, commandBytesIncreasePitch.Length);
SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch, 0, commandBytesIncreasePitch.Length);
}
else
{
MessageBox.Show("串口未開啟,無法發送升調指令。");
}
}
private void StandardKeyButton_Click(object sender, EventArgs e)
{
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{
byte[] commandBytesIncreasePitch = new byte[] { 0xA2, 0x7F, 0xA4 };
SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch, 0, commandBytesIncreasePitch.Length);
}
else
{
MessageBox.Show("串口未開啟,無法發送升調指令。");
}
}
private void PitchUpButton_Click(object sender, EventArgs e)
{
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{
byte[] commandBytesIncreasePitch = new byte[] { 0xA2, 0xB1, 0xA4 };
SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch, 0, commandBytesIncreasePitch.Length);
}
else
{
MessageBox.Show("串口未開啟,無法發送升調指令。");
}
}
private void PitchDownButton_Click(object sender, EventArgs e)
{
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{
byte[] commandBytesDecreasePitch = new byte[] { 0xA2, 0xB2, 0xA4 };
SerialPortManager.mySerialPort.Write(commandBytesDecreasePitch, 0, commandBytesDecreasePitch.Length);
}
else
{
MessageBox.Show("串口未開啟,無法發送降調指令。");
}
}
private void ApplauseButton_Click(object sender, EventArgs e)
{
PlayApplauseSound();
}
private bool isWaiting = false;
//服務鈴事件
private async void OnServiceBellButtonClick(object sender, EventArgs e)
{
if (isWaiting) return;
isWaiting = true;
// 显示提示信息
//OverlayForm.MainForm.HideAllLabels();
OverlayForm.MainForm.ShowTopRightLabel("服務鈴", "a2 53 a4");
// 延迟3秒
await Task.Delay(3000);
isWaiting = false;
}
#endregion
private void InitializeSendOffPanel()
{
sendOffPanel = new Panel
{
Dock = DockStyle.Fill,
//BackColor = Color.Black,
BackgroundImage = LoadSendOffImage(),
BackgroundImageLayout = ImageLayout.Stretch
};
// 初始化服務鈴圖標
serviceBellPictureBox = new PictureBox
{
Visible = true,
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Image = LoadButtonImage("服務鈴.png"),
Cursor = System.Windows.Forms.Cursors.Hand,
};
// 添加服務鈴點擊事件
serviceBellPictureBox.Click += (sender, e) =>
{
if (serviceBellButton != null)
{
OnServiceBellButtonClick(sender, e);
}
};
// 使用 PictureBox 並加載小圖片
buttonMiddle = new PictureBox
{
Visible = true,
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Image = null,//LoadButtonImage("巨.png")
Cursor = System.Windows.Forms.Cursors.Hand
};
buttonTopRight = new PictureBox
{
Visible = true,
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Image = null, //LoadButtonImage("級.png")
Cursor = System.Windows.Forms.Cursors.Hand
};
buttonTopLeft = new PictureBox
{
Visible = true,
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Image = null, //LoadButtonImage("超.png")
Cursor = System.Windows.Forms.Cursors.Hand
};
buttonThanks = new PictureBox
{
Visible = true,
BackColor = Color.Transparent,
SizeMode = PictureBoxSizeMode.StretchImage,
Image = null, //LoadButtonImage("星.png")
Cursor = System.Windows.Forms.Cursors.Hand
};
// 設定按鈕的初始位置和大小
UpdateSendOffButtonPositions();
// 添加點擊事件
buttonMiddle.Click += buttonMiddle_Click;
buttonTopRight.Click += buttonTopRight_Click;
buttonTopLeft.Click += buttonTopLeft_Click;
buttonThanks.Click += buttonThanks_Click;
// 添加控件到面板
sendOffPanel.Controls.Add(serviceBellPictureBox); // 添加服務鈴
sendOffPanel.Controls.Add(buttonMiddle);
sendOffPanel.Controls.Add(buttonTopRight);
sendOffPanel.Controls.Add(buttonTopLeft);
sendOffPanel.Controls.Add(buttonThanks);
// 包廂名稱顯示
sendOffPanel.Paint += SendOffPanel_Paint;
// 確保圖片在最上層
serviceBellPictureBox.BringToFront(); // 確保服務鈴在最上層
buttonMiddle.BringToFront();
buttonTopRight.BringToFront();
buttonTopLeft.BringToFront();
buttonThanks.BringToFront();
// 重新計算按鈕位置
sendOffPanel.Resize += (s, e) =>
{
UpdateSendOffButtonPositions();
sendOffPanel.Invalidate(); // 重新繪製面板以更新顯示
};
this.Controls.Add(sendOffPanel);
}
/// <summary>
/// 動態按鈕座標位置設定(依據螢幕大小)
/// </summary>
private void UpdateSendOffButtonPositions()
{
Size designSize = new Size(1920, 1080);
var panelWidth = sendOffPanel.Width;
var panelHeight = sendOffPanel.Height;
// 計算寬高的縮放比例
float scaleX = panelWidth / (float)designSize.Width;
float scaleY = panelHeight / (float)designSize.Height;
// 幫你設定的按鈕位置(以原始座標為基礎)
buttonTopLeft.Location = new Point((int)(1598 * scaleX), (int)(490 * scaleY));
buttonTopRight.Location = new Point(panelWidth - (int)(80 * scaleX), 0);
buttonMiddle.Location = new Point(0, 0);
buttonThanks.Location = new Point((int)(831 * scaleX), (int)(490 * scaleY));
// 設定按鈕縮放後的大小(原始尺寸 * 縮放比例)
buttonTopLeft.Size = new Size((int)(150 * scaleX), (int)(150 * scaleY));
buttonTopRight.Size = new Size((int)(80 * scaleX), (int)(80 * scaleY));
buttonMiddle.Size = new Size((int)(80 * scaleX), (int)(80 * scaleY));
buttonThanks.Size = new Size((int)(150 * scaleX), (int)(150 * scaleY));
// ========== 服務鈴位置與大小 ==========
//serviceBellPictureBox.Location = new Point((int)(757 * scaleX), (int)(151 * scaleY));
serviceBellPictureBox.Location = new Point(740, 103);
//serviceBellPictureBox.Size = new Size((int)(410 * scaleX), (int)(130 * scaleY));
serviceBellPictureBox.Size = new Size(430, 146);
}
/// <summary>
/// 送客畫面包廂名稱顯示
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SendOffPanel_Paint(object sender, PaintEventArgs e)
{
Size designSize = new Size(1920, 1080);
var panelWidth = sendOffPanel.Width;
var panelHeight = sendOffPanel.Height;
// 計算寬高的縮放比例
float scaleX = panelWidth / (float)designSize.Width;
float scaleY = panelHeight / (float)designSize.Height;
float scaledFontSize = 84f * scaleY;
string hostName = System.Net.Dns.GetHostName();
string displayName = "包廂" + hostName.Substring(Math.Max(0, hostName.Length - 3));
using (Font font = new Font("微軟正黑體", scaledFontSize, FontStyle.Bold))
using (Brush brush = new SolidBrush(Color.Red))
{
PointF point_PCName = new PointF(820 * scaleX, 325 * scaleY);
e.Graphics.DrawString(displayName, font, brush, point_PCName);
}
}
// 添加載入按鈕圖片的方法
private Image LoadButtonImage(string imageName)
{
var data = LoadConfigData();
try
{
string filePath = Path.Combine(serverPath, "themes", "superstar", "ButtonImages", imageName);
if (File.Exists(filePath))
{
return Image.FromFile(filePath);
}
return null;
}
catch (Exception ex)
{
Console.WriteLine($"載入按鈕圖片時發生錯誤: {ex.Message}");
return null;
}
}
/// <summary>
/// 加載送客畫面圖片
/// </summary>
/// <returns></returns>
private Image LoadSendOffImage()
{
var data = LoadConfigData();
try
{
string filePath = Path.Combine(serverPath, "themes\\superstar\\主畫面\\選單內介面_送客畫面.jpg");
if (File.Exists(filePath))
{
return Image.FromFile(filePath);
}
else
{
Console.WriteLine("選單內介面_送客畫面.jpg 文件未找到。");
return null;
}
}
catch (Exception ex)
{
Console.WriteLine($"加載送客畫面圖片時發生錯誤: {ex.Message}");
return null;
}
}
// 添加 Form Load 事件處理方法
private void PrimaryForm_Load(object sender, EventArgs e)
{
if (hotPlayButton != null)
{
HotPlayButton_Click(null, EventArgs.Empty);
}
if (Program.room.IsClose())
{
ShowSendOffScreen();
}
// 確保所有控件都已初始化完成後,再觸發熱門排行按鈕點擊
}
private void AutoRefreshTimer_Tick(object sender, EventArgs e)
{
if (isOnOrderedSongsPage)
{
multiPagePanel.RefreshDisplay();
}
}
private void OrderedSongsButton_Click(object sender, EventArgs e)
{
var data = LoadConfigData();
ResetPrimaryBtnStatus();
orderedSongsButton.BackgroundImage = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別上方_已點歌曲(已按).png"));
isOnOrderedSongsPage = true;
autoRefreshTimer.Start(); // 开始自动刷新
// 已點歌曲錨點
var List = SongList.GetHistory();
totalPages = (int)Math.Ceiling((double)List.Count / itemsPerPage);
multiPagePanel.currentPageIndex = 0;
SetHotSongButtonsVisibility(false);
SetNewSongButtonsVisibility(false);
SetSingerSearchButtonsVisibility(false);
SetSongSearchButtonsVisibility(false);
SetPictureBoxLanguageButtonsVisibility(false);
SetGroupButtonsVisibility(false);
SetZhuYinSingersAndButtonsVisibility(false);
SetZhuYinSongsAndButtonsVisibility(false);
SetEnglishSingersAndButtonsVisibility(false);
SetEnglishSongsAndButtonsVisibility(false);
// SetPictureBoxWordCountAndButtonsVisibility(false);
SetPinYinSingersAndButtonsVisibility(false);
SetPinYinSongsAndButtonsVisibility(false);
SetPictureBoxToggleLightAndButtonsVisibility(false);
SetPictureBoxSceneSoundEffectsAndButtonsVisibility(false);
if (pictureBoxQRCode != null)
{
pictureBoxQRCode.Visible = false;
closeQRCodeButton.Visible = false;
}
multiPagePanel.LoadPlayedSongs(List);
}
#region Visible屬性設定
private void SetUIVisible(Control parent)
{
foreach (Control ctrl in parent.Controls)
{
parent.Visible = true;
parent.BringToFront();
ctrl.Visible = true;
ctrl.BringToFront();
if (ctrl.HasChildren)
{
SetUIVisible(ctrl);
}
}
}
private void CloseUI(Control parent)
{
foreach (Control ctrl in parent.Controls)
{
parent.Visible = false;
ctrl.Visible = false;
if (ctrl.HasChildren)
{
CloseUI(ctrl);
}
}
}
#endregion
/// <summary>
/// 從設定檔 (config.ini) 載入 INI 設定數據。
/// </summary>
/// <returns>回傳解析後的 INI 設定數據 (IniData)。</returns>
private IniData LoadConfigData()
{
var parser = new FileIniDataParser();
string iniFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini");
// 使用 UTF-8 讀取 INI 檔案並解析內容
using (var reader = new StreamReader(iniFilePath, Encoding.UTF8))
{
return parser.ReadData(reader);
}
}
private IniData LoadBtnConfigData()
{
var parser = new FileIniDataParser();
string iniFilePath = Path.Combine(serverPath, "img.ini");
// 使用 UTF-8 讀取 INI 檔案並解析內容
using (var reader = new StreamReader(iniFilePath, Encoding.UTF8))
{
return parser.ReadData(reader);
}
}
//主畫面按鍵圖形重置
private void ResetPrimaryBtnStatus()
{
newSongAlertButton.BackgroundImage = newSongAlertNormalBackground;
hotPlayButton.BackgroundImage = hotPlayNormalBackground;
singerSearchButton.BackgroundImage = singerSearchNormalBackground;
songSearchButton.BackgroundImage = songSearchNormalBackground;
languageSearchButton.BackgroundImage = languageSearchNormalBackground;
groupSearchButton.BackgroundImage = groupSearchNormalBackground;
categorySearchButton.BackgroundImage = categorySearchNormalBackground;
orderedSongsButton.BackgroundImage = orderedSongsNormalBackground;
myFavoritesButton.BackgroundImage = myFavoritesNormalBackground;
promotionsButton.BackgroundImage = promotionsNormalBackground;
deliciousFoodButton.BackgroundImage = deliciousFoodNormalBackground;
}
}
}