Exemple #1
0
    //--------------------------------------------------------------------------------------
    // OnPointerDown: Called by the EventSystem when a PointerDown event occurs.
    //
    // Param:
    //      eventData: Current event data.
    //--------------------------------------------------------------------------------------
    public void OnPointerDown(PointerEventData eventData)
    {
        // get the currently selected stack
        ItemStack oCurrentSelectedStack = m_gInventoryManger.GetSelectedStack();

        // make a copy of the current stack
        ItemStack oCurrentStackCopy = m_oCurrentStack.CopyStack();

        // if the mouse is left click
        if (eventData.pointerId == -1)
        {
            // run the left click method
            OnLeftClick(oCurrentSelectedStack, oCurrentStackCopy);
        }

        // if the mouse is right click
        if (eventData.pointerId == -2)
        {
            // run the right click method
            OnRightClick(oCurrentSelectedStack, oCurrentStackCopy);
        }

        // if the mouse is middle clicked
        if (eventData.pointerId == -3 && !m_gInventoryManger.m_bHasHotbar)
        {
            // run the middle click method
            OnMiddleClick(oCurrentSelectedStack, oCurrentStackCopy);
        }
    }
Exemple #2
0
    //--------------------------------------------------------------------------------------
    // OnRightClick: What the item slot will do on a right click.
    //
    // Param:
    //      oCurrentSelectedStack: an ItemStack of the current stack.
    //      oCurrentStackCopy: and ItemStack of the copy of the item stack.
    //--------------------------------------------------------------------------------------
    private void OnRightClick(ItemStack oCurrentSelectedStack, ItemStack oCurrentStackCopy)
    {
        // if the current stack is not empty and the selected stack is empty
        if (!m_oCurrentStack.IsStackEmpty() && oCurrentSelectedStack.IsStackEmpty())
        {
            // split the current stack in half
            ItemStack oSplitStack = oCurrentStackCopy.SplitStack(oCurrentStackCopy.GetItemCount() / 2);

            // set the currently selected stack to the split stack.
            m_gInventoryManger.SetSelectedStack(oSplitStack);

            // set the contentto the copy of the current stack.
            SetSlotContent(oCurrentStackCopy);

            // deactivate the tooltip
            SetTooltip(string.Empty);
        }

        // if the current stack is empty and the selected stack is not empty
        if (m_oCurrentStack.IsStackEmpty() && !oCurrentSelectedStack.IsStackEmpty())
        {
            // Set the slot content of a new item stack
            SetSlotContent(new ItemStack(oCurrentSelectedStack.GetItem(), 1));

            // get a copy of the currently selected stack
            ItemStack oCurrentSelectedStackCopy = oCurrentSelectedStack.CopyStack();

            // decrease the currently selected count by 1
            oCurrentSelectedStackCopy.DecreaseStack(1);

            // set the currently selected stack in the manager to this one
            m_gInventoryManger.SetSelectedStack(oCurrentSelectedStackCopy);

            // deactivate the tooltip
            SetTooltip(string.Empty);
        }

        // if both current stack and selected stack are empty
        if (!m_oCurrentStack.IsStackEmpty() && !oCurrentSelectedStack.IsStackEmpty())
        {
            // if the items stacks are equal
            if (ItemStack.AreItemsEqual(oCurrentStackCopy, oCurrentSelectedStack))
            {
                // if the current stack has room to add one item
                if (m_oCurrentStack.IsItemAddable(1))
                {
                    // increase the count of the current stack
                    oCurrentStackCopy.IncreaseStack(1);

                    // set the content of the current slot
                    SetSlotContent(oCurrentStackCopy);

                    // get a copy of the currently selected stack
                    ItemStack oCurrentSelectedStackCopy = oCurrentSelectedStack.CopyStack();

                    // decrease the count
                    oCurrentSelectedStackCopy.DecreaseStack(1);

                    // set the currently selected stack in the manager to this new one
                    m_gInventoryManger.SetSelectedStack(oCurrentSelectedStackCopy);

                    // deactivate the tooltip
                    SetTooltip(string.Empty);
                }
            }
        }
    }
