1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-28 01:37:46 +08:00

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

View File

@ -40,6 +40,7 @@ namespace osu.Game.Screens.Multi.Components
protected readonly RoomAvailabilityPicker AvailabilityPicker; protected readonly RoomAvailabilityPicker AvailabilityPicker;
protected readonly GameTypePicker TypePicker; protected readonly GameTypePicker TypePicker;
protected readonly TriangleButton ApplyButton; protected readonly TriangleButton ApplyButton;
protected readonly OsuPasswordTextBox PasswordField;
public RoomSettingsOverlay() public RoomSettingsOverlay()
{ {
@ -116,20 +117,16 @@ namespace osu.Game.Screens.Multi.Components
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
TabbableContentContainer = this, TabbableContentContainer = this,
Alpha = 0.2f,
ReadOnly = true,
OnCommit = (sender, text) => apply(), OnCommit = (sender, text) => apply(),
}, },
}, },
new Section("PASSWORD (OPTIONAL)") new Section("PASSWORD (OPTIONAL)")
{ {
Child = new SettingsPasswordTextBox Child = PasswordField = new SettingsPasswordTextBox
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
TabbableContentContainer = this, TabbableContentContainer = this,
OnCommit = (sender, text) => apply(), OnCommit = (sender, text) => apply()
Alpha = 0.2f,
ReadOnly = true,
}, },
}, },
}, },
@ -154,20 +151,6 @@ namespace osu.Game.Screens.Multi.Components
typeBind.ValueChanged += t => TypePicker.Current.Value = t; typeBind.ValueChanged += t => TypePicker.Current.Value = t;
maxParticipantsBind.ValueChanged += m => MaxParticipantsField.Text = m?.ToString(); 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(); Room = new Room();
} }
@ -177,6 +160,27 @@ namespace osu.Game.Screens.Multi.Components
typeLabel.Colour = colours.Yellow; 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; private Room room;
/// <summary> /// <summary>

View File

@ -4,14 +4,23 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.Multiplayer; 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 public class CreateRoomOverlay : RoomSettingsOverlay
{ {
[Resolved] [Resolved]
private APIAccess api { get; set; } private APIAccess api { get; set; }
public CreateRoomOverlay()
{
MaxParticipantsField.ReadOnly = true;
AvailabilityPicker.ReadOnly.Value = true;
TypePicker.ReadOnly.Value = true;
PasswordField.ReadOnly = true;
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {

View File

@ -75,7 +75,8 @@ namespace osu.Game.Screens.Multi.Screens.Match
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Height = 0.9f, Height = 0.9f,
Room = room Room = room,
ReadOnly = true
}, },
}, },
}; };