From e399d6c6d1603f05e4a02d9037c9ab919b516716 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 2 Mar 2017 21:14:06 +0900 Subject: [PATCH] Use bindable for PlayMode. --- .../Tests/TestCaseModSelectOverlay.cs | 9 +-- osu.Game/Overlays/Mods/ModSelectOverlay.cs | 79 +++++++++---------- osu.Game/Screens/Select/PlaySongSelect.cs | 2 - 3 files changed, 43 insertions(+), 47 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseModSelectOverlay.cs b/osu.Desktop.VisualTests/Tests/TestCaseModSelectOverlay.cs index e455771811..d535ac63b8 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseModSelectOverlay.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseModSelectOverlay.cs @@ -28,14 +28,13 @@ namespace osu.Desktop.VisualTests.Tests RelativeSizeAxes = Axes.X, Origin = Anchor.BottomCentre, Anchor = Anchor.BottomCentre, - ModMode = PlayMode.Osu, }); AddButton("Toggle", modSelect.ToggleVisibility); - AddButton("osu!", () => modSelect.ModMode = PlayMode.Osu); - AddButton("osu!taiko", () => modSelect.ModMode = PlayMode.Taiko); - AddButton("osu!catch", () => modSelect.ModMode = PlayMode.Catch); - AddButton("osu!mania", () => modSelect.ModMode = PlayMode.Mania); + AddButton("osu!", () => modSelect.PlayMode.Value = PlayMode.Osu); + AddButton("osu!taiko", () => modSelect.PlayMode.Value = PlayMode.Taiko); + AddButton("osu!catch", () => modSelect.PlayMode.Value = PlayMode.Catch); + AddButton("osu!mania", () => modSelect.PlayMode.Value = PlayMode.Mania); } } } diff --git a/osu.Game/Overlays/Mods/ModSelectOverlay.cs b/osu.Game/Overlays/Mods/ModSelectOverlay.cs index 66504bad21..d08ccec3da 100644 --- a/osu.Game/Overlays/Mods/ModSelectOverlay.cs +++ b/osu.Game/Overlays/Mods/ModSelectOverlay.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using System.Linq; using System.Collections.Generic; using OpenTK; @@ -34,53 +35,51 @@ namespace osu.Game.Overlays.Mods public Bindable SelectedMods = new Bindable(); - private PlayMode modMode; - public PlayMode ModMode - { - get - { - return modMode; - } - set - { - modMode = value; - var ruleset = Ruleset.GetRuleset(value); + public readonly Bindable PlayMode = new Bindable(); - modSectionsContainer.Children = new ModSection[] + private void modeChanged(object sender, EventArgs eventArgs) + { + var ruleset = Ruleset.GetRuleset(PlayMode); + + modSectionsContainer.Children = new ModSection[] + { + new DifficultyReductionSection { - new DifficultyReductionSection - { - RelativeSizeAxes = Axes.X, - Origin = Anchor.TopCentre, - Anchor = Anchor.TopCentre, - Action = modButtonPressed, - Buttons = ruleset.GetModsFor(ModType.DifficultyReduction).Select(m => new ModButton(m)).ToArray(), - }, - new DifficultyIncreaseSection - { - RelativeSizeAxes = Axes.X, - Origin = Anchor.TopCentre, - Anchor = Anchor.TopCentre, - Action = modButtonPressed, - Buttons = ruleset.GetModsFor(ModType.DifficultyIncrease).Select(m => new ModButton(m)).ToArray(), - }, - new AssistedSection - { - RelativeSizeAxes = Axes.X, - Origin = Anchor.TopCentre, - Anchor = Anchor.TopCentre, - Action = modButtonPressed, - Buttons = ruleset.GetModsFor(ModType.Special).Select(m => new ModButton(m)).ToArray(), - }, - }; - } + RelativeSizeAxes = Axes.X, + Origin = Anchor.TopCentre, + Anchor = Anchor.TopCentre, + Action = modButtonPressed, + Buttons = ruleset.GetModsFor(ModType.DifficultyReduction).Select(m => new ModButton(m)).ToArray(), + }, + new DifficultyIncreaseSection + { + RelativeSizeAxes = Axes.X, + Origin = Anchor.TopCentre, + Anchor = Anchor.TopCentre, + Action = modButtonPressed, + Buttons = ruleset.GetModsFor(ModType.DifficultyIncrease).Select(m => new ModButton(m)).ToArray(), + }, + new AssistedSection + { + RelativeSizeAxes = Axes.X, + Origin = Anchor.TopCentre, + Anchor = Anchor.TopCentre, + Action = modButtonPressed, + Buttons = ruleset.GetModsFor(ModType.Special).Select(m => new ModButton(m)).ToArray(), + }, + }; } - [BackgroundDependencyLoader] - private void load(OsuColour colours) + [BackgroundDependencyLoader(permitNulls:true)] + private void load(OsuColour colours, OsuGame osu) { lowMultiplierColour = colours.Red; highMultiplierColour = colours.Green; + + if (osu != null) + PlayMode.BindTo(osu.PlayMode); + PlayMode.ValueChanged += modeChanged; + PlayMode.TriggerChange(); } protected override void PopOut() diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index 936d36eadd..8bc8d75932 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -162,7 +162,6 @@ namespace osu.Game.Screens.Select if (osuGame != null) { playMode = osuGame.PlayMode; - modSelect.ModMode = playMode; playMode.ValueChanged += playMode_ValueChanged; } @@ -287,7 +286,6 @@ namespace osu.Game.Screens.Select private void playMode_ValueChanged(object sender, EventArgs e) { - modSelect.ModMode = playMode; } private void changeBackground(WorkingBeatmap beatmap)