mirror of
https://github.com/ppy/osu.git
synced 2025-03-23 01:37:31 +08:00
Cleanup handling of readonly fields
This commit is contained in:
parent
be3a912d0b
commit
c7970e5425
@ -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);
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ namespace osu.Game.Screens.Multi.Components
|
||||
protected readonly RoomAvailabilityPicker AvailabilityPicker;
|
||||
protected readonly GameTypePicker TypePicker;
|
||||
protected readonly TriangleButton ApplyButton;
|
||||
protected readonly OsuPasswordTextBox PasswordField;
|
||||
|
||||
public RoomSettingsOverlay()
|
||||
{
|
||||
@ -116,20 +117,16 @@ namespace osu.Game.Screens.Multi.Components
|
||||
{
|
||||
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 @@ namespace osu.Game.Screens.Multi.Components
|
||||
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 @@ namespace osu.Game.Screens.Multi.Components
|
||||
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>
|
||||
|
@ -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()
|
||||
{
|
@ -75,7 +75,8 @@ namespace osu.Game.Screens.Multi.Screens.Match
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Height = 0.9f,
|
||||
Room = room
|
||||
Room = room,
|
||||
ReadOnly = true
|
||||
},
|
||||
},
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user