1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 19:33:01 +08:00
osu-lazer/osu.Game/Screens/Multi/Components/DisableableTabControl.cs

46 lines
1.4 KiB
C#
Raw Normal View History

2018-12-05 16:01:14 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2018-12-10 15:50:00 +08:00
using osu.Framework.Configuration;
2018-12-05 16:01:14 +08:00
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
2018-12-10 16:06:34 +08:00
using osuTK.Graphics;
2018-12-05 16:01:14 +08:00
namespace osu.Game.Screens.Multi.Components
{
public abstract class DisableableTabControl<T> : TabControl<T>
{
2018-12-10 15:50:00 +08:00
public readonly BindableBool ReadOnly = new BindableBool();
protected override void AddTabItem(TabItem<T> tab, bool addToDropdown = true)
2018-12-05 16:01:14 +08:00
{
2018-12-10 15:50:00 +08:00
if (tab is DisableableTabItem<T> disableable)
disableable.ReadOnly.BindTo(ReadOnly);
base.AddTabItem(tab, addToDropdown);
2018-12-05 16:01:14 +08:00
}
protected abstract class DisableableTabItem<T> : TabItem<T>
{
2018-12-10 15:50:00 +08:00
public readonly BindableBool ReadOnly = new BindableBool();
2018-12-05 16:01:14 +08:00
protected DisableableTabItem(T value)
: base(value)
{
2018-12-10 15:50:00 +08:00
ReadOnly.BindValueChanged(updateReadOnly);
2018-12-05 16:01:14 +08:00
}
2018-12-10 15:50:00 +08:00
private void updateReadOnly(bool readOnly)
2018-12-05 16:01:14 +08:00
{
2018-12-10 16:06:34 +08:00
Colour = readOnly ? Color4.Gray : Color4.White;
2018-12-05 16:01:14 +08:00
}
protected override bool OnClick(ClickEvent e)
{
2018-12-10 15:50:00 +08:00
if (ReadOnly)
2018-12-05 16:01:14 +08:00
return true;
return base.OnClick(e);
}
}
}
}