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

Progress on layer editor

This commit is contained in:
SpoinkyNL 2016-03-24 23:26:23 +01:00
parent 2cb8cac90d
commit 99e9620db2
16 changed files with 566 additions and 283 deletions

View File

@ -274,7 +274,7 @@
<Compile Include="Models\EffectModel.cs" /> <Compile Include="Models\EffectModel.cs" />
<Compile Include="Models\EffectSettings.cs" /> <Compile Include="Models\EffectSettings.cs" />
<Compile Include="Models\GameSettings.cs" /> <Compile Include="Models\GameSettings.cs" />
<Compile Include="Models\Interfaces\IGameDataModel.cs" /> <Compile Include="Models\Interfaces\GameDataModel.cs" />
<Compile Include="Models\Profiles\LayerConditionModel.cs" /> <Compile Include="Models\Profiles\LayerConditionModel.cs" />
<Compile Include="Models\Profiles\LayerModel.cs" /> <Compile Include="Models\Profiles\LayerModel.cs" />
<Compile Include="Models\Profiles\LayerDynamicPropertiesModel.cs" /> <Compile Include="Models\Profiles\LayerDynamicPropertiesModel.cs" />
@ -383,6 +383,7 @@
<Compile Include="Utilities\GeneralHelpers.cs" /> <Compile Include="Utilities\GeneralHelpers.cs" />
<Compile Include="Utilities\ImageUtilities.cs" /> <Compile Include="Utilities\ImageUtilities.cs" />
<Compile Include="Utilities\Keyboard\KeyboardHook.cs" /> <Compile Include="Utilities\Keyboard\KeyboardHook.cs" />
<Compile Include="Utilities\LayerDrawer.cs" />
<Compile Include="Utilities\LogitechDll\DllManager.cs" /> <Compile Include="Utilities\LogitechDll\DllManager.cs" />
<Compile Include="Utilities\LogitechDll\NamedPipeServer.cs" /> <Compile Include="Utilities\LogitechDll\NamedPipeServer.cs" />
<Compile Include="Utilities\LogitechDll\PipeServer.cs" /> <Compile Include="Utilities\LogitechDll\PipeServer.cs" />
@ -409,6 +410,7 @@
<Compile Include="Modules\Games\Dota2\Dota2ViewModel.cs" /> <Compile Include="Modules\Games\Dota2\Dota2ViewModel.cs" />
<Compile Include="Modules\Games\RocketLeague\RocketLeagueViewModel.cs" /> <Compile Include="Modules\Games\RocketLeague\RocketLeagueViewModel.cs" />
<Compile Include="Modules\Games\Witcher3\Witcher3ViewModel.cs" /> <Compile Include="Modules\Games\Witcher3\Witcher3ViewModel.cs" />
<Compile Include="ViewModels\LayerEditorViewModel.cs" />
<Compile Include="ViewModels\OverlaysViewModel.cs" /> <Compile Include="ViewModels\OverlaysViewModel.cs" />
<Compile Include="Modules\Overlays\VolumeDisplay\VolumeDisplayViewModel.cs" /> <Compile Include="Modules\Overlays\VolumeDisplay\VolumeDisplayViewModel.cs" />
<Compile Include="ViewModels\ProfileEditorViewModel.cs" /> <Compile Include="ViewModels\ProfileEditorViewModel.cs" />
@ -448,6 +450,9 @@
<Compile Include="Modules\Games\Witcher3\Witcher3View.xaml.cs"> <Compile Include="Modules\Games\Witcher3\Witcher3View.xaml.cs">
<DependentUpon>Witcher3View.xaml</DependentUpon> <DependentUpon>Witcher3View.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Views\LayerEditorView.xaml.cs">
<DependentUpon>LayerEditorView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\OverlaysView.xaml.cs"> <Compile Include="Views\OverlaysView.xaml.cs">
<DependentUpon>OverlaysView.xaml</DependentUpon> <DependentUpon>OverlaysView.xaml</DependentUpon>
</Compile> </Compile>
@ -597,6 +602,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Views\LayerEditorView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\OverlaysView.xaml"> <Page Include="Views\OverlaysView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>

View File

