1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-01-02 02:33:32 +00:00

Small fixes

This commit is contained in:
SpoinkyNL 2016-10-30 01:34:07 +02:00
parent a982e28615
commit 8e7f327200
7 changed files with 166 additions and 138 deletions

View File

@ -88,8 +88,6 @@ namespace Artemis
ContractResolver = _kernel.Get<NinjectContractResolver>() ContractResolver = _kernel.Get<NinjectContractResolver>()
}; };
JsonConvert.DefaultSettings = () => settings; JsonConvert.DefaultSettings = () => settings;
// Configure MoonSharp
UserData.RegisterAssembly();
} }
protected override void OnExit(object sender, EventArgs e) protected override void OnExit(object sender, EventArgs e)

View File

@ -11,6 +11,7 @@ using Artemis.Profiles;
using Artemis.Profiles.Layers.Types.Keyboard; using Artemis.Profiles.Layers.Types.Keyboard;
using Artemis.Properties; using Artemis.Properties;
using Artemis.Utilities; using Artemis.Utilities;
using MoonSharp.Interpreter;
using Newtonsoft.Json; using Newtonsoft.Json;
using NLog; using NLog;
@ -27,17 +28,23 @@ namespace Artemis.DAL
static ProfileProvider() static ProfileProvider()
{ {
// Configure MoonSharp
UserData.RegisterAssembly();
CheckProfiles(); CheckProfiles();
InstallDefaults(); InstallDefaults();
} }
public static List<string> GetProfileNames(KeyboardProvider keyboard, EffectModel effect) public static List<string> GetProfileNames(KeyboardProvider keyboard, EffectModel effect)
{ {
if (keyboard == null || effect == null)
return null;
return ReadProfiles(keyboard.Slug + "/" + effect.Name).Select(p => p.Name).ToList(); return ReadProfiles(keyboard.Slug + "/" + effect.Name).Select(p => p.Name).ToList();
} }
public static ProfileModel GetProfile(KeyboardProvider keyboard, EffectModel effect, string name) public static ProfileModel GetProfile(KeyboardProvider keyboard, EffectModel effect, string name)
{ {
if (keyboard == null || effect == null)
return null;
return ReadProfiles(keyboard.Slug + "/" + effect.Name).FirstOrDefault(p => p.Name == name); return ReadProfiles(keyboard.Slug + "/" + effect.Name).FirstOrDefault(p => p.Name == name);
} }

View File

@ -5,7 +5,6 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Timers; using System.Timers;
using Artemis.DeviceProviders; using Artemis.DeviceProviders;
using Caliburn.Micro;
using Ninject.Extensions.Logging; using Ninject.Extensions.Logging;
using Timer = System.Timers.Timer; using Timer = System.Timers.Timer;
@ -160,9 +159,18 @@ namespace Artemis.Managers
generic.UpdateDevice(frame.GenericBitmap); generic.UpdateDevice(frame.GenericBitmap);
foreach (var mousemat in mousemats) foreach (var mousemat in mousemats)
mousemat.UpdateDevice(frame.MousematBitmap); mousemat.UpdateDevice(frame.MousematBitmap);
OnRenderCompleted();
} }
} }
} }
public event EventHandler RenderCompleted;
protected virtual void OnRenderCompleted()
{
RenderCompleted?.Invoke(this, EventArgs.Empty);
}
} }
public class RenderFrame : IDisposable public class RenderFrame : IDisposable
@ -185,16 +193,26 @@ namespace Artemis.Managers
MousematBitmap.SetResolution(96, 96); MousematBitmap.SetResolution(96, 96);
using (var g = Graphics.FromImage(KeyboardBitmap)) using (var g = Graphics.FromImage(KeyboardBitmap))
{
g.Clear(Color.Black); g.Clear(Color.Black);
}
using (var g = Graphics.FromImage(MouseBitmap)) using (var g = Graphics.FromImage(MouseBitmap))
{
g.Clear(Color.Black); g.Clear(Color.Black);
}
using (var g = Graphics.FromImage(HeadsetBitmap)) using (var g = Graphics.FromImage(HeadsetBitmap))
{
g.Clear(Color.Black); g.Clear(Color.Black);
}
using (var g = Graphics.FromImage(GenericBitmap)) using (var g = Graphics.FromImage(GenericBitmap))
{
g.Clear(Color.Black); g.Clear(Color.Black);
}
using (var g = Graphics.FromImage(MousematBitmap)) using (var g = Graphics.FromImage(MousematBitmap))
{
g.Clear(Color.Black); g.Clear(Color.Black);
} }
}
public Bitmap KeyboardBitmap { get; set; } public Bitmap KeyboardBitmap { get; set; }
public Bitmap MouseBitmap { get; set; } public Bitmap MouseBitmap { get; set; }

