2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2017-02-07 12:52:19 +08:00
|
|
|
|
|
2017-07-13 13:46:17 +08:00
|
|
|
|
using System;
|
2017-02-07 12:52:19 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using OpenTK;
|
2017-03-27 23:05:11 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-05-24 11:23:48 +08:00
|
|
|
|
using osu.Game.Users;
|
2017-05-25 06:44:48 +08:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
|
|
|
|
|
using Container = osu.Framework.Graphics.Containers.Container;
|
2017-02-07 12:52:19 +08:00
|
|
|
|
|
2017-05-15 09:55:29 +08:00
|
|
|
|
namespace osu.Game.Overlays.Settings.Sections.General
|
2017-02-07 12:52:19 +08:00
|
|
|
|
{
|
2017-05-25 06:44:48 +08:00
|
|
|
|
public class LoginSettings : FillFlowContainer, IOnlineComponent
|
2017-02-07 12:52:19 +08:00
|
|
|
|
{
|
|
|
|
|
private bool bounding = true;
|
2017-03-27 23:05:11 +08:00
|
|
|
|
private LoginForm form;
|
2017-05-25 08:09:18 +08:00
|
|
|
|
private OsuColour colours;
|
2017-02-07 12:52:19 +08:00
|
|
|
|
|
2017-05-25 18:47:18 +08:00
|
|
|
|
private UserPanel panel;
|
|
|
|
|
private UserDropdown dropdown;
|
|
|
|
|
|
2017-07-13 13:46:17 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called to request a hide of a parent displaying this container.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Action RequestHide;
|
|
|
|
|
|
2017-02-07 12:52:19 +08:00
|
|
|
|
public override RectangleF BoundingBox => bounding ? base.BoundingBox : RectangleF.Empty;
|
|
|
|
|
|
|
|
|
|
public bool Bounding
|
|
|
|
|
{
|
|
|
|
|
get { return bounding; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
bounding = value;
|
2017-06-08 15:53:45 +08:00
|
|
|
|
Invalidate(Invalidation.MiscGeometry);
|
2017-02-07 12:52:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 06:44:48 +08:00
|
|
|
|
public LoginSettings()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
Direction = FillDirection.Vertical;
|
|
|
|
|
Spacing = new Vector2(0f, 5f);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 12:52:19 +08:00
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
2017-08-15 13:30:50 +08:00
|
|
|
|
private void load(OsuColour colours, APIAccess api)
|
2017-02-07 12:52:19 +08:00
|
|
|
|
{
|
2017-05-25 08:09:18 +08:00
|
|
|
|
this.colours = colours;
|
2017-07-13 13:46:17 +08:00
|
|
|
|
|
2017-02-07 12:52:19 +08:00
|
|
|
|
api?.Register(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void APIStateChanged(APIAccess api, APIState state)
|
|
|
|
|
{
|
2017-03-27 23:05:11 +08:00
|
|
|
|
form = null;
|
|
|
|
|
|
2017-02-07 12:52:19 +08:00
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case APIState.Offline:
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-05-25 06:44:48 +08:00
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2017-05-25 09:02:32 +08:00
|
|
|
|
Text = "ACCOUNT",
|
|
|
|
|
Margin = new MarginPadding { Bottom = 5 },
|
2017-05-25 06:44:48 +08:00
|
|
|
|
Font = @"Exo2.0-Black",
|
|
|
|
|
},
|
2017-03-27 23:05:11 +08:00
|
|
|
|
form = new LoginForm()
|
2017-02-07 12:52:19 +08:00
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
case APIState.Failing:
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = "Connection failing :(",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
case APIState.Connecting:
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2017-05-25 06:44:48 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2017-02-07 12:52:19 +08:00
|
|
|
|
Text = "Connecting...",
|
2017-05-25 06:44:48 +08:00
|
|
|
|
Margin = new MarginPadding { Top = 10, Bottom = 10 },
|
2017-02-07 12:52:19 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
case APIState.Online:
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-05-25 06:44:48 +08:00
|
|
|
|
new FillFlowContainer
|
2017-02-07 12:52:19 +08:00
|
|
|
|
{
|
2017-05-24 11:23:48 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-05-25 06:44:48 +08:00
|
|
|
|
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 },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-07-13 13:46:17 +08:00
|
|
|
|
panel = new UserPanel(api.LocalUser.Value)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Action = RequestHide
|
|
|
|
|
},
|
2017-05-25 18:47:18 +08:00
|
|
|
|
dropdown = new UserDropdown { RelativeSizeAxes = Axes.X },
|
2017-05-25 06:44:48 +08:00
|
|
|
|
},
|
2017-02-07 12:52:19 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
2017-05-25 18:47:18 +08:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-05-25 21:43:33 +08:00
|
|
|
|
dropdown.Current.TriggerChange();
|
|
|
|
|
|
2017-02-07 12:52:19 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-03-27 23:05:11 +08:00
|
|
|
|
|
2017-08-18 09:48:35 +08:00
|
|
|
|
if (form != null) GetContainingInputManager()?.ChangeFocus(form);
|
2017-03-27 23:05:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 15:33:26 +08:00
|
|
|
|
public override bool AcceptsFocus => true;
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(InputState state) => true;
|
|
|
|
|
|
|
|
|
|
protected override void OnFocus(InputState state)
|
2017-03-27 23:05:11 +08:00
|
|
|
|
{
|
2017-08-15 13:30:50 +08:00
|
|
|
|
if (form != null) GetContainingInputManager().ChangeFocus(form);
|
2017-05-30 15:33:26 +08:00
|
|
|
|
base.OnFocus(state);
|
2017-02-07 12:52:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 09:59:19 +08:00
|
|
|
|
private class LoginForm : FillFlowContainer
|
2017-02-07 12:52:19 +08:00
|
|
|
|
{
|
|
|
|
|
private TextBox username;
|
|
|
|
|
private TextBox password;
|
|
|
|
|
private APIAccess api;
|
|
|
|
|
|
|
|
|
|
private void performLogin()
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(username.Text) && !string.IsNullOrEmpty(password.Text))
|
|
|
|
|
api.Login(username.Text, password.Text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
2017-08-15 13:30:50 +08:00
|
|
|
|
private void load(APIAccess api, OsuConfigManager config)
|
2017-02-07 12:52:19 +08:00
|
|
|
|
{
|
|
|
|
|
this.api = api;
|
2017-03-04 18:00:17 +08:00
|
|
|
|
Direction = FillDirection.Vertical;
|
2017-03-02 02:33:01 +08:00
|
|
|
|
Spacing = new Vector2(0, 5);
|
2017-02-07 12:52:19 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
username = new OsuTextBox
|
|
|
|
|
{
|
2017-02-08 13:01:17 +08:00
|
|
|
|
PlaceholderText = "Username",
|
2017-02-07 12:52:19 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-02-23 16:50:09 +08:00
|
|
|
|
Text = api?.Username ?? string.Empty,
|
|
|
|
|
TabbableContentContainer = this
|
2017-02-07 12:52:19 +08:00
|
|
|
|
},
|
|
|
|
|
password = new OsuPasswordTextBox
|
|
|
|
|
{
|
2017-02-08 13:01:17 +08:00
|
|
|
|
PlaceholderText = "Password",
|
2017-02-23 16:50:09 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-03-03 11:05:32 +08:00
|
|
|
|
TabbableContentContainer = this,
|
2017-03-09 13:25:49 +08:00
|
|
|
|
OnCommit = (sender, newText) => performLogin()
|
2017-02-07 12:52:19 +08:00
|
|
|
|
},
|
2017-05-15 09:55:29 +08:00
|
|
|
|
new SettingsCheckbox
|
2017-02-07 12:52:19 +08:00
|
|
|
|
{
|
|
|
|
|
LabelText = "Remember username",
|
2017-05-15 09:56:27 +08:00
|
|
|
|
Bindable = config.GetBindable<bool>(OsuSetting.SaveUsername),
|
2017-02-07 12:52:19 +08:00
|
|
|
|
},
|
2017-05-15 09:55:29 +08:00
|
|
|
|
new SettingsCheckbox
|
2017-02-07 12:52:19 +08:00
|
|
|
|
{
|
|
|
|
|
LabelText = "Stay logged in",
|
2017-05-15 09:56:27 +08:00
|
|
|
|
Bindable = config.GetBindable<bool>(OsuSetting.SavePassword),
|
2017-02-07 12:52:19 +08:00
|
|
|
|
},
|
|
|
|
|
new OsuButton
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Text = "Sign in",
|
|
|
|
|
Action = performLogin
|
|
|
|
|
},
|
|
|
|
|
new OsuButton
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Text = "Register new account",
|
2017-08-13 09:36:57 +08:00
|
|
|
|
//Action = registerLink
|
2017-02-07 12:52:19 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-03-27 23:05:11 +08:00
|
|
|
|
|
2017-05-30 15:33:26 +08:00
|
|
|
|
public override bool AcceptsFocus => true;
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(InputState state) => true;
|
|
|
|
|
|
|
|
|
|
protected override void OnFocus(InputState state)
|
2017-03-27 23:05:11 +08:00
|
|
|
|
{
|
2017-08-15 13:30:50 +08:00
|
|
|
|
Schedule(() => { GetContainingInputManager().ChangeFocus(string.IsNullOrEmpty(username.Text) ? username : password); });
|
2017-03-27 23:05:11 +08:00
|
|
|
|
}
|
2017-02-07 12:52:19 +08:00
|
|
|
|
}
|
2017-05-25 06:44:48 +08:00
|
|
|
|
|
|
|
|
|
private class UserDropdown : OsuEnumDropdown<UserAction>
|
|
|
|
|
{
|
2017-08-29 17:17:01 +08:00
|
|
|
|
protected override DropdownHeader CreateHeader() => new UserDropdownHeader();
|
2017-08-25 14:57:43 +08:00
|
|
|
|
|
|
|
|
|
protected override DropdownMenu CreateMenu() => new UserDropdownMenu();
|
2017-05-25 06:44:48 +08:00
|
|
|
|
|
2017-05-25 08:09:18 +08:00
|
|
|
|
public Color4 StatusColour
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-05-25 09:39:07 +08:00
|
|
|
|
var h = Header as UserDropdownHeader;
|
|
|
|
|
if (h == null) return;
|
|
|
|
|
h.StatusColour = value;
|
2017-05-25 08:09:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 06:44:48 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
2017-08-29 17:17:01 +08:00
|
|
|
|
AccentColour = colours.Gray5;
|
2017-08-25 14:57:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class UserDropdownMenu : OsuDropdownMenu
|
|
|
|
|
{
|
|
|
|
|
public UserDropdownMenu()
|
|
|
|
|
{
|
|
|
|
|
Masking = true;
|
|
|
|
|
CornerRadius = 5;
|
|
|
|
|
|
|
|
|
|
Margin = new MarginPadding { Bottom = 5 };
|
|
|
|
|
|
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.25f),
|
|
|
|
|
Radius = 4,
|
|
|
|
|
};
|
2017-09-04 08:10:04 +08:00
|
|
|
|
|
|
|
|
|
ItemsContainer.Padding = new MarginPadding();
|
2017-08-25 14:57:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
BackgroundColour = colours.Gray3;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 13:42:52 +08:00
|
|
|
|
protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableUserDropdownMenuItem(item);
|
2017-08-25 14:57:43 +08:00
|
|
|
|
|
2017-08-25 17:41:12 +08:00
|
|
|
|
private class DrawableUserDropdownMenuItem : DrawableOsuDropdownMenuItem
|
2017-08-25 14:57:43 +08:00
|
|
|
|
{
|
2017-08-28 13:42:52 +08:00
|
|
|
|
public DrawableUserDropdownMenuItem(MenuItem item)
|
2017-08-25 17:41:12 +08:00
|
|
|
|
: base(item)
|
2017-08-25 14:57:43 +08:00
|
|
|
|
{
|
|
|
|
|
Foreground.Padding = new MarginPadding { Top = 5, Bottom = 5, Left = 10, Right = 5 };
|
|
|
|
|
CornerRadius = 5;
|
|
|
|
|
}
|
2017-08-28 11:33:31 +08:00
|
|
|
|
|
2017-08-29 17:17:01 +08:00
|
|
|
|
protected override Drawable CreateContent() => new Content
|
2017-08-28 11:33:31 +08:00
|
|
|
|
{
|
|
|
|
|
Label = { Margin = new MarginPadding { Left = UserDropdownHeader.LABEL_LEFT_MARGIN - 11 } }
|
|
|
|
|
};
|
2017-08-25 14:57:43 +08:00
|
|
|
|
}
|
2017-05-25 06:44:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class UserDropdownHeader : OsuDropdownHeader
|
|
|
|
|
{
|
2017-05-25 09:39:07 +08:00
|
|
|
|
public const float LABEL_LEFT_MARGIN = 20;
|
2017-05-25 06:44:48 +08:00
|
|
|
|
|
2017-08-03 13:36:21 +08:00
|
|
|
|
private readonly SpriteIcon statusIcon;
|
2017-05-25 08:09:18 +08:00
|
|
|
|
public Color4 StatusColour
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-07-23 02:50:25 +08:00
|
|
|
|
statusIcon.FadeColour(value, 500, Easing.OutQuint);
|
2017-05-25 08:09:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 06:44:48 +08:00
|
|
|
|
public UserDropdownHeader()
|
|
|
|
|
{
|
|
|
|
|
Foreground.Padding = new MarginPadding { Left = 10, Right = 10 };
|
|
|
|
|
Margin = new MarginPadding { Bottom = 5 };
|
|
|
|
|
Masking = true;
|
|
|
|
|
CornerRadius = 5;
|
2017-06-12 11:48:47 +08:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2017-05-25 06:44:48 +08:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.25f),
|
|
|
|
|
Radius = 4,
|
|
|
|
|
};
|
|
|
|
|
|
2017-08-03 13:36:21 +08:00
|
|
|
|
Icon.Size = new Vector2(14);
|
2017-05-25 06:44:48 +08:00
|
|
|
|
Icon.Margin = new MarginPadding(0);
|
|
|
|
|
|
2017-08-03 13:36:21 +08:00
|
|
|
|
Foreground.Add(statusIcon = new SpriteIcon
|
2017-05-25 06:44:48 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Icon = FontAwesome.fa_circle_o,
|
2017-08-03 13:36:21 +08:00
|
|
|
|
Size = new Vector2(14),
|
2017-05-25 06:44:48 +08:00
|
|
|
|
});
|
2017-05-25 09:26:48 +08:00
|
|
|
|
|
2017-05-25 08:51:00 +08:00
|
|
|
|
Text.Margin = new MarginPadding { Left = LABEL_LEFT_MARGIN };
|
2017-05-25 06:44:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
BackgroundColour = colours.Gray3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private enum UserAction
|
|
|
|
|
{
|
|
|
|
|
Online,
|
|
|
|
|
[Description(@"Do not disturb")]
|
|
|
|
|
DoNotDisturb,
|
|
|
|
|
[Description(@"Appear offline")]
|
|
|
|
|
AppearOffline,
|
|
|
|
|
[Description(@"Sign out")]
|
|
|
|
|
SignOut,
|
|
|
|
|
}
|
2017-02-07 12:52:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|