-
Notifications
You must be signed in to change notification settings - Fork 348
Expand file tree
/
Copy pathInstrumentDifficultyView.cs
More file actions
85 lines (70 loc) · 3.08 KB
/
Copy pathInstrumentDifficultyView.cs
File metadata and controls
85 lines (70 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.UI;
using YARG.Core.Game;
using YARG.Helpers.Extensions;
using YARG.Settings;
namespace YARG.Menu.MusicLibrary
{
public class InstrumentDifficultyView : MonoBehaviour
{
private static readonly Dictionary<string, Sprite> SpriteCache = new();
[SerializeField]
private Image _instrumentIcon;
[SerializeField]
private Image _difficultyIcon;
[SerializeField]
private Image _difficultyRing;
[SerializeField]
private TextMeshProUGUI _percentText;
private static readonly Color FcGold = new(1, 208 / 255f, 41 / 255f);
private static readonly Color DefaultEngineColor = Color.white;
private static readonly Color CasualEngineColor = new(0.9f, 0.3f, 0.9f);
private static readonly Color PrecisionEngineColor = new(1f, 0.9f, 0f);
private static readonly Color SoloTapsEngineColor = new(0.5411765f, 0.1686275f, 0.8862746f);
private static readonly Color CustomEngineColor = new(1f, 0.25f, 0.25f);
public void SetInfo(ViewType.ScoreInfo scoreInfo)
{
// Set width
var rect = GetComponent<RectTransform>();
var length = SettingsManager.Settings.ShowPercentDecimals.Value ? 150 : 130;
rect.sizeDelta = new Vector2(length, rect.sizeDelta.y);
// Set instrument icon
_instrumentIcon.sprite = GetSprite($"InstrumentIcons[{scoreInfo.Instrument.ToResourceName()}]");
// Set difficulty icon
_difficultyIcon.sprite = GetSprite($"DifficultyIcons[{scoreInfo.Difficulty.ToString()}]");
_difficultyIcon.color = Color.white;
_difficultyRing.color = GetEngineColor(scoreInfo.EnginePresetId);
// Set percent value
if (SettingsManager.Settings.ShowPercentDecimals.Value)
{
var percent = Mathf.Floor(scoreInfo.Percent * 1000f) / 10f;
_percentText.text = $"{percent:0.0}%";
}
else
{
_percentText.text = $"{Mathf.FloorToInt(scoreInfo.Percent * 100f)}%";
}
_percentText.color = scoreInfo.IsFc ? FcGold : Color.white;
}
private static Sprite GetSprite(string assetKey)
{
if (!SpriteCache.TryGetValue(assetKey, out var sprite))
{
SpriteCache[assetKey] = sprite = Addressables.LoadAssetAsync<Sprite>(assetKey).WaitForCompletion();
}
return sprite;
}
private static Color GetEngineColor(Guid enginePresetId) => enginePresetId switch
{
var id when id == Guid.Empty || id == EnginePreset.Default.Id => DefaultEngineColor,
var id when id == EnginePreset.Casual.Id => CasualEngineColor,
var id when id == EnginePreset.Precision.Id => PrecisionEngineColor,
var id when id == EnginePreset.SoloTaps.Id => SoloTapsEngineColor,
_ => CustomEngineColor
};
}
}