2022-12-13 07:10:18 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-01-11 13:10:18 +00:00
|
|
|
|
using System.Timers;
|
2022-12-13 07:10:18 +00:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
|
|
|
|
namespace VPet_Simulator.Core
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// MessageBar.xaml 的交互逻辑
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MessageBar : UserControl
|
|
|
|
|
{
|
|
|
|
|
public MessageBar()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-01-12 22:11:55 +00:00
|
|
|
|
EndTimer.Elapsed += EndTimer_Elapsed;
|
2023-01-11 13:10:18 +00:00
|
|
|
|
ShowTimer.Elapsed += ShowTimer_Elapsed;
|
|
|
|
|
}
|
2023-01-12 22:11:55 +00:00
|
|
|
|
List<char> outputtext;
|
2023-01-11 13:10:18 +00:00
|
|
|
|
private void ShowTimer_Elapsed(object sender, ElapsedEventArgs e)
|
2023-01-12 22:11:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (outputtext.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(() => { TText.Text += outputtext[0]; outputtext.RemoveAt(0); });
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ShowTimer.Stop();
|
|
|
|
|
EndTimer.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-13 14:45:42 +00:00
|
|
|
|
public Action EndAction;
|
2023-01-12 22:11:55 +00:00
|
|
|
|
private void EndTimer_Elapsed(object sender, ElapsedEventArgs e)
|
2023-01-11 13:10:18 +00:00
|
|
|
|
{
|
2023-01-11 16:46:28 +00:00
|
|
|
|
if (--timeleft <= 0)
|
2023-01-13 14:45:42 +00:00
|
|
|
|
{
|
2023-01-11 16:46:28 +00:00
|
|
|
|
Dispatcher.Invoke(() => this.Visibility = Visibility.Collapsed);
|
2023-01-13 14:45:42 +00:00
|
|
|
|
EndAction?.Invoke();
|
|
|
|
|
}
|
2023-01-11 13:10:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 22:11:55 +00:00
|
|
|
|
public Timer EndTimer = new Timer() { Interval = 100 };
|
|
|
|
|
public Timer ShowTimer = new Timer() { Interval = 20 };
|
2023-01-11 16:46:28 +00:00
|
|
|
|
int timeleft;
|
2023-01-11 13:10:18 +00:00
|
|
|
|
public void Show(string name, string text)
|
|
|
|
|
{
|
2023-01-12 22:11:55 +00:00
|
|
|
|
TText.Text = "";
|
|
|
|
|
outputtext = text.ToList();
|
2023-01-11 13:10:18 +00:00
|
|
|
|
LName.Content = name;
|
2023-01-12 22:11:55 +00:00
|
|
|
|
timeleft = text.Length + 5;
|
|
|
|
|
ShowTimer.Start(); EndTimer.Stop();
|
2023-01-11 13:10:18 +00:00
|
|
|
|
this.Visibility = Visibility.Visible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Border_MouseEnter(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2023-01-12 22:11:55 +00:00
|
|
|
|
EndTimer.Stop();
|
2023-01-11 13:10:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Border_MouseLeave(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2023-01-12 22:11:55 +00:00
|
|
|
|
if (!ShowTimer.Enabled)
|
|
|
|
|
EndTimer.Start();
|
2023-01-11 13:10:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UserControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
|
|
|
{
|
2023-01-12 22:11:55 +00:00
|
|
|
|
EndTimer.Stop(); ShowTimer.Stop();
|
2023-01-11 13:10:18 +00:00
|
|
|
|
this.Visibility = Visibility.Collapsed;
|
2023-01-13 14:45:42 +00:00
|
|
|
|
EndAction?.Invoke();
|
2022-12-13 07:10:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|