1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +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\EffectSettings.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\LayerModel.cs" />
<Compile Include="Models\Profiles\LayerDynamicPropertiesModel.cs" />
@ -383,6 +383,7 @@
<Compile Include="Utilities\GeneralHelpers.cs" />
<Compile Include="Utilities\ImageUtilities.cs" />
<Compile Include="Utilities\Keyboard\KeyboardHook.cs" />
<Compile Include="Utilities\LayerDrawer.cs" />
<Compile Include="Utilities\LogitechDll\DllManager.cs" />
<Compile Include="Utilities\LogitechDll\NamedPipeServer.cs" />
<Compile Include="Utilities\LogitechDll\PipeServer.cs" />
@ -409,6 +410,7 @@
<Compile Include="Modules\Games\Dota2\Dota2ViewModel.cs" />
<Compile Include="Modules\Games\RocketLeague\RocketLeagueViewModel.cs" />
<Compile Include="Modules\Games\Witcher3\Witcher3ViewModel.cs" />
<Compile Include="ViewModels\LayerEditorViewModel.cs" />
<Compile Include="ViewModels\OverlaysViewModel.cs" />
<Compile Include="Modules\Overlays\VolumeDisplay\VolumeDisplayViewModel.cs" />
<Compile Include="ViewModels\ProfileEditorViewModel.cs" />
@ -448,6 +450,9 @@
<Compile Include="Modules\Games\Witcher3\Witcher3View.xaml.cs">
<DependentUpon>Witcher3View.xaml</DependentUpon>
</Compile>
<Compile Include="Views\LayerEditorView.xaml.cs">
<DependentUpon>LayerEditorView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\OverlaysView.xaml.cs">
<DependentUpon>OverlaysView.xaml</DependentUpon>
</Compile>
@ -597,6 +602,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\LayerEditorView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\OverlaysView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

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

View File

