/// <summary>Method used to activate the loot screen</summary> /// <param name="loot_">Reference to the LootLocation component that contains the loot that's available</param> private void OpenLoot(LootLocation loot_) { //Activating the UI and the background UI blocker this.cityUI.cityPanelObject.SetActive(false); this.dungeonUI.dungeonPanelObject.SetActive(false); this.holyShrineUI.holyShrinePanelObject.SetActive(false); this.cursedShrineUI.cursedShrinePanelObject.SetActive(false); this.ambushUI.ambushPanelObject.SetActive(false); this.lootUI.lootPanelObject.SetActive(true); this.questUI.questPanelObject.SetActive(false); this.uiBlocker.SetActive(true); this.lootUI.nameplate.text = loot_.locationName; this.lootUI.descriptionText.text = loot_.descriptionText; this.DisplayLootItems(); }
/// <summary>Method called from OpenLoot, LootItemAtIndex, and LootAllItems to update the display of items available</summary> private void DisplayLootItems() { //If for some reason the location isn't valid, we do nothing if (!this.lootUI.lootPanelObject.activeInHierarchy || !this.currentLocation.GetComponent <LootLocation>()) { return; } //Deleting all selection buttons that aren't the main one Transform buttonParentTrans = this.lootUI.itemSelectionButton.transform.parent; for (int c = 0; c < buttonParentTrans.childCount; c++) { if (buttonParentTrans.GetChild(c) != this.lootUI.itemSelectionButton.transform) { Destroy(buttonParentTrans.GetChild(c).gameObject); c -= 1; } } //Looping through each item in the loot location and creating a new button for them LootLocation lootLoc = this.currentLocation.GetComponent <LootLocation>(); for (int b = 0; b < lootLoc.spawnedItems.Length + 1; b++) { //For the first item, we don't create a new button but instead use the default one if (b == 0) { //If there are items that were spawned if (lootLoc.spawnedItems.Length > 0) { if (lootLoc.spawnedItems[0] > 0) { this.lootUI.itemSelectionButton.gameObject.SetActive(true); this.lootUI.itemSelectionButton.selectedItemIndex = 0; this.lootUI.itemSelectionButton.itemNameText.text = lootLoc.lootTableItems[lootLoc.spawnedItems[b]].lootItem.itemNameID + " x" + lootLoc.lootTableItems[lootLoc.spawnedItems[b]].stackQuantity; } } //If the spawned items array is empty, this button can be used to store gold loot instead of items else if (lootLoc.spawnedItems.Length == 0 && lootLoc.spawnedGold > 0) { this.lootUI.itemSelectionButton.gameObject.SetActive(true); this.lootUI.itemSelectionButton.selectedItemIndex = 0; this.lootUI.itemSelectionButton.itemNameText.text = lootLoc.spawnedGold + " Gold"; } //Otherwise there's no loot at all and this button is hidden else { this.lootUI.itemSelectionButton.gameObject.SetActive(false); } } //This index is technically out of bounds for the spawnedItems array, but it's used to hold the gold loot else if (b == lootLoc.spawnedItems.Length && lootLoc.spawnedGold > 0) { //Creating a new button to display the amount of gold in the location GameObject newbutton = GameObject.Instantiate(this.lootUI.itemSelectionButton.gameObject); LootSelectionButton newSelectButton = newbutton.GetComponent <LootSelectionButton>(); newSelectButton.selectedItemIndex = b; newSelectButton.itemNameText.text = lootLoc.spawnedGold + " Gold"; } //For all other loot items, we create a new selection button to display the item else { if (lootLoc.spawnedItems[b] > 0) { GameObject newbutton = GameObject.Instantiate(this.lootUI.itemSelectionButton.gameObject); LootSelectionButton newSelectButton = newbutton.GetComponent <LootSelectionButton>(); newSelectButton.selectedItemIndex = b; newSelectButton.itemNameText.text = lootLoc.lootTableItems[lootLoc.spawnedItems[b]].lootItem.itemNameID + " x" + lootLoc.lootTableItems[lootLoc.spawnedItems[b]].stackQuantity; } } } }