1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 09:32:55 +08:00

Add basic structure/layout for the beat snap visualiser

This commit is contained in:
smoogipoo 2018-03-19 19:46:26 +09:00
parent cbe2de33c5
commit 6b035e8c53
6 changed files with 273 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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.Graphics;
using osu.Game.Screens.Edit.Screens.Compose.BeatSnap;
namespace osu.Game.Tests.Visual
{
public class TestCaseBeatSnapVisualiser : OsuTestCase
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(BeatSnapVisualiser),
typeof(Tick),
typeof(TickContainer)
};
[BackgroundDependencyLoader]
private void load()
{
Child = new BeatSnapVisualiser
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
}
}
}

View File

@ -116,6 +116,7 @@
<Compile Include="Visual\TestCaseBeatmapOptionsOverlay.cs" />
<Compile Include="Visual\TestCaseBeatmapScoresContainer.cs" />
<Compile Include="Visual\TestCaseBeatmapSetOverlay.cs" />
<Compile Include="Visual\TestCaseBeatSnapVisualiser.cs" />
<Compile Include="Visual\TestCaseBeatSyncedContainer.cs" />
<Compile Include="Visual\TestCaseBreadcrumbs.cs" />
<Compile Include="Visual\TestCaseBreakOverlay.cs" />

View File

@ -0,0 +1,136 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Screens.Edit.Screens.Compose.BeatSnap
{
public class BeatSnapVisualiser : CompositeDrawable
{
public readonly Bindable<int> Divisor = new Bindable<int>(1);
private TickContainer tickContainer;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Size = new Vector2(100, 110);
Masking = true;
CornerRadius = 5;
InternalChildren = new Drawable[]
{
new Box
{
Name = "Background",
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black
},
new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[]
{
tickContainer = new TickContainer(1, 2, 3, 4, 6, 8, 12, 16)
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 5 }
}
},
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.Gray4
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 5 },
Child = new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[]
{
new DivisorButton
{
Icon = FontAwesome.fa_chevron_left,
},
null,
new DivisorButton
{
Icon = FontAwesome.fa_chevron_right,
}
},
new Drawable[]
{
null,
new TextFlowContainer(s => s.TextSize = 12)
{
Text = "beat snap divisor",
RelativeSizeAxes = Axes.X,
TextAnchor = Anchor.TopCentre
},
},
},
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, 20),
new Dimension(),
new Dimension(GridSizeMode.Absolute, 20)
}
}
}
}
}
},
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, 35),
}
}
};
tickContainer.Divisor.BindTo(Divisor);
}
private class DivisorButton : IconButton
{
public DivisorButton()
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
ButtonSize = new Vector2(20);
IconScale = new Vector2(0.7f);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
IconColour = Color4.Black;
HoverColour = colours.Gray7;
FlashColour = colours.Gray9;
}
}
}
}

View File

@ -0,0 +1,33 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using OpenTK;
namespace osu.Game.Screens.Edit.Screens.Compose.BeatSnap
{
public class Tick : Box
{
private readonly int divisor;
public Tick(int divisor)
{
this.divisor = divisor;
Size = new Vector2(2, 10);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
if (divisor >= 16)
Colour = colours.Red;
else if (divisor >= 8)
Colour = colours.Yellow;
else
Colour = colours.Gray4;
}
}
}

View File

@ -0,0 +1,69 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using OpenTK;
namespace osu.Game.Screens.Edit.Screens.Compose.BeatSnap
{
public class TickContainer : CompositeDrawable
{
public readonly BindableInt Divisor = new BindableInt();
public new MarginPadding Padding { set => base.Padding = value; }
private EquilateralTriangle marker;
private readonly int[] availableDivisors;
private readonly float tickSpacing;
public TickContainer(params int[] divisors)
{
availableDivisors = divisors;
tickSpacing = 1f / (availableDivisors.Length + 1);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
InternalChild = marker = new EquilateralTriangle
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomCentre,
RelativePositionAxes = Axes.X,
Height = 7,
EdgeSmoothness = new Vector2(1),
Colour = colours.Gray4,
};
for (int i = 0; i < availableDivisors.Length; i++)
{
AddInternal(new Tick(availableDivisors[i])
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopCentre,
RelativePositionAxes = Axes.X,
X = getTickPosition(i)
});
}
}
protected override void LoadComplete()
{
base.LoadComplete();
Divisor.ValueChanged += v => updatePosition();
updatePosition();
}
private void updatePosition() => marker.X = getTickPosition(Array.IndexOf(availableDivisors, Divisor.Value));
private float getTickPosition(int index) => (index + 1) * tickSpacing;
}
}

View File

@ -380,6 +380,9 @@
<Compile Include="Rulesets\Replays\Types\IConvertibleReplayFrame.cs" />
<Compile Include="Rulesets\Scoring\Legacy\LegacyScoreParser.cs" />
<Compile Include="Rulesets\UI\JudgementContainer.cs" />
<Compile Include="Screens\Edit\Screens\Compose\BeatSnap\BeatSnapVisualiser.cs" />
<Compile Include="Screens\Edit\Screens\Compose\BeatSnap\Tick.cs" />
<Compile Include="Screens\Edit\Screens\Compose\BeatSnap\TickContainer.cs" />
<Compile Include="Screens\Edit\Screens\Compose\Layers\BorderLayer.cs" />
<Compile Include="Screens\Edit\Screens\Compose\Layers\HitObjectMaskLayer.cs" />
<Compile Include="Screens\Edit\Screens\Compose\Layers\SelectionBox.cs" />