mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Profile editor - Removed delay in module override
Modules - Streamline update rules and properly honor them in timed updates
This commit is contained in:
parent
2eb4d615ae
commit
447a497945
@ -91,13 +91,13 @@ namespace Artemis.Core.Modules
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this module's activation was due to an override, can only be true if <see cref="IsActivated" /> is
|
||||
/// true
|
||||
/// <see langword="true" />
|
||||
/// </summary>
|
||||
public bool IsActivatedOverride { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this module should update if <see cref="IsActivatedOverride" /> is true
|
||||
/// <para>Defaults to <c>true</c></para>
|
||||
/// Gets whether this module should update if <see cref="IsActivatedOverride" /> is <see langword="true" />
|
||||
/// <para>Defaults to <see langword="true" /></para>
|
||||
/// </summary>
|
||||
public bool UpdateDuringActivationOverride { get; protected set; } = true;
|
||||
|
||||
@ -138,6 +138,11 @@ namespace Artemis.Core.Modules
|
||||
/// </summary>
|
||||
public IEnumerable<ModuleTab> ModuleTabs { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether updating this module is currently allowed
|
||||
/// </summary>
|
||||
public bool IsUpdateAllowed => IsActivated && (UpdateDuringActivationOverride || !IsActivatedOverride);
|
||||
|
||||
/// <summary>
|
||||
/// Called each frame when the module must update
|
||||
/// </summary>
|
||||
@ -189,7 +194,7 @@ namespace Artemis.Core.Modules
|
||||
|
||||
internal virtual void InternalUpdate(double deltaTime)
|
||||
{
|
||||
if (!IsActivatedOverride || UpdateDuringActivationOverride)
|
||||
if (IsUpdateAllowed)
|
||||
Update(deltaTime);
|
||||
}
|
||||
|
||||
|
||||
@ -141,7 +141,7 @@ namespace Artemis.Core.Modules
|
||||
|
||||
internal override void InternalUpdate(double deltaTime)
|
||||
{
|
||||
if (!IsActivatedOverride || UpdateDuringActivationOverride)
|
||||
if (IsUpdateAllowed)
|
||||
Update(deltaTime);
|
||||
|
||||
lock (this)
|
||||
|
||||
@ -20,7 +20,6 @@ namespace Artemis.Core
|
||||
|
||||
PluginInfo.Instance.PluginEnabled += InstanceOnPluginEnabled;
|
||||
PluginInfo.Instance.PluginDisabled += InstanceOnPluginDisabled;
|
||||
|
||||
if (PluginInfo.Instance.Enabled)
|
||||
Start();
|
||||
}
|
||||
@ -54,13 +53,6 @@ namespace Artemis.Core
|
||||
if (_timer != null)
|
||||
return;
|
||||
|
||||
// Don't update during override if that is disabled on the module
|
||||
if (PluginInfo.Instance is Module module)
|
||||
{
|
||||
if (module.IsActivatedOverride && !module.UpdateDuringActivationOverride)
|
||||
return;
|
||||
}
|
||||
|
||||
_lastEvent = DateTime.Now;
|
||||
_timer = new Timer(Interval.TotalMilliseconds);
|
||||
_timer.Elapsed += TimerOnElapsed;
|
||||
@ -94,6 +86,10 @@ namespace Artemis.Core
|
||||
var interval = DateTime.Now - _lastEvent;
|
||||
_lastEvent = DateTime.Now;
|
||||
|
||||
// Modules don't always want to update, honor that
|
||||
if (PluginInfo.Instance is Module module && !module.IsUpdateAllowed)
|
||||
return;
|
||||
|
||||
Action(interval.TotalSeconds);
|
||||
}
|
||||
|
||||
|
||||
@ -47,38 +47,24 @@ namespace Artemis.Core.Services
|
||||
if (ActiveModuleOverride == overrideModule)
|
||||
return;
|
||||
|
||||
// If set to null, resume regular activation
|
||||
if (overrideModule == null)
|
||||
{
|
||||
ActiveModuleOverride = null;
|
||||
_logger.Information("Cleared active module override");
|
||||
return;
|
||||
}
|
||||
|
||||
// If a module was provided, activate it and deactivate everything else
|
||||
// Always deactivate all modules whenever override is called
|
||||
var modules = _pluginService.GetPluginsOfType<Module>().ToList();
|
||||
var tasks = new List<Task>();
|
||||
foreach (var module in modules)
|
||||
OverrideDeactivate(module);
|
||||
|
||||
if (overrideModule != null)
|
||||
{
|
||||
if (module != overrideModule)
|
||||
tasks.Add(DeactivateModule(module, true));
|
||||
OverrideActivate(overrideModule);
|
||||
_logger.Information($"Setting active module override to {overrideModule.DisplayName}");
|
||||
}
|
||||
else
|
||||
_logger.Information("Clearing active module override");
|
||||
|
||||
if (!overrideModule.IsActivated)
|
||||
tasks.Add(ActivateModule(overrideModule, true));
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
ActiveModuleOverride = overrideModule;
|
||||
|
||||
_logger.Information($"Set active module override to {ActiveModuleOverride.DisplayName}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
ActiveModuleSemaphore.Release();
|
||||
|
||||
// With the semaphore released, trigger an update with the override was cleared
|
||||
if (ActiveModuleOverride == null)
|
||||
await UpdateModuleActivation();
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,9 +86,9 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
var shouldBeActivated = module.EvaluateActivationRequirements();
|
||||
if (shouldBeActivated && !module.IsActivated)
|
||||
tasks.Add(ActivateModule(module, false));
|
||||
tasks.Add(ActivateModule(module));
|
||||
else if (!shouldBeActivated && module.IsActivated)
|
||||
tasks.Add(DeactivateModule(module, false));
|
||||
tasks.Add(DeactivateModule(module));
|
||||
}
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
@ -149,11 +135,11 @@ namespace Artemis.Core.Services
|
||||
await UpdateModuleActivation();
|
||||
}
|
||||
|
||||
private async Task ActivateModule(Module module, bool isOverride)
|
||||
private async Task ActivateModule(Module module)
|
||||
{
|
||||
try
|
||||
{
|
||||
module.Activate(isOverride);
|
||||
module.Activate(false);
|
||||
|
||||
// If this is a profile module, activate the last active profile after module activation
|
||||
if (module is ProfileModule profileModule)
|
||||
@ -166,7 +152,27 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeactivateModule(Module module, bool isOverride)
|
||||
private void OverrideActivate(Module module)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (module.IsActivated)
|
||||
return;
|
||||
|
||||
module.Activate(true);
|
||||
|
||||
// If this is a profile module, activate the last active profile after module activation
|
||||
if (module is ProfileModule profileModule)
|
||||
_profileService.ActivateLastProfile(profileModule);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(new ArtemisPluginException(module.PluginInfo, "Failed to activate module and last profile.", e), "Failed to activate module and last profile");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeactivateModule(Module module)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -174,7 +180,27 @@ namespace Artemis.Core.Services
|
||||
if (module.IsActivated && module is ProfileModule profileModule)
|
||||
await profileModule.ChangeActiveProfileAnimated(null, null);
|
||||
|
||||
module.Deactivate(isOverride);
|
||||
module.Deactivate(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(new ArtemisPluginException(module.PluginInfo, "Failed to deactivate module and last profile.", e), "Failed to deactivate module and last profile");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void OverrideDeactivate(Module module)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!module.IsActivated)
|
||||
return;
|
||||
|
||||
// If this is a profile module, activate the last active profile after module activation
|
||||
if (module is ProfileModule profileModule)
|
||||
profileModule.ChangeActiveProfile(null, null);
|
||||
|
||||
module.Deactivate(true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@ -58,8 +58,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
|
||||
|
||||
ShowDataModelValues = settingsService.GetSetting<bool>("ProfileEditor.ShowDataModelValues");
|
||||
|
||||
// Initialize async, no need to wait for it
|
||||
Task.Run(Initialize);
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public DisplayConditionPredicate DisplayConditionPredicate => (DisplayConditionPredicate) Model;
|
||||
|
||||
@ -10,8 +10,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
public class TimelinePropertyViewModel<T> : Conductor<TimelineKeyframeViewModel<T>>.Collection.AllActive, ITimelinePropertyViewModel
|
||||
{
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
public LayerProperty<T> LayerProperty { get; }
|
||||
public LayerPropertyViewModel LayerPropertyViewModel { get; }
|
||||
private double _width;
|
||||
|
||||
public TimelinePropertyViewModel(LayerProperty<T> layerProperty, LayerPropertyViewModel layerPropertyViewModel, IProfileEditorService profileEditorService)
|
||||
{
|
||||
@ -23,22 +22,17 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
LayerProperty.KeyframesToggled += LayerPropertyOnKeyframesToggled;
|
||||
LayerProperty.KeyframeAdded += LayerPropertyOnKeyframeAdded;
|
||||
LayerProperty.KeyframeRemoved += LayerPropertyOnKeyframeRemoved;
|
||||
_profileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
|
||||
UpdateKeyframes();
|
||||
}
|
||||
|
||||
private void LayerPropertyOnKeyframesToggled(object sender, LayerPropertyEventArgs<T> e)
|
||||
{
|
||||
UpdateKeyframes();
|
||||
}
|
||||
public LayerProperty<T> LayerProperty { get; }
|
||||
public LayerPropertyViewModel LayerPropertyViewModel { get; }
|
||||
|
||||
private void LayerPropertyOnKeyframeRemoved(object sender, LayerPropertyEventArgs<T> e)
|
||||
public double Width
|
||||
{
|
||||
UpdateKeyframes();
|
||||
}
|
||||
|
||||
private void LayerPropertyOnKeyframeAdded(object sender, LayerPropertyEventArgs<T> e)
|
||||
{
|
||||
UpdateKeyframes();
|
||||
get => _width;
|
||||
set => SetAndNotify(ref _width, value);
|
||||
}
|
||||
|
||||
public List<ITimelineKeyframeViewModel> GetAllKeyframeViewModels()
|
||||
@ -46,29 +40,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
return Items.Cast<ITimelineKeyframeViewModel>().ToList();
|
||||
}
|
||||
|
||||
private void UpdateKeyframes()
|
||||
{
|
||||
// Only show keyframes if they are enabled
|
||||
if (LayerProperty.KeyframesEnabled)
|
||||
{
|
||||
var keyframes = LayerProperty.Keyframes.ToList();
|
||||
var toRemove = Items.Where(t => !keyframes.Contains(t.LayerPropertyKeyframe)).ToList();
|
||||
foreach (var timelineKeyframeViewModel in toRemove)
|
||||
timelineKeyframeViewModel.Dispose();
|
||||
|
||||
Items.RemoveRange(toRemove);
|
||||
Items.AddRange(keyframes
|
||||
.Where(k => Items.All(t => t.LayerPropertyKeyframe != k))
|
||||
.Select(k => new TimelineKeyframeViewModel<T>(k, _profileEditorService))
|
||||
);
|
||||
}
|
||||
else
|
||||
Items.Clear();
|
||||
|
||||
foreach (var timelineKeyframeViewModel in Items)
|
||||
timelineKeyframeViewModel.Update();
|
||||
}
|
||||
|
||||
public void WipeKeyframes(TimeSpan? start, TimeSpan? end)
|
||||
{
|
||||
start ??= TimeSpan.Zero;
|
||||
@ -98,6 +69,50 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
LayerProperty.KeyframesToggled -= LayerPropertyOnKeyframesToggled;
|
||||
LayerProperty.KeyframeAdded -= LayerPropertyOnKeyframeAdded;
|
||||
LayerProperty.KeyframeRemoved -= LayerPropertyOnKeyframeRemoved;
|
||||
_profileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
|
||||
}
|
||||
|
||||
private void LayerPropertyOnKeyframesToggled(object sender, LayerPropertyEventArgs<T> e)
|
||||
{
|
||||
UpdateKeyframes();
|
||||
}
|
||||
|
||||
private void LayerPropertyOnKeyframeRemoved(object sender, LayerPropertyEventArgs<T> e)
|
||||
{
|
||||
UpdateKeyframes();
|
||||
}
|
||||
|
||||
private void LayerPropertyOnKeyframeAdded(object sender, LayerPropertyEventArgs<T> e)
|
||||
{
|
||||
UpdateKeyframes();
|
||||
}
|
||||
|
||||
private void ProfileEditorServiceOnPixelsPerSecondChanged(object sender, EventArgs e)
|
||||
{
|
||||
Width = GetAllKeyframeViewModels().Max(k => k.Position.TotalSeconds * _profileEditorService.PixelsPerSecond + 25);
|
||||
}
|
||||
|
||||
private void UpdateKeyframes()
|
||||
{
|
||||
// Only show keyframes if they are enabled
|
||||
if (LayerProperty.KeyframesEnabled)
|
||||
{
|
||||
var keyframes = LayerProperty.Keyframes.ToList();
|
||||
var toRemove = Items.Where(t => !keyframes.Contains(t.LayerPropertyKeyframe)).ToList();
|
||||
foreach (var timelineKeyframeViewModel in toRemove)
|
||||
timelineKeyframeViewModel.Dispose();
|
||||
|
||||
Items.RemoveRange(toRemove);
|
||||
Items.AddRange(keyframes
|
||||
.Where(k => Items.All(t => t.LayerPropertyKeyframe != k))
|
||||
.Select(k => new TimelineKeyframeViewModel<T>(k, _profileEditorService))
|
||||
);
|
||||
}
|
||||
else
|
||||
Items.Clear();
|
||||
|
||||
foreach (var timelineKeyframeViewModel in Items)
|
||||
timelineKeyframeViewModel.Update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@ namespace Artemis.Plugins.Modules.Overlay
|
||||
DisplayName = "Overlay";
|
||||
DisplayIcon = "ArrangeBringToFront";
|
||||
DefaultPriorityCategory = ModulePriorityCategory.Overlay;
|
||||
UpdateDuringActivationOverride = false;
|
||||
|
||||
ActivationRequirements.Add(new ProcessActivationRequirement("taskmgr"));
|
||||
ActivationRequirements.Add(new ProcessActivationRequirement("calc"));
|
||||
@ -22,6 +23,12 @@ namespace Artemis.Plugins.Modules.Overlay
|
||||
{
|
||||
Location = Path.Combine(Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.System)).FullName, "System32")
|
||||
});
|
||||
|
||||
AddTimedUpdate(TimeSpan.FromSeconds(5), DelayedUpdate);
|
||||
}
|
||||
|
||||
private void DelayedUpdate(double obj)
|
||||
{
|
||||
}
|
||||
|
||||
// This is the end of your plugin life cycle.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user