static PyObject *py_editor_close(PyObject *self) { EditorObject *editor = (EditorObject *)self; if (editor->done) { PyErr_SetString(PyExc_RuntimeError, "Editor already closed/aborted"); return NULL; } if (editor->active_child) { PyErr_SetString(PyExc_RuntimeError, "a child is still open"); return NULL; } RUN_SVN(editor->editor->close_edit(editor->baton, editor->pool)); editor->done = true; apr_pool_destroy(editor->pool); editor->pool = NULL; if (editor->done_cb != NULL) editor->done_cb(editor->done_baton); Py_RETURN_NONE; }
static PyObject *py_editor_ctx_exit(PyObject *self, PyObject *args) { EditorObject *editor = (EditorObject *)self; PyObject *exc_type, *exc_val, *exc_tb; if (!PyArg_ParseTuple(args, "OOO", &exc_type, &exc_val, &exc_tb)) return NULL; if (editor->done) { PyErr_SetString(PyExc_RuntimeError, "Editor already closed/aborted"); return NULL; } if (exc_type != Py_None) { RUN_SVN(editor->editor->abort_edit(editor->baton, editor->pool)); } else { if (editor->active_child) { PyErr_SetString(PyExc_RuntimeError, "a child is still open"); return NULL; } RUN_SVN(editor->editor->close_edit(editor->baton, editor->pool)); } if (editor->done_cb != NULL) editor->done_cb(editor->done_baton); Py_RETURN_FALSE; }
void ModifyBuildingAction::updateNotedObjectPositions() { OBJ_ID_LIST::EIterator iter4 = buildingIDs.Begin(); for ( OBJ_INFO_PTR_LIST::EIterator iter = buildingPtrs.Begin(); !iter.IsDone(); iter++) { EditorObject *pBuilding = (*iter); if (pBuilding) { (*iter4).x = pBuilding->getPosition().x; (*iter4).y = pBuilding->getPosition().y; } else { gosASSERT(false); } iter4++; } }
void ModifyBuildingAction::addBuildingInfo(EditorObject& info) { if ((0 < buildingPtrs.Count()) && (OBJ_INFO_PTR_LIST::INVALID_ITERATOR != buildingPtrs.Find(&info))) { return; } // if we made it here, it isn't in there already EditorObject *pInfoCopy = info.Clone(); buildingCopyPtrs.Append( pInfoCopy ); buildingAppearanceCopies.Append(*(info.appearance())); buildingPtrs.Append( &info ); CObjectID id; id.x = info.getPosition().x; id.y = info.getPosition().y; buildingIDs.Append(id); }
bool ModifyBuildingAction::doRedo() { bool bRetVal = true; OBJ_INFO_PTR_LIST::EIterator iter2 = buildingPtrs.Begin(); OBJ_APPEAR_LIST::EIterator iter3 = buildingAppearanceCopies.Begin(); OBJ_ID_LIST::EIterator iter4 = buildingIDs.Begin(); for ( OBJ_INFO_PTR_LIST::EIterator iter = buildingCopyPtrs.Begin(); !iter.IsDone(); iter++) { //EditorObject *pBuilding = (*iter2); EditorObject *pBuilding = EditorObjectMgr::instance()->getObjectAtLocation((*iter4).x, (*iter4).y); if (pBuilding) { EditorObject *pBuildingSwap = (*iter)->Clone(); ObjectAppearance AppearanceSwap = (*iter3); (*iter)->CastAndCopy(*pBuilding); (*iter3) = (*(pBuilding->appearance())); (*pBuilding).CastAndCopy(*pBuildingSwap); (*(pBuilding->appearance())) = AppearanceSwap; delete pBuildingSwap; { /*this is just to make sure the visuals are up-to-date*/ bool d = pBuilding->getDamage(); pBuilding->setDamage(!d); pBuilding->setDamage(d); } long row, column; pBuilding->getCells(row, column); EditorObjectMgr::instance()->moveBuilding(pBuilding, row, column); (*iter4).x = pBuilding->getPosition().x; (*iter4).y = pBuilding->getPosition().y; } else { gosASSERT(false); } iter2++; iter3++; iter4++; } return bRetVal; }
static PyObject *py_editor_abort(PyObject *self) { EditorObject *editor = (EditorObject *)self; if (editor->done) { PyErr_SetString(PyExc_RuntimeError, "Editor already closed/aborted"); return NULL; } /* FIXME: Check for open active childs ? */ RUN_SVN(editor->editor->abort_edit(editor->baton, editor->pool)); editor->done = true; apr_pool_destroy(editor->pool); editor->pool = NULL; if (editor->done_cb != NULL) editor->done_cb(editor->done_baton); Py_RETURN_NONE; }
EditorObject * EditorObject::load(QString file) { QList< QPair<QString, QString> > props; if( ! EditorResourceManager::loadTextFile(file, props) ) return NULL; EditorObject * out = new EditorObject(); out->m_resourceName = QFileInfo(file).fileName(); out->m_layerNames.clear(); for(int i=0; i<props.size(); ++i) { const QPair<QString, QString> & pair = props.at(i); if( pair.first.compare("version", Qt::CaseInsensitive) == 0 ) { int codeVersion = 1; int fileVersion = pair.second.toInt(); if( codeVersion != fileVersion ) { qDebug() << "EditorObject::load - file version does not match code version"; return NULL; // TODO fix this memory leak } } else if( pair.first.compare("name", Qt::CaseInsensitive) == 0 ) { out->m_name = pair.second; } else if( pair.first.compare("size", Qt::CaseInsensitive) == 0 ) { QStringList sizes = pair.second.split(","); int sizeX = sizes.at(0).toInt(); int sizeY = sizes.at(1).toInt(); int sizeZ = sizes.at(2).toInt(); out->m_surfaceTypes = new Array3<Tile::SurfaceType>(sizeX, sizeY, sizeZ); out->m_shapes = new Array3<Tile::Shape>(sizeX, sizeY, sizeZ); } else if( pair.first.compare("description", Qt::CaseInsensitive) == 0 ) { out->m_description = pair.second; } else if( pair.first.compare("surfaceTypes", Qt::CaseInsensitive) == 0 ) { QStringList surfaceTypes = pair.second.split(","); int i=0; for(int z=0; z<out->layerCount(); ++z) { for(int y=0; y<out->tileCountY(); ++y) { for(int x=0; x<out->tileCountX(); ++x) { out->m_surfaceTypes->set(x,y,z, (Tile::SurfaceType) surfaceTypes.at(i).toInt() ); ++i; } } } } else if( pair.first.compare("shapes", Qt::CaseInsensitive) == 0 ) { QStringList shapes = pair.second.split(","); int i=0; for(int z=0; z<out->layerCount(); ++z) { for(int y=0; y<out->tileCountY(); ++y) { for(int x=0; x<out->tileCountX(); ++x) { out->m_shapes->set(x,y,z, (Tile::Shape) shapes.at(i).toInt() ); ++i; } } } } else if( pair.first.compare("graphic", Qt::CaseInsensitive) == 0 ) { // create a graphic and add it to the list ObjectGraphic * graphic = new ObjectGraphic; // x,y,width,height,layer,graphicFile QStringList graphicProps = pair.second.split(","); graphic->x = graphicProps.at(0).toDouble(); graphic->y = graphicProps.at(1).toDouble(); graphic->width = graphicProps.at(2).toDouble(); graphic->height = graphicProps.at(3).toDouble(); graphic->layer = graphicProps.at(4).toInt(); graphic->graphicName = graphicProps.at(5); graphic->graphic = EditorResourceManager::graphic(graphic->graphicName); out->graphics()->at(graphic->layer)->append(graphic); } else if( pair.first.compare("layerName", Qt::CaseInsensitive) == 0 ) { out->m_layerNames << pair.second; } else { qDebug() << "EditorObject::load - unrecognized property name: " << pair.first; return NULL; // TODO: fix this memory leak } } if( out->m_layerNames.size() != out->m_surfaceTypes->sizeZ() ) { // layers do not match qDebug() << "Layer names do not match actual layer size"; return NULL; // TODO: fix this memory leak } return out; }
void BuildingBrush::BuildingAction::addBuildingInfo(EditorObject& info) { EditorObject* pCopy = info.Clone(); gosASSERT(pCopy); objInfoPtrList.Append(pCopy); }
void BuildingSettingsDlg::updateMemberVariables() { long forest = -1; bool bForests = true; EditorObject* pEditorObject = units.GetHead(); m_Alignment = pEditorObject->getAlignment(); if (m_Alignment == -1) m_Alignment = 8; //Move it to the neutral select button for ( EDITOROBJECT_LIST::EIterator iter = units.Begin(); !iter.IsDone(); iter++ ) { if ( ((*iter)->getAlignment() != m_Alignment) && ((*iter)->getAlignment() != -1)) { m_Alignment = -1; break; } if ( (*iter)->getForestID() != -1 ) { if ( forest == -1 ) forest = (*iter)->getForestID(); else if ( forest != (*iter)->getForestID() ) bForests = false; } } if ( forest != -1 ) { const Forest* pForest = EditorObjectMgr::instance()->getForest( forest ); if ( pForest ) { m_forestName = pForest->getFileName(); } } EditorObjectMgr* pMgr = EditorObjectMgr::instance(); int groupCount = pMgr->getBuildingGroupCount(); const char** pGroups = new const char*[groupCount]; m_Group.ResetContent(); pMgr->getBuildingGroupNames(pGroups, groupCount); int count = 0; for ( int i = 0; i < groupCount; ++i ) { if ((4/*mech group*/ == i) || (6/*vehicle group*/ == i)) { continue; } m_Group.AddString( pGroups[i] ); m_Group.SetItemData( count, (DWORD)i ); count += 1; } delete [] pGroups; // make sure all the units we are editing are in the same group int group = units.GetHead()->getGroup(); for ( iter = units.Begin(); !iter.IsDone(); iter++ ) { if ( (*iter)->getGroup() != group ) { group = -1; break; } } if ( group != -1 ) // we found a valid group { const char* pGroupName = pMgr->getGroupName( group ); int index = m_Group.FindString( -1, pGroupName ); m_Group.SetCurSel( index ); // OK, now fill in the index.... const char* MechNames[256]; int count = 256; m_Mech.ResetContent(); pMgr->getBuildingNamesInGroup( group, MechNames, count ); for ( int i = 0; i < count; ++i ) { m_Mech.AddString( MechNames[i] ); } // ok, now determine if all of the mechs are the same. int indexInGroup = units.GetHead()->getIndexInGroup(); for ( iter = units.Begin(); !iter.IsDone(); iter++ ) { if ( (*iter)->getIndexInGroup() != indexInGroup ) { indexInGroup = -1; break; } } if ( indexInGroup != -1 ) { const char* pName = units.GetHead()->getDisplayName(); index = m_Mech.FindString( -1, pName ); if ( index != -1 ) { m_Mech.SetCurSel( index ); } } } m_x = pEditorObject->getPosition().x; m_y = pEditorObject->getPosition().y; long row, column; pEditorObject->getCells(row, column); m_partID = MIN_TERRAIN_PART_ID + row * MAX_MAP_CELL_WIDTH + column; UpdateData( false ); }