1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-06 02:46:08 +08:00

Reorder parameters

This commit is contained in:
smoogipoo 2019-11-08 12:55:22 +09:00
parent 30f877c4ab
commit 0a15a13fab
4 changed files with 22 additions and 13 deletions

View File

@ -53,12 +53,12 @@ namespace osu.Game.Tests.Visual.UserInterface
private class TestMenuItem : StatefulMenuItem<TestStates> private class TestMenuItem : StatefulMenuItem<TestStates>
{ {
public TestMenuItem(string text, MenuItemType type = MenuItemType.Standard) public TestMenuItem(string text, MenuItemType type = MenuItemType.Standard)
: base(text, type) : this(text, type, null)
{ {
} }
public TestMenuItem(string text, MenuItemType type, Func<TestStates, TestStates> changeStateFunc) public TestMenuItem(string text, MenuItemType type, Func<TestStates, TestStates> changeStateFunc)
: base(text, type, changeStateFunc) : base(text, changeStateFunc, type)
{ {
} }

View File

@ -11,15 +11,19 @@ namespace osu.Game.Graphics.UserInterface
{ {
public readonly Bindable<object> State = new Bindable<object>(); public readonly Bindable<object> State = new Bindable<object>();
protected StatefulMenuItem(string text, MenuItemType type = MenuItemType.Standard) protected StatefulMenuItem(string text, Func<object, object> changeStateFunc, MenuItemType type = MenuItemType.Standard)
: this(text, type, null) : this(text, changeStateFunc, type, null)
{ {
} }
protected StatefulMenuItem(string text, MenuItemType type, Func<object, object> changeStateFunc) protected StatefulMenuItem(string text, Func<object, object> changeStateFunc, MenuItemType type, Action<object> action)
: base(text, type) : base(text, type)
{ {
Action.Value = () => State.Value = changeStateFunc?.Invoke(State.Value) ?? State.Value; Action.Value = () =>
{
State.Value = changeStateFunc?.Invoke(State.Value) ?? State.Value;
action?.Invoke(State.Value);
};
} }
public abstract IconUsage? GetIconForState(object state); public abstract IconUsage? GetIconForState(object state);
@ -30,13 +34,13 @@ namespace osu.Game.Graphics.UserInterface
{ {
public new readonly Bindable<T> State = new Bindable<T>(); public new readonly Bindable<T> State = new Bindable<T>();
protected StatefulMenuItem(string text, MenuItemType type = MenuItemType.Standard) protected StatefulMenuItem(string text, Func<T, T> changeStateFunc, MenuItemType type = MenuItemType.Standard)
: this(text, type, null) : this(text, changeStateFunc, type, null)
{ {
} }
protected StatefulMenuItem(string text, MenuItemType type, Func<T, T> changeStateFunc) protected StatefulMenuItem(string text, Func<T, T> changeStateFunc, MenuItemType type, Action<T> action)
: base(text, type, o => changeStateFunc?.Invoke((T)o) ?? o) : base(text, o => changeStateFunc?.Invoke((T)o) ?? o, type, o => action?.Invoke((T)o))
{ {
base.State.BindValueChanged(state => base.State.BindValueChanged(state =>
{ {

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
@ -8,7 +9,12 @@ namespace osu.Game.Graphics.UserInterface
public class ThreeStateMenuItem : StatefulMenuItem<ThreeStates> public class ThreeStateMenuItem : StatefulMenuItem<ThreeStates>
{ {
public ThreeStateMenuItem(string text, MenuItemType type = MenuItemType.Standard) public ThreeStateMenuItem(string text, MenuItemType type = MenuItemType.Standard)
: base(text, type, getNextState) : this(text, type, null)
{
}
public ThreeStateMenuItem(string text, MenuItemType type, Action<ThreeStates> action)
: base(text, getNextState, type, action)
{ {
} }

View File

@ -14,9 +14,8 @@ namespace osu.Game.Graphics.UserInterface
} }
public ToggleMenuItem(string text, MenuItemType type, Action<bool> action) public ToggleMenuItem(string text, MenuItemType type, Action<bool> action)
: base(text, type, value => !value) : base(text, value => !value, type, action)
{ {
State.BindValueChanged(state => action?.Invoke(state.NewValue));
} }
public override IconUsage? GetIconForState(bool state) => state ? (IconUsage?)FontAwesome.Solid.Check : null; public override IconUsage? GetIconForState(bool state) => state ? (IconUsage?)FontAwesome.Solid.Check : null;