2023-06-23 01:37:25 +09:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2020-11-03 16:01:14 +09:00
|
|
|
|
// 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 01:50:41 +03:00
|
|
|
|
using osu.Game.Localisation;
|
2020-11-03 16:01:14 +09:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit
|
|
|
|
|
{
|
2021-04-21 18:05:26 +09:00
|
|
|
|
internal class WaveformOpacityMenuItem : MenuItem
|
2020-11-03 16:01:14 +09:00
|
|
|
|
{
|
|
|
|
|
private readonly Bindable<float> waveformOpacity;
|
|
|
|
|
|
2021-05-22 16:42:20 -07:00
|
|
|
|
private readonly Dictionary<float, TernaryStateRadioMenuItem> menuItemLookup = new Dictionary<float, TernaryStateRadioMenuItem>();
|
2020-11-03 16:01:14 +09:00
|
|
|
|
|
2021-04-21 18:05:26 +09:00
|
|
|
|
public WaveformOpacityMenuItem(Bindable<float> waveformOpacity)
|
2023-01-15 01:50:41 +03:00
|
|
|
|
: base(EditorStrings.WaveformOpacity)
|
2020-11-03 16:01:14 +09:00
|
|
|
|
{
|
|
|
|
|
Items = new[]
|
|
|
|
|
{
|
2024-06-17 10:16:40 +02:00
|
|
|
|
createMenuItem(0f),
|
2020-11-03 16:01:14 +09:00
|
|
|
|
createMenuItem(0.25f),
|
|
|
|
|
createMenuItem(0.5f),
|
|
|
|
|
createMenuItem(0.75f),
|
|
|
|
|
createMenuItem(1f),
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-21 18:05:26 +09:00
|
|
|
|
this.waveformOpacity = waveformOpacity;
|
2020-11-03 16:01:14 +09:00
|
|
|
|
waveformOpacity.BindValueChanged(opacity =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var kvp in menuItemLookup)
|
2021-05-22 16:42:20 -07:00
|
|
|
|
kvp.Value.State.Value = kvp.Key == opacity.NewValue ? TernaryState.True : TernaryState.False;
|
2020-11-03 16:01:14 +09:00
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-22 16:42:20 -07:00
|
|
|
|
private TernaryStateRadioMenuItem createMenuItem(float opacity)
|
2020-11-03 16:01:14 +09:00
|
|
|
|
{
|
2021-05-22 16:42:20 -07:00
|
|
|
|
var item = new TernaryStateRadioMenuItem($"{opacity * 100}%", MenuItemType.Standard, _ => updateOpacity(opacity));
|
2020-11-03 16:01:14 +09:00
|
|
|
|
menuItemLookup[opacity] = item;
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateOpacity(float opacity) => waveformOpacity.Value = opacity;
|
|
|
|
|
}
|
|
|
|
|
}
|