Exemple #1
0
void DragAndDrop::startDrag (int index, SortFilterItemModel* sortModel, ItemModel* sourceModel, ItemView* sourceView, int count)
{
    mItem = sourceModel->getItem(index);
    mDraggedCount = count;
    mSourceModel = sourceModel;
    mSourceView = sourceView;
    mSourceSortModel = sortModel;
    mIsOnDragAndDrop = true;

    // If picking up an item that isn't from the player's inventory, the item gets added to player inventory backend
    // immediately, even though it's still floating beneath the mouse cursor. A bit counterintuitive,
    // but this is how it works in vanilla, and not doing so would break quests (BM_beasts for instance).
    ItemModel* playerModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getModel();
    if (mSourceModel != playerModel)
    {
        MWWorld::Ptr item = mSourceModel->moveItem(mItem, mDraggedCount, playerModel);

        playerModel->update();

        ItemModel::ModelIndex newIndex = -1;
        for (unsigned int i=0; i<playerModel->getItemCount(); ++i)
        {
            if (playerModel->getItem(i).mBase == item)
            {
                newIndex = i;
                break;
            }
        }
        mItem = playerModel->getItem(newIndex);
        mSourceModel = playerModel;

        SortFilterItemModel* playerFilterModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getSortFilterModel();
        mSourceSortModel = playerFilterModel;
    }

    std::string sound = mItem.mBase.getClass().getUpSoundId(mItem.mBase);
    MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);

    if (mSourceSortModel)
    {
        mSourceSortModel->clearDragItems();
        mSourceSortModel->addDragItem(mItem.mBase, count);
    }

    ItemWidget* baseWidget = MyGUI::Gui::getInstance().createWidget<ItemWidget>("MW_ItemIcon", 0, 0, 42, 42, MyGUI::Align::Default, "DragAndDrop");

    Controllers::ControllerFollowMouse* controller =
            MyGUI::ControllerManager::getInstance().createItem(Controllers::ControllerFollowMouse::getClassTypeName())
            ->castType<Controllers::ControllerFollowMouse>();
    MyGUI::ControllerManager::getInstance().addItem(baseWidget, controller);

    mDraggedWidget = baseWidget;
    baseWidget->setItem(mItem.mBase);
    baseWidget->setNeedMouseFocus(false);
    baseWidget->setCount(count);

    sourceView->update();

    MWBase::Environment::get().getWindowManager()->setDragDrop(true);
}
//----------------------------------------------------------------------------//
bool TreeViewItemRenderingState::operator>(const TreeViewItemRenderingState& other) const
{
    ItemModel* model = d_attachedTreeView->getModel();

    return model->compareIndices(
        model->makeIndex(d_childId, d_parentIndex),
        model->makeIndex(other.d_childId, other.d_parentIndex)
        ) > 0;
}
bool GameLayerMapBorder::init()
{
    GameLayerBase::init();
    setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
     _mapGrid = nullptr;    
    _quads = nullptr;
    GameLayerMapBorder::initQuadMap();
   // if(!_itemBorderLine) = new ItemModel();
    static ItemModel itemline;
    itemline.setType(TypeBorderLine);
    _itemBorderLine =&itemline;
   // _itemBorderLine->setType(111);
    return true;
}
Exemple #4
0
void PhysicsHandler::dealCollisions()
{
    std::set<ItemModel*> _toDealWith;
    
    std::set<MyContact>::iterator it;
    ItemModel* item;
    ItemModel* plantHead;
    for (it = _contacts.begin(); it!= _contacts.end(); it++) {
        item = (ItemModel*)(it->first->GetBody()->GetUserData());
        plantHead = (ItemModel*)it->second->GetBody()->GetUserData();
        //
        bool exchange = false;
        if (!item->isNeedCallBackType()) {
            plantHead = item;
            item = (ItemModel*)it->second->GetBody()->GetUserData();
            exchange = true;
        }
        //
        if (item->_type == DoubDragon_Anti || item->_type == DoubDragon_Clockwise) {
            if (!exchange) {
                if(it->first->GetDensity() == 1.0){
                    ((DoubleDragon*)item)->setCollisionSign(1);
                }else{
                    ((DoubleDragon*)item)->setCollisionSign(-1);
                }
            }else{
                if (it->second->GetDensity() == 1.0) {
                    ((DoubleDragon*)item)->setCollisionSign(1);
                }else{
                    ((DoubleDragon*)item)->setCollisionSign(-1);
                }
            }
        }
        
        
        _toDealWith.insert(item);
    }
    
    for (ItemModel* itemModel : _toDealWith) {
        itemModel->_collisionCallBack(plantHead);
    }
    
}
Exemple #5
0
    void TradeItemModel::transferItems()
    {
        std::vector<ItemStack>::iterator it = mBorrowedToUs.begin();
        for (; it != mBorrowedToUs.end(); ++it)
        {
            // get index in the source model
            ItemModel* sourceModel = it->mCreator;
            size_t i=0;
            for (; i<sourceModel->getItemCount(); ++i)
            {
                if (it->mBase == sourceModel->getItem(i).mBase)
                    break;
            }
            if (i == sourceModel->getItemCount())
                throw std::runtime_error("The borrowed item disappeared");

            const ItemStack& item = sourceModel->getItem(i);
            // copy the borrowed items to our model
            copyItem(item, it->mCount);
            // then remove them from the source model
            sourceModel->removeItem(item, it->mCount);
        }
        mBorrowedToUs.clear();
        mBorrowedFromUs.clear();
    }
Exemple #6
0
    void TradeItemModel::transferItems()
    {
        std::vector<ItemStack>::iterator it = mBorrowedToUs.begin();
        for (; it != mBorrowedToUs.end(); ++it)
        {
            // get index in the source model
            ItemModel* sourceModel = it->mCreator;
            size_t i=0;
            for (; i<sourceModel->getItemCount(); ++i)
            {
                if (it->mBase == sourceModel->getItem(i).mBase)
                    break;
            }
            if (i == sourceModel->getItemCount())
                throw std::runtime_error("The borrowed item disappeared");

            // reset owner while copying, but only for items bought by the player
            bool setNewOwner = (mMerchant.isEmpty());
            const ItemStack& item = sourceModel->getItem(i);
            // copy the borrowed items to our model
            copyItem(item, it->mCount, setNewOwner);
            // then remove them from the source model
            sourceModel->removeItem(item, it->mCount);
        }
        mBorrowedToUs.clear();
        mBorrowedFromUs.clear();
    }
Exemple #7
0
    void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender)
    {
        if(mDragAndDrop == NULL || !mDragAndDrop->mIsOnDragAndDrop)
        {
            // transfer everything into the player's inventory
            ItemModel* playerModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getModel();
            mModel->update();
            for (size_t i=0; i<mModel->getItemCount(); ++i)
            {
                if (i==0)
                {
                    // play the sound of the first object
                    MWWorld::Ptr item = mModel->getItem(i).mBase;
                    std::string sound = MWWorld::Class::get(item).getUpSoundId(item);
                    MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
                }

                playerModel->copyItem(mModel->getItem(i), mModel->getItem(i).mCount);
                mModel->removeItem(mModel->getItem(i), mModel->getItem(i).mCount);
            }

            MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Container);
        }
    }