@ -1,22 +1,18 @@
using System;
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;
using System.Windows.Media.Imaging;
using Artemis.Models.Interfaces;
using Artemis.Properties;
using Artemis.Utilities;
using Newtonsoft.Json;
using Color = System.Drawing.Color;
using Pen = System.Drawing.Pen;
namespace Artemis.Models.Profiles
{
public class LayerModel
{
[JsonIgnore] private readonly LayerDrawer _drawer;
public LayerModel(string name, LayerType layerType)
{
Name = name;
@ -27,56 +23,23 @@ namespace Artemis.Models.Profiles
Children = new List<LayerModel>();
LayerConditions = new List<LayerConditionModel>();
LayerProperties = new List<LayerDynamicPropertiesModel>();
_drawer = new LayerDrawer(this);
}
public string Name { get; set; }
public LayerType LayerType { get; set; }
public LayerPropertiesModel LayerUserProperties { get; set; }
[JsonIgnore]
public LayerPropertiesModel LayerCalculatedProperties { get; }
public List<LayerModel> Children { get; set; }
public List<LayerConditionModel> LayerConditions { get; set; }
public List<LayerDynamicPropertiesModel> LayerProperties { get; set; }
public ImageSource LayerImage => GetPreviewImage();
private BitmapImage GetPreviewImage()
{
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;
}
}
[JsonIgnore]
public LayerPropertiesModel LayerCalculatedProperties { get; }
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;
}
}
[JsonIgnore]
public ImageSource LayerImage => _drawer.GetPreviewImage();
public bool ConditionsMet<T>(IGameDataModel dataModel)
{
@ -95,10 +58,10 @@ namespace Artemis.Models.Profiles
DrawChildren<T>(dataModel, g);
break;
case LayerType.Rectangle:
DrawRectangle(g);
_drawer.DrawRectangle(g);
break;
case LayerType.Ellipse:
DrawEllipse(g);
_drawer.DrawEllipse(g);
break;
default:
throw new ArgumentOutOfRangeException();
@ -107,6 +70,7 @@ namespace Artemis.Models.Profiles
private void Update<T>(IGameDataModel dataModel)
{
GeneralHelpers.CopyProperties(LayerCalculatedProperties, LayerUserProperties);
foreach (var dynamicProperty in LayerProperties)
dynamicProperty.ApplyProperty<T>(dataModel, LayerUserProperties, LayerCalculatedProperties);
}
@ -116,14 +80,6 @@ namespace Artemis.Models.Profiles
foreach (var layerModel in Children)
layerModel.Draw<T>(dataModel, g);
}
private void DrawRectangle(Graphics g)
{
}
private void DrawEllipse(Graphics g)
{
}
}
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
{
internal class RocketLeagueDataModel : IGameDataModel
{
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
{
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()
{
DivisionPlayers = new List<DivisionPlayer>();
TestyTest = new TestTest();
}
public PlayerState PartyMember1 { get; set; }
public PlayerState PartyMember2 { get; set; }
public PlayerState PartyMember3 { get; set; }
public bool LowAmmo { get; set; }
public bool LowHp { get; set; }
public GrenadeState GrenadeState { get; set; }
public TestTest TestyTest { get; set; }
}
public class DivisionPlayer
public class TestTest
{
public int Id { get; set; }
public PlayerState PlayerState { get; set; }
public DivisionPlayer(int id)
{
Id = id;
}
public string TestS { get; set; }
public int TestI { get; set; }
}
public enum GrenadeState

View File

@ -1,14 +1,12 @@
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using Artemis.Managers;
using Artemis.Models;
using Artemis.Modules.Effects.TypeWave;
using Artemis.Utilities;
using Artemis.Utilities.Keyboard;
using Artemis.Utilities.LogitechDll;
using CUE.NET;
namespace Artemis.Modules.Games.TheDivision
{
@ -95,8 +93,6 @@ namespace Artemis.Modules.Games.TheDivision
DllManager.PlaceDll();
_dataModel = new TheDivisionDataModel();
for (var i = 1; i < 5; i++)
_dataModel.DivisionPlayers.Add(new DivisionPlayer(i));
MainManager.PipeServer.PipeMessage += PipeServerOnPipeMessage;
Initialized = true;
@ -129,16 +125,21 @@ namespace Artemis.Modules.Games.TheDivision
if (keyCode >= 59 && keyCode <= 62)
{
var playerId = keyCode - 58;
var playerDataModel = _dataModel.DivisionPlayers.FirstOrDefault(p => p.Id == playerId);
if (playerDataModel == null)
return;
PlayerState newState;
if (gPer > 10)
playerDataModel.PlayerState = PlayerState.Online;
newState = PlayerState.Online;
else if (rPer > 10)
playerDataModel.PlayerState = PlayerState.Hit;
newState = PlayerState.Hit;
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
else if (keyCode == 19)
@ -180,26 +181,26 @@ namespace Artemis.Modules.Games.TheDivision
_hpRect.Colors = _dataModel.LowHp
? 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};
else if (_dataModel.DivisionPlayers[1].PlayerState == PlayerState.Online)
_p2.Colors = new List<Color> { Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45) };
else if (_dataModel.PartyMember1 == PlayerState.Online)
_p2.Colors = new List<Color> {Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45)};
else
_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};
else if (_dataModel.DivisionPlayers[2].PlayerState == PlayerState.Online)
_p3.Colors = new List<Color> { Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45) };
else if (_dataModel.PartyMember2 == PlayerState.Online)
_p3.Colors = new List<Color> {Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45)};
else
_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};
else if (_dataModel.DivisionPlayers[3].PlayerState == PlayerState.Online)
_p4.Colors = new List<Color> { Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45) };
else if (_dataModel.PartyMember3 == PlayerState.Online)
_p4.Colors = new List<Color> {Color.FromArgb(10, 255, 0), Color.FromArgb(80, 255, 45)};
else
_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);
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";
}

View File