@ -2,8 +2,6 @@
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Forms; using System.Windows.Forms;
using Artemis.Utilities;
using Artemis.Utilities.LogitechDll;
using Artemis.ViewModels; using Artemis.ViewModels;
using Autofac; using Autofac;
using Caliburn.Micro; using Caliburn.Micro;

View File

@ -1,22 +1,18 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq; using System.Linq;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging;
using Artemis.Models.Interfaces; using Artemis.Models.Interfaces;
using Artemis.Properties; using Artemis.Utilities;
using Newtonsoft.Json; using Newtonsoft.Json;
using Color = System.Drawing.Color;
using Pen = System.Drawing.Pen;
namespace Artemis.Models.Profiles namespace Artemis.Models.Profiles
{ {
public class LayerModel public class LayerModel
{ {
[JsonIgnore] private readonly LayerDrawer _drawer;
public LayerModel(string name, LayerType layerType) public LayerModel(string name, LayerType layerType)
{ {
Name = name; Name = name;
@ -27,56 +23,23 @@ namespace Artemis.Models.Profiles
Children = new List<LayerModel>(); Children = new List<LayerModel>();
LayerConditions = new List<LayerConditionModel>(); LayerConditions = new List<LayerConditionModel>();
LayerProperties = new List<LayerDynamicPropertiesModel>(); LayerProperties = new List<LayerDynamicPropertiesModel>();
_drawer = new LayerDrawer(this);
} }
public string Name { get; set; } public string Name { get; set; }
public LayerType LayerType { get; set; } public LayerType LayerType { get; set; }
public LayerPropertiesModel LayerUserProperties { get; set; } public LayerPropertiesModel LayerUserProperties { get; set; }
[JsonIgnore]
public LayerPropertiesModel LayerCalculatedProperties { get; }
public List<LayerModel> Children { get; set; } public List<LayerModel> Children { get; set; }
public List<LayerConditionModel> LayerConditions { get; set; } public List<LayerConditionModel> LayerConditions { get; set; }
public List<LayerDynamicPropertiesModel> LayerProperties { get; set; } public List<LayerDynamicPropertiesModel> LayerProperties { get; set; }
public ImageSource LayerImage => GetPreviewImage();
private BitmapImage GetPreviewImage() [JsonIgnore]
{ public LayerPropertiesModel LayerCalculatedProperties { get; }
var bitmap = new Bitmap(18, 18);
using (var g = Graphics.FromImage(bitmap))
{
g.SmoothingMode = SmoothingMode.AntiAlias;
if (LayerType == LayerType.Ellipse)
{
g.FillEllipse(new SolidBrush(LayerUserProperties.Colors.FirstOrDefault()), 0, 0, 18, 18);
g.DrawEllipse(new Pen(Color.Black, 1), 0, 0, 17, 17);
}
else if (LayerType == LayerType.Rectangle)
{
g.FillRectangle(new SolidBrush(LayerUserProperties.Colors.FirstOrDefault()), 0, 0, 18, 18);
g.DrawRectangle(new Pen(Color.Black, 1), 0, 0, 17, 17);
}
else
{
bitmap = Resources.folder;
}
}
using (var memory = new MemoryStream()) [JsonIgnore]
{ public ImageSource LayerImage => _drawer.GetPreviewImage();
bitmap.Save(memory, ImageFormat.Png);
memory.Position = 0;
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
return bitmapImage;
}
}
public bool ConditionsMet<T>(IGameDataModel dataModel) public bool ConditionsMet<T>(IGameDataModel dataModel)
{ {
@ -95,10 +58,10 @@ namespace Artemis.Models.Profiles
DrawChildren<T>(dataModel, g); DrawChildren<T>(dataModel, g);
break; break;
case LayerType.Rectangle: case LayerType.Rectangle:
DrawRectangle(g); _drawer.DrawRectangle(g);
break; break;
case LayerType.Ellipse: case LayerType.Ellipse:
DrawEllipse(g); _drawer.DrawEllipse(g);
break; break;
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
@ -107,6 +70,7 @@ namespace Artemis.Models.Profiles
private void Update<T>(IGameDataModel dataModel) private void Update<T>(IGameDataModel dataModel)
{ {
GeneralHelpers.CopyProperties(LayerCalculatedProperties, LayerUserProperties);
foreach (var dynamicProperty in LayerProperties) foreach (var dynamicProperty in LayerProperties)
dynamicProperty.ApplyProperty<T>(dataModel, LayerUserProperties, LayerCalculatedProperties); dynamicProperty.ApplyProperty<T>(dataModel, LayerUserProperties, LayerCalculatedProperties);
} }
@ -116,14 +80,6 @@ namespace Artemis.Models.Profiles
foreach (var layerModel in Children) foreach (var layerModel in Children)
layerModel.Draw<T>(dataModel, g); layerModel.Draw<T>(dataModel, g);
} }
private void DrawRectangle(Graphics g)
{
}
private void DrawEllipse(Graphics g)
{
}
} }
public enum LayerType public enum LayerType

View File

@ -1,9 +1,12 @@
using Artemis.Models.Interfaces; using System.Collections.Generic;
using Artemis.Models.Interfaces;
using Artemis.Utilities;
namespace Artemis.Modules.Games.RocketLeague namespace Artemis.Modules.Games.RocketLeague
{ {
internal class RocketLeagueDataModel : IGameDataModel internal class RocketLeagueDataModel : IGameDataModel
{ {
public int Boost { get; set; } public int Boost { get; set; }
public List<GeneralHelpers.PropertyCollection> Properties { get; }
} }
} }

View File

@ -1,30 +1,29 @@
 using System.Collections.Generic; using Artemis.Models.Interfaces;
using Artemis.Models.Interfaces;
namespace Artemis.Modules.Games.TheDivision namespace Artemis.Modules.Games.TheDivision
{ {
public class TheDivisionDataModel : IGameDataModel public class TheDivisionDataModel : IGameDataModel
{ {
public List<DivisionPlayer> DivisionPlayers { get; set; }
public GrenadeState GrenadeState { get; set; }
public bool LowAmmo { get; set; }
public bool LowHp { get; set; }
public TheDivisionDataModel() public TheDivisionDataModel()
{ {
DivisionPlayers = new List<DivisionPlayer>(); TestyTest = new TestTest();
}
} }
public class DivisionPlayer public PlayerState PartyMember1 { get; set; }
{ public PlayerState PartyMember2 { get; set; }
public int Id { get; set; } public PlayerState PartyMember3 { get; set; }
public PlayerState PlayerState { get; set; }
public DivisionPlayer(int id) public bool LowAmmo { get; set; }
{ public bool LowHp { get; set; }
Id = id; public GrenadeState GrenadeState { get; set; }
public TestTest TestyTest { get; set; }
} }
public class TestTest
{
public string TestS { get; set; }
public int TestI { get; set; }
} }
public enum GrenadeState public enum GrenadeState

View File

@ -1,14 +1,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Linq;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Models; using Artemis.Models;
using Artemis.Modules.Effects.TypeWave; using Artemis.Modules.Effects.TypeWave;
using Artemis.Utilities; using Artemis.Utilities;
using Artemis.Utilities.Keyboard; using Artemis.Utilities.Keyboard;
using Artemis.Utilities.LogitechDll; using Artemis.Utilities.LogitechDll;
using CUE.NET;
namespace Artemis.Modules.Games.TheDivision namespace Artemis.Modules.Games.TheDivision
{ {
@ -95,8 +93,6 @@ namespace Artemis.Modules.Games.TheDivision
DllManager.PlaceDll(); DllManager.PlaceDll();
_dataModel = new TheDivisionDataModel(); _dataModel = new TheDivisionDataModel();
for (var i = 1; i < 5; i++)
_dataModel.DivisionPlayers.Add(new DivisionPlayer(i));
MainManager.PipeServer.PipeMessage += PipeServerOnPipeMessage; MainManager.PipeServer.PipeMessage += PipeServerOnPipeMessage;
Initialized = true; Initialized = true;
@ -129,16 +125,21 @@ namespace Artemis.Modules.Games.TheDivision
if (keyCode >= 59 && keyCode <= 62) if (keyCode >= 59 && keyCode <= 62)
{ {
var playerId = keyCode - 58; var playerId = keyCode - 58;
var playerDataModel = _dataModel.DivisionPlayers.FirstOrDefault(p => p.Id == playerId);
if (playerDataModel == null)
return;
PlayerState newState;
if (gPer > 10) if (gPer > 10)
playerDataModel.PlayerState = PlayerState.Online; newState = PlayerState.Online;
else if (rPer > 10) else if (rPer > 10)
playerDataModel.PlayerState = PlayerState.Hit; newState = PlayerState.Hit;
else else
playerDataModel.PlayerState = PlayerState.Offline; newState = PlayerState.Offline;
if (playerId == 1)
_dataModel.PartyMember1 = newState;
else if (playerId == 2)
_dataModel.PartyMember2 = newState;
else if (playerId == 3)
_dataModel.PartyMember3 = newState;
} }
// R blinks white when low on ammo // R blinks white when low on ammo
else if (keyCode == 19) else if (keyCode == 19)
@ -182,23 +183,23 @@ namespace Artemis.Modules.Games.TheDivision
? new List<Color> {Color.Red, Color.Orange} ? new List<Color> {Color.Red, Color.Orange}
: new List<Color> {Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45)}; : new List<Color> {Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45)};
if (_dataModel.DivisionPlayers[1].PlayerState == PlayerState.Offline) if (_dataModel.PartyMember1 == PlayerState.Offline)
_p2.Colors = new List<Color> {Color.Gray, Color.White}; _p2.Colors = new List<Color> {Color.Gray, Color.White};
else if (_dataModel.DivisionPlayers[1].PlayerState == PlayerState.Online) else if (_dataModel.PartyMember1 == PlayerState.Online)
_p2.Colors = new List<Color> {Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45)}; _p2.Colors = new List<Color> {Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45)};
else else
_p2.Colors = new List<Color> {Color.Red, Color.Orange}; _p2.Colors = new List<Color> {Color.Red, Color.Orange};
if (_dataModel.DivisionPlayers[2].PlayerState == PlayerState.Offline) if (_dataModel.PartyMember2 == PlayerState.Offline)
_p3.Colors = new List<Color> {Color.Gray, Color.White}; _p3.Colors = new List<Color> {Color.Gray, Color.White};
else if (_dataModel.DivisionPlayers[2].PlayerState == PlayerState.Online) else if (_dataModel.PartyMember2 == PlayerState.Online)
_p3.Colors = new List<Color> {Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45)}; _p3.Colors = new List<Color> {Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45)};
else else
_p3.Colors = new List<Color> {Color.Red, Color.Orange}; _p3.Colors = new List<Color> {Color.Red, Color.Orange};
if (_dataModel.DivisionPlayers[3].PlayerState == PlayerState.Offline) if (_dataModel.PartyMember3 == PlayerState.Offline)
_p4.Colors = new List<Color> {Color.Gray, Color.White}; _p4.Colors = new List<Color> {Color.Gray, Color.White};
else if (_dataModel.DivisionPlayers[3].PlayerState == PlayerState.Online) else if (_dataModel.PartyMember3 == PlayerState.Online)
_p4.Colors = new List<Color> {Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45)}; _p4.Colors = new List<Color> {Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45)};
else else
_p4.Colors = new List<Color> {Color.Red, Color.Orange}; _p4.Colors = new List<Color> {Color.Red, Color.Orange};

