A game framework written with osu! in mind.
at master 1.2 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5using osu.Framework.Graphics; 6using osuTK.Graphics; 7 8namespace osu.Framework.Testing.Drawables.Steps 9{ 10 public class ToggleStepButton : StepButton 11 { 12 private readonly Action<bool> reloadCallback; 13 private static readonly Color4 off_colour = Color4.Red; 14 private static readonly Color4 on_colour = Color4.YellowGreen; 15 16 public bool State; 17 18 public override int RequiredRepetitions => 2; 19 20 public ToggleStepButton(Action<bool> reloadCallback) 21 { 22 this.reloadCallback = reloadCallback; 23 Action = clickAction; 24 LightColour = off_colour; 25 } 26 27 private void clickAction() 28 { 29 State = !State; 30 Light.FadeColour(State ? on_colour : off_colour); 31 reloadCallback?.Invoke(State); 32 33 if (!State) 34 Success(); 35 } 36 37 public override string ToString() => $"Toggle: {base.ToString()} ({(State ? "on" : "off")})"; 38 } 39}