調整 Barrage 顯示 20250717
This commit is contained in:
parent
3fc4eeb497
commit
af3286292c
@ -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
|
||||||
{
|
{
|
||||||
@ -878,17 +908,18 @@ namespace DualScreenDemo
|
|||||||
context.Response.ContentType = "application/json"; // 确保返回 JSON 格式
|
context.Response.ContentType = "application/json"; // 确保返回 JSON 格式
|
||||||
int startIndex = json.IndexOf("\"message\":\"") + 11; // 11 是 "message\":\"" 的长度
|
int startIndex = json.IndexOf("\"message\":\"") + 11; // 11 是 "message\":\"" 的长度
|
||||||
int endIndex = json.IndexOf("\"", startIndex);
|
int endIndex = json.IndexOf("\"", startIndex);
|
||||||
string Messagefist ="藏鏡人:";
|
string Messagefist = "藏鏡人:";
|
||||||
|
|
||||||
// 如果找到了 "message" 字段
|
// 如果找到了 "message" 字段
|
||||||
if (startIndex >= 0 && endIndex >= 0)
|
if (startIndex >= 0 && endIndex >= 0)
|
||||||
{
|
{
|
||||||
// 提取 "message" 字段的值
|
// 提取 "message" 字段的值
|
||||||
string message = json.Substring(startIndex, endIndex - startIndex);
|
string message = json.Substring(startIndex, endIndex - startIndex);
|
||||||
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,17 +927,17 @@ 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 + '_');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 真情告白顯示秒數
|
// 真情告白顯示秒數
|
||||||
await Task.Delay(3000);
|
await Task.Delay(3000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@ namespace OverlayFormObj
|
|||||||
|
|
||||||
|
|
||||||
private void InitializeLabels()
|
private void InitializeLabels()
|
||||||
{
|
{
|
||||||
InitializeBlackBackgroundPanel();
|
InitializeBlackBackgroundPanel();
|
||||||
InitializeDisplayLabel();
|
InitializeDisplayLabel();
|
||||||
InitializeDisplayLabels();
|
InitializeDisplayLabels();
|
||||||
@ -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(); };
|
||||||
|
|
||||||
@ -109,7 +105,7 @@ namespace OverlayFormObj
|
|||||||
marqueeTextSecondLine = "";
|
marqueeTextSecondLine = "";
|
||||||
marqueeXPosSecondLine = this.Width;
|
marqueeXPosSecondLine = this.Width;
|
||||||
Invalidate();
|
Invalidate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeDisplayLabel()
|
private void InitializeDisplayLabel()
|
||||||
@ -164,8 +160,8 @@ namespace OverlayFormObj
|
|||||||
pauseLabel.Location = new Point(
|
pauseLabel.Location = new Point(
|
||||||
(this.Width - pauseLabel.Width) / 2, // 水平居中
|
(this.Width - pauseLabel.Width) / 2, // 水平居中
|
||||||
(this.Height - pauseLabel.Height) / 2 + 500 // 垂直居中偏下 50 像素
|
(this.Height - pauseLabel.Height) / 2 + 500 // 垂直居中偏下 50 像素
|
||||||
);
|
);
|
||||||
|
|
||||||
pauseLabel.Paint += (s, e) =>
|
pauseLabel.Paint += (s, e) =>
|
||||||
{
|
{
|
||||||
string text = "播放暫停";
|
string text = "播放暫停";
|
||||||
@ -214,11 +210,11 @@ namespace OverlayFormObj
|
|||||||
muteLabel.Location = new Point(
|
muteLabel.Location = new Point(
|
||||||
(this.Width - muteLabel.Width) / 2, // 水平居中
|
(this.Width - muteLabel.Width) / 2, // 水平居中
|
||||||
(this.Height - muteLabel.Height) / 2 + 250 // 垂直居中偏下 50 像素
|
(this.Height - muteLabel.Height) / 2 + 250 // 垂直居中偏下 50 像素
|
||||||
);
|
);
|
||||||
|
|
||||||
muteLabel.Paint += (s, e) =>
|
muteLabel.Paint += (s, e) =>
|
||||||
{
|
{
|
||||||
string text = "【全部靜音】";
|
string text = "【全部靜音】";
|
||||||
Font font = muteLabel.Font;
|
Font font = muteLabel.Font;
|
||||||
Graphics g = e.Graphics;
|
Graphics g = e.Graphics;
|
||||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||||
@ -282,7 +278,7 @@ namespace OverlayFormObj
|
|||||||
float yPosition2 = 56;
|
float yPosition2 = 56;
|
||||||
Rectangle clipRect = new Rectangle(
|
Rectangle clipRect = new Rectangle(
|
||||||
(int)(this.Width / 32), // 从1/8改成1/16(因为要居中)
|
(int)(this.Width / 32), // 从1/8改成1/16(因为要居中)
|
||||||
(int)yPosition2,
|
(int)yPosition2,
|
||||||
(int)(15 * this.Width / 16), // 从3/4改成7/8
|
(int)(15 * this.Width / 16), // 从3/4改成7/8
|
||||||
(int)textSize.Height
|
(int)textSize.Height
|
||||||
);
|
);
|
||||||
@ -357,9 +353,9 @@ namespace OverlayFormObj
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
// 显示标准标签
|
// 显示标准标签
|
||||||
|
|
||||||
|
|
||||||
public void ShowPauseLabel() => pauseLabel.Visible = true;
|
|
||||||
|
public void ShowPauseLabel() => pauseLabel.Visible = true;
|
||||||
|
|
||||||
// 隐藏暂停标签
|
// 隐藏暂停标签
|
||||||
public void HidePauseLabel() => pauseLabel.Visible = false;
|
public void HidePauseLabel() => pauseLabel.Visible = false;
|
||||||
@ -369,7 +365,7 @@ namespace OverlayFormObj
|
|||||||
|
|
||||||
// 隐藏静音标签
|
// 隐藏静音标签
|
||||||
public void HideMuteLabel() => muteLabel.Visible = false;
|
public void HideMuteLabel() => muteLabel.Visible = false;
|
||||||
public void ShowTopRightLabel(string customText = "",string tag =null)
|
public void ShowTopRightLabel(string customText = "", string tag = null)
|
||||||
{
|
{
|
||||||
if (tag != null)
|
if (tag != null)
|
||||||
{
|
{
|
||||||
@ -379,7 +375,7 @@ namespace OverlayFormObj
|
|||||||
topRightLabel.Text = customText;
|
topRightLabel.Text = customText;
|
||||||
topRightLabel.Visible = true;
|
topRightLabel.Visible = true;
|
||||||
}
|
}
|
||||||
public void ShowTopRightLabelTime(string customText = "",string tag =null)
|
public void ShowTopRightLabelTime(string customText = "", string tag = null)
|
||||||
{
|
{
|
||||||
ShowTopRightLabel(customText, tag);
|
ShowTopRightLabel(customText, tag);
|
||||||
topRightTimer.Stop();
|
topRightTimer.Stop();
|
||||||
@ -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;
|
this.Invoke(new Action(() => DisplayBarrage(text)));
|
||||||
messageLabel.Font = new Font("Microsoft JhengHei", 34, FontStyle.Bold);
|
return;
|
||||||
messageLabel.BackColor = Color.Transparent;
|
}
|
||||||
messageLabel.Text = "";
|
|
||||||
messageLabel.Visible = false;
|
Label lblBarrage = new Label
|
||||||
this.Controls.Add(messageLabel);
|
{
|
||||||
UpdateMessageLabelPosition();
|
Text = "藏鏡人:", // 一開始不顯示任何字
|
||||||
this.Resize += (s, e) => UpdateMessageLabelPosition();
|
AutoSize = true,
|
||||||
}
|
ForeColor = Color.White,
|
||||||
public void ShowmessageLabel(string customText)
|
Font = new Font("Microsoft JhengHei", 34, FontStyle.Bold),
|
||||||
{
|
Location = new Point(10, this.Height / 2)
|
||||||
messageLabel.Visible = true;
|
};
|
||||||
messageLabel.Text = customText;
|
|
||||||
messageTimer.Start();
|
this.Controls.Add(lblBarrage);
|
||||||
|
lblBarrage.BringToFront();
|
||||||
|
|
||||||
|
// 逐字顯示文字
|
||||||
|
for (int i = 0; i < text.Length; i++)
|
||||||
|
{
|
||||||
|
lblBarrage.Text += text[i];
|
||||||
|
await Task.Delay(500); // 每個字間隔 200ms,可依喜好調整
|
||||||
|
}
|
||||||
|
// 完成後停留 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 HidemessageLabel()
|
public void DisplayBarrage1(string text)
|
||||||
{
|
{
|
||||||
messageLabel.Visible = false;
|
if (this.InvokeRequired)
|
||||||
messageTimer.Stop();
|
{
|
||||||
}
|
this.Invoke(new System.Action(() => DisplayBarrage1(text)));
|
||||||
private void UpdateMessageLabelPosition()
|
return;
|
||||||
{
|
}
|
||||||
int yPosition = (this.Height - messageLabel.Height) / 2;
|
|
||||||
int xPosition = 10;
|
|
||||||
messageLabel.Location = new Point(xPosition, yPosition);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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.");
|
||||||
|
@ -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("正在與中控取得聯繫...");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user