Input - Polished up UI

Input - Added events to service
This commit is contained in:
SpoinkyNL committed 2020-11-23 19:41:48 +01:00
1 parent 6ee5cbd09c
commit f1f0abfec5
40 files changed
+552 -203

No files matched your search

@@ -28,11 +28,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Dialogs
Session.Close(ProfileName);
}
public void Cancel()
{
Session.Close();
}
}
public class ProfileCreateViewModelValidator : AbstractValidator<ProfileCreateViewModel>
@@ -30,10 +30,5 @@ namespace Artemis.UI.Screens.ProfileEditor.Dialogs
Session.Close();
}
public void Cancel()
{
Session.Close();
}
}
}
@@ -37,10 +37,5 @@ namespace Artemis.UI.Screens.ProfileEditor.Dialogs
_mainMessageQueue.Enqueue("Profile imported.");
Session.Close(descriptor);
}
public void Cancel()
{
Session.Close();
}
}
}
@@ -32,11 +32,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Dialogs
Session.Close(ElementName);
}
public void Cancel()
{
Session.Close();
}
}
public class ProfileElementRenameViewModelValidator : AbstractValidator<RenameViewModel>
@@ -19,6 +19,7 @@ using Artemis.UI.Shared.Services;
using GongSolutions.Wpf.DragDrop;
using Stylet;
using static Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree.TreeGroupViewModel.LayerPropertyGroupType;
using MouseButtonEventArgs = System.Windows.Input.MouseButtonEventArgs;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
{
@@ -38,11 +38,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Dialogs
Segment.UpdateLength(TimelineSegmentDialogViewModelValidator.CreateTime(InputValue));
Session.Close();
}
public void Cancel()
{
Session.Close();
}
}
public class TimelineSegmentDialogViewModelValidator : AbstractValidator<TimelineSegmentDialogViewModel>
@@ -12,6 +12,7 @@ using Artemis.UI.Screens.ProfileEditor.Visualization.Tools;
using Artemis.UI.Screens.Shared;
using Artemis.UI.Shared.Services;
using Stylet;
using MouseButtonEventArgs = System.Windows.Input.MouseButtonEventArgs;
namespace Artemis.UI.Screens.ProfileEditor.Visualization
{
@@ -8,6 +8,7 @@ using Artemis.Core.LayerBrushes;
using Artemis.Core.Services;
using Artemis.UI.Properties;
using Artemis.UI.Shared.Services;
using MouseButtonEventArgs = System.Windows.Input.MouseButtonEventArgs;
namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
{
+1
View File
@@ -17,6 +17,7 @@ using Artemis.UI.Utilities;
using MaterialDesignExtensions.Controls;
using MaterialDesignThemes.Wpf;
using Stylet;
using MouseButtonEventArgs = System.Windows.Input.MouseButtonEventArgs;
namespace Artemis.UI.Screens
{
@@ -54,8 +54,31 @@
</CheckBox>
<materialDesign:PopupBox Style="{StaticResource MaterialDesignToolPopupBox}" Padding="2 0 2 0">
<StackPanel>
<Button Content="Show device debugger" Command="{s:Action ShowDeviceDebugger}" />
<Button Content="Open plugin directory" Command="{s:Action OpenPluginDirectory}" />
<Button Command="{s:Action ShowDeviceDebugger}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Tools" Margin="0 0 10 0 " VerticalAlignment="Center"/>
<TextBlock VerticalAlignment="Center">Show device debugger</TextBlock>
</StackPanel>
</Button>
<Button Command="{s:Action OpenPluginDirectory}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="FolderOpen" Margin="0 0 10 0 " VerticalAlignment="Center"/>
<TextBlock VerticalAlignment="Center">Open plugin directory</TextBlock>
</StackPanel>
</Button>
<Separator/>
<Button Command="{s:Action DetectInput}" ToolTip="Teach Artemis which keypresses and/or button presses belong to this device">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="GestureDoubleTap" Margin="0 0 10 0 " VerticalAlignment="Center"/>
<TextBlock VerticalAlignment="Center">Identify input</TextBlock>
</StackPanel>
</Button>
<Button Command="{s:Action ViewProperties}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Gear" Margin="0 0 10 0 " VerticalAlignment="Center"/>
<TextBlock VerticalAlignment="Center">View surface properties</TextBlock>
</StackPanel>
</Button>
</StackPanel>
</materialDesign:PopupBox>
</StackPanel>
@@ -1,10 +1,15 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.SurfaceEditor.Dialogs;
using Artemis.UI.Screens.SurfaceEditor.Visualization;
using Artemis.UI.Shared.Services;
using Humanizer;
using RGB.NET.Core;
using Stylet;
namespace Artemis.UI.Screens.Settings.Tabs.Devices
@@ -12,18 +17,24 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices
public class DeviceSettingsViewModel : PropertyChangedBase
{
private readonly IDeviceDebugVmFactory _deviceDebugVmFactory;
private readonly ISurfaceService _surfaceService;
private readonly IDeviceService _deviceService;
private readonly IDialogService _dialogService;
private readonly IWindowManager _windowManager;
private bool _isDeviceEnabled;
public DeviceSettingsViewModel(ArtemisDevice device, IDeviceService deviceService, IDialogService dialogService,
IWindowManager windowManager, IDeviceDebugVmFactory deviceDebugVmFactory)
public DeviceSettingsViewModel(ArtemisDevice device,
IDeviceService deviceService,
IDialogService dialogService,
IWindowManager windowManager,
IDeviceDebugVmFactory deviceDebugVmFactory,
ISurfaceService surfaceService)
{
_deviceService = deviceService;
_dialogService = dialogService;
_windowManager = windowManager;
_deviceDebugVmFactory = deviceDebugVmFactory;
_surfaceService = surfaceService;
Device = device;
Type = Device.RgbDevice.DeviceInfo.DeviceType.ToString().Humanize();
@@ -40,6 +51,9 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices
public string Name { get; }
public string Manufacturer { get; }
public bool CanDetectInput => Device.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Keyboard ||
Device.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Mouse;
public bool IsDeviceEnabled
{
get => _isDeviceEnabled;
@@ -67,5 +81,25 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices
_dialogService.ShowExceptionDialog("Welp, we couldn't open the device's plugin folder for you", e);
}
}
public async Task DetectInput()
{
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceDetectInputViewModel>(
new Dictionary<string, object> { { "device", Device } }
);
if ((bool)madeChanges)
_surfaceService.UpdateSurfaceConfiguration(_surfaceService.ActiveSurface, true);
}
public async Task ViewProperties()
{
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceConfigViewModel>(
new Dictionary<string, object> {{"device", Device}}
);
if ((bool) madeChanges)
_surfaceService.UpdateSurfaceConfiguration(_surfaceService.ActiveSurface, true);
}
}
}
@@ -6,6 +6,7 @@ using Humanizer;
using MaterialDesignExtensions.Controls;
using Stylet;
using MouseButton = System.Windows.Input.MouseButton;
using MouseButtonEventArgs = System.Windows.Input.MouseButtonEventArgs;
namespace Artemis.UI.Screens.Splash
{
@@ -27,10 +27,5 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
Session.Close(SurfaceName);
}
public void Cancel()
{
Session.Close();
}
}
}
@@ -1,6 +1,6 @@
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Screens.SurfaceEditor.Visualization;
using Artemis.UI.Shared.Services;
using Stylet;
@@ -15,20 +15,21 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
private int _x;
private int _y;
public SurfaceDeviceConfigViewModel(SurfaceDeviceViewModel surfaceDeviceViewModel, ICoreService coreService, IModelValidator<SurfaceDeviceConfigViewModel> validator)
: base(validator)
public SurfaceDeviceConfigViewModel(ArtemisDevice device, ICoreService coreService, IModelValidator<SurfaceDeviceConfigViewModel> validator) : base(validator)
{
_coreService = coreService;
SurfaceDeviceViewModel = surfaceDeviceViewModel;
Title = $"{SurfaceDeviceViewModel.Device.RgbDevice.DeviceInfo.DeviceName} - Properties";
X = (int) SurfaceDeviceViewModel.Device.X;
Y = (int) SurfaceDeviceViewModel.Device.Y;
Scale = SurfaceDeviceViewModel.Device.Scale;
Rotation = (int) SurfaceDeviceViewModel.Device.Rotation;
Device = device;
Title = $"{Device.RgbDevice.DeviceInfo.DeviceName} - Properties";
X = (int) Device.X;
Y = (int) Device.Y;
Scale = Device.Scale;
Rotation = (int) Device.Rotation;
}
public SurfaceDeviceViewModel SurfaceDeviceViewModel { get; }
public ArtemisDevice Device { get; }
public string Title
{
@@ -69,19 +70,14 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
_coreService.ModuleRenderingDisabled = true;
await Task.Delay(100);
SurfaceDeviceViewModel.Device.X = X;
SurfaceDeviceViewModel.Device.Y = Y;
SurfaceDeviceViewModel.Device.Scale = Scale;
SurfaceDeviceViewModel.Device.Rotation = Rotation;
Device.X = X;
Device.Y = Y;
Device.Scale = Scale;
Device.Rotation = Rotation;
_coreService.ModuleRenderingDisabled = false;
Session.Close(true);
}
public void Cancel()
{
Session.Close(false);
}
}
}
@@ -17,13 +17,39 @@
that is currently showing a <Bold Foreground="Yellow">yellow</Bold> color.
</TextBlock>
<materialDesign:PackIcon Kind="GestureDoubleTap" Width="300" Height="340" HorizontalAlignment="Center" />
<materialDesign:PackIcon Kind="Keyboard"
Width="300"
Height="340"
HorizontalAlignment="Center"
Visibility="{Binding IsMouse, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}" />
<materialDesign:PackIcon Kind="Mouse"
Width="250"
Height="340"
HorizontalAlignment="Center"
Visibility="{Binding IsMouse, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" TextWrapping="Wrap">
This will teach Artemis to associate button/key presses with this specific device.
</TextBlock>
<Button HorizontalAlignment="Right" Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0" Command="{s:Action Cancel}">
<Button HorizontalAlignment="Right"
Style="{StaticResource MaterialDesignFlatButton}"
IsCancel="True"
Command="{s:Action Cancel}"
Visibility="{Binding IsMouse, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
<Button.CommandParameter>
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
False
</system:Boolean>
</Button.CommandParameter>
PRESS ESC TO CANCEL
</Button>
<Button HorizontalAlignment="Right"
Style="{StaticResource MaterialDesignFlatButton}"
IsCancel="True"
Command="{s:Action Cancel}"
Visibility="{Binding IsMouse, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
<Button.CommandParameter>
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
False
@@ -1,7 +1,7 @@
using System;
using System.Linq;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Screens.SurfaceEditor.Visualization;
using Artemis.UI.Shared.Services;
using MaterialDesignThemes.Wpf;
using RGB.NET.Brushes;
@@ -13,36 +13,31 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
public class SurfaceDeviceDetectInputViewModel : DialogViewModelBase
{
private readonly IInputService _inputService;
private readonly ListLedGroup _ledGroup;
private readonly ISnackbarMessageQueue _mainMessageQueue;
private string _title;
private ListLedGroup _ledGroup;
public SurfaceDeviceDetectInputViewModel(SurfaceDeviceViewModel surfaceDeviceViewModel, IInputService inputService, ISnackbarMessageQueue mainMessageQueue)
public SurfaceDeviceDetectInputViewModel(ArtemisDevice device, IInputService inputService, ISnackbarMessageQueue mainMessageQueue)
{
SurfaceDeviceViewModel = surfaceDeviceViewModel;
Title = $"{SurfaceDeviceViewModel.Device.RgbDevice.DeviceInfo.DeviceName} - Detect input";
Device = device;
Title = $"{Device.RgbDevice.DeviceInfo.DeviceName} - Detect input";
IsMouse = Device.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Mouse;
_inputService = inputService;
_mainMessageQueue = mainMessageQueue;
_inputService.IdentifyDevice(Device);
_inputService.DeviceIdentified += InputServiceOnDeviceIdentified;
// Create a LED group way at the top
_ledGroup = new ListLedGroup(SurfaceDeviceViewModel.Device.Leds.Select(l => l.RgbLed))
_ledGroup = new ListLedGroup(Device.Leds.Select(l => l.RgbLed))
{
Brush = new SolidColorBrush(new Color(255, 255, 0)),
ZIndex = 999
};
_inputService = inputService;
_mainMessageQueue = mainMessageQueue;
_inputService.IdentifyDevice(surfaceDeviceViewModel.Device);
_inputService.DeviceIdentified += InputServiceOnDeviceIdentified;
}
public SurfaceDeviceViewModel SurfaceDeviceViewModel { get; }
public string Title
{
get => _title;
set => SetAndNotify(ref _title, value);
}
public ArtemisDevice Device { get; }
public string Title { get; }
public bool IsMouse { get; }
public override void OnDialogClosed(object sender, DialogClosingEventArgs e)
{
@@ -51,15 +46,10 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
_ledGroup.Detach();
}
public void Cancel()
{
Session?.Close(false);
}
private void InputServiceOnDeviceIdentified(object sender, EventArgs e)
{
Session?.Close(true);
_mainMessageQueue.Enqueue("Device identified.");
_mainMessageQueue.Enqueue($"{Device.RgbDevice.DeviceInfo.DeviceName} identified 😁");
}
}
}
@@ -144,9 +144,11 @@
</MenuItem.Icon>
</MenuItem>
<Separator />
<!-- Stylet can't disable it for us here, do it ourselves -->
<MenuItem Header="Identify input"
Command="{s:Action DetectInput}"
CommandParameter="{Binding}"
IsEnabled="{Binding CanDetectInput}"
ToolTip="Teach Artemis which keypresses and/or button presses belong to this device">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="GestureDoubleTap" />
@@ -16,6 +16,7 @@ using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Stylet;
using MouseButton = System.Windows.Input.MouseButton;
using MouseButtonEventArgs = System.Windows.Input.MouseButtonEventArgs;
namespace Artemis.UI.Screens.SurfaceEditor
{
@@ -35,11 +36,11 @@ namespace Artemis.UI.Screens.SurfaceEditor
private ObservableCollection<ArtemisSurface> _surfaceConfigurations;
private PluginSetting<GridLength> _surfaceListWidth;
public SurfaceEditorViewModel(IRgbService rgbService,
ISurfaceService surfaceService,
IDialogService dialogService,
public SurfaceEditorViewModel(IRgbService rgbService,
ISurfaceService surfaceService,
IDialogService dialogService,
ISettingsService settingsService,
IDeviceService deviceService,
IDeviceService deviceService,
IInputService inputService)
{
DisplayName = "Surface Editor";
@@ -286,10 +287,9 @@ namespace Artemis.UI.Screens.SurfaceEditor
public async Task ViewProperties(SurfaceDeviceViewModel surfaceDeviceViewModel)
{
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceConfigViewModel>(new Dictionary<string, object>
{
{"surfaceDeviceViewModel", surfaceDeviceViewModel}
});
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceConfigViewModel>(
new Dictionary<string, object> {{"device", surfaceDeviceViewModel.Device}}
);
if ((bool) madeChanges)
_surfaceService.UpdateSurfaceConfiguration(SelectedSurface, true);
@@ -297,12 +297,11 @@ namespace Artemis.UI.Screens.SurfaceEditor
public async Task DetectInput(SurfaceDeviceViewModel surfaceDeviceViewModel)
{
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceDetectInputViewModel>(new Dictionary<string, object>
{
{"surfaceDeviceViewModel", surfaceDeviceViewModel}
});
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceDetectInputViewModel>(
new Dictionary<string, object> {{"device", surfaceDeviceViewModel.Device}}
);
if ((bool)madeChanges)
if ((bool) madeChanges)
_surfaceService.UpdateSurfaceConfiguration(SelectedSurface, true);
}
@@ -2,7 +2,9 @@
using System.Windows;
using System.Windows.Input;
using Artemis.Core;
using RGB.NET.Core;
using Stylet;
using Point = System.Windows.Point;
namespace Artemis.UI.Screens.SurfaceEditor.Visualization
{
@@ -45,6 +47,9 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization
? new Rect()
: new Rect(Device.X, Device.Y, Device.RgbDevice.DeviceRectangle.Size.Width, Device.RgbDevice.DeviceRectangle.Size.Height);
public bool CanDetectInput => Device.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Keyboard ||
Device.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Mouse;
public void StartMouseDrag(Point mouseStartPosition)
{
_dragOffsetX = Device.X - mouseStartPosition.X;