Skip to content

Commit

Permalink
up修复窗口bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloryr committed Aug 5, 2024
1 parent 691eae9 commit c1ae822
Show file tree
Hide file tree
Showing 48 changed files with 391 additions and 237 deletions.
12 changes: 12 additions & 0 deletions src/ColorMC.Core/Utils/SystemInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public static class SystemInfo
/// 是否为64位处理器
/// </summary>
public static bool Is64Bit { get; private set; }
/// <summary>
/// 是否为Windows11
/// </summary>
public static bool IsWin11 { get; private set; }

/// <summary>
/// 初始化
Expand Down Expand Up @@ -72,6 +76,14 @@ public static void Init()
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Os = OsType.Windows;

var os = Environment.OSVersion;
var version = os.Version;

if (version.Major > 10 || (version.Major == 10 && version.Build >= 22000))
{
IsWin11 = true;
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Expand Down
2 changes: 1 addition & 1 deletion src/ColorMC.Gui/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public App()
ColorMCGui.StartLock();
}

public static TopLevel? TopLevel { get; set; }
//public static TopLevel? TopLevel { get; set; }

public static readonly SelfCrossFade CrossFade300 = new(TimeSpan.FromMilliseconds(300));
public static readonly SelfCrossFade CrossFade200 = new(TimeSpan.FromMilliseconds(200));
Expand Down
17 changes: 0 additions & 17 deletions src/ColorMC.Gui/ColorMC.Gui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -343,21 +343,4 @@
<ProjectReference Include="..\..\X11.Net\X11\X11.csproj" />
<ProjectReference Include="..\ColorMC.Core\ColorMC.Core.csproj" />
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Remove="UI\Controls\Main\MainUserControl.axaml" />
</ItemGroup>
<ItemGroup>
<Compile Update="UI\Windows\MultiLinuxWindow.axaml.cs">
<DependentUpon>MultiLinuxWindow.axaml</DependentUpon>
</Compile>
<Compile Update="UI\Windows\SingleControl.axaml.cs">
<DependentUpon>SingleControl.axaml</DependentUpon>
</Compile>
<Compile Update="UI\Windows\MultiWindow.axaml.cs">
<DependentUpon>MultiWindow.axaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Remove="UI\Windows\SingleLinuxWindow.axaml" />
</ItemGroup>
</Project>
94 changes: 42 additions & 52 deletions src/ColorMC.Gui/Manager/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void Init()
}
else if (SystemInfo.Os == OsType.Linux)
{
var win = new SingleLinuxWindow();
var win = new SingleBorderWindow();
AllWindow = win.Win;
win.Show();
}
Expand All @@ -92,11 +92,6 @@ public static void Init()
AllWindow = win.Win;
win.Show();
}

Dispatcher.UIThread.Post(() =>
{
App.TopLevel ??= TopLevel.GetTopLevel(AllWindow);
});
}

if (!ShowCustom())
Expand All @@ -119,6 +114,47 @@ public static IBaseWindow FindRoot(object? con)
return AllWindow!;
}

private static void ShowWindow(BaseUserControl con)
{
AMultiWindow win;
if (SystemInfo.Os == OsType.Linux ||
(SystemInfo.Os == OsType.Windows && !SystemInfo.IsWin11))
{
win = new MultiBorderWindow(con);
}
else
{
win = new MultiWindow(con);
}
con.SetBaseModel(win.Model);
win.Show();
}

public static void AWindow(BaseUserControl con, bool newwindow = false)
{
if (ConfigBinding.WindowMode())
{
if (newwindow)
{
if (SystemInfo.Os == OsType.Android)
{
return;
}

ShowWindow(con);
}
else
{
con.SetBaseModel(AllWindow!.Model);
AllWindow.Add(con);
}
}
else
{
ShowWindow(con);
}
}

public static bool ShowCustom(bool test = false)
{
if (CustomWindow != null)
Expand Down Expand Up @@ -172,52 +208,6 @@ public static bool ShowCustom(bool test = false)
return false;
}

