improve:计时器

This commit is contained in:
2025-10-12 17:44:44 +08:00
parent 04f98eb9e7
commit 04184cf731
10 changed files with 137 additions and 4 deletions
+1
View File
@@ -192,6 +192,7 @@
</ItemGroup>
<ItemGroup>
<None Include="Resources\TimerDownNotice.wav" />
<None Include="Resources\ProgressiveAudio.wav" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\IACore\IACore.dll" />
+29
View File
@@ -3351,6 +3351,35 @@
<Button Name="ButtonResetTimerSound" Content="重置" FontFamily="Microsoft YaHei UI"
Click="ButtonResetTimerSound_Click" Padding="10,3" Margin="5,0,0,0"/>
</ui:SimpleStackPanel>
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,5,0,0">
<TextBlock Foreground="#fafafa" Text="渐进提醒" VerticalAlignment="Center"
FontSize="14" Margin="0,0,16,0" />
<ui:ToggleSwitch OnContent="" OffContent=""
Name="ToggleSwitchEnableProgressiveReminder"
IsOn="False" FontFamily="Microsoft YaHei UI"
FontWeight="Bold"
Toggled="ToggleSwitchEnableProgressiveReminder_Toggled" />
</ui:SimpleStackPanel>
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,5,0,0">
<TextBlock Foreground="#fafafa" Text="渐进提醒音量" VerticalAlignment="Center"
FontSize="14" Margin="0,0,16,0" />
<Slider x:Name="ProgressiveReminderVolumeSlider" Minimum="0"
Maximum="1" Width="168" FontFamily="Microsoft YaHei UI"
ValueChanged="ProgressiveReminderVolumeSlider_ValueChanged"
FontSize="20" IsSnapToTickEnabled="True" Value="1" TickFrequency="0.1"
TickPlacement="None" AutoToolTipPlacement="None" />
<TextBlock VerticalAlignment="Center" Margin="12,0,16,0" FontSize="14"
FontFamily="Consolas"
Text="{Binding ElementName=ProgressiveReminderVolumeSlider, Path=Value, StringFormat={}{0:P0}}" />
</ui:SimpleStackPanel>
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,5,0,0">
<TextBlock Foreground="#fafafa" Text="自定义渐进提醒音频:" VerticalAlignment="Center"
FontSize="14" Margin="0,0,16,0" />
<Button Name="ButtonSelectCustomProgressiveReminderSound" Content="选择文件" FontFamily="Microsoft YaHei UI"
Click="ButtonSelectCustomProgressiveReminderSound_Click" Padding="10,3"/>
<Button Name="ButtonResetProgressiveReminderSound" Content="重置" FontFamily="Microsoft YaHei UI"
Click="ButtonResetProgressiveReminderSound_Click" Padding="10,3" Margin="5,0,0,0"/>
</ui:SimpleStackPanel>
</ui:SimpleStackPanel>
</GroupBox>
<GroupBox>
+1
View File
@@ -2460,6 +2460,7 @@ namespace Ink_Canvas
RandWindowOnceCloseLatencySlider,
RandWindowOnceMaxStudentsSlider,
TimerVolumeSlider,
ProgressiveReminderVolumeSlider,
BoardInkWidthSlider,
BoardInkAlphaSlider,
BoardHighlighterWidthSlider,
+36
View File
@@ -2664,6 +2664,42 @@ namespace Ink_Canvas
SaveSettingsToFile();
}
private void ToggleSwitchEnableProgressiveReminder_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.RandSettings.EnableProgressiveReminder = ToggleSwitchEnableProgressiveReminder.IsOn;
SaveSettingsToFile();
}
private void ProgressiveReminderVolumeSlider_ValueChanged(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.RandSettings.ProgressiveReminderVolume = ProgressiveReminderVolumeSlider.Value;
SaveSettingsToFile();
}
private void ButtonSelectCustomProgressiveReminderSound_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
{
Title = "选择渐进提醒音频文件",
Filter = "音频文件 (*.wav)|*.wav|所有文件 (*.*)|*.*",
DefaultExt = "wav"
};
if (openFileDialog.ShowDialog() == true)
{
Settings.RandSettings.ProgressiveReminderSoundPath = openFileDialog.FileName;
SaveSettingsToFile();
}
}
private void ButtonResetProgressiveReminderSound_Click(object sender, RoutedEventArgs e)
{
Settings.RandSettings.ProgressiveReminderSoundPath = "";
SaveSettingsToFile();
}
private void ButtonSelectCustomTimerSound_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
@@ -895,6 +895,10 @@ namespace Ink_Canvas
TimerVolumeSlider.Value = Settings.RandSettings.TimerVolume;
// 渐进提醒设置
ToggleSwitchEnableProgressiveReminder.IsOn = Settings.RandSettings.EnableProgressiveReminder;
ProgressiveReminderVolumeSlider.Value = Settings.RandSettings.ProgressiveReminderVolume;
// 加载自定义点名背景
UpdatePickNameBackgroundsInComboBox();
@@ -925,6 +929,10 @@ namespace Ink_Canvas
}
TimerVolumeSlider.Value = Settings.RandSettings.TimerVolume;
// 渐进提醒设置
ToggleSwitchEnableProgressiveReminder.IsOn = Settings.RandSettings.EnableProgressiveReminder;
ProgressiveReminderVolumeSlider.Value = Settings.RandSettings.ProgressiveReminderVolume;
}
// ModeSettings
+9
View File
@@ -74,5 +74,14 @@ namespace Ink_Canvas.Properties {
return ResourceManager.GetStream("TimerDownNotice", resourceCulture);
}
}
/// <summary>
/// Looks up a localized resource of type System.IO.UnmanagedMemoryStream similar to System.IO.MemoryStream.
/// </summary>
internal static UnmanagedMemoryStream ProgressiveAudio {
get {
return ResourceManager.GetStream("ProgressiveAudio", resourceCulture);
}
}
}
}
+3
View File
@@ -121,4 +121,7 @@
<data name="TimerDownNotice" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\TimerDownNotice.wav;System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="ProgressiveAudio" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ProgressiveAudio.wav;System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
Binary file not shown.
+6
View File
@@ -641,6 +641,12 @@ namespace Ink_Canvas
public bool EnableOvertimeCountUp { get; set; } = false;
[JsonProperty("enableOvertimeRedText")]
public bool EnableOvertimeRedText { get; set; } = false;
[JsonProperty("enableProgressiveReminder")]
public bool EnableProgressiveReminder { get; set; } = false;
[JsonProperty("progressiveReminderVolume")]
public double ProgressiveReminderVolume { get; set; } = 1.0;
[JsonProperty("progressiveReminderSoundPath")]
public string ProgressiveReminderSoundPath { get; set; } = "";
}
public class CustomPickNameBackground
+44 -4
View File
@@ -65,6 +65,14 @@ namespace Ink_Canvas
SetDigitDisplay("Digit5Display", leftTimeSpan.Seconds / 10);
SetDigitDisplay("Digit6Display", leftTimeSpan.Seconds % 10);
if (leftTimeSpan.TotalSeconds == 3 &&
MainWindow.Settings.RandSettings?.EnableProgressiveReminder == true &&
!hasPlayedProgressiveReminder)
{
PlayProgressiveReminderSound();
hasPlayedProgressiveReminder = true;
}
if (leftTimeSpan.TotalSeconds <= 0 && MainWindow.Settings.RandSettings?.EnableOvertimeCountUp == true)
{
isOvertimeMode = true;
@@ -121,6 +129,7 @@ namespace Ink_Canvas
bool isPaused = false;
bool isOvertimeMode = false;
TimeSpan remainingTime = TimeSpan.Zero;
bool hasPlayedProgressiveReminder = false;
Timer timer = new Timer();
private Timer hideTimer;
@@ -692,7 +701,8 @@ namespace Ink_Canvas
StartPauseIcon.Data = Geometry.Parse(PauseIconData);
isPaused = false;
isTimerRunning = true;
isOvertimeMode = false;
isOvertimeMode = false;
hasPlayedProgressiveReminder = false;
timer.Start();
// 启动隐藏定时器
@@ -736,12 +746,10 @@ namespace Ink_Canvas
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)
{
@@ -757,11 +765,43 @@ namespace Ink_Canvas
}
catch (Exception ex)
{
// 如果播放失败,静默处理
System.Diagnostics.Debug.WriteLine($"播放计时器铃声失败: {ex.Message}");
}
}
private void PlayProgressiveReminderSound()
{
try
{
double volume = MainWindow.Settings.RandSettings?.ProgressiveReminderVolume ?? 1.0;
mediaPlayer.Volume = volume;
if (!string.IsNullOrEmpty(MainWindow.Settings.RandSettings?.ProgressiveReminderSoundPath) &&
System.IO.File.Exists(MainWindow.Settings.RandSettings.ProgressiveReminderSoundPath))
{
mediaPlayer.Open(new Uri(MainWindow.Settings.RandSettings.ProgressiveReminderSoundPath));
}
else
{
string tempPath = System.IO.Path.GetTempFileName() + ".wav";
using (var stream = Properties.Resources.ProgressiveAudio)
{
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_Loaded(object sender, RoutedEventArgs e)
{
// 窗口加载时的初始化