Skip to content
Draft
Show file tree
Hide file tree
Changes from 9 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
192 changes: 192 additions & 0 deletions Plain Craft Launcher 2/Controls/Dialog/DialogControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
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();
internal 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.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);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Grid x:Class="PCL.MyMsgSelect"
<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"
Expand All @@ -24,22 +24,18 @@
<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" Text="测试标题文本"
VerticalAlignment="Top" SnapsToDevicePixels="False" UseLayoutRounding="False" />
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="PanCaption" Margin="0,0,0,17"
<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">
<StackPanel x:Name="PanSelection" Orientation="Vertical" />
<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">
<my:MyButton ColorType="Normal" x:FieldModifier="public" Text="测试按钮1" x:Name="Btn1" Margin="12,0,0,0"
TextPadding="7" SnapsToDevicePixels="False" Padding="5,0" UseLayoutRounding="False" />
<my:MyButton ColorType="Normal" x:FieldModifier="public" Text="测试按钮2" x:Name="Btn2" Margin="12,0,0,0"
TextPadding="7" SnapsToDevicePixels="False" Padding="5,0" UseLayoutRounding="False" />
</StackPanel>
Margin="150,0,8,0" Orientation="Horizontal" />
</Grid>
</Border>
</Grid>
</Grid>
52 changes: 0 additions & 52 deletions Plain Craft Launcher 2/Controls/MyMsg/MyMsgInput.xaml

This file was deleted.

Loading
Loading