1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 07:27:51 +08:00
osu-lazer/osu.Game/Screens/Multi/Lounge/Components/DrawableRoom.cs

237 lines
8.7 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2018-05-11 09:48:07 +08:00
using System;
2018-05-22 11:33:41 +08:00
using System.Collections.Generic;
2018-05-11 09:48:07 +08:00
using osu.Framework;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-04-02 13:51:28 +08:00
using osu.Framework.Graphics.Effects;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
2018-05-11 09:48:07 +08:00
using osu.Game.Graphics.UserInterface;
2018-04-13 17:19:50 +08:00
using osu.Game.Online.Multiplayer;
2018-12-10 18:20:41 +08:00
using osu.Game.Screens.Multi.Components;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
2018-12-10 18:20:41 +08:00
namespace osu.Game.Screens.Multi.Lounge.Components
2018-04-13 17:19:50 +08:00
{
2018-05-22 11:33:41 +08:00
public class DrawableRoom : OsuClickableContainer, IStateful<SelectionState>, IFilterable
2018-04-13 17:19:50 +08:00
{
2018-05-22 11:07:04 +08:00
public const float SELECTION_BORDER_WIDTH = 4;
2018-05-11 09:48:07 +08:00
private const float corner_radius = 5;
2018-05-28 12:02:15 +08:00
private const float transition_duration = 60;
2018-04-13 17:19:50 +08:00
private const float content_padding = 10;
2018-12-19 14:20:23 +08:00
private const float height = 110;
2018-04-13 17:19:50 +08:00
private const float side_strip_width = 5;
private const float cover_width = 145;
2018-12-04 14:26:06 +08:00
public event Action<SelectionState> StateChanged;
2018-12-22 13:01:06 +08:00
private readonly Box selectionBox;
2019-02-05 18:00:01 +08:00
private CachedModelDependencyContainer<Room> dependencies;
2018-12-13 17:38:03 +08:00
2018-12-06 11:21:30 +08:00
[Resolved]
private BeatmapManager beatmaps { get; set; }
2018-04-13 17:19:50 +08:00
public readonly Room Room;
2018-05-11 09:48:07 +08:00
private SelectionState state;
2019-02-28 12:31:40 +08:00
2018-05-11 09:48:07 +08:00
public SelectionState State
{
get => state;
2018-05-11 09:48:07 +08:00
set
{
if (value == state) return;
2019-02-28 12:31:40 +08:00
2018-05-11 09:48:07 +08:00
state = value;
if (state == SelectionState.Selected)
selectionBox.FadeIn(transition_duration);
else
selectionBox.FadeOut(transition_duration);
StateChanged?.Invoke(State);
}
}
2018-05-22 11:33:41 +08:00
public IEnumerable<string> FilterTerms => new[] { Room.Name.Value };
private bool matchingFilter;
2019-02-28 12:31:40 +08:00
2018-05-22 11:33:41 +08:00
public bool MatchingFilter
{
get => matchingFilter;
2018-05-22 11:33:41 +08:00
set
{
matchingFilter = value;
if (!IsLoaded)
return;
if (matchingFilter)
this.FadeIn(200);
else
Hide();
2018-05-22 11:33:41 +08:00
}
}
2019-03-28 23:29:07 +08:00
public bool FilteringActive { get; set; }
2018-04-13 17:19:50 +08:00
public DrawableRoom(Room room)
{
Room = room;
RelativeSizeAxes = Axes.X;
2018-05-22 11:07:04 +08:00
Height = height + SELECTION_BORDER_WIDTH * 2;
CornerRadius = corner_radius + SELECTION_BORDER_WIDTH / 2;
2018-04-13 17:19:50 +08:00
Masking = true;
2018-05-11 09:48:07 +08:00
// create selectionBox here so State can be set before being loaded
selectionBox = new Box
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
Alpha = 0f,
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
float stripWidth = side_strip_width * (Room.Category.Value == RoomCategory.Spotlight ? 2 : 1);
2018-04-13 17:19:50 +08:00
Children = new Drawable[]
{
new StatusColouredContainer(transition_duration)
2019-02-06 12:52:48 +08:00
{
RelativeSizeAxes = Axes.Both,
Child = selectionBox
},
2018-04-13 17:19:50 +08:00
new Container
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
2018-05-22 11:07:04 +08:00
Padding = new MarginPadding(SELECTION_BORDER_WIDTH),
2018-05-11 09:48:07 +08:00
Child = new Container
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
Masking = true,
CornerRadius = corner_radius,
EdgeEffect = new EdgeEffectParameters
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(40),
Radius = 5,
2018-04-13 17:19:50 +08:00
},
2018-05-11 09:48:07 +08:00
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
new Box
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex(@"212121"),
2018-05-11 09:48:07 +08:00
},
new StatusColouredContainer(transition_duration)
2018-05-11 09:48:07 +08:00
{
RelativeSizeAxes = Axes.Y,
Width = stripWidth,
2019-02-06 12:52:48 +08:00
Child = new Box { RelativeSizeAxes = Axes.Both }
2018-05-11 09:48:07 +08:00
},
2018-12-06 11:21:30 +08:00
new Container
2018-05-11 09:48:07 +08:00
{
RelativeSizeAxes = Axes.Y,
2018-12-06 11:21:30 +08:00
Width = cover_width,
2018-05-11 09:48:07 +08:00
Masking = true,
Margin = new MarginPadding { Left = stripWidth },
2019-03-05 17:59:25 +08:00
Child = new MultiplayerBackgroundSprite(BeatmapSetCoverType.List) { RelativeSizeAxes = Axes.Both }
2018-04-13 17:19:50 +08:00
},
2018-05-11 09:48:07 +08:00
new Container
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
Vertical = content_padding,
Left = stripWidth + cover_width + content_padding,
2018-05-11 09:48:07 +08:00
Right = content_padding,
2018-04-13 17:19:50 +08:00
},
2018-05-11 09:48:07 +08:00
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
new FillFlowContainer
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(5f),
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
new RoomName { Font = OsuFont.GetFont(size: 18) },
2019-02-05 18:00:01 +08:00
new ParticipantInfo(),
2018-04-13 17:19:50 +08:00
},
2018-05-11 09:48:07 +08:00
},
new FillFlowContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
2018-05-11 09:48:07 +08:00
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
2019-02-05 18:00:01 +08:00
new RoomStatusInfo(),
new BeatmapTitle { TextSize = 14 },
2018-04-13 17:19:50 +08:00
},
},
2019-02-05 18:00:01 +08:00
new ModeTypeInfo
2018-05-11 09:48:07 +08:00
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
},
2018-04-13 17:19:50 +08:00
},
},
},
},
},
};
}
2018-05-22 11:07:04 +08:00
2019-02-05 18:00:01 +08:00
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
dependencies = new CachedModelDependencyContainer<Room>(base.CreateChildDependencies(parent));
dependencies.Model.Value = Room;
return dependencies;
}
protected override void LoadComplete()
{
base.LoadComplete();
if (matchingFilter)
this.FadeInFromZero(transition_duration);
else
Alpha = 0;
}
2019-02-06 12:52:48 +08:00
protected override bool ShouldBeConsideredForInput(Drawable child) => state == SelectionState.Selected;
2019-02-06 12:52:48 +08:00
private class RoomName : OsuSpriteText
{
[Resolved(typeof(Room), nameof(Online.Multiplayer.Room.Name))]
private Bindable<string> name { get; set; }
[BackgroundDependencyLoader]
private void load()
{
Current = name;
}
}
2018-04-13 17:19:50 +08:00
}
}