1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-23 00:42:55 +08:00
osu-lazer/osu.Game/Skinning/TrianglesSkin.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

200 lines
8.3 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
2018-02-23 11:35:25 +08:00
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
2018-02-22 16:16:48 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
2019-08-23 19:32:43 +08:00
using osu.Game.Audio;
using osu.Game.Beatmaps.Formats;
using osu.Game.Extensions;
using osu.Game.IO;
using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Play.HUD.HitErrorMeters;
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
2018-02-22 16:16:48 +08:00
namespace osu.Game.Skinning
{
2022-09-17 23:14:49 +08:00
public class TrianglesSkin : Skin
2018-02-22 16:16:48 +08:00
{
2021-11-29 16:15:26 +08:00
public static SkinInfo CreateInfo() => new SkinInfo
{
2022-09-17 23:14:49 +08:00
ID = osu.Game.Skinning.SkinInfo.TRIANGLES_SKIN,
2022-09-15 14:49:15 +08:00
Name = "osu! \"triangles\" (2017)",
2021-11-29 16:15:26 +08:00
Creator = "team osu!",
Protected = true,
2022-09-17 23:14:49 +08:00
InstantiationInfo = typeof(TrianglesSkin).GetInvariantInstantiationInfo()
2021-11-29 16:15:26 +08:00
};
private readonly IStorageResourceProvider resources;
2022-09-17 23:14:49 +08:00
public TrianglesSkin(IStorageResourceProvider resources)
2021-11-29 16:15:26 +08:00
: this(CreateInfo(), resources)
2018-02-22 16:16:48 +08:00
{
}
2018-04-13 17:19:50 +08:00
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedWithFixedConstructorSignature)]
2022-09-17 23:14:49 +08:00
public TrianglesSkin(SkinInfo skin, IStorageResourceProvider resources)
: base(skin, resources)
2018-02-22 16:16:48 +08:00
{
this.resources = resources;
2018-02-22 16:16:48 +08:00
}
2018-04-13 17:19:50 +08:00
public override Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => Textures?.Get(componentName, wrapModeS, wrapModeT);
2018-04-13 17:19:50 +08:00
public override ISample GetSample(ISampleInfo sampleInfo)
{
foreach (string lookup in sampleInfo.LookupNames)
{
var sample = Samples?.Get(lookup) ?? resources.AudioManager?.Samples.Get(lookup);
if (sample != null)
return sample;
}
return null;
}
public override Drawable GetDrawableComponent(ISkinComponent component)
{
if (base.GetDrawableComponent(component) is Drawable c)
return c;
switch (component)
{
case SkinnableTargetComponent target:
switch (target.Target)
{
case SkinnableTarget.SongSelect:
2022-06-24 20:25:23 +08:00
var songSelectComponents = new SkinnableTargetComponentsContainer(_ =>
{
// do stuff when we need to.
});
return songSelectComponents;
case SkinnableTarget.MainHUDComponents:
var skinnableTargetWrapper = new SkinnableTargetComponentsContainer(container =>
{
var score = container.OfType<DefaultScoreCounter>().FirstOrDefault();
var accuracy = container.OfType<DefaultAccuracyCounter>().FirstOrDefault();
var combo = container.OfType<DefaultComboCounter>().FirstOrDefault();
2021-10-04 19:34:08 +08:00
var ppCounter = container.OfType<PerformancePointsCounter>().FirstOrDefault();
if (score != null)
{
score.Anchor = Anchor.TopCentre;
score.Origin = Anchor.TopCentre;
// elements default to beneath the health bar
const float vertical_offset = 30;
const float horizontal_padding = 20;
score.Position = new Vector2(0, vertical_offset);
2021-09-30 16:55:00 +08:00
if (ppCounter != null)
{
ppCounter.Y = score.Position.Y + ppCounter.ScreenSpaceDeltaToParentSpace(score.ScreenSpaceDrawQuad.Size).Y - 4;
2021-09-30 16:55:00 +08:00
ppCounter.Origin = Anchor.TopCentre;
ppCounter.Anchor = Anchor.TopCentre;
}
if (accuracy != null)
{
accuracy.Position = new Vector2(-accuracy.ScreenSpaceDeltaToParentSpace(score.ScreenSpaceDrawQuad.Size).X / 2 - horizontal_padding, vertical_offset + 5);
accuracy.Origin = Anchor.TopRight;
accuracy.Anchor = Anchor.TopCentre;
if (combo != null)
{
combo.Position = new Vector2(accuracy.ScreenSpaceDeltaToParentSpace(score.ScreenSpaceDrawQuad.Size).X / 2 + horizontal_padding, vertical_offset + 5);
combo.Anchor = Anchor.TopCentre;
}
}
var hitError = container.OfType<HitErrorMeter>().FirstOrDefault();
if (hitError != null)
{
hitError.Anchor = Anchor.CentreLeft;
hitError.Origin = Anchor.CentreLeft;
}
var hitError2 = container.OfType<HitErrorMeter>().LastOrDefault();
if (hitError2 != null)
{
hitError2.Anchor = Anchor.CentreRight;
hitError2.Scale = new Vector2(-1, 1);
// origin flipped to match scale above.
hitError2.Origin = Anchor.CentreLeft;
}
}
})
{
Children = new Drawable[]
{
new DefaultComboCounter(),
new DefaultScoreCounter(),
new DefaultAccuracyCounter(),
new DefaultHealthDisplay(),
new DefaultSongProgress(),
new BarHitErrorMeter(),
new BarHitErrorMeter(),
2021-10-04 19:34:08 +08:00
new PerformancePointsCounter()
}
};
return skinnableTargetWrapper;
}
return null;
}
switch (component.LookupName)
{
// Temporary until default skin has a valid hit lighting.
case @"lighting":
return Drawable.Empty();
}
if (GetTexture(component.LookupName) is Texture t)
return new Sprite { Texture = t };
return null;
}
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)
{
case GlobalSkinColours global:
switch (global)
{
case GlobalSkinColours.ComboColours:
return SkinUtils.As<TValue>(new Bindable<IReadOnlyList<Color4>>(Configuration.ComboColours));
}
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];
2018-02-22 16:16:48 +08:00
}
}