/// <summary> /// Positions the tool tips. /// </summary> private void PositionToolTips() { if (!_unequippedToolTipPanel.activeSelf && !_isDragging) { GameObject leftToolTipPanel = _unequippedToolTipPanel; GameObject rightToolTipPanel = null; Color unequippedAttribute1Color = Color.black; Color unequippedAttribute2Color = Color.black; // Determine if the right panel needs to be displayed (i.e. we're doing a comparison) InventorySlots.SlotType slot = _item.SlotType; Slot equipmentSlot = _inventoryController.GetEquipmentSlot(slot); if (equipmentSlot != null && equipmentSlot.SlotImage != null && equipmentSlot != GetSlot()) { _secondaryItem = equipmentSlot.SlotImage.GetComponent <SlotImageCanvas> ().GetItem(); leftToolTipPanel = _equippedToolTipPanel; rightToolTipPanel = _unequippedToolTipPanel; // Determine colors for attributes if (_item.Type == Item.ItemType.WEAPON || _item.Type == Item.ItemType.MONSTER_ATTACK) { unequippedAttribute1Color = GetToolTipColorByAttribute(_item, _secondaryItem, AttributeEnums.AttributeType.DAMAGE); unequippedAttribute2Color = GetToolTipColorByAttribute(_item, _secondaryItem, AttributeEnums.AttributeType.CRITICAL_CHANCE); } else if (_item.Type == Item.ItemType.ARMOR) { unequippedAttribute1Color = GetToolTipColorByAttribute(_item, _secondaryItem, AttributeEnums.AttributeType.ARMOR); unequippedAttribute2Color = GetToolTipColorByAttribute(_item, _secondaryItem, AttributeEnums.AttributeType.DODGE_CHANCE); } } // Position the tool tip panels Vector3 imagePosition = this.gameObject.transform.position; Vector3 oldToolTipPosition = leftToolTipPanel.transform.position; leftToolTipPanel.transform.position = new Vector3(imagePosition.x + 128, imagePosition.y, oldToolTipPosition.z); if (rightToolTipPanel != null) { rightToolTipPanel.transform.position = new Vector3(imagePosition.x + 328, imagePosition.y, oldToolTipPosition.z); } // Set the data on the tool tip(s) SetUnequippedToolTip(unequippedAttribute1Color, unequippedAttribute2Color); if (rightToolTipPanel != null) { SetEquippedToolTip(); } // Display tool tip(s) leftToolTipPanel.SetActive(true); if (rightToolTipPanel != null) { rightToolTipPanel.SetActive(true); } } }
/// <summary> /// Gets the slot. /// </summary> /// <returns>The slot.</returns> /// <param name="slot">Slot.</param> public Slot GetSlot(InventorySlots.SlotType slot) { GameObject panel = GetPanelBySlot(slot); if (panel != null) { return(panel.transform.Find("Slot").GetComponent <Slot> ()); } return(null); }
/// <summary> /// Sets the panels active/inactive depending on the item. /// </summary> /// <param name="item">Item.</param> public void SetPanelsActive(Item item) { InventorySlots.SlotType slotType = item.SlotType; SetPanelActive(rightHandPanel, CanEquip(rightHandPanel, slotType)); SetPanelActive(leftHandPanel, CanEquip(leftHandPanel, slotType)); SetPanelActive(chestPanel, CanEquip(chestPanel, slotType)); SetPanelActive(armsPanel, CanEquip(armsPanel, slotType)); SetPanelActive(legsPanel, CanEquip(legsPanel, slotType)); }
/// <summary> /// Add the item to the specified slot. /// Slot will be inferred from the item. /// </summary> /// <param name="item">Item.</param> public void Add(Item item) { // Get inventory slot from item InventorySlots.SlotType slotType = item.SlotType; if (_items.ContainsKey(slotType)) { // Remove currently equipped item Remove(slotType); } // Add item to slot Add(slotType, item); }
/// <summary> /// Gets the slot if available. /// </summary> /// <returns>The slot if available.</returns> /// <param name="slot">Slot.</param> public Slot GetSlotIfAvailable(InventorySlots.SlotType slot) { GameObject panel = GetPanelBySlot(slot); if (panel != null) { Slot slotObject = GetSlot(slot); return(slotObject.SlotImage == null ? slotObject : null); } else { return(null); } }
// ----------------------------- POINTER CLICK EVENTS ----------------------------- // /// <summary> /// Raises the pointer click event. /// </summary> /// <param name="eventData">Event data.</param> public void OnPointerClick(PointerEventData eventData) { // Check for double click if (eventData.clickCount == 2) { Slot oldSlot = GetSlot(); // This item is in inventory if (oldSlot.slotType == InventorySlots.SlotType.ANY) { // Get item slot and see if it's filled InventorySlots.SlotType slotType = _item.SlotType; Slot equipmentSlot = _inventoryController.GetEquipmentSlot(slotType); if (equipmentSlot != null) { GameObject slotImageCanvasObject = equipmentSlot.SlotImage; // If there is an item in the equipment slot, swap it out if (slotImageCanvasObject != null) { SlotImageCanvas slotImageCanvas = equipmentSlot.SlotImage.GetComponent <SlotImageCanvas> (); SwapSlots(this, slotImageCanvas, oldSlot, equipmentSlot); } else { // Drop item into slot DropInSlot(equipmentSlot); } // Play SFX PlaySFX(); } } // This item is equipped else if (oldSlot.slotType != InventorySlots.SlotType.ANY) { Slot newSlot = _inventoryController.GetFirstOpenSlot(); if (newSlot != null) { // Drop item into slot DropInSlot(newSlot); // Play SFX PlaySFX(); } } } }
/// <summary> /// Initializes a new instance of the <see cref="Item"/> class. /// </summary> /// <param name="id">Identifier.</param> /// <param name="itemType">Item type.</param> /// <param name="name">Name.</param> /// <param name="description">Description.</param> /// <param name="toolTip">Tool tip.</param> /// <param name="attributeCollection">Attribute collection.</param> /// <param name="slot">Slot.</param> /// <param name="tier">Tier.</param> /// <param name="iconPath">Icon path.</param> /// <param name="vfxPath">VFX path.</param> private void Init(int id, ItemType itemType, string name, string description, string toolTip, AttributeCollection attributeCollection, InventorySlots.SlotType slot, ItemTier tier, string iconPath, string soundPath, string vfxPath) { Id = id; Type = itemType; Name = name; Description = description; ToolTip = toolTip; _attributeCollection = attributeCollection; SlotType = slot; Tier = tier; TierColor = GetTierColor(); TierName = GetTierName(); IconPath = iconPath; Icon = Resources.Load <Sprite> (IconPath); SoundPath = soundPath; Sound = Resources.Load <AudioClip> (SoundPath); VFXPath = vfxPath; }
/// <summary> /// Gets the panel by slot. /// </summary> /// <returns>The panel by slot.</returns> /// <param name="slot">Slot.</param> private GameObject GetPanelBySlot(InventorySlots.SlotType slot) { switch (slot) { case InventorySlots.SlotType.RIGHT_HAND: return(rightHandPanel); case InventorySlots.SlotType.LEFT_HAND: return(leftHandPanel); case InventorySlots.SlotType.BODY: return(chestPanel); case InventorySlots.SlotType.HANDS: return(armsPanel); case InventorySlots.SlotType.FEET: return(legsPanel); default: return(null); } }
private Item(int id, ItemType itemType, string name, string description, string toolTip, Dictionary <AttributeEnums.AttributeType, float> attributes, InventorySlots.SlotType slot, ItemTier tier, string iconPath, string soundPath, string vfxPath) { Init(id, itemType, name, description, toolTip, null, slot, tier, iconPath, soundPath, vfxPath); AttributeCollection globalAttributeCollection = AttributeManager.Instance.GlobalAttributeCollection; if (_attributeCollection == null) { _attributeCollection = new AttributeCollection(); } _attributeCollection = AttributeCollection.GetFromGlobalCollection(attributes, globalAttributeCollection, _attributeCollection); }
/// <summary> /// Initializes a new instance of the <see cref="Item"/> class. /// </summary> /// <param name="id">Identifier.</param> /// <param name="itemType">Item type.</param> /// <param name="name">Name.</param> /// <param name="description">Description.</param> /// <param name="toolTip">Tool tip.</param> /// <param name="attributeCollection">Attribute collection.</param> /// <param name="slot">Slot.</param> /// <param name="tier">Tier.</param> /// <param name="iconPath">Icon path.</param> /// <param name="vfxPath">VFX path.</param> public Item(int id, ItemType itemType, string name, string description, string toolTip, AttributeCollection attributeCollection, InventorySlots.SlotType slot, ItemTier tier, string iconPath, string soundPath, string vfxPath) { Init(id, itemType, name, description, toolTip, attributeCollection, slot, tier, iconPath, soundPath, vfxPath); }
/// <summary> /// Add the item to the specified slot. /// </summary> /// <param name="slotType">Slot type.</param> /// <param name="item">Item.</param> public void Add(InventorySlots.SlotType slotType, Item item) { _items.Add(slotType, item); }
/// <summary> /// Gets the item in slot. /// </summary> /// <returns>The item in slot.</returns> /// <param name="slotType">Slot type.</param> public Item GetItemInSlot(InventorySlots.SlotType slotType) { return(_inventorySlots.Get(slotType)); }
/// <summary> /// Gets the equipment slot. /// </summary> /// <returns>The equipment slot.</returns> /// <param name="slotType">Slot type.</param> public Slot GetEquipmentSlot(InventorySlots.SlotType slotType) { return(_equippedItemsController.GetSlot(slotType)); }
/// <summary> /// Removes the item. /// </summary> /// <param name="slotType">Slot type.</param> public void RemoveItem(InventorySlots.SlotType slotType) { Item item = _inventorySlots.Remove(slotType); DecrementAllAttributesText(item); }
/// <summary> /// Determines whether this instance can equip an item in the specified slot. /// </summary> /// <returns><c>true</c> if this instance can equip the item in the specified slot; otherwise, <c>false</c>.</returns> /// <param name="panel">Panel.</param> /// <param name="slot">Slot.</param> private bool CanEquip(GameObject panel, InventorySlots.SlotType slotType) { return(slotType == panel.transform.Find("Slot").GetComponent <Slot> ().slotType); }
/// <summary> /// Determines whether this instance is equipped in the specified slotType. /// </summary> /// <returns><c>true</c> if this instance is equipped in the specified slotType; otherwise, <c>false</c>.</returns> /// <param name="slotType">Slot type.</param> private bool IsEquipped(InventorySlots.SlotType slotType) { return(_inventoryController.GetEquipmentSlot(slotType) == GetSlot()); }