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

247 lines
8.7 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
{
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,
2016-09-29 19:13:58 +08:00
Colour = new Color4(0.1f, 0.1f, 0.1f, 0.9f)
2016-11-03 07:07:07 +08:00
},
// TODO: Links on the side to jump to a section
new ScrollContainer
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = 5, Right = 5, Top = 50 },
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 = "Options",
TextSize = 40,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
},
new SpriteText
{
Colour = new Color4(235, 117, 139, 255),
Text = "Change the way osu! behaves",
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Margin = new MarginPadding { Bottom = 25 },
},
new SpriteText
{
Text = "TODO: SEARCH",
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Margin = new MarginPadding { Bottom = 25 },
}
}
}
}
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.OpenOsuDirectory,
}
}
}
}
});
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.ToUpper(); }
}
public OptionsSection()
{
const int headerSize = 40, headerMargin = 25;
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
AddInternal(new[]
{
header = new SpriteText
{
TextSize = headerSize,
Colour = new Color4(88, 218, 254, 255),
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
},
content = new FlowContainer
{
Margin = new MarginPadding { Top = headerSize + headerMargin, Left = 10 },
Direction = FlowDirection.VerticalOnly,
Spacing = new Vector2(0, 25),
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
},
});
}
}
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()
{
const int borderWidth = 3, borderMargin = 10;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
AddInternal(new Drawable[]
{
new Box
{
Colour = new Color4(50, 50, 50, 255),
RelativeSizeAxes = Axes.Y,
Width = borderWidth,
},
content = new FlowContainer
{
Direction = FlowDirection.VerticalOnly,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Left = borderWidth + borderMargin },
Children = new[]
{
header = new SpriteText
{
TextSize = 25,
// TODO: Bold
}
}
},
});
}
}
2016-09-29 19:13:58 +08:00
}