コード例 #1
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);
                }
            }
        }
    }