@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Artemis.Utilities
{
@ -37,12 +37,50 @@ namespace Artemis.Utilities
Environment.Exit(0);
}
public static bool IsRunAsAdministrator()
{
var wi = WindowsIdentity.GetCurrent();
var wp = new WindowsPrincipal(wi);
return wp.IsInRole(WindowsBuiltInRole.Administrator);
public static bool IsRunAsAdministrator()
{
var wi = WindowsIdentity.GetCurrent();
var wp = new WindowsPrincipal(wi);
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.Drawing;
using System.Drawing.Drawing2D;
using System.Dynamic;
using System.Linq;
using System.Windows.Media;
using Artemis.DAL;
using Artemis.Managers;
using Artemis.Models;
using Artemis.Models.Profiles;
using Artemis.Modules.Games.RocketLeague;
using Artemis.Modules.Games.TheDivision;
using Caliburn.Micro;
using Color = System.Drawing.Color;
namespace Artemis.ViewModels
{
public class ProfileEditorViewModel : Screen
public class ProfileEditorViewModel<T> : Screen
{
private readonly GameModel _gameModel;
private readonly MainManager _mainManager;
private BindableCollection<ProfileModel> _profileModels;
private ProfileModel _selectedProfileModel;
private LayerEditorViewModel<T> _editorVm;
public ProfileEditorViewModel(MainManager mainManager, GameModel gameModel)
{
@ -82,50 +78,22 @@ namespace Artemis.ViewModels
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);
LoadProfiles();
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()
{
return null;

View File

@ -1,54 +1,53 @@
using System;
using System.Windows;
using Artemis.Events;
using Artemis.Properties;
using Artemis.Settings;
using Artemis.Utilities;
using Caliburn.Micro;
namespace Artemis.ViewModels
{
public class SystemTrayViewModel : Screen, IHandle<ToggleEnabled>
{
private readonly ShellViewModel _shellViewModel;
private readonly IWindowManager _windowManager;
private string _activeIcon;
private bool _checkedForUpdate;
private bool _enabled;
private string _toggleText;
public SystemTrayViewModel(IWindowManager windowManager, ShellViewModel shellViewModel)
{
_windowManager = windowManager;
_shellViewModel = shellViewModel;
_shellViewModel.MainManager.Events.Subscribe(this);
_shellViewModel.MainManager.EnableProgram();
_checkedForUpdate = false;
//ActiveIcon = "../logo.ico";
if (General.Default.ShowOnStartup)
ShowWindow();
}
public bool CanShowWindow => !_shellViewModel.IsActive;
public bool CanHideWindow => _shellViewModel.IsActive;
public bool Enabled
{
get { return _enabled; }
set
{
if (value == _enabled) return;
_enabled = value;
ToggleText = _enabled ? "Disable Artemis" : "Enable Artemis";
ActiveIcon = _enabled ? "../Resources/logo.ico" : "../Resources/logo-disabled.ico";
NotifyOfPropertyChange(() => Enabled);
}
}
using System;
using System.Windows;
using Artemis.Events;
using Artemis.Properties;
using Artemis.Settings;
using Artemis.Utilities;
using Caliburn.Micro;
namespace Artemis.ViewModels
{
public class SystemTrayViewModel : Screen, IHandle<ToggleEnabled>
{
private readonly ShellViewModel _shellViewModel;
private readonly IWindowManager _windowManager;
private string _activeIcon;
private bool _checkedForUpdate;
private bool _enabled;
private string _toggleText;
public SystemTrayViewModel(IWindowManager windowManager, ShellViewModel shellViewModel)
{
_windowManager = windowManager;
_shellViewModel = shellViewModel;
_shellViewModel.MainManager.Events.Subscribe(this);
_shellViewModel.MainManager.EnableProgram();
_checkedForUpdate = false;
if (General.Default.ShowOnStartup)
ShowWindow();
}
public bool CanShowWindow => !_shellViewModel.IsActive;
public bool CanHideWindow => _shellViewModel.IsActive;
public bool Enabled
{
get { return _enabled; }
set
{
if (value == _enabled) return;
_enabled = value;
ToggleText = _enabled ? "Disable Artemis" : "Enable Artemis";
ActiveIcon = _enabled ? "../Resources/logo.ico" : "../Resources/logo-disabled.ico";
NotifyOfPropertyChange(() => Enabled);
}
}
public string ActiveIcon
{
get { return _activeIcon; }
@ -57,77 +56,77 @@ namespace Artemis.ViewModels
_activeIcon = value;
NotifyOfPropertyChange();
}
}
public string ToggleText
{
get { return _toggleText; }
set
{
if (value == _toggleText) return;
_toggleText = value;
NotifyOfPropertyChange(() => ToggleText);
}
}
public void Handle(ToggleEnabled message)
{
Enabled = message.Enabled;
}
public void ToggleEnabled()
{
if (Enabled)
_shellViewModel.MainManager.DisableProgram();
else
_shellViewModel.MainManager.EnableProgram();
}
protected override void OnActivate()
{
base.OnActivate();
NotifyOfPropertyChange(() => CanShowWindow);
NotifyOfPropertyChange(() => CanHideWindow);
}
public void ShowWindow()
{
if (!CanShowWindow)
return;
// manually show the next window view-model
_windowManager.ShowWindow(_shellViewModel);
NotifyOfPropertyChange(() => CanShowWindow);
NotifyOfPropertyChange(() => CanHideWindow);
if (_checkedForUpdate)
return;
_checkedForUpdate = true;
Updater.CheckForUpdate(_shellViewModel.MainManager.DialogService);
}
public void HideWindow()
{
if (!CanHideWindow)
return;
_shellViewModel.TryClose();
NotifyOfPropertyChange(() => CanShowWindow);
NotifyOfPropertyChange(() => CanHideWindow);
}
public void ExitApplication()
{
_shellViewModel.MainManager.Shutdown();
Application.Current.Shutdown();
// Sometimes you need to be rough.
Environment.Exit(0);
}
}
}
public string ToggleText
{
get { return _toggleText; }
set
{
if (value == _toggleText) return;
_toggleText = value;
NotifyOfPropertyChange(() => ToggleText);
}
}
public void Handle(ToggleEnabled message)
{
Enabled = message.Enabled;
}
public void ToggleEnabled()
{
if (Enabled)
_shellViewModel.MainManager.DisableProgram();
else
_shellViewModel.MainManager.EnableProgram();
}
protected override void OnActivate()
{
base.OnActivate();
NotifyOfPropertyChange(() => CanShowWindow);
NotifyOfPropertyChange(() => CanHideWindow);
}
public void ShowWindow()
{
if (!CanShowWindow)
return;
// manually show the next window view-model
_windowManager.ShowWindow(_shellViewModel);
NotifyOfPropertyChange(() => CanShowWindow);
NotifyOfPropertyChange(() => CanHideWindow);
if (_checkedForUpdate)
return;
_checkedForUpdate = true;
Updater.CheckForUpdate(_shellViewModel.MainManager.DialogService);
}
public void HideWindow()
{
if (!CanHideWindow)
return;
_shellViewModel.TryClose();
NotifyOfPropertyChange(() => CanShowWindow);
NotifyOfPropertyChange(() => CanHideWindow);
}
public void ExitApplication()
{
_shellViewModel.MainManager.Shutdown();
Application.Current.Shutdown();
// Sometimes you need to be rough.
Environment.Exit(0);
}
}
}

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:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.Views"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:cal="http://www.caliburnproject.org"
mc:Ignorable="d"
d:DesignHeight="772.5" d:DesignWidth="1335">
<Grid Width="Auto" Height="Auto">
@ -38,29 +40,31 @@
<ComboBox Grid.Row="1" Grid.Column="1" Width="110" VerticalAlignment="Top" x:Name="ProfileModels"
DisplayMemberPath="Name" Margin="5,0,0,0" />
<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"
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Right"
Margin="10,0,0,0" />
</StackPanel>
<!-- 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}"
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>
<ResourceDictionary
Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
</TreeView.Resources>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" Tag="{Binding DataContext, ElementName=ProfileTree}">
<StackPanel.ContextMenu>
<ContextMenu>
<ContextMenu cal:Action.TargetWithoutContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}">
<MenuItem Header="Rename" />
<MenuItem Header="Delete" />
<MenuItem Header="Properties" />
<MenuItem Header="Properties" cal:Message.Attach="LayerEditor($datacontext)"/>
</ContextMenu>
</StackPanel.ContextMenu>
<CheckBox VerticalAlignment="Center" ToolTip="Layer enabled" />