add: 添加从注册表中读取按键的功能(待完善:星之归还、隐藏UI按键无法获取;拾取按键、派蒙菜单按键可能存在错误)

This commit is contained in:
Ayu0K
2025-01-04 12:42:32 +08:00
parent 317a526f16
commit accd0280bb
3 changed files with 207 additions and 6 deletions

View File

@@ -107,7 +107,7 @@ namespace BetterGenshinImpact.Core.Config
/// 特定玩法内交互操作
/// </summary>
[ObservableProperty]
private VK _interaction = VK.VK_T;
private VK _interactionInSomeMode = VK.VK_T;
/// <summary>
/// 开启任务追踪
@@ -291,7 +291,7 @@ namespace BetterGenshinImpact.Core.Config
/// 隐藏主界面
/// </summary>
[ObservableProperty]
private VK _hideUI = VK.VK_DIVIDE;
private VK _hideUI = VK.VK_OEM_2;
#endregion

View File

@@ -32,11 +32,11 @@
<ui:TextBlock Grid.Row="1"
Margin="0,0,0,8"
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
Text="此处的按键绑定设置对除自动拾取外的功能有效。"
Text="此处的按键绑定设置对除自动拾取外的功能有效。请手动设置拾取按键、星之归还按键、隐藏主界面按键。"
TextWrapping="Wrap" />
<StackPanel Grid.Row="2" Orientation="Horizontal" Margin="0,0,0,8">
<ui:Button Command="{Binding OpenScriptsFolderCommand}"
<ui:Button Command="{Binding FetchFromRegistryCommand}"
Content="从注册表读取"
Icon="{ui:SymbolIcon Notepad32}" />
</StackPanel>

View File