View File

@ -17,10 +17,10 @@ namespace Artemis.Modules.Games.TheDivision
GameModel = new TheDivisionModel(mainManager, (TheDivisionSettings) GameSettings); GameModel = new TheDivisionModel(mainManager, (TheDivisionSettings) GameSettings);
MainManager.EffectManager.EffectModels.Add(GameModel); MainManager.EffectManager.EffectModels.Add(GameModel);
ProfileEditor = new ProfileEditorViewModel(MainManager, GameModel); ProfileEditor = new ProfileEditorViewModel<TheDivisionDataModel>(MainManager, GameModel);
} }
public ProfileEditorViewModel ProfileEditor { get; set; } public ProfileEditorViewModel<TheDivisionDataModel> ProfileEditor { get; set; }
public static string Name => "The Division"; public static string Name => "The Division";
} }

View File

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Security.Principal; using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Artemis.Utilities namespace Artemis.Utilities
{ {
@ -44,5 +44,43 @@ namespace Artemis.Utilities
return wp.IsInRole(WindowsBuiltInRole.Administrator); return wp.IsInRole(WindowsBuiltInRole.Administrator);
} }
public static void CopyProperties(object dest, object src)
{
foreach (PropertyDescriptor item in TypeDescriptor.GetProperties(src))
{
item.SetValue(dest, item.GetValue(src));
}
}
public static List<PropertyCollection> GetPropertyMap(object o)
{
var res = new List<PropertyCollection>();
// No point reinventing the wheel, just serialize it to JSON and parse that
var json = JObject.FromObject(o, JsonSerializer.CreateDefault());
res.AddRange(JObjectToPropertyCollection(json));
return res;
}
private static List<PropertyCollection> JObjectToPropertyCollection(JObject json)
{
var res = new List<PropertyCollection>();
foreach (var property in json.Properties())
{
var parent = new PropertyCollection {Name = property.Name};
foreach (var child in property.Children<JObject>())
parent.Children = JObjectToPropertyCollection(child);
res.Add(parent);
}
return res;
}
public struct PropertyCollection
{
public string Name { get; set; }
public List<PropertyCollection> Children { get; set; }
}
} }
} }

