mirror of
https://github.com/ppy/osu.git
synced 2025-01-30 06:12:58 +08:00
Make skinning better
This commit is contained in:
parent
8914585021
commit
4cee21f356
@ -65,7 +65,7 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawable
|
|||||||
base.SkinChanged(skin, allowFallback);
|
base.SkinChanged(skin, allowFallback);
|
||||||
|
|
||||||
if (HitObject is IHasComboInformation combo)
|
if (HitObject is IHasComboInformation combo)
|
||||||
AccentColour = skin.GetValue<SkinConfiguration, Color4>(s => s.ComboColours.Count > 0 ? s.ComboColours[combo.ComboIndex % s.ComboColours.Count] : (Color4?)null) ?? Color4.White;
|
AccentColour = skin.GetValue<SkinConfiguration, Color4>(s => s.ComboColours.Count > 0 ? s.ComboColours[combo.ComboIndex % s.ComboColours.Count] : Color4.White);
|
||||||
}
|
}
|
||||||
|
|
||||||
private const float preempt = 1000;
|
private const float preempt = 1000;
|
||||||
|
@ -58,7 +58,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
base.SkinChanged(skin, allowFallback);
|
base.SkinChanged(skin, allowFallback);
|
||||||
|
|
||||||
if (HitObject is IHasComboInformation combo)
|
if (HitObject is IHasComboInformation combo)
|
||||||
AccentColour = skin.GetValue<SkinConfiguration, Color4>(s => s.ComboColours.Count > 0 ? s.ComboColours[combo.ComboIndex % s.ComboColours.Count] : (Color4?)null) ?? Color4.White;
|
AccentColour = skin.GetValue<SkinConfiguration, Color4>(s => s.ComboColours.Count > 0 ? s.ComboColours[combo.ComboIndex % s.ComboColours.Count] : Color4.White);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void UpdatePreemptState() => this.FadeIn(HitObject.TimeFadeIn);
|
protected virtual void UpdatePreemptState() => this.FadeIn(HitObject.TimeFadeIn);
|
||||||
|
@ -155,9 +155,10 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
|
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
|
||||||
{
|
{
|
||||||
base.SkinChanged(skin, allowFallback);
|
base.SkinChanged(skin, allowFallback);
|
||||||
Body.AccentColour = skin.GetValue<SkinConfiguration, Color4>(s => s.CustomColours.ContainsKey("SliderTrackOverride") ? s.CustomColours["SliderTrackOverride"] : (Color4?)null) ?? Body.AccentColour;
|
|
||||||
Body.BorderColour = skin.GetValue<SkinConfiguration, Color4>(s => s.CustomColours.ContainsKey("SliderBorder") ? s.CustomColours["SliderBorder"] : (Color4?)null) ?? Body.BorderColour;
|
Body.AccentColour = skin.GetValue<SkinConfiguration, Color4>(s => s.CustomColours.ContainsKey("SliderTrackOverride") ? s.CustomColours["SliderTrackOverride"] : Body.AccentColour);
|
||||||
Ball.AccentColour = skin.GetValue<SkinConfiguration, Color4>(s => s.CustomColours.ContainsKey("SliderBall") ? s.CustomColours["SliderBall"] : (Color4?)null) ?? Ball.AccentColour;
|
Body.BorderColour = skin.GetValue<SkinConfiguration, Color4>(s => s.CustomColours.ContainsKey("SliderBorder") ? s.CustomColours["SliderBorder"] : Body.BorderColour);
|
||||||
|
Ball.AccentColour = skin.GetValue<SkinConfiguration, Color4>(s => s.CustomColours.ContainsKey("SliderBall") ? s.CustomColours["SliderBall"] : Ball.AccentColour);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
||||||
|
@ -111,7 +111,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
|
|
||||||
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
|
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
|
||||||
{
|
{
|
||||||
cursorExpand = skin.GetValue<SkinConfiguration, bool>(s => s.CursorExpand) ?? true;
|
cursorExpand = skin.GetValue<SkinConfiguration, bool>(s => s.CursorExpand ?? true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
|
@ -21,8 +21,8 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
SampleChannel GetSample(string sampleName);
|
SampleChannel GetSample(string sampleName);
|
||||||
|
|
||||||
TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration where TValue : class;
|
TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration;
|
||||||
|
|
||||||
TValue? GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue?> query) where TConfiguration : SkinConfiguration where TValue : struct;
|
bool TryGetValue<TConfiguration, TValue>(Func<TConfiguration, TValue, bool> query, out TValue val) where TConfiguration : SkinConfiguration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,22 +43,30 @@ namespace osu.Game.Skinning
|
|||||||
return fallbackSource?.GetSample(sampleName);
|
return fallbackSource?.GetSample(sampleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TValue? GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue?> query) where TConfiguration : SkinConfiguration where TValue : struct
|
public TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration
|
||||||
{
|
|
||||||
TValue? val;
|
|
||||||
if ((source as Skin)?.Configuration is TConfiguration conf)
|
|
||||||
if (beatmapSkins && (val = query?.Invoke(conf)) != null)
|
|
||||||
return val;
|
|
||||||
return fallbackSource?.GetValue(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration where TValue : class
|
|
||||||
{
|
{
|
||||||
TValue val;
|
TValue val;
|
||||||
if ((source as Skin)?.Configuration is TConfiguration conf)
|
if ((source as Skin)?.Configuration is TConfiguration conf)
|
||||||
if (beatmapSkins && (val = query?.Invoke(conf)) != null)
|
if (beatmapSkins && (val = query.Invoke(conf)) != null)
|
||||||
return val;
|
return val;
|
||||||
return fallbackSource?.GetValue(query);
|
|
||||||
|
return fallbackSource == null ? default : fallbackSource.GetValue(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryGetValue<TConfiguration, TValue>(Func<TConfiguration, TValue, bool> query, out TValue val) where TConfiguration : SkinConfiguration
|
||||||
|
{
|
||||||
|
val = default;
|
||||||
|
|
||||||
|
if ((source as Skin)?.Configuration is TConfiguration conf)
|
||||||
|
if (beatmapSkins && query(conf, val))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (fallbackSource == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fallbackSource.TryGetValue(query, out val);
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ISkinSource source;
|
private readonly ISkinSource source;
|
||||||
|
@ -22,11 +22,18 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
public abstract Texture GetTexture(string componentName);
|
public abstract Texture GetTexture(string componentName);
|
||||||
|
|
||||||
public TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration where TValue : class
|
public TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration
|
||||||
=> Configuration is TConfiguration conf ? query?.Invoke(conf) : null;
|
=> Configuration is TConfiguration conf ? query.Invoke(conf) : default;
|
||||||
|
|
||||||
public TValue? GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue?> query) where TConfiguration : SkinConfiguration where TValue : struct
|
public bool TryGetValue<TConfiguration, TValue>(Func<TConfiguration, TValue, bool> query, out TValue val) where TConfiguration : SkinConfiguration
|
||||||
=> Configuration is TConfiguration conf ? query?.Invoke(conf) : null;
|
{
|
||||||
|
val = default;
|
||||||
|
|
||||||
|
if (Configuration is TConfiguration conf)
|
||||||
|
return query(conf, val);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected Skin(SkinInfo skin)
|
protected Skin(SkinInfo skin)
|
||||||
{
|
{
|
||||||
|
@ -116,8 +116,8 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
public SampleChannel GetSample(string sampleName) => CurrentSkin.Value.GetSample(sampleName);
|
public SampleChannel GetSample(string sampleName) => CurrentSkin.Value.GetSample(sampleName);
|
||||||
|
|
||||||
public TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration where TValue : class => CurrentSkin.Value.GetValue(query);
|
public TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration => CurrentSkin.Value.GetValue(query);
|
||||||
|
|
||||||
public TValue? GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue?> query) where TConfiguration : SkinConfiguration where TValue : struct => CurrentSkin.Value.GetValue(query);
|
public bool TryGetValue<TConfiguration, TValue>(Func<TConfiguration, TValue, bool> query, out TValue val) where TConfiguration : SkinConfiguration => CurrentSkin.Value.TryGetValue(query, out val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user