調整 Barrage 顯示 20250717

This commit is contained in:
jasonchenwork 2025-07-17 13:21:08 +08:00
parent 3fc4eeb497
commit af3286292c
4 changed files with 154 additions and 133 deletions

View File

@ -271,7 +271,7 @@ namespace DualScreenDemo
await HandleOrderSongListRequest(context); await HandleOrderSongListRequest(context);
break; break;
case "/message": case "/message":
await HandlemessageRequest(context); await HandleMessageRequest(context);
break; break;
case "/favorite": case "/favorite":
await HandleFavoriteRequest(context); await HandleFavoriteRequest(context);
@ -858,7 +858,37 @@ namespace DualScreenDemo
action(); action();
} }
} }
private static async Task HandlemessageRequest(HttpListenerContext context) private static async Task HandleMessageRequest(HttpListenerContext context)
{
try
{
using (var reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding))
{
string json = await reader.ReadToEndAsync();
if (!string.IsNullOrEmpty(json))
{
context.Response.StatusCode = 200;
context.Response.ContentType = "application/json";
int startIndex = json.IndexOf("\"message\":\"") + 11;
int endIndex = json.IndexOf("\"", startIndex);
if (startIndex >= 0 && endIndex >= 0)
OnDisplayBarrage?.Invoke( json.Substring(startIndex, endIndex - startIndex) );
}
else
{
// 如果没有有效的 JSON 数据,返回错误响应
context.Response.StatusCode = 400; // Bad Request
context.Response.StatusDescription = "Invalid JSON data.";
}
}
}
finally
{
context.Response.Close();
}
}
/*
private static async Task HandleMessageRequest2(HttpListenerContext context)
{ {
try try
{ {
@ -888,7 +918,8 @@ namespace DualScreenDemo
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
string Messagelast = ""; string Messagelast = "";
for(int j=0;j < message.Length;j++){ for (int j = 0; j < message.Length; j++)
{
Messagelast += message[j]; Messagelast += message[j];
await Task.Delay(10); await Task.Delay(10);
// 将读取到的 "message" 字段传递给 UI 控件显示 // 将读取到的 "message" 字段传递给 UI 控件显示
@ -896,12 +927,12 @@ namespace DualScreenDemo
{ {
OverlayForm.MainForm.Invoke(new System.Action(() => OverlayForm.MainForm.Invoke(new System.Action(() =>
{ {
OverlayForm.MainForm.ShowmessageLabel(Messagefist + Messagelast + '_'); OverlayForm.MainForm.ShowMessageLabel(Messagefist + Messagelast + '_');
})); }));
} }
else else
{ {
OverlayForm.MainForm.ShowmessageLabel(Messagefist + Messagelast + '_'); OverlayForm.MainForm.ShowMessageLabel(Messagefist + Messagelast + '_');
} }
} }
// 真情告白顯示秒數 // 真情告白顯示秒數
@ -931,21 +962,9 @@ namespace DualScreenDemo
{ {
context.Response.Close(); context.Response.Close();
} }
} }*/
private static async Task OutputMessageAsync(string message, Label messageLabel)
{
messageLabel.Text = ""; // 清空现有的文本
foreach (char c in message)
{
messageLabel.Text += c; // 逐字显示消息
await Task.Delay(500); // 每个字符间隔 0.5 秒
}
// 模拟等待 5 秒后继续其他操作
await Task.Delay(5000);
}
private static string GetMimeType(string filePath) private static string GetMimeType(string filePath)
{ {

View File

@ -29,15 +29,11 @@ namespace OverlayFormObj
InitializeTopRightLabel(); InitializeTopRightLabel();
InitializeTopLeftLabel(); InitializeTopLeftLabel();
ConfigureKeyTimers(); ConfigureKeyTimers();
InitializemessageLabel();
} }
private void ConfigureKeyTimers() private void ConfigureKeyTimers()
{ {
messageTimer.Interval = 5000;
messageTimer.Tick += (sender, e) => {messageLabel.Visible = false;messageTimer.Stop();RedisplayTopRigthLabel();};
topRightTimer.Interval = 1000; topRightTimer.Interval = 1000;
topRightTimer.Tick += (sender, e) => { topRightLabel.Visible = false; topRightTimer.Stop(); RedisplayTopRigthLabel(); }; topRightTimer.Tick += (sender, e) => { topRightLabel.Visible = false; topRightTimer.Stop(); RedisplayTopRigthLabel(); };
@ -401,37 +397,108 @@ namespace OverlayFormObj
HideTopRightLabels(); HideTopRightLabels();
ShowTopRightEchoLabel(switchmic); ShowTopRightEchoLabel(switchmic);
} }
private void InitializemessageLabel() public async void DisplayBarrage(string text)
{ {
messageLabel = new Label(); if (this.InvokeRequired)
messageLabel.AutoSize = true;
messageLabel.ForeColor = Color.White;
messageLabel.Font = new Font("Microsoft JhengHei", 34, FontStyle.Bold);
messageLabel.BackColor = Color.Transparent;
messageLabel.Text = "";
messageLabel.Visible = false;
this.Controls.Add(messageLabel);
UpdateMessageLabelPosition();
this.Resize += (s, e) => UpdateMessageLabelPosition();
}
public void ShowmessageLabel(string customText)
{ {
messageLabel.Visible = true; this.Invoke(new Action(() => DisplayBarrage(text)));
messageLabel.Text = customText; return;
messageTimer.Start();
} }
// 隐藏標準調标签 Label lblBarrage = new Label
public void HidemessageLabel()
{ {
messageLabel.Visible = false; Text = "藏鏡人:", // 一開始不顯示任何字
messageTimer.Stop(); AutoSize = true,
} ForeColor = Color.White,
private void UpdateMessageLabelPosition() Font = new Font("Microsoft JhengHei", 34, FontStyle.Bold),
Location = new Point(10, this.Height / 2)
};
this.Controls.Add(lblBarrage);
lblBarrage.BringToFront();
// 逐字顯示文字
for (int i = 0; i < text.Length; i++)
{ {
int yPosition = (this.Height - messageLabel.Height) / 2; lblBarrage.Text += text[i];
int xPosition = 10; await Task.Delay(500); // 每個字間隔 200ms可依喜好調整
messageLabel.Location = new Point(xPosition, yPosition); }
// 完成後停留 2 秒
await Task.Delay(5000);
// 閃爍三下
for (int i = 0; i < 3; i++)
{
lblBarrage.Visible = false;
await Task.Delay(300);
lblBarrage.Visible = true;
await Task.Delay(300);
}
this.Controls.Remove(lblBarrage);
lblBarrage.Dispose();
}
/*
public void DisplayBarrage1(string text)
{
if (this.InvokeRequired)
{
this.Invoke(new System.Action(() => DisplayBarrage1(text)));
return;
}
Random rnd = new Random();
for (int i = 0; i < 30; i++)
{
Label lblBarrage = new Label
{
Text = text,
AutoSize = true,
ForeColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)),
Font = new Font("Arial", rnd.Next(10, 50)),
Location = new Point(rnd.Next(0, this.Width), rnd.Next(0, this.Height))
};
this.Controls.Add(lblBarrage);
lblBarrage.BringToFront();
System.Windows.Forms.Timer moveTimer = new System.Windows.Forms.Timer { Interval = 50 };
moveTimer.Tick += (sender, e) =>
{
lblBarrage.Left -= 5;
if (lblBarrage.Right < 0)
{
lblBarrage.Dispose();
moveTimer.Dispose();
}
};
moveTimer.Start();
int duration = rnd.Next(3000, 7000);
System.Windows.Forms.Timer durationTimer = new System.Windows.Forms.Timer { Interval = duration };
durationTimer.Tick += (sender, e) =>
{
if (moveTimer.Enabled)
{
moveTimer.Stop();
moveTimer.Dispose();
}
this.Controls.Remove(lblBarrage);
lblBarrage.Dispose();
durationTimer.Stop();
durationTimer.Dispose();
};
durationTimer.Start();
} }
} }
*/
}
} }

