1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 09:43:46 +00:00

Disable layers by default when Toggle Enable keybind is first keybind

Layer editor move and resize selected layer when underneath other layers
Fix copy-paste crash
This commit is contained in:
SpoinkyNL 2017-04-30 22:34:11 +02:00
parent 954f4864d8
commit 5c8968a32d
5 changed files with 545 additions and 520 deletions

View File

@ -61,7 +61,7 @@ namespace Artemis
} }
// If there is another type of of IInputControl get the non-scaled position - or do some processing to get a scaled position, whatever needs to happen // If there is another type of of IInputControl get the non-scaled position - or do some processing to get a scaled position, whatever needs to happen
if ((e != null) && (input != null)) if (e != null && input != null)
return e.GetPosition(input).X; return e.GetPosition(input).X;
// Return 0 if no processing could be done // Return 0 if no processing could be done
@ -98,7 +98,7 @@ namespace Artemis
logger.Info("Artemis was run using the autorun shortcut, sleeping for 15 sec."); logger.Info("Artemis was run using the autorun shortcut, sleeping for 15 sec.");
Thread.Sleep(15000); Thread.Sleep(15000);
} }
InputHook.Start();
_kernel = new StandardKernel(new BaseModules(), new ManagerModules()); _kernel = new StandardKernel(new BaseModules(), new ManagerModules());
_kernel.Bind<IWindowManager>().To<WindowManager>().InSingletonScope(); _kernel.Bind<IWindowManager>().To<WindowManager>().InSingletonScope();
@ -145,6 +145,7 @@ namespace Artemis
protected override void OnStartup(object sender, StartupEventArgs e) protected override void OnStartup(object sender, StartupEventArgs e)
{ {
DisplayRootViewFor<ShellViewModel>(); DisplayRootViewFor<ShellViewModel>();
InputHook.Start();
} }
} }
} }

View File

