mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Fix volume controls handling mouse wheel at a higher level than anything else game-wide.
This commit is contained in:
110
osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs
Normal file
110
osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Threading;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface.Volume
|
||||
{
|
||||
internal class VolumeControl : OverlayContainer
|
||||
{
|
||||
public BindableDouble VolumeGlobal { get; set; }
|
||||
public BindableDouble VolumeSample { get; set; }
|
||||
public BindableDouble VolumeTrack { get; set; }
|
||||
|
||||
private VolumeMeter volumeMeterMaster;
|
||||
|
||||
public override bool Contains(Vector2 screenSpacePos) => true;
|
||||
|
||||
private void volumeChanged(object sender, EventArgs e)
|
||||
{
|
||||
Show();
|
||||
schedulePopOut();
|
||||
}
|
||||
|
||||
public VolumeControl()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Anchor = Anchor.BottomRight;
|
||||
Origin = Anchor.BottomRight;
|
||||
}
|
||||
|
||||
public override void Load(BaseGame game)
|
||||
{
|
||||
VolumeGlobal.ValueChanged += volumeChanged;
|
||||
VolumeSample.ValueChanged += volumeChanged;
|
||||
VolumeTrack.ValueChanged += volumeChanged;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new FlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.BottomRight,
|
||||
Origin = Anchor.BottomRight,
|
||||
Position = new Vector2(10, 30),
|
||||
Spacing = new Vector2(15,0),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
volumeMeterMaster = new VolumeMeter("Master", VolumeGlobal),
|
||||
new VolumeMeter("Effects", VolumeSample),
|
||||
new VolumeMeter("Music", VolumeTrack)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
base.Load(game);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
VolumeGlobal.ValueChanged -= volumeChanged;
|
||||
VolumeSample.ValueChanged -= volumeChanged;
|
||||
VolumeTrack.ValueChanged -= volumeChanged;
|
||||
base.Dispose(isDisposing);
|
||||
}
|
||||
|
||||
protected override bool OnWheelDown(InputState state)
|
||||
{
|
||||
if (!IsVisible)
|
||||
return false;
|
||||
|
||||
volumeMeterMaster.TriggerWheelDown(state);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnWheelUp(InputState state)
|
||||
{
|
||||
if (!IsVisible)
|
||||
return false;
|
||||
|
||||
volumeMeterMaster.TriggerWheelUp(state);
|
||||
return true;
|
||||
}
|
||||
|
||||
ScheduledDelegate popOutDelegate;
|
||||
|
||||
protected override void PopIn()
|
||||
{
|
||||
ClearTransformations();
|
||||
FadeIn(100);
|
||||
|
||||
schedulePopOut();
|
||||
}
|
||||
|
||||
protected override void PopOut()
|
||||
{
|
||||
FadeOut(100);
|
||||
}
|
||||
|
||||
private void schedulePopOut()
|
||||
{
|
||||
popOutDelegate?.Cancel();
|
||||
Delay(1000);
|
||||
popOutDelegate = Schedule(Hide);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK.Input;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface.Volume
|
||||
{
|
||||
class VolumeControlReceptor : Container
|
||||
{
|
||||
public Action ActivateRequested;
|
||||
|
||||
protected override bool OnWheelDown(InputState state)
|
||||
{
|
||||
ActivateRequested?.Invoke();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnWheelUp(InputState state)
|
||||
{
|
||||
ActivateRequested?.Invoke();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
switch (args.Key)
|
||||
{
|
||||
case Key.Up:
|
||||
case Key.Down:
|
||||
ActivateRequested?.Invoke();
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnKeyDown(state, args);
|
||||
}
|
||||
}
|
||||
}
|
90
osu.Game/Graphics/UserInterface/Volume/VolumeMeter.cs
Normal file
90
osu.Game/Graphics/UserInterface/Volume/VolumeMeter.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using osu.Framework;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface.Volume
|
||||
{
|
||||
internal class VolumeMeter : Container
|
||||
{
|
||||
private Box meterFill;
|
||||
private BindableDouble volume;
|
||||
|
||||
public VolumeMeter(string meterName, BindableDouble volume)
|
||||
{
|
||||
this.volume = volume;
|
||||
Size = new Vector2(40, 180);
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = Color4.Black,
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = new Vector2(0.5f, 0.9f),
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = Color4.DarkGray,
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
meterFill = new Box
|
||||
{
|
||||
Colour = Color4.White,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Anchor = Anchor.BottomCentre
|
||||
}
|
||||
}
|
||||
},
|
||||
new SpriteText
|
||||
{
|
||||
Text = meterName,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.TopCentre
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public override void Load(BaseGame game)
|
||||
{
|
||||
base.Load(game);
|
||||
updateFill();
|
||||
}
|
||||
|
||||
public double Volume
|
||||
{
|
||||
get { return volume.Value; }
|
||||
private set
|
||||
{
|
||||
volume.Value = value;
|
||||
updateFill();
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnWheelUp(InputState state)
|
||||
{
|
||||
Volume += 0.05f;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnWheelDown(InputState state)
|
||||
{
|
||||
Volume -= 0.05f;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateFill() => meterFill.ScaleTo(new Vector2(1, (float)Volume), 300, EasingTypes.OutQuint);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user