using UnityEngine;
using System.Collections.Generic;
public class ResearchWindow : MonoBehaviour {
// Contains all our tech tree data:
public TechTreeManager techTree;
// Each row of this will be a tech lineage:
public GameObject techLineageTable;
// The prefab we use for each tech node displayed in the tree:
public GameObject techButtonPrefab;
// Various UI labels:
public UILabel researchPoints;
public UILabel techLabel;
public UILabel techDescription;
public UILabel techCost;
private TechNode _activeNode;
/**
* Set the active node details:
**/
public TechNode ActiveNode
{
get
{
return _activeNode;
}
set
{
_activeNode = value;
if (value != null)
{
if (techLabel != null)
{
techLabel.text = _activeNode.name;
techDescription.text = _activeNode.description;
techCost.text = "Cost: " + _activeNode.researchPoints + " RP";
}
}
}
}
void Start () {
DrawTechTree();
researchPoints.text = "You have " + GameManager.Instance.player.researchPoints + " Research Points";
}
// Update is called once per frame
void Update () {
// This actually DOES reset the position how we want, but we don't want it here:
//UIScrollView scrollView = GetComponentInChildren<UIScrollView>();
//scrollView.ResetPosition();
}
/**
* Adds the individual lineage tables to the overall tech tree table, and the individual
* node buttons to each of those linage tables.
**/
private void DrawTechTree()
{
// Get the scrollview:
UIScrollView scrollView = GetComponentInChildren<UIScrollView>();
scrollView.ResetPosition();
// Get a list of all lineages:
List<string> lineageIds = techTree.GetLineageIds();
foreach (string id in lineageIds)
{
TechLineage lineage = techTree.GetLineage(id);
// Create a UITable for this lineage row:
GameObject lineageRow = NGUITools.AddChild(techLineageTable);
UITable rowTable = lineageRow.AddComponent<UITable>();
// For each node in the linage, add a button for it:
foreach (TechNode node in lineage.nodes)
{
GameObject nodeButton = NGUITools.AddChild(lineageRow, techButtonPrefab);
TechNodeButton techNodeButton = nodeButton.GetComponent<TechNodeButton>();
techNodeButton.Node = node;
techNodeButton.researchWindow = this;
}
rowTable.Reposition();
}
// This does nothing:
scrollView.ResetPosition();
}
}