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

Fixed GIFs and dynamic properties. LayerEditor now animates GIFs and animations

This commit is contained in:
SpoinkyNL 2016-05-18 00:46:31 +02:00
parent c8c4143e88
commit 6e451c06cd
17 changed files with 155 additions and 67 deletions

View File

@ -2,6 +2,7 @@
using System.Windows;
using System.Windows.Threading;
using Artemis.Utilities;
using NLog;
using WpfExceptionViewer;
namespace Artemis
@ -40,7 +41,6 @@ namespace Artemis
}
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = e.ExceptionObject as Exception;
@ -49,6 +49,8 @@ namespace Artemis
private static ExceptionViewer GetArtemisExceptionViewer(Exception e)
{
var logger = LogManager.GetCurrentClassLogger();
logger.Fatal(e, "Unhandled exception, showing dialog and shutting down.");
return new ExceptionViewer("An unexpected error occurred in Artemis.", e)
{
Title = "Artemis - Exception :c",

View File

@ -310,6 +310,7 @@
<Compile Include="Models\Profiles\Properties\DynamicPropertiesModel.cs" />
<Compile Include="Models\Profiles\Properties\KeyboardPropertiesModel.cs" />
<Compile Include="Models\Profiles\Properties\LayerPropertiesModel.cs" />
<Compile Include="Models\Profiles\Properties\GenericPropertiesModel.cs" />
<Compile Include="Models\Profiles\Properties\MousePropertiesModel.cs" />
<Compile Include="Modules\Effects\AmbientLightning\AmbientLightningEffectModel.cs" />
<Compile Include="Modules\Effects\AmbientLightning\AmbientLightningEffectSettings.cs" />

View File

@ -66,7 +66,7 @@ namespace Artemis.KeyboardProviders.Corsair
try
{
if (CueSDK.ProtocolDetails == null)
CueSDK.Initialize();
CueSDK.Initialize(true);
}
catch (WrapperException)
{

View File

@ -123,6 +123,12 @@ namespace Artemis.Managers
ActiveEffect = effectModel;
ActiveEffect.Enable();
if (!ActiveEffect.Initialized)
{
_logger.Debug("Cancelling effect change, couldn't initialize the effect ({0})", effectModel.Name);
ActiveEffect = null;
return;
}
}
if (loopManager != null && !loopManager.Running)

View File

@ -25,13 +25,14 @@ namespace Artemis.Models.Profiles
public ChildItemCollection<LayerModel, LayerModel> Children { get; }
[XmlIgnore]
public ImageSource LayerImage => GetThumbnail();
public ImageSource LayerImage => Drawer.DrawThumbnail(this);
[XmlIgnore]
public LayerModel Parent { get; internal set; }
[XmlIgnore]
public ProfileModel Profile { get; internal set; }
[XmlIgnore]
public GifImage GifImage { get; set; }
@ -47,19 +48,23 @@ namespace Artemis.Models.Profiles
return;
// Preview simply shows the properties as they are. When not previewing they are applied
LayerPropertiesModel properties;
LayerPropertiesModel appliedProperties;
if (!preview)
{
if (!ConditionsMet<T>(dataModel))
return; // Don't draw the layer when not previewing and the conditions arent met
properties = Properties.GetAppliedProperties(dataModel);
appliedProperties = Properties.GetAppliedProperties(dataModel);
}
else
properties = GeneralHelpers.Clone(Properties);
appliedProperties = GeneralHelpers.Clone(Properties);
// Update animations on layer types that support them
if (LayerType == LayerType.Keyboard || LayerType == LayerType.KeyboardGif)
AnimationUpdater.UpdateAnimation((KeyboardPropertiesModel) properties);
{
AnimationUpdater.UpdateAnimation((KeyboardPropertiesModel) Properties);
((KeyboardPropertiesModel) appliedProperties).AnimationProgress =
((KeyboardPropertiesModel) Properties).AnimationProgress;
}
// Folders are drawn recursively
if (LayerType == LayerType.Folder)
@ -69,19 +74,35 @@ namespace Artemis.Models.Profiles
}
// All other types are handles by the Drawer helper
else if (LayerType == LayerType.Keyboard)
Drawer.Draw(c, (KeyboardPropertiesModel) properties);
Drawer.Draw(c, (KeyboardPropertiesModel) appliedProperties);
else if (LayerType == LayerType.KeyboardGif)
Drawer.DrawGif(c, (KeyboardPropertiesModel) properties, GifImage);
GifImage = Drawer.DrawGif(c, (KeyboardPropertiesModel) appliedProperties, GifImage);
else if (LayerType == LayerType.Mouse)
Drawer.UpdateMouse(properties);
Drawer.UpdateMouse(appliedProperties);
else if (LayerType == LayerType.Headset)
Drawer.UpdateHeadset(properties);
Drawer.UpdateHeadset(appliedProperties);
}
private ImageSource GetThumbnail()
public void SetupProperties()
{
// TODO
return null;
if ((LayerType == LayerType.Keyboard || LayerType == LayerType.KeyboardGif) &&
!(Properties is KeyboardPropertiesModel))
{
Properties = new KeyboardPropertiesModel
{
Brush = new SolidColorBrush(ColorHelpers.GetRandomRainbowMediaColor()),
Animation = LayerAnimation.None,
Height = 1,
Width = 1,
X = 0,
Y = 0,
Opacity = 1
};
}
else if (LayerType == LayerType.Mouse && !(Properties is MousePropertiesModel))
Properties = new MousePropertiesModel();
else if (!(Properties is GenericPropertiesModel))
Properties = new GenericPropertiesModel();
}
public void Reorder(LayerModel selectedLayer, bool moveUp)

