diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 32e761669..b0e05c345 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -306,9 +306,11 @@ - - + + + + @@ -420,7 +422,8 @@ - + + @@ -451,10 +454,12 @@ - + + + @@ -491,8 +496,8 @@ Witcher3View.xaml - - LayerKeyboardView.xaml + + KeyboardPropertiesView.xaml LayerConditionView.xaml @@ -503,8 +508,8 @@ LayerEditorView.xaml - - LayerMouseView.xaml + + MousePropertiesView.xaml OverlaysView.xaml @@ -673,7 +678,7 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile @@ -689,7 +694,7 @@ MSBuild:Compile Designer - + Designer MSBuild:Compile diff --git a/Artemis/Artemis/Managers/LoopManager.cs b/Artemis/Artemis/Managers/LoopManager.cs index a2ed94f53..f0e892a64 100644 --- a/Artemis/Artemis/Managers/LoopManager.cs +++ b/Artemis/Artemis/Managers/LoopManager.cs @@ -114,7 +114,7 @@ namespace Artemis.Managers if (renderEffect.Initialized == false) return; - // Update the current effect + // ApplyProperties the current effect if (renderEffect.Initialized) renderEffect.Update(); diff --git a/Artemis/Artemis/Managers/MainManager.cs b/Artemis/Artemis/Managers/MainManager.cs index 9afa9e00e..b24d99cc1 100644 --- a/Artemis/Artemis/Managers/MainManager.cs +++ b/Artemis/Artemis/Managers/MainManager.cs @@ -83,7 +83,6 @@ namespace Artemis.Managers _logger.Debug("Shutting down MainManager"); LoopManager.Stop(); ProcessWorker.CancelAsync(); - ProcessWorker.CancelAsync(); GameStateWebServer.Stop(); PipeServer.Stop(); } diff --git a/Artemis/Artemis/Models/Profiles/LayerDynamicPropertiesModel.cs b/Artemis/Artemis/Models/Profiles/LayerDynamicPropertiesModel.cs deleted file mode 100644 index 3740627b6..000000000 --- a/Artemis/Artemis/Models/Profiles/LayerDynamicPropertiesModel.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System.ComponentModel; -using Artemis.Models.Interfaces; -using Artemis.Utilities; -using static System.Decimal; - -namespace Artemis.Models.Profiles -{ - public class LayerDynamicPropertiesModel - { - /// - /// Property this dynamic property applies on - /// - public string LayerProperty { get; set; } - - /// - /// Property to base the percentage upon - /// - public string GameProperty { get; set; } - - /// - /// Percentage source, the number that defines 100% - /// - public string PercentageSource { get; set; } - - /// - /// Type of property - /// - public LayerPropertyType LayerPropertyType { get; set; } - - internal void ApplyProperty(IGameDataModel data, LayerPropertiesModel userProps, LayerPropertiesModel props) - { - if (LayerPropertyType == LayerPropertyType.PercentageOf) - Apply(props, userProps, data, int.Parse(PercentageSource)); - if (LayerPropertyType == LayerPropertyType.PercentageOfProperty) - ApplyProp(props, userProps, data); - } - - private void Apply(LayerPropertiesModel props, LayerPropertiesModel userProps, IGameDataModel data, - int percentageSource) - { - // Property to apply on - var layerProp = props.GetType().GetProperty(LayerProperty); - // User's settings - var userProp = userProps.GetType().GetProperty(LayerProperty); - // Property to base the percentage upon - var gameProperty = data.GetPropValue(GameProperty); - if (layerProp == null || userProp == null) - return; - - var percentage = ToDouble(gameProperty)/percentageSource; - - // Opacity requires some special treatment as it causes an exception if it's < 0.0 or > 1.0 - if (LayerProperty == "Opacity") - { - var opacity = percentage*(double) userProp.GetValue(userProps, null); - if (opacity < 0.0) - opacity = 0.0; - if (opacity > 1.0) - opacity = 1.0; - layerProp.SetValue(props, opacity); - } - else - layerProp.SetValue(props, percentage*(double) userProp.GetValue(userProps, null)); - } - - private void ApplyProp(LayerPropertiesModel props, LayerPropertiesModel userProps, IGameDataModel data) - { - var value = data.GetPropValue(PercentageSource); - Apply(props, userProps, data, value); - } - } - - public enum LayerPropertyType - { - [Description("None")] None, - [Description("% of")] PercentageOf, - [Description("% of property")] PercentageOfProperty - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Models/Profiles/LayerModel.cs b/Artemis/Artemis/Models/Profiles/LayerModel.cs index 1d60ad829..7666d5621 100644 --- a/Artemis/Artemis/Models/Profiles/LayerModel.cs +++ b/Artemis/Artemis/Models/Profiles/LayerModel.cs @@ -1,106 +1,87 @@ -using System.Collections.Generic; -using System.ComponentModel; +using System.ComponentModel; using System.Linq; using System.Windows.Media; using System.Xml.Serialization; using Artemis.Models.Interfaces; +using Artemis.Models.Profiles.Properties; using Artemis.Utilities; +using Artemis.Utilities.Layers; using Artemis.Utilities.ParentChild; namespace Artemis.Models.Profiles { public class LayerModel : IChildItem, IChildItem { - [XmlIgnore] private readonly LayerDrawer _drawer; - [XmlIgnore] private bool _mustDraw; - public LayerModel() { - UserProps = new LayerPropertiesModel(); - CalcProps = new LayerPropertiesModel(); - Children = new ChildItemCollection(this); - LayerConditions = new List(); - LayerProperties = new List(); - - _mustDraw = true; - _drawer = new LayerDrawer(this, 4); } public string Name { get; set; } public LayerType LayerType { get; set; } - public string GifFile { get; set; } public bool Enabled { get; set; } public int Order { get; set; } - public LayerPropertiesModel UserProps { get; set; } - + public LayerPropertiesModel Properties { get; set; } public ChildItemCollection Children { get; } - public List LayerConditions { get; set; } - public List LayerProperties { get; set; } [XmlIgnore] - public LayerPropertiesModel CalcProps { get; set; } + public ImageSource LayerImage => GetThumbnail(); [XmlIgnore] - public ImageSource LayerImage => _drawer.GetThumbnail(); + public LayerModel Parent { get; internal set; } [XmlIgnore] - public LayerModel ParentLayer { get; internal set; } - + public ProfileModel Profile { get; internal set; } [XmlIgnore] - public ProfileModel ParentProfile { get; internal set; } + public GifImage GifImage { get; set; } public bool ConditionsMet(IGameDataModel dataModel) { - return Enabled && LayerConditions.All(cm => cm.ConditionMet(dataModel)); - } - - public void DrawPreview(DrawingContext c) - { - GeneralHelpers.CopyProperties(CalcProps, UserProps); - if (LayerType == LayerType.Keyboard || LayerType == LayerType.Keyboard) - _drawer.Draw(c, _mustDraw); - else if (LayerType == LayerType.KeyboardGif) - _drawer.DrawGif(c, _mustDraw); - _mustDraw = false; + return Enabled && Properties.Conditions.All(cm => cm.ConditionMet(dataModel)); } public void Draw(IGameDataModel dataModel, DrawingContext c, bool preview = false) { - // Conditions aren't checked during a preview because there is no game data to base them on + // Don't draw when the layer is disabled + if (!Enabled) + return; + + // Preview simply shows the properties as they are. When not previewing they are applied + LayerPropertiesModel properties; if (!preview) + { if (!ConditionsMet(dataModel)) - return; + return; // Don't draw the layer when not previewing and the conditions arent met + properties = Properties.GetAppliedProperties(dataModel); + } + else + properties = GeneralHelpers.Clone(Properties); - if (LayerType == LayerType.Folder) - foreach (var layerModel in Children.OrderByDescending(l => l.Order)) - layerModel.Draw(dataModel, c); - else if (LayerType == LayerType.Keyboard || LayerType == LayerType.Keyboard) - _drawer.Draw(c); - else if (LayerType == LayerType.KeyboardGif) - _drawer.DrawGif(c); - else if (LayerType == LayerType.Mouse) - _drawer.UpdateMouse(); - else if (LayerType == LayerType.Headset) - _drawer.UpdateHeadset(); - } + // Update animations on layer types that support them + if (LayerType == LayerType.Keyboard || LayerType == LayerType.KeyboardGif) + AnimationUpdater.UpdateAnimation((KeyboardPropertiesModel) properties); - public void Update(IGameDataModel dataModel, bool preview = false) - { + // Folders are drawn recursively if (LayerType == LayerType.Folder) { - foreach (var layerModel in Children) - layerModel.Update(dataModel); - return; + foreach (var layerModel in Children.OrderByDescending(l => l.Order)) + layerModel.Draw(dataModel, c); } + // All other types are handles by the Drawer helper + else if (LayerType == LayerType.Keyboard) + Drawer.Draw(c, (KeyboardPropertiesModel) properties); + else if (LayerType == LayerType.KeyboardGif) + Drawer.DrawGif(c, (KeyboardPropertiesModel) properties, GifImage); + else if (LayerType == LayerType.Mouse) + Drawer.UpdateMouse(properties); + else if (LayerType == LayerType.Headset) + Drawer.UpdateHeadset(properties); + } - GeneralHelpers.CopyProperties(CalcProps, UserProps); - - // Dynamic properties aren't applied during preview because there is no game data to base them on - if (preview) - return; - foreach (var dynamicProperty in LayerProperties) - dynamicProperty.ApplyProperty(dataModel, UserProps, CalcProps); + private ImageSource GetThumbnail() + { + // TODO + return null; } public void Reorder(LayerModel selectedLayer, bool moveUp) @@ -133,14 +114,14 @@ namespace Artemis.Models.Profiles LayerModel IChildItem.Parent { - get { return ParentLayer; } - set { ParentLayer = value; } + get { return Parent; } + set { Parent = value; } } ProfileModel IChildItem.Parent { - get { return ParentProfile; } - set { ParentProfile = value; } + get { return Profile; } + set { Profile = value; } } #endregion diff --git a/Artemis/Artemis/Models/Profiles/LayerPropertiesModel.cs b/Artemis/Artemis/Models/Profiles/LayerPropertiesModel.cs deleted file mode 100644 index 745997fa1..000000000 --- a/Artemis/Artemis/Models/Profiles/LayerPropertiesModel.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.ComponentModel; -using System.Windows; -using System.Windows.Media; -using System.Xml.Serialization; - -namespace Artemis.Models.Profiles -{ - [XmlInclude(typeof(SolidColorBrush))] - [XmlInclude(typeof(LinearGradientBrush))] - [XmlInclude(typeof(RadialGradientBrush))] - [XmlInclude(typeof(MatrixTransform))] - public class LayerPropertiesModel - { - public double X { get; set; } - public double Y { get; set; } - public double Width { get; set; } - public double Height { get; set; } - public double Opacity { get; set; } - public bool ContainedBrush { get; set; } - public LayerAnimation Animation { get; set; } - public double AnimationSpeed { get; set; } - public Brush Brush { get; set; } - - public Rect GetRect(int scale = 4) - { - return new Rect(X*scale, Y*scale, Width*scale, Height*scale); - } - } - - - public enum LayerAnimation - { - [Description("None")] None, - [Description("Slide left")] SlideLeft, - [Description("Slide right")] SlideRight, - [Description("Slide up")] SlideUp, - [Description("Slide down")] SlideDown, - [Description("Grow")] Grow, - [Description("Pulse")] Pulse - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Models/Profiles/ProfileModel.cs b/Artemis/Artemis/Models/Profiles/ProfileModel.cs index 27edc4e12..03cb2bea2 100644 --- a/Artemis/Artemis/Models/Profiles/ProfileModel.cs +++ b/Artemis/Artemis/Models/Profiles/ProfileModel.cs @@ -2,7 +2,9 @@ using System.Linq; using System.Windows; using System.Windows.Media; +using System.Xml.Serialization; using Artemis.Models.Interfaces; +using Artemis.Models.Profiles.Properties; using Artemis.Utilities; using Artemis.Utilities.ParentChild; using Color = System.Windows.Media.Color; @@ -22,12 +24,14 @@ namespace Artemis.Models.Profiles public string Name { get; set; } public string KeyboardName { get; set; } public string GameName { get; set; } + + [XmlIgnore] public DrawingVisual DrawingVisual { get; set; } - - + protected bool Equals(ProfileModel other) { - return string.Equals(Name, other.Name) && string.Equals(KeyboardName, other.KeyboardName) && + return string.Equals(Name, other.Name) && + string.Equals(KeyboardName, other.KeyboardName) && string.Equals(GameName, other.GameName); } @@ -62,7 +66,7 @@ namespace Artemis.Models.Profiles Enabled = true, Order = -1, LayerType = LayerType.Keyboard, - UserProps = new LayerPropertiesModel + Properties = new KeyboardPropertiesModel { Brush = new SolidColorBrush(ColorHelpers.GetRandomRainbowMediaColor()), Animation = LayerAnimation.None, diff --git a/Artemis/Artemis/Models/Profiles/Properties/DynamicPropertiesModel.cs b/Artemis/Artemis/Models/Profiles/Properties/DynamicPropertiesModel.cs new file mode 100644 index 000000000..952a55b6f --- /dev/null +++ b/Artemis/Artemis/Models/Profiles/Properties/DynamicPropertiesModel.cs @@ -0,0 +1,85 @@ +using System.ComponentModel; +using Artemis.Models.Interfaces; +using Artemis.Utilities; +using static System.Decimal; + +namespace Artemis.Models.Profiles.Properties +{ + public class DynamicPropertiesModel + { + /// + /// Property this dynamic property applies on + /// + public string LayerProperty { get; set; } + + /// + /// Property to base the percentage upon + /// + public string GameProperty { get; set; } + + /// + /// Percentage source, the number that defines 100% + /// + public double PercentageSource { get; set; } + + /// + /// Percentage source property, the property that defines 100% + /// + public string PercentageProperty { get; set; } + + /// + /// Type of property + /// + public LayerPropertyType LayerPropertyType { get; set; } + + + + + internal void ApplyProperty(IGameDataModel dataModel, KeyboardPropertiesModel properties) + { + if (LayerPropertyType == LayerPropertyType.PercentageOf) + ApplyPercentageOf(dataModel, properties, PercentageSource); + if (LayerPropertyType == LayerPropertyType.PercentageOfProperty) + ApplyPercentageOfProperty(dataModel, properties); + } + + private void ApplyPercentageOf(IGameDataModel dataModel, KeyboardPropertiesModel properties, + double percentageSource) + { + // Property to apply on + var layerProp = properties.GetType().GetProperty(LayerProperty); + // Property to base the percentage upon + var gameProperty = dataModel.GetPropValue(GameProperty); + + if (layerProp == null) + return; + + var percentage = ToDouble(gameProperty)/percentageSource; + var appliedValue = percentage*(double) layerProp.GetValue(layerProp, null); + + // Opacity requires some special treatment as it causes an exception if it's < 0.0 or > 1.0 + if (LayerProperty == "Opacity") + { + if (appliedValue < 0.0) + appliedValue = 0.0; + if (appliedValue > 1.0) + appliedValue = 1.0; + } + + layerProp.SetValue(layerProp, appliedValue); + } + + private void ApplyPercentageOfProperty(IGameDataModel dataModel, KeyboardPropertiesModel properties) + { + var value = dataModel.GetPropValue(PercentageProperty); + ApplyPercentageOf(dataModel, properties, value); + } + } + + public enum LayerPropertyType + { + [Description("None")] None, + [Description("% of")] PercentageOf, + [Description("% of property")] PercentageOfProperty + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Models/Profiles/Properties/KeyboardPropertiesModel.cs b/Artemis/Artemis/Models/Profiles/Properties/KeyboardPropertiesModel.cs new file mode 100644 index 000000000..8a3dc7be1 --- /dev/null +++ b/Artemis/Artemis/Models/Profiles/Properties/KeyboardPropertiesModel.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using System.ComponentModel; +using System.Windows; +using System.Xml.Serialization; +using Artemis.Models.Interfaces; +using Artemis.Utilities; + +namespace Artemis.Models.Profiles.Properties +{ + public class KeyboardPropertiesModel : LayerPropertiesModel + { + public KeyboardPropertiesModel() + { + DynamicProperties = new List(); + } + + public double X { get; set; } + public double Y { get; set; } + public double Width { get; set; } + public double Height { get; set; } + public double Opacity { get; set; } + public bool Contain { get; set; } + public LayerAnimation Animation { get; set; } + public double AnimationSpeed { get; set; } + public string GifFile { get; set; } + public List DynamicProperties { get; set; } + + [XmlIgnore] + public int AnimationProgress { get; set; } + + public Rect GetRect(int scale = 4) + { + return new Rect(X*scale, Y*scale, Width*scale, Height*scale); + } + + public override LayerPropertiesModel GetAppliedProperties(IGameDataModel dataModel) + { + var properties = GeneralHelpers.Clone(this); + + foreach (var dynamicProperty in properties.DynamicProperties) + dynamicProperty.ApplyProperty(dataModel, properties); + properties.Brush.Opacity = Opacity; + + return properties; + } + } + + public enum LayerAnimation + { + [Description("None")] None, + [Description("Slide left")] SlideLeft, + [Description("Slide right")] SlideRight, + [Description("Slide up")] SlideUp, + [Description("Slide down")] SlideDown, + [Description("Grow")] Grow, + [Description("Pulse")] Pulse + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Models/Profiles/Properties/LayerPropertiesModel.cs b/Artemis/Artemis/Models/Profiles/Properties/LayerPropertiesModel.cs new file mode 100644 index 000000000..5e09bcc17 --- /dev/null +++ b/Artemis/Artemis/Models/Profiles/Properties/LayerPropertiesModel.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.Windows.Media; +using System.Xml.Serialization; +using Artemis.Models.Interfaces; + +namespace Artemis.Models.Profiles.Properties +{ + [XmlInclude(typeof(SolidColorBrush))] + [XmlInclude(typeof(LinearGradientBrush))] + [XmlInclude(typeof(RadialGradientBrush))] + [XmlInclude(typeof(MatrixTransform))] + [XmlInclude(typeof(KeyboardPropertiesModel))] + [XmlInclude(typeof(MousePropertiesModel))] + public abstract class LayerPropertiesModel + { + protected LayerPropertiesModel() + { + Conditions = new List(); + } + + public abstract LayerPropertiesModel GetAppliedProperties(IGameDataModel dataModel); + + public List Conditions { get; set; } + public Brush Brush { get; set; } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Models/Profiles/Properties/MousePropertiesModel.cs b/Artemis/Artemis/Models/Profiles/Properties/MousePropertiesModel.cs new file mode 100644 index 000000000..a64df1c3b --- /dev/null +++ b/Artemis/Artemis/Models/Profiles/Properties/MousePropertiesModel.cs @@ -0,0 +1,14 @@ +using Artemis.Models.Interfaces; +using Artemis.Utilities; + +namespace Artemis.Models.Profiles.Properties +{ + public class MousePropertiesModel : LayerPropertiesModel + { + public override LayerPropertiesModel GetAppliedProperties(IGameDataModel dataModel) + { + // TODO: Apply any properties, if applicable to mice in the first place. + return GeneralHelpers.Clone(this); + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs b/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs index ece8fae49..06a35dabe 100644 --- a/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs +++ b/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs @@ -31,11 +31,6 @@ namespace Artemis.Modules.Effects.ProfilePreview public override void Update() { - if (SelectedProfile == null) - return; - - foreach (var layerModel in SelectedProfile.Layers) - layerModel.Update(_previewDataModel, true); } public override Bitmap GenerateBitmap() diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs index a0bf77546..5fe39ca59 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs @@ -39,11 +39,7 @@ namespace Artemis.Modules.Games.CounterStrike public override void Update() { - if (Profile == null || GameDataModel == null) - return; - - foreach (var layerModel in Profile.Layers) - layerModel.Update(GameDataModel); + // TODO: Set up active weapon in the datamodel } public override Bitmap GenerateBitmap() diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs index 8eb5396f9..2032b3076 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs @@ -62,9 +62,6 @@ namespace Artemis.Modules.Games.RocketLeague ((RocketLeagueDataModel) GameDataModel).Boost = 0; if (((RocketLeagueDataModel) GameDataModel).Boost > 100) ((RocketLeagueDataModel) GameDataModel).Boost = 100; - - foreach (var layerModel in Profile.Layers) - layerModel.Update(GameDataModel); } public override Bitmap GenerateBitmap() diff --git a/Artemis/Artemis/Properties/AssemblyInfo.cs b/Artemis/Artemis/Properties/AssemblyInfo.cs index 9709b8516..f6e912e89 100644 --- a/Artemis/Artemis/Properties/AssemblyInfo.cs +++ b/Artemis/Artemis/Properties/AssemblyInfo.cs @@ -25,7 +25,7 @@ using System.Windows; //CultureYouAreCodingWith in your .csproj file //inside a . For example, if you are using US english //in your source files, set the to en-US. Then uncomment -//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the NeutralResourceLanguage attribute below. ApplyProperties the "en-US" in //the line below to match the UICulture setting in the project file. //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] diff --git a/Artemis/Artemis/Styles/ColorBox.xaml b/Artemis/Artemis/Styles/ColorBox.xaml index 39439d247..8eee66da0 100644 --- a/Artemis/Artemis/Styles/ColorBox.xaml +++ b/Artemis/Artemis/Styles/ColorBox.xaml @@ -446,11 +446,6 @@ - - -