public void OnEndDrag(PointerEventData eventData)
 {
     // verify if user clicked left or right mouse button
     if (Input.GetMouseButtonUp(0))
     {
         // trigger end drag event
         itemEndDragEvent.Raise();
         // Instruct Edit Party Screen to disable ActiveItemDrag state (true) because we might be in battle screen mode using item
         // transform.root.Find("MiscUI").GetComponentInChildren<EditPartyScreen>(true).SetActiveState(EditPartyScreenActiveState.ActiveItemDrag, false);
         // get Battle screen
         // BattleScreen battleScreen = transform.root.Find("MiscUI").GetComponentInChildren<BattleScreen>(false);
         // Verify if battle screen is active
         //if (battleScreen != null)
         //{
         //    // Instruct Battle screen to update units highlight
         //    battleScreen.SetHighlight();
         //}
         // reset item being dragged
         itemBeingDragged = null;
         // enable block raycasts, so item can be dragged again
         GetComponent <CanvasGroup>().blocksRaycasts = true;
         // verify if on drop was not triggered (parent has not changed)
         if (transform.parent == outOfMaskParentTransform)
         {
             Debug.Log("Return to original position");
             // change parent back to original
             transform.SetParent(itemBeingDraggedSlot.transform);
             // reset position to 0/0/0/0
             // [ left - bottom ]
             GetComponent <RectTransform>().offsetMin = new Vector2(0, 0);
             // [ right - top ]
             GetComponent <RectTransform>().offsetMax = new Vector2(0, 0);
         }
         else
         {
             // parent has changed
             //// verify if previous parent was hero equipment slot
             //if (ItemSlotDropHandler.Mode.HeroEquipment == itemBeingDraggedSlot.SlotMode)
             //{
             //    // update unit info UI
             //    transform.root.Find("MiscUI/UnitInfoPanel").GetComponent<UnitInfoPanel>().ActivateAdvance(itemBeingDraggedSlot.GetComponentInParent<HeroEquipment>().LPartyUnit, UnitInfoPanel.Align.Right, false, UnitInfoPanel.ContentMode.Short);
             //}
         }
     }
     // verify if there is still item linked
     if (LInventoryItem != null)
     {
         // verify if item has usages
         if (LInventoryItem.IsUsable)
         {
             // update usages info, because it may be reduced, if item is usable
             GetComponentInChildren <Text>().text = LInventoryItem.ItemName + LInventoryItem.GetUsagesInfo();
         }
     }
 }
    public void ExchangeWithSlotOnDrop(ItemSlotDropHandler destinationSlot)
    {
        // this is an item being dragged slot
        // get item drag handler in destination slot
        InventoryItemDragHandler destinationItemDragHandler = destinationSlot.GetComponentInChildren <InventoryItemDragHandler>();

        // move item being dragged (source) into destination slot
        InventoryItemDragHandler.itemBeingDragged.SetParent(destinationSlot);
        // move destination drag handler into this slot
        destinationItemDragHandler.SetParent(this);
        // raise events
        itemHasBeenDroppedIntoTheItemSlotEvent.Raise(this);
        itemHasBeenDroppedIntoTheItemSlotEvent.Raise(destinationSlot);
    }
예제 #3
0
    //public void FillInEmptySlots()
    //{
    //    // there should be at least minNumberOfSlots item slots present in UI
    //    // .. Change this to list and get only first-level items, non-recursive
    //    int numberOfItems = 0;
    //    if (transform.root.Find("MiscUI").GetComponentInChildren<EditPartyScreen>(false) != null)
    //    {
    //        foreach (Transform childTransform in GetComponentInParent<HeroPartyUI>().LHeroParty.transform)
    //        {
    //            // verify if this is InventoryItem
    //            if (childTransform.GetComponent<InventoryItem>() != null)
    //                // increment items count
    //                numberOfItems += 1;
    //        }
    //    }
    //    // verify if we are in battle screen mode
    //    else if (transform.root.Find("MiscUI").GetComponentInChildren<BattleScreen>(false) != null)
    //    {
    //        // get all usable items from party leader equipment
    //        foreach (Transform childTransform in GetComponentInParent<HeroPartyUI>().LHeroParty.GetPartyLeader().transform)
    //        {
    //            // get item
    //            InventoryItem inventoryItem = childTransform.GetComponent<InventoryItem>();
    //            // verify if there is an item
    //            if (inventoryItem != null)
    //            {
    //                // verify if item is in hero eqipment slot
    //                if (inventoryItem.CurrentHeroEquipmentSlot != HeroEquipmentSlots.None)
    //                {
    //                    // increment items count
    //                    numberOfItems += 1;
    //                }
    //            }
    //        }
    //    }
    //    else if (transform.root.Find("MiscUI").GetComponentInChildren<PartiesInfoPanel>(false) != null)
    //    {
    //        Debug.Log("Parties info panel is active, probably we are on map. Normally inventory should not be active in this case.");
    //    }
    //    else
    //    {
    //        Debug.LogWarning("Unknown active screen");
    //    }
    //    // get number of empty item slots
    //    int emptySlots = minNumberOfSlots - numberOfItems;
    //    // create an empty slot for each empty slot
    //    for (int i = 0; i < emptySlots; i++)
    //    {
    //        // create slot in items list
    //        AddSlot();
    //    }
    //}

    // on change - check similar function in HeroEquipment class
    public void SetItemRepresentationInInventoryUI(InventoryItem inventoryItem, bool setCurrentItemEquipmentSlot = false)
    {
        // verify if this is InventoryItem
        if (inventoryItem != null)
        {
            // create drag handler and slotTransform
            InventoryItemDragHandler dragHandler = AddItemDragHandler(AddSlot(inventoryItem, setCurrentItemEquipmentSlot));
            // link item to drag handler
            dragHandler.LInventoryItem = inventoryItem;
            // set item name in UI
            dragHandler.GetComponentInChildren <Text>().text = inventoryItem.ItemName;
            // verify if item has active modifiers
            if (inventoryItem.IsUsable)
            {
                dragHandler.GetComponentInChildren <Text>().text += inventoryItem.GetUsagesInfo();
            }
        }
    }
