1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 18:07:25 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Lounge/Components/DrawableRoom.cs

337 lines
12 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;
2021-07-06 19:04:32 +08:00
using osu.Framework.Graphics.Colour;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
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.Framework.Graphics.UserInterface;
2018-04-13 17:19:50 +08:00
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;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Components;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
2018-04-13 17:19:50 +08:00
{
public class DrawableRoom : OsuClickableContainer, IStateful<SelectionState>, IFilterable, IHasContextMenu
2018-04-13 17:19:50 +08:00
{
2018-05-22 11:07:04 +08:00
public const float SELECTION_BORDER_WIDTH = 4;
2021-07-06 19:04:32 +08:00
private const float corner_radius = 10;
2018-05-28 12:02:15 +08:00
private const float transition_duration = 60;
2021-07-06 19:04:32 +08:00
private const float height = 100;
2018-04-13 17:19:50 +08:00
2018-12-04 14:26:06 +08:00
public event Action<SelectionState> StateChanged;
2021-07-06 19:04:32 +08:00
private Drawable selectionBox;
2018-12-13 17:38:03 +08:00
[Resolved(canBeNull: true)]
private OnlinePlayScreen parentScreen { get; set; }
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
{
2021-07-06 17:24:06 +08:00
if (value == state)
return;
2019-02-28 12:31:40 +08:00
2018-05-11 09:48:07 +08:00
state = value;
2021-07-06 17:24:06 +08:00
if (selectionBox != null)
{
if (state == SelectionState.Selected)
selectionBox.FadeIn(transition_duration);
else
selectionBox.FadeOut(transition_duration);
}
2018-05-11 09:48:07 +08:00
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;
2021-07-12 13:07:21 +08:00
Height = height;
2018-05-22 11:07:04 +08:00
CornerRadius = corner_radius + SELECTION_BORDER_WIDTH / 2;
2018-04-13 17:19:50 +08:00
Masking = true;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2018-04-13 17:19:50 +08:00
Children = new Drawable[]
{
new Container
{
2021-07-06 19:04:32 +08:00
Name = @"Room content",
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
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
{
2021-07-12 15:30:34 +08:00
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex(@"#27302E"),
},
2018-12-06 11:21:30 +08:00
new Container
2018-05-11 09:48:07 +08:00
{
2021-07-06 19:04:32 +08:00
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fill,
Child = new OnlinePlayBackgroundSprite(BeatmapSetCoverType.List) { RelativeSizeAxes = Axes.Both }
2018-04-13 17:19:50 +08:00
},
2021-07-12 13:07:21 +08:00
new GridContainer
2021-07-06 19:04:32 +08:00
{
RelativeSizeAxes = Axes.Both,
2021-07-12 13:07:21 +08:00
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Relative, 0.2f)
},
Content = new[]
{
new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex(@"#27302E"),
},
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(Color4Extensions.FromHex(@"#27302E"), Color4Extensions.FromHex(@"#27302E").Opacity(0.3f))
},
}
}
2021-07-06 19:04:32 +08:00
},
2018-05-11 09:48:07 +08:00
new Container
2018-04-13 17:19:50 +08:00
{
2021-07-06 19:04:32 +08:00
Name = @"Left details",
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
2018-04-13 17:19:50 +08:00
{
2021-07-06 19:04:32 +08:00
Left = 20,
Vertical = 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
{
2021-07-12 14:11:53 +08:00
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(4),
Children = new Drawable[]
{
new RoomStatusPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
},
new EndDateInfo
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
},
}
},
2021-07-12 15:28:22 +08:00
new FillFlowContainer
2018-04-13 17:19:50 +08:00
{
2021-07-06 19:04:32 +08:00
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
2021-07-12 15:28:22 +08:00
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new RoomNameText(),
new RoomHostText()
}
2018-05-11 09:48:07 +08:00
},
new FillFlowContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
2021-07-06 19:04:32 +08:00
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
2021-07-12 14:11:07 +08:00
Spacing = new Vector2(4),
2018-05-11 09:48:07 +08:00
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
2021-07-12 14:11:53 +08:00
new PlaylistCountPill
2021-07-12 14:11:07 +08:00
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
new StarRatingRangeDisplay
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Scale = new Vector2(0.85f)
}
2021-07-06 19:04:32 +08:00
}
}
}
2018-04-13 17:19:50 +08:00
},
},
},
},
2021-07-06 19:04:32 +08:00
new StatusColouredContainer(transition_duration)
{
RelativeSizeAxes = Axes.Both,
Child = selectionBox = new Container
{
RelativeSizeAxes = Axes.Both,
Alpha = state == SelectionState.Selected ? 1 : 0,
Masking = true,
CornerRadius = corner_radius,
BorderThickness = SELECTION_BORDER_WIDTH,
BorderColour = Color4.White,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true
}
}
},
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)
{
return new CachedModelDependencyContainer<Room>(base.CreateChildDependencies(parent))
{
Model = { Value = Room }
};
2019-02-05 18:00:01 +08:00
}
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;
2021-07-12 15:28:22 +08:00
private class RoomNameText : OsuSpriteText
2019-02-06 12:52:48 +08:00
{
2020-12-25 12:38:11 +08:00
[Resolved(typeof(Room), nameof(Online.Rooms.Room.Name))]
2019-02-06 12:52:48 +08:00
private Bindable<string> name { get; set; }
2021-07-12 15:28:22 +08:00
public RoomNameText()
{
Font = OsuFont.GetFont(size: 24);
}
2019-02-06 12:52:48 +08:00
[BackgroundDependencyLoader]
private void load()
{
Current = name;
}
}
2021-07-12 15:28:22 +08:00
private class RoomHostText : OnlinePlayComposite
{
private LinkFlowContainer hostText;
public RoomHostText()
{
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = hostText = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14))
{
AutoSizeAxes = Axes.Both
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Host.BindValueChanged(host =>
{
hostText.Clear();
if (host.NewValue != null)
{
hostText.AddText("hosted by ");
hostText.AddUserLink(host.NewValue);
}
}, true);
}
}
public MenuItem[] ContextMenuItems => new MenuItem[]
{
new OsuMenuItem("Create copy", MenuItemType.Standard, () =>
{
parentScreen?.OpenNewRoom(Room.CreateCopy());
})
};
2018-04-13 17:19:50 +08:00
}
}