Skip to content

Commit

Permalink
Use LabelledSwitchButton for warmup and chat toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
CloneWith committed Jul 28, 2024
1 parent 01d615a commit 5c99492
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions osu.Game.Tournament/Screens/Gameplay/GameplayScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Threading;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays.Settings;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.IPC;
Expand All @@ -24,7 +24,8 @@ public partial class GameplayScreen : BeatmapInfoScreen
private readonly BindableBool warmup = new BindableBool();

public readonly Bindable<TourneyState> State = new Bindable<TourneyState>();
private OsuButton warmupButton = null!;
private LabelledSwitchButton warmupToggle = null!;
private LabelledSwitchButton chatToggle = null!;
private MatchIPCInfo ipc = null!;

[Resolved]
Expand Down Expand Up @@ -95,17 +96,17 @@ private void load(MatchIPCInfo ipc)
{
Children = new Drawable[]
{
warmupButton = new TourneyButton
warmupToggle = new LabelledSwitchButton
{
RelativeSizeAxes = Axes.X,
Text = "Toggle warmup",
Action = () => warmup.Toggle()
Label = "Warmup stage",
Current = warmup,
},
new TourneyButton
chatToggle = new LabelledSwitchButton
{
RelativeSizeAxes = Axes.X,
Text = "Toggle chat",
Action = () => { State.Value = State.Value == TourneyState.Idle ? TourneyState.Playing : TourneyState.Idle; }
Label = "Show chat",
Current = { Value = State.Value == TourneyState.Idle }
},
new SettingsSlider<int>
{
Expand All @@ -125,17 +126,34 @@ private void load(MatchIPCInfo ipc)

LadderInfo.ChromaKeyWidth.BindValueChanged(width => chroma.Width = width.NewValue, true);

chatToggle.Current.BindValueChanged(_ => updateChat());

warmup.BindValueChanged(w =>
{
warmupButton.Alpha = !w.NewValue ? 0.5f : 1;
header.ShowScores = !w.NewValue;
}, true);
}

private void updateChat()
{
State.Value = chatToggle.Current.Value ? TourneyState.Idle : TourneyState.Playing;
updateState();
chatToggle.Current.Value = State.Value == TourneyState.Idle;
}

private void updateWarmup()
{
warmup.Value = warmupToggle.Current.Value;
updateState();
warmupToggle.Current.Value = warmup.Value;
}

protected override void LoadComplete()
{
base.LoadComplete();

warmupToggle.Current.BindValueChanged(_ => updateWarmup(), true);

State.BindTo(ipc.State);
State.BindValueChanged(_ => updateState(), true);
}
Expand Down

0 comments on commit 5c99492

Please sign in to comment.