Split up options into subclasses

This commit is contained in:
Drew DeVault 2016-11-02 22:22:34 -04:00
parent 2f990b884e
commit 2aa85a4b18
8 changed files with 178 additions and 65 deletions

View File

@ -16,13 +16,13 @@ namespace osu.Desktop.VisualTests.Tests
public override string Description => @"Tests the options overlay";
private Options options;
private OptionsOverlay options;
public override void Reset()
{
base.Reset();
Children = new[] { options = new Options() };
Children = new[] { options = new OptionsOverlay() };
options.ToggleVisibility();
}
}

View File

@ -27,7 +27,7 @@ namespace osu.Game
protected override string MainResourceFile => @"osu.Game.Resources.dll";
public Options Options;
public OptionsOverlay Options;
public APIAccess API;
protected override Container Content => ratioContainer;
@ -44,7 +44,7 @@ namespace osu.Game
Children = new Drawable[]
{
Options = new Options(),
Options = new OptionsOverlay(),
Cursor = new OsuCursorContainer()
};

View File

@ -0,0 +1,25 @@
using System;
using OpenTK.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Platform;
using osu.Game.Online.API;
namespace osu.Game.Overlays.Options
{
public class GeneralOptions : OptionsSection
{
public GeneralOptions(BasicStorage storage, APIAccess api)
{
Header = "General";
Children = new Drawable[]
{
new LoginOptions(api),
new LanguageOptions(),
new UpdateOptions(storage),
};
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
namespace osu.Game.Overlays.Options
{
public class LanguageOptions : OptionsSubsection
{
public LanguageOptions()
{
Header = "Language";
Children = new Drawable[]
{
new SpriteText { Text = "TODO: Dropdown" },
new BasicCheckBox
{
Children = new[] { new SpriteText { Text = "Prefer metadata in original language" } }
},
new BasicCheckBox
{
Children = new[] { new SpriteText { Text = "Use alternative font for chat display" } }
},
};
}
}
}

View File

@ -0,0 +1,64 @@
using System;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Online.API;
namespace osu.Game.Overlays.Options
{
public class LoginOptions : OptionsSubsection
{
public LoginOptions(APIAccess api)
{
var state = api == null ? APIAccess.APIState.Offline : api.State;
Header = "Sign In";
Children = new[]
{
new Container
{
Alpha = state == APIAccess.APIState.Online ? 1 : 0,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new[]
{
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() }
},
};
}
}
public class LoginForm : FlowContainer
{
public LoginForm()
{
Direction = FlowDirection.VerticalOnly;
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
Spacing = new Vector2(0, 5);
// TODO: Wire things up
Children = new Drawable[]
{
new SpriteText { Text = "Username" },
new TextBox { Height = 20, RelativeSizeAxes = Axes.X },
new SpriteText { Text = "Password" },
new TextBox { Height = 20, RelativeSizeAxes = Axes.X },
new Button
{
RelativeSizeAxes = Axes.X,
Text = "Log in",
}
};
}
}
}

View File

@ -0,0 +1,29 @@
using System;
using OpenTK.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Platform;
namespace osu.Game.Overlays.Options
{
public class UpdateOptions : OptionsSubsection
{
public UpdateOptions(BasicStorage storage)
{
Header = "Updates";
Children = new Drawable[]
{
new SpriteText { Text = "TODO: Dropdown" },
new SpriteText { Text = "Your osu! is up to date" }, // TODO: map this to reality
new Button
{
RelativeSizeAxes = Axes.X,
Text = "Open osu! folder",
Action = storage.OpenInNativeExplorer,
}
};
}
}
}

View File

@ -14,15 +14,20 @@ using osu.Framework.Graphics.Transformations;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Framework.Platform;
using osu.Game.Configuration;
using osu.Game.Online.API;
using osu.Game.Overlays.Options;
namespace osu.Game.Overlays
{
public class Options : OverlayContainer
public class OptionsOverlay : OverlayContainer
{
internal const float SideMargins = 10;
private const float width = 400;
private FlowContainer optionsContainer;
private BasicStorage storage;
private OsuConfigManager configManager;
private APIAccess api;
protected override void Load(BaseGame game)
{
@ -30,6 +35,13 @@ namespace osu.Game.Overlays
storage = game.Host.Storage;
var osuGame = game as OsuGameBase;
if (osuGame != null)
{
configManager = osuGame.Config;
api = osuGame.API;
}
Depth = float.MaxValue;
RelativeSizeAxes = Axes.Y;
Size = new Vector2(width, 1);
@ -54,7 +66,7 @@ namespace osu.Game.Overlays
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FlowDirection.VerticalOnly,
Children = new[]
Children = new Drawable[]
{
new SpriteText
{
@ -68,65 +80,13 @@ namespace osu.Game.Overlays
Text = "Change the way osu! behaves",
TextSize = 18,
Margin = new MarginPadding { Left = SideMargins, Bottom = 30 },
}
},
new GeneralOptions(storage, api),
}
}
}
}
};
addGeneral();
}
private void addGeneral()
{
optionsContainer.Add(new OptionsSection
{
Header = "General",
Children = new[]
{
new OptionsSubsection
{
Header = "Sign In",
Children = new[]
{
new SpriteText { Text = "TODO" }
}
},
new OptionsSubsection
{
Header = "Language",
Children = new Drawable[]
{
new SpriteText { Text = "TODO: Dropdown" },
new BasicCheckBox
{
Children = new[] { new SpriteText { Text = "Prefer metadata in original language" } }
},
new BasicCheckBox
{
Children = new[] { new SpriteText { Text = "Use alternative font for chat display" } }
},
}
},
new OptionsSubsection
{
Header = "Updates",
Children = new Drawable[]
{
new SpriteText { Text = "TODO: Dropdown" },
new SpriteText { Text = "Your osu! is up to date" }, // TODO: map this to reality
new Button
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Colour = new Color4(14, 132, 165, 255),
Text = "Open osu! folder",
Action = storage.OpenInNativeExplorer,
}
}
}
}
});
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
@ -153,7 +113,7 @@ namespace osu.Game.Overlays
}
}
class OptionsSection : Container
public class OptionsSection : Container
{
private SpriteText header;
private FlowContainer content;
@ -184,8 +144,8 @@ namespace osu.Game.Overlays
Padding = new MarginPadding
{
Top = 10 + borderSize,
Left = Options.SideMargins,
Right = Options.SideMargins,
Left = OptionsOverlay.SideMargins,
Right = OptionsOverlay.SideMargins,
},
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
@ -210,7 +170,7 @@ namespace osu.Game.Overlays
}
}
class OptionsSubsection : Container
public class OptionsSubsection : Container
{
private SpriteText header;
private Container content;
@ -233,6 +193,7 @@ namespace osu.Game.Overlays
Direction = FlowDirection.VerticalOnly,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(0, 5),
Children = new[]
{
header = new SpriteText

View File

@ -177,7 +177,7 @@
<Compile Include="OsuGame.cs" />
<Compile Include="OsuGameBase.cs" />
<Compile Include="Overlays\ChatConsole.cs" />
<Compile Include="Overlays\Options.cs" />
<Compile Include="Overlays\OptionsOverlay.cs" />
<Compile Include="Overlays\Toolbar.cs" />
<Compile Include="Overlays\ToolbarButton.cs" />
<Compile Include="Overlays\ToolbarModeButton.cs" />
@ -196,6 +196,10 @@
<Compile Include="Database\BeatmapMetadata.cs" />
<Compile Include="Database\BeatmapInfo.cs" />
<Compile Include="Database\BaseDifficulty.cs" />
<Compile Include="Overlays\Options\LoginOptions.cs" />
<Compile Include="Overlays\Options\GeneralOptions.cs" />
<Compile Include="Overlays\Options\LanguageOptions.cs" />
<Compile Include="Overlays\Options\UpdateOptions.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">
@ -215,6 +219,9 @@
</ItemGroup>
<ItemGroup />
<ItemGroup />
<ItemGroup>
<Folder Include="Overlays\Options\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.