void CMapObjectManager::update(float dt)
{
	MapObject* array[1024] = {0};
	int len = 0;
	assert(m_Objects.size() < 1024);
	for ( MapObjectList::iterator itr = m_Objects.begin();itr != m_Objects.end(); )
	{
		MapObject* pObject = *itr;

		// 清理掉被标记为删除的,和没有地图的野对象
		if ( !pObject || pObject->GetDeleted() || !pObject->GetMap() )
		{
			CC_SAFE_RELEASE(pObject);
			itr = m_Objects.erase(itr);
			continue;
		}

		// 合法的对象加入新的列表
		array[len++] = pObject;
		pObject->retain();
		++itr;
	}

	// 对新列表按照遮挡关系排序
	//qsort(array,len,sizeof(MapObject*),(int (__cdecl *)(const void *,const void *))compare);
	sortZorder(array,len);
	
	for ( int i = 0;i<len;++i )
	{
		array[i]->setLocalZOrder(len-i);
		array[i]->update(dt);
		array[i]->release();
		array[i] = NULL;
	}
}
Esempio n. 2
0
QModelIndex MapObjectModel::parent(const QModelIndex &index) const
{
    MapObject *mapObject = toMapObject(index);
    if (mapObject)
        return this->index(mapObject->objectGroup());
    return QModelIndex();
}
Esempio n. 3
0
void SpawnDetailDoodadsCommand::redo()
{
    /*if(object)
        delete object; // crash
*/

    for(int i = 0; i < spawnData.count(); ++i)
    {
        QVector<QPair<QString, QVector3D>> resultData = spawnData[i];

        for(int j = 0; j < resultData.count(); ++j)
        {
            QPair<QString, QVector3D> pair = resultData[j];

            // todo rotation based on heightmap bounding boxes
            MapObject* object = new MapObject(world->getModelManager()->getModel(world->getModelManager()->getIndex(pair.first)));
            object->setTranslate(pair.second, false);
            object->setRotation(QVector3D(0.0f, 0.0f, 0.0f));
            object->setScale(QVector3D(1.0f, 1.0f, 1.0f));
            object->updateBoundingBox();

            objects.append(object);

            world->addObject(object);
        }
    }
}
Esempio n. 4
0
//private
void BodyCreator::m_Split(const MapObject& object, b2Body* body)
{
	//check object shapes is valid
	if (!m_CheckShape(const_cast<MapObject&>(object))) return;

	const Shape& points = object.PolyPoints();
	Shapes shapes;
	if (object.Convex())
		shapes = m_ProcessConvex(points);
	else
		shapes = m_ProcessConcave(points);

	for (auto& shape : shapes)
	{
		sf::Uint16 s = shape.size();

		if (s > b2_maxPolygonVertices)
		{
			//break into smaller and append
			Shapes moreShapes = m_ProcessConvex(shape);
			for (auto& anotherShape : moreShapes)
				m_CreateFixture(anotherShape, body);

			continue; //skip shape because it's too big
		}
		m_CreateFixture(shape, body);
	}
}
MapObject*	CMapObjectManager::SelectObject(float x,float y,MapObject* pExclude )
{
	MapObjectList objects;
	SelectObjects(x,y,objects);

	MapObject* pRet = NULL; 
	for ( size_t i = 0;i<objects.size();++i )
	{
		MapObject* pObject = objects[i];
		if ( pObject == pExclude || pObject->GetDeleted())
		{
			continue;
		}

		if ( !pRet )
		{
			pRet = pObject;
			continue;
		}

		if ( pRet->getZOrder() < pObject->getZOrder() )
		{
			pRet = pObject;
		}
	}

	return pRet;
}
Esempio n. 6
0
/**
 * Accepts dropping a single template into an object group
 */
