DutyContent/Overlay/DutyOvForm.cs

215 lines
4.3 KiB
C#
Raw Normal View History

2021-03-17 18:14:48 +01:00
using System;
using System.Drawing;
using System.Windows;
2021-03-17 18:14:48 +01:00
using System.Windows.Forms;
namespace DutyContent.Overlay
{
public partial class DutyOvForm : Form
{
private static DutyOvForm _self;
public static DutyOvForm Self => _self;
private const int BlinkElapse = 300;
private const int BlinkTotalCount = 20;
2021-03-17 18:14:48 +01:00
private static readonly Color ColorFate = Color.DarkOrange;
private static readonly Color ColorMatch = Color.Red;
private static readonly Color ColorNone = Color.Black;
private static readonly Color ColorHide = Color.Transparent;
2021-03-17 18:14:48 +01:00
//
private Timer _blink_timer;
private int _blink_count;
2021-03-17 18:14:48 +01:00
private Color _accent;
private Timer _hide_timer;
2021-03-17 18:14:48 +01:00
//
public DutyOvForm()
{
_self = this;
2021-03-17 18:14:48 +01:00
InitializeComponent();
Location = DcConfig.Duty.OverlayLocation;
_blink_timer = new Timer { Interval = BlinkElapse };
_blink_timer.Tick += (sender, e) =>
2021-03-17 18:14:48 +01:00
{
if (++_blink_count > BlinkTotalCount)
2021-03-17 18:14:48 +01:00
{
StopBlink();
}
else
{
//BackColor = (BackColor == ColorNone) ? _accent : ColorNone;
BackColor = (BackColor == _accent) ? ColorNone : _accent;
2021-03-17 18:14:48 +01:00
}
};
_hide_timer = new Timer { Interval = DcConfig.Duty.OverlayAutoElapse };
_hide_timer.Tick += (sender, e) =>
{
Visible = false;
};
2021-03-17 18:14:48 +01:00
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x80/*WS_EX_TOOLWINDOW*/ | 0x80000/*WS_EX_LAYERED*/;
return cp;
}
}
private void DutyOvForm_Load(object sender, EventArgs e)
{
}
private void DoMoveDown(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ThirdParty.NativeMethods.ReleaseCapture();
ThirdParty.NativeMethods.SendMessage(Handle, 0xA1/*WM_NCLBUTTONDOWN*/, new IntPtr(0x2/*HT_CAPTION*/), IntPtr.Zero);
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
DoMoveDown(e);
}
protected override void OnLocationChanged(EventArgs e)
{
base.OnLocationChanged(e);
DcConfig.Duty.OverlayLocation = Location;
}
2021-06-14 11:45:49 +02:00
private void LblText_MouseDown(object sender, MouseEventArgs e)
2021-03-17 18:14:48 +01:00
{
DoMoveDown(e);
}
2021-06-14 11:45:49 +02:00
public void SetClickThruStatus(bool is_click_thru)
{
long style = (long)ThirdParty.NativeMethods.GetWindowLong(Handle, -20);
long value = is_click_thru ? (style | 0x80000 | 0x20) : (0x80000 | 0x0);
ThirdParty.NativeMethods.SetWindowLong(Handle, -20, (IntPtr)value);
}
public void SetText(string text, bool hidenow = false)
2021-03-17 18:14:48 +01:00
{
lblText.Text = text;
if (DcConfig.Duty.OverlayAutoHide)
{
if (hidenow)
Visible = false;
else
{
Visible = true;
_hide_timer.Enabled = false;
_hide_timer.Interval = DcConfig.Duty.OverlayAutoElapse;
_hide_timer.Start();
}
}
}
public void ResetAutoHide()
{
if (DcConfig.Duty.OverlayAutoHide)
{
Visible = true;
_hide_timer.Enabled = false;
_hide_timer.Interval = DcConfig.Duty.OverlayAutoElapse;
_hide_timer.Start();
}
2021-03-17 18:14:48 +01:00
}
public void StartBlink()
{
_blink_count = 0;
_blink_timer.Enabled = false;
_blink_timer.Start();
2021-03-17 18:14:48 +01:00
}
public void StopBlink()
{
_blink_timer.Stop();
2021-03-17 18:14:48 +01:00
BackColor = ColorNone;
_accent = ColorNone;
if (!DcConfig.Duty.OverlayAutoHide)
lblText.Text = string.Empty;
2021-03-17 18:14:48 +01:00
}
public void PlayNone()
{
Invoke((MethodInvoker)(() =>
{
_accent = ColorNone;
SetText(string.Empty, true);
2021-03-17 18:14:48 +01:00
StopBlink();
}));
}
public void PlayFate(DcContent.Fate f)
{
Invoke((MethodInvoker)(() =>
{
_accent = ColorFate;
SetText(f.Name);
2021-03-17 18:14:48 +01:00
StartBlink();
}));
}
public void PlayQueue(string name)
{
Invoke((MethodInvoker)(() =>
{
_accent = ColorNone;
SetText(name);
2021-03-17 18:14:48 +01:00
}));
}
2021-03-20 19:43:05 +01:00
public void PlayMatch(string name, bool blink = true) // PlayEnter
2021-03-17 18:14:48 +01:00
{
Invoke((MethodInvoker)(() =>
{
_accent = ColorMatch;
SetText(name);
2021-03-17 18:14:48 +01:00
if (blink)
StartBlink();
}));
}
2021-03-20 19:43:05 +01:00
public void ResetStat()
{
lblStat.BackColor = Color.Transparent;
SetText(string.Empty, true);
2021-03-20 19:43:05 +01:00
}
public void SetStatPing(Color color, long rtt, double loss)
{
Invoke((MethodInvoker)(() =>
{
if (rtt > 999)
rtt = 999;
2021-04-28 06:46:03 +02:00
lblStat.Text = (Math.Abs(loss) < 0.0001)
? string.Format("{0}", rtt)
: string.Format("{0}{1}{2:0.#}%", rtt, Environment.NewLine, loss);
2021-03-20 19:43:05 +01:00
lblStat.BackColor = color;
}));
}
2021-03-17 18:14:48 +01:00
}
}