View File

@ -0,0 +1,13 @@
using Artemis.Models.Interfaces;
using Artemis.Utilities;
namespace Artemis.Models.Profiles.Properties
{
public class GenericPropertiesModel : LayerPropertiesModel
{
public override LayerPropertiesModel GetAppliedProperties(IGameDataModel dataModel)
{
return GeneralHelpers.Clone(this);
}
}
}

View File

@ -26,7 +26,7 @@ namespace Artemis.Models.Profiles.Properties
public List<DynamicPropertiesModel> DynamicProperties { get; set; }
[XmlIgnore]
public int AnimationProgress { get; set; }
public double AnimationProgress { get; set; }
public Rect GetRect(int scale = 4)
{

View File

@ -41,6 +41,9 @@ namespace Artemis.Modules.Games.RocketLeague
_pointer = JsonConvert.DeserializeObject<GamePointersCollection>(Offsets.Default.RocketLeague);
var tempProcess = MemoryHelpers.GetProcessIfRunning(ProcessName);
if (tempProcess == null)
return;
_memory = new Memory(tempProcess);
Initialized = true;

View File

@ -6,8 +6,15 @@
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >
<targets>
<target name="file" xsi:type="File" maxArchiveFiles="7" fileName="${specialfolder:folder=MyDocuments}/Artemis/logs/${shortdate}.txt"/>
<target name="debugger" xsi:type="Debugger" layout="${logger:shortName=True} - ${uppercase:${level}}: ${message}"/>
<target name="file"
xsi:type="File"
maxArchiveFiles="7"
fileName="${specialfolder:folder=MyDocuments}/Artemis/logs/${shortdate}.txt"
layout="${longdate}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}"/>
<target name="debugger"
xsi:type="Debugger"
layout="${logger:shortName=True} - ${uppercase:${level}}: ${message}"/>
</targets>
<rules>

View File

@ -446,6 +446,11 @@
<nc:GradientStopAdder Height="20" Focusable="False"
IsTabStop="False" FocusVisualStyle="{x:Null}"
ColorBox="{Binding RelativeSource={RelativeSource TemplatedParent}}">
<nc:GradientStopAdder.Background>
<LinearGradientBrush
GradientStops="{Binding Brush.GradientStops, RelativeSource={RelativeSource TemplatedParent}}"
StartPoint="0, .5" EndPoint="1, .5" />
</nc:GradientStopAdder.Background>
<Button.Style>
<Style TargetType="Button">
<Setter Property="Template">

View File

@ -47,8 +47,8 @@ namespace Artemis.Utilities.GameState
}
catch (HttpListenerException)
{
MessageBox.Show(
"Couldn't start the webserver. CS:GO/Dota2 effects won't work :c \n\nTry changing the port in Settings and restart Artemis.");
MessageBox.Show("Couldn't start the webserver. CS:GO/Dota2 effects won't work :c \n\n" +
"Try changing the port in Settings and restart Artemis.");
}
Running = true;

View File