@ -63,9 +63,15 @@ namespace Artemis.Profiles.Layers.Models
switch (ToggleType) switch (ToggleType)
{ {
case ToggleType.Enable: case ToggleType.Enable:
// Apply RenderAllowed only if this is the first keybind
if (index == 0)
layerModel.RenderAllowed = false;
action = () => layerModel.RenderAllowed = true; action = () => layerModel.RenderAllowed = true;
break; break;
case ToggleType.Disable: case ToggleType.Disable:
// Apply RenderAllowed only if this is the first keybind
if (index == 0)
layerModel.RenderAllowed = false;
action = () => layerModel.RenderAllowed = false; action = () => layerModel.RenderAllowed = false;
break; break;
case ToggleType.Toggle: case ToggleType.Toggle:

View File

@ -1,261 +1,261 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using Artemis.Modules.Abstract; using Artemis.Modules.Abstract;
using Artemis.Profiles.Layers.Abstract; using Artemis.Profiles.Layers.Abstract;
using Artemis.Profiles.Layers.Animations; using Artemis.Profiles.Layers.Animations;
using Artemis.Profiles.Layers.Conditions; using Artemis.Profiles.Layers.Conditions;
using Artemis.Profiles.Layers.Interfaces; using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Types.Keyboard; using Artemis.Profiles.Layers.Types.Keyboard;
using Artemis.Utilities; using Artemis.Utilities;
using Artemis.Utilities.ParentChild; using Artemis.Utilities.ParentChild;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Artemis.Profiles.Layers.Models namespace Artemis.Profiles.Layers.Models
{ {
public class LayerModel : IChildItem<LayerModel>, IChildItem<ProfileModel> public class LayerModel : IChildItem<LayerModel>, IChildItem<ProfileModel>
{ {
public LayerModel() public LayerModel()
{ {
Children = new ChildItemCollection<LayerModel, LayerModel>(this); Children = new ChildItemCollection<LayerModel, LayerModel>(this);
TweenModel = new TweenModel(this); TweenModel = new TweenModel(this);
RenderAllowed = true; RenderAllowed = true;
var model = Properties as KeyboardPropertiesModel; var model = Properties as KeyboardPropertiesModel;
if (model != null) if (model != null)
GifImage = new GifImage(model.GifFile, Properties.AnimationSpeed); GifImage = new GifImage(model.GifFile, Properties.AnimationSpeed);
} }
[JsonIgnore] [JsonIgnore]
public ImageSource LayerImage => LayerType.DrawThumbnail(this); public ImageSource LayerImage => LayerType.DrawThumbnail(this);
[JsonIgnore] [JsonIgnore]
public TweenModel TweenModel { get; set; } public TweenModel TweenModel { get; set; }
/// <summary> /// <summary>
/// Checks whether this layers conditions are met. /// Checks whether this layers conditions are met.
/// If they are met and this layer is an event, this also triggers that event. /// If they are met and this layer is an event, this also triggers that event.
/// </summary> /// </summary>
/// <param name="dataModel"></param> /// <param name="dataModel"></param>
/// <returns></returns> /// <returns></returns>
public bool AreConditionsMet(ModuleDataModel dataModel) public bool AreConditionsMet(ModuleDataModel dataModel)
{ {
// Conditions are not even checked if the layer isn't enabled // Conditions are not even checked if the layer isn't enabled
return Enabled && LayerCondition.ConditionsMet(this, dataModel); return Enabled && LayerCondition.ConditionsMet(this, dataModel);
} }
/// <summary> /// <summary>
/// Update the layer /// Update the layer
/// </summary> /// </summary>
/// <param name="dataModel"></param> /// <param name="dataModel"></param>
/// <param name="preview"></param> /// <param name="preview"></param>
/// <param name="updateAnimations"></param> /// <param name="updateAnimations"></param>
public void Update(ModuleDataModel dataModel, bool preview, bool updateAnimations) public void Update(ModuleDataModel dataModel, bool preview, bool updateAnimations)
{ {
if (LayerType == null) if (LayerType == null)
return; return;
LayerType.Update(this, dataModel, preview); LayerType.Update(this, dataModel, preview);
LayerAnimation?.Update(this, updateAnimations); LayerAnimation?.Update(this, updateAnimations);
if (!preview) if (!preview)
TweenModel.Update(); TweenModel.Update();
LastRender = DateTime.Now; LastRender = DateTime.Now;
} }
/// <summary> /// <summary>
/// Applies the saved properties to the current properties /// Applies the saved properties to the current properties
/// </summary> /// </summary>
/// <param name="advanced">Include advanced properties (opacity, brush)</param> /// <param name="advanced">Include advanced properties (opacity, brush)</param>
public void ApplyProperties(bool advanced) public void ApplyProperties(bool advanced)
{ {
X = Properties.X; X = Properties.X;
Y = Properties.Y; Y = Properties.Y;
Width = Properties.Width; Width = Properties.Width;
Height = Properties.Height; Height = Properties.Height;
if (!advanced) if (!advanced)
return; return;
Opacity = Properties.Opacity; Opacity = Properties.Opacity;
Brush = Properties.Brush; Brush = Properties.Brush;
} }
/// <summary> /// <summary>
/// Draw the layer using the provided context /// Draw the layer using the provided context
/// </summary> /// </summary>
/// <param name="dataModel"></param> /// <param name="dataModel"></param>
/// <param name="c"></param> /// <param name="c"></param>
/// <param name="preview"></param> /// <param name="preview"></param>
/// <param name="updateAnimations"></param> /// <param name="updateAnimations"></param>
public void Draw(ModuleDataModel dataModel, DrawingContext c, bool preview, bool updateAnimations) public void Draw(ModuleDataModel dataModel, DrawingContext c, bool preview, bool updateAnimations)
{ {
if (Brush == null || !preview && !RenderAllowed) if (Brush == null || !preview && !RenderAllowed)
return; return;
LayerType.Draw(this, c); LayerType.Draw(this, c);
} }
/// <summary> /// <summary>
/// Tells the current layer type to setup the layer's LayerProperties /// Tells the current layer type to setup the layer's LayerProperties
/// </summary> /// </summary>
public void SetupProperties() public void SetupProperties()
{ {
LayerType.SetupProperties(this); LayerType.SetupProperties(this);
// If the type is an event, set it up // If the type is an event, set it up
if (IsEvent && EventProperties == null) if (IsEvent && EventProperties == null)
EventProperties = new KeyboardEventPropertiesModel EventProperties = new KeyboardEventPropertiesModel
{ {
ExpirationType = ExpirationType.Time, ExpirationType = ExpirationType.Time,
Length = new TimeSpan(0, 0, 1), Length = new TimeSpan(0, 0, 1),
TriggerDelay = new TimeSpan(0) TriggerDelay = new TimeSpan(0)
}; };
} }
/// <summary> /// <summary>
/// Ensures all child layers have a unique order /// Ensures all child layers have a unique order
/// </summary> /// </summary>
public void FixOrder() public void FixOrder()
{ {
Children.Sort(l => l.Order); Children.Sort(l => l.Order);
for (var i = 0; i < Children.Count; i++) for (var i = 0; i < Children.Count; i++)
Children[i].Order = i; Children[i].Order = i;
} }
/// <summary> /// <summary>
/// Returns whether the layer meets the requirements to be drawn in the profile editor /// Returns whether the layer meets the requirements to be drawn in the profile editor
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public bool MustDraw() public bool MustDraw()
{ {
// If any of the parents are disabled, this layer must not be drawn // If any of the parents are disabled, this layer must not be drawn
var parent = Parent; var parent = Parent;
while (parent != null) while (parent != null)
{ {
if (!parent.Enabled) if (!parent.Enabled)
return false; return false;
parent = parent.Parent; parent = parent.Parent;
} }
return Enabled && LayerType.ShowInEdtor; return Enabled && LayerType.ShowInEdtor;
} }
/// <summary> /// <summary>
/// Returns every descendant of this layer /// Returns every descendant of this layer
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public IEnumerable<LayerModel> GetLayers() public IEnumerable<LayerModel> GetLayers()
{ {
var layers = new List<LayerModel>(); var layers = new List<LayerModel>();
foreach (var layerModel in Children.OrderBy(c => c.Order)) foreach (var layerModel in Children.OrderBy(c => c.Order))
{ {
layers.Add(layerModel); layers.Add(layerModel);
layers.AddRange(layerModel.GetLayers()); layers.AddRange(layerModel.GetLayers());
} }
return layers; return layers;
} }
/// <summary> /// <summary>
/// Creates a new Keyboard layer with default settings /// Creates a new Keyboard layer with default settings
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static LayerModel CreateLayer() public static LayerModel CreateLayer()
{ {
return new LayerModel return new LayerModel
{ {
Name = "New layer", Name = "New layer",
Enabled = true, Enabled = true,
Order = -1, Order = -1,
LayerType = new KeyboardType(), LayerType = new KeyboardType(),
LayerCondition = new DataModelCondition(), LayerCondition = new DataModelCondition(),
LayerAnimation = new NoneAnimation(), LayerAnimation = new NoneAnimation(),
Properties = new KeyboardPropertiesModel Properties = new KeyboardPropertiesModel
{ {
Brush = new SolidColorBrush(ColorHelpers.GetRandomRainbowMediaColor()), Brush = new SolidColorBrush(ColorHelpers.GetRandomRainbowMediaColor()),
Height = 1, Height = 1,
Width = 1, Width = 1,
X = 0, X = 0,
Y = 0, Y = 0,
Opacity = 1, Opacity = 1,
HeightEaseTime = 0, HeightEaseTime = 0,
HeightEase = "Linear", HeightEase = "Linear",
WidthEaseTime = 0, WidthEaseTime = 0,
WidthEase = "Linear", WidthEase = "Linear",
OpacityEaseTime = 0, OpacityEaseTime = 0,
OpacityEase = "Linear" OpacityEase = "Linear"
} }
}; };
} }
/// <summary> /// <summary>
/// Insert this layer before the given layer /// Insert this layer before the given layer
/// </summary> /// </summary>
/// <param name="source"></param> /// <param name="source"></param>
public void InsertBefore(LayerModel source) public void InsertBefore(LayerModel source)
{ {
source.Order = Order; source.Order = Order;
Insert(source); Insert(source);
} }
/// <summary> /// <summary>
/// Insert this layer after the given layer /// Insert this layer after the given layer
/// </summary> /// </summary>
/// <param name="source"></param> /// <param name="source"></param>
public void InsertAfter(LayerModel source) public void InsertAfter(LayerModel source)
{ {
source.Order = Order + 1; source.Order = Order + 1;
Insert(source); Insert(source);
} }
/// <summary> /// <summary>
/// Insert the layer as a sibling /// Insert the layer as a sibling
/// </summary> /// </summary>
/// <param name="source"></param> /// <param name="source"></param>
private void Insert(LayerModel source) private void Insert(LayerModel source)
{ {
if (Parent != null) if (Parent != null)
{ {
foreach (var child in Parent.Children.OrderBy(c => c.Order)) foreach (var child in Parent.Children.OrderBy(c => c.Order))
if (child.Order >= source.Order) if (child.Order >= source.Order)
child.Order++; child.Order++;
Parent.Children.Add(source); Parent.Children.Add(source);
} }
else if (Profile != null) else if (Profile != null)
{ {
foreach (var layer in Profile.Layers.OrderBy(l => l.Order)) foreach (var layer in Profile.Layers.OrderBy(l => l.Order))
if (layer.Order >= source.Order) if (layer.Order >= source.Order)
layer.Order++; layer.Order++;
Profile.Layers.Add(source); Profile.Layers.Add(source);
} }
} }
public Rect LayerRect(int scale = 4) public Rect LayerRect(int scale = 4)
{ {
var width = Width; var width = Width;
var height = Height; var height = Height;
if (width < 0) if (width < 0)
width = 0; width = 0;
if (height < 0) if (height < 0)
height = 0; height = 0;
return new Rect(X * scale, Y * scale, width * scale, height * scale); return new Rect(X * scale, Y * scale, width * scale, height * scale);
} }
// TODO: Make this and ProfileModel's GetRenderLayers the same through inheritance // TODO: Make this and ProfileModel's GetRenderLayers the same through inheritance
/// <summary> /// <summary>
/// Generates a flat list containing all layers that must be rendered on the keyboard, /// Generates a flat list containing all layers that must be rendered on the keyboard,
/// the first mouse layer to be rendered and the first headset layer to be rendered /// the first mouse layer to be rendered and the first headset layer to be rendered
/// </summary> /// </summary>
/// <param name="dataModel">Instance of said game data model</param> /// <param name="dataModel">Instance of said game data model</param>
/// <param name="keyboardOnly">Whether or not to ignore anything but keyboards</param> /// <param name="keyboardOnly">Whether or not to ignore anything but keyboards</param>
/// <param name="ignoreConditions"></param> /// <param name="ignoreConditions"></param>
/// <returns>A flat list containing all layers that must be rendered</returns> /// <returns>A flat list containing all layers that must be rendered</returns>
public List<LayerModel> GetRenderLayers(ModuleDataModel dataModel, bool keyboardOnly, bool ignoreConditions = false) public List<LayerModel> GetRenderLayers(ModuleDataModel dataModel, bool keyboardOnly, bool ignoreConditions = false)
{ {
var layers = new List<LayerModel>(); var layers = new List<LayerModel>();
foreach (var layerModel in Children.OrderByDescending(l => l.Order)) foreach (var layerModel in Children.OrderByDescending(l => l.Order))
{ {
@ -272,149 +272,149 @@ namespace Artemis.Profiles.Layers.Models
layers.AddRange(layerModel.GetRenderLayers(dataModel, keyboardOnly, ignoreConditions)); layers.AddRange(layerModel.GetRenderLayers(dataModel, keyboardOnly, ignoreConditions));
} }
return layers; return layers;
} }
public void SetupCondition() public void SetupCondition()
{ {
if (IsEvent && !(LayerCondition is EventCondition)) if (IsEvent && !(LayerCondition is EventCondition))
LayerCondition = new EventCondition(); LayerCondition = new EventCondition();
else if (!IsEvent && !(LayerCondition is DataModelCondition)) else if (!IsEvent && !(LayerCondition is DataModelCondition))
LayerCondition = new DataModelCondition(); LayerCondition = new DataModelCondition();
} }
public void SetupKeybinds() public void SetupKeybinds()
{ {
RenderAllowed = true; RenderAllowed = true;
// Clean up old keybinds // Clean up old keybinds
RemoveKeybinds(); RemoveKeybinds();
for (var index = 0; index < Properties.LayerKeybindModels.Count; index++) for (var index = 0; index < Properties.LayerKeybindModels.Count; index++)
{ {
var keybindModel = Properties.LayerKeybindModels[index]; var keybindModel = Properties.LayerKeybindModels[index];
keybindModel.Register(this, index); keybindModel.Register(this, index);
} }
} }
public void RemoveKeybinds() public void RemoveKeybinds()
{ {
foreach (var keybindModel in Properties.LayerKeybindModels) foreach (var keybindModel in Properties.LayerKeybindModels)
keybindModel.Unregister(); keybindModel.Unregister();
} }
#region Properties #region Properties
#region Layer type properties #region Layer type properties
public ILayerType LayerType { get; set; } public ILayerType LayerType { get; set; }
public ILayerCondition LayerCondition { get; set; } public ILayerCondition LayerCondition { get; set; }
public ILayerAnimation LayerAnimation { get; set; } public ILayerAnimation LayerAnimation { get; set; }
#endregion #endregion
#region Generic properties #region Generic properties
public string Name { get; set; } public string Name { get; set; }
public int Order { get; set; } public int Order { get; set; }
public bool Enabled { get; set; } public bool Enabled { get; set; }
public bool RenderAllowed { get; set; } public bool RenderAllowed { get; set; }
public bool Expanded { get; set; } public bool Expanded { get; set; }
public bool IsEvent { get; set; } public bool IsEvent { get; set; }
public LayerPropertiesModel Properties { get; set; } public LayerPropertiesModel Properties { get; set; }
public EventPropertiesModel EventProperties { get; set; } public EventPropertiesModel EventProperties { get; set; }
#endregion #endregion
#region Relational properties #region Relational properties
public ChildItemCollection<LayerModel, LayerModel> Children { get; } public ChildItemCollection<LayerModel, LayerModel> Children { get; }
[JsonIgnore] [JsonIgnore]
public LayerModel Parent { get; internal set; } public LayerModel Parent { get; internal set; }
[JsonIgnore] [JsonIgnore]
public ProfileModel Profile { get; internal set; } public ProfileModel Profile { get; internal set; }
#endregion #endregion
#region Render properties #region Render properties
[JsonIgnore] private Brush _brush; [JsonIgnore] private Brush _brush;
[JsonIgnore] [JsonIgnore]
public double X { get; set; } public double X { get; set; }
[JsonIgnore] [JsonIgnore]
public double Y { get; set; } public double Y { get; set; }
[JsonIgnore] [JsonIgnore]
public double Width { get; set; } public double Width { get; set; }
[JsonIgnore] [JsonIgnore]
public double Height { get; set; } public double Height { get; set; }
[JsonIgnore] [JsonIgnore]
public double Opacity { get; set; } public double Opacity { get; set; }
[JsonIgnore] [JsonIgnore]
public Brush Brush public Brush Brush
{ {
get { return _brush; } get { return _brush; }
set set
{ {
if (value == null) if (value == null)
{ {
_brush = null; _brush = null;
return; return;
} }
if (value.IsFrozen) if (value.IsFrozen)
{ {
_brush = value; _brush = value;
return; return;
} }
// Clone the brush off of the UI thread and freeze it // Clone the brush off of the UI thread and freeze it
var cloned = value.Dispatcher.Invoke(value.CloneCurrentValue); var cloned = value.Dispatcher.Invoke(value.CloneCurrentValue);
cloned.Freeze(); cloned.Freeze();
_brush = cloned; _brush = cloned;
} }
} }
[JsonIgnore] [JsonIgnore]
public double AnimationProgress { get; set; } public double AnimationProgress { get; set; }
[JsonIgnore] [JsonIgnore]
public GifImage GifImage { get; set; } public GifImage GifImage { get; set; }
[JsonIgnore] [JsonIgnore]
public DateTime LastRender { get; set; } public DateTime LastRender { get; set; }
#endregion #endregion
#endregion #endregion
#region IChildItem<Parent> Members #region IChildItem<Parent> Members
LayerModel IChildItem<LayerModel>.Parent LayerModel IChildItem<LayerModel>.Parent
{ {
get { return Parent; } get { return Parent; }
set { Parent = value; } set { Parent = value; }
} }
ProfileModel IChildItem<ProfileModel>.Parent ProfileModel IChildItem<ProfileModel>.Parent
{ {
get { return Profile; } get { return Profile; }
set { Profile = value; } set { Profile = value; }
} }
#endregion #endregion
/// <inheritdoc /> /// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"{nameof(Name)}: {Name}, {nameof(Order)}: {Order}, {nameof(X)}: {X}, {nameof(Y)}: {Y}, {nameof(Width)}: {Width}, {nameof(Height)}: {Height}"; return $"{nameof(Name)}: {Name}, {nameof(Order)}: {Order}, {nameof(X)}: {X}, {nameof(Y)}: {Y}, {nameof(Width)}: {Width}, {nameof(Height)}: {Height}";
} }
} }
} }

