From 33e86cb81e757df40f32b5ce3a996b1b8ccaf316 Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Wed, 6 Jun 2018 02:06:33 -0300 Subject: [PATCH] Add GameTypePicker. --- .../Multi/Screens/Match/GameTypePicker.cs | 122 ++++++++++++++++++ .../Screens/Match/RoomSettingsOverlay.cs | 5 +- 2 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 osu.Game/Screens/Multi/Screens/Match/GameTypePicker.cs diff --git a/osu.Game/Screens/Multi/Screens/Match/GameTypePicker.cs b/osu.Game/Screens/Multi/Screens/Match/GameTypePicker.cs new file mode 100644 index 0000000000..1b4d69a35b --- /dev/null +++ b/osu.Game/Screens/Multi/Screens/Match/GameTypePicker.cs @@ -0,0 +1,122 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.UserInterface; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Online.Multiplayer; +using osu.Game.Screens.Multi.Components; +using OpenTK; + +namespace osu.Game.Screens.Multi.Screens.Match +{ + public class GameTypePicker : FillFlowContainer, IHasCurrentValue + { + private readonly OsuSpriteText tooltip; + + public Bindable Current { get; } = new Bindable(); + + public GameTypePicker() + { + AutoSizeAxes = Axes.Y; + RelativeSizeAxes = Axes.X; + Direction = FillDirection.Vertical; + Spacing = new Vector2(7); + + Picker picker; + Children = new Drawable[] + { + picker = new Picker + { + RelativeSizeAxes = Axes.X, + }, + tooltip = new OsuSpriteText + { + TextSize = 14, + }, + }; + + Current.ValueChanged += t => tooltip.Text = t.Name; + + picker.AddItem(new GameTypeTag()); + picker.AddItem(new GameTypeVersus()); + picker.AddItem(new GameTypeTagTeam()); + picker.AddItem(new GameTypeTeamVersus()); + + Current.BindTo(picker.Current); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + tooltip.Colour = colours.Yellow; + } + + private class Picker : TabControl + { + private const float height = 40; + private const float selection_width = 3; + + protected override TabItem CreateTabItem(GameType value) => new PickerItem(value); + protected override Dropdown CreateDropdown() => null; + + public Picker() + { + Height = height + selection_width * 2; + TabContainer.Spacing = new Vector2(10 - selection_width * 2); + } + + private class PickerItem : TabItem + { + private const float transition_duration = 200; + + private readonly Container selection; + + public PickerItem(GameType value) + : base(value) + { + AutoSizeAxes = Axes.Both; + + Child = selection = new CircularContainer + { + RelativeSizeAxes = Axes.Both, + Masking = true, + Alpha = 0, + Child = new Box + { + RelativeSizeAxes = Axes.Both, + }, + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + DrawableGameType icon; + Add(icon = new DrawableGameType(Value) + { + Size = new Vector2(height), + }); + + selection.Colour = colours.Yellow; + icon.Margin = new MarginPadding(selection_width); + } + + protected override void OnActivated() + { + selection.FadeIn(transition_duration, Easing.OutQuint); + } + + protected override void OnDeactivated() + { + selection.FadeOut(transition_duration, Easing.OutQuint); + } + } + } + } +} diff --git a/osu.Game/Screens/Multi/Screens/Match/RoomSettingsOverlay.cs b/osu.Game/Screens/Multi/Screens/Match/RoomSettingsOverlay.cs index 6cb814163f..3780e43a4c 100644 --- a/osu.Game/Screens/Multi/Screens/Match/RoomSettingsOverlay.cs +++ b/osu.Game/Screens/Multi/Screens/Match/RoomSettingsOverlay.cs @@ -51,7 +51,10 @@ namespace osu.Game.Screens.Multi.Screens.Match Child = new SettingsTextBox(), }, new Section("ROOM VISIBILITY"), - new Section("GAME TYPE"), + new Section("GAME TYPE") + { + Child = new GameTypePicker(), + }, }, }, new SectionContainer