1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00
osu-lazer/osu.Game/Overlays/Options.cs

249 lines
8.6 KiB
C#
Raw Normal View History

2016-09-29 19:13:58 +08:00
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-11-03 07:07:07 +08:00
using System.Diagnostics;
2016-09-29 19:13:58 +08:00
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
2016-10-10 16:17:26 +08:00
using osu.Framework;
2016-10-13 22:57:05 +08:00
using osu.Framework.Graphics;
2016-10-16 17:14:17 +08:00
using osu.Framework.Graphics.Containers;
2016-11-03 07:07:07 +08:00
using osu.Framework.Graphics.Primitives;
2016-10-16 20:10:06 +08:00
using osu.Framework.Graphics.Sprites;
2016-10-13 22:57:05 +08:00
using osu.Framework.Graphics.Transformations;
2016-11-03 07:07:07 +08:00
using osu.Framework.Graphics.UserInterface;
2016-10-13 22:57:05 +08:00
using osu.Framework.Input;
2016-11-03 07:07:07 +08:00
using osu.Framework.Platform;
2016-09-29 19:13:58 +08:00
namespace osu.Game.Overlays
{
2016-10-16 17:14:17 +08:00
public class Options : OverlayContainer
2016-09-29 19:13:58 +08:00
{
internal const float SideMargins = 10;
2016-11-03 07:07:07 +08:00
private const float width = 400;
private FlowContainer optionsContainer;
private BasicStorage storage;
2016-09-29 19:13:58 +08:00
2016-11-01 22:24:14 +08:00
protected override void Load(BaseGame game)
2016-09-29 19:13:58 +08:00
{
2016-10-10 16:17:26 +08:00
base.Load(game);
2016-09-29 19:13:58 +08:00
2016-11-03 07:07:07 +08:00
storage = game.Host.Storage;
2016-09-29 19:13:58 +08:00
Depth = float.MaxValue;
RelativeSizeAxes = Axes.Y;
2016-09-29 19:13:58 +08:00
Size = new Vector2(width, 1);
Position = new Vector2(-width, 0);
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = new Color4(51, 51, 51, 255)
2016-11-03 07:07:07 +08:00
},
// TODO: Links on the side to jump to a section
new ScrollContainer
{
RelativeSizeAxes = Axes.Both,
2016-11-03 07:25:00 +08:00
ScrollDraggerOnLeft = true,
2016-11-03 07:07:07 +08:00
Children = new[]
{
optionsContainer = new FlowContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FlowDirection.VerticalOnly,
Children = new[]
{
new SpriteText
{
Text = "settings",
2016-11-03 07:07:07 +08:00
TextSize = 40,
Margin = new MarginPadding { Left = SideMargins, Top = 30 },
2016-11-03 07:07:07 +08:00
},
new SpriteText
{
Colour = new Color4(235, 117, 139, 255),
Text = "Change the way osu! behaves",
TextSize = 18,
Margin = new MarginPadding { Left = SideMargins, Bottom = 30 },
2016-11-03 07:07:07 +08:00
}
}
}
}
2016-09-29 19:13:58 +08:00
}
};
2016-11-03 07:07:07 +08:00
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,
2016-11-03 07:07:07 +08:00
}
}
}
}
});
2016-09-29 19:13:58 +08:00
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
switch (args.Key)
{
case Key.Escape:
2016-10-13 22:27:37 +08:00
if (State == Visibility.Hidden) return false;
2016-09-29 19:13:58 +08:00
2016-10-13 22:27:37 +08:00
State = Visibility.Hidden;
2016-09-29 19:13:58 +08:00
return true;
}
return base.OnKeyDown(state, args);
}
2016-10-13 22:57:05 +08:00
protected override void PopIn()
2016-09-29 19:13:58 +08:00
{
2016-10-13 22:57:05 +08:00
MoveToX(0, 300, EasingTypes.Out);
}
2016-09-29 19:13:58 +08:00
2016-10-13 22:57:05 +08:00
protected override void PopOut()
{
MoveToX(-width, 300, EasingTypes.Out);
2016-09-29 19:13:58 +08:00
}
}
2016-11-03 07:07:07 +08:00
class OptionsSection : Container
{
private SpriteText header;
private FlowContainer content;
protected override Container Content => content;
public string Header
{
get { return header.Text; }
set { header.Text = value; }
2016-11-03 07:07:07 +08:00
}
public OptionsSection()
{
const int headerSize = 30, headerMargin = 25;
const int borderSize = 2;
2016-11-03 07:07:07 +08:00
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
AddInternal(new Drawable[]
2016-11-03 07:07:07 +08:00
{
new Box
2016-11-03 07:07:07 +08:00
{
Colour = new Color4(3, 3, 3, 255),
RelativeSizeAxes = Axes.X,
Height = borderSize,
2016-11-03 07:07:07 +08:00
},
new Container
2016-11-03 07:07:07 +08:00
{
Padding = new MarginPadding
{
Top = 10 + borderSize,
Left = Options.SideMargins,
Right = Options.SideMargins,
},
2016-11-03 07:07:07 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new[]
{
header = new SpriteText
{
TextSize = headerSize,
Colour = new Color4(247, 198, 35, 255),
},
content = new FlowContainer
{
Margin = new MarginPadding { Top = headerSize + headerMargin },
Direction = FlowDirection.VerticalOnly,
Spacing = new Vector2(0, 25),
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
},
}
2016-11-03 07:07:07 +08:00
},
});
}
}
class OptionsSubsection : Container
{
private SpriteText header;
private Container content;
protected override Container Content => content;
public string Header
{
get { return header.Text; }
set { header.Text = value.ToUpper(); }
}
public OptionsSubsection()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
AddInternal(new Drawable[]
{
content = new FlowContainer
{
Direction = FlowDirection.VerticalOnly,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new[]
{
header = new SpriteText
{
TextSize = 25,
// TODO: Bold
}
}
},
});
}
}
2016-09-29 19:13:58 +08:00
}