mirror of
https://github.com/vcmi/vcmi.git
synced 2025-10-08 23:22:25 +02:00
Improve editor performance
This commit is contained in:
@@ -295,6 +295,7 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||||||
|
|
||||||
mapLevel = combo->currentIndex();
|
mapLevel = combo->currentIndex();
|
||||||
ui->mapView->setScene(controller.scene(mapLevel));
|
ui->mapView->setScene(controller.scene(mapLevel));
|
||||||
|
ui->mapView->setViewports();
|
||||||
ui->minimapView->setScene(controller.miniScene(mapLevel));
|
ui->minimapView->setScene(controller.miniScene(mapLevel));
|
||||||
});
|
});
|
||||||
layout->addWidget(combo, c == ui->menuView ? 1 : 0);
|
layout->addWidget(combo, c == ui->menuView ? 1 : 0);
|
||||||
@@ -1323,9 +1324,10 @@ void MainWindow::on_actionUpdate_appearance_triggered()
|
|||||||
controller.scene(mapLevel)->selectionObjectsView.deselectObject(obj);
|
controller.scene(mapLevel)->selectionObjectsView.deselectObject(obj);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
std::vector<int3> selectedTiles;
|
||||||
for(auto & offset : obj->appearance->getBlockedOffsets())
|
for(auto & offset : obj->appearance->getBlockedOffsets())
|
||||||
controller.scene(mapLevel)->selectionTerrainView.select(obj->pos + offset);
|
selectedTiles.push_back(obj->pos + offset);
|
||||||
|
controller.scene(mapLevel)->selectionTerrainView.select(selectedTiles);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1484,8 +1486,6 @@ void MainWindow::on_actionLock_triggered()
|
|||||||
}
|
}
|
||||||
controller.scene(mapLevel)->selectionObjectsView.clear();
|
controller.scene(mapLevel)->selectionObjectsView.clear();
|
||||||
}
|
}
|
||||||
controller.scene(mapLevel)->objectsView.update();
|
|
||||||
controller.scene(mapLevel)->selectionObjectsView.update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1497,7 +1497,6 @@ void MainWindow::on_actionUnlock_triggered()
|
|||||||
controller.scene(mapLevel)->selectionObjectsView.unlockAll();
|
controller.scene(mapLevel)->selectionObjectsView.unlockAll();
|
||||||
controller.scene(mapLevel)->objectsView.unlockAll();
|
controller.scene(mapLevel)->objectsView.unlockAll();
|
||||||
}
|
}
|
||||||
controller.scene(mapLevel)->objectsView.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -229,7 +229,7 @@ void MapController::setMap(std::unique_ptr<CMap> cmap)
|
|||||||
_miniscenes[i].reset(new MinimapScene(i));
|
_miniscenes[i].reset(new MinimapScene(i));
|
||||||
}
|
}
|
||||||
resetMapHandler();
|
resetMapHandler();
|
||||||
sceneForceUpdate();
|
initializeMap();
|
||||||
|
|
||||||
connectScenes();
|
connectScenes();
|
||||||
|
|
||||||
@@ -256,21 +256,24 @@ void MapController::initObstaclePainters(CMap * map)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapController::initializeMap()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < _map->mapLevels; i++)
|
||||||
|
{
|
||||||
|
_scenes[i]->createMap();
|
||||||
|
_miniscenes[i]->createMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MapController::sceneForceUpdate()
|
void MapController::sceneForceUpdate()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < _map->mapLevels; i++)
|
for(int i = 0; i < _map->mapLevels; i++)
|
||||||
{
|
{
|
||||||
_scenes[i]->updateViews();
|
_scenes[i]->updateMap();
|
||||||
_miniscenes[i]->updateViews();
|
_miniscenes[i]->updateMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapController::sceneForceUpdate(int level)
|
|
||||||
{
|
|
||||||
_scenes[level]->updateViews();
|
|
||||||
_miniscenes[level]->updateViews();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MapController::resetMapHandler()
|
void MapController::resetMapHandler()
|
||||||
{
|
{
|
||||||
if(!_mapHandler)
|
if(!_mapHandler)
|
||||||
@@ -293,16 +296,13 @@ void MapController::commitTerrainChange(int level, const TerrainId & terrain)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
_scenes[level]->selectionTerrainView.clear();
|
_scenes[level]->selectionTerrainView.clear();
|
||||||
_scenes[level]->selectionTerrainView.draw();
|
|
||||||
|
|
||||||
_map->getEditManager()->getTerrainSelection().setSelection(v);
|
_map->getEditManager()->getTerrainSelection().setSelection(v);
|
||||||
_map->getEditManager()->drawTerrain(terrain, terrainDecorationPercentageLevel, &CRandomGenerator::getDefault());
|
_map->getEditManager()->drawTerrain(terrain, terrainDecorationPercentageLevel, &CRandomGenerator::getDefault());
|
||||||
|
|
||||||
for(auto & t : v)
|
_scenes[level]->terrainView.redrawTerrain(v);
|
||||||
_scenes[level]->terrainView.setDirty(t);
|
|
||||||
_scenes[level]->terrainView.draw();
|
|
||||||
|
|
||||||
_miniscenes[level]->updateViews();
|
_miniscenes[level]->updateMap();
|
||||||
main->mapChanged();
|
main->mapChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,19 +314,16 @@ void MapController::commitRoadOrRiverChange(int level, ui8 type, bool isRoad)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
_scenes[level]->selectionTerrainView.clear();
|
_scenes[level]->selectionTerrainView.clear();
|
||||||
_scenes[level]->selectionTerrainView.draw();
|
|
||||||
|
|
||||||
_map->getEditManager()->getTerrainSelection().setSelection(v);
|
_map->getEditManager()->getTerrainSelection().setSelection(v);
|
||||||
if(isRoad)
|
if(isRoad)
|
||||||
_map->getEditManager()->drawRoad(RoadId(type), &CRandomGenerator::getDefault());
|
_map->getEditManager()->drawRoad(RoadId(type), &CRandomGenerator::getDefault());
|
||||||
else
|
else
|
||||||
_map->getEditManager()->drawRiver(RiverId(type), &CRandomGenerator::getDefault());
|
_map->getEditManager()->drawRiver(RiverId(type), &CRandomGenerator::getDefault());
|
||||||
|
|
||||||
|
_scenes[level]->terrainView.redrawTerrain(v);
|
||||||
|
|
||||||
for(auto & t : v)
|
_miniscenes[level]->updateMap();
|
||||||
_scenes[level]->terrainView.setDirty(t);
|
|
||||||
_scenes[level]->terrainView.draw();
|
|
||||||
|
|
||||||
_miniscenes[level]->updateViews();
|
|
||||||
main->mapChanged();
|
main->mapChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,15 +348,13 @@ void MapController::commitObjectErase(int level)
|
|||||||
{
|
{
|
||||||
//invalidate tiles under objects
|
//invalidate tiles under objects
|
||||||
_mapHandler->removeObject(obj);
|
_mapHandler->removeObject(obj);
|
||||||
_scenes[level]->objectsView.setDirty(obj);
|
|
||||||
}
|
}
|
||||||
|
_scenes[level]->objectsView.redrawObjects(selectedObjects);
|
||||||
|
|
||||||
_scenes[level]->selectionObjectsView.clear();
|
_scenes[level]->selectionObjectsView.clear();
|
||||||
_scenes[level]->objectsView.draw();
|
_scenes[level]->passabilityView.redraw();
|
||||||
_scenes[level]->selectionObjectsView.draw();
|
|
||||||
_scenes[level]->passabilityView.update();
|
|
||||||
|
|
||||||
_miniscenes[level]->updateViews();
|
_miniscenes[level]->updateMap();
|
||||||
main->mapChanged();
|
main->mapChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,11 +402,11 @@ void MapController::pasteFromClipboard(int level)
|
|||||||
if(!errors.isEmpty())
|
if(!errors.isEmpty())
|
||||||
QMessageBox::warning(main, QObject::tr("Can't place object"), errors.join('\n'));
|
QMessageBox::warning(main, QObject::tr("Can't place object"), errors.join('\n'));
|
||||||
|
|
||||||
_scenes[level]->objectsView.draw();
|
_scenes[level]->objectsView.redraw();
|
||||||
_scenes[level]->passabilityView.update();
|
_scenes[level]->passabilityView.redraw();
|
||||||
_scenes[level]->selectionObjectsView.draw();
|
_scenes[level]->selectionObjectsView.redraw();
|
||||||
|
|
||||||
_miniscenes[level]->updateViews();
|
_miniscenes[level]->updateMap();
|
||||||
main->mapChanged();
|
main->mapChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,9 +416,8 @@ bool MapController::discardObject(int level) const
|
|||||||
if(_scenes[level]->selectionObjectsView.newObject)
|
if(_scenes[level]->selectionObjectsView.newObject)
|
||||||
{
|
{
|
||||||
_scenes[level]->selectionObjectsView.newObject.reset();
|
_scenes[level]->selectionObjectsView.newObject.reset();
|
||||||
_scenes[level]->selectionObjectsView.shift = QPoint(0, 0);
|
_scenes[level]->selectionObjectsView.setShift(0, 0);
|
||||||
_scenes[level]->selectionObjectsView.selectionMode = SelectionObjectsLayer::NOTHING;
|
_scenes[level]->selectionObjectsView.selectionMode = SelectionObjectsLayer::NOTHING;
|
||||||
_scenes[level]->selectionObjectsView.draw();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -433,7 +427,7 @@ void MapController::createObject(int level, std::shared_ptr<CGObjectInstance> ob
|
|||||||
{
|
{
|
||||||
_scenes[level]->selectionObjectsView.newObject = obj;
|
_scenes[level]->selectionObjectsView.newObject = obj;
|
||||||
_scenes[level]->selectionObjectsView.selectionMode = SelectionObjectsLayer::MOVEMENT;
|
_scenes[level]->selectionObjectsView.selectionMode = SelectionObjectsLayer::MOVEMENT;
|
||||||
_scenes[level]->selectionObjectsView.draw();
|
_scenes[level]->selectionObjectsView.redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapController::commitObstacleFill(int level)
|
void MapController::commitObstacleFill(int level)
|
||||||
@@ -463,29 +457,26 @@ void MapController::commitObstacleFill(int level)
|
|||||||
for(auto o : sel.second->placeObstacles(CRandomGenerator::getDefault()))
|
for(auto o : sel.second->placeObstacles(CRandomGenerator::getDefault()))
|
||||||
{
|
{
|
||||||
_mapHandler->invalidate(o.get());
|
_mapHandler->invalidate(o.get());
|
||||||
_scenes[level]->objectsView.setDirty(o.get());
|
_scenes[level]->objectsView.redrawObjects({o.get()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_scenes[level]->selectionTerrainView.clear();
|
_scenes[level]->selectionTerrainView.clear();
|
||||||
_scenes[level]->selectionTerrainView.draw();
|
_scenes[level]->objectsView.update();
|
||||||
_scenes[level]->objectsView.draw();
|
|
||||||
_scenes[level]->passabilityView.update();
|
_scenes[level]->passabilityView.update();
|
||||||
|
|
||||||
_miniscenes[level]->updateViews();
|
_miniscenes[level]->updateMap();
|
||||||
main->mapChanged();
|
main->mapChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapController::commitObjectChange(int level)
|
void MapController::commitObjectChange(int level)
|
||||||
{
|
{
|
||||||
for( auto * o : _scenes[level]->selectionObjectsView.getSelection())
|
_scenes[level]->objectsView.redrawObjects(_scenes[level]->selectionObjectsView.getSelection());
|
||||||
_scenes[level]->objectsView.setDirty(o);
|
|
||||||
|
|
||||||
_scenes[level]->objectsView.draw();
|
_scenes[level]->selectionObjectsView.redraw();
|
||||||
_scenes[level]->selectionObjectsView.draw();
|
_scenes[level]->passabilityView.redraw();
|
||||||
_scenes[level]->passabilityView.update();
|
|
||||||
|
|
||||||
_miniscenes[level]->updateViews();
|
_miniscenes[level]->updateMap();
|
||||||
main->mapChanged();
|
main->mapChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,29 +493,30 @@ void MapController::commitObjectShift(int level)
|
|||||||
bool makeShift = !shift.isNull();
|
bool makeShift = !shift.isNull();
|
||||||
if(makeShift)
|
if(makeShift)
|
||||||
{
|
{
|
||||||
for(auto * obj : _scenes[level]->selectionObjectsView.getSelection())
|
std::set<CGObjectInstance*> movedObjects = _scenes[level]->selectionObjectsView.getSelection();
|
||||||
|
for(auto * obj : movedObjects)
|
||||||
{
|
{
|
||||||
int3 pos = obj->pos;
|
int3 pos = obj->pos;
|
||||||
pos.z = level;
|
pos.z = level;
|
||||||
pos.x += shift.x(); pos.y += shift.y();
|
pos.x += shift.x(); pos.y += shift.y();
|
||||||
|
|
||||||
_scenes[level]->objectsView.setDirty(obj); //set dirty before movement
|
|
||||||
_map->getEditManager()->moveObject(obj, pos);
|
_map->getEditManager()->moveObject(obj, pos);
|
||||||
_mapHandler->invalidate(obj);
|
_mapHandler->invalidate(obj);
|
||||||
}
|
}
|
||||||
|
_scenes[level]->objectsView.redrawObjects(movedObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
_scenes[level]->selectionObjectsView.newObject = nullptr;
|
_scenes[level]->selectionObjectsView.newObject = nullptr;
|
||||||
_scenes[level]->selectionObjectsView.shift = QPoint(0, 0);
|
_scenes[level]->selectionObjectsView.setShift(0, 0);
|
||||||
_scenes[level]->selectionObjectsView.selectionMode = SelectionObjectsLayer::NOTHING;
|
_scenes[level]->selectionObjectsView.selectionMode = SelectionObjectsLayer::NOTHING;
|
||||||
|
|
||||||
if(makeShift)
|
if(makeShift)
|
||||||
{
|
{
|
||||||
_scenes[level]->objectsView.draw();
|
_scenes[level]->objectsView.redraw();
|
||||||
_scenes[level]->selectionObjectsView.draw();
|
_scenes[level]->passabilityView.redraw();
|
||||||
_scenes[level]->passabilityView.update();
|
_scenes[level]->selectionObjectsView.redraw();
|
||||||
|
|
||||||
_miniscenes[level]->updateViews();
|
_miniscenes[level]->updateMap();
|
||||||
main->mapChanged();
|
main->mapChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -547,16 +539,14 @@ void MapController::commitObjectCreate(int level)
|
|||||||
|
|
||||||
_map->getEditManager()->insertObject(newObj);
|
_map->getEditManager()->insertObject(newObj);
|
||||||
_mapHandler->invalidate(newObj.get());
|
_mapHandler->invalidate(newObj.get());
|
||||||
_scenes[level]->objectsView.setDirty(newObj.get());
|
_scenes[level]->objectsView.redrawObjects({newObj.get()});
|
||||||
|
|
||||||
_scenes[level]->selectionObjectsView.newObject = nullptr;
|
_scenes[level]->selectionObjectsView.newObject = nullptr;
|
||||||
_scenes[level]->selectionObjectsView.shift = QPoint(0, 0);
|
_scenes[level]->selectionObjectsView.setShift(0, 0);
|
||||||
_scenes[level]->selectionObjectsView.selectionMode = SelectionObjectsLayer::NOTHING;
|
_scenes[level]->selectionObjectsView.selectionMode = SelectionObjectsLayer::NOTHING;
|
||||||
_scenes[level]->objectsView.draw();
|
_scenes[level]->passabilityView.redraw();
|
||||||
_scenes[level]->selectionObjectsView.draw();
|
|
||||||
_scenes[level]->passabilityView.update();
|
|
||||||
|
|
||||||
_miniscenes[level]->updateViews();
|
_miniscenes[level]->updateMap();
|
||||||
main->mapChanged();
|
main->mapChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -48,8 +48,8 @@ public:
|
|||||||
|
|
||||||
void resetMapHandler();
|
void resetMapHandler();
|
||||||
|
|
||||||
|
void initializeMap();
|
||||||
void sceneForceUpdate();
|
void sceneForceUpdate();
|
||||||
void sceneForceUpdate(int level);
|
|
||||||
|
|
||||||
void commitTerrainChange(int level, const TerrainId & terrain);
|
void commitTerrainChange(int level, const TerrainId & terrain);
|
||||||
void commitRoadOrRiverChange(int level, ui8 type, bool isRoad);
|
void commitRoadOrRiverChange(int level, ui8 type, bool isRoad);
|
||||||
|
@@ -109,18 +109,17 @@ void MapHandler::initTerrainGraphics()
|
|||||||
loadFlipped(roadAnimations, roadImages, roadFiles);
|
loadFlipped(roadAnimations, roadImages, roadFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapHandler::drawTerrainTile(QPainter & painter, int x, int y, int z)
|
void MapHandler::drawTerrainTile(QPainter & painter, int x, int y, int z, QPointF offset)
|
||||||
{
|
{
|
||||||
const auto & tinfo = map->getTile(int3(x, y, z));
|
const auto & tinfo = map->getTile(int3(x, y, z));
|
||||||
|
|
||||||
auto terrainName = tinfo.getTerrain()->getJsonKey();
|
auto terrainName = tinfo.getTerrain()->getJsonKey();
|
||||||
if(terrainImages.at(terrainName).size() <= tinfo.terView)
|
if(terrainImages.at(terrainName).size() <= tinfo.terView)
|
||||||
return;
|
return;
|
||||||
|
painter.drawImage(x * tileSize - offset.x(), y * tileSize - offset.y(), flippedImage(terrainImages.at(terrainName)[tinfo.terView], tinfo.extTileFlags));
|
||||||
painter.drawImage(x * tileSize, y * tileSize, flippedImage(terrainImages.at(terrainName)[tinfo.terView], tinfo.extTileFlags));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapHandler::drawRoad(QPainter & painter, int x, int y, int z)
|
void MapHandler::drawRoad(QPainter & painter, int x, int y, int z, QPointF offset)
|
||||||
{
|
{
|
||||||
const auto & tinfo = map->getTile(int3(x, y, z));
|
const auto & tinfo = map->getTile(int3(x, y, z));
|
||||||
auto * tinfoUpper = map->isInTheMap(int3(x, y - 1, z)) ? &map->getTile(int3(x, y - 1, z)) : nullptr;
|
auto * tinfoUpper = map->isInTheMap(int3(x, y - 1, z)) ? &map->getTile(int3(x, y - 1, z)) : nullptr;
|
||||||
@@ -132,7 +131,7 @@ void MapHandler::drawRoad(QPainter & painter, int x, int y, int z)
|
|||||||
{
|
{
|
||||||
const QRect source{0, tileSize / 2, tileSize, tileSize / 2};
|
const QRect source{0, tileSize / 2, tileSize, tileSize / 2};
|
||||||
const ui8 rotationFlags = tinfoUpper->extTileFlags >> 4;
|
const ui8 rotationFlags = tinfoUpper->extTileFlags >> 4;
|
||||||
painter.drawImage(QPoint(x * tileSize, y * tileSize), flippedImage(roadImages.at(roadName)[tinfoUpper->roadDir], rotationFlags), source);
|
painter.drawImage(QPoint(x * tileSize - offset.x(), y * tileSize - offset.y()), flippedImage(roadImages.at(roadName)[tinfoUpper->roadDir], rotationFlags), source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,12 +142,12 @@ void MapHandler::drawRoad(QPainter & painter, int x, int y, int z)
|
|||||||
{
|
{
|
||||||
const QRect source{0, 0, tileSize, tileSize / 2};
|
const QRect source{0, 0, tileSize, tileSize / 2};
|
||||||
const ui8 rotationFlags = tinfo.extTileFlags >> 4;
|
const ui8 rotationFlags = tinfo.extTileFlags >> 4;
|
||||||
painter.drawImage(QPoint(x * tileSize, y * tileSize + tileSize / 2), flippedImage(roadImages.at(roadName)[tinfo.roadDir], rotationFlags), source);
|
painter.drawImage(QPoint(x * tileSize - offset.x(), y * tileSize + tileSize / 2 - offset.y()), flippedImage(roadImages.at(roadName)[tinfo.roadDir], rotationFlags), source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapHandler::drawRiver(QPainter & painter, int x, int y, int z)
|
void MapHandler::drawRiver(QPainter & painter, int x, int y, int z, QPointF offset)
|
||||||
{
|
{
|
||||||
const auto & tinfo = map->getTile(int3(x, y, z));
|
const auto & tinfo = map->getTile(int3(x, y, z));
|
||||||
|
|
||||||
@@ -162,7 +161,7 @@ void MapHandler::drawRiver(QPainter & painter, int x, int y, int z)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const ui8 rotationFlags = tinfo.extTileFlags >> 2;
|
const ui8 rotationFlags = tinfo.extTileFlags >> 2;
|
||||||
painter.drawImage(x * tileSize, y * tileSize, flippedImage(riverImages.at(riverName)[tinfo.riverDir], rotationFlags));
|
painter.drawImage(x * tileSize - offset.x(), y * tileSize - offset.y(), flippedImage(riverImages.at(riverName)[tinfo.riverDir], rotationFlags));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPlayerColor(QImage * sur, PlayerColor player)
|
void setPlayerColor(QImage * sur, PlayerColor player)
|
||||||
@@ -366,7 +365,7 @@ std::vector<ObjectRect> & MapHandler::getObjects(int x, int y, int z)
|
|||||||
return tileObjects[index(x, y, z)];
|
return tileObjects[index(x, y, z)];
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapHandler::drawObjects(QPainter & painter, int x, int y, int z, const std::set<const CGObjectInstance *> & locked)
|
void MapHandler::drawObjects(QPainter & painter, int x, int y, int z, QPointF offset, const std::set<const CGObjectInstance *> & locked)
|
||||||
{
|
{
|
||||||
painter.setRenderHint(QPainter::Antialiasing, false);
|
painter.setRenderHint(QPainter::Antialiasing, false);
|
||||||
painter.setRenderHint(QPainter::SmoothPixmapTransform, false);
|
painter.setRenderHint(QPainter::SmoothPixmapTransform, false);
|
||||||
@@ -390,7 +389,7 @@ void MapHandler::drawObjects(QPainter & painter, int x, int y, int z, const std:
|
|||||||
{
|
{
|
||||||
auto pos = obj->anchorPos();
|
auto pos = obj->anchorPos();
|
||||||
|
|
||||||
painter.drawImage(QPoint(x * tileSize, y * tileSize), *objData.objBitmap, object.rect, Qt::AutoColor | Qt::NoOpaqueDetection);
|
painter.drawImage(QPoint(x * tileSize - offset.x(), y * tileSize - offset.y()), *objData.objBitmap, object.rect, Qt::AutoColor | Qt::NoOpaqueDetection);
|
||||||
|
|
||||||
if(locked.count(obj))
|
if(locked.count(obj))
|
||||||
{
|
{
|
||||||
@@ -402,13 +401,13 @@ void MapHandler::drawObjects(QPainter & painter, int x, int y, int z, const std:
|
|||||||
if(objData.flagBitmap)
|
if(objData.flagBitmap)
|
||||||
{
|
{
|
||||||
if(x == pos.x && y == pos.y)
|
if(x == pos.x && y == pos.y)
|
||||||
painter.drawImage(QPoint((x - 2) * tileSize, (y - 1) * tileSize), *objData.flagBitmap);
|
painter.drawImage(QPoint((x - 2) * tileSize - offset.x(), (y - 1) * tileSize - offset.y()), *objData.flagBitmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapHandler::drawObjectAt(QPainter & painter, const CGObjectInstance * obj, int x, int y)
|
void MapHandler::drawObjectAt(QPainter & painter, const CGObjectInstance * obj, int x, int y, QPointF offset)
|
||||||
{
|
{
|
||||||
if (!obj)
|
if (!obj)
|
||||||
{
|
{
|
||||||
@@ -424,10 +423,10 @@ void MapHandler::drawObjectAt(QPainter & painter, const CGObjectInstance * obj,
|
|||||||
|
|
||||||
if (objData.objBitmap)
|
if (objData.objBitmap)
|
||||||
{
|
{
|
||||||
painter.drawImage(QPoint((x + 1) * tileSize - objData.objBitmap->width(), (y + 1) * tileSize - objData.objBitmap->height()), *objData.objBitmap);
|
painter.drawImage(QPoint((x + 1) * tileSize - objData.objBitmap->width() - offset.x(), (y + 1) * tileSize - objData.objBitmap->height() - offset.y()), *objData.objBitmap);
|
||||||
|
|
||||||
if (objData.flagBitmap)
|
if (objData.flagBitmap)
|
||||||
painter.drawImage(QPoint((x + 1) * tileSize - objData.objBitmap->width(), (y + 1) * tileSize - objData.objBitmap->height()), *objData.flagBitmap);
|
painter.drawImage(QPoint((x + 1) * tileSize - objData.objBitmap->width() - offset.x(), (y + 1) * tileSize - objData.objBitmap->height() - offset.y()), *objData.flagBitmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -92,11 +92,11 @@ public:
|
|||||||
|
|
||||||
void reset(const CMap * Map);
|
void reset(const CMap * Map);
|
||||||
|
|
||||||
void drawTerrainTile(QPainter & painter, int x, int y, int z);
|
void drawTerrainTile(QPainter & painter, int x, int y, int z, QPointF offset);
|
||||||
/// draws a river segment on current tile
|
/// draws a river segment on current tile
|
||||||
void drawRiver(QPainter & painter, int x, int y, int z);
|
void drawRiver(QPainter & painter, int x, int y, int z, QPointF offset);
|
||||||
/// draws a road segment on current tile
|
/// draws a road segment on current tile
|
||||||
void drawRoad(QPainter & painter, int x, int y, int z);
|
void drawRoad(QPainter & painter, int x, int y, int z, QPointF offset);
|
||||||
|
|
||||||
std::set<int3> invalidate(const CGObjectInstance *); //invalidates object rects
|
std::set<int3> invalidate(const CGObjectInstance *); //invalidates object rects
|
||||||
void invalidateObjects(); //invalidates all objects on the map
|
void invalidateObjects(); //invalidates all objects on the map
|
||||||
@@ -111,8 +111,8 @@ public:
|
|||||||
std::set<int3> addObject(const CGObjectInstance * object);
|
std::set<int3> addObject(const CGObjectInstance * object);
|
||||||
|
|
||||||
/// draws all objects on current tile (higher-level logic, unlike other draw*** methods)
|
/// draws all objects on current tile (higher-level logic, unlike other draw*** methods)
|
||||||
void drawObjects(QPainter & painter, int x, int y, int z, const std::set<const CGObjectInstance *> & locked);
|
void drawObjects(QPainter & painter, int x, int y, int z, QPointF offset, const std::set<const CGObjectInstance *> & locked);
|
||||||
void drawObjectAt(QPainter & painter, const CGObjectInstance * object, int x, int y);
|
void drawObjectAt(QPainter & painter, const CGObjectInstance * object, int x, int y, QPointF offset);
|
||||||
|
|
||||||
void drawMinimapTile(QPainter & painter, int x, int y, int z);
|
void drawMinimapTile(QPainter & painter, int x, int y, int z);
|
||||||
|
|
||||||
|
@@ -59,6 +59,8 @@ MapView::MapView(QWidget * parent):
|
|||||||
QGraphicsView(parent),
|
QGraphicsView(parent),
|
||||||
selectionTool(MapView::SelectionTool::None)
|
selectionTool(MapView::SelectionTool::None)
|
||||||
{
|
{
|
||||||
|
connect(horizontalScrollBar(), &QScrollBar::valueChanged, this, &MapView::setViewports);
|
||||||
|
connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &MapView::setViewports);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapView::cameraChanged(const QPointF & pos)
|
void MapView::cameraChanged(const QPointF & pos)
|
||||||
@@ -71,6 +73,11 @@ void MapView::setController(MapController * ctrl)
|
|||||||
controller = ctrl;
|
controller = ctrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapView::resizeEvent(QResizeEvent * event)
|
||||||
|
{
|
||||||
|
setViewports();
|
||||||
|
}
|
||||||
|
|
||||||
void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
||||||
{
|
{
|
||||||
this->update();
|
this->update();
|
||||||
@@ -96,24 +103,24 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
|||||||
{
|
{
|
||||||
case MapView::SelectionTool::Brush:
|
case MapView::SelectionTool::Brush:
|
||||||
if(mouseEvent->buttons() & Qt::RightButton)
|
if(mouseEvent->buttons() & Qt::RightButton)
|
||||||
sc->selectionTerrainView.erase(tile);
|
sc->selectionTerrainView.erase({tile});
|
||||||
else if(mouseEvent->buttons() == Qt::LeftButton)
|
else if(mouseEvent->buttons() == Qt::LeftButton)
|
||||||
sc->selectionTerrainView.select(tile);
|
sc->selectionTerrainView.select({tile});
|
||||||
sc->selectionTerrainView.draw();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MapView::SelectionTool::Brush2:
|
case MapView::SelectionTool::Brush2:
|
||||||
{
|
{
|
||||||
std::array<int3, 4> extra{ int3{0, 0, 0}, int3{1, 0, 0}, int3{0, 1, 0}, int3{1, 1, 0} };
|
std::array<int3, 4> extra{ int3{0, 0, 0}, int3{1, 0, 0}, int3{0, 1, 0}, int3{1, 1, 0} };
|
||||||
|
std::vector<int3> tiles;
|
||||||
for(auto & e : extra)
|
for(auto & e : extra)
|
||||||
{
|
{
|
||||||
if(mouseEvent->buttons() & Qt::RightButton)
|
tiles.push_back(tile + e);
|
||||||
sc->selectionTerrainView.erase(tile + e);
|
|
||||||
else if(mouseEvent->buttons() == Qt::LeftButton)
|
|
||||||
sc->selectionTerrainView.select(tile + e);
|
|
||||||
}
|
}
|
||||||
|
if(mouseEvent->buttons() & Qt::RightButton)
|
||||||
|
sc->selectionTerrainView.erase(tiles);
|
||||||
|
else if(mouseEvent->buttons() == Qt::LeftButton)
|
||||||
|
sc->selectionTerrainView.select(tiles);
|
||||||
}
|
}
|
||||||
sc->selectionTerrainView.draw();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MapView::SelectionTool::Brush4:
|
case MapView::SelectionTool::Brush4:
|
||||||
@@ -124,33 +131,37 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
|||||||
int3{-1, 1, 0}, int3{0, 1, 0}, int3{1, 1, 0}, int3{2, 1, 0},
|
int3{-1, 1, 0}, int3{0, 1, 0}, int3{1, 1, 0}, int3{2, 1, 0},
|
||||||
int3{-1, 2, 0}, int3{0, 2, 0}, int3{1, 2, 0}, int3{2, 2, 0}
|
int3{-1, 2, 0}, int3{0, 2, 0}, int3{1, 2, 0}, int3{2, 2, 0}
|
||||||
};
|
};
|
||||||
|
std::vector<int3> tiles;
|
||||||
for(auto & e : extra)
|
for(auto & e : extra)
|
||||||
{
|
{
|
||||||
if(mouseEvent->buttons() & Qt::RightButton)
|
tiles.push_back(tile + e);
|
||||||
sc->selectionTerrainView.erase(tile + e);
|
|
||||||
else if(mouseEvent->buttons() == Qt::LeftButton)
|
|
||||||
sc->selectionTerrainView.select(tile + e);
|
|
||||||
}
|
}
|
||||||
|
if(mouseEvent->buttons() & Qt::RightButton)
|
||||||
|
sc->selectionTerrainView.erase(tiles);
|
||||||
|
else if(mouseEvent->buttons() == Qt::LeftButton)
|
||||||
|
sc->selectionTerrainView.select(tiles);
|
||||||
}
|
}
|
||||||
sc->selectionTerrainView.draw();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MapView::SelectionTool::Area:
|
case MapView::SelectionTool::Area:
|
||||||
|
{
|
||||||
if(mouseEvent->buttons() & Qt::RightButton || !(mouseEvent->buttons() & Qt::LeftButton))
|
if(mouseEvent->buttons() & Qt::RightButton || !(mouseEvent->buttons() & Qt::LeftButton))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
sc->selectionTerrainView.clear();
|
sc->selectionTerrainView.clear();
|
||||||
|
std::vector<int3> selectedTiles;
|
||||||
for(int j = std::min(tile.y, tileStart.y); j < std::max(tile.y, tileStart.y); ++j)
|
for(int j = std::min(tile.y, tileStart.y); j < std::max(tile.y, tileStart.y); ++j)
|
||||||
{
|
{
|
||||||
for(int i = std::min(tile.x, tileStart.x); i < std::max(tile.x, tileStart.x); ++i)
|
for(int i = std::min(tile.x, tileStart.x); i < std::max(tile.x, tileStart.x); ++i)
|
||||||
{
|
{
|
||||||
sc->selectionTerrainView.select(int3(i, j, sc->level));
|
selectedTiles.emplace_back(i, j, sc->level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sc->selectionTerrainView.draw();
|
sc->selectionTerrainView.select(selectedTiles);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case MapView::SelectionTool::Line:
|
case MapView::SelectionTool::Line:
|
||||||
|
{
|
||||||
{
|
{
|
||||||
assert(tile.z == tileStart.z);
|
assert(tile.z == tileStart.z);
|
||||||
const auto diff = tile - tileStart;
|
const auto diff = tile - tileStart;
|
||||||
@@ -174,39 +185,45 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
|||||||
|
|
||||||
if(mouseEvent->buttons() == Qt::LeftButton)
|
if(mouseEvent->buttons() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
for(auto & ts : temporaryTiles)
|
std::vector<int3>erasedTiles(temporaryTiles.begin(), temporaryTiles.end());
|
||||||
sc->selectionTerrainView.erase(ts);
|
sc->selectionTerrainView.erase(erasedTiles);
|
||||||
|
|
||||||
|
std::vector<int3>selectedTiles;
|
||||||
for(auto ts = tileStart; ts.dist2d(tileStart) < edge; ts += dir)
|
for(auto ts = tileStart; ts.dist2d(tileStart) < edge; ts += dir)
|
||||||
{
|
{
|
||||||
if(!controller->map()->isInTheMap(ts))
|
if(!controller->map()->isInTheMap(ts))
|
||||||
break;
|
break;
|
||||||
if(!sc->selectionTerrainView.selection().count(ts))
|
if(!sc->selectionTerrainView.selection().count(ts))
|
||||||
temporaryTiles.insert(ts);
|
temporaryTiles.insert(ts);
|
||||||
sc->selectionTerrainView.select(ts);
|
selectedTiles.push_back(ts);
|
||||||
}
|
}
|
||||||
|
sc->selectionTerrainView.select(selectedTiles);
|
||||||
}
|
}
|
||||||
if(mouseEvent->buttons() == Qt::RightButton)
|
if(mouseEvent->buttons() == Qt::RightButton)
|
||||||
{
|
{
|
||||||
for(auto & ts : temporaryTiles)
|
std::vector<int3>selectedTiles(temporaryTiles.begin(), temporaryTiles.end());
|
||||||
sc->selectionTerrainView.select(ts);
|
sc->selectionTerrainView.select(selectedTiles);
|
||||||
|
|
||||||
|
std::vector<int3>erasedTiles;
|
||||||
for(auto ts = tileStart; ts.dist2d(tileStart) < edge; ts += dir)
|
for(auto ts = tileStart; ts.dist2d(tileStart) < edge; ts += dir)
|
||||||
{
|
{
|
||||||
if(!controller->map()->isInTheMap(ts))
|
if(!controller->map()->isInTheMap(ts))
|
||||||
break;
|
break;
|
||||||
if(sc->selectionTerrainView.selection().count(ts))
|
if(sc->selectionTerrainView.selection().count(ts))
|
||||||
temporaryTiles.insert(ts);
|
temporaryTiles.insert(ts);
|
||||||
sc->selectionTerrainView.erase(ts);
|
erasedTiles.push_back(ts);
|
||||||
}
|
}
|
||||||
|
sc->selectionTerrainView.erase(selectedTiles);
|
||||||
}
|
}
|
||||||
sc->selectionTerrainView.draw();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case MapView::SelectionTool::Lasso:
|
case MapView::SelectionTool::Lasso:
|
||||||
|
{
|
||||||
if(mouseEvent->buttons() == Qt::LeftButton)
|
if(mouseEvent->buttons() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
|
std::vector<int3>tiles;
|
||||||
for(auto i = tilePrev; i != tile;)
|
for(auto i = tilePrev; i != tile;)
|
||||||
{
|
{
|
||||||
int length = std::numeric_limits<int>::max();
|
int length = std::numeric_limits<int>::max();
|
||||||
@@ -220,18 +237,19 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
i += dir;
|
i += dir;
|
||||||
sc->selectionTerrainView.select(i);
|
tiles.push_back(i);
|
||||||
}
|
}
|
||||||
sc->selectionTerrainView.draw();
|
sc->selectionTerrainView.select(tiles);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case MapView::SelectionTool::None:
|
case MapView::SelectionTool::None:
|
||||||
if(mouseEvent->buttons() & Qt::RightButton)
|
if(mouseEvent->buttons() & Qt::RightButton)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
auto sh = tile - tileStart;
|
auto sh = tile - tileStart;
|
||||||
sc->selectionObjectsView.shift = QPoint(sh.x, sh.y);
|
sc->selectionObjectsView.setShift(sh.x, sh.y);
|
||||||
|
|
||||||
if(sh.x || sh.y)
|
if(sh.x || sh.y)
|
||||||
{
|
{
|
||||||
@@ -244,8 +262,6 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sc->selectionObjectsView.draw();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,34 +292,31 @@ void MapView::mousePressEvent(QMouseEvent *event)
|
|||||||
case MapView::SelectionTool::Brush:
|
case MapView::SelectionTool::Brush:
|
||||||
case MapView::SelectionTool::Line:
|
case MapView::SelectionTool::Line:
|
||||||
sc->selectionObjectsView.clear();
|
sc->selectionObjectsView.clear();
|
||||||
sc->selectionObjectsView.draw();
|
|
||||||
|
|
||||||
if(event->button() == Qt::RightButton)
|
if(event->button() == Qt::RightButton)
|
||||||
sc->selectionTerrainView.erase(tileStart);
|
sc->selectionTerrainView.erase({tileStart});
|
||||||
else if(event->button() == Qt::LeftButton)
|
else if(event->button() == Qt::LeftButton)
|
||||||
sc->selectionTerrainView.select(tileStart);
|
sc->selectionTerrainView.select({tileStart});
|
||||||
sc->selectionTerrainView.draw();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MapView::SelectionTool::Brush2:
|
case MapView::SelectionTool::Brush2:
|
||||||
sc->selectionObjectsView.clear();
|
sc->selectionObjectsView.clear();
|
||||||
sc->selectionObjectsView.draw();
|
|
||||||
{
|
{
|
||||||
std::array<int3, 4> extra{ int3{0, 0, 0}, int3{1, 0, 0}, int3{0, 1, 0}, int3{1, 1, 0} };
|
std::array<int3, 4> extra{ int3{0, 0, 0}, int3{1, 0, 0}, int3{0, 1, 0}, int3{1, 1, 0} };
|
||||||
|
std::vector<int3> tiles;
|
||||||
for(auto & e : extra)
|
for(auto & e : extra)
|
||||||
{
|
{
|
||||||
if(event->button() == Qt::RightButton)
|
tiles.push_back(tileStart + e);
|
||||||
sc->selectionTerrainView.erase(tileStart + e);
|
|
||||||
else if(event->button() == Qt::LeftButton)
|
|
||||||
sc->selectionTerrainView.select(tileStart + e);
|
|
||||||
}
|
}
|
||||||
|
if(event->buttons() & Qt::RightButton)
|
||||||
|
sc->selectionTerrainView.erase(tiles);
|
||||||
|
else if(event->buttons() == Qt::LeftButton)
|
||||||
|
sc->selectionTerrainView.select(tiles);
|
||||||
}
|
}
|
||||||
sc->selectionTerrainView.draw();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MapView::SelectionTool::Brush4:
|
case MapView::SelectionTool::Brush4:
|
||||||
sc->selectionObjectsView.clear();
|
sc->selectionObjectsView.clear();
|
||||||
sc->selectionObjectsView.draw();
|
|
||||||
{
|
{
|
||||||
std::array<int3, 16> extra{
|
std::array<int3, 16> extra{
|
||||||
int3{-1, -1, 0}, int3{0, -1, 0}, int3{1, -1, 0}, int3{2, -1, 0},
|
int3{-1, -1, 0}, int3{0, -1, 0}, int3{1, -1, 0}, int3{2, -1, 0},
|
||||||
@@ -311,15 +324,16 @@ void MapView::mousePressEvent(QMouseEvent *event)
|
|||||||
int3{-1, 1, 0}, int3{0, 1, 0}, int3{1, 1, 0}, int3{2, 1, 0},
|
int3{-1, 1, 0}, int3{0, 1, 0}, int3{1, 1, 0}, int3{2, 1, 0},
|
||||||
int3{-1, 2, 0}, int3{0, 2, 0}, int3{1, 2, 0}, int3{2, 2, 0}
|
int3{-1, 2, 0}, int3{0, 2, 0}, int3{1, 2, 0}, int3{2, 2, 0}
|
||||||
};
|
};
|
||||||
|
std::vector<int3> tiles;
|
||||||
for(auto & e : extra)
|
for(auto & e : extra)
|
||||||
{
|
{
|
||||||
if(event->button() == Qt::RightButton)
|
tiles.push_back(tileStart + e);
|
||||||
sc->selectionTerrainView.erase(tileStart + e);
|
|
||||||
else if(event->button() == Qt::LeftButton)
|
|
||||||
sc->selectionTerrainView.select(tileStart + e);
|
|
||||||
}
|
}
|
||||||
|
if(event->buttons() & Qt::RightButton)
|
||||||
|
sc->selectionTerrainView.erase(tiles);
|
||||||
|
else if(event->buttons() == Qt::LeftButton)
|
||||||
|
sc->selectionTerrainView.select(tiles);
|
||||||
}
|
}
|
||||||
sc->selectionTerrainView.draw();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MapView::SelectionTool::Area:
|
case MapView::SelectionTool::Area:
|
||||||
@@ -328,63 +342,63 @@ void MapView::mousePressEvent(QMouseEvent *event)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
sc->selectionTerrainView.clear();
|
sc->selectionTerrainView.clear();
|
||||||
sc->selectionTerrainView.draw();
|
|
||||||
sc->selectionObjectsView.clear();
|
sc->selectionObjectsView.clear();
|
||||||
sc->selectionObjectsView.draw();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MapView::SelectionTool::Fill:
|
case MapView::SelectionTool::Fill:
|
||||||
{
|
{
|
||||||
if(event->button() != Qt::RightButton && event->button() != Qt::LeftButton)
|
if(event->button() != Qt::RightButton && event->button() != Qt::LeftButton)
|
||||||
break;
|
|
||||||
|
|
||||||
std::vector<int3> queue;
|
|
||||||
queue.push_back(tileStart);
|
|
||||||
|
|
||||||
const std::array<int3, 4> dirs{ int3{1, 0, 0}, int3{-1, 0, 0}, int3{0, 1, 0}, int3{0, -1, 0} };
|
|
||||||
|
|
||||||
while(!queue.empty())
|
|
||||||
{
|
|
||||||
auto tile = queue.back();
|
|
||||||
queue.pop_back();
|
|
||||||
if(event->button() == Qt::LeftButton)
|
|
||||||
sc->selectionTerrainView.select(tile);
|
|
||||||
else
|
|
||||||
sc->selectionTerrainView.erase(tile);
|
|
||||||
for(auto & d : dirs)
|
|
||||||
{
|
|
||||||
auto tilen = tile + d;
|
|
||||||
if(!controller->map()->isInTheMap(tilen))
|
|
||||||
continue;
|
|
||||||
if(event->button() == Qt::LeftButton)
|
|
||||||
{
|
|
||||||
if(controller->map()->getTile(tile).roadType
|
|
||||||
&& controller->map()->getTile(tile).roadType != controller->map()->getTile(tilen).roadType)
|
|
||||||
continue;
|
|
||||||
else if(controller->map()->getTile(tile).riverType
|
|
||||||
&& controller->map()->getTile(tile).riverType != controller->map()->getTile(tilen).riverType)
|
|
||||||
continue;
|
|
||||||
else if(controller->map()->getTile(tile).terrainType != controller->map()->getTile(tilen).terrainType)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(event->button() == Qt::LeftButton && sc->selectionTerrainView.selection().count(tilen))
|
|
||||||
continue;
|
|
||||||
if(event->button() == Qt::RightButton && !sc->selectionTerrainView.selection().count(tilen))
|
|
||||||
continue;
|
|
||||||
queue.push_back(tilen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sc->selectionTerrainView.draw();
|
|
||||||
sc->selectionObjectsView.clear();
|
|
||||||
sc->selectionObjectsView.draw();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
std::vector<int3> queue;
|
||||||
|
std::set<int3> tilesToFill;
|
||||||
|
queue.push_back(tileStart);
|
||||||
|
|
||||||
|
const std::array<int3, 4> dirs{ int3{1, 0, 0}, int3{-1, 0, 0}, int3{0, 1, 0}, int3{0, -1, 0} };
|
||||||
|
|
||||||
|
while(!queue.empty())
|
||||||
|
{
|
||||||
|
auto tile = queue.back();
|
||||||
|
queue.pop_back();
|
||||||
|
tilesToFill.insert(tile);
|
||||||
|
for(auto & d : dirs)
|
||||||
|
{
|
||||||
|
auto tilen = tile + d;
|
||||||
|
if (tilesToFill.count(tilen))
|
||||||
|
continue;
|
||||||
|
if(!controller->map()->isInTheMap(tilen))
|
||||||
|
continue;
|
||||||
|
if(event->button() == Qt::LeftButton)
|
||||||
|
{
|
||||||
|
if(controller->map()->getTile(tile).roadType
|
||||||
|
&& controller->map()->getTile(tile).roadType != controller->map()->getTile(tilen).roadType)
|
||||||
|
continue;
|
||||||
|
else if(controller->map()->getTile(tile).riverType
|
||||||
|
&& controller->map()->getTile(tile).riverType != controller->map()->getTile(tilen).riverType)
|
||||||
|
continue;
|
||||||
|
else if(controller->map()->getTile(tile).terrainType != controller->map()->getTile(tilen).terrainType)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(event->button() == Qt::LeftButton && sc->selectionTerrainView.selection().count(tilen))
|
||||||
|
continue;
|
||||||
|
if(event->button() == Qt::RightButton && !sc->selectionTerrainView.selection().count(tilen))
|
||||||
|
continue;
|
||||||
|
queue.push_back(tilen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
std::vector<int3> result(tilesToFill.begin(), tilesToFill.end());
|
||||||
|
|
||||||
|
if(event->button() == Qt::LeftButton)
|
||||||
|
sc->selectionTerrainView.select(result);
|
||||||
|
else
|
||||||
|
sc->selectionTerrainView.erase(result);
|
||||||
|
|
||||||
|
sc->selectionObjectsView.clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case MapView::SelectionTool::None:
|
case MapView::SelectionTool::None:
|
||||||
sc->selectionTerrainView.clear();
|
sc->selectionTerrainView.clear();
|
||||||
sc->selectionTerrainView.draw();
|
|
||||||
|
|
||||||
if(sc->selectionObjectsView.newObject && sc->selectionObjectsView.isSelected(sc->selectionObjectsView.newObject.get()))
|
if(sc->selectionObjectsView.newObject && sc->selectionObjectsView.isSelected(sc->selectionObjectsView.newObject.get()))
|
||||||
{
|
{
|
||||||
@@ -426,15 +440,14 @@ void MapView::mousePressEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
sc->selectionObjectsView.clear();
|
sc->selectionObjectsView.clear();
|
||||||
sc->selectionObjectsView.selectionMode = SelectionObjectsLayer::SELECTION;
|
sc->selectionObjectsView.selectionMode = SelectionObjectsLayer::SELECTION;
|
||||||
|
|
||||||
if(!rubberBand)
|
if(!rubberBand)
|
||||||
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
|
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
|
||||||
rubberBand->setGeometry(QRect(mapFromScene(mouseStart), QSize()));
|
rubberBand->setGeometry(QRect(mapFromScene(mouseStart), QSize()));
|
||||||
rubberBand->show();
|
rubberBand->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sc->selectionObjectsView.shift = QPoint(0, 0);
|
sc->selectionObjectsView.setShift(0, 0);
|
||||||
sc->selectionObjectsView.draw();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -474,7 +487,7 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
case MapView::SelectionTool::Lasso: {
|
case MapView::SelectionTool::Lasso: {
|
||||||
if(event->button() == Qt::RightButton)
|
if(event->button() == Qt::RightButton)
|
||||||
break;
|
break;
|
||||||
|
std::vector<int3>initialTiles;
|
||||||
//connect with initial tile
|
//connect with initial tile
|
||||||
for(auto i = tilePrev; i != tileStart;)
|
for(auto i = tilePrev; i != tileStart;)
|
||||||
{
|
{
|
||||||
@@ -489,9 +502,10 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
i += dir;
|
i += dir;
|
||||||
sc->selectionTerrainView.select(i);
|
initialTiles.push_back(i);
|
||||||
}
|
}
|
||||||
|
sc->selectionTerrainView.select(initialTiles);
|
||||||
|
|
||||||
//key: y position of tile
|
//key: y position of tile
|
||||||
//value.first: x position of left tile
|
//value.first: x position of left tile
|
||||||
//value.second: x postiion of right tile
|
//value.second: x postiion of right tile
|
||||||
@@ -532,10 +546,8 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
selectionByY.insert(int3(selectionRange.first, i, sc->level));
|
selectionByY.insert(int3(selectionRange.first, i, sc->level));
|
||||||
}
|
}
|
||||||
std::set_intersection(selectionByX.begin(), selectionByX.end(), selectionByY.begin(), selectionByY.end(), std::back_inserter(finalSelection));
|
std::set_intersection(selectionByX.begin(), selectionByX.end(), selectionByY.begin(), selectionByY.end(), std::back_inserter(finalSelection));
|
||||||
for(auto & lassoTile : finalSelection)
|
sc->selectionTerrainView.select(finalSelection);
|
||||||
sc->selectionTerrainView.select(lassoTile);
|
|
||||||
|
|
||||||
sc->selectionTerrainView.draw();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,8 +568,7 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
sc->selectionObjectsView.selectionMode = SelectionObjectsLayer::NOTHING;
|
sc->selectionObjectsView.selectionMode = SelectionObjectsLayer::NOTHING;
|
||||||
sc->selectionObjectsView.shift = QPoint(0, 0);
|
sc->selectionObjectsView.setShift(0, 0);
|
||||||
sc->selectionObjectsView.draw();
|
|
||||||
tab = true;
|
tab = true;
|
||||||
}
|
}
|
||||||
auto selection = sc->selectionObjectsView.getSelection();
|
auto selection = sc->selectionObjectsView.getSelection();
|
||||||
@@ -642,10 +653,9 @@ void MapView::dragMoveEvent(QDragMoveEvent * event)
|
|||||||
|
|
||||||
if(sc->selectionObjectsView.newObject)
|
if(sc->selectionObjectsView.newObject)
|
||||||
{
|
{
|
||||||
sc->selectionObjectsView.shift = QPoint(tile.x, tile.y);
|
|
||||||
sc->selectionObjectsView.selectObject(sc->selectionObjectsView.newObject.get());
|
|
||||||
sc->selectionObjectsView.selectionMode = SelectionObjectsLayer::MOVEMENT;
|
sc->selectionObjectsView.selectionMode = SelectionObjectsLayer::MOVEMENT;
|
||||||
sc->selectionObjectsView.draw();
|
sc->selectionObjectsView.selectObject(sc->selectionObjectsView.newObject.get());
|
||||||
|
sc->selectionObjectsView.setShift(tile.x, tile.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
@@ -655,23 +665,25 @@ void MapView::dragLeaveEvent(QDragLeaveEvent * event)
|
|||||||
{
|
{
|
||||||
if(!controller || !controller->map())
|
if(!controller || !controller->map())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto * sc = static_cast<MapScene*>(scene());
|
auto * sc = static_cast<MapScene*>(scene());
|
||||||
if(!sc)
|
if(!sc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
controller->discardObject(sc->level);
|
controller->discardObject(sc->level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapView::setViewports()
|
||||||
bool MapView::viewportEvent(QEvent *event)
|
|
||||||
{
|
{
|
||||||
if(auto * sc = static_cast<MapScene*>(scene()))
|
if(auto * sc = dynamic_cast<MapScene*>(scene()))
|
||||||
{
|
{
|
||||||
auto rect = mapToScene(viewport()->geometry()).boundingRect();
|
auto rect = mapToScene(viewport()->geometry()).boundingRect();
|
||||||
controller->miniScene(sc->level)->viewport.setViewport(rect.x() / 32, rect.y() / 32, rect.width() / 32, rect.height() / 32);
|
controller->miniScene(sc->level)->viewport.setViewport(rect.x() / 32, rect.y() / 32, rect.width() / 32, rect.height() / 32);
|
||||||
|
for (auto * layer : sc->getDynamicLayers())
|
||||||
|
{
|
||||||
|
layer->setViewport(rect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return QGraphicsView::viewportEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MapSceneBase::MapSceneBase(int lvl):
|
MapSceneBase::MapSceneBase(int lvl):
|
||||||
@@ -682,18 +694,31 @@ MapSceneBase::MapSceneBase(int lvl):
|
|||||||
|
|
||||||
void MapSceneBase::initialize(MapController & controller)
|
void MapSceneBase::initialize(MapController & controller)
|
||||||
{
|
{
|
||||||
for(auto * layer : getAbstractLayers())
|
for(auto * layer : getStaticLayers())
|
||||||
|
layer->initialize(controller);
|
||||||
|
for(auto * layer : getDynamicLayers())
|
||||||
layer->initialize(controller);
|
layer->initialize(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapSceneBase::updateViews()
|
void MapSceneBase::createMap()
|
||||||
{
|
{
|
||||||
for(auto * layer : getAbstractLayers())
|
for(auto * layer : getStaticLayers())
|
||||||
layer->update();
|
layer->update();
|
||||||
|
for(auto * layer : getDynamicLayers())
|
||||||
|
layer->createLayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapSceneBase::updateMap()
|
||||||
|
{
|
||||||
|
for(auto * layer : getStaticLayers())
|
||||||
|
layer->update();
|
||||||
|
for(auto * layer : getDynamicLayers())
|
||||||
|
layer->redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
MapScene::MapScene(int lvl):
|
MapScene::MapScene(int lvl):
|
||||||
MapSceneBase(lvl),
|
MapSceneBase(lvl),
|
||||||
|
emptyLayer(this),
|
||||||
gridView(this),
|
gridView(this),
|
||||||
passabilityView(this),
|
passabilityView(this),
|
||||||
selectionTerrainView(this),
|
selectionTerrainView(this),
|
||||||
@@ -708,7 +733,14 @@ MapScene::MapScene(int lvl):
|
|||||||
connect(&selectionObjectsView, &SelectionObjectsLayer::selectionMade, this, &MapScene::objectSelected);
|
connect(&selectionObjectsView, &SelectionObjectsLayer::selectionMade, this, &MapScene::objectSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<AbstractLayer *> MapScene::getAbstractLayers()
|
std::list<AbstractFixedLayer *> MapScene::getStaticLayers()
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
&emptyLayer
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<AbstractViewportLayer *> MapScene::getDynamicLayers()
|
||||||
{
|
{
|
||||||
//sequence is important because it defines rendering order
|
//sequence is important because it defines rendering order
|
||||||
return {
|
return {
|
||||||
@@ -722,9 +754,9 @@ std::list<AbstractLayer *> MapScene::getAbstractLayers()
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapScene::updateViews()
|
void MapScene::createMap()
|
||||||
{
|
{
|
||||||
MapSceneBase::updateViews();
|
MapSceneBase::createMap();
|
||||||
|
|
||||||
terrainView.show(true);
|
terrainView.show(true);
|
||||||
objectsView.show(true);
|
objectsView.show(true);
|
||||||
@@ -752,7 +784,7 @@ MinimapScene::MinimapScene(int lvl):
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<AbstractLayer *> MinimapScene::getAbstractLayers()
|
std::list<AbstractFixedLayer *> MinimapScene::getStaticLayers()
|
||||||
{
|
{
|
||||||
//sequence is important because it defines rendering order
|
//sequence is important because it defines rendering order
|
||||||
return {
|
return {
|
||||||
@@ -761,10 +793,16 @@ std::list<AbstractLayer *> MinimapScene::getAbstractLayers()
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinimapScene::updateViews()
|
std::list<AbstractViewportLayer *> MinimapScene::getDynamicLayers()
|
||||||
{
|
{
|
||||||
MapSceneBase::updateViews();
|
//Nothing here
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinimapScene::createMap()
|
||||||
|
{
|
||||||
|
MapSceneBase::createMap();
|
||||||
|
|
||||||
minimapView.show(true);
|
minimapView.show(true);
|
||||||
viewport.show(true);
|
viewport.show(true);
|
||||||
}
|
}
|
||||||
|
@@ -31,12 +31,11 @@ public:
|
|||||||
MapSceneBase(int lvl);
|
MapSceneBase(int lvl);
|
||||||
|
|
||||||
const int level;
|
const int level;
|
||||||
|
virtual void createMap();
|
||||||
virtual void updateViews();
|
virtual void updateMap();
|
||||||
virtual void initialize(MapController &);
|
virtual void initialize(MapController &);
|
||||||
|
virtual std::list<AbstractFixedLayer *> getStaticLayers() = 0;
|
||||||
protected:
|
virtual std::list<AbstractViewportLayer *> getDynamicLayers() = 0;
|
||||||
virtual std::list<AbstractLayer *> getAbstractLayers() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MinimapScene : public MapSceneBase
|
class MinimapScene : public MapSceneBase
|
||||||
@@ -44,13 +43,12 @@ class MinimapScene : public MapSceneBase
|
|||||||
public:
|
public:
|
||||||
MinimapScene(int lvl);
|
MinimapScene(int lvl);
|
||||||
|
|
||||||
void updateViews() override;
|
void createMap() override;
|
||||||
|
|
||||||
MinimapLayer minimapView;
|
MinimapLayer minimapView;
|
||||||
MinimapViewLayer viewport;
|
MinimapViewLayer viewport;
|
||||||
|
std::list<AbstractFixedLayer *> getStaticLayers() override;
|
||||||
protected:
|
std::list<AbstractViewportLayer *> getDynamicLayers() override;
|
||||||
std::list<AbstractLayer *> getAbstractLayers() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MapScene : public MapSceneBase
|
class MapScene : public MapSceneBase
|
||||||
@@ -59,8 +57,11 @@ class MapScene : public MapSceneBase
|
|||||||
public:
|
public:
|
||||||
MapScene(int lvl);
|
MapScene(int lvl);
|
||||||
|
|
||||||
void updateViews() override;
|
void createMap() override;
|
||||||
|
std::list<AbstractFixedLayer *> getStaticLayers() override;
|
||||||
|
std::list<AbstractViewportLayer *> getDynamicLayers() override;
|
||||||
|
|
||||||
|
EmptyLayer emptyLayer;
|
||||||
GridLayer gridView;
|
GridLayer gridView;
|
||||||
PassabilityLayer passabilityView;
|
PassabilityLayer passabilityView;
|
||||||
SelectionTerrainLayer selectionTerrainView;
|
SelectionTerrainLayer selectionTerrainView;
|
||||||
@@ -75,10 +76,8 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
void terrainSelected(bool anything);
|
void terrainSelected(bool anything);
|
||||||
void objectSelected(bool anything);
|
void objectSelected(bool anything);
|
||||||
|
|
||||||
protected:
|
|
||||||
std::list<AbstractLayer *> getAbstractLayers() override;
|
|
||||||
|
|
||||||
|
protected:
|
||||||
bool isTerrainSelected;
|
bool isTerrainSelected;
|
||||||
bool isObjectSelected;
|
bool isObjectSelected;
|
||||||
|
|
||||||
@@ -100,6 +99,7 @@ public:
|
|||||||
SelectionTool selectionTool;
|
SelectionTool selectionTool;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void resizeEvent (QResizeEvent * event) override;
|
||||||
void mouseMoveEvent(QMouseEvent * mouseEvent) override;
|
void mouseMoveEvent(QMouseEvent * mouseEvent) override;
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
@@ -107,8 +107,8 @@ public slots:
|
|||||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||||
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||||
void dropEvent(QDropEvent * event) override;
|
void dropEvent(QDropEvent * event) override;
|
||||||
|
|
||||||
void cameraChanged(const QPointF & pos);
|
void cameraChanged(const QPointF & pos);
|
||||||
|
void setViewports();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void openObjectProperties(CGObjectInstance *, bool switchTab);
|
void openObjectProperties(CGObjectInstance *, bool switchTab);
|
||||||
@@ -116,7 +116,6 @@ signals:
|
|||||||
//void viewportChanged(const QRectF & rect);
|
//void viewportChanged(const QRectF & rect);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool viewportEvent(QEvent *event) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MapController * controller = nullptr;
|
MapController * controller = nullptr;
|
||||||
|
@@ -29,15 +29,32 @@ void AbstractLayer::initialize(MapController & controller)
|
|||||||
|
|
||||||
void AbstractLayer::show(bool show)
|
void AbstractLayer::show(bool show)
|
||||||
{
|
{
|
||||||
if(isShown == show)
|
|
||||||
return;
|
|
||||||
|
|
||||||
isShown = show;
|
isShown = show;
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractLayer::redraw()
|
|
||||||
|
int AbstractLayer::mapWidthPx() const
|
||||||
|
{
|
||||||
|
return map ? map->width * tileSize : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AbstractLayer::mapHeightPx() const
|
||||||
|
{
|
||||||
|
return map ? map->height * tileSize : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AbstractLayer::toInt(double value) const
|
||||||
|
{
|
||||||
|
return static_cast<int>(std::round(value)); // is rounded explicitly in order to avoid rounding down unprecise double values
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractFixedLayer::AbstractFixedLayer(MapSceneBase * s): AbstractLayer(s)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractFixedLayer::redraw()
|
||||||
{
|
{
|
||||||
if(item)
|
if(item)
|
||||||
{
|
{
|
||||||
@@ -55,65 +72,284 @@ void AbstractLayer::redraw()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GridLayer::GridLayer(MapSceneBase * s): AbstractLayer(s)
|
AbstractViewportLayer::AbstractViewportLayer(MapSceneBase * s): AbstractLayer(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridLayer::update()
|
void AbstractViewportLayer::createLayer()
|
||||||
|
{
|
||||||
|
QList<QGraphicsItem *>emptyList;
|
||||||
|
items.reset(scene->createItemGroup(emptyList));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractViewportLayer::setViewport(const QRectF & viewPort)
|
||||||
{
|
{
|
||||||
if(!map)
|
if(!map)
|
||||||
return;
|
return;
|
||||||
|
if (items->boundingRect().contains(viewPort))
|
||||||
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
return;
|
||||||
pixmap->fill(Qt::transparent);
|
|
||||||
QPainter painter(pixmap.get());
|
std::vector<QGraphicsItem *> outOfScreenSectors;
|
||||||
painter.setPen(QColor(0, 0, 0, 190));
|
for (QGraphicsItem * sector : getAllSectors())
|
||||||
|
|
||||||
for(int j = 0; j < map->height; ++j)
|
|
||||||
{
|
{
|
||||||
painter.drawLine(0, j * 32, map->width * 32 - 1, j * 32);
|
if (!viewPort.intersects(sector->sceneBoundingRect()))
|
||||||
|
outOfScreenSectors.push_back(sector);
|
||||||
}
|
}
|
||||||
for(int i = 0; i < map->width; ++i)
|
for (QGraphicsItem * sector : outOfScreenSectors)
|
||||||
{
|
{
|
||||||
painter.drawLine(i * 32, 0, i * 32, map->height * 32 - 1);
|
removeSector(sector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<QRectF> newAreas;
|
||||||
|
|
||||||
|
int left = toInt(viewPort.left());
|
||||||
|
int right = toInt(viewPort.right());
|
||||||
|
int top = toInt(viewPort.top());
|
||||||
|
int bottom = toInt(viewPort.bottom());
|
||||||
|
int startX = left - (left % sectorSize);
|
||||||
|
int limitX = std::min(right + (sectorSize - right % sectorSize), mapWidthPx());
|
||||||
|
int startY = top - (top % sectorSize);
|
||||||
|
int limitY = std::min(bottom + (sectorSize - bottom % sectorSize), mapHeightPx());
|
||||||
|
|
||||||
|
for (int x = startX; x < limitX; x += sectorSize)
|
||||||
|
{
|
||||||
|
for (int y = startY; y < limitY; y += sectorSize)
|
||||||
|
{
|
||||||
|
int width = x + sectorSize < limitX ? sectorSize : limitX - x;
|
||||||
|
int height = y + sectorSize < limitY ? sectorSize : limitY - y;
|
||||||
|
QRectF area(x, y, width, height);
|
||||||
|
if (!items->boundingRect().intersects(area))
|
||||||
|
newAreas.emplace_back(area);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(QRectF newSection : newAreas)
|
||||||
|
{
|
||||||
|
QGraphicsItem * sector = draw(newSection);
|
||||||
|
if (sector)
|
||||||
|
addSector(sector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractViewportLayer::update()
|
||||||
|
{
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
PassabilityLayer::PassabilityLayer(MapSceneBase * s): AbstractLayer(s)
|
void AbstractViewportLayer::redraw()
|
||||||
{
|
{
|
||||||
|
std::set<QGraphicsItem *> allSectors;
|
||||||
|
for (auto * sector : getAllSectors())
|
||||||
|
allSectors.insert(sector);
|
||||||
|
redrawSectors(allSectors);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PassabilityLayer::update()
|
void AbstractViewportLayer::redraw(const std::vector<int3> & tiles)
|
||||||
{
|
{
|
||||||
if(!map)
|
std::set<QGraphicsItem *> sectorsToRedraw = getContainingSectors(tiles);
|
||||||
return;
|
redrawSectors(sectorsToRedraw);
|
||||||
|
}
|
||||||
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
|
||||||
pixmap->fill(Qt::transparent);
|
void AbstractViewportLayer::redrawWithSurroundingTiles(const std::vector<int3> & tiles)
|
||||||
|
{
|
||||||
QPainter painter(pixmap.get());
|
int maxX = 0;
|
||||||
for(int j = 0; j < map->height; ++j)
|
int maxY = 0;
|
||||||
|
int minX = INT_MAX;
|
||||||
|
int minY = INT_MAX;
|
||||||
|
for (const int3 tile : tiles)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < map->width; ++i)
|
maxX = std::max(tile.x, maxX);
|
||||||
|
maxY = std::max(tile.y, maxY);
|
||||||
|
minX = std::min(tile.x, minX);
|
||||||
|
minY = std::min(tile.y, minY);
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF bounds((minX - 2) * tileSize, (minY - 2) * tileSize, (maxX - minX + 4) * tileSize, (maxY - minY + 4) * tileSize); //tiles start with 1, QRectF from 0
|
||||||
|
redraw({bounds});
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractViewportLayer::redraw(const std::set<CGObjectInstance *> & objects)
|
||||||
|
{
|
||||||
|
std::vector<QRectF> areas(objects.size());
|
||||||
|
for (const CGObjectInstance * object : objects)
|
||||||
|
{
|
||||||
|
areas.push_back(getObjectArea(object));
|
||||||
|
}
|
||||||
|
redraw(areas);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractViewportLayer::redraw(const std::vector<QRectF> & areas)
|
||||||
|
{
|
||||||
|
std::set<QGraphicsItem *> intersectingSectors;
|
||||||
|
for (QGraphicsItem * existingSector : getAllSectors())
|
||||||
|
{
|
||||||
|
for (auto area : areas)
|
||||||
{
|
{
|
||||||
auto tl = map->getTile(int3(i, j, scene->level));
|
if (existingSector->sceneBoundingRect().intersects(area))
|
||||||
if(tl.blocked() || tl.visitable())
|
|
||||||
{
|
{
|
||||||
painter.fillRect(i * 32, j * 32, 31, 31, tl.visitable() ? QColor(200, 200, 0, 64) : QColor(255, 0, 0, 64));
|
intersectingSectors.insert(existingSector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
redrawSectors(intersectingSectors);
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF AbstractViewportLayer::getObjectArea(const CGObjectInstance * object)
|
||||||
|
{
|
||||||
|
auto pos = object->pos;
|
||||||
|
int x = ((pos.x + 1) * tileSize) - (object->getWidth() * tileSize); //Qt set 0,0 point on the top right corner, CGObjectInstance on the bottom left
|
||||||
|
int y = ((pos.y + 1) * tileSize) - (object->getHeight() * tileSize);
|
||||||
|
QRectF objectArea(x, y, object->getWidth() * tileSize, object->getHeight() * tileSize);
|
||||||
|
return objectArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractViewportLayer::addSector(QGraphicsItem * sector)
|
||||||
|
{
|
||||||
|
items->addToGroup(sector);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractViewportLayer::removeSector(QGraphicsItem * sector)
|
||||||
|
{
|
||||||
|
items->removeFromGroup(sector);
|
||||||
|
delete sector;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractViewportLayer::redrawSectors(std::set<QGraphicsItem *> & sectors)
|
||||||
|
{
|
||||||
|
std::set<QGraphicsItem *> sectorsToRemove;
|
||||||
|
|
||||||
|
for (QGraphicsItem * existingSectors : getAllSectors())
|
||||||
|
{
|
||||||
|
for (QGraphicsItem * sector : sectors)
|
||||||
|
{
|
||||||
|
if (existingSectors->sceneBoundingRect().contains(sector->sceneBoundingRect()))
|
||||||
|
sectorsToRemove.insert(existingSectors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (QGraphicsItem * sectorToRemove : sectorsToRemove)
|
||||||
|
{
|
||||||
|
addSector(draw(sectorToRemove->sceneBoundingRect()));
|
||||||
|
removeSector(sectorToRemove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<QGraphicsItem *> AbstractViewportLayer::getAllSectors() //returning const is necessary to avoid "range-loop might detach Qt container" problem
|
||||||
|
{
|
||||||
|
QList<QGraphicsItem *> emptyList;
|
||||||
|
return items ? items->childItems() : emptyList;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<QGraphicsItem *> AbstractViewportLayer::getContainingSectors(const std::vector<int3> & tiles)
|
||||||
|
{
|
||||||
|
std::set<QGraphicsItem *> result;
|
||||||
|
for (QGraphicsItem * existingSector : getAllSectors()) {
|
||||||
|
for (const int3 tile : tiles)
|
||||||
|
{
|
||||||
|
if (existingSector->sceneBoundingRect().contains(QPointF(tile.x * tileSize, tile.y * tileSize)))
|
||||||
|
{
|
||||||
|
result.insert(existingSector);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<QGraphicsItem *> AbstractViewportLayer::getIntersectingSectors(const std::vector<QRectF> & areas)
|
||||||
|
{
|
||||||
|
std::set<QGraphicsItem *> result;
|
||||||
|
for (QGraphicsItem * existingSector : getAllSectors()) {
|
||||||
|
for (QRectF area : areas)
|
||||||
|
{
|
||||||
|
if (existingSector->sceneBoundingRect().intersects(area))
|
||||||
|
{
|
||||||
|
result.insert(existingSector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
EmptyLayer::EmptyLayer(MapSceneBase * s): AbstractFixedLayer(s)
|
||||||
|
{
|
||||||
|
isShown = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmptyLayer::update()
|
||||||
|
{
|
||||||
|
if(!map)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pixmap = std::make_unique<QPixmap>(map->width * 32, map->height * 32);
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectPickerLayer::ObjectPickerLayer(MapSceneBase * s): AbstractLayer(s)
|
GridLayer::GridLayer(MapSceneBase * s): AbstractViewportLayer(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectPickerLayer::highlight(std::function<bool(const CGObjectInstance *)> predicate)
|
QGraphicsItem * GridLayer::draw(const QRectF & section)
|
||||||
|
{
|
||||||
|
QPixmap pixmap(toInt(section.width()), toInt(section.height()));
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
if (isShown)
|
||||||
|
{
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
painter.setPen(QColor(0, 0, 0, 190));
|
||||||
|
|
||||||
|
for(int j = 0; j <= pixmap.height(); j += tileSize)
|
||||||
|
{
|
||||||
|
painter.drawLine(0, j, pixmap.width(), j);
|
||||||
|
}
|
||||||
|
for(int i = 0; i <= pixmap.width(); i += tileSize)
|
||||||
|
{
|
||||||
|
painter.drawLine(i, 0, i, pixmap.height());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsItem * result = scene->addPixmap(pixmap);
|
||||||
|
result->setPos(section.x(), section.y());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
PassabilityLayer::PassabilityLayer(MapSceneBase * s): AbstractViewportLayer(s)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsItem * PassabilityLayer::draw(const QRectF & section)
|
||||||
|
{
|
||||||
|
|
||||||
|
QPixmap pixmap(toInt(section.width()), toInt(section.height()));
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
|
||||||
|
if(isShown)
|
||||||
|
{
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
for(int j = 0; j <= pixmap.height(); j += tileSize)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < pixmap.width(); i += tileSize)
|
||||||
|
{
|
||||||
|
auto tl = map->getTile(int3(toInt(section.x())/tileSize + i/tileSize, toInt(section.y())/tileSize + j/tileSize, scene->level));
|
||||||
|
if(tl.blocked() || tl.visitable())
|
||||||
|
{
|
||||||
|
painter.fillRect(i, j, 31, 31, tl.visitable() ? QColor(200, 200, 0, 64) : QColor(255, 0, 0, 64));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsItem * result = scene->addPixmap(pixmap);
|
||||||
|
result->setPos(section.x(), section.y());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectPickerLayer::ObjectPickerLayer(MapSceneBase * s): AbstractViewportLayer(s)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectPickerLayer::highlight(const std::function<bool(const CGObjectInstance *)> & predicate)
|
||||||
{
|
{
|
||||||
if(!map)
|
if(!map)
|
||||||
return;
|
return;
|
||||||
@@ -151,29 +387,33 @@ void ObjectPickerLayer::clear()
|
|||||||
isActive = false;
|
isActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectPickerLayer::update()
|
QGraphicsItem * ObjectPickerLayer::draw(const QRectF & section)
|
||||||
{
|
{
|
||||||
if(!map)
|
|
||||||
return;
|
int offsetX = toInt(section.x());
|
||||||
|
int offsetY = toInt(section.y());
|
||||||
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
QPixmap pixmap(toInt(section.width()), toInt(section.height()));
|
||||||
pixmap->fill(Qt::transparent);
|
pixmap.fill(Qt::transparent);
|
||||||
if(isActive)
|
|
||||||
pixmap->fill(QColor(255, 255, 255, 128));
|
if(isVisible())
|
||||||
|
pixmap.fill(QColor(255, 255, 255, 128));
|
||||||
|
|
||||||
QPainter painter(pixmap.get());
|
|
||||||
|
QPainter painter(&pixmap);
|
||||||
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||||
for(auto * obj : possibleObjects)
|
for(const auto * obj : possibleObjects)
|
||||||
{
|
{
|
||||||
if(obj->pos.z != scene->level)
|
if(obj->pos.z != scene->level)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for(auto & pos : obj->getBlockedPos())
|
for(const auto & pos : obj->getBlockedPos())
|
||||||
painter.fillRect(pos.x * 32, pos.y * 32, 32, 32, QColor(255, 211, 0, 64));
|
painter.fillRect(pos.x * tileSize - offsetX, pos.y * tileSize - offsetY, tileSize, tileSize, QColor(255, 211, 0, 64));
|
||||||
}
|
}
|
||||||
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
|
||||||
redraw();
|
QGraphicsItem * result = scene->addPixmap(pixmap);
|
||||||
|
result->setPos(section.x(), section.y());
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectPickerLayer::select(const CGObjectInstance * obj)
|
void ObjectPickerLayer::select(const CGObjectInstance * obj)
|
||||||
@@ -181,92 +421,73 @@ void ObjectPickerLayer::select(const CGObjectInstance * obj)
|
|||||||
if(obj && possibleObjects.count(obj))
|
if(obj && possibleObjects.count(obj))
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
selectionMade(obj);
|
Q_EMIT selectionMade(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectPickerLayer::discard()
|
void ObjectPickerLayer::discard()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
selectionMade(nullptr);
|
Q_EMIT selectionMade(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectionTerrainLayer::SelectionTerrainLayer(MapSceneBase * s): AbstractLayer(s)
|
SelectionTerrainLayer::SelectionTerrainLayer(MapSceneBase * s): AbstractViewportLayer(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionTerrainLayer::update()
|
QGraphicsItem * SelectionTerrainLayer::draw(const QRectF & section)
|
||||||
{
|
{
|
||||||
if(!map)
|
int offsetX = toInt(section.x());
|
||||||
return;
|
int offsetY = toInt(section.y());
|
||||||
|
QPixmap pixmap(toInt(section.width()), toInt(section.height()));
|
||||||
area.clear();
|
pixmap.fill(Qt::transparent);
|
||||||
areaAdd.clear();
|
|
||||||
areaErase.clear();
|
QPainter painter(&pixmap);
|
||||||
onSelection();
|
|
||||||
|
|
||||||
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
|
||||||
pixmap->fill(Qt::transparent);
|
|
||||||
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SelectionTerrainLayer::draw()
|
|
||||||
{
|
|
||||||
if(!pixmap)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QPainter painter(pixmap.get());
|
|
||||||
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||||
for(auto & t : areaAdd)
|
for(const auto & t : area)
|
||||||
{
|
{
|
||||||
painter.fillRect(t.x * 32, t.y * 32, 31, 31, QColor(128, 128, 128, 96));
|
if(section.contains(t.x * tileSize, t.y * tileSize))
|
||||||
|
painter.fillRect(t.x * tileSize - offsetX, t.y * tileSize - offsetY, 31, 31, QColor(128, 128, 128, 96));
|
||||||
}
|
}
|
||||||
for(auto & t : areaErase)
|
|
||||||
{
|
QGraphicsPixmapItem * result = scene->addPixmap(pixmap);
|
||||||
painter.fillRect(t.x * 32, t.y * 32, 31, 31, QColor(0, 0, 0, 0));
|
result->setPos(section.x(), section.y());
|
||||||
}
|
|
||||||
|
return result;
|
||||||
areaAdd.clear();
|
|
||||||
areaErase.clear();
|
|
||||||
|
|
||||||
redraw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionTerrainLayer::select(const int3 & tile)
|
void SelectionTerrainLayer::select(const std::vector<int3> & tiles)
|
||||||
{
|
{
|
||||||
if(!map || !map->isInTheMap(tile))
|
for (int3 tile : tiles)
|
||||||
return;
|
|
||||||
|
|
||||||
if(!area.count(tile))
|
|
||||||
{
|
{
|
||||||
area.insert(tile);
|
if(!area.count(tile))
|
||||||
areaAdd.insert(tile);
|
{
|
||||||
areaErase.erase(tile);
|
area.insert(tile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
redraw(tiles);
|
||||||
onSelection();
|
onSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionTerrainLayer::erase(const int3 & tile)
|
void SelectionTerrainLayer::erase(const std::vector<int3> & tiles)
|
||||||
{
|
{
|
||||||
if(!map || !map->isInTheMap(tile))
|
for (int3 tile : tiles)
|
||||||
return;
|
|
||||||
|
|
||||||
if(area.count(tile))
|
|
||||||
{
|
{
|
||||||
area.erase(tile);
|
if(area.count(tile))
|
||||||
areaErase.insert(tile);
|
{
|
||||||
areaAdd.erase(tile);
|
area.erase(tile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
redraw(tiles);
|
||||||
onSelection();
|
onSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionTerrainLayer::clear()
|
void SelectionTerrainLayer::clear()
|
||||||
{
|
{
|
||||||
areaErase = area;
|
|
||||||
areaAdd.clear();
|
|
||||||
area.clear();
|
area.clear();
|
||||||
onSelection();
|
onSelection();
|
||||||
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::set<int3> & SelectionTerrainLayer::selection() const
|
const std::set<int3> & SelectionTerrainLayer::selection() const
|
||||||
@@ -276,157 +497,87 @@ const std::set<int3> & SelectionTerrainLayer::selection() const
|
|||||||
|
|
||||||
void SelectionTerrainLayer::onSelection()
|
void SelectionTerrainLayer::onSelection()
|
||||||
{
|
{
|
||||||
selectionMade(!area.empty());
|
Q_EMIT selectionMade(!area.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TerrainLayer::TerrainLayer(MapSceneBase * s): AbstractLayer(s)
|
TerrainLayer::TerrainLayer(MapSceneBase * s): AbstractViewportLayer(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerrainLayer::update()
|
void TerrainLayer::redrawTerrain(const std::vector<int3> & tiles)
|
||||||
{
|
{
|
||||||
if(!map)
|
redrawWithSurroundingTiles(tiles);
|
||||||
return;
|
|
||||||
|
|
||||||
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
|
||||||
draw(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerrainLayer::setDirty(const int3 & tile)
|
QGraphicsItem * TerrainLayer::draw(const QRectF & section)
|
||||||
{
|
{
|
||||||
dirty.insert(tile);
|
int left = toInt(section.left());
|
||||||
}
|
int right = toInt(section.right());
|
||||||
|
int top = toInt(section.top());
|
||||||
|
int bottom = toInt(section.bottom());
|
||||||
|
QPixmap pixmap(toInt(section.width()), toInt(section.height()));
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
|
||||||
void TerrainLayer::draw(bool onlyDirty)
|
QPainter painter(&pixmap);
|
||||||
{
|
|
||||||
if(!pixmap)
|
QPointF offset = section.topLeft();
|
||||||
return;
|
|
||||||
|
for(int x = left/tileSize; x < right/tileSize; ++x)
|
||||||
if(!map)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QPainter painter(pixmap.get());
|
|
||||||
//painter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
||||||
|
|
||||||
if(onlyDirty)
|
|
||||||
{
|
{
|
||||||
std::set<int3> forRedrawing(dirty);
|
for(int y = top/tileSize; y < bottom/tileSize; ++y)
|
||||||
std::set<int3> neighbours;
|
|
||||||
for(auto & t : dirty)
|
|
||||||
{
|
{
|
||||||
for(auto & tt : int3::getDirs())
|
handler->drawTerrainTile(painter, x, y, scene->level, offset);
|
||||||
{
|
handler->drawRiver(painter, x, y, scene->level, offset);
|
||||||
if(map->isInTheMap(t + tt))
|
handler->drawRoad(painter, x, y, scene->level, offset);
|
||||||
neighbours.insert(t + tt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(auto & t : neighbours)
|
|
||||||
{
|
|
||||||
for(auto & tt : int3::getDirs())
|
|
||||||
{
|
|
||||||
forRedrawing.insert(t);
|
|
||||||
if(map->isInTheMap(t + tt))
|
|
||||||
forRedrawing.insert(t + tt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(auto & t : forRedrawing)
|
|
||||||
{
|
|
||||||
handler->drawTerrainTile(painter, t.x, t.y, scene->level);
|
|
||||||
handler->drawRiver(painter, t.x, t.y, scene->level);
|
|
||||||
handler->drawRoad(painter, t.x, t.y, scene->level);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
QGraphicsPixmapItem * result = scene->addPixmap(pixmap);
|
||||||
|
result->setPos(section.x(), section.y());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectsLayer::ObjectsLayer(MapSceneBase * s): AbstractViewportLayer(s)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsItem * ObjectsLayer::draw(const QRectF & section)
|
||||||
|
{
|
||||||
|
int left = toInt(section.left());
|
||||||
|
int right = toInt(section.right());
|
||||||
|
int top = toInt(section.top());
|
||||||
|
int bottom = toInt(section.bottom());
|
||||||
|
QPixmap pixmap(toInt(section.width()), toInt(section.height()));
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
|
||||||
|
if (isShown)
|
||||||
{
|
{
|
||||||
for(int j = 0; j < map->height; ++j)
|
QPainter painter(&pixmap);
|
||||||
|
|
||||||
|
QPointF offset = section.topLeft();
|
||||||
|
|
||||||
|
int margin = 2; // margin is necessary to properly display flags on heroes on a border between two sections
|
||||||
|
|
||||||
|
for(int x = (left - margin)/tileSize; x < (right + margin)/tileSize; ++x)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < map->width; ++i)
|
for(int y = (top - margin)/tileSize; y < (bottom + margin)/tileSize; ++y)
|
||||||
{
|
{
|
||||||
handler->drawTerrainTile(painter, i, j, scene->level);
|
handler->drawObjects(painter, x, y, scene->level, offset, lockedObjects);
|
||||||
handler->drawRiver(painter, i, j, scene->level);
|
|
||||||
handler->drawRoad(painter, i, j, scene->level);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dirty.clear();
|
QGraphicsPixmapItem * result = scene->addPixmap(pixmap);
|
||||||
redraw();
|
result->setPos(section.x(), section.y());
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectsLayer::ObjectsLayer(MapSceneBase * s): AbstractLayer(s)
|
void ObjectsLayer::redrawObjects(const std::set<CGObjectInstance *> & objects)
|
||||||
{
|
{
|
||||||
}
|
redraw(objects);
|
||||||
|
|
||||||
void ObjectsLayer::update()
|
|
||||||
{
|
|
||||||
if(!map)
|
|
||||||
return;
|
|
||||||
|
|
||||||
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
|
||||||
pixmap->fill(Qt::transparent);
|
|
||||||
draw(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjectsLayer::draw(bool onlyDirty)
|
|
||||||
{
|
|
||||||
if(!pixmap)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!map)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QPainter painter(pixmap.get());
|
|
||||||
|
|
||||||
if(onlyDirty)
|
|
||||||
{
|
|
||||||
//objects could be modified
|
|
||||||
for(auto * obj : objDirty)
|
|
||||||
setDirty(obj);
|
|
||||||
|
|
||||||
//clear tiles which will be redrawn. It's needed because some object could be replaced
|
|
||||||
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
||||||
for(auto & p : dirty)
|
|
||||||
painter.fillRect(p.x * 32, p.y * 32, 32, 32, Qt::transparent);
|
|
||||||
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
|
||||||
|
|
||||||
for(auto & p : dirty)
|
|
||||||
handler->drawObjects(painter, p.x, p.y, p.z, lockedObjects);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pixmap->fill(Qt::transparent);
|
|
||||||
for(int j = 0; j < map->height; ++j)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < map->width; ++i)
|
|
||||||
{
|
|
||||||
handler->drawObjects(painter, i, j, scene->level, lockedObjects);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dirty.clear();
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjectsLayer::setDirty(int x, int y)
|
|
||||||
{
|
|
||||||
int3 pos(x, y, scene->level);
|
|
||||||
if(map->isInTheMap(pos))
|
|
||||||
dirty.insert(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjectsLayer::setDirty(const CGObjectInstance * object)
|
|
||||||
{
|
|
||||||
objDirty.insert(object);
|
|
||||||
//mark tiles under object as dirty
|
|
||||||
for(int j = 0; j < object->getHeight(); ++j)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < object->getWidth(); ++i)
|
|
||||||
{
|
|
||||||
setDirty(object->anchorPos().x - i, object->anchorPos().y - j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectsLayer::setLockObject(const CGObjectInstance * object, bool lock)
|
void ObjectsLayer::setLockObject(const CGObjectInstance * object, bool lock)
|
||||||
@@ -442,64 +593,63 @@ void ObjectsLayer::unlockAll()
|
|||||||
lockedObjects.clear();
|
lockedObjects.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectionObjectsLayer::SelectionObjectsLayer(MapSceneBase * s): AbstractLayer(s), newObject(nullptr)
|
SelectionObjectsLayer::SelectionObjectsLayer(MapSceneBase * s): AbstractViewportLayer(s), newObject(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionObjectsLayer::update()
|
|
||||||
{
|
|
||||||
if(!map)
|
|
||||||
return;
|
|
||||||
|
|
||||||
selectedObjects.clear();
|
|
||||||
onSelection();
|
|
||||||
shift = QPoint();
|
|
||||||
newObject.reset();
|
|
||||||
|
|
||||||
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
|
||||||
//pixmap->fill(QColor(0, 0, 0, 0));
|
|
||||||
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SelectionObjectsLayer::draw()
|
QGraphicsItem * SelectionObjectsLayer::draw(const QRectF & section)
|
||||||
{
|
{
|
||||||
if(!pixmap)
|
QPixmap pixmap(toInt(section.width()), toInt(section.height()));
|
||||||
return;
|
pixmap.fill(Qt::transparent);
|
||||||
|
|
||||||
pixmap->fill(Qt::transparent);
|
if (isShown)
|
||||||
|
|
||||||
QPainter painter(pixmap.get());
|
|
||||||
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
||||||
painter.setPen(Qt::white);
|
|
||||||
|
|
||||||
for(auto * obj : selectedObjects)
|
|
||||||
{
|
{
|
||||||
if(obj != newObject.get())
|
QPainter painter(&pixmap);
|
||||||
|
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||||
|
painter.setPen(Qt::white);
|
||||||
|
|
||||||
|
QPointF offset = section.topLeft();
|
||||||
|
|
||||||
|
for(auto * obj : selectedObjects)
|
||||||
{
|
{
|
||||||
QRect bbox(obj->anchorPos().x, obj->anchorPos().y, 1, 1);
|
auto objectArea = getObjectArea(obj);
|
||||||
for(auto & t : obj->getBlockedPos())
|
if(obj != newObject.get() && section.intersects(objectArea))
|
||||||
{
|
{
|
||||||
QPoint topLeft(std::min(t.x, bbox.topLeft().x()), std::min(t.y, bbox.topLeft().y()));
|
auto pos = obj->anchorPos();
|
||||||
bbox.setTopLeft(topLeft);
|
QRectF bbox(pos.x, pos.y, 1, 1);
|
||||||
QPoint bottomRight(std::max(t.x, bbox.bottomRight().x()), std::max(t.y, bbox.bottomRight().y()));
|
for(const auto & t : obj->getBlockedPos())
|
||||||
bbox.setBottomRight(bottomRight);
|
{
|
||||||
|
QPointF topLeft(std::min(t.x * 1.0, bbox.topLeft().x()), std::min(t.y * 1.0, bbox.topLeft().y()));
|
||||||
|
bbox.setTopLeft(topLeft);
|
||||||
|
QPointF bottomRight(std::max(t.x * 1.0, bbox.bottomRight().x()), std::max(t.y * 1.0, bbox.bottomRight().y()));
|
||||||
|
bbox.setBottomRight(bottomRight);
|
||||||
|
}
|
||||||
|
//selection box's size was decreased by 1 px to get rid of a persistent bug
|
||||||
|
//with displaying a box on a border of two sectors. Bite me.
|
||||||
|
|
||||||
|
painter.setOpacity(1.0);
|
||||||
|
QRectF rect((bbox.x() * tileSize + 1) - offset.x(), (bbox.y() * tileSize + 1) - offset.y(), (bbox.width() * tileSize) - 2, (bbox.height() * tileSize) - 2);
|
||||||
|
painter.drawRect(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(selectionMode == SelectionMode::MOVEMENT && (shift.x() || shift.y()))
|
||||||
|
{
|
||||||
|
objectArea.moveTo(objectArea.topLeft() + (shift * tileSize));
|
||||||
|
if (section.intersects(objectArea))
|
||||||
|
{
|
||||||
|
painter.setOpacity(0.7);
|
||||||
|
auto newPos = QPoint(obj->anchorPos().x, obj->anchorPos().y) + shift;
|
||||||
|
handler->drawObjectAt(painter, obj, newPos.x(), newPos.y(), offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.setOpacity(1.0);
|
|
||||||
painter.drawRect(bbox.x() * 32, bbox.y() * 32, bbox.width() * 32, bbox.height() * 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
//show translation
|
|
||||||
if(selectionMode == SelectionMode::MOVEMENT && (shift.x() || shift.y()))
|
|
||||||
{
|
|
||||||
painter.setOpacity(0.7);
|
|
||||||
auto newPos = QPoint(obj->anchorPos().x, obj->anchorPos().y) + shift;
|
|
||||||
handler->drawObjectAt(painter, obj, newPos.x(), newPos.y());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
redraw();
|
QGraphicsPixmapItem * result = scene->addPixmap(pixmap);
|
||||||
|
result->setPos(section.x(), section.y());
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGObjectInstance * SelectionObjectsLayer::selectObjectAt(int x, int y, const CGObjectInstance * ignore) const
|
CGObjectInstance * SelectionObjectsLayer::selectObjectAt(int x, int y, const CGObjectInstance * ignore) const
|
||||||
@@ -558,7 +708,8 @@ void SelectionObjectsLayer::selectObjects(int x1, int y1, int x2, int y2)
|
|||||||
|
|
||||||
if(y1 > y2)
|
if(y1 > y2)
|
||||||
std::swap(y1, y2);
|
std::swap(y1, y2);
|
||||||
|
|
||||||
|
std::set<CGObjectInstance *> selectedObjects;
|
||||||
for(int j = y1; j < y2; ++j)
|
for(int j = y1; j < y2; ++j)
|
||||||
{
|
{
|
||||||
for(int i = x1; i < x2; ++i)
|
for(int i = x1; i < x2; ++i)
|
||||||
@@ -567,25 +718,36 @@ void SelectionObjectsLayer::selectObjects(int x1, int y1, int x2, int y2)
|
|||||||
{
|
{
|
||||||
for(auto & o : handler->getObjects(i, j, scene->level))
|
for(auto & o : handler->getObjects(i, j, scene->level))
|
||||||
if(!lockedObjects.count(o.obj))
|
if(!lockedObjects.count(o.obj))
|
||||||
selectObject(const_cast<CGObjectInstance*>(o.obj), false); //do not inform about each object added
|
{
|
||||||
|
selectedObjects.insert(const_cast<CGObjectInstance*>(o.obj));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onSelection();
|
selectObjects(selectedObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionObjectsLayer::selectObject(CGObjectInstance * obj, bool inform /* = true */)
|
void SelectionObjectsLayer::selectObject(CGObjectInstance * obj)
|
||||||
{
|
{
|
||||||
selectedObjects.insert(obj);
|
selectedObjects.insert(obj);
|
||||||
if (inform)
|
onSelection();
|
||||||
|
redraw({obj});
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectionObjectsLayer::selectObjects(const std::set<CGObjectInstance *> & objs)
|
||||||
|
{
|
||||||
|
for (CGObjectInstance * obj : objs)
|
||||||
{
|
{
|
||||||
onSelection();
|
selectedObjects.insert(obj);
|
||||||
}
|
}
|
||||||
|
onSelection();
|
||||||
|
redraw(objs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionObjectsLayer::deselectObject(CGObjectInstance * obj)
|
void SelectionObjectsLayer::deselectObject(CGObjectInstance * obj)
|
||||||
{
|
{
|
||||||
selectedObjects.erase(obj);
|
selectedObjects.erase(obj);
|
||||||
|
redraw({obj});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SelectionObjectsLayer::isSelected(const CGObjectInstance * obj) const
|
bool SelectionObjectsLayer::isSelected(const CGObjectInstance * obj) const
|
||||||
@@ -601,22 +763,47 @@ std::set<CGObjectInstance*> SelectionObjectsLayer::getSelection() const
|
|||||||
void SelectionObjectsLayer::clear()
|
void SelectionObjectsLayer::clear()
|
||||||
{
|
{
|
||||||
selectedObjects.clear();
|
selectedObjects.clear();
|
||||||
onSelection();
|
|
||||||
shift.setX(0);
|
shift.setX(0);
|
||||||
shift.setY(0);
|
shift.setY(0);
|
||||||
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionObjectsLayer::onSelection()
|
void SelectionObjectsLayer::onSelection()
|
||||||
{
|
{
|
||||||
selectionMade(!selectedObjects.empty());
|
Q_EMIT selectionMade(!selectedObjects.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionObjectsLayer::setLockObject(const CGObjectInstance * object, bool lock)
|
void SelectionObjectsLayer::setShift(int x, int y)
|
||||||
|
{
|
||||||
|
std::vector<QRectF>areas;
|
||||||
|
|
||||||
|
if(shift.x() || shift.y())
|
||||||
|
{
|
||||||
|
for (auto * selectedObject : selectedObjects)
|
||||||
|
{
|
||||||
|
QRectF formerArea = getObjectArea(selectedObject);
|
||||||
|
formerArea.moveTo(formerArea.topLeft() + (shift * tileSize));
|
||||||
|
areas.emplace_back(formerArea);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shift = QPoint(x, y);
|
||||||
|
for (auto * selectedObject : selectedObjects)
|
||||||
|
{
|
||||||
|
QRectF area = getObjectArea(selectedObject);
|
||||||
|
area.moveTo(area.topLeft() + (shift * tileSize));
|
||||||
|
areas.emplace_back(area);
|
||||||
|
}
|
||||||
|
redraw(areas);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectionObjectsLayer::setLockObject(CGObjectInstance * object, bool lock)
|
||||||
{
|
{
|
||||||
if(lock)
|
if(lock)
|
||||||
lockedObjects.insert(object);
|
lockedObjects.insert(object);
|
||||||
else
|
else
|
||||||
lockedObjects.erase(object);
|
lockedObjects.erase(object);
|
||||||
|
redraw({object});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionObjectsLayer::unlockAll()
|
void SelectionObjectsLayer::unlockAll()
|
||||||
@@ -624,18 +811,18 @@ void SelectionObjectsLayer::unlockAll()
|
|||||||
lockedObjects.clear();
|
lockedObjects.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
MinimapLayer::MinimapLayer(MapSceneBase * s): AbstractLayer(s)
|
MinimapLayer::MinimapLayer(MapSceneBase * s): AbstractFixedLayer(s)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinimapLayer::update()
|
void MinimapLayer::update()
|
||||||
{
|
{
|
||||||
if(!map)
|
if(!map)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pixmap.reset(new QPixmap(map->width, map->height));
|
pixmap = std::make_unique<QPixmap>(map->width, map->height);
|
||||||
|
|
||||||
QPainter painter(pixmap.get());
|
QPainter painter(pixmap.get());
|
||||||
//coordinate transformation
|
//coordinate transformation
|
||||||
for(int j = 0; j < map->height; ++j)
|
for(int j = 0; j < map->height; ++j)
|
||||||
@@ -649,7 +836,7 @@ void MinimapLayer::update()
|
|||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
MinimapViewLayer::MinimapViewLayer(MapSceneBase * s): AbstractLayer(s)
|
MinimapViewLayer::MinimapViewLayer(MapSceneBase * s): AbstractFixedLayer(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -657,9 +844,9 @@ void MinimapViewLayer::update()
|
|||||||
{
|
{
|
||||||
if(!map)
|
if(!map)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pixmap.reset(new QPixmap(map->width, map->height));
|
pixmap = std::make_unique<QPixmap>(map->width, map->height);
|
||||||
|
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,60 +28,111 @@ class AbstractLayer : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AbstractLayer(MapSceneBase * s);
|
AbstractLayer(MapSceneBase * s);
|
||||||
|
|
||||||
virtual void update() = 0;
|
|
||||||
|
|
||||||
void show(bool show);
|
|
||||||
void redraw();
|
|
||||||
void initialize(MapController & controller);
|
void initialize(MapController & controller);
|
||||||
|
void show(bool show);
|
||||||
|
virtual void update() = 0;
|
||||||
|
virtual void redraw() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
int mapWidthPx() const;
|
||||||
|
int mapHeightPx() const;
|
||||||
|
int toInt(double value) const;
|
||||||
|
|
||||||
MapSceneBase * scene;
|
MapSceneBase * scene;
|
||||||
CMap * map = nullptr;
|
CMap * map = nullptr;
|
||||||
MapHandler * handler = nullptr;
|
MapHandler * handler = nullptr;
|
||||||
bool isShown = false;
|
bool isShown = false;
|
||||||
|
const int tileSize = 32;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AbstractFixedLayer : public AbstractLayer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
AbstractFixedLayer(MapSceneBase * s);
|
||||||
|
void redraw();
|
||||||
|
|
||||||
|
protected:
|
||||||
std::unique_ptr<QPixmap> pixmap;
|
std::unique_ptr<QPixmap> pixmap;
|
||||||
QPixmap emptyPixmap;
|
QPixmap emptyPixmap;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<QGraphicsPixmapItem> item;
|
std::unique_ptr<QGraphicsPixmapItem> item;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AbstractViewportLayer : public AbstractLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AbstractViewportLayer(MapSceneBase * s);
|
||||||
|
void createLayer();
|
||||||
|
void setViewport(const QRectF & _viewPort);
|
||||||
|
|
||||||
class GridLayer: public AbstractLayer
|
void update();
|
||||||
|
void redraw();
|
||||||
|
protected:
|
||||||
|
virtual QGraphicsItem * draw(const QRectF & area) = 0;
|
||||||
|
void redraw(const std::vector<int3> & tiles);
|
||||||
|
void redrawWithSurroundingTiles(const std::vector<int3> & tiles);
|
||||||
|
void redraw(const std::set<CGObjectInstance *> & objects);
|
||||||
|
void redraw(const std::vector<QRectF> & areas);
|
||||||
|
QRectF getObjectArea(const CGObjectInstance * object);
|
||||||
|
private:
|
||||||
|
void addSector(QGraphicsItem * item);
|
||||||
|
void removeSector(QGraphicsItem * item);
|
||||||
|
void redrawSectors(std::set<QGraphicsItem *> & items);
|
||||||
|
const QList<QGraphicsItem *> getAllSectors();
|
||||||
|
|
||||||
|
std::set<QGraphicsItem *> getContainingSectors(const std::vector<int3> & tiles);
|
||||||
|
std::set<QGraphicsItem *> getIntersectingSectors(const std::vector<QRectF> & areas);
|
||||||
|
std::unique_ptr<QGraphicsItemGroup> items;
|
||||||
|
const int sectorSizeInTiles = 10;
|
||||||
|
const int sectorSize = sectorSizeInTiles * tileSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
class EmptyLayer: public AbstractFixedLayer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
EmptyLayer(MapSceneBase * s);
|
||||||
|
|
||||||
|
void update() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class GridLayer: public AbstractViewportLayer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
GridLayer(MapSceneBase * s);
|
GridLayer(MapSceneBase * s);
|
||||||
|
|
||||||
void update() override;
|
protected:
|
||||||
|
QGraphicsItem * draw(const QRectF & section) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PassabilityLayer: public AbstractLayer
|
class PassabilityLayer: public AbstractViewportLayer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
PassabilityLayer(MapSceneBase * s);
|
PassabilityLayer(MapSceneBase * s);
|
||||||
|
|
||||||
void update() override;
|
protected:
|
||||||
|
QGraphicsItem * draw(const QRectF & section) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SelectionTerrainLayer: public AbstractLayer
|
class SelectionTerrainLayer: public AbstractViewportLayer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SelectionTerrainLayer(MapSceneBase* s);
|
SelectionTerrainLayer(MapSceneBase* s);
|
||||||
|
|
||||||
void update() override;
|
void select(const std::vector<int3> & tiles);
|
||||||
|
void erase(const std::vector<int3> & tiles);
|
||||||
void draw();
|
|
||||||
void select(const int3 & tile);
|
|
||||||
void erase(const int3 & tile);
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
const std::set<int3> & selection() const;
|
const std::set<int3> & selection() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QGraphicsItem * draw(const QRectF & section) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void selectionMade(bool anythingSelected);
|
void selectionMade(bool anythingSelected);
|
||||||
|
|
||||||
@@ -94,52 +145,39 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class TerrainLayer: public AbstractLayer
|
class TerrainLayer: public AbstractViewportLayer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
TerrainLayer(MapSceneBase * s);
|
TerrainLayer(MapSceneBase * s);
|
||||||
|
void redrawTerrain(const std::vector<int3> & tiles);
|
||||||
void update() override;
|
|
||||||
|
protected:
|
||||||
void draw(bool onlyDirty = true);
|
QGraphicsItem * draw(const QRectF & section) override;
|
||||||
void setDirty(const int3 & tile);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::set<int3> dirty;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ObjectsLayer: public AbstractLayer
|
class ObjectsLayer: public AbstractViewportLayer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ObjectsLayer(MapSceneBase * s);
|
ObjectsLayer(MapSceneBase * s);
|
||||||
|
|
||||||
void update() override;
|
|
||||||
|
|
||||||
void draw(bool onlyDirty = true);
|
|
||||||
|
|
||||||
void setDirty(int x, int y);
|
|
||||||
void setDirty(const CGObjectInstance * object);
|
|
||||||
|
|
||||||
|
void redrawObjects(const std::set<CGObjectInstance *> & objects);
|
||||||
void setLockObject(const CGObjectInstance * object, bool lock);
|
void setLockObject(const CGObjectInstance * object, bool lock);
|
||||||
void unlockAll();
|
void unlockAll();
|
||||||
|
protected:
|
||||||
|
QGraphicsItem * draw(const QRectF & section) override;
|
||||||
private:
|
private:
|
||||||
std::set<const CGObjectInstance *> objDirty;
|
|
||||||
std::set<const CGObjectInstance *> lockedObjects;
|
std::set<const CGObjectInstance *> lockedObjects;
|
||||||
std::set<int3> dirty;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ObjectPickerLayer: public AbstractLayer
|
class ObjectPickerLayer: public AbstractViewportLayer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ObjectPickerLayer(MapSceneBase * s);
|
ObjectPickerLayer(MapSceneBase * s);
|
||||||
|
|
||||||
void update() override;
|
|
||||||
bool isVisible() const;
|
bool isVisible() const;
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@@ -147,14 +185,16 @@ public:
|
|||||||
{
|
{
|
||||||
highlight([](const CGObjectInstance * o){ return dynamic_cast<T*>(o); });
|
highlight([](const CGObjectInstance * o){ return dynamic_cast<T*>(o); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void highlight(std::function<bool(const CGObjectInstance *)> predicate);
|
void highlight(const std::function<bool(const CGObjectInstance *)> & predicate);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
void select(const CGObjectInstance *);
|
void select(const CGObjectInstance *);
|
||||||
void discard();
|
void discard();
|
||||||
|
protected:
|
||||||
|
QGraphicsItem * draw(const QRectF & section) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void selectionMade(const CGObjectInstance *);
|
void selectionMade(const CGObjectInstance *);
|
||||||
|
|
||||||
@@ -164,7 +204,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class SelectionObjectsLayer: public AbstractLayer
|
class SelectionObjectsLayer: public AbstractViewportLayer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@@ -174,38 +214,37 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
SelectionObjectsLayer(MapSceneBase* s);
|
SelectionObjectsLayer(MapSceneBase* s);
|
||||||
|
|
||||||
void update() override;
|
|
||||||
|
|
||||||
void draw();
|
|
||||||
|
|
||||||
CGObjectInstance * selectObjectAt(int x, int y, const CGObjectInstance * ignore = nullptr) const;
|
CGObjectInstance * selectObjectAt(int x, int y, const CGObjectInstance * ignore = nullptr) const;
|
||||||
void selectObjects(int x1, int y1, int x2, int y2);
|
void selectObjects(int x1, int y1, int x2, int y2);
|
||||||
void selectObject(CGObjectInstance *, bool inform = true);
|
void selectObject(CGObjectInstance *);
|
||||||
void deselectObject(CGObjectInstance *);
|
void deselectObject(CGObjectInstance *);
|
||||||
bool isSelected(const CGObjectInstance *) const;
|
bool isSelected(const CGObjectInstance *) const;
|
||||||
std::set<CGObjectInstance*> getSelection() const;
|
std::set<CGObjectInstance*> getSelection() const;
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
void setLockObject(const CGObjectInstance * object, bool lock);
|
void setShift(int x, int y);
|
||||||
|
void setLockObject(CGObjectInstance * object, bool lock);
|
||||||
void unlockAll();
|
void unlockAll();
|
||||||
|
|
||||||
QPoint shift;
|
|
||||||
std::shared_ptr<CGObjectInstance> newObject;
|
std::shared_ptr<CGObjectInstance> newObject;
|
||||||
//FIXME: magic number
|
QPoint shift;
|
||||||
SelectionMode selectionMode = SelectionMode::NOTHING;
|
SelectionMode selectionMode = SelectionMode::NOTHING;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QGraphicsItem * draw(const QRectF & section) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void selectionMade(bool anythingSelected);
|
void selectionMade(bool anythingSelected);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void selectObjects(const std::set<CGObjectInstance *> & objs);
|
||||||
std::set<CGObjectInstance *> selectedObjects;
|
std::set<CGObjectInstance *> selectedObjects;
|
||||||
std::set<const CGObjectInstance *> lockedObjects;
|
std::set<const CGObjectInstance *> lockedObjects;
|
||||||
|
|
||||||
void onSelection();
|
void onSelection();
|
||||||
};
|
};
|
||||||
|
|
||||||
class MinimapLayer: public AbstractLayer
|
class MinimapLayer: public AbstractFixedLayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MinimapLayer(MapSceneBase * s);
|
MinimapLayer(MapSceneBase * s);
|
||||||
@@ -213,7 +252,7 @@ public:
|
|||||||
void update() override;
|
void update() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MinimapViewLayer: public AbstractLayer
|
class MinimapViewLayer: public AbstractFixedLayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MinimapViewLayer(MapSceneBase * s);
|
MinimapViewLayer(MapSceneBase * s);
|
||||||
|
Reference in New Issue
Block a user