Example #1
0
 public ItemSlotData(UiItem uiItem, SlotTypes slotType, Transform physicalItemLocation, InventoryUi inventoryUi)
 {
     this.uiItem               = uiItem;
     this.slotType             = slotType;
     this.physicalItemLocation = physicalItemLocation;
     this.inventoryUi          = inventoryUi;
 }
Example #2
0
    public void Initialize(ItemSlotData data, InventoryUi ui)
    {
        inventoryUi = ui;
//        uiItem = data.uiItem;
//        slotType = data.slotType;
//        physicalItemLocation = data.physicalItemLocation;
//        humanInventoryUi = data.inventoryUi;
    }
Example #3
0
    private void Start()
    {
        if (!inventoryUi)
        {
            inventoryUi = GetComponentInParent <InventoryUi>();
        }
//        humanInventoryUi = GetComponentInParent<HumanInventoryUI>();
    }
 public override void OnInitialise(Player parent)
 {
     //Hide the cursor.
     Cursor.visible = false;
     //Get the inventory
     inventoryUi = Object.FindObjectOfType <InventoryUi>();
     //Get the hotbar
     hotbarParent = Object.FindObjectOfType <Hotbar>();
     //Find the cursor object
     cursorObject = GameObject.FindGameObjectWithTag("Cursor");
 }
Example #5
0
    public ArmorSystem(InventoryUi InventroyUi, PlayerUI playerUi, Action <int> updateFunc)
    {
        this.inventoryUi = InventroyUi;
        this.playerUi    = playerUi;
        this.updateFunc  = updateFunc;

        remainArmor = 0;
        maxArmor    = -1;

        UpdateArmorUi();
    }
    public void UpdateInventoryIcon(int index)
    {
        InventoryUi inventoryUi = Object.FindObjectOfType <InventoryUi>();

        //TODO: Caching
        if (inventory[index] != null)
        {
            inventoryUi.GetComponentsInChildren <Image>()[index * 2 + 1].sprite = Resources.Load <Sprite>($"Icons/{inventory[index].iconName}");
        }
        else
        {
            inventoryUi.GetComponentsInChildren <Image>()[index * 2 + 1].sprite = Resources.Load <Sprite>($"Icons/icon_blank");
        }
    }
Example #7
0
 public Inventory(InventoryUi inventoryUi)
 {
     this.inventoryUi = inventoryUi;
     this.inventoryUi.LinkAllItemList(allItemList);
 }
    public override void OnUpdate(Player parent)
    {
        //Get button
        if (Input.GetButtonDown("inventory"))
        {
            //Update the inventory open
            inventoryOpen = !inventoryOpen;
            //Set lockstate
            Cursor.lockState = inventoryOpen ? CursorLockMode.None : CursorLockMode.Locked;
            //Update inventory
            inventoryUi.SetOpen(inventoryOpen);
            //Put the cursor in the center of the screen.
            cursorObject.transform.localPosition = Vector3.zero;
        }
        //Update hotbar
        //TODO: Have this in controls or something
        if (Input.mouseScrollDelta.y > 0.2f)
        {
            parent.inventory.IncreaseHotbarIndex(hotbarParent);
        }
        else if (Input.mouseScrollDelta.y < -0.2f)
        {
            parent.inventory.DecreaseHotbarIndex(hotbarParent);
        }

        //Hotbar buttons
        HandleHotbarButtons(parent);

        //Update cursor
        if (!inventoryOpen)
        {
            return;
        }

        //Set the position of the cursor object
        cursorObject.transform.position = Input.mousePosition;

        //Perform actions!
        //ACTION PRIORITY:
        // - Dropdown menu handling
        // - Handling Drag Actions

        //===== Dropdown Handling =====
        //Open the dropdown menu
        if (Input.GetMouseButtonDown(1))
        {
            //Get the pointer position
            Vector3 pointerPosition = Input.mousePosition;
            //Find the index of what we are over
            int index = InventoryUi.CursorPositionToIndex(pointerPosition.x, pointerPosition.y);
            //Check if something is even there
            if (index != -1 && parent.inventory.inventory[index] != null)
            {
                inventoryUi.OpenDropdownMenu(parent.inventory.inventory[index].GetInteractionOptions());

                /*inventoryUi.OpenDropdownMenu(new DropdownOption[] {
                 *  new DropdownOption("Use", null),
                 *  new DropdownOption("Equip", null),
                 *  new DropdownOption("Examine", null),
                 *  new DropdownOption("Drop", null),
                 * });*/
            }
        }

        //Ignore any other actions
        if (inventoryUi.currentlyOpenDropdown)
        {
            if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(1))
            {
                //Select the current button option
                DropdownButton.hoveredButton?.OnClick();
                //Close the dropdown
                inventoryUi.CloseDropdownMenu();
            }
            return;
        }

        //===== Drag Handling =====
        //Todo: Dragging from the hotbar too
        if (Input.GetMouseButtonDown(0) && !isDragging)
        {
            //Get the pointer position
            Vector3 pointerPosition = Input.mousePosition;
            //Find the index of what we are over
            int index = InventoryUi.CursorPositionToIndex(pointerPosition.x, pointerPosition.y);
            //Check if something is even there
            if (index != -1 && parent.inventory.inventory[index] != null)
            {
                //Find the image we are dragging
                draggingImage             = inventoryUi.GetComponentsInChildren <Image>()[index * 2 + 1];
                startingDragImagePosition = draggingImage.transform.localPosition;
                dragStartIndex            = index;
                //Begin dragging
                isDragging = true;
            }
        }
        //If Dragging
        if (isDragging)
        {
            draggingImage.transform.position = Input.mousePosition;
        }
        //End Dragging
        if (Input.GetMouseButtonUp(0) && isDragging)
        {
            //Reset the image
            draggingImage.transform.localPosition = startingDragImagePosition;
            draggingImage = null;
            isDragging    = false;
            //Apply effects of the drag
            //Get the pointer position
            Vector3 pointerPosition = Input.mousePosition;
            //Find the index of what we are over
            int index = InventoryUi.CursorPositionToIndex(pointerPosition.x, pointerPosition.y);
            if (index != -1 && parent.inventory.inventory[index] == null)
            {
                parent.inventory.SwapInventoryIndexes(dragStartIndex, index);
            }
            else
            {
                //Check for putting into the hotbar
                int hotbarRequest = InventoryUi.CursorPositionToHotbarIndex(hotbarParent, pointerPosition.x, pointerPosition.y);
                if (hotbarRequest != -1)
                {
                    Log.PrintDebug($"{hotbarRequest}");
                    parent.inventory.InsertIntoHotbar(hotbarRequest, dragStartIndex);
                }
                else
                {
                    //Dragged onto blank space, assume user wants to drop the item.
                    parent.inventory.DropItemAtIndex(dragStartIndex);
                }
            }
        }
    }
 //initialise instance of this
 void Awake()
 {
     instance = this;
 }
 public void SetInventoryUi(InventoryUi inventoryUi)
 {
     _inventoryUi = inventoryUi;
 }
Example #11
0
 public void LinkInventoryUi(InventoryUi inventoryUi)
 {
     this.inventoryUi = inventoryUi;
 }