mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:37:28 +08:00
Remove bindable to promote one-way access
This commit is contained in:
parent
06e25091f6
commit
9e2be6f2f4
@ -56,7 +56,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
AddStep("disable menu items", () =>
|
||||
{
|
||||
foreach (var item in menu.Items)
|
||||
((OsuMenuItem)item).Enabled.Value = false;
|
||||
((OsuMenuItem)item).Action.Disabled = true;
|
||||
});
|
||||
|
||||
AddStep("move to first menu item", () => InputManager.MoveMouseTo(menu.ChildrenOfType<DrawableOsuMenuItem>().First()));
|
||||
@ -71,13 +71,13 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
AddStep("disable menu items", () =>
|
||||
{
|
||||
foreach (var item in menu.Items)
|
||||
((OsuMenuItem)item).Enabled.Value = false;
|
||||
((OsuMenuItem)item).Action.Disabled = true;
|
||||
});
|
||||
|
||||
AddStep("enable menu items", () =>
|
||||
{
|
||||
foreach (var item in menu.Items)
|
||||
((OsuMenuItem)item).Enabled.Value = true;
|
||||
((OsuMenuItem)item).Action.Disabled = false;
|
||||
});
|
||||
|
||||
AddStep("move to first menu item", () => InputManager.MoveMouseTo(menu.ChildrenOfType<DrawableOsuMenuItem>().First()));
|
||||
|
@ -2,15 +2,12 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class OsuMenuItem : MenuItem
|
||||
{
|
||||
public readonly Bindable<bool> Enabled = new Bindable<bool>(true);
|
||||
|
||||
public readonly MenuItemType Type;
|
||||
|
||||
public OsuMenuItem(string text, MenuItemType type = MenuItemType.Standard)
|
||||
@ -22,9 +19,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
: base(text, action)
|
||||
{
|
||||
Type = type;
|
||||
|
||||
Enabled.BindValueChanged(enabled => Action.Disabled = !enabled.NewValue);
|
||||
Action.BindDisabledChanged(disabled => Enabled.Value = !disabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,8 @@ namespace osu.Game.Screens.Edit
|
||||
dependencies.CacheAs<IEditorChangeHandler>(changeHandler);
|
||||
|
||||
EditorMenuBar menuBar;
|
||||
OsuMenuItem undoMenuItem;
|
||||
OsuMenuItem redoMenuItem;
|
||||
|
||||
var fileMenuItems = new List<MenuItem>
|
||||
{
|
||||
@ -155,8 +157,8 @@ namespace osu.Game.Screens.Edit
|
||||
{
|
||||
Items = new[]
|
||||
{
|
||||
new EditorMenuItem("Undo", MenuItemType.Standard, undo) { Enabled = { BindTarget = changeHandler.CanUndo } },
|
||||
new EditorMenuItem("Redo", MenuItemType.Standard, redo) { Enabled = { BindTarget = changeHandler.CanRedo } }
|
||||
undoMenuItem = new EditorMenuItem("Undo", MenuItemType.Standard, undo),
|
||||
redoMenuItem = new EditorMenuItem("Redo", MenuItemType.Standard, redo)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -214,6 +216,9 @@ namespace osu.Game.Screens.Edit
|
||||
}
|
||||
});
|
||||
|
||||
changeHandler.CanUndo.BindValueChanged(v => undoMenuItem.Action.Disabled = !v.NewValue, true);
|
||||
changeHandler.CanRedo.BindValueChanged(v => redoMenuItem.Action.Disabled = !v.NewValue, true);
|
||||
|
||||
menuBar.Mode.ValueChanged += onModeChanged;
|
||||
|
||||
bottomBackground.Colour = colours.Gray2;
|
||||
|
Loading…
Reference in New Issue
Block a user