mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 13:28:33 +00:00
Core - Reworked profile render override for the editor and new previewer
This commit is contained in:
parent
c6a318b6e3
commit
d2b8123a30
@ -17,13 +17,12 @@ public sealed class Profile : ProfileElement
|
||||
private readonly ObservableCollection<ScriptConfiguration> _scriptConfigurations;
|
||||
private readonly ObservableCollection<ProfileScript> _scripts;
|
||||
private bool _isFreshImport;
|
||||
private ProfileElement? _lastSelectedProfileElement;
|
||||
|
||||
internal Profile(ProfileConfiguration configuration, ProfileEntity profileEntity) : base(null!)
|
||||
{
|
||||
_scripts = new ObservableCollection<ProfileScript>();
|
||||
_scriptConfigurations = new ObservableCollection<ScriptConfiguration>();
|
||||
|
||||
|
||||
Opacity = 0d;
|
||||
ShouldDisplay = true;
|
||||
Configuration = configuration;
|
||||
@ -67,15 +66,6 @@ public sealed class Profile : ProfileElement
|
||||
set => SetAndNotify(ref _isFreshImport, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the last selected profile element of this profile
|
||||
/// </summary>
|
||||
public ProfileElement? LastSelectedProfileElement
|
||||
{
|
||||
get => _lastSelectedProfileElement;
|
||||
set => SetAndNotify(ref _lastSelectedProfileElement, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the profile entity this profile uses for persistent storage
|
||||
/// </summary>
|
||||
@ -105,7 +95,7 @@ public sealed class Profile : ProfileElement
|
||||
profileScript.OnProfileUpdated(deltaTime);
|
||||
|
||||
const double OPACITY_PER_SECOND = 1;
|
||||
|
||||
|
||||
if (ShouldDisplay && Opacity < 1)
|
||||
Opacity = Math.Clamp(Opacity + OPACITY_PER_SECOND * deltaTime, 0d, 1d);
|
||||
if (!ShouldDisplay && Opacity > 0)
|
||||
@ -123,14 +113,14 @@ public sealed class Profile : ProfileElement
|
||||
|
||||
foreach (ProfileScript profileScript in Scripts)
|
||||
profileScript.OnProfileRendering(canvas, canvas.LocalClipBounds);
|
||||
|
||||
|
||||
SKPaint? opacityPaint = null;
|
||||
bool applyOpacityLayer = Configuration.FadeInAndOut && Opacity < 1;
|
||||
|
||||
|
||||
if (applyOpacityLayer)
|
||||
{
|
||||
opacityPaint = new SKPaint();
|
||||
opacityPaint.Color = new SKColor(0, 0, 0, (byte)(255d * Easings.CubicEaseInOut(Opacity)));
|
||||
opacityPaint.Color = new SKColor(0, 0, 0, (byte) (255d * Easings.CubicEaseInOut(Opacity)));
|
||||
canvas.SaveLayer(opacityPaint);
|
||||
}
|
||||
|
||||
@ -242,20 +232,13 @@ public sealed class Profile : ProfileElement
|
||||
AddChild(new Folder(this, this, rootFolder));
|
||||
}
|
||||
|
||||
List<RenderProfileElement> renderElements = GetAllRenderElements();
|
||||
|
||||
if (ProfileEntity.LastSelectedProfileElement != Guid.Empty)
|
||||
LastSelectedProfileElement = renderElements.FirstOrDefault(f => f.EntityId == ProfileEntity.LastSelectedProfileElement);
|
||||
else
|
||||
LastSelectedProfileElement = null;
|
||||
|
||||
while (_scriptConfigurations.Any())
|
||||
RemoveScriptConfiguration(_scriptConfigurations[0]);
|
||||
foreach (ScriptConfiguration scriptConfiguration in ProfileEntity.ScriptConfigurations.Select(e => new ScriptConfiguration(e)))
|
||||
AddScriptConfiguration(scriptConfiguration);
|
||||
|
||||
// Load node scripts last since they may rely on the profile structure being in place
|
||||
foreach (RenderProfileElement renderProfileElement in renderElements)
|
||||
foreach (RenderProfileElement renderProfileElement in GetAllRenderElements())
|
||||
renderProfileElement.LoadNodeScript();
|
||||
}
|
||||
|
||||
@ -312,7 +295,6 @@ public sealed class Profile : ProfileElement
|
||||
ProfileEntity.Id = EntityId;
|
||||
ProfileEntity.Name = Configuration.Name;
|
||||
ProfileEntity.IsFreshImport = IsFreshImport;
|
||||
ProfileEntity.LastSelectedProfileElement = LastSelectedProfileElement?.EntityId ?? Guid.Empty;
|
||||
|
||||
foreach (ProfileElement profileElement in Children)
|
||||
profileElement.Save();
|
||||
|
||||
@ -147,16 +147,7 @@ public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable
|
||||
get => _activationConditionMet;
|
||||
private set => SetAndNotify(ref _activationConditionMet, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether this profile configuration is being edited
|
||||
/// </summary>
|
||||
public bool IsBeingEdited
|
||||
{
|
||||
get => _isBeingEdited;
|
||||
set => SetAndNotify(ref _isBeingEdited, value);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the profile of this profile configuration
|
||||
/// </summary>
|
||||
@ -243,8 +234,6 @@ public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ProfileConfiguration");
|
||||
if (IsBeingEdited)
|
||||
return true;
|
||||
if (Category.IsSuspended || IsSuspended || IsMissingModule)
|
||||
return false;
|
||||
|
||||
|
||||
@ -26,19 +26,26 @@ public interface IProfileService : IArtemisService
|
||||
ReadOnlyCollection<ProfileConfiguration> ProfileConfigurations { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether hotkeys are enabled.
|
||||
/// Gets or sets the focused profile configuration which is rendered exclusively.
|
||||
/// </summary>
|
||||
bool HotkeysEnabled { get; set; }
|
||||
ProfileConfiguration? FocusProfile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether rendering should only be done for profiles being edited.
|
||||
/// Gets or sets the profile element which is rendered exclusively.
|
||||
/// </summary>
|
||||
bool RenderForEditor { get; set; }
|
||||
ProfileElement? FocusProfileElement { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the profile element to focus on while rendering for the editor.
|
||||
/// Gets or sets a value indicating whether the currently focused profile should receive updates.
|
||||
/// </summary>
|
||||
ProfileElement? EditorFocus { get; set; }
|
||||
bool UpdateFocusProfile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a copy of the provided profile configuration.
|
||||
/// </summary>
|
||||
/// <param name="profileConfiguration">The profile configuration to clone.</param>
|
||||
/// <returns>The resulting clone.</returns>
|
||||
ProfileConfiguration CloneProfileConfiguration(ProfileConfiguration profileConfiguration);
|
||||
|
||||
/// <summary>
|
||||
/// Activates the profile of the given <see cref="ProfileConfiguration" /> with the currently active surface.
|
||||
|
||||
@ -15,14 +15,14 @@ namespace Artemis.Core.Services;
|
||||
internal class ProfileService : IProfileService
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly IProfileCategoryRepository _profileCategoryRepository;
|
||||
private readonly IPluginManagementService _pluginManagementService;
|
||||
|
||||
private readonly List<ArtemisKeyboardKeyEventArgs> _pendingKeyboardEvents = new();
|
||||
private readonly IPluginManagementService _pluginManagementService;
|
||||
private readonly List<ProfileCategory> _profileCategories;
|
||||
private readonly IProfileCategoryRepository _profileCategoryRepository;
|
||||
private readonly IProfileRepository _profileRepository;
|
||||
private readonly List<Exception> _renderExceptions = new();
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly List<Exception> _updateExceptions = new();
|
||||
private DateTime _lastRenderExceptionLog;
|
||||
private DateTime _lastUpdateExceptionLog;
|
||||
@ -45,7 +45,6 @@ internal class ProfileService : IProfileService
|
||||
_pluginManagementService.PluginFeatureEnabled += PluginManagementServiceOnPluginFeatureToggled;
|
||||
_pluginManagementService.PluginFeatureDisabled += PluginManagementServiceOnPluginFeatureToggled;
|
||||
|
||||
HotkeysEnabled = true;
|
||||
inputService.KeyboardKeyUp += InputServiceOnKeyboardKeyUp;
|
||||
|
||||
if (!_profileCategories.Any())
|
||||
@ -53,140 +52,21 @@ internal class ProfileService : IProfileService
|
||||
UpdateModules();
|
||||
}
|
||||
|
||||
private void InputServiceOnKeyboardKeyUp(object? sender, ArtemisKeyboardKeyEventArgs e)
|
||||
{
|
||||
if (!HotkeysEnabled)
|
||||
return;
|
||||
|
||||
lock (_profileCategories)
|
||||
{
|
||||
_pendingKeyboardEvents.Add(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populates all missing LEDs on all currently active profiles
|
||||
/// </summary>
|
||||
private void ActiveProfilesPopulateLeds()
|
||||
{
|
||||
foreach (ProfileConfiguration profileConfiguration in ProfileConfigurations)
|
||||
{
|
||||
if (profileConfiguration.Profile == null) continue;
|
||||
profileConfiguration.Profile.PopulateLeds(_rgbService.EnabledDevices);
|
||||
|
||||
if (!profileConfiguration.Profile.IsFreshImport) continue;
|
||||
_logger.Debug("Profile is a fresh import, adapting to surface - {profile}", profileConfiguration.Profile);
|
||||
AdaptProfile(profileConfiguration.Profile);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateModules()
|
||||
{
|
||||
lock (_profileRepository)
|
||||
{
|
||||
List<Module> modules = _pluginManagementService.GetFeaturesOfType<Module>();
|
||||
foreach (ProfileCategory profileCategory in _profileCategories)
|
||||
{
|
||||
foreach (ProfileConfiguration profileConfiguration in profileCategory.ProfileConfigurations)
|
||||
profileConfiguration.LoadModules(modules);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RgbServiceOnLedsChanged(object? sender, EventArgs e)
|
||||
{
|
||||
ActiveProfilesPopulateLeds();
|
||||
}
|
||||
|
||||
private void PluginManagementServiceOnPluginFeatureToggled(object? sender, PluginFeatureEventArgs e)
|
||||
{
|
||||
if (e.PluginFeature is Module)
|
||||
UpdateModules();
|
||||
}
|
||||
|
||||
private void ProcessPendingKeyEvents(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
if (profileConfiguration.HotkeyMode == ProfileConfigurationHotkeyMode.None)
|
||||
return;
|
||||
|
||||
bool before = profileConfiguration.IsSuspended;
|
||||
foreach (ArtemisKeyboardKeyEventArgs e in _pendingKeyboardEvents)
|
||||
{
|
||||
if (profileConfiguration.HotkeyMode == ProfileConfigurationHotkeyMode.Toggle)
|
||||
{
|
||||
if (profileConfiguration.EnableHotkey != null && profileConfiguration.EnableHotkey.MatchesEventArgs(e))
|
||||
profileConfiguration.IsSuspended = !profileConfiguration.IsSuspended;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (profileConfiguration.IsSuspended && profileConfiguration.EnableHotkey != null && profileConfiguration.EnableHotkey.MatchesEventArgs(e))
|
||||
profileConfiguration.IsSuspended = false;
|
||||
else if (!profileConfiguration.IsSuspended && profileConfiguration.DisableHotkey != null && profileConfiguration.DisableHotkey.MatchesEventArgs(e))
|
||||
profileConfiguration.IsSuspended = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If suspension was changed, save the category
|
||||
if (before != profileConfiguration.IsSuspended)
|
||||
SaveProfileCategory(profileConfiguration.Category);
|
||||
}
|
||||
|
||||
private void CreateDefaultProfileCategories()
|
||||
{
|
||||
foreach (DefaultCategoryName defaultCategoryName in Enum.GetValues<DefaultCategoryName>())
|
||||
CreateProfileCategory(defaultCategoryName.ToString());
|
||||
}
|
||||
|
||||
private void LogProfileUpdateExceptions()
|
||||
{
|
||||
// Only log update exceptions every 10 seconds to avoid spamming the logs
|
||||
if (DateTime.Now - _lastUpdateExceptionLog < TimeSpan.FromSeconds(10))
|
||||
return;
|
||||
_lastUpdateExceptionLog = DateTime.Now;
|
||||
|
||||
if (!_updateExceptions.Any())
|
||||
return;
|
||||
|
||||
// Group by stack trace, that should gather up duplicate exceptions
|
||||
foreach (IGrouping<string?, Exception> exceptions in _updateExceptions.GroupBy(e => e.StackTrace))
|
||||
{
|
||||
_logger.Warning(exceptions.First(),
|
||||
"Exception was thrown {count} times during profile update in the last 10 seconds",
|
||||
exceptions.Count());
|
||||
}
|
||||
|
||||
// When logging is finished start with a fresh slate
|
||||
_updateExceptions.Clear();
|
||||
}
|
||||
|
||||
private void LogProfileRenderExceptions()
|
||||
{
|
||||
// Only log update exceptions every 10 seconds to avoid spamming the logs
|
||||
if (DateTime.Now - _lastRenderExceptionLog < TimeSpan.FromSeconds(10))
|
||||
return;
|
||||
_lastRenderExceptionLog = DateTime.Now;
|
||||
|
||||
if (!_renderExceptions.Any())
|
||||
return;
|
||||
|
||||
// Group by stack trace, that should gather up duplicate exceptions
|
||||
foreach (IGrouping<string?, Exception> exceptions in _renderExceptions.GroupBy(e => e.StackTrace))
|
||||
{
|
||||
_logger.Warning(exceptions.First(),
|
||||
"Exception was thrown {count} times during profile render in the last 10 seconds",
|
||||
exceptions.Count());
|
||||
}
|
||||
|
||||
// When logging is finished start with a fresh slate
|
||||
_renderExceptions.Clear();
|
||||
}
|
||||
|
||||
public bool HotkeysEnabled { get; set; }
|
||||
public bool RenderForEditor { get; set; }
|
||||
public ProfileElement? EditorFocus { get; set; }
|
||||
public ProfileConfiguration? FocusProfile { get; set; }
|
||||
public ProfileElement? FocusProfileElement { get; set; }
|
||||
public bool UpdateFocusProfile { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void UpdateProfiles(double deltaTime)
|
||||
{
|
||||
// If there is a focus profile update only that, and only if UpdateFocusProfile is true
|
||||
if (FocusProfile != null)
|
||||
{
|
||||
if (UpdateFocusProfile)
|
||||
FocusProfile.Profile?.Update(deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_profileCategories)
|
||||
{
|
||||
// Iterate the children in reverse because the first category must be rendered last to end up on top
|
||||
@ -200,16 +80,11 @@ internal class ProfileService : IProfileService
|
||||
// Process hotkeys that where pressed since this profile last updated
|
||||
ProcessPendingKeyEvents(profileConfiguration);
|
||||
|
||||
// Profiles being edited are updated at their own leisure
|
||||
if (profileConfiguration.IsBeingEdited && RenderForEditor)
|
||||
continue;
|
||||
|
||||
bool shouldBeActive = profileConfiguration.ShouldBeActive(false);
|
||||
if (shouldBeActive)
|
||||
{
|
||||
profileConfiguration.Update();
|
||||
if (!profileConfiguration.IsBeingEdited)
|
||||
shouldBeActive = profileConfiguration.ActivationConditionMet;
|
||||
shouldBeActive = profileConfiguration.ActivationConditionMet;
|
||||
}
|
||||
|
||||
try
|
||||
@ -243,20 +118,18 @@ internal class ProfileService : IProfileService
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RenderProfiles(SKCanvas canvas)
|
||||
{
|
||||
// If there is a focus profile, render only that
|
||||
if (FocusProfile != null)
|
||||
{
|
||||
FocusProfile.Profile?.Render(canvas, SKPointI.Empty, FocusProfileElement);
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_profileCategories)
|
||||
{
|
||||
ProfileConfiguration? editedProfileConfiguration = _profileCategories.SelectMany(c => c.ProfileConfigurations).FirstOrDefault(p => p.IsBeingEdited);
|
||||
if (editedProfileConfiguration != null)
|
||||
{
|
||||
editedProfileConfiguration.Profile?.Render(canvas, SKPointI.Empty, RenderForEditor ? EditorFocus : null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (RenderForEditor)
|
||||
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--)
|
||||
{
|
||||
@ -282,6 +155,7 @@ internal class ProfileService : IProfileService
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ReadOnlyCollection<ProfileCategory> ProfileCategories
|
||||
{
|
||||
get
|
||||
@ -293,6 +167,7 @@ internal class ProfileService : IProfileService
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ReadOnlyCollection<ProfileConfiguration> ProfileConfigurations
|
||||
{
|
||||
get
|
||||
@ -304,6 +179,7 @@ internal class ProfileService : IProfileService
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LoadProfileConfigurationIcon(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
if (profileConfiguration.Icon.IconType == ProfileConfigurationIconType.MaterialIcon)
|
||||
@ -314,6 +190,7 @@ internal class ProfileService : IProfileService
|
||||
profileConfiguration.Icon.SetIconByStream(profileConfiguration.Entity.IconOriginalFileName, stream);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SaveProfileConfigurationIcon(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
if (profileConfiguration.Icon.IconType == ProfileConfigurationIconType.MaterialIcon)
|
||||
@ -327,6 +204,13 @@ internal class ProfileService : IProfileService
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ProfileConfiguration CloneProfileConfiguration(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
return new ProfileConfiguration(profileConfiguration.Category, profileConfiguration.Entity);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Profile ActivateProfile(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
if (profileConfiguration.Profile != null)
|
||||
@ -364,9 +248,10 @@ internal class ProfileService : IProfileService
|
||||
return profile;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void DeactivateProfile(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
if (profileConfiguration.IsBeingEdited)
|
||||
if (FocusProfile == profileConfiguration)
|
||||
throw new ArtemisCoreException("Cannot disable a profile that is being edited, that's rude");
|
||||
if (profileConfiguration.Profile == null)
|
||||
return;
|
||||
@ -378,9 +263,10 @@ internal class ProfileService : IProfileService
|
||||
OnProfileDeactivated(new ProfileConfigurationEventArgs(profileConfiguration));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RequestDeactivation(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
if (profileConfiguration.IsBeingEdited)
|
||||
if (FocusProfile == profileConfiguration)
|
||||
throw new ArtemisCoreException("Cannot disable a profile that is being edited, that's rude");
|
||||
if (profileConfiguration.Profile == null)
|
||||
return;
|
||||
@ -388,6 +274,7 @@ internal class ProfileService : IProfileService
|
||||
profileConfiguration.Profile.ShouldDisplay = false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void DeleteProfile(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
DeactivateProfile(profileConfiguration);
|
||||
@ -401,6 +288,7 @@ internal class ProfileService : IProfileService
|
||||
SaveProfileCategory(profileConfiguration.Category);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ProfileCategory CreateProfileCategory(string name)
|
||||
{
|
||||
ProfileCategory profileCategory;
|
||||
@ -415,6 +303,7 @@ internal class ProfileService : IProfileService
|
||||
return profileCategory;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void DeleteProfileCategory(ProfileCategory profileCategory)
|
||||
{
|
||||
List<ProfileConfiguration> profileConfigurations = profileCategory.ProfileConfigurations.ToList();
|
||||
@ -430,6 +319,7 @@ internal class ProfileService : IProfileService
|
||||
OnProfileCategoryRemoved(new ProfileCategoryEventArgs(profileCategory));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ProfileConfiguration CreateProfileConfiguration(ProfileCategory category, string name, string icon)
|
||||
{
|
||||
ProfileConfiguration configuration = new(category, name, icon);
|
||||
@ -441,6 +331,7 @@ internal class ProfileService : IProfileService
|
||||
return configuration;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RemoveProfileConfiguration(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
profileConfiguration.Category.RemoveProfileConfiguration(profileConfiguration);
|
||||
@ -454,6 +345,7 @@ internal class ProfileService : IProfileService
|
||||
profileConfiguration.Dispose();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SaveProfileCategory(ProfileCategory profileCategory)
|
||||
{
|
||||
profileCategory.Save();
|
||||
@ -465,6 +357,7 @@ internal class ProfileService : IProfileService
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SaveProfile(Profile profile, bool includeChildren)
|
||||
{
|
||||
_logger.Debug("Updating profile - Saving {Profile}", profile);
|
||||
@ -480,6 +373,7 @@ internal class ProfileService : IProfileService
|
||||
_profileRepository.Save(profile.ProfileEntity);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ProfileConfigurationExportModel ExportProfile(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
// The profile may not be active and in that case lets activate it real quick
|
||||
@ -493,6 +387,7 @@ internal class ProfileService : IProfileService
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ProfileConfiguration ImportProfile(ProfileCategory category, ProfileConfigurationExportModel exportModel,
|
||||
bool makeUnique, bool markAsFreshImport, string? nameAffix)
|
||||
{
|
||||
@ -565,6 +460,131 @@ internal class ProfileService : IProfileService
|
||||
_profileRepository.Save(profile.ProfileEntity);
|
||||
}
|
||||
|
||||
private void InputServiceOnKeyboardKeyUp(object? sender, ArtemisKeyboardKeyEventArgs e)
|
||||
{
|
||||
lock (_profileCategories)
|
||||
{
|
||||
_pendingKeyboardEvents.Add(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populates all missing LEDs on all currently active profiles
|
||||
/// </summary>
|
||||
private void ActiveProfilesPopulateLeds()
|
||||
{
|
||||
foreach (ProfileConfiguration profileConfiguration in ProfileConfigurations)
|
||||
{
|
||||
if (profileConfiguration.Profile == null) continue;
|
||||
profileConfiguration.Profile.PopulateLeds(_rgbService.EnabledDevices);
|
||||
|
||||
if (!profileConfiguration.Profile.IsFreshImport) continue;
|
||||
_logger.Debug("Profile is a fresh import, adapting to surface - {profile}", profileConfiguration.Profile);
|
||||
AdaptProfile(profileConfiguration.Profile);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateModules()
|
||||
{
|
||||
lock (_profileRepository)
|
||||
{
|
||||
List<Module> modules = _pluginManagementService.GetFeaturesOfType<Module>();
|
||||
foreach (ProfileCategory profileCategory in _profileCategories)
|
||||
{
|
||||
foreach (ProfileConfiguration profileConfiguration in profileCategory.ProfileConfigurations)
|
||||
profileConfiguration.LoadModules(modules);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RgbServiceOnLedsChanged(object? sender, EventArgs e)
|
||||
{
|
||||
ActiveProfilesPopulateLeds();
|
||||
}
|
||||
|
||||
private void PluginManagementServiceOnPluginFeatureToggled(object? sender, PluginFeatureEventArgs e)
|
||||
{
|
||||
if (e.PluginFeature is Module)
|
||||
UpdateModules();
|
||||
}
|
||||
|
||||
private void ProcessPendingKeyEvents(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
if (profileConfiguration.HotkeyMode == ProfileConfigurationHotkeyMode.None)
|
||||
return;
|
||||
|
||||
bool before = profileConfiguration.IsSuspended;
|
||||
foreach (ArtemisKeyboardKeyEventArgs e in _pendingKeyboardEvents)
|
||||
{
|
||||
if (profileConfiguration.HotkeyMode == ProfileConfigurationHotkeyMode.Toggle)
|
||||
{
|
||||
if (profileConfiguration.EnableHotkey != null && profileConfiguration.EnableHotkey.MatchesEventArgs(e))
|
||||
profileConfiguration.IsSuspended = !profileConfiguration.IsSuspended;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (profileConfiguration.IsSuspended && profileConfiguration.EnableHotkey != null && profileConfiguration.EnableHotkey.MatchesEventArgs(e))
|
||||
profileConfiguration.IsSuspended = false;
|
||||
else if (!profileConfiguration.IsSuspended && profileConfiguration.DisableHotkey != null && profileConfiguration.DisableHotkey.MatchesEventArgs(e))
|
||||
profileConfiguration.IsSuspended = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If suspension was changed, save the category
|
||||
if (before != profileConfiguration.IsSuspended)
|
||||
SaveProfileCategory(profileConfiguration.Category);
|
||||
}
|
||||
|
||||
private void CreateDefaultProfileCategories()
|
||||
{
|
||||
foreach (DefaultCategoryName defaultCategoryName in Enum.GetValues<DefaultCategoryName>())
|
||||
CreateProfileCategory(defaultCategoryName.ToString());
|
||||
}
|
||||
|
||||
private void LogProfileUpdateExceptions()
|
||||
{
|
||||
// Only log update exceptions every 10 seconds to avoid spamming the logs
|
||||
if (DateTime.Now - _lastUpdateExceptionLog < TimeSpan.FromSeconds(10))
|
||||
return;
|
||||
_lastUpdateExceptionLog = DateTime.Now;
|
||||
|
||||
if (!_updateExceptions.Any())
|
||||
return;
|
||||
|
||||
// Group by stack trace, that should gather up duplicate exceptions
|
||||
foreach (IGrouping<string?, Exception> exceptions in _updateExceptions.GroupBy(e => e.StackTrace))
|
||||
{
|
||||
_logger.Warning(exceptions.First(),
|
||||
"Exception was thrown {count} times during profile update in the last 10 seconds",
|
||||
exceptions.Count());
|
||||
}
|
||||
|
||||
// When logging is finished start with a fresh slate
|
||||
_updateExceptions.Clear();
|
||||
}
|
||||
|
||||
private void LogProfileRenderExceptions()
|
||||
{
|
||||
// Only log update exceptions every 10 seconds to avoid spamming the logs
|
||||
if (DateTime.Now - _lastRenderExceptionLog < TimeSpan.FromSeconds(10))
|
||||
return;
|
||||
_lastRenderExceptionLog = DateTime.Now;
|
||||
|
||||
if (!_renderExceptions.Any())
|
||||
return;
|
||||
|
||||
// Group by stack trace, that should gather up duplicate exceptions
|
||||
foreach (IGrouping<string?, Exception> exceptions in _renderExceptions.GroupBy(e => e.StackTrace))
|
||||
{
|
||||
_logger.Warning(exceptions.First(),
|
||||
"Exception was thrown {count} times during profile render in the last 10 seconds",
|
||||
exceptions.Count());
|
||||
}
|
||||
|
||||
// When logging is finished start with a fresh slate
|
||||
_renderExceptions.Clear();
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler<ProfileConfigurationEventArgs>? ProfileActivated;
|
||||
|
||||
@ -18,7 +18,6 @@ public class ProfileEntity
|
||||
|
||||
public string Name { get; set; }
|
||||
public bool IsFreshImport { get; set; }
|
||||
public Guid LastSelectedProfileElement { get; set; }
|
||||
|
||||
public List<FolderEntity> Folders { get; set; }
|
||||
public List<LayerEntity> Layers { get; set; }
|
||||
|
||||
@ -10,7 +10,6 @@ using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared.Services.MainWindow;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor.Commands;
|
||||
using Avalonia.Threading;
|
||||
using DynamicData;
|
||||
using Serilog;
|
||||
|
||||
@ -140,14 +139,14 @@ internal class ProfileEditorService : IProfileEditorService
|
||||
private void ApplyFocusMode()
|
||||
{
|
||||
if (_suspendedEditingSubject.Value)
|
||||
_profileService.EditorFocus = null;
|
||||
_profileService.FocusProfileElement = null;
|
||||
|
||||
_profileService.EditorFocus = _focusModeSubject.Value switch
|
||||
_profileService.FocusProfileElement = _focusModeSubject.Value switch
|
||||
{
|
||||
ProfileEditorFocusMode.None => null,
|
||||
ProfileEditorFocusMode.Folder => _profileElementSubject.Value?.Parent,
|
||||
ProfileEditorFocusMode.Selection => _profileElementSubject.Value,
|
||||
_ => _profileService.EditorFocus
|
||||
_ => _profileService.FocusProfileElement
|
||||
};
|
||||
}
|
||||
|
||||
@ -164,52 +163,38 @@ internal class ProfileEditorService : IProfileEditorService
|
||||
|
||||
public async Task ChangeCurrentProfileConfiguration(ProfileConfiguration? profileConfiguration)
|
||||
{
|
||||
if (ReferenceEquals(_profileConfigurationSubject.Value, profileConfiguration))
|
||||
ProfileConfiguration? previous = _profileConfigurationSubject.Value;
|
||||
if (ReferenceEquals(previous, profileConfiguration))
|
||||
return;
|
||||
|
||||
_logger.Verbose("ChangeCurrentProfileConfiguration {profile}", profileConfiguration);
|
||||
|
||||
// Stop playing and save the current profile
|
||||
Pause();
|
||||
if (_profileConfigurationSubject.Value?.Profile != null)
|
||||
{
|
||||
_profileConfigurationSubject.Value.Profile.Reset();
|
||||
_profileConfigurationSubject.Value.Profile.LastSelectedProfileElement = _profileElementSubject.Value;
|
||||
}
|
||||
|
||||
await SaveProfileAsync();
|
||||
|
||||
// No need to deactivate the profile, if needed it will be deactivated next update
|
||||
if (_profileConfigurationSubject.Value != null)
|
||||
_profileConfigurationSubject.Value.IsBeingEdited = false;
|
||||
|
||||
// Deselect whatever profile element was active
|
||||
ChangeCurrentProfileElement(null);
|
||||
ChangeSuspendedEditing(false);
|
||||
|
||||
// Close the command scope if one was open
|
||||
_profileEditorHistoryScope?.Dispose();
|
||||
|
||||
// The new profile may need activation
|
||||
if (profileConfiguration != null)
|
||||
// Activate the profile and it's mode off of the UI thread
|
||||
await Task.Run(() =>
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
profileConfiguration.IsBeingEdited = true;
|
||||
_moduleService.SetActivationOverride(profileConfiguration.Module);
|
||||
// Activate the profile if one was provided
|
||||
if (profileConfiguration != null)
|
||||
_profileService.ActivateProfile(profileConfiguration);
|
||||
_profileService.RenderForEditor = true;
|
||||
});
|
||||
if (profileConfiguration.Profile?.LastSelectedProfileElement is RenderProfileElement renderProfileElement)
|
||||
ChangeCurrentProfileElement(renderProfileElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
_moduleService.SetActivationOverride(null);
|
||||
_profileService.RenderForEditor = false;
|
||||
}
|
||||
// If there is no profile configuration or module, deliberately set the override to null
|
||||
_moduleService.SetActivationOverride(profileConfiguration?.Module);
|
||||
});
|
||||
|
||||
_profileService.FocusProfile = profileConfiguration;
|
||||
_profileConfigurationSubject.OnNext(profileConfiguration);
|
||||
|
||||
ChangeTime(TimeSpan.Zero);
|
||||
previous?.Profile?.Reset();
|
||||
}
|
||||
|
||||
public void ChangeCurrentProfileElement(RenderProfileElement? renderProfileElement)
|
||||
@ -238,23 +223,23 @@ internal class ProfileEditorService : IProfileEditorService
|
||||
if (_suspendedEditingSubject.Value == suspend)
|
||||
return;
|
||||
|
||||
_suspendedEditingSubject.OnNext(suspend);
|
||||
if (suspend)
|
||||
{
|
||||
Pause();
|
||||
_profileService.RenderForEditor = false;
|
||||
_profileService.UpdateFocusProfile = true;
|
||||
_profileConfigurationSubject.Value?.Profile?.Reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_profileConfigurationSubject.Value != null)
|
||||
_profileService.RenderForEditor = true;
|
||||
_profileService.UpdateFocusProfile = false;
|
||||
Tick(_timeSubject.Value);
|
||||
}
|
||||
|
||||
_suspendedEditingSubject.OnNext(suspend);
|
||||
ApplyFocusMode();
|
||||
}
|
||||
|
||||
|
||||
public void ChangeFocusMode(ProfileEditorFocusMode focusMode)
|
||||
{
|
||||
if (_focusModeSubject.Value == focusMode)
|
||||
@ -411,10 +396,8 @@ internal class ProfileEditorService : IProfileEditorService
|
||||
public void SaveProfile()
|
||||
{
|
||||
Profile? profile = _profileConfigurationSubject.Value?.Profile;
|
||||
if (profile == null)
|
||||
return;
|
||||
|
||||
_profileService.SaveProfile(profile, true);
|
||||
if (profile != null)
|
||||
_profileService.SaveProfile(profile, true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -10,15 +10,10 @@
|
||||
<TextBlock Classes="h5">This is heading 5</TextBlock>
|
||||
<TextBlock Classes="h6">This is heading 6</TextBlock>
|
||||
<TextBlock Classes="subtitle">This is a subtitle</TextBlock>
|
||||
<TextBlock>
|
||||
<Run Classes="h1">This is heading 1</Run>
|
||||
<Run Classes="h2">This is heading 2</Run>
|
||||
<Run Classes="h3">This is heading 3</Run>
|
||||
<Run Classes="h4">This is heading 4</Run>
|
||||
<Run Classes="h5">This is heading 5</Run>
|
||||
<Run Classes="h6">This is heading 6</Run>
|
||||
<Run Classes="subtitle">This is a subtitle</Run>
|
||||
</TextBlock>
|
||||
<TextBlock Classes="danger">Danger</TextBlock>
|
||||
<TextBlock Classes="warning">Warning</TextBlock>
|
||||
<TextBlock Classes="success">Success</TextBlock>
|
||||
<TextBlock Classes="info">Info</TextBlock>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Design.PreviewWith>
|
||||
@ -81,4 +76,30 @@
|
||||
<Style Selector="Run.subtitle">
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="TextBlock.danger">
|
||||
<Setter Property="Foreground" Value="#FF5C5C"></Setter>
|
||||
</Style>
|
||||
<Style Selector="TextBlock.warning">
|
||||
<Setter Property="Foreground" Value="#DAA520"></Setter>
|
||||
</Style>
|
||||
<Style Selector="TextBlock.success">
|
||||
<Setter Property="Foreground" Value="#12B775"></Setter>
|
||||
</Style>
|
||||
<Style Selector="TextBlock.info">
|
||||
<Setter Property="Foreground" Value="{DynamicResource AccentButtonBackground}"></Setter>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Run.danger">
|
||||
<Setter Property="Foreground" Value="#FF5C5C"></Setter>
|
||||
</Style>
|
||||
<Style Selector="Run.warning">
|
||||
<Setter Property="Foreground" Value="#DAA520"></Setter>
|
||||
</Style>
|
||||
<Style Selector="Run.success">
|
||||
<Setter Property="Foreground" Value="#12B775"></Setter>
|
||||
</Style>
|
||||
<Style Selector="Run.info">
|
||||
<Setter Property="Foreground" Value="{DynamicResource AccentButtonBackground}"></Setter>
|
||||
</Style>
|
||||
</Styles>
|
||||
|
||||
@ -39,9 +39,17 @@
|
||||
<PackageReference Include="RGB.NET.Layout" Version="$(RGBDotNetVersion)" />
|
||||
<PackageReference Include="SkiaSharp" Version="$(SkiaSharpVersion)" />
|
||||
<PackageReference Include="Splat.DryIoc" Version="14.6.8" />
|
||||
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AvaloniaResource Include="Assets\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Screens\Workshop\SubmissionWizard\Steps\Profile\ProfileSelectionStepView.axaml.cs">
|
||||
<DependentUpon>ProfileSelectionStepView.axaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@ -16,7 +16,6 @@ using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using Newtonsoft.Json;
|
||||
using ReactiveUI;
|
||||
using Serilog;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.MenuBar;
|
||||
|
||||
@ -182,7 +181,7 @@ public class MenuBarViewModel : ActivatableViewModelBase
|
||||
if (!await _windowService.ShowConfirmContentDialog("Delete profile", "Are you sure you want to permanently delete this profile?"))
|
||||
return;
|
||||
|
||||
if (ProfileConfiguration.IsBeingEdited)
|
||||
if (_profileService.FocusProfile == ProfileConfiguration)
|
||||
await _router.Navigate("home");
|
||||
_profileService.RemoveProfileConfiguration(ProfileConfiguration);
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.PanAndZoom;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.ReactiveUI;
|
||||
using Avalonia.Threading;
|
||||
@ -19,7 +19,7 @@ public partial class VisualEditorView : ReactiveUserControl<VisualEditorViewMode
|
||||
public VisualEditorView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
ZoomBorder.PropertyChanged += ZoomBorderOnPropertyChanged;
|
||||
ZoomBorder.PointerMoved += ZoomBorderOnPointerMoved;
|
||||
ZoomBorder.PointerWheelChanged += ZoomBorderOnPointerWheelChanged;
|
||||
@ -31,11 +31,7 @@ public partial class VisualEditorView : ReactiveUserControl<VisualEditorViewMode
|
||||
Disposable.Create(() => ViewModel.AutoFitRequested -= ViewModelOnAutoFitRequested).DisposeWith(d);
|
||||
});
|
||||
|
||||
this.WhenAnyValue(v => v.Bounds).Subscribe(_ =>
|
||||
{
|
||||
if (!_movedByUser)
|
||||
AutoFit(true);
|
||||
});
|
||||
this.WhenAnyValue(v => v.Bounds).Where(_ => !_movedByUser).Subscribe(_ => AutoFit(true));
|
||||
}
|
||||
|
||||
private void ZoomBorderOnPointerWheelChanged(object? sender, PointerWheelEventArgs e)
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Updating;
|
||||
|
||||
@ -10,9 +8,4 @@ public partial class ReleaseView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -52,9 +52,9 @@ public class ProfileConfigurationEditViewModel : DialogViewModelBase<ProfileConf
|
||||
_windowService = windowService;
|
||||
_profileService = profileService;
|
||||
_profileEditorService = profileEditorService;
|
||||
|
||||
_profileConfiguration = profileConfiguration == ProfileConfiguration.Empty
|
||||
? profileService.CreateProfileConfiguration(profileCategory, "New profile", Enum.GetValues<MaterialIconKind>().First().ToString())
|
||||
|
||||
_profileConfiguration = profileConfiguration == ProfileConfiguration.Empty
|
||||
? profileService.CreateProfileConfiguration(profileCategory, "New profile", Enum.GetValues<MaterialIconKind>().First().ToString())
|
||||
: profileConfiguration;
|
||||
_profileName = _profileConfiguration.Name;
|
||||
_iconType = _profileConfiguration.Icon.IconType;
|
||||
@ -140,7 +140,7 @@ public class ProfileConfigurationEditViewModel : DialogViewModelBase<ProfileConf
|
||||
public ReactiveCommand<Unit, Unit> Confirm { get; }
|
||||
public ReactiveCommand<Unit, Unit> Delete { get; }
|
||||
public ReactiveCommand<Unit, Unit> Cancel { get; }
|
||||
|
||||
|
||||
private async Task ExecuteDelete()
|
||||
{
|
||||
if (IsNew)
|
||||
@ -148,7 +148,7 @@ public class ProfileConfigurationEditViewModel : DialogViewModelBase<ProfileConf
|
||||
if (!await _windowService.ShowConfirmContentDialog("Delete profile", "Are you sure you want to permanently delete this profile?"))
|
||||
return;
|
||||
|
||||
if (_profileConfiguration.IsBeingEdited)
|
||||
if (_profileService.FocusProfile == _profileConfiguration)
|
||||
await _profileEditorService.ChangeCurrentProfileConfiguration(null);
|
||||
_profileService.RemoveProfileConfiguration(_profileConfiguration);
|
||||
Close(_profileConfiguration);
|
||||
@ -184,7 +184,7 @@ public class ProfileConfigurationEditViewModel : DialogViewModelBase<ProfileConf
|
||||
get => _iconType;
|
||||
set => RaiseAndSetIfChanged(ref _iconType, value);
|
||||
}
|
||||
|
||||
|
||||
public ProfileIconViewModel? SelectedMaterialIcon
|
||||
{
|
||||
get => _selectedMaterialIcon;
|
||||
|
||||
@ -24,9 +24,9 @@ namespace Artemis.UI.Screens.Sidebar;
|
||||
public class SidebarCategoryViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IWindowService _windowService;
|
||||
private readonly ISidebarVmFactory _vmFactory;
|
||||
private readonly IRouter _router;
|
||||
private readonly ISidebarVmFactory _vmFactory;
|
||||
private readonly IWindowService _windowService;
|
||||
private ObservableAsPropertyHelper<bool>? _isCollapsed;
|
||||
private ObservableAsPropertyHelper<bool>? _isSuspended;
|
||||
private SidebarProfileConfigurationViewModel? _selectedProfileConfiguration;
|
||||
@ -67,9 +67,9 @@ public class SidebarCategoryViewModel : ActivatableViewModelBase
|
||||
.WhereNotNull()
|
||||
.Subscribe(s => _router.Navigate($"profile-editor/{s.ProfileConfiguration.ProfileId}", new RouterNavigationOptions {IgnoreOnPartialMatch = true, RecycleScreens = false}))
|
||||
.DisposeWith(d);
|
||||
|
||||
|
||||
_router.CurrentPath.WhereNotNull().Subscribe(r => SelectedProfileConfiguration = ProfileConfigurations.FirstOrDefault(c => c.Matches(r))).DisposeWith(d);
|
||||
|
||||
|
||||
// Update the list of profiles whenever the category fires events
|
||||
Observable.FromEventPattern<ProfileConfigurationEventArgs>(x => profileCategory.ProfileConfigurationAdded += x, x => profileCategory.ProfileConfigurationAdded -= x)
|
||||
.Subscribe(e => profileConfigurations.Add(e.EventArgs.ProfileConfiguration))
|
||||
@ -77,7 +77,7 @@ public class SidebarCategoryViewModel : ActivatableViewModelBase
|
||||
Observable.FromEventPattern<ProfileConfigurationEventArgs>(x => profileCategory.ProfileConfigurationRemoved += x, x => profileCategory.ProfileConfigurationRemoved -= x)
|
||||
.Subscribe(e => profileConfigurations.RemoveMany(profileConfigurations.Items.Where(c => c == e.EventArgs.ProfileConfiguration)))
|
||||
.DisposeWith(d);
|
||||
|
||||
|
||||
_isCollapsed = ProfileCategory.WhenAnyValue(vm => vm.IsCollapsed).ToProperty(this, vm => vm.IsCollapsed).DisposeWith(d);
|
||||
_isSuspended = ProfileCategory.WhenAnyValue(vm => vm.IsSuspended).ToProperty(this, vm => vm.IsSuspended).DisposeWith(d);
|
||||
});
|
||||
@ -136,7 +136,7 @@ public class SidebarCategoryViewModel : ActivatableViewModelBase
|
||||
{
|
||||
if (await _windowService.ShowConfirmContentDialog($"Delete {ProfileCategory.Name}", "Do you want to delete this category and all its profiles?"))
|
||||
{
|
||||
if (ProfileCategory.ProfileConfigurations.Any(c => c.IsBeingEdited))
|
||||
if (ProfileCategory.ProfileConfigurations.Any(c => _profileService.FocusProfile == c))
|
||||
await _router.Navigate("home");
|
||||
_profileService.DeleteProfileCategory(ProfileCategory);
|
||||
}
|
||||
@ -153,7 +153,7 @@ public class SidebarCategoryViewModel : ActivatableViewModelBase
|
||||
}
|
||||
|
||||
private async Task ExecuteImportProfile()
|
||||
{
|
||||
{
|
||||
string[]? result = await _windowService.CreateOpenFileDialog()
|
||||
.HavingFilter(f => f.WithExtension("json").WithName("Artemis profile"))
|
||||
.ShowAsync();
|
||||
|
||||
@ -98,7 +98,7 @@ public class SidebarProfileConfigurationViewModel : ActivatableViewModelBase
|
||||
if (!await _windowService.ShowConfirmContentDialog("Delete profile", "Are you sure you want to permanently delete this profile?"))
|
||||
return;
|
||||
|
||||
if (ProfileConfiguration.IsBeingEdited)
|
||||
if (_profileService.FocusProfile == ProfileConfiguration)
|
||||
await _router.Navigate("home");
|
||||
_profileService.RemoveProfileConfiguration(ProfileConfiguration);
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Categories;
|
||||
@ -12,10 +11,6 @@ public partial class CategoriesView : ReactiveUserControl<CategoriesViewModel>
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
private void InputElement_OnPointerReleased(object? sender, PointerReleasedEventArgs e)
|
||||
{
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.CurrentUser;
|
||||
@ -9,9 +8,4 @@ public partial class WorkshopLoginView : ReactiveUserControl<WorkshopLoginViewMo
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,3 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Entries;
|
||||
@ -11,9 +8,4 @@ public partial class EntryListView : ReactiveUserControl<EntryListViewModel>
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,3 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Home;
|
||||
@ -11,9 +8,4 @@ public partial class WorkshopHomeView : ReactiveUserControl<WorkshopHomeViewMode
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,3 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Layout;
|
||||
@ -9,9 +8,4 @@ public partial class LayoutDetailsView : ReactiveUserControl<LayoutDetailsViewMo
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,3 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Layout;
|
||||
@ -9,9 +8,4 @@ public partial class LayoutListView : ReactiveUserControl<LayoutListViewModel>
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,3 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Profile;
|
||||
@ -9,9 +8,4 @@ public partial class ProfileDetailsView : ReactiveUserControl<ProfileDetailsView
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,3 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Profile;
|
||||
@ -9,9 +8,4 @@ public partial class ProfileListView : ReactiveUserControl<ProfileListViewModel>
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
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:profile="clr-namespace:Artemis.UI.Screens.Workshop.Profile"
|
||||
xmlns:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Workshop.Profile.ProfilePreviewView"
|
||||
x:DataType="profile:ProfilePreviewViewModel">
|
||||
<UserControl.Resources>
|
||||
<VisualBrush x:Key="LargeCheckerboardBrush" TileMode="Tile" Stretch="Uniform" SourceRect="0,0,20,20">
|
||||
<VisualBrush.Visual>
|
||||
<Canvas Width="20" Height="20">
|
||||
<Rectangle Width="10" Height="10" Fill="Black" Opacity="0.15" />
|
||||
<Rectangle Width="10" Height="10" Canvas.Left="10" />
|
||||
<Rectangle Width="10" Height="10" Canvas.Top="10" />
|
||||
<Rectangle Width="10" Height="10" Canvas.Left="10" Canvas.Top="10" Fill="Black" Opacity="0.15" />
|
||||
</Canvas>
|
||||
</VisualBrush.Visual>
|
||||
</VisualBrush>
|
||||
</UserControl.Resources>
|
||||
<ZoomBorder Name="ZoomBorder"
|
||||
Stretch="None"
|
||||
ClipToBounds="True"
|
||||
Focusable="True"
|
||||
VerticalAlignment="Stretch"
|
||||
HorizontalAlignment="Stretch"
|
||||
Background="{StaticResource LargeCheckerboardBrush}"
|
||||
ZoomChanged="ZoomBorder_OnZoomChanged">
|
||||
<Grid Name="ContainerGrid" Background="Transparent">
|
||||
<Grid.Transitions>
|
||||
<Transitions>
|
||||
<TransformOperationsTransition Property="RenderTransform" Duration="0:0:0.2" Easing="CubicEaseOut" />
|
||||
</Transitions>
|
||||
</Grid.Transitions>
|
||||
|
||||
<ItemsControl Name="DevicesContainer" ItemsSource="{CompiledBinding Devices}" ClipToBounds="False">
|
||||
<ItemsControl.Styles>
|
||||
<Style Selector="ContentPresenter" x:DataType="core:ArtemisDevice">
|
||||
<Setter Property="Canvas.Left" Value="{CompiledBinding X}" />
|
||||
<Setter Property="Canvas.Top" Value="{CompiledBinding Y}" />
|
||||
</Style>
|
||||
</ItemsControl.Styles>
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="core:ArtemisDevice">
|
||||
<shared:DeviceVisualizer Device="{CompiledBinding}" ShowColors="True" RenderOptions.BitmapInterpolationMode="MediumQuality" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</ZoomBorder>
|
||||
</UserControl>
|
||||
@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.PanAndZoom;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.ReactiveUI;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Profile;
|
||||
|
||||
public partial class ProfilePreviewView : ReactiveUserControl<ProfilePreviewViewModel>
|
||||
{
|
||||
private bool _movedByUser;
|
||||
|
||||
public ProfilePreviewView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
ZoomBorder.PropertyChanged += ZoomBorderOnPropertyChanged;
|
||||
ZoomBorder.PointerMoved += ZoomBorderOnPointerMoved;
|
||||
ZoomBorder.PointerWheelChanged += ZoomBorderOnPointerWheelChanged;
|
||||
UpdateZoomBorderBackground();
|
||||
|
||||
this.WhenAnyValue(v => v.Bounds).Where(_ => !_movedByUser).Subscribe(_ => AutoFit());
|
||||
}
|
||||
|
||||
private void ZoomBorderOnPointerWheelChanged(object? sender, PointerWheelEventArgs e)
|
||||
{
|
||||
_movedByUser = true;
|
||||
}
|
||||
|
||||
private void ZoomBorderOnPointerMoved(object? sender, PointerEventArgs e)
|
||||
{
|
||||
if (e.GetCurrentPoint(ZoomBorder).Properties.IsMiddleButtonPressed)
|
||||
_movedByUser = true;
|
||||
}
|
||||
|
||||
private void ZoomBorderOnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.Property.Name == nameof(ZoomBorder.Background))
|
||||
UpdateZoomBorderBackground();
|
||||
}
|
||||
|
||||
private void UpdateZoomBorderBackground()
|
||||
{
|
||||
if (ZoomBorder.Background is VisualBrush visualBrush)
|
||||
visualBrush.DestinationRect = new RelativeRect(ZoomBorder.OffsetX * -1, ZoomBorder.OffsetY * -1, 20, 20, RelativeUnit.Absolute);
|
||||
}
|
||||
|
||||
private void ZoomBorder_OnZoomChanged(object sender, ZoomChangedEventArgs e)
|
||||
{
|
||||
UpdateZoomBorderBackground();
|
||||
}
|
||||
|
||||
private void AutoFit()
|
||||
{
|
||||
if (ViewModel == null || !ViewModel.Devices.Any())
|
||||
return;
|
||||
|
||||
double left = ViewModel.Devices.Select(d => d.Rectangle.Left).Min();
|
||||
double top = ViewModel.Devices.Select(d => d.Rectangle.Top).Min();
|
||||
double bottom = ViewModel.Devices.Select(d => d.Rectangle.Bottom).Max();
|
||||
double right = ViewModel.Devices.Select(d => d.Rectangle.Right).Max();
|
||||
|
||||
// Add a 10 pixel margin around the rect
|
||||
Rect scriptRect = new(new Point(left - 10, top - 10), new Point(right + 10, bottom + 10));
|
||||
|
||||
// The scale depends on the available space
|
||||
double scale = Math.Min(3, Math.Min(Bounds.Width / scriptRect.Width, Bounds.Height / scriptRect.Height));
|
||||
|
||||
// Pan and zoom to make the script fit
|
||||
ZoomBorder.Zoom(scale, 0, 0, true);
|
||||
ZoomBorder.Pan(Bounds.Center.X - scriptRect.Center.X * scale, Bounds.Center.Y - scriptRect.Center.Y * scale, true);
|
||||
|
||||
_movedByUser = false;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Profile;
|
||||
|
||||
public class ProfilePreviewViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IWindowService _windowService;
|
||||
private ProfileConfiguration? _profileConfiguration;
|
||||
|
||||
public ProfilePreviewViewModel(IProfileService profileService, IRgbService rgbService, IWindowService windowService)
|
||||
{
|
||||
_profileService = profileService;
|
||||
_windowService = windowService;
|
||||
|
||||
Devices = new ObservableCollection<ArtemisDevice>(rgbService.EnabledDevices.OrderBy(d => d.ZIndex));
|
||||
|
||||
this.WhenAnyValue(vm => vm.ProfileConfiguration).Subscribe(_ => Update());
|
||||
this.WhenActivated(d => Disposable.Create(() => PreviewProfile(null)).DisposeWith(d));
|
||||
}
|
||||
|
||||
public ObservableCollection<ArtemisDevice> Devices { get; }
|
||||
|
||||
public ProfileConfiguration? ProfileConfiguration
|
||||
{
|
||||
get => _profileConfiguration;
|
||||
set => RaiseAndSetIfChanged(ref _profileConfiguration, value);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
try
|
||||
{
|
||||
PreviewProfile(ProfileConfiguration);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_windowService.ShowExceptionDialog("Failed to load preview", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void PreviewProfile(ProfileConfiguration? profileConfiguration)
|
||||
{
|
||||
_profileService.FocusProfile = profileConfiguration;
|
||||
_profileService.UpdateFocusProfile = profileConfiguration != null;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.Search;
|
||||
|
||||
@ -10,9 +8,4 @@ public partial class SearchView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,3 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
|
||||
@ -9,9 +8,4 @@ public partial class EntryTypeView : ReactiveUserControl<EntryTypeViewModel>
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
|
||||
using Artemis.WebClient.Workshop;
|
||||
using ReactiveUI;
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
|
||||
@ -9,9 +8,4 @@ public partial class LoginStepView : ReactiveUserControl<LoginStepView>
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Screens.ProfileEditor.ProfileTree.Dialogs;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using FluentAvalonia.Core;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
|
||||
|
||||
public class ProfileAdaptionHintsLayerViewModel : ViewModelBase
|
||||
{
|
||||
private readonly IWindowService _windowService;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly ObservableAsPropertyHelper<string> _adaptionHintText;
|
||||
private int _adaptionHintCount;
|
||||
|
||||
public Layer Layer { get; }
|
||||
|
||||
public ProfileAdaptionHintsLayerViewModel(Layer layer, IWindowService windowService, IProfileService profileService)
|
||||
{
|
||||
_windowService = windowService;
|
||||
_profileService = profileService;
|
||||
_adaptionHintText = this.WhenAnyValue(vm => vm.AdaptionHintCount).Select(c => c == 1 ? "1 adaption hint" : $"{c} adaption hints").ToProperty(this, vm => vm.AdaptionHintText);
|
||||
|
||||
Layer = layer;
|
||||
EditAdaptionHints = ReactiveCommand.CreateFromTask(ExecuteEditAdaptionHints);
|
||||
AdaptionHintCount = layer.Adapter.AdaptionHints.Count;
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> EditAdaptionHints { get; }
|
||||
|
||||
public int AdaptionHintCount
|
||||
{
|
||||
get => _adaptionHintCount;
|
||||
private set => RaiseAndSetIfChanged(ref _adaptionHintCount, value);
|
||||
}
|
||||
|
||||
public string AdaptionHintText => _adaptionHintText.Value;
|
||||
|
||||
private async Task ExecuteEditAdaptionHints()
|
||||
{
|
||||
await _windowService.ShowDialogAsync<LayerHintsDialogViewModel, bool>(Layer);
|
||||
_profileService.SaveProfile(Layer.Profile, true);
|
||||
|
||||
AdaptionHintCount = Layer.Adapter.AdaptionHints.Count;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
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:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
xmlns:profile="clr-namespace:Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile.ProfileAdaptionHintsStepView"
|
||||
x:DataType="profile:ProfileAdaptionHintsStepViewModel">
|
||||
<Grid ColumnDefinitions="*,Auto" RowDefinitions="Auto,Auto, *">
|
||||
<Grid.Styles>
|
||||
<Styles>
|
||||
<Style Selector="TextBlock">
|
||||
<Setter Property="TextWrapping" Value="Wrap"></Setter>
|
||||
</Style>
|
||||
</Styles>
|
||||
</Grid.Styles>
|
||||
<TextBlock Grid.Row="0" Theme="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap">
|
||||
Set up profile adaption hints
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" TextWrapping="Wrap">
|
||||
Add hints below to help decide where to place this each layer when the profile is imported by another user.
|
||||
</TextBlock>
|
||||
|
||||
|
||||
<controls:HyperlinkButton Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Top"
|
||||
NavigateUri="https://wiki.artemis-rgb.com/guides/user/profiles/layers/adaption-hints?mtm_campaign=artemis&mtm_kwd=workshop-wizard">
|
||||
Learn more about adaption hints
|
||||
</controls:HyperlinkButton>
|
||||
|
||||
<ItemsRepeater ItemsSource="{CompiledBinding Layers}" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="0 10 0 0">
|
||||
<ItemsRepeater.ItemTemplate>
|
||||
<DataTemplate DataType="profile:ProfileAdaptionHintsLayerViewModel">
|
||||
<StackPanel>
|
||||
<Border Classes="card-separator" />
|
||||
<Grid ColumnDefinitions="Auto,*,Auto" RowDefinitions="*,*">
|
||||
<avalonia:MaterialIcon Grid.Column="0"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Width="25"
|
||||
Height="25"
|
||||
Margin="5 0 10 0"
|
||||
Kind="{CompiledBinding Layer.LayerBrush.Descriptor.Icon, FallbackValue=QuestionMark}" />
|
||||
<TextBlock Grid.Column="1" Grid.Row="0" Text="{CompiledBinding Layer.Name}" />
|
||||
<TextBlock Grid.Column="1"
|
||||
Grid.Row="1"
|
||||
VerticalAlignment="Top"
|
||||
Classes="subtitle"
|
||||
Classes.danger="{CompiledBinding !AdaptionHintCount}"
|
||||
Text="{CompiledBinding AdaptionHintText}">
|
||||
</TextBlock>
|
||||
<Button Grid.Column="2"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Command="{Binding EditAdaptionHints}">
|
||||
Edit hints
|
||||
</Button>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ItemsRepeater.ItemTemplate>
|
||||
</ItemsRepeater>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -0,0 +1,11 @@
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
|
||||
|
||||
public partial class ProfileAdaptionHintsStepView : ReactiveUserControl<ProfileAdaptionHintsStepViewModel>
|
||||
{
|
||||
public ProfileAdaptionHintsStepView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Screens.ProfileEditor.ProfileTree.Dialogs;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using DynamicData;
|
||||
using ReactiveUI;
|
||||
using DynamicData.Aggregation;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
|
||||
|
||||
public class ProfileAdaptionHintsStepViewModel : SubmissionViewModel
|
||||
{
|
||||
private readonly IWindowService _windowService;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly SourceList<ProfileAdaptionHintsLayerViewModel> _layers;
|
||||
|
||||
public ProfileAdaptionHintsStepViewModel(IWindowService windowService, IProfileService profileService, Func<Layer, ProfileAdaptionHintsLayerViewModel> getLayerViewModel)
|
||||
{
|
||||
_windowService = windowService;
|
||||
_profileService = profileService;
|
||||
_layers = new SourceList<ProfileAdaptionHintsLayerViewModel>();
|
||||
_layers.Connect().Bind(out ReadOnlyObservableCollection<ProfileAdaptionHintsLayerViewModel> layers).Subscribe();
|
||||
|
||||
GoBack = ReactiveCommand.Create(() => State.ChangeScreen<ProfileSelectionStepViewModel>());
|
||||
Continue = ReactiveCommand.Create(ExecuteContinue, _layers.Connect().AutoRefresh(l => l.AdaptionHintCount).Filter(l => l.AdaptionHintCount == 0).IsEmpty());
|
||||
EditAdaptionHints = ReactiveCommand.CreateFromTask<Layer>(ExecuteEditAdaptionHints);
|
||||
Layers = layers;
|
||||
|
||||
this.WhenActivated((CompositeDisposable _) =>
|
||||
{
|
||||
if (State.EntrySource is ProfileConfiguration profileConfiguration && profileConfiguration.Profile != null)
|
||||
{
|
||||
_layers.Edit(l =>
|
||||
{
|
||||
l.Clear();
|
||||
l.AddRange(profileConfiguration.Profile.GetAllLayers().Select(getLayerViewModel));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public override ReactiveCommand<Unit, Unit> Continue { get; }
|
||||
public override ReactiveCommand<Unit, Unit> GoBack { get; }
|
||||
public ReactiveCommand<Layer, Unit> EditAdaptionHints { get; }
|
||||
public ReadOnlyObservableCollection<ProfileAdaptionHintsLayerViewModel> Layers { get; }
|
||||
|
||||
private async Task ExecuteEditAdaptionHints(Layer layer)
|
||||
{
|
||||
await _windowService.ShowDialogAsync<LayerHintsDialogViewModel, bool>(layer);
|
||||
_profileService.SaveProfile(layer.Profile, true);
|
||||
}
|
||||
|
||||
private void ExecuteContinue()
|
||||
{
|
||||
if (Layers.Any(l => l.AdaptionHintCount == 0))
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
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:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:profile="clr-namespace:Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile.ProfileSelectionStepView"
|
||||
x:DataType="profile:ProfileSelectionStepViewModel">
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<StackPanel>
|
||||
<StackPanel.Styles>
|
||||
<Styles>
|
||||
<Style Selector="TextBlock">
|
||||
<Setter Property="TextWrapping" Value="Wrap"></Setter>
|
||||
</Style>
|
||||
</Styles>
|
||||
</StackPanel.Styles>
|
||||
<TextBlock Theme="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap">
|
||||
Profile selection
|
||||
</TextBlock>
|
||||
<TextBlock TextWrapping="Wrap">
|
||||
Please select the profile you want to share, a preview will be shown below.
|
||||
</TextBlock>
|
||||
|
||||
<ComboBox ItemsSource="{CompiledBinding Profiles}" SelectedItem="{CompiledBinding SelectedProfile}"
|
||||
Width="460"
|
||||
VerticalContentAlignment="Center"
|
||||
Height="50"
|
||||
Margin="0 15"
|
||||
PlaceholderText="Select a profile">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate DataType="core:ProfileConfiguration">
|
||||
<Grid RowDefinitions="Auto,*" ColumnDefinitions="Auto,*">
|
||||
<shared:ProfileConfigurationIcon Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="0"
|
||||
ConfigurationIcon="{CompiledBinding Icon}"
|
||||
VerticalAlignment="Center"
|
||||
Width="22"
|
||||
Height="22"
|
||||
Margin="0 0 10 0" />
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Text="{CompiledBinding Name}" TextTrimming="CharacterEllipsis"></TextBlock>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Text="{CompiledBinding Category.Name}" TextTrimming="CharacterEllipsis" Classes="subtitle"></TextBlock>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
<Border Grid.Row="1" Classes="card" Padding="0" ClipToBounds="True" IsVisible="{CompiledBinding SelectedProfile, Converter={x:Static ObjectConverters.IsNotNull}}">
|
||||
<ContentControl Content="{CompiledBinding ProfilePreview}"></ContentControl>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
</UserControl>
|
||||
@ -0,0 +1,11 @@
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
|
||||
|
||||
public partial class ProfileSelectionStepView : ReactiveUserControl<ProfileSelectionStepViewModel>
|
||||
{
|
||||
public ProfileSelectionStepView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using Artemis.UI.Screens.Workshop.Profile;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
|
||||
|
||||
public class ProfileSelectionStepViewModel : SubmissionViewModel
|
||||
{
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IProfileCategoryRepository _profileCategoryRepository;
|
||||
private ProfileConfiguration? _selectedProfile;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ProfileSelectionStepViewModel(IProfileService profileService, ProfilePreviewViewModel profilePreviewViewModel)
|
||||
{
|
||||
_profileService = profileService;
|
||||
|
||||
// Use copies of the profiles, the originals are used by the core and could be disposed
|
||||
Profiles = new ObservableCollection<ProfileConfiguration>(_profileService.ProfileConfigurations.Select(_profileService.CloneProfileConfiguration));
|
||||
ProfilePreview = profilePreviewViewModel;
|
||||
|
||||
GoBack = ReactiveCommand.Create(() => State.ChangeScreen<EntryTypeViewModel>());
|
||||
Continue = ReactiveCommand.Create(ExecuteContinue, this.WhenAnyValue(vm => vm.SelectedProfile).Select(p => p != null));
|
||||
|
||||
this.WhenAnyValue(vm => vm.SelectedProfile).Subscribe(p => Update(p));
|
||||
this.WhenActivated((CompositeDisposable _) =>
|
||||
{
|
||||
if (State.EntrySource is ProfileConfiguration profileConfiguration)
|
||||
SelectedProfile = Profiles.FirstOrDefault(p => p.ProfileId == profileConfiguration.ProfileId);
|
||||
});
|
||||
}
|
||||
|
||||
private void Update(ProfileConfiguration? profileConfiguration)
|
||||
{
|
||||
ProfilePreview.ProfileConfiguration = null;
|
||||
|
||||
foreach (ProfileConfiguration configuration in Profiles)
|
||||
{
|
||||
if (configuration == profileConfiguration)
|
||||
_profileService.ActivateProfile(configuration);
|
||||
else
|
||||
_profileService.DeactivateProfile(configuration);
|
||||
}
|
||||
|
||||
ProfilePreview.ProfileConfiguration = profileConfiguration;
|
||||
}
|
||||
|
||||
public ObservableCollection<ProfileConfiguration> Profiles { get; }
|
||||
public ProfilePreviewViewModel ProfilePreview { get; }
|
||||
|
||||
public ProfileConfiguration? SelectedProfile
|
||||
{
|
||||
get => _selectedProfile;
|
||||
set => RaiseAndSetIfChanged(ref _selectedProfile, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ReactiveCommand<Unit, Unit> Continue { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ReactiveCommand<Unit, Unit> GoBack { get; }
|
||||
|
||||
private void ExecuteContinue()
|
||||
{
|
||||
if (SelectedProfile == null)
|
||||
return;
|
||||
|
||||
State.EntrySource = SelectedProfile;
|
||||
State.Name = SelectedProfile.Name;
|
||||
State.Icon = SelectedProfile.Icon.GetIconStream();
|
||||
|
||||
State.ChangeScreen<ProfileAdaptionHintsStepViewModel>();
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
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:steps="clr-namespace:Artemis.UI.Screens.Workshop.SubmissionWizard.Steps"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.ProfileSelectionStepView"
|
||||
x:DataType="steps:ProfileSelectionStepViewModel">
|
||||
Welcome to Avalonia!
|
||||
</UserControl>
|
||||
@ -1,18 +0,0 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
|
||||
|
||||
public partial class ProfileSelectionStepView : UserControl
|
||||
{
|
||||
public ProfileSelectionStepView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
using System.Reactive;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
|
||||
|
||||
public class ProfileSelectionStepViewModel : SubmissionViewModel
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override ReactiveCommand<Unit, Unit> Continue { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ReactiveCommand<Unit, Unit> GoBack { get; }
|
||||
}
|
||||
@ -1,4 +1,3 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
|
||||
@ -9,9 +8,4 @@ public partial class ValidateEmailStepView : ReactiveUserControl<ValidateEmailSt
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,3 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
|
||||
@ -9,9 +8,4 @@ public partial class WelcomeStepView : ReactiveUserControl<WelcomeStepViewModel>
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -7,8 +7,8 @@ namespace Artemis.UI.Screens.Workshop.SubmissionWizard;
|
||||
|
||||
public class SubmissionWizardState
|
||||
{
|
||||
private readonly SubmissionWizardViewModel _wizardViewModel;
|
||||
private readonly IContainer _container;
|
||||
private readonly SubmissionWizardViewModel _wizardViewModel;
|
||||
|
||||
public SubmissionWizardState(SubmissionWizardViewModel wizardViewModel, IContainer container)
|
||||
{
|
||||
@ -27,6 +27,8 @@ public class SubmissionWizardState
|
||||
public List<int> Tags { get; set; } = new();
|
||||
public List<Stream> Images { get; set; } = new();
|
||||
|
||||
public object? EntrySource { get; set; }
|
||||
|
||||
public void ChangeScreen<TSubmissionViewModel>() where TSubmissionViewModel : SubmissionViewModel
|
||||
{
|
||||
_wizardViewModel.Screen = _container.Resolve<TSubmissionViewModel>();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user