diff --git a/.gitignore b/.gitignore index 5138e940ed..8f011deabe 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,10 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +### Cake ### +tools/* +!tools/cakebuild.csproj + # Build results bin/[Dd]ebug/ [Dd]ebugPublic/ @@ -98,6 +102,7 @@ $tf/ _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user +inspectcode # JustCode is a .NET coding add-in .JustCode @@ -257,3 +262,5 @@ paket-files/ __pycache__/ *.pyc Staging/ + +inspectcodereport.xml diff --git a/README.md b/README.md index dc36145337..baaba22726 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Build and run - Using Visual Studio 2017, Rider or Visual Studio Code (configurations are included) - From command line using `dotnet run --project osu.Desktop`. When building for non-development purposes, add `-c Release` to gain higher performance. +- To run with code analysis, instead use `powershell ./build.ps1` or `build.sh`. This is currently only supported under windows due to [resharper cli shortcomings](https://youtrack.jetbrains.com/issue/RSRP-410004). Alternative, you can install resharper or use rider to get inline support in your IDE of choice. Note: If you run from command line under linux, you will need to prefix the output folder to your `LD_LIBRARY_PATH`. See `.vscode/launch.json` for an example diff --git a/appveyor.yml b/appveyor.yml index 8c06b42fd2..1f485485da 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,22 +1,8 @@ clone_depth: 1 version: '{branch}-{build}' image: Visual Studio 2017 -configuration: Debug -cache: - - C:\ProgramData\chocolatey\bin -> appveyor.yml - - C:\ProgramData\chocolatey\lib -> appveyor.yml +test: off install: - cmd: git submodule update --init --recursive --depth=5 - - cmd: choco install resharper-clt -y - - cmd: choco install nvika -y - - cmd: dotnet tool install CodeFileSanity --version 0.0.16 --global -before_build: - - cmd: CodeFileSanity - - cmd: nuget restore -verbosity quiet -build: - project: osu.sln - parallel: true - verbosity: minimal -after_build: - - cmd: inspectcode --o="inspectcodereport.xml" --projects:osu.Game* --caches-home="inspectcode" osu.sln > NUL - - cmd: NVika parsereport "inspectcodereport.xml" --treatwarningsaserrors +build_script: + - cmd: PowerShell -Version 2.0 .\build.ps1 diff --git a/build.cake b/build.cake new file mode 100644 index 0000000000..bc7dfafb8c --- /dev/null +++ b/build.cake @@ -0,0 +1,72 @@ +#addin "nuget:?package=CodeFileSanity&version=0.0.21" +#addin "nuget:?package=JetBrains.ReSharper.CommandLineTools&version=2018.2.2" +#tool "nuget:?package=NVika.MSBuild&version=1.0.1" + +/////////////////////////////////////////////////////////////////////////////// +// ARGUMENTS +/////////////////////////////////////////////////////////////////////////////// + +var target = Argument("target", "Build"); +var configuration = Argument("configuration", "Release"); + +var osuSolution = new FilePath("./osu.sln"); + +/////////////////////////////////////////////////////////////////////////////// +// TASKS +/////////////////////////////////////////////////////////////////////////////// + +Task("Restore") + .Does(() => { + DotNetCoreRestore(osuSolution.FullPath); + }); + +Task("Compile") + .IsDependentOn("Restore") + .Does(() => { + DotNetCoreBuild(osuSolution.FullPath, new DotNetCoreBuildSettings { + Configuration = configuration, + NoRestore = true, + }); + }); + +Task("Test") + .IsDependentOn("Compile") + .Does(() => { + var testAssemblies = GetFiles("**/*.Tests/bin/**/*.Tests.dll"); + + DotNetCoreVSTest(testAssemblies, new DotNetCoreVSTestSettings { + Logger = AppVeyor.IsRunningOnAppVeyor ? "Appveyor" : $"trx", + Parallel = true, + ToolTimeout = TimeSpan.FromMinutes(10), + }); + }); + +// windows only because both inspectcore and nvika depend on net45 +Task("InspectCode") + .WithCriteria(IsRunningOnWindows()) + .IsDependentOn("Compile") + .Does(() => { + var nVikaToolPath = GetFiles("./tools/NVika.MSBuild.*/tools/NVika.exe").First(); + + InspectCode(osuSolution, new InspectCodeSettings { + CachesHome = "inspectcode", + OutputFile = "inspectcodereport.xml", + }); + + StartProcess(nVikaToolPath, @"parsereport ""inspectcodereport.xml"" --treatwarningsaserrors"); + }); + +Task("CodeFileSanity") + .Does(() => { + ValidateCodeSanity(new ValidateCodeSanitySettings { + RootDirectory = ".", + IsAppveyorBuild = AppVeyor.IsRunningOnAppVeyor + }); + }); + +Task("Build") + .IsDependentOn("CodeFileSanity") + .IsDependentOn("InspectCode") + .IsDependentOn("Test"); + +RunTarget(target); \ No newline at end of file diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000000..9968673c90 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,79 @@ +########################################################################## +# This is a customized Cake bootstrapper script for PowerShell. +########################################################################## + +<# + +.SYNOPSIS +This is a Powershell script to bootstrap a Cake build. + +.DESCRIPTION +This Powershell script restores NuGet tools (including Cake) +and execute your Cake build script with the parameters you provide. + +.PARAMETER Script +The build script to execute. +.PARAMETER Target +The build script target to run. +.PARAMETER Configuration +The build configuration to use. +.PARAMETER Verbosity +Specifies the amount of information to be displayed. +.PARAMETER ShowDescription +Shows description about tasks. +.PARAMETER DryRun +Performs a dry run. +.PARAMETER ScriptArgs +Remaining arguments are added here. + +.LINK +https://cakebuild.net + +#> + +[CmdletBinding()] +Param( + [string]$Script = "build.cake", + [string]$Target, + [string]$Configuration, + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity, + [switch]$ShowDescription, + [Alias("WhatIf", "Noop")] + [switch]$DryRun, + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$ScriptArgs +) + +Write-Host "Preparing to run build script..." + +# Determine the script root for resolving other paths. +if(!$PSScriptRoot){ + $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent +} + +# Resolve the paths for resources used for debugging. +$TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$CAKE_CSPROJ = Join-Path $TOOLS_DIR "cakebuild.csproj" + +# Install the required tools locally. +Write-Host "Restoring cake tools..." +Invoke-Expression "dotnet restore `"$CAKE_CSPROJ`" --packages `"$TOOLS_DIR`"" | Out-Null + +# Find the Cake executable +$CAKE_EXECUTABLE = (Get-ChildItem -Path ./tools/cake.coreclr/ -Filter Cake.dll -Recurse).FullName + +# Build Cake arguments +$cakeArguments = @("$Script"); +if ($Target) { $cakeArguments += "-target=$Target" } +if ($Configuration) { $cakeArguments += "-configuration=$Configuration" } +if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" } +if ($ShowDescription) { $cakeArguments += "-showdescription" } +if ($DryRun) { $cakeArguments += "-dryrun" } +if ($Experimental) { $cakeArguments += "-experimental" } +$cakeArguments += $ScriptArgs + +# Start Cake +Write-Host "Running build script..." +Invoke-Expression "dotnet `"$CAKE_EXECUTABLE`" $cakeArguments" +exit $LASTEXITCODE diff --git a/build.sh b/build.sh new file mode 100644 index 0000000000..caf1702f41 --- /dev/null +++ b/build.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +########################################################################## +# This is a customized Cake bootstrapper script for Shell. +########################################################################## + +echo "Preparing to run build script..." + +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +TOOLS_DIR=$SCRIPT_DIR/tools +CAKE_BINARY_PATH=$TOOLS_DIR/"cake.coreclr" + +SCRIPT="build.cake" +CAKE_CSPROJ=$TOOLS_DIR/"cakebuild.csproj" + +# Parse arguments. +CAKE_ARGUMENTS=() +for i in "$@"; do + case $1 in + -s|--script) SCRIPT="$2"; shift ;; + --) shift; CAKE_ARGUMENTS+=("$@"); break ;; + *) CAKE_ARGUMENTS+=("$1") ;; + esac + shift +done + +# Install the required tools locally. +echo "Restoring cake tools..." +dotnet restore $CAKE_CSPROJ --packages $TOOLS_DIR > /dev/null 2>&1 + +# Search for the CakeBuild binary. +CAKE_BINARY=$(find $CAKE_BINARY_PATH -name "Cake.dll") + +# Start Cake +echo "Running build script..." + +dotnet "$CAKE_BINARY" $SCRIPT "${CAKE_ARGUMENTS[@]}" diff --git a/cake.config b/cake.config new file mode 100644 index 0000000000..187d825591 --- /dev/null +++ b/cake.config @@ -0,0 +1,5 @@ + +[Nuget] +Source=https://api.nuget.org/v3/index.json +UseInProcessClient=true +LoadDependencies=true diff --git a/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs b/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs index bd0fec43a1..94233bc9f0 100644 --- a/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs +++ b/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs @@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Catch.UI public override PassThroughInputManager CreateInputManager() => new CatchInputManager(Ruleset.RulesetInfo); - protected override DrawableHitObject GetVisualRepresentation(CatchHitObject h) + public override DrawableHitObject GetVisualRepresentation(CatchHitObject h) { switch (h) { diff --git a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs index f37d8134ce..fcacde769b 100644 --- a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs +++ b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs @@ -1,22 +1,23 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using osu.Game.Beatmaps; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Tools; -using osu.Game.Rulesets.Mania.Edit.Layers.Selection.Overlays; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables; -using osu.Game.Rulesets.UI; using System.Collections.Generic; using osu.Framework.Allocation; using osu.Game.Rulesets.Mania.Configuration; +using osu.Game.Rulesets.Mania.Edit.Masks; using osu.Game.Rulesets.Mania.UI; +using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Mania.Edit { - public class ManiaHitObjectComposer : HitObjectComposer + public class ManiaHitObjectComposer : HitObjectComposer { protected new ManiaConfigManager Config => (ManiaConfigManager)base.Config; @@ -32,22 +33,19 @@ namespace osu.Game.Rulesets.Mania.Edit return dependencies; } - protected override RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => new ManiaEditRulesetContainer(ruleset, beatmap); + protected override RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) + => new ManiaEditRulesetContainer(ruleset, beatmap); - protected override IReadOnlyList CompositionTools => new ICompositionTool[] - { - new HitObjectCompositionTool("Note"), - new HitObjectCompositionTool("Hold"), - }; + protected override IReadOnlyList CompositionTools => Array.Empty(); - public override HitObjectMask CreateMaskFor(DrawableHitObject hitObject) + public override SelectionMask CreateMaskFor(DrawableHitObject hitObject) { switch (hitObject) { case DrawableNote note: - return new NoteMask(note); + return new NoteSelectionMask(note); case DrawableHoldNote holdNote: - return new HoldNoteMask(holdNote); + return new HoldNoteSelectionMask(holdNote); } return base.CreateMaskFor(hitObject); diff --git a/osu.Game.Rulesets.Mania/Edit/Layers/Selection/Overlays/HoldNoteMask.cs b/osu.Game.Rulesets.Mania/Edit/Masks/HoldNoteSelectionMask.cs similarity index 86% rename from osu.Game.Rulesets.Mania/Edit/Layers/Selection/Overlays/HoldNoteMask.cs rename to osu.Game.Rulesets.Mania/Edit/Masks/HoldNoteSelectionMask.cs index 03d2ba19cb..a2c01d7a0e 100644 --- a/osu.Game.Rulesets.Mania/Edit/Layers/Selection/Overlays/HoldNoteMask.cs +++ b/osu.Game.Rulesets.Mania/Edit/Masks/HoldNoteSelectionMask.cs @@ -13,9 +13,9 @@ using osu.Game.Rulesets.UI.Scrolling; using OpenTK; using OpenTK.Graphics; -namespace osu.Game.Rulesets.Mania.Edit.Layers.Selection.Overlays +namespace osu.Game.Rulesets.Mania.Edit.Masks { - public class HoldNoteMask : HitObjectMask + public class HoldNoteSelectionMask : SelectionMask { public new DrawableHoldNote HitObject => (DrawableHoldNote)base.HitObject; @@ -23,13 +23,13 @@ namespace osu.Game.Rulesets.Mania.Edit.Layers.Selection.Overlays private readonly BodyPiece body; - public HoldNoteMask(DrawableHoldNote hold) + public HoldNoteSelectionMask(DrawableHoldNote hold) : base(hold) { InternalChildren = new Drawable[] { - new HoldNoteNoteMask(hold.Head), - new HoldNoteNoteMask(hold.Tail), + new HoldNoteNoteSelectionMask(hold.Head), + new HoldNoteNoteSelectionMask(hold.Tail), body = new BodyPiece { AccentColour = Color4.Transparent @@ -59,9 +59,9 @@ namespace osu.Game.Rulesets.Mania.Edit.Layers.Selection.Overlays Y -= HitObject.Tail.DrawHeight; } - private class HoldNoteNoteMask : NoteMask + private class HoldNoteNoteSelectionMask : NoteSelectionMask { - public HoldNoteNoteMask(DrawableNote note) + public HoldNoteNoteSelectionMask(DrawableNote note) : base(note) { Select(); diff --git a/osu.Game.Rulesets.Mania/Edit/Layers/Selection/Overlays/NoteMask.cs b/osu.Game.Rulesets.Mania/Edit/Masks/NoteSelectionMask.cs similarity index 85% rename from osu.Game.Rulesets.Mania/Edit/Layers/Selection/Overlays/NoteMask.cs rename to osu.Game.Rulesets.Mania/Edit/Masks/NoteSelectionMask.cs index 78f876cb14..18f042a483 100644 --- a/osu.Game.Rulesets.Mania/Edit/Layers/Selection/Overlays/NoteMask.cs +++ b/osu.Game.Rulesets.Mania/Edit/Masks/NoteSelectionMask.cs @@ -7,11 +7,11 @@ using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces; -namespace osu.Game.Rulesets.Mania.Edit.Layers.Selection.Overlays +namespace osu.Game.Rulesets.Mania.Edit.Masks { - public class NoteMask : HitObjectMask + public class NoteSelectionMask : SelectionMask { - public NoteMask(DrawableNote note) + public NoteSelectionMask(DrawableNote note) : base(note) { Scale = note.Scale; diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModDualStages.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModDualStages.cs index aecfb50fbe..4790a77cc0 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModDualStages.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModDualStages.cs @@ -5,13 +5,11 @@ using System.Collections.Generic; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Mania.Objects; -using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mods; -using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Mania.Mods { - public class ManiaModDualStages : Mod, IPlayfieldTypeMod, IApplicableToBeatmapConverter, IApplicableToRulesetContainer + public class ManiaModDualStages : Mod, IPlayfieldTypeMod, IApplicableToBeatmapConverter, IApplicableToBeatmap { public override string Name => "Dual Stages"; public override string ShortenedName => "DS"; @@ -34,22 +32,21 @@ namespace osu.Game.Rulesets.Mania.Mods mbc.TargetColumns *= 2; } - public void ApplyToRulesetContainer(RulesetContainer rulesetContainer) + public void ApplyToBeatmap(Beatmap beatmap) { - var mrc = (ManiaRulesetContainer)rulesetContainer; - - // Although this can work, for now let's not allow keymods for mania-specific beatmaps if (isForCurrentRuleset) return; + var maniaBeatmap = (ManiaBeatmap)beatmap; + var newDefinitions = new List(); - foreach (var existing in mrc.Beatmap.Stages) + foreach (var existing in maniaBeatmap.Stages) { newDefinitions.Add(new StageDefinition { Columns = existing.Columns / 2 }); newDefinitions.Add(new StageDefinition { Columns = existing.Columns / 2 }); } - mrc.Beatmap.Stages = newDefinitions; + maniaBeatmap.Stages = newDefinitions; } public PlayfieldType PlayfieldType => PlayfieldType.Dual; diff --git a/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs index 49874f6dc1..500fb5a631 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs @@ -96,7 +96,7 @@ namespace osu.Game.Rulesets.Mania.UI public override PassThroughInputManager CreateInputManager() => new ManiaInputManager(Ruleset.RulesetInfo, Variant); - protected override DrawableHitObject GetVisualRepresentation(ManiaHitObject h) + public override DrawableHitObject GetVisualRepresentation(ManiaHitObject h) { switch (h) { diff --git a/osu.Game.Rulesets.Osu.Tests/TestCaseHitCirclePlacementMask.cs b/osu.Game.Rulesets.Osu.Tests/TestCaseHitCirclePlacementMask.cs new file mode 100644 index 0000000000..be0b94c4c8 --- /dev/null +++ b/osu.Game.Rulesets.Osu.Tests/TestCaseHitCirclePlacementMask.cs @@ -0,0 +1,19 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Osu.Edit.Masks.HitCircleMasks; +using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Rulesets.Osu.Objects.Drawables; +using osu.Game.Tests.Visual; + +namespace osu.Game.Rulesets.Osu.Tests +{ + public class TestCaseHitCirclePlacementMask : HitObjectPlacementMaskTestCase + { + protected override DrawableHitObject CreateHitObject(HitObject hitObject) => new DrawableHitCircle((HitCircle)hitObject); + protected override PlacementMask CreateMask() => new HitCirclePlacementMask(); + } +} diff --git a/osu.Game.Rulesets.Osu.Tests/TestCaseHitCircleSelectionMask.cs b/osu.Game.Rulesets.Osu.Tests/TestCaseHitCircleSelectionMask.cs new file mode 100644 index 0000000000..e3d61623bf --- /dev/null +++ b/osu.Game.Rulesets.Osu.Tests/TestCaseHitCircleSelectionMask.cs @@ -0,0 +1,29 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.ControlPoints; +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Osu.Edit.Masks.HitCircleMasks; +using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Rulesets.Osu.Objects.Drawables; +using osu.Game.Tests.Visual; +using OpenTK; + +namespace osu.Game.Rulesets.Osu.Tests +{ + public class TestCaseHitCircleSelectionMask : HitObjectSelectionMaskTestCase + { + private readonly DrawableHitCircle drawableObject; + + public TestCaseHitCircleSelectionMask() + { + var hitCircle = new HitCircle { Position = new Vector2(256, 192) }; + hitCircle.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = 2 }); + + Add(drawableObject = new DrawableHitCircle(hitCircle)); + } + + protected override SelectionMask CreateMask() => new HitCircleSelectionMask(drawableObject); + } +} diff --git a/osu.Game.Rulesets.Osu.Tests/TestCaseSliderSelectionMask.cs b/osu.Game.Rulesets.Osu.Tests/TestCaseSliderSelectionMask.cs new file mode 100644 index 0000000000..5e68d5cdc9 --- /dev/null +++ b/osu.Game.Rulesets.Osu.Tests/TestCaseSliderSelectionMask.cs @@ -0,0 +1,42 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.ControlPoints; +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Objects.Types; +using osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks; +using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Rulesets.Osu.Objects.Drawables; +using osu.Game.Tests.Visual; +using OpenTK; + +namespace osu.Game.Rulesets.Osu.Tests +{ + public class TestCaseSliderSelectionMask : HitObjectSelectionMaskTestCase + { + private readonly DrawableSlider drawableObject; + + public TestCaseSliderSelectionMask() + { + var slider = new Slider + { + Position = new Vector2(256, 192), + ControlPoints = new[] + { + Vector2.Zero, + new Vector2(150, 150), + new Vector2(300, 0) + }, + CurveType = CurveType.Bezier, + Distance = 350 + }; + + slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = 2 }); + + Add(drawableObject = new DrawableSlider(slider)); + } + + protected override SelectionMask CreateMask() => new SliderSelectionMask(drawableObject); + } +} diff --git a/osu.Game.Rulesets.Osu/Beatmaps/OsuBeatmapConverter.cs b/osu.Game.Rulesets.Osu/Beatmaps/OsuBeatmapConverter.cs index 9e0e649eb2..b2914d4b82 100644 --- a/osu.Game.Rulesets.Osu/Beatmaps/OsuBeatmapConverter.cs +++ b/osu.Game.Rulesets.Osu/Beatmaps/OsuBeatmapConverter.cs @@ -43,7 +43,10 @@ namespace osu.Game.Rulesets.Osu.Beatmaps Position = positionData?.Position ?? Vector2.Zero, NewCombo = comboData?.NewCombo ?? false, ComboOffset = comboData?.ComboOffset ?? 0, - LegacyLastTickOffset = legacyOffset?.LegacyLastTickOffset + LegacyLastTickOffset = legacyOffset?.LegacyLastTickOffset, + // prior to v8, speed multipliers don't adjust for how many ticks are generated over the same distance. + // this results in more (or less) ticks being generated in . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Edit.Tools; +using osu.Game.Rulesets.Osu.Edit.Masks.HitCircleMasks; +using osu.Game.Rulesets.Osu.Objects; + +namespace osu.Game.Rulesets.Osu.Edit +{ + public class HitCircleCompositionTool : HitObjectCompositionTool + { + public HitCircleCompositionTool() + : base(nameof(HitCircle)) + { + } + + public override PlacementMask CreatePlacementMask() => new HitCirclePlacementMask(); + } +} diff --git a/osu.Game.Rulesets.Osu/Edit/Layers/Selection/Overlays/HitCircleMask.cs b/osu.Game.Rulesets.Osu/Edit/Layers/Selection/Overlays/HitCircleMask.cs deleted file mode 100644 index a2aa639004..0000000000 --- a/osu.Game.Rulesets.Osu/Edit/Layers/Selection/Overlays/HitCircleMask.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework.Graphics; -using osu.Framework.Allocation; -using osu.Game.Graphics; -using osu.Game.Rulesets.Edit; -using osu.Game.Rulesets.Osu.Objects.Drawables; -using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces; - -namespace osu.Game.Rulesets.Osu.Edit.Layers.Selection.Overlays -{ - public class HitCircleMask : HitObjectMask - { - public HitCircleMask(DrawableHitCircle hitCircle) - : base(hitCircle) - { - Origin = Anchor.Centre; - - Position = hitCircle.Position; - Size = hitCircle.Size; - Scale = hitCircle.Scale; - - CornerRadius = Size.X / 2; - - AddInternal(new RingPiece()); - - hitCircle.HitObject.PositionChanged += _ => Position = hitCircle.Position; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - Colour = colours.Yellow; - } - } -} diff --git a/osu.Game.Rulesets.Osu/Edit/Layers/Selection/Overlays/SliderCircleMask.cs b/osu.Game.Rulesets.Osu/Edit/Layers/Selection/Overlays/SliderCircleMask.cs deleted file mode 100644 index 151564a2a8..0000000000 --- a/osu.Game.Rulesets.Osu/Edit/Layers/Selection/Overlays/SliderCircleMask.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2007-2018 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.Game.Graphics; -using osu.Game.Rulesets.Edit; -using osu.Game.Rulesets.Osu.Objects; -using osu.Game.Rulesets.Osu.Objects.Drawables; -using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces; -using OpenTK; - -namespace osu.Game.Rulesets.Osu.Edit.Layers.Selection.Overlays -{ - public class SliderCircleMask : HitObjectMask - { - public SliderCircleMask(DrawableHitCircle sliderHead, DrawableSlider slider) - : this(sliderHead, Vector2.Zero, slider) - { - } - - public SliderCircleMask(DrawableSliderTail sliderTail, DrawableSlider slider) - : this(sliderTail, ((Slider)slider.HitObject).Curve.PositionAt(1), slider) - { - } - - private readonly DrawableOsuHitObject hitObject; - - private SliderCircleMask(DrawableOsuHitObject hitObject, Vector2 position, DrawableSlider slider) - : base(hitObject) - { - this.hitObject = hitObject; - - Origin = Anchor.Centre; - - Position = position; - Size = slider.HeadCircle.Size; - Scale = slider.HeadCircle.Scale; - - AddInternal(new RingPiece()); - - Select(); - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - Colour = colours.Yellow; - } - - protected override void Update() - { - base.Update(); - - RelativeAnchorPosition = hitObject.RelativeAnchorPosition; - } - - // Todo: This is temporary, since the slider circle masks don't do anything special yet. In the future they will handle input. - public override bool HandlePositionalInput => false; - } -} diff --git a/osu.Game.Rulesets.Osu/Edit/Layers/Selection/Overlays/SliderMask.cs b/osu.Game.Rulesets.Osu/Edit/Layers/Selection/Overlays/SliderMask.cs deleted file mode 100644 index aff42dd233..0000000000 --- a/osu.Game.Rulesets.Osu/Edit/Layers/Selection/Overlays/SliderMask.cs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2007-2018 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.Primitives; -using osu.Game.Graphics; -using osu.Game.Rulesets.Edit; -using osu.Game.Rulesets.Osu.Objects; -using osu.Game.Rulesets.Osu.Objects.Drawables; -using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces; -using OpenTK; -using OpenTK.Graphics; - -namespace osu.Game.Rulesets.Osu.Edit.Layers.Selection.Overlays -{ - public class SliderMask : HitObjectMask - { - private readonly SliderBody body; - private readonly DrawableSlider slider; - - public SliderMask(DrawableSlider slider) - : base(slider) - { - this.slider = slider; - - Position = slider.Position; - - var sliderObject = (Slider)slider.HitObject; - - InternalChildren = new Drawable[] - { - body = new SliderBody(sliderObject) - { - AccentColour = Color4.Transparent, - PathWidth = sliderObject.Scale * 64 - }, - new SliderCircleMask(slider.HeadCircle, slider), - new SliderCircleMask(slider.TailCircle, slider), - }; - - sliderObject.PositionChanged += _ => Position = slider.Position; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - body.BorderColour = colours.Yellow; - } - - protected override void Update() - { - base.Update(); - - Size = slider.Size; - OriginPosition = slider.OriginPosition; - - // Need to cause one update - body.UpdateProgress(0); - } - - public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => body.ReceivePositionalInputAt(screenSpacePos); - - public override Vector2 SelectionPoint => ToScreenSpace(OriginPosition); - public override Quad SelectionQuad => body.PathDrawQuad; - } -} diff --git a/osu.Game.Rulesets.Osu/Edit/Masks/HitCircleMasks/Components/HitCirclePiece.cs b/osu.Game.Rulesets.Osu/Edit/Masks/HitCircleMasks/Components/HitCirclePiece.cs new file mode 100644 index 0000000000..c11ae096a7 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Edit/Masks/HitCircleMasks/Components/HitCirclePiece.cs @@ -0,0 +1,44 @@ +// Copyright (c) 2007-2018 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.Game.Graphics; +using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces; +using OpenTK; + +namespace osu.Game.Rulesets.Osu.Edit.Masks.HitCircleMasks.Components +{ + public class HitCirclePiece : CompositeDrawable + { + private readonly HitCircle hitCircle; + + public HitCirclePiece(HitCircle hitCircle) + { + this.hitCircle = hitCircle; + Origin = Anchor.Centre; + + Size = new Vector2((float)OsuHitObject.OBJECT_RADIUS * 2); + Scale = new Vector2(hitCircle.Scale); + CornerRadius = Size.X / 2; + + InternalChild = new RingPiece(); + + hitCircle.PositionChanged += _ => UpdatePosition(); + hitCircle.StackHeightChanged += _ => UpdatePosition(); + hitCircle.ScaleChanged += _ => Scale = new Vector2(hitCircle.Scale); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + Colour = colours.Yellow; + + UpdatePosition(); + } + + protected virtual void UpdatePosition() => Position = hitCircle.StackedPosition; + } +} diff --git a/osu.Game.Rulesets.Osu/Edit/Masks/HitCircleMasks/HitCirclePlacementMask.cs b/osu.Game.Rulesets.Osu/Edit/Masks/HitCircleMasks/HitCirclePlacementMask.cs new file mode 100644 index 0000000000..0d0acbed7d --- /dev/null +++ b/osu.Game.Rulesets.Osu/Edit/Masks/HitCircleMasks/HitCirclePlacementMask.cs @@ -0,0 +1,42 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Input.Events; +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Osu.Edit.Masks.HitCircleMasks.Components; +using osu.Game.Rulesets.Osu.Objects; + +namespace osu.Game.Rulesets.Osu.Edit.Masks.HitCircleMasks +{ + public class HitCirclePlacementMask : PlacementMask + { + public new HitCircle HitObject => (HitCircle)base.HitObject; + + public HitCirclePlacementMask() + : base(new HitCircle()) + { + InternalChild = new HitCirclePiece(HitObject); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + // Fixes a 1-frame position discrpancy due to the first mouse move event happening in the next frame + HitObject.Position = GetContainingInputManager().CurrentState.Mouse.Position; + } + + protected override bool OnClick(ClickEvent e) + { + HitObject.StartTime = EditorClock.CurrentTime; + EndPlacement(); + return true; + } + + protected override bool OnMouseMove(MouseMoveEvent e) + { + HitObject.Position = e.MousePosition; + return true; + } + } +} diff --git a/osu.Game.Rulesets.Osu/Edit/Masks/HitCircleMasks/HitCircleSelectionMask.cs b/osu.Game.Rulesets.Osu/Edit/Masks/HitCircleMasks/HitCircleSelectionMask.cs new file mode 100644 index 0000000000..da46da92a5 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Edit/Masks/HitCircleMasks/HitCircleSelectionMask.cs @@ -0,0 +1,19 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Osu.Edit.Masks.HitCircleMasks.Components; +using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Rulesets.Osu.Objects.Drawables; + +namespace osu.Game.Rulesets.Osu.Edit.Masks.HitCircleMasks +{ + public class HitCircleSelectionMask : SelectionMask + { + public HitCircleSelectionMask(DrawableHitCircle hitCircle) + : base(hitCircle) + { + InternalChild = new HitCirclePiece((HitCircle)hitCircle.HitObject); + } + } +} diff --git a/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/Components/SliderBodyPiece.cs b/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/Components/SliderBodyPiece.cs new file mode 100644 index 0000000000..3123a4fcea --- /dev/null +++ b/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/Components/SliderBodyPiece.cs @@ -0,0 +1,51 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Graphics.Containers; +using osu.Game.Graphics; +using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces; +using OpenTK.Graphics; + +namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks.Components +{ + public class SliderBodyPiece : CompositeDrawable + { + private readonly Slider slider; + private readonly SnakingSliderBody body; + + public SliderBodyPiece(Slider slider) + { + this.slider = slider; + InternalChild = body = new SnakingSliderBody(slider) + { + AccentColour = Color4.Transparent, + PathWidth = slider.Scale * 64 + }; + + slider.PositionChanged += _ => updatePosition(); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + body.BorderColour = colours.Yellow; + + updatePosition(); + } + + private void updatePosition() => Position = slider.StackedPosition; + + protected override void Update() + { + base.Update(); + + Size = body.Size; + OriginPosition = body.PathOffset; + + // Need to cause one update + body.UpdateProgress(0); + } + } +} diff --git a/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/Components/SliderCirclePiece.cs b/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/Components/SliderCirclePiece.cs new file mode 100644 index 0000000000..c5ecde5c4c --- /dev/null +++ b/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/Components/SliderCirclePiece.cs @@ -0,0 +1,34 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Osu.Edit.Masks.HitCircleMasks.Components; +using osu.Game.Rulesets.Osu.Objects; + +namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks.Components +{ + public class SliderCirclePiece : HitCirclePiece + { + private readonly Slider slider; + private readonly SliderPosition position; + + public SliderCirclePiece(Slider slider, SliderPosition position) + : base(slider.HeadCircle) + { + this.slider = slider; + this.position = position; + } + + protected override void UpdatePosition() + { + switch (position) + { + case SliderPosition.Start: + Position = slider.StackedPosition + slider.Curve.PositionAt(0); + break; + case SliderPosition.End: + Position = slider.StackedPosition + slider.Curve.PositionAt(1); + break; + } + } + } +} diff --git a/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/SliderCircleSelectionMask.cs b/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/SliderCircleSelectionMask.cs new file mode 100644 index 0000000000..a1b3fd545c --- /dev/null +++ b/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/SliderCircleSelectionMask.cs @@ -0,0 +1,24 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks.Components; +using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Rulesets.Osu.Objects.Drawables; + +namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks +{ + public class SliderCircleSelectionMask : SelectionMask + { + public SliderCircleSelectionMask(DrawableOsuHitObject hitObject, Slider slider, SliderPosition position) + : base(hitObject) + { + InternalChild = new SliderCirclePiece(slider, position); + + Select(); + } + + // Todo: This is temporary, since the slider circle masks don't do anything special yet. In the future they will handle input. + public override bool HandlePositionalInput => false; + } +} diff --git a/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/SliderPosition.cs b/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/SliderPosition.cs new file mode 100644 index 0000000000..01c1871131 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/SliderPosition.cs @@ -0,0 +1,11 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks +{ + public enum SliderPosition + { + Start, + End + } +} diff --git a/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/SliderSelectionMask.cs b/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/SliderSelectionMask.cs new file mode 100644 index 0000000000..a411064f68 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Edit/Masks/SliderMasks/SliderSelectionMask.cs @@ -0,0 +1,32 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks.Components; +using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Rulesets.Osu.Objects.Drawables; +using OpenTK; + +namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks +{ + public class SliderSelectionMask : SelectionMask + { + private readonly SliderCircleSelectionMask headMask; + + public SliderSelectionMask(DrawableSlider slider) + : base(slider) + { + var sliderObject = (Slider)slider.HitObject; + + InternalChildren = new Drawable[] + { + new SliderBodyPiece(sliderObject), + headMask = new SliderCircleSelectionMask(slider.HeadCircle, sliderObject, SliderPosition.Start), + new SliderCircleSelectionMask(slider.TailCircle, sliderObject, SliderPosition.End), + }; + } + + public override Vector2 SelectionPoint => headMask.SelectionPoint; + } +} diff --git a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs index d6972d55d2..ac41d6ef27 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs @@ -8,7 +8,8 @@ using osu.Game.Beatmaps; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Tools; using osu.Game.Rulesets.Objects.Drawables; -using osu.Game.Rulesets.Osu.Edit.Layers.Selection.Overlays; +using osu.Game.Rulesets.Osu.Edit.Masks.HitCircleMasks; +using osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.UI; @@ -16,32 +17,31 @@ using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Osu.Edit { - public class OsuHitObjectComposer : HitObjectComposer + public class OsuHitObjectComposer : HitObjectComposer { public OsuHitObjectComposer(Ruleset ruleset) : base(ruleset) { } - protected override RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => new OsuEditRulesetContainer(ruleset, beatmap); + protected override RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) + => new OsuEditRulesetContainer(ruleset, beatmap); - protected override IReadOnlyList CompositionTools => new ICompositionTool[] + protected override IReadOnlyList CompositionTools => new[] { - new HitObjectCompositionTool(), - new HitObjectCompositionTool(), - new HitObjectCompositionTool() + new HitCircleCompositionTool(), }; protected override Container CreateLayerContainer() => new PlayfieldAdjustmentContainer { RelativeSizeAxes = Axes.Both }; - public override HitObjectMask CreateMaskFor(DrawableHitObject hitObject) + public override SelectionMask CreateMaskFor(DrawableHitObject hitObject) { switch (hitObject) { case DrawableHitCircle circle: - return new HitCircleMask(circle); + return new HitCircleSelectionMask(circle); case DrawableSlider slider: - return new SliderMask(slider); + return new SliderSelectionMask(slider); } return base.CreateMaskFor(hitObject); diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableHitCircle.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableHitCircle.cs index 4bdddcef11..e663989eeb 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableHitCircle.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableHitCircle.cs @@ -61,6 +61,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables Size = circle.DrawSize; HitObject.PositionChanged += _ => Position = HitObject.StackedPosition; + HitObject.StackHeightChanged += _ => Position = HitObject.StackedPosition; + HitObject.ScaleChanged += s => Scale = new Vector2(s); } public override Color4 AccentColour diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs index 89f380db4e..16bd522c1d 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs @@ -23,7 +23,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables public readonly DrawableHitCircle HeadCircle; public readonly DrawableSliderTail TailCircle; - public readonly SliderBody Body; + public readonly SnakingSliderBody Body; public readonly SliderBall Ball; public DrawableSlider(Slider s) @@ -38,7 +38,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables InternalChildren = new Drawable[] { - Body = new SliderBody(s) + Body = new SnakingSliderBody(s) { PathWidth = s.Scale * 64, }, diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ManualSliderBody.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ManualSliderBody.cs new file mode 100644 index 0000000000..9d239c15f2 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ManualSliderBody.cs @@ -0,0 +1,20 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; +using OpenTK; + +namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces +{ + /// + /// A with the ability to set the drawn vertices manually. + /// + public class ManualSliderBody : SliderBody + { + public new void SetVertices(IReadOnlyList vertices) + { + base.SetVertices(vertices); + Size = Path.Size; + } + } +} diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/NumberPiece.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/NumberPiece.cs index 30140484de..acb3ee92ff 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/NumberPiece.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/NumberPiece.cs @@ -4,7 +4,6 @@ using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; using osu.Game.Graphics.Sprites; using OpenTK.Graphics; using osu.Framework.Graphics.Shapes; @@ -14,7 +13,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces { public class NumberPiece : Container { - private readonly SpriteText number; + private readonly SkinnableSpriteText number; public string Text { @@ -41,15 +40,14 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces }, Child = new Box() }, s => s.GetTexture("Play/osu/hitcircle") == null), - number = new OsuSpriteText + number = new SkinnableSpriteText("Play/osu/number-text", _ => new OsuSpriteText { - Text = @"1", Font = @"Venera", UseFullGlyphHeight = false, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, TextSize = 40, - Alpha = 1 + }, restrictSize: false) + { + Text = @"1" } }; } diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBody.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBody.cs index f4ccf673e9..ca2daa3adb 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBody.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBody.cs @@ -1,24 +1,22 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . +// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using System.Collections.Generic; -using osu.Framework.Allocation; -using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Lines; -using OpenTK.Graphics.ES30; -using OpenTK.Graphics; using osu.Framework.Graphics.Primitives; -using osu.Game.Rulesets.Objects.Types; using OpenTK; +using OpenTK.Graphics; +using OpenTK.Graphics.ES30; namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces { - public class SliderBody : Container, ISliderProgress + public abstract class SliderBody : CompositeDrawable { private readonly SliderPath path; + protected Path Path => path; + private readonly BufferedContainer container; public float PathWidth @@ -30,15 +28,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces /// /// Offset in absolute coordinates from the start of the curve. /// - public Vector2 PathOffset { get; private set; } - - public readonly List CurrentCurve = new List(); - - public readonly Bindable SnakingIn = new Bindable(); - public readonly Bindable SnakingOut = new Bindable(); - - public double? SnakedStart { get; private set; } - public double? SnakedEnd { get; private set; } + public virtual Vector2 PathOffset => path.PositionInBoundingBox(path.Vertices[0]); /// /// Used to colour the path. @@ -74,28 +64,13 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces public Quad PathDrawQuad => container.ScreenSpaceDrawQuad; - private Vector2 topLeftOffset; - - private readonly Slider slider; - - public SliderBody(Slider s) + protected SliderBody() { - slider = s; - - Children = new Drawable[] + InternalChild = container = new BufferedContainer { - container = new BufferedContainer - { - RelativeSizeAxes = Axes.Both, - CacheDrawnFrameBuffer = true, - Children = new Drawable[] - { - path = new SliderPath - { - Blending = BlendingMode.None, - }, - } - }, + RelativeSizeAxes = Axes.Both, + CacheDrawnFrameBuffer = true, + Child = path = new SliderPath { Blending = BlendingMode.None } }; container.Attach(RenderbufferInternalFormat.DepthComponent16); @@ -103,80 +78,14 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => path.ReceivePositionalInputAt(screenSpacePos); - public void SetRange(double p0, double p1) + /// + /// Sets the vertices of the path which should be drawn by this . + /// + /// The vertices + protected void SetVertices(IReadOnlyList vertices) { - if (p0 > p1) - MathHelper.Swap(ref p0, ref p1); - - if (updateSnaking(p0, p1)) - { - // The path is generated such that its size encloses it. This change of size causes the path - // to move around while snaking, so we need to offset it to make sure it maintains the - // same position as when it is fully snaked. - var newTopLeftOffset = path.PositionInBoundingBox(Vector2.Zero); - path.Position = topLeftOffset - newTopLeftOffset; - - container.ForceRedraw(); - } - } - - [BackgroundDependencyLoader] - private void load() - { - computeSize(); - } - - private void computeSize() - { - // Generate the entire curve - slider.Curve.GetPathToProgress(CurrentCurve, 0, 1); - foreach (Vector2 p in CurrentCurve) - path.AddVertex(p); - - Size = path.Size; - - topLeftOffset = path.PositionInBoundingBox(Vector2.Zero); - PathOffset = path.PositionInBoundingBox(CurrentCurve[0]); - } - - private bool updateSnaking(double p0, double p1) - { - if (SnakedStart == p0 && SnakedEnd == p1) return false; - - SnakedStart = p0; - SnakedEnd = p1; - - slider.Curve.GetPathToProgress(CurrentCurve, p0, p1); - - path.ClearVertices(); - foreach (Vector2 p in CurrentCurve) - path.AddVertex(p); - - return true; - } - - public void UpdateProgress(double completionProgress) - { - var span = slider.SpanAt(completionProgress); - var spanProgress = slider.ProgressAt(completionProgress); - - double start = 0; - double end = SnakingIn ? MathHelper.Clamp((Time.Current - (slider.StartTime - slider.TimePreempt)) / slider.TimeFadeIn, 0, 1) : 1; - - if (span >= slider.SpanCount() - 1) - { - if (Math.Min(span, slider.SpanCount() - 1) % 2 == 1) - { - start = 0; - end = SnakingOut ? spanProgress : 1; - } - else - { - start = SnakingOut ? spanProgress : 0; - } - } - - SetRange(start, end); + path.Vertices = vertices; + container.ForceRedraw(); } private class SliderPath : SmoothPath diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SnakingSliderBody.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SnakingSliderBody.cs new file mode 100644 index 0000000000..09d6f9459a --- /dev/null +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SnakingSliderBody.cs @@ -0,0 +1,105 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Game.Rulesets.Objects.Types; +using OpenTK; + +namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces +{ + /// + /// A which changes its curve depending on the snaking progress. + /// + public class SnakingSliderBody : SliderBody, ISliderProgress + { + public readonly List CurrentCurve = new List(); + + public readonly Bindable SnakingIn = new Bindable(); + public readonly Bindable SnakingOut = new Bindable(); + + public double? SnakedStart { get; private set; } + public double? SnakedEnd { get; private set; } + + public override Vector2 PathOffset => snakedPathOffset; + + /// + /// The top-left position of the path when fully snaked. + /// + private Vector2 snakedPosition; + + /// + /// The offset of the path from when fully snaked. + /// + private Vector2 snakedPathOffset; + + private readonly Slider slider; + + public SnakingSliderBody(Slider slider) + { + this.slider = slider; + } + + [BackgroundDependencyLoader] + private void load() + { + // Generate the entire curve + slider.Curve.GetPathToProgress(CurrentCurve, 0, 1); + SetVertices(CurrentCurve); + + // The body is sized to the full path size to avoid excessive autosize computations + Size = Path.Size; + + snakedPosition = Path.PositionInBoundingBox(Vector2.Zero); + snakedPathOffset = Path.PositionInBoundingBox(Path.Vertices[0]); + } + + public void UpdateProgress(double completionProgress) + { + var span = slider.SpanAt(completionProgress); + var spanProgress = slider.ProgressAt(completionProgress); + + double start = 0; + double end = SnakingIn ? MathHelper.Clamp((Time.Current - (slider.StartTime - slider.TimePreempt)) / slider.TimeFadeIn, 0, 1) : 1; + + if (span >= slider.SpanCount() - 1) + { + if (Math.Min(span, slider.SpanCount() - 1) % 2 == 1) + { + start = 0; + end = SnakingOut ? spanProgress : 1; + } + else + { + start = SnakingOut ? spanProgress : 0; + } + } + + setRange(start, end); + } + + private void setRange(double p0, double p1) + { + if (p0 > p1) + MathHelper.Swap(ref p0, ref p1); + + if (SnakedStart == p0 && SnakedEnd == p1) return; + + SnakedStart = p0; + SnakedEnd = p1; + + slider.Curve.GetPathToProgress(CurrentCurve, p0, p1); + + SetVertices(CurrentCurve); + + // The bounding box of the path expands as it snakes, which in turn shifts the position of the path. + // Depending on the direction of expansion, it may appear as if the path is expanding towards the position of the slider + // rather than expanding out from the position of the slider. + // To remove this effect, the path's position is shifted towards its final snaked position + + Path.Position = snakedPosition - Path.PositionInBoundingBox(Vector2.Zero); + } + } +} diff --git a/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs index fdf5aaffa8..67396c7ae4 100644 --- a/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs +++ b/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs @@ -16,13 +16,15 @@ namespace osu.Game.Rulesets.Osu.Objects public const double OBJECT_RADIUS = 64; public event Action PositionChanged; + public event Action StackHeightChanged; + public event Action ScaleChanged; public double TimePreempt = 600; public double TimeFadeIn = 400; private Vector2 position; - public Vector2 Position + public virtual Vector2 Position { get => position; set @@ -44,13 +46,39 @@ namespace osu.Game.Rulesets.Osu.Objects public Vector2 StackedEndPosition => EndPosition + StackOffset; - public virtual int StackHeight { get; set; } + private int stackHeight; + + public int StackHeight + { + get => stackHeight; + set + { + if (stackHeight == value) + return; + stackHeight = value; + + StackHeightChanged?.Invoke(value); + } + } public Vector2 StackOffset => new Vector2(StackHeight * Scale * -6.4f); public double Radius => OBJECT_RADIUS * Scale; - public float Scale { get; set; } = 1; + private float scale = 1; + + public float Scale + { + get => scale; + set + { + if (scale == value) + return; + scale = value; + + ScaleChanged?.Invoke(value); + } + } public virtual bool NewCombo { get; set; } diff --git a/osu.Game.Rulesets.Osu/Objects/Slider.cs b/osu.Game.Rulesets.Osu/Objects/Slider.cs index c284335c98..a6f5bdb24e 100644 --- a/osu.Game.Rulesets.Osu/Objects/Slider.cs +++ b/osu.Game.Rulesets.Osu/Objects/Slider.cs @@ -70,6 +70,21 @@ namespace osu.Game.Rulesets.Osu.Objects set { Curve.Distance = value; } } + public override Vector2 Position + { + get => base.Position; + set + { + base.Position = value; + + if (HeadCircle != null) + HeadCircle.Position = value; + + if (TailCircle != null) + TailCircle.Position = EndPosition; + } + } + public double? LegacyLastTickOffset { get; set; } /// @@ -92,8 +107,21 @@ namespace osu.Game.Rulesets.Osu.Objects /// public double SpanDuration => Duration / this.SpanCount(); - public double Velocity; - public double TickDistance; + /// + /// Velocity of this . + /// + public double Velocity { get; private set; } + + /// + /// Spacing between s of this . + /// + public double TickDistance { get; private set; } + + /// + /// An extra multiplier that affects the number of s generated by this . + /// An increase in this value increases , which reduces the number of ticks generated. + /// + public double TickDistanceMultiplier = 1; public HitCircle HeadCircle; public SliderTailCircle TailCircle; @@ -108,7 +136,7 @@ namespace osu.Game.Rulesets.Osu.Objects double scoringDistance = base_scoring_distance * difficulty.SliderMultiplier * difficultyPoint.SpeedMultiplier; Velocity = scoringDistance / timingPoint.BeatLength; - TickDistance = scoringDistance / difficulty.SliderTickRate; + TickDistance = scoringDistance / difficulty.SliderTickRate * TickDistanceMultiplier; } protected override void CreateNestedHitObjects() diff --git a/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs b/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs index 0ea8d3ede8..ea5718bed2 100644 --- a/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs +++ b/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs @@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.UI public override PassThroughInputManager CreateInputManager() => new OsuInputManager(Ruleset.RulesetInfo); - protected override DrawableHitObject GetVisualRepresentation(OsuHitObject h) + public override DrawableHitObject GetVisualRepresentation(OsuHitObject h) { switch (h) { diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoRulesetContainer.cs b/osu.Game.Rulesets.Taiko/UI/TaikoRulesetContainer.cs index 3d08bffe0f..c94ced3390 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoRulesetContainer.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoRulesetContainer.cs @@ -78,7 +78,7 @@ namespace osu.Game.Rulesets.Taiko.UI protected override Playfield CreatePlayfield() => new TaikoPlayfield(Beatmap.ControlPointInfo); - protected override DrawableHitObject GetVisualRepresentation(TaikoHitObject h) + public override DrawableHitObject GetVisualRepresentation(TaikoHitObject h) { switch (h) { diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs index af63a39662..f1ae366ee1 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs @@ -8,11 +8,13 @@ using OpenTK.Graphics; using osu.Game.Tests.Resources; using System.Linq; using osu.Game.Audio; +using osu.Game.Beatmaps; using osu.Game.Rulesets.Objects.Types; using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets.Catch.Beatmaps; using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Beatmaps; using osu.Game.Skinning; @@ -21,6 +23,25 @@ namespace osu.Game.Tests.Beatmaps.Formats [TestFixture] public class LegacyBeatmapDecoderTest { + [Test] + public void TestDecodeBeatmapVersion() + { + using (var resStream = Resource.OpenResource("beatmap-version.osu")) + using (var stream = new StreamReader(resStream)) + { + var decoder = Decoder.GetDecoder(stream); + + stream.BaseStream.Position = 0; + stream.DiscardBufferedData(); + + var working = new TestWorkingBeatmap(decoder.Decode(stream)); + + Assert.AreEqual(6, working.BeatmapInfo.BeatmapVersion); + Assert.AreEqual(6, working.Beatmap.BeatmapInfo.BeatmapVersion); + Assert.AreEqual(6, working.GetPlayableBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo.BeatmapVersion); + } + } + [Test] public void TestDecodeBeatmapGeneral() { diff --git a/osu.Game.Tests/Resources/beatmap-version.osu b/osu.Game.Tests/Resources/beatmap-version.osu new file mode 100644 index 0000000000..5749054ac4 --- /dev/null +++ b/osu.Game.Tests/Resources/beatmap-version.osu @@ -0,0 +1 @@ +osu file format v6 \ No newline at end of file diff --git a/osu.Game.Tests/Visual/TestCaseHitObjectComposer.cs b/osu.Game.Tests/Visual/TestCaseHitObjectComposer.cs index a2bc28bc3c..61647ffdc5 100644 --- a/osu.Game.Tests/Visual/TestCaseHitObjectComposer.cs +++ b/osu.Game.Tests/Visual/TestCaseHitObjectComposer.cs @@ -13,14 +13,18 @@ using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Edit; +using osu.Game.Rulesets.Osu.Edit.Masks.HitCircleMasks; +using osu.Game.Rulesets.Osu.Edit.Masks.HitCircleMasks.Components; using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Screens.Edit.Screens.Compose; using osu.Game.Screens.Edit.Screens.Compose.Layers; using osu.Game.Tests.Beatmaps; namespace osu.Game.Tests.Visual { [TestFixture] - public class TestCaseHitObjectComposer : OsuTestCase + [Cached(Type = typeof(IPlacementHandler))] + public class TestCaseHitObjectComposer : OsuTestCase, IPlacementHandler { public override IReadOnlyList RequiredTypes => new[] { @@ -29,9 +33,14 @@ namespace osu.Game.Tests.Visual typeof(HitObjectComposer), typeof(OsuHitObjectComposer), typeof(HitObjectMaskLayer), - typeof(NotNullAttribute) + typeof(NotNullAttribute), + typeof(HitCirclePiece), + typeof(HitCircleSelectionMask), + typeof(HitCirclePlacementMask), }; + private HitObjectComposer composer; + [BackgroundDependencyLoader] private void load() { @@ -49,9 +58,7 @@ namespace osu.Game.Tests.Visual Vector2.Zero, new Vector2(216, 0), }, - Distance = 400, - Velocity = 1, - TickDistance = 100, + Distance = 216, Scale = 0.5f, } }, @@ -61,7 +68,15 @@ namespace osu.Game.Tests.Visual Dependencies.CacheAs(clock); Dependencies.CacheAs(clock); - Child = new OsuHitObjectComposer(new OsuRuleset()); + Child = composer = new OsuHitObjectComposer(new OsuRuleset()); } + + public void BeginPlacement(HitObject hitObject) + { + } + + public void EndPlacement(HitObject hitObject) => composer.Add(hitObject); + + public void Delete(HitObject hitObject) => composer.Remove(hitObject); } } diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index 1aa4818393..3e1f3bdf54 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -19,7 +19,6 @@ namespace osu.Game.Beatmaps [JsonIgnore] public int ID { get; set; } - //TODO: should be in database public int BeatmapVersion; private int? onlineBeatmapID; diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index aa653d88f9..24c68d392b 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -148,11 +148,12 @@ namespace osu.Game.Beatmaps /// /// The to be downloaded. /// Whether the beatmap should be downloaded without video. Defaults to false. - public void Download(BeatmapSetInfo beatmapSetInfo, bool noVideo = false) + /// Downloading can happen + public bool Download(BeatmapSetInfo beatmapSetInfo, bool noVideo = false) { var existing = GetExistingDownload(beatmapSetInfo); - if (existing != null || api == null) return; + if (existing != null || api == null) return false; if (!api.LocalUser.Value.IsSupporter) { @@ -161,7 +162,7 @@ namespace osu.Game.Beatmaps Icon = FontAwesome.fa_superpowers, Text = "You gotta be an osu!supporter to download for now 'yo" }); - return; + return false; } var downloadNotification = new DownloadNotification @@ -227,6 +228,7 @@ namespace osu.Game.Beatmaps // don't run in the main api queue as this is a long-running task. Task.Factory.StartNew(() => request.Perform(api), TaskCreationOptions.LongRunning); BeatmapDownloadBegan?.Invoke(request); + return true; } protected override void PresentCompletedImport(IEnumerable imported) @@ -348,7 +350,7 @@ namespace osu.Game.Beatmaps OnlineBeatmapSetID = beatmap.BeatmapInfo.BeatmapSet?.OnlineBeatmapSetID, Beatmaps = new List(), Hash = computeBeatmapSetHash(reader), - Metadata = beatmap.Metadata + Metadata = beatmap.Metadata, }; } diff --git a/osu.Game/Beatmaps/Drawables/BeatmapSetDownloader.cs b/osu.Game/Beatmaps/Drawables/BeatmapSetDownloader.cs index 6f4d4c0d6f..5b5dbec9c8 100644 --- a/osu.Game/Beatmaps/Drawables/BeatmapSetDownloader.cs +++ b/osu.Game/Beatmaps/Drawables/BeatmapSetDownloader.cs @@ -71,9 +71,11 @@ namespace osu.Game.Beatmaps.Drawables if (DownloadState.Value > DownloadStatus.NotDownloaded) return; - beatmaps.Download(set, noVideo); - - DownloadState.Value = DownloadStatus.Downloading; + if (beatmaps.Download(set, noVideo)) + { + // Only change state if download can happen + DownloadState.Value = DownloadStatus.Downloading; + } } private void setAdded(BeatmapSetInfo s) diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index e0a22460ef..5b76122616 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -41,8 +41,13 @@ namespace osu.Game.Beatmaps beatmap = new RecyclableLazy(() => { var b = GetBeatmap() ?? new Beatmap(); - // use the database-backed info. + + // The original beatmap version needs to be preserved as the database doesn't contain it + BeatmapInfo.BeatmapVersion = b.BeatmapInfo.BeatmapVersion; + + // Use the database-backed info for more up-to-date values (beatmap id, ranked status, etc) b.BeatmapInfo = BeatmapInfo; + return b; }); diff --git a/osu.Game/Online/API/Requests/SearchBeatmapSetsRequest.cs b/osu.Game/Online/API/Requests/SearchBeatmapSetsRequest.cs index 3c808d1bee..ffea7b83e1 100644 --- a/osu.Game/Online/API/Requests/SearchBeatmapSetsRequest.cs +++ b/osu.Game/Online/API/Requests/SearchBeatmapSetsRequest.cs @@ -1,16 +1,14 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Collections.Generic; using System.ComponentModel; -using osu.Game.Online.API.Requests.Responses; using osu.Game.Overlays; using osu.Game.Overlays.Direct; using osu.Game.Rulesets; namespace osu.Game.Online.API.Requests { - public class SearchBeatmapSetsRequest : APIRequest> + public class SearchBeatmapSetsRequest : APIRequest { private readonly string query; private readonly RulesetInfo ruleset; @@ -35,6 +33,7 @@ namespace osu.Game.Online.API.Requests public enum BeatmapSearchCategory { Any = 7, + [Description("Ranked & Approved")] RankedApproved = 0, Approved = 1, @@ -43,6 +42,7 @@ namespace osu.Game.Online.API.Requests Qualified = 3, Pending = 4, Graveyard = 5, + [Description("My Maps")] MyMaps = 6, } diff --git a/osu.Game/Online/API/Requests/SearchBeatmapSetsResponse.cs b/osu.Game/Online/API/Requests/SearchBeatmapSetsResponse.cs new file mode 100644 index 0000000000..cf8b40d068 --- /dev/null +++ b/osu.Game/Online/API/Requests/SearchBeatmapSetsResponse.cs @@ -0,0 +1,20 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; +using Newtonsoft.Json; +using osu.Game.Online.API.Requests.Responses; + +namespace osu.Game.Online.API.Requests +{ + public class SearchBeatmapSetsResponse + { + public IEnumerable BeatmapSets; + + /// + /// A collection of parameters which should be passed to the search endpoint to fetch the next page. + /// + [JsonProperty("cursor")] + public dynamic CursorJson; + } +} diff --git a/osu.Game/Overlays/DirectOverlay.cs b/osu.Game/Overlays/DirectOverlay.cs index f63d314053..641f57d25f 100644 --- a/osu.Game/Overlays/DirectOverlay.cs +++ b/osu.Game/Overlays/DirectOverlay.cs @@ -288,7 +288,7 @@ namespace osu.Game.Overlays { Task.Run(() => { - var sets = response.Select(r => r.ToBeatmapSet(rulesets)).ToList(); + var sets = response.BeatmapSets.Select(r => r.ToBeatmapSet(rulesets)).ToList(); // may not need scheduling; loads async internally. Schedule(() => diff --git a/osu.Game/Rulesets/Edit/EditRulesetContainer.cs b/osu.Game/Rulesets/Edit/EditRulesetContainer.cs new file mode 100644 index 0000000000..bc54c907ab --- /dev/null +++ b/osu.Game/Rulesets/Edit/EditRulesetContainer.cs @@ -0,0 +1,106 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Linq; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Beatmaps; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.UI; + +namespace osu.Game.Rulesets.Edit +{ + public abstract class EditRulesetContainer : CompositeDrawable + { + /// + /// The contained by this . + /// + public abstract Playfield Playfield { get; } + + internal EditRulesetContainer() + { + RelativeSizeAxes = Axes.Both; + } + + /// + /// Adds a to the and displays a visual representation of it. + /// + /// The to add. + /// The visual representation of . + internal abstract DrawableHitObject Add(HitObject hitObject); + + /// + /// Removes a from the and the display. + /// + /// The to remove. + /// The visual representation of the removed . + internal abstract DrawableHitObject Remove(HitObject hitObject); + } + + public class EditRulesetContainer : EditRulesetContainer + where TObject : HitObject + { + public override Playfield Playfield => rulesetContainer.Playfield; + + private Ruleset ruleset => rulesetContainer.Ruleset; + private Beatmap beatmap => rulesetContainer.Beatmap; + + private readonly RulesetContainer rulesetContainer; + + public EditRulesetContainer(RulesetContainer rulesetContainer) + { + this.rulesetContainer = rulesetContainer; + + InternalChild = rulesetContainer; + + Playfield.DisplayJudgements.Value = false; + } + + internal override DrawableHitObject Add(HitObject hitObject) + { + var tObject = (TObject)hitObject; + + // Add to beatmap, preserving sorting order + var insertionIndex = beatmap.HitObjects.FindLastIndex(h => h.StartTime <= hitObject.StartTime); + beatmap.HitObjects.Insert(insertionIndex + 1, tObject); + + // Process object + var processor = ruleset.CreateBeatmapProcessor(beatmap); + + processor.PreProcess(); + tObject.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty); + processor.PostProcess(); + + // Add visual representation + var drawableObject = rulesetContainer.GetVisualRepresentation(tObject); + + rulesetContainer.Playfield.Add(drawableObject); + rulesetContainer.Playfield.PostProcess(); + + return drawableObject; + } + + internal override DrawableHitObject Remove(HitObject hitObject) + { + var tObject = (TObject)hitObject; + + // Remove from beatmap + beatmap.HitObjects.Remove(tObject); + + // Process the beatmap + var processor = ruleset.CreateBeatmapProcessor(beatmap); + + processor.PreProcess(); + processor.PostProcess(); + + // Remove visual representation + var drawableObject = Playfield.AllHitObjects.Single(d => d.HitObject == hitObject); + + rulesetContainer.Playfield.Remove(drawableObject); + rulesetContainer.Playfield.PostProcess(); + + return drawableObject; + } + } +} diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index 8060ac742a..13571bda84 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -13,6 +13,7 @@ using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Edit.Tools; +using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.UI; using osu.Game.Screens.Edit.Screens.Compose.Layers; @@ -22,21 +23,24 @@ namespace osu.Game.Rulesets.Edit { public abstract class HitObjectComposer : CompositeDrawable { - private readonly Ruleset ruleset; - public IEnumerable HitObjects => rulesetContainer.Playfield.AllHitObjects; - protected ICompositionTool CurrentTool { get; private set; } + protected readonly Ruleset Ruleset; + + protected readonly IBindable Beatmap = new Bindable(); + protected IRulesetConfigManager Config { get; private set; } private readonly List layerContainers = new List(); - private readonly IBindable beatmap = new Bindable(); - private RulesetContainer rulesetContainer; + private EditRulesetContainer rulesetContainer; - protected HitObjectComposer(Ruleset ruleset) + private HitObjectMaskLayer maskLayer; + private PlacementContainer placementContainer; + + internal HitObjectComposer(Ruleset ruleset) { - this.ruleset = ruleset; + Ruleset = ruleset; RelativeSizeAxes = Axes.Both; } @@ -44,11 +48,11 @@ namespace osu.Game.Rulesets.Edit [BackgroundDependencyLoader] private void load(IBindableBeatmap beatmap, IFrameBasedClock framedClock) { - this.beatmap.BindTo(beatmap); + Beatmap.BindTo(beatmap); try { - rulesetContainer = CreateRulesetContainer(ruleset, beatmap.Value); + rulesetContainer = CreateRulesetContainer(); rulesetContainer.Clock = framedClock; } catch (Exception e) @@ -57,14 +61,15 @@ namespace osu.Game.Rulesets.Edit return; } - var layerBelowRuleset = new BorderLayer - { - RelativeSizeAxes = Axes.Both, - Child = CreateLayerContainer() - }; + var layerBelowRuleset = CreateLayerContainer(); + layerBelowRuleset.Child = new BorderLayer { RelativeSizeAxes = Axes.Both }; var layerAboveRuleset = CreateLayerContainer(); - layerAboveRuleset.Child = new HitObjectMaskLayer(); + layerAboveRuleset.Children = new Drawable[] + { + maskLayer = new HitObjectMaskLayer(), + placementContainer = new PlacementContainer(), + }; layerContainers.Add(layerBelowRuleset); layerContainers.Add(layerAboveRuleset); @@ -107,8 +112,8 @@ namespace osu.Game.Rulesets.Edit }; toolboxCollection.Items = - CompositionTools.Select(t => new RadioButton(t.Name, () => setCompositionTool(t))) - .Prepend(new RadioButton("Select", () => setCompositionTool(null))) + CompositionTools.Select(t => new RadioButton(t.Name, () => placementContainer.CurrentTool = t)) + .Prepend(new RadioButton("Select", () => placementContainer.CurrentTool = null)) .ToList(); toolboxCollection.Items[0].Select(); @@ -119,18 +124,11 @@ namespace osu.Game.Rulesets.Edit var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); dependencies.CacheAs(this); - Config = dependencies.Get().GetConfigFor(ruleset); + Config = dependencies.Get().GetConfigFor(Ruleset); return dependencies; } - protected override void LoadComplete() - { - base.LoadComplete(); - - rulesetContainer.Playfield.DisplayJudgements.Value = false; - } - protected override void UpdateAfterChildren() { base.UpdateAfterChildren(); @@ -144,17 +142,27 @@ namespace osu.Game.Rulesets.Edit }); } - private void setCompositionTool(ICompositionTool tool) => CurrentTool = tool; + /// + /// Adds a to the and visualises it. + /// + /// The to add. + public void Add(HitObject hitObject) + { + maskLayer.AddMaskFor(rulesetContainer.Add(hitObject)); + placementContainer.Refresh(); + } - protected virtual RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => ruleset.CreateRulesetContainerWith(beatmap); + public void Remove(HitObject hitObject) => maskLayer.RemoveMaskFor(rulesetContainer.Remove(hitObject)); - protected abstract IReadOnlyList CompositionTools { get; } + internal abstract EditRulesetContainer CreateRulesetContainer(); + + protected abstract IReadOnlyList CompositionTools { get; } /// - /// Creates a for a specific . + /// Creates a for a specific . /// /// The to create the overlay for. - public virtual HitObjectMask CreateMaskFor(DrawableHitObject hitObject) => null; + public virtual SelectionMask CreateMaskFor(DrawableHitObject hitObject) => null; /// /// Creates a which outlines s @@ -167,4 +175,18 @@ namespace osu.Game.Rulesets.Edit /// protected virtual Container CreateLayerContainer() => new Container { RelativeSizeAxes = Axes.Both }; } + + public abstract class HitObjectComposer : HitObjectComposer + where TObject : HitObject + { + protected HitObjectComposer(Ruleset ruleset) + : base(ruleset) + { + } + + internal override EditRulesetContainer CreateRulesetContainer() + => new EditRulesetContainer(CreateRulesetContainer(Ruleset, Beatmap.Value)); + + protected abstract RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap); + } } diff --git a/osu.Game/Rulesets/Edit/PlacementMask.cs b/osu.Game/Rulesets/Edit/PlacementMask.cs new file mode 100644 index 0000000000..97c6a74c92 --- /dev/null +++ b/osu.Game/Rulesets/Edit/PlacementMask.cs @@ -0,0 +1,96 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Input; +using osu.Framework.Input.Events; +using osu.Framework.Timing; +using osu.Game.Beatmaps; +using osu.Game.Rulesets.Objects; +using osu.Game.Screens.Edit.Screens.Compose; +using OpenTK; + +namespace osu.Game.Rulesets.Edit +{ + /// + /// A mask which governs the creation of a new to actualisation. + /// + public abstract class PlacementMask : CompositeDrawable, IRequireHighFrequencyMousePosition + { + /// + /// The that is being placed. + /// + protected readonly HitObject HitObject; + + protected IClock EditorClock { get; private set; } + + private readonly IBindable beatmap = new Bindable(); + + [Resolved] + private IPlacementHandler placementHandler { get; set; } + + protected PlacementMask(HitObject hitObject) + { + HitObject = hitObject; + + RelativeSizeAxes = Axes.Both; + } + + [BackgroundDependencyLoader] + private void load(IBindableBeatmap beatmap, IAdjustableClock clock) + { + this.beatmap.BindTo(beatmap); + + EditorClock = clock; + + ApplyDefaultsToHitObject(); + } + + private bool placementBegun; + + /// + /// Signals that the placement of has started. + /// + protected void BeginPlacement() + { + placementHandler.BeginPlacement(HitObject); + placementBegun = true; + } + + /// + /// Signals that the placement of has finished. + /// This will destroy this , and add the to the . + /// + protected void EndPlacement() + { + if (!placementBegun) + BeginPlacement(); + placementHandler.EndPlacement(HitObject); + } + + /// + /// Invokes , refreshing and parameters for the . + /// + protected void ApplyDefaultsToHitObject() => HitObject.ApplyDefaults(beatmap.Value.Beatmap.ControlPointInfo, beatmap.Value.Beatmap.BeatmapInfo.BaseDifficulty); + + public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent?.ReceivePositionalInputAt(screenSpacePos) ?? false; + + protected override bool Handle(UIEvent e) + { + base.Handle(e); + + switch (e) + { + case ScrollEvent _: + return false; + case MouseEvent _: + return true; + default: + return false; + } + } + } +} diff --git a/osu.Game/Rulesets/Edit/HitObjectMask.cs b/osu.Game/Rulesets/Edit/SelectionMask.cs similarity index 74% rename from osu.Game/Rulesets/Edit/HitObjectMask.cs rename to osu.Game/Rulesets/Edit/SelectionMask.cs index 636ea418f3..3b78d5aaf6 100644 --- a/osu.Game/Rulesets/Edit/HitObjectMask.cs +++ b/osu.Game/Rulesets/Edit/SelectionMask.cs @@ -3,6 +3,7 @@ using System; using osu.Framework; +using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Framework.Input.Events; @@ -16,31 +17,31 @@ namespace osu.Game.Rulesets.Edit /// /// A mask placed above a adding editing functionality. /// - public class HitObjectMask : CompositeDrawable, IStateful + public class SelectionMask : CompositeDrawable, IStateful { /// - /// Invoked when this has been selected. + /// Invoked when this has been selected. /// - public event Action Selected; + public event Action Selected; /// - /// Invoked when this has been deselected. + /// Invoked when this has been deselected. /// - public event Action Deselected; + public event Action Deselected; /// - /// Invoked when this has requested selection. + /// Invoked when this has requested selection. /// Will fire even if already selected. Does not actually perform selection. /// - public event Action SelectionRequested; + public event Action SelectionRequested; /// - /// Invoked when this has requested drag. + /// Invoked when this has requested drag. /// - public event Action DragRequested; + public event Action DragRequested; /// - /// The which this applies to. + /// The which this applies to. /// public readonly DrawableHitObject HitObject; @@ -48,10 +49,12 @@ namespace osu.Game.Rulesets.Edit public override bool HandlePositionalInput => ShouldBeAlive; public override bool RemoveWhenNotAlive => false; - public HitObjectMask(DrawableHitObject hitObject) + public SelectionMask(DrawableHitObject hitObject) { HitObject = hitObject; + RelativeSizeAxes = Axes.Both; + AlwaysPresent = true; Alpha = 0; } @@ -83,17 +86,19 @@ namespace osu.Game.Rulesets.Edit } /// - /// Selects this , causing it to become visible. + /// Selects this , causing it to become visible. /// public void Select() => State = SelectionState.Selected; /// - /// Deselects this , causing it to become invisible. + /// Deselects this , causing it to become invisible. /// public void Deselect() => State = SelectionState.NotSelected; public bool IsSelected => State == SelectionState.Selected; + public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => HitObject.ReceivePositionalInputAt(screenSpacePos); + private bool selectionRequested; protected override bool OnMouseDown(MouseDownEvent e) @@ -130,13 +135,13 @@ namespace osu.Game.Rulesets.Edit } /// - /// The screen-space point that causes this to be selected. + /// The screen-space point that causes this to be selected. /// - public virtual Vector2 SelectionPoint => ScreenSpaceDrawQuad.Centre; + public virtual Vector2 SelectionPoint => HitObject.ScreenSpaceDrawQuad.Centre; /// - /// The screen-space quad that outlines this for selections. + /// The screen-space quad that outlines this for selections. /// - public virtual Quad SelectionQuad => ScreenSpaceDrawQuad; + public virtual Quad SelectionQuad => HitObject.ScreenSpaceDrawQuad; } } diff --git a/osu.Game/Rulesets/Edit/Tools/HitObjectCompositionTool.cs b/osu.Game/Rulesets/Edit/Tools/HitObjectCompositionTool.cs index 78ad236e74..c5d64e3d4d 100644 --- a/osu.Game/Rulesets/Edit/Tools/HitObjectCompositionTool.cs +++ b/osu.Game/Rulesets/Edit/Tools/HitObjectCompositionTool.cs @@ -1,23 +1,17 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Game.Rulesets.Objects; - namespace osu.Game.Rulesets.Edit.Tools { - public class HitObjectCompositionTool : ICompositionTool - where T : HitObject + public abstract class HitObjectCompositionTool { - public string Name { get; } + public readonly string Name; - public HitObjectCompositionTool() - : this(typeof(T).Name) - { - } - - public HitObjectCompositionTool(string name) + protected HitObjectCompositionTool(string name) { Name = name; } + + public abstract PlacementMask CreatePlacementMask(); } } diff --git a/osu.Game/Rulesets/Edit/Tools/ICompositionTool.cs b/osu.Game/Rulesets/Edit/Tools/ICompositionTool.cs deleted file mode 100644 index ce8b139b43..0000000000 --- a/osu.Game/Rulesets/Edit/Tools/ICompositionTool.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -namespace osu.Game.Rulesets.Edit.Tools -{ - public interface ICompositionTool - { - string Name { get; } - } -} diff --git a/osu.Game/Rulesets/Mods/IApplicableToBeatmap.cs b/osu.Game/Rulesets/Mods/IApplicableToBeatmap.cs new file mode 100644 index 0000000000..1eb74ca76a --- /dev/null +++ b/osu.Game/Rulesets/Mods/IApplicableToBeatmap.cs @@ -0,0 +1,22 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Beatmaps; +using osu.Game.Rulesets.Objects; + +namespace osu.Game.Rulesets.Mods +{ + /// + /// Interface for a that applies changes to a + /// after conversion and post-processing has completed. + /// + public interface IApplicableToBeatmap : IApplicableMod + where TObject : HitObject + { + /// + /// Applies this to a . + /// + /// The to apply to. + void ApplyToBeatmap(Beatmap beatmap); + } +} diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index a23a5a78f7..0abd358113 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -73,7 +73,7 @@ namespace osu.Game.Rulesets.UI /// public readonly CursorContainer Cursor; - protected readonly Ruleset Ruleset; + public readonly Ruleset Ruleset; protected IRulesetConfigManager Config { get; private set; } @@ -238,6 +238,8 @@ namespace osu.Game.Rulesets.UI KeyBindingInputManager = CreateInputManager(); KeyBindingInputManager.RelativeSizeAxes = Axes.Both; + + applyBeatmapMods(Mods); } [BackgroundDependencyLoader] @@ -255,16 +257,29 @@ namespace osu.Game.Rulesets.UI KeyBindingInputManager.Add(Cursor); // Apply mods - applyMods(Mods, config); + applyRulesetMods(Mods, config); loadObjects(); } + /// + /// Applies the active mods to the Beatmap. + /// + /// + private void applyBeatmapMods(IEnumerable mods) + { + if (mods == null) + return; + + foreach (var mod in mods.OfType>()) + mod.ApplyToBeatmap(Beatmap); + } + /// /// Applies the active mods to this RulesetContainer. /// /// - private void applyMods(IEnumerable mods, OsuConfigManager config) + private void applyRulesetMods(IEnumerable mods, OsuConfigManager config) { if (mods == null) return; @@ -290,17 +305,7 @@ namespace osu.Game.Rulesets.UI private void loadObjects() { foreach (TObject h in Beatmap.HitObjects) - { - var drawableObject = GetVisualRepresentation(h); - - if (drawableObject == null) - continue; - - drawableObject.OnNewResult += (_, r) => OnNewResult?.Invoke(r); - drawableObject.OnRevertResult += (_, r) => OnRevertResult?.Invoke(r); - - Playfield.Add(drawableObject); - } + AddRepresentation(h); Playfield.PostProcess(); @@ -308,12 +313,30 @@ namespace osu.Game.Rulesets.UI mod.ApplyToDrawableHitObjects(Playfield.HitObjectContainer.Objects); } + /// + /// Creates and adds the visual representation of a to this . + /// + /// The to add the visual representation for. + internal void AddRepresentation(TObject hitObject) + { + var drawableObject = GetVisualRepresentation(hitObject); + + if (drawableObject == null) + return; + + drawableObject.OnNewResult += (_, r) => OnNewResult?.Invoke(r); + drawableObject.OnRevertResult += (_, r) => OnRevertResult?.Invoke(r); + + Playfield.Add(drawableObject); + } + + /// /// Creates a DrawableHitObject from a HitObject. /// /// The HitObject to make drawable. /// The DrawableHitObject. - protected abstract DrawableHitObject GetVisualRepresentation(TObject h); + public abstract DrawableHitObject GetVisualRepresentation(TObject h); } /// diff --git a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs index a862485fd6..ae42942d24 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs @@ -9,18 +9,21 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Logging; +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Objects; using osu.Game.Screens.Edit.Screens.Compose.Timeline; namespace osu.Game.Screens.Edit.Screens.Compose { - public class Compose : EditorScreen + [Cached(Type = typeof(IPlacementHandler))] + public class Compose : EditorScreen, IPlacementHandler { private const float vertical_margins = 10; private const float horizontal_margins = 20; private readonly BindableBeatDivisor beatDivisor = new BindableBeatDivisor(); - private Container composerContainer; + private HitObjectComposer composer; [BackgroundDependencyLoader(true)] private void load([CanBeNull] BindableBeatDivisor beatDivisor) @@ -28,6 +31,8 @@ namespace osu.Game.Screens.Edit.Screens.Compose if (beatDivisor != null) this.beatDivisor.BindTo(beatDivisor); + Container composerContainer; + Children = new Drawable[] { new GridContainer @@ -101,7 +106,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose return; } - var composer = ruleset.CreateHitObjectComposer(); + composer = ruleset.CreateHitObjectComposer(); if (composer == null) { Logger.Log($"Ruleset {ruleset.Description} doesn't support hitobject composition."); @@ -111,5 +116,13 @@ namespace osu.Game.Screens.Edit.Screens.Compose composerContainer.Child = composer; } + + public void BeginPlacement(HitObject hitObject) + { + } + + public void EndPlacement(HitObject hitObject) => composer.Add(hitObject); + + public void Delete(HitObject hitObject) => composer.Remove(hitObject); } } diff --git a/osu.Game/Screens/Edit/Screens/Compose/IPlacementHandler.cs b/osu.Game/Screens/Edit/Screens/Compose/IPlacementHandler.cs new file mode 100644 index 0000000000..cd213c2885 --- /dev/null +++ b/osu.Game/Screens/Edit/Screens/Compose/IPlacementHandler.cs @@ -0,0 +1,28 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Objects; + +namespace osu.Game.Screens.Edit.Screens.Compose +{ + public interface IPlacementHandler + { + /// + /// Notifies that a placement has begun. + /// + /// The being placed. + void BeginPlacement(HitObject hitObject); + + /// + /// Notifies that a placement has finished. + /// + /// The that has been placed. + void EndPlacement(HitObject hitObject); + + /// + /// Deletes a . + /// + /// The to delete. + void Delete(HitObject hitObject); + } +} diff --git a/osu.Game/Screens/Edit/Screens/Compose/Layers/DragLayer.cs b/osu.Game/Screens/Edit/Screens/Compose/Layers/DragLayer.cs index 981ddd989c..fdc0dee0ce 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Layers/DragLayer.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Layers/DragLayer.cs @@ -14,7 +14,7 @@ using OpenTK.Graphics; namespace osu.Game.Screens.Edit.Screens.Compose.Layers { /// - /// A layer that handles and displays drag selection for a collection of s. + /// A layer that handles and displays drag selection for a collection of s. /// public class DragLayer : CompositeDrawable { @@ -30,7 +30,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers /// /// Creates a new . /// - /// The selectable s. + /// The selectable s. public DragLayer(Action performSelection) { this.performSelection = performSelection; diff --git a/osu.Game/Screens/Edit/Screens/Compose/Layers/HitObjectMaskLayer.cs b/osu.Game/Screens/Edit/Screens/Compose/Layers/HitObjectMaskLayer.cs index 65f31dd56d..3e33ceefcd 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Layers/HitObjectMaskLayer.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Layers/HitObjectMaskLayer.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -13,7 +14,9 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers public class HitObjectMaskLayer : CompositeDrawable { private MaskContainer maskContainer; - private HitObjectComposer composer; + + [Resolved] + private HitObjectComposer composer { get; set; } public HitObjectMaskLayer() { @@ -21,10 +24,8 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers } [BackgroundDependencyLoader] - private void load(HitObjectComposer composer) + private void load() { - this.composer = composer; - maskContainer = new MaskContainer(); var maskSelection = composer.CreateMaskSelection(); @@ -48,7 +49,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers }; foreach (var obj in composer.HitObjects) - addMask(obj); + AddMaskFor(obj); } protected override bool OnMouseDown(MouseDownEvent e) @@ -61,7 +62,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers /// Adds a mask for a which adds movement support. /// /// The to create a mask for. - private void addMask(DrawableHitObject hitObject) + public void AddMaskFor(DrawableHitObject hitObject) { var mask = composer.CreateMaskFor(hitObject); if (mask == null) @@ -69,5 +70,19 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers maskContainer.Add(mask); } + + /// + /// Removes a mask for a . + /// + /// The for which to remove the mask. + public void RemoveMaskFor(DrawableHitObject hitObject) + { + var maskToRemove = maskContainer.Single(m => m.HitObject == hitObject); + if (maskToRemove == null) + return; + + maskToRemove.Deselect(); + maskContainer.Remove(maskToRemove); + } } } diff --git a/osu.Game/Screens/Edit/Screens/Compose/Layers/MaskContainer.cs b/osu.Game/Screens/Edit/Screens/Compose/Layers/MaskContainer.cs index 19258d669e..42a7757721 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Layers/MaskContainer.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Layers/MaskContainer.cs @@ -13,36 +13,36 @@ using RectangleF = osu.Framework.Graphics.Primitives.RectangleF; namespace osu.Game.Screens.Edit.Screens.Compose.Layers { - public class MaskContainer : Container + public class MaskContainer : Container { /// - /// Invoked when any is selected. + /// Invoked when any is selected. /// - public event Action MaskSelected; + public event Action MaskSelected; /// - /// Invoked when any is deselected. + /// Invoked when any is deselected. /// - public event Action MaskDeselected; + public event Action MaskDeselected; /// - /// Invoked when any requests selection. + /// Invoked when any requests selection. /// - public event Action MaskSelectionRequested; + public event Action MaskSelectionRequested; /// - /// Invoked when any requests drag. + /// Invoked when any requests drag. /// - public event Action MaskDragRequested; + public event Action MaskDragRequested; - private IEnumerable aliveMasks => AliveInternalChildren.Cast(); + private IEnumerable aliveMasks => AliveInternalChildren.Cast(); public MaskContainer() { RelativeSizeAxes = Axes.Both; } - public override void Add(HitObjectMask drawable) + public override void Add(SelectionMask drawable) { if (drawable == null) throw new ArgumentNullException(nameof(drawable)); @@ -54,7 +54,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers drawable.DragRequested += onDragRequested; } - public override bool Remove(HitObjectMask drawable) + public override bool Remove(SelectionMask drawable) { if (drawable == null) throw new ArgumentNullException(nameof(drawable)); @@ -87,33 +87,33 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers } /// - /// Deselects all selected s. + /// Deselects all selected s. /// public void DeselectAll() => aliveMasks.ToList().ForEach(m => m.Deselect()); - private void onMaskSelected(HitObjectMask mask) + private void onMaskSelected(SelectionMask mask) { MaskSelected?.Invoke(mask); ChangeChildDepth(mask, 1); } - private void onMaskDeselected(HitObjectMask mask) + private void onMaskDeselected(SelectionMask mask) { MaskDeselected?.Invoke(mask); ChangeChildDepth(mask, 0); } - private void onSelectionRequested(HitObjectMask mask, InputState state) => MaskSelectionRequested?.Invoke(mask, state); - private void onDragRequested(HitObjectMask mask, Vector2 delta, InputState state) => MaskDragRequested?.Invoke(mask, delta, state); + private void onSelectionRequested(SelectionMask mask, InputState state) => MaskSelectionRequested?.Invoke(mask, state); + private void onDragRequested(SelectionMask mask, Vector2 delta, InputState state) => MaskDragRequested?.Invoke(mask, delta, state); protected override int Compare(Drawable x, Drawable y) { - if (!(x is HitObjectMask xMask) || !(y is HitObjectMask yMask)) + if (!(x is SelectionMask xMask) || !(y is SelectionMask yMask)) return base.Compare(x, y); return Compare(xMask, yMask); } - public int Compare(HitObjectMask x, HitObjectMask y) + public int Compare(SelectionMask x, SelectionMask y) { // dpeth is used to denote selected status (we always want selected masks to handle input first). int d = x.Depth.CompareTo(y.Depth); diff --git a/osu.Game/Screens/Edit/Screens/Compose/Layers/MaskSelection.cs b/osu.Game/Screens/Edit/Screens/Compose/Layers/MaskSelection.cs index 635edf82da..17b34bfb49 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Layers/MaskSelection.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Layers/MaskSelection.cs @@ -3,32 +3,38 @@ using System; using System.Collections.Generic; +using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Framework.Input.Events; using osu.Framework.Input.States; using osu.Game.Graphics; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Types; using OpenTK; +using OpenTK.Input; namespace osu.Game.Screens.Edit.Screens.Compose.Layers { /// - /// A box which surrounds s and provides interactive handles, context menus etc. + /// A box which surrounds s and provides interactive handles, context menus etc. /// public class MaskSelection : CompositeDrawable { public const float BORDER_RADIUS = 2; - private readonly List selectedMasks; + private readonly List selectedMasks; private Drawable outline; + [Resolved] + private IPlacementHandler placementHandler { get; set; } + public MaskSelection() { - selectedMasks = new List(); + selectedMasks = new List(); RelativeSizeAxes = Axes.Both; AlwaysPresent = true; @@ -54,7 +60,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers #region User Input Handling - public void HandleDrag(HitObjectMask m, Vector2 delta, InputState state) + public void HandleDrag(SelectionMask m, Vector2 delta, InputState state) { // Todo: Various forms of snapping @@ -69,6 +75,22 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers } } + protected override bool OnKeyDown(KeyDownEvent e) + { + if (e.Repeat) + return base.OnKeyDown(e); + + switch (e.Key) + { + case Key.Delete: + foreach (var h in selectedMasks.ToList()) + placementHandler.Delete(h.HitObject.HitObject); + return true; + } + + return base.OnKeyDown(e); + } + #endregion #region Selection Handling @@ -82,13 +104,13 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers /// Handle a mask becoming selected. /// /// The mask. - public void HandleSelected(HitObjectMask mask) => selectedMasks.Add(mask); + public void HandleSelected(SelectionMask mask) => selectedMasks.Add(mask); /// /// Handle a mask becoming deselected. /// /// The mask. - public void HandleDeselected(HitObjectMask mask) + public void HandleDeselected(SelectionMask mask) { selectedMasks.Remove(mask); @@ -101,7 +123,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers /// Handle a mask requesting selection. /// /// The mask. - public void HandleSelectionRequested(HitObjectMask mask, InputState state) + public void HandleSelectionRequested(SelectionMask mask, InputState state) { if (state.Keyboard.ControlPressed) { diff --git a/osu.Game/Screens/Edit/Screens/Compose/Layers/PlacementContainer.cs b/osu.Game/Screens/Edit/Screens/Compose/Layers/PlacementContainer.cs new file mode 100644 index 0000000000..ea167a5c6b --- /dev/null +++ b/osu.Game/Screens/Edit/Screens/Compose/Layers/PlacementContainer.cs @@ -0,0 +1,50 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Rulesets.Edit.Tools; +using Container = System.ComponentModel.Container; + +namespace osu.Game.Screens.Edit.Screens.Compose.Layers +{ + public class PlacementContainer : CompositeDrawable + { + private readonly Container maskContainer; + + public PlacementContainer() + { + RelativeSizeAxes = Axes.Both; + } + + private HitObjectCompositionTool currentTool; + + /// + /// The current placement tool. + /// + public HitObjectCompositionTool CurrentTool + { + get => currentTool; + set + { + if (currentTool == value) + return; + currentTool = value; + + Refresh(); + } + } + + /// + /// Refreshes the current placement tool. + /// + public void Refresh() + { + ClearInternal(); + + var mask = CurrentTool?.CreatePlacementMask(); + if (mask != null) + InternalChild = mask; + } + } +} diff --git a/osu.Game/Screens/Play/HUDOverlay.cs b/osu.Game/Screens/Play/HUDOverlay.cs index db0d7b6ccc..0f9f4fc20a 100644 --- a/osu.Game/Screens/Play/HUDOverlay.cs +++ b/osu.Game/Screens/Play/HUDOverlay.cs @@ -134,11 +134,13 @@ namespace osu.Game.Screens.Play { PlayerSettingsOverlay.Show(); ModDisplay.FadeIn(200); + KeyCounter.Margin = new MarginPadding(10) { Bottom = 30 }; } else { PlayerSettingsOverlay.Hide(); ModDisplay.Delay(2000).FadeOut(200); + KeyCounter.Margin = new MarginPadding(10); } } diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index 2e2c77c1c8..d4615b3016 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -21,7 +21,7 @@ namespace osu.Game.Screens.Play { private const int bottom_bar_height = 5; - private static readonly Vector2 handle_size = new Vector2(14, 25); + private static readonly Vector2 handle_size = new Vector2(10, 18); private const float transition_duration = 200; @@ -135,6 +135,8 @@ namespace osu.Game.Screens.Play { bar.FadeTo(allowSeeking ? 1 : 0, transition_duration, Easing.In); this.MoveTo(new Vector2(0, allowSeeking ? 0 : bottom_bar_height), transition_duration, Easing.In); + + info.Margin = new MarginPadding { Bottom = Height - (allowSeeking ? 0 : handle_size.Y) }; } protected override void PopIn() diff --git a/osu.Game/Screens/Select/BeatmapDetails.cs b/osu.Game/Screens/Select/BeatmapDetails.cs index f7b955941d..3999adfede 100644 --- a/osu.Game/Screens/Select/BeatmapDetails.cs +++ b/osu.Game/Screens/Select/BeatmapDetails.cs @@ -307,10 +307,10 @@ namespace osu.Game.Screens.Select { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; - Alpha = 0; InternalChild = textContainer = new FillFlowContainer { + Alpha = 0, RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Spacing = new Vector2(spacing / 2), @@ -337,7 +337,7 @@ namespace osu.Game.Screens.Select { if (string.IsNullOrEmpty(value)) { - this.FadeOut(transition_duration); + textContainer.FadeOut(transition_duration); return; } @@ -345,8 +345,6 @@ namespace osu.Game.Screens.Select } } - public override bool IsPresent => base.IsPresent || textFlow == null; // Visibility is updated in the LoadComponentAsync callback - private void setTextAsync(string text) { LoadComponentAsync(new OsuTextFlowContainer(s => s.TextSize = 14) @@ -361,7 +359,7 @@ namespace osu.Game.Screens.Select textContainer.Add(textFlow = loaded); // fade in if we haven't yet. - this.FadeIn(transition_duration); + textContainer.FadeIn(transition_duration); }); } } diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index 917a08d172..285410ce20 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -16,7 +16,6 @@ using osu.Game.Graphics; using osu.Game.Overlays; using osu.Game.Overlays.Mods; using osu.Game.Rulesets.Mods; -using osu.Game.Screens.Edit; using osu.Game.Screens.Play; using osu.Game.Screens.Ranking; using osu.Game.Skinning; @@ -68,7 +67,7 @@ namespace osu.Game.Screens.Select BeatmapOptions.AddButton(@"Edit", @"beatmap", FontAwesome.fa_pencil, colours.Yellow, () => { ValidForResume = false; - Push(new Editor()); + Edit(); }, Key.Number3); if (dialogOverlay != null) diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index b4f552ce93..acf699aa24 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -223,9 +223,9 @@ namespace osu.Game.Screens.Select Carousel.LoadBeatmapSetsFromManager(this.beatmaps); } - public void Edit(BeatmapInfo beatmap) + public void Edit(BeatmapInfo beatmap = null) { - Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap, Beatmap.Value); + Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap ?? beatmapNoDebounce); Push(new Editor()); } @@ -350,7 +350,7 @@ namespace osu.Game.Screens.Select } } - ensurePlayingSelected(preview); + if (IsCurrentScreen) ensurePlayingSelected(preview); UpdateBeatmap(Beatmap.Value); } diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs index ce7edf8683..bd7ca22fa1 100644 --- a/osu.Game/Skinning/LegacySkin.cs +++ b/osu.Game/Skinning/LegacySkin.cs @@ -12,6 +12,7 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Framework.IO.Stores; using osu.Game.Database; +using osu.Game.Graphics.Sprites; using OpenTK; namespace osu.Game.Skinning @@ -56,30 +57,39 @@ namespace osu.Game.Skinning case "Play/Great": componentName = "hit300"; break; + case "Play/osu/number-text": + return !hasFont(Configuration.HitCircleFont) ? null : new LegacySpriteText(Textures, Configuration.HitCircleFont) { Scale = new Vector2(0.96f) }; } - float ratio = 0.72f; // brings sizing roughly in-line with stable + var texture = GetTexture(componentName); - var texture = GetTexture($"{componentName}@2x"); if (texture == null) - { - ratio *= 2; - texture = GetTexture(componentName); - } + return null; - if (texture == null) return null; - - return new Sprite - { - Texture = texture, - Scale = new Vector2(ratio), - }; + return new Sprite { Texture = texture }; } - public override Texture GetTexture(string componentName) => Textures.Get(componentName); + public override Texture GetTexture(string componentName) + { + float ratio = 2; + + var texture = Textures.Get($"{componentName}@2x"); + if (texture == null) + { + ratio = 1; + texture = Textures.Get(componentName); + } + + if (texture != null) + texture.ScaleAdjust = ratio / 0.72f; // brings sizing roughly in-line with stable + + return texture; + } public override SampleChannel GetSample(string sampleName) => Samples.Get(sampleName); + private bool hasFont(string fontName) => GetTexture($"{fontName}-0") != null; + protected class LegacySkinResourceStore : IResourceStore where T : INamedFileInfo { @@ -142,5 +152,40 @@ namespace osu.Game.Skinning #endregion } + + private class LegacySpriteText : OsuSpriteText + { + private readonly TextureStore textures; + private readonly string font; + + public LegacySpriteText(TextureStore textures, string font) + { + this.textures = textures; + this.font = font; + + Shadow = false; + UseFullGlyphHeight = false; + } + + protected override Texture GetTextureForCharacter(char c) + { + string textureName = $"{font}-{c}"; + + // Approximate value that brings character sizing roughly in-line with stable + float ratio = 36; + + var texture = textures.Get($"{textureName}@2x"); + if (texture == null) + { + ratio = 18; + texture = textures.Get(textureName); + } + + if (texture != null) + texture.ScaleAdjust = ratio; + + return texture; + } + } } } diff --git a/osu.Game/Skinning/LegacySkinDecoder.cs b/osu.Game/Skinning/LegacySkinDecoder.cs index d4f1c5c6f1..67a031fb50 100644 --- a/osu.Game/Skinning/LegacySkinDecoder.cs +++ b/osu.Game/Skinning/LegacySkinDecoder.cs @@ -19,6 +19,7 @@ namespace osu.Game.Skinning switch (section) { case Section.General: + { var pair = SplitKeyVal(line); switch (pair.Key) @@ -32,6 +33,20 @@ namespace osu.Game.Skinning } break; + } + case Section.Fonts: + { + var pair = SplitKeyVal(line); + + switch (pair.Key) + { + case "HitCirclePrefix": + skin.HitCircleFont = pair.Value; + break; + } + + break; + } } base.ParseLine(skin, section, line); diff --git a/osu.Game/Skinning/SkinConfiguration.cs b/osu.Game/Skinning/SkinConfiguration.cs index ac59fcc7db..40f5c158cc 100644 --- a/osu.Game/Skinning/SkinConfiguration.cs +++ b/osu.Game/Skinning/SkinConfiguration.cs @@ -14,5 +14,7 @@ namespace osu.Game.Skinning public List ComboColours { get; set; } = new List(); public Dictionary CustomColours { get; set; } = new Dictionary(); + + public string HitCircleFont { get; set; } = "default"; } } diff --git a/osu.Game/Skinning/SkinnableDrawable.cs b/osu.Game/Skinning/SkinnableDrawable.cs index a40c3da82d..5195daee65 100644 --- a/osu.Game/Skinning/SkinnableDrawable.cs +++ b/osu.Game/Skinning/SkinnableDrawable.cs @@ -18,6 +18,11 @@ namespace osu.Game.Skinning public class SkinnableDrawable : SkinReloadableDrawable where T : Drawable { + /// + /// The displayed component. May or may not be a type- member. + /// + protected Drawable Drawable { get; private set; } + private readonly Func createDefault; private readonly string componentName; @@ -31,7 +36,8 @@ namespace osu.Game.Skinning /// A function to create the default skin implementation of this element. /// A conditional to decide whether to allow fallback to the default implementation if a skinned element is not present. /// Whether a user-skin drawable should be limited to the size of our parent. - public SkinnableDrawable(string name, Func defaultImplementation, Func allowFallback = null, bool restrictSize = true) : base(allowFallback) + public SkinnableDrawable(string name, Func defaultImplementation, Func allowFallback = null, bool restrictSize = true) + : base(allowFallback) { componentName = name; createDefault = defaultImplementation; @@ -42,26 +48,27 @@ namespace osu.Game.Skinning protected override void SkinChanged(ISkinSource skin, bool allowFallback) { - var drawable = skin.GetDrawableComponent(componentName); - if (drawable != null) + Drawable = skin.GetDrawableComponent(componentName); + + if (Drawable != null) { if (restrictSize) { - drawable.RelativeSizeAxes = Axes.Both; - drawable.Size = Vector2.One; - drawable.Scale = Vector2.One; - drawable.FillMode = FillMode.Fit; + Drawable.RelativeSizeAxes = Axes.Both; + Drawable.Size = Vector2.One; + Drawable.Scale = Vector2.One; + Drawable.FillMode = FillMode.Fit; } } else if (allowFallback) - drawable = createDefault(componentName); + Drawable = createDefault(componentName); - if (drawable != null) + if (Drawable != null) { - drawable.Origin = Anchor.Centre; - drawable.Anchor = Anchor.Centre; + Drawable.Origin = Anchor.Centre; + Drawable.Anchor = Anchor.Centre; - InternalChild = drawable; + InternalChild = Drawable; } else ClearInternal(); diff --git a/osu.Game/Skinning/SkinnableSpriteText.cs b/osu.Game/Skinning/SkinnableSpriteText.cs new file mode 100644 index 0000000000..8b09417bed --- /dev/null +++ b/osu.Game/Skinning/SkinnableSpriteText.cs @@ -0,0 +1,40 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using osu.Framework.Graphics.Sprites; + +namespace osu.Game.Skinning +{ + public class SkinnableSpriteText : SkinnableDrawable, IHasText + { + public SkinnableSpriteText(string name, Func defaultImplementation, Func allowFallback = null, bool restrictSize = true) + : base(name, defaultImplementation, allowFallback, restrictSize) + { + } + + protected override void SkinChanged(ISkinSource skin, bool allowFallback) + { + base.SkinChanged(skin, allowFallback); + + if (Drawable is IHasText textDrawable) + textDrawable.Text = Text; + } + + private string text; + + public string Text + { + get => text; + set + { + if (text == value) + return; + text = value; + + if (Drawable is IHasText textDrawable) + textDrawable.Text = value; + } + } + } +} diff --git a/osu.Game/Tests/Visual/HitObjectPlacementMaskTestCase.cs b/osu.Game/Tests/Visual/HitObjectPlacementMaskTestCase.cs new file mode 100644 index 0000000000..adf74b9a7d --- /dev/null +++ b/osu.Game/Tests/Visual/HitObjectPlacementMaskTestCase.cs @@ -0,0 +1,65 @@ +// Copyright (c) 2007-2018 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.Timing; +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Screens.Edit.Screens.Compose; + +namespace osu.Game.Tests.Visual +{ + [Cached(Type = typeof(IPlacementHandler))] + public abstract class HitObjectPlacementMaskTestCase : OsuTestCase, IPlacementHandler + { + private readonly Container hitObjectContainer; + private PlacementMask currentMask; + + protected HitObjectPlacementMaskTestCase() + { + Beatmap.Value.BeatmapInfo.BaseDifficulty.CircleSize = 2; + + Add(hitObjectContainer = new Container + { + RelativeSizeAxes = Axes.Both, + Clock = new FramedClock(new StopwatchClock()) + }); + } + + [BackgroundDependencyLoader] + private void load() + { + Add(currentMask = CreateMask()); + } + + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) + { + var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); + dependencies.CacheAs(new StopwatchClock()); + + return dependencies; + } + + public void BeginPlacement(HitObject hitObject) + { + } + + public void EndPlacement(HitObject hitObject) + { + hitObjectContainer.Add(CreateHitObject(hitObject)); + + Remove(currentMask); + Add(currentMask = CreateMask()); + } + + public void Delete(HitObject hitObject) + { + } + + protected abstract DrawableHitObject CreateHitObject(HitObject hitObject); + protected abstract PlacementMask CreateMask(); + } +} diff --git a/osu.Game/Tests/Visual/HitObjectSelectionMaskTestCase.cs b/osu.Game/Tests/Visual/HitObjectSelectionMaskTestCase.cs new file mode 100644 index 0000000000..3ba6841280 --- /dev/null +++ b/osu.Game/Tests/Visual/HitObjectSelectionMaskTestCase.cs @@ -0,0 +1,47 @@ +// Copyright (c) 2007-2018 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.Input.Events; +using osu.Framework.Timing; +using osu.Game.Rulesets.Edit; + +namespace osu.Game.Tests.Visual +{ + public abstract class HitObjectSelectionMaskTestCase : OsuTestCase + { + private SelectionMask mask; + + protected override Container Content => content ?? base.Content; + private readonly Container content; + + protected HitObjectSelectionMaskTestCase() + { + base.Content.Add(content = new Container + { + Clock = new FramedClock(new StopwatchClock()), + RelativeSizeAxes = Axes.Both + }); + } + + [BackgroundDependencyLoader] + private void load() + { + base.Content.Add(mask = CreateMask()); + mask.SelectionRequested += (_, __) => mask.Select(); + + AddStep("Select", () => mask.Select()); + AddStep("Deselect", () => mask.Deselect()); + } + + protected override bool OnClick(ClickEvent e) + { + mask.Deselect(); + return true; + } + + protected abstract SelectionMask CreateMask(); + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 3022b66762..921da942f0 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -19,6 +19,7 @@ + diff --git a/tools/cakebuild.csproj b/tools/cakebuild.csproj new file mode 100644 index 0000000000..8ccce35e26 --- /dev/null +++ b/tools/cakebuild.csproj @@ -0,0 +1,11 @@ + + + Exe + true + netcoreapp2.0 + + + + + + \ No newline at end of file