mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-21 09:45:48 +08:00
add common settings
This commit is contained in:
@@ -9,7 +9,10 @@ using CommunityToolkit.Mvvm.Messaging;
|
||||
using CommunityToolkit.Mvvm.Messaging.Messages;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel
|
||||
{
|
||||
@@ -19,9 +22,11 @@ namespace BetterGenshinImpact.ViewModel
|
||||
|
||||
[ObservableProperty] private ObservableCollection<MaskButton> _maskButtons = new();
|
||||
|
||||
public AllConfig Config { get; set; }
|
||||
public AllConfig? Config { get; set; }
|
||||
|
||||
[ObservableProperty] private Visibility _logTextBoxVisibility = Visibility.Visible;
|
||||
[ObservableProperty] private Visibility _uidCoverVisibility = Visibility.Visible;
|
||||
[ObservableProperty] private Rect _uidCoverRect = new(0, 0, 200, 30);
|
||||
|
||||
public MaskWindowViewModel()
|
||||
{
|
||||
@@ -55,18 +60,54 @@ namespace BetterGenshinImpact.ViewModel
|
||||
{
|
||||
UIDispatcherHelper.Invoke(() => { _maskButtons.Clear(); });
|
||||
}
|
||||
else if (msg.PropertyName == "RefreshSettings")
|
||||
{
|
||||
UIDispatcherHelper.Invoke(RefreshSettings);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OnLoaded()
|
||||
{
|
||||
// 这个窗口比较特殊,无法直接使用构造函数依赖注入
|
||||
var configService = App.GetService<IConfigService>();
|
||||
if (configService != null)
|
||||
RefreshSettings();
|
||||
}
|
||||
|
||||
private void RefreshSettings()
|
||||
{
|
||||
InitConfig();
|
||||
if (Config != null)
|
||||
{
|
||||
Config = configService.Get();
|
||||
LogTextBoxVisibility = Config.MaskWindowConfig.ShowLogBox ? Visibility.Visible: Visibility.Collapsed;
|
||||
// 日志窗口
|
||||
LogTextBoxVisibility = Config.MaskWindowConfig.ShowLogBox ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
// UID遮盖
|
||||
UidCoverVisibility = Config.MaskWindowConfig.UidCoverEnabled ? Visibility.Visible : Visibility.Collapsed;
|
||||
// 比较特殊,必须要启动过任务调度器才能够获取到缩放信息
|
||||
if (TaskContext.Instance().SystemInfo != null)
|
||||
{
|
||||
var assetScale = TaskContext.Instance().SystemInfo.AssetScale;
|
||||
var dpiScale = TaskContext.Instance().DpiScale;
|
||||
UidCoverRect = new Rect(Config.MaskWindowConfig.UidCoverRect.X * assetScale / dpiScale,
|
||||
Config.MaskWindowConfig.UidCoverRect.Y * assetScale / dpiScale,
|
||||
Config.MaskWindowConfig.UidCoverRect.Width * assetScale / dpiScale,
|
||||
Config.MaskWindowConfig.UidCoverRect.Height * assetScale / dpiScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 这个窗口比较特殊,无法直接使用构造函数依赖注入
|
||||
/// </summary>
|
||||
private void InitConfig()
|
||||
{
|
||||
if (Config == null)
|
||||
{
|
||||
var configService = App.GetService<IConfigService>();
|
||||
if (configService != null)
|
||||
{
|
||||
Config = configService.Get();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user