1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 06:23:21 +08:00

Better disabling of various controls

This commit is contained in:
smoogipoo 2018-12-05 17:01:14 +09:00
parent ec83790734
commit e7d7e00516
5 changed files with 66 additions and 27 deletions

View File

@ -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,

View File

@ -0,0 +1,44 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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<T> : TabControl<T>
{
public IEnumerable<T> DisabledItems
{
set
{
foreach (var item in value)
(TabMap[item] as DisableableTabItem<T>)?.Disable();
}
}
protected abstract class DisableableTabItem<T> : TabItem<T>
{
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);
}
}
}
}

View File

@ -13,7 +13,7 @@ using osuTK;
namespace osu.Game.Screens.Multi.Components
{
public class GameTypePicker : TabControl<GameType>
public class GameTypePicker : DisableableTabControl<GameType>
{
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<GameType>
private class GameTypePickerItem : DisableableTabItem<GameType>
{
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);

View File

@ -15,7 +15,7 @@ using osuTK.Graphics;
namespace osu.Game.Screens.Multi.Components
{
public class RoomAvailabilityPicker : TabControl<RoomAvailability>
public class RoomAvailabilityPicker : DisableableTabControl<RoomAvailability>
{
protected override TabItem<RoomAvailability> CreateTabItem(RoomAvailability value) => new RoomAvailabilityPickerItem(value);
protected override Dropdown<RoomAvailability> CreateDropdown() => null;
@ -32,7 +32,7 @@ namespace osu.Game.Screens.Multi.Components
AddItem(RoomAvailability.InviteOnly);
}
private class RoomAvailabilityPickerItem : TabItem<RoomAvailability>
private class RoomAvailabilityPickerItem : DisableableTabItem<RoomAvailability>
{
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;

View File

@ -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();
}