From 4c2d7bf343999b55213b8d8900b62aee79d56276 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 17:41:13 +0200 Subject: [PATCH 01/54] Parse the mods of a leaderboard's score --- osu.Game.Rulesets.Catch/CatchRuleset.cs | 18 +++++++++ osu.Game.Rulesets.Mania/ManiaRuleset.cs | 30 +++++++++++++++ osu.Game.Rulesets.Mania/Mods/ManiaMod.cs | 4 ++ .../Mods/ManiaModGravity.cs | 1 + osu.Game.Rulesets.Osu/Mods/OsuMod.cs | 3 ++ osu.Game.Rulesets.Osu/OsuRuleset.cs | 21 ++++++++++ osu.Game.Rulesets.Taiko/TaikoRuleset.cs | 18 +++++++++ osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 2 + osu.Game/Rulesets/Mods/Mod.cs | 5 +++ osu.Game/Rulesets/Mods/ModAutoplay.cs | 1 + osu.Game/Rulesets/Mods/ModCinema.cs | 1 + osu.Game/Rulesets/Mods/ModDaycore.cs | 1 + osu.Game/Rulesets/Mods/ModDoubleTime.cs | 1 + osu.Game/Rulesets/Mods/ModEasy.cs | 1 + osu.Game/Rulesets/Mods/ModFlashlight.cs | 1 + osu.Game/Rulesets/Mods/ModHalfTime.cs | 1 + osu.Game/Rulesets/Mods/ModHardRock.cs | 1 + osu.Game/Rulesets/Mods/ModHidden.cs | 1 + osu.Game/Rulesets/Mods/ModNightcore.cs | 1 + osu.Game/Rulesets/Mods/ModNoFail.cs | 1 + osu.Game/Rulesets/Mods/ModPerfect.cs | 1 + osu.Game/Rulesets/Mods/ModRelax.cs | 1 + osu.Game/Rulesets/Mods/ModSuddenDeath.cs | 1 + osu.Game/Rulesets/Mods/MultiMod.cs | 1 + osu.Game/Rulesets/Ruleset.cs | 15 +++++++- osu.Game/Rulesets/Scoring/Score.cs | 38 ++++++++++++++++++- .../Select/Leaderboards/Leaderboard.cs | 6 ++- .../Select/Leaderboards/LeaderboardScore.cs | 19 +++++++++- 28 files changed, 188 insertions(+), 7 deletions(-) diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index 8d45ea8fa2..69f22f7121 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -20,6 +20,24 @@ namespace osu.Game.Rulesets.Catch { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new CatchRulesetContainer(this, beatmap, isForCurrentRuleset); + public override IEnumerable GetAllMods() => new Mod[] + { + new CatchModEasy(), + new CatchModNoFail(), + new CatchModHalfTime(), + new CatchModDaycore(), + new CatchModHardRock(), + new CatchModSuddenDeath(), + new CatchModPerfect(), + new CatchModDoubleTime(), + new CatchModNightcore(), + new CatchModHidden(), + new CatchModFlashlight(), + new CatchModRelax(), + new ModAutoplay(), + new ModCinema() + }; + public override IEnumerable GetModsFor(ModType type) { switch (type) diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index 50ad6960ae..3a7c072604 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -19,6 +19,36 @@ namespace osu.Game.Rulesets.Mania { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new ManiaRulesetContainer(this, beatmap, isForCurrentRuleset); + public override IEnumerable GetAllMods() => new Mod[] + { + new ManiaModEasy(), + new ManiaModNoFail(), + new ManiaModHalfTime(), + new ManiaModDaycore(), + new ManiaModHardRock(), + new ManiaModSuddenDeath(), + new ManiaModPerfect(), + new ManiaModDoubleTime(), + new ManiaModNightcore(), + new ManiaModFadeIn(), + new ManiaModHidden(), + new ManiaModFlashlight(), + new ManiaModKey4(), + new ManiaModKey5(), + new ManiaModKey6(), + new ManiaModKey7(), + new ManiaModKey8(), + new ManiaModKey9(), + new ManiaModKey1(), + new ManiaModKey2(), + new ManiaModKey3(), + new ManiaModRandom(), + new ManiaModKeyCoop(), + new ModAutoplay(), + new ModCinema(), + new ManiaModGravity() + }; + public override IEnumerable GetModsFor(ModType type) { switch (type) diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs b/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs index f44ad6fd60..12aa9b0886 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs @@ -68,6 +68,7 @@ namespace osu.Game.Rulesets.Mania.Mods public class ManiaModFadeIn : Mod { public override string Name => "FadeIn"; + public override string ShortenedName => "FI"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_hidden; public override ModType Type => ModType.DifficultyIncrease; public override double ScoreMultiplier => 1; @@ -78,12 +79,14 @@ namespace osu.Game.Rulesets.Mania.Mods public class ManiaModRandom : Mod { public override string Name => "Random"; + public override string ShortenedName => "RD"; public override string Description => @"Shuffle around the notes!"; public override double ScoreMultiplier => 1; } public abstract class ManiaKeyMod : Mod { + public override string ShortenedName => Name; public abstract int KeyCount { get; } public override double ScoreMultiplier => 1; // TODO: Implement the mania key mod score multiplier public override bool Ranked => true; @@ -146,6 +149,7 @@ namespace osu.Game.Rulesets.Mania.Mods public class ManiaModKeyCoop : Mod { public override string Name => "KeyCoop"; + public override string ShortenedName => "CO"; public override string Description => @"Double the key amount, double the fun!"; public override double ScoreMultiplier => 1; public override bool Ranked => true; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs index a054e0db56..132c49ab31 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs @@ -15,6 +15,7 @@ namespace osu.Game.Rulesets.Mania.Mods public class ManiaModGravity : Mod, IGenerateSpeedAdjustments { public override string Name => "Gravity"; + public override string ShortenedName => "GR"; public override double ScoreMultiplier => 0; diff --git a/osu.Game.Rulesets.Osu/Mods/OsuMod.cs b/osu.Game.Rulesets.Osu/Mods/OsuMod.cs index 3b0cfc1ef1..649e6cfb3c 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuMod.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuMod.cs @@ -78,6 +78,7 @@ namespace osu.Game.Rulesets.Osu.Mods public class OsuModSpunOut : Mod { public override string Name => "Spun Out"; + public override string ShortenedName => "SO"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_spunout; public override string Description => @"Spinners will be automatically completed"; public override double ScoreMultiplier => 0.9; @@ -88,6 +89,7 @@ namespace osu.Game.Rulesets.Osu.Mods public class OsuModAutopilot : Mod { public override string Name => "Autopilot"; + public override string ShortenedName => "AP"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_autopilot; public override string Description => @"Automatic cursor movement - just follow the rhythm."; public override double ScoreMultiplier => 0; @@ -108,6 +110,7 @@ namespace osu.Game.Rulesets.Osu.Mods public class OsuModTarget : Mod { public override string Name => "Target"; + public override string ShortenedName => "TP"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_target; public override string Description => @""; public override double ScoreMultiplier => 1; diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 212c634aaf..fbcb5e3abf 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -24,6 +24,27 @@ namespace osu.Game.Rulesets.Osu { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new OsuRulesetContainer(this, beatmap, isForCurrentRuleset); + public override IEnumerable GetAllMods() => new Mod[] + { + new OsuModEasy(), + new OsuModNoFail(), + new OsuModHalfTime(), + new OsuModDaycore(), + new OsuModHardRock(), + new OsuModSuddenDeath(), + new OsuModPerfect(), + new OsuModDoubleTime(), + new OsuModNightcore(), + new OsuModHidden(), + new OsuModFlashlight(), + new OsuModRelax(), + new OsuModAutopilot(), + new OsuModSpunOut(), + new OsuModAutoplay(), + new ModCinema(), + new OsuModTarget(), + }; + public override IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new[] { new BeatmapStatistic diff --git a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs index 4d4bbb7bc5..3e126cec4e 100644 --- a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs +++ b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs @@ -20,6 +20,24 @@ namespace osu.Game.Rulesets.Taiko { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new TaikoRulesetContainer(this, beatmap, isForCurrentRuleset); + public override IEnumerable GetAllMods() => new Mod[] + { + new TaikoModEasy(), + new TaikoModNoFail(), + new TaikoModHalfTime(), + new TaikoModDaycore(), + new TaikoModHardRock(), + new TaikoModSuddenDeath(), + new TaikoModPerfect(), + new TaikoModDoubleTime(), + new TaikoModNightcore(), + new TaikoModHidden(), + new TaikoModFlashlight(), + new TaikoModRelax(), + new TaikoModAutoplay(), + new ModCinema() + }; + public override IEnumerable GetModsFor(ModType type) { switch (type) diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index 2fb9a568f8..f807b5828f 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -58,6 +58,8 @@ namespace osu.Game.Beatmaps private class DummyRuleset : Ruleset { + public override IEnumerable GetAllMods() => new Mod[] { }; + public override IEnumerable GetModsFor(ModType type) => new Mod[] { }; public override Mod GetAutoplayMod() => new ModAutoplay(); diff --git a/osu.Game/Rulesets/Mods/Mod.cs b/osu.Game/Rulesets/Mods/Mod.cs index f54267af29..7b0034863e 100644 --- a/osu.Game/Rulesets/Mods/Mod.cs +++ b/osu.Game/Rulesets/Mods/Mod.cs @@ -16,6 +16,11 @@ namespace osu.Game.Rulesets.Mods /// public abstract string Name { get; } + /// + /// The shortened name of this mod. + /// + public abstract string ShortenedName { get; } + /// /// The icon of this mod. /// diff --git a/osu.Game/Rulesets/Mods/ModAutoplay.cs b/osu.Game/Rulesets/Mods/ModAutoplay.cs index ca120e446e..2b10d098f3 100644 --- a/osu.Game/Rulesets/Mods/ModAutoplay.cs +++ b/osu.Game/Rulesets/Mods/ModAutoplay.cs @@ -24,6 +24,7 @@ namespace osu.Game.Rulesets.Mods public class ModAutoplay : Mod { public override string Name => "Autoplay"; + public override string ShortenedName => "AT"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_auto; public override string Description => "Watch a perfect automated play through the song"; public override double ScoreMultiplier => 0; diff --git a/osu.Game/Rulesets/Mods/ModCinema.cs b/osu.Game/Rulesets/Mods/ModCinema.cs index 332bd2c5ac..581fbc5e3a 100644 --- a/osu.Game/Rulesets/Mods/ModCinema.cs +++ b/osu.Game/Rulesets/Mods/ModCinema.cs @@ -8,6 +8,7 @@ namespace osu.Game.Rulesets.Mods public class ModCinema : ModAutoplay { public override string Name => "Cinema"; + public override string ShortenedName => "CN"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_cinema; } } \ No newline at end of file diff --git a/osu.Game/Rulesets/Mods/ModDaycore.cs b/osu.Game/Rulesets/Mods/ModDaycore.cs index 3e878d7104..cbad224316 100644 --- a/osu.Game/Rulesets/Mods/ModDaycore.cs +++ b/osu.Game/Rulesets/Mods/ModDaycore.cs @@ -10,6 +10,7 @@ namespace osu.Game.Rulesets.Mods public abstract class ModDaycore : ModHalfTime { public override string Name => "Daycore"; + public override string ShortenedName => "DC"; public override FontAwesome Icon => FontAwesome.fa_question; public override string Description => "whoaaaaa"; diff --git a/osu.Game/Rulesets/Mods/ModDoubleTime.cs b/osu.Game/Rulesets/Mods/ModDoubleTime.cs index 1aab56a9fc..d8aa5ea1d2 100644 --- a/osu.Game/Rulesets/Mods/ModDoubleTime.cs +++ b/osu.Game/Rulesets/Mods/ModDoubleTime.cs @@ -10,6 +10,7 @@ namespace osu.Game.Rulesets.Mods public class ModDoubleTime : Mod, IApplicableToClock { public override string Name => "Double Time"; + public override string ShortenedName => "DT"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_doubletime; public override ModType Type => ModType.DifficultyIncrease; public override string Description => "Zoooooooooom"; diff --git a/osu.Game/Rulesets/Mods/ModEasy.cs b/osu.Game/Rulesets/Mods/ModEasy.cs index 075a62b0d7..aaf083fd9e 100644 --- a/osu.Game/Rulesets/Mods/ModEasy.cs +++ b/osu.Game/Rulesets/Mods/ModEasy.cs @@ -10,6 +10,7 @@ namespace osu.Game.Rulesets.Mods public abstract class ModEasy : Mod, IApplicableToDifficulty { public override string Name => "Easy"; + public override string ShortenedName => "EZ"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_easy; public override ModType Type => ModType.DifficultyReduction; public override string Description => "Reduces overall difficulty - larger circles, more forgiving HP drain, less accuracy required."; diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index b5ad859172..b7499e624a 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -8,6 +8,7 @@ namespace osu.Game.Rulesets.Mods public abstract class ModFlashlight : Mod { public override string Name => "Flashlight"; + public override string ShortenedName => "FL"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_flashlight; public override ModType Type => ModType.DifficultyIncrease; public override string Description => "Restricted view area."; diff --git a/osu.Game/Rulesets/Mods/ModHalfTime.cs b/osu.Game/Rulesets/Mods/ModHalfTime.cs index 14aede0809..a9e49bb4b0 100644 --- a/osu.Game/Rulesets/Mods/ModHalfTime.cs +++ b/osu.Game/Rulesets/Mods/ModHalfTime.cs @@ -10,6 +10,7 @@ namespace osu.Game.Rulesets.Mods public abstract class ModHalfTime : Mod, IApplicableToClock { public override string Name => "Half Time"; + public override string ShortenedName => "HT"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_halftime; public override ModType Type => ModType.DifficultyReduction; public override string Description => "Less zoom"; diff --git a/osu.Game/Rulesets/Mods/ModHardRock.cs b/osu.Game/Rulesets/Mods/ModHardRock.cs index f33f46a207..36d82362e3 100644 --- a/osu.Game/Rulesets/Mods/ModHardRock.cs +++ b/osu.Game/Rulesets/Mods/ModHardRock.cs @@ -10,6 +10,7 @@ namespace osu.Game.Rulesets.Mods public abstract class ModHardRock : Mod, IApplicableToDifficulty { public override string Name => "Hard Rock"; + public override string ShortenedName => "HR"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_hardrock; public override ModType Type => ModType.DifficultyIncrease; public override string Description => "Everything just got a bit harder..."; diff --git a/osu.Game/Rulesets/Mods/ModHidden.cs b/osu.Game/Rulesets/Mods/ModHidden.cs index 89b9b3b62d..25f6ad024d 100644 --- a/osu.Game/Rulesets/Mods/ModHidden.cs +++ b/osu.Game/Rulesets/Mods/ModHidden.cs @@ -8,6 +8,7 @@ namespace osu.Game.Rulesets.Mods public abstract class ModHidden : Mod { public override string Name => "Hidden"; + public override string ShortenedName => "HD"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_hidden; public override ModType Type => ModType.DifficultyIncrease; public override bool Ranked => true; diff --git a/osu.Game/Rulesets/Mods/ModNightcore.cs b/osu.Game/Rulesets/Mods/ModNightcore.cs index d04643fb8b..5cefd89023 100644 --- a/osu.Game/Rulesets/Mods/ModNightcore.cs +++ b/osu.Game/Rulesets/Mods/ModNightcore.cs @@ -10,6 +10,7 @@ namespace osu.Game.Rulesets.Mods public abstract class ModNightcore : ModDoubleTime { public override string Name => "Nightcore"; + public override string ShortenedName => "NC"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_nightcore; public override string Description => "uguuuuuuuu"; diff --git a/osu.Game/Rulesets/Mods/ModNoFail.cs b/osu.Game/Rulesets/Mods/ModNoFail.cs index d41c4e3956..3a3878d77e 100644 --- a/osu.Game/Rulesets/Mods/ModNoFail.cs +++ b/osu.Game/Rulesets/Mods/ModNoFail.cs @@ -9,6 +9,7 @@ namespace osu.Game.Rulesets.Mods public abstract class ModNoFail : Mod { public override string Name => "NoFail"; + public override string ShortenedName => "NF"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_nofail; public override ModType Type => ModType.DifficultyReduction; public override string Description => "You can't fail, no matter what."; diff --git a/osu.Game/Rulesets/Mods/ModPerfect.cs b/osu.Game/Rulesets/Mods/ModPerfect.cs index 35217c8305..082370ea5d 100644 --- a/osu.Game/Rulesets/Mods/ModPerfect.cs +++ b/osu.Game/Rulesets/Mods/ModPerfect.cs @@ -6,6 +6,7 @@ namespace osu.Game.Rulesets.Mods public abstract class ModPerfect : ModSuddenDeath { public override string Name => "Perfect"; + public override string ShortenedName => "PF"; public override string Description => "SS or quit."; } } \ No newline at end of file diff --git a/osu.Game/Rulesets/Mods/ModRelax.cs b/osu.Game/Rulesets/Mods/ModRelax.cs index 5491f8fc58..a3f38e4ff6 100644 --- a/osu.Game/Rulesets/Mods/ModRelax.cs +++ b/osu.Game/Rulesets/Mods/ModRelax.cs @@ -9,6 +9,7 @@ namespace osu.Game.Rulesets.Mods public abstract class ModRelax : Mod { public override string Name => "Relax"; + public override string ShortenedName => "RX"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_relax; public override double ScoreMultiplier => 0; public override Type[] IncompatibleMods => new[] { typeof(ModAutoplay), typeof(ModNoFail), typeof(ModSuddenDeath) }; diff --git a/osu.Game/Rulesets/Mods/ModSuddenDeath.cs b/osu.Game/Rulesets/Mods/ModSuddenDeath.cs index 2bf0278046..999cb40f89 100644 --- a/osu.Game/Rulesets/Mods/ModSuddenDeath.cs +++ b/osu.Game/Rulesets/Mods/ModSuddenDeath.cs @@ -9,6 +9,7 @@ namespace osu.Game.Rulesets.Mods public abstract class ModSuddenDeath : Mod { public override string Name => "Sudden Death"; + public override string ShortenedName => "SD"; public override FontAwesome Icon => FontAwesome.fa_osu_mod_suddendeath; public override ModType Type => ModType.DifficultyIncrease; public override string Description => "Miss a note and fail."; diff --git a/osu.Game/Rulesets/Mods/MultiMod.cs b/osu.Game/Rulesets/Mods/MultiMod.cs index c5fac250d0..c40d107bda 100644 --- a/osu.Game/Rulesets/Mods/MultiMod.cs +++ b/osu.Game/Rulesets/Mods/MultiMod.cs @@ -6,6 +6,7 @@ namespace osu.Game.Rulesets.Mods public class MultiMod : Mod { public override string Name => string.Empty; + public override string ShortenedName => string.Empty; public override string Description => string.Empty; public override double ScoreMultiplier => 0.0; diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index ba040403ba..b6bcd48562 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -1,12 +1,12 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Collections.Generic; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.UI; using osu.Game.Screens.Play; -using System.Collections.Generic; using osu.Framework.Graphics; using osu.Game.Rulesets.Scoring; using osu.Game.Overlays.Settings; @@ -19,8 +19,21 @@ namespace osu.Game.Rulesets public virtual IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; + public abstract IEnumerable GetAllMods(); + public abstract IEnumerable GetModsFor(ModType type); + public Mod GetModByShortenedName(string shortenedName) + { + foreach(Mod mod in GetAllMods()) + { + if (string.Equals(mod.ShortenedName, shortenedName)) + return mod; + } + + return null; + } + public abstract Mod GetAutoplayMod(); protected Ruleset(RulesetInfo rulesetInfo) diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 6169bb7380..8377b95cb2 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Reflection; using Newtonsoft.Json; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mods; @@ -27,10 +28,31 @@ namespace osu.Game.Rulesets.Scoring public int Combo { get; set; } + private string[] modStrings; [JsonProperty(@"mods")] - protected string[] ModStrings { get; set; } //todo: parse to Mod objects + protected string[] ModStrings { + get { return modStrings; } + set + { + modStrings = value; - public RulesetInfo Ruleset { get; set; } + if (ruleset != null) + handleModString(); + } + } + + private RulesetInfo ruleset; + public RulesetInfo Ruleset + { + get { return ruleset; } + set + { + ruleset = value; + + if (modStrings != null) + handleModString(); + } + } public Mod[] Mods { get; set; } @@ -80,5 +102,17 @@ namespace osu.Game.Rulesets.Scoring } public Dictionary Statistics = new Dictionary(); + + private void handleModString() + { + List modList = new List(); + + Ruleset rulesetInstance = Ruleset.CreateInstance(); + + foreach (string modShortenedName in modStrings) + modList.Add(rulesetInstance.GetModByShortenedName(modShortenedName)); + + Mods = modList.ToArray(); + } } } diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index 5a375e55d4..341e24baf0 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -1,15 +1,15 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using System.Collections.Generic; using OpenTK; using OpenTK.Graphics; +using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; -using System; -using osu.Framework.Allocation; using osu.Framework.Threading; using osu.Game.Beatmaps; using osu.Game.Graphics.Containers; @@ -55,6 +55,8 @@ namespace osu.Game.Screens.Select.Leaderboards i = 0; foreach (var s in scores) { + s.Ruleset = beatmap.Ruleset; + var ls = new LeaderboardScore(s, 1 + i) { AlwaysPresent = true, diff --git a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs index ac3b0b5c3b..993186ffdf 100644 --- a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs @@ -256,8 +256,23 @@ namespace osu.Game.Screens.Select.Leaderboards { foreach (Mod mod in Score.Mods) { - // TODO: Get actual mod colours - modsContainer.Add(new ScoreModIcon(mod.Icon, OsuColour.FromHex(@"ffcc22"))); + Color4 modColor; + + switch (mod.Type) + { + default: + case ModType.DifficultyIncrease: + modColor = OsuColour.FromHex(@"ffcc22"); + break; + case ModType.DifficultyReduction: + modColor = OsuColour.FromHex(@"88b300"); + break; + case ModType.Special: + modColor = OsuColour.FromHex(@"66ccff"); + break; + } + + modsContainer.Add(new ScoreModIcon(mod.Icon, modColor)); } } } From 997d0c9053c0b7cd641fa7047c0508203dac3744 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 17:45:46 +0200 Subject: [PATCH 02/54] CI fix --- osu.Game/Rulesets/Scoring/Score.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 8377b95cb2..0200e883ba 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Reflection; using Newtonsoft.Json; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mods; From e1e4eb78e324b972241d3ae57161f3da631f23aa Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 18:00:53 +0200 Subject: [PATCH 03/54] Fix nullref in the leaderboard's test case --- osu.Game/Screens/Select/Leaderboards/Leaderboard.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index 341e24baf0..740dc90586 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -55,7 +55,7 @@ namespace osu.Game.Screens.Select.Leaderboards i = 0; foreach (var s in scores) { - s.Ruleset = beatmap.Ruleset; + s.Ruleset = beatmap?.Ruleset; var ls = new LeaderboardScore(s, 1 + i) { From d9c26f98c7d132a8109f37174cfcbc791b7ac9ab Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 19:54:07 +0200 Subject: [PATCH 04/54] Suggested changes --- osu.Game.Rulesets.Catch/CatchRuleset.cs | 18 ----- osu.Game.Rulesets.Mania/ManiaRuleset.cs | 30 --------- osu.Game.Rulesets.Osu/OsuRuleset.cs | 21 ------ osu.Game.Rulesets.Taiko/TaikoRuleset.cs | 18 ----- osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 2 - osu.Game/Rulesets/Ruleset.cs | 28 +++++--- osu.Game/Rulesets/Scoring/Score.cs | 10 +-- osu.Game/Rulesets/UI/ModIcon.cs | 6 +- .../Select/Leaderboards/LeaderboardScore.cs | 67 ++++--------------- 9 files changed, 38 insertions(+), 162 deletions(-) diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index 69f22f7121..8d45ea8fa2 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -20,24 +20,6 @@ namespace osu.Game.Rulesets.Catch { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new CatchRulesetContainer(this, beatmap, isForCurrentRuleset); - public override IEnumerable GetAllMods() => new Mod[] - { - new CatchModEasy(), - new CatchModNoFail(), - new CatchModHalfTime(), - new CatchModDaycore(), - new CatchModHardRock(), - new CatchModSuddenDeath(), - new CatchModPerfect(), - new CatchModDoubleTime(), - new CatchModNightcore(), - new CatchModHidden(), - new CatchModFlashlight(), - new CatchModRelax(), - new ModAutoplay(), - new ModCinema() - }; - public override IEnumerable GetModsFor(ModType type) { switch (type) diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index 3a7c072604..50ad6960ae 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -19,36 +19,6 @@ namespace osu.Game.Rulesets.Mania { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new ManiaRulesetContainer(this, beatmap, isForCurrentRuleset); - public override IEnumerable GetAllMods() => new Mod[] - { - new ManiaModEasy(), - new ManiaModNoFail(), - new ManiaModHalfTime(), - new ManiaModDaycore(), - new ManiaModHardRock(), - new ManiaModSuddenDeath(), - new ManiaModPerfect(), - new ManiaModDoubleTime(), - new ManiaModNightcore(), - new ManiaModFadeIn(), - new ManiaModHidden(), - new ManiaModFlashlight(), - new ManiaModKey4(), - new ManiaModKey5(), - new ManiaModKey6(), - new ManiaModKey7(), - new ManiaModKey8(), - new ManiaModKey9(), - new ManiaModKey1(), - new ManiaModKey2(), - new ManiaModKey3(), - new ManiaModRandom(), - new ManiaModKeyCoop(), - new ModAutoplay(), - new ModCinema(), - new ManiaModGravity() - }; - public override IEnumerable GetModsFor(ModType type) { switch (type) diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index fbcb5e3abf..212c634aaf 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -24,27 +24,6 @@ namespace osu.Game.Rulesets.Osu { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new OsuRulesetContainer(this, beatmap, isForCurrentRuleset); - public override IEnumerable GetAllMods() => new Mod[] - { - new OsuModEasy(), - new OsuModNoFail(), - new OsuModHalfTime(), - new OsuModDaycore(), - new OsuModHardRock(), - new OsuModSuddenDeath(), - new OsuModPerfect(), - new OsuModDoubleTime(), - new OsuModNightcore(), - new OsuModHidden(), - new OsuModFlashlight(), - new OsuModRelax(), - new OsuModAutopilot(), - new OsuModSpunOut(), - new OsuModAutoplay(), - new ModCinema(), - new OsuModTarget(), - }; - public override IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new[] { new BeatmapStatistic diff --git a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs index 3e126cec4e..4d4bbb7bc5 100644 --- a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs +++ b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs @@ -20,24 +20,6 @@ namespace osu.Game.Rulesets.Taiko { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new TaikoRulesetContainer(this, beatmap, isForCurrentRuleset); - public override IEnumerable GetAllMods() => new Mod[] - { - new TaikoModEasy(), - new TaikoModNoFail(), - new TaikoModHalfTime(), - new TaikoModDaycore(), - new TaikoModHardRock(), - new TaikoModSuddenDeath(), - new TaikoModPerfect(), - new TaikoModDoubleTime(), - new TaikoModNightcore(), - new TaikoModHidden(), - new TaikoModFlashlight(), - new TaikoModRelax(), - new TaikoModAutoplay(), - new ModCinema() - }; - public override IEnumerable GetModsFor(ModType type) { switch (type) diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index f807b5828f..2fb9a568f8 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -58,8 +58,6 @@ namespace osu.Game.Beatmaps private class DummyRuleset : Ruleset { - public override IEnumerable GetAllMods() => new Mod[] { }; - public override IEnumerable GetModsFor(ModType type) => new Mod[] { }; public override Mod GetAutoplayMod() => new ModAutoplay(); diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index b6bcd48562..56a255eda5 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -1,6 +1,8 @@ // 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 osu.Game.Beatmaps; using osu.Game.Graphics; @@ -19,19 +21,29 @@ namespace osu.Game.Rulesets public virtual IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; - public abstract IEnumerable GetAllMods(); + public IEnumerable GetAllMods() + { + List modList = new List(); + + foreach (ModType type in Enum.GetValues(typeof(ModType))) + modList.AddRange(GetModsFor(type).SelectMany(mod => + { + var multiMod = mod as MultiMod; + + if (multiMod != null) + return multiMod.Mods; + + return new Mod[] { mod }; + })); + + return modList.ToArray(); + } public abstract IEnumerable GetModsFor(ModType type); public Mod GetModByShortenedName(string shortenedName) { - foreach(Mod mod in GetAllMods()) - { - if (string.Equals(mod.ShortenedName, shortenedName)) - return mod; - } - - return null; + return GetAllMods().First(mod => mod.ShortenedName == shortenedName); } public abstract Mod GetAutoplayMod(); diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 0200e883ba..b9fe54677d 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Linq; using System.Collections.Generic; using Newtonsoft.Json; using osu.Game.Beatmaps; @@ -104,14 +105,7 @@ namespace osu.Game.Rulesets.Scoring private void handleModString() { - List modList = new List(); - - Ruleset rulesetInstance = Ruleset.CreateInstance(); - - foreach (string modShortenedName in modStrings) - modList.Add(rulesetInstance.GetModByShortenedName(modShortenedName)); - - Mods = modList.ToArray(); + Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); } } } diff --git a/osu.Game/Rulesets/UI/ModIcon.cs b/osu.Game/Rulesets/UI/ModIcon.cs index 986d8c92dc..47a39d4644 100644 --- a/osu.Game/Rulesets/UI/ModIcon.cs +++ b/osu.Game/Rulesets/UI/ModIcon.cs @@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.UI private readonly SpriteIcon modIcon; private readonly SpriteIcon background; - private const float icon_size = 80; + private const float background_size = 80; public FontAwesome Icon { @@ -39,7 +39,7 @@ namespace osu.Game.Rulesets.UI { Origin = Anchor.Centre, Anchor = Anchor.Centre, - Size = new Vector2(icon_size), + Size = new Vector2(background_size), Icon = FontAwesome.fa_osu_mod_bg, Shadow = true, }, @@ -48,7 +48,7 @@ namespace osu.Game.Rulesets.UI Origin = Anchor.TopCentre, Anchor = Anchor.TopCentre, Colour = OsuColour.Gray(84), - Size = new Vector2(icon_size - 35), + Size = new Vector2(background_size - 35), Y = 25, Icon = mod.Icon }, diff --git a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs index 993186ffdf..fcd87363d6 100644 --- a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs @@ -3,17 +3,18 @@ using OpenTK; using OpenTK.Graphics; +using osu.Framework; +using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; -using osu.Framework.Extensions.Color4Extensions; -using osu.Game.Rulesets.Mods; -using osu.Game.Users; -using osu.Framework; -using osu.Game.Rulesets.Scoring; using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Scoring; +using osu.Game.Rulesets.UI; +using osu.Game.Users; namespace osu.Game.Screens.Select.Leaderboards { @@ -38,7 +39,7 @@ namespace osu.Game.Screens.Select.Leaderboards private readonly ScoreComponentLabel maxCombo; private readonly ScoreComponentLabel accuracy; private readonly Container flagBadgeContainer; - private readonly FillFlowContainer modsContainer; + private readonly FillFlowContainer modsContainer; private Visibility state; public Visibility State @@ -239,7 +240,7 @@ namespace osu.Game.Screens.Select.Leaderboards }, }, }, - modsContainer = new FillFlowContainer + modsContainer = new FillFlowContainer { Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, @@ -256,23 +257,11 @@ namespace osu.Game.Screens.Select.Leaderboards { foreach (Mod mod in Score.Mods) { - Color4 modColor; - - switch (mod.Type) + modsContainer.Add(new ModIcon(mod) { - default: - case ModType.DifficultyIncrease: - modColor = OsuColour.FromHex(@"ffcc22"); - break; - case ModType.DifficultyReduction: - modColor = OsuColour.FromHex(@"88b300"); - break; - case ModType.Special: - modColor = OsuColour.FromHex(@"66ccff"); - break; - } - - modsContainer.Add(new ScoreModIcon(mod.Icon, modColor)); + AutoSizeAxes = Axes.Both, + Scale = new Vector2(0.375f) + }); } } } @@ -341,36 +330,6 @@ namespace osu.Game.Screens.Select.Leaderboards } } - private class ScoreModIcon : Container - { - public ScoreModIcon(FontAwesome icon, Color4 colour) - { - AutoSizeAxes = Axes.Both; - - Children = new[] - { - new SpriteIcon - { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - Icon = FontAwesome.fa_osu_mod_bg, - Colour = colour, - Shadow = true, - Size = new Vector2(30), - }, - new SpriteIcon - { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - Icon = icon, - Colour = OsuColour.Gray(84), - Size = new Vector2(18), - Position = new Vector2(0f, 2f), - }, - }; - } - } - private class ScoreComponentLabel : Container { public ScoreComponentLabel(FontAwesome icon, string value) From 81289db33b3a9f9d219ce930359e78222cdc234d Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 20:12:01 +0200 Subject: [PATCH 05/54] CI fix, fixed nullref and removed abstraction of GetAutoplayMod --- osu.Game.Rulesets.Catch/CatchRuleset.cs | 2 -- osu.Game.Rulesets.Mania/ManiaRuleset.cs | 2 -- osu.Game.Rulesets.Osu/OsuRuleset.cs | 2 -- osu.Game.Rulesets.Taiko/TaikoRuleset.cs | 2 -- osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 2 -- osu.Game/Rulesets/Ruleset.cs | 6 +++--- 6 files changed, 3 insertions(+), 13 deletions(-) diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index 8d45ea8fa2..a5c9cf67b3 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -84,8 +84,6 @@ namespace osu.Game.Rulesets.Catch } } - public override Mod GetAutoplayMod() => new ModAutoplay(); - public override string Description => "osu!catch"; public override Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_osu_fruits_o }; diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index 50ad6960ae..90732df1f2 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -105,8 +105,6 @@ namespace osu.Game.Rulesets.Mania } } - public override Mod GetAutoplayMod() => new ModAutoplay(); - public override string Description => "osu!mania"; public override Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_osu_mania_o }; diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 212c634aaf..92cfbf8afa 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -105,8 +105,6 @@ namespace osu.Game.Rulesets.Osu } } - public override Mod GetAutoplayMod() => new OsuModAutoplay(); - public override Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_osu_osu_o }; public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new OsuDifficultyCalculator(beatmap); diff --git a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs index 4d4bbb7bc5..7fa053161d 100644 --- a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs +++ b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs @@ -84,8 +84,6 @@ namespace osu.Game.Rulesets.Taiko } } - public override Mod GetAutoplayMod() => new TaikoModAutoplay(); - public override string Description => "osu!taiko"; public override Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_osu_taiko_o }; diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index 2fb9a568f8..22ad4f38ff 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -60,8 +60,6 @@ namespace osu.Game.Beatmaps { public override IEnumerable GetModsFor(ModType type) => new Mod[] { }; - public override Mod GetAutoplayMod() => new ModAutoplay(); - public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) { throw new NotImplementedException(); diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index 56a255eda5..46ab53a7d2 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -26,14 +26,14 @@ namespace osu.Game.Rulesets List modList = new List(); foreach (ModType type in Enum.GetValues(typeof(ModType))) - modList.AddRange(GetModsFor(type).SelectMany(mod => + modList.AddRange(GetModsFor(type).Where(mod => mod != null).SelectMany(mod => { var multiMod = mod as MultiMod; if (multiMod != null) return multiMod.Mods; - return new Mod[] { mod }; + return new[] { mod }; })); return modList.ToArray(); @@ -46,7 +46,7 @@ namespace osu.Game.Rulesets return GetAllMods().First(mod => mod.ShortenedName == shortenedName); } - public abstract Mod GetAutoplayMod(); + public Mod GetAutoplayMod() => GetAllMods().First(mod => mod is ModAutoplay); protected Ruleset(RulesetInfo rulesetInfo) { From 2f89fc432b3ed495a239170b2261aac6b3470a10 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 20:28:30 +0200 Subject: [PATCH 06/54] Removed unused function --- osu.Game/Rulesets/Ruleset.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index 46ab53a7d2..cd4480bbb9 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -41,11 +41,6 @@ namespace osu.Game.Rulesets public abstract IEnumerable GetModsFor(ModType type); - public Mod GetModByShortenedName(string shortenedName) - { - return GetAllMods().First(mod => mod.ShortenedName == shortenedName); - } - public Mod GetAutoplayMod() => GetAllMods().First(mod => mod is ModAutoplay); protected Ruleset(RulesetInfo rulesetInfo) From e54f659916c4a897fb2ca5e51f13805923a1bb9e Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sun, 13 Aug 2017 22:37:39 +0200 Subject: [PATCH 07/54] Suggested changes --- osu.Game.Rulesets.Mania/Mods/ManiaMod.cs | 2 +- osu.Game/Rulesets/Ruleset.cs | 2 +- osu.Game/Rulesets/Scoring/Score.cs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs b/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs index 12aa9b0886..bb11a05fc8 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs @@ -149,7 +149,7 @@ namespace osu.Game.Rulesets.Mania.Mods public class ManiaModKeyCoop : Mod { public override string Name => "KeyCoop"; - public override string ShortenedName => "CO"; + public override string ShortenedName => "2P"; public override string Description => @"Double the key amount, double the fun!"; public override double ScoreMultiplier => 1; public override bool Ranked => true; diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index cd4480bbb9..bb08850af9 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -36,7 +36,7 @@ namespace osu.Game.Rulesets return new[] { mod }; })); - return modList.ToArray(); + return modList; } public abstract IEnumerable GetModsFor(ModType type); diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index b9fe54677d..399a805bcc 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -30,7 +30,8 @@ namespace osu.Game.Rulesets.Scoring private string[] modStrings; [JsonProperty(@"mods")] - protected string[] ModStrings { + protected string[] ModStrings + { get { return modStrings; } set { From 6b1184e8aff6f4de5fabe58a430595e0e1e19b02 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Mon, 14 Aug 2017 00:27:54 +0200 Subject: [PATCH 08/54] General formatting --- .../Select/Leaderboards/LeaderboardScore.cs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs index fcd87363d6..2971600a74 100644 --- a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs @@ -8,6 +8,7 @@ using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Framework.Input; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; @@ -253,16 +254,13 @@ namespace osu.Game.Screens.Select.Leaderboards }, }; - if (Score.Mods != null) + foreach (Mod mod in Score.Mods) { - foreach (Mod mod in Score.Mods) + modsContainer.Add(new ModIcon(mod) { - modsContainer.Add(new ModIcon(mod) - { - AutoSizeAxes = Axes.Both, - Scale = new Vector2(0.375f) - }); - } + AutoSizeAxes = Axes.Both, + Scale = new Vector2(0.375f) + }); } } @@ -271,13 +269,13 @@ namespace osu.Game.Screens.Select.Leaderboards public override void Hide() => State = Visibility.Hidden; public override void Show() => State = Visibility.Visible; - protected override bool OnHover(Framework.Input.InputState state) + protected override bool OnHover(InputState state) { background.FadeTo(0.5f, 300, Easing.OutQuint); return base.OnHover(state); } - protected override void OnHoverLost(Framework.Input.InputState state) + protected override void OnHoverLost(InputState state) { background.FadeTo(background_alpha, 200, Easing.OutQuint); base.OnHoverLost(state); @@ -307,8 +305,8 @@ namespace osu.Game.Screens.Select.Leaderboards Anchor = Anchor.Centre, Origin = Anchor.Centre, Font = font, - TextSize = textSize, FixedWidth = true, + TextSize = textSize, Text = text, Colour = glowColour, Shadow = false, From 718eefa362e326efdb07331d2a6a2e7c52d53e1f Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Mon, 14 Aug 2017 01:16:19 +0200 Subject: [PATCH 09/54] Fixed wrong test case accuracy format --- .../Visual/TestCaseLeaderboard.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs b/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs index 5f8ee8795c..2386881d24 100644 --- a/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs +++ b/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs @@ -24,7 +24,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.XH, - Accuracy = 100, + Accuracy = 1, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -42,7 +42,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.X, - Accuracy = 100, + Accuracy = 1, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -60,7 +60,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.SH, - Accuracy = 100, + Accuracy = 1, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -78,7 +78,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.S, - Accuracy = 100, + Accuracy = 1, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -96,7 +96,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.A, - Accuracy = 100, + Accuracy = 1, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -114,7 +114,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.B, - Accuracy = 98.26, + Accuracy = 0.9826, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -132,7 +132,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.C, - Accuracy = 96.54, + Accuracy = 0.9654, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -150,7 +150,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.F, - Accuracy = 60.25, + Accuracy = 0.6025, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -168,7 +168,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.F, - Accuracy = 51.40, + Accuracy = 0.5140, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, @@ -186,7 +186,7 @@ namespace osu.Desktop.Tests.Visual new Score { Rank = ScoreRank.F, - Accuracy = 42.22, + Accuracy = 0.4222, MaxCombo = 244, TotalScore = 1707827, Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, From 920710e7d0b3e37f027becbe059394f8e1345eb2 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Mon, 14 Aug 2017 13:30:54 +0200 Subject: [PATCH 10/54] Assign a score's beatmap and cleanup to the Score class --- osu.Game/Rulesets/Scoring/Score.cs | 23 ++++--------------- .../Select/Leaderboards/Leaderboard.cs | 1 + 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 399a805bcc..15217352d0 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -28,19 +28,8 @@ namespace osu.Game.Rulesets.Scoring public int Combo { get; set; } - private string[] modStrings; [JsonProperty(@"mods")] - protected string[] ModStrings - { - get { return modStrings; } - set - { - modStrings = value; - - if (ruleset != null) - handleModString(); - } - } + protected string[] ModStrings { get; set; } private RulesetInfo ruleset; public RulesetInfo Ruleset @@ -50,8 +39,9 @@ namespace osu.Game.Rulesets.Scoring { ruleset = value; - if (modStrings != null) - handleModString(); + // Handle the mod strings if they are assigned + if (ModStrings != null) + Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => ModStrings.Contains(mod.ShortenedName)).ToArray(); } } @@ -103,10 +93,5 @@ namespace osu.Game.Rulesets.Scoring } public Dictionary Statistics = new Dictionary(); - - private void handleModString() - { - Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); - } } } diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index 740dc90586..5ec76a59ac 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -55,6 +55,7 @@ namespace osu.Game.Screens.Select.Leaderboards i = 0; foreach (var s in scores) { + s.Beatmap = beatmap; s.Ruleset = beatmap?.Ruleset; var ls = new LeaderboardScore(s, 1 + i) From 5ed717ef861d15e02a7319127dcc060fd0cad1a3 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Mon, 14 Aug 2017 15:16:22 +0200 Subject: [PATCH 11/54] Shortened GetAllMods() using LINQ --- osu.Game/Rulesets/Ruleset.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index bb08850af9..af51a2cd3f 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -4,14 +4,14 @@ using System; using System.Linq; using System.Collections.Generic; +using osu.Framework.Graphics; using osu.Game.Beatmaps; using osu.Game.Graphics; +using osu.Game.Overlays.Settings; using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; using osu.Game.Screens.Play; -using osu.Framework.Graphics; -using osu.Game.Rulesets.Scoring; -using osu.Game.Overlays.Settings; namespace osu.Game.Rulesets { @@ -23,10 +23,9 @@ namespace osu.Game.Rulesets public IEnumerable GetAllMods() { - List modList = new List(); - - foreach (ModType type in Enum.GetValues(typeof(ModType))) - modList.AddRange(GetModsFor(type).Where(mod => mod != null).SelectMany(mod => + return Enum.GetValues(typeof(ModType)).Cast().SelectMany(type => + { + return GetModsFor(type).Where(mod => mod != null).SelectMany(mod => { var multiMod = mod as MultiMod; @@ -34,9 +33,8 @@ namespace osu.Game.Rulesets return multiMod.Mods; return new[] { mod }; - })); - - return modList; + }); + }); } public abstract IEnumerable GetModsFor(ModType type); From e908a3675ee2ac024abce62243a1261539a1956d Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Mon, 14 Aug 2017 18:24:54 +0200 Subject: [PATCH 12/54] Formatted the GetAllMods() function --- osu.Game/Rulesets/Ruleset.cs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index af51a2cd3f..b875dff44f 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -21,21 +21,7 @@ namespace osu.Game.Rulesets public virtual IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; - public IEnumerable GetAllMods() - { - return Enum.GetValues(typeof(ModType)).Cast().SelectMany(type => - { - return GetModsFor(type).Where(mod => mod != null).SelectMany(mod => - { - var multiMod = mod as MultiMod; - - if (multiMod != null) - return multiMod.Mods; - - return new[] { mod }; - }); - }); - } + public IEnumerable GetAllMods() => Enum.GetValues(typeof(ModType)).Cast().SelectMany(type => GetModsFor(type).Where(mod => mod != null).SelectMany(mod => (mod as MultiMod)?.Mods ?? new[] { mod })); public abstract IEnumerable GetModsFor(ModType type); From 21ced322976ddf9d0892f2d939858fe782d82d97 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Tue, 15 Aug 2017 12:03:43 +0200 Subject: [PATCH 13/54] Formatted and commented the GetAllMods() function --- osu.Game/Rulesets/Ruleset.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index b875dff44f..65cc6199f0 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -21,7 +21,14 @@ namespace osu.Game.Rulesets public virtual IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; - public IEnumerable GetAllMods() => Enum.GetValues(typeof(ModType)).Cast().SelectMany(type => GetModsFor(type).Where(mod => mod != null).SelectMany(mod => (mod as MultiMod)?.Mods ?? new[] { mod })); + public IEnumerable GetAllMods() => Enum.GetValues(typeof(ModType)).Cast() + //Get all mod types as an IEnumerable + .SelectMany(type => GetModsFor(type)) + // Confine all mods of each mod type into a single IEnumerable + .Where(mod => mod != null) + // Filter out all null mods + .SelectMany(mod => (mod as MultiMod)?.Mods ?? new[] { mod }); + // Resolve MultiMods as their .Mods property public abstract IEnumerable GetModsFor(ModType type); From 2c287e13486419e771572fadd682d73d870c2261 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Tue, 15 Aug 2017 12:27:51 +0200 Subject: [PATCH 14/54] CI and comment fix --- osu.Game/Rulesets/Ruleset.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index 65cc6199f0..fa12199a58 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -22,8 +22,8 @@ namespace osu.Game.Rulesets public virtual IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; public IEnumerable GetAllMods() => Enum.GetValues(typeof(ModType)).Cast() - //Get all mod types as an IEnumerable - .SelectMany(type => GetModsFor(type)) + // Get all mod types as an IEnumerable + .SelectMany(GetModsFor) // Confine all mods of each mod type into a single IEnumerable .Where(mod => mod != null) // Filter out all null mods From 105048500ad9a30f173d04892c5dd56ec28e5cdc Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Tue, 15 Aug 2017 15:30:53 +0200 Subject: [PATCH 15/54] Made modString private and moved the beatmap assignment inside GetScoresRequest --- osu.Game/Online/API/Requests/GetScoresRequest.cs | 11 +++++++++++ osu.Game/Rulesets/Scoring/Score.cs | 6 +++--- osu.Game/Screens/Select/Leaderboards/Leaderboard.cs | 3 --- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index 966049429e..a902c8c807 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -16,6 +16,17 @@ namespace osu.Game.Online.API.Requests public GetScoresRequest(BeatmapInfo beatmap) { this.beatmap = beatmap; + + Success += onSuccess; + } + + private void onSuccess(GetScoresResponse r) + { + foreach (Score score in r.Scores) + { + score.Beatmap = beatmap; + score.Ruleset = beatmap.Ruleset; + } } protected override WebRequest CreateWebRequest() diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 15217352d0..e42c3b2df0 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -29,7 +29,7 @@ namespace osu.Game.Rulesets.Scoring public int Combo { get; set; } [JsonProperty(@"mods")] - protected string[] ModStrings { get; set; } + private string[] modStrings { get; set; } private RulesetInfo ruleset; public RulesetInfo Ruleset @@ -40,8 +40,8 @@ namespace osu.Game.Rulesets.Scoring ruleset = value; // Handle the mod strings if they are assigned - if (ModStrings != null) - Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => ModStrings.Contains(mod.ShortenedName)).ToArray(); + if (modStrings != null) + Mods = ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); } } diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index 5ec76a59ac..0506784614 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -55,9 +55,6 @@ namespace osu.Game.Screens.Select.Leaderboards i = 0; foreach (var s in scores) { - s.Beatmap = beatmap; - s.Ruleset = beatmap?.Ruleset; - var ls = new LeaderboardScore(s, 1 + i) { AlwaysPresent = true, From 586a652b08ea3591a7c237f193afebafb9f6d268 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Thu, 17 Aug 2017 12:24:22 +0200 Subject: [PATCH 16/54] Changed Mods to be a property --- .../Visual/TestCaseLeaderboard.cs | 2 +- osu.Game/Rulesets/Scoring/Score.cs | 24 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs b/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs index 2386881d24..f67db2f41a 100644 --- a/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs +++ b/osu.Desktop.Tests/Visual/TestCaseLeaderboard.cs @@ -1,13 +1,13 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using OpenTK; using osu.Framework.Graphics; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Screens.Select.Leaderboards; using osu.Game.Users; -using OpenTK; namespace osu.Desktop.Tests.Visual { diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index e42c3b2df0..e83cb916bb 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -31,22 +31,28 @@ namespace osu.Game.Rulesets.Scoring [JsonProperty(@"mods")] private string[] modStrings { get; set; } - private RulesetInfo ruleset; - public RulesetInfo Ruleset + public RulesetInfo Ruleset; + + private Mod[] mods; + public Mod[] Mods { - get { return ruleset; } + get + { + // Evaluate the mod strings + if (mods == null) + mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); + + return mods; + } set { - ruleset = value; + mods = value; - // Handle the mod strings if they are assigned - if (modStrings != null) - Mods = ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); + // Assign the mod strings + modStrings = mods.Select(mod => mod.ShortenedName).ToArray(); } } - public Mod[] Mods { get; set; } - [JsonProperty(@"user")] public User User; From f831832c59b0b015abd22fe2e5d529f962b4196c Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Sat, 19 Aug 2017 00:13:06 +0200 Subject: [PATCH 17/54] CI fix --- osu.Game/Rulesets/Scoring/Score.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index e83cb916bb..154188a2fa 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -38,11 +38,8 @@ namespace osu.Game.Rulesets.Scoring { get { - // Evaluate the mod strings - if (mods == null) - mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); - - return mods; + // Evaluate the mod strings if necessary + return mods ?? (mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray()); } set { From 511fccdba733a8f70112024fd9a182ac636342c8 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 24 Aug 2017 17:28:47 +0900 Subject: [PATCH 18/54] Add editor menu bar test case. --- osu-framework | 2 +- .../Visual/TestCaseEditorMenuBar.cs | 184 ++++++++++++++++++ osu.Desktop.Tests/osu.Desktop.Tests.csproj | 1 + 3 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs diff --git a/osu-framework b/osu-framework index 1ba1e8ef1e..fbbcd942e2 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 1ba1e8ef1e5ec0466632be02492023a081cb85ab +Subproject commit fbbcd942e262778b166acde2cc89a10782734f2d diff --git a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs new file mode 100644 index 0000000000..455c25f385 --- /dev/null +++ b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs @@ -0,0 +1,184 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Testing; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; + +namespace osu.Desktop.Tests.Visual +{ + public class TestCaseEditorMenuBar : TestCase + { + public TestCaseEditorMenuBar() + { + Add(new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Width = 500, + Child = new EditorMenuBar + { + Items = new[] + { + new EditorMenuBarItem("File") + { + Items = new OsuContextMenuItem[] + { + new EditorContextMenuItem("Clear All Notes"), + new EditorContextMenuItem("Open Difficulty..."), + new EditorContextMenuItem("Save"), + new EditorContextMenuItem("Create a new Difficulty..."), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Revert to Saved"), + new EditorContextMenuItem("Revert to Saved (Full)"), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Test Beatmap"), + new EditorContextMenuItem("Open AiMod"), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Upload Beatmap..."), + new EditorContextMenuItem("Export Package"), + new EditorContextMenuItem("Export Map Package"), + new EditorContextMenuItem("Import from..."), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Open Song Folder"), + new EditorContextMenuItem("Open .osu in Notepad"), + new EditorContextMenuItem("Open .osb in Notepad"), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Exit"), + } + }, + new EditorMenuBarItem("Timing") + { + Items = new[] + { + new EditorContextMenuItem("Time Signature"), + new EditorContextMenuItem("Metronome Clicks"), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Add Timing Section"), + new EditorContextMenuItem("Add Inheriting Section"), + new EditorContextMenuItem("Reset Current Section"), + new EditorContextMenuItem("Delete Timing Section"), + new EditorContextMenuItem("Resnap Current Section"), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Timing Setup"), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Resnap All Notes", MenuItemType.Destructive), + new EditorContextMenuItem("Move all notes in time...", MenuItemType.Destructive), + new EditorContextMenuItem("Recalculate Slider Lengths", MenuItemType.Destructive), + new EditorContextMenuItem("Delete All Timing Sections", MenuItemType.Destructive), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Set Current Position as Preview Point"), + } + }, + new EditorMenuBarItem("Testing") + { + Items = new[] + { + new EditorContextMenuItem("Item 1"), + new EditorContextMenuItem("Item 2"), + new EditorContextMenuItem("Item 3"), + } + }, + } + } + }); + } + } + + public class EditorMenuBar : MenuBar + { + } + + public class EditorMenuBarItem : MenuBarItem + { + private const int fade_duration = 250; + private const float text_size = 17; + + private readonly Container background; + + private Color4 normalColour; + + public EditorMenuBarItem(string title) + : base(title) + { + Content.Padding = new MarginPadding(8); + + AddInternal(background = new Container + { + RelativeSizeAxes = Axes.Both, + Masking = true, + Depth = float.MaxValue, + Alpha = 0, + Child = new Container + { + // The following is done so we can have top rounded corners but not bottom corners + RelativeSizeAxes = Axes.Both, + Height = 2, + Masking = true, + CornerRadius = 5, + Child = new Box { RelativeSizeAxes = Axes.Both } + } + }); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + background.Colour = colours.Gray3; + ContextMenu.Menu.Background.Colour = colours.Gray3; + TitleText.Colour = normalColour = colours.BlueLight; + } + + public override void Open() + { + base.Open(); + + background.FadeIn(fade_duration, Easing.OutQuint); + TitleText.FadeColour(Color4.White, fade_duration, Easing.OutQuint); + } + + public override void Close() + { + base.Close(); + + background.FadeOut(fade_duration, Easing.OutQuint); + TitleText.FadeColour(normalColour, fade_duration, Easing.OutQuint); + } + + protected override SpriteText CreateTitleText() => new OsuSpriteText { TextSize = text_size }; + + protected override ContextMenu CreateContextMenu() => new OsuContextMenu + { + OriginPosition = new Vector2(8, 0) + }; + } + + public class EditorContextMenuSpacer : EditorContextMenuItem + { + public override bool HandleInput => false; + + public EditorContextMenuSpacer() + : base(" ") + { + } + } + + public class EditorContextMenuItem : OsuContextMenuItem + { + private const int min_text_length = 40; + + public EditorContextMenuItem(string title, MenuItemType type = MenuItemType.Standard) + : base(title.PadRight(min_text_length), type) + { + } + } +} diff --git a/osu.Desktop.Tests/osu.Desktop.Tests.csproj b/osu.Desktop.Tests/osu.Desktop.Tests.csproj index 24d112a45c..86268e6110 100644 --- a/osu.Desktop.Tests/osu.Desktop.Tests.csproj +++ b/osu.Desktop.Tests/osu.Desktop.Tests.csproj @@ -87,6 +87,7 @@ + From 26a4238a383a034feca20a3c586476d41832b57b Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 24 Aug 2017 17:31:23 +0900 Subject: [PATCH 19/54] Make classes private for now. --- .../Visual/TestCaseEditorMenuBar.cs | 146 +++++++++--------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs index 455c25f385..7c46107365 100644 --- a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs +++ b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs @@ -92,93 +92,93 @@ namespace osu.Desktop.Tests.Visual } }); } - } - public class EditorMenuBar : MenuBar - { - } - - public class EditorMenuBarItem : MenuBarItem - { - private const int fade_duration = 250; - private const float text_size = 17; - - private readonly Container background; - - private Color4 normalColour; - - public EditorMenuBarItem(string title) - : base(title) + private class EditorMenuBar : MenuBar { - Content.Padding = new MarginPadding(8); + } - AddInternal(background = new Container + private class EditorMenuBarItem : MenuBarItem + { + private const int fade_duration = 250; + private const float text_size = 17; + + private readonly Container background; + + private Color4 normalColour; + + public EditorMenuBarItem(string title) + : base(title) { - RelativeSizeAxes = Axes.Both, - Masking = true, - Depth = float.MaxValue, - Alpha = 0, - Child = new Container + Content.Padding = new MarginPadding(8); + + AddInternal(background = new Container { - // The following is done so we can have top rounded corners but not bottom corners RelativeSizeAxes = Axes.Both, - Height = 2, Masking = true, - CornerRadius = 5, - Child = new Box { RelativeSizeAxes = Axes.Both } - } - }); + Depth = float.MaxValue, + Alpha = 0, + Child = new Container + { + // The following is done so we can have top rounded corners but not bottom corners + RelativeSizeAxes = Axes.Both, + Height = 2, + Masking = true, + CornerRadius = 5, + Child = new Box { RelativeSizeAxes = Axes.Both } + } + }); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + background.Colour = colours.Gray3; + ContextMenu.Menu.Background.Colour = colours.Gray3; + TitleText.Colour = normalColour = colours.BlueLight; + } + + public override void Open() + { + base.Open(); + + background.FadeIn(fade_duration, Easing.OutQuint); + TitleText.FadeColour(Color4.White, fade_duration, Easing.OutQuint); + } + + public override void Close() + { + base.Close(); + + background.FadeOut(fade_duration, Easing.OutQuint); + TitleText.FadeColour(normalColour, fade_duration, Easing.OutQuint); + } + + protected override SpriteText CreateTitleText() => new OsuSpriteText { TextSize = text_size }; + + protected override ContextMenu CreateContextMenu() => new OsuContextMenu + { + OriginPosition = new Vector2(8, 0) + }; } - [BackgroundDependencyLoader] - private void load(OsuColour colours) + private class EditorContextMenuSpacer : EditorContextMenuItem { - background.Colour = colours.Gray3; - ContextMenu.Menu.Background.Colour = colours.Gray3; - TitleText.Colour = normalColour = colours.BlueLight; + public override bool HandleInput => false; + + public EditorContextMenuSpacer() + : base(" ") + { + } } - public override void Open() + private class EditorContextMenuItem : OsuContextMenuItem { - base.Open(); + private const int min_text_length = 40; - background.FadeIn(fade_duration, Easing.OutQuint); - TitleText.FadeColour(Color4.White, fade_duration, Easing.OutQuint); - } - - public override void Close() - { - base.Close(); - - background.FadeOut(fade_duration, Easing.OutQuint); - TitleText.FadeColour(normalColour, fade_duration, Easing.OutQuint); - } - - protected override SpriteText CreateTitleText() => new OsuSpriteText { TextSize = text_size }; - - protected override ContextMenu CreateContextMenu() => new OsuContextMenu - { - OriginPosition = new Vector2(8, 0) - }; - } - - public class EditorContextMenuSpacer : EditorContextMenuItem - { - public override bool HandleInput => false; - - public EditorContextMenuSpacer() - : base(" ") - { - } - } - - public class EditorContextMenuItem : OsuContextMenuItem - { - private const int min_text_length = 40; - - public EditorContextMenuItem(string title, MenuItemType type = MenuItemType.Standard) - : base(title.PadRight(min_text_length), type) - { + public EditorContextMenuItem(string title, MenuItemType type = MenuItemType.Standard) + : base(title.PadRight(min_text_length), type) + { + } } } } From a863eb2a2ffef640a85be6e287de46980af71a1f Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 24 Aug 2017 17:43:56 +0900 Subject: [PATCH 20/54] Add EditorMenuBarItem colours. --- osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs index 7c46107365..8d14f5f2df 100644 --- a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs +++ b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs @@ -31,7 +31,7 @@ namespace osu.Desktop.Tests.Visual { new EditorMenuBarItem("File") { - Items = new OsuContextMenuItem[] + Items = new[] { new EditorContextMenuItem("Clear All Notes"), new EditorContextMenuItem("Open Difficulty..."), @@ -179,6 +179,13 @@ namespace osu.Desktop.Tests.Visual : base(title.PadRight(min_text_length), type) { } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + BackgroundColour = colours.Gray3; + BackgroundColourHover = colours.Gray2; + } } } } From c39bb6e64777933287fabcf1f7a6b25945638ba2 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 24 Aug 2017 17:50:22 +0900 Subject: [PATCH 21/54] Pretty-ifying test case. --- .../Visual/TestCaseEditorMenuBar.cs | 127 +++++++++--------- 1 file changed, 60 insertions(+), 67 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs index 8d14f5f2df..49a382c9f9 100644 --- a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs +++ b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs @@ -20,83 +20,76 @@ namespace osu.Desktop.Tests.Visual { public TestCaseEditorMenuBar() { - Add(new Container + Add(new MenuBar { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Width = 500, - Child = new EditorMenuBar + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Y = 50, + Items = new[] { - Items = new[] + new EditorMenuBarItem("File") { - new EditorMenuBarItem("File") + Items = new[] { - Items = new[] - { - new EditorContextMenuItem("Clear All Notes"), - new EditorContextMenuItem("Open Difficulty..."), - new EditorContextMenuItem("Save"), - new EditorContextMenuItem("Create a new Difficulty..."), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Revert to Saved"), - new EditorContextMenuItem("Revert to Saved (Full)"), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Test Beatmap"), - new EditorContextMenuItem("Open AiMod"), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Upload Beatmap..."), - new EditorContextMenuItem("Export Package"), - new EditorContextMenuItem("Export Map Package"), - new EditorContextMenuItem("Import from..."), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Open Song Folder"), - new EditorContextMenuItem("Open .osu in Notepad"), - new EditorContextMenuItem("Open .osb in Notepad"), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Exit"), - } - }, - new EditorMenuBarItem("Timing") + new EditorContextMenuItem("Clear All Notes"), + new EditorContextMenuItem("Open Difficulty..."), + new EditorContextMenuItem("Save"), + new EditorContextMenuItem("Create a new Difficulty..."), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Revert to Saved"), + new EditorContextMenuItem("Revert to Saved (Full)"), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Test Beatmap"), + new EditorContextMenuItem("Open AiMod"), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Upload Beatmap..."), + new EditorContextMenuItem("Export Package"), + new EditorContextMenuItem("Export Map Package"), + new EditorContextMenuItem("Import from..."), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Open Song Folder"), + new EditorContextMenuItem("Open .osu in Notepad"), + new EditorContextMenuItem("Open .osb in Notepad"), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Exit"), + } + }, + new EditorMenuBarItem("Timing") + { + Items = new[] { - Items = new[] - { - new EditorContextMenuItem("Time Signature"), - new EditorContextMenuItem("Metronome Clicks"), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Add Timing Section"), - new EditorContextMenuItem("Add Inheriting Section"), - new EditorContextMenuItem("Reset Current Section"), - new EditorContextMenuItem("Delete Timing Section"), - new EditorContextMenuItem("Resnap Current Section"), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Timing Setup"), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Resnap All Notes", MenuItemType.Destructive), - new EditorContextMenuItem("Move all notes in time...", MenuItemType.Destructive), - new EditorContextMenuItem("Recalculate Slider Lengths", MenuItemType.Destructive), - new EditorContextMenuItem("Delete All Timing Sections", MenuItemType.Destructive), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Set Current Position as Preview Point"), - } - }, - new EditorMenuBarItem("Testing") + new EditorContextMenuItem("Time Signature"), + new EditorContextMenuItem("Metronome Clicks"), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Add Timing Section"), + new EditorContextMenuItem("Add Inheriting Section"), + new EditorContextMenuItem("Reset Current Section"), + new EditorContextMenuItem("Delete Timing Section"), + new EditorContextMenuItem("Resnap Current Section"), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Timing Setup"), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Resnap All Notes", MenuItemType.Destructive), + new EditorContextMenuItem("Move all notes in time...", MenuItemType.Destructive), + new EditorContextMenuItem("Recalculate Slider Lengths", MenuItemType.Destructive), + new EditorContextMenuItem("Delete All Timing Sections", MenuItemType.Destructive), + new EditorContextMenuSpacer(), + new EditorContextMenuItem("Set Current Position as Preview Point"), + } + }, + new EditorMenuBarItem("Testing") + { + Items = new[] { - Items = new[] - { - new EditorContextMenuItem("Item 1"), - new EditorContextMenuItem("Item 2"), - new EditorContextMenuItem("Item 3"), - } - }, - } + new EditorContextMenuItem("Item 1"), + new EditorContextMenuItem("Item 2"), + new EditorContextMenuItem("Item 3"), + } + }, } }); } - private class EditorMenuBar : MenuBar - { - } - private class EditorMenuBarItem : MenuBarItem { private const int fade_duration = 250; From 4ab209bdce8a5fbc234c6bf899e62a9c8290db5b Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 24 Aug 2017 19:05:51 +0900 Subject: [PATCH 22/54] Add EditorContextMenu in line with framework changes To avoid public Menu. --- osu-framework | 2 +- osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/osu-framework b/osu-framework index fbbcd942e2..a5fd0c82c8 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit fbbcd942e262778b166acde2cc89a10782734f2d +Subproject commit a5fd0c82c8f86d41c80ac1b0b07727cb312330f1 diff --git a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs index 49a382c9f9..7a9c97f5d5 100644 --- a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs +++ b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs @@ -126,7 +126,6 @@ namespace osu.Desktop.Tests.Visual private void load(OsuColour colours) { background.Colour = colours.Gray3; - ContextMenu.Menu.Background.Colour = colours.Gray3; TitleText.Colour = normalColour = colours.BlueLight; } @@ -148,12 +147,21 @@ namespace osu.Desktop.Tests.Visual protected override SpriteText CreateTitleText() => new OsuSpriteText { TextSize = text_size }; - protected override ContextMenu CreateContextMenu() => new OsuContextMenu + protected override ContextMenu CreateContextMenu() => new EditorContextMenu { OriginPosition = new Vector2(8, 0) }; } + private class EditorContextMenu : OsuContextMenu + { + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + Menu.Background.Colour = colours.Gray3; + } + } + private class EditorContextMenuSpacer : EditorContextMenuItem { public override bool HandleInput => false; From 5dae408ecb1204293a664862b78a9e8567fbfc5a Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 28 Aug 2017 15:32:12 +0900 Subject: [PATCH 23/54] Reimplement TestCaseEditorMenuBar. --- osu-framework | 2 +- .../Visual/TestCaseEditorMenuBar.cs | 272 ++++++++++-------- 2 files changed, 157 insertions(+), 117 deletions(-) diff --git a/osu-framework b/osu-framework index 2cb3e59c8b..f6a1df24ee 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 2cb3e59c8bc7e67edef4dfe7f9c7dfc01db386a7 +Subproject commit f6a1df24eeef78e89f2d6e24fe1b43756eaae51e diff --git a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs index 7a9c97f5d5..b7a4bc355d 100644 --- a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs +++ b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.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 OpenTK; using OpenTK.Graphics; using osu.Framework.Allocation; @@ -20,7 +21,7 @@ namespace osu.Desktop.Tests.Visual { public TestCaseEditorMenuBar() { - Add(new MenuBar + Add(new EditorMenuBar { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, @@ -31,162 +32,201 @@ namespace osu.Desktop.Tests.Visual { Items = new[] { - new EditorContextMenuItem("Clear All Notes"), - new EditorContextMenuItem("Open Difficulty..."), - new EditorContextMenuItem("Save"), - new EditorContextMenuItem("Create a new Difficulty..."), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Revert to Saved"), - new EditorContextMenuItem("Revert to Saved (Full)"), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Test Beatmap"), - new EditorContextMenuItem("Open AiMod"), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Upload Beatmap..."), - new EditorContextMenuItem("Export Package"), - new EditorContextMenuItem("Export Map Package"), - new EditorContextMenuItem("Import from..."), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Open Song Folder"), - new EditorContextMenuItem("Open .osu in Notepad"), - new EditorContextMenuItem("Open .osb in Notepad"), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Exit"), + new EditorMenuItem("Clear All Notes"), + new EditorMenuItem("Open Difficulty..."), + new EditorMenuItem("Save"), + new EditorMenuItem("Create a new Difficulty..."), + new EditorMenuSpacer(), + new EditorMenuItem("Revert to Saved"), + new EditorMenuItem("Revert to Saved (Full)"), + new EditorMenuSpacer(), + new EditorMenuItem("Test Beatmap"), + new EditorMenuItem("Open AiMod"), + new EditorMenuSpacer(), + new EditorMenuItem("Upload Beatmap..."), + new EditorMenuItem("Export Package"), + new EditorMenuItem("Export Map Package"), + new EditorMenuItem("Import from..."), + new EditorMenuSpacer(), + new EditorMenuItem("Open Song Folder"), + new EditorMenuItem("Open .osu in Notepad"), + new EditorMenuItem("Open .osb in Notepad"), + new EditorMenuSpacer(), + new EditorMenuItem("Exit"), } }, new EditorMenuBarItem("Timing") { Items = new[] { - new EditorContextMenuItem("Time Signature"), - new EditorContextMenuItem("Metronome Clicks"), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Add Timing Section"), - new EditorContextMenuItem("Add Inheriting Section"), - new EditorContextMenuItem("Reset Current Section"), - new EditorContextMenuItem("Delete Timing Section"), - new EditorContextMenuItem("Resnap Current Section"), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Timing Setup"), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Resnap All Notes", MenuItemType.Destructive), - new EditorContextMenuItem("Move all notes in time...", MenuItemType.Destructive), - new EditorContextMenuItem("Recalculate Slider Lengths", MenuItemType.Destructive), - new EditorContextMenuItem("Delete All Timing Sections", MenuItemType.Destructive), - new EditorContextMenuSpacer(), - new EditorContextMenuItem("Set Current Position as Preview Point"), + new EditorMenuItem("Time Signature"), + new EditorMenuItem("Metronome Clicks"), + new EditorMenuSpacer(), + new EditorMenuItem("Add Timing Section"), + new EditorMenuItem("Add Inheriting Section"), + new EditorMenuItem("Reset Current Section"), + new EditorMenuItem("Delete Timing Section"), + new EditorMenuItem("Resnap Current Section"), + new EditorMenuSpacer(), + new EditorMenuItem("Timing Setup"), + new EditorMenuSpacer(), + new EditorMenuItem("Resnap All Notes", MenuItemType.Destructive), + new EditorMenuItem("Move all notes in time...", MenuItemType.Destructive), + new EditorMenuItem("Recalculate Slider Lengths", MenuItemType.Destructive), + new EditorMenuItem("Delete All Timing Sections", MenuItemType.Destructive), + new EditorMenuSpacer(), + new EditorMenuItem("Set Current Position as Preview Point"), } }, new EditorMenuBarItem("Testing") { Items = new[] { - new EditorContextMenuItem("Item 1"), - new EditorContextMenuItem("Item 2"), - new EditorContextMenuItem("Item 3"), + new EditorMenuItem("Item 1"), + new EditorMenuItem("Item 2"), + new EditorMenuItem("Item 3"), } }, } }); } - private class EditorMenuBarItem : MenuBarItem + private class EditorMenuBar : MenuBar { - private const int fade_duration = 250; - private const float text_size = 17; + protected override DrawableMenuBarItem CreateDrawableMenuBarItem(MenuItem item) => new DrawableEditorMenuBarItem(item); - private readonly Container background; - - private Color4 normalColour; - - public EditorMenuBarItem(string title) - : base(title) + private class DrawableEditorMenuBarItem : DrawableMenuBarItem { - Content.Padding = new MarginPadding(8); + private const int fade_duration = 250; + private const float text_size = 17; - AddInternal(background = new Container + private readonly Container background; + + private Color4 normalColour; + + public DrawableEditorMenuBarItem(MenuItem item) + : base(item) { - RelativeSizeAxes = Axes.Both, - Masking = true, - Depth = float.MaxValue, - Alpha = 0, - Child = new Container + if (!(item is EditorMenuBarItem)) + throw new ArgumentException($"{nameof(item)} must be a {nameof(EditorMenuBarItem)}."); + + Text.Padding = new MarginPadding(8); + + AddInternal(background = new Container { - // The following is done so we can have top rounded corners but not bottom corners RelativeSizeAxes = Axes.Both, - Height = 2, Masking = true, - CornerRadius = 5, - Child = new Box { RelativeSizeAxes = Axes.Both } + Depth = float.MaxValue, + Alpha = 0, + Child = new Container + { + // The following is done so we can have top rounded corners but not bottom corners + RelativeSizeAxes = Axes.Both, + Height = 2, + Masking = true, + CornerRadius = 5, + Child = new Box { RelativeSizeAxes = Axes.Both } + } + }); + + Menu.OnOpen += menuOpen; + Menu.OnClose += menuClose; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + background.Colour = colours.Gray3; + Text.Colour = normalColour = colours.BlueLight; + } + + private void menuOpen() + { + background.FadeIn(fade_duration, Easing.OutQuint); + Text.FadeColour(Color4.White, fade_duration, Easing.OutQuint); + } + + private void menuClose() + { + background.FadeOut(fade_duration, Easing.OutQuint); + Text.FadeColour(normalColour, fade_duration, Easing.OutQuint); + } + + protected override SpriteText CreateText() => new OsuSpriteText { TextSize = text_size }; + + protected override Menu CreateMenu() => new EditorMenu(); + + private class EditorMenu : OsuMenu + { + public EditorMenu() + { + Anchor = Anchor.BottomLeft; + BypassAutoSizeAxes = Axes.Both; + OriginPosition = new Vector2(8, 0); } - }); - } - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - background.Colour = colours.Gray3; - TitleText.Colour = normalColour = colours.BlueLight; - } + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + BackgroundColour = colours.Gray3; + } - public override void Open() - { - base.Open(); + protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableEditorMenuItem(item); - background.FadeIn(fade_duration, Easing.OutQuint); - TitleText.FadeColour(Color4.White, fade_duration, Easing.OutQuint); - } + private class DrawableEditorMenuItem : DrawableOsuMenuItem + { + public override bool HandleInput => !isSpacer; + private readonly bool isSpacer; - public override void Close() - { - base.Close(); + public DrawableEditorMenuItem(MenuItem item) + : base(item) + { + if (!(item is EditorMenuItem)) + throw new ArgumentException($"{nameof(item)} must be a {nameof(EditorMenuItem)}."); - background.FadeOut(fade_duration, Easing.OutQuint); - TitleText.FadeColour(normalColour, fade_duration, Easing.OutQuint); - } + isSpacer = item is EditorMenuSpacer; + } - protected override SpriteText CreateTitleText() => new OsuSpriteText { TextSize = text_size }; - - protected override ContextMenu CreateContextMenu() => new EditorContextMenu - { - OriginPosition = new Vector2(8, 0) - }; - } - - private class EditorContextMenu : OsuContextMenu - { - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - Menu.Background.Colour = colours.Gray3; + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + BackgroundColour = colours.Gray3; + BackgroundColourHover = colours.Gray2; + } + } + } } } - private class EditorContextMenuSpacer : EditorContextMenuItem + private class EditorMenuBarItem : MenuItem { - public override bool HandleInput => false; + public EditorMenuBarItem(string text) + : base(text) + { + } + } - public EditorContextMenuSpacer() + private class EditorMenuItem : OsuMenuItem + { + private const int min_text_length = 40; + + public EditorMenuItem(string text, MenuItemType type = MenuItemType.Standard) + : base(text.PadRight(min_text_length), type) + { + } + + public EditorMenuItem(string text, MenuItemType type, Action action) + : base(text.PadRight(min_text_length), type, action) + { + } + } + + private class EditorMenuSpacer : EditorMenuItem + { + public EditorMenuSpacer() : base(" ") { } } - - private class EditorContextMenuItem : OsuContextMenuItem - { - private const int min_text_length = 40; - - public EditorContextMenuItem(string title, MenuItemType type = MenuItemType.Standard) - : base(title.PadRight(min_text_length), type) - { - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - BackgroundColour = colours.Gray3; - BackgroundColourHover = colours.Gray2; - } - } } } From 7c9c7f93aece86a7e976c9be7032f391832d188d Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 28 Aug 2017 15:42:21 +0900 Subject: [PATCH 24/54] Remove unnecessary exception, replace with default styling. --- osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs index b7a4bc355d..95d34543bb 100644 --- a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs +++ b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs @@ -107,8 +107,6 @@ namespace osu.Desktop.Tests.Visual public DrawableEditorMenuBarItem(MenuItem item) : base(item) { - if (!(item is EditorMenuBarItem)) - throw new ArgumentException($"{nameof(item)} must be a {nameof(EditorMenuBarItem)}."); Text.Padding = new MarginPadding(8); @@ -181,8 +179,6 @@ namespace osu.Desktop.Tests.Visual public DrawableEditorMenuItem(MenuItem item) : base(item) { - if (!(item is EditorMenuItem)) - throw new ArgumentException($"{nameof(item)} must be a {nameof(EditorMenuItem)}."); isSpacer = item is EditorMenuSpacer; } From b17d9ac06ea649b977ead563b7b5e4ecefe70ab9 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 28 Aug 2017 17:55:50 +0900 Subject: [PATCH 25/54] Move EditorMenuBar into the Edit namespace, and fix a minor styling issue. --- osu-framework | 2 +- .../Visual/TestCaseEditorMenuBar.cs | 145 +-------------- osu.Game/Graphics/UserInterface/OsuMenu.cs | 5 +- osu.Game/Screens/Edit/Editor.cs | 174 ++++++++++++++++++ osu.Game/Screens/Edit/Menus/EditorMenuBar.cs | 131 +++++++++++++ .../Screens/Edit/Menus/EditorMenuBarItem.cs | 15 ++ osu.Game/Screens/Edit/Menus/EditorMenuItem.cs | 23 +++ .../Edit/Menus/EditorMenuItemSpacer.cs | 13 ++ osu.Game/osu.Game.csproj | 4 + 9 files changed, 365 insertions(+), 147 deletions(-) create mode 100644 osu.Game/Screens/Edit/Menus/EditorMenuBar.cs create mode 100644 osu.Game/Screens/Edit/Menus/EditorMenuBarItem.cs create mode 100644 osu.Game/Screens/Edit/Menus/EditorMenuItem.cs create mode 100644 osu.Game/Screens/Edit/Menus/EditorMenuItemSpacer.cs diff --git a/osu-framework b/osu-framework index f6a1df24ee..c7457f0ce9 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit f6a1df24eeef78e89f2d6e24fe1b43756eaae51e +Subproject commit c7457f0ce9ef3f663ee800f6b7fc574e9abff1da diff --git a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs index 95d34543bb..9ff4f4c591 100644 --- a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs +++ b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs @@ -1,19 +1,10 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; -using OpenTK; -using OpenTK.Graphics; -using osu.Framework.Allocation; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.UserInterface; using osu.Framework.Testing; -using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; +using osu.Game.Screens.Edit.Menus; namespace osu.Desktop.Tests.Visual { @@ -90,139 +81,5 @@ namespace osu.Desktop.Tests.Visual } }); } - - private class EditorMenuBar : MenuBar - { - protected override DrawableMenuBarItem CreateDrawableMenuBarItem(MenuItem item) => new DrawableEditorMenuBarItem(item); - - private class DrawableEditorMenuBarItem : DrawableMenuBarItem - { - private const int fade_duration = 250; - private const float text_size = 17; - - private readonly Container background; - - private Color4 normalColour; - - public DrawableEditorMenuBarItem(MenuItem item) - : base(item) - { - - Text.Padding = new MarginPadding(8); - - AddInternal(background = new Container - { - RelativeSizeAxes = Axes.Both, - Masking = true, - Depth = float.MaxValue, - Alpha = 0, - Child = new Container - { - // The following is done so we can have top rounded corners but not bottom corners - RelativeSizeAxes = Axes.Both, - Height = 2, - Masking = true, - CornerRadius = 5, - Child = new Box { RelativeSizeAxes = Axes.Both } - } - }); - - Menu.OnOpen += menuOpen; - Menu.OnClose += menuClose; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - background.Colour = colours.Gray3; - Text.Colour = normalColour = colours.BlueLight; - } - - private void menuOpen() - { - background.FadeIn(fade_duration, Easing.OutQuint); - Text.FadeColour(Color4.White, fade_duration, Easing.OutQuint); - } - - private void menuClose() - { - background.FadeOut(fade_duration, Easing.OutQuint); - Text.FadeColour(normalColour, fade_duration, Easing.OutQuint); - } - - protected override SpriteText CreateText() => new OsuSpriteText { TextSize = text_size }; - - protected override Menu CreateMenu() => new EditorMenu(); - - private class EditorMenu : OsuMenu - { - public EditorMenu() - { - Anchor = Anchor.BottomLeft; - BypassAutoSizeAxes = Axes.Both; - OriginPosition = new Vector2(8, 0); - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - BackgroundColour = colours.Gray3; - } - - protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableEditorMenuItem(item); - - private class DrawableEditorMenuItem : DrawableOsuMenuItem - { - public override bool HandleInput => !isSpacer; - private readonly bool isSpacer; - - public DrawableEditorMenuItem(MenuItem item) - : base(item) - { - - isSpacer = item is EditorMenuSpacer; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - BackgroundColour = colours.Gray3; - BackgroundColourHover = colours.Gray2; - } - } - } - } - } - - private class EditorMenuBarItem : MenuItem - { - public EditorMenuBarItem(string text) - : base(text) - { - } - } - - private class EditorMenuItem : OsuMenuItem - { - private const int min_text_length = 40; - - public EditorMenuItem(string text, MenuItemType type = MenuItemType.Standard) - : base(text.PadRight(min_text_length), type) - { - } - - public EditorMenuItem(string text, MenuItemType type, Action action) - : base(text.PadRight(min_text_length), type, action) - { - } - } - - private class EditorMenuSpacer : EditorMenuItem - { - public EditorMenuSpacer() - : base(" ") - { - } - } } } diff --git a/osu.Game/Graphics/UserInterface/OsuMenu.cs b/osu.Game/Graphics/UserInterface/OsuMenu.cs index efc6998ca7..e0bb23df5d 100644 --- a/osu.Game/Graphics/UserInterface/OsuMenu.cs +++ b/osu.Game/Graphics/UserInterface/OsuMenu.cs @@ -105,9 +105,10 @@ namespace osu.Game.Graphics.UserInterface return base.OnClick(state); } - protected override Drawable CreateContent() => text = new TextContainer(); + protected sealed override Drawable CreateContent() => text = CreateTextContainer(); + protected virtual TextContainer CreateTextContainer() => new TextContainer(); - private class TextContainer : Container, IHasText + protected class TextContainer : Container, IHasText { public string Text { diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 9f33d624e2..0454609689 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -8,6 +8,11 @@ using osu.Framework.Screens; using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Select; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics; +using osu.Game.Graphics.UserInterface; +using osu.Game.Screens.Edit.Menus; namespace osu.Game.Screens.Edit { @@ -17,6 +22,175 @@ namespace osu.Game.Screens.Edit protected override BackgroundScreen CreateBackground() => new BackgroundScreenCustom(@"Backgrounds/bg4"); + internal override bool ShowOverlays => false; + + public Editor() + { + Add(new Container + { + RelativeSizeAxes = Axes.X, + Height = 40, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = OsuColour.FromHex("111") + }, + new EditorMenuBar + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + X = 100, + Items = new[] + { + new EditorMenuBarItem("File") + { + Items = new[] + { + new EditorMenuItem("Clear all notes"), + new EditorMenuItem("Open difficulty..."), + new EditorMenuItem("Save"), + new EditorMenuItem("Create new difficulty..."), + new EditorMenuSpacer(), + new EditorMenuItem("Revert to saved"), + new EditorMenuItem("Revert to saved (full"), + new EditorMenuSpacer(), + new EditorMenuItem("Test beatmap"), + new EditorMenuItem("Open AiMod"), + new EditorMenuSpacer(), + new EditorMenuItem("Upload Beatmap..."), + new EditorMenuItem("Export package"), + new EditorMenuItem("Export map package"), + new EditorMenuItem("Import from..."), + new EditorMenuSpacer(), + new EditorMenuItem("Open song folder"), + new EditorMenuItem("Open .osu in Notepad"), + new EditorMenuItem("Open .osb in Notepad"), + new EditorMenuSpacer(), + new EditorMenuItem("Exit", MenuItemType.Standard, Exit) + } + }, + new EditorMenuBarItem("Edit") + { + Items = new[] + { + new EditorMenuItem("Undo"), + new EditorMenuItem("Redo"), + new EditorMenuSpacer(), + new EditorMenuItem("Cut"), + new EditorMenuItem("Copy"), + new EditorMenuItem("Paste"), + new EditorMenuItem("Delete"), + new EditorMenuSpacer(), + new EditorMenuItem("Select all"), + new EditorMenuItem("Clone"), + new EditorMenuSpacer(), + new EditorMenuItem("Reverse selection"), + new EditorMenuItem("Flip horizontally"), + new EditorMenuItem("Flip vertically"), + new EditorMenuItem("Rotate 90deg clockwise"), + new EditorMenuItem("Rotate 90deg anticlockwise"), + new EditorMenuItem("Rotate by..."), + new EditorMenuItem("Scale by..."), + new EditorMenuSpacer(), + new EditorMenuItem("Reset selected objects' samples"), + new EditorMenuItem("Reset all samples", MenuItemType.Destructive), + new EditorMenuItem("Reset combo colours", MenuItemType.Destructive), + new EditorMenuItem("Reset breaks", MenuItemType.Destructive), + new EditorMenuSpacer(), + new EditorMenuItem("Nudge backward"), + new EditorMenuItem("Nudge forward") + } + }, + new EditorMenuBarItem("View") + { + Items = new[] + { + new EditorMenuItem("Compose"), + new EditorMenuItem("Design"), + new EditorMenuItem("Timing"), + new EditorMenuSpacer(), + new EditorMenuItem("Song setup..."), + new EditorMenuItem("Timing setup..."), + new EditorMenuSpacer(), + new EditorMenuItem("Volume"), + new EditorMenuItem("Grid level"), + new EditorMenuItem("Show video"), + new EditorMenuItem("Show sample name"), + new EditorMenuItem("Snaking sliders"), + new EditorMenuItem("Hit animations"), + new EditorMenuItem("Follow points"), + new EditorMenuItem("Stacking") + } + }, + new EditorMenuBarItem("Compose") + { + Items = new[] + { + new EditorMenuItem("Snap divisor"), + new EditorMenuItem("Audio rate"), + new EditorMenuItem("Grid snapping"), + new EditorMenuSpacer(), + new EditorMenuItem("Create polygon cricles..."), + new EditorMenuItem("Convert slider to stream"), + new EditorMenuItem("Enable live mapping mode"), + new EditorMenuItem("Sample import") + } + }, + new EditorMenuBarItem("Design") + { + Items = new[] + { + new EditorMenuItem("Move all elements in time...") + } + }, + new EditorMenuBarItem("Timing") + { + Items = new[] + { + new EditorMenuItem("Time signature"), + new EditorMenuItem("Metronome clicks"), + new EditorMenuSpacer(), + new EditorMenuItem("Add timing section"), + new EditorMenuItem("Add inheriting section"), + new EditorMenuItem("Reset current section"), + new EditorMenuItem("Delete timing section"), + new EditorMenuItem("Resnap current section"), + new EditorMenuSpacer(), + new EditorMenuItem("Timing setup..."), + new EditorMenuSpacer(), + new EditorMenuItem("Resnap all notes", MenuItemType.Destructive), + new EditorMenuItem("Move all notes in time...", MenuItemType.Destructive), + new EditorMenuItem("Recalculate slider lengths", MenuItemType.Destructive), + new EditorMenuItem("Delete all timing sections", MenuItemType.Destructive), + new EditorMenuSpacer(), + new EditorMenuItem("Set current position as preview point") + } + }, + new EditorMenuBarItem("Web") + { + Items = new[] + { + new EditorMenuItem("This Beatmap's information page"), + new EditorMenuItem("This Beatmap's thread"), + new EditorMenuItem("Quick reply") + } + }, + new EditorMenuBarItem("Help") + { + Items = new[] + { + new EditorMenuItem("Show in-game help"), + new EditorMenuItem("View FAQ") + } + } + } + } + } + }); + } + protected override void OnResuming(Screen last) { Beatmap.Value.Track?.Stop(); diff --git a/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs b/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs new file mode 100644 index 0000000000..9fd8669922 --- /dev/null +++ b/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs @@ -0,0 +1,131 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; +using OpenTK; +using OpenTK.Graphics; + +namespace osu.Game.Screens.Edit.Menus +{ + public class EditorMenuBar : MenuBar + { + protected override DrawableMenuBarItem CreateDrawableMenuBarItem(MenuItem item) => new DrawableEditorMenuBarItem(item); + + private class DrawableEditorMenuBarItem : DrawableMenuBarItem + { + private const int fade_duration = 250; + private const float text_size = 14; + + private readonly Container background; + + private Color4 normalColour; + + public DrawableEditorMenuBarItem(MenuItem item) + : base(item) + { + Text.Padding = new MarginPadding(8); + + AddInternal(background = new Container + { + RelativeSizeAxes = Axes.Both, + Masking = true, + Depth = float.MaxValue, + Alpha = 0, + Child = new Container + { + // The following is done so we can have top rounded corners but not bottom corners + RelativeSizeAxes = Axes.Both, + Height = 2, + Masking = true, + CornerRadius = 5, + Child = new Box { RelativeSizeAxes = Axes.Both } + } + }); + + Menu.OnOpen += menuOpen; + Menu.OnClose += menuClose; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + background.Colour = colours.Gray3; + Text.Colour = normalColour = colours.BlueLight; + } + + private void menuOpen() + { + background.FadeIn(fade_duration, Easing.OutQuint); + Text.FadeColour(Color4.White, fade_duration, Easing.OutQuint); + } + + private void menuClose() + { + background.FadeOut(fade_duration, Easing.OutQuint); + Text.FadeColour(normalColour, fade_duration, Easing.OutQuint); + } + + protected override SpriteText CreateText() => new OsuSpriteText { TextSize = text_size }; + + protected override Framework.Graphics.UserInterface.Menu CreateMenu() => new EditorMenu(); + + private class EditorMenu : OsuMenu + { + public EditorMenu() + { + Anchor = Anchor.BottomLeft; + BypassAutoSizeAxes = Axes.Both; + OriginPosition = new Vector2(8, 0); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + BackgroundColour = colours.Gray3; + } + + protected override MarginPadding ItemFlowContainerPadding => new MarginPadding { Top = 5, Bottom = 5 }; + + protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableEditorMenuItem(item); + + private class DrawableEditorMenuItem : DrawableOsuMenuItem + { + public override bool HandleInput => !isSpacer; + private readonly bool isSpacer; + + public DrawableEditorMenuItem(MenuItem item) + : base(item) + { + isSpacer = item is EditorMenuSpacer; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + BackgroundColour = colours.Gray3; + BackgroundColourHover = colours.Gray2; + } + + protected override TextContainer CreateTextContainer() => new EditorTextContainer(); + + private class EditorTextContainer : TextContainer + { + public EditorTextContainer() + { + BoldText.TextSize = text_size; + NormalText.TextSize = text_size; + } + } + } + } + } + } +} diff --git a/osu.Game/Screens/Edit/Menus/EditorMenuBarItem.cs b/osu.Game/Screens/Edit/Menus/EditorMenuBarItem.cs new file mode 100644 index 0000000000..201bc6e5c3 --- /dev/null +++ b/osu.Game/Screens/Edit/Menus/EditorMenuBarItem.cs @@ -0,0 +1,15 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics.UserInterface; + +namespace osu.Game.Screens.Edit.Menus +{ + public class EditorMenuBarItem : MenuItem + { + public EditorMenuBarItem(string text) + : base(text) + { + } + } +} diff --git a/osu.Game/Screens/Edit/Menus/EditorMenuItem.cs b/osu.Game/Screens/Edit/Menus/EditorMenuItem.cs new file mode 100644 index 0000000000..c7e36522cf --- /dev/null +++ b/osu.Game/Screens/Edit/Menus/EditorMenuItem.cs @@ -0,0 +1,23 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Screens.Edit.Menus +{ + public class EditorMenuItem : OsuMenuItem + { + private const int min_text_length = 40; + + public EditorMenuItem(string text, MenuItemType type = MenuItemType.Standard) + : base(text.PadRight(min_text_length), type) + { + } + + public EditorMenuItem(string text, MenuItemType type, Action action) + : base(text.PadRight(min_text_length), type, action) + { + } + } +} diff --git a/osu.Game/Screens/Edit/Menus/EditorMenuItemSpacer.cs b/osu.Game/Screens/Edit/Menus/EditorMenuItemSpacer.cs new file mode 100644 index 0000000000..0e01992846 --- /dev/null +++ b/osu.Game/Screens/Edit/Menus/EditorMenuItemSpacer.cs @@ -0,0 +1,13 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Screens.Edit.Menus +{ + public class EditorMenuSpacer : EditorMenuItem + { + public EditorMenuSpacer() + : base(" ") + { + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 325cfba986..05ba3e25ab 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -133,6 +133,10 @@ + + + + From 6304a685c3317b143d7d5d6d3e75769bf7d61dca Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 29 Aug 2017 14:43:23 +0900 Subject: [PATCH 26/54] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index c7457f0ce9..167d5cda8f 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit c7457f0ce9ef3f663ee800f6b7fc574e9abff1da +Subproject commit 167d5cda8f3ddae702ffc8d8d22dac67e48b509c From 06fac913bfe5c03e479fca450a5f45ac0ad006cf Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 6 Sep 2017 21:14:29 +0900 Subject: [PATCH 27/54] Re-implement EditorMenuBar. --- osu-framework | 2 +- osu.Game/Graphics/UserInterface/OsuMenu.cs | 6 +- osu.Game/Screens/Edit/Menus/EditorMenuBar.cs | 160 +++++++++---------- 3 files changed, 83 insertions(+), 85 deletions(-) diff --git a/osu-framework b/osu-framework index 3edf658577..3e91706ad5 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 3edf65857759f32d5a6d07ed523a2892b09c3c6a +Subproject commit 3e91706ad54609c9477588730b5de7db9d1311f8 diff --git a/osu.Game/Graphics/UserInterface/OsuMenu.cs b/osu.Game/Graphics/UserInterface/OsuMenu.cs index 3c9b9797ba..4e23a8939d 100644 --- a/osu.Game/Graphics/UserInterface/OsuMenu.cs +++ b/osu.Game/Graphics/UserInterface/OsuMenu.cs @@ -46,6 +46,11 @@ namespace osu.Game.Graphics.UserInterface protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableOsuMenuItem(item); + protected override Menu CreateSubMenu() => new OsuMenu(Direction.Vertical) + { + Anchor = Direction == Direction.Horizontal ? Anchor.BottomLeft : Anchor.TopRight + }; + protected class DrawableOsuMenuItem : DrawableMenuItem { private const int margin_horizontal = 17; @@ -61,7 +66,6 @@ namespace osu.Game.Graphics.UserInterface public DrawableOsuMenuItem(MenuItem item) : base(item) { - } [BackgroundDependencyLoader] diff --git a/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs b/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs index 9fd8669922..15610fcebd 100644 --- a/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs +++ b/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs @@ -5,125 +5,119 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; +using osu.Framework.Input; using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using OpenTK; using OpenTK.Graphics; namespace osu.Game.Screens.Edit.Menus { - public class EditorMenuBar : MenuBar + public class EditorMenuBar : OsuMenu { - protected override DrawableMenuBarItem CreateDrawableMenuBarItem(MenuItem item) => new DrawableEditorMenuBarItem(item); - - private class DrawableEditorMenuBarItem : DrawableMenuBarItem + public EditorMenuBar() + : base(Direction.Horizontal) { - private const int fade_duration = 250; - private const float text_size = 14; + AlwaysOpen = true; + RequireClickToOpen = true; - private readonly Container background; + ItemsContainer.Padding = new MarginPadding(0); + BackgroundColour = Color4.Transparent; + } - private Color4 normalColour; + protected override Framework.Graphics.UserInterface.Menu CreateSubMenu() => new SubMenu(); - public DrawableEditorMenuBarItem(MenuItem item) + protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableEditorBarMenuItem(item); + + private class DrawableEditorBarMenuItem : DrawableOsuMenuItem + { + private Color4 openedForegroundColour; + private Color4 openedBackgroundColour; + + public DrawableEditorBarMenuItem(MenuItem item) : base(item) { - Text.Padding = new MarginPadding(8); - - AddInternal(background = new Container - { - RelativeSizeAxes = Axes.Both, - Masking = true, - Depth = float.MaxValue, - Alpha = 0, - Child = new Container - { - // The following is done so we can have top rounded corners but not bottom corners - RelativeSizeAxes = Axes.Both, - Height = 2, - Masking = true, - CornerRadius = 5, - Child = new Box { RelativeSizeAxes = Axes.Both } - } - }); - - Menu.OnOpen += menuOpen; - Menu.OnClose += menuClose; } [BackgroundDependencyLoader] private void load(OsuColour colours) { - background.Colour = colours.Gray3; - Text.Colour = normalColour = colours.BlueLight; + ForegroundColour = ForegroundColourHover = colours.BlueLight; + BackgroundColour = BackgroundColourHover = Color4.Transparent; + openedForegroundColour = Color4.White; + openedBackgroundColour = colours.Gray3; } - private void menuOpen() + protected override void UpdateBackgroundColour() { - background.FadeIn(fade_duration, Easing.OutQuint); - Text.FadeColour(Color4.White, fade_duration, Easing.OutQuint); + if (State == MenuItemState.Selected) + Background.FadeColour(openedBackgroundColour); + else + base.UpdateBackgroundColour(); } - private void menuClose() + protected override void UpdateForegroundColour() { - background.FadeOut(fade_duration, Easing.OutQuint); - Text.FadeColour(normalColour, fade_duration, Easing.OutQuint); + if (State == MenuItemState.Selected) + Foreground.FadeColour(openedForegroundColour); + else + base.UpdateForegroundColour(); } - protected override SpriteText CreateText() => new OsuSpriteText { TextSize = text_size }; - - protected override Framework.Graphics.UserInterface.Menu CreateMenu() => new EditorMenu(); - - private class EditorMenu : OsuMenu + protected override Drawable CreateBackground() => new Container { - public EditorMenu() + RelativeSizeAxes = Axes.Both, + Masking = true, + Child = new Container + { + RelativeSizeAxes = Axes.Both, + Height = 2, + Masking = true, + CornerRadius = 4, + Child = new Box { RelativeSizeAxes = Axes.Both } + } + }; + } + + private class SubMenu : OsuMenu + { + public SubMenu() + : base(Direction.Vertical) + { + OriginPosition = new Vector2(5, 1); + ItemsContainer.Padding = new MarginPadding { Top = 5, Bottom = 5 }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + BackgroundColour = colours.Gray3; + } + + protected override Framework.Graphics.UserInterface.Menu CreateSubMenu() => new SubMenu(); + + protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableSubMenuItem(item); + + private class DrawableSubMenuItem : DrawableOsuMenuItem + { + public DrawableSubMenuItem(MenuItem item) + : base(item) { - Anchor = Anchor.BottomLeft; - BypassAutoSizeAxes = Axes.Both; - OriginPosition = new Vector2(8, 0); } - [BackgroundDependencyLoader] - private void load(OsuColour colours) + protected override bool OnHover(InputState state) { - BackgroundColour = colours.Gray3; + if (Item is EditorMenuSpacer) + return true; + return base.OnHover(state); } - protected override MarginPadding ItemFlowContainerPadding => new MarginPadding { Top = 5, Bottom = 5 }; - - protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableEditorMenuItem(item); - - private class DrawableEditorMenuItem : DrawableOsuMenuItem + protected override bool OnClick(InputState state) { - public override bool HandleInput => !isSpacer; - private readonly bool isSpacer; - - public DrawableEditorMenuItem(MenuItem item) - : base(item) - { - isSpacer = item is EditorMenuSpacer; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - BackgroundColour = colours.Gray3; - BackgroundColourHover = colours.Gray2; - } - - protected override TextContainer CreateTextContainer() => new EditorTextContainer(); - - private class EditorTextContainer : TextContainer - { - public EditorTextContainer() - { - BoldText.TextSize = text_size; - NormalText.TextSize = text_size; - } - } + if (Item is EditorMenuSpacer) + return true; + return base.OnClick(state); } } } From 69ff4bfa46cc51aab72dd6e17260c376fb0704c6 Mon Sep 17 00:00:00 2001 From: naoey Date: Wed, 6 Sep 2017 20:04:21 +0530 Subject: [PATCH 28/54] Fix startup crash on mono. --- osu.Game/Graphics/UserInterface/OsuDropdown.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterface/OsuDropdown.cs b/osu.Game/Graphics/UserInterface/OsuDropdown.cs index b69186e8b0..f605804aaa 100644 --- a/osu.Game/Graphics/UserInterface/OsuDropdown.cs +++ b/osu.Game/Graphics/UserInterface/OsuDropdown.cs @@ -96,7 +96,7 @@ namespace osu.Game.Graphics.UserInterface protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableOsuDropdownMenuItem(item) { AccentColour = accentColour }; #region DrawableOsuDropdownMenuItem - protected class DrawableOsuDropdownMenuItem : DrawableDropdownMenuItem, IHasAccentColour + public class DrawableOsuDropdownMenuItem : DrawableDropdownMenuItem, IHasAccentColour { private Color4? accentColour; public Color4 AccentColour From b98346c79feddd797cf6a6dc1718c27727a7bf5a Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 7 Sep 2017 15:32:28 +0900 Subject: [PATCH 29/54] Update framework. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 3e91706ad5..23d1932eae 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 3e91706ad54609c9477588730b5de7db9d1311f8 +Subproject commit 23d1932eae87a871d65624eac3e6e8deb7e286c2 From ef9b87e8c7b32b0cdcedaf2b52280731a0efa5e4 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 7 Sep 2017 16:15:25 +0900 Subject: [PATCH 30/54] Make column lights not increase in brightness when successfully pressed --- osu.Game.Rulesets.Mania/UI/Column.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index a8f5b4919d..d5bc7cc659 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -198,7 +198,7 @@ namespace osu.Game.Rulesets.Mania.UI { if (action == Action) { - background.FadeTo(background.Alpha + 0.2f, 50, Easing.OutQuint); + background.FadeTo(0.6f, 50, Easing.OutQuint); keyIcon.ScaleTo(1.4f, 50, Easing.OutQuint); } From b085208d247d9a78fb66d659321a3a6e46a5d1a7 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 7 Sep 2017 16:15:33 +0900 Subject: [PATCH 31/54] Remove unused code --- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index d3dc920fc6..ce91fda023 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -11,7 +11,6 @@ using osu.Framework.Graphics.Containers; using System; using osu.Game.Graphics; using osu.Framework.Allocation; -using OpenTK.Input; using System.Linq; using System.Collections.Generic; using osu.Framework.Configuration; @@ -25,12 +24,6 @@ namespace osu.Game.Rulesets.Mania.UI { public const float HIT_TARGET_POSITION = 50; - /// - /// Default column keys, expanding outwards from the middle as more column are added. - /// E.g. 2 columns use FJ, 4 columns use DFJK, 6 use SDFJKL, etc... - /// - private static readonly Key[] default_keys = { Key.A, Key.S, Key.D, Key.F, Key.J, Key.K, Key.L, Key.Semicolon }; - private SpecialColumnPosition specialColumnPosition; /// /// The style to use for the special column. From 41398f57d65cfb8462f8e646c1453ef4e46b44e4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 7 Sep 2017 20:36:32 +0900 Subject: [PATCH 32/54] Changes in line with framework --- osu.Game/Graphics/UserInterface/OsuMenu.cs | 4 ++-- osu.Game/Screens/Edit/Menus/EditorMenuBar.cs | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuMenu.cs b/osu.Game/Graphics/UserInterface/OsuMenu.cs index 4e23a8939d..3fd5481152 100644 --- a/osu.Game/Graphics/UserInterface/OsuMenu.cs +++ b/osu.Game/Graphics/UserInterface/OsuMenu.cs @@ -18,8 +18,8 @@ namespace osu.Game.Graphics.UserInterface { public class OsuMenu : Menu { - public OsuMenu(Direction direction) - : base(direction) + public OsuMenu(Direction direction, bool topLevelMenu = false) + : base(direction, topLevelMenu) { BackgroundColour = Color4.Black.Opacity(0.5f); diff --git a/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs b/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs index 15610fcebd..24625570a1 100644 --- a/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs +++ b/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs @@ -17,11 +17,8 @@ namespace osu.Game.Screens.Edit.Menus public class EditorMenuBar : OsuMenu { public EditorMenuBar() - : base(Direction.Horizontal) + : base(Direction.Horizontal, true) { - AlwaysOpen = true; - RequireClickToOpen = true; - ItemsContainer.Padding = new MarginPadding(0); BackgroundColour = Color4.Transparent; } From b9bec6a983a48f6e39ccb594effe1bf1dd6a3542 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 7 Sep 2017 23:06:35 +0900 Subject: [PATCH 33/54] CI fixes --- .../Visual/TestCaseEditorMenuBar.cs | 18 +++++----- osu.Game/Screens/Edit/Editor.cs | 34 +++++++++---------- osu.Game/Screens/Edit/Menus/EditorMenuBar.cs | 4 +-- .../Edit/Menus/EditorMenuItemSpacer.cs | 4 +-- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs index 9ff4f4c591..d04a12501e 100644 --- a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs +++ b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs @@ -27,22 +27,22 @@ namespace osu.Desktop.Tests.Visual new EditorMenuItem("Open Difficulty..."), new EditorMenuItem("Save"), new EditorMenuItem("Create a new Difficulty..."), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Revert to Saved"), new EditorMenuItem("Revert to Saved (Full)"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Test Beatmap"), new EditorMenuItem("Open AiMod"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Upload Beatmap..."), new EditorMenuItem("Export Package"), new EditorMenuItem("Export Map Package"), new EditorMenuItem("Import from..."), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Open Song Folder"), new EditorMenuItem("Open .osu in Notepad"), new EditorMenuItem("Open .osb in Notepad"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Exit"), } }, @@ -52,20 +52,20 @@ namespace osu.Desktop.Tests.Visual { new EditorMenuItem("Time Signature"), new EditorMenuItem("Metronome Clicks"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Add Timing Section"), new EditorMenuItem("Add Inheriting Section"), new EditorMenuItem("Reset Current Section"), new EditorMenuItem("Delete Timing Section"), new EditorMenuItem("Resnap Current Section"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Timing Setup"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Resnap All Notes", MenuItemType.Destructive), new EditorMenuItem("Move all notes in time...", MenuItemType.Destructive), new EditorMenuItem("Recalculate Slider Lengths", MenuItemType.Destructive), new EditorMenuItem("Delete All Timing Sections", MenuItemType.Destructive), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Set Current Position as Preview Point"), } }, diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 0454609689..be9098e3be 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -52,22 +52,22 @@ namespace osu.Game.Screens.Edit new EditorMenuItem("Open difficulty..."), new EditorMenuItem("Save"), new EditorMenuItem("Create new difficulty..."), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Revert to saved"), new EditorMenuItem("Revert to saved (full"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Test beatmap"), new EditorMenuItem("Open AiMod"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Upload Beatmap..."), new EditorMenuItem("Export package"), new EditorMenuItem("Export map package"), new EditorMenuItem("Import from..."), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Open song folder"), new EditorMenuItem("Open .osu in Notepad"), new EditorMenuItem("Open .osb in Notepad"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Exit", MenuItemType.Standard, Exit) } }, @@ -77,15 +77,15 @@ namespace osu.Game.Screens.Edit { new EditorMenuItem("Undo"), new EditorMenuItem("Redo"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Cut"), new EditorMenuItem("Copy"), new EditorMenuItem("Paste"), new EditorMenuItem("Delete"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Select all"), new EditorMenuItem("Clone"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Reverse selection"), new EditorMenuItem("Flip horizontally"), new EditorMenuItem("Flip vertically"), @@ -93,12 +93,12 @@ namespace osu.Game.Screens.Edit new EditorMenuItem("Rotate 90deg anticlockwise"), new EditorMenuItem("Rotate by..."), new EditorMenuItem("Scale by..."), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Reset selected objects' samples"), new EditorMenuItem("Reset all samples", MenuItemType.Destructive), new EditorMenuItem("Reset combo colours", MenuItemType.Destructive), new EditorMenuItem("Reset breaks", MenuItemType.Destructive), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Nudge backward"), new EditorMenuItem("Nudge forward") } @@ -110,10 +110,10 @@ namespace osu.Game.Screens.Edit new EditorMenuItem("Compose"), new EditorMenuItem("Design"), new EditorMenuItem("Timing"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Song setup..."), new EditorMenuItem("Timing setup..."), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Volume"), new EditorMenuItem("Grid level"), new EditorMenuItem("Show video"), @@ -131,7 +131,7 @@ namespace osu.Game.Screens.Edit new EditorMenuItem("Snap divisor"), new EditorMenuItem("Audio rate"), new EditorMenuItem("Grid snapping"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Create polygon cricles..."), new EditorMenuItem("Convert slider to stream"), new EditorMenuItem("Enable live mapping mode"), @@ -151,20 +151,20 @@ namespace osu.Game.Screens.Edit { new EditorMenuItem("Time signature"), new EditorMenuItem("Metronome clicks"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Add timing section"), new EditorMenuItem("Add inheriting section"), new EditorMenuItem("Reset current section"), new EditorMenuItem("Delete timing section"), new EditorMenuItem("Resnap current section"), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Timing setup..."), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Resnap all notes", MenuItemType.Destructive), new EditorMenuItem("Move all notes in time...", MenuItemType.Destructive), new EditorMenuItem("Recalculate slider lengths", MenuItemType.Destructive), new EditorMenuItem("Delete all timing sections", MenuItemType.Destructive), - new EditorMenuSpacer(), + new EditorMenuItemSpacer(), new EditorMenuItem("Set current position as preview point") } }, diff --git a/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs b/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs index 24625570a1..bb349b1531 100644 --- a/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs +++ b/osu.Game/Screens/Edit/Menus/EditorMenuBar.cs @@ -105,14 +105,14 @@ namespace osu.Game.Screens.Edit.Menus protected override bool OnHover(InputState state) { - if (Item is EditorMenuSpacer) + if (Item is EditorMenuItemSpacer) return true; return base.OnHover(state); } protected override bool OnClick(InputState state) { - if (Item is EditorMenuSpacer) + if (Item is EditorMenuItemSpacer) return true; return base.OnClick(state); } diff --git a/osu.Game/Screens/Edit/Menus/EditorMenuItemSpacer.cs b/osu.Game/Screens/Edit/Menus/EditorMenuItemSpacer.cs index 0e01992846..5060165ef7 100644 --- a/osu.Game/Screens/Edit/Menus/EditorMenuItemSpacer.cs +++ b/osu.Game/Screens/Edit/Menus/EditorMenuItemSpacer.cs @@ -3,9 +3,9 @@ namespace osu.Game.Screens.Edit.Menus { - public class EditorMenuSpacer : EditorMenuItem + public class EditorMenuItemSpacer : EditorMenuItem { - public EditorMenuSpacer() + public EditorMenuItemSpacer() : base(" ") { } From 439cbd09a0a9b84af357151232c9bcb525b81ca2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 7 Sep 2017 23:23:51 +0900 Subject: [PATCH 34/54] Fix incorrect TestCase type --- osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs index d04a12501e..9cb3053ff2 100644 --- a/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs +++ b/osu.Desktop.Tests/Visual/TestCaseEditorMenuBar.cs @@ -2,13 +2,12 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Graphics; -using osu.Framework.Testing; using osu.Game.Graphics.UserInterface; using osu.Game.Screens.Edit.Menus; namespace osu.Desktop.Tests.Visual { - public class TestCaseEditorMenuBar : TestCase + public class TestCaseEditorMenuBar : OsuTestCase { public TestCaseEditorMenuBar() { From 709aa1ed3dc315e6b751784e06e509e3a83bde77 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Thu, 7 Sep 2017 18:20:14 +0200 Subject: [PATCH 35/54] Moved all online score related parsing to its own class --- .../Online/API/Requests/GetScoresRequest.cs | 11 ++++------ osu.Game/Rulesets/Scoring/OnlineScore.cs | 19 +++++++++++++++++ osu.Game/Rulesets/Scoring/Score.cs | 21 +------------------ osu.Game/osu.Game.csproj | 1 + 4 files changed, 25 insertions(+), 27 deletions(-) create mode 100644 osu.Game/Rulesets/Scoring/OnlineScore.cs diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index a902c8c807..72b8649ae0 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -22,11 +22,8 @@ namespace osu.Game.Online.API.Requests private void onSuccess(GetScoresResponse r) { - foreach (Score score in r.Scores) - { - score.Beatmap = beatmap; - score.Ruleset = beatmap.Ruleset; - } + foreach (OnlineScore score in r.Scores) + score.GetModsFor(beatmap.Ruleset); } protected override WebRequest CreateWebRequest() @@ -43,6 +40,6 @@ namespace osu.Game.Online.API.Requests public class GetScoresResponse { [JsonProperty(@"scores")] - public IEnumerable Scores; + public IEnumerable Scores; } -} \ No newline at end of file +} diff --git a/osu.Game/Rulesets/Scoring/OnlineScore.cs b/osu.Game/Rulesets/Scoring/OnlineScore.cs new file mode 100644 index 0000000000..1f652e3d6c --- /dev/null +++ b/osu.Game/Rulesets/Scoring/OnlineScore.cs @@ -0,0 +1,19 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Linq; +using Newtonsoft.Json; + +namespace osu.Game.Rulesets.Scoring +{ + public class OnlineScore : Score + { + [JsonProperty(@"mods")] + private string[] modStrings { get; set; } + + public void GetModsFor(RulesetInfo ruleset) + { + Mods = ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); + } + } +} diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 154188a2fa..ecc7b60986 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using System.Linq; using System.Collections.Generic; using Newtonsoft.Json; using osu.Game.Beatmaps; @@ -28,27 +27,9 @@ namespace osu.Game.Rulesets.Scoring public int Combo { get; set; } - [JsonProperty(@"mods")] - private string[] modStrings { get; set; } - public RulesetInfo Ruleset; - private Mod[] mods; - public Mod[] Mods - { - get - { - // Evaluate the mod strings if necessary - return mods ?? (mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray()); - } - set - { - mods = value; - - // Assign the mod strings - modStrings = mods.Select(mod => mod.ShortenedName).ToArray(); - } - } + public Mod[] Mods; [JsonProperty(@"user")] public User User; diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 07ab58bffc..16812c3467 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -128,6 +128,7 @@ + From e71f907f899352f656d8a55236834e4c266385f1 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Thu, 7 Sep 2017 18:36:16 +0200 Subject: [PATCH 36/54] CI fix --- osu.Game/Rulesets/Ruleset.cs | 1 - osu.Game/Rulesets/Scoring/Score.cs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index 3d89afb7ff..33621662af 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -12,7 +12,6 @@ using osu.Game.Overlays.Settings; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; -using osu.Game.Screens.Play; namespace osu.Game.Rulesets { diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index ecc7b60986..c09df06633 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -27,9 +27,9 @@ namespace osu.Game.Rulesets.Scoring public int Combo { get; set; } - public RulesetInfo Ruleset; + public RulesetInfo Ruleset { get; set; } - public Mod[] Mods; + public Mod[] Mods { get; set; } [JsonProperty(@"user")] public User User; From 01553fc9ef9d6bdddfac28f68986f5db169fbd69 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Fri, 8 Sep 2017 02:46:54 +0200 Subject: [PATCH 37/54] Moved all online related score parsing to its class --- .../Online/API/Requests/GetScoresRequest.cs | 7 +- osu.Game/Rulesets/Scoring/OnlineScore.cs | 75 ++++++++++++++++++- osu.Game/Rulesets/Scoring/Score.cs | 38 ---------- 3 files changed, 79 insertions(+), 41 deletions(-) diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index 72b8649ae0..6e22bd6989 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -23,7 +23,12 @@ namespace osu.Game.Online.API.Requests private void onSuccess(GetScoresResponse r) { foreach (OnlineScore score in r.Scores) - score.GetModsFor(beatmap.Ruleset); + { + score.Beatmap = beatmap; + score.Ruleset = beatmap.Ruleset; + + score.ResolveModString(); + } } protected override WebRequest CreateWebRequest() diff --git a/osu.Game/Rulesets/Scoring/OnlineScore.cs b/osu.Game/Rulesets/Scoring/OnlineScore.cs index 1f652e3d6c..694ce023d1 100644 --- a/osu.Game/Rulesets/Scoring/OnlineScore.cs +++ b/osu.Game/Rulesets/Scoring/OnlineScore.cs @@ -1,19 +1,90 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; +using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; +using osu.Game.Users; +using osu.Game.Rulesets.Replays; namespace osu.Game.Rulesets.Scoring { public class OnlineScore : Score { + [JsonProperty(@"score")] + private double totalScore + { + set { TotalScore = value; } + } + + [JsonProperty(@"max_combo")] + private int maxCombo + { + set { MaxCombo = value; } + } + + [JsonProperty(@"user")] + private User user + { + set { User = value; } + } + + [JsonProperty(@"replay_data")] + private Replay replay + { + set { Replay = value; } + } + + [JsonProperty(@"score_id")] + private long onlineScoreID + { + set { OnlineScoreID = value; } + } + + [JsonProperty(@"created_at")] + private DateTimeOffset date + { + set { Date = value; } + } + + [JsonProperty(@"statistics")] + private Dictionary jsonStats + { + set + { + foreach (var kvp in value) + { + string key = kvp.Key; + switch (key) + { + case @"count_300": + key = @"300"; + break; + case @"count_100": + key = @"100"; + break; + case @"count_50": + key = @"50"; + break; + case @"count_miss": + key = @"x"; + break; + default: + continue; + } + + Statistics.Add(key, kvp.Value); + } + } + } + [JsonProperty(@"mods")] private string[] modStrings { get; set; } - public void GetModsFor(RulesetInfo ruleset) + public void ResolveModString() { - Mods = ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); + Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); } } } diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index c09df06633..ff4632a9c2 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Newtonsoft.Json; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mods; using osu.Game.Users; @@ -15,14 +14,12 @@ namespace osu.Game.Rulesets.Scoring { public ScoreRank Rank { get; set; } - [JsonProperty(@"score")] public double TotalScore { get; set; } public double Accuracy { get; set; } public double Health { get; set; } = 1; - [JsonProperty(@"max_combo")] public int MaxCombo { get; set; } public int Combo { get; set; } @@ -31,51 +28,16 @@ namespace osu.Game.Rulesets.Scoring public Mod[] Mods { get; set; } - [JsonProperty(@"user")] public User User; - [JsonProperty(@"replay_data")] public Replay Replay; public BeatmapInfo Beatmap; - [JsonProperty(@"score_id")] public long OnlineScoreID; - [JsonProperty(@"created_at")] public DateTimeOffset Date; - [JsonProperty(@"statistics")] - private Dictionary jsonStats - { - set - { - foreach (var kvp in value) - { - string key = kvp.Key; - switch (key) - { - case @"count_300": - key = @"300"; - break; - case @"count_100": - key = @"100"; - break; - case @"count_50": - key = @"50"; - break; - case @"count_miss": - key = @"x"; - break; - default: - continue; - } - - Statistics.Add(key, kvp.Value); - } - } - } - public Dictionary Statistics = new Dictionary(); } } From 80c35801a62a21289aff1053759c4f51dc0c05bc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 8 Sep 2017 16:15:41 +0900 Subject: [PATCH 38/54] Hide all overlays when home button is pressed --- osu.Game/OsuGame.cs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index c020675881..b4fbdfb252 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -245,7 +245,11 @@ namespace osu.Game LoadComponentAsync(Toolbar = new Toolbar { Depth = -4, - OnHome = delegate { intro?.ChildScreen?.MakeCurrent(); }, + OnHome = delegate + { + hideAllOverlays(); + intro?.ChildScreen?.MakeCurrent(); + }, }, overlayContent.Add); settings.StateChanged += delegate @@ -310,6 +314,16 @@ namespace osu.Game private OsuScreen currentScreen; private FrameworkConfigManager frameworkConfig; + private void hideAllOverlays() + { + settings.State = Visibility.Hidden; + chat.State = Visibility.Hidden; + direct.State = Visibility.Hidden; + social.State = Visibility.Hidden; + userProfile.State = Visibility.Hidden; + notificationOverlay.State = Visibility.Hidden; + } + private void screenChanged(Screen newScreen) { currentScreen = newScreen as OsuScreen; @@ -323,19 +337,12 @@ namespace osu.Game //central game screen change logic. if (!currentScreen.ShowOverlays) { - settings.State = Visibility.Hidden; - Toolbar.State = Visibility.Hidden; + hideAllOverlays(); musicController.State = Visibility.Hidden; - chat.State = Visibility.Hidden; - direct.State = Visibility.Hidden; - social.State = Visibility.Hidden; - userProfile.State = Visibility.Hidden; - notificationOverlay.State = Visibility.Hidden; + Toolbar.State = Visibility.Hidden; } else - { Toolbar.State = Visibility.Visible; - } ScreenChanged?.Invoke(newScreen); } From a5281739438f0c4bc38f52ce3a7f57cb980e0f98 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 8 Sep 2017 19:04:24 +0900 Subject: [PATCH 39/54] Ensure that WorkingBeatmap's Beatmap is never null Also ensures some extra fields inside Beatmap have non-null defaults. --- osu.Game/Beatmaps/Beatmap.cs | 8 ++++---- osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 6 +----- osu.Game/Beatmaps/Formats/BeatmapDecoder.cs | 4 +--- osu.Game/Beatmaps/WorkingBeatmap.cs | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 82777734bb..15953fcd82 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -17,7 +17,7 @@ namespace osu.Game.Beatmaps public class Beatmap where T : HitObject { - public BeatmapInfo BeatmapInfo; + public BeatmapInfo BeatmapInfo = new BeatmapInfo(); public ControlPointInfo ControlPointInfo = new ControlPointInfo(); public List Breaks = new List(); public readonly List ComboColors = new List @@ -33,7 +33,7 @@ namespace osu.Game.Beatmaps /// /// The HitObjects this Beatmap contains. /// - public List HitObjects; + public List HitObjects = new List(); /// /// Total amount of break time in the beatmap. @@ -44,12 +44,13 @@ namespace osu.Game.Beatmaps /// Constructs a new beatmap. /// /// The original beatmap to use the parameters of. - public Beatmap(Beatmap original = null) + public Beatmap(Beatmap original = null) { BeatmapInfo = original?.BeatmapInfo.DeepClone() ?? BeatmapInfo; ControlPointInfo = original?.ControlPointInfo ?? ControlPointInfo; Breaks = original?.Breaks ?? Breaks; ComboColors = original?.ComboColors ?? ComboColors; + HitObjects = original?.HitObjects ?? HitObjects; } } @@ -65,7 +66,6 @@ namespace osu.Game.Beatmaps public Beatmap(Beatmap original = null) : base(original) { - HitObjects = original?.HitObjects; } } } diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index 479f274efb..cc982c7a70 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -7,7 +7,6 @@ using osu.Framework.Audio.Track; using osu.Framework.Graphics.Textures; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; -using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; @@ -42,10 +41,7 @@ namespace osu.Game.Beatmaps this.game = game; } - protected override Beatmap GetBeatmap() => new Beatmap - { - HitObjects = new List(), - }; + protected override Beatmap GetBeatmap() => new Beatmap(); protected override Texture GetBackground() => game.Textures.Get(@"Backgrounds/bg4"); diff --git a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs index 234d65eee4..81695c3b5a 100644 --- a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.IO; -using osu.Game.Rulesets.Objects; namespace osu.Game.Beatmaps.Formats { @@ -21,7 +20,7 @@ namespace osu.Game.Beatmaps.Formats { string line; do { line = stream.ReadLine()?.Trim(); } - while (line != null && line.Length == 0); + while (line != null && line.Length == 0); if (line == null || !decoders.ContainsKey(line)) throw new IOException(@"Unknown file format"); @@ -47,7 +46,6 @@ namespace osu.Game.Beatmaps.Formats { var beatmap = new Beatmap { - HitObjects = new List(), BeatmapInfo = new BeatmapInfo { Metadata = new BeatmapMetadata(), diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index 462f94ed7c..4797f438d0 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -54,7 +54,7 @@ namespace osu.Game.Beatmaps { if (beatmap != null) return beatmap; - beatmap = GetBeatmap(); + beatmap = GetBeatmap() ?? new Beatmap(); // use the database-backed info. beatmap.BeatmapInfo = BeatmapInfo; From 526ee107b8102ad0dd815e59e8d543f00cc52436 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Fri, 8 Sep 2017 12:17:16 +0200 Subject: [PATCH 40/54] Use a method to apply a beatmap, its ruleset and the mods. --- osu.Game/Online/API/Requests/GetScoresRequest.cs | 7 +------ osu.Game/Rulesets/Scoring/OnlineScore.cs | 7 ++++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index 6e22bd6989..d5ba22b9ac 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -23,12 +23,7 @@ namespace osu.Game.Online.API.Requests private void onSuccess(GetScoresResponse r) { foreach (OnlineScore score in r.Scores) - { - score.Beatmap = beatmap; - score.Ruleset = beatmap.Ruleset; - - score.ResolveModString(); - } + score.ApplyBeatmap(beatmap); } protected override WebRequest CreateWebRequest() diff --git a/osu.Game/Rulesets/Scoring/OnlineScore.cs b/osu.Game/Rulesets/Scoring/OnlineScore.cs index 694ce023d1..a58d682d05 100644 --- a/osu.Game/Rulesets/Scoring/OnlineScore.cs +++ b/osu.Game/Rulesets/Scoring/OnlineScore.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; +using osu.Game.Beatmaps; using osu.Game.Users; using osu.Game.Rulesets.Replays; @@ -82,8 +83,12 @@ namespace osu.Game.Rulesets.Scoring [JsonProperty(@"mods")] private string[] modStrings { get; set; } - public void ResolveModString() + public void ApplyBeatmap(BeatmapInfo beatmap) { + Beatmap = beatmap; + Ruleset = beatmap.Ruleset; + + // Evaluate the mod string Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); } } From 0b1403683bc9a806a152067707eaba56052e273e Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Fri, 8 Sep 2017 12:21:35 +0200 Subject: [PATCH 41/54] Moved OnlineScore inside GetScoresRequest.cs --- .../Online/API/Requests/GetScoresRequest.cs | 86 +++++++++++++++++ osu.Game/Rulesets/Scoring/OnlineScore.cs | 95 ------------------- osu.Game/osu.Game.csproj | 1 - 3 files changed, 86 insertions(+), 96 deletions(-) delete mode 100644 osu.Game/Rulesets/Scoring/OnlineScore.cs diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index d5ba22b9ac..ef9ee85d25 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -1,10 +1,14 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using System.Collections.Generic; +using System.Linq; using Newtonsoft.Json; using osu.Framework.IO.Network; using osu.Game.Beatmaps; +using osu.Game.Users; +using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Scoring; namespace osu.Game.Online.API.Requests @@ -42,4 +46,86 @@ namespace osu.Game.Online.API.Requests [JsonProperty(@"scores")] public IEnumerable Scores; } + + public class OnlineScore : Score + { + [JsonProperty(@"score")] + private double totalScore + { + set { TotalScore = value; } + } + + [JsonProperty(@"max_combo")] + private int maxCombo + { + set { MaxCombo = value; } + } + + [JsonProperty(@"user")] + private User user + { + set { User = value; } + } + + [JsonProperty(@"replay_data")] + private Replay replay + { + set { Replay = value; } + } + + [JsonProperty(@"score_id")] + private long onlineScoreID + { + set { OnlineScoreID = value; } + } + + [JsonProperty(@"created_at")] + private DateTimeOffset date + { + set { Date = value; } + } + + [JsonProperty(@"statistics")] + private Dictionary jsonStats + { + set + { + foreach (var kvp in value) + { + string key = kvp.Key; + switch (key) + { + case @"count_300": + key = @"300"; + break; + case @"count_100": + key = @"100"; + break; + case @"count_50": + key = @"50"; + break; + case @"count_miss": + key = @"x"; + break; + default: + continue; + } + + Statistics.Add(key, kvp.Value); + } + } + } + + [JsonProperty(@"mods")] + private string[] modStrings { get; set; } + + public void ApplyBeatmap(BeatmapInfo beatmap) + { + Beatmap = beatmap; + Ruleset = beatmap.Ruleset; + + // Evaluate the mod string + Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); + } + } } diff --git a/osu.Game/Rulesets/Scoring/OnlineScore.cs b/osu.Game/Rulesets/Scoring/OnlineScore.cs deleted file mode 100644 index a58d682d05..0000000000 --- a/osu.Game/Rulesets/Scoring/OnlineScore.cs +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; -using osu.Game.Beatmaps; -using osu.Game.Users; -using osu.Game.Rulesets.Replays; - -namespace osu.Game.Rulesets.Scoring -{ - public class OnlineScore : Score - { - [JsonProperty(@"score")] - private double totalScore - { - set { TotalScore = value; } - } - - [JsonProperty(@"max_combo")] - private int maxCombo - { - set { MaxCombo = value; } - } - - [JsonProperty(@"user")] - private User user - { - set { User = value; } - } - - [JsonProperty(@"replay_data")] - private Replay replay - { - set { Replay = value; } - } - - [JsonProperty(@"score_id")] - private long onlineScoreID - { - set { OnlineScoreID = value; } - } - - [JsonProperty(@"created_at")] - private DateTimeOffset date - { - set { Date = value; } - } - - [JsonProperty(@"statistics")] - private Dictionary jsonStats - { - set - { - foreach (var kvp in value) - { - string key = kvp.Key; - switch (key) - { - case @"count_300": - key = @"300"; - break; - case @"count_100": - key = @"100"; - break; - case @"count_50": - key = @"50"; - break; - case @"count_miss": - key = @"x"; - break; - default: - continue; - } - - Statistics.Add(key, kvp.Value); - } - } - } - - [JsonProperty(@"mods")] - private string[] modStrings { get; set; } - - public void ApplyBeatmap(BeatmapInfo beatmap) - { - Beatmap = beatmap; - Ruleset = beatmap.Ruleset; - - // Evaluate the mod string - Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray(); - } - } -} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 66a892406f..05ba3e25ab 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -244,7 +244,6 @@ - From 7b497c0ecbc40b9979e6a340c8a9726738f89357 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 8 Sep 2017 23:24:47 +0900 Subject: [PATCH 42/54] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 5f2d5a57e5..4e7ea6af4f 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 5f2d5a57e5d506d7e5d87eeeb442adf10be061f6 +Subproject commit 4e7ea6af4f59f21f6afc522fb063c05417e1a5fe From 5c125737cb6a52b8a9c025fcdc1c7274d94120a0 Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Fri, 8 Sep 2017 17:47:23 +0200 Subject: [PATCH 43/54] Fix wrong initial topic color of not joined channels in the channel selection --- osu.Game/Overlays/Chat/ChannelListItem.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Chat/ChannelListItem.cs b/osu.Game/Overlays/Chat/ChannelListItem.cs index f43154ea20..8360e793d8 100644 --- a/osu.Game/Overlays/Chat/ChannelListItem.cs +++ b/osu.Game/Overlays/Chat/ChannelListItem.cs @@ -76,7 +76,6 @@ namespace osu.Game.Overlays.Chat Size = new Vector2(text_size), Shadow = false, Margin = new MarginPadding { Right = 10f }, - Alpha = 0f, }, }, }, @@ -109,7 +108,6 @@ namespace osu.Game.Overlays.Chat TextSize = text_size, Font = @"Exo2.0-SemiBold", Shadow = false, - Alpha = 0.8f, }, }, }, @@ -151,6 +149,9 @@ namespace osu.Game.Overlays.Chat joinedBind.ValueChanged += updateColour; joinedBind.BindTo(channel.Joined); + + joinedBind.TriggerChange(); + FinishTransforms(true); } protected override bool OnHover(InputState state) From 20f93c83d694b17f86c0343e86bdf96811796d2e Mon Sep 17 00:00:00 2001 From: naoey Date: Fri, 8 Sep 2017 22:37:28 +0530 Subject: [PATCH 44/54] Make downloads happen in BeatmapManager. --- .../Visual/TestCasePlaySongSelect.cs | 2 +- osu.Game/Beatmaps/BeatmapManager.cs | 74 ++++++++++++++++++- .../API/Requests/DownloadBeatmapSetRequest.cs | 21 ++++++ osu.Game/OsuGameBase.cs | 14 ++-- osu.Game/Overlays/Direct/DirectPanel.cs | 68 +++-------------- osu.Game/osu.Game.csproj | 1 + 6 files changed, 115 insertions(+), 65 deletions(-) create mode 100644 osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs diff --git a/osu.Desktop.Tests/Visual/TestCasePlaySongSelect.cs b/osu.Desktop.Tests/Visual/TestCasePlaySongSelect.cs index 379100b543..8d1ae7d913 100644 --- a/osu.Desktop.Tests/Visual/TestCasePlaySongSelect.cs +++ b/osu.Desktop.Tests/Visual/TestCasePlaySongSelect.cs @@ -32,7 +32,7 @@ namespace osu.Desktop.Tests.Visual backingDatabase.CreateTable(); rulesets = new RulesetStore(backingDatabase); - manager = new BeatmapManager(storage, null, backingDatabase, rulesets); + manager = new BeatmapManager(storage, null, backingDatabase, rulesets, null); for (int i = 0; i < 100; i += 10) manager.Import(createTestBeatmapSet(i)); diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 551612330b..fbbc94a8f5 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -20,6 +20,9 @@ using osu.Game.IPC; using osu.Game.Overlays.Notifications; using osu.Game.Rulesets; using SQLite.Net; +using osu.Game.Online.API.Requests; +using System.Threading.Tasks; +using osu.Game.Online.API; namespace osu.Game.Beatmaps { @@ -63,6 +66,10 @@ namespace osu.Game.Beatmaps private readonly BeatmapStore beatmaps; + private readonly APIAccess api; + + private readonly Dictionary downloadsMap; + // ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised) private BeatmapIPCChannel ipc; @@ -76,7 +83,7 @@ namespace osu.Game.Beatmaps /// public Func GetStableStorage { private get; set; } - public BeatmapManager(Storage storage, FileStore files, SQLiteConnection connection, RulesetStore rulesets, IIpcHost importHost = null) + public BeatmapManager(Storage storage, FileStore files, SQLiteConnection connection, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null) { beatmaps = new BeatmapStore(connection); beatmaps.BeatmapSetAdded += s => BeatmapSetAdded?.Invoke(s); @@ -88,9 +95,12 @@ namespace osu.Game.Beatmaps this.files = files; this.connection = connection; this.rulesets = rulesets; + this.api = api; if (importHost != null) ipc = new BeatmapIPCChannel(importHost, this); + + downloadsMap = new Dictionary(); } /// @@ -177,6 +187,68 @@ namespace osu.Game.Beatmaps beatmaps.Add(beatmapSetInfo); } + /// + /// Download a beatmap + /// + /// The beatmap to be downloaded + public DownloadBeatmapSetRequest Download(BeatmapSetInfo beatmapSetInfo) + { + if (api == null || downloadsMap.ContainsKey(beatmapSetInfo)) return null; + + ProgressNotification downloadNotification = new ProgressNotification + { + Text = $"Downloading {beatmapSetInfo.Metadata.Artist} - {beatmapSetInfo.Metadata.Title}", + }; + + var request = new DownloadBeatmapSetRequest(beatmapSetInfo); + + request.DownloadProgressed += progress => + { + downloadNotification.State = ProgressNotificationState.Active; + downloadNotification.Progress = progress; + }; + + request.Success += data => + { + downloadNotification.State = ProgressNotificationState.Completed; + + using (var stream = new MemoryStream(data)) + using (var archive = new OszArchiveReader(stream)) + Import(archive); + + downloadsMap.Remove(beatmapSetInfo); + }; + + request.Failure += data => + { + downloadNotification.State = ProgressNotificationState.Completed; + Logger.Error(data, "Failed to get beatmap download information"); + downloadsMap.Remove(beatmapSetInfo); + }; + + downloadNotification.CancelRequested += () => + { + Logger.Log("Cancel requested"); + downloadsMap.Remove(beatmapSetInfo); + return true; + }; + + downloadsMap[beatmapSetInfo] = request; + PostNotification?.Invoke(downloadNotification); + + // don't run in the main api queue as this is a long-running task. + Task.Run(() => request.Perform(api)); + + return request; + } + + /// + /// Check if a beatmap is already downloading. + /// + /// The to check against. + /// true if a download request already exists, false if it doesn't. + public bool IsDownloading(BeatmapSetInfo beatmap) => downloadsMap.ContainsKey(beatmap); + /// /// Delete a beatmap from the manager. /// Is a no-op for already deleted beatmaps. diff --git a/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs b/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs new file mode 100644 index 0000000000..28473d9f66 --- /dev/null +++ b/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs @@ -0,0 +1,21 @@ +using osu.Game.Beatmaps; +using System; + +namespace osu.Game.Online.API.Requests +{ + public class DownloadBeatmapSetRequest : APIDownloadRequest + { + private readonly BeatmapSetInfo beatmapSet; + + public Action DownloadProgressed; + + public DownloadBeatmapSetRequest(BeatmapSetInfo beatmapSet) + { + this.beatmapSet = beatmapSet; + + Progress += (current, total) => DownloadProgressed?.Invoke((float) current / total); + } + + protected override string Target => $@"beatmapsets/{beatmapSet.OnlineBeatmapSetID}/download"; + } +} diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index a7136ce803..76eb7d5101 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -106,9 +106,15 @@ namespace osu.Game connection.CreateTable(); + dependencies.Cache(API = new APIAccess + { + Username = LocalConfig.Get(OsuSetting.Username), + Token = LocalConfig.Get(OsuSetting.Token) + }); + dependencies.Cache(RulesetStore = new RulesetStore(connection)); dependencies.Cache(FileStore = new FileStore(connection, Host.Storage)); - dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, FileStore, connection, RulesetStore, Host)); + dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, FileStore, connection, RulesetStore, API, Host)); dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, connection, Host, BeatmapManager, RulesetStore)); dependencies.Cache(KeyBindingStore = new KeyBindingStore(connection, RulesetStore)); dependencies.Cache(new OsuColour()); @@ -144,12 +150,6 @@ namespace osu.Game Beatmap = new NonNullableBindable(defaultBeatmap); BeatmapManager.DefaultBeatmap = defaultBeatmap; - dependencies.Cache(API = new APIAccess - { - Username = LocalConfig.Get(OsuSetting.Username), - Token = LocalConfig.Get(OsuSetting.Token) - }); - Beatmap.ValueChanged += b => { // compare to last beatmap as sometimes the two may share a track representation (optimisation, see WorkingBeatmap.TransferTo) diff --git a/osu.Game/Overlays/Direct/DirectPanel.cs b/osu.Game/Overlays/Direct/DirectPanel.cs index a642f72821..746cd39085 100644 --- a/osu.Game/Overlays/Direct/DirectPanel.cs +++ b/osu.Game/Overlays/Direct/DirectPanel.cs @@ -115,23 +115,8 @@ namespace osu.Game.Overlays.Direct base.OnHoverLost(state); } - // this should eventually be moved to a more central place, like BeatmapManager. - private DownloadBeatmapSetRequest downloadRequest; - protected void StartDownload() { - if (api == null) return; - - // we already have an active download running. - if (downloadRequest != null) - { - content.MoveToX(-5, 50, Easing.OutSine).Then() - .MoveToX(5, 100, Easing.InOutSine).Then() - .MoveToX(-5, 100, Easing.InOutSine).Then() - .MoveToX(0, 50, Easing.InSine).Then(); - return; - } - if (!api.LocalUser.Value.IsSupporter) { notifications.Post(new SimpleNotification @@ -142,25 +127,28 @@ namespace osu.Game.Overlays.Direct return; } + // we already have an active download running. + if (beatmaps.IsDownloading(SetInfo)) + { + content.MoveToX(-5, 50, Easing.OutSine).Then() + .MoveToX(5, 100, Easing.InOutSine).Then() + .MoveToX(-5, 100, Easing.InOutSine).Then() + .MoveToX(0, 50, Easing.InSine).Then(); + return; + } + + var downloadRequest = beatmaps.Download(SetInfo); + progressBar.FadeIn(400, Easing.OutQuint); progressBar.ResizeHeightTo(4, 400, Easing.OutQuint); progressBar.Current.Value = 0; - ProgressNotification downloadNotification = new ProgressNotification - { - Text = $"Downloading {SetInfo.Metadata.Artist} - {SetInfo.Metadata.Title}", - }; - - downloadRequest = new DownloadBeatmapSetRequest(SetInfo); downloadRequest.Failure += e => { progressBar.Current.Value = 0; progressBar.FadeOut(500); - downloadNotification.State = ProgressNotificationState.Completed; Logger.Error(e, "Failed to get beatmap download information"); - - downloadRequest = null; }; downloadRequest.Progress += (current, total) => @@ -169,45 +157,13 @@ namespace osu.Game.Overlays.Direct progressBar.Current.Value = progress; - downloadNotification.State = ProgressNotificationState.Active; - downloadNotification.Progress = progress; }; downloadRequest.Success += data => { progressBar.Current.Value = 1; progressBar.FadeOut(500); - - downloadNotification.State = ProgressNotificationState.Completed; - - using (var stream = new MemoryStream(data)) - using (var archive = new OszArchiveReader(stream)) - beatmaps.Import(archive); }; - - downloadNotification.CancelRequested += () => - { - downloadRequest.Cancel(); - downloadRequest = null; - return true; - }; - - notifications.Post(downloadNotification); - - // don't run in the main api queue as this is a long-running task. - Task.Run(() => downloadRequest.Perform(api)); - } - - public class DownloadBeatmapSetRequest : APIDownloadRequest - { - private readonly BeatmapSetInfo beatmapSet; - - public DownloadBeatmapSetRequest(BeatmapSetInfo beatmapSet) - { - this.beatmapSet = beatmapSet; - } - - protected override string Target => $@"beatmapsets/{beatmapSet.OnlineBeatmapSetID}/download"; } protected override void LoadComplete() diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 05ba3e25ab..5e1c5426ec 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -98,6 +98,7 @@ + From 31a507372a0795f850c76a9e717978d6ab75d3fa Mon Sep 17 00:00:00 2001 From: naoey Date: Fri, 8 Sep 2017 23:16:48 +0530 Subject: [PATCH 45/54] Don't show beatmaps that are already added. --- osu.Game/Overlays/DirectOverlay.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/DirectOverlay.cs b/osu.Game/Overlays/DirectOverlay.cs index f734e43826..8bbb937641 100644 --- a/osu.Game/Overlays/DirectOverlay.cs +++ b/osu.Game/Overlays/DirectOverlay.cs @@ -27,6 +27,7 @@ namespace osu.Game.Overlays private APIAccess api; private RulesetStore rulesets; + private BeatmapManager beatmaps; private readonly FillFlowContainer resultCountsContainer; private readonly OsuSpriteText resultCountsText; @@ -147,6 +148,8 @@ namespace osu.Game.Overlays { this.api = api; this.rulesets = rulesets; + this.beatmaps = beatmaps; + resultCountsContainer.Colour = colours.Yellow; beatmaps.BeatmapSetAdded += setAdded; @@ -237,7 +240,10 @@ namespace osu.Game.Overlays getSetsRequest.Success += r => { - BeatmapSets = r?.Select(response => response.ToBeatmapSet(rulesets)); + BeatmapSets = r?. + Select(response => response.ToBeatmapSet(rulesets)). + Where(b => (beatmaps.QueryBeatmapSet(q => q.OnlineBeatmapSetID == b.OnlineBeatmapSetID) == null)); + if (BeatmapSets == null) return; var artists = new List(); From 00306b6e3807d08867a2f09aef9623308b565fbf Mon Sep 17 00:00:00 2001 From: naoey Date: Fri, 8 Sep 2017 23:55:20 +0530 Subject: [PATCH 46/54] Maintain download progress between switching result views. - Check for existing download requests on creating DirectPanel - Actually remove downloaded beatmap from results --- osu.Game/Beatmaps/BeatmapManager.cs | 25 +++++---- osu.Game/Overlays/Direct/DirectPanel.cs | 71 +++++++++++++++---------- osu.Game/Overlays/DirectOverlay.cs | 30 ++++++----- 3 files changed, 72 insertions(+), 54 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index fbbc94a8f5..22402ba76a 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -68,7 +68,7 @@ namespace osu.Game.Beatmaps private readonly APIAccess api; - private readonly Dictionary downloadsMap; + private readonly Dictionary downloadsMap; // ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised) private BeatmapIPCChannel ipc; @@ -100,7 +100,7 @@ namespace osu.Game.Beatmaps if (importHost != null) ipc = new BeatmapIPCChannel(importHost, this); - downloadsMap = new Dictionary(); + downloadsMap = new Dictionary(); } /// @@ -191,9 +191,10 @@ namespace osu.Game.Beatmaps /// Download a beatmap /// /// The beatmap to be downloaded + /// The new , or null if a download already exists for the same beatmap. public DownloadBeatmapSetRequest Download(BeatmapSetInfo beatmapSetInfo) { - if (api == null || downloadsMap.ContainsKey(beatmapSetInfo)) return null; + if (api == null || downloadsMap.ContainsKey(beatmapSetInfo.OnlineBeatmapSetID)) return null; ProgressNotification downloadNotification = new ProgressNotification { @@ -216,24 +217,26 @@ namespace osu.Game.Beatmaps using (var archive = new OszArchiveReader(stream)) Import(archive); - downloadsMap.Remove(beatmapSetInfo); + downloadsMap.Remove(beatmapSetInfo.OnlineBeatmapSetID); }; request.Failure += data => { downloadNotification.State = ProgressNotificationState.Completed; Logger.Error(data, "Failed to get beatmap download information"); - downloadsMap.Remove(beatmapSetInfo); + downloadsMap.Remove(beatmapSetInfo.OnlineBeatmapSetID); }; downloadNotification.CancelRequested += () => { Logger.Log("Cancel requested"); - downloadsMap.Remove(beatmapSetInfo); + downloadsMap[beatmapSetInfo.OnlineBeatmapSetID].Cancel(); + downloadsMap.Remove(beatmapSetInfo.OnlineBeatmapSetID); + downloadNotification.State = ProgressNotificationState.Cancelled; return true; }; - downloadsMap[beatmapSetInfo] = request; + downloadsMap[beatmapSetInfo.OnlineBeatmapSetID] = request; PostNotification?.Invoke(downloadNotification); // don't run in the main api queue as this is a long-running task. @@ -243,11 +246,11 @@ namespace osu.Game.Beatmaps } /// - /// Check if a beatmap is already downloading. + /// Get an existing download request if it exists. /// - /// The to check against. - /// true if a download request already exists, false if it doesn't. - public bool IsDownloading(BeatmapSetInfo beatmap) => downloadsMap.ContainsKey(beatmap); + /// The whose download request is wanted. + /// The object if it exists, or null. + public DownloadBeatmapSetRequest GetExistingDownload(BeatmapSetInfo beatmap) => downloadsMap.GetOrDefault(beatmap.OnlineBeatmapSetID); /// /// Delete a beatmap from the manager. diff --git a/osu.Game/Overlays/Direct/DirectPanel.cs b/osu.Game/Overlays/Direct/DirectPanel.cs index 746cd39085..0f87d22123 100644 --- a/osu.Game/Overlays/Direct/DirectPanel.cs +++ b/osu.Game/Overlays/Direct/DirectPanel.cs @@ -22,6 +22,7 @@ using osu.Game.Online.API; using osu.Framework.Logging; using osu.Game.Beatmaps.IO; using osu.Game.Overlays.Notifications; +using osu.Game.Online.API.Requests; namespace osu.Game.Overlays.Direct { @@ -40,6 +41,44 @@ namespace osu.Game.Overlays.Direct private BeatmapManager beatmaps; private NotificationOverlay notifications; + private DownloadBeatmapSetRequest downloadRequest; + protected DownloadBeatmapSetRequest DownloadRequest + { + get { return downloadRequest; } + set + { + if (value == null) return; + + downloadRequest = value; + + progressBar.FadeIn(400, Easing.OutQuint); + progressBar.ResizeHeightTo(4, 400, Easing.OutQuint); + + progressBar.Current.Value = 0; + + downloadRequest.Failure += e => + { + progressBar.Current.Value = 0; + progressBar.FadeOut(500); + Logger.Error(e, "Failed to get beatmap download information"); + }; + + downloadRequest.Progress += (current, total) => + { + float progress = (float)current / total; + + progressBar.Current.Value = progress; + + }; + + downloadRequest.Success += data => + { + progressBar.Current.Value = 1; + progressBar.FadeOut(500); + }; + } + } + protected override Container Content => content; protected DirectPanel(BeatmapSetInfo setInfo) @@ -97,6 +136,8 @@ namespace osu.Game.Overlays.Direct }, } }); + + DownloadRequest = beatmaps.GetExistingDownload(SetInfo); } protected override bool OnHover(InputState state) @@ -128,7 +169,7 @@ namespace osu.Game.Overlays.Direct } // we already have an active download running. - if (beatmaps.IsDownloading(SetInfo)) + if ((DownloadRequest = beatmaps.Download(SetInfo)) == null) { content.MoveToX(-5, 50, Easing.OutSine).Then() .MoveToX(5, 100, Easing.InOutSine).Then() @@ -136,34 +177,6 @@ namespace osu.Game.Overlays.Direct .MoveToX(0, 50, Easing.InSine).Then(); return; } - - var downloadRequest = beatmaps.Download(SetInfo); - - progressBar.FadeIn(400, Easing.OutQuint); - progressBar.ResizeHeightTo(4, 400, Easing.OutQuint); - - progressBar.Current.Value = 0; - - downloadRequest.Failure += e => - { - progressBar.Current.Value = 0; - progressBar.FadeOut(500); - Logger.Error(e, "Failed to get beatmap download information"); - }; - - downloadRequest.Progress += (current, total) => - { - float progress = (float)current / total; - - progressBar.Current.Value = progress; - - }; - - downloadRequest.Success += data => - { - progressBar.Current.Value = 1; - progressBar.FadeOut(500); - }; } protected override void LoadComplete() diff --git a/osu.Game/Overlays/DirectOverlay.cs b/osu.Game/Overlays/DirectOverlay.cs index 8bbb937641..2aa64e2b99 100644 --- a/osu.Game/Overlays/DirectOverlay.cs +++ b/osu.Game/Overlays/DirectOverlay.cs @@ -47,9 +47,22 @@ namespace osu.Game.Overlays set { if (beatmapSets?.Equals(value) ?? false) return; + beatmapSets = value; - recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value); + if (beatmapSets == null) return; + + var artists = new List(); + var songs = new List(); + var tags = new List(); + foreach (var s in beatmapSets) + { + artists.Add(s.Metadata.Artist); + songs.Add(s.Metadata.Title); + tags.AddRange(s.Metadata.Tags.Split(' ')); + } + + ResultAmounts = new ResultCounts(distinctCount(artists), distinctCount(songs), distinctCount(tags)); } } @@ -159,6 +172,7 @@ namespace osu.Game.Overlays { // if a new map was imported, we should remove it from search results (download completed etc.) panels?.FirstOrDefault(p => p.SetInfo.OnlineBeatmapSetID == set.OnlineBeatmapSetID)?.FadeOut(400).Expire(); + BeatmapSets = BeatmapSets.Where(b => b.OnlineBeatmapSetID != set.OnlineBeatmapSetID); } private void updateResultCounts() @@ -244,19 +258,7 @@ namespace osu.Game.Overlays Select(response => response.ToBeatmapSet(rulesets)). Where(b => (beatmaps.QueryBeatmapSet(q => q.OnlineBeatmapSetID == b.OnlineBeatmapSetID) == null)); - if (BeatmapSets == null) return; - - var artists = new List(); - var songs = new List(); - var tags = new List(); - foreach (var s in BeatmapSets) - { - artists.Add(s.Metadata.Artist); - songs.Add(s.Metadata.Title); - tags.AddRange(s.Metadata.Tags.Split(' ')); - } - - ResultAmounts = new ResultCounts(distinctCount(artists), distinctCount(songs), distinctCount(tags)); + recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value); }; api.Queue(getSetsRequest); From 0e4973020aaf65f8c3c7f1075af932cbfd63c2d9 Mon Sep 17 00:00:00 2001 From: naoey Date: Sat, 9 Sep 2017 00:17:38 +0530 Subject: [PATCH 47/54] Resharper and test case fixes. --- osu.Desktop.Tests/Visual/TestCaseDirect.cs | 8 ++++++++ osu.Game/Overlays/Direct/DirectPanel.cs | 4 ---- osu.Game/Overlays/DirectOverlay.cs | 6 +++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseDirect.cs b/osu.Desktop.Tests/Visual/TestCaseDirect.cs index b78ea02767..9fd93c3f1e 100644 --- a/osu.Desktop.Tests/Visual/TestCaseDirect.cs +++ b/osu.Desktop.Tests/Visual/TestCaseDirect.cs @@ -41,12 +41,14 @@ namespace osu.Desktop.Tests.Visual { new BeatmapSetInfo { + OnlineBeatmapSetID = 578332, Metadata = new BeatmapMetadata { Title = @"OrVid", Artist = @"An", Author = @"RLC", Source = @"", + Tags = @"acuticnotes an-fillnote revid tear tearvid encrpted encryption axi axivid quad her hervid recoll", }, OnlineInfo = new BeatmapSetOnlineInfo { @@ -71,12 +73,14 @@ namespace osu.Desktop.Tests.Visual }, new BeatmapSetInfo { + OnlineBeatmapSetID = 599627, Metadata = new BeatmapMetadata { Title = @"tiny lamp", Artist = @"fhana", Author = @"Sotarks", Source = @"ぎんぎつね", + Tags = @"lantis junichi sato yuxuki waga kevin mitsunaga towana gingitsune opening op full ver version kalibe collab collaboration", }, OnlineInfo = new BeatmapSetOnlineInfo { @@ -101,12 +105,14 @@ namespace osu.Desktop.Tests.Visual }, new BeatmapSetInfo { + OnlineBeatmapSetID = 513268, Metadata = new BeatmapMetadata { Title = @"At Gwanghwamun", Artist = @"KYUHYUN", Author = @"Cerulean Veyron", Source = @"", + Tags = @"soul ballad kh super junior sj suju 슈퍼주니어 kt뮤직 sm엔터테인먼트 s.m.entertainment kt music 1st mini album ep", }, OnlineInfo = new BeatmapSetOnlineInfo { @@ -146,12 +152,14 @@ namespace osu.Desktop.Tests.Visual }, new BeatmapSetInfo { + OnlineBeatmapSetID = 586841, Metadata = new BeatmapMetadata { Title = @"RHAPSODY OF BLUE SKY", Artist = @"fhana", Author = @"[Kamiya]", Source = @"小林さんちのメイドラゴン", + Tags = @"kobayashi san chi no maidragon aozora no opening anime maid dragon oblivion karen dynamix imoutosan pata-mon gxytcgxytc", }, OnlineInfo = new BeatmapSetOnlineInfo { diff --git a/osu.Game/Overlays/Direct/DirectPanel.cs b/osu.Game/Overlays/Direct/DirectPanel.cs index 0f87d22123..4bbba27d99 100644 --- a/osu.Game/Overlays/Direct/DirectPanel.cs +++ b/osu.Game/Overlays/Direct/DirectPanel.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; -using System.IO; -using System.Threading.Tasks; using OpenTK; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -20,7 +18,6 @@ using osu.Framework.Input; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osu.Framework.Logging; -using osu.Game.Beatmaps.IO; using osu.Game.Overlays.Notifications; using osu.Game.Online.API.Requests; @@ -175,7 +172,6 @@ namespace osu.Game.Overlays.Direct .MoveToX(5, 100, Easing.InOutSine).Then() .MoveToX(-5, 100, Easing.InOutSine).Then() .MoveToX(0, 50, Easing.InSine).Then(); - return; } } diff --git a/osu.Game/Overlays/DirectOverlay.cs b/osu.Game/Overlays/DirectOverlay.cs index 2aa64e2b99..54fda5a38d 100644 --- a/osu.Game/Overlays/DirectOverlay.cs +++ b/osu.Game/Overlays/DirectOverlay.cs @@ -63,6 +63,10 @@ namespace osu.Game.Overlays } ResultAmounts = new ResultCounts(distinctCount(artists), distinctCount(songs), distinctCount(tags)); + + if (beatmapSets.Any() && panels == null) + // real use case? currently only seems to be for test case + recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value); } } @@ -256,7 +260,7 @@ namespace osu.Game.Overlays { BeatmapSets = r?. Select(response => response.ToBeatmapSet(rulesets)). - Where(b => (beatmaps.QueryBeatmapSet(q => q.OnlineBeatmapSetID == b.OnlineBeatmapSetID) == null)); + Where(b => beatmaps.QueryBeatmapSet(q => q.OnlineBeatmapSetID == b.OnlineBeatmapSetID) == null); recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value); }; From 5a3814b02e765e8b34491fed43b8d91ad2eb4032 Mon Sep 17 00:00:00 2001 From: naoey Date: Sat, 9 Sep 2017 01:04:55 +0530 Subject: [PATCH 48/54] XMLdoc fixes and a cautionary check. --- osu.Game/Beatmaps/BeatmapManager.cs | 4 ++-- osu.Game/Overlays/Direct/DirectPanel.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 22402ba76a..4de5d49b1e 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -188,9 +188,9 @@ namespace osu.Game.Beatmaps } /// - /// Download a beatmap + /// Downloads a beatmap. /// - /// The beatmap to be downloaded + /// The to be downloaded. /// The new , or null if a download already exists for the same beatmap. public DownloadBeatmapSetRequest Download(BeatmapSetInfo beatmapSetInfo) { diff --git a/osu.Game/Overlays/Direct/DirectPanel.cs b/osu.Game/Overlays/Direct/DirectPanel.cs index 4bbba27d99..7f0c8ac350 100644 --- a/osu.Game/Overlays/Direct/DirectPanel.cs +++ b/osu.Game/Overlays/Direct/DirectPanel.cs @@ -44,7 +44,7 @@ namespace osu.Game.Overlays.Direct get { return downloadRequest; } set { - if (value == null) return; + if (value == null || downloadRequest == value) return; downloadRequest = value; From 20becbe5760fa2c5d9f07c00558513aa4c59f00a Mon Sep 17 00:00:00 2001 From: naoey Date: Sat, 9 Sep 2017 01:53:42 +0530 Subject: [PATCH 49/54] Use the specifically created progress action, add license header. --- osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs | 5 ++++- osu.Game/Overlays/Direct/DirectPanel.cs | 8 +------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs b/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs index 28473d9f66..0ba4adf9c9 100644 --- a/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs +++ b/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs @@ -1,4 +1,7 @@ -using osu.Game.Beatmaps; +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Beatmaps; using System; namespace osu.Game.Online.API.Requests diff --git a/osu.Game/Overlays/Direct/DirectPanel.cs b/osu.Game/Overlays/Direct/DirectPanel.cs index 7f0c8ac350..4bf3442453 100644 --- a/osu.Game/Overlays/Direct/DirectPanel.cs +++ b/osu.Game/Overlays/Direct/DirectPanel.cs @@ -60,13 +60,7 @@ namespace osu.Game.Overlays.Direct Logger.Error(e, "Failed to get beatmap download information"); }; - downloadRequest.Progress += (current, total) => - { - float progress = (float)current / total; - - progressBar.Current.Value = progress; - - }; + downloadRequest.DownloadProgressed += progress => progressBar.Current.Value = progress; downloadRequest.Success += data => { From 5f5dd54f9d1e99971218ad4910ab13c0df421dc5 Mon Sep 17 00:00:00 2001 From: naoey Date: Sat, 9 Sep 2017 09:51:37 +0530 Subject: [PATCH 50/54] Use a List instead of a Dictionary. --- osu.Game/Beatmaps/BeatmapManager.cs | 21 ++++++++++--------- .../API/Requests/DownloadBeatmapSetRequest.cs | 8 +++---- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 4de5d49b1e..8e7b38a50c 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -68,7 +68,7 @@ namespace osu.Game.Beatmaps private readonly APIAccess api; - private readonly Dictionary downloadsMap; + private readonly List downloadsList; // ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised) private BeatmapIPCChannel ipc; @@ -100,7 +100,7 @@ namespace osu.Game.Beatmaps if (importHost != null) ipc = new BeatmapIPCChannel(importHost, this); - downloadsMap = new Dictionary(); + downloadsList = new List(); } /// @@ -194,7 +194,8 @@ namespace osu.Game.Beatmaps /// The new , or null if a download already exists for the same beatmap. public DownloadBeatmapSetRequest Download(BeatmapSetInfo beatmapSetInfo) { - if (api == null || downloadsMap.ContainsKey(beatmapSetInfo.OnlineBeatmapSetID)) return null; + if (api == null || downloadsList.Find(d => d.BeatmapSet.OnlineBeatmapSetID == beatmapSetInfo.OnlineBeatmapSetID) != null) + return null; ProgressNotification downloadNotification = new ProgressNotification { @@ -217,29 +218,29 @@ namespace osu.Game.Beatmaps using (var archive = new OszArchiveReader(stream)) Import(archive); - downloadsMap.Remove(beatmapSetInfo.OnlineBeatmapSetID); + downloadsList.Remove(request); }; request.Failure += data => { downloadNotification.State = ProgressNotificationState.Completed; Logger.Error(data, "Failed to get beatmap download information"); - downloadsMap.Remove(beatmapSetInfo.OnlineBeatmapSetID); + downloadsList.Remove(request); }; downloadNotification.CancelRequested += () => { - Logger.Log("Cancel requested"); - downloadsMap[beatmapSetInfo.OnlineBeatmapSetID].Cancel(); - downloadsMap.Remove(beatmapSetInfo.OnlineBeatmapSetID); + request.Cancel(); + downloadsList.Remove(request); downloadNotification.State = ProgressNotificationState.Cancelled; return true; }; - downloadsMap[beatmapSetInfo.OnlineBeatmapSetID] = request; + downloadsList.Add(request); PostNotification?.Invoke(downloadNotification); // don't run in the main api queue as this is a long-running task. + // TODO: ensure the Success/Failure callbacks are being scheduled to the main thread for thread safety. Task.Run(() => request.Perform(api)); return request; @@ -250,7 +251,7 @@ namespace osu.Game.Beatmaps /// /// The whose download request is wanted. /// The object if it exists, or null. - public DownloadBeatmapSetRequest GetExistingDownload(BeatmapSetInfo beatmap) => downloadsMap.GetOrDefault(beatmap.OnlineBeatmapSetID); + public DownloadBeatmapSetRequest GetExistingDownload(BeatmapSetInfo beatmap) => downloadsList.Find(d => d.BeatmapSet.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID); /// /// Delete a beatmap from the manager. diff --git a/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs b/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs index 0ba4adf9c9..5a9f609bca 100644 --- a/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs +++ b/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs @@ -8,17 +8,17 @@ namespace osu.Game.Online.API.Requests { public class DownloadBeatmapSetRequest : APIDownloadRequest { - private readonly BeatmapSetInfo beatmapSet; + public readonly BeatmapSetInfo BeatmapSet; public Action DownloadProgressed; - public DownloadBeatmapSetRequest(BeatmapSetInfo beatmapSet) + public DownloadBeatmapSetRequest(BeatmapSetInfo set) { - this.beatmapSet = beatmapSet; + BeatmapSet = set; Progress += (current, total) => DownloadProgressed?.Invoke((float) current / total); } - protected override string Target => $@"beatmapsets/{beatmapSet.OnlineBeatmapSetID}/download"; + protected override string Target => $@"beatmapsets/{BeatmapSet.OnlineBeatmapSetID}/download"; } } From e67606e2031722830b89c63ef0bd5d24d24aca94 Mon Sep 17 00:00:00 2001 From: naoey Date: Sat, 9 Sep 2017 10:25:28 +0530 Subject: [PATCH 51/54] Return existing download if it exists. --- osu.Game/Beatmaps/BeatmapManager.cs | 9 ++++++--- osu.Game/Overlays/Direct/DirectPanel.cs | 6 +++++- osu.Game/Overlays/DirectOverlay.cs | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 8e7b38a50c..472e44f36b 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -191,11 +191,14 @@ namespace osu.Game.Beatmaps /// Downloads a beatmap. /// /// The to be downloaded. - /// The new , or null if a download already exists for the same beatmap. + /// A new , or an existing one if a download is already in progress. public DownloadBeatmapSetRequest Download(BeatmapSetInfo beatmapSetInfo) { - if (api == null || downloadsList.Find(d => d.BeatmapSet.OnlineBeatmapSetID == beatmapSetInfo.OnlineBeatmapSetID) != null) - return null; + var existing = downloadsList.Find(d => d.BeatmapSet.OnlineBeatmapSetID == beatmapSetInfo.OnlineBeatmapSetID); + + if (existing != null) return existing; + + if (api == null) return null; ProgressNotification downloadNotification = new ProgressNotification { diff --git a/osu.Game/Overlays/Direct/DirectPanel.cs b/osu.Game/Overlays/Direct/DirectPanel.cs index 4bf3442453..66b3ff8bf9 100644 --- a/osu.Game/Overlays/Direct/DirectPanel.cs +++ b/osu.Game/Overlays/Direct/DirectPanel.cs @@ -160,13 +160,17 @@ namespace osu.Game.Overlays.Direct } // we already have an active download running. - if ((DownloadRequest = beatmaps.Download(SetInfo)) == null) + if (beatmaps.GetExistingDownload(SetInfo) != null) { content.MoveToX(-5, 50, Easing.OutSine).Then() .MoveToX(5, 100, Easing.InOutSine).Then() .MoveToX(-5, 100, Easing.InOutSine).Then() .MoveToX(0, 50, Easing.InSine).Then(); + + return; } + + DownloadRequest = beatmaps.Download(SetInfo); } protected override void LoadComplete() diff --git a/osu.Game/Overlays/DirectOverlay.cs b/osu.Game/Overlays/DirectOverlay.cs index 54fda5a38d..9c07e1087f 100644 --- a/osu.Game/Overlays/DirectOverlay.cs +++ b/osu.Game/Overlays/DirectOverlay.cs @@ -176,7 +176,7 @@ namespace osu.Game.Overlays { // if a new map was imported, we should remove it from search results (download completed etc.) panels?.FirstOrDefault(p => p.SetInfo.OnlineBeatmapSetID == set.OnlineBeatmapSetID)?.FadeOut(400).Expire(); - BeatmapSets = BeatmapSets.Where(b => b.OnlineBeatmapSetID != set.OnlineBeatmapSetID); + BeatmapSets = BeatmapSets?.Where(b => b.OnlineBeatmapSetID != set.OnlineBeatmapSetID); } private void updateResultCounts() From d12a5e927a2154449583ad7b9015ade70b30cdeb Mon Sep 17 00:00:00 2001 From: naoey Date: Sat, 9 Sep 2017 11:03:25 +0530 Subject: [PATCH 52/54] Rename property. --- osu.Game/Beatmaps/BeatmapManager.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 472e44f36b..6c3a703c19 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -68,7 +68,7 @@ namespace osu.Game.Beatmaps private readonly APIAccess api; - private readonly List downloadsList; + private readonly List currentDownloads; // ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised) private BeatmapIPCChannel ipc; @@ -100,7 +100,7 @@ namespace osu.Game.Beatmaps if (importHost != null) ipc = new BeatmapIPCChannel(importHost, this); - downloadsList = new List(); + currentDownloads = new List(); } /// @@ -194,7 +194,7 @@ namespace osu.Game.Beatmaps /// A new , or an existing one if a download is already in progress. public DownloadBeatmapSetRequest Download(BeatmapSetInfo beatmapSetInfo) { - var existing = downloadsList.Find(d => d.BeatmapSet.OnlineBeatmapSetID == beatmapSetInfo.OnlineBeatmapSetID); + var existing = currentDownloads.Find(d => d.BeatmapSet.OnlineBeatmapSetID == beatmapSetInfo.OnlineBeatmapSetID); if (existing != null) return existing; @@ -221,25 +221,25 @@ namespace osu.Game.Beatmaps using (var archive = new OszArchiveReader(stream)) Import(archive); - downloadsList.Remove(request); + currentDownloads.Remove(request); }; request.Failure += data => { downloadNotification.State = ProgressNotificationState.Completed; Logger.Error(data, "Failed to get beatmap download information"); - downloadsList.Remove(request); + currentDownloads.Remove(request); }; downloadNotification.CancelRequested += () => { request.Cancel(); - downloadsList.Remove(request); + currentDownloads.Remove(request); downloadNotification.State = ProgressNotificationState.Cancelled; return true; }; - downloadsList.Add(request); + currentDownloads.Add(request); PostNotification?.Invoke(downloadNotification); // don't run in the main api queue as this is a long-running task. @@ -254,7 +254,7 @@ namespace osu.Game.Beatmaps /// /// The whose download request is wanted. /// The object if it exists, or null. - public DownloadBeatmapSetRequest GetExistingDownload(BeatmapSetInfo beatmap) => downloadsList.Find(d => d.BeatmapSet.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID); + public DownloadBeatmapSetRequest GetExistingDownload(BeatmapSetInfo beatmap) => currentDownloads.Find(d => d.BeatmapSet.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID); /// /// Delete a beatmap from the manager. From 0c2bad1de4abce4610b6e4d263b3ef103709b8f6 Mon Sep 17 00:00:00 2001 From: naoey Date: Sat, 9 Sep 2017 12:44:27 +0530 Subject: [PATCH 53/54] Get rid of some properties and todos. --- osu.Game/Beatmaps/BeatmapManager.cs | 7 +-- osu.Game/Overlays/Direct/DirectPanel.cs | 66 ++++++++++++------------- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 6c3a703c19..f58b3505c5 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -68,7 +68,7 @@ namespace osu.Game.Beatmaps private readonly APIAccess api; - private readonly List currentDownloads; + private readonly List currentDownloads = new List(); // ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised) private BeatmapIPCChannel ipc; @@ -99,8 +99,6 @@ namespace osu.Game.Beatmaps if (importHost != null) ipc = new BeatmapIPCChannel(importHost, this); - - currentDownloads = new List(); } /// @@ -194,7 +192,7 @@ namespace osu.Game.Beatmaps /// A new , or an existing one if a download is already in progress. public DownloadBeatmapSetRequest Download(BeatmapSetInfo beatmapSetInfo) { - var existing = currentDownloads.Find(d => d.BeatmapSet.OnlineBeatmapSetID == beatmapSetInfo.OnlineBeatmapSetID); + var existing = GetExistingDownload(beatmapSetInfo); if (existing != null) return existing; @@ -243,7 +241,6 @@ namespace osu.Game.Beatmaps PostNotification?.Invoke(downloadNotification); // don't run in the main api queue as this is a long-running task. - // TODO: ensure the Success/Failure callbacks are being scheduled to the main thread for thread safety. Task.Run(() => request.Perform(api)); return request; diff --git a/osu.Game/Overlays/Direct/DirectPanel.cs b/osu.Game/Overlays/Direct/DirectPanel.cs index 66b3ff8bf9..6f1f581d0b 100644 --- a/osu.Game/Overlays/Direct/DirectPanel.cs +++ b/osu.Game/Overlays/Direct/DirectPanel.cs @@ -38,38 +38,6 @@ namespace osu.Game.Overlays.Direct private BeatmapManager beatmaps; private NotificationOverlay notifications; - private DownloadBeatmapSetRequest downloadRequest; - protected DownloadBeatmapSetRequest DownloadRequest - { - get { return downloadRequest; } - set - { - if (value == null || downloadRequest == value) return; - - downloadRequest = value; - - progressBar.FadeIn(400, Easing.OutQuint); - progressBar.ResizeHeightTo(4, 400, Easing.OutQuint); - - progressBar.Current.Value = 0; - - downloadRequest.Failure += e => - { - progressBar.Current.Value = 0; - progressBar.FadeOut(500); - Logger.Error(e, "Failed to get beatmap download information"); - }; - - downloadRequest.DownloadProgressed += progress => progressBar.Current.Value = progress; - - downloadRequest.Success += data => - { - progressBar.Current.Value = 1; - progressBar.FadeOut(500); - }; - } - } - protected override Container Content => content; protected DirectPanel(BeatmapSetInfo setInfo) @@ -128,7 +96,10 @@ namespace osu.Game.Overlays.Direct } }); - DownloadRequest = beatmaps.GetExistingDownload(SetInfo); + var downloadRequest = beatmaps.GetExistingDownload(SetInfo); + + if (downloadRequest != null) + attachDownload(downloadRequest); } protected override bool OnHover(InputState state) @@ -159,9 +130,9 @@ namespace osu.Game.Overlays.Direct return; } - // we already have an active download running. if (beatmaps.GetExistingDownload(SetInfo) != null) { + // we already have an active download running. content.MoveToX(-5, 50, Easing.OutSine).Then() .MoveToX(5, 100, Easing.InOutSine).Then() .MoveToX(-5, 100, Easing.InOutSine).Then() @@ -170,7 +141,32 @@ namespace osu.Game.Overlays.Direct return; } - DownloadRequest = beatmaps.Download(SetInfo); + var request = beatmaps.Download(SetInfo); + + attachDownload(request); + } + + private void attachDownload(DownloadBeatmapSetRequest request) + { + progressBar.FadeIn(400, Easing.OutQuint); + progressBar.ResizeHeightTo(4, 400, Easing.OutQuint); + + progressBar.Current.Value = 0; + + request.Failure += e => + { + progressBar.Current.Value = 0; + progressBar.FadeOut(500); + Logger.Error(e, "Failed to get beatmap download information"); + }; + + request.DownloadProgressed += progress => progressBar.Current.Value = progress; + + request.Success += data => + { + progressBar.Current.Value = 1; + progressBar.FadeOut(500); + }; } protected override void LoadComplete() From 0a9ca8a1ff89c58f39b171256239be41640ea3e0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 10 Sep 2017 11:53:47 +0900 Subject: [PATCH 54/54] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 4e7ea6af4f..a617245a42 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 4e7ea6af4f59f21f6afc522fb063c05417e1a5fe +Subproject commit a617245a4261d7d6e138c2fddbbeaa7940d24ca7