1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 05:27:40 +08:00
osu-lazer/osu.Game/Screens/Multi/Components/DisableableTabControl.cs
2018-12-10 16:50:00 +09:00

45 lines
1.3 KiB
C#

// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Configuration;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
namespace osu.Game.Screens.Multi.Components
{
public abstract class DisableableTabControl<T> : TabControl<T>
{
public readonly BindableBool ReadOnly = new BindableBool();
protected override void AddTabItem(TabItem<T> tab, bool addToDropdown = true)
{
if (tab is DisableableTabItem<T> disableable)
disableable.ReadOnly.BindTo(ReadOnly);
base.AddTabItem(tab, addToDropdown);
}
protected abstract class DisableableTabItem<T> : TabItem<T>
{
public readonly BindableBool ReadOnly = new BindableBool();
protected DisableableTabItem(T value)
: base(value)
{
ReadOnly.BindValueChanged(updateReadOnly);
}
private void updateReadOnly(bool readOnly)
{
Alpha = readOnly ? 0.2f : 1;
}
protected override bool OnClick(ClickEvent e)
{
if (ReadOnly)
return true;
return base.OnClick(e);
}
}
}
}