add:issue #224
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Ink_Canvas.Helpers;
|
||||
using Ink_Canvas.Resources;
|
||||
using System;
|
||||
using System.Media;
|
||||
using System.Timers;
|
||||
@@ -6,6 +7,7 @@ using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
@@ -21,6 +23,7 @@ namespace Ink_Canvas
|
||||
|
||||
timer.Elapsed += Timer_Elapsed;
|
||||
timer.Interval = 50;
|
||||
InitializeUI();
|
||||
}
|
||||
|
||||
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
@@ -62,24 +65,25 @@ namespace Ink_Canvas
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
//Play sound
|
||||
player.Stream = Properties.Resources.TimerDownNotice;
|
||||
player.Play();
|
||||
PlayTimerSound();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
SoundPlayer player = new SoundPlayer();
|
||||
MediaPlayer mediaPlayer = new MediaPlayer();
|
||||
|
||||
int hour = 0;
|
||||
int hour;
|
||||
int minute = 1;
|
||||
int second = 0;
|
||||
int second;
|
||||
int totalSeconds = 60;
|
||||
|
||||
DateTime startTime = DateTime.Now;
|
||||
DateTime pauseTime = DateTime.Now;
|
||||
|
||||
bool isTimerRunning = false;
|
||||
bool isPaused = false;
|
||||
bool isTimerRunning;
|
||||
bool isPaused;
|
||||
bool useLegacyUI;
|
||||
|
||||
Timer timer = new Timer();
|
||||
|
||||
@@ -334,6 +338,97 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeUI()
|
||||
{
|
||||
// 从设置中读取配置
|
||||
if (MainWindow.Settings.RandSettings != null)
|
||||
{
|
||||
useLegacyUI = MainWindow.Settings.RandSettings.UseLegacyTimerUI;
|
||||
UpdateButtonTexts();
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshUI()
|
||||
{
|
||||
InitializeUI();
|
||||
}
|
||||
|
||||
private void UpdateButtonTexts()
|
||||
{
|
||||
if (useLegacyUI)
|
||||
{
|
||||
// 老版UI:使用+5, +1, -1, -5
|
||||
HourPlus5Text.Text = "+5";
|
||||
HourPlus1Text.Text = "+1";
|
||||
HourMinus1Text.Text = "-1";
|
||||
HourMinus5Text.Text = "-5";
|
||||
|
||||
MinutePlus5Text.Text = "+5";
|
||||
MinutePlus1Text.Text = "+1";
|
||||
MinuteMinus1Text.Text = "-1";
|
||||
MinuteMinus5Text.Text = "-5";
|
||||
|
||||
SecondPlus5Text.Text = "+5";
|
||||
SecondPlus1Text.Text = "+1";
|
||||
SecondMinus1Text.Text = "-1";
|
||||
SecondMinus5Text.Text = "-5";
|
||||
}
|
||||
else
|
||||
{
|
||||
// 新版UI:使用箭头符号
|
||||
HourPlus5Text.Text = "∧∧";
|
||||
HourPlus1Text.Text = "∧";
|
||||
HourMinus1Text.Text = "∨";
|
||||
HourMinus5Text.Text = "∨∨";
|
||||
|
||||
MinutePlus5Text.Text = "∧∧";
|
||||
MinutePlus1Text.Text = "∧";
|
||||
MinuteMinus1Text.Text = "∨";
|
||||
MinuteMinus5Text.Text = "∨∨";
|
||||
|
||||
SecondPlus5Text.Text = "∧∧";
|
||||
SecondPlus1Text.Text = "∧";
|
||||
SecondMinus1Text.Text = "∨";
|
||||
SecondMinus5Text.Text = "∨∨";
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayTimerSound()
|
||||
{
|
||||
try
|
||||
{
|
||||
double volume = MainWindow.Settings.RandSettings?.TimerVolume ?? 1.0;
|
||||
mediaPlayer.Volume = volume;
|
||||
|
||||
if (!string.IsNullOrEmpty(MainWindow.Settings.RandSettings?.CustomTimerSoundPath) &&
|
||||
System.IO.File.Exists(MainWindow.Settings.RandSettings.CustomTimerSoundPath))
|
||||
{
|
||||
// 播放自定义铃声
|
||||
mediaPlayer.Open(new Uri(MainWindow.Settings.RandSettings.CustomTimerSoundPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 播放默认铃声
|
||||
string tempPath = System.IO.Path.GetTempFileName() + ".wav";
|
||||
using (var stream = Properties.Resources.TimerDownNotice)
|
||||
{
|
||||
using (var fileStream = new System.IO.FileStream(tempPath, System.IO.FileMode.Create))
|
||||
{
|
||||
stream.CopyTo(fileStream);
|
||||
}
|
||||
}
|
||||
mediaPlayer.Open(new Uri(tempPath));
|
||||
}
|
||||
|
||||
mediaPlayer.Play();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 如果播放失败,静默处理
|
||||
System.Diagnostics.Debug.WriteLine($"播放计时器铃声失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
isTimerRunning = false;
|
||||
@@ -344,7 +439,7 @@ namespace Ink_Canvas
|
||||
Close();
|
||||
}
|
||||
|
||||
private bool _isInCompact = false;
|
||||
private bool _isInCompact;
|
||||
|
||||
private void BtnMinimal_OnMouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user