Cleanup handling of readonly fields

This commit is contained in:
smoogipoo 2018-12-10 16:50:00 +09:00
parent be3a912d0b
commit c7970e5425
4 changed files with 49 additions and 35 deletions

View File

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

View File

@ -40,6 +40,7 @@ public class RoomSettingsOverlay : FocusedOverlayContainer
protected readonly RoomAvailabilityPicker AvailabilityPicker;
protected readonly GameTypePicker TypePicker;
protected readonly TriangleButton ApplyButton;
protected readonly OsuPasswordTextBox PasswordField;
public RoomSettingsOverlay()
{
@ -116,20 +117,16 @@ public RoomSettingsOverlay()
{
RelativeSizeAxes = Axes.X,
TabbableContentContainer = this,
Alpha = 0.2f,
ReadOnly = true,
OnCommit = (sender, text) => apply(),
},
},
new Section("PASSWORD (OPTIONAL)")
{
Child = new SettingsPasswordTextBox
Child = PasswordField = new SettingsPasswordTextBox
{
RelativeSizeAxes = Axes.X,
TabbableContentContainer = this,
OnCommit = (sender, text) => apply(),
Alpha = 0.2f,
ReadOnly = true,
OnCommit = (sender, text) => apply()
},
},
},
@ -154,20 +151,6 @@ public RoomSettingsOverlay()
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();
}
@ -177,6 +160,27 @@ private void load(OsuColour colours)
typeLabel.Colour = colours.Yellow;
}
private bool readOnly;
public bool ReadOnly
{
get => readOnly;
set
{
if (readOnly == value)
return;
readOnly = value;
NameField.ReadOnly = value;
MaxParticipantsField.ReadOnly = value;
PasswordField.ReadOnly = value;
AvailabilityPicker.ReadOnly.Value = value;
TypePicker.ReadOnly.Value = value;
ApplyButton.Enabled.Value = !value;
}
}
private Room room;
/// <summary>

View File

@ -4,14 +4,23 @@
using osu.Framework.Allocation;
using osu.Game.Online.API;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi.Components;
namespace osu.Game.Screens.Multi.Components
namespace osu.Game.Screens.Multi.Screens.Lounge
{
public class CreateRoomOverlay : RoomSettingsOverlay
{
[Resolved]
private APIAccess api { get; set; }
public CreateRoomOverlay()
{
MaxParticipantsField.ReadOnly = true;
AvailabilityPicker.ReadOnly.Value = true;
TypePicker.ReadOnly.Value = true;
PasswordField.ReadOnly = true;
}
[BackgroundDependencyLoader]
private void load()
{

View File

@ -75,7 +75,8 @@ public Match(Room room)
{
RelativeSizeAxes = Axes.Both,
Height = 0.9f,
Room = room
Room = room,
ReadOnly = true
},
},
};