From 0783671db76c155eca030938ad0458cea2c42a56 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 7 Aug 2023 21:16:31 +0200 Subject: [PATCH] Added configuration to disable transparency in profiles which prevents profiles below from rendering --- .../ProfileConfiguration.cs | 11 +++++ .../Services/Storage/ProfileService.cs | 42 ++++++++++++------- .../ProfileConfigurationEditView.axaml | 4 ++ .../ProfileConfigurationEditViewModel.cs | 9 ++++ 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs b/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs index 06a2090d3..49c65bf5b 100644 --- a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs +++ b/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs @@ -27,6 +27,7 @@ public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable private bool _isMissingModule; private bool _isSuspended; private bool _fadeInAndOut; + private bool _allowTransparency = true; private Module? _module; private string _name; @@ -175,6 +176,16 @@ public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable set => SetAndNotify(ref _fadeInAndOut, value); } + /// + /// Gets or sets a boolean indicating whether this profile allows transparency. + /// If true, transparency is enabled and layers below are rendered; if false this profile is rendered on top of solid black and profiles below are not rendered. + /// + public bool AllowTransparency + { + get => _allowTransparency; + set => SetAndNotify(ref _allowTransparency, value); + } + /// /// Gets or sets the module this profile uses /// diff --git a/src/Artemis.Core/Services/Storage/ProfileService.cs b/src/Artemis.Core/Services/Storage/ProfileService.cs index ba1f496e7..293d01e98 100644 --- a/src/Artemis.Core/Services/Storage/ProfileService.cs +++ b/src/Artemis.Core/Services/Storage/ProfileService.cs @@ -125,7 +125,7 @@ internal class ProfileService : IProfileService profileConfiguration.IsSuspended = true; } } - + // If suspension was changed, save the category if (before != profileConfiguration.IsSuspended) SaveProfileCategory(profileConfiguration.Category); @@ -258,23 +258,16 @@ internal class ProfileService : IProfileService return; // Iterate the children in reverse because the first category must be rendered last to end up on top - for (int i = _profileCategories.Count - 1; i > -1; i--) + IEnumerable profilesToRender = GetProfilesToRender(_profileCategories).Reverse(); + foreach (Profile profile in profilesToRender) { - ProfileCategory profileCategory = _profileCategories[i]; - for (int j = profileCategory.ProfileConfigurations.Count - 1; j > -1; j--) + try { - try - { - ProfileConfiguration profileConfiguration = profileCategory.ProfileConfigurations[j]; - // Ensure all criteria are met before rendering - bool fadingOut = profileConfiguration.Profile?.ShouldDisplay == false && profileConfiguration.Profile?.Opacity > 0; - if (!profileConfiguration.IsSuspended && !profileConfiguration.IsMissingModule && (profileConfiguration.ActivationConditionMet || fadingOut)) - profileConfiguration.Profile?.Render(canvas, SKPointI.Empty, null); - } - catch (Exception e) - { - _renderExceptions.Add(e); - } + profile.Render(canvas, SKPointI.Empty, null); + } + catch (Exception e) + { + _renderExceptions.Add(e); } } @@ -282,6 +275,23 @@ internal class ProfileService : IProfileService } } + private static IEnumerable GetProfilesToRender(IEnumerable profileCategories) + { + IEnumerable profiles = profileCategories.SelectMany(x => x.ProfileConfigurations).Select(x => x.Profile); + foreach (Profile? profile in profiles) + if (profile != null) + { + bool fadingOut = profile.ShouldDisplay == false && profile.Opacity > 0; + if (!profile.Configuration.IsSuspended && !profile.Configuration.IsMissingModule && (profile.Configuration.ActivationConditionMet || fadingOut)) + { + yield return profile; + + if (!profile.Configuration.AllowTransparency) + break; + } + } + } + public ReadOnlyCollection ProfileCategories { get diff --git a/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditView.axaml b/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditView.axaml index a6df27dcf..222c223bd 100644 --- a/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditView.axaml +++ b/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditView.axaml @@ -120,6 +120,10 @@ Fade when enabling and disabling + + + Allow layers from below to shine through transparent leds + diff --git a/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditViewModel.cs b/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditViewModel.cs index c0d130ce6..539231f5d 100644 --- a/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditViewModel.cs +++ b/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditViewModel.cs @@ -30,6 +30,7 @@ public class ProfileConfigurationEditViewModel : DialogViewModelBase RaiseAndSetIfChanged(ref _fadeInAndOut, value); } + public bool AllowTransparency + { + get => _allowTransparency; + set => RaiseAndSetIfChanged(ref _allowTransparency, value); + } + public ObservableCollection Modules { get; } public ProfileModuleViewModel? SelectedModule @@ -162,6 +170,7 @@ public class ProfileConfigurationEditViewModel : DialogViewModelBase