mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Add layer copy paste across profiles with Ctrl+C/Ctrl+V for #194
This commit is contained in:
parent
e8e6e084a7
commit
650e506266
@ -653,7 +653,6 @@
|
||||
<Compile Include="Utilities\Converters\NinjectCustomConverter.cs" />
|
||||
<Compile Include="Utilities\Converters\ValueConverters.cs" />
|
||||
<Compile Include="Utilities\DataReaders\DllManager.cs" />
|
||||
<Compile Include="Utilities\EditorHelper.cs" />
|
||||
<Compile Include="Utilities\ExtensionMethods.cs" />
|
||||
<Compile Include="Utilities\GameState\GameDataReceivedEventArgs.cs" />
|
||||
<Compile Include="Utilities\GameState\GameStateWebServer.cs" />
|
||||
|
||||
@ -1,92 +1,92 @@
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using Artemis.DAL;
|
||||
using Artemis.DeviceProviders.CoolerMaster.Utilities;
|
||||
using Artemis.DeviceProviders.Logitech.Utilities;
|
||||
using Artemis.Properties;
|
||||
using Artemis.Settings;
|
||||
using Artemis.Utilities;
|
||||
|
||||
namespace Artemis.DeviceProviders.CoolerMaster
|
||||
{
|
||||
public class MasterkeysProL : KeyboardProvider
|
||||
{
|
||||
private GeneralSettings _generalSettings;
|
||||
|
||||
public MasterkeysProL()
|
||||
{
|
||||
Name = "CM Masterkeys Pro L";
|
||||
Slug = "cm-masterkeys-pro-l";
|
||||
|
||||
CantEnableText = "Couldn't connect to your CM Masterkeys Pro L.\n" +
|
||||
"Please check your cables and try updating your CM software.\n\n" +
|
||||
"If needed, you can select a different keyboard in Artemis under settings.";
|
||||
|
||||
Height = 6;
|
||||
Width = 22;
|
||||
|
||||
PreviewSettings = new PreviewSettings(670, 189, new Thickness(-2, -5, 0, 0), Resources.masterkeys_pro_l);
|
||||
_generalSettings = SettingsProvider.Load<GeneralSettings>();
|
||||
}
|
||||
|
||||
public override void Disable()
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using Artemis.DAL;
|
||||
using Artemis.DeviceProviders.CoolerMaster.Utilities;
|
||||
using Artemis.DeviceProviders.Logitech.Utilities;
|
||||
using Artemis.Properties;
|
||||
using Artemis.Settings;
|
||||
using Artemis.Utilities;
|
||||
|
||||
namespace Artemis.DeviceProviders.CoolerMaster
|
||||
{
|
||||
public class MasterkeysProL : KeyboardProvider
|
||||
{
|
||||
private GeneralSettings _generalSettings;
|
||||
|
||||
public MasterkeysProL()
|
||||
{
|
||||
CmSdk.SetControlDevice(DEVICE_INDEX.DEV_MKeys_L);
|
||||
CmSdk.EnableLedControl(false);
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
public override bool CanEnable()
|
||||
{
|
||||
CmSdk.SetControlDevice(DEVICE_INDEX.DEV_MKeys_L);
|
||||
|
||||
// Doesn't seem reliable but better than nothing I suppose
|
||||
return CmSdk.IsDevicePlug();
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
CmSdk.SetControlDevice(DEVICE_INDEX.DEV_MKeys_L);
|
||||
CmSdk.EnableLedControl(true);
|
||||
}
|
||||
|
||||
public override void DrawBitmap(Bitmap bitmap)
|
||||
{
|
||||
// Resize the bitmap
|
||||
using (var b = ImageUtilities.ResizeImage(bitmap, Width, Height))
|
||||
{
|
||||
// Create an empty matrix
|
||||
var matrix = new COLOR_MATRIX {KeyColor = new KEY_COLOR[6, 22]};
|
||||
|
||||
// Map the bytes to the matix
|
||||
for (var x = 0; x < Width; x++)
|
||||
{
|
||||
for (var y = 0; y < Height; y++)
|
||||
{
|
||||
var c = b.GetPixel(x, y);
|
||||
matrix.KeyColor[y, x] = new KEY_COLOR(c.R, c.G, c.B);
|
||||
}
|
||||
}
|
||||
|
||||
// Send the matrix to the keyboard
|
||||
CmSdk.SetAllLedColor(matrix);
|
||||
}
|
||||
}
|
||||
|
||||
public override KeyMatch? GetKeyPosition(Keys keyCode)
|
||||
{
|
||||
switch (_generalSettings.Layout)
|
||||
{
|
||||
case "Qwerty":
|
||||
return KeyMap.QwertyLayout.FirstOrDefault(k => k.KeyCode == keyCode);
|
||||
case "Qwertz":
|
||||
return KeyMap.QwertzLayout.FirstOrDefault(k => k.KeyCode == keyCode);
|
||||
default:
|
||||
return KeyMap.AzertyLayout.FirstOrDefault(k => k.KeyCode == keyCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
Name = "CM Masterkeys Pro L";
|
||||
Slug = "cm-masterkeys-pro-l";
|
||||
|
||||
CantEnableText = "Couldn't connect to your CM Masterkeys Pro L.\n" +
|
||||
"Please check your cables and try updating your CM software.\n\n" +
|
||||
"If needed, you can select a different keyboard in Artemis under settings.";
|
||||
|
||||
Height = 6;
|
||||
Width = 22;
|
||||
|
||||
PreviewSettings = new PreviewSettings(670, 189, new Thickness(-2, -5, 0, 0), Resources.masterkeys_pro_l);
|
||||
_generalSettings = SettingsProvider.Load<GeneralSettings>();
|
||||
}
|
||||
|
||||
public override void Disable()
|
||||
{
|
||||
CmSdk.SetControlDevice(DEVICE_INDEX.DEV_MKeys_L);
|
||||
CmSdk.EnableLedControl(false);
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
public override bool CanEnable()
|
||||
{
|
||||
CmSdk.SetControlDevice(DEVICE_INDEX.DEV_MKeys_L);
|
||||
|
||||
// Doesn't seem reliable but better than nothing I suppose
|
||||
return CmSdk.IsDevicePlug();
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
CmSdk.SetControlDevice(DEVICE_INDEX.DEV_MKeys_L);
|
||||
CmSdk.EnableLedControl(true);
|
||||
}
|
||||
|
||||
public override void DrawBitmap(Bitmap bitmap)
|
||||
{
|
||||
// Resize the bitmap
|
||||
using (var b = ImageUtilities.ResizeImage(bitmap, Width, Height))
|
||||
{
|
||||
// Create an empty matrix
|
||||
var matrix = new COLOR_MATRIX {KeyColor = new KEY_COLOR[6, 22]};
|
||||
|
||||
// Map the bytes to the matix
|
||||
for (var x = 0; x < Width; x++)
|
||||
{
|
||||
for (var y = 0; y < Height; y++)
|
||||
{
|
||||
var c = b.GetPixel(x, y);
|
||||
matrix.KeyColor[y, x] = new KEY_COLOR(c.R, c.G, c.B);
|
||||
}
|
||||
}
|
||||
|
||||
// Send the matrix to the keyboard
|
||||
CmSdk.SetAllLedColor(matrix);
|
||||
}
|
||||
}
|
||||
|
||||
public override KeyMatch? GetKeyPosition(Keys keyCode)
|
||||
{
|
||||
switch (_generalSettings.Layout)
|
||||
{
|
||||
case "Qwerty":
|
||||
return KeyMap.QwertyLayout.FirstOrDefault(k => k.KeyCode == keyCode);
|
||||
case "Qwertz":
|
||||
return KeyMap.QwertzLayout.FirstOrDefault(k => k.KeyCode == keyCode);
|
||||
default:
|
||||
return KeyMap.AzertyLayout.FirstOrDefault(k => k.KeyCode == keyCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,7 +59,7 @@ namespace Artemis.DeviceProviders.CoolerMaster
|
||||
using (var b = ImageUtilities.ResizeImage(bitmap, Width, Height))
|
||||
{
|
||||
// Create an empty matrix
|
||||
var matrix = new COLOR_MATRIX { KeyColor = new KEY_COLOR[6, 22] };
|
||||
var matrix = new COLOR_MATRIX {KeyColor = new KEY_COLOR[6, 22]};
|
||||
|
||||
// Map the bytes to the matix
|
||||
for (var x = 0; x < Width; x++)
|
||||
|
||||
@ -194,8 +194,13 @@ namespace Artemis.Profiles
|
||||
}
|
||||
|
||||
public void Deactivate(LuaManager luaManager)
|
||||
{
|
||||
KeybindManager.Clear();
|
||||
{
|
||||
foreach (var layerModel in Layers)
|
||||
{
|
||||
for (var index = 0; index < layerModel.Properties.Conditions.Count; index++)
|
||||
KeybindManager.Remove($"{GameName}-{Name}-{layerModel.Name}-{index}");
|
||||
}
|
||||
|
||||
luaManager.ClearLua();
|
||||
}
|
||||
|
||||
@ -220,6 +225,7 @@ namespace Artemis.Profiles
|
||||
public void ApplyKeybinds()
|
||||
{
|
||||
foreach (var layerModel in Layers)
|
||||
{
|
||||
for (var index = 0; index < layerModel.Properties.Conditions.Count; index++)
|
||||
{
|
||||
var condition = layerModel.Properties.Conditions[index];
|
||||
@ -231,6 +237,7 @@ namespace Artemis.Profiles
|
||||
var kb = new KeybindModel($"{GameName}-{Name}-{layerModel.Name}-{index}", condition.HotKey, action);
|
||||
KeybindManager.AddOrUpdate(kb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Compare
|
||||
|
||||
@ -53,7 +53,7 @@ using System.Windows;
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
[assembly: AssemblyVersion("1.8.1.0")]
|
||||
[assembly: AssemblyFileVersion("1.8.1.0")]
|
||||
[assembly: AssemblyVersion("1.8.2.0")]
|
||||
[assembly: AssemblyFileVersion("1.8.2.0")]
|
||||
[assembly: InternalsVisibleTo("Artemis.Explorables")]
|
||||
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artemis.Utilities
|
||||
{
|
||||
public static class EditorHelper
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,8 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using Microsoft.Win32;
|
||||
using Newtonsoft.Json;
|
||||
using static System.String;
|
||||
@ -126,5 +128,13 @@ namespace Artemis.Utilities
|
||||
public List<PropertyCollection> Children { get; set; }
|
||||
public string DisplayType { get; set; }
|
||||
}
|
||||
|
||||
public static void ExecuteSta(Action action)
|
||||
{
|
||||
var thread = new Thread(action.Invoke);
|
||||
thread.SetApartmentState(ApartmentState.STA); //Set the thread to STA
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -28,9 +28,12 @@ using Caliburn.Micro;
|
||||
using Castle.Components.DictionaryAdapter;
|
||||
using GongSolutions.Wpf.DragDrop;
|
||||
using MahApps.Metro;
|
||||
using MahApps.Metro.Controls;
|
||||
using MahApps.Metro.Controls.Dialogs;
|
||||
using Newtonsoft.Json;
|
||||
using NuGet;
|
||||
using Application = System.Windows.Application;
|
||||
using Clipboard = System.Windows.Clipboard;
|
||||
using Cursor = System.Windows.Input.Cursor;
|
||||
using Cursors = System.Windows.Input.Cursors;
|
||||
using DragDropEffects = System.Windows.DragDropEffects;
|
||||
@ -44,6 +47,8 @@ namespace Artemis.ViewModels
|
||||
{
|
||||
private readonly DeviceManager _deviceManager;
|
||||
private readonly MetroDialogService _dialogService;
|
||||
private KeybindModel _copyKeybind;
|
||||
private KeybindModel _pasteKeybind;
|
||||
private readonly LoopManager _loopManager;
|
||||
private readonly ModuleModel _moduleModel;
|
||||
private ImageSource _keyboardPreview;
|
||||
@ -60,6 +65,8 @@ namespace Artemis.ViewModels
|
||||
_loopManager = loopManager;
|
||||
_moduleModel = moduleModel;
|
||||
_dialogService = dialogService;
|
||||
_copyKeybind = new KeybindModel("copy", new HotKey(Key.C, ModifierKeys.Control), LayerToClipboard);
|
||||
_pasteKeybind = new KeybindModel("paste", new HotKey(Key.V, ModifierKeys.Control), ClipboardToLayer);
|
||||
|
||||
ProfileNames = new ObservableCollection<string>();
|
||||
Layers = new ObservableCollection<LayerModel>();
|
||||
@ -69,6 +76,7 @@ namespace Artemis.ViewModels
|
||||
PropertyChanged += EditorStateHandler;
|
||||
_deviceManager.OnKeyboardChanged += DeviceManagerOnOnKeyboardChanged;
|
||||
_moduleModel.ProfileChanged += ModuleModelOnProfileChanged;
|
||||
|
||||
LoadProfiles();
|
||||
}
|
||||
|
||||
@ -77,6 +85,8 @@ namespace Artemis.ViewModels
|
||||
base.OnActivate();
|
||||
|
||||
_loopManager.RenderCompleted += LoopManagerOnRenderCompleted;
|
||||
KeybindManager.AddOrUpdate(_copyKeybind);
|
||||
KeybindManager.AddOrUpdate(_pasteKeybind);
|
||||
}
|
||||
|
||||
public new void OnDeactivate(bool close)
|
||||
@ -85,6 +95,8 @@ namespace Artemis.ViewModels
|
||||
|
||||
SaveSelectedProfile();
|
||||
_loopManager.RenderCompleted -= LoopManagerOnRenderCompleted;
|
||||
KeybindManager.Remove(_copyKeybind);
|
||||
KeybindManager.Remove(_pasteKeybind);
|
||||
}
|
||||
|
||||
#region LUA
|
||||
@ -302,6 +314,38 @@ namespace Artemis.ViewModels
|
||||
UpdateLayerList(clone);
|
||||
}
|
||||
|
||||
public void LayerToClipboard()
|
||||
{
|
||||
if (SelectedLayer == null)
|
||||
return;
|
||||
|
||||
// Probably not how the cool kids do it but leveraging on JsonConvert gives flawless serialization
|
||||
GeneralHelpers.ExecuteSta(() => Clipboard.SetData("layer", JsonConvert.SerializeObject(SelectedLayer)));
|
||||
}
|
||||
|
||||
public void ClipboardToLayer()
|
||||
{
|
||||
GeneralHelpers.ExecuteSta(() =>
|
||||
{
|
||||
var data = (string) Clipboard.GetData("layer");
|
||||
if (data == null)
|
||||
return;
|
||||
|
||||
var layerModel = JsonConvert.DeserializeObject<LayerModel>(data);
|
||||
if (layerModel == null)
|
||||
return;
|
||||
|
||||
if (SelectedLayer != null)
|
||||
SelectedLayer.InsertAfter(layerModel);
|
||||
else
|
||||
{
|
||||
SelectedProfile.Layers.Add(layerModel);
|
||||
SelectedProfile.FixOrder();
|
||||
}
|
||||
Execute.OnUIThread(() => UpdateLayerList(layerModel));
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateLayerList(LayerModel selectModel)
|
||||
{
|
||||
// Update the UI
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user