1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-09 09:37:42 +08:00
osu-lazer/osu.Game/Screens/Edit/BackgroundDimMenuItem.cs
2022-11-08 17:20:37 +09:00

46 lines
1.5 KiB
C#

// 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.
using System.Collections.Generic;
using osu.Framework.Bindables;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Screens.Edit
{
internal class BackgroundDimMenuItem : MenuItem
{
private readonly Bindable<float> backgroudDim;
private readonly Dictionary<float, TernaryStateRadioMenuItem> menuItemLookup = new Dictionary<float, TernaryStateRadioMenuItem>();
public BackgroundDimMenuItem(Bindable<float> backgroudDim)
: base("Background dim")
{
Items = new[]
{
createMenuItem(0f),
createMenuItem(0.25f),
createMenuItem(0.5f),
createMenuItem(0.75f),
};
this.backgroudDim = backgroudDim;
backgroudDim.BindValueChanged(dim =>
{
foreach (var kvp in menuItemLookup)
kvp.Value.State.Value = kvp.Key == dim.NewValue ? TernaryState.True : TernaryState.False;
}, true);
}
private TernaryStateRadioMenuItem createMenuItem(float dim)
{
var item = new TernaryStateRadioMenuItem($"{dim * 100}%", MenuItemType.Standard, _ => updateOpacity(dim));
menuItemLookup[dim] = item;
return item;
}
private void updateOpacity(float dim) => backgroudDim.Value = dim;
}
}