@ -8,36 +8,36 @@ namespace Artemis.Utilities.Layers
public static void UpdateAnimation(KeyboardPropertiesModel properties)
{
const int scale = 4;
var progress = properties.AnimationProgress;
// Horizontal sliding
if (properties.Animation == LayerAnimation.SlideRight || properties.Animation == LayerAnimation.SlideLeft)
{
if (properties.AnimationProgress > properties.Width*scale)
properties.AnimationProgress = 0;
if (progress > properties.Width*scale)
progress = 0;
}
// Vertical sliding
if (properties.Animation == LayerAnimation.SlideDown || properties.Animation == LayerAnimation.SlideUp)
{
if (properties.AnimationProgress > properties.Height*scale)
properties.AnimationProgress = 0;
if (progress > properties.Height*scale)
progress = 0;
}
// Pulse animation
if (properties.Animation == LayerAnimation.Pulse)
{
var opac = (Math.Sin(properties.AnimationProgress*Math.PI) + 1)*(properties.Opacity/2);
properties.Opacity = opac;
if (properties.AnimationProgress > 2)
properties.AnimationProgress = 0;
if (progress > 2)
progress = 0;
properties.AnimationProgress = (int) (properties.AnimationProgress + properties.AnimationSpeed/2);
progress = progress + properties.AnimationSpeed/2;
}
else
{
// ApplyProperties the animation progress
properties.AnimationProgress = (int) (properties.AnimationProgress + properties.AnimationSpeed);
progress = progress + properties.AnimationSpeed * 2;
}
properties.AnimationProgress = progress;
}
}
}

View File

@ -1,4 +1,5 @@
using System.Drawing;
using System;
using System.Drawing;
using System.IO;
using System.Windows;
using System.Windows.Media;
@ -52,8 +53,13 @@ namespace Artemis.Utilities.Layers
private static void DrawRectangle(DrawingContext c, KeyboardPropertiesModel properties, Rect rectangle,
Rect slide1, Rect slide2)
{
// Apply the pulse animation
var brush = properties.Brush.CloneCurrentValue();
brush.Opacity = properties.Opacity;
if (properties.Animation == LayerAnimation.Pulse)
brush.Opacity = (Math.Sin(properties.AnimationProgress * Math.PI) + 1) * (properties.Opacity / 2);
else
brush.Opacity = properties.Opacity;
// TODO: Implement clipping modes
// Most animation types can be drawn regularly
@ -73,13 +79,13 @@ namespace Artemis.Utilities.Layers
}
}
public static void DrawGif(DrawingContext c, KeyboardPropertiesModel properties, GifImage gifImage,
public static GifImage DrawGif(DrawingContext c, KeyboardPropertiesModel properties, GifImage gifImage,
bool update = true)
{
if (string.IsNullOrEmpty(properties.GifFile))
return;
return null;
if (!File.Exists(properties.GifFile))
return;
return null;
const int scale = 4;
@ -94,6 +100,7 @@ namespace Artemis.Utilities.Layers
var draw = update ? gifImage.GetNextFrame() : gifImage.GetFrame(0);
c.DrawImage(ImageUtilities.BitmapToBitmapImage(new Bitmap(draw)), gifRect);
return gifImage;
}
public static void UpdateMouse(LayerPropertiesModel properties)
@ -104,7 +111,7 @@ namespace Artemis.Utilities.Layers
{
}
public static DrawingImage GetThumbnail(LayerModel layerModel)
public static ImageSource DrawThumbnail(LayerModel layerModel)
{
var thumbnailRect = new Rect(0, 0, 18, 18);
var visual = new DrawingVisual();

View File

@ -99,6 +99,18 @@ namespace Artemis.ViewModels.Abstract
GameModel.Profile = ProfileEditor.SelectedProfile;
ProfilePreviewModel.SelectedProfile = ProfileEditor.SelectedProfile;
}
protected override void OnActivate()
{
base.OnActivate();
ProfileEditor.PreviewTimer.Start();
}
protected override void OnDeactivate(bool close)
{
base.OnDeactivate(close);
ProfileEditor.PreviewTimer.Stop();
}
}
public delegate void OnLayersUpdatedCallback(object sender);

View File

