Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .codegraph/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CodeGraph data files — local to each machine, not for committing.
# Ignore everything in .codegraph/ except this file itself, so transient
# files (the database, daemon.pid, sockets, logs) never show up in git.
*
!.gitignore
3 changes: 2 additions & 1 deletion PCL.Core/UI/MsgBoxWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public static int ShowWithCustomButtons(
ICollection<MsgBoxButtonInfo> buttonCollection)
{
var result = 0;
if (buttonCollection.Count == 0) buttonCollection = [new MsgBoxButtonInfo(Lang.Text("Common.Action.Confirm"))];
if (buttonCollection.Count == 0)
buttonCollection = [new MsgBoxButtonInfo(Lang.Text("Common.Action.Confirm"))];
OnShow?.Invoke(message, caption, buttonCollection, theme, block, ref result);
return result;
}
Expand Down
193 changes: 193 additions & 0 deletions Plain Craft Launcher 2/Controls/Dialog/DialogControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Threading;
using PCL.Core.UI.Controls;

namespace PCL;

public partial class DialogControl
{
private int _result;
private bool _exited;
private readonly int _uuid = ModBase.GetUuid();
private readonly List<MyButton> _buttons = [];

public DispatcherFrame WaitFrame { get; } = new(true);

public string Title
{
get => LabTitle.Text;
set => LabTitle.Text = value;
}

public bool IsWarn { get; set; }

public UIElement? DialogContent
{
get => (UIElement?)ContentArea.Content;
set => ContentArea.Content = value;
}

public int Result => _result;

public DialogControl()
{
try
{
InitializeComponent();
ShapeLine.StrokeThickness = ModBase.GetWPFSize(1d);
}
catch (Exception ex)
{
ModBase.Log(ex, "DialogControl 初始化失败", ModBase.LogLevel.Hint);
}

Loaded += OnLoad;
}

public MyButton AddButton(string text, Action? onClick = null, bool isPrimary = false, int id = 0)
{
var btn = new MyButton
{
Text = text,
ColorType = isPrimary
? (IsWarn ? MyButton.ColorState.Red : MyButton.ColorState.Highlight)
: MyButton.ColorState.Normal,
Visibility = string.IsNullOrEmpty(text) ? Visibility.Collapsed : Visibility.Visible,
IsEnabled = true,
};
btn.ApplyTemplate();
btn.TextPadding = new Thickness(7);
btn.Padding = new Thickness(5, 0, 5, 0);
btn.Margin = new Thickness(12, 0, 0, 0);
btn.Name += ModBase.GetUuid();
var buttonId = id > 0 ? id : _buttons.Count + 1;
btn.Click += (_, _) =>
{
if (_exited) return;
if (onClick is not null)
{
onClick();
}
else
{
Close(buttonId);
}
};
_buttons.Add(btn);
PanBtn.Children.Add(btn);
return btn;
}

public event Action<int>? OnClosed;

private void OnLoad(object sender, RoutedEventArgs e)
{
try
{
if (_buttons.Count > 1 && _buttons[0].ColorType != MyButton.ColorState.Red)
_buttons[0].ColorType = MyButton.ColorState.Highlight;
if (_buttons.Count > 0)
_buttons[0].Focus();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore initial focus to input prompts

DialogControl always focuses the first button during load. Since MyMsgBoxInput prompts are now built with this container, the text box no longer receives the caret as the old input dialog did, so users typing immediately into prompts such as instance/profile names type nowhere until they click the field. Let input dialogs request focus for their MyTextBox instead of unconditionally focusing the first button.

Useful? React with 👍 / 👎.


Opacity = 0d;
ModAnimation.AniStart(
ModAnimation.AaColor(ModMain.frmMain.PanMsgBackground, BlurBorder.BackgroundProperty,
(IsWarn
? new ModBase.MyColor(140d, 80d, 0d, 0d)
: new ModBase.MyColor(90d, 0d, 0d, 0d)) - ModMain.frmMain.PanMsgBackground.Background, 200),
"PanMsgBackground Background");
ModAnimation.AniStart(
new ModAnimation.AniData[]
{
ModAnimation.AaOpacity(this, 1d, 120, 60),
ModAnimation.AaDouble(i => TransformPos.Y += (double)i,
-TransformPos.Y, 300, 60, new ModAnimation.AniEaseOutBack(ModAnimation.AniEasePower.Weak)),
ModAnimation.AaDouble(i => TransformRotate.Angle += (double)i,
-TransformRotate.Angle, 300, 60,
new ModAnimation.AniEaseOutFluent(ModAnimation.AniEasePower.Weak))
}, "DialogControl " + _uuid);

ModBase.Log("[Dialog] " + LabTitle.Text);
}
catch (Exception ex)
{
ModBase.Log(ex, "DialogControl 加载失败", ModBase.LogLevel.Hint);
}
}

public void Close(int result)
{
if (_exited) return;
_exited = true;
_result = result;
CloseInternal();
}

public void Close()
{
if (_exited) return;
_exited = true;
_result = -1;
CloseInternal();
}

private void CloseInternal()
{
try
{
WaitFrame.Continue = false;
}
catch
{
// ignore
}

try
{
ComponentDispatcher.PopModal();
}
catch
{
// ignore
}

OnClosed?.Invoke(_result);

ModAnimation.AniStart(
new ModAnimation.AniData[]
{
ModAnimation.AaCode(() =>
{
var hasMore = ModMain.WaitingMyMsgBox.Any()
|| (ModMain.frmMain?.PanMsg?.Children.Count ?? 0) > 1;
if (!hasMore)
ModAnimation.AniStart(ModAnimation.AaColor(ModMain.frmMain.PanMsgBackground,
BlurBorder.BackgroundProperty,
new ModBase.MyColor(0d, 0d, 0d, 0d) - ModMain.frmMain.PanMsgBackground.Background, 200,
ease: new ModAnimation.AniEaseOutFluent(ModAnimation.AniEasePower.Weak)));
}, 30),
ModAnimation.AaOpacity(this, -Opacity, 80, 20),
ModAnimation.AaDouble(i => TransformPos.Y += (double)i, 20d - TransformPos.Y,
150, 0, new ModAnimation.AniEaseOutFluent()),
ModAnimation.AaDouble(i => TransformRotate.Angle += (double)i,
6d - TransformRotate.Angle, 150, 0, new ModAnimation.AniEaseInFluent(ModAnimation.AniEasePower.Weak)),
ModAnimation.AaCode(() => ((Grid)Parent)?.Children.Remove(this), after: true)
}, "DialogControl " + _uuid);
}

private void Drag(object sender, MouseButtonEventArgs e)
{
try
{
if (e.LeftButton == MouseButtonState.Pressed && e.GetPosition(ShapeLine).Y <= 2d)
ModMain.frmMain.DragMove();
}
catch (Exception ex)
{
ModBase.Log(ex, "拖拽移动失败", ModBase.LogLevel.Hint);
}
}
}
41 changes: 41 additions & 0 deletions Plain Craft Launcher 2/Controls/Dialog/DialogControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Grid x:Class="PCL.DialogControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:PCL"
RenderTransformOrigin="0,0.5" UseLayoutRounding="True" SnapsToDevicePixels="True" MinWidth="400"
HorizontalAlignment="Center" VerticalAlignment="Center" Margin="25">
<Grid.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="TransformRotate" Angle="-4" />
<TranslateTransform x:Name="TransformPos" X="0" Y="40" />
</TransformGroup>
</Grid.RenderTransform>
<Border Name="PanBorder" CornerRadius="7" Background="{DynamicResource ColorBrushBackground}">
<Border.Effect>
<DropShadowEffect Color="{DynamicResource ColorObjectMsgBoxShadow}" BlurRadius="20" ShadowDepth="2"
RenderingBias="Performance" Opacity="0.8" x:Name="EffectShadow" />
</Border.Effect>
<Grid Name="PanMain" VerticalAlignment="Top" Margin="22,22,22,23">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="2" />
<RowDefinition Height="13" />
<RowDefinition Height="1*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" FontSize="23" TextTrimming="None" Foreground="{DynamicResource ColorBrush2}"
HorizontalAlignment="Left" Name="LabTitle" Margin="7,-1,70,9"
VerticalAlignment="Top" SnapsToDevicePixels="False" UseLayoutRounding="False"
MouseLeftButtonDown="Drag" />
<Rectangle x:Name="ShapeLine" Grid.Row="1" Height="2" Fill="{Binding Foreground, ElementName=LabTitle}" />
<my:MyScrollViewer Grid.Row="3" VerticalAlignment="Top" x:Name="ContentScrollViewer" Margin="0,0,0,17"
Padding="7,0,15,0"
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled"
DeltaMult="0.7">
<ContentControl x:Name="ContentArea" Focusable="False" />
</my:MyScrollViewer>
<StackPanel Grid.Row="4" Name="PanBtn" VerticalAlignment="Top" HorizontalAlignment="Right"
Margin="150,0,8,0" Orientation="Horizontal" />
</Grid>
</Border>
</Grid>
32 changes: 32 additions & 0 deletions Plain Craft Launcher 2/Dialog/DialogButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using PCL.Core.App.Localization;

