Rework how references are passed about

This commit is contained in:
Drew DeVault 2016-11-03 22:43:00 -04:00
parent 55821a1a2b
commit cb40b7079f
6 changed files with 74 additions and 63 deletions

View File

@ -0,0 +1,13 @@
using System;
using osu.Framework.Graphics.Sprites;
namespace osu.Game.Graphics.UserInterface
{
public class LoadingAnimation : SpriteText
{
public LoadingAnimation()
{
Text = "Loading";
}
}
}

View File

@ -10,14 +10,14 @@ namespace osu.Game.Overlays.Options
{ {
public class GeneralOptions : OptionsSection public class GeneralOptions : OptionsSection
{ {
public GeneralOptions(BasicStorage storage, APIAccess api) public GeneralOptions()
{ {
Header = "General"; Header = "General";
Children = new Drawable[] Children = new Drawable[]
{ {
new LoginOptions(api), new LoginOptions(),
new LanguageOptions(), new LanguageOptions(),
new UpdateOptions(storage), new UpdateOptions(),
}; };
} }
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
@ -12,36 +13,37 @@ namespace osu.Game.Overlays.Options
{ {
public class LoginOptions : OptionsSubsection public class LoginOptions : OptionsSubsection
{ {
public LoginOptions(APIAccess api) private Container loginForm;
public LoginOptions()
{ {
var state = api == null ? APIAccess.APIState.Offline : api.State;
Header = "Sign In"; Header = "Sign In";
Children = new[] Children = new[]
{ {
new Container loginForm = new Container
{ {
Alpha = state == APIAccess.APIState.Online ? 1 : 0,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Children = new[] Children = new[] { new LoadingAnimation() }
{
new SpriteText { Text = $"Logged in as {api?.Username}" }
} }
},
new Container
{
Alpha = state == APIAccess.APIState.Offline ? 1 : 0,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new[] { new LoginForm() }
},
}; };
} }
protected override void Load(BaseGame game)
{
base.Load(game);
var osuGame = game as OsuGameBase;
if (osuGame == null)
return;
loginForm.Children = new Drawable[]
{
new LoginForm(osuGame.API)
};
} }
public class LoginForm : FlowContainer class LoginForm : FlowContainer
{ {
public LoginForm() public LoginForm(APIAccess api)
{ {
Direction = FlowDirection.VerticalOnly; Direction = FlowDirection.VerticalOnly;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
@ -51,7 +53,7 @@ namespace osu.Game.Overlays.Options
Children = new Drawable[] Children = new Drawable[]
{ {
new SpriteText { Text = "Username" }, new SpriteText { Text = "Username" },
new TextBox { Height = 20, RelativeSizeAxes = Axes.X }, new TextBox { Height = 20, RelativeSizeAxes = Axes.X, Text = api?.Username ?? string.Empty },
new SpriteText { Text = "Password" }, new SpriteText { Text = "Password" },
new TextBox { Height = 20, RelativeSizeAxes = Axes.X }, new TextBox { Height = 20, RelativeSizeAxes = Axes.X },
new OsuButton new OsuButton
@ -63,3 +65,4 @@ namespace osu.Game.Overlays.Options
} }
} }
} }
}

View File

@ -1,5 +1,6 @@
using System; using System;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
@ -10,7 +11,9 @@ namespace osu.Game.Overlays.Options
{ {
public class UpdateOptions : OptionsSubsection public class UpdateOptions : OptionsSubsection
{ {
public UpdateOptions(BasicStorage storage) private BasicStorage storage;
public UpdateOptions()
{ {
Header = "Updates"; Header = "Updates";
Children = new Drawable[] Children = new Drawable[]
@ -21,10 +24,16 @@ namespace osu.Game.Overlays.Options
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Text = "Open osu! folder", Text = "Open osu! folder",
Action = storage.OpenInNativeExplorer, Action = () => storage?.OpenInNativeExplorer(),
} }
}; };
} }
protected override void Load(BaseGame game)
{
base.Load(game);
this.storage = game.Host.Storage;
}
} }
} }

View File

@ -24,24 +24,9 @@ namespace osu.Game.Overlays
{ {
internal const float SideMargins = 10; internal const float SideMargins = 10;
private const float width = 400; private const float width = 400;
private FlowContainer optionsContainer;
private BasicStorage storage;
private OsuConfigManager configManager;
private APIAccess api;
protected override void Load(BaseGame game) public OptionsOverlay()
{ {
base.Load(game);
storage = game.Host.Storage;
var osuGame = game as OsuGameBase;
if (osuGame != null)
{
configManager = osuGame.Config;
api = osuGame.API;
}
Depth = float.MaxValue; Depth = float.MaxValue;
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
Size = new Vector2(width, 1); Size = new Vector2(width, 1);
@ -61,7 +46,7 @@ namespace osu.Game.Overlays
ScrollDraggerOnLeft = true, ScrollDraggerOnLeft = true,
Children = new[] Children = new[]
{ {
optionsContainer = new FlowContainer new FlowContainer
{ {
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -81,7 +66,7 @@ namespace osu.Game.Overlays
TextSize = 18, TextSize = 18,
Margin = new MarginPadding { Left = SideMargins, Bottom = 30 }, Margin = new MarginPadding { Left = SideMargins, Bottom = 30 },
}, },
new GeneralOptions(storage, api), new GeneralOptions(),
new GraphicsOptions(), new GraphicsOptions(),
new GameplayOptions(), new GameplayOptions(),
new AudioOptions(), new AudioOptions(),

View File

@ -227,6 +227,7 @@
<Compile Include="Overlays\Options\MaintenanceOptions.cs" /> <Compile Include="Overlays\Options\MaintenanceOptions.cs" />
<Compile Include="Overlays\Options\OptionsSection.cs" /> <Compile Include="Overlays\Options\OptionsSection.cs" />
<Compile Include="Overlays\Options\OptionsSubsection.cs" /> <Compile Include="Overlays\Options\OptionsSubsection.cs" />
<Compile Include="Graphics\UserInterface\LoadingAnimation.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj"> <ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">