public class PlayerGuiController : MonoBehaviour {
public UIPanel panelStoreCategories;
public UIPanel panelStoreItems;
public UIGrid gridStoreItems;
public GameObject prefabSaleItem;
// Use this for initialization
void Start () {
CloseAll ();
}
public void CloseAll() {
panelStoreCategories.gameObject.SetActive(false);
panelStoreItems.gameObject.SetActive(false);
StartCoroutine(RemoveAllSaleItems());
}
public void ShowTreasure() {
CloseAll();
UILabel label = panelStoreItems.transform.FindChild("Title").GetComponent<UILabel>();
label.text = "Shop: Treasure";
panelStoreItems.gameObject.SetActive(true);
List<Dictionary<string,string>> items = ConfigManager.Instance.treasureItems;
foreach(Dictionary<string,string> item in items) {
NewSaleItem(item["title"]);
}
gridStoreItems.Reposition();
UIScrollBar sb = panelStoreItems.transform.FindChild("Scroll Bar").GetComponent<UIScrollBar>();
sb.scrollValue = 0;
}
public void ShowResources() {
CloseAll();
UILabel label = panelStoreItems.transform.FindChild("Title").GetComponent<UILabel>();
label.text = "Shop: Resources";
panelStoreItems.gameObject.SetActive(true);
List<Dictionary<string,string>> items = ConfigManager.Instance.resourceItems;
foreach(Dictionary<string,string> item in items) {
NewSaleItem(item["title"]);
}
gridStoreItems.Reposition();
UIScrollBar sb = panelStoreItems.transform.FindChild("Scroll Bar").GetComponent<UIScrollBar>();
sb.scrollValue = 0;
}
private IEnumerator RemoveAllSaleItems() {
foreach(Transform child in gridStoreItems.transform) {
child.parent = null;
DestroyImmediate(child.gameObject);
}
yield return new WaitForEndOfFrame
(); }
private void NewSaleItem(string name) {
GameObject item = NGUITools.AddChild(gridStoreItems.gameObject, prefabSaleItem);
gridStoreItems.Reposition();
UILabel label = item.transform.FindChild("Label").GetComponent<UILabel>();
label.text = name;
}
}