-
Notifications
You must be signed in to change notification settings - Fork 113
refactor(msgbox): add customizable DialogControl + Dialog API #3168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
tangge233
wants to merge
14
commits into
dev
Choose a base branch
from
refactor/msgbox
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bef259d
refactor(msgbox): add customizable DialogControl + Dialog API
tangge233 bf89224
feat(demo): add dialog test button in toolbox (debug-only)
tangge233 a81caa7
feat(dialog): add Id to DialogButton, preset button factories, i18n
tangge233 afb6f74
feat(dialog): add async wait model, support sync/async blocking
tangge233 1bd383f
refactor(dialog): eliminate MyMsgBoxConverter from Dialog path
tangge233 e38a2c5
refactor(dialog): route all MyMsg types through DialogControl
tangge233 072e641
refactor: extract dialog code to ModMain.Dialog.cs partial class
tangge233 f7ad35d
refactor(dialog): DialogManager with XamlRoot, split into clean files
tangge233 be51f26
refactor: remove MyMsgBoxConverter, migrate MS login, delete old cont…
tangge233 3dec522
fix(dialog): catch TaskCanceledException on Dispatcher.Invoke
tangge233 9e4d841
feat(dialog): generic Dialog<T>, Show(content), cancel flag, keyboard…
tangge233 99a6acb
refactor: rename MyMsgLogin → DialogMsOAuthLogin, use DialogManager.S…
tangge233 024de3a
fix: dialog color
tangge233 17f6761
refactor(dialog): AddButton accepts DialogButton, ButtonBuilder, drop…
tangge233 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
Plain Craft Launcher 2/Controls/Dialog/DialogControl.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
|
||
| 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); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DialogControlalways focuses the first button during load. SinceMyMsgBoxInputprompts 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 theirMyTextBoxinstead of unconditionally focusing the first button.Useful? React with 👍 / 👎.