1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Display conditions - Added Toggle mode to event conditions

Display conditions - Added Contains and Does not contain for enums
Profile editor - Changed display behaviour on zero-length timelines
This commit is contained in:
Robert 2021-06-19 12:25:11 +02:00
parent 048864fe78
commit f24e1ae264
7 changed files with 88 additions and 18 deletions

View File

@ -0,0 +1,15 @@
using System;
namespace Artemis.Core
{
internal class EnumContainsConditionOperator : ConditionOperator<Enum, Enum>
{
public override string Description => "Contains";
public override string Icon => "Contain";
public override bool Evaluate(Enum a, Enum b)
{
return a != null && b != null && a.HasFlag(b);
}
}
}

View File

@ -0,0 +1,15 @@
using System;
namespace Artemis.Core
{
internal class EnumNotContainsConditionOperator : ConditionOperator<Enum, Enum>
{
public override string Description => "Does not contain";
public override string Icon => "FormatStrikethrough";
public override bool Evaluate(Enum a, Enum b)
{
return a != null && (b == null || !a.HasFlag(b));
}
}
}

View File

@ -9,7 +9,7 @@ namespace Artemis.Core
public override bool Evaluate(string a, string b) public override bool Evaluate(string a, string b)
{ {
return a != null && b != null && !a.Contains(b, StringComparison.InvariantCultureIgnoreCase); return a != null && (b == null || !a.Contains(b, StringComparison.InvariantCultureIgnoreCase));
} }
} }
} }

View File

@ -124,8 +124,8 @@ namespace Artemis.Core
public void UpdateTimeline(double deltaTime) public void UpdateTimeline(double deltaTime)
{ {
// The play mode dictates whether to stick to the main segment unless the display conditions contains events // The play mode dictates whether to stick to the main segment unless the display conditions contains events
bool stickToMainSegment = Timeline.PlayMode == TimelinePlayMode.Repeat && DisplayConditionMet; bool stickToMainSegment = (Timeline.PlayMode == TimelinePlayMode.Repeat || Timeline.EventOverlapMode == TimeLineEventOverlapMode.Toggle) && DisplayConditionMet;
if (DisplayCondition != null && DisplayCondition.ContainsEvents) if (DisplayCondition != null && DisplayCondition.ContainsEvents && Timeline.EventOverlapMode != TimeLineEventOverlapMode.Toggle)
stickToMainSegment = false; stickToMainSegment = false;
Timeline.Update(TimeSpan.FromSeconds(deltaTime), stickToMainSegment); Timeline.Update(TimeSpan.FromSeconds(deltaTime), stickToMainSegment);
@ -356,6 +356,7 @@ namespace Artemis.Core
private DataModelConditionGroup? _displayCondition; private DataModelConditionGroup? _displayCondition;
private bool _displayConditionMet; private bool _displayConditionMet;
private bool _toggledOnByEvent = false;
/// <summary> /// <summary>
/// Gets or sets the root display condition group /// Gets or sets the root display condition group
@ -383,6 +384,9 @@ namespace Artemis.Core
return; return;
} }
if (Timeline.EventOverlapMode != TimeLineEventOverlapMode.Toggle)
_toggledOnByEvent = false;
bool conditionMet = DisplayCondition.Evaluate(); bool conditionMet = DisplayCondition.Evaluate();
if (Parent is RenderProfileElement parent && !parent.DisplayConditionMet) if (Parent is RenderProfileElement parent && !parent.DisplayConditionMet)
conditionMet = false; conditionMet = false;
@ -398,25 +402,36 @@ namespace Artemis.Core
} }
else if (conditionMet) else if (conditionMet)
{ {
// Event conditions reset if the timeline finished if (Timeline.EventOverlapMode == TimeLineEventOverlapMode.Toggle)
if (Timeline.IsFinished)
{ {
Timeline.JumpToStart(); _toggledOnByEvent = !_toggledOnByEvent;
if (_toggledOnByEvent)
Timeline.JumpToStart();
} }
// and otherwise apply their overlap mode
else else
{ {
if (Timeline.EventOverlapMode == TimeLineEventOverlapMode.Restart) // Event conditions reset if the timeline finished
if (Timeline.IsFinished)
{
Timeline.JumpToStart(); Timeline.JumpToStart();
else if (Timeline.EventOverlapMode == TimeLineEventOverlapMode.Copy) }
Timeline.AddExtraTimeline(); // and otherwise apply their overlap mode
// The third option is ignore which is handled below: else
{
if (Timeline.EventOverlapMode == TimeLineEventOverlapMode.Restart)
Timeline.JumpToStart();
else if (Timeline.EventOverlapMode == TimeLineEventOverlapMode.Copy)
Timeline.AddExtraTimeline();
// The third option is ignore which is handled below:
// done // done
}
} }
} }
DisplayConditionMet = conditionMet; DisplayConditionMet = Timeline.EventOverlapMode == TimeLineEventOverlapMode.Toggle
? _toggledOnByEvent
: conditionMet;
} }
#endregion #endregion

View File