View File

@ -0,0 +1,173 @@
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Windows.Media.Imaging;
using Artemis.Models.Profiles;
using Artemis.Properties;
namespace Artemis.Utilities
{
internal class LayerDrawer
{
private readonly LayerModel _layerModel;
private Rectangle _rectangle;
private double _rotationProgress;
private Rectangle _userRectangle;
public LayerDrawer(LayerModel layerModel)
{
_layerModel = layerModel;
_rotationProgress = 0;
}
public void Draw(Graphics graphics)
{
_rectangle = new Rectangle(
_layerModel.LayerCalculatedProperties.X,
_layerModel.LayerCalculatedProperties.Y,
_layerModel.LayerCalculatedProperties.Width,
_layerModel.LayerCalculatedProperties.Height);
_userRectangle = new Rectangle(
_layerModel.LayerUserProperties.X,
_layerModel.LayerUserProperties.Y,
_layerModel.LayerUserProperties.Width,
_layerModel.LayerUserProperties.Height);
if (_layerModel.LayerType == LayerType.Ellipse)
DrawEllipse(graphics);
else if (_layerModel.LayerType == LayerType.Ellipse)
DrawRectangle(graphics);
// Update the rotation progress
_rotationProgress = _rotationProgress + _layerModel.LayerCalculatedProperties.RotateSpeed;
if (_layerModel.LayerCalculatedProperties.ContainedBrush && _rotationProgress > _rectangle.Width)
_rotationProgress = _layerModel.LayerCalculatedProperties.RotateSpeed;
else if (!_layerModel.LayerCalculatedProperties.ContainedBrush && _rotationProgress > _userRectangle.Width)
_rotationProgress = _layerModel.LayerCalculatedProperties.RotateSpeed;
}
public BitmapImage GetPreviewImage()
{
_rectangle = new Rectangle(0, 0, 18, 18);
_userRectangle = new Rectangle(0, 0, 18, 18);
_layerModel.LayerCalculatedProperties.Opacity = 255;
var brush = CreateGradientBrush(_layerModel.LayerUserProperties.Colors);
var bitmap = new Bitmap(18, 18);
using (var g = Graphics.FromImage(bitmap))
{
g.SmoothingMode = SmoothingMode.AntiAlias;
if (_layerModel.LayerType == LayerType.Ellipse)
{
g.FillEllipse(brush, _rectangle);
g.DrawEllipse(new Pen(Color.Black, 1), 0, 0, 17, 17);
}
else if (_layerModel.LayerType == LayerType.Rectangle)
{
g.FillRectangle(brush, _rectangle);
g.DrawRectangle(new Pen(Color.Black, 1), 0, 0, 17, 17);
}
else
bitmap = Resources.folder;
}
using (var memory = new MemoryStream())
{
bitmap.Save(memory, ImageFormat.Png);
memory.Position = 0;
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
return bitmapImage;
}
}
public void DrawRectangle(Graphics graphics)
{
}
public void DrawEllipse(Graphics graphics)
{
}
private LinearGradientBrush CreateGradientBrush(List<Color> colors)
{
ColorBlend colorBlend;
var props = _layerModel.LayerCalculatedProperties;
// Create a ColorBlend
if (colors.Count == 0)
{
colorBlend = new ColorBlend
{
Colors = new[] {Color.Transparent, Color.Transparent},
Positions = new[] {0F, 1F}
};
}
else if (colors.Count == 1)
{
colorBlend = new ColorBlend
{
Colors = new[] {colors[0], colors[0]},
Positions = new[] {0F, 1F}
};
}
else
{
colorBlend = props.Rotate
? new ColorBlend {Colors = CreateTilebleColors(colors).ToArray()}
: new ColorBlend {Colors = colors.ToArray()};
}
// If needed, apply opacity to the colors in the blend
if (props.Opacity < 255)
for (var i = 0; i < colorBlend.Colors.Length; i++)
colorBlend.Colors[i] = Color.FromArgb(props.Opacity, colorBlend.Colors[i]);
// Devide the colors over the colorblend
var devider = (float) colorBlend.Colors.Length - 1;
var positions = new List<float>();
for (var i = 0; i < colorBlend.Colors.Length; i++)
positions.Add(i/devider);
// Apply the devided positions
colorBlend.Positions = positions.ToArray();
RectangleF rect;
if (props.Rotate)
rect = _layerModel.LayerCalculatedProperties.ContainedBrush
? new Rectangle((int) _rotationProgress + _rectangle.X, _rectangle.Y, _rectangle.Width*2,
_rectangle.Height*2)
: new Rectangle((int) _rotationProgress + _userRectangle.X, _userRectangle.Y, _userRectangle.Width*2,
_userRectangle.Height*2);
else
rect = _layerModel.LayerCalculatedProperties.ContainedBrush
? new Rectangle(_rectangle.X, _rectangle.Y, _rectangle.Width, _rectangle.Height)
: new Rectangle(_userRectangle.X, _userRectangle.Y, _userRectangle.Width, _userRectangle.Height);
return new LinearGradientBrush(rect, Color.Transparent, Color.Transparent,
_layerModel.LayerCalculatedProperties.GradientMode)
{
InterpolationColors = colorBlend
};
}
private List<Color> CreateTilebleColors(List<Color> sourceColors)
{
// Create a list using the original colors
var tilebleColors = new List<Color>(sourceColors);
// Add the original colors again
tilebleColors.AddRange(sourceColors);
// Add the first color, smoothing the transition
tilebleColors.Add(sourceColors.FirstOrDefault());
return tilebleColors;
}
}
}

