Dropdown actions, +User.Status, +UserStatusDoNotDisturb, properly align UserDropdownMenuItem

This commit is contained in:
DrabWeb 2017-05-24 21:09:18 -03:00
parent b57a3f2056
commit efd4c57431
3 changed files with 57 additions and 6 deletions

View File

@ -26,6 +26,7 @@ public class LoginSettings : FillFlowContainer, IOnlineComponent
{
private bool bounding = true;
private LoginForm form;
private OsuColour colours;
public override RectangleF BoundingBox => bounding ? base.BoundingBox : RectangleF.Empty;
@ -48,8 +49,9 @@ public LoginSettings()
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(APIAccess api)
private void load(OsuColour colours, APIAccess api)
{
this.colours = colours;
api?.Register(this);
}
@ -93,6 +95,8 @@ public void APIStateChanged(APIAccess api, APIState state)
};
break;
case APIState.Online:
UserDropdown dropdown;
UserPanel panel;
Children = new Drawable[]
{
new FillFlowContainer
@ -121,17 +125,40 @@ public void APIStateChanged(APIAccess api, APIState state)
},
},
},
new UserPanel(api.LocalUser.Value)
panel = new UserPanel(api.LocalUser.Value)
{
RelativeSizeAxes = Axes.X,
},
new UserDropdown
dropdown = new UserDropdown
{
RelativeSizeAxes = Axes.X,
},
},
},
};
panel.Status.BindTo(api.LocalUser.Value.Status);
dropdown.Current.ValueChanged += newValue =>
{
switch (newValue)
{
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;
}
@ -225,6 +252,14 @@ private class UserDropdown : OsuEnumDropdown<UserAction>
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
{
(Header as UserDropdownHeader).StatusColour = value;
}
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
@ -235,6 +270,14 @@ private class UserDropdownHeader : OsuDropdownHeader
{
protected readonly TextAwesome statusIcon;
public Color4 StatusColour
{
set
{
statusIcon.FadeColour(value, 500, EasingTypes.OutQuint);
}
}
public UserDropdownHeader()
{
Foreground.Padding = new MarginPadding { Left = 10, Right = 10 };
@ -268,8 +311,6 @@ private void load(OsuColour colours)
{
BackgroundColour = colours.Gray3;
}
public void SetStatusColour(Color4 colour) => statusIcon.FadeColour(colour, 500, EasingTypes.OutQuint);
}
private class UserDropdownMenu : OsuMenu
@ -298,7 +339,8 @@ private class UserDropdownMenuItem : OsuDropdownMenuItem
{
public UserDropdownMenuItem(string text, UserAction current) : base(text, current)
{
Foreground.Padding = new MarginPadding(5);
//todo: Another magic number
Foreground.Padding = new MarginPadding { Top = 5, Bottom = 5, Left = 19, Right = 5 };
CornerRadius = 5;
}
}

View File

@ -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 @@ public class User
[JsonProperty(@"country")]
public Country Country;
public Bindable<UserStatus> Status = new Bindable<UserStatus>();
//public Team Team;
[JsonProperty(@"profile_colour")]

View File

@ -58,4 +58,10 @@ public class UserStatusModding : UserStatus
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;
}
}