inline void reset( const char* const* _items, int _itemLen, char _sep, const char* _states, int _defaultState )
    {
        /// save previous selection state
        std::string states;
        if ( _states ) {
            states = std::string( _states );
        }
        /// clear
        clear();

        /// reset
        if ( widget_ && _items && _itemLen > 0 ) {

            widget_->setSuspendUpdate( true );

            widget_->itemIndices().reserve( _itemLen );

            int stateLen( static_cast< int >( states.size() ) );
            QTreeWidgetItem* parent = NULL;
            std::string fullPath;

            for ( int idx( 0 ); idx < _itemLen; ++idx ) {
                parent = NULL;
                fullPath.clear();

                /// this variable denotes the item state, also considers the
                /// parent nodes
                bool itemState( true );

                QStringList tokens;
                if ( _sep != '\0' ) {
                    tokens = QStringList( QString::fromStdString( _items[ idx ] ).split( _sep, QString::SkipEmptyParts) );
                } else {
                    tokens = QStringList( QString::fromStdString( _items[ idx ] ) );
                }

                for ( int tokenIdx( 0 ); tokenIdx < tokens.size(); ++tokenIdx ) {
                    QString itemStr( tokens.at( tokenIdx ) );

                    if ( !parent ) {
                        parent = createWidgetItem( widget_, widget_, itemStr, fullPath, stateLen, states, _defaultState );
                    } else {
                        parent = createWidgetItem( parent, parent->child( 0 ), itemStr, fullPath, stateLen, states, _defaultState );
                    }

                    if ( parent && itemState && ! parent->checkState( 0 ) ) {
                        itemState = false;
                    }

                    fullPath = fullPath + "/" + itemStr.toStdString();
                }
                widget_->itemIndices().append( QPair< QString, QTreeWidgetItem* >( fullPath.c_str(), parent ) );
                itemStatesStr_.push_back( itemState ? '1' : '0' );
            }
            widget_->expandAll();

            widget_->setSuspendUpdate( false );
        }
    }
Ejemplo n.º 2
0
int AdlEngine_v2::o2_placeItem(ScriptEnv &e) {
	OP_DEBUG_4("\tPLACE_ITEM(%s, %s, (%d, %d))", itemStr(e.arg(1)).c_str(), itemRoomStr(e.arg(2)).c_str(), e.arg(3), e.arg(4));

	Item &item = getItem(e.arg(1));

	item.room = roomArg(e.arg(2));
	item.position.x = e.arg(3);
	item.position.y = e.arg(4);
	item.state = IDI_ITEM_NOT_MOVED;

	return 4;
}
Ejemplo n.º 3
0
int AdlEngine_v2::o2_moveItem(ScriptEnv &e) {
	OP_DEBUG_2("\tSET_ITEM_ROOM(%s, %s)", itemStr(e.arg(1)).c_str(), itemRoomStr(e.arg(2)).c_str());

	byte room = roomArg(e.arg(2));

	Item &item = getItem(e.arg(1));

	if (item.room == _roomOnScreen)
		_picOnScreen = 0;

	// Set items that move from inventory to a room to state "dropped"
	if (item.room == IDI_ANY && room != IDI_VOID_ROOM)
		item.state = IDI_ITEM_DROPPED;

	item.room = room;
	return 2;
}