View File

@ -0,0 +1,45 @@
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using Artemis.Models.Profiles;
using Artemis.Utilities;
using Caliburn.Micro;
namespace Artemis.ViewModels
{
public class LayerEditorViewModel<T> : Screen
{
private LayerModel _layer;
public LayerEditorViewModel(LayerModel layer)
{
Layer = layer;
DataModelProps = new BindableCollection<GeneralHelpers.PropertyCollection>();
DataModelProps.AddRange(GeneralHelpers.GetPropertyMap((T)Activator.CreateInstance(typeof(T), new object[] { })));
ProposedProperties = new LayerPropertiesModel();
GeneralHelpers.CopyProperties(ProposedProperties, Layer.LayerUserProperties);
}
public LayerModel Layer
{
get { return _layer; }
set
{
if (Equals(value, _layer)) return;
_layer = value;
NotifyOfPropertyChange(() => Layer);
}
}
public BindableCollection<GeneralHelpers.PropertyCollection> DataModelProps { get; set; }
public LayerPropertiesModel ProposedProperties { get; set; }
public void Apply()
{
GeneralHelpers.CopyProperties(Layer.LayerUserProperties, ProposedProperties);
}
}
}

View File

@ -1,25 +1,21 @@
using System.Collections.Generic; using System.Dynamic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq; using System.Linq;
using System.Windows.Media; using System.Windows.Media;
using Artemis.DAL; using Artemis.DAL;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Models; using Artemis.Models;
using Artemis.Models.Profiles; using Artemis.Models.Profiles;
using Artemis.Modules.Games.RocketLeague;
using Artemis.Modules.Games.TheDivision;
using Caliburn.Micro; using Caliburn.Micro;
using Color = System.Drawing.Color;
namespace Artemis.ViewModels namespace Artemis.ViewModels
{ {
public class ProfileEditorViewModel : Screen public class ProfileEditorViewModel<T> : Screen
{ {
private readonly GameModel _gameModel; private readonly GameModel _gameModel;
private readonly MainManager _mainManager; private readonly MainManager _mainManager;
private BindableCollection<ProfileModel> _profileModels; private BindableCollection<ProfileModel> _profileModels;
private ProfileModel _selectedProfileModel; private ProfileModel _selectedProfileModel;
private LayerEditorViewModel<T> _editorVm;
public ProfileEditorViewModel(MainManager mainManager, GameModel gameModel) public ProfileEditorViewModel(MainManager mainManager, GameModel gameModel)
{ {
@ -82,50 +78,22 @@ namespace Artemis.ViewModels
return; return;
} }
// Test
profile.Layers = new List<LayerModel>();
var layerFolder = new LayerModel("[VM TEST] Folder 1", LayerType.Folder);
var layer1 = new LayerModel("[VM TEST] Rectangle 1", LayerType.Rectangle);
layer1.LayerConditions.Add(new LayerConditionModel {Field = "Boost", Operator = ">", Value = "0"});
layer1.LayerProperties.Add(new LayerDynamicPropertiesModel
{
LayerProperty = "Width",
LayerPopertyType = LayerPopertyType.PercentageOf,
GameProperty = "Boost",
PercentageSource = "100"
});
layer1.LayerUserProperties = new LayerPropertiesModel
{
Colors = new List<Color> {Color.Red, Color.OrangeRed},
ContainedBrush = true,
GradientMode = LinearGradientMode.Vertical,
Width = 21,
Height = 7,
Opacity = 100,
Rotate = true,
RotateSpeed = 1,
X = 0,
Y = 0
};
layerFolder.Children.Add(layer1);
layerFolder.Children.Add(new LayerModel("[VM TEST] Ellipse 1", LayerType.Ellipse));
var testData = new RocketLeagueDataModel {Boost = 20};
var bitmap = _mainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(4);
using (var g = Graphics.FromImage(bitmap))
{
layerFolder.Draw<RocketLeagueDataModel>(testData, g);
}
// End test
profile.Layers.Add(layerFolder);
ProfileProvider.AddOrUpdate(profile); ProfileProvider.AddOrUpdate(profile);
LoadProfiles(); LoadProfiles();
SelectedProfileModel = profile; SelectedProfileModel = profile;
} }
public void LayerEditor(LayerModel layer)
{
IWindowManager manager = new WindowManager();
_editorVm = new LayerEditorViewModel<T>(layer);
dynamic settings = new ExpandoObject();
settings.Title = "Artemis | Edit " + layer.Name;
manager.ShowDialog(_editorVm, null, settings);
}
private ImageSource GenerateKeyboardImage() private ImageSource GenerateKeyboardImage()
{ {
return null; return null;

View File

@ -25,7 +25,6 @@ namespace Artemis.ViewModels
_shellViewModel.MainManager.Events.Subscribe(this); _shellViewModel.MainManager.Events.Subscribe(this);
_shellViewModel.MainManager.EnableProgram(); _shellViewModel.MainManager.EnableProgram();
_checkedForUpdate = false; _checkedForUpdate = false;
//ActiveIcon = "../logo.ico";
if (General.Default.ShowOnStartup) if (General.Default.ShowOnStartup)
ShowWindow(); ShowWindow();

View File

@ -0,0 +1,62 @@
<controls:MetroWindow x:Class="Artemis.Views.LayerEditorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Artemis.Views"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:cal="http://www.caliburnproject.org"
mc:Ignorable="d"
Title="Artemis | Edit Layer" Height="400" Width="600"
GlowBrush="{DynamicResource AccentColorBrush}" Icon="../logo.ico">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="10" FontSize="16" Text="Display if.." />
<ListBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
<ListBoxItem Margin="10, 0, 10, 0" Padding="10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- Left -->
<Border BorderThickness="1" BorderBrush="{DynamicResource GrayBrush6}">
<TreeView x:Name="ProfileTree" ItemsSource="{Binding Path=DataModelProps}" Width="200"
Height="100">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Border>
<!-- Center -->
<TextBlock Grid.Column="1" Text="is" VerticalAlignment="Top" HorizontalAlignment="Center"
Margin="0,3,0,0" />
<ComboBox Grid.Column="2" Width="60" IsEditable="True" MaxDropDownHeight="125"
Style="{DynamicResource VirtualisedMetroComboBox}" HorizontalAlignment="Center"
VerticalAlignment="Top" ItemsSource="{Binding Path=DataModelProps}" />
<TextBlock Grid.Column="3" Text="than" VerticalAlignment="Top" HorizontalAlignment="Center"
Margin="0,3,0,0" />
<!-- Right -->
<TextBox Grid.Column="4" Width="200" VerticalAlignment="Top" />
</Grid>
</ListBoxItem>
</ListBox>
</Grid>
</controls:MetroWindow>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MahApps.Metro.Controls;
namespace Artemis.Views
{
/// <summary>
/// Interaction logic for LayerEditorView.xaml
/// </summary>
public partial class LayerEditorView : MetroWindow
{
public LayerEditorView()
{
InitializeComponent();
}
}
}

View File

@ -4,6 +4,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.Views" xmlns:local="clr-namespace:Artemis.Views"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:cal="http://www.caliburnproject.org"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="772.5" d:DesignWidth="1335"> d:DesignHeight="772.5" d:DesignWidth="1335">
<Grid Width="Auto" Height="Auto"> <Grid Width="Auto" Height="Auto">
@ -38,29 +40,31 @@
<ComboBox Grid.Row="1" Grid.Column="1" Width="110" VerticalAlignment="Top" x:Name="ProfileModels" <ComboBox Grid.Row="1" Grid.Column="1" Width="110" VerticalAlignment="Top" x:Name="ProfileModels"
DisplayMemberPath="Name" Margin="5,0,0,0" /> DisplayMemberPath="Name" Margin="5,0,0,0" />
<Button x:Name="AddProfile" Content="Add profile" VerticalAlignment="Top" <Button x:Name="AddProfile" Content="Add profile" VerticalAlignment="Top"
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Left" Margin="10,0,0,0" /> Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Left"
Margin="10,0,0,0" />
<Button x:Name="RemoveProfile" Content="Remove profile" VerticalAlignment="Top" <Button x:Name="RemoveProfile" Content="Remove profile" VerticalAlignment="Top"
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Right" Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Right"
Margin="10,0,0,0" /> Margin="10,0,0,0" />
</StackPanel> </StackPanel>
<!-- Layer list --> <!-- Layer list -->
<Label Grid.Column="1" Grid.Row="0" FontSize="20" HorizontalAlignment="Left" Content="Layers" Margin="10,0,0,0" /> <Label Grid.Column="1" Grid.Row="0" FontSize="20" HorizontalAlignment="Left" Content="Layers"
Margin="10,0,0,0" />
<Border Grid.Column="1" Grid.Row="1" Background="#FF232323" BorderBrush="{DynamicResource HighlightBrush}" <Border Grid.Column="1" Grid.Row="1" Background="#FF232323" BorderBrush="{DynamicResource HighlightBrush}"
BorderThickness="3" Margin="10,0,0,0" Height="400" Width="250"> BorderThickness="3" Margin="10,0,0,0" Height="400" Width="250">
<TreeView ItemsSource="{Binding Path=SelectedProfileModel.Layers}"> <TreeView x:Name="ProfileTree" ItemsSource="{Binding Path=SelectedProfileModel.Layers}">
<TreeView.Resources> <TreeView.Resources>
<ResourceDictionary <ResourceDictionary
Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" /> Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
</TreeView.Resources> </TreeView.Resources>
<TreeView.ItemTemplate> <TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}"> <HierarchicalDataTemplate ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal" Tag="{Binding DataContext, ElementName=ProfileTree}">
<StackPanel.ContextMenu> <StackPanel.ContextMenu>
<ContextMenu> <ContextMenu cal:Action.TargetWithoutContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}">
<MenuItem Header="Rename" /> <MenuItem Header="Rename" />
<MenuItem Header="Delete" /> <MenuItem Header="Delete" />
<MenuItem Header="Properties" /> <MenuItem Header="Properties" cal:Message.Attach="LayerEditor($datacontext)"/>
</ContextMenu> </ContextMenu>
</StackPanel.ContextMenu> </StackPanel.ContextMenu>
<CheckBox VerticalAlignment="Center" ToolTip="Layer enabled" /> <CheckBox VerticalAlignment="Center" ToolTip="Layer enabled" />