1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Merge branch 'development'

This commit is contained in:
Robert 2021-06-13 21:50:02 +02:00
commit b8f562f941
19 changed files with 502 additions and 165 deletions

View File

@ -203,45 +203,4 @@ namespace Artemis.Core
/// </summary>
General
}
/// <summary>
/// Represents a type of behaviour when this profile is activated
/// </summary>
public enum ActivationBehaviour
{
/// <summary>
/// Do nothing to other profiles
/// </summary>
None,
/// <summary>
/// Disable all other profiles
/// </summary>
DisableOthers,
/// <summary>
/// Disable all other profiles below this one
/// </summary>
DisableOthersBelow,
/// <summary>
/// Disable all other profiles above this one
/// </summary>
DisableOthersAbove,
/// <summary>
/// Disable all other profiles in the same category
/// </summary>
DisableOthersInCategory,
/// <summary>
/// Disable all other profiles below this one in the same category
/// </summary>
DisableOthersBelowInCategory,
/// <summary>
/// Disable all other profiles above this one in the same category
/// </summary>
DisableOthersAboveInCategory
}
}

View File

@ -92,6 +92,21 @@ namespace Artemis.Core
/// </summary>
public ProfileConfigurationIcon Icon { get; }
/// <summary>
/// Gets or sets the <see cref="ProfileConfigurationHotkeyMode" /> used to determine hotkey behaviour
/// </summary>
public ProfileConfigurationHotkeyMode HotkeyMode { get; set; }
/// <summary>
/// Gets or sets the hotkey used to enable or toggle the profile
/// </summary>
public ProfileConfigurationHotkey? EnableHotkey { get; set; }
/// <summary>
/// Gets or sets the hotkey used to disable the profile
/// </summary>
public ProfileConfigurationHotkey? DisableHotkey { get; set; }
/// <summary>
/// Gets the profile of this profile configuration
/// </summary>
@ -151,6 +166,10 @@ namespace Artemis.Core
ActivationConditionMet = ActivationCondition == null || ActivationCondition.Evaluate();
}
/// <summary>
/// Determines whether the profile of this configuration should be active
/// </summary>
/// <param name="includeActivationCondition">Whether or not to take activation conditions into consideration</param>
public bool ShouldBeActive(bool includeActivationCondition)
{
if (_disposed)
@ -201,13 +220,15 @@ namespace Artemis.Core
Name = Entity.Name;
IsSuspended = Entity.IsSuspended;
ActivationBehaviour = (ActivationBehaviour) Entity.ActivationBehaviour;
HotkeyMode = (ProfileConfigurationHotkeyMode) Entity.HotkeyMode;
Order = Entity.Order;
Icon.Load();
ActivationCondition = Entity.ActivationCondition != null
? new DataModelConditionGroup(null, Entity.ActivationCondition)
: null;
ActivationCondition = Entity.ActivationCondition != null ? new DataModelConditionGroup(null, Entity.ActivationCondition) : null;
EnableHotkey = Entity.EnableHotkey != null ? new ProfileConfigurationHotkey(Entity.EnableHotkey) : null;
DisableHotkey = Entity.DisableHotkey != null ? new ProfileConfigurationHotkey(Entity.DisableHotkey) : null;
}
/// <inheritdoc />
@ -219,18 +240,19 @@ namespace Artemis.Core
Entity.Name = Name;
Entity.IsSuspended = IsSuspended;
Entity.ActivationBehaviour = (int) ActivationBehaviour;
Entity.HotkeyMode = (int) HotkeyMode;
Entity.ProfileCategoryId = Category.Entity.Id;
Entity.Order = Order;
Icon.Save();
if (ActivationCondition != null)
{
ActivationCondition.Save();
Entity.ActivationCondition = ActivationCondition.Entity;
}
else
Entity.ActivationCondition = null;
ActivationCondition?.Save();
Entity.ActivationCondition = ActivationCondition?.Entity;
EnableHotkey?.Save();
Entity.EnableHotkey = EnableHotkey?.Entity;
DisableHotkey?.Save();
Entity.DisableHotkey = DisableHotkey?.Entity;
if (!IsMissingModule)
Entity.ModuleId = Module?.Id;
@ -238,4 +260,66 @@ namespace Artemis.Core
#endregion
}
/// <summary>
/// Represents a type of behaviour when this profile is activated
/// </summary>
public enum ActivationBehaviour
{
/// <summary>
/// Do nothing to other profiles
/// </summary>
None,
/// <summary>
/// Disable all other profiles
/// </summary>
DisableOthers,
/// <summary>
/// Disable all other profiles below this one
/// </summary>
DisableOthersBelow,
/// <summary>
/// Disable all other profiles above this one
/// </summary>
DisableOthersAbove,
/// <summary>
/// Disable all other profiles in the same category
/// </summary>
DisableOthersInCategory,
/// <summary>
/// Disable all other profiles below this one in the same category
/// </summary>
DisableOthersBelowInCategory,
/// <summary>
/// Disable all other profiles above this one in the same category
/// </summary>
DisableOthersAboveInCategory
}
/// <summary>
/// Represents a hotkey mode for a profile configuration
/// </summary>
public enum ProfileConfigurationHotkeyMode
{
/// <summary>
/// Use no hotkeys
/// </summary>
None,
/// <summary>
/// Toggle the profile with one hotkey
/// </summary>
Toggle,
/// <summary>
/// Enable and disable the profile with two separate hotkeys
/// </summary>
EnableDisable
}
}