void MapScene::dropEvent(QGraphicsSceneDragDropEvent *event)
{
    const QMimeData *mimeData = event->mimeData();

    ObjectGroup *objectGroup = dynamic_cast<ObjectGroup*>(mapDocument()->currentLayer());
    if (!objectGroup || !mimeData->hasFormat(QLatin1String(TEMPLATES_MIMETYPE)))
        return;

    QByteArray encodedData = mimeData->data(QLatin1String(TEMPLATES_MIMETYPE));
    QDataStream stream(&encodedData, QIODevice::ReadOnly);

    TemplateManager *templateManager = TemplateManager::instance();

    QString fileName;
    stream >> fileName;

    const ObjectTemplate *objectTemplate = templateManager->findObjectTemplate(fileName);
    if (!objectTemplate)
        return;

    MapObject *newMapObject = new MapObject();
    newMapObject->setObjectTemplate(objectTemplate);
    newMapObject->syncWithTemplate();
    newMapObject->setPosition(event->scenePos());

    auto addObjectCommand = new AddMapObject(mapDocument(),
                                             objectGroup,
                                             newMapObject);

    mapDocument()->undoStack()->push(addObjectCommand);

    mapDocument()->setSelectedObjects(QList<MapObject*>() << newMapObject);
}
int	CMapObjectManager::getObjectsInView(MapObjectType type,MapObjectList& objects)
{
	Rect rect;
	m_pMap->getViewRect(rect);

	float x = 0;
	float y = 0;

	for ( MapObjectList::iterator itr = m_Objects.begin();itr != m_Objects.end();++itr)
	{
		MapObject* pObject = *itr;
		if ( pObject && !pObject->GetDeleted() )
		{
			x = pObject->getPositionX();
			y = pObject->getPositionY();

			if ( rect.containsPoint(Point(x,y)) && pObject->GetType() == type )
			{
				objects.push_back(pObject);
			}
		}
	}

	return (int)objects.size();
}
Esempio n. 8
0
// EDIT
void MapLayer::Add(int number, int x, int y, int option, bool initial){
    if(number == 0) return;
    
    MapObject *obj = nullptr;
    
    if(number < 10){    // tile
        if(!initial && mapData[y][x] != 0){
            this->removeChildByTag(y*width+x);
        }
        mapData[y][x] = number;
    }
    else if(number < 100){  // obstacle
        for(MapObject *obstacle : obstacleList){
            MapObjectInfo info = obstacle->GetInfo();
            if(info.x == x && info.y == y)
                return;
        }
        if(number == 20){
            mapData[y][x] = 1;
            mapData[y+1][x] = 1;
        }
    }
    else{   // object
        for(MapObject *object : objectList){
            MapObjectInfo info = object->GetInfo();
            if(info.x == x && info.y == y)
                return;
        }
    }
    
    obj = MapObject::create(number, x, y, option);
    obj->setTag(y*width+x);
    this->addChild(obj);
}
Esempio n. 9
0
void CreateObjectTool::startNewMapObject(const QPointF &pos,
                                         ObjectGroup *objectGroup)
{
    Q_ASSERT(!mNewMapObjectItem);

    MapObject *newMapObject = new MapObject;
    newMapObject->setPosition(pos);

    if (mMode == CreatePolygon || mMode == CreatePolyline) {
        MapObject::Shape shape = mMode == CreatePolygon ? MapObject::Polygon
                                                        : MapObject::Polyline;
        QPolygonF polygon;
        polygon.append(QPointF());
        newMapObject->setPolygon(polygon);
        newMapObject->setShape(shape);

        polygon.append(QPointF()); // The last point is connected to the mouse
        mOverlayPolygonObject->setPolygon(polygon);
        mOverlayPolygonObject->setShape(shape);
        mOverlayPolygonObject->setPosition(pos);

        mOverlayPolygonItem = new MapObjectItem(mOverlayPolygonObject,
                                                mapDocument());
        mapScene()->addItem(mOverlayPolygonItem);
    }

    objectGroup->addObject(newMapObject);

    mNewMapObjectItem = new MapObjectItem(newMapObject, mapDocument());
    mapScene()->addItem(mNewMapObjectItem);
}
Esempio n. 10
0
MapObject* ObjectFactory::createMapObject(const char *idMapObject, b2World *world)
{
    MapObject* mapObject = NULL;
    
    mapObject = new MapObject();
    
    //sprite
    const char* nameSprite = (std::string( idMapObject) + std::string(".png")).c_str();
    
    CCSprite* sprite=CCSprite::createWithSpriteFrameName(nameSprite);
    
    //body
    b2BodyDef bodyDef;
    bodyDef.type = b2_staticBody;
    bodyDef.angle = ccpToAngle(ccp(0,0));
    
    b2Body *body = world->CreateBody(&bodyDef);
    
    gbox2d::GB2ShapeCache *sc =  gbox2d::GB2ShapeCache::sharedGB2ShapeCache();
    sc->addFixturesToBody(body, idMapObject);
    sprite->setAnchorPoint(sc->anchorPointForShape(idMapObject));
    
    mapObject->setSkin(body, sprite);
    mapObject->onCreate();
    
    return mapObject;
    
}
Esempio n. 11
0
void EditPolygonTool::splitSegments()
{
    if (mSelectedHandles.size() < 2)
        return;

    const PointIndexesByObject p = groupIndexesByObject(mSelectedHandles);
    QMapIterator<MapObject*, RangeSet<int> > i(p);

    QUndoStack *undoStack = mapDocument()->undoStack();
    bool macroStarted = false;

    while (i.hasNext()) {
        MapObject *object = i.next().key();
        const RangeSet<int> &indexRanges = i.value();

        const bool closed = object->shape() == MapObject::Polygon;
        QPolygonF oldPolygon = object->polygon();
        QPolygonF newPolygon = splitPolygonSegments(oldPolygon, indexRanges,
                                                    closed);

        if (newPolygon.size() > oldPolygon.size()) {
            if (!macroStarted) {
                undoStack->beginMacro(tr("Split Segments"));
                macroStarted = true;
            }

            undoStack->push(new ChangePolygon(mapDocument(), object,
                                              newPolygon,
                                              oldPolygon));
        }
    }

    if (macroStarted)
        undoStack->endMacro();
}
Esempio n. 12
0
void EditPolygonTool::startMoving()
{
    // Move only the clicked handle, if it was not part of the selection
    if (!mSelectedHandles.contains(mClickedHandle))
        setSelectedHandle(mClickedHandle);

    mMode = Moving;

    MapRenderer *renderer = mapDocument()->renderer();

    // Remember the current object positions
    mOldHandlePositions.clear();
    mOldPolygons.clear();
    mAlignPosition = renderer->screenToPixelCoords((*mSelectedHandles.begin())->pos());

    const auto &selectedHandles = mSelectedHandles;
    for (PointHandle *handle : selectedHandles) {
        const QPointF pos = renderer->screenToPixelCoords(handle->pos());
        mOldHandlePositions.append(handle->pos());
        if (pos.x() < mAlignPosition.x())
            mAlignPosition.setX(pos.x());
        if (pos.y() < mAlignPosition.y())
            mAlignPosition.setY(pos.y());

        MapObject *mapObject = handle->mapObject();
        if (!mOldPolygons.contains(mapObject))
            mOldPolygons.insert(mapObject, mapObject->polygon());
    }
}
Esempio n. 13
0
File: Map.cpp Progetto: pecore/LEFT
void Map::draw()
{
  MapObject * o = 0;
  foreach(MapObjectList, o, mMapObjects) {
    o->setAlpha(getOpacity(o->pos()));
    o->draw();
  }
MapObject* LevelObjectCreator::sCreateMapAnimations(int index, const char* spriteName)
{
	MapObject* object = new MapObject(spriteName, index, index * 2);				
	object->autorelease();

	return object;
}
Esempio n. 15
0
ObjectLayer::ObjectLayer(const QString &name, int x, int y, int w, int h) :
    Layer(name, x, y, w, h)
{
    QPixmap img(":/Images/coin_gold.png");
    MapObject *obj = new MapObject("test", "thing", QPoint(100, 100), img.size());
    obj->setImage(img);
    addObject(obj);
}
Esempio n. 16
0
void DialogueSupervisor::_UpdateEmote()
{
    MapObject *object = MapMode::CurrentInstance()->GetObjectSupervisor()->GetObject(_current_dialogue->GetLineSpeaker(_line_counter));
    if(!object || !object->HasEmote()) {
        _emote_triggered = true;
        _BeginLine();
    }
}
Esempio n. 17
0
void PointHandle::setPointPosition(const QPointF &pos)
{
    // TODO: It could be faster to update the polygon only once when changing
    // multiple points of the same polygon.
    MapObject *mapObject = mMapObjectItem->mapObject();
    QPolygonF polygon = mapObject->polygon();
    polygon[mPointIndex] = pos - mapObject->position();
    mMapObjectItem->setPolygon(polygon);
}
Esempio n. 18
0
// -----------------------------------------------------------------
// Name : displayObjects
// -----------------------------------------------------------------
void Map::displayObjects(PlayerManager * pPlayerMngr)
{
    DisplayEngine * pDisplay = m_pTombGeometry->getDisplay();
    for (int x = 0; x < m_iWidth; x++)
    {
        for (int y = 0; y < m_iHeight; y++)
        {
            Coords3D pos3D = pDisplay->get3DCoords(CoordsMap(x, y), BOARDPLANE);
            MapObject * mapObj = m_pTiles[x][y]->getFirstMapObject(GOTYPE_TOWN);
            if (mapObj != NULL)
                mapObj->display();
            mapObj = m_pTiles[x][y]->getFirstMapObject(GOTYPE_TEMPLE);
            if (mapObj != NULL)
                mapObj->display();
            mapObj = m_pTiles[x][y]->getFirstMapObject(GOTYPE_DEAD_UNIT);
            if (mapObj != NULL)
                m_pTombGeometry->display(pos3D + Coords3D(0.6f, 0.1f), F_RGBA_NULL);
            mapObj = m_pTiles[x][y]->getFirstMapObject(GOTYPE_UNIT);
            if (mapObj != NULL)
            {
                mapObj->display();
                Player * pPlayer = pPlayerMngr->findPlayer(mapObj->getOwner());
                assert(pPlayer != NULL);
                pPlayer->m_pBannerGeometry->display(pos3D + Coords3D(0.7f, 0.0f), pPlayer->m_Color);
            }
            Player * pPlayer = pPlayerMngr->getActiveLocalPlayer();
            if (pPlayer != NULL)
            {
                if (m_pTiles[x][y]->m_pNbAlliesGeo != NULL)
                {
//          float fy = 0.31f;
                    if (m_pTiles[x][y]->m_pNbFoesGeo == NULL)
                    {
//            fy = 0.62f;
                        m_pCountUnitsBgGeometry1L->display(pos3D + Coords3D(-0.1f, 0.0f), F_RGBA_NULL);
                    }
                    else
                        m_pCountUnitsBgGeometry2L->display(pos3D + Coords3D(-0.1f, 0.0f), F_RGBA_NULL);
                    pPlayer->m_pBannerGeometry->display(pos3D + Coords3D(-0.1f, 0.0f), pPlayer->m_Color);
                    m_pTiles[x][y]->m_pNbAlliesGeo->display(pos3D + Coords3D(0.15f, 0.0f), F_RGBA_NULL);
                }
                if (m_pTiles[x][y]->m_pNbFoesGeo != NULL)
                {
                    float fy = 0.31f;
                    if (m_pTiles[x][y]->m_pNbAlliesGeo == NULL)
                    {
                        fy = 0.0f;
                        m_pCountUnitsBgGeometry1L->display(pos3D + Coords3D(-0.1f, 0.0f), F_RGBA_NULL);
                    }
                    m_pFoeBannerGeometry->display(pos3D + Coords3D(-0.1f, fy), rgb(0, 0, 0));
                    m_pTiles[x][y]->m_pNbFoesGeo->display(pos3D + Coords3D(0.15f, fy), F_RGBA_NULL);
                }
            }
        }
    }
}
Esempio n. 19
0
void MapLayer::SetNavigationString(){
    float option = 0.0f;
    MapObject *obj = (MapObject*)this->getChildByTag(mouseY*width+mouseX);
    if(obj)
        option = obj->GetInfo().option;
    if(isEraser)
        navigation->setString(StringUtils::format("<mapEdit>\ncurser : %d\nerase : true\nposition : (%d,%d)\nnumber : %d\noption : %.1f", nowTile, mouseX, mouseY, mapData[mouseY][mouseX], option));
    else
        navigation->setString(StringUtils::format("<mapEdit>\ncurser : %d\nerase : false\nposition : (%d,%d)\nnumber : %d\noption : %.1f", nowTile, mouseX, mouseY, mapData[mouseY][mouseX], option));
}
Esempio n. 20
0
/**
 * Convenience method that deals with some of the logic related to pasting
 * a group of objects.
 */
void ClipboardManager::pasteObjectGroup(const ObjectGroup *objectGroup,
                                        MapDocument *mapDocument,
                                        const MapView *view,
                                        PasteFlags flags)
{
    Layer *currentLayer = mapDocument->currentLayer();
    if (!currentLayer)
        return;

    ObjectGroup *currentObjectGroup = currentLayer->asObjectGroup();
    if (!currentObjectGroup)
        return;

    QPointF insertPos;

    if (!(flags & PasteInPlace)) {
        // Determine where to insert the objects
        const MapRenderer *renderer = mapDocument->renderer();
        const QPointF center = objectGroup->objectsBoundingRect().center();

        // Take the mouse position if the mouse is on the view, otherwise
        // take the center of the view.
        QPoint viewPos;
        if (view->underMouse())
            viewPos = view->mapFromGlobal(QCursor::pos());
        else
            viewPos = QPoint(view->width() / 2, view->height() / 2);

        const QPointF scenePos = view->mapToScene(viewPos);

        insertPos = renderer->screenToPixelCoords(scenePos) - center;
        SnapHelper(renderer).snap(insertPos);
    }

    QUndoStack *undoStack = mapDocument->undoStack();
    QList<MapObject*> pastedObjects;
    pastedObjects.reserve(objectGroup->objectCount());

    undoStack->beginMacro(tr("Paste Objects"));
    for (const MapObject *mapObject : objectGroup->objects()) {
        if (flags & PasteNoTileObjects && !mapObject->cell().isEmpty())
            continue;

        MapObject *objectClone = mapObject->clone();
        objectClone->resetId();
        objectClone->setPosition(objectClone->position() + insertPos);
        pastedObjects.append(objectClone);
        undoStack->push(new AddMapObject(mapDocument,
                                         currentObjectGroup,
                                         objectClone));
    }
    undoStack->endMacro();

    mapDocument->setSelectedObjects(pastedObjects);
}
MapObject *CreateTileObjectTool::createNewMapObject()
{
    if (!mTile)
        return 0;

    MapObject *newMapObject = new MapObject;
    newMapObject->setShape(MapObject::Rectangle);
    newMapObject->setCell(Cell(mTile));
    newMapObject->setSize(mTile->size());
    return newMapObject;
}
Esempio n. 22
0
void CreateObjectTool::finishNewMapObject()
{
    Q_ASSERT(mNewMapObjectItem);
    MapObject *newMapObject = mNewMapObjectItem->mapObject();
    ObjectGroup *objectGroup = newMapObject->objectGroup();
    clearNewMapObjectItem();

    mapDocument()->undoStack()->push(new AddMapObject(mapDocument(),
                                                      objectGroup,
                                                      newMapObject));
}
Esempio n. 23
0
void DialogueSupervisor::_UpdateEmote()
{
    uint32 speaker_id = _current_dialogue->GetLineSpeaker(_line_counter);
    MapObject *object = speaker_id > 0 ?
        MapMode::CurrentInstance()->GetObjectSupervisor()->GetObject(speaker_id)
        : NULL;

    if(!object || !object->HasEmote()) {
        _emote_triggered = true;
        _BeginLine();
    }
}
Esempio n. 24
0
MapObject *CreateTemplateTool::createNewMapObject()
{
    auto newObjectTemplate = objectTemplate();

    if (!newObjectTemplate)
        return nullptr;

    MapObject *newMapObject = new MapObject();
    newMapObject->setObjectTemplate(newObjectTemplate);
    newMapObject->syncWithTemplate();
    return newMapObject;
}
Esempio n. 25
0
void ResizeHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    Handle::mouseReleaseEvent(event);

    // If we resized the object, create an undo command
    MapObject *obj = mMapObjectItem->mapObject();
    if (event->button() == Qt::LeftButton && mOldSize != obj->size()) {
        MapDocument *document = mMapObjectItem->mapDocument();
        QUndoCommand *cmd = new ResizeMapObject(document, obj, mOldSize);
        document->undoStack()->push(cmd);
    }
}
Esempio n. 26
0
bool RotateMapObjectCommand::mergeWith(const QUndoCommand* other)
{
    const RotateMapObjectCommand* rotateCommand = static_cast<const RotateMapObjectCommand*>(other);

    MapObject* item = rotateCommand->object;

    if(item != object)
        return false;

    newRotation = item->getRotation();

    return true;
}
Esempio n. 27
0
bool MoveMapObjectCommand::mergeWith(const QUndoCommand* other)
{
    const MoveMapObjectCommand* moveCommand = static_cast<const MoveMapObjectCommand*>(other);

    MapObject* item = moveCommand->object;

    if(item != object)
        return false;

    newPosition = item->getTranslate();

    return true;
}
MapObject*	CMapObjectManager::getObject(MapObjectID id)
{
	for ( MapObjectList::iterator itr = m_Objects.begin();itr != m_Objects.end();++itr)
	{
		MapObject* pObject = *itr;
		if ( pObject && !pObject->GetDeleted() && pObject->GetId() == id )
		{
			return pObject;
		}
	}

	return NULL;
}
MapObject*	CMapObjectManager::getObject(int cx,int cy)
{
	for ( MapObjectList::iterator itr = m_Objects.begin();itr != m_Objects.end();++itr)
	{
		MapObject* pObject = *itr;
		if ( pObject  && !pObject->GetDeleted() && pObject->GetCellX() == cx && pObject->GetCellY() == cy )
		{
			return pObject;
		}
	}

	return NULL;
}
void CMapObjectManager::clear()
{
	for ( MapObjectList::iterator itr = m_Objects.begin();itr != m_Objects.end();++itr )
	{
		MapObject* pObject = *itr;
		if ( pObject )
		{
			pObject->release();
		}
	}

	m_Objects.clear();
}