Esempio n. 1
0
void psSlotManager::Handle( pawsSlot* slot, bool grabOne, bool grabAll )
{
    //printf("In psSlotManager::Handle()\n");

    if ( !isDragging )
    {
        // Make sure other code isn't drag-and-dropping a different object.
        pawsWidget *dndWidget = PawsManager::GetSingleton().GetDragDropWidget();
        if (dndWidget)
            return; 

        //printf("Starting a drag/drop action\n");

        int stackCount = slot->StackCount();
        if ( stackCount > 0 )
        {          
            int tmpID = (int)slotsInUse.Push(slot);

            if ( stackCount == 1 || grabOne )
            {
                OnNumberEntered("StackCount",tmpID, 1);
            }
            else if ( grabAll )
            {
                OnNumberEntered("StackCount",tmpID, stackCount);
            }
            else // Ask for the number of items to grab
            {
                csString max;
                max.Format("Max %d", stackCount );
                
                pawsNumberPromptWindow::Create(max,
                                               -1, 1, stackCount, this, "StackCount", tmpID);
            }
        }
    }
    else
    {
        //printf("Sending slot movement message\n");
        psSlotMovementMsg msg( draggingSlot.containerID, draggingSlot.slotID,
                               slot->ContainerID(), slot->ID(),
                               draggingSlot.stackCount );
        msg.SendMessage();

        // Reset widgets/objects/status.
        PawsManager::GetSingleton().SetDragDropWidget( NULL );
        isDragging = false;
        if(isPlacing)
        {
            psengine->GetSceneManipulator()->RemoveSelected();
            isPlacing = false;
            isRotating = false;
        }
    }    
}
void psSlotManager::Handle( pawsSlot* slot, bool grabOne, bool grabAll )
{
    if ( !isDragging )
    {
        // Make sure other code isn't drag-and-dropping a different object.
        pawsWidget *dndWidget = PawsManager::GetSingleton().GetDragDropWidget();
        if (dndWidget)
            return;

        if( !slot->GetLock() ){
            int stackCount = slot->StackCount();
            if ( stackCount > 0 )
            {
                int tmpID = (int)slotsInUse.Push(slot);

                if ( stackCount == 1 || grabOne )
                {
                    int old_count = last_count;
                    OnNumberEntered("StackCount",tmpID, 1);
                    last_count = old_count;
                }
                else if ( grabAll )
                {
                    int old_count = last_count;
                    OnNumberEntered("StackCount",tmpID, stackCount);
                    last_count = old_count;
                }
                else // Ask for the number of items to grab
                {
                    csString max;
                    max.Format("Max %d", stackCount );

                    pawsNumberPromptWindow::Create(max, last_count,
                                                   1, stackCount, this, "StackCount", tmpID);
                }
            }
        }
    }
    else
    {
        // Do nothing if it's the same slot and we aren't dropping a split stack.
        // Note that crafters use this to pick up one item from a stack,
        // drop it on the stack, and have the server put the item in a
        // different slot.
        if(slot == draggingSlot.slot && !draggingSlot.split)
        {
            CancelDrag();
            return;
        }
        if( !slot->GetLock() )
        {
            //printf("Slot->ID: %d\n", slot->ID() );
            //printf("Container: %d\n", slot->ContainerID() );
            //printf("DraggingSlot.ID %d\n", draggingSlot.slotID);
            

            if ( draggingSlot.containerID == CONTAINER_SPELL_BOOK )
            {
                // Stop dragging the spell around
                CancelDrag();

                // Set the image to this slot.
                slot->PlaceItem( ((pawsSlot *)draggingSlot.slot)->ImageName(), "", "", draggingSlot.stackCount);
            }
            else
            {
                psSlotMovementMsg msg( draggingSlot.containerID, draggingSlot.slotID,
                               slot->ContainerID(), slot->ID(),
                               draggingSlot.stackCount );
                msg.SendMessage();

                // Reset widgets/objects/status.
                PawsManager::GetSingleton().SetDragDropWidget( NULL );
                isDragging = false;
                if(isPlacing)
                {
                    psengine->GetSceneManipulator()->RemoveSelected();
                    if(hadInventory)
                    {
                        PawsManager::GetSingleton().GetMainWidget()->FindWidget("InventoryWindow")->Show();
                    }
                    isPlacing = false;
                    isRotating = false;
                    hadInventory = false;
                }
            }
        }
    }
}