Example #1
0
    void HUD::onWorldClicked(MyGUI::Widget* _sender)
    {
        if (!MWBase::Environment::get().getWindowManager ()->isGuiMode ())
            return;

        if (mDragAndDrop->mIsOnDragAndDrop)
        {
            // drop item into the gameworld
            MWWorld::Ptr object = mDragAndDrop->mItem.mBase;

            MWBase::World* world = MWBase::Environment::get().getWorld();

            MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
            MyGUI::IntPoint cursorPosition = MyGUI::InputManager::getInstance().getMousePosition();
            float mouseX = cursorPosition.left / float(viewSize.width);
            float mouseY = cursorPosition.top / float(viewSize.height);

            int origCount = object.getRefData().getCount();
            object.getRefData().setCount(mDragAndDrop->mDraggedCount);

            if (world->canPlaceObject(mouseX, mouseY))
                world->placeObject(object, mouseX, mouseY);
            else
                world->dropObjectOnGround(world->getPlayer().getPlayer(), object);

            MWBase::Environment::get().getWindowManager()->changePointer("arrow");

            std::string sound = MWWorld::Class::get(object).getDownSoundId(object);
            MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);

            object.getRefData().setCount(origCount);

            // remove object from the container it was coming from
            mDragAndDrop->mSourceModel->removeItem(mDragAndDrop->mItem, mDragAndDrop->mDraggedCount);
            mDragAndDrop->finish();
        }
        else
        {
            GuiMode mode = MWBase::Environment::get().getWindowManager()->getMode();

            if ( (mode != GM_Console) && (mode != GM_Container) && (mode != GM_Inventory) )
                return;

            MWWorld::Ptr object = MWBase::Environment::get().getWorld()->getFacedObject();

            if (mode == GM_Console)
                MWBase::Environment::get().getWindowManager()->getConsole()->setSelectedObject(object);
            else if ((mode == GM_Container) || (mode == GM_Inventory))
            {
                // pick up object
                MWBase::Environment::get().getWindowManager()->getInventoryWindow()->pickUpObject(object);
            }
        }
    }
Example #2
0
        virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false)
        {
            MWBase::World* world = MWBase::Environment::get().getWorld();

            MWWorld::Ptr dropped;
            if (world->canPlaceObject(mLeft, mTop))
                dropped = world->placeObject(item.mBase, mLeft, mTop, count);
            else
                dropped = world->dropObjectOnGround(world->getPlayerPtr(), item.mBase, count);
            if (setNewOwner)
                dropped.getCellRef().setOwner("");

            return dropped;
        }
Example #3
0
void HUD::onWorldClicked(MyGUI::Widget* _sender)
{
    if (!MWBase::Environment::get().getWindowManager ()->isGuiMode ())
        return;

    if (mDragAndDrop->mIsOnDragAndDrop)
    {
        // drop item into the gameworld
        MWWorld::Ptr object = *mDragAndDrop->mDraggedWidget->getUserData<MWWorld::Ptr>();

        MWBase::World* world = MWBase::Environment::get().getWorld();

        MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
        MyGUI::IntPoint cursorPosition = MyGUI::InputManager::getInstance().getMousePosition();
        float mouseX = cursorPosition.left / float(viewSize.width);
        float mouseY = cursorPosition.top / float(viewSize.height);

        int origCount = object.getRefData().getCount();
        object.getRefData().setCount(mDragAndDrop->mDraggedCount);

        if (world->canPlaceObject(mouseX, mouseY))
            world->placeObject(object, mouseX, mouseY);
        else
            world->dropObjectOnGround(object);

        MyGUI::PointerManager::getInstance().setPointer("arrow");

        std::string sound = MWWorld::Class::get(object).getDownSoundId(object);
        MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);

        // remove object from the container it was coming from
        object.getRefData().setCount(origCount - mDragAndDrop->mDraggedCount);

        mDragAndDrop->mIsOnDragAndDrop = false;
        MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget);
        mDragAndDrop->mDraggedWidget = 0;

        MWBase::Environment::get().getWindowManager()->setDragDrop(false);
        MWBase::Environment::get().getWindowManager()->getInventoryWindow()->drawItems();
    }
    else
    {
        GuiMode mode = MWBase::Environment::get().getWindowManager()->getMode();

        if ( (mode != GM_Console) && (mode != GM_Container) && (mode != GM_Inventory) )
            return;

        std::string handle = MWBase::Environment::get().getWorld()->getFacedHandle();
        MWWorld::Ptr object;
        try
        {
            object = MWBase::Environment::get().getWorld()->getPtrViaHandle(handle);
        }
        catch (std::exception& /* e */)
        {
            return;
        }

        if (mode == GM_Console)
            MWBase::Environment::get().getWindowManager()->getConsole()->setSelectedObject(object);
        else if ((mode == GM_Container) || (mode == GM_Inventory))
        {
            // pick up object
            MWBase::Environment::get().getWindowManager()->getInventoryWindow()->pickUpObject(object);
        }
    }
}