@ -1,4 +1,6 @@
using Artemis.Models.Interfaces;
using System.Windows.Forms;
using Artemis.Models.Interfaces;
using Artemis.Models.Profiles;
using Artemis.Models.Profiles.Properties;
using Artemis.Utilities;
using Caliburn.Micro;
@ -24,6 +26,17 @@ namespace Artemis.ViewModels.LayerEditor
OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", DataModelProps, keyboardProperties);
}
public KeyboardPropertiesModel ProposedProperties
{
get { return _proposedProperties; }
set
{
if (Equals(value, _proposedProperties)) return;
_proposedProperties = value;
NotifyOfPropertyChange(() => ProposedProperties);
}
}
public bool IsGif
{
get { return _isGif; }
@ -36,24 +49,27 @@ namespace Artemis.ViewModels.LayerEditor
}
public bool ShowGif => IsGif;
public bool ShowBrush => !IsGif;
public BindableCollection<GeneralHelpers.PropertyCollection> DataModelProps { get; set; }
public LayerDynamicPropertiesViewModel HeightProperties { get; set; }
public LayerDynamicPropertiesViewModel WidthProperties { get; set; }
public LayerDynamicPropertiesViewModel OpacityProperties { get; set; }
public KeyboardPropertiesModel ProposedProperties
public void BrowseGif()
{
get { return _proposedProperties; }
set
{
if (Equals(value, _proposedProperties)) return;
_proposedProperties = value;
var dialog = new OpenFileDialog { Filter = "Animated image file (*.gif)|*.gif" };
var result = dialog.ShowDialog();
if (result != DialogResult.OK)
return;
ProposedProperties.GifFile = dialog.FileName;
NotifyOfPropertyChange(() => ProposedProperties);
}
}
public override LayerPropertiesModel GetAppliedProperties()
{

View File

@ -32,12 +32,14 @@ namespace Artemis.ViewModels.LayerEditor
Layer = layer;
Layer.Enabled = false;
if (Layer.Properties == null)
Layer.SetupProperties();
DataModelProps = new BindableCollection<GeneralHelpers.PropertyCollection>();
DataModelProps.AddRange(GeneralHelpers.GenerateTypeMap(gameDataModel));
LayerConditionVms = new BindableCollection<LayerConditionViewModel>(layer.Properties.Conditions
.Select(c => new LayerConditionViewModel(this, c, DataModelProps)));
PropertyChanged += PropertiesViewModelHandler;
PreSelect();
}
@ -120,7 +122,12 @@ namespace Artemis.ViewModels.LayerEditor
if (e.PropertyName != "LayerType")
return;
// Update the model
if (Layer.LayerType != LayerType)
{
Layer.LayerType = LayerType;
Layer.SetupProperties();
}
// Update the KeyboardPropertiesViewModel if it's being used
var model = LayerPropertiesViewModel as KeyboardPropertiesViewModel;
@ -166,16 +173,6 @@ namespace Artemis.ViewModels.LayerEditor
Layer.Properties.Conditions.Remove(layerConditionModel);
}
public void BrowseGif()
{
if (Layer.LayerType != LayerType.KeyboardGif)
return;
var dialog = new OpenFileDialog {Filter = "Animated image file (*.gif)|*.gif"};
var result = dialog.ShowDialog();
if (result == DialogResult.OK)
((KeyboardPropertiesModel) Layer.Properties).GifFile = dialog.FileName;
}
public override void CanClose(Action<bool> callback)
{
_layer.Enabled = _wasEnabled;

View File

@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Dynamic;
using System.Linq;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@ -46,6 +47,9 @@ namespace Artemis.ViewModels
Layers = new BindableCollection<LayerModel>();
events.Subscribe(this);
PreviewTimer = new Timer(40);
PreviewTimer.Elapsed += (sender, args) => NotifyOfPropertyChange(() => KeyboardPreview);
PropertyChanged += PropertyChangeHandler;
LoadProfiles();
}
@ -53,6 +57,8 @@ namespace Artemis.ViewModels
[Inject]
public MetroDialogService DialogService { get; set; }
public Timer PreviewTimer { get; set; }
public BindableCollection<ProfileModel> Profiles
{
get { return _profiles; }
@ -204,8 +210,6 @@ namespace Artemis.ViewModels
if (e.PropertyName == "KeyboardPreview")
return;
NotifyOfPropertyChange(() => KeyboardPreview);
if (SelectedProfile != null)
ProfileProvider.AddOrUpdate(SelectedProfile);
}
@ -262,11 +266,6 @@ namespace Artemis.ViewModels
SelectedProfile = profile;
}
public void ToggleEnabled(LayerModel layer)
{
NotifyOfPropertyChange(() => KeyboardPreview);
}
/// <summary>
/// Opens a new LayerEditorView for the given layer
/// </summary>
@ -496,7 +495,6 @@ namespace Artemis.ViewModels
draggingProps.X = (int) Math.Round(x - _draggingLayerOffset.Value.X);
draggingProps.Y = (int) Math.Round(y - _draggingLayerOffset.Value.Y);
}
NotifyOfPropertyChange(() => KeyboardPreview);
}
private bool ShouldDrawLayer(LayerModel layer)