143 lines
5.3 KiB
C#
143 lines
5.3 KiB
C#
|
||
using Microsoft.UI.Xaml;
|
||
using Microsoft.UI.Xaml.Controls;
|
||
using RustTools.muqing;
|
||
using RustTools.ViewModels;
|
||
using Windows.Storage.Pickers;
|
||
|
||
namespace RustTools.Views;
|
||
|
||
// TODO: Set the URL for your privacy policy by updating SettingsPage_PrivacyTermsLink.NavigateUri in Resources.resw.
|
||
public sealed partial class SettingsPage : Page
|
||
{
|
||
public SettingsViewModel ViewModel
|
||
{
|
||
get;
|
||
}
|
||
public enum SystemBackdropEmnu
|
||
{
|
||
None,
|
||
}
|
||
|
||
public SettingsPage()
|
||
{
|
||
//this.windowEx = windowEx;
|
||
ViewModel = App.GetService<SettingsViewModel>();
|
||
InitializeComponent();
|
||
|
||
//BackgroundRadioButtons
|
||
var iniHelper = new IniHelper();
|
||
iniHelper.Load(IniHelper.FILE.Config);
|
||
var v = iniHelper.GetValue(IniHelper.CODE.Settings, IniHelper.KEY.SystemBackdrop);
|
||
switch (v)
|
||
{
|
||
case "None":
|
||
BackgroundRadioButtons.SelectedIndex = 0;
|
||
break;
|
||
case "Blur":
|
||
BackgroundRadioButtons.SelectedIndex = 1;
|
||
break;
|
||
case "AcrylicBlur":
|
||
BackgroundRadioButtons.SelectedIndex = 2;
|
||
break;
|
||
case "Mica":
|
||
BackgroundRadioButtons.SelectedIndex = 3;
|
||
break;
|
||
}
|
||
BackgroundRadioButtons.SelectionChanged += BackgroundColor_SelectionChanged;
|
||
ModFileUrlText.Text = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl);
|
||
MapsFileUrlText.Text = iniHelper.GetValue(IniHelper.CODE.Rust,IniHelper.KEY.MapsFileUrl);
|
||
}
|
||
private bool Backone = false;
|
||
private void BackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||
{
|
||
if (Backone)
|
||
{
|
||
if (App.MainWindow != null && sender is RadioButtons rb)
|
||
{
|
||
var colorName = rb.SelectedItem as string;
|
||
var iniHelper = new IniHelper();
|
||
iniHelper.Load(IniHelper.FILE.Config);
|
||
#pragma warning disable CS8604 // 引用类型参数可能为 null。
|
||
iniHelper.SetValue(IniHelper.CODE.Settings, IniHelper.KEY.SystemBackdrop, colorName);
|
||
iniHelper.Save();
|
||
gj.SetBackTheme(App.MainWindow);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Backone = true;
|
||
}
|
||
}
|
||
|
||
private async void AutoSuggestBox_Url(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
|
||
{
|
||
var dialog = new ContentDialog
|
||
{
|
||
XamlRoot = XamlRoot,
|
||
//dialog.Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style;
|
||
Title = "选择搜索模式",
|
||
SecondaryButtonText = "手动选择",
|
||
PrimaryButtonText = "自动搜索",
|
||
Content = "手动选择请找到Rusted Warfare文件目录软件会自动给你填写mod和maps路径," +
|
||
"自动搜索直到找到 Rusted Warfare 文件夹为止 途中可选择中断。"
|
||
};
|
||
//dialog.DefaultButton = ContentDialogButton.Primary;
|
||
dialog.SecondaryButtonClick += Dialog_SecondaryButtonClick;
|
||
dialog.PrimaryButtonClick += Dialog_PrimaryButtonClick;
|
||
await dialog.ShowAsync();
|
||
|
||
}
|
||
private void Dialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args){
|
||
var mod = new Mod();
|
||
ModFileUrlText.Text =mod.getUnitsDir();
|
||
MapsFileUrlText.Text =mod.getMaps();
|
||
SaveModAndMaps();
|
||
}
|
||
|
||
private async void Dialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args){
|
||
var openPicker = new FolderPicker();
|
||
var window = App.MainWindow;
|
||
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
|
||
WinRT.Interop.InitializeWithWindow.Initialize(openPicker, hWnd);
|
||
openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
|
||
openPicker.FileTypeFilter.Add("*");
|
||
var folder = await openPicker.PickSingleFolderAsync();
|
||
if (folder != null)
|
||
{
|
||
//StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
|
||
var a = Path.Combine(folder.Path, "mods\\units");
|
||
ModFileUrlText.Text = a;
|
||
var b = Path.Combine(folder.Path, "mods\\maps");
|
||
MapsFileUrlText.Text = b;
|
||
SaveModAndMaps();
|
||
}
|
||
}
|
||
|
||
private void SaveModAndMaps()
|
||
{
|
||
var iniHelper = new IniHelper();
|
||
iniHelper.Load(IniHelper.FILE.Config);
|
||
iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.MapsFileUrl, MapsFileUrlText.Text);
|
||
iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl, ModFileUrlText.Text);
|
||
iniHelper.Save();
|
||
}
|
||
|
||
private void ModFileUrlText_LostFocus(object sender, RoutedEventArgs e)
|
||
{
|
||
var a=(AutoSuggestBox) sender;
|
||
var iniHelper = new IniHelper();
|
||
iniHelper.Load(IniHelper.FILE.Config);
|
||
if (a.Name.Equals("MapsFileUrlText"))
|
||
{
|
||
iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.MapsFileUrl, MapsFileUrlText.Text);
|
||
}
|
||
else if(a.Name.Equals("ModFileUrlText"))
|
||
{
|
||
iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl, ModFileUrlText.Text);
|
||
}
|
||
// 获取 AutoSuggestBox 的当前文本
|
||
iniHelper.Save();
|
||
}
|
||
}
|