View File

@ -29,8 +29,6 @@ namespace OverlayFormObj
public static System.Timers.Timer unifiedTimer; public static System.Timers.Timer unifiedTimer;
private System.Windows.Forms.Timer stickerTimer1 = new System.Windows.Forms.Timer(); private System.Windows.Forms.Timer stickerTimer1 = new System.Windows.Forms.Timer();
private System.Windows.Forms.Timer stickerTimer2 = new System.Windows.Forms.Timer(); private System.Windows.Forms.Timer stickerTimer2 = new System.Windows.Forms.Timer();
private System.Windows.Forms.Timer messageTimer = new System.Windows.Forms.Timer();
public Label messageLabel;
private System.Windows.Forms.Timer secondLineTimer; private System.Windows.Forms.Timer secondLineTimer;
private DateTime secondLineStartTime; private DateTime secondLineStartTime;
private const int secondLineDuration = 20000; private const int secondLineDuration = 20000;
@ -620,69 +618,6 @@ namespace OverlayFormObj
} }
public void DisplayBarrage(string text)
{
if (this.InvokeRequired)
{
this.Invoke(new System.Action(() => DisplayBarrage(text)));
return;
}
Random rnd = new Random();
for (int i = 0; i < 30; i++)
{
Label lblBarrage = new Label
{
Text = text,
AutoSize = true,
ForeColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)),
Font = new Font("Arial", rnd.Next(10, 50)),
Location = new Point(rnd.Next(0, this.Width), rnd.Next(0, this.Height))
};
this.Controls.Add(lblBarrage);
lblBarrage.BringToFront();
System.Windows.Forms.Timer moveTimer = new System.Windows.Forms.Timer { Interval = 50 };
moveTimer.Tick += (sender, e) =>
{
lblBarrage.Left -= 5;
if (lblBarrage.Right < 0)
{
lblBarrage.Dispose();
moveTimer.Dispose();
}
};
moveTimer.Start();
int duration = rnd.Next(3000, 7000);
System.Windows.Forms.Timer durationTimer = new System.Windows.Forms.Timer { Interval = duration };
durationTimer.Tick += (sender, e) =>
{
if (moveTimer.Enabled)
{
moveTimer.Stop();
moveTimer.Dispose();
}
this.Controls.Remove(lblBarrage);
lblBarrage.Dispose();
durationTimer.Stop();
durationTimer.Dispose();
};
durationTimer.Start();
}
}
public void DisplaySticker(string stickerId) public void DisplaySticker(string stickerId)
{ {
//Console.WriteLine("Attempting to display sticker."); //Console.WriteLine("Attempting to display sticker.");

View File

@ -17,7 +17,7 @@ namespace DualScreenDemo
[STAThread] [STAThread]
static void Main() { static void Main() {
Console.WriteLine("Server V.1.2.1 20250716"); Console.WriteLine("Server V.1.2.1 202507171314");
if(Utils.Env.GetBool("IsCursor", true))Cursor.Hide(); if(Utils.Env.GetBool("IsCursor", true))Cursor.Hide();
AppDomain.CurrentDomain.ProcessExit += (s, e) => Cursor.Show(); AppDomain.CurrentDomain.ProcessExit += (s, e) => Cursor.Show();
//Console.WriteLine("正在與中控取得聯繫..."); //Console.WriteLine("正在與中控取得聯繫...");