@@ -11,6 +11,9 @@ using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Text;
using Wpf.Ui.Controls;
using BetterGenshinImpact.Genshin.Settings;
using CommunityToolkit.Mvvm.Input;
using static Vanara.PInvoke.User32;
namespace BetterGenshinImpact.ViewModel.Pages;
@@ -195,8 +198,8 @@ public partial class KeyBindingsSettingsPageViewModel : ObservableObject, INavig
));
actionDirectory.Children.Add(new KeyBindingSettingModel(
"特定玩法内交互操作",
nameof(_config.Interaction),
_config.Interaction
nameof(_config.InteractionInSomeMode),
_config.InteractionInSomeMode
));
actionDirectory.Children.Add(new KeyBindingSettingModel(
"开启任务追踪",
@@ -355,4 +358,202 @@ public partial class KeyBindingsSettingsPageViewModel : ObservableObject, INavig
KeyBindingSettingModels.Add(menuDirectory);
}
/// <summary>
/// 从注册表中读取按键
/// </summary>
[RelayCommand]
private void FetchFromRegistry()
{
// 读取注册表
SettingsContainer settings = new();
settings.FromReg();
var keySetting = settings.OverrideController?.KeyboardMap?.ActionElementMap;
if (keySetting != null)
{
foreach (var item in keySetting)
{
if (item.ElementIdentifierId is ElementIdentifierId keyId)
{
// 跳过无法识别的按键
if (keyId.ToName() == "Unknown" || keyId.ToName() == "None")
{
continue;
}
var key = keyId.ToVK();
switch (item.ActionId)
{
case ActionId.MoveForwardShow:
_config.MoveForward = key;
break;
case ActionId.MoveBackShow:
_config.MoveBackward = key;
break;
case ActionId.MoveLeftShow:
_config.MoveLeft = key;
break;
case ActionId.MoveRightShow:
_config.MoveRight = key;
break;
case ActionId.WalkRun:
_config.SwitchToWalkOrRun = key;
break;
case ActionId.Attack:
_config.NormalAttack = key;
break;
case ActionId.ElementalSkill:
_config.ElementalSkill = key;
break;
case ActionId.ElementalBurst:
_config.ElementalBurst = key;
break;
case ActionId.Sprint:
if (key >= VK.VK_LBUTTON && key <= VK.VK_XBUTTON2)
{
_config.SprintMouse = key;
}
else
{
_config.SprintKeyboard = key;
}
break;
case ActionId.AimMode:
_config.SwitchAimingMode = key;
break;
case ActionId.Jump:
_config.Jump = key;
break;
case ActionId.CancelClimb:
_config.Drop = key;
break;
// TODO: 拾取&交互可能不正确
case ActionId.UseTalk:
_config.PickUpOrInteract = key;
break;
case ActionId.Gadget:
_config.QuickUseGadget = key;
break;
case ActionId.InteractionSomeModes:
_config.InteractionInSomeMode = key;
break;
case ActionId.Navigation:
_config.QuestNavigation = key;
break;
case ActionId.AbandonChallenge:
_config.AbandonChallenge = key;
break;
case ActionId.Char1:
_config.SwitchMember1 = key;
break;
case ActionId.Char2:
_config.SwitchMember2 = key;
break;
case ActionId.Char3:
_config.SwitchMember3 = key;
break;
case ActionId.Char4:
_config.SwitchMember4 = key;
break;
case ActionId.Char5:
_config.SwitchMember5 = key;
break;
case ActionId.QuickWheel:
_config.ShortcutWheel = key;
break;
case ActionId.Inventory:
_config.OpenInventory = key;
break;
case ActionId.CharacterList:
_config.OpenCharacterScreen = key;
break;
case ActionId.Map:
_config.OpenMap = key;
break;
// TODO: 派蒙界面可能不正确
case ActionId.MenuGamepad:
_config.OpenPaimonMenu = key;
break;
case ActionId.AdventurerHandbook:
_config.OpenAdventurerHandbook = key;
break;
case ActionId.CoOp:
_config.OpenCoOpScreen = key;
break;
case ActionId.Wish:
_config.OpenWishScreen = key;
break;
case ActionId.BattlePass:
_config.OpenBattlePassScreen = key;
break;
case ActionId.Events:
_config.OpenTheEventsMenu = key;
break;
case ActionId.PotTasks:
_config.OpenTheSettingsMenu = key;
break;
case ActionId.PotEdit:
_config.OpenTheFurnishingScreen = key;
break;
// TODO: 星之归还未找到
case ActionId.QuestList:
_config.OpenQuestMenu = key;
break;
case ActionId.NotificationDetails:
_config.OpenNotificationDetails = key;
break;
case ActionId.Chat:
_config.OpenChatScreen = key;
break;
case ActionId.EnvironmentInfo:
_config.OpenSpecialEnvironmentInformation = key;
break;
case ActionId.Tutorial:
_config.CheckTutorialDetails = key;
break;
case ActionId.ElementalSight:
_config.ElementalSight = key;
break;
case ActionId.ShowCursor:
_config.ShowCursor = key;
break;
case ActionId.PartySetup:
_config.OpenPartySetupScreen = key;
break;
case ActionId.Friends:
_config.OpenFriendsScreen = key;
break;
// TODO: 隐藏主界面未找到
default:
break;
}
}
}
// 重新加载按键绑定列表
KeyBindingSettingModels.Clear();
BuildKeyBindingsList();
var list = GetAllNonDirectoryKeyBinding(KeyBindingSettingModels);
foreach (var keyConfig in list)
{
keyConfig.PropertyChanged += (sender, e) =>
{
if (sender is KeyBindingSettingModel model)
{
// 使用反射更新配置文件
if (e.PropertyName == nameof(model.KeyValue))
{
Debug.WriteLine($"按键绑定 \"{model.ActionName}\" 变更为 {model.KeyValue}");
var pi = _config.GetType().GetProperty(model.ConfigPropertyName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
if (pi != null && pi.CanWrite)
{
pi.SetValue(_config, model.KeyValue, null);
}
}
}
};
}
}
}
}