Exemple #3
0
    //--------------------------------------------------------------------------------------
    // OnLeftClick: What the item slot will do on a left click.
    //
    // Param:
    //      oCurrentSelectedStack: an ItemStack of the currently slected stack.
    //      oCurrentStackCopy: and ItemStack of the copy of the item stack.
    //--------------------------------------------------------------------------------------
    private void OnLeftClick(ItemStack oCurrentSelectedStack, ItemStack oCurrentStackCopy)
    {
        // if the current stack is not empty and the selected stack is empty
        if (!m_oCurrentStack.IsStackEmpty() && oCurrentSelectedStack.IsStackEmpty())
        {
            // set the selected stack to the current stack copy
            m_gInventoryManger.SetSelectedStack(oCurrentStackCopy);

            // Set the slot content to empty
            SetSlotContent(ItemStack.m_oEmpty);

            // deactivate the tooltip
            SetTooltip(string.Empty);
        }

        // if the current stack is empty and the selected stack is not empty
        if (m_oCurrentStack.IsStackEmpty() && !oCurrentSelectedStack.IsStackEmpty())
        {
            // Set the slot content to the current selected stack
            SetSlotContent(oCurrentSelectedStack);

            // set the current selected stack to empty
            m_gInventoryManger.SetSelectedStack(ItemStack.m_oEmpty);

            // activate the tooltip
            SetTooltip(m_oCurrentStack.GetItem().m_strTitle);
        }

        // if both current stack and selected stack are empty
        if (!m_oCurrentStack.IsStackEmpty() && !oCurrentSelectedStack.IsStackEmpty())
        {
            // are the stacks equal
            if (ItemStack.AreItemsEqual(oCurrentStackCopy, oCurrentSelectedStack))
            {
                // Can you add to the stack copy
                if (oCurrentStackCopy.IsItemAddable(oCurrentSelectedStack.GetItemCount()))
                {
                    // increase the current stack copy count by the selected stack count
                    oCurrentStackCopy.IncreaseStack(oCurrentSelectedStack.GetItemCount());

                    // set the slot conent to the current stack copy
                    SetSlotContent(oCurrentStackCopy);

                    // set the currently selected stack to empty
                    m_gInventoryManger.SetSelectedStack(ItemStack.m_oEmpty);

                    // activate the tooltip
                    SetTooltip(m_oCurrentStack.GetItem().m_strTitle);
                }

                // else if the item is not addable
                else
                {
                    // new int var, get the difference between current copied stak and currently selected stack
                    int nDifference = (oCurrentStackCopy.GetItemCount() + oCurrentSelectedStack.GetItemCount()) - oCurrentStackCopy.GetItem().m_nMaxStackSize;

                    // set the current copy stack count to the max stack size of the stacks item
                    oCurrentStackCopy.SetItemCount(m_oCurrentStack.GetItem().m_nMaxStackSize);

                    // get a copy of the currently selected stack
                    ItemStack oCurrentSelectedStackCopy = oCurrentSelectedStack.CopyStack();

                    // set the count of the copied current selected stack to the differnce
                    oCurrentSelectedStackCopy.SetItemCount(nDifference);

                    // set the content of the stack to the current stack copy
                    SetSlotContent(oCurrentStackCopy);

                    // set the currently selected stack to the current selected stack copy
                    m_gInventoryManger.SetSelectedStack(oCurrentSelectedStackCopy);

                    // deactivate the tooltip
                    SetTooltip(string.Empty);
                }
            }

            // if the stacks arent equal
            else
            {
                // set the slot content to the currently selected stack
                SetSlotContent(oCurrentSelectedStack);

                // set the currently selected stack to the current selected stack copy
                m_gInventoryManger.SetSelectedStack(oCurrentStackCopy);

                // deactivate the tooltip
                SetTooltip(string.Empty);
            }
        }
    }