Esempio n. 1
0
        public void Swap(SlottableItem item)
        {
            SlottableItem currentItem = Item;
            SlottableItem draggedItem = item;

            if (draggedItem == null || currentItem == draggedItem)
            {
                return;
            }
            var oldSlot = draggedItem.Slot;

            if (IsFree && AcceptsItem(draggedItem) && draggedItem.AcceptsSlot(this))
            {
                Drop(draggedItem);
                oldSlot.Clear();
                return;
            }

            // Items need to be swapped
            if (AcceptsItem(draggedItem) && oldSlot.AcceptsItem(currentItem) &&
                draggedItem.AcceptsSlot(this) && currentItem.AcceptsSlot(oldSlot))
            {
                Drop(draggedItem);
                oldSlot.Drop(currentItem);
            }
        }
Esempio n. 2
0
        public void Clear()
        {
            SlottableItem oldItem = Item;

            Item = null;
            ExecuteEvents.ExecuteHierarchy <ISlotChanged>(gameObject, null, (x, y) => x.SlotChanged(this, null, oldItem));
        }
Esempio n. 3
0
 public bool AcceptsItem(SlottableItem item)
 {
     if (AcceptedItemType == "" || AcceptedItemType == item.Item.GetType().Name)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 4
0
 /// <summary>
 /// Weather the Slot accepts the given Item.</summary>
 public override bool AcceptsItem(SlottableItem item)
 {
     if (_acceptedItemType == "" || _acceptedItemType == item.Data.GetType().Name)
     {
         return true;
     }
     return false;
 }
Esempio n. 5
0
 /// <summary>
 /// Add an Item to the next available Slot.</summary>
 public virtual void AddItem(SlottableItem item)
 {
     Slot slot = NextAvailableSlot();
     if (slot != null)
     {
         slot.Drop(item);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Add an Item to the next available Slot.</summary>
        public void AddItem(SlottableItem item)
        {
            Slot slot = NextAvailableSlot();

            if (slot != null)
            {
                slot.Drop(item);
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Drop an Item onto this Slot.</summary>
 public void Drop(SlottableItem item)
 {
     var oldItem = _item;
     var newItem = item;
     item.transform.SetParent(transform);
     item.FitIntoSlot();
     ExecuteEvents.ExecuteHierarchy<ISlotChanged>(gameObject, null, (x, y) => x.SlotChanged(this, newItem, oldItem));
     _item = item;
     _item._slot = this;
 }
Esempio n. 8
0
        /// <summary>
        /// Drop an Item onto this Slot.</summary>
        public void Drop(SlottableItem item)
        {
            var oldItem = Item;
            var newItem = item;

            item.transform.SetParent(transform);
            item.FitIntoSlot();
            ExecuteEvents.ExecuteHierarchy <ISlotChanged>(gameObject, null, (x, y) => x.SlotChanged(this, newItem, oldItem));
            Item      = item;
            Item.Slot = this;
        }
Esempio n. 9
0
 public void OnBeginDrag(PointerEventData eventData)
 {
     if (!Slot.AllowsDrag)
     {
         return;
     }
     _canvas     = GetComponentInParent <Canvas>();
     DraggedItem = this;
     _startSlot  = Slot;
     _canvasGroup.blocksRaycasts = false;
     transform.SetParent(GetComponentInParent <Canvas>().transform);
 }
Esempio n. 10
0
 /// <summary>
 /// Catch the current Slot.
 /// Parent the Item under the Canvas in order to have it in
 /// front of everything while dragging.</summary>
 public void OnBeginDrag(PointerEventData eventData)
 {
     if (!_slot._allowsDrag)
     {
         return;
     }
     _canvas = GetComponentInParent<Canvas>();
     _draggedItem = this;
     startSlot = _slot;
     GetComponent<CanvasGroup>().blocksRaycasts = false;
     transform.SetParent(GetComponentInParent<Canvas>().transform);
 }
Esempio n. 11
0
 public void OnEndDrag(PointerEventData eventData)
 {
     if (!Slot.AllowsDrag)
     {
         return;
     }
     DraggedItem = null;
     _canvasGroup.blocksRaycasts = true;
     if (Slot == _startSlot)
     {
         Slot.Drop(this);
     }
 }
Esempio n. 12
0
        public void AddItem(SlottableItem item, string slotName = null)
        {
            Slot slot = null;

            if (slotName == null)
            {
                slot = NextAvailableSlot();
            }
            else
            {
                slot = SlotByName(slotName);
            }
            if (slot != null)
            {
                slot.Drop(item);
            }
        }
Esempio n. 13
0
 public void ResetSlots()
 {
     foreach (Slot slot in _slots)
     {
         if (slot.Item != null)
         {
             slot.Item.gameObject.SetActive(false);
             Items.Remove(slot.Item.Name.text);
             slot.Item.Amount = 0;
             slot.Item.Item   = null;
             SlottableItem item = slot.Item;
             slot.Clear();
             Slot target = NextAvailableSlot();
             if (target != null)
             {
                 target.Drop(item);
             }
         }
     }
 }
Esempio n. 14
0
 /// <summary>
 /// Update the Character in case the Item is placed in a special
 /// Slot, like the Weapon Slot.</summary>
 public override void SlotChanged(Slot slot,
                                   SlottableItem currentItem,
                                   SlottableItem previousItem)
 {
     if (slot == _weaponSlot)
     {
         Player._player.Stats._equippedWeapon = currentItem != null ? (Weapon)currentItem.Data : null;
     }
 }
Esempio n. 15
0
 /// <summary>
 /// Slots have changed.</summary>
 public virtual void SlotChanged(Slot slot,
                                  SlottableItem currentItem,
                                  SlottableItem previousItem)
 {
 }
Esempio n. 16
0
        /// <summary>
        /// Swap the given Item with the Item in this Slot if possible.</summary>
        public void Swap(SlottableItem item)
        {
            var currentItem = _item;
            var draggedItem = item;
            if (draggedItem == null || currentItem == draggedItem)
            {
                return;
            }
            var oldSlot = draggedItem._slot;

            if (IsFree && AcceptsItem(draggedItem) && draggedItem.AcceptsSlot(this))
            {
                Drop(draggedItem);
                oldSlot.Clear();
                return;
            }

            // Items need to be swapped
            if (AcceptsItem(draggedItem) && oldSlot.AcceptsItem(currentItem) &&
                draggedItem.AcceptsSlot(this) && currentItem.AcceptsSlot(oldSlot))
            {
                Drop(draggedItem);
                oldSlot.Drop(currentItem);
            }
        }
Esempio n. 17
0
 /// <summary>
 /// Set the Slot free.</summary>
 public void Clear()
 {
     var oldItem = _item;
     _item = null;
     ExecuteEvents.ExecuteHierarchy<ISlotChanged>(gameObject, null, (x, y) => x.SlotChanged(this, null, oldItem));
 }
Esempio n. 18
0
 /// <summary>
 /// Weather the Slot accepts the given Item.</summary>
 public virtual bool AcceptsItem(SlottableItem item)
 {
     return true;
 }
Esempio n. 19
0
 /// <summary>
 /// Update the Character in case the Item is placed in a special
 /// Slot, like the Weapon Slot.</summary>
 public void SlotChanged(Slot slot, SlottableItem currentItem, SlottableItem previousItem)
 {
 }
Esempio n. 20
0
 /// <summary>
 /// If no new Slot was found, drop the Item back into the current Slot.</summary>
 public void OnEndDrag(PointerEventData eventData)
 {
     if (!_slot._allowsDrag)
     {
         return;
     }
     _draggedItem = null;
     GetComponent<CanvasGroup>().blocksRaycasts = true;
     if (_slot == startSlot)
     {
         _slot.Drop(this);
     }
 }