mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 15:22:55 +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,
|
||||
Alpha = 0.5f,
|
||||
}
|
||||
}, restrictSize: false);
|
||||
}, confineMode: ConfineMode.NoScaling);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Icon = FontAwesome.Solid.ChevronRight
|
||||
}, restrictSize: false)
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
||||
public DrawableSliderTick(SliderTick sliderTick)
|
||||
: base(sliderTick)
|
||||
{
|
||||
Size = new Vector2(16) * sliderTick.Scale;
|
||||
Size = new Vector2(16 * sliderTick.Scale);
|
||||
Origin = Anchor.Centre;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
@ -44,7 +44,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
||||
Colour = AccentColour,
|
||||
Alpha = 0.3f,
|
||||
}
|
||||
}, restrictSize: false)
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
||||
{
|
||||
Font = OsuFont.Numeric.With(size: 40),
|
||||
UseFullGlyphHeight = false,
|
||||
}, restrictSize: false)
|
||||
}, confineMode: ConfineMode.NoScaling)
|
||||
{
|
||||
Text = @"1"
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
||||
},
|
||||
},
|
||||
}
|
||||
}, restrictSize: false)
|
||||
})
|
||||
{
|
||||
Origin = Anchor.Centre,
|
||||
Anchor = Anchor.Centre,
|
||||
|
@ -92,8 +92,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
public new Drawable Drawable => base.Drawable;
|
||||
public int SkinChangedCount { get; private set; }
|
||||
|
||||
public SkinConsumer(string name, Func<string, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
|
||||
: base(name, defaultImplementation, allowFallback, restrictSize)
|
||||
public SkinConsumer(string name, Func<string, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null)
|
||||
: base(name, defaultImplementation, allowFallback)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ namespace osu.Game.Rulesets.Judgements
|
||||
Font = OsuFont.Numeric.With(size: 12),
|
||||
Colour = judgementColour(Result.Type),
|
||||
Scale = new Vector2(0.85f, 1),
|
||||
}, restrictSize: false)
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,8 @@ namespace osu.Game.Skinning
|
||||
{
|
||||
public class SkinnableDrawable : SkinnableDrawable<Drawable>
|
||||
{
|
||||
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
|
||||
: base(name, defaultImplementation, allowFallback, restrictSize)
|
||||
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||
: base(name, defaultImplementation, allowFallback, confineMode)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -29,7 +29,7 @@ namespace osu.Game.Skinning
|
||||
|
||||
private readonly string componentName;
|
||||
|
||||
private readonly bool restrictSize;
|
||||
private readonly ConfineMode confineMode;
|
||||
|
||||
/// <summary>
|
||||
/// 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="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="restrictSize">Whether a user-skin drawable should be limited to the size of our parent.</param>
|
||||
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
|
||||
: this(name, allowFallback, restrictSize)
|
||||
/// <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, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||
: this(name, allowFallback, confineMode)
|
||||
{
|
||||
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)
|
||||
{
|
||||
componentName = name;
|
||||
this.restrictSize = restrictSize;
|
||||
this.confineMode = confineMode;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
@ -58,7 +58,7 @@ namespace osu.Game.Skinning
|
||||
protected virtual T CreateDefault(string name) => createDefault(name);
|
||||
|
||||
/// <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>
|
||||
protected virtual bool ApplySizeRestrictionsToDefault => false;
|
||||
|
||||
@ -76,12 +76,18 @@ namespace osu.Game.Skinning
|
||||
|
||||
if (Drawable != null)
|
||||
{
|
||||
if (restrictSize && (!isDefault || ApplySizeRestrictionsToDefault))
|
||||
if (confineMode != ConfineMode.NoScaling && (!isDefault || ApplySizeRestrictionsToDefault))
|
||||
{
|
||||
Drawable.RelativeSizeAxes = Axes.Both;
|
||||
Drawable.Size = Vector2.One;
|
||||
Drawable.Scale = Vector2.One;
|
||||
Drawable.FillMode = FillMode.Fit;
|
||||
bool applyScaling = confineMode == ConfineMode.ScaleToFit ||
|
||||
(confineMode == ConfineMode.ScaleDownToFit && (Drawable.DrawSize.X > DrawSize.X || Drawable.DrawSize.Y > DrawSize.Y));
|
||||
|
||||
if (applyScaling)
|
||||
{
|
||||
Drawable.RelativeSizeAxes = Axes.Both;
|
||||
Drawable.Size = Vector2.One;
|
||||
Drawable.Scale = Vector2.One;
|
||||
Drawable.FillMode = FillMode.Fit;
|
||||
}
|
||||
}
|
||||
|
||||
Drawable.Origin = Anchor.Centre;
|
||||
@ -93,4 +99,14 @@ namespace osu.Game.Skinning
|
||||
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]
|
||||
private TextureStore textures { get; set; }
|
||||
|
||||
public SkinnableSprite(string name, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
|
||||
: base(name, allowFallback, restrictSize)
|
||||
public SkinnableSprite(string name, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||
: base(name, allowFallback, confineMode)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,8 @@ namespace osu.Game.Skinning
|
||||
{
|
||||
public class SkinnableSpriteText : SkinnableDrawable<SpriteText>, IHasText
|
||||
{
|
||||
public SkinnableSpriteText(string name, Func<string, SpriteText> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
|
||||
: base(name, defaultImplementation, allowFallback, restrictSize)
|
||||
public SkinnableSpriteText(string name, Func<string, SpriteText> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||
: base(name, defaultImplementation, allowFallback, confineMode)
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user