public void Awake() { Constants.ShopUI = gameObject; Text TG = null; Text TK = null; Text TT = null; // get important item elements UIItems = new UIItem[numElemsPerPage]; HashSet<string> addedList = new HashSet<string>(); int i = 0; foreach (Component g in gameObject.GetComponentsInChildren<Component>()) { if (g.name.StartsWith("ItemElem") && !addedList.Contains(g.name)) { UIItems[i] = new UIItem(g); UIItems[i].id = i; addedList.Add(g.name); ++i; } else if (g.name.Equals("MoneyLabel")) { foreach (Text t in g.GetComponentsInChildren<Text>()) { if (t.name.Equals("Text_G")) TG = t; else if (t.name.Equals("Text_K")) TK = t; else if (t.name.Equals("Text_T")) TT = t; else Debug.Log("MoneyLabel contained unexpected text objects? " + t.name); } break; } else if (g.name.Equals("PanelTop")) panelTop = g; else if (g.name.Equals("PanelItems")) panelItems = g; else if (g.name.Equals("PanelPageSetter")) panelPageSetter = g; else if (g.name.Equals("PanelBottom")) panelBottom = g; else if (g.name.Equals("ButtonClose")) buttonClose = new UIButton(g, mouseOverColor, mouseSelectColor, mouseSelectOverColor); else if (g.name.Equals("ButtonSelectBuy")) buttonSelectBuy = new UIButton(g, mouseOverColor, mouseSelectColor, mouseSelectOverColor); else if (g.name.Equals("ButtonSelectSell")) buttonSell = new UIButton(g, mouseOverColor, mouseSelectColor, mouseSelectOverColor); else if (g.name.Equals("ButtonSelectRebuy")) buttonRebuy = new UIButton(g, mouseOverColor, mouseSelectColor, mouseSelectOverColor); else if (g.name.Equals("TextPage")) textPage = g.GetComponent<Text>(); else if (g.name.Equals("ButtonPageLeft")) { g.GetComponent<Button>().onClick.RemoveAllListeners(); g.GetComponent<Button>().onClick.AddListener(() => { if (page - 1 >= 0) SetUpPage(--page); }); } else if (g.name.Equals("ButtonPageRight")) { g.GetComponent<Button>().onClick.RemoveAllListeners(); g.GetComponent<Button>().onClick.AddListener(() => { if (page + 1 < maxPage) SetUpPage(++page); }); } else if (g.name.Equals("ButtonBuy")) { buttonBuy = g.GetComponent<Button>(); g.GetComponent<Button>().onClick.RemoveAllListeners(); // the buttons are found multiple times in the list of child components g.GetComponent<Button>().onClick.AddListener(() => { switch(userMode) { case EShopMode.buy: if (selectedUIItem != null) // an item icon can only be selected if a valid item is presend if (Input.GetKey(KeyCode.LeftControl)) tryBuy(selectedUIItem, true); else tryBuy(selectedUIItem, false); break; case EShopMode.sell: if (selectedUIItem != null) if (Input.GetKey(KeyCode.LeftControl)) trySell(selectedUIItem, true); else trySell(selectedUIItem, false); break; case EShopMode.rebuy: if (selectedUIItem != null) if (Input.GetKey(KeyCode.LeftControl)) tryBuy(selectedUIItem, true); else tryBuy(selectedUIItem, false); break; default: throw new System.NotImplementedException(); } //TODO: apply amount selection screen during leftshift-click! }); } } UIbuyerMoney = new UICurrency(TG, TK, TT); }
/** * empty slot constructor */ public UIItem(Component itemElem) { Text TG = null, TK = null, TT = null, TN = null; foreach (Text t in itemElem.GetComponentsInChildren<Text>()) { if (t.name.Equals("Text_G")) TG = t; else if (t.name.Equals("Text_K")) TK = t; else if (t.name.Equals("Text_T")) TT = t; else if (t.name.Equals("Text_N")) TN = t; } _itemElem = itemElem; _itemElemBorderImage = itemElem.GetComponent<Image>(); _origColor = _itemElemBorderImage.color; _but = itemElem.GetComponent<Button>(); _value = new UICurrency(TG, TK, TT, TN); }