mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Sidebar - Show message when profile is broken
Events - Keep the old event type around for if you change your mind
This commit is contained in:
parent
d6372dffad
commit
02f4609eae
@ -377,7 +377,7 @@ namespace Artemis.Core
|
||||
public ICondition? DisplayCondition
|
||||
{
|
||||
get => _displayCondition;
|
||||
private set => SetAndNotify(ref _displayCondition, value);
|
||||
set => SetAndNotify(ref _displayCondition, value);
|
||||
}
|
||||
|
||||
private ICondition? _displayCondition;
|
||||
@ -404,21 +404,6 @@ namespace Artemis.Core
|
||||
DisplayConditionMet = DisplayCondition.IsMet;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the current <see cref="DisplayCondition" /> with the provided <paramref name="condition" /> or
|
||||
/// <see langword="null" />
|
||||
/// </summary>
|
||||
/// <param name="condition">The condition to change the <see cref="DisplayCondition" /> to</param>
|
||||
public void ChangeDisplayCondition(ICondition? condition)
|
||||
{
|
||||
if (condition == DisplayCondition)
|
||||
return;
|
||||
|
||||
ICondition? old = DisplayCondition;
|
||||
DisplayCondition = condition;
|
||||
old?.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -327,7 +327,17 @@ namespace Artemis.Core.Services
|
||||
if (profileConfiguration.Profile != null)
|
||||
return profileConfiguration.Profile;
|
||||
|
||||
ProfileEntity profileEntity = _profileRepository.Get(profileConfiguration.Entity.ProfileId);
|
||||
ProfileEntity profileEntity;
|
||||
try
|
||||
{
|
||||
profileEntity = _profileRepository.Get(profileConfiguration.Entity.ProfileId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
profileConfiguration.SetBrokenState("Failed to activate profile", e);
|
||||
throw;
|
||||
}
|
||||
|
||||
if (profileEntity == null)
|
||||
throw new ArtemisCoreException($"Cannot find profile named: {profileConfiguration.Name} ID: {profileConfiguration.Entity.ProfileId}");
|
||||
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance {x:Type displayConditions:DisplayConditionsViewModel}}">
|
||||
<UserControl.Resources>
|
||||
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
|
||||
<converters:ComparisonConverter x:Key="ComparisonConverter" />
|
||||
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
</UserControl.Resources>
|
||||
@ -100,6 +99,20 @@
|
||||
s:View.Model="{Binding ActiveItem}"
|
||||
VerticalContentAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
IsTabStop="False"/>
|
||||
IsTabStop="False"
|
||||
Visibility="{Binding ActiveItem, Converter={StaticResource NullToVisibilityConverter}}"/>
|
||||
|
||||
<StackPanel Grid.Row="2"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Visibility="{Binding ActiveItem, ConverterParameter=Inverted, Converter={StaticResource NullToVisibilityConverter}}">
|
||||
<TextBlock Style="{StaticResource MaterialDesignHeadline5TextBlock}" TextWrapping="Wrap" TextAlignment="Center" Margin="0 10">
|
||||
Display conditions disabled
|
||||
<materialDesign:PackIcon Kind="No" Margin="0 0 0 -6" Width="30" Height="30" VerticalAlignment="Center" />
|
||||
</TextBlock>
|
||||
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}" TextWrapping="Wrap" TextAlignment="Center">
|
||||
This element will always display.
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -11,6 +11,8 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
|
||||
private readonly IConditionVmFactory _conditionVmFactory;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private DisplayConditionType _displayConditionType;
|
||||
private StaticCondition _staticCondition;
|
||||
private EventCondition _eventCondition;
|
||||
|
||||
public DisplayConditionsViewModel(IProfileEditorService profileEditorService, IConditionVmFactory conditionVmFactory)
|
||||
{
|
||||
@ -47,12 +49,19 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
|
||||
if (_profileEditorService.SelectedProfileElement == null)
|
||||
return;
|
||||
|
||||
// Keep the old condition around in case the user changes their mind
|
||||
if (_profileEditorService.SelectedProfileElement.DisplayCondition is StaticCondition staticCondition)
|
||||
_staticCondition = staticCondition;
|
||||
else if (_profileEditorService.SelectedProfileElement.DisplayCondition is EventCondition eventCondition)
|
||||
_eventCondition = eventCondition;
|
||||
|
||||
// If we have the old condition around put it back
|
||||
if (DisplayConditionType == DisplayConditionType.Static)
|
||||
_profileEditorService.SelectedProfileElement.ChangeDisplayCondition(new StaticCondition(_profileEditorService.SelectedProfileElement));
|
||||
_profileEditorService.SelectedProfileElement.DisplayCondition = _staticCondition ?? new StaticCondition(_profileEditorService.SelectedProfileElement);
|
||||
else if (DisplayConditionType == DisplayConditionType.Events)
|
||||
_profileEditorService.SelectedProfileElement.ChangeDisplayCondition(new EventCondition(_profileEditorService.SelectedProfileElement));
|
||||
_profileEditorService.SelectedProfileElement.DisplayCondition = _eventCondition ?? new EventCondition(_profileEditorService.SelectedProfileElement);
|
||||
else
|
||||
_profileEditorService.SelectedProfileElement.ChangeDisplayCondition(null);
|
||||
_profileEditorService.SelectedProfileElement.DisplayCondition = null;
|
||||
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
Update(_profileEditorService.SelectedProfileElement);
|
||||
@ -87,6 +96,11 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
|
||||
|
||||
private void ProfileEditorServiceOnSelectedProfileElementChanged(object sender, RenderProfileElementEventArgs e)
|
||||
{
|
||||
if (_staticCondition != null && e.PreviousRenderProfileElement?.DisplayCondition != _staticCondition)
|
||||
_staticCondition.Dispose();
|
||||
if (_eventCondition != null && e.PreviousRenderProfileElement?.DisplayCondition != _eventCondition)
|
||||
_eventCondition.Dispose();
|
||||
|
||||
Update(e.RenderProfileElement);
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@
|
||||
IsChecked="{Binding TriggerConditionally}"
|
||||
Content="Conditional trigger"
|
||||
VerticalAlignment="Center"
|
||||
ToolTip="When enabled, the layer will only trigger if the script evaluates to true"
|
||||
ToolTip="When enabled, the element will only trigger if the script evaluates to true"
|
||||
Style="{StaticResource MaterialDesignDarkCheckBox}" />
|
||||
|
||||
<Grid Grid.Row="1"
|
||||
@ -60,7 +60,7 @@
|
||||
Cursor="Hand"
|
||||
Visibility="{Binding EventCondition.Script, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Normal, Mode=OneWay}">
|
||||
<controls:VisualScriptPresenter Script="{Binding EventCondition.Script}" AutoFitScript="True" />
|
||||
<Border VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
|
||||
<Border VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Opacity="0">
|
||||
<Border.Background>
|
||||
<SolidColorBrush Color="{Binding Color, Source={StaticResource MaterialDesignCardBackground}}" Opacity="0.75" />
|
||||
</Border.Background>
|
||||
@ -105,7 +105,7 @@
|
||||
<materialDesign:PackIcon Kind="No" Margin="0 0 0 -6" Width="30" Height="30" VerticalAlignment="Center" />
|
||||
</TextBlock>
|
||||
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}" TextWrapping="Wrap" TextAlignment="Center">
|
||||
When enabled, the layer will only trigger if the script evaluates to true
|
||||
This element will trigger any time the event fires.
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
@ -84,6 +84,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions.Event
|
||||
{
|
||||
EventCondition.UpdateEventNode();
|
||||
DisplayName = EventCondition.EventPath?.Segments.LastOrDefault()?.GetPropertyDescription()?.Name ?? "Invalid event";
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
public void ScriptGridMouseUp(object sender, MouseButtonEventArgs e)
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
<!-- Above is a dumb hack to get the context menu to cover the entire item -->
|
||||
<UserControl.Resources>
|
||||
<converters:ValuesAdditionConverter x:Key="ValuesAddition" />
|
||||
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
</UserControl.Resources>
|
||||
<UserControl.ContextMenu>
|
||||
<ContextMenu>
|
||||
@ -183,7 +184,13 @@
|
||||
</Border.Style>
|
||||
</Border>
|
||||
|
||||
<Button Grid.Column="2" ToolTip="View properties" Width="20" Height="20" Command="{s:Action ViewProperties}" HorizontalAlignment="Right">
|
||||
<Button Grid.Column="2"
|
||||
ToolTip="View properties"
|
||||
Width="20"
|
||||
Height="20"
|
||||
Command="{s:Action ViewProperties}"
|
||||
HorizontalAlignment="Right"
|
||||
Visibility="{Binding ProfileConfiguration.BrokenState, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignIconForegroundButton}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
@ -196,7 +203,13 @@
|
||||
</Button.Style>
|
||||
<materialDesign:PackIcon Kind="Cog" Width="16" Height="16" />
|
||||
</Button>
|
||||
<ToggleButton Grid.Column="3" ToolTip="Suspend profile" Width="18" Height="18" Margin="2 0 0 0" IsChecked="{Binding IsSuspended}">
|
||||
<ToggleButton Grid.Column="3"
|
||||
ToolTip="Suspend profile"
|
||||
Width="18"
|
||||
Height="18"
|
||||
Margin="2 0 0 0"
|
||||
IsChecked="{Binding IsSuspended}"
|
||||
Visibility="{Binding ProfileConfiguration.BrokenState, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
|
||||
<ToggleButton.Style>
|
||||
<Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource MaterialDesignFlatToggleButton}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
@ -209,5 +222,14 @@
|
||||
</ToggleButton.Style>
|
||||
<materialDesign:PackIcon Kind="Pause" Height="14" Width="14" />
|
||||
</ToggleButton>
|
||||
|
||||
<materialDesign:PackIcon Grid.Column="3"
|
||||
Margin="-2"
|
||||
Kind="AlertCircle"
|
||||
Height="22"
|
||||
Width="22"
|
||||
Foreground="#E74C4C"
|
||||
ToolTip="{Binding ProfileConfiguration.BrokenState}"
|
||||
Visibility="{Binding ProfileConfiguration.BrokenState, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -157,6 +157,12 @@ namespace Artemis.UI.Screens.Sidebar
|
||||
|
||||
public void SelectProfileConfiguration(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
if (profileConfiguration?.BrokenStateException != null)
|
||||
{
|
||||
_dialogService.ShowExceptionDialog("The profile failed to load", profileConfiguration.BrokenStateException);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (SidebarCategoryViewModel sidebarCategoryViewModel in Items)
|
||||
sidebarCategoryViewModel.SelectedProfileConfiguration = sidebarCategoryViewModel.Items.FirstOrDefault(i => i.ProfileConfiguration == profileConfiguration);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user