View File

@ -20,11 +20,14 @@ namespace Artemis.Modules.Effects.WindowsProfile
private PerformanceCounter _overallCpu; private PerformanceCounter _overallCpu;
private SpotifyLocalAPI _spotify; private SpotifyLocalAPI _spotify;
private bool _spotifySetupBusy; private bool _spotifySetupBusy;
private DateTime _lastSpotifyUpdate;
public WindowsProfileModel(ILogger logger, MainManager mainManager) public WindowsProfileModel(ILogger logger, MainManager mainManager)
: base(mainManager, SettingsProvider.Load<WindowsProfileSettings>(), new WindowsProfileDataModel()) : base(mainManager, SettingsProvider.Load<WindowsProfileSettings>(), new WindowsProfileDataModel())
{ {
_logger = logger; _logger = logger;
_lastSpotifyUpdate = DateTime.Now;
Name = "WindowsProfile"; Name = "WindowsProfile";
} }
@ -163,10 +166,7 @@ namespace Artemis.Modules.Effects.WindowsProfile
return; return;
_spotifySetupBusy = true; _spotifySetupBusy = true;
_spotify = new SpotifyLocalAPI {ListenForEvents = true}; _spotify = new SpotifyLocalAPI();
_spotify.OnPlayStateChange += UpdateSpotifyPlayState;
_spotify.OnTrackChange += UpdateSpotifyTrack;
_spotify.OnTrackTimeChange += UpdateSpotifyTrackTime;
// Connecting can sometimes use a little bit more conviction // Connecting can sometimes use a little bit more conviction
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
@ -186,31 +186,28 @@ namespace Artemis.Modules.Effects.WindowsProfile
public void UpdateSpotify(WindowsProfileDataModel dataModel) public void UpdateSpotify(WindowsProfileDataModel dataModel)
{ {
// This is quite resource hungry so only update it once every two seconds
if (DateTime.Now - _lastSpotifyUpdate < TimeSpan.FromSeconds(2))
return;
_lastSpotifyUpdate = DateTime.Now;
if (!dataModel.Spotify.Running && SpotifyLocalAPI.IsSpotifyRunning()) if (!dataModel.Spotify.Running && SpotifyLocalAPI.IsSpotifyRunning())
SetupSpotify(); SetupSpotify();
var status = _spotify.GetStatus();
dataModel.Spotify.Playing = status.Playing;
dataModel.Spotify.Running = SpotifyLocalAPI.IsSpotifyRunning(); dataModel.Spotify.Running = SpotifyLocalAPI.IsSpotifyRunning();
if (status.Track != null)
{
dataModel.Spotify.Artist = status.Track.ArtistResource?.Name;
dataModel.Spotify.SongName = status.Track.TrackResource?.Name;
dataModel.Spotify.Album = status.Track.AlbumResource?.Name;
dataModel.Spotify.SongLength = status.Track.Length;
} }
private void UpdateSpotifyPlayState(object sender, PlayStateEventArgs e)
{
((WindowsProfileDataModel) DataModel).Spotify.Playing = e.Playing;
}
private void UpdateSpotifyTrack(object sender, TrackChangeEventArgs e)
{
var dataModel = (WindowsProfileDataModel) DataModel;
dataModel.Spotify.Artist = e.NewTrack.ArtistResource?.Name;
dataModel.Spotify.SongName = e.NewTrack.TrackResource?.Name;
dataModel.Spotify.Album = e.NewTrack.AlbumResource?.Name;
dataModel.Spotify.SongLength = e.NewTrack.Length;
}
private void UpdateSpotifyTrackTime(object sender, TrackTimeChangeEventArgs e)
{
var dataModel = (WindowsProfileDataModel) DataModel;
if (dataModel.Spotify.SongLength > 0) if (dataModel.Spotify.SongLength > 0)
dataModel.Spotify.SongPercentCompleted = (int) (e.TrackTime/dataModel.Spotify.SongLength*100.0); dataModel.Spotify.SongPercentCompleted =
(int) (status.PlayingPosition/dataModel.Spotify.SongLength*100.0);
} }
#endregion #endregion

