public void TradeStick(InventoryButton inventoryButton) { if (!AllowTrading()) { Debug.Log("Unable to trade sticks at this time."); return; } string selectedStickName = inventoryButton.stickName; Sprite selectedStickIcon = GameStateManager.Instance.GetSpriteForNewStickPopup(selectedStickName); GameStateManager.Instance.GiveStickToTrader(selectedStickName); GameStateManager.Instance.MarkCurrentTraderAsDone(); HideInventoryScreen(); ShowNewStickPopup(selectedStickIcon); }
private void BuildInventoryIcons() { // Clear out any buttons that we used last time... inventoryButtons.Clear(); // Copy the stick configs to a new array each time we build the icons to prevent re-using old state... StickConfig[] stickConfigs = (StickConfig[])GameStateManager.Instance.CurrentInventoryStickConfigs().ToArray().Clone(); for (int index = 0; index < stickConfigs.Length; index++) { StickConfig stickConfig = stickConfigs[index]; string stickName = stickConfig.name; // ReSharper disable once UseObjectOrCollectionInitializer SpriteState spriteState = new SpriteState(); //spriteState.pressedSprite = stickConfig.spriteForHighlighted; //spriteState.highlightedSprite = stickConfig.spriteForHighlighted; spriteState.selectedSprite = stickConfig.spriteForHighlighted; GameObject newButton = Instantiate(buttonPrefab, InventoryUIRoot, true); newButton.GetComponentInChildren <Text>().text = stickName; newButton.transform.SetSiblingIndex(index); newButton.name = stickName; // RectTransform rectTransform = newButton.GetComponent<RectTransform>(); newButton.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); Vector3 position = newButton.transform.localPosition; position = new Vector3(position.x, position.y, -1000.0f); newButton.transform.localPosition = position; InventoryButton newInventoryButton = newButton.GetComponent <InventoryButton>(); newInventoryButton.image.sprite = stickConfig.spriteForNormal; newInventoryButton.inventoryUserInterfaceManager = this; newInventoryButton.spriteState = spriteState; newInventoryButton.stickName = stickName; // newInventoryButton.onClick.AddListener( () => { UpdateActiveInventoryButton(stickName); } ); inventoryButtons.Add(newInventoryButton); } }