mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 06:52:56 +08:00
Merge pull request #852 from DrabWeb/user-dropdown
Update user dropdown
This commit is contained in:
commit
7a369547fd
@ -42,7 +42,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
protected override DropdownMenuItem<T> CreateMenuItem(string text, T value) => new OsuDropdownMenuItem(text, value) { AccentColour = AccentColour };
|
||||
|
||||
private class OsuDropdownMenuItem : DropdownMenuItem<T>
|
||||
public class OsuDropdownMenuItem : DropdownMenuItem<T>
|
||||
{
|
||||
public OsuDropdownMenuItem(string text, T current) : base(text, current)
|
||||
{
|
||||
@ -60,7 +60,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
chevron = new TextAwesome
|
||||
Chevron = new TextAwesome
|
||||
{
|
||||
AlwaysPresent = true,
|
||||
Icon = FontAwesome.fa_chevron_right,
|
||||
@ -84,12 +84,12 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
private Color4? accentColour;
|
||||
|
||||
private readonly TextAwesome chevron;
|
||||
protected readonly TextAwesome Chevron;
|
||||
|
||||
protected override void FormatForeground(bool hover = false)
|
||||
{
|
||||
base.FormatForeground(hover);
|
||||
chevron.Alpha = hover ? 1 : 0;
|
||||
Chevron.Alpha = hover ? 1 : 0;
|
||||
}
|
||||
|
||||
public Color4 AccentColour
|
||||
@ -115,11 +115,11 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
public class OsuDropdownHeader : DropdownHeader
|
||||
{
|
||||
private readonly SpriteText label;
|
||||
protected readonly SpriteText Text;
|
||||
protected override string Label
|
||||
{
|
||||
get { return label.Text; }
|
||||
set { label.Text = value; }
|
||||
get { return Text.Text; }
|
||||
set { Text.Text = value; }
|
||||
}
|
||||
|
||||
protected readonly TextAwesome Icon;
|
||||
@ -146,7 +146,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
Foreground.Children = new Drawable[]
|
||||
{
|
||||
label = new OsuSpriteText
|
||||
Text = new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
|
@ -13,15 +13,20 @@ using osu.Game.Online.API;
|
||||
using OpenTK;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Users;
|
||||
using System.ComponentModel;
|
||||
using osu.Game.Graphics;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
|
||||
using Container = osu.Framework.Graphics.Containers.Container;
|
||||
|
||||
namespace osu.Game.Overlays.Settings.Sections.General
|
||||
{
|
||||
public class LoginSettings : SettingsSubsection, IOnlineComponent
|
||||
public class LoginSettings : FillFlowContainer, IOnlineComponent
|
||||
{
|
||||
private bool bounding = true;
|
||||
private LoginForm form;
|
||||
|
||||
protected override string Header => "Account";
|
||||
private OsuColour colours;
|
||||
|
||||
public override RectangleF BoundingBox => bounding ? base.BoundingBox : RectangleF.Empty;
|
||||
|
||||
@ -35,9 +40,18 @@ namespace osu.Game.Overlays.Settings.Sections.General
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load(APIAccess api)
|
||||
public LoginSettings()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Direction = FillDirection.Vertical;
|
||||
Spacing = new Vector2(0f, 5f);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load(OsuColour colours, APIAccess api)
|
||||
{
|
||||
this.colours = colours;
|
||||
api?.Register(this);
|
||||
}
|
||||
|
||||
@ -50,6 +64,12 @@ namespace osu.Game.Overlays.Settings.Sections.General
|
||||
case APIState.Offline:
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = "ACCOUNT",
|
||||
Margin = new MarginPadding { Bottom = 5 },
|
||||
Font = @"Exo2.0-Black",
|
||||
},
|
||||
form = new LoginForm()
|
||||
};
|
||||
break;
|
||||
@ -67,24 +87,78 @@ namespace osu.Game.Overlays.Settings.Sections.General
|
||||
{
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Text = "Connecting...",
|
||||
Margin = new MarginPadding { Top = 10, Bottom = 10 },
|
||||
},
|
||||
};
|
||||
break;
|
||||
case APIState.Online:
|
||||
UserDropdown dropdown;
|
||||
UserPanel panel;
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new UserPanel(api.LocalUser.Value)
|
||||
new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = new MarginPadding { Left = 20, Right = 20 },
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(0f, 10f),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Children = new[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Text = "Signed in",
|
||||
TextSize = 18,
|
||||
Font = @"Exo2.0-Bold",
|
||||
Margin = new MarginPadding { Top = 5, Bottom = 5 },
|
||||
},
|
||||
},
|
||||
},
|
||||
panel = new UserPanel(api.LocalUser.Value)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
},
|
||||
dropdown = new UserDropdown
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
},
|
||||
},
|
||||
},
|
||||
new OsuButton
|
||||
};
|
||||
panel.Status.BindTo(api.LocalUser.Value.Status);
|
||||
dropdown.Current.ValueChanged += newValue =>
|
||||
{
|
||||
switch (newValue)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Text = "Sign out",
|
||||
Action = api.Logout
|
||||
case UserAction.Online:
|
||||
api.LocalUser.Value.Status.Value = new UserStatusOnline();
|
||||
dropdown.StatusColour = colours.Green;
|
||||
break;
|
||||
case UserAction.DoNotDisturb:
|
||||
api.LocalUser.Value.Status.Value = new UserStatusDoNotDisturb();
|
||||
dropdown.StatusColour = colours.Red;
|
||||
break;
|
||||
case UserAction.AppearOffline:
|
||||
api.LocalUser.Value.Status.Value = new UserStatusOffline();
|
||||
dropdown.StatusColour = colours.Gray7;
|
||||
break;
|
||||
case UserAction.SignOut:
|
||||
api.Logout();
|
||||
break;
|
||||
}
|
||||
};
|
||||
dropdown.Current.TriggerChange();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -171,5 +245,119 @@ namespace osu.Game.Overlays.Settings.Sections.General
|
||||
return base.OnFocus(state);
|
||||
}
|
||||
}
|
||||
|
||||
private class UserDropdown : OsuEnumDropdown<UserAction>
|
||||
{
|
||||
protected override DropdownHeader CreateHeader() => new UserDropdownHeader { AccentColour = AccentColour };
|
||||
protected override Menu CreateMenu() => new UserDropdownMenu();
|
||||
protected override DropdownMenuItem<UserAction> CreateMenuItem(string text, UserAction value) => new UserDropdownMenuItem(text, value) { AccentColour = AccentColour };
|
||||
|
||||
public Color4 StatusColour
|
||||
{
|
||||
set
|
||||
{
|
||||
var h = Header as UserDropdownHeader;
|
||||
if (h == null) return;
|
||||
h.StatusColour = value;
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
AccentColour = colours.Gray5;
|
||||
}
|
||||
|
||||
private class UserDropdownHeader : OsuDropdownHeader
|
||||
{
|
||||
public const float LABEL_LEFT_MARGIN = 20;
|
||||
|
||||
private readonly TextAwesome statusIcon;
|
||||
public Color4 StatusColour
|
||||
{
|
||||
set
|
||||
{
|
||||
statusIcon.FadeColour(value, 500, EasingTypes.OutQuint);
|
||||
}
|
||||
}
|
||||
|
||||
public UserDropdownHeader()
|
||||
{
|
||||
Foreground.Padding = new MarginPadding { Left = 10, Right = 10 };
|
||||
Margin = new MarginPadding { Bottom = 5 };
|
||||
Masking = true;
|
||||
CornerRadius = 5;
|
||||
EdgeEffect = new EdgeEffect
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Colour = Color4.Black.Opacity(0.25f),
|
||||
Radius = 4,
|
||||
};
|
||||
|
||||
Icon.TextSize = 14;
|
||||
Icon.Margin = new MarginPadding(0);
|
||||
|
||||
Foreground.Add(statusIcon = new TextAwesome
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Icon = FontAwesome.fa_circle_o,
|
||||
TextSize = 14,
|
||||
});
|
||||
|
||||
Text.Margin = new MarginPadding { Left = LABEL_LEFT_MARGIN };
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
BackgroundColour = colours.Gray3;
|
||||
}
|
||||
}
|
||||
|
||||
private class UserDropdownMenu : OsuMenu
|
||||
{
|
||||
public UserDropdownMenu()
|
||||
{
|
||||
Margin = new MarginPadding { Bottom = 5 };
|
||||
CornerRadius = 5;
|
||||
ItemsContainer.Padding = new MarginPadding(0);
|
||||
Masking = true;
|
||||
EdgeEffect = new EdgeEffect
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Colour = Color4.Black.Opacity(0.25f),
|
||||
Radius = 4,
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
Background.Colour = colours.Gray3;
|
||||
}
|
||||
}
|
||||
|
||||
private class UserDropdownMenuItem : OsuDropdownMenuItem
|
||||
{
|
||||
public UserDropdownMenuItem(string text, UserAction current) : base(text, current)
|
||||
{
|
||||
Foreground.Padding = new MarginPadding { Top = 5, Bottom = 5, Left = UserDropdownHeader.LABEL_LEFT_MARGIN, Right = 5 };
|
||||
Chevron.Margin = new MarginPadding { Left = 2, Right = 3 };
|
||||
CornerRadius = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum UserAction
|
||||
{
|
||||
Online,
|
||||
[Description(@"Do not disturb")]
|
||||
DoNotDisturb,
|
||||
[Description(@"Appear offline")]
|
||||
AppearOffline,
|
||||
[Description(@"Sign out")]
|
||||
SignOut,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Configuration;
|
||||
|
||||
namespace osu.Game.Users
|
||||
{
|
||||
@ -19,6 +20,8 @@ namespace osu.Game.Users
|
||||
[JsonProperty(@"country")]
|
||||
public Country Country;
|
||||
|
||||
public Bindable<UserStatus> Status = new Bindable<UserStatus>();
|
||||
|
||||
//public Team Team;
|
||||
|
||||
[JsonProperty(@"profile_colour")]
|
||||
|
@ -58,4 +58,10 @@ namespace osu.Game.Users
|
||||
public override string Message => @"Modding a map";
|
||||
public override Color4 GetAppropriateColour(OsuColour colours) => colours.PurpleDark;
|
||||
}
|
||||
|
||||
public class UserStatusDoNotDisturb : UserStatus
|
||||
{
|
||||
public override string Message => @"Do not disturb";
|
||||
public override Color4 GetAppropriateColour(OsuColour colours) => colours.RedDark;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user