add:一言名言种类自定义

This commit is contained in:
2026-02-21 18:47:30 +08:00
parent 86cdb231d0
commit 3e3db27296
4 changed files with 210 additions and 11 deletions
+16 -10
View File
@@ -1267,17 +1267,23 @@
IsOn="True" FontFamily="Microsoft YaHei UI" FontWeight="Bold"
Toggled="ToggleSwitchEnableChickenSoupInWhiteboardMode_Toggled" />
</ui:SimpleStackPanel>
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<ui:SimpleStackPanel Orientation="Vertical" HorizontalAlignment="Left">
<TextBlock Foreground="#fafafa" Text="信仰の源出自Where" VerticalAlignment="Center"
FontSize="14" Margin="0,0,16,0" />
<ComboBox Name="ComboBoxChickenSoupSource" FontFamily="Microsoft YaHei UI"
SelectedIndex="1"
SelectionChanged="ComboBoxChickenSoupSource_SelectionChanged">
<ComboBoxItem Content="osu!玩家语录" FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="励志立志的名言警句" FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="高考祝福语" FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="一言(Hitokoto API" FontFamily="Microsoft YaHei UI" />
</ComboBox>
FontSize="14" Margin="0,0,0,6" />
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<ComboBox Name="ComboBoxChickenSoupSource" FontFamily="Microsoft YaHei UI"
SelectedIndex="1" Width="240"
SelectionChanged="ComboBoxChickenSoupSource_SelectionChanged">
<ComboBoxItem Content="osu!玩家语录" FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="励志立志的名言警句" FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="高考祝福语" FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="一言(Hitokoto API" FontFamily="Microsoft YaHei UI" />
</ComboBox>
<Button Name="BtnHitokotoCustomize" Content="自定义" FontFamily="Microsoft YaHei UI"
FontSize="14" Padding="14,4" Margin="8,0,0,0" MinWidth="65" VerticalAlignment="Center"
Click="BtnHitokotoCustomize_Click"
Visibility="Collapsed" />
</ui:SimpleStackPanel>
</ui:SimpleStackPanel>
<Line HorizontalAlignment="Center" X1="0" Y1="0" X2="400" Y2="0"
Stroke="#3f3f46" StrokeThickness="1" Margin="0,4,0,4" />
+178 -1
View File
@@ -3,8 +3,10 @@ using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using OSVersionExtension;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Text;
@@ -952,7 +954,22 @@ namespace Ink_Canvas
return;
}
var response = await client.GetAsync("https://v1.hitokoto.cn/?encode=text").ConfigureAwait(true);
// 构建API URL,包含选中的分类参数
var categories = Settings.Appearance.HitokotoCategories;
if (categories == null || categories.Count == 0)
{
// 如果没有选中任何分类,默认全选
categories = new List<string> { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l" };
Settings.Appearance.HitokotoCategories = categories;
}
var urlBuilder = new StringBuilder("https://v1.hitokoto.cn/?encode=text");
foreach (var category in categories)
{
urlBuilder.Append($"&c={category}");
}
var response = await client.GetAsync(urlBuilder.ToString()).ConfigureAwait(true);
response.EnsureSuccessStatusCode();
var text = await response.Content.ReadAsStringAsync().ConfigureAwait(true);
@@ -986,10 +1003,170 @@ namespace Ink_Canvas
{
if (!isLoaded) return;
Settings.Appearance.ChickenSoupSource = ComboBoxChickenSoupSource.SelectedIndex;
if (BtnHitokotoCustomize != null)
{
BtnHitokotoCustomize.Visibility = ComboBoxChickenSoupSource.SelectedIndex == 3
? Visibility.Visible
: Visibility.Collapsed;
}
SaveSettingsToFile();
await UpdateChickenSoupTextAsync();
}
private async void BtnHitokotoCustomize_Click(object sender, RoutedEventArgs e)
{
var categories = new Dictionary<string, string>
{
{ "a", "动画" },
{ "b", "漫画" },
{ "c", "游戏" },
{ "d", "文学" },
{ "e", "原创" },
{ "f", "来自网络" },
{ "g", "其他" },
{ "h", "影视" },
{ "i", "诗词" },
{ "j", "网易云" },
{ "k", "哲学" },
{ "l", "抖机灵" }
};
// 创建弹窗内容
var contentPanel = new StackPanel
{
Margin = new Thickness(20),
Orientation = System.Windows.Controls.Orientation.Vertical
};
// 全选复选框
var selectAllCheckBox = new CheckBox
{
Content = "全选",
FontSize = 14,
FontFamily = new FontFamily("Microsoft YaHei UI"),
Margin = new Thickness(0, 0, 0, 8)
};
// 存储各个分类的复选框
var categoryCheckBoxes = new Dictionary<string, CheckBox>();
// 创建分类复选框
foreach (var category in categories)
{
var checkBox = new CheckBox
{
Content = category.Value,
Tag = category.Key,
FontSize = 13,
FontFamily = new FontFamily("Microsoft YaHei UI"),
IsChecked = Settings.Appearance.HitokotoCategories.Contains(category.Key),
Margin = new Thickness(0, 0, 0, 8)
};
categoryCheckBoxes[category.Key] = checkBox;
contentPanel.Children.Add(checkBox);
}
// 全选复选框逻辑
bool isUpdatingSelectAll = false;
selectAllCheckBox.IsChecked = Settings.Appearance.HitokotoCategories.Count == categories.Count;
selectAllCheckBox.Checked += (s, args) =>
{
if (isUpdatingSelectAll) return;
isUpdatingSelectAll = true;
foreach (var checkBox in categoryCheckBoxes.Values)
{
checkBox.IsChecked = true;
}
isUpdatingSelectAll = false;
};
selectAllCheckBox.Unchecked += (s, args) =>
{
if (isUpdatingSelectAll) return;
isUpdatingSelectAll = true;
foreach (var checkBox in categoryCheckBoxes.Values)
{
checkBox.IsChecked = false;
}
isUpdatingSelectAll = false;
};
// 监听各个复选框的变化,更新全选状态
foreach (var checkBox in categoryCheckBoxes.Values)
{
checkBox.Checked += (s, args) =>
{
if (isUpdatingSelectAll) return;
isUpdatingSelectAll = true;
selectAllCheckBox.IsChecked = categoryCheckBoxes.Values.All(cb => cb.IsChecked == true);
isUpdatingSelectAll = false;
};
checkBox.Unchecked += (s, args) =>
{
if (isUpdatingSelectAll) return;
isUpdatingSelectAll = true;
selectAllCheckBox.IsChecked = false;
isUpdatingSelectAll = false;
};
}
// 将全选复选框添加到顶部
var mainPanel = new StackPanel
{
Margin = new Thickness(0),
Orientation = System.Windows.Controls.Orientation.Vertical
};
mainPanel.Children.Add(selectAllCheckBox);
mainPanel.Children.Add(new Separator { Margin = new Thickness(0, 8, 0, 8) });
mainPanel.Children.Add(contentPanel);
var scrollViewer = new ScrollViewer
{
Content = mainPanel,
MaxHeight = 400,
VerticalScrollBarVisibility = ScrollBarVisibility.Auto
};
// 创建ContentDialog显示自定义内容
var contentDialog = new iNKORE.UI.WPF.Modern.Controls.ContentDialog
{
Title = "自定义一言分类",
Content = scrollViewer,
PrimaryButtonText = "确定",
SecondaryButtonText = "取消",
DefaultButton = iNKORE.UI.WPF.Modern.Controls.ContentDialogButton.Primary,
Owner = this
};
var dialogResult = await contentDialog.ShowAsync();
if (dialogResult == iNKORE.UI.WPF.Modern.Controls.ContentDialogResult.Primary)
{
// 保存选中的分类
Settings.Appearance.HitokotoCategories = categoryCheckBoxes
.Where(kvp => kvp.Value.IsChecked == true)
.Select(kvp => kvp.Key)
.ToList();
// 如果没有任何选中,默认全选
if (Settings.Appearance.HitokotoCategories.Count == 0)
{
Settings.Appearance.HitokotoCategories = categories.Keys.ToList();
}
SaveSettingsToFile();
// 如果当前正在使用API,更新名言
if (Settings.Appearance.ChickenSoupSource == 3 && Settings.Appearance.EnableChickenSoupInWhiteboardMode)
{
_ = UpdateChickenSoupTextAsync();
}
}
}
private void ToggleSwitchEnableViewboxBlackBoardScaleTransform_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
@@ -388,6 +388,20 @@ namespace Ink_Canvas
ComboBoxTheme.SelectedIndex = Settings.Appearance.Theme;
ComboBoxChickenSoupSource.SelectedIndex = Settings.Appearance.ChickenSoupSource;
// 初始化自定义按钮的可见性(仅在选择API时显示)
if (BtnHitokotoCustomize != null)
{
BtnHitokotoCustomize.Visibility = Settings.Appearance.ChickenSoupSource == 3
? Visibility.Visible
: Visibility.Collapsed;
}
// 初始化HitokotoCategories,如果为空则默认全选
if (Settings.Appearance.HitokotoCategories == null || Settings.Appearance.HitokotoCategories.Count == 0)
{
Settings.Appearance.HitokotoCategories = new List<string> { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l" };
}
ToggleSwitchEnableQuickPanel.IsOn = Settings.Appearance.IsShowQuickPanel;
+2
View File
@@ -273,6 +273,8 @@ namespace Ink_Canvas
public bool IsShowQuickPanel { get; set; } = true;
[JsonProperty("chickenSoupSource")]
public int ChickenSoupSource { get; set; } = 1;
[JsonProperty("hitokotoCategories")]
public List<string> HitokotoCategories { get; set; } = new List<string> { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l" }; // 默认全选所有分类
[JsonProperty("isShowModeFingerToggleSwitch")]
public bool IsShowModeFingerToggleSwitch { get; set; } = true;
[JsonProperty("theme")]