namespace PCL.Core.UI;

public class DialogButton
{
public string Text { get; set; }
public int Id { get; set; }
public Action? OnClick { get; set; }
public bool IsPrimary { get; set; }

public DialogButton(string text, Action? onClick = null, bool isPrimary = false, int id = 0)
{
Text = text;
OnClick = onClick;
IsPrimary = isPrimary;
Id = id;
}

public static DialogButton Confirm(string? text = null)
=> new(text ?? Lang.Text("Common.Action.Confirm"), isPrimary: true, id: DialogResult.Ok);

public static DialogButton Cancel(string? text = null)
=> new(text ?? Lang.Text("Common.Action.Cancel"), id: DialogResult.Cancel);

public static DialogButton Yes(string? text = null)
=> new(text ?? Lang.Text("Common.Option.Yes"), isPrimary: true, id: DialogResult.Yes);

public static DialogButton No(string? text = null)
=> new(text ?? Lang.Text("Common.Option.No"), id: DialogResult.No);
}
16 changes: 16 additions & 0 deletions Plain Craft Launcher 2/Dialog/DialogContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.ObjectModel;

namespace PCL.Core.UI;

public class DialogContext
{
public string Caption { get; set; } = "";
public string Title { get; set; } = "";
public DialogTheme Theme { get; set; } = DialogTheme.Info;
public bool Block { get; set; } = true;
public object? Content { get; set; }
public Collection<DialogButton> Buttons { get; set; } = [];
public int Result { get; set; }
public Action<int>? OnClosed { get; set; }
}
Loading
Loading