1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-18 08:42:56 +08:00
osu-lazer/osu.Game/Screens/Edit/BackgroundDimMenuItem.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.6 KiB
C#
Raw Normal View History

// 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;
2023-01-15 06:50:41 +08:00
using osu.Game.Localisation;
namespace osu.Game.Screens.Edit
{
internal class BackgroundDimMenuItem : MenuItem
{
2023-01-15 06:50:41 +08:00
private readonly Bindable<float> backgroundDim;
private readonly Dictionary<float, TernaryStateRadioMenuItem> menuItemLookup = new Dictionary<float, TernaryStateRadioMenuItem>();
2023-01-15 06:50:41 +08:00
public BackgroundDimMenuItem(Bindable<float> backgroundDim)
2023-01-15 19:39:34 +08:00
: base(GameplaySettingsStrings.BackgroundDim)
{
Items = new[]
{
createMenuItem(0f),
createMenuItem(0.25f),
createMenuItem(0.5f),
createMenuItem(0.75f),
};
2023-01-15 06:50:41 +08:00
this.backgroundDim = backgroundDim;
backgroundDim.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;
}
2023-01-15 06:50:41 +08:00
private void updateOpacity(float dim) => backgroundDim.Value = dim;
}
}