新增模块操作按钮并优化链接图标绘制逻辑

This commit is contained in:
waynebian01
2026-08-11 11:22:23 +08:00
parent 88eb47146c
commit 3740a21746
4 changed files with 109 additions and 57 deletions

View File

@@ -648,17 +648,45 @@ public sealed class MainForm : Form, IMessageFilter
_settingsToolTip.SetToolTip(moduleWebsiteLabel, $"在默认浏览器中打开 {ModuleWebsiteUrl}");
getModulesCard.Controls.Add(moduleWebsiteLabel, 0, 2);
var moduleActions = new FlowLayoutPanel
{
Dock = DockStyle.Fill,
AutoSize = false,
FlowDirection = FlowDirection.LeftToRight,
WrapContents = false,
BackColor = Color.Transparent,
Margin = new Padding(0),
Padding = new Padding(0)
};
var moduleWebsiteButtonColor = Color.FromArgb(252, 238, 10);
var openModuleWebsiteButton = UiTheme.CreateButton("打开模块网站", moduleWebsiteButtonColor, Color.Black);
var openModuleWebsiteButton = UiTheme.CreateButton("获取模块", moduleWebsiteButtonColor, Color.Black);
openModuleWebsiteButton.AutoSize = false;
openModuleWebsiteButton.Size = new Size(160, settingsActionButtonHeight);
openModuleWebsiteButton.Dock = DockStyle.Left;
openModuleWebsiteButton.Margin = new Padding(0);
openModuleWebsiteButton.Margin = new Padding(0, 0, 10, 0);
openModuleWebsiteButton.Padding = new Padding(0, 2, 24, 2);
openModuleWebsiteButton.FlatAppearance.BorderColor = moduleWebsiteButtonColor;
openModuleWebsiteButton.FlatAppearance.MouseOverBackColor = Color.FromArgb(255, 244, 64);
openModuleWebsiteButton.FlatAppearance.MouseDownBackColor = Color.FromArgb(220, 207, 8);
openModuleWebsiteButton.Paint += (_, e) => UiTheme.DrawExternalLinkIcon(
e.Graphics,
openModuleWebsiteButton.ClientRectangle,
openModuleWebsiteButton.Text,
openModuleWebsiteButton.Font,
openModuleWebsiteButton.ForeColor,
openModuleWebsiteButton.DeviceDpi / 96F);
openModuleWebsiteButton.Click += (_, _) => OpenModuleWebsite();
getModulesCard.Controls.Add(openModuleWebsiteButton, 0, 3);
var openModuleDirectoryButton = UiTheme.CreateButton("打开模块目录", UiTheme.ButtonKind.Secondary);
openModuleDirectoryButton.AutoSize = false;
openModuleDirectoryButton.Size = new Size(160, settingsActionButtonHeight);
openModuleDirectoryButton.Margin = new Padding(0);
openModuleDirectoryButton.Click += (_, _) => OpenModuleDirectory();
_settingsToolTip.SetToolTip(openModuleDirectoryButton, "在资源管理器中打开本地模块目录");
moduleActions.Controls.Add(openModuleWebsiteButton);
moduleActions.Controls.Add(openModuleDirectoryButton);
getModulesCard.Controls.Add(moduleActions, 0, 3);
panel.Controls.Add(inputCard, 0, 0);
panel.Controls.Add(configCard, 1, 0);
@@ -689,6 +717,30 @@ public sealed class MainForm : Form, IMessageFilter
}
}
private void OpenModuleDirectory()
{
var moduleDirectory = _moduleStore.ModuleDirectory;
try
{
Directory.CreateDirectory(moduleDirectory);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = "explorer.exe",
Arguments = $"\"{moduleDirectory}\"",
UseShellExecute = true
});
}
catch (Exception ex)
{
MessageBox.Show(
this,
$"无法打开模块目录:{ex.Message}",
"Shigure",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
}
private async Task UpdateConfigFromProjectWithFeedbackAsync()
{
_updateConfigButton.Enabled = false;

View File

@@ -195,7 +195,7 @@ public sealed class ModuleEditorControl : UserControl
getModulesButton.FlatAppearance.BorderColor = Color.FromArgb(252, 238, 10);
getModulesButton.FlatAppearance.MouseOverBackColor = Color.FromArgb(255, 244, 64);
getModulesButton.FlatAppearance.MouseDownBackColor = Color.FromArgb(220, 207, 8);
getModulesButton.Paint += (_, e) => DrawExternalLinkIcon(
getModulesButton.Paint += (_, e) => UiTheme.DrawExternalLinkIcon(
e.Graphics,
getModulesButton.ClientRectangle,
getModulesButton.Text,
@@ -209,57 +209,6 @@ public sealed class ModuleEditorControl : UserControl
return footer;
}
private static void DrawExternalLinkIcon(
Graphics graphics,
Rectangle clientBounds,
string text,
Font font,
Color color,
float scale)
{
var iconSize = 17F * scale;
var iconGap = 6F * scale;
var textSize = TextRenderer.MeasureText(
graphics,
text,
font,
Size.Empty,
TextFormatFlags.NoPadding | TextFormatFlags.SingleLine);
var groupWidth = textSize.Width + iconGap + iconSize;
var left = clientBounds.Left
+ ((clientBounds.Width - groupWidth) / 2F)
+ textSize.Width
+ iconGap;
var top = clientBounds.Top + (clientBounds.Height - iconSize) / 2F;
var previousSmoothingMode = graphics.SmoothingMode;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using var pen = new Pen(color, 1.8F * scale)
{
StartCap = LineCap.Round,
EndCap = LineCap.Round,
LineJoin = LineJoin.Round
};
PointF Point(float x, float y) => new(left + (x * scale), top + (y * scale));
graphics.DrawLines(
pen,
[
Point(7, 2),
Point(4, 2),
Point(2, 4),
Point(2, 13),
Point(4, 15),
Point(13, 15),
Point(15, 13),
Point(15, 9)
]);
graphics.DrawLine(pen, Point(8, 9), Point(15, 2));
graphics.DrawLines(pen, [Point(10, 2), Point(15, 2), Point(15, 7)]);
graphics.SmoothingMode = previousSmoothingMode;
}
private static void OpenModuleWebsite()
{
try

View File

@@ -705,7 +705,7 @@ public sealed class StatusForm : Form
}, 0, 0);
heading.Controls.Add(new Label
{
Text = "应用信息与 ClassBlocks 可用状态字段参考",
Text = "世界上的大多数人想到荒坂公司时,脑中浮现的景象便是被众多企业、组织、权势雇佣的黑衣保安。",
AutoSize = true,
ForeColor = UiTheme.Muted,
BackColor = Color.Transparent,

View File

@@ -265,6 +265,57 @@ internal static class UiTheme
return path;
}
public static void DrawExternalLinkIcon(
Graphics graphics,
Rectangle clientBounds,
string text,
Font font,
Color color,
float scale)
{
var iconSize = 17F * scale;
var iconGap = 6F * scale;
var textSize = TextRenderer.MeasureText(
graphics,
text,
font,
Size.Empty,
TextFormatFlags.NoPadding | TextFormatFlags.SingleLine);
var groupWidth = textSize.Width + iconGap + iconSize;
var left = clientBounds.Left
+ ((clientBounds.Width - groupWidth) / 2F)
+ textSize.Width
+ iconGap;
var top = clientBounds.Top + (clientBounds.Height - iconSize) / 2F;
var previousSmoothingMode = graphics.SmoothingMode;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using var pen = new Pen(color, 1.8F * scale)
{
StartCap = LineCap.Round,
EndCap = LineCap.Round,
LineJoin = LineJoin.Round
};
PointF Point(float x, float y) => new(left + (x * scale), top + (y * scale));
graphics.DrawLines(
pen,
[
Point(7, 2),
Point(4, 2),
Point(2, 4),
Point(2, 13),
Point(4, 15),
Point(13, 15),
Point(15, 13),
Point(15, 9)
]);
graphics.DrawLine(pen, Point(8, 9), Point(15, 2));
graphics.DrawLines(pen, [Point(10, 2), Point(15, 2), Point(15, 7)]);
graphics.SmoothingMode = previousSmoothingMode;
}
public static void ApplyControlRoundedRegion(Control control, int logicalRadius = 8)
{
void UpdateRegion()