Add type constraints for resource managers. Generalize detail panel.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Unity;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -45,40 +43,22 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
m_icon.sprite = m_iconPlaceholder;
|
||||
m_desc.text = string.Empty;
|
||||
|
||||
var basicProps = EnumerateBasicProperties().GetEnumerator();
|
||||
var basicProps = meta.EnumerateBasicProperties(true).GetEnumerator();
|
||||
if (basicProps.MoveNext()) {
|
||||
m_title.text = basicProps.Current.Value;
|
||||
m_title.text = basicProps.Current.Value.ToString();
|
||||
if (basicProps.MoveNext()) {
|
||||
m_desc.text = basicProps.Current.Value;
|
||||
m_desc.text = basicProps.Current.Value.ToString();
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_title.text = "<color=#ff0000>Invalid resource</color>";
|
||||
}
|
||||
|
||||
_cover = (AsyncDelivery<Texture2D>)EnumerateProperties().Where(prop => prop.Value is AsyncDelivery<Texture2D>).FirstOrDefault().Value;
|
||||
_cover = meta.EnumerateProperties<AsyncDelivery<Texture2D>>().FirstOrDefault().Value;
|
||||
|
||||
if (_cover != null) _cover.Destination = DisplayCover;
|
||||
if (selected) _tweener.EnterState("Selected");
|
||||
}
|
||||
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