一个编译器的地基写了一下午QWQ
This commit is contained in:
parent
a1f19d5d86
commit
0ddd8fdbc7
|
@ -1,8 +1,7 @@
|
||||||
using System.Threading;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
|
|
||||||
using RustTools.Contracts.Services;
|
using RustTools.Contracts.Services;
|
||||||
using RustTools.Models;
|
using RustTools.Models;
|
||||||
using RustTools.Services;
|
using RustTools.Services;
|
||||||
|
@ -10,14 +9,10 @@ using RustTools.ViewModels;
|
||||||
using RustTools.Views;
|
using RustTools.Views;
|
||||||
using RustTools.muqing;
|
using RustTools.muqing;
|
||||||
using RustTools.Activation;
|
using RustTools.Activation;
|
||||||
using System.Diagnostics;
|
|
||||||
using RustTools.WindowUI;
|
using RustTools.WindowUI;
|
||||||
using Windows.ApplicationModel.Activation;
|
using Windows.ApplicationModel.Activation;
|
||||||
using Windows.Storage;
|
|
||||||
using Microsoft.UI.Xaml.Controls;
|
|
||||||
using Microsoft.Windows.AppLifecycle;
|
using Microsoft.Windows.AppLifecycle;
|
||||||
using Windows.ApplicationModel;
|
using WinUIEx;
|
||||||
using Windows.Management.Core;
|
|
||||||
|
|
||||||
namespace RustTools;
|
namespace RustTools;
|
||||||
|
|
||||||
|
@ -47,7 +42,7 @@ public partial class App : Microsoft.UI.Xaml.Application
|
||||||
|
|
||||||
|
|
||||||
public static UIElement? AppTitlebar { get; set; }
|
public static UIElement? AppTitlebar { get; set; }
|
||||||
public static WindowEx MainWindow { get; } = new MainWindow();
|
public static WindowEx? MainWindow;
|
||||||
|
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
|
@ -116,7 +111,6 @@ public partial class App : Microsoft.UI.Xaml.Application
|
||||||
protected async override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
|
protected async override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
|
||||||
{
|
{
|
||||||
base.OnLaunched(args);
|
base.OnLaunched(args);
|
||||||
|
|
||||||
var activatedEventArgs = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs();
|
var activatedEventArgs = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs();
|
||||||
if (activatedEventArgs.Kind == Microsoft.Windows.AppLifecycle.ExtendedActivationKind.File)
|
if (activatedEventArgs.Kind == Microsoft.Windows.AppLifecycle.ExtendedActivationKind.File)
|
||||||
{
|
{
|
||||||
|
@ -158,7 +152,10 @@ public partial class App : Microsoft.UI.Xaml.Application
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//MainWindow.Activate();
|
//MainWindow.Activate();
|
||||||
await App.GetService<IActivationService>().ActivateAsync(args);
|
//MainWindow = new MainWindow();
|
||||||
|
var editor=new Editor.EditorWin();
|
||||||
|
editor.Activate();
|
||||||
|
//await App.GetService<IActivationService>().ActivateAsync(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
24
RustTools/Editor/EditorWin.xaml
Normal file
24
RustTools/Editor/EditorWin.xaml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<windowex:WindowEx
|
||||||
|
x:Class="RustTools.Editor.EditorWin"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="using:RustTools"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:windowex="using:WinUIEx"
|
||||||
|
MinWidth="500"
|
||||||
|
MinHeight="500"
|
||||||
|
mc:Ignorable="d">
|
||||||
|
|
||||||
|
<Grid Name="grid">
|
||||||
|
<Grid Padding="9" Visibility="Visible">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
<ColumnDefinition />
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock Grid.Column="0" Text="这是模组名称" />
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</windowex:WindowEx>
|
99
RustTools/Editor/EditorWin.xaml.cs
Normal file
99
RustTools/Editor/EditorWin.xaml.cs
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Microsoft.UI;
|
||||||
|
using Microsoft.UI.Windowing;
|
||||||
|
using Microsoft.UI.Xaml;
|
||||||
|
using Microsoft.UI.Xaml.Controls;
|
||||||
|
using RustTools.muqing;
|
||||||
|
using Windows.ApplicationModel.Core;
|
||||||
|
using Windows.Foundation;
|
||||||
|
using Windows.UI.Core.Preview;
|
||||||
|
using Windows.UI.Popups;
|
||||||
|
using Windows.UI.WindowManagement;
|
||||||
|
using WinRT.Interop;
|
||||||
|
namespace RustTools.Editor;
|
||||||
|
/// <summary>
|
||||||
|
/// 编辑器主窗口
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class EditorWin : WindowEx
|
||||||
|
{
|
||||||
|
|
||||||
|
private Microsoft.UI.Windowing.AppWindow? app;
|
||||||
|
public EditorWin()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
gj.SetBackTheme(this);
|
||||||
|
ExtendsContentIntoTitleBar = true;
|
||||||
|
var frame = App.AppTitlebar as FrameworkElement;
|
||||||
|
if (frame != null)
|
||||||
|
{
|
||||||
|
gj.UpdateTitleBar(this, frame.ActualTheme);
|
||||||
|
grid.RequestedTheme = frame.ActualTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
//WindowManager.Get(this).IsMinimizable = false;
|
||||||
|
//WindowManager.Get(this).IsMaximizable = false;
|
||||||
|
//WindowManager.Get(this).IsResizable = false;
|
||||||
|
//WindowManager.Get(this).IsAlwaysOnTop = false;
|
||||||
|
//WindowManager.Get(this).IsTitleBarVisible = false;
|
||||||
|
|
||||||
|
|
||||||
|
//app = GetAppWindowForCurrentWindow();
|
||||||
|
//app.Closing += OnClosing;
|
||||||
|
//Closed += EditorWin_Closed;
|
||||||
|
|
||||||
|
Closed += EditorWin_Closed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveDataAsync()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
//用户有没有保存
|
||||||
|
private bool IsSave = false;
|
||||||
|
private ContentDialog? ClosedDialog;
|
||||||
|
private async void EditorWin_Closed(object sender, WindowEventArgs e)
|
||||||
|
{
|
||||||
|
if (IsSave == false)
|
||||||
|
{
|
||||||
|
// 防止窗口关闭
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
if (ClosedDialog != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 显示一个对话框,告知用户窗口不能关闭
|
||||||
|
ClosedDialog = new ContentDialog
|
||||||
|
{
|
||||||
|
XamlRoot = grid.XamlRoot,
|
||||||
|
Title = "警告",
|
||||||
|
Content = "你还有未保存的文件在编译器中。",
|
||||||
|
PrimaryButtonText = "保存关闭",
|
||||||
|
PrimaryButtonStyle = Application.Current.Resources["AccentButtonStyle"] as Style,
|
||||||
|
SecondaryButtonText = "直接关闭",
|
||||||
|
CloseButtonText = "取消"
|
||||||
|
};
|
||||||
|
var result = await ClosedDialog.ShowAsync();
|
||||||
|
if (result == ContentDialogResult.Primary)
|
||||||
|
{
|
||||||
|
IsSave = true;
|
||||||
|
Application.Current.Exit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (result == ContentDialogResult.Secondary)
|
||||||
|
{
|
||||||
|
|
||||||
|
IsSave = true;
|
||||||
|
Application.Current.Exit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ClosedDialog = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Microsoft.UI.Windowing.AppWindow GetAppWindowForCurrentWindow()
|
||||||
|
{
|
||||||
|
var hWnd = WindowNative.GetWindowHandle(this);
|
||||||
|
var myWndId = Win32Interop.GetWindowIdFromWindow(hWnd);
|
||||||
|
return Microsoft.UI.Windowing.AppWindow.GetFromWindowId(myWndId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using RustTools.Helpers;
|
using RustTools.Helpers;
|
||||||
using RustTools.muqing;
|
using RustTools.muqing;
|
||||||
|
using RustTools.WindowUI;
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
using Windows.UI.ViewManagement;
|
using Windows.UI.ViewManagement;
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ public sealed partial class MainWindow : WindowEx
|
||||||
dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
|
dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
|
||||||
settings.ColorValuesChanged += Settings_ColorValuesChanged;
|
settings.ColorValuesChanged += Settings_ColorValuesChanged;
|
||||||
// cannot use FrameworkElement.ActualThemeChanged event
|
// cannot use FrameworkElement.ActualThemeChanged event
|
||||||
|
//var editorWin = new Editor.EditorWin();
|
||||||
}
|
}
|
||||||
|
|
||||||
// this handles updating the caption button colors correctly when indows system theme is changed
|
// this handles updating the caption button colors correctly when indows system theme is changed
|
||||||
|
|
|
@ -31,13 +31,16 @@ public sealed partial class ModuleInfoWin : WindowEx
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ExtendsContentIntoTitleBar = true;
|
ExtendsContentIntoTitleBar = true;
|
||||||
gj.SetBackTheme(this);
|
gj.SetBackTheme(this);
|
||||||
init(v);
|
|
||||||
var frame = App.AppTitlebar as FrameworkElement;
|
var frame = App.AppTitlebar as FrameworkElement;
|
||||||
if (frame != null)
|
if (frame != null)
|
||||||
{
|
{
|
||||||
gj.UpdateTitleBar(this, frame.ActualTheme);
|
gj.UpdateTitleBar(this, frame.ActualTheme);
|
||||||
grid.RequestedTheme = frame.ActualTheme;
|
grid.RequestedTheme = frame.ActualTheme;
|
||||||
}
|
}
|
||||||
|
if (v != string.Empty)
|
||||||
|
{
|
||||||
|
init(v);
|
||||||
|
}
|
||||||
// ÉèÖô°¿Ú±³¾°ÑÕÉ«
|
// ÉèÖô°¿Ú±³¾°ÑÕÉ«
|
||||||
}
|
}
|
||||||
private async void init(string v)
|
private async void init(string v)
|
||||||
|
@ -185,7 +188,6 @@ public sealed partial class ModuleInfoWin : WindowEx
|
||||||
|
|
||||||
private void DownloadDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
|
private void DownloadDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Prevent the dialog from closing
|
// Prevent the dialog from closing
|
||||||
if (args.Result != ContentDialogResult.Secondary)
|
if (args.Result != ContentDialogResult.Secondary)
|
||||||
{
|
{
|
||||||
|
|
|
@ -85,31 +85,6 @@ public class gj
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetBackColor(WindowEx windowEx)
|
|
||||||
{
|
|
||||||
var uISettings = new UISettings();
|
|
||||||
// 获取当前的背景颜色
|
|
||||||
var backgroundColor = uISettings.GetColorValue(UIColorType.Background);
|
|
||||||
|
|
||||||
// 判断主题模式
|
|
||||||
if (backgroundColor == Colors.Black)
|
|
||||||
{
|
|
||||||
// 设置背景色为黑色
|
|
||||||
//uISettings.SetColorValue(UIColorType.Background, Colors.Black);
|
|
||||||
//uISettings.SetColorValue(UIColorType.Foreground, Colors.White);
|
|
||||||
}
|
|
||||||
else if (backgroundColor == Colors.White)
|
|
||||||
{
|
|
||||||
// 设置背景色为白色
|
|
||||||
//uISettings.SetColorValue(UIColorType.Background, Colors.White);
|
|
||||||
//uISettings.SetColorValue(UIColorType.Foreground, Colors.Black);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("Current theme mode is unknown.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private const int WAINACTIVE = 0x00;
|
private const int WAINACTIVE = 0x00;
|
||||||
private const int WAACTIVE = 0x01;
|
private const int WAACTIVE = 0x01;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user