mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 00:02:54 +08:00
Extract storable attributes to bindables
This commit is contained in:
parent
99b428ee4b
commit
74fb7cd180
@ -111,7 +111,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
public override bool HandleRotation(float angle)
|
||||
{
|
||||
foreach (var c in SelectedBlueprints)
|
||||
c.Item.Rotation += angle;
|
||||
c.Item.SkinRotation.Value += angle;
|
||||
|
||||
return base.HandleRotation(angle);
|
||||
}
|
||||
@ -121,11 +121,18 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
adjustScaleFromAnchor(ref scale, anchor);
|
||||
|
||||
foreach (var c in SelectedBlueprints)
|
||||
c.Item.Scale += scale * 0.01f;
|
||||
c.Item.SkinScale.Value += scale.X * 0.01f;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandleMovement(MoveSelectionEvent<SkinnableHUDComponent> moveEvent)
|
||||
{
|
||||
foreach (var c in SelectedBlueprints)
|
||||
c.Item.SkinPosition.Value += moveEvent.InstantDelta.X;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void adjustScaleFromAnchor(ref Vector2 scale, Anchor reference)
|
||||
{
|
||||
// cancel out scale in axes we don't care about (based on which drag handle was used).
|
||||
@ -136,13 +143,6 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
if ((reference & Anchor.x0) > 0) scale.X = -scale.X;
|
||||
if ((reference & Anchor.y0) > 0) scale.Y = -scale.Y;
|
||||
}
|
||||
|
||||
public override bool HandleMovement(MoveSelectionEvent<SkinnableHUDComponent> moveEvent)
|
||||
{
|
||||
foreach (var c in SelectedBlueprints)
|
||||
c.Item.Position += moveEvent.InstantDelta;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override SelectionBlueprint<SkinnableHUDComponent> CreateBlueprintFor(SkinnableHUDComponent component)
|
||||
|
@ -4,8 +4,10 @@
|
||||
using System;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Layout;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Skinning;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
@ -15,18 +17,33 @@ namespace osu.Game.Screens.Play.HUD
|
||||
public abstract class SkinnableHUDComponent : SkinnableDrawable
|
||||
{
|
||||
[SettingSource("Scale", "The scale at which this component should be displayed.")]
|
||||
public BindableNumber<float> SkinScale { get; } = new BindableFloat(1)
|
||||
{
|
||||
Precision = 0.1f,
|
||||
MinValue = 0.1f,
|
||||
MaxValue = 10,
|
||||
Default = 1,
|
||||
Value = 1,
|
||||
};
|
||||
public BindableNumber<float> SkinScale { get; } = new BindableFloat(1);
|
||||
|
||||
[SettingSource("Position", "The position at which this component should be displayed.")]
|
||||
public BindableNumber<float> SkinPosition { get; } = new BindableFloat();
|
||||
|
||||
[SettingSource("Rotation", "The rotation at which this component should be displayed.")]
|
||||
public BindableNumber<float> SkinRotation { get; } = new BindableFloat();
|
||||
|
||||
[SettingSource("Anchor", "The screen edge this component should align to.")]
|
||||
public Bindable<Anchor> SkinAnchor { get; } = new Bindable<Anchor>();
|
||||
|
||||
protected SkinnableHUDComponent(ISkinComponent component, Func<ISkinComponent, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.NoScaling)
|
||||
: base(component, defaultImplementation, allowFallback, confineMode)
|
||||
{
|
||||
SkinScale.BindValueChanged(scale => Drawable.Scale = new Vector2(scale.NewValue));
|
||||
SkinPosition.BindValueChanged(position => Position = new Vector2(position.NewValue));
|
||||
SkinRotation.BindValueChanged(rotation => Drawable.Rotation = rotation.NewValue);
|
||||
SkinAnchor.BindValueChanged(anchor => Anchor = anchor.NewValue);
|
||||
}
|
||||
|
||||
protected override bool OnInvalidate(Invalidation invalidation, InvalidationSource source)
|
||||
{
|
||||
SkinScale.Value = Drawable.Scale.X;
|
||||
SkinPosition.Value = Position.X;
|
||||
SkinRotation.Value = Drawable.Rotation;
|
||||
SkinAnchor.Value = Anchor;
|
||||
return base.OnInvalidate(invalidation, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user