mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 09:47:52 +08:00
Merge pull request #2522 from DrabWeb/drawable-room-improvements
DrawableRoom improvements
This commit is contained in:
commit
416356492b
@ -6,6 +6,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Multi.Components;
|
||||
@ -111,6 +112,7 @@ namespace osu.Game.Tests.Visual
|
||||
}
|
||||
});
|
||||
|
||||
AddStep(@"select", () => first.State = SelectionState.Selected);
|
||||
AddStep(@"change title", () => first.Room.Name.Value = @"I Changed Name");
|
||||
AddStep(@"change host", () => first.Room.Host.Value = new User { Username = @"DrabWeb", Id = 6946022, Country = new Country { FlagName = @"CA" } });
|
||||
AddStep(@"change status", () => first.Room.Status.Value = new RoomStatusPlaying());
|
||||
@ -121,6 +123,7 @@ namespace osu.Game.Tests.Visual
|
||||
new User { Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 1254 } } },
|
||||
new User { Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 123189 } } },
|
||||
});
|
||||
AddStep(@"deselect", () => first.State = SelectionState.NotSelected);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
11
osu.Game/Graphics/UserInterface/SelectionState.cs
Normal file
11
osu.Game/Graphics/UserInterface/SelectionState.cs
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public enum SelectionState
|
||||
{
|
||||
NotSelected,
|
||||
Selected
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ using osu.Framework;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using OpenTK;
|
||||
|
||||
@ -137,10 +138,4 @@ namespace osu.Game.Rulesets.Edit
|
||||
/// </summary>
|
||||
public virtual Quad SelectionQuad => ScreenSpaceDrawQuad;
|
||||
}
|
||||
|
||||
public enum SelectionState
|
||||
{
|
||||
NotSelected,
|
||||
Selected
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
// 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;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
@ -13,6 +15,7 @@ using osu.Game.Beatmaps.Drawables;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Users;
|
||||
using OpenTK;
|
||||
@ -20,20 +23,17 @@ using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Multi.Components
|
||||
{
|
||||
public class DrawableRoom : OsuClickableContainer
|
||||
public class DrawableRoom : OsuClickableContainer, IStateful<SelectionState>
|
||||
{
|
||||
private const float corner_radius = 5;
|
||||
private const float selection_border_width = 4;
|
||||
private const float transition_duration = 100;
|
||||
private const float content_padding = 10;
|
||||
private const float height = 100;
|
||||
private const float side_strip_width = 5;
|
||||
private const float cover_width = 145;
|
||||
|
||||
private readonly Box sideStrip;
|
||||
private readonly Container coverContainer;
|
||||
private readonly OsuSpriteText name, status, beatmapTitle, beatmapDash, beatmapArtist;
|
||||
private readonly FillFlowContainer<OsuSpriteText> beatmapInfoFlow;
|
||||
private readonly ParticipantInfo participantInfo;
|
||||
private readonly ModeTypeInfo modeTypeInfo;
|
||||
private readonly Box selectionBox;
|
||||
|
||||
private readonly Bindable<string> nameBind = new Bindable<string>();
|
||||
private readonly Bindable<User> hostBind = new Bindable<User>();
|
||||
@ -42,26 +42,74 @@ namespace osu.Game.Screens.Multi.Components
|
||||
private readonly Bindable<BeatmapInfo> beatmapBind = new Bindable<BeatmapInfo>();
|
||||
private readonly Bindable<User[]> participantsBind = new Bindable<User[]>();
|
||||
|
||||
private OsuColour colours;
|
||||
private LocalisationEngine localisation;
|
||||
|
||||
public readonly Room Room;
|
||||
|
||||
private SelectionState state;
|
||||
public SelectionState State
|
||||
{
|
||||
get { return state; }
|
||||
set
|
||||
{
|
||||
if (value == state) return;
|
||||
state = value;
|
||||
|
||||
if (state == SelectionState.Selected)
|
||||
selectionBox.FadeIn(transition_duration);
|
||||
else
|
||||
selectionBox.FadeOut(transition_duration);
|
||||
|
||||
StateChanged?.Invoke(State);
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<SelectionState> StateChanged;
|
||||
|
||||
public DrawableRoom(Room room)
|
||||
{
|
||||
Room = room;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = height;
|
||||
CornerRadius = 5;
|
||||
Height = height + selection_border_width * 2;
|
||||
CornerRadius = corner_radius + selection_border_width / 2;
|
||||
Masking = true;
|
||||
|
||||
// create selectionBox here so State can be set before being loaded
|
||||
selectionBox = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0f,
|
||||
};
|
||||
|
||||
Action += () => State = SelectionState.Selected;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours, LocalisationEngine localisation)
|
||||
{
|
||||
Box sideStrip;
|
||||
Container coverContainer;
|
||||
OsuSpriteText name, status, beatmapTitle, beatmapDash, beatmapArtist;
|
||||
ParticipantInfo participantInfo;
|
||||
ModeTypeInfo modeTypeInfo;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
selectionBox,
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding(selection_border_width),
|
||||
Child = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
CornerRadius = corner_radius,
|
||||
EdgeEffect = new EdgeEffectParameters
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Colour = Color4.Black.Opacity(40),
|
||||
Radius = 5,
|
||||
};
|
||||
|
||||
},
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
@ -133,10 +181,11 @@ namespace osu.Game.Screens.Multi.Components
|
||||
TextSize = 14,
|
||||
Font = @"Exo2.0-Bold",
|
||||
},
|
||||
beatmapInfoFlow = new FillFlowContainer<OsuSpriteText>
|
||||
new FillFlowContainer<OsuSpriteText>
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Colour = colours.Gray9,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Children = new[]
|
||||
{
|
||||
@ -166,81 +215,43 @@ namespace osu.Game.Screens.Multi.Components
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
nameBind.ValueChanged += displayName;
|
||||
hostBind.ValueChanged += displayUser;
|
||||
typeBind.ValueChanged += displayGameType;
|
||||
participantsBind.ValueChanged += displayParticipants;
|
||||
nameBind.ValueChanged += n => name.Text = n;
|
||||
hostBind.ValueChanged += h => participantInfo.Host = h;
|
||||
typeBind.ValueChanged += m => modeTypeInfo.Type = m;
|
||||
participantsBind.ValueChanged += p => participantInfo.Participants = p;
|
||||
|
||||
nameBind.BindTo(Room.Name);
|
||||
hostBind.BindTo(Room.Host);
|
||||
statusBind.BindTo(Room.Status);
|
||||
typeBind.BindTo(Room.Type);
|
||||
beatmapBind.BindTo(Room.Beatmap);
|
||||
participantsBind.BindTo(Room.Participants);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours, LocalisationEngine localisation)
|
||||
statusBind.ValueChanged += s =>
|
||||
{
|
||||
this.localisation = localisation;
|
||||
this.colours = colours;
|
||||
status.Text = s.Message;
|
||||
|
||||
beatmapInfoFlow.Colour = colours.Gray9;
|
||||
foreach (Drawable d in new Drawable[] { selectionBox, sideStrip, status })
|
||||
d.FadeColour(s.GetAppropriateColour(colours), 100);
|
||||
};
|
||||
|
||||
//binded here instead of ctor because dependencies are needed
|
||||
statusBind.ValueChanged += displayStatus;
|
||||
beatmapBind.ValueChanged += displayBeatmap;
|
||||
|
||||
statusBind.TriggerChange();
|
||||
beatmapBind.TriggerChange();
|
||||
}
|
||||
|
||||
private void displayName(string value)
|
||||
beatmapBind.ValueChanged += b =>
|
||||
{
|
||||
name.Text = value;
|
||||
}
|
||||
modeTypeInfo.Beatmap = b;
|
||||
|
||||
private void displayUser(User value)
|
||||
{
|
||||
participantInfo.Host = value;
|
||||
}
|
||||
|
||||
private void displayStatus(RoomStatus value)
|
||||
{
|
||||
if (value == null) return;
|
||||
status.Text = value.Message;
|
||||
|
||||
foreach (Drawable d in new Drawable[] { sideStrip, status })
|
||||
d.FadeColour(value.GetAppropriateColour(colours), 100);
|
||||
}
|
||||
|
||||
private void displayGameType(GameType value)
|
||||
{
|
||||
modeTypeInfo.Type = value;
|
||||
}
|
||||
|
||||
private void displayBeatmap(BeatmapInfo value)
|
||||
{
|
||||
modeTypeInfo.Beatmap = value;
|
||||
|
||||
if (value != null)
|
||||
if (b != null)
|
||||
{
|
||||
coverContainer.FadeIn(transition_duration);
|
||||
|
||||
LoadComponentAsync(new BeatmapSetCover(value.BeatmapSet)
|
||||
LoadComponentAsync(new BeatmapSetCover(b.BeatmapSet)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
FillMode = FillMode.Fill,
|
||||
OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out),
|
||||
},
|
||||
coverContainer.Add);
|
||||
}, coverContainer.Add);
|
||||
|
||||
beatmapTitle.Current = localisation.GetUnicodePreference(value.Metadata.TitleUnicode, value.Metadata.Title);
|
||||
beatmapTitle.Current = localisation.GetUnicodePreference(b.Metadata.TitleUnicode, b.Metadata.Title);
|
||||
beatmapDash.Text = @" - ";
|
||||
beatmapArtist.Current = localisation.GetUnicodePreference(value.Metadata.ArtistUnicode, value.Metadata.Artist);
|
||||
beatmapArtist.Current = localisation.GetUnicodePreference(b.Metadata.ArtistUnicode, b.Metadata.Artist);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -252,11 +263,14 @@ namespace osu.Game.Screens.Multi.Components
|
||||
beatmapTitle.Text = "Changing map";
|
||||
beatmapDash.Text = beatmapArtist.Text = string.Empty;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void displayParticipants(User[] value)
|
||||
{
|
||||
participantInfo.Participants = value;
|
||||
nameBind.BindTo(Room.Name);
|
||||
hostBind.BindTo(Room.Host);
|
||||
statusBind.BindTo(Room.Status);
|
||||
typeBind.BindTo(Room.Type);
|
||||
beatmapBind.BindTo(Room.Beatmap);
|
||||
participantsBind.BindTo(Room.Participants);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user