mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 08:02:55 +08:00
Added UserPanel and UserStatus
This commit is contained in:
parent
f8c419f9ba
commit
7ce3b73ecd
40
osu.Desktop.VisualTests/Tests/TestCaseUserPanel.cs
Normal file
40
osu.Desktop.VisualTests/Tests/TestCaseUserPanel.cs
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Desktop.VisualTests.Tests
|
||||
{
|
||||
internal class TestCaseUserPanel : TestCase
|
||||
{
|
||||
public override string Description => @"Panels for displaying a user's status";
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
|
||||
UserPanel p;
|
||||
Add(p = new UserPanel(new User
|
||||
{
|
||||
Username = @"flyte",
|
||||
Id = 3103765,
|
||||
Country = new Country { FlagName = @"JP" },
|
||||
CoverUrl = @"https://assets.ppy.sh/user-profile-covers/3103765/5b012e13611d5761caa7e24fecb3d3a16e1cf48fc2a3032cfd43dd444af83d82.jpeg"
|
||||
})
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Width = 300,
|
||||
});
|
||||
|
||||
p.Status.Value = new UserStatusOnline();
|
||||
|
||||
AddStep(@"spectating", () => { p.Status.Value = new UserStatusSpectating(); });
|
||||
AddStep(@"multiplaying", () => { p.Status.Value = new UserStatusMultiplayerGame(); });
|
||||
AddStep(@"modding", () => { p.Status.Value = new UserStatusModding(); });
|
||||
}
|
||||
}
|
||||
}
|
@ -220,6 +220,7 @@
|
||||
<Compile Include="Tests\TestCaseLeaderboard.cs" />
|
||||
<Compile Include="Beatmaps\TestWorkingBeatmap.cs" />
|
||||
<Compile Include="Tests\TestCaseBeatmapDetailArea.cs" />
|
||||
<Compile Include="Tests\TestCaseUserPanel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup />
|
||||
|
183
osu.Game/Users/UserPanel.cs
Normal file
183
osu.Game/Users/UserPanel.cs
Normal file
@ -0,0 +1,183 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
|
||||
namespace osu.Game.Users
|
||||
{
|
||||
public class UserPanel : Container
|
||||
{
|
||||
private const float height = 100;
|
||||
private const float content_padding = 10;
|
||||
private const float status_height = 30;
|
||||
|
||||
private readonly User user;
|
||||
private OsuColour colours;
|
||||
|
||||
private readonly Container cover;
|
||||
private readonly Box statusBg;
|
||||
private readonly OsuSpriteText statusMessage;
|
||||
|
||||
public readonly Bindable<UserStatus> Status = new Bindable<UserStatus>();
|
||||
|
||||
public UserPanel(User user)
|
||||
{
|
||||
this.user = user;
|
||||
|
||||
Height = height;
|
||||
Masking = true;
|
||||
CornerRadius = 5;
|
||||
EdgeEffect = new EdgeEffect
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Colour = Color4.Black.Opacity(0.25f),
|
||||
Radius = 4,
|
||||
};
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
cover = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black.Opacity(0.7f),
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Top = content_padding, Bottom = status_height + content_padding, Left = content_padding, Right = content_padding },
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new UpdateableAvatar
|
||||
{
|
||||
Size = new Vector2(height - status_height - content_padding * 2),
|
||||
User = user,
|
||||
Masking = true,
|
||||
CornerRadius = 5,
|
||||
EdgeEffect = new EdgeEffect
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Colour = Color4.Black.Opacity(0.25f),
|
||||
Radius = 4,
|
||||
},
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Margin = new MarginPadding { Left = height - status_height - content_padding },
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = user.Username,
|
||||
TextSize = 18,
|
||||
Font = @"Exo2.0-SemiBoldItalic",
|
||||
},
|
||||
new FillFlowContainer
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
AutoSizeAxes = Axes.X,
|
||||
Height = 20f,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(5f, 0f),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new DrawableFlag(user.Country?.FlagName ?? @"__")
|
||||
{
|
||||
Width = 30f,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Width = 40f,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
},
|
||||
new CircularContainer
|
||||
{
|
||||
Width = 20f,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = status_height,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
statusBg = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0.5f,
|
||||
},
|
||||
new FillFlowContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Spacing = new Vector2(5f, 0f),
|
||||
Children = new[]
|
||||
{
|
||||
new TextAwesome
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Icon = FontAwesome.fa_circle_o,
|
||||
Shadow = true,
|
||||
TextSize = 14,
|
||||
},
|
||||
statusMessage = new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Font = @"Exo2.0-Semibold",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Status.ValueChanged += displayStatus;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours, TextureStore textures)
|
||||
{
|
||||
this.colours = colours;
|
||||
|
||||
cover.Add(new AsyncLoadWrapper(new Sprite
|
||||
{
|
||||
Texture = textures.Get(user.CoverUrl),
|
||||
FillMode = FillMode.Fill,
|
||||
OnLoadComplete = d => d.FadeInFromZero(200),
|
||||
}) { RelativeSizeAxes = Axes.Both });
|
||||
}
|
||||
|
||||
private void displayStatus(UserStatus status)
|
||||
{
|
||||
statusBg.FadeColour(status.Colour(colours), 200);
|
||||
statusMessage.Text = status.Message;
|
||||
}
|
||||
}
|
||||
}
|
55
osu.Game/Users/UserStatus.cs
Normal file
55
osu.Game/Users/UserStatus.cs
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using osu.Game.Graphics;
|
||||
|
||||
namespace osu.Game.Users
|
||||
{
|
||||
public abstract class UserStatus
|
||||
{
|
||||
public abstract string Message { get; }
|
||||
public abstract Color4 Colour(OsuColour colours);
|
||||
}
|
||||
|
||||
public abstract class UserStatusAvailable : UserStatus
|
||||
{
|
||||
public override Color4 Colour(OsuColour colours) => colours.BlueDarker;
|
||||
}
|
||||
|
||||
public abstract class UserStatusBusy : UserStatus
|
||||
{
|
||||
public override Color4 Colour(OsuColour colours) => colours.YellowDark;
|
||||
}
|
||||
|
||||
public class UserStatusOnline : UserStatusAvailable
|
||||
{
|
||||
public override string Message => @"Online";
|
||||
}
|
||||
|
||||
public class UserStatusSpectating : UserStatusAvailable
|
||||
{
|
||||
public override string Message => @"Spectating a game";
|
||||
}
|
||||
|
||||
public class UserStatusInLobby : UserStatusAvailable
|
||||
{
|
||||
public override string Message => @"in Multiplayer Lobby";
|
||||
}
|
||||
|
||||
public class UserStatusSoloGame : UserStatusBusy
|
||||
{
|
||||
public override string Message => @"Solo Game";
|
||||
}
|
||||
|
||||
public class UserStatusMultiplayerGame: UserStatusBusy
|
||||
{
|
||||
public override string Message => @"Multiplaying";
|
||||
}
|
||||
|
||||
public class UserStatusModding : UserStatus
|
||||
{
|
||||
public override string Message => @"Modding a map";
|
||||
public override Color4 Colour(OsuColour colours) => colours.PurpleDark;
|
||||
}
|
||||
}
|
@ -425,6 +425,8 @@
|
||||
<Compile Include="Overlays\Music\PlaylistOverlay.cs" />
|
||||
<Compile Include="Rulesets\Replays\IAutoGenerator.cs" />
|
||||
<Compile Include="Rulesets\Replays\AutoGenerator.cs" />
|
||||
<Compile Include="Users\UserPanel.cs" />
|
||||
<Compile Include="Users\UserStatus.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\osu-framework\osu.Framework\osu.Framework.csproj">
|
||||
|
Loading…
Reference in New Issue
Block a user