예제 #4
0
 // on change - check similar function in PartyInventoryUI class
 void SetItemRepresentationInEquipmentUI(InventoryItem inventoryItem)
 {
     // verify if this is InventoryItem
     if (inventoryItem != null)
     {
         // create drag handler and slotTransform
         InventoryItemDragHandler dragHandler = Instantiate(inventoryItemDragHandlerTemplate, GetEquipmentSlotByType(inventoryItem.CurrentHeroEquipmentSlot).transform).GetComponent <InventoryItemDragHandler>();
         // link item to drag handler
         dragHandler.LInventoryItem = inventoryItem;
         // set item name in UI
         dragHandler.GetComponentInChildren <Text>().text = inventoryItem.ItemName;
         // verify if item has active modifiers
         if (inventoryItem.IsUsable)
         {
             dragHandler.GetComponentInChildren <Text>().text += inventoryItem.GetUsagesInfo();
         }
     }
 }
 public void OnBeginDrag(PointerEventData eventData)
 {
     if (Input.GetMouseButton(0))
     {
         // Debug.Log("OnBeginDrag: left mouse");
         // on left mouse drag
         BringItemToFront();
         itemBeingDragged = this;
         //startPosition = transform.position;
         itemBeingDraggedSlot = GetComponentInParent <ItemSlotDropHandler>();
         // change parent outside of Mask, to PartyInventory, so that canvas is not affected by Mask UI component
         // structure 4PartyInventory-3ItemsList-2Grid-1ItemSlot(Drop)-Item(Drag)
         outOfMaskParentTransform = transform.parent.parent.parent.parent;
         transform.SetParent(outOfMaskParentTransform);
         // disable raycasts
         GetComponent <CanvasGroup>().blocksRaycasts = false;
         // trigger begin item drag event
         itemBeginDragEvent.Raise();
         // Instruct Edit Party Screen that item is being dragged
         // transform.root.Find("MiscUI").GetComponentInChildren<EditPartyScreen>(true).SetActiveState(EditPartyScreenActiveState.ActiveItemDrag, true);
     }
 }
