优化单位编辑器窗口大小的保存与恢复逻辑,调整相关UI组件属性

This commit is contained in:
waynebian01
2026-08-28 15:37:33 +08:00
parent 220edae2d8
commit 6f4163cf89
5 changed files with 82 additions and 9 deletions

View File

@@ -559,8 +559,8 @@ Fuyutsui.ClassMacros = {
DRUID = {
dynamicSpells = { "回春术", "愈合", "生命绽放", "迅捷治愈", "自然之愈" },
staticSpells = {
"[nostance:2]猎豹形态(变形)",
"[nostance:1]熊形态(变形)",
"[nostance:2]猎豹形态",
"[nostance:1]熊形态",
"[nostance:4]枭兽形态",
"月火术",
"树皮术",

View File

@@ -106,6 +106,7 @@ internal sealed class UiCacheState
public WindowBounds? VerticalMainWindowBounds { get; set; }
public WindowBounds? SettingsWindowBounds { get; set; }
public WindowSize? ConditionEditorWindowSize { get; set; }
public WindowSize? UnitEditorWindowSize { get; set; }
public string? SelectedSettingsPage { get; set; }
public string? MainWindowLayout { get; set; }
public string? CloseButtonBehavior { get; set; }

View File

@@ -2027,6 +2027,7 @@ public sealed class MainForm : Form, IMessageFilter
_uiCache.ModuleRulesGridColumns = latestCache.ModuleRulesGridColumns;
_uiCache.ColumnWidths = latestCache.ColumnWidths;
_uiCache.ConditionEditorWindowSize = latestCache.ConditionEditorWindowSize;
_uiCache.UnitEditorWindowSize = latestCache.UnitEditorWindowSize;
var currentBounds = CaptureMainWindowBounds();
_uiCache.MainWindowBounds = currentBounds;

View File

@@ -641,6 +641,7 @@ public sealed class ModuleEditorControl : UserControl
_adjustmentFieldColumn.MinimumWidth = 200;
_adjustmentFieldColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
_adjustmentFieldColumn.FlatStyle = FlatStyle.Flat;
_adjustmentFieldColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
_adjustmentsGrid.Columns.Add(_adjustmentFieldColumn);
_adjustmentsGrid.Columns.Add(new DataGridViewTextBoxColumn
@@ -666,6 +667,7 @@ public sealed class ModuleEditorControl : UserControl
_adjustmentTypeColumn.MinimumWidth = 100;
_adjustmentTypeColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
_adjustmentTypeColumn.FlatStyle = FlatStyle.Flat;
_adjustmentTypeColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
foreach (var option in AdjustmentTypeOptions)
{
_adjustmentTypeColumn.Items.Add(option.Text);
@@ -2194,7 +2196,7 @@ public sealed class ModuleEditorControl : UserControl
var columnName = _rulesGrid.Columns[e.ColumnIndex].Name;
if (columnName is "Spell" or "Unit" or "MacroCondition")
{
PaintRuleComboBoxCell(e);
PaintGridComboBoxCell(_rulesGrid, e);
return;
}
@@ -2393,7 +2395,14 @@ public sealed class ModuleEditorControl : UserControl
return;
}
if (_adjustmentsGrid.Columns[e.ColumnIndex].Name != "Delete")
var columnName = _adjustmentsGrid.Columns[e.ColumnIndex].Name;
if (columnName is "Type" or "Field")
{
PaintGridComboBoxCell(_adjustmentsGrid, e);
return;
}
if (columnName != "Delete")
{
return;
}
@@ -2436,7 +2445,7 @@ public sealed class ModuleEditorControl : UserControl
}
// 避免 WinForms 按系统主题绘制高亮白色方块,统一成深色圆角按钮和青色箭头。
private void PaintRuleComboBoxCell(DataGridViewCellPaintingEventArgs e)
private static void PaintGridComboBoxCell(DataGridView grid, DataGridViewCellPaintingEventArgs e)
{
e.Paint(e.CellBounds, DataGridViewPaintParts.Background | DataGridViewPaintParts.Border);
if (e.Graphics is null)
@@ -2445,8 +2454,8 @@ public sealed class ModuleEditorControl : UserControl
return;
}
var selected = (_rulesGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].State & DataGridViewElementStates.Selected) != 0;
var cellStyle = e.CellStyle ?? _rulesGrid.DefaultCellStyle;
var selected = (grid.Rows[e.RowIndex].Cells[e.ColumnIndex].State & DataGridViewElementStates.Selected) != 0;
var cellStyle = e.CellStyle ?? grid.DefaultCellStyle;
var textColor = selected ? cellStyle.SelectionForeColor : cellStyle.ForeColor;
var buttonSize = Math.Min(24, Math.Max(18, e.CellBounds.Height - 12));
var buttonBounds = new Rectangle(
@@ -2463,7 +2472,7 @@ public sealed class ModuleEditorControl : UserControl
TextRenderer.DrawText(
e.Graphics,
e.FormattedValue?.ToString() ?? string.Empty,
cellStyle.Font ?? _rulesGrid.Font,
cellStyle.Font ?? grid.Font,
textBounds,
textColor,
TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.EndEllipsis);

View File

@@ -135,6 +135,24 @@ public sealed class UnitEditorForm : Form
UiTheme.ApplyDarkTitleBar(this);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
RestoreCachedWindowSize();
}
protected override void OnResizeEnd(EventArgs e)
{
base.OnResizeEnd(e);
SaveWindowSize();
}
protected override void OnFormClosed(FormClosedEventArgs e)
{
SaveWindowSize();
base.OnFormClosed(e);
}
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
@@ -142,6 +160,49 @@ public sealed class UnitEditorForm : Form
_nameBox.SelectAll();
}
private void RestoreCachedWindowSize()
{
var cached = UiCacheStore.Load().UnitEditorWindowSize;
if (cached is null || cached.Width <= 0 || cached.Height <= 0)
{
return;
}
var workingArea = Owner is not null
? Screen.FromControl(Owner).WorkingArea
: Screen.FromControl(this).WorkingArea;
var maximumWidth = Math.Max(MinimumSize.Width, workingArea.Width - 40);
var maximumHeight = Math.Max(MinimumSize.Height, workingArea.Height - 40);
Size = new Size(
Math.Clamp(cached.Width, MinimumSize.Width, maximumWidth),
Math.Clamp(cached.Height, MinimumSize.Height, maximumHeight));
if (Owner is not null)
{
CenterToParent();
}
else
{
CenterToScreen();
}
}
private void SaveWindowSize()
{
if (WindowState != FormWindowState.Normal || Width <= 0 || Height <= 0)
{
return;
}
var cache = UiCacheStore.Load();
cache.UnitEditorWindowSize = new WindowSize
{
Width = Width,
Height = Height
};
UiCacheStore.Save(cache);
}
private void InitializeComponent()
{
Text = "编辑单位";
@@ -150,11 +211,12 @@ public sealed class UnitEditorForm : Form
BackColor = UiTheme.Surface;
ForeColor = UiTheme.Text;
ClientSize = new Size(RowWidth + 36, 534);
FormBorderStyle = FormBorderStyle.FixedDialog;
FormBorderStyle = FormBorderStyle.Sizable;
MaximizeBox = false;
MinimizeBox = false;
ShowInTaskbar = false;
StartPosition = FormStartPosition.CenterParent;
MinimumSize = new Size(RowWidth + 52, 420);
var root = new TableLayoutPanel
{