public static void AWindow(BaseUserControl con, bool newwindow = false)
{
if (ConfigBinding.WindowMode())
{
if (newwindow)
{
if (SystemInfo.Os == OsType.Android)
{
return;
}

AMultiWindow win;
if (SystemInfo.Os == OsType.Linux)
{
win = new MultiLinuxWindow(con);
}
else
{
win = new MultiWindow(con);
}
con.SetBaseModel(win.Model);
win.Show();
}
else
{
con.SetBaseModel(AllWindow!.Model);
AllWindow.Add(con);
}
}
else
{
AMultiWindow win;
if (SystemInfo.Os == OsType.Linux)
{
win = new MultiLinuxWindow(con);
}
else
{
win = new MultiWindow(con);
}
App.TopLevel ??= win;
con.SetBaseModel(win.Model);
win.Show();
}
}

public static void ShowAddGame(string? group, bool isDir = false, string? file = null)
{
if (AddGameWindow != null)
Expand Down
8 changes: 6 additions & 2 deletions src/ColorMC.Gui/UI/Controls/Error/ErrorControl.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.ComponentModel;
using Avalonia.Controls;
using Avalonia.Media.Imaging;
using ColorMC.Gui.Manager;
using ColorMC.Gui.UI.Model;
Expand Down Expand Up @@ -56,14 +58,16 @@ public override void Closed()

public override void SetModel(BaseModel model)
{
ErrorModel amodel;
if (_type)
{
DataContext = new ErrorModel(model, _data, _e, _close);
amodel = new ErrorModel(model, _data, _e, _close);
}
else
{
DataContext = new ErrorModel(model, _data ?? "", _e1, _close);
amodel = new ErrorModel(model, _data ?? "", _e1, _close);
}
DataContext = amodel;
}

public override Bitmap GetIcon()
Expand Down
2 changes: 1 addition & 1 deletion src/ColorMC.Gui/UI/Controls/Items/GameControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void GameControl_PointerMoved(object? sender, PointerEventArgs e)
if (Math.Sqrt(Math.Pow(Math.Abs(pos.X - point.X), 2) + Math.Pow(Math.Abs(pos.Y - point.Y), 2)) > 30)
{
LongPressed.Cancel();
model.Move(e);
model.Move(TopLevel.GetTopLevel(this), e);
e.Handled = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ColorMC.Gui/UI/Flyouts/GameEditFlyout1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public GameEditFlyout1(Control con, IList list, GameEditModel model)
(App.Lang("GameEditWindow.Flyouts.Text6"), true, async ()=>
{
var list = new List<IStorageFile>();
if (App.TopLevel is { } top)
if (TopLevel.GetTopLevel(con) is { } top)
{
foreach (var item in mods)
{
Expand All @@ -69,7 +69,7 @@ public GameEditFlyout1(Control con, IList list, GameEditModel model)
list.Add(data);
}
await BaseBinding.CopyFileClipboard(list);
await BaseBinding.CopyFileClipboard(top, list);
}
}),
(App.Lang("GameEditWindow.Flyouts.Text3"), single, ()=>
Expand Down
7 changes: 6 additions & 1 deletion src/ColorMC.Gui/UI/Flyouts/GameEditFlyout5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ public GameEditFlyout5(Control con, GameEditModel model)
}),
(App.Lang("GameEditWindow.Flyouts.Text13"), true, ()=>
{
GameBinding.CopyServer(_model.ServerItem!);
var top =TopLevel.GetTopLevel(con);
if (top == null)
{
return;
}
GameBinding.CopyServer(top, _model.ServerItem!);
})
}, con);
}
Expand Down
7 changes: 6 additions & 1 deletion src/ColorMC.Gui/UI/Flyouts/MainFlyout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ public MainFlyout(Control con, GameItemModel obj)
(App.Lang("MainWindow.Flyouts.Text7"), true, obj.EditGroup),
(App.Lang("MainWindow.Flyouts.Text8"), true, async ()=>
{
await GameBinding.SetGameIconFromFile(obj.Model, obj.Obj);
var top = TopLevel.GetTopLevel(con);
if (top == null)
{
return;
}
await GameBinding.SetGameIconFromFile(top, obj.Model, obj.Obj);
obj.LoadIcon();
}),
(App.Lang("MainWindow.Flyouts.Text15"), SystemInfo.Os == OsType.Windows, ()=>
Expand Down
8 changes: 7 additions & 1 deletion src/ColorMC.Gui/UI/Model/Add/AddGameTab1Model.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Threading;
using AvaloniaEdit.Utils;
using ColorMC.Core.Helpers;
Expand Down Expand Up @@ -124,7 +125,12 @@ partial void OnVersionTypeChanged(int value)
[RelayCommand]
public async Task SelectLoader()
{
var file = await PathBinding.SelectFile(FileType.Loader);
var top = Model.GetTopLevel();
if (top == null)
{
return;
}
var file = await PathBinding.SelectFile(top, FileType.Loader);
if (file.Item1 == null)
{
return;
Expand Down
9 changes: 6 additions & 3 deletions src/ColorMC.Gui/UI/Model/Add/AddGameTab2Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ public void AddPackGame()
[RelayCommand]
public async Task SelectPack()
{
var file = await PathBinding.SelectFile(FileType.ModPack);
var top = Model.GetTopLevel();
if (top == null)
{
return;
}
var file = await PathBinding.SelectFile(top, FileType.ModPack);
if (file.Item1 != null)
{
ZipLocal = file.Item1;
Expand Down Expand Up @@ -124,6 +129,4 @@ public void SetFile(string file)
{
ZipLocal = file;
}


}
7 changes: 6 additions & 1 deletion src/ColorMC.Gui/UI/Model/Add/AddGameTab3Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ public async Task AddFiles()
[RelayCommand]
public async Task SelectLocal()
{
var res = await PathBinding.SelectPath(PathType.GamePath);
var top = Model.GetTopLevel();
if (top == null)
{
return;
}
var res = await PathBinding.SelectPath(top, PathType.GamePath);
if (string.IsNullOrWhiteSpace(res))
{
return;
Expand Down
15 changes: 15 additions & 0 deletions src/ColorMC.Gui/UI/Model/BaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public partial class BaseModel : ObservableObject
{
public const string InfoShow = "InfoShow";
public const string IconName = "Icon";
public const string GetTopLevelName = "GetTopLevel";

/// <summary>
/// 进度条
Expand Down Expand Up @@ -51,6 +52,7 @@ public partial class BaseModel : ObservableObject

private Action? _choiseClick;
private Action? _choise1Click;
private TopLevel? _top;

public string NotifyText;

Expand Down Expand Up @@ -693,6 +695,19 @@ public async Task<bool> ShowTextWait(string data, string data1)
return !_info6.IsCancel;
}

public void SetTopLevel(TopLevel? top)
{
_top = top;
}

public TopLevel? GetTopLevel()
{
OnPropertyChanged(GetTopLevelName);
var top = _top;
_top = null;
return top;
}

private void DClose()
{
try
Expand Down
16 changes: 13 additions & 3 deletions src/ColorMC.Gui/UI/Model/Error/ErrorModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Avalonia.Controls;
using AvaloniaEdit.Document;
using ColorMC.Core.Objs;
using ColorMC.Gui.UIBinding;
Expand Down Expand Up @@ -40,7 +41,12 @@ public ErrorModel(BaseModel model, string data, string e, bool close) : base(mod

public async void Save()
{
await PathBinding.SaveFile(FileType.Text, new[] { Text.Text });
var top = Model.GetTopLevel();
if (top == null)
{
return;
}
await PathBinding.SaveFile(top, FileType.Text, [Text.Text]);
}

public async void Push()
Expand All @@ -66,9 +72,13 @@ public async void Push()
}
else
{
var top = Model.GetTopLevel();
if (top == null)
{
return;
}
Model.ShowReadInfoOne(string.Format(App.Lang("GameLogWindow.Info5"), url), null);

await BaseBinding.CopyTextClipboard(url);
await BaseBinding.CopyTextClipboard(top, url!);
Model.Notify(App.Lang("GameLogWindow.Info7"));
}
}
Expand Down
Loading

0 comments on commit c1ae822

Please sign in to comment.