void ChooseBuildingDlg::OnUsePointer()
{
	if (!EditorInterface::instance()->ObjectSelectOnlyMode()) {
		EditorInterface::instance()->SelectionMode();
		EditorInterface::instance()->ObjectSelectOnlyMode(true);
		return;
	} else {
		EditorInterface::instance()->ObjectSelectOnlyMode(false);

		EditorObjectMgr::EDITOR_OBJECT_LIST selectedObjects = EditorObjectMgr::instance()->getSelectedObjectList();
		int num_buildings_selected = 0;
		int validObjectIndex = -1;
		EditorObjectMgr::EDITOR_OBJECT_LIST::EConstIterator it = selectedObjects.Begin();
		while (!it.IsDone()) {
			int index = 0;
			EditorObjectMgr::BUILDING_LIST::EConstIterator it2 = m_buildingList.Begin();
			while (!it2.IsDone()) {
				if ((*it) == (*it2)) {
					num_buildings_selected += 1;
					validObjectIndex = index;
				}
				index += 1;
				it2++;
			}
			it++;
		}
		if (0 > validObjectIndex) {
			AfxMessageBox(IDS_NO_BUILDINGS_SELECTED);
		} else {
			if (1 < num_buildings_selected) {
				AfxMessageBox(IDS_MORE_THAN_ONE_BUILDING_SELECTED);
			}
			m_pComboBox->SetCurSel(validObjectIndex);
		}
	}
}
Пример #2
0
Action* Eraser::applyToSelection()
{
	EraserAction* pRetAction = new EraserAction;
	{
		CTeams originalTeams = EditorData::instance->TeamsRef();
		/*first remove all references to objects that are about to be deleted*/
		EditorObjectMgr::EDITOR_OBJECT_LIST selectedObjectsList =
			EditorObjectMgr::instance()->getSelectedObjectList();
		EditorObjectMgr::EDITOR_OBJECT_LIST::EIterator it = selectedObjectsList.Begin();
		while (!it.IsDone())
		{
			const EditorObject* pInfo = (*it);
			if (pInfo)
			{
				EditorData::instance->handleObjectInvalidation(pInfo);
			}
			it++;
		}
		if (!(originalTeams == EditorData::instance->TeamsRef()))
		{
			/*record undo info regarding removal of references to deleted
			objects before we actually delete the objects (because we need info
			from the actual objects before they're deleted)*/
			pRetAction->teamsAction.PreviousTeams(originalTeams);
			pRetAction->teamsActionIsSet = true;
		}
	}
	EditorObjectMgr::EDITOR_OBJECT_LIST selectedObjectsList =
		EditorObjectMgr::instance()->getSelectedObjectList();
	EditorObjectMgr::EDITOR_OBJECT_LIST::EIterator it = selectedObjectsList.Begin();
	while (!it.IsDone())
	{
		EditorObject* pInfo = (*it);
		if (pInfo)
		{
			{
				BuildingLink* pLink = EditorObjectMgr::instance()->getLinkWithParent(pInfo);
				if (pLink)
				{
					pRetAction->linkAction.AddToListOnce(
						LinkBrush::LinkInfo(pLink, LinkBrush::LinkInfo::REMOVE));
					EditorObjectMgr::instance()->deleteLink(pLink);
				}
				{
					pLink = EditorObjectMgr::instance()->getLinkWithBuilding(pInfo);
					if (pLink)
					{
						pRetAction->linkAction.AddToListOnce(
							LinkBrush::LinkInfo(pLink, LinkBrush::LinkInfo::EDIT));
						pLink->RemoveObject(pInfo);
					}
				}
			}
			pRetAction->bldgAction.addBuildingInfo(*pInfo); // undo!
			EditorObjectMgr::instance()->deleteObject(pInfo);
		}
		it++;
	}
	// EditorObjectMgr::instance()->deleteSelectedObjects();
	for (size_t i = 0; i < land->realVerticesMapSide; ++i)
	{
		for (size_t j = 0; j < land->realVerticesMapSide; ++j)
		{
			if (land->isVertexSelected(j, i))
			{
				pRetAction->addChangedVertexInfo(j, i);
				land->setOverlay(j, i, INVALID_OVERLAY, 0);
				land->setTerrain(j, i, DEFAULT_TERRAIN);
				for (size_t icell = 0; icell < terrain_const::MAPCELL_DIM; icell++)
				{
					for (size_t jcell = 0; jcell < terrain_const::MAPCELL_DIM; jcell++)
					{
						int32_t cellRow = j * terrain_const::MAPCELL_DIM + jcell;
						int32_t cellCol = i * terrain_const::MAPCELL_DIM + icell;
						GameMap->setMine(cellRow, cellCol, 0);
					}
				}
			}
		}
	}
	return pRetAction;
}