View File

@ -0,0 +1,65 @@
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core
{
/// <summary>
/// Represents a key or combination of keys that changes the suspension status of a <see cref="ProfileConfiguration"/>
/// </summary>
public class ProfileConfigurationHotkey : CorePropertyChanged, IStorageModel
{
/// <summary>
/// Creates a new instance of <see cref="ProfileConfigurationHotkey" />
/// </summary>
public ProfileConfigurationHotkey()
{
Entity = new ProfileConfigurationHotkeyEntity();
}
internal ProfileConfigurationHotkey(ProfileConfigurationHotkeyEntity entity)
{
Entity = entity;
Load();
}
internal ProfileConfigurationHotkeyEntity Entity { get; }
/// <summary>
/// Gets or sets the <see cref="KeyboardKey" /> of the hotkey
/// </summary>
public KeyboardKey? Key { get; set; }
/// <summary>
/// Gets or sets the <see cref="KeyboardModifierKey" />s of the hotkey
/// </summary>
public KeyboardModifierKey? Modifiers { get; set; }
/// <summary>
/// Determines whether the provided <see cref="ArtemisKeyboardKeyEventArgs" /> match the hotkey
/// </summary>
/// <returns><see langword="true" /> if the event args match the hotkey; otherwise <see langword="false" /></returns>
public bool MatchesEventArgs(ArtemisKeyboardKeyEventArgs eventArgs)
{
return eventArgs.Key == Key && eventArgs.Modifiers == Modifiers;
}
#region Implementation of IStorageModel
/// <inheritdoc />
public void Load()
{
Key = (KeyboardKey?) Entity.Key;
Modifiers = (KeyboardModifierKey?) Entity.Modifiers;
}
/// <inheritdoc />
public void Save()
{
Entity.Key = (int?) Key;
Entity.Modifiers = (int?) Modifiers;
}
#endregion
}
}

View File

@ -57,6 +57,7 @@ namespace Artemis.Core.Modules
/// <summary>
/// Gets a read-only list of <see cref="DataModelPath" />s targeting this data model
/// </summary>
[DataModelIgnore]
public ReadOnlyCollection<DataModelPath> ActivePaths => _activePaths.AsReadOnly();
/// <summary>

View File