@ -155,7 +155,7 @@ namespace Artemis.Core
/// <summary> /// <summary>
/// Gets a boolean indicating whether the timeline has finished its run /// Gets a boolean indicating whether the timeline has finished its run
/// </summary> /// </summary>
public bool IsFinished => (Position > Length || Length == TimeSpan.Zero) && !ExtraTimelines.Any(); public bool IsFinished => Position > Length && !ExtraTimelines.Any();
/// <summary> /// <summary>
/// Gets a boolean indicating whether the timeline progress has been overridden /// Gets a boolean indicating whether the timeline progress has been overridden
@ -516,6 +516,11 @@ namespace Artemis.Core
/// <summary> /// <summary>
/// Play another copy of the timeline on top of the current run /// Play another copy of the timeline on top of the current run
/// </summary> /// </summary>
Copy Copy,
/// <summary>
/// Repeat the timeline until the event fires again
/// </summary>
Toggle
} }
} }

View File

@ -64,6 +64,10 @@ namespace Artemis.Core.Services
RegisterConditionOperator(Constants.CorePlugin, new StringNullConditionOperator()); RegisterConditionOperator(Constants.CorePlugin, new StringNullConditionOperator());
RegisterConditionOperator(Constants.CorePlugin, new StringNotNullConditionOperator()); RegisterConditionOperator(Constants.CorePlugin, new StringNotNullConditionOperator());
// Enum operators
RegisterConditionOperator(Constants.CorePlugin, new EnumContainsConditionOperator());
RegisterConditionOperator(Constants.CorePlugin, new EnumNotContainsConditionOperator());
// Null checks, at the bottom // Null checks, at the bottom
// TODO: Implement a priority mechanism // TODO: Implement a priority mechanism
RegisterConditionOperator(Constants.CorePlugin, new NullConditionOperator()); RegisterConditionOperator(Constants.CorePlugin, new NullConditionOperator());

View File

@ -192,11 +192,11 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!-- Trigger mode --> <!-- Trigger mode -->
<TextBlock Grid.Column="0" Text="Rapid trigger mode"> <TextBlock Grid.Column="0" Text="Trigger mode">
<TextBlock.ToolTip> <TextBlock.ToolTip>
<ToolTip Placement="Center" VerticalOffset="-30"> <ToolTip Placement="Center" VerticalOffset="-30">
<TextBlock> <TextBlock>
Configure how the layer should act when the event(s) trigger before the timeline finishes Configure how the layer should act when the event(s) trigger
</TextBlock> </TextBlock>
</ToolTip> </ToolTip>
</TextBlock.ToolTip> </TextBlock.ToolTip>
@ -207,6 +207,7 @@
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<RadioButton Grid.Column="0" <RadioButton Grid.Column="0"
Style="{StaticResource MaterialDesignTabRadioButton}" Style="{StaticResource MaterialDesignTabRadioButton}"
@ -224,6 +225,21 @@
</RadioButton.ToolTip> </RadioButton.ToolTip>
</RadioButton> </RadioButton>
<RadioButton Grid.Column="1" <RadioButton Grid.Column="1"
Style="{StaticResource MaterialDesignTabRadioButton}"
IsChecked="{Binding Path=EventOverlapMode, Converter={StaticResource ComparisonConverter}, ConverterParameter={x:Static core:TimeLineEventOverlapMode.Toggle}}">
<TextBlock VerticalAlignment="Center" FontSize="12">
<materialDesign:PackIcon Kind="TrafficLight" VerticalAlignment="Center" Margin="-3 0 0 -3" />
TOGGLE
</TextBlock>
<RadioButton.ToolTip>
<ToolTip Placement="Center" VerticalOffset="-40">
<TextBlock>
Repeat the timeline until the event fires again
</TextBlock>
</ToolTip>
</RadioButton.ToolTip>
</RadioButton>
<RadioButton Grid.Column="2"
Style="{StaticResource MaterialDesignTabRadioButton}" Style="{StaticResource MaterialDesignTabRadioButton}"
IsChecked="{Binding Path=EventOverlapMode, Converter={StaticResource ComparisonConverter}, ConverterParameter={x:Static core:TimeLineEventOverlapMode.Ignore}}"> IsChecked="{Binding Path=EventOverlapMode, Converter={StaticResource ComparisonConverter}, ConverterParameter={x:Static core:TimeLineEventOverlapMode.Ignore}}">
<TextBlock VerticalAlignment="Center" FontSize="12"> <TextBlock VerticalAlignment="Center" FontSize="12">
@ -238,7 +254,7 @@
</ToolTip> </ToolTip>
</RadioButton.ToolTip> </RadioButton.ToolTip>
</RadioButton> </RadioButton>
<RadioButton Grid.Column="2" <RadioButton Grid.Column="3"
Style="{StaticResource MaterialDesignTabRadioButton}" Style="{StaticResource MaterialDesignTabRadioButton}"
IsChecked="{Binding Path=EventOverlapMode, Converter={StaticResource ComparisonConverter}, ConverterParameter={x:Static core:TimeLineEventOverlapMode.Copy}}"> IsChecked="{Binding Path=EventOverlapMode, Converter={StaticResource ComparisonConverter}, ConverterParameter={x:Static core:TimeLineEventOverlapMode.Copy}}">
<TextBlock VerticalAlignment="Center" FontSize="12"> <TextBlock VerticalAlignment="Center" FontSize="12">