View File

@ -1,95 +1,95 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using Artemis.Utilities.Converters; using Artemis.Utilities.Converters;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Artemis.Profiles.Layers.Models namespace Artemis.Profiles.Layers.Models
{ {
public abstract class LayerPropertiesModel public abstract class LayerPropertiesModel
{ {
private Brush _brush; private Brush _brush;
public LayerPropertiesModel(LayerPropertiesModel source = null) public LayerPropertiesModel(LayerPropertiesModel source = null)
{ {
if (source == null) if (source == null)
return; return;
// Clone the source's properties onto the new properties model (useful when changing property type) // Clone the source's properties onto the new properties model (useful when changing property type)
X = source.X; X = source.X;
Y = source.Y; Y = source.Y;
Width = source.Width; Width = source.Width;
Height = source.Height; Height = source.Height;
Contain = source.Contain; Contain = source.Contain;
Opacity = source.Opacity; Opacity = source.Opacity;
AnimationSpeed = source.AnimationSpeed; AnimationSpeed = source.AnimationSpeed;
Conditions = source.Conditions; Conditions = source.Conditions;
LayerKeybindModels = source.LayerKeybindModels; LayerKeybindModels = source.LayerKeybindModels;
ConditionType = source.ConditionType; ConditionType = source.ConditionType;
DynamicProperties = source.DynamicProperties; DynamicProperties = source.DynamicProperties;
Brush = source.Brush; Brush = source.Brush;
HeightEase = source.HeightEase; HeightEase = source.HeightEase;
WidthEase = source.WidthEase; WidthEase = source.WidthEase;
OpacityEase = source.OpacityEase; OpacityEase = source.OpacityEase;
HeightEaseTime = source.HeightEaseTime; HeightEaseTime = source.HeightEaseTime;
WidthEaseTime = source.WidthEaseTime; WidthEaseTime = source.WidthEaseTime;
OpacityEaseTime = source.OpacityEaseTime; OpacityEaseTime = source.OpacityEaseTime;
} }
public double X { get; set; } public double X { get; set; }
public double Y { get; set; } public double Y { get; set; }
public double Width { get; set; } public double Width { get; set; }
public double Height { get; set; } public double Height { get; set; }
public bool Contain { get; set; } public bool Contain { get; set; }
public double Opacity { get; set; } public double Opacity { get; set; }
public double AnimationSpeed { get; set; } public double AnimationSpeed { get; set; }
public double OpacityEaseTime { get; set; } public double OpacityEaseTime { get; set; }
public double HeightEaseTime { get; set; } public double HeightEaseTime { get; set; }
public double WidthEaseTime { get; set; } public double WidthEaseTime { get; set; }
public string WidthEase { set; get; } public string WidthEase { set; get; }
public string HeightEase { get; set; } public string HeightEase { get; set; }
public string OpacityEase { get; set; } public string OpacityEase { get; set; }
public ConditionType ConditionType { get; set; } public ConditionType ConditionType { get; set; }
public List<LayerConditionModel> Conditions { get; set; } = new List<LayerConditionModel>(); public List<LayerConditionModel> Conditions { get; set; } = new List<LayerConditionModel>();
public List<LayerKeybindModel> LayerKeybindModels { get; set; } = new List<LayerKeybindModel>(); public List<LayerKeybindModel> LayerKeybindModels { get; set; } = new List<LayerKeybindModel>();
public List<DynamicPropertiesModel> DynamicProperties { get; set; } = new List<DynamicPropertiesModel>(); public List<DynamicPropertiesModel> DynamicProperties { get; set; } = new List<DynamicPropertiesModel>();
[JsonConverter(typeof(BrushJsonConverter))] [JsonConverter(typeof(BrushJsonConverter))]
public Brush Brush public Brush Brush
{ {
get { return _brush; } get { return _brush; }
set set
{ {
if (value == null) if (value == null)
{ {
_brush = null; _brush = null;
return; return;
} }
if (value.IsFrozen) if (value.IsFrozen)
{ {
_brush = value; _brush = value;
return; return;
} }
// Clone the brush off of the UI thread and freeze it // Clone the brush off of the UI thread and freeze it
var cloned = value.Dispatcher.Invoke(value.CloneCurrentValue); var cloned = value.Dispatcher.Invoke(value.CloneCurrentValue);
cloned.Freeze(); cloned.Freeze();
_brush = cloned; _brush = cloned;
} }
} }
public Rect PropertiesRect(int scale = 4) public Rect PropertiesRect(int scale = 4)
{ {
return new Rect(X*scale, Y*scale, Width*scale, Height*scale); return new Rect(X*scale, Y*scale, Width*scale, Height*scale);
} }
} }
public enum ConditionType public enum ConditionType
{ {
[Description("All met")] AllMet, [Description("All met")] AllMet,
[Description("Any met")] AnyMet, [Description("Any met")] AnyMet,
[Description("None met")] NoneMet [Description("None met")] NoneMet
} }
} }