@ -537,15 +537,13 @@ namespace Artemis.Core.Services
string metaDataDirectory = metaDataFileEntry.FullName.Replace(metaDataFileEntry.Name, "");
foreach (ZipArchiveEntry zipArchiveEntry in archive.Entries)
{
if (zipArchiveEntry.FullName.StartsWith(metaDataDirectory))
if (zipArchiveEntry.FullName.StartsWith(metaDataDirectory) && !zipArchiveEntry.FullName.EndsWith("/"))
{
string target = Path.Combine(directoryInfo.FullName, zipArchiveEntry.FullName.Remove(0, metaDataDirectory.Length));
// Create folders
if (zipArchiveEntry.FullName.EndsWith("/"))
Utilities.CreateAccessibleDirectory(Path.GetDirectoryName(target)!);
Utilities.CreateAccessibleDirectory(Path.GetDirectoryName(target)!);
// Extract files
else
zipArchiveEntry.ExtractToFile(target);
zipArchiveEntry.ExtractToFile(target);
}
}

View File

@ -386,6 +386,10 @@ namespace Artemis.Core.Services
private void ReloadDevice(ArtemisDevice device)
{
// Any pending changes are otherwise lost including DisableDefaultLayout
device.ApplyToEntity();
_deviceRepository.Save(device.DeviceEntity);
DeviceProvider deviceProvider = device.DeviceProvider;
// Feels bad but need to in order to get the initial LEDs back

View File

@ -10,14 +10,14 @@ namespace Artemis.Core.Services
public interface IProfileService : IArtemisService
{
/// <summary>
/// Gets the JSON serializer settings used to create profile mementos
/// Gets the JSON serializer settings used to create profile mementos
/// </summary>
public static JsonSerializerSettings MementoSettings { get; } = new() {TypeNameHandling = TypeNameHandling.All};
/// <summary>
/// Gets the JSON serializer settings used to import/export profiles
/// Gets the JSON serializer settings used to import/export profiles
/// </summary>
public static JsonSerializerSettings ExportSettings { get; } = new() {TypeNameHandling = TypeNameHandling.All, Formatting = Formatting.Indented};
public static JsonSerializerSettings ExportSettings { get; } = new() {TypeNameHandling = TypeNameHandling.All, Formatting = Formatting.Indented};
/// <summary>
/// Gets a read only collection containing all the profile categories
@ -29,6 +29,11 @@ namespace Artemis.Core.Services
/// </summary>
ReadOnlyCollection<ProfileConfiguration> ProfileConfigurations { get; }
/// <summary>
/// Gets or sets a boolean indicating whether hotkeys are enabled
/// </summary>
bool HotkeysEnabled { get; set; }
/// <summary>
/// Gets or sets a boolean indicating whether rendering should only be done for profiles being edited
/// </summary>
@ -128,10 +133,14 @@ namespace Artemis.Core.Services
/// <param name="category">The <see cref="ProfileCategory" /> in which to import the profile</param>
/// <param name="exportModel">The model containing the profile to import</param>
/// <param name="makeUnique">Whether or not to give the profile a new GUID, making it unique</param>
/// <param name="markAsFreshImport">Whether or not to mark the profile as a fresh import, causing it to be adapted until any changes are made to it</param>
/// <param name="markAsFreshImport">
/// Whether or not to mark the profile as a fresh import, causing it to be adapted until
/// any changes are made to it
/// </param>
/// <param name="nameAffix">Text to add after the name of the profile (separated by a dash)</param>
/// <returns>The resulting profile configuration</returns>
ProfileConfiguration ImportProfile(ProfileCategory category, ProfileConfigurationExportModel exportModel, bool makeUnique = true, bool markAsFreshImport = true, string? nameAffix = "imported");
ProfileConfiguration ImportProfile(ProfileCategory category, ProfileConfigurationExportModel exportModel, bool makeUnique = true, bool markAsFreshImport = true,
string? nameAffix = "imported");
/// <summary>
/// Adapts a given profile to the currently active devices

View File

@ -15,16 +15,17 @@ namespace Artemis.Core.Services
internal class ProfileService : IProfileService
{
private readonly ILogger _logger;
private readonly List<ArtemisKeyboardKeyEventArgs> _pendingKeyboardEvents = new();
private readonly IPluginManagementService _pluginManagementService;
private readonly List<ProfileCategory> _profileCategories;
private readonly IProfileCategoryRepository _profileCategoryRepository;
private readonly IProfileRepository _profileRepository;
private readonly IRgbService _rgbService;
private readonly List<Exception> _updateExceptions = new();
private DateTime _lastUpdateExceptionLog;
private readonly List<Exception> _renderExceptions = new();
private readonly IRgbService _rgbService;
private readonly List<Exception> _updateExceptions = new();
private DateTime _lastRenderExceptionLog;
private DateTime _lastUpdateExceptionLog;
public ProfileService(ILogger logger,
IRgbService rgbService,
@ -33,6 +34,7 @@ namespace Artemis.Core.Services
IDataBindingService dataBindingService,
IProfileCategoryRepository profileCategoryRepository,
IPluginManagementService pluginManagementService,
IInputService inputService,
IProfileRepository profileRepository)
{
_logger = logger;
@ -46,10 +48,23 @@ namespace Artemis.Core.Services
_pluginManagementService.PluginFeatureEnabled += PluginManagementServiceOnPluginFeatureToggled;
_pluginManagementService.PluginFeatureDisabled += PluginManagementServiceOnPluginFeatureToggled;
inputService.KeyboardKeyUp += InputServiceOnKeyboardKeyUp;
if (!_profileCategories.Any())
CreateDefaultProfileCategories();
}
private void InputServiceOnKeyboardKeyUp(object? sender, ArtemisKeyboardKeyEventArgs e)
{
if (!HotkeysEnabled)
return;
lock (_profileCategories)
{
_pendingKeyboardEvents.Add(e);
}
}
/// <summary>
/// Populates all missing LEDs on all currently active profiles
/// </summary>
@ -88,84 +103,25 @@ namespace Artemis.Core.Services
UpdateModules();
}
public bool RenderForEditor { get; set; }
public void UpdateProfiles(double deltaTime)
private void ProcessPendingKeyEvents(ProfileConfiguration profileConfiguration)
{
lock (_profileCategories)
if (profileConfiguration.HotkeyMode == ProfileConfigurationHotkeyMode.None)
return;
foreach (ArtemisKeyboardKeyEventArgs e in _pendingKeyboardEvents)
{
// Iterate the children in reverse because the first category must be rendered last to end up on top
for (int i = _profileCategories.Count - 1; i > -1; i--)
if (profileConfiguration.HotkeyMode == ProfileConfigurationHotkeyMode.Toggle)
{
ProfileCategory profileCategory = _profileCategories[i];
for (int j = profileCategory.ProfileConfigurations.Count - 1; j > -1; j--)
{
ProfileConfiguration profileConfiguration = profileCategory.ProfileConfigurations[j];
// Profiles being edited are updated at their own leisure
if (profileConfiguration.IsBeingEdited)
continue;
bool shouldBeActive = profileConfiguration.ShouldBeActive(false);
if (shouldBeActive)
{
profileConfiguration.Update();
shouldBeActive = profileConfiguration.ActivationConditionMet;
}
try
{
// Make sure the profile is active or inactive according to the parameters above
if (shouldBeActive && profileConfiguration.Profile == null)
ActivateProfile(profileConfiguration);
else if (!shouldBeActive && profileConfiguration.Profile != null)
DeactivateProfile(profileConfiguration);
profileConfiguration.Profile?.Update(deltaTime);
}
catch (Exception e)
{
_updateExceptions.Add(e);
}
}
if (profileConfiguration.EnableHotkey != null && profileConfiguration.EnableHotkey.MatchesEventArgs(e))
profileConfiguration.IsSuspended = !profileConfiguration.IsSuspended;
}
LogProfileUpdateExceptions();
}
}
public void RenderProfiles(SKCanvas canvas)
{
lock (_profileCategories)
{
// Iterate the children in reverse because the first category must be rendered last to end up on top
for (int i = _profileCategories.Count - 1; i > -1; i--)
else
{
ProfileCategory profileCategory = _profileCategories[i];
for (int j = profileCategory.ProfileConfigurations.Count - 1; j > -1; j--)
{
try
{
ProfileConfiguration profileConfiguration = profileCategory.ProfileConfigurations[j];
if (RenderForEditor)
{
if (profileConfiguration.IsBeingEdited)
profileConfiguration.Profile?.Render(canvas, SKPointI.Empty);
}
else
{
// Ensure all criteria are met before rendering
if (!profileConfiguration.IsSuspended && !profileConfiguration.IsMissingModule && profileConfiguration.ActivationConditionMet)
profileConfiguration.Profile?.Render(canvas, SKPointI.Empty);
}
}
catch (Exception e)
{
_renderExceptions.Add(e);
}
}
if (profileConfiguration.IsSuspended && profileConfiguration.EnableHotkey != null && profileConfiguration.EnableHotkey.MatchesEventArgs(e))
profileConfiguration.IsSuspended = false;
if (!profileConfiguration.IsSuspended && profileConfiguration.DisableHotkey != null && profileConfiguration.DisableHotkey.MatchesEventArgs(e))
profileConfiguration.IsSuspended = true;
}
LogProfileRenderExceptions();
}
}
@ -211,6 +167,93 @@ namespace Artemis.Core.Services
_renderExceptions.Clear();
}
public bool HotkeysEnabled { get; set; }
public bool RenderForEditor { get; set; }
public void UpdateProfiles(double deltaTime)
{
lock (_profileCategories)
{
// Iterate the children in reverse because the first category must be rendered last to end up on top
for (int i = _profileCategories.Count - 1; i > -1; i--)
{
ProfileCategory profileCategory = _profileCategories[i];
for (int j = profileCategory.ProfileConfigurations.Count - 1; j > -1; j--)
{
ProfileConfiguration profileConfiguration = profileCategory.ProfileConfigurations[j];
// Process hotkeys that where pressed since this profile last updated
ProcessPendingKeyEvents(profileConfiguration);
// Profiles being edited are updated at their own leisure
if (profileConfiguration.IsBeingEdited)
continue;
bool shouldBeActive = profileConfiguration.ShouldBeActive(false);
if (shouldBeActive)
{
profileConfiguration.Update();
shouldBeActive = profileConfiguration.ActivationConditionMet;
}
try
{
// Make sure the profile is active or inactive according to the parameters above
if (shouldBeActive && profileConfiguration.Profile == null)
ActivateProfile(profileConfiguration);
else if (!shouldBeActive && profileConfiguration.Profile != null)
DeactivateProfile(profileConfiguration);
profileConfiguration.Profile?.Update(deltaTime);
}
catch (Exception e)
{
_updateExceptions.Add(e);
}
}
}
LogProfileUpdateExceptions();
_pendingKeyboardEvents.Clear();
}
}
public void RenderProfiles(SKCanvas canvas)
{
lock (_profileCategories)
{
// Iterate the children in reverse because the first category must be rendered last to end up on top
for (int i = _profileCategories.Count - 1; i > -1; i--)
{
ProfileCategory profileCategory = _profileCategories[i];
for (int j = profileCategory.ProfileConfigurations.Count - 1; j > -1; j--)
{
try
{
ProfileConfiguration profileConfiguration = profileCategory.ProfileConfigurations[j];
if (RenderForEditor)
{
if (profileConfiguration.IsBeingEdited)
profileConfiguration.Profile?.Render(canvas, SKPointI.Empty);
}
else
{
// Ensure all criteria are met before rendering
if (!profileConfiguration.IsSuspended && !profileConfiguration.IsMissingModule && profileConfiguration.ActivationConditionMet)
profileConfiguration.Profile?.Render(canvas, SKPointI.Empty);
}
}
catch (Exception e)
{
_renderExceptions.Add(e);
}
}
}
LogProfileRenderExceptions();
}
}
public ReadOnlyCollection<ProfileCategory> ProfileCategories
{
get
@ -485,7 +528,8 @@ namespace Artemis.Core.Services
if (markAsFreshImport)
profileEntity.IsFreshImport = true;
_profileRepository.Add(profileEntity);
if (!makeUnique && _profileRepository.Get(profileEntity.Id) == null)
_profileRepository.Add(profileEntity);
ProfileConfiguration profileConfiguration;
if (exportModel.ProfileConfigurationEntity != null)
@ -500,9 +544,7 @@ namespace Artemis.Core.Services
profileConfiguration.Name = $"{profileConfiguration.Name} - {nameAffix}";
}
else
{
profileConfiguration = new ProfileConfiguration(category, profileEntity.Name, "Import");
}
if (exportModel.ProfileImage != null)
{

View File

@ -15,6 +15,10 @@ namespace Artemis.Storage.Entities.Profile
public int ActivationBehaviour { get; set; }
public DataModelConditionGroupEntity ActivationCondition { get; set; }
public int HotkeyMode { get; set; }
public ProfileConfigurationHotkeyEntity EnableHotkey { get; set; }
public ProfileConfigurationHotkeyEntity DisableHotkey { get; set; }
public string ModuleId { get; set; }
public Guid ProfileCategoryId { get; set; }

View File

@ -0,0 +1,8 @@
namespace Artemis.Storage.Entities.Profile
{
public class ProfileConfigurationHotkeyEntity
{
public int? Key { get; set; }
public int? Modifiers { get; set; }
}
}

View File

@ -106,6 +106,7 @@ namespace Artemis.UI.Ninject.Factories
{
SidebarCategoryViewModel SidebarCategoryViewModel(ProfileCategory profileCategory);
SidebarProfileConfigurationViewModel SidebarProfileConfigurationViewModel(ProfileConfiguration profileConfiguration);
ProfileConfigurationHotkeyViewModel ProfileConfigurationHotkeyViewModel(ProfileConfiguration profileConfiguration, bool isDisableHotkey);
ModuleActivationRequirementViewModel ModuleActivationRequirementViewModel(IModuleActivationRequirement activationRequirement);
}

View File

@ -9,6 +9,7 @@ using Artemis.UI.Extensions;
using Artemis.UI.Screens.ProfileEditor.Conditions.Abstract;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.Conditions
{
@ -61,7 +62,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
protected override List<DataModelPropertiesViewModel> GetExtraRightSideDataModelViewModels()
{
// Extra data models are expected to not have an empty root, so lets return the child
// Only the VM housing the event arguments is expected here which is a DataModelPropertiesViewModel
return GetEventDataModel().Children.Cast<DataModelPropertiesViewModel>().ToList();
}
@ -76,7 +77,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
public override void Evaluate()
{
throw new NotImplementedException();
}
}
}

View File

@ -30,22 +30,20 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs
#region Overrides of Screen
/// <inheritdoc />
protected override void OnInitialActivate()
protected override void OnActivate()
{
BindableCollection<ArtemisLed> selectedLeds = ((DeviceDialogViewModel) Parent).SelectedLeds;
LedViewModels.Clear();
LedViewModels.AddRange(Device.Leds.Select(l => new DeviceLedsTabLedViewModel(l, selectedLeds)));
selectedLeds.CollectionChanged += SelectedLedsOnCollectionChanged;
base.OnInitialActivate();
base.OnActivate();
}
/// <inheritdoc />
protected override void OnClose()
protected override void OnDeactivate()
{
((DeviceDialogViewModel) Parent).SelectedLeds.CollectionChanged -= SelectedLedsOnCollectionChanged;
base.OnClose();
base.OnDeactivate();
}
#endregion

View File

@ -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>

View File

@ -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();
}
}
}

View File

@ -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>

View File

@ -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>

View File

@ -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

View File

@ -241,6 +241,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Hotkey/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=luma/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=pixmap/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=snackbar/@EntryIndexedValue">True</s:Boolean>