projectEli/Assets/Inventory System/ICWM Assets/Inventory/Scripts/DragAndDrop/DragHandler.cs

1617 lines
84 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//********************************************************//
// //
// Copyright © All rights reserved. MyNameIsVoo. 2020. //
// //
// COPYING FORBIDEN //
// //
//********************************************************//
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using ItemsClassList;
using ICWM.Loot;
using ICWM.Enemy;
using ICWM.IconSystem;
using ICWM.HelperSystem;
using ICWM.StoreSystem;
/// <summary>
/// Class is needed to manipulate the icons in the inventory
/// </summary>
namespace ICWM
{
namespace DragAndDrop
{
public class DragHandler : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
#region Attributes
public enum BackpackItemDragged
{
NONE,
STASH,
STORE,
BACKPACK,
TACTICALRIG_OR_POCKETS,
BACKPACK_WINDOW,
TACTICALRIG_OR_POCKETS_WINDOW
}
public GameObject icon; // Link to the icon inside the root (we will copy and drag)
public bool isActiveDrag;
public bool isPlayerSlot;
public bool isStashSlot;
public bool isStoreSlot;
public bool isTacticRigSlot; // Сменить название
public bool isBackpackSlot;
public bool deleteVSP = false; // Do we delete the icon?
public bool isAttached = false; // If true that mean that we attachet an attach on the weapon and we need to open the slots under the item(attachment)
public static BackpackItemDragged itemDragged = default;
public static GameObject itemIcon; // Link to the root of the icon (PlayerIcon)
public static GameObject stash; // To work in the inventory (a dummy, since its coordinate system must be linked to the parent's coordinate system of this object)
public static GameObject mBackpack; // To work with the backpack (a dummy, since its coordinate system must be tied to the parent's coordinate system of this object)
public static GameObject mBackpackEnemy;
public static bool isPlayer = false;
public static bool isPlayerBackpack = false;
public static bool isEnemy = false;
public static bool isEnemyBackpack = false;
public static bool isExchangeInventory; // If we change places in the inventory
public static bool isExchangePlayerSlot; // If we change places from inventory to a slot
public static bool isDeleteIcon; // Removing the icon from the inventory
public static bool canNotBeMoved = false; // Indicates that you can not drag
private Quaternion startRotation; // To remember the original angle of the icon (for tracking, if we turned and returned it to the basic state, we do not need to do anything)
private Transform startParent; // Original root (to check where we release our icon)
private GameObject vspInstance;
private GameObject m_vspBackpackWindow; // Временно хранит ссылку на окно рюкзака, от куда была взята иконка
private Vector2 startIndexPos60x60; // Remembers the original size of the icon
private Vector2 screenCoef = Vector2.zero;
private bool isBackpackItem;
private bool isTagSize2x1; // To keep track of, but are we trying to throw this tag into the backpack where you can not just throw
private bool isActive;
private bool isRotatedIcon = false;
private bool isChangeEnemyItemRoot = false;
public ItemList CL = new ItemList();
#endregion
private void Update()
{
if (isActiveDrag) // If we drag, then update the position of the dummy
{
UpdateDummiesPosition();
isActiveDrag = false;
}
// Rotate icons
if (isActive && !CL.isLockRotate && Input.GetKeyDown(KeyCode.R) && !StoreBase.instance.isActive)
UpdateDummiesRotation();
}
#region PUBLIC
#region Drag & Drop
public void OnBeginDrag(PointerEventData eventData) // When pressed and held
{
if (Input.GetMouseButton(1) || Input.GetMouseButton(2))
return;
CL = gameObject.GetComponentInChildren<ButtonOptions>().CL;
screenCoef = Helper.CalculateScreenCoefficient();
//
// Audio
//
if (InventoryBase.instance.a_AudioSelected)
{
InventoryBase.instance.audioSource.clip = InventoryBase.instance.a_AudioSelected;
InventoryBase.instance.audioSource.PlayOneShot(InventoryBase.instance.audioSource.clip);
}
//
// Create the icon
//
vspInstance = (GameObject)Instantiate(icon, InventoryBase.instance.RootIconSpawnPlayer.transform);
vspInstance.name = "vspInstance";
vspInstance.transform.localScale = Vector3.one;
vspInstance.transform.localRotation = icon.transform.localRotation;
vspInstance.transform.localPosition = Vector3.zero;
vspInstance.GetComponent<Image>().raycastTarget = false;
if (GetComponent<CanvasGroup>()) // To avoid self-targeting
GetComponent<CanvasGroup>().blocksRaycasts = false;
else
GetComponentInParent<CanvasGroup>().blocksRaycasts = false;
CreateDummies();
//
//
//
itemIcon = gameObject;
if (itemIcon.GetComponentInParent<PlayerInventorySlot>() && itemIcon.GetComponentInParent<PlayerInventorySlot>().IsPlayerSlot)
{
isPlayerSlot = true;
isPlayer = true;
}
else
{
isPlayerSlot = false;
}
if (itemIcon.GetComponentInParent<StoreInventorySlot>() && itemIcon.GetComponentInParent<StoreInventorySlot>().IsStoreInventory)
isStoreSlot = true;
//
//
//
if (MouseInterStashInventory.instance && MouseInterStashInventory.instance.isActive) // If we drag from the inventory, we release the place under it
{
itemDragged = BackpackItemDragged.STASH;
StashSystem.instance.OpenIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
StashSystem.instance.GetUpdateAssistent().UpdateIconTextBackpack();
if (CL.tagSize == ItemList.SizeIconInventory.Size2x1)
isTagSize2x1 = true;
}
else if (MouseEnterStoreInventory.instance && MouseEnterStoreInventory.instance.isActive)
{
itemDragged = BackpackItemDragged.STORE;
}
else if (MouseEnterBackpack.instance && MouseEnterBackpack.instance.IsActive) // We take from the backpack
{
if (GetComponentInParent<PointEnterPlayerSlots>()) // If there is a parent, then block it (if it's a weapon slot or a backpack slot)
{
if (GetComponentInParent<PointEnterPlayerSlots>().transform.GetComponent<CanvasGroup>())
GetComponentInParent<PointEnterPlayerSlots>().transform.GetComponent<CanvasGroup>().blocksRaycasts = false;
}
isPlayerBackpack = true;
isBackpackItem = true;
if (CL.isPutOn && CL.IsBackpackItemSlot())
BackpackSystem.instance.SaveItemSlots(CL, null, false);
if (isBackpackSlot)
{
BackpackSystem.instance.OpenIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else
{
if (CL.tagItem == ItemList.TagItems.BODYBACKPACK) // To prevent that the backpack itself put in itself - this does not happen
BackpackSystem.instance.rootBackpackCells.GetComponent<CanvasGroup>().blocksRaycasts = false;
BackpackSystem.instance.OpenIndicesTacticalRigPockets(CL);
}
itemDragged = isBackpackSlot ? BackpackItemDragged.BACKPACK : BackpackItemDragged.TACTICALRIG_OR_POCKETS;
}
//
// Backpack Window
//
else if (BackpackSystem.instance.m_vspBackpackWindow && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>().isActive) // We take from the window (backpack)
{
if (GetComponentInParent<PointEnterPlayerSlots>()) // If there is a parent, then block it (if it's a weapon slot or a backpack slot)
{
if (GetComponentInParent<PointEnterPlayerSlots>().transform.GetComponent<CanvasGroup>())
GetComponentInParent<PointEnterPlayerSlots>().transform.GetComponent<CanvasGroup>().blocksRaycasts = false;
}
itemDragged = BackpackItemDragged.BACKPACK_WINDOW;
BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().OpenIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
m_vspBackpackWindow = BackpackSystem.instance.m_vspBackpackWindow;
}
//
// Tactical Rig \ Pockets window
//
else if (BackpackSystem.instance.m_vspBackpackWindow && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>().isActive) // We take from the window (tactical rig, pockets)
{
if (GetComponentInParent<PointEnterPlayerSlots>()) // If there is a parent, then block it (if it's a weapon slot or a backpack slot)
{
if (GetComponentInParent<PointEnterPlayerSlots>().transform.GetComponent<CanvasGroup>())
GetComponentInParent<PointEnterPlayerSlots>().transform.GetComponent<CanvasGroup>().blocksRaycasts = false;
}
itemDragged = BackpackItemDragged.TACTICALRIG_OR_POCKETS_WINDOW;
BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().OpenIndicesTacticalRigPockets(CL);
m_vspBackpackWindow = BackpackSystem.instance.m_vspBackpackWindow;
}
//
// Enemy backpack slots
//
else if (MouseEnterEnemyBackpack.instance && MouseEnterEnemyBackpack.instance.isActive) // We take from the backpack
{
if (GetComponentInParent<PointEnterPlayerSlots>()) // If there is a parent, then block it (if it's a weapon slot or a backpack slot)
{
if (GetComponentInParent<PointEnterPlayerSlots>().transform.GetComponent<CanvasGroup>())
GetComponentInParent<PointEnterPlayerSlots>().transform.GetComponent<CanvasGroup>().blocksRaycasts = false;
}
isEnemyBackpack = true;
isBackpackItem = true;
if (CL.isPutOn && CL.IsBackpackItemSlot())
BackpackEnemyBase.instance.SaveSlotItems(CL, null, false);
if (isBackpackSlot)
{
BackpackEnemyBase.instance.OpenIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else
{
if (CL.tagItem == ItemList.TagItems.BODYBACKPACK) // To prevent that the backpack itself put in itself - this does not happen
BackpackEnemyBase.instance.rootBackpack.GetComponent<CanvasGroup>().blocksRaycasts = false;
BackpackEnemyBase.instance.OpenIndicesTacticalRigPockets(CL);
}
itemDragged = isBackpackSlot ? BackpackItemDragged.BACKPACK : BackpackItemDragged.TACTICALRIG_OR_POCKETS;
}
else if (MouseEnterEnemyPlayerSlots.instance && MouseEnterEnemyPlayerSlots.instance.isActive)
{
isEnemy = true;
}
//
//
//
// Remember...
startRotation = icon.transform.localRotation;
startIndexPos60x60 = CL.indexPos60x60;
startParent = transform.parent;
GetComponent<PlayerIconPlaneInventory>().startPos = transform.localPosition; // At each start, remember the starting position (for certainty)
InventoryBase.instance.CL = CL; // Remember, then send to PointEnterIcon1x1
InventoryBase.instance.isDragHandlerIcon = true; // We are dragging something
Helper.SetImageAlpha(icon.GetComponent<Image>(), 0.5f); // Darken the original icon (when we drag)
isActive = true;
}
public void OnDrag(PointerEventData eventData) // When we drag
{
if (!isActive)
return;
isActiveDrag = true;
Vector2 newPos;
newPos.x = Input.mousePosition.x + Input.mousePosition.x * screenCoef.x; // Add percentage
newPos.y = Input.mousePosition.y + Input.mousePosition.y * screenCoef.y;
// Update the position of the icon when we move the mouse
vspInstance.transform.localPosition = newPos;
}
public void OnEndDrag(PointerEventData eventData) // When we drop
{
if (!isActive)
return;
if (!isDeleteIcon)
{
GetComponent<CanvasGroup>().blocksRaycasts = true;
if (transform.parent != startParent)
DropItemOnLocations();
else
DropItemToSartLocation();
}
else
{
Destroy(gameObject);
}
CloseDragHandler();
}
#endregion
#region Helpers
public void SetReserveParameters(ItemList cl, bool mode)
{
if (mode)
{
cl.isPlayerSlot = cl.isStashSlot = cl.isTacticRigSlot = cl.isBackpackSlot = false; // Reset
if (isPlayerSlot)
cl.isPlayerSlot = isPlayerSlot;
else if (isStashSlot)
cl.isStashSlot = isStashSlot;
else if (isTacticRigSlot)
cl.isTacticRigSlot = isTacticRigSlot;
else if (isBackpackSlot)
cl.isBackpackSlot = isBackpackSlot;
isPlayerSlot = isStashSlot = isTacticRigSlot = isBackpackSlot = false; // Reset
}
else
{
isPlayerSlot = isStashSlot = isTacticRigSlot = isBackpackSlot = false;
if (cl.isPlayerSlot)
isPlayerSlot = cl.isPlayerSlot;
else if (cl.isStashSlot)
isStashSlot = cl.isStashSlot;
else if (cl.isTacticRigSlot)
isTacticRigSlot = cl.isTacticRigSlot;
else if (cl.isBackpackSlot)
isBackpackSlot = cl.isBackpackSlot;
cl.isPlayerSlot = cl.isStashSlot = cl.isTacticRigSlot = cl.isBackpackSlot = false;
}
}
#endregion
#endregion
#region PRIVATE
#region Update
private void UpdateDummiesPosition()
{
if (stash)
{
stash.transform.position = vspInstance.transform.position;
stash.transform.localRotation = vspInstance.transform.localRotation;
}
if (mBackpack)
{
mBackpack.transform.position = vspInstance.transform.position;
mBackpack.transform.localRotation = vspInstance.transform.localRotation;
}
if (mBackpackEnemy)
{
mBackpackEnemy.transform.position = vspInstance.transform.position;
mBackpackEnemy.transform.localRotation = vspInstance.transform.localRotation;
}
BackpackSystem.instance.UpdateBackpackDummyPosition(vspInstance);
}
private void UpdateDummiesRotation()
{
// Here the icon turns
// Can only call when we drag and drop the icons
// There is no sense in turning icons 1x1 and mn
if (itemDragged == BackpackItemDragged.STASH && LootBase.instance.isLootWindowMode)
return;
isRotatedIcon = true;
if (vspInstance.transform.localRotation == Quaternion.Euler(Vector3.zero))
{
vspInstance.transform.localRotation = Quaternion.Euler(new Vector3(0f, 0f, -90f)); // Turn clockwise
int x = (int)CL.indexPos60x60.x;
CL.indexPos60x60.x = CL.indexPos60x60.y;
CL.indexPos60x60.y = x;
}
else
{
vspInstance.transform.localRotation = Quaternion.Euler(Vector3.zero); // Return to the original state
int y = (int)CL.indexPos60x60.y;
CL.indexPos60x60.y = CL.indexPos60x60.x;
CL.indexPos60x60.x = y;
}
CL.tagSize = CL.GetReverseCurrentSizeTag(); // Changes the tag size
// In advance, if in one session (i.e., for one drag and drop) after a series of angle changes, we still returned to the basic condition, then do nothing
if (vspInstance.transform.localRotation == startRotation)
isRotatedIcon = false;
if (stash)
stash.transform.localRotation = vspInstance.transform.localRotation;
if (mBackpack)
mBackpack.transform.localRotation = vspInstance.transform.localRotation;
if (mBackpackEnemy)
mBackpackEnemy.transform.localRotation = vspInstance.transform.localRotation;
BackpackSystem.instance.UpdateBackpackDummyPosition(vspInstance);
// We update the parameter, because it is passed to the PointEnterIcon1x1 method and draws the field
InventoryBase.instance.CL = CL;
}
#endregion
#region Another Location
private void DropItemOnLocations()
{
if (transform.GetComponentInChildren<ButtonOptions>().CL.tagItem == CL.tagItem) // If the tags are equal, change places
{
if (!isExchangePlayerSlot) // If we do not change the places inventory to slot
{
if (!BackpackSystem.instance.RE4O_IsActive() && MouseEnterPlayerInventory.instance && MouseEnterPlayerInventory.instance.isActive) // If we are in slots for the player (ie from the inventory we drag into slots)
DropInPlayersSlots();
else if (!BackpackSystem.instance.RE4O_IsActive() && MouseEnterEnemyPlayerSlots.instance && MouseEnterEnemyPlayerSlots.instance.isActive) // If we are in slots for the player (ie from the inventory we drag into slots)
DropInEnemySlots();
if (MouseEnterBackpack.instance && MouseEnterBackpack.instance.IsActive) // In the backpack
DropInPlayerBackpack();
else if (MouseEnterEnemyBackpack.instance && MouseEnterEnemyBackpack.instance.isActive) // In the backpack
DropInEnemyBackpack();
}
else if (!isPlayerSlot && isStashSlot) // If we take from the inventory and drop it the slot for the player
StashSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
if (vspInstance)
Destroy(vspInstance);
if (stash)
Destroy(stash);
}
private void DropInPlayersSlots()
{
bool canChangeSize = false;
bool isCreatedIcon = false;
if (isRotatedIcon) // If turned and if we drop it in some other place (not on the icon or in inventory) we return to the basic size
{
if (!canNotBeMoved)
canChangeSize = PlayerSystem.instance.CreateNewIcon(itemIcon, CL, transform.parent, false, isRotatedIcon); // transform.parent - you can not transfer
deleteVSP = true;
isCreatedIcon = true;
}
if (CL.itWasRotated && !canChangeSize && !isCreatedIcon) // Если мы перетаскиваем уже поверную иконку
{
canChangeSize = PlayerSystem.instance.CreateNewIcon(itemIcon, CL, transform.parent, true);
deleteVSP = true;
}
if (!canChangeSize)
ExchangeIconsSize();
//
// In Player Slots
//
if (isBackpackSlot) // If from a backpack
{
if (transform.parent == startParent) // If the parent does not changed - close
{
if (isRotatedIcon)
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
if (isPlayerBackpack)
BackpackSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
}
else if (itemDragged == BackpackItemDragged.STASH) // From inventory
{
if (!deleteVSP)
StashSystem.instance.OpenIndicesBackpackByIconPosition(GetComponent<PlayerIconPlaneInventory>().startPos, CL.indexPos60x60);
if (LootBase.instance.isLootWindowMode || LootBase.instance.isLootWindow)
{
if (CL.IsRenderItem())
CL.SetItemModdingParameters(false, InventoryBase.instance.RootSpawnWeaponModding.transform);
else
CL.SetItemModdingParameters(false, InventoryBase.instance.RootSpawnItemsAttach.transform);
if (CL.destroyItemDrop)
Destroy(CL.destroyItemDrop);
}
}
}
private void DropInEnemySlots()
{
if (!isPlayerSlot) // From backpack
{
bool canChangeSize = false;
bool isCreatedIcon = false;
if (isRotatedIcon) // If turned and if we drop it in some other place (not on the icon or in inventory) we return to the basic size
{
if (!canNotBeMoved)
canChangeSize = PlayerEnemySystem.instance.CreateNewIcon(itemIcon, CL, transform.parent, false, isRotatedIcon); // transform.parent - you can not transfer
deleteVSP = true;
isCreatedIcon = true;
}
if (CL.itWasRotated && !canChangeSize && !isCreatedIcon)
{
canChangeSize = PlayerEnemySystem.instance.CreateNewIcon(itemIcon, CL, transform.parent, true);
deleteVSP = true;
}
if (!canChangeSize)
ExchangeIconsSize();
//
// In Player Slots
//
if (isBackpackSlot) // If from a backpack
{
if (transform.parent == startParent) // If the parent does not change - close
{
if (isRotatedIcon)
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
if (isPlayerBackpack)
BackpackSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
}
else if (itemDragged == BackpackItemDragged.STASH && !deleteVSP) // From inventory
{
StashSystem.instance.OpenIndicesBackpackByIconPosition(GetComponent<PlayerIconPlaneInventory>().startPos, CL.indexPos60x60);
}
}
SetEnemyItemPutOn();
}
private void DropInPlayerBackpack()
{
if (!isExchangeInventory) // If we do not interchange the two items with each other
{
if (isEnemyBackpack && CL.IsBackpackItemSlot() && CL.isPutOn)
BackpackEnemyBase.instance.OpenCells(CL);
if (!canNotBeMoved)
BackpackSystem.instance.UpdateIconPositionAfterDropOnTacticalRigOrPocketsSlot(itemIcon, CL, isRotatedIcon, startParent, isPlayerSlot, isEnemyBackpack, itemDragged);
}
}
private void DropInEnemyBackpack()
{
if (!isExchangeInventory) // If we do not interchange the two items with each other
{
if (isPlayerBackpack && CL.IsBackpackItemSlot() && CL.isPutOn)
BackpackSystem.instance.OpenCells(CL);
if (!canNotBeMoved)
{
BackpackEnemyBase.instance.UpdateIconPositionAfterDropOnTacticalRigOrPocketsSlot(itemIcon, CL, isRotatedIcon, startParent, isPlayerSlot, true, itemDragged);
CheckRootItem();
}
}
}
private void SetEnemyItemPutOn()
{
CL.isPutOn = true;
CL.isEnemyItem = true;
// CL.DestroyItemDrop - т.к. в скрипте Slot мы создали в корне Енеми префам ItemDrop
InventoryBase.instance.inventoryEnemy.GetComponent<EnemyInventory>().PutOnSlots(CL, CL.destroyItemDrop);
}
#endregion
#region Start Location
private void DropItemToSartLocation()
{
if (!isExchangeInventory) // If we do not change the places 2 items in the inventory
{
// If we are in the inventory
if (MouseInterStashInventory.instance && MouseInterStashInventory.instance.isActive && itemDragged != DragHandler.BackpackItemDragged.STORE)
{
DropInStashSlotsByStartLoc();
}
else if ((MouseEnterBackpack.instance && MouseEnterBackpack.instance.IsActive) || (MouseEnterEnemyBackpack.instance && MouseEnterEnemyBackpack.instance.isActive)) // In the backpack
{
DropInBackpackTacticalRigPocketsByStartLoc();
}
else if (BackpackSystem.instance.m_vspBackpackWindow && ((BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>().isActive) || (BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>().isActive))) // In the backpack/tactical rig /pockets window
{
DropInBackpackTacticalRigPocketsWindowByStartLoc();
}
else
{
DropInPlayersSlotsByStartLoc();
}
}
else // If we swap 2 items in the inventory
{
if (isRotatedIcon) // If turned and if we drop it in some other place (not on the icon or in inventory) we return to the basic state
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
StashSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
}
private void DropInBackpackTacticalRigPocketsByStartLoc()
{
//
// Player BACKPACK
//
if (MouseEnterBackpackSlot.instance && MouseEnterBackpackSlot.instance.IsActive && BackpackSystem.instance.GetBackpackInfo().isActiveBackpack) // If we drop in a backpack
{
if (!canNotBeMoved)
{
if (MouseEnterEnemyBackpackSlots.instance && MouseEnterEnemyBackpackSlots.instance.isActive && BackpackEnemyBase.instance.GetBackpackInfo().isActiveBackpack) // Куда переносим
{
deleteVSP = BackpackSystem.instance.UpdateIconPositionAfterDropInBackpack(mBackpackEnemy.transform, CL, itemIcon, GetComponent<PlayerIconPlaneInventory>().startPos, isPlayerSlot, isRotatedIcon, isBackpackItem, isEnemyBackpack, itemDragged);
}
if (BackpackSystem.instance.m_vspBackpackWindow && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>().isActive)
{
deleteVSP = BackpackSystem.instance.UpdateIconPositionAfterDropInBackpack(BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().mBackpackWindow.transform, CL, itemIcon, GetComponent<PlayerIconPlaneInventory>().startPos, isPlayerSlot, isRotatedIcon, isBackpackItem, isEnemyBackpack, itemDragged);
}
else //
{
CloseAllOpendBackpackWindows();
deleteVSP = BackpackSystem.instance.UpdateIconPositionAfterDropInBackpack(mBackpack.transform, CL, itemIcon, GetComponent<PlayerIconPlaneInventory>().startPos, isPlayerSlot, isRotatedIcon, isBackpackItem, isEnemyBackpack, itemDragged);
}
}
GetComponent<PlayerIconPlaneInventory>().startPos = itemIcon.transform.localPosition; // Change the original position of the icon in the inventory
// If we do not reassign the parent (ie, drop into the empty place or there is no place or simply drop in the inventory)
if (transform.parent == startParent)
CloseBackpackSlots();
else
OpenBackpackSlots();
}
//
// Enemy backpack
//
else if (MouseEnterEnemyBackpackSlots.instance && MouseEnterEnemyBackpackSlots.instance.isActive && BackpackEnemyBase.instance.GetBackpackInfo().isActiveBackpack) // If we drop in a backpack (that is, in this little ***)
{
if (!canNotBeMoved)
{
if (MouseEnterBackpackSlot.instance && MouseEnterBackpackSlot.instance.IsActive && BackpackSystem.instance.GetBackpackInfo().isActiveBackpack)
{
deleteVSP = BackpackEnemyBase.instance.UpdateIconPositionAfterDropInBackpack(mBackpack.transform, CL, itemIcon, GetComponent<PlayerIconPlaneInventory>().startPos, isPlayerSlot, isRotatedIcon, isBackpackItem, itemDragged);
}
else if (BackpackSystem.instance.m_vspBackpackWindow && ((BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>().isActive) || (BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>().isActive)) && !BackpackSystem.instance.RE4O_IsActive() && !BackpackSystem.instance.RE4_IsActive())
{
deleteVSP = BackpackEnemyBase.instance.UpdateIconPositionAfterDropInBackpack(BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().mBackpackWindow.transform, CL, itemIcon, GetComponent<PlayerIconPlaneInventory>().startPos, isPlayerSlot, isRotatedIcon, isBackpackItem, itemDragged);
}
else
{
CloseAllOpendBackpackWindows();
deleteVSP = BackpackEnemyBase.instance.UpdateIconPositionAfterDropInBackpack(mBackpackEnemy.transform, CL, itemIcon, GetComponent<PlayerIconPlaneInventory>().startPos, isPlayerSlot, isRotatedIcon, isBackpackItem, itemDragged);
}
}
GetComponent<PlayerIconPlaneInventory>().startPos = itemIcon.transform.localPosition; // Change the original position of the icon in the inventory
// If we do not reassign the parent (ie, drop into the empty place or there is no place or simply drop in the inventory)
if (transform.parent == startParent)
CloseBackpackSlots();
else
OpenBackpackSlots();
}
//
// TACTICAL RIG, POCKETS
//
else
{
bool flag = false;
if (!canNotBeMoved)
{
if (MouseEnterBackpack.instance && MouseEnterBackpack.instance.IsActive) // в слоты игрока
{
flag = BackpackSystem.instance.UpdateIconPositionAfterDropOnTacticalRigOrPocketsSlot(itemIcon, CL, isRotatedIcon, startParent, isPlayerSlot, isEnemyBackpack, itemDragged);
}
else if (MouseEnterEnemyBackpack.instance && MouseEnterEnemyBackpack.instance.isActive) // Если переносим в слоты другого инвентаря
{
flag = BackpackEnemyBase.instance.UpdateIconPositionAfterDropOnTacticalRigOrPocketsSlot(itemIcon, CL, isRotatedIcon, startParent, isPlayerSlot, isPlayerBackpack, itemDragged);
}
}
// Many stupid situations happen during the rearrangement of icons, for example:
// from the inventory raised - turned a couple of hundred times - it did not rise in its original position (ie if we once clicked on the turn)
// and after they drop it in a backpack where such icons are forbidden, here, now it is necessary to return everything in a condition
if (transform.parent == startParent && !deleteVSP) // If we do not reassign the parent (ie, drop into the empty place or not)
{
if (itemDragged != BackpackItemDragged.STASH) // If in a backpack (or tactical rig)
{
if (isBackpackSlot)
{
if (isRotatedIcon)
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
if (isPlayerBackpack)
BackpackSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (itemDragged == DragHandler.BackpackItemDragged.BACKPACK_WINDOW && m_vspBackpackWindow)
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (itemDragged == DragHandler.BackpackItemDragged.TACTICALRIG_OR_POCKETS_WINDOW && m_vspBackpackWindow)
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesTacticalRigPockets(CL);
}
else if (itemDragged == DragHandler.BackpackItemDragged.BACKPACK_WINDOW && m_vspBackpackWindow)
{
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else if (itemDragged == DragHandler.BackpackItemDragged.TACTICALRIG_OR_POCKETS_WINDOW && m_vspBackpackWindow)
{
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesTacticalRigPockets(CL);
}
else
{
if (!isPlayerSlot)
{
if (isRotatedIcon)
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
if (isPlayerBackpack)
BackpackSystem.instance.CloseIndicesTacticalRigPockets(CL);
else if (isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesTacticalRigPockets(CL);
}
else
{
if (MouseEnterEnemyPlayerSlots.instance && MouseEnterEnemyPlayerSlots.instance.isActive)
PlayerEnemySystem.instance.UpdatePlayerSlotOnDrop(CL);
else
StartCoroutine(PlayerSystem.instance.UpdatePlayerSlotOnDropEndOfFrame(CL)); // Next frame we will update the slots
}
}
}
else if (isBackpackSlot) // From a backpack to pockets or tactical rig
{
if (isRotatedIcon)
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
if (isPlayerBackpack)
BackpackSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else
{
if (isRotatedIcon)
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
StashSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
}
else
{
if (flag && itemDragged == BackpackItemDragged.STASH) // If we drag from the inventory into the backpack and at the same time there is no place
{
if (isRotatedIcon)
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
StashSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else if (!flag)
{
if (!isRotatedIcon && itemDragged == BackpackItemDragged.STASH && isTagSize2x1)
{
StashSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else if (isRotatedIcon)
{
if (itemDragged == BackpackItemDragged.STASH && CL.tagSize == ItemList.SizeIconInventory.Size2x1)
{
StashSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else if (itemDragged != BackpackItemDragged.STASH) // If in the backpack everything happens
{
if (isPlayerBackpack)
BackpackSystem.instance.CloseIndicesTacticalRigPockets(CL);
else if (isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesTacticalRigPockets(CL);
}
}
}
}
}
if (transform.parent != startParent)
CheckRootItem();
}
private void DropInBackpackTacticalRigPocketsWindowByStartLoc()
{
if (!canNotBeMoved && BackpackSystem.instance.m_vspBackpackWindow)
{
if (MouseEnterEnemyBackpackSlots.instance && MouseEnterEnemyBackpackSlots.instance.isActive && BackpackEnemyBase.instance.GetBackpackInfo().isActiveBackpack) // Куда переносим
{
deleteVSP = BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().UpdateIconPositionAfterDropInBackpack(mBackpackEnemy.transform, CL, itemIcon, GetComponent<PlayerIconPlaneInventory>().startPos, isPlayerSlot, isRotatedIcon, isBackpackItem, isEnemyBackpack, itemDragged);
}
else if (BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>().isActive) // Куда переносим
{
if (!CanDestrorItemIcon())
deleteVSP = BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().UpdateIconPositionAfterDropInBackpack(BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().mBackpackWindow.transform, CL, itemIcon, GetComponent<PlayerIconPlaneInventory>().startPos, isPlayerSlot, isRotatedIcon, isBackpackItem, isEnemyBackpack, itemDragged);
}
else if (BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>().isActive) // Куда переносим
{
if (!CanDestrorItemIcon())
BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().UpdateIconPositionAfterDropOnTacticalRigOrPocketsSlot(itemIcon, CL, isRotatedIcon, startParent, isPlayerSlot, itemDragged);
}
else //
{
deleteVSP = BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().UpdateIconPositionAfterDropInBackpack(mBackpack.transform, CL, itemIcon, GetComponent<PlayerIconPlaneInventory>().startPos, isPlayerSlot, isRotatedIcon, isBackpackItem, isEnemyBackpack, itemDragged);
}
}
GetComponent<PlayerIconPlaneInventory>().startPos = itemIcon.transform.localPosition; // Change the original position of the icon in the inventory
// If we do not reassign the parent (ie, drop into the empty place or there is no place or simply drop in the inventory)
if (transform.parent == startParent && !deleteVSP)
CloseBackpackSlots();
else
OpenBackpackSlots();
if (transform.parent != startParent)
CheckRootItem();
}
private void DropInPlayersSlotsByStartLoc()
{
//
// PLAYER SLOTS
//
if (!BackpackSystem.instance.RE4O_IsActive() && MouseEnterPlayerInventory.instance && !MouseEnterPlayerInventory.instance.isActive)
{
if (!isPlayerSlot) // If we do not drag from the player's slot (not to close our area)
CloseBackpackSlotsFromPlayer();
}
else if (!BackpackSystem.instance.RE4O_IsActive() && MouseEnterEnemyPlayerSlots.instance && !MouseEnterEnemyPlayerSlots.instance.isActive)
{
if (!isPlayerSlot) // If we do not drag from the player's slot (not to close our area)
CloseBackpackSlotsFromPlayer();
}
else
{
if (!isPlayerSlot) // If we do not drag from the player's slot (not to close our area)
{
if (itemDragged == BackpackItemDragged.STASH)
{
if (isRotatedIcon) // If turned and if we drop it in some other place (not on the icon or in inventory) we return to the basic state
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
if (!isAttached)
StashSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else if (isBackpackSlot) // If we drag from the backpack into a slot
{
if (isRotatedIcon)
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
if (isPlayerBackpack)
{
if (!isAttached)
{
BackpackSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
}
else if (isEnemyBackpack)
{
BackpackEnemyBase.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else if (itemDragged == BackpackItemDragged.BACKPACK_WINDOW && m_vspBackpackWindow)
{
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
}
else if (itemDragged == BackpackItemDragged.BACKPACK_WINDOW && m_vspBackpackWindow)
{
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else if (itemDragged == BackpackItemDragged.TACTICALRIG_OR_POCKETS_WINDOW && m_vspBackpackWindow)
{
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesTacticalRigPockets(CL);
}
else if (itemDragged == BackpackItemDragged.TACTICALRIG_OR_POCKETS)
{
if (isPlayerBackpack && !isAttached) // We can't close the index if we attached an item on the weapon
BackpackSystem.instance.CloseIndicesTacticalRigPockets(CL);
else if (isEnemyBackpack)
BackpackSystem.instance.CloseIndicesTacticalRigPockets(CL);
}
}
else
{
if (isRotatedIcon) // If turned and if we drop it in some other place (not on the icon or in inventory) we return to the basic state
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
}
}
}
private void DropInStashSlotsByStartLoc()
{
//
// STASH
//
//
// We perform the appropriate calculations
//
if (!canNotBeMoved && StoreBase.instance && !StoreBase.instance.isActive) // Для всего магазина
{
CloseAllOpendBackpackWindows();
deleteVSP = StashSystem.instance.UpdateIconPositionAfterDropInStash(stash.transform, CL, itemIcon, GetComponent<PlayerIconPlaneInventory>().startPos, isPlayerSlot, isRotatedIcon, isBackpackSlot, itemDragged);
}
GetComponent<PlayerIconPlaneInventory>().startPos = itemIcon.transform.localPosition; // Change the original position of the icon in the inventory
//
//// We check, and we drop the backpack in the Stash or something like that
//
if (itemDragged == BackpackItemDragged.TACTICALRIG_OR_POCKETS) // With tactical rig or pockets
{
if (transform.parent != startParent) // We look, but we actually dropped
OpenBackpackSlots();
}
else if (isBackpackSlot && !deleteVSP) // From the backpack
{
if (transform.parent == startParent) // Look, if the parent has not changed, you need to close the place under the icon
{
if (isRotatedIcon)
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
if (isPlayerBackpack)
BackpackSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (itemDragged == BackpackItemDragged.BACKPACK_WINDOW && m_vspBackpackWindow)
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (itemDragged == BackpackItemDragged.TACTICALRIG_OR_POCKETS_WINDOW && m_vspBackpackWindow)
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesTacticalRigPockets(CL);
}
}
else if (itemDragged == BackpackItemDragged.BACKPACK_WINDOW && m_vspBackpackWindow)
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (itemDragged == BackpackItemDragged.TACTICALRIG_OR_POCKETS_WINDOW && m_vspBackpackWindow)
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesTacticalRigPockets(CL);
else
{
if (isRotatedIcon && !deleteVSP) // If turned and if we drop it in some other place (not on the icon or in inventory) we return to the basuc state
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
if (!isPlayerSlot)
StashSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
}
private void CloseBackpackSlots()
{
if (isBackpackSlot)
{
if (isRotatedIcon && !deleteVSP) // We need to somehow track the situation, when in the backpack we move + the turn + there is no place or beyond the limits left
{
CL.indexPos60x60 = startIndexPos60x60;
if (CL.itWasRotated == false)
CL.tagSize = CL.baseTagSize;
else
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
if (isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (isPlayerBackpack)
BackpackSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (itemDragged == BackpackItemDragged.BACKPACK_WINDOW && m_vspBackpackWindow)
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (itemDragged == BackpackItemDragged.TACTICALRIG_OR_POCKETS_WINDOW && m_vspBackpackWindow)
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesTacticalRigPockets(CL);
}
else if (itemDragged == BackpackItemDragged.STASH) // If we drop from inventory + turn + no place
{
if (isRotatedIcon)
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
StashSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else if (isPlayerSlot) // If from the player's slot in the backpack + turn + there is no place
{
if (isRotatedIcon && !deleteVSP)
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
}
else if (itemDragged == BackpackItemDragged.TACTICALRIG_OR_POCKETS)
{
//Если мы переносим из слотов енеми (тактик рик, покетс) и так получилось, что не перенесли (попали в красную обл и тд) нужно закрыть
if (isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesTacticalRigPockets(CL);
else if (isPlayerBackpack)
BackpackSystem.instance.CloseIndicesTacticalRigPockets(CL);
if (isRotatedIcon && !deleteVSP)
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
}
else if (itemDragged == BackpackItemDragged.BACKPACK_WINDOW && m_vspBackpackWindow)
{
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else if (itemDragged == BackpackItemDragged.TACTICALRIG_OR_POCKETS_WINDOW && m_vspBackpackWindow)
{
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesTacticalRigPockets(CL);
}
}
private void CloseBackpackSlotsFromPlayer()
{
if (isRotatedIcon) // If turned and if we drop it in some other place (not on the icon or in inventory) we return to the basic state
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
if (itemDragged == BackpackItemDragged.STASH)
{
StashSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else if (itemDragged == BackpackItemDragged.TACTICALRIG_OR_POCKETS) // With tactical rig or pockets
{
if (isPlayerBackpack)
BackpackSystem.instance.CloseIndicesTacticalRigPockets(CL);
else if (isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesTacticalRigPockets(CL);
}
else if (itemDragged == BackpackItemDragged.BACKPACK_WINDOW && m_vspBackpackWindow)
{
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
else if (itemDragged == BackpackItemDragged.TACTICALRIG_OR_POCKETS_WINDOW && m_vspBackpackWindow)
{
m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CloseIndicesTacticalRigPockets(CL);
}
else if (isBackpackSlot) // From the backpack
{
if (isRotatedIcon && !deleteVSP)
{
CL.indexPos60x60 = startIndexPos60x60;
CL.tagSize = CL.GetReverseCurrentSizeTag();
}
if (isPlayerBackpack)
BackpackSystem.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
else if (isEnemyBackpack)
BackpackEnemyBase.instance.CloseIndicesBackpackByIconPosition(CL.indexPos60x60, GetComponent<PlayerIconPlaneInventory>().startPos);
}
}
private void OpenBackpackSlots()
{
if (itemDragged != BackpackItemDragged.TACTICALRIG_OR_POCKETS || !CL.isPutOn)
return;
if (CL.IsBackpackItemSlot())
{
if (isPlayerBackpack)
BackpackSystem.instance.OpenCells(CL);
else if (isEnemyBackpack)
BackpackEnemyBase.instance.OpenCells(CL);
}
}
private bool CanDestrorItemIcon()
{
if (!CL.isPutOn)
return false;
if (isPlayerBackpack) // Если взяли у игрока
{
if (CL.tagItem == ItemList.TagItems.BODYBACKPACK) // Если это рюкзак и он надет
{
if (BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().vspButtonOption.isOpenedFromPlayerInv) // Если переносим в открытый неактивный рюкзак, который был открыт из слотов игрока (из его инвентаря)
return true;
}
}
else if (isEnemyBackpack)
{
if (CL.tagItem == ItemList.TagItems.BODYBACKPACK) // Если это рюкзак и он надет
{
if (BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().vspButtonOption.isOpenedFromEnemyInv) // Если переносим в открытый неактивный рюкзак, который был открыт из слотов игрока (из его инвентаря)
return true;
}
}
return false;
}
#endregion
#region Helpers
// Меняем директорию
private void CheckRootItem()
{
if (canNotBeMoved)
return;
if ((MouseEnterPlayerInventory.instance && MouseEnterPlayerInventory.instance.isActive) || (MouseEnterBackpack.instance && MouseEnterBackpack.instance.IsActive)) // Куда
{
if (isEnemyBackpack || isEnemy) // От куда
{
ChangeRootItem();
}
}
else if (BackpackSystem.instance.m_vspBackpackWindow && ((BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterBackpackWindow>().isActive) || (BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>() && BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<MouseEnterTacticalRigPocketsWindow>().isActive))) // Куда
{
if (isEnemyBackpack || isEnemy) // От куда
{
ChangeRootItem(3);
}
}
else if (MouseEnterEnemyPlayerSlots.instance && MouseEnterEnemyPlayerSlots.instance.isActive) // Куда
{
if (isPlayerBackpack || isPlayer || isEnemyBackpack || itemDragged == BackpackItemDragged.BACKPACK_WINDOW || itemDragged == BackpackItemDragged.TACTICALRIG_OR_POCKETS_WINDOW) // От куда
{
if (!CL.isPutOn)
ChangeRootItem(2);
else
ChangeRootItem(1);
}
}
else if (MouseEnterEnemyBackpack.instance && MouseEnterEnemyBackpack.instance.isActive) // Куда
{
if (isPlayerBackpack || isPlayer || isEnemyBackpack || itemDragged == BackpackItemDragged.BACKPACK_WINDOW || itemDragged == BackpackItemDragged.TACTICALRIG_OR_POCKETS_WINDOW) // От куда
{
if (!CL.isPutOn || isPlayer)
ChangeRootItem(1);
else
ChangeRootItem(2);
}
}
}
// Проверяем у кого мы взяли
// mode = 0 - Player int
// mode = 1 - Enemy Backpack
// mode = 2 - Enemy Player slots
// mode = 3 - Backpack Window
private void ChangeRootItem(int mode = 0)
{
if (mode == 0 || mode == 3) // Player
{
// Удалим объект (он больше не нужен)
if (CL.destroyItemDrop)
{
if (isEnemyBackpack)
{
if (CL.tagItem == ItemList.TagItems.BODYTACTICALRIG)
{
if (CL.insertCL.Length > 0)
{
for (int i = 0; i < CL.insertCL.Length; i++)
{
if (CL.insertCL[i] == null)
break;
if (CL.insertCL[i].idSlotBackpack > 10)
continue;
if (mode == 1)
{
if (CL.insertCL[i].IsRenderItem())
CL.insertCL[i].itemModding.transform.SetParent(InventoryBase.instance.RootSpawnWeaponModding.transform);
}
else
{
if (BackpackSystem.instance.m_vspBackpackWindow)
CL.insertCL[i].itemModding.transform.SetParent(BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().rootSpawnWeaponModding.transform);
}
}
}
}
}
if (mode == 0)
{
if (CL.IsRenderItem())
CL.SetItemModdingParameters(false, InventoryBase.instance.RootSpawnWeaponModding.transform);
}
else
{
if (BackpackSystem.instance.m_vspBackpackWindow)
CL.SetItemModdingParameters(false, BackpackSystem.instance.m_vspBackpackWindow.GetComponent<BackpackWindow>().rootSpawnWeaponModding.transform);
}
Destroy(CL.destroyItemDrop);
CL.destroyItemDrop = null;
}
}
else // Enemy
{
if (CL.destroyItemDrop)
{
if (CL.destroyItemDrop.transform.parent)
Destroy(CL.destroyItemDrop);
CL.destroyItemDrop = null;
}
if (CL.destroyItemDrop == null)
CL.destroyItemDrop = (GameObject)Instantiate(InventoryBase.instance.ItemsDropPrefab);
CL.destroyItemDrop.name = CL.id.ToString();
Helper.SetParameters(CL.destroyItemDrop, CL); // New Set
if (mode == 1)
isChangeEnemyItemRoot = true; // Выносим эту функцию в конец операции (т.к. не все параметры еще присвоены)
else if (mode == 2)
CL.destroyItemDrop.transform.SetParent(InventoryBase.instance.inventoryEnemy.m_SpawnEnemyDropItems); // Player items
CL.destroyItemDrop.transform.localPosition = Vector3.zero;
CL.SetItemModdingParameters(false, CL.destroyItemDrop.transform);
}
}
// Зайдем сюда только если повернули в процессе переноса
// IMP THIS
private void ExchangeIconsSize()
{
if (CL.tagItem == ItemList.TagItems.WEAPON)
{
itemIcon.GetComponent<RectTransform>().sizeDelta = CL.GetIconSizeForSlots();
}
else
{
// Change the size under the icon 120х120
// Shift to half the icon
itemIcon.transform.localPosition = Vector3.zero;
itemIcon.GetComponent<RectTransform>().sizeDelta = new Vector2(120, 120);
itemIcon.GetComponentInChildren<ButtonOptions>().transform.localPosition = Vector3.zero;
itemIcon.GetComponentInChildren<ButtonOptions>().Icon.GetComponent<RectTransform>().sizeDelta = CL.GetIconSizeForSlots();
}
}
private void CreateDummies()
{
//
// In the Stash coordinate system (if it is on)
//
if (InventoryBase.instance.hideStash || LootBase.instance.isActiveLoot || StoreBase.instance.isActive)
{
stash = new GameObject("mStash");
stash.GetComponent<Transform>().SetParent(StashSystem.instance.GetRootIconsSpawn().transform);
stash.GetComponent<Transform>().localScale = Vector3.one;
stash.GetComponent<Transform>().localRotation = icon.transform.localRotation;
stash.GetComponent<Transform>().localPosition = Vector3.zero;
}
//
// In the backpack's coordinate system (if it is on)
//
if (BackpackSystem.instance.GetBackpackInfo().isActiveBackpack)
{
mBackpack = new GameObject("mBackpackDummy");
mBackpack.GetComponent<Transform>().SetParent(BackpackSystem.instance.rootIconItemsBackpackSpawn.transform);
mBackpack.GetComponent<Transform>().localScale = Vector3.one;
mBackpack.GetComponent<Transform>().localRotation = icon.transform.localRotation;
mBackpack.GetComponent<Transform>().localPosition = Vector3.zero;
}
if (BackpackEnemyBase.instance && BackpackEnemyBase.instance.GetBackpackInfo().isActiveBackpack)
{
mBackpackEnemy = new GameObject("mBackpackEnemyDummy");
mBackpackEnemy.GetComponent<Transform>().SetParent(BackpackEnemyBase.instance.rootBackpackIconsSpawn.transform);
mBackpackEnemy.GetComponent<Transform>().localScale = Vector3.one;
mBackpackEnemy.GetComponent<Transform>().localRotation = icon.transform.localRotation;
mBackpackEnemy.GetComponent<Transform>().localPosition = Vector3.zero;
}
BackpackSystem.instance.CreateBackpacksDummy(icon);
}
#endregion
#region Close, Reset, etc
private void CloseDragHandler()
{
//
// Audio
//
if (InventoryBase.instance.audioSource.clip)
InventoryBase.instance.audioSource.PlayOneShot(InventoryBase.instance.audioSource.clip);
//
// Reset
//
ResetParameters();
ResetDragAndDrop();
if (vspInstance)
Destroy(vspInstance);
if (stash)
Destroy(stash);
if (mBackpack)
Destroy(mBackpack);
if (mBackpackEnemy)
Destroy(mBackpackEnemy);
BackpackSystem.instance.DestroyBackpackDummies();
}
private void ResetParameters()
{
if (GetComponent<CanvasGroup>())
GetComponent<CanvasGroup>().blocksRaycasts = true;
else
GetComponentInParent<CanvasGroup>().blocksRaycasts = true;
BackpackSystem.instance.rootBackpackCells.GetComponent<CanvasGroup>().blocksRaycasts = true;
if (BackpackEnemyBase.instance && BackpackEnemyBase.instance.isActive)
BackpackEnemyBase.instance.rootBackpack.GetComponent<CanvasGroup>().blocksRaycasts = true;
if (CL.IsBackpackItemSlot()) // If there is a parent, then block it (if it's a weapon slot or the backpack slot)
{
if (transform.parent == startParent)
{
if (GetComponentInParent<PointEnterPlayerSlots>())
if (GetComponentInParent<PointEnterPlayerSlots>().transform.GetComponent<CanvasGroup>())
GetComponentInParent<PointEnterPlayerSlots>().transform.GetComponent<CanvasGroup>().blocksRaycasts = true;
}
else
{
if (startParent != null && startParent.GetComponentInParent<PointEnterPlayerSlots>())
if (startParent.GetComponentInParent<PointEnterPlayerSlots>().transform.GetComponent<CanvasGroup>())
startParent.GetComponentInParent<PointEnterPlayerSlots>().transform.GetComponent<CanvasGroup>().blocksRaycasts = true;
}
}
if (InventoryBase.instance.hideStash || LootBase.instance.isActiveLoot)
StashSystem.instance.GetUpdateAssistent().UpdateIconTextBackpack();
InventoryBase.instance.isDragHandlerIcon = false;
InventoryBase.instance.CL = null;
//
// Определяем, нужно ли нам удалять префаб ItemDrop для предмета
//
bool flagLoot = false;
if (isStashSlot && itemDragged != BackpackItemDragged.STORE)
{
if (transform.parent == startParent) // Предмет остался в луте
flagLoot = false;
else
flagLoot = true;
}
//
//
//
if (!BackpackSystem.instance.RE4O_IsActive())
PlayerSystem.instance.UpdateSlots(CL, flagLoot); // If it was a player's slot then you need to update all the slots
}
//
// Для сброса цвета активного оружия
//
private void ResetBackgroundColor()
{
if (!BackpackSystem.instance.RE4O_IsActive())
{
if (CL != null && gameObject != null)
{
gameObject.GetComponentInChildren<ButtonOptions>().ResetBaseColor();
}
}
}
private void ResetDragAndDrop()
{
if (itemIcon.GetComponentInParent<PlayerInventorySlot>())
{
if (itemIcon.GetComponentInParent<PlayerInventorySlot>().IsPlayerSlot)
{
if (InventoryBase.instance.m_Hotbar.isActiveHotbar)
InventoryBase.instance.m_Hotbar.UpdateHotbarOnDragAndDrop(CL); // Update hotbar
PlayerSystem.instance.UpdatePosition();
isPlayerSlot = true;
}
else
{
isPlayerSlot = false;
ResetBackgroundColor();
}
}
if (isPlayerSlot)
{
if (MouseEnterEnemyPlayerSlots.instance && MouseEnterEnemyPlayerSlots.instance.isActive)
CL.isEnemyItem = true;
else
CL.isEnemyItem = false;
ResetBackgroundColor();
}
if (isEnemy)
{
PlayerEnemySystem.instance.isActiveUpdateSlots = true;
BackpackEnemyBase.instance.isActiveUpdateSlots = true;
isEnemy = false;
ResetBackgroundColor();
}
else
{
if (BackpackEnemyBase.instance && BackpackEnemyBase.instance.isActive) // *
{
PlayerEnemySystem.instance.isActiveUpdateSlots = true;
BackpackEnemyBase.instance.isActiveUpdateSlots = true;
}
}
if (itemIcon.GetComponentInParent<MouseEnterBackpack>() || itemIcon.GetComponentInParent<MouseEnterTacticalRigPocketsWindow>())
{
CL.isEnemyItem = false;
isTacticRigSlot = true;
}
else
isTacticRigSlot = false;
if (itemIcon.GetComponentInParent<MouseEnterEnemyBackpack>())
{
CL.isEnemyItem = true;
isTacticRigSlot = true;
}
if (itemIcon.GetComponentInParent<StoreInventorySlot>())
isStoreSlot = true;
else
isStoreSlot = false;
if (itemIcon.GetComponentInParent<MouseEnterBackpackSlot>() || itemIcon.GetComponentInParent<MouseEnterEnemyBackpackSlots>() || itemIcon.GetComponentInParent<MouseEnterBackpackWindow>())
{
isBackpackSlot = true;
isTacticRigSlot = false;
isPlayerSlot = false;
ResetBackgroundColor();
}
else
isBackpackSlot = false;
if (MouseInterStashInventory.instance && itemIcon.GetComponentInParent<MouseInterStashInventory>())
isStashSlot = true;
else
isStashSlot = false;
if (isChangeEnemyItemRoot)
{
//
// Проверка куда мы кинули (туда и спавним предмет)
//
if (isTacticRigSlot)
CL.destroyItemDrop.transform.SetParent(InventoryBase.instance.inventoryEnemy.m_SpawnEnemyTacticalRigItems); // Tactical Rig \ Pockets items
else
CL.destroyItemDrop.transform.SetParent(InventoryBase.instance.inventoryEnemy.m_SpawnEnemyBackpackItems); // Backpack items
isChangeEnemyItemRoot = false;
}
isExchangeInventory = false;
isExchangePlayerSlot = false;
isPlayer = false;
canNotBeMoved = false;
isTagSize2x1 = false;
isActiveDrag = false;
isActive = false;
isRotatedIcon = false;
isPlayerBackpack = false;
isEnemyBackpack = false;
isBackpackItem = false;
isAttached = false;
m_vspBackpackWindow = null;
itemDragged = default;
if (itemIcon && itemIcon.transform.parent.GetComponent<PointEnterPlayerSlots>())
CL.isPutOn = true;
else
CL.isPutOn = false;
if (deleteVSP || isDeleteIcon)
{
Destroy(itemIcon);
CL.isPutOn = false;
}
itemIcon = null;
deleteVSP = false;
isDeleteIcon = false;
Helper.SetImageAlpha(icon.GetComponent<Image>(), 1.0f);
if (CL.storeID == -1)
gameObject.GetComponentInChildren<ButtonOptions>().SetTextParameters(CL);
else
gameObject.GetComponentInChildren<ButtonOptions>().SetTextParameters("", CL.statisticList.itemPrice.ToString(), 11, 10, CL.statisticList.GetTypeOfMoney());
if (InventoryBase.instance.m_Hotbar.isActiveHotbar)
{
// Update hotbar slot
InventoryBase.instance.m_Hotbar.UpdateHotbarPutOnSlots(CL);
InventoryBase.instance.m_Hotbar.isPutOn = false;
}
InventoryBase.instance.ResetSortingButton();
if (BackpackSystem.instance.RE4_spaceButtons != null)
{
for (int i = 0; i < BackpackSystem.instance.RE4_spaceButtons.Length; i++)
if (BackpackSystem.instance.RE4_spaceButtons[i] != null)
BackpackSystem.instance.RE4_spaceButtons[i].SetActive(false);
}
}
private void CloseAllOpendBackpackWindows()
{
if (CL.tagItem == ItemList.TagItems.BODYBACKPACK && CL.isPutOn) // Если это рюкзак и он надет
{
if (BackpackSystem.instance.CheckOpenedBackpackWindow(CL))
BackpackSystem.instance.CloseBackpackWindowSlotForOpenedBackpack(CL);
}
}
#endregion
#endregion
}
}
}