예제 #6
0
    public override void MoveItemIntoThisSlot()
    {
        // Get source item slot transform
        ItemSlotDropHandler srcItemSlot = InventoryItemDragHandler.itemBeingDragged.ItemBeindDraggedSlot;
        // init exchange flag
        //bool thisIsExachnge = false;
        // Get item in this slot
        InventoryItemDragHandler itemInThisSlot = GetComponentInChildren <InventoryItemDragHandler>();

        // verify if there is no item already in this slot
        if (itemInThisSlot != null)
        {
            //thisIsExachnge = true;
            // Put item from this slot to the slot of the item beind dragged
            srcItemSlot.PutItemIntoSlot(itemInThisSlot);
        }
        // Put dragged item into this slot
        PutItemIntoSlot(InventoryItemDragHandler.itemBeingDragged);
        //// verify if it was not exchange between 2 slots (means that we might need to fill in empty slots in source PartyInventoryUI)
        //if (!thisIsExachnge)
        //{
        //    // verify if source slot is in party inventory mode
        //    if ((srcItemSlot is InventorySlotDropHandler)
        //    // OR verify if source slot is equipment slot
        //     || ((srcItemSlot is EquipmentSlotDropHandler)
        //        // and that battle screen is active
        //        && (transform.root.Find("MiscUI").GetComponentInChildren<BattleScreen>(false) != null)))
        //    {
        //        // .. Optimize
        //        // Get source slot PartyInventoryUI (before slot is removed)
        //        PartyInventoryUI partyInventoryUI = srcItemSlot.GetComponentInParent<PartyInventoryUI>();
        //        // remove all empty slots in inventory
        //        partyInventoryUI.RemoveAllEmptySlots();
        //        // fill in empty slots in inventory
        //        partyInventoryUI.FillInEmptySlots();
        //    }
        //}
    }
 public void PutItemIntoSlot(InventoryItemDragHandler itemBeingDragged)
 {
     // move item being dragged UI into this slot
     itemBeingDragged.SetParent(this);
     //// reset UI position to 0/0/0/0
     //itemBeingDragged.transform.gameObject.GetComponent<RectTransform>().offsetMin = new Vector2(0, 0); // [ left - bottom ]
     //itemBeingDragged.transform.gameObject.GetComponent<RectTransform>().offsetMax = new Vector2(0, 0); // [ right - top ]
     //// verify if we are in edit party screen
     //if (transform.root.Find("MiscUI").GetComponentInChildren<EditPartyScreen>(false) != null)
     //{
     //    // move InventoryItem to the new parent object
     //    itemBeingDragged.LInventoryItem.transform.SetParent(GetParentObjectTransform());
     //}
     //// verify if we are in battle screen
     //else if (transform.root.Find("MiscUI").GetComponentInChildren<BattleScreen>(false) != null)
     //{
     //    // do not move InventoryItem to the new parent object, because this is item equipped on a hero
     //}
     //else
     //{
     //    Debug.LogError("Unknonw active screen");
     //}
     //Debug.LogError("remove below");
     // verify if this is hero eqiupment slot
     //if (Mode.HeroEquipment == slotMode)
     //{
     //    //itemHasBeenDroppedIntoEquipmentSlotEvent.Raise(this);
     //}
     //else
     //{
     //    // Mode.PartyInventory
     //    itemHasBeenDroppedIntoInventorySlotEvent.Raise(this);
     //}
     // raise event
     itemHasBeenDroppedIntoTheItemSlotEvent.Raise(this);
 }
예제 #8
0
    public override void MoveItemIntoThisSlot()
    {
        // Get source item slot transform
        ItemSlotDropHandler srcItemSlot = InventoryItemDragHandler.itemBeingDragged.ItemBeindDraggedSlot;
        // init exchange flag
        //bool thisIsExachnge = false;
        // init destination slot variable with this slot
        ItemSlotDropHandler dstItemSlot = this;
        // Get item in this slot
        InventoryItemDragHandler itemInThisSlot = GetComponentInChildren <InventoryItemDragHandler>();

        // verify if there is no item already in this slot
        if (itemInThisSlot != null)
        {
            // verify if source is equipment slot and destination is party inventory slot
            if (srcItemSlot is EquipmentSlotDropHandler)
            {
                // do not do exchange, just move item into inventory into the new slot
                // create new slot and set it as destination
                // reasons:
                //  we don't want to accidentally exchange boots with sword => in this case sword will appear in boots slot
                //  we don't want to accidentally exchange with the item which is cannot be used by this hero due to requirements (skills) not met.
                dstItemSlot = GetComponentInParent <PartyInventoryUI>().AddSlot();
                // Put dragged item into new slot
                dstItemSlot.PutItemIntoSlot(InventoryItemDragHandler.itemBeingDragged);
            }
            else
            {
                //thisIsExachnge = true;
                // Put item from this slot to the slot of the item beind dragged
                srcItemSlot.ExchangeWithSlotOnDrop(this);
            }
        }
        else
        {
            // Put dragged item into this slot
            dstItemSlot.PutItemIntoSlot(InventoryItemDragHandler.itemBeingDragged);
        }
        //// verify if it was not just simple exchange
        //if (!thisIsExachnge)
        //{
        //    // verify if source slot is in party inventory mode
        //    if ( (srcItemSlot is InventorySlotDropHandler)
        //    // OR verify if source slot is equipment slot
        //     || ( (srcItemSlot is EquipmentSlotDropHandler)
        //        // and that battle screen is active
        //        && (transform.root.Find("MiscUI").GetComponentInChildren<BattleScreen>(false) != null) ) )
        //    {
        //        // .. Optimize
        //        // Get source slot PartyInventoryUI (before slot is removed)
        //        PartyInventoryUI partyInventoryUI = srcItemSlot.GetComponentInParent<PartyInventoryUI>();
        //        // remove all empty slots in inventory
        //        partyInventoryUI.RemoveAllEmptySlots();
        //        // fill in empty slots in inventory
        //        partyInventoryUI.FillInEmptySlots();
        //    }
        //    // verify if destination slot was changed to the other from this slot
        //    if (dstItemSlot.gameObject.GetInstanceID() != gameObject.GetInstanceID())
        //    {
        //        // trigger this party inventory reorganisation
        //        // remove all empty slots in this inventory
        //        GetComponentInParent<PartyInventoryUI>().RemoveAllEmptySlots();
        //        // fill in empty slots in inventory
        //        GetComponentInParent<PartyInventoryUI>().FillInEmptySlots();
        //    }
        //}
    }