diff --git a/Project-Aurora/Project-Aurora/Settings/Overrides/Logic/Boolean/Boolean_FlipFlop.cs b/Project-Aurora/Project-Aurora/Settings/Overrides/Logic/Boolean/Boolean_FlipFlop.cs index a22bbf8c5..76ccbeb5b 100644 --- a/Project-Aurora/Project-Aurora/Settings/Overrides/Logic/Boolean/Boolean_FlipFlop.cs +++ b/Project-Aurora/Project-Aurora/Settings/Overrides/Logic/Boolean/Boolean_FlipFlop.cs @@ -1,17 +1,19 @@ using Aurora.Profiles; using Aurora.Utils; +using System; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; -namespace Aurora.Settings.Overrides.Logic.Boolean { - +namespace Aurora.Settings.Overrides.Logic.Boolean +{ + #region Obsolete /// /// A simple memory gate that can be used for storing a boolean state. /// While the given input is true, the state of the flip-flop is toggled. /// - [Evaluatable("Flip-flop (Toggle)", category: EvaluatableCategory.Logic)] + [Obsolete("This Evaluatable is obsolete. Use Boolean_FlipFlop instead.", false)] public class Boolean_FlipFlopT : Evaluatable { private bool state = false; @@ -42,7 +44,7 @@ protected override bool Execute(IGameState gameState) { /// A simple memory gate that can be used for storing a boolean state. /// When 'Set' is true, the gate will start outputting true until 'Reset' becomes true. /// - [Evaluatable("Flip-flop (Set-Reset)", category: EvaluatableCategory.Logic)] + [Obsolete("This Evaluatable is obsolete. Use Boolean_FlipFlop instead.", false)] public class Boolean_FlipFlopSR : Evaluatable { private bool state = false; @@ -74,4 +76,52 @@ protected override bool Execute(IGameState gameState) { public override Evaluatable Clone() => new Boolean_FlipFlopSR(Set.Clone(), Reset.Clone()); } -} + #endregion + + /// + /// A simple memory gate that can be used for storing a boolean state and also Toggle it. + /// When 'Set' is true, the gate will start outputting true until 'Reset' becomes true. + /// You can also Toggle it with the toggle input. + /// + [Evaluatable("Flip-flop", category: EvaluatableCategory.Logic)] + public class Boolean_FlipFlop : Evaluatable + { + + private bool state = false; + + public Evaluatable Toggle { get; set; } + public Evaluatable Set { get; set; } + public Evaluatable Reset { get; set; } + + public Boolean_FlipFlop() : this(EvaluatableDefaults.Get(), EvaluatableDefaults.Get(), EvaluatableDefaults.Get()) { } + public Boolean_FlipFlop(Evaluatable toggle, Evaluatable set, Evaluatable reset) { Toggle = toggle; Set = set; Reset = reset; } + + protected override bool Execute(IGameState gameState) + { + if (Toggle.Evaluate(gameState)) + state = !state; + if (Reset.Evaluate(gameState)) + state = false; + if (Set.Evaluate(gameState)) + state = true; + return state; + } + + public override Visual GetControl() => new StackPanel() + .WithChild(new TextBlock { Text = "Flip-Flop", FontWeight = FontWeights.Bold }) + .WithChild(new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 4, 0, 4) } + .WithChild(new Label { Content = "Toggle" }) + .WithChild(new Control_EvaluatablePresenter { EvalType = typeof(bool) } + .WithBinding(Control_EvaluatablePresenter.ExpressionProperty, new Binding(nameof(Toggle)) { Source = this, Mode = BindingMode.TwoWay }))) + .WithChild(new StackPanel { Orientation = Orientation.Horizontal } + .WithChild(new Label { Content = "Set" }) + .WithChild(new Control_EvaluatablePresenter { EvalType = typeof(bool) } + .WithBinding(Control_EvaluatablePresenter.ExpressionProperty, new Binding(nameof(Set)) { Source = this, Mode = BindingMode.TwoWay }))) + .WithChild(new StackPanel { Orientation = Orientation.Horizontal } + .WithChild(new Label { Content = "Reset" }) + .WithChild(new Control_EvaluatablePresenter { EvalType = typeof(bool) } + .WithBinding(Control_EvaluatablePresenter.ExpressionProperty, new Binding(nameof(Reset)) { Source = this, Mode = BindingMode.TwoWay }))); + + public override Evaluatable Clone() => new Boolean_FlipFlop(Toggle.Clone(), Set.Clone(), Reset.Clone()); + } +} \ No newline at end of file