mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 13:23:05 +08:00
Add more flexible skin element confine modes
This commit is contained in:
parent
38d39be678
commit
74c961bcff
@ -41,7 +41,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Alpha = 0.5f,
|
Alpha = 0.5f,
|
||||||
}
|
}
|
||||||
}, restrictSize: false);
|
}, confineMode: ConfineMode.NoScaling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Icon = FontAwesome.Solid.ChevronRight
|
Icon = FontAwesome.Solid.ChevronRight
|
||||||
}, restrictSize: false)
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
public DrawableSliderTick(SliderTick sliderTick)
|
public DrawableSliderTick(SliderTick sliderTick)
|
||||||
: base(sliderTick)
|
: base(sliderTick)
|
||||||
{
|
{
|
||||||
Size = new Vector2(16) * sliderTick.Scale;
|
Size = new Vector2(16 * sliderTick.Scale);
|
||||||
Origin = Anchor.Centre;
|
Origin = Anchor.Centre;
|
||||||
|
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
@ -44,7 +44,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
Colour = AccentColour,
|
Colour = AccentColour,
|
||||||
Alpha = 0.3f,
|
Alpha = 0.3f,
|
||||||
}
|
}
|
||||||
}, restrictSize: false)
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|||||||
{
|
{
|
||||||
Font = OsuFont.Numeric.With(size: 40),
|
Font = OsuFont.Numeric.With(size: 40),
|
||||||
UseFullGlyphHeight = false,
|
UseFullGlyphHeight = false,
|
||||||
}, restrictSize: false)
|
}, confineMode: ConfineMode.NoScaling)
|
||||||
{
|
{
|
||||||
Text = @"1"
|
Text = @"1"
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}, restrictSize: false)
|
})
|
||||||
{
|
{
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
|
@ -92,8 +92,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
public new Drawable Drawable => base.Drawable;
|
public new Drawable Drawable => base.Drawable;
|
||||||
public int SkinChangedCount { get; private set; }
|
public int SkinChangedCount { get; private set; }
|
||||||
|
|
||||||
public SkinConsumer(string name, Func<string, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
|
public SkinConsumer(string name, Func<string, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null)
|
||||||
: base(name, defaultImplementation, allowFallback, restrictSize)
|
: base(name, defaultImplementation, allowFallback)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ namespace osu.Game.Rulesets.Judgements
|
|||||||
Font = OsuFont.Numeric.With(size: 12),
|
Font = OsuFont.Numeric.With(size: 12),
|
||||||
Colour = judgementColour(Result.Type),
|
Colour = judgementColour(Result.Type),
|
||||||
Scale = new Vector2(0.85f, 1),
|
Scale = new Vector2(0.85f, 1),
|
||||||
}, restrictSize: false)
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ namespace osu.Game.Skinning
|
|||||||
{
|
{
|
||||||
public class SkinnableDrawable : SkinnableDrawable<Drawable>
|
public class SkinnableDrawable : SkinnableDrawable<Drawable>
|
||||||
{
|
{
|
||||||
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
|
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||||
: base(name, defaultImplementation, allowFallback, restrictSize)
|
: base(name, defaultImplementation, allowFallback, confineMode)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
private readonly string componentName;
|
private readonly string componentName;
|
||||||
|
|
||||||
private readonly bool restrictSize;
|
private readonly ConfineMode confineMode;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new skinnable drawable.
|
/// Create a new skinnable drawable.
|
||||||
@ -37,18 +37,18 @@ namespace osu.Game.Skinning
|
|||||||
/// <param name="name">The namespace-complete resource name for this skinnable element.</param>
|
/// <param name="name">The namespace-complete resource name for this skinnable element.</param>
|
||||||
/// <param name="defaultImplementation">A function to create the default skin implementation of this element.</param>
|
/// <param name="defaultImplementation">A function to create the default skin implementation of this element.</param>
|
||||||
/// <param name="allowFallback">A conditional to decide whether to allow fallback to the default implementation if a skinned element is not present.</param>
|
/// <param name="allowFallback">A conditional to decide whether to allow fallback to the default implementation if a skinned element is not present.</param>
|
||||||
/// <param name="restrictSize">Whether a user-skin drawable should be limited to the size of our parent.</param>
|
/// <param name="confineMode">How (if at all) the <see cref="Drawable"/> should be resize to fit within our own bounds.</param>
|
||||||
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
|
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||||
: this(name, allowFallback, restrictSize)
|
: this(name, allowFallback, confineMode)
|
||||||
{
|
{
|
||||||
createDefault = defaultImplementation;
|
createDefault = defaultImplementation;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SkinnableDrawable(string name, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
|
protected SkinnableDrawable(string name, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||||
: base(allowFallback)
|
: base(allowFallback)
|
||||||
{
|
{
|
||||||
componentName = name;
|
componentName = name;
|
||||||
this.restrictSize = restrictSize;
|
this.confineMode = confineMode;
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ namespace osu.Game.Skinning
|
|||||||
protected virtual T CreateDefault(string name) => createDefault(name);
|
protected virtual T CreateDefault(string name) => createDefault(name);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to apply size restrictions (specified via <see cref="restrictSize"/>) to the default implementation.
|
/// Whether to apply size restrictions (specified via <see cref="confineMode"/>) to the default implementation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual bool ApplySizeRestrictionsToDefault => false;
|
protected virtual bool ApplySizeRestrictionsToDefault => false;
|
||||||
|
|
||||||
@ -76,12 +76,18 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
if (Drawable != null)
|
if (Drawable != null)
|
||||||
{
|
{
|
||||||
if (restrictSize && (!isDefault || ApplySizeRestrictionsToDefault))
|
if (confineMode != ConfineMode.NoScaling && (!isDefault || ApplySizeRestrictionsToDefault))
|
||||||
{
|
{
|
||||||
Drawable.RelativeSizeAxes = Axes.Both;
|
bool applyScaling = confineMode == ConfineMode.ScaleToFit ||
|
||||||
Drawable.Size = Vector2.One;
|
(confineMode == ConfineMode.ScaleDownToFit && (Drawable.DrawSize.X > DrawSize.X || Drawable.DrawSize.Y > DrawSize.Y));
|
||||||
Drawable.Scale = Vector2.One;
|
|
||||||
Drawable.FillMode = FillMode.Fit;
|
if (applyScaling)
|
||||||
|
{
|
||||||
|
Drawable.RelativeSizeAxes = Axes.Both;
|
||||||
|
Drawable.Size = Vector2.One;
|
||||||
|
Drawable.Scale = Vector2.One;
|
||||||
|
Drawable.FillMode = FillMode.Fit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Drawable.Origin = Anchor.Centre;
|
Drawable.Origin = Anchor.Centre;
|
||||||
@ -93,4 +99,14 @@ namespace osu.Game.Skinning
|
|||||||
ClearInternal();
|
ClearInternal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ConfineMode
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Don't apply any scaling. This allows the user element to be of any size, exceeding specified bounds.
|
||||||
|
/// </summary>
|
||||||
|
NoScaling,
|
||||||
|
ScaleDownToFit,
|
||||||
|
ScaleToFit,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@ namespace osu.Game.Skinning
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private TextureStore textures { get; set; }
|
private TextureStore textures { get; set; }
|
||||||
|
|
||||||
public SkinnableSprite(string name, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
|
public SkinnableSprite(string name, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||||
: base(name, allowFallback, restrictSize)
|
: base(name, allowFallback, confineMode)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ namespace osu.Game.Skinning
|
|||||||
{
|
{
|
||||||
public class SkinnableSpriteText : SkinnableDrawable<SpriteText>, IHasText
|
public class SkinnableSpriteText : SkinnableDrawable<SpriteText>, IHasText
|
||||||
{
|
{
|
||||||
public SkinnableSpriteText(string name, Func<string, SpriteText> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
|
public SkinnableSpriteText(string name, Func<string, SpriteText> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||||
: base(name, defaultImplementation, allowFallback, restrictSize)
|
: base(name, defaultImplementation, allowFallback, confineMode)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user