// Assign our componenet based on the slot type. private void LateUpdate() { player = Player.localPlayer; if (player != null) { switch (slotType) { case SlotType.Equipment: // refresh all int lastECount = 0; if (lastECount != player.equipment.Count) { for (int i = 0; i < player.equipment.Count; ++i) { lastECount = player.equipment.Count; if (player.equipment[i].amount > 0) { UIEquipment equipmentContents = gameObject.GetComponent <UIEquipment>(); UIUtils.BalancePrefabs(equipmentContents.slotPrefab.gameObject, player.equipment.Count, equipmentContents.content); if (equipmentContents.panel.activeSelf) { UIEquipmentSlot slot = equipmentContents.content.transform.GetChild(i).GetComponent <UIEquipmentSlot>(); raritySlot = slot.GetComponent <UCE_RaritySlot>(); tooltip = slot.tooltip; slot.dragAndDropable.name = i.ToString(); // drag and drop slot itemSlot = player.equipment[i]; SetRarityColor(itemSlot.item.data); } } else { UIEquipment equipmentContents = gameObject.GetComponent <UIEquipment>(); if (equipmentContents.panel.activeSelf) { UIEquipmentSlot slot = equipmentContents.content.transform.GetChild(i).GetComponent <UIEquipmentSlot>(); raritySlot = slot.GetComponent <UCE_RaritySlot>(); raritySlot.rarityOutline.color = Color.clear; } } } } break; case SlotType.Inventory: // refresh all int lastICount = 0; if (lastICount != player.inventory.Count) { for (int i = 0; i < player.inventory.Count; ++i) { lastICount = player.inventory.Count; if (player.inventory[i].amount > 0) { UIInventory inventoryContents = GetComponent <UIInventory>(); UIUtils.BalancePrefabs(inventoryContents.slotPrefab.gameObject, player.inventory.Count, inventoryContents.content); if (inventoryContents.panel.activeSelf) { UIInventorySlot slot = inventoryContents.content.transform.GetChild(i).GetComponent <UIInventorySlot>(); raritySlot = slot.GetComponent <UCE_RaritySlot>(); tooltip = slot.tooltip; slot.dragAndDropable.name = i.ToString(); // drag and drop slot itemSlot = player.inventory[i]; SetRarityColor(itemSlot.item.data); } } else { UIInventory inventoryContents = gameObject.GetComponent <UIInventory>(); if (inventoryContents.panel.activeSelf) { UIInventorySlot slot = inventoryContents.content.transform.GetChild(i).GetComponent <UIInventorySlot>(); raritySlot = slot.GetComponent <UCE_RaritySlot>(); raritySlot.rarityOutline.color = Color.clear; } } } } break; case SlotType.Loot: if (player.target != null && player.target.health <= 0) { UILoot lootContent = GetComponent <UILoot>(); List <ItemSlot> items = player.target.inventory.Where(slot => slot.amount > 0).ToList(); UIUtils.BalancePrefabs(lootContent.itemSlotPrefab.gameObject, items.Count, lootContent.content); // refresh all valid items for (int i = 0; i < items.Count; ++i) { UILootSlot slot = lootContent.content.GetChild(i).GetComponent <UILootSlot>(); slot.dragAndDropable.name = i.ToString(); // drag and drop index int itemIndex = player.target.inventory.FindIndex( // note: .Equals because name AND dynamic variables matter (petLevel etc.) itemSlot => itemSlot.amount > 0 && itemSlot.item.Equals(items[i].item) ); // refresh raritySlot = slot.GetComponent <UCE_RaritySlot>(); tooltip = slot.tooltip; slot.dragAndDropable.name = i.ToString(); // drag and drop slot itemSlot = items[i]; SetRarityColor(itemSlot.item.data); } } break; case SlotType.PlayerTrade: if (player.state == "TRADING") { Player other = (Player)player.target; int lastPTYCount = 0; if (lastPTYCount != player.tradeOfferItems.Count) { for (int i = 0; i < player.tradeOfferItems.Count; ++i) { lastPTYCount = player.tradeOfferItems.Count; UIPlayerTrading tradeContents = GetComponent <UIPlayerTrading>(); UIUtils.BalancePrefabs(tradeContents.slotPrefab.gameObject, player.tradeOfferItems.Count, tradeContents.myContent); if (tradeContents.panel.activeSelf) { UIPlayerTradingSlot slot = tradeContents.myContent.transform.GetChild(i).GetComponent <UIPlayerTradingSlot>(); if (slot.amountText.text != "0") { raritySlot = slot.GetComponent <UCE_RaritySlot>(); tooltip = slot.tooltip; slot.dragAndDropable.name = i.ToString(); // drag and drop slot int inventoryIndex = player.tradeOfferItems[i]; itemSlot = player.inventory[inventoryIndex]; SetRarityColor(itemSlot.item.data); } else { raritySlot = slot.GetComponent <UCE_RaritySlot>(); raritySlot.rarityOutline.color = Color.clear; } } } } int lastPTOCount = 0; if (lastPTOCount != other.tradeOfferItems.Count) { for (int i = 0; i < other.tradeOfferItems.Count; ++i) { lastPTOCount = other.tradeOfferItems.Count; UIPlayerTrading tradeContents = GetComponent <UIPlayerTrading>(); UIUtils.BalancePrefabs(tradeContents.slotPrefab.gameObject, other.tradeOfferItems.Count, tradeContents.otherContent); if (tradeContents.panel.activeSelf) { UIPlayerTradingSlot slot = tradeContents.otherContent.transform.GetChild(i).GetComponent <UIPlayerTradingSlot>(); if (slot.amountText.text != "0") { raritySlot = slot.GetComponent <UCE_RaritySlot>(); tooltip = slot.tooltip; slot.dragAndDropable.name = i.ToString(); // drag and drop slot int inventoryIndex = other.tradeOfferItems[i]; itemSlot = other.inventory[inventoryIndex]; SetRarityColor(itemSlot.item.data); } else { raritySlot = slot.GetComponent <UCE_RaritySlot>(); raritySlot.rarityOutline.color = Color.clear; } } } } } break; case SlotType.NpcTrade: if (player.target is Npc) { Npc npc = (Npc)player.target; #if _iMMONPCSHOP UCE_UI_NpcShop shopContents = GetComponent <UCE_UI_NpcShop>(); if (shopContents.panel.activeSelf) { ScriptableItem[] items = npc.saleItems.Where(x => x.itemCategory == shopContents.currentCategory || shopContents.currentCategory == "").ToArray(); UIUtils.BalancePrefabs(shopContents.itemSlotPrefab.gameObject, items.Length, shopContents.itemContent); int lastIMCount = 0; string currentPage = ""; if (lastIMCount != items.Length || currentPage != shopContents.currentCategory) { for (int i = 0; i < items.Length; ++i) { lastIMCount = items.Length; currentPage = shopContents.currentCategory; UCE_UI_NpcShopSlot slot = shopContents.itemContent.GetChild(i).GetComponent <UCE_UI_NpcShopSlot>(); raritySlot = slot.GetComponent <UCE_RaritySlot>(); tooltip = slot.tooltip; scriptItem = items[i]; SetRarityColor(scriptItem); } } } #else int lastNTCount = 0; if (lastNTCount != npc.saleItems.Length) { for (int i = 0; i < npc.saleItems.Length; ++i) { lastNTCount = npc.saleItems.Length; UINpcTrading npcContents = GetComponent <UINpcTrading>(); UIUtils.BalancePrefabs(npcContents.slotPrefab.gameObject, npc.saleItems.Length, npcContents.content); if (npcContents.panel.activeSelf) { UINpcTradingSlot slot = npcContents.content.transform.GetChild(i).GetComponent <UINpcTradingSlot>(); raritySlot = slot.GetComponent <UCE_RaritySlot>(); tooltip = slot.tooltip; scriptItem = npc.saleItems[i]; SetRarityColor(scriptItem); } } } #endif } break; case SlotType.ItemMall: UIItemMall mallContents = GetComponent <UIItemMall>(); if (mallContents.panel.activeSelf) { ScriptableItem[] items = player.itemMallCategories[mallContents.currentCategory].items; UIUtils.BalancePrefabs(mallContents.itemSlotPrefab.gameObject, items.Length, mallContents.itemContent); int lastIMCount = 0; int currentPage = 0; if (lastIMCount != items.Length || currentPage != mallContents.currentCategory) { for (int i = 0; i < items.Length; ++i) { lastIMCount = items.Length; currentPage = mallContents.currentCategory; UIItemMallSlot slot = mallContents.itemContent.GetChild(i).GetComponent <UIItemMallSlot>(); raritySlot = slot.GetComponent <UCE_RaritySlot>(); tooltip = slot.tooltip; scriptItem = items[i]; SetRarityColor(scriptItem); } } } break; case SlotType.Crafting: UICrafting craftContents = GetComponent <UICrafting>(); UIUtils.BalancePrefabs(craftContents.ingredientSlotPrefab.gameObject, player.craftingIndices.Count, craftContents.ingredientContent); if (craftContents.panel.activeSelf) { int lastCCount = 0; if (lastCCount != player.craftingIndices.Count) { for (int i = 0; i < player.craftingIndices.Count; ++i) { lastCCount = player.craftingIndices.Count; UICraftingIngredientSlot slot = craftContents.ingredientContent.GetChild(i).GetComponent <UICraftingIngredientSlot>(); if (player.craftingIndices[i] != -1) { int itemIndex = player.craftingIndices[i]; raritySlot = slot.GetComponent <UCE_RaritySlot>(); tooltip = slot.tooltip; itemSlot = player.inventory[itemIndex]; SetRarityColor(itemSlot.item.data); } else { raritySlot = slot.GetComponent <UCE_RaritySlot>(); raritySlot.rarityOutline.color = Color.clear; } } } } break; } } }
void Update() { Player player = Player.localPlayer; // use collider point(s) to also work with big entities if (player != null && player.target != null && player.target is Npc && Utils.ClosestDistance(player.collider, player.target.collider) <= player.interactionRange) { Npc npc = (Npc)player.target; // items for sale UIUtils.BalancePrefabs(slotPrefab.gameObject, npc.saleItems.Length, content); for (int i = 0; i < npc.saleItems.Length; ++i) { UINpcTradingSlot slot = content.GetChild(i).GetComponent <UINpcTradingSlot>(); ScriptableItem itemData = npc.saleItems[i]; // show item in UI int icopy = i; slot.button.onClick.SetListener(() => { buyIndex = icopy; }); slot.image.color = Color.white; slot.image.sprite = itemData.image; slot.tooltip.enabled = true; slot.tooltip.text = new ItemSlot(new Item(itemData)).ToolTip(); // with slot for {AMOUNT} } // buy if (buyIndex != -1 && buyIndex < npc.saleItems.Length) { ScriptableItem itemData = npc.saleItems[buyIndex]; // make valid amount, calculate price int amount = buyAmountInput.text.ToInt(); amount = Mathf.Clamp(amount, 1, itemData.maxStack); long price = amount * itemData.buyPrice; // show buy panel with item in UI buyAmountInput.text = amount.ToString(); buySlot.GetComponent <Image>().color = Color.white; buySlot.GetComponent <Image>().sprite = itemData.image; buySlot.GetComponent <UIShowToolTip>().enabled = true; buySlot.GetComponent <UIShowToolTip>().text = new ItemSlot(new Item(itemData)).ToolTip(); // with slot for {AMOUNT} buySlot.dragable = true; buyCostsText.text = price.ToString(); buyButton.interactable = amount > 0 && price <= player.gold && player.InventoryCanAdd(new Item(itemData), amount); buyButton.onClick.SetListener(() => { player.CmdNpcBuyItem(buyIndex, amount); buyIndex = -1; buyAmountInput.text = "1"; }); } else { // show default buy panel in UI buySlot.GetComponent <Image>().color = Color.clear; buySlot.GetComponent <Image>().sprite = null; buySlot.GetComponent <UIShowToolTip>().enabled = false; buySlot.dragable = false; buyCostsText.text = "0"; buyButton.interactable = false; } // sell if (sellIndex != -1 && sellIndex < player.inventory.Count && player.inventory[sellIndex].amount > 0) { ItemSlot itemSlot = player.inventory[sellIndex]; // make valid amount, calculate price int amount = sellAmountInput.text.ToInt(); amount = Mathf.Clamp(amount, 1, itemSlot.amount); long price = amount * itemSlot.item.sellPrice; // show sell panel with item in UI sellAmountInput.text = amount.ToString(); sellSlot.GetComponent <Image>().color = Color.white; sellSlot.GetComponent <Image>().sprite = itemSlot.item.image; sellSlot.GetComponent <UIShowToolTip>().enabled = true; sellSlot.GetComponent <UIShowToolTip>().text = itemSlot.ToolTip(); sellSlot.dragable = true; sellCostsText.text = price.ToString(); sellButton.interactable = amount > 0; sellButton.onClick.SetListener(() => { player.CmdNpcSellItem(sellIndex, amount); sellIndex = -1; sellAmountInput.text = "1"; }); } else { // show default sell panel in UI sellSlot.GetComponent <Image>().color = Color.clear; sellSlot.GetComponent <Image>().sprite = null; sellSlot.GetComponent <UIShowToolTip>().enabled = false; sellSlot.dragable = false; sellCostsText.text = "0"; sellButton.interactable = false; } } else { panel.SetActive(false); // hide } }
void Update() { GameObject player = Player.player; if (!player) { return; } PlayerInteraction interaction = player.GetComponent <PlayerInteraction>(); PlayerInventory inventory = player.GetComponent <PlayerInventory>(); PlayerNpcTrading trading = player.GetComponent <PlayerNpcTrading>(); if (interaction.current != null && ((MonoBehaviour)interaction.current).GetComponent <NpcTrading>() != null) { panel.SetActive(true); NpcTrading npc = ((MonoBehaviour)interaction.current).GetComponent <NpcTrading>(); // items for sale UIUtils.BalancePrefabs(slotPrefab.gameObject, npc.saleItems.Length, content); for (int i = 0; i < npc.saleItems.Length; ++i) { UINpcTradingSlot slot = content.GetChild(i).GetComponent <UINpcTradingSlot>(); ScriptableItem itemData = npc.saleItems[i]; // show item in UI int icopy = i; slot.button.onClick.SetListener(() => { buyIndex = icopy; }); slot.image.color = Color.white; slot.image.sprite = itemData.image; slot.tooltip.enabled = true; slot.tooltip.text = new ItemSlot(new Item(itemData)).ToolTip(); // with slot for {AMOUNT} } // buy if (buyIndex != -1 && buyIndex < npc.saleItems.Length) { ScriptableItem itemData = npc.saleItems[buyIndex]; // make valid amount, calculate price int amount = buyAmountInput.text.ToInt(); amount = Mathf.Clamp(amount, 1, itemData.maxStack); long price = amount * itemData.buyPrice; // show buy panel with item in UI buyAmountInput.text = amount.ToString(); buySlot.GetComponent <Image>().color = Color.white; buySlot.GetComponent <Image>().sprite = itemData.image; buySlot.GetComponent <UIShowToolTip>().enabled = true; buySlot.GetComponent <UIShowToolTip>().text = new Item(itemData).ToolTip(); buyCostsText.text = price.ToString(); buyButton.interactable = amount > 0 && price <= inventory.gold && inventory.CanAdd(new Item(itemData), amount); buyButton.onClick.SetListener(() => { trading.BuyItem(buyIndex, amount, npc); buyIndex = -1; buyAmountInput.text = "1"; }); } else { // show default buy panel in UI buySlot.GetComponent <Image>().color = Color.clear; buySlot.GetComponent <Image>().sprite = null; buySlot.GetComponent <UIShowToolTip>().enabled = false; buyCostsText.text = "0"; buyButton.interactable = false; } // sell if (sellIndex != -1 && sellIndex < inventory.slots.Count && inventory.slots[sellIndex].amount > 0) { ItemSlot itemSlot = inventory.slots[sellIndex]; // make valid amount, calculate price int amount = sellAmountInput.text.ToInt(); amount = Mathf.Clamp(amount, 1, itemSlot.amount); long price = amount * itemSlot.item.sellPrice; // show sell panel with item in UI sellAmountInput.text = amount.ToString(); sellSlot.GetComponent <Image>().color = Color.white; sellSlot.GetComponent <Image>().sprite = itemSlot.item.image; sellSlot.GetComponent <UIShowToolTip>().enabled = true; sellSlot.GetComponent <UIShowToolTip>().text = itemSlot.ToolTip(); sellCostsText.text = price.ToString(); sellButton.interactable = amount > 0; sellButton.onClick.SetListener(() => { trading.SellItem(sellIndex, amount, npc); sellIndex = -1; sellAmountInput.text = "1"; }); } else { // show default sell panel in UI sellSlot.GetComponent <Image>().color = Color.clear; sellSlot.GetComponent <Image>().sprite = null; sellSlot.GetComponent <UIShowToolTip>().enabled = false; sellCostsText.text = "0"; sellButton.interactable = false; } } else { panel.SetActive(false); } }
void Update() { Player player = Player.localPlayer; // use collider point(s) to also work with big entities if (player != null && player.target != null && player.target is Npc npc && Utils.ClosestDistance(player, player.target) <= player.interactionRange) { // items for sale UIUtils.BalancePrefabs(slotPrefab.gameObject, npc.trading.saleItems.Length, content); for (int i = 0; i < npc.trading.saleItems.Length; ++i) { UINpcTradingSlot slot = content.GetChild(i).GetComponent <UINpcTradingSlot>(); ScriptableItem itemData = npc.trading.saleItems[i]; // show item in UI int icopy = i; slot.button.onClick.SetListener(() => { buyIndex = icopy; }); slot.image.color = Color.white; slot.image.sprite = itemData.image; // only build tooltip while it's actually shown. this // avoids MASSIVE amounts of StringBuilder allocations. slot.tooltip.enabled = true; if (slot.tooltip.IsVisible()) { slot.tooltip.text = new ItemSlot(new Item(itemData)).ToolTip(); // with slot for {AMOUNT} } } // buy if (buyIndex != -1 && buyIndex < npc.trading.saleItems.Length) { ScriptableItem itemData = npc.trading.saleItems[buyIndex]; // make valid amount, calculate price int amount = buyAmountInput.text.ToInt(); amount = Mathf.Clamp(amount, 1, itemData.maxStack); long price = amount * itemData.buyPrice; // show buy panel with item in UI buyAmountInput.text = amount.ToString(); buySlot.GetComponent <Image>().color = Color.white; buySlot.GetComponent <Image>().sprite = itemData.image; // only build tooltip while it's actually shown. this // avoids MASSIVE amounts of StringBuilder allocations. buySlot.GetComponent <UIShowToolTip>().enabled = true; if (buySlot.GetComponent <UIShowToolTip>().IsVisible()) { buySlot.GetComponent <UIShowToolTip>().text = new ItemSlot(new Item(itemData)).ToolTip(); // with slot for {AMOUNT} } buySlot.dragable = true; buyCostsText.text = price.ToString(); buyButton.interactable = amount > 0 && price <= player.gold && player.inventory.CanAdd(new Item(itemData), amount); buyButton.onClick.SetListener(() => { player.npcTrading.CmdBuyItem(buyIndex, amount); buyIndex = -1; buyAmountInput.text = "1"; }); } else { // show default buy panel in UI buySlot.GetComponent <Image>().color = Color.clear; buySlot.GetComponent <Image>().sprite = null; buySlot.GetComponent <UIShowToolTip>().enabled = false; buySlot.dragable = false; buyCostsText.text = "0"; buyButton.interactable = false; } // sell if (sellIndex != -1 && sellIndex < player.inventory.slots.Count && player.inventory.slots[sellIndex].amount > 0) { ItemSlot itemSlot = player.inventory.slots[sellIndex]; // make valid amount, calculate price int amount = sellAmountInput.text.ToInt(); amount = Mathf.Clamp(amount, 1, itemSlot.amount); long price = amount * itemSlot.item.sellPrice; // show sell panel with item in UI sellAmountInput.text = amount.ToString(); // use durability colors? if (itemSlot.item.maxDurability > 0) { if (itemSlot.item.durability == 0) { sellSlot.GetComponent <Image>().color = brokenDurabilityColor; } else if (itemSlot.item.DurabilityPercent() < lowDurabilityThreshold) { sellSlot.GetComponent <Image>().color = lowDurabilityColor; } else { sellSlot.GetComponent <Image>().color = Color.white; } } else { sellSlot.GetComponent <Image>().color = Color.white; // reset for no-durability items } sellSlot.GetComponent <Image>().sprite = itemSlot.item.image; // only build tooltip while it's actually shown. this // avoids MASSIVE amounts of StringBuilder allocations. sellSlot.GetComponent <UIShowToolTip>().enabled = true; if (sellSlot.GetComponent <UIShowToolTip>().IsVisible()) { sellSlot.GetComponent <UIShowToolTip>().text = itemSlot.ToolTip(); } sellSlot.dragable = true; sellCostsText.text = price.ToString(); sellButton.interactable = amount > 0; sellButton.onClick.SetListener(() => { player.npcTrading.CmdSellItem(sellIndex, amount); sellIndex = -1; sellAmountInput.text = "1"; }); } else { // show default sell panel in UI sellSlot.GetComponent <Image>().color = Color.clear; sellSlot.GetComponent <Image>().sprite = null; sellSlot.GetComponent <UIShowToolTip>().enabled = false; sellSlot.dragable = false; sellCostsText.text = "0"; sellButton.interactable = false; } // repair items if (npc.trading.offersRepair) { int missing = player.inventory.GetTotalMissingDurability() + player.equipment.GetTotalMissingDurability(); int price = missing * npc.trading.repairCostPerDurabilityPoint; repairButton.gameObject.SetActive(true); repairButton.interactable = player.gold >= price; repairButton.onClick.SetListener(() => { UIConfirmation.singleton.Show("Repair all Items for: " + price + " gold?", () => { player.npcTrading.CmdRepairAllItems(); }); }); } else { repairButton.gameObject.SetActive(false); } }