Profile configuration - Implemented hotkeys

Plugin import - Fixed folders causing errors in some ZIP formats
This commit is contained in:
Robert committed 2021-06-13 21:36:47 +02:00
1 parent 6e197d725a
commit a7c7d74e03
16 files changed
+494 -158

No files matched your search

@@ -0,0 +1,20 @@
<UserControl x:Class="Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit.ProfileConfigurationHotkeyView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:ProfileConfigurationHotkeyViewModel}">
<TextBox Style="{StaticResource MaterialDesignFilledTextBox}"
IsReadOnly="True"
IsReadOnlyCaretVisible="True"
Text="{Binding HotkeyDisplay, UpdateSourceTrigger=PropertyChanged}"
VerticalAlignment="Center"
materialDesign:TextFieldAssist.HasClearButton="True"
materialDesign:HintAssist.Hint="{Binding Hint}"
KeyUp="{s:Action TextBoxKeyUp}"/>
</UserControl>
@@ -0,0 +1,84 @@
using System;
using System.Linq;
using System.Windows.Input;
using Artemis.Core;
using Artemis.Core.Services;
using Stylet;
namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
{
public class ProfileConfigurationHotkeyViewModel : Screen
{
private readonly bool _isDisableHotkey;
private readonly ProfileConfiguration _profileConfiguration;
private string _hint;
private string _hotkeyDisplay;
public ProfileConfigurationHotkeyViewModel(ProfileConfiguration profileConfiguration, bool isDisableHotkey)
{
_profileConfiguration = profileConfiguration;
_isDisableHotkey = isDisableHotkey;
UpdateHotkeyDisplay();
}
public ProfileConfigurationHotkey Hotkey => _isDisableHotkey ? _profileConfiguration.DisableHotkey : _profileConfiguration.EnableHotkey;
public string Hint
{
get => _hint;
set => SetAndNotify(ref _hint, value);
}
public string HotkeyDisplay
{
get => _hotkeyDisplay;
set
{
if (!SetAndNotify(ref _hotkeyDisplay, value)) return;
if (value == null && Hotkey != null)
{
Hotkey.Key = null;
Hotkey.Modifiers = null;
}
}
}
public void UpdateHotkeyDisplay()
{
string display = null;
if (Hotkey?.Modifiers != null)
display = string.Join("+", Enum.GetValues<KeyboardModifierKey>().Skip(1).Where(m => Hotkey.Modifiers.Value.HasFlag(m)));
if (Hotkey?.Key != null)
display = string.IsNullOrEmpty(display) ? Hotkey.Key.ToString() : $"{display}+{Hotkey.Key}";
HotkeyDisplay = display;
if (_profileConfiguration.HotkeyMode == ProfileConfigurationHotkeyMode.EnableDisable)
Hint = _isDisableHotkey ? "Disable hotkey" : "Enable hotkey";
else
Hint = "Toggle hotkey";
}
public void TextBoxKeyUp(object sender, KeyEventArgs e)
{
if (e.Key >= Key.LeftShift && e.Key <= Key.RightAlt)
return;
if (_isDisableHotkey)
{
_profileConfiguration.DisableHotkey ??= new ProfileConfigurationHotkey();
_profileConfiguration.DisableHotkey.Key = (KeyboardKey?) e.Key;
_profileConfiguration.DisableHotkey.Modifiers = (KeyboardModifierKey?) Keyboard.Modifiers;
}
else
{
_profileConfiguration.EnableHotkey ??= new ProfileConfigurationHotkey();
_profileConfiguration.EnableHotkey.Key = (KeyboardKey?) e.Key;
_profileConfiguration.EnableHotkey.Modifiers = (KeyboardModifierKey?) Keyboard.Modifiers;
}
e.Handled = true;
UpdateHotkeyDisplay();
}
}
}
@@ -221,16 +221,29 @@
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}">
Keybinds
Hotkeys
</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody2TextBlock}">You may set up keybinds to activate/deactivate the profile</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody2TextBlock}">You may set up hotkeys to activate/deactivate the profile</TextBlock>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Top" Margin="16">
<materialDesign:PackIcon Kind="Crane" Width="100" Height="100" HorizontalAlignment="Center" />
<TextBlock Style="{StaticResource MaterialDesignHeadline6TextBlock}" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="0 20">
Keybinds are not yet implemented
</TextBlock>
</StackPanel>
<ComboBox materialDesign:HintAssist.Hint="Hotkey mode"
Margin="0 6 0 8"
Style="{StaticResource MaterialDesignFilledComboBox}"
SelectedValue="{Binding SelectedHotkeyMode}"
ItemsSource="{Binding HotkeyModes}"
SelectedValuePath="Value"
DisplayMemberPath="Description" />
<ContentControl s:View.Model="{Binding EnableHotkeyViewModel}"
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch"
IsTabStop="False"
Visibility="{Binding ShowEnableHotkey, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"
Margin="0 0 0 8"/>
<ContentControl s:View.Model="{Binding DisableHotkeyViewModel}"
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch"
IsTabStop="False"
Visibility="{Binding ShowDisableHotkey, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"/>
</StackPanel>
</Grid>
@@ -48,17 +48,23 @@ namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
_modules = ProfileConfiguration.Module != null ? new List<Module> {ProfileConfiguration.Module} : new List<Module>();
IconTypes = new BindableCollection<ValueDescription>(EnumUtilities.GetAllValuesAndDescriptions(typeof(ProfileConfigurationIconType)));
HotkeyModes = new BindableCollection<ValueDescription>(EnumUtilities.GetAllValuesAndDescriptions(typeof(ProfileConfigurationHotkeyMode)));
Icons = new BindableCollection<ProfileIconViewModel>();
Modules = new BindableCollection<ProfileModuleViewModel>(
pluginManagementService.GetFeaturesOfType<Module>().Where(m => !m.IsAlwaysAvailable).Select(m => new ProfileModuleViewModel(m))
);
Initializing = true;
ActivationConditionViewModel = dataModelConditionsVmFactory.DataModelConditionGroupViewModel(_dataModelConditionGroup, ConditionGroupType.General, _modules);
ActivationConditionViewModel.ConductWith(this);
ActivationConditionViewModel.IsRootGroup = true;
ModuleActivationRequirementsViewModel = new ModuleActivationRequirementsViewModel(sidebarVmFactory);
ModuleActivationRequirementsViewModel.ConductWith(this);
ModuleActivationRequirementsViewModel.SetModule(ProfileConfiguration.Module);
EnableHotkeyViewModel = sidebarVmFactory.ProfileConfigurationHotkeyViewModel(ProfileConfiguration, false);
EnableHotkeyViewModel.ConductWith(this);
DisableHotkeyViewModel = sidebarVmFactory.ProfileConfigurationHotkeyViewModel(ProfileConfiguration, true);
DisableHotkeyViewModel.ConductWith(this);
_profileName = ProfileConfiguration.Name;
_selectedModule = Modules.FirstOrDefault(m => m.Module == ProfileConfiguration.Module);
@@ -79,9 +85,15 @@ namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
});
}
public ProfileConfiguration ProfileConfiguration { get; }
public DataModelConditionGroupViewModel ActivationConditionViewModel { get; }
public ModuleActivationRequirementsViewModel ModuleActivationRequirementsViewModel { get; }
public ProfileConfigurationHotkeyViewModel EnableHotkeyViewModel { get; }
public ProfileConfigurationHotkeyViewModel DisableHotkeyViewModel { get; }
public bool IsNew { get; }
public ProfileConfiguration ProfileConfiguration { get; }
public BindableCollection<ValueDescription> IconTypes { get; }
public BindableCollection<ValueDescription> HotkeyModes { get; }
public BindableCollection<ProfileIconViewModel> Icons { get; }
public BindableCollection<ProfileModuleViewModel> Modules { get; }
public bool HasUsableModules => Modules.Any();
@@ -108,6 +120,24 @@ namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
}
}
public ProfileConfigurationHotkeyMode SelectedHotkeyMode
{
get => ProfileConfiguration.HotkeyMode;
set
{
ProfileConfiguration.HotkeyMode = value;
NotifyOfPropertyChange(nameof(SelectedHotkeyMode));
NotifyOfPropertyChange(nameof(ShowEnableHotkey));
NotifyOfPropertyChange(nameof(ShowDisableHotkey));
EnableHotkeyViewModel.UpdateHotkeyDisplay();
DisableHotkeyViewModel.UpdateHotkeyDisplay();
}
}
public bool ShowEnableHotkey => ProfileConfiguration.HotkeyMode != ProfileConfigurationHotkeyMode.None;
public bool ShowDisableHotkey => ProfileConfiguration.HotkeyMode == ProfileConfigurationHotkeyMode.EnableDisable;
public Stream SelectedImage
{
get => _selectedImage;
@@ -135,9 +165,6 @@ namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
}
}
public DataModelConditionGroupViewModel ActivationConditionViewModel { get; }
public ModuleActivationRequirementsViewModel ModuleActivationRequirementsViewModel { get; }
public void Delete()
{
Session.Close(nameof(Delete));
@@ -202,6 +229,22 @@ namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
_changedImage = true;
SelectedImage = File.OpenRead(dialog.FileName);
}
#region Overrides of Screen
protected override void OnInitialActivate()
{
_profileService.HotkeysEnabled = false;
base.OnInitialActivate();
}
protected override void OnClose()
{
_profileService.HotkeysEnabled = true;
base.OnClose();
}
#endregion
}
public class ProfileEditViewModelValidator : AbstractValidator<ProfileEditViewModel>
@@ -200,13 +200,16 @@ namespace Artemis.UI.Screens.Sidebar
private void ProfileCategoryOnProfileConfigurationAdded(object sender, ProfileConfigurationEventArgs e)
{
if (!_addingProfile && ShowItems)
Execute.PostToUIThread(() =>
{
Items.Add(_vmFactory.SidebarProfileConfigurationViewModel(e.ProfileConfiguration));
((BindableCollection<SidebarProfileConfigurationViewModel>) Items).Sort(p => p.ProfileConfiguration.Order);
}
if (!_addingProfile && ShowItems)
{
Items.Add(_vmFactory.SidebarProfileConfigurationViewModel(e.ProfileConfiguration));
((BindableCollection<SidebarProfileConfigurationViewModel>)Items).Sort(p => p.ProfileConfiguration.Order);
}
SelectedProfileConfiguration = Items.FirstOrDefault(i => i.ProfileConfiguration.IsBeingEdited);
SelectedProfileConfiguration = Items.FirstOrDefault(i => i.ProfileConfiguration.IsBeingEdited);
});
}
#region Overrides of Screen