You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.7 KiB
78 lines
2.7 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
/// <summary>
|
|
/// This component searches all children for a bunch of other components such as names, descriptions, stats, etc
|
|
/// and updates them with all necessary information whenever it is updated.
|
|
/// It is assumed that children of a view info panel never get destroyed separately, as it is treated as one object.
|
|
/// Similarly, it is assumed that all children already exist at the time of startup.
|
|
/// </summary>
|
|
public class ViewItemInfoPanel : MonoBehaviour
|
|
{
|
|
private List<ItemNameDisplay> names;
|
|
private List<ItemStatsDisplay> stats;
|
|
private List<ItemTypeDisplay> types;
|
|
private List<ItemPriceDisplay> prices;
|
|
private List<ItemDescriptionDisplay> descr;
|
|
private List<ItemClassDisplay> rarity;
|
|
private void Awake()
|
|
{
|
|
UpdateComponentInfo();
|
|
}
|
|
|
|
private void UpdateComponentInfo()
|
|
{
|
|
names = GetComponentsInChildren<ItemNameDisplay>().ToList();
|
|
Debug.Assert(names != null,this);
|
|
stats = GetComponentsInChildren<ItemStatsDisplay>().ToList();
|
|
types = GetComponentsInChildren<ItemTypeDisplay>().ToList();
|
|
prices = GetComponentsInChildren<ItemPriceDisplay>().ToList();
|
|
descr = GetComponentsInChildren<ItemDescriptionDisplay>().ToList();
|
|
rarity = GetComponentsInChildren<ItemClassDisplay>().ToList();
|
|
//if (names == null) names = ;
|
|
// TODO: Create and add all other types in here as components!
|
|
}
|
|
|
|
// When this is set, it updates all relevant game objects to reflect the item's propertiese.
|
|
public void SetItemInfo(Item item)
|
|
{
|
|
if (item == null)
|
|
{
|
|
gameObject.SetActive(false); // If the seelcted item doesn't exist, disable the whole panel
|
|
return;
|
|
}
|
|
if(names == null) UpdateComponentInfo(); // Assume that if the names component is null, we probably never initialised
|
|
//gameObject.SetActive(true);
|
|
foreach (var name in names)
|
|
{
|
|
name.SetName(item.name);
|
|
}
|
|
|
|
foreach (var itemStatsDisplay in stats)
|
|
{
|
|
itemStatsDisplay.SetStats(item.GetStats());
|
|
}
|
|
|
|
foreach (var type in types)
|
|
{
|
|
type.SetType(item.GetItemType().ToString());
|
|
}
|
|
|
|
foreach (var price in prices)
|
|
{
|
|
price.SetPrice(item.basePrice); // TODO: Price modifier here!
|
|
}
|
|
|
|
foreach (var descriptionDisplay in descr)
|
|
{
|
|
descriptionDisplay.SetDescription(item.description);
|
|
}
|
|
|
|
foreach (var itemClass in rarity)
|
|
{
|
|
itemClass.SetClass(item.rarity);
|
|
}
|
|
}
|
|
}
|
|
|