mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-02 10:43:31 +00:00
Updated view models and views to work a lot smoother in combination with previewing
This commit is contained in:
parent
9ddde37333
commit
b936908274
@ -12,7 +12,6 @@ namespace Artemis.Managers
|
||||
{
|
||||
private readonly DeviceManager _deviceManager;
|
||||
private readonly ILogger _logger;
|
||||
private ModuleModel _activeModule;
|
||||
private LoopManager _waitLoopManager;
|
||||
private ModuleModel _waitEffect;
|
||||
private readonly GeneralSettings _generalSettings;
|
||||
@ -36,16 +35,7 @@ namespace Artemis.Managers
|
||||
public List<ModuleModel> Modules { get; set; }
|
||||
public List<ModuleModel> ProcessModules { get; set; }
|
||||
public List<ModuleModel> OverlayModules { get; set; }
|
||||
|
||||
public ModuleModel ActiveModule
|
||||
{
|
||||
get { return _activeModule; }
|
||||
private set
|
||||
{
|
||||
_activeModule = value;
|
||||
RaiseEffectChangedEvent(new ModuleChangedEventArgs(value));
|
||||
}
|
||||
}
|
||||
public ModuleModel ActiveModule { get; private set; }
|
||||
|
||||
public event EventHandler<ModuleChangedEventArgs> EffectChanged;
|
||||
|
||||
@ -131,13 +121,14 @@ namespace Artemis.Managers
|
||||
loopManager.StartAsync();
|
||||
}
|
||||
|
||||
_logger.Debug("Changed active module to: {0}", moduleModel.Name);
|
||||
if (!ActiveModule.IsBoundToProcess && !ActiveModule.IsOverlay && storeAsLast)
|
||||
{
|
||||
_generalSettings.LastModule = ActiveModule?.Name;
|
||||
_generalSettings.Save();
|
||||
}
|
||||
|
||||
if (ActiveModule.IsBoundToProcess || ActiveModule.IsOverlay || !storeAsLast)
|
||||
return;
|
||||
// Regular modules are stored as the last active module
|
||||
_generalSettings.LastModule = ActiveModule?.Name;
|
||||
_generalSettings.Save();
|
||||
_logger.Debug("Changed active module to: {0}", moduleModel.Name);
|
||||
RaiseEffectChangedEvent(new ModuleChangedEventArgs(moduleModel));
|
||||
}
|
||||
|
||||
private void DeviceManagerOnOnKeyboardChanged(object sender, KeyboardChangedEventArgs e)
|
||||
|
||||
@ -46,7 +46,8 @@ namespace Artemis.Managers
|
||||
if (string.IsNullOrEmpty(_generalSettings.LastKeyboard) || _deviceManager.ChangingKeyboard)
|
||||
return;
|
||||
|
||||
var activePreview = PreviewViewModules.FirstOrDefault(vm => vm.IsActive && vm.UsesProfileEditor);
|
||||
var activePreview = PreviewViewModules.FirstOrDefault(
|
||||
vm => vm.IsActive && vm.UsesProfileEditor && vm.ModuleModel.Settings.IsEnabled);
|
||||
if (activePreview != null)
|
||||
EnsurePreviewActive(activePreview);
|
||||
else
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using Artemis.Events;
|
||||
using Artemis.Managers;
|
||||
using Artemis.Services;
|
||||
using Artemis.Settings;
|
||||
using Artemis.ViewModels.Profiles;
|
||||
using Caliburn.Micro;
|
||||
using Ninject;
|
||||
@ -15,15 +16,18 @@ namespace Artemis.Modules.Abstract
|
||||
private readonly MainManager _mainManager;
|
||||
private readonly IKernel _kernel;
|
||||
private ModuleSettings _settings;
|
||||
private GeneralSettings _generalSettings;
|
||||
|
||||
public ModuleViewModel(MainManager mainManager, ModuleModel moduleModel, IKernel kernel)
|
||||
{
|
||||
_mainManager = mainManager;
|
||||
_kernel = kernel;
|
||||
_moduleManager = mainManager.ModuleManager;
|
||||
_generalSettings = DAL.SettingsProvider.Load<GeneralSettings>();
|
||||
ModuleModel = moduleModel;
|
||||
Settings = moduleModel.Settings;
|
||||
|
||||
|
||||
_mainManager.EnabledChanged += MainManagerOnEnabledChanged;
|
||||
_moduleManager.EffectChanged += ModuleManagerOnModuleChanged;
|
||||
}
|
||||
@ -49,21 +53,33 @@ namespace Artemis.Modules.Abstract
|
||||
}
|
||||
|
||||
public virtual bool IsModuleActive => _moduleManager.ActiveModule == ModuleModel;
|
||||
|
||||
public virtual bool IsModuleEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ModuleModel.IsBoundToProcess || ModuleModel.IsBoundToProcess)
|
||||
return Settings.IsEnabled;
|
||||
return _generalSettings.LastModule == ModuleModel.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract bool UsesProfileEditor { get; }
|
||||
|
||||
private void MainManagerOnEnabledChanged(object sender, EnabledChangedEventArgs e)
|
||||
{
|
||||
UpdatedEnabledSetting();
|
||||
NotifyOfPropertyChange(() => IsModuleActive);
|
||||
UpdateIsEnabled();
|
||||
}
|
||||
|
||||
private void ModuleManagerOnModuleChanged(object sender, ModuleChangedEventArgs e)
|
||||
{
|
||||
UpdatedEnabledSetting();
|
||||
NotifyOfPropertyChange(() => IsModuleActive);
|
||||
UpdateIsEnabled();
|
||||
NotifyOfPropertyChange(() => IsModuleEnabled);
|
||||
}
|
||||
|
||||
private void UpdateIsEnabled()
|
||||
private void UpdatedEnabledSetting()
|
||||
{
|
||||
if (ModuleModel.IsBoundToProcess || ModuleModel.IsOverlay)
|
||||
return;
|
||||
@ -81,13 +97,20 @@ namespace Artemis.Modules.Abstract
|
||||
|
||||
// On process-bound modules, only set the module model
|
||||
if (ModuleModel.IsBoundToProcess || ModuleModel.IsOverlay)
|
||||
{
|
||||
NotifyOfPropertyChange(() => IsModuleActive);
|
||||
NotifyOfPropertyChange(() => IsModuleEnabled);
|
||||
return;
|
||||
}
|
||||
|
||||
// On other modules, activate them if necessary
|
||||
if (IsModuleActive && !Settings.IsEnabled)
|
||||
_moduleManager.ClearActiveModule();
|
||||
else if (!IsModuleActive && Settings.IsEnabled)
|
||||
_moduleManager.ChangeActiveModule(ModuleModel, _mainManager.LoopManager);
|
||||
|
||||
NotifyOfPropertyChange(() => IsModuleActive);
|
||||
NotifyOfPropertyChange(() => IsModuleEnabled);
|
||||
}
|
||||
|
||||
public virtual void SaveSettings()
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@ -51,7 +51,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
@ -49,7 +49,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
@ -50,7 +50,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
<ToggleButton Margin="0 3 0 0" Width="25" Height="25"
|
||||
Style="{DynamicResource MetroCircleToggleButtonStyle}"
|
||||
ToolTip="Note: You can't enable an module when Artemis is disabled"
|
||||
IsChecked="{Binding Path=Settings.Enabled, Mode=OneWay}"
|
||||
IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}"
|
||||
cal:Message.Attach="[Event Click] = [Action ToggleModule]" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@ -69,7 +69,6 @@ namespace Artemis.ViewModels.Profiles
|
||||
_deviceManager.OnKeyboardChanged += DeviceManagerOnOnKeyboardChanged;
|
||||
_moduleModel.ProfileChanged += ModuleModelOnProfileChanged;
|
||||
LoadProfiles();
|
||||
ProfileViewModel.Activate();
|
||||
|
||||
_saveTimer = new Timer(5000);
|
||||
_saveTimer.Elapsed += ProfileSaveHandler;
|
||||
@ -780,8 +779,7 @@ namespace Artemis.ViewModels.Profiles
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ProfileViewModel.Deactivate();
|
||||
|
||||
ProfileViewModel.Dispose();
|
||||
_saveTimer?.Stop();
|
||||
_saveTimer?.Dispose();
|
||||
_watcher?.Dispose();
|
||||
|
||||
@ -20,9 +20,10 @@ using MahApps.Metro;
|
||||
|
||||
namespace Artemis.ViewModels.Profiles
|
||||
{
|
||||
public class ProfileViewModel : PropertyChangedBase
|
||||
public class ProfileViewModel : PropertyChangedBase, IDisposable
|
||||
{
|
||||
private readonly DeviceManager _deviceManager;
|
||||
private readonly LoopManager _loopManager;
|
||||
private double _blurProgress;
|
||||
private double _blurRadius;
|
||||
private DateTime _downTime;
|
||||
@ -37,11 +38,12 @@ namespace Artemis.ViewModels.Profiles
|
||||
public ProfileViewModel(DeviceManager deviceManager, LoopManager loopManager)
|
||||
{
|
||||
_deviceManager = deviceManager;
|
||||
_loopManager = loopManager;
|
||||
|
||||
ShowAll = false;
|
||||
|
||||
loopManager.RenderCompleted += LoopManagerOnRenderCompleted;
|
||||
deviceManager.OnKeyboardChanged += DeviceManagerOnOnKeyboardChanged;
|
||||
_loopManager.RenderCompleted += LoopManagerOnRenderCompleted;
|
||||
_deviceManager.OnKeyboardChanged += DeviceManagerOnOnKeyboardChanged;
|
||||
}
|
||||
|
||||
public ModuleModel ModuleModel { get; set; }
|
||||
@ -94,13 +96,8 @@ namespace Artemis.ViewModels.Profiles
|
||||
public ImageSource KeyboardImage => ImageUtilities
|
||||
.BitmapToBitmapImage(_deviceManager.ActiveKeyboard?.PreviewSettings.Image ?? Resources.none);
|
||||
|
||||
public bool Activated { get; set; }
|
||||
|
||||
private void LoopManagerOnRenderCompleted(object sender, EventArgs eventArgs)
|
||||
{
|
||||
if (!Activated)
|
||||
return;
|
||||
|
||||
// Update the glowing effect around the keyboard
|
||||
if (_blurProgress > 2)
|
||||
_blurProgress = 0;
|
||||
@ -108,12 +105,9 @@ namespace Artemis.ViewModels.Profiles
|
||||
BlurRadius = (Math.Sin(_blurProgress * Math.PI) + 1) * 10 + 10;
|
||||
|
||||
// Besides the usual checks, also check if the ActiveKeyboard isn't the NoneKeyboard
|
||||
if (SelectedProfile == null || _deviceManager.ActiveKeyboard == null ||
|
||||
_deviceManager.ActiveKeyboard.Slug == "none")
|
||||
if (SelectedProfile == null || _deviceManager.ActiveKeyboard == null || _deviceManager.ActiveKeyboard.Slug == "none")
|
||||
{
|
||||
var preview = new DrawingImage();
|
||||
preview.Freeze();
|
||||
KeyboardPreview = preview;
|
||||
KeyboardPreview = null;
|
||||
|
||||
// Setup layers for the next frame
|
||||
if (ModuleModel.IsInitialized)
|
||||
@ -192,17 +186,6 @@ namespace Artemis.ViewModels.Profiles
|
||||
NotifyOfPropertyChange(() => KeyboardImage);
|
||||
}
|
||||
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
Activated = true;
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
Activated = false;
|
||||
}
|
||||
|
||||
#region Processing
|
||||
|
||||
/// <summary>
|
||||
@ -395,6 +378,13 @@ namespace Artemis.ViewModels.Profiles
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_keyboardPreviewCursor?.Dispose();
|
||||
_loopManager.RenderCompleted -= LoopManagerOnRenderCompleted;
|
||||
_deviceManager.OnKeyboardChanged -= DeviceManagerOnOnKeyboardChanged;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user