mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
Merge pull request #12682 from frenzibyte/refactor-combo-colour-retrieval
Refactor combo colours retrieval to use skin config lookups instead
This commit is contained in:
commit
d066ebcd70
@ -9,6 +9,7 @@ using osu.Game.Audio;
|
||||
using osu.Game.Rulesets.Catch.Judgements;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Game.Utils;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -31,7 +32,7 @@ namespace osu.Game.Rulesets.Catch.Objects
|
||||
}
|
||||
|
||||
// override any external colour changes with banananana
|
||||
Color4 IHasComboInformation.GetComboColour(IReadOnlyList<Color4> comboColours) => getBananaColour();
|
||||
Color4 IHasComboInformation.GetComboColour(ISkin skin) => getBananaColour();
|
||||
|
||||
private Color4 getBananaColour()
|
||||
{
|
||||
|
@ -1,10 +1,10 @@
|
||||
// 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 Newtonsoft.Json;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Skinning;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Rulesets.Catch.Objects
|
||||
@ -45,6 +45,6 @@ namespace osu.Game.Rulesets.Catch.Objects
|
||||
}
|
||||
}
|
||||
|
||||
Color4 IHasComboInformation.GetComboColour(IReadOnlyList<Color4> comboColours) => comboColours[(IndexInBeatmap + 1) % comboColours.Count];
|
||||
Color4 IHasComboInformation.GetComboColour(ISkin skin) => IHasComboInformation.GetSkinComboColour(this, skin, IndexInBeatmap + 1);
|
||||
}
|
||||
}
|
||||
|
@ -129,14 +129,8 @@ namespace osu.Game.Tests.Gameplay
|
||||
{
|
||||
switch (lookup)
|
||||
{
|
||||
case GlobalSkinColours global:
|
||||
switch (global)
|
||||
{
|
||||
case GlobalSkinColours.ComboColours:
|
||||
return SkinUtils.As<TValue>(new Bindable<IReadOnlyList<Color4>>(ComboColours));
|
||||
}
|
||||
|
||||
break;
|
||||
case SkinComboColourLookup comboColour:
|
||||
return SkinUtils.As<TValue>(new Bindable<Color4>(ComboColours[comboColour.ColourIndex % ComboColours.Count]));
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
|
@ -502,8 +502,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
{
|
||||
if (!(HitObject is IHasComboInformation combo)) return;
|
||||
|
||||
var comboColours = CurrentSkin.GetConfig<GlobalSkinColours, IReadOnlyList<Color4>>(GlobalSkinColours.ComboColours)?.Value ?? Array.Empty<Color4>();
|
||||
AccentColour.Value = combo.GetComboColour(comboColours);
|
||||
AccentColour.Value = combo.GetComboColour(CurrentSkin);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,9 +1,8 @@
|
||||
// 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 JetBrains.Annotations;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Skinning;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Rulesets.Objects.Types
|
||||
@ -40,11 +39,21 @@ namespace osu.Game.Rulesets.Objects.Types
|
||||
bool LastInCombo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the colour of the combo described by this <see cref="IHasComboInformation"/> object from a set of possible combo colours.
|
||||
/// Defaults to using <see cref="ComboIndex"/> to decide the colour.
|
||||
/// Retrieves the colour of the combo described by this <see cref="IHasComboInformation"/> object.
|
||||
/// </summary>
|
||||
/// <param name="comboColours">A list of possible combo colours provided by the beatmap or skin.</param>
|
||||
/// <returns>The colour of the combo described by this <see cref="IHasComboInformation"/> object.</returns>
|
||||
Color4 GetComboColour([NotNull] IReadOnlyList<Color4> comboColours) => comboColours.Count > 0 ? comboColours[ComboIndex % comboColours.Count] : Color4.White;
|
||||
/// <param name="skin">The skin to retrieve the combo colour from, if wanted.</param>
|
||||
Color4 GetComboColour(ISkin skin) => GetSkinComboColour(this, skin, ComboIndex);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the colour of the combo described by a given <see cref="IHasComboInformation"/> object from a given skin.
|
||||
/// </summary>
|
||||
/// <param name="combo">The combo information, should be <c>this</c>.</param>
|
||||
/// <param name="skin">The skin to retrieve the combo colour from.</param>
|
||||
/// <param name="comboIndex">The index to retrieve the combo colour with.</param>
|
||||
/// <returns></returns>
|
||||
protected static Color4 GetSkinComboColour(IHasComboInformation combo, ISkin skin, int comboIndex)
|
||||
{
|
||||
return skin.GetConfig<SkinComboColourLookup, Color4>(new SkinComboColourLookup(comboIndex, combo))?.Value ?? Color4.White;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -153,11 +152,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
break;
|
||||
|
||||
case IHasComboInformation combo:
|
||||
{
|
||||
var comboColours = skin.GetConfig<GlobalSkinColours, IReadOnlyList<Color4>>(GlobalSkinColours.ComboColours)?.Value ?? Array.Empty<Color4>();
|
||||
colour = combo.GetComboColour(comboColours);
|
||||
colour = combo.GetComboColour(skin);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
|
@ -10,6 +10,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.OpenGL.Textures;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Game.Audio;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.Screens.Play;
|
||||
@ -136,10 +137,10 @@ namespace osu.Game.Skinning
|
||||
|
||||
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
||||
{
|
||||
// todo: this code is pulled from LegacySkin and should not exist.
|
||||
// will likely change based on how databased storage of skin configuration goes.
|
||||
switch (lookup)
|
||||
{
|
||||
// todo: this code is pulled from LegacySkin and should not exist.
|
||||
// will likely change based on how databased storage of skin configuration goes.
|
||||
case GlobalSkinColours global:
|
||||
switch (global)
|
||||
{
|
||||
@ -148,9 +149,15 @@ namespace osu.Game.Skinning
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SkinComboColourLookup comboColour:
|
||||
return SkinUtils.As<TValue>(new Bindable<Color4>(getComboColour(Configuration, comboColour.ColourIndex)));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Color4 getComboColour(IHasComboColours source, int colourIndex)
|
||||
=> source.ComboColours[colourIndex % source.ComboColours.Count];
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ using osu.Framework.IO.Stores;
|
||||
using osu.Game.Audio;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
@ -129,6 +130,9 @@ namespace osu.Game.Skinning
|
||||
|
||||
break;
|
||||
|
||||
case SkinComboColourLookup comboColour:
|
||||
return SkinUtils.As<TValue>(GetComboColour(Configuration, comboColour.ColourIndex, comboColour.Combo));
|
||||
|
||||
case SkinCustomColourLookup customColour:
|
||||
return SkinUtils.As<TValue>(getCustomColour(Configuration, customColour.Lookup.ToString()));
|
||||
|
||||
@ -286,6 +290,18 @@ namespace osu.Game.Skinning
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the correct combo colour for a given colour index and information on the combo.
|
||||
/// </summary>
|
||||
/// <param name="source">The source to retrieve the combo colours from.</param>
|
||||
/// <param name="colourIndex">The preferred index for retrieving the combo colour with.</param>
|
||||
/// <param name="combo">Information on the combo whose using the returned colour.</param>
|
||||
protected virtual IBindable<Color4> GetComboColour(IHasComboColours source, int colourIndex, IHasComboInformation combo)
|
||||
{
|
||||
var colour = source.ComboColours?[colourIndex % source.ComboColours.Count];
|
||||
return colour.HasValue ? new Bindable<Color4>(colour.Value) : null;
|
||||
}
|
||||
|
||||
private IBindable<Color4> getCustomColour(IHasCustomColours source, string lookup)
|
||||
=> source.CustomColours.TryGetValue(lookup, out var col) ? new Bindable<Color4>(col) : null;
|
||||
|
||||
|
26
osu.Game/Skinning/SkinComboColourLookup.cs
Normal file
26
osu.Game/Skinning/SkinComboColourLookup.cs
Normal file
@ -0,0 +1,26 @@
|
||||
// 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 osu.Game.Rulesets.Objects.Types;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
public class SkinComboColourLookup
|
||||
{
|
||||
/// <summary>
|
||||
/// The index to use for deciding the combo colour.
|
||||
/// </summary>
|
||||
public readonly int ColourIndex;
|
||||
|
||||
/// <summary>
|
||||
/// The combo information requesting the colour.
|
||||
/// </summary>
|
||||
public readonly IHasComboInformation Combo;
|
||||
|
||||
public SkinComboColourLookup(int colourIndex, IHasComboInformation combo)
|
||||
{
|
||||
ColourIndex = colourIndex;
|
||||
Combo = combo;
|
||||
}
|
||||
}
|
||||
}
|
@ -272,6 +272,7 @@ namespace osu.Game.Skinning
|
||||
switch (lookup)
|
||||
{
|
||||
case GlobalSkinColours _:
|
||||
case SkinComboColourLookup _:
|
||||
case SkinCustomColourLookup _:
|
||||
if (provider.AllowColourLookup)
|
||||
return skin.GetConfig<TLookup, TValue>(lookup);
|
||||
|
Loading…
Reference in New Issue
Block a user