public void SetParent(ItemSlotDropHandler itemSlotDropHandler) { // move item being dragged UI into this slot transform.SetParent(itemSlotDropHandler.transform); // reset UI position to 0/0/0/0 transform.gameObject.GetComponent <RectTransform>().offsetMin = new Vector2(0, 0); // [ left - bottom ] transform.gameObject.GetComponent <RectTransform>().offsetMax = new Vector2(0, 0); // [ right - top ] }
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); }
public void OnDrop(PointerEventData eventData) { // verify if item being dragged is not null if ((InventoryItemDragHandler.itemBeingDragged != null) // verify if we are in edit screen mode && (transform.root.Find("MiscUI").GetComponentInChildren <EditPartyScreen>(false) != null)) { Debug.Log("Find or create the right slot and put an item into it"); // Get empty slot ItemSlotDropHandler itemSlot = GetEmptySlot(); // verify if slot is not null if (itemSlot == null) { // get PartyInventoryUI PartyInventoryUI partyInventoryUI = GetComponentInParent <PartyInventoryUI>(); // create new slot itemSlot = partyInventoryUI.AddSlot(); } // move item drag handler into slot itemSlot.MoveItemIntoThisSlot(); } }
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); } }
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(); // } //} }
void ChangeItemParent(ItemSlotDropHandler itemSlotDropHandler) { // move InventoryItem to the new parent object itemSlotDropHandler.GetComponentInChildren <InventoryItemDragHandler>().LInventoryItem.transform.SetParent(itemSlotDropHandler.GetParentObjectTransform()); }
public InventoryItemDragHandler AddItemDragHandler(ItemSlotDropHandler slot) { return(Instantiate(inventoryItemDragHandlerTemplate.gameObject, slot.transform).GetComponent <InventoryItemDragHandler>()); }
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(); // } //} }