diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml
index 3e6b94d7..ab3f927a 100644
--- a/Ink Canvas/MainWindow.xaml
+++ b/Ink Canvas/MainWindow.xaml
@@ -2415,7 +2415,7 @@
-
+
@@ -2425,6 +2425,29 @@
FontWeight="Bold"
Toggled="ToggleSwitchDisplayRandWindowNamesInputBtn_OnToggled" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Ink Canvas/MainWindow_cs/MW_Settings.cs b/Ink Canvas/MainWindow_cs/MW_Settings.cs
index 069f94a0..7b5e7b63 100644
--- a/Ink Canvas/MainWindow_cs/MW_Settings.cs
+++ b/Ink Canvas/MainWindow_cs/MW_Settings.cs
@@ -1934,5 +1934,65 @@ namespace Ink_Canvas {
}
}
}
+
+ // 自定义点名背景相关方法
+ public void UpdatePickNameBackgroundsInComboBox()
+ {
+ // 清除现有的自定义背景选项
+ if (ComboBoxPickNameBackground != null)
+ {
+ // 保留第一个默认选项
+ while (ComboBoxPickNameBackground.Items.Count > 1)
+ {
+ ComboBoxPickNameBackground.Items.RemoveAt(ComboBoxPickNameBackground.Items.Count - 1);
+ }
+
+ // 添加自定义背景选项
+ foreach (var background in Settings.RandSettings.CustomPickNameBackgrounds)
+ {
+ ComboBoxItem item = new ComboBoxItem();
+ item.Content = background.Name;
+ item.FontFamily = new System.Windows.Media.FontFamily("Microsoft YaHei UI");
+ ComboBoxPickNameBackground.Items.Add(item);
+ }
+ }
+ }
+
+ public void UpdatePickNameBackgroundDisplay()
+ {
+ // 此方法主要用于在外部窗口更改背景后更新UI
+ if (ComboBoxPickNameBackground != null)
+ {
+ ComboBoxPickNameBackground.SelectedIndex = Settings.RandSettings.SelectedBackgroundIndex;
+ }
+ }
+
+ private void ComboBoxPickNameBackground_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (!isLoaded) return;
+
+ Settings.RandSettings.SelectedBackgroundIndex = ComboBoxPickNameBackground.SelectedIndex;
+ SaveSettingsToFile();
+ }
+
+ private void ButtonAddCustomBackground_Click(object sender, RoutedEventArgs e)
+ {
+ AddPickNameBackgroundWindow dialog = new AddPickNameBackgroundWindow(this);
+ dialog.Owner = this;
+ dialog.ShowDialog();
+
+ if (dialog.IsSuccess)
+ {
+ // 自动选中新添加的背景
+ ComboBoxPickNameBackground.SelectedIndex = ComboBoxPickNameBackground.Items.Count - 1;
+ }
+ }
+
+ private void ButtonManageBackgrounds_Click(object sender, RoutedEventArgs e)
+ {
+ ManagePickNameBackgroundsWindow dialog = new ManagePickNameBackgroundsWindow(this);
+ dialog.Owner = this;
+ dialog.ShowDialog();
+ }
}
}
diff --git a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs
index 48f9befc..4a4e365d 100644
--- a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs
+++ b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs
@@ -602,6 +602,16 @@ namespace Ink_Canvas {
ToggleSwitchDirectCallCiRand.IsOn = Settings.RandSettings.DirectCallCiRand;
RandomDrawPanel.Visibility = Settings.RandSettings.ShowRandomAndSingleDraw ? Visibility.Visible : Visibility.Collapsed;
SingleDrawPanel.Visibility = Settings.RandSettings.ShowRandomAndSingleDraw ? Visibility.Visible : Visibility.Collapsed;
+
+ // 加载自定义点名背景
+ UpdatePickNameBackgroundsInComboBox();
+
+ // 设置选择的背景索引
+ if (Settings.RandSettings.SelectedBackgroundIndex >= ComboBoxPickNameBackground.Items.Count)
+ {
+ Settings.RandSettings.SelectedBackgroundIndex = 0;
+ }
+ ComboBoxPickNameBackground.SelectedIndex = Settings.RandSettings.SelectedBackgroundIndex;
} else {
Settings.RandSettings = new RandSettings();
ToggleSwitchDisplayRandWindowNamesInputBtn.IsOn = Settings.RandSettings.DisplayRandWindowNamesInputBtn;
diff --git a/Ink Canvas/Resources/Settings.cs b/Ink Canvas/Resources/Settings.cs
index a19bc9ac..906c658d 100644
--- a/Ink Canvas/Resources/Settings.cs
+++ b/Ink Canvas/Resources/Settings.cs
@@ -440,6 +440,28 @@ namespace Ink_Canvas
public bool ShowRandomAndSingleDraw { get; set; } = true;
[JsonProperty("directCallCiRand")]
public bool DirectCallCiRand { get; set; } = false;
+ [JsonProperty("selectedBackgroundIndex")]
+ public int SelectedBackgroundIndex { get; set; } = 0;
+ [JsonProperty("customPickNameBackgrounds")]
+ public List CustomPickNameBackgrounds { get; set; } = new List();
+ }
+
+ public class CustomPickNameBackground
+ {
+ [JsonProperty("name")]
+ public string Name { get; set; }
+
+ [JsonProperty("filePath")]
+ public string FilePath { get; set; }
+
+ public CustomPickNameBackground(string name, string filePath)
+ {
+ Name = name;
+ FilePath = filePath;
+ }
+
+ // 用于JSON序列化
+ public CustomPickNameBackground() { }
}
public class CustomFloatingBarIcon
diff --git a/Ink Canvas/Windows/AddPickNameBackgroundWindow.xaml b/Ink Canvas/Windows/AddPickNameBackgroundWindow.xaml
new file mode 100644
index 00000000..44c6ccf1
--- /dev/null
+++ b/Ink Canvas/Windows/AddPickNameBackgroundWindow.xaml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ink Canvas/Windows/AddPickNameBackgroundWindow.xaml.cs b/Ink Canvas/Windows/AddPickNameBackgroundWindow.xaml.cs
new file mode 100644
index 00000000..8fb7ff2c
--- /dev/null
+++ b/Ink Canvas/Windows/AddPickNameBackgroundWindow.xaml.cs
@@ -0,0 +1,121 @@
+using System;
+using System.IO;
+using System.Windows;
+using System.Windows.Media.Imaging;
+using Microsoft.Win32;
+
+namespace Ink_Canvas
+{
+ ///
+ /// AddPickNameBackgroundWindow.xaml 的交互逻辑
+ ///
+ public partial class AddPickNameBackgroundWindow : Window
+ {
+ private MainWindow mainWindow;
+ private string selectedFilePath;
+ public bool IsSuccess { get; private set; }
+
+ public AddPickNameBackgroundWindow(MainWindow owner)
+ {
+ InitializeComponent();
+ mainWindow = owner;
+ IsSuccess = false;
+
+ // 添加TextBox内容变化事件以检查是否可以保存
+ BackgroundNameTextBox.TextChanged += (s, e) => ValidateSaveButton();
+ }
+
+ private void BrowseButton_Click(object sender, RoutedEventArgs e)
+ {
+ OpenFileDialog openFileDialog = new OpenFileDialog
+ {
+ Filter = "图像文件|*.png;*.jpg;*.jpeg;*.bmp;*.gif",
+ Title = "选择一个背景图片"
+ };
+
+ if (openFileDialog.ShowDialog() == true)
+ {
+ selectedFilePath = openFileDialog.FileName;
+ BackgroundPathTextBox.Text = selectedFilePath;
+
+ // 显示预览
+ try
+ {
+ BitmapImage bitmap = new BitmapImage();
+ bitmap.BeginInit();
+ bitmap.UriSource = new Uri(selectedFilePath);
+ bitmap.EndInit();
+ BackgroundPreviewImage.Source = bitmap;
+ NoImageText.Visibility = Visibility.Collapsed;
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"无法加载图像: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+
+ // 自动填充名称建议(文件名,不包括扩展名)
+ string suggestedName = Path.GetFileNameWithoutExtension(selectedFilePath);
+ BackgroundNameTextBox.Text = suggestedName;
+
+ ValidateSaveButton();
+ }
+ }
+
+ private void ValidateSaveButton()
+ {
+ SaveButton.IsEnabled = !string.IsNullOrWhiteSpace(BackgroundNameTextBox.Text) && !string.IsNullOrEmpty(selectedFilePath);
+ }
+
+ private void CancelButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+
+ private void SaveButton_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ // 创建pictures/picknamebackgrounds文件夹结构(如果不存在)
+ string picturesFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pictures");
+ string backgroundsFolder = Path.Combine(picturesFolder, "picknamebackgrounds");
+
+ if (!Directory.Exists(picturesFolder))
+ {
+ Directory.CreateDirectory(picturesFolder);
+ }
+
+ if (!Directory.Exists(backgroundsFolder))
+ {
+ Directory.CreateDirectory(backgroundsFolder);
+ }
+
+ // 生成一个唯一的文件名(使用GUID)
+ string extension = Path.GetExtension(selectedFilePath);
+ string newFileName = $"{Guid.NewGuid()}{extension}";
+ string destPath = Path.Combine(backgroundsFolder, newFileName);
+
+ // 复制文件到pictures/picknamebackgrounds文件夹
+ File.Copy(selectedFilePath, destPath);
+
+ // 创建新的自定义背景对象
+ var customBackground = new CustomPickNameBackground(BackgroundNameTextBox.Text, destPath);
+
+ // 添加到主窗口的设置中
+ MainWindow.Settings.RandSettings.CustomPickNameBackgrounds.Add(customBackground);
+
+ // 更新ComboBox
+ mainWindow.UpdatePickNameBackgroundsInComboBox();
+
+ // 保存设置
+ MainWindow.SaveSettingsToFile();
+
+ IsSuccess = true;
+ this.Close();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"保存背景时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ink Canvas/Windows/ManagePickNameBackgroundsWindow.xaml b/Ink Canvas/Windows/ManagePickNameBackgroundsWindow.xaml
new file mode 100644
index 00000000..c5fa1e66
--- /dev/null
+++ b/Ink Canvas/Windows/ManagePickNameBackgroundsWindow.xaml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ink Canvas/Windows/ManagePickNameBackgroundsWindow.xaml.cs b/Ink Canvas/Windows/ManagePickNameBackgroundsWindow.xaml.cs
new file mode 100644
index 00000000..1d059721
--- /dev/null
+++ b/Ink Canvas/Windows/ManagePickNameBackgroundsWindow.xaml.cs
@@ -0,0 +1,98 @@
+using System;
+using System.Collections.ObjectModel;
+using System.IO;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace Ink_Canvas
+{
+ ///
+ /// ManagePickNameBackgroundsWindow.xaml 的交互逻辑
+ ///
+ public partial class ManagePickNameBackgroundsWindow : Window
+ {
+ private MainWindow mainWindow;
+ public ObservableCollection Backgrounds { get; set; }
+
+ public ManagePickNameBackgroundsWindow(MainWindow owner)
+ {
+ InitializeComponent();
+ mainWindow = owner;
+
+ // 从主窗口的设置获取自定义背景列表
+ Backgrounds = new ObservableCollection(MainWindow.Settings.RandSettings.CustomPickNameBackgrounds);
+ BackgroundsListView.ItemsSource = Backgrounds;
+ }
+
+ private void SetAsCurrentButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (sender is Button button && button.Tag is CustomPickNameBackground background)
+ {
+ // 找到背景在列表中的索引(加8,因为前8个是默认值)
+ int index = Backgrounds.IndexOf(background) + 1; // 增加1因为索引0将是"默认"
+
+ // 更新设置
+ MainWindow.Settings.RandSettings.SelectedBackgroundIndex = index;
+
+ // 更新UI
+ mainWindow.UpdatePickNameBackgroundDisplay();
+
+ // 保存设置
+ MainWindow.SaveSettingsToFile();
+
+ MessageBox.Show($"已将\"{background.Name}\"设置为当前点名背景", "设置成功", MessageBoxButton.OK, MessageBoxImage.Information);
+ }
+ }
+
+ private void DeleteBackgroundButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (sender is Button button && button.Tag is CustomPickNameBackground background)
+ {
+ if (MessageBox.Show($"确定要删除背景\"{background.Name}\"吗?", "确认删除", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
+ {
+ try
+ {
+ // 尝试删除文件
+ if (File.Exists(background.FilePath))
+ {
+ File.Delete(background.FilePath);
+ }
+
+ // 从列表中移除背景
+ Backgrounds.Remove(background);
+
+ // 更新主窗口的设置
+ MainWindow.Settings.RandSettings.CustomPickNameBackgrounds.Clear();
+ foreach (var bg in Backgrounds)
+ {
+ MainWindow.Settings.RandSettings.CustomPickNameBackgrounds.Add(bg);
+ }
+
+ // 如果当前选中的是被删除的背景,重置为默认背景
+ int selectedIndex = MainWindow.Settings.RandSettings.SelectedBackgroundIndex;
+ if (selectedIndex > 0 && selectedIndex - 1 >= MainWindow.Settings.RandSettings.CustomPickNameBackgrounds.Count)
+ {
+ MainWindow.Settings.RandSettings.SelectedBackgroundIndex = 0;
+ mainWindow.UpdatePickNameBackgroundDisplay();
+ }
+
+ // 更新ComboBox
+ mainWindow.UpdatePickNameBackgroundsInComboBox();
+
+ // 保存设置
+ MainWindow.SaveSettingsToFile();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"删除背景时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
+ }
+ }
+
+ private void CloseButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ink Canvas/Windows/RandWindow.xaml b/Ink Canvas/Windows/RandWindow.xaml
index a866e504..00ef6d31 100644
--- a/Ink Canvas/Windows/RandWindow.xaml
+++ b/Ink Canvas/Windows/RandWindow.xaml
@@ -9,7 +9,10 @@
mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True" Loaded="Window_Loaded"
WindowStartupLocation="CenterScreen"
Title="Ink Canvas 抽奖" Height="500" Width="900">
-
+
+
+
+