View File

@ -324,7 +324,7 @@ namespace Artemis.ViewModels
public void LayerToClipboard() public void LayerToClipboard()
{ {
if (SelectedLayer == null || !ActiveWindowHelper.MainWindowActive) if (SelectedLayer == null || !ActiveWindowHelper.MainWindowActive || !IsActive)
return; return;
// Probably not how the cool kids do it but leveraging on JsonConvert gives flawless serialization // Probably not how the cool kids do it but leveraging on JsonConvert gives flawless serialization
@ -333,28 +333,35 @@ namespace Artemis.ViewModels
public void ClipboardToLayer() public void ClipboardToLayer()
{ {
if (!ActiveWindowHelper.MainWindowActive) if (!ActiveWindowHelper.MainWindowActive || !IsActive)
return; return;
GeneralHelpers.ExecuteSta(() => try
{ {
var data = (string) Clipboard.GetData("layer"); GeneralHelpers.ExecuteSta(() =>
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); var data = (string) Clipboard.GetData("layer");
SelectedProfile.FixOrder(); if (data == null)
} return;
Execute.OnUIThread(() => UpdateLayerList(layerModel));
}); 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));
});
}
catch (Exception)
{
// ignored
}
} }
private void UpdateLayerList(LayerModel selectModel) private void UpdateLayerList(LayerModel selectModel)
@ -665,7 +672,7 @@ namespace Artemis.ViewModels
return; return;
var pos = GetScaledPosition(e); var pos = GetScaledPosition(e);
var hoverLayer = GetLayers().Where(l => l.MustDraw()).FirstOrDefault(l => l.Properties.PropertiesRect(1).Contains(pos.X, pos.Y)); var hoverLayer = GetHoverLayer(pos.X, pos.Y);
if (hoverLayer != null) if (hoverLayer != null)
SelectedLayer = hoverLayer; SelectedLayer = hoverLayer;
@ -681,7 +688,7 @@ namespace Artemis.ViewModels
return; return;
var pos = GetScaledPosition(e); var pos = GetScaledPosition(e);
var hoverLayer = GetLayers().Where(l => l.MustDraw()).FirstOrDefault(l => l.Properties.PropertiesRect(1).Contains(pos.X, pos.Y)); var hoverLayer = GetHoverLayer(pos.X, pos.Y);
HandleDragging(e, pos.X, pos.Y, hoverLayer); HandleDragging(e, pos.X, pos.Y, hoverLayer);
@ -703,6 +710,8 @@ namespace Artemis.ViewModels
KeyboardPreviewCursor = Cursors.Hand; KeyboardPreviewCursor = Cursors.Hand;
} }
private Point GetScaledPosition(MouseEventArgs e) private Point GetScaledPosition(MouseEventArgs e)
{ {
var previewSettings = _deviceManager.ActiveKeyboard.PreviewSettings; var previewSettings = _deviceManager.ActiveKeyboard.PreviewSettings;
@ -723,6 +732,15 @@ namespace Artemis.ViewModels
return pos; return pos;
} }
private LayerModel GetHoverLayer(double x, double y)
{
// Prefer the selected layer as the hover layer even if it's underneath something else
if (SelectedLayer != null && SelectedLayer.Properties.PropertiesRect(1).Contains(x, y))
return SelectedLayer;
return GetLayers().Where(l => l.MustDraw()).FirstOrDefault(l => l.Properties.PropertiesRect(1).Contains(x, y));
}
public Cursor KeyboardPreviewCursor public Cursor KeyboardPreviewCursor
{ {
get { return _keyboardPreviewCursor; } get { return _keyboardPreviewCursor; }