mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Cleanup handling of readonly fields
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
// 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.Configuration;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
|
||||
@ -9,33 +9,33 @@ namespace osu.Game.Screens.Multi.Components
|
||||
{
|
||||
public abstract class DisableableTabControl<T> : TabControl<T>
|
||||
{
|
||||
public IEnumerable<T> DisabledItems
|
||||
public readonly BindableBool ReadOnly = new BindableBool();
|
||||
|
||||
protected override void AddTabItem(TabItem<T> tab, bool addToDropdown = true)
|
||||
{
|
||||
set
|
||||
{
|
||||
foreach (var item in value)
|
||||
(TabMap[item] as DisableableTabItem<T>)?.Disable();
|
||||
}
|
||||
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 bool isDisabled;
|
||||
|
||||
public void Disable()
|
||||
private void updateReadOnly(bool readOnly)
|
||||
{
|
||||
Alpha = 0.2f;
|
||||
isDisabled = true;
|
||||
Alpha = readOnly ? 0.2f : 1;
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
if (isDisabled)
|
||||
if (ReadOnly)
|
||||
return true;
|
||||
return base.OnClick(e);
|
||||
}
|
||||
|
Reference in New Issue
Block a user