From e7d7e005169abffc7039258041722c184b4eb1a4 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 5 Dec 2018 17:01:14 +0900 Subject: [PATCH] Better disabling of various controls --- osu.Game/Online/Multiplayer/GameType.cs | 12 ----- .../Multi/Components/DisableableTabControl.cs | 44 +++++++++++++++++++ .../Multi/Components/GameTypePicker.cs | 14 +----- .../Components/RoomAvailabilityPicker.cs | 6 +-- .../Multi/Components/RoomSettingsOverlay.cs | 17 +++++++ 5 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 osu.Game/Screens/Multi/Components/DisableableTabControl.cs diff --git a/osu.Game/Online/Multiplayer/GameType.cs b/osu.Game/Online/Multiplayer/GameType.cs index ced6d7d318..8c9d635eea 100644 --- a/osu.Game/Online/Multiplayer/GameType.cs +++ b/osu.Game/Online/Multiplayer/GameType.cs @@ -14,8 +14,6 @@ namespace osu.Game.Online.Multiplayer { public abstract string Name { get; } - public abstract bool IsAvailable { get; } - public abstract Drawable GetIcon(OsuColour colours, float size); public override int GetHashCode() => GetType().GetHashCode(); @@ -26,8 +24,6 @@ namespace osu.Game.Online.Multiplayer { public override string Name => "Tag"; - public override bool IsAvailable => false; - public override Drawable GetIcon(OsuColour colours, float size) { return new SpriteIcon @@ -46,8 +42,6 @@ namespace osu.Game.Online.Multiplayer { public override string Name => "Versus"; - public override bool IsAvailable => false; - public override Drawable GetIcon(OsuColour colours, float size) { return new VersusRow(colours.Blue, colours.Blue, size * 0.6f) @@ -62,8 +56,6 @@ namespace osu.Game.Online.Multiplayer { public override string Name => "Tag Team"; - public override bool IsAvailable => false; - public override Drawable GetIcon(OsuColour colours, float size) { return new FillFlowContainer @@ -98,8 +90,6 @@ namespace osu.Game.Online.Multiplayer { public override string Name => "Team Versus"; - public override bool IsAvailable => false; - public override Drawable GetIcon(OsuColour colours, float size) { return new FillFlowContainer @@ -166,8 +156,6 @@ namespace osu.Game.Online.Multiplayer { public override string Name => "Timeshift"; - public override bool IsAvailable => true; - public override Drawable GetIcon(OsuColour colours, float size) => new SpriteIcon { Anchor = Anchor.Centre, diff --git a/osu.Game/Screens/Multi/Components/DisableableTabControl.cs b/osu.Game/Screens/Multi/Components/DisableableTabControl.cs new file mode 100644 index 0000000000..1ca61a2678 --- /dev/null +++ b/osu.Game/Screens/Multi/Components/DisableableTabControl.cs @@ -0,0 +1,44 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Input.Events; + +namespace osu.Game.Screens.Multi.Components +{ + public abstract class DisableableTabControl : TabControl + { + public IEnumerable DisabledItems + { + set + { + foreach (var item in value) + (TabMap[item] as DisableableTabItem)?.Disable(); + } + } + + protected abstract class DisableableTabItem : TabItem + { + protected DisableableTabItem(T value) + : base(value) + { + } + + private bool isDisabled; + + public void Disable() + { + Alpha = 0.2f; + isDisabled = true; + } + + protected override bool OnClick(ClickEvent e) + { + if (isDisabled) + return true; + return base.OnClick(e); + } + } + } +} diff --git a/osu.Game/Screens/Multi/Components/GameTypePicker.cs b/osu.Game/Screens/Multi/Components/GameTypePicker.cs index 9cd1a7dc14..d9619ad35d 100644 --- a/osu.Game/Screens/Multi/Components/GameTypePicker.cs +++ b/osu.Game/Screens/Multi/Components/GameTypePicker.cs @@ -13,7 +13,7 @@ using osuTK; namespace osu.Game.Screens.Multi.Components { - public class GameTypePicker : TabControl + public class GameTypePicker : DisableableTabControl { private const float height = 40; private const float selection_width = 3; @@ -34,7 +34,7 @@ namespace osu.Game.Screens.Multi.Components AddItem(new GameTypeTimeshift()); } - private class GameTypePickerItem : TabItem + private class GameTypePickerItem : DisableableTabItem { private const float transition_duration = 200; @@ -84,9 +84,6 @@ namespace osu.Game.Screens.Multi.Components private void load(OsuColour colours) { selection.Colour = colours.Yellow; - - if (!Value.IsAvailable) - Colour = colours.Gray5; } protected override bool OnHover(HoverEvent e) @@ -101,13 +98,6 @@ namespace osu.Game.Screens.Multi.Components base.OnHoverLost(e); } - protected override bool OnClick(ClickEvent e) - { - if (!Value.IsAvailable) - return true; - return base.OnClick(e); - } - protected override void OnActivated() { selection.FadeIn(transition_duration, Easing.OutQuint); diff --git a/osu.Game/Screens/Multi/Components/RoomAvailabilityPicker.cs b/osu.Game/Screens/Multi/Components/RoomAvailabilityPicker.cs index f0a2a2e8dc..287add5de1 100644 --- a/osu.Game/Screens/Multi/Components/RoomAvailabilityPicker.cs +++ b/osu.Game/Screens/Multi/Components/RoomAvailabilityPicker.cs @@ -15,7 +15,7 @@ using osuTK.Graphics; namespace osu.Game.Screens.Multi.Components { - public class RoomAvailabilityPicker : TabControl + public class RoomAvailabilityPicker : DisableableTabControl { protected override TabItem CreateTabItem(RoomAvailability value) => new RoomAvailabilityPickerItem(value); protected override Dropdown CreateDropdown() => null; @@ -32,7 +32,7 @@ namespace osu.Game.Screens.Multi.Components AddItem(RoomAvailability.InviteOnly); } - private class RoomAvailabilityPickerItem : TabItem + private class RoomAvailabilityPickerItem : DisableableTabItem { private const float transition_duration = 200; @@ -41,7 +41,7 @@ namespace osu.Game.Screens.Multi.Components public RoomAvailabilityPickerItem(RoomAvailability value) : base(value) { RelativeSizeAxes = Axes.Y; - Width = 120; + Width = 102; Masking = true; CornerRadius = 5; diff --git a/osu.Game/Screens/Multi/Components/RoomSettingsOverlay.cs b/osu.Game/Screens/Multi/Components/RoomSettingsOverlay.cs index f50eefe4c6..99afc437d0 100644 --- a/osu.Game/Screens/Multi/Components/RoomSettingsOverlay.cs +++ b/osu.Game/Screens/Multi/Components/RoomSettingsOverlay.cs @@ -125,6 +125,8 @@ namespace osu.Game.Screens.Multi.Components RelativeSizeAxes = Axes.X, TabbableContentContainer = this, OnCommit = (sender, text) => apply(), + Alpha = 0.2f, + ReadOnly = true, }, }, }, @@ -149,6 +151,21 @@ namespace osu.Game.Screens.Multi.Components typeBind.ValueChanged += t => TypePicker.Current.Value = t; maxParticipantsBind.ValueChanged += m => MaxParticipantsField.Text = m?.ToString(); + AvailabilityPicker.DisabledItems = new[] + { + RoomAvailability.FriendsOnly, + RoomAvailability.InviteOnly + }; + + TypePicker.DisabledItems = new GameType[] + { + new GameTypeTag(), + new GameTypeVersus(), + new GameTypeTagTeam(), + new GameTypeTeamVersus(), + }; + + Room = new Room(); }