Allow different sizing modes for OverlinedParticipants

This commit is contained in:
smoogipoo 2020-02-19 17:37:01 +09:00
parent 380d200b46
commit ec73e8f0c7
6 changed files with 110 additions and 25 deletions

View File

@ -1,8 +1,10 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Screens.Multi.Components;
using osuTK;
@ -10,18 +12,46 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestSceneOverlinedParticipants : MultiplayerTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(OverlinedParticipants),
typeof(OverlinedDisplay),
typeof(ParticipantsList)
};
protected override bool UseOnlineAPI => true;
public TestSceneOverlinedParticipants()
{
Room.RoomID.Value = 7;
}
Add(new Container
[Test]
public void TestHorizontalLayout()
{
AddStep("create component", () =>
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(500),
Child = new OverlinedParticipants()
Child = new OverlinedParticipants(Direction.Horizontal)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 500,
AutoSizeAxes = Axes.Y,
};
});
}
[Test]
public void TestVerticalLayout()
{
AddStep("create component", () =>
{
Child = new OverlinedParticipants(Direction.Vertical)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(500)
};
});
}
}

View File

@ -14,6 +14,9 @@ namespace osu.Game.Graphics.Containers
{
public class OsuScrollContainer : ScrollContainer<Drawable>
{
public const float SCROLL_BAR_HEIGHT = 10;
public const float SCROLL_BAR_PADDING = 3;
/// <summary>
/// Allows controlling the scroll bar from any position in the container using the right mouse button.
/// Uses the value of <see cref="DistanceDecayOnRightMouseScrollbar"/> to smoothly scroll to the dragged location.
@ -96,8 +99,6 @@ protected override bool OnScroll(ScrollEvent e)
protected class OsuScrollbar : ScrollbarContainer
{
private const float dim_size = 10;
private Color4 hoverColour;
private Color4 defaultColour;
private Color4 highlightColour;
@ -135,7 +136,7 @@ private void load(OsuColour colours)
public override void ResizeTo(float val, int duration = 0, Easing easing = Easing.None)
{
Vector2 size = new Vector2(dim_size)
Vector2 size = new Vector2(SCROLL_BAR_HEIGHT)
{
[(int)ScrollDirection] = val
};

View File

@ -3,15 +3,43 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics.Containers;
namespace osu.Game.Screens.Multi.Components
{
public class OverlinedParticipants : OverlinedDisplay
{
public OverlinedParticipants()
public new Axes AutoSizeAxes
{
get => base.AutoSizeAxes;
set => base.AutoSizeAxes = value;
}
public OverlinedParticipants(Direction direction)
: base("Participants")
{
Content.Add(new ParticipantsList { RelativeSizeAxes = Axes.Both });
OsuScrollContainer scroll;
ParticipantsList list;
Content.Add(scroll = new OsuScrollContainer(direction)
{
Child = list = new ParticipantsList()
});
switch (direction)
{
case Direction.Horizontal:
scroll.RelativeSizeAxes = Axes.X;
scroll.Height = ParticipantsList.TILE_SIZE + OsuScrollContainer.SCROLL_BAR_HEIGHT + OsuScrollContainer.SCROLL_BAR_PADDING * 2;
list.AutoSizeAxes = Axes.Both;
break;
case Direction.Vertical:
scroll.RelativeSizeAxes = Axes.Both;
list.RelativeSizeAxes = Axes.X;
list.AutoSizeAxes = Axes.Y;
break;
}
}
[BackgroundDependencyLoader]

View File

@ -8,7 +8,6 @@
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Users;
@ -19,21 +18,39 @@ namespace osu.Game.Screens.Multi.Components
{
public class ParticipantsList : MultiplayerComposite
{
public const float TILE_SIZE = 70;
public override Axes RelativeSizeAxes
{
get => base.RelativeSizeAxes;
set
{
base.RelativeSizeAxes = value;
fill.RelativeSizeAxes = value;
}
}
public new Axes AutoSizeAxes
{
get => base.AutoSizeAxes;
set
{
base.AutoSizeAxes = value;
fill.AutoSizeAxes = value;
}
}
public FillDirection Direction
{
get => fill.Direction;
set => fill.Direction = value;
}
private readonly FillFlowContainer fill;
public ParticipantsList()
{
InternalChild = new OsuScrollContainer
{
RelativeSizeAxes = Axes.Both,
Child = fill = new FillFlowContainer
{
Spacing = new Vector2(10),
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Full,
}
};
InternalChild = fill = new FillFlowContainer { Spacing = new Vector2(10) };
}
[BackgroundDependencyLoader]

View File

@ -10,6 +10,7 @@
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi.Components;
@ -157,7 +158,15 @@ private void load(OsuColour colours)
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 10 },
Child = new ParticipantsList { RelativeSizeAxes = Axes.Both }
Child = new OsuScrollContainer
{
RelativeSizeAxes = Axes.Both,
Child = new ParticipantsList
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y
}
}
}
}
}

View File

@ -114,7 +114,7 @@ private void load()
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = 5 },
Child = new OverlinedParticipants { RelativeSizeAxes = Axes.Both }
Child = new OverlinedParticipants(Direction.Vertical) { RelativeSizeAxes = Axes.Both }
},
new Container
{