Add browser item meta interface.
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Unity;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
@@ -19,6 +23,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
TMP_Text m_desc;
|
||||
|
||||
StateTweener _tweener;
|
||||
AsyncDelivery<Texture2D> _cover;
|
||||
|
||||
void Awake() {
|
||||
_tweener = GetComponent<StateTweener>();
|
||||
@@ -28,7 +33,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
OnReset();
|
||||
}
|
||||
protected override void OnReset() {
|
||||
if (meta.Cover != null) meta.Cover.Cancel();
|
||||
if (_cover != null) _cover.Cancel();
|
||||
if (m_icon.sprite != null && m_icon.sprite != m_iconPlaceholder) {
|
||||
Destroy(m_icon.sprite.texture);
|
||||
Destroy(m_icon.sprite);
|
||||
@@ -38,18 +43,43 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
|
||||
protected override void OnLoad(bool selected) {
|
||||
m_icon.sprite = m_iconPlaceholder;
|
||||
if (meta.Cover != null) meta.Cover.Destination = DisplayCover;
|
||||
if (meta.Meta != null) {
|
||||
m_title.text = meta.Meta.song.name;
|
||||
m_desc.text = meta.Meta.name;
|
||||
m_desc.text = string.Empty;
|
||||
|
||||
var basicProps = EnumerateBasicProperties().GetEnumerator();
|
||||
if (basicProps.MoveNext()) {
|
||||
m_title.text = basicProps.Current.Value;
|
||||
if (basicProps.MoveNext()) {
|
||||
m_desc.text = basicProps.Current.Value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_title.text = "<color=#ff0000>Invalid resource</color>";
|
||||
m_desc.text = string.Empty;
|
||||
}
|
||||
|
||||
_cover = (AsyncDelivery<Texture2D>)EnumerateProperties().Where(prop => prop.Value is AsyncDelivery<Texture2D>).FirstOrDefault().Value;
|
||||
|
||||
if (_cover != null) _cover.Destination = DisplayCover;
|
||||
if (selected) _tweener.EnterState("Selected");
|
||||
}
|
||||
private void DisplayCover(bool succeeded, Texture2D tex) {
|
||||
IEnumerable<KeyValuePair<string, string>> EnumerateBasicProperties() {
|
||||
foreach (var prop in EnumerateProperties()) {
|
||||
if (prop.Value is string || prop.Value is IFormattable) {
|
||||
yield return new KeyValuePair<string, string>(prop.Key, prop.Value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
IEnumerable<KeyValuePair<string, object>> EnumerateProperties() {
|
||||
foreach (var prop in meta.Properties) {
|
||||
if (prop.Values.ContainsKey("distinct-primary")) {
|
||||
yield return new KeyValuePair<string, object>(prop.Name, prop.Values["distinct-primary"]);
|
||||
if (prop.Values.ContainsKey("distinct-secondary")) {
|
||||
yield return new KeyValuePair<string, object>(prop.Name, prop.Values["distinct-secondary"]);
|
||||
}
|
||||
}
|
||||
else yield return new KeyValuePair<string, object>(prop.Name, prop.MainValue);
|
||||
}
|
||||
}
|
||||
void DisplayCover(bool succeeded, Texture2D tex) {
|
||||
if (succeeded) {
|
||||
m_icon.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 160, 0, SpriteMeshType.FullRect);
|
||||
}
|
||||
|
Reference in New Issue
Block a user