View File

@ -48,14 +48,15 @@ namespace Artemis.Modules.Games.Witcher3
} }
// Load the ZIP from resources // Load the ZIP from resources
var stream = new MemoryStream(Resources.witcher3_mod); using (var stream = new MemoryStream(Resources.witcher3_mod))
var archive = new ZipArchive(stream); {
using (var archive = new ZipArchive(stream))
{
// Look for any conflicting mods // Look for any conflicting mods
if (Directory.Exists(dialog.SelectedPath + @"\mods")) if (Directory.Exists(dialog.SelectedPath + @"\mods"))
{ {
var file = var file = Directory.GetFiles(dialog.SelectedPath + @"\mods", "playerWitcher.ws",
Directory.GetFiles(dialog.SelectedPath + @"\mods", "playerWitcher.ws", SearchOption.AllDirectories) SearchOption.AllDirectories)
.FirstOrDefault(); .FirstOrDefault();
if (file != null) if (file != null)
if (!file.Contains("modArtemis")) if (!file.Contains("modArtemis"))
@ -70,17 +71,20 @@ namespace Artemis.Modules.Games.Witcher3
// Put the mod in the documents folder instead // Put the mod in the documents folder instead
// Create the directory structure // Create the directory structure
var folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artemis"; var folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
@"\Artemis";
archive.ExtractToDirectory(folder + @"witcher3-mod", true); archive.ExtractToDirectory(folder + @"witcher3-mod", true);
System.Diagnostics.Process.Start(new ProcessStartInfo("https://github.com/SpoinkyNL/Artemis/wiki/The-Witcher-3")); System.Diagnostics.Process.Start(
new ProcessStartInfo("https://github.com/SpoinkyNL/Artemis/wiki/The-Witcher-3"));
return; return;
} }
} }
archive.ExtractToDirectory(dialog.SelectedPath, true); archive.ExtractToDirectory(dialog.SelectedPath, true);
DialogService.ShowMessageBox("Success", "The mod was successfully installed!"); DialogService.ShowMessageBox("Success", "The mod was successfully installed!");
} }
} }
} }
}
}

View File

@ -34,76 +34,21 @@ namespace Artemis.ViewModels.Profiles
private LayerModel _selectedLayer; private LayerModel _selectedLayer;
private bool _showAll; private bool _showAll;
public ProfileViewModel(DeviceManager deviceManager) public ProfileViewModel(DeviceManager deviceManager, LoopManager loopManager)
{ {
_deviceManager = deviceManager; _deviceManager = deviceManager;
PreviewTimer = new Timer(40);
ShowAll = false; ShowAll = false;
PreviewTimer.Elapsed += InvokeUpdateKeyboardPreview; loopManager.RenderCompleted += LoopManagerOnRenderCompleted;
deviceManager.OnKeyboardChangedEvent += DeviceManagerOnOnKeyboardChangedEvent; deviceManager.OnKeyboardChangedEvent += DeviceManagerOnOnKeyboardChangedEvent;
} }
public ProfileModel SelectedProfile { get; set; } private void LoopManagerOnRenderCompleted(object sender, EventArgs eventArgs)
public Timer PreviewTimer { get; set; } {
if (!Activated)
return;
public LayerModel SelectedLayer
{
get { return _selectedLayer; }
set
{
if (Equals(value, _selectedLayer)) return;
_selectedLayer = value;
NotifyOfPropertyChange(() => SelectedLayer);
}
}
public DrawingImage KeyboardPreview
{
get { return _keyboardPreview; }
set
{
if (Equals(value, _keyboardPreview)) return;
_keyboardPreview = value;
NotifyOfPropertyChange(() => KeyboardPreview);
}
}
public double BlurRadius
{
get { return _blurRadius; }
set
{
if (value.Equals(_blurRadius)) return;
_blurRadius = value;
NotifyOfPropertyChange(() => BlurRadius);
}
}
public bool ShowAll
{
get { return _showAll; }
set
{
if (value == _showAll) return;
_showAll = value;
NotifyOfPropertyChange(() => ShowAll);
}
}
public ImageSource KeyboardImage => ImageUtilities
.BitmapToBitmapImage(_deviceManager.ActiveKeyboard?.PreviewSettings.Image ?? Resources.none);
public bool Activated { get; set; }
private void DeviceManagerOnOnKeyboardChangedEvent(object sender, KeyboardChangedEventArgs e)
{
NotifyOfPropertyChange(() => KeyboardImage);
}
private void InvokeUpdateKeyboardPreview(object sender, ElapsedEventArgs e)
{
if (_blurProgress > 2) if (_blurProgress > 2)
_blurProgress = 0; _blurProgress = 0;
_blurProgress = _blurProgress + 0.025; _blurProgress = _blurProgress + 0.025;
@ -117,7 +62,6 @@ namespace Artemis.ViewModels.Profiles
return; return;
} }
var keyboardRect = _deviceManager.ActiveKeyboard.KeyboardRectangle(4); var keyboardRect = _deviceManager.ActiveKeyboard.KeyboardRectangle(4);
var visual = new DrawingVisual(); var visual = new DrawingVisual();
using (var drawingContext = visual.RenderOpen()) using (var drawingContext = visual.RenderOpen())
@ -175,19 +119,75 @@ namespace Artemis.ViewModels.Profiles
} }
var drawnPreview = new DrawingImage(visual.Drawing); var drawnPreview = new DrawingImage(visual.Drawing);
drawnPreview.Freeze(); drawnPreview.Freeze();
KeyboardPreview = drawnPreview; KeyboardPreview = drawnPreview;
} }
public ProfileModel SelectedProfile { get; set; }
public LayerModel SelectedLayer
{
get { return _selectedLayer; }
set
{
if (Equals(value, _selectedLayer)) return;
_selectedLayer = value;
NotifyOfPropertyChange(() => SelectedLayer);
}
}
public DrawingImage KeyboardPreview
{
get { return _keyboardPreview; }
set
{
if (Equals(value, _keyboardPreview)) return;
_keyboardPreview = value;
NotifyOfPropertyChange(() => KeyboardPreview);
}
}
public double BlurRadius
{
get { return _blurRadius; }
set
{
if (value.Equals(_blurRadius)) return;
_blurRadius = value;
NotifyOfPropertyChange(() => BlurRadius);
}
}
public bool ShowAll
{
get { return _showAll; }
set
{
if (value == _showAll) return;
_showAll = value;
NotifyOfPropertyChange(() => ShowAll);
}
}
public ImageSource KeyboardImage => ImageUtilities
.BitmapToBitmapImage(_deviceManager.ActiveKeyboard?.PreviewSettings.Image ?? Resources.none);
public bool Activated { get; set; }
private void DeviceManagerOnOnKeyboardChangedEvent(object sender, KeyboardChangedEventArgs e)
{
NotifyOfPropertyChange(() => KeyboardImage);
}
public void Activate() public void Activate()
{ {
Activated = true; Activated = true;
PreviewTimer.Start();
} }
public void Deactivate() public void Deactivate()
{ {
Activated = false; Activated = false;
PreviewTimer.Stop();
} }
#region Processing #region Processing

View File

@ -66,13 +66,17 @@ namespace ColorBox
arr = stream.ToArray(); arr = stream.ToArray();
} }
BitmapSource bitmap = BitmapFrame.Create(new MemoryStream(arr)); using (var ms = new MemoryStream(arr))
{
BitmapSource bitmap = BitmapFrame.Create(ms);
var pixels = new byte[4]; var pixels = new byte[4];
var cb = new CroppedBitmap(bitmap, new Int32Rect((int) p.X, (int) p.Y, 1, 1)); var cb = new CroppedBitmap(bitmap, new Int32Rect((int) p.X, (int) p.Y, 1, 1));
cb.CopyPixels(pixels, 4, 0); cb.CopyPixels(pixels, 4, 0);
return Color.FromArgb(pixels[3], pixels[2], pixels[1], pixels[0]); return Color.FromArgb(pixels[3], pixels[2], pixels[1], pixels[0]);
} }
}
catch (Exception) catch (Exception)
{ {
return ColorBox.Color; return ColorBox.Color;