mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 17:33:02 +08:00
Update accent colour on combo index change
This commit is contained in:
parent
3155a90501
commit
706e884cc0
@ -76,6 +76,8 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
/// </summary>
|
||||
public JudgementResult Result { get; private set; }
|
||||
|
||||
private Bindable<int> comboIndexBindable;
|
||||
|
||||
public override bool RemoveWhenNotAlive => false;
|
||||
public override bool RemoveCompletedTransforms => false;
|
||||
protected override bool RequiresChildrenUpdate => true;
|
||||
@ -122,6 +124,13 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
if (HitObject is IHasComboInformation combo)
|
||||
{
|
||||
comboIndexBindable = combo.ComboIndexBindable.GetBoundCopy();
|
||||
comboIndexBindable.BindValueChanged(_ => updateAccentColour());
|
||||
}
|
||||
|
||||
updateState(ArmedState.Idle, true);
|
||||
}
|
||||
|
||||
@ -244,12 +253,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
{
|
||||
base.SkinChanged(skin, allowFallback);
|
||||
|
||||
if (HitObject is IHasComboInformation combo)
|
||||
{
|
||||
var comboColours = skin.GetConfig<GlobalSkinConfiguration, List<Color4>>(GlobalSkinConfiguration.ComboColours)?.Value;
|
||||
|
||||
AccentColour.Value = comboColours?.Count > 0 ? comboColours[combo.ComboIndex % comboColours.Count] : Color4.White;
|
||||
}
|
||||
updateAccentColour();
|
||||
|
||||
ApplySkin(skin, allowFallback);
|
||||
|
||||
@ -257,6 +261,15 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
updateState(State.Value, true);
|
||||
}
|
||||
|
||||
private void updateAccentColour()
|
||||
{
|
||||
if (HitObject is IHasComboInformation combo)
|
||||
{
|
||||
var comboColours = CurrentSkin.GetConfig<GlobalSkinConfiguration, List<Color4>>(GlobalSkinConfiguration.ComboColours)?.Value;
|
||||
AccentColour.Value = comboColours?.Count > 0 ? comboColours[combo.ComboIndex % comboColours.Count] : Color4.White;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when a change is made to the skin.
|
||||
/// </summary>
|
||||
|
@ -12,13 +12,17 @@ namespace osu.Game.Skinning
|
||||
/// </summary>
|
||||
public abstract class SkinReloadableDrawable : CompositeDrawable
|
||||
{
|
||||
/// <summary>
|
||||
/// The current skin source.
|
||||
/// </summary>
|
||||
protected ISkinSource CurrentSkin { get; private set; }
|
||||
|
||||
private readonly Func<ISkinSource, bool> allowFallback;
|
||||
private ISkinSource skin;
|
||||
|
||||
/// <summary>
|
||||
/// Whether fallback to default skin should be allowed if the custom skin is missing this resource.
|
||||
/// </summary>
|
||||
private bool allowDefaultFallback => allowFallback == null || allowFallback.Invoke(skin);
|
||||
private bool allowDefaultFallback => allowFallback == null || allowFallback.Invoke(CurrentSkin);
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="SkinReloadableDrawable"/>
|
||||
@ -32,19 +36,19 @@ namespace osu.Game.Skinning
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(ISkinSource source)
|
||||
{
|
||||
skin = source;
|
||||
skin.SourceChanged += onChange;
|
||||
CurrentSkin = source;
|
||||
CurrentSkin.SourceChanged += onChange;
|
||||
}
|
||||
|
||||
private void onChange() =>
|
||||
// schedule required to avoid calls after disposed.
|
||||
// note that this has the side-effect of components only performing a skin change when they are alive.
|
||||
Scheduler.AddOnce(() => SkinChanged(skin, allowDefaultFallback));
|
||||
Scheduler.AddOnce(() => SkinChanged(CurrentSkin, allowDefaultFallback));
|
||||
|
||||
protected override void LoadAsyncComplete()
|
||||
{
|
||||
base.LoadAsyncComplete();
|
||||
SkinChanged(skin, allowDefaultFallback);
|
||||
SkinChanged(CurrentSkin, allowDefaultFallback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -60,8 +64,8 @@ namespace osu.Game.Skinning
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (skin != null)
|
||||
skin.SourceChanged -= onChange;
|
||||
if (CurrentSkin != null)
|
||||
CurrentSkin.SourceChanged -= onChange;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user