2022-09-01 03:51:29 +02:00
|
|
|
#include "StdInc.h"
|
2022-08-31 20:05:57 +02:00
|
|
|
#include "mapview.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
|
2022-09-02 23:04:28 +02:00
|
|
|
#include "../lib/mapping/CMapEditManager.h"
|
|
|
|
|
2022-08-31 20:05:57 +02:00
|
|
|
MapView::MapView(QWidget *parent):
|
2022-09-01 03:51:29 +02:00
|
|
|
QGraphicsView(parent),
|
2022-09-01 15:08:03 +02:00
|
|
|
selectionTool(MapView::SelectionTool::None)
|
2022-08-31 20:05:57 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::setMain(MainWindow * m)
|
|
|
|
{
|
|
|
|
main = m;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
|
|
|
{
|
|
|
|
this->update();
|
|
|
|
|
2022-09-01 03:51:29 +02:00
|
|
|
auto * sc = static_cast<MapScene*>(scene());
|
|
|
|
if(!sc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto pos = mapToScene(mouseEvent->pos()); //TODO: do we need to check size?
|
|
|
|
int3 tile(pos.x() / 32, pos.y() / 32, sc->level);
|
|
|
|
|
|
|
|
if(tile == tilePrev) //do not redraw
|
|
|
|
return;
|
|
|
|
|
|
|
|
tilePrev = tile;
|
|
|
|
|
|
|
|
//main->setStatusMessage(QString("x: %1 y: %2").arg(QString::number(pos.x()), QString::number(pos.y())));
|
|
|
|
|
|
|
|
switch(selectionTool)
|
|
|
|
{
|
|
|
|
case MapView::SelectionTool::Brush:
|
|
|
|
if(pressedOnSelected)
|
|
|
|
sc->selectionTerrainView.erase(tile);
|
|
|
|
else
|
|
|
|
sc->selectionTerrainView.select(tile);
|
|
|
|
sc->selectionTerrainView.draw();
|
|
|
|
break;
|
2022-08-31 20:05:57 +02:00
|
|
|
|
2022-09-01 03:51:29 +02:00
|
|
|
case MapView::SelectionTool::Area:
|
|
|
|
sc->selectionTerrainView.clear();
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
sc->selectionTerrainView.select(int3(i, j, sc->level));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sc->selectionTerrainView.draw();
|
|
|
|
break;
|
2022-09-01 16:07:36 +02:00
|
|
|
|
|
|
|
case MapView::SelectionTool::None:
|
|
|
|
auto sh = tile - tileStart;
|
|
|
|
sc->selectionObjectsView.shift = QPoint(sh.x, sh.y);
|
|
|
|
sc->selectionObjectsView.draw();
|
|
|
|
break;
|
2022-09-01 03:51:29 +02:00
|
|
|
}
|
2022-08-31 20:05:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
this->update();
|
2022-09-01 03:51:29 +02:00
|
|
|
|
|
|
|
auto * sc = static_cast<MapScene*>(scene());
|
|
|
|
if(!sc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mouseStart = mapToScene(event->pos());
|
|
|
|
tileStart = tilePrev = int3(mouseStart.x() / 32, mouseStart.y() / 32, sc->level);
|
|
|
|
|
|
|
|
if(sc->selectionTerrainView.selection().count(tileStart))
|
|
|
|
pressedOnSelected = true;
|
|
|
|
else
|
|
|
|
pressedOnSelected = false;
|
|
|
|
|
|
|
|
switch(selectionTool)
|
|
|
|
{
|
|
|
|
case MapView::SelectionTool::Brush:
|
2022-09-01 15:08:03 +02:00
|
|
|
sc->selectionObjectsView.clear();
|
|
|
|
sc->selectionObjectsView.draw();
|
2022-09-01 03:51:29 +02:00
|
|
|
if(pressedOnSelected)
|
|
|
|
sc->selectionTerrainView.erase(tileStart);
|
|
|
|
else
|
|
|
|
sc->selectionTerrainView.select(tileStart);
|
|
|
|
sc->selectionTerrainView.draw();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MapView::SelectionTool::Area:
|
|
|
|
sc->selectionTerrainView.clear();
|
|
|
|
sc->selectionTerrainView.draw();
|
2022-09-01 15:08:03 +02:00
|
|
|
sc->selectionObjectsView.clear();
|
|
|
|
sc->selectionObjectsView.draw();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MapView::SelectionTool::None:
|
|
|
|
sc->selectionTerrainView.clear();
|
|
|
|
sc->selectionTerrainView.draw();
|
|
|
|
sc->selectionObjectsView.clear();
|
|
|
|
sc->selectionObjectsView.selectObjectAt(tileStart.x, tileStart.y);
|
|
|
|
sc->selectionObjectsView.draw();
|
2022-09-01 03:51:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//main->setStatusMessage(QString("x: %1 y: %2").arg(QString::number(event->pos().x()), QString::number(event->pos().y())));
|
2022-08-31 20:05:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
this->update();
|
2022-09-01 16:07:36 +02:00
|
|
|
|
|
|
|
auto * sc = static_cast<MapScene*>(scene());
|
|
|
|
if(!sc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch(selectionTool)
|
|
|
|
{
|
|
|
|
case MapView::SelectionTool::None:
|
2022-09-02 23:04:28 +02:00
|
|
|
//switch position
|
|
|
|
if(sc->selectionObjectsView.applyShift())
|
|
|
|
{
|
|
|
|
main->resetMapHandler();
|
|
|
|
sc->updateViews();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sc->selectionObjectsView.shift = QPoint(0, 0);
|
|
|
|
sc->selectionObjectsView.draw();
|
|
|
|
}
|
2022-09-01 16:07:36 +02:00
|
|
|
break;
|
|
|
|
}
|
2022-08-31 20:05:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MapScene::MapScene(MainWindow *parent, int l):
|
|
|
|
QGraphicsScene(parent),
|
|
|
|
gridView(parent, this),
|
|
|
|
passabilityView(parent, this),
|
2022-09-01 03:51:29 +02:00
|
|
|
selectionTerrainView(parent, this),
|
|
|
|
terrainView(parent, this),
|
2022-09-01 13:54:39 +02:00
|
|
|
objectsView(parent, this),
|
2022-09-01 15:08:03 +02:00
|
|
|
selectionObjectsView(parent, this),
|
2022-08-31 20:05:57 +02:00
|
|
|
main(parent),
|
|
|
|
level(l)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-09-01 03:51:29 +02:00
|
|
|
void MapScene::updateViews()
|
2022-08-31 20:05:57 +02:00
|
|
|
{
|
2022-09-01 13:54:39 +02:00
|
|
|
//sequence is important because it defines rendering order
|
2022-09-01 03:51:29 +02:00
|
|
|
terrainView.update();
|
2022-09-01 13:54:39 +02:00
|
|
|
objectsView.update();
|
2022-08-31 20:05:57 +02:00
|
|
|
gridView.update();
|
|
|
|
passabilityView.update();
|
2022-09-01 03:51:29 +02:00
|
|
|
selectionTerrainView.update();
|
2022-09-01 15:08:03 +02:00
|
|
|
selectionObjectsView.update();
|
2022-09-01 13:04:34 +02:00
|
|
|
|
|
|
|
terrainView.show(true);
|
2022-09-01 13:54:39 +02:00
|
|
|
objectsView.show(true);
|
2022-09-01 13:04:34 +02:00
|
|
|
selectionTerrainView.show(true);
|
2022-09-01 15:08:03 +02:00
|
|
|
selectionObjectsView.show(true);
|
2022-08-31 20:05:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BasicView::BasicView(MainWindow * m, MapScene * s): main(m), scene(s)
|
|
|
|
{
|
|
|
|
if(main->getMap())
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasicView::show(bool show)
|
|
|
|
{
|
|
|
|
if(isShown == show)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(show)
|
|
|
|
{
|
2022-09-01 13:04:34 +02:00
|
|
|
if(pixmap)
|
|
|
|
{
|
|
|
|
if(item)
|
|
|
|
item->setPixmap(*pixmap);
|
|
|
|
else
|
|
|
|
item.reset(scene->addPixmap(*pixmap));
|
|
|
|
}
|
2022-08-31 20:05:57 +02:00
|
|
|
else
|
2022-09-01 13:04:34 +02:00
|
|
|
{
|
|
|
|
if(item)
|
|
|
|
item->setPixmap(emptyPixmap);
|
|
|
|
else
|
|
|
|
item.reset(scene->addPixmap(emptyPixmap));
|
|
|
|
}
|
2022-08-31 20:05:57 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-01 13:04:34 +02:00
|
|
|
item->setPixmap(emptyPixmap);
|
2022-08-31 20:05:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
isShown = show;
|
|
|
|
}
|
|
|
|
|
2022-09-01 03:51:29 +02:00
|
|
|
void BasicView::redraw()
|
|
|
|
{
|
|
|
|
if(item)
|
|
|
|
{
|
2022-09-01 13:04:34 +02:00
|
|
|
if(pixmap && isShown)
|
|
|
|
item->setPixmap(*pixmap);
|
|
|
|
else
|
|
|
|
item->setPixmap(emptyPixmap);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(pixmap && isShown)
|
|
|
|
item.reset(scene->addPixmap(*pixmap));
|
|
|
|
else
|
|
|
|
item.reset(scene->addPixmap(emptyPixmap));
|
2022-09-01 03:51:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-31 20:05:57 +02:00
|
|
|
GridView::GridView(MainWindow * m, MapScene * s): BasicView(m, s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridView::update()
|
|
|
|
{
|
|
|
|
auto map = main->getMap();
|
2022-09-01 03:51:29 +02:00
|
|
|
if(!map)
|
|
|
|
return;
|
|
|
|
|
2022-08-31 20:05:57 +02:00
|
|
|
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
|
|
|
pixmap->fill(QColor(0, 0, 0, 0));
|
|
|
|
QPainter painter(pixmap.get());
|
|
|
|
painter.setPen(QColor(0, 0, 0, 190));
|
|
|
|
|
|
|
|
for(int j = 0; j < map->height; ++j)
|
|
|
|
{
|
|
|
|
painter.drawLine(0, j * 32, map->width * 32 - 1, j * 32);
|
|
|
|
}
|
|
|
|
for(int i = 0; i < map->width; ++i)
|
|
|
|
{
|
|
|
|
painter.drawLine(i * 32, 0, i * 32, map->height * 32 - 1);
|
|
|
|
}
|
|
|
|
|
2022-09-01 13:04:34 +02:00
|
|
|
redraw();
|
2022-08-31 20:05:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PassabilityView::PassabilityView(MainWindow * m, MapScene * s): BasicView(m, s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PassabilityView::update()
|
|
|
|
{
|
|
|
|
auto map = main->getMap();
|
2022-09-01 03:51:29 +02:00
|
|
|
if(!map)
|
|
|
|
return;
|
|
|
|
|
2022-08-31 20:05:57 +02:00
|
|
|
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
|
|
|
pixmap->fill(QColor(0, 0, 0, 0));
|
|
|
|
|
|
|
|
if(scene->level == 0 || map->twoLevel)
|
|
|
|
{
|
|
|
|
QPainter painter(pixmap.get());
|
|
|
|
for(int j = 0; j < map->height; ++j)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < map->width; ++i)
|
|
|
|
{
|
|
|
|
auto tl = map->getTile(int3(i, j, scene->level));
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 13:04:34 +02:00
|
|
|
redraw();
|
2022-08-31 20:05:57 +02:00
|
|
|
}
|
2022-09-01 03:51:29 +02:00
|
|
|
|
|
|
|
SelectionTerrainView::SelectionTerrainView(MainWindow * m, MapScene * s): BasicView(m, s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTerrainView::update()
|
|
|
|
{
|
|
|
|
auto map = main->getMap();
|
|
|
|
if(!map)
|
|
|
|
return;
|
|
|
|
|
|
|
|
area.clear();
|
|
|
|
areaAdd.clear();
|
|
|
|
areaErase.clear();
|
|
|
|
|
|
|
|
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
|
|
|
pixmap->fill(QColor(0, 0, 0, 0));
|
|
|
|
|
2022-09-01 13:04:34 +02:00
|
|
|
redraw();
|
2022-09-01 03:51:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTerrainView::draw()
|
|
|
|
{
|
|
|
|
if(!pixmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QPainter painter(pixmap.get());
|
|
|
|
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
for(auto & t : areaAdd)
|
|
|
|
{
|
|
|
|
painter.fillRect(t.x * 32, t.y * 32, 31, 31, QColor(128, 128, 128, 96));
|
|
|
|
}
|
|
|
|
for(auto & t : areaErase)
|
|
|
|
{
|
|
|
|
painter.fillRect(t.x * 32, t.y * 32, 31, 31, QColor(0, 0, 0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
areaAdd.clear();
|
|
|
|
areaErase.clear();
|
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTerrainView::select(const int3 & tile)
|
|
|
|
{
|
|
|
|
if(!area.count(tile))
|
|
|
|
{
|
|
|
|
area.insert(tile);
|
|
|
|
areaAdd.insert(tile);
|
|
|
|
areaErase.erase(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTerrainView::erase(const int3 & tile)
|
|
|
|
{
|
|
|
|
if(area.count(tile))
|
|
|
|
{
|
|
|
|
area.erase(tile);
|
|
|
|
areaErase.insert(tile);
|
|
|
|
areaAdd.erase(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTerrainView::clear()
|
|
|
|
{
|
|
|
|
areaErase = area;
|
|
|
|
areaAdd.clear();
|
|
|
|
area.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::set<int3> & SelectionTerrainView::selection() const
|
|
|
|
{
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
TerrainView::TerrainView(MainWindow * m, MapScene * s): BasicView(m, s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TerrainView::update()
|
|
|
|
{
|
|
|
|
auto map = main->getMap();
|
|
|
|
if(!map)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
|
|
|
draw(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TerrainView::setDirty(const int3 & tile)
|
|
|
|
{
|
|
|
|
dirty.insert(tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TerrainView::draw(bool onlyDirty)
|
|
|
|
{
|
|
|
|
if(!pixmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto map = main->getMap();
|
2022-09-01 13:54:39 +02:00
|
|
|
if(!map)
|
|
|
|
return;
|
2022-09-01 03:51:29 +02:00
|
|
|
|
|
|
|
QPainter painter(pixmap.get());
|
|
|
|
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
|
|
|
|
if(onlyDirty)
|
|
|
|
{
|
|
|
|
std::set<int3> forRedrawing(dirty), neighbours;
|
|
|
|
for(auto & t : dirty)
|
|
|
|
{
|
|
|
|
for(auto & tt : int3::getDirs())
|
|
|
|
{
|
|
|
|
if(map->isInTheMap(t + tt))
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
main->getMapHandler()->drawTerrainTile(painter, t.x, t.y, scene->level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(int j = 0; j < map->height; ++j)
|
|
|
|
for(int i = 0; i < map->width; ++i)
|
|
|
|
main->getMapHandler()->drawTerrainTile(painter, i, j, scene->level);
|
|
|
|
}
|
|
|
|
|
2022-09-01 13:54:39 +02:00
|
|
|
dirty.clear();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectsView::ObjectsView(MainWindow * m, MapScene * s): BasicView(m, s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectsView::update()
|
|
|
|
{
|
|
|
|
auto map = main->getMap();
|
|
|
|
if(!map)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
|
|
|
pixmap->fill(QColor(0, 0, 0, 0));
|
|
|
|
draw(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectsView::draw(bool onlyDirty)
|
|
|
|
{
|
|
|
|
if(!pixmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto map = main->getMap();
|
|
|
|
if(!map)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pixmap->fill(QColor(0, 0, 0, 0));
|
|
|
|
QPainter painter(pixmap.get());
|
|
|
|
//painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
|
|
|
std::set<const CGObjectInstance *> drawen;
|
|
|
|
|
|
|
|
|
|
|
|
for(int j = 0; j < map->height; ++j)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < map->width; ++i)
|
|
|
|
{
|
|
|
|
main->getMapHandler()->drawObjects(painter, i, j, scene->level);
|
|
|
|
/*auto & objects = main->getMapHandler()->getObjects(i, j, scene->level);
|
|
|
|
for(auto & object : objects)
|
|
|
|
{
|
|
|
|
if(!object.obj || drawen.count(object.obj))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(!onlyDirty || dirty.count(object.obj))
|
|
|
|
{
|
|
|
|
main->getMapHandler()->drawObject(painter, object);
|
|
|
|
drawen.insert(object.obj);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dirty.clear();
|
2022-09-01 03:51:29 +02:00
|
|
|
redraw();
|
|
|
|
}
|
2022-09-01 13:54:39 +02:00
|
|
|
|
|
|
|
void ObjectsView::setDirty(int x, int y)
|
|
|
|
{
|
|
|
|
auto & objects = main->getMapHandler()->getObjects(x, y, scene->level);
|
|
|
|
for(auto & object : objects)
|
|
|
|
{
|
|
|
|
if(object.obj)
|
|
|
|
dirty.insert(object.obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectsView::setDirty(const CGObjectInstance * object)
|
|
|
|
{
|
|
|
|
dirty.insert(object);
|
|
|
|
}
|
2022-09-01 15:08:03 +02:00
|
|
|
|
|
|
|
SelectionObjectsView::SelectionObjectsView(MainWindow * m, MapScene * s): BasicView(m, s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionObjectsView::update()
|
|
|
|
{
|
|
|
|
auto map = main->getMap();
|
|
|
|
if(!map)
|
|
|
|
return;
|
|
|
|
|
|
|
|
selectedObjects.clear();
|
2022-09-02 23:04:28 +02:00
|
|
|
shift = QPoint();
|
2022-09-01 15:08:03 +02:00
|
|
|
|
|
|
|
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
|
|
|
//pixmap->fill(QColor(0, 0, 0, 0));
|
|
|
|
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionObjectsView::draw()
|
|
|
|
{
|
|
|
|
if(!pixmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pixmap->fill(QColor(0, 0, 0, 0));
|
|
|
|
|
|
|
|
QPainter painter(pixmap.get());
|
|
|
|
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
painter.setPen(QColor(255, 255, 255));
|
|
|
|
|
|
|
|
for(auto * obj : selectedObjects)
|
|
|
|
{
|
|
|
|
QRect bbox(obj->getPosition().x, obj->getPosition().y, 1, 1);
|
|
|
|
for(auto & t : obj->getBlockedPos())
|
|
|
|
{
|
|
|
|
QPoint topLeft(std::min(t.x, bbox.topLeft().x()), std::min(t.y, bbox.topLeft().y()));
|
|
|
|
bbox.setTopLeft(topLeft);
|
|
|
|
QPoint bottomRight(std::max(t.x, bbox.bottomRight().x()), std::max(t.y, bbox.bottomRight().y()));
|
|
|
|
bbox.setBottomRight(bottomRight);
|
|
|
|
}
|
|
|
|
|
2022-09-01 16:07:36 +02:00
|
|
|
painter.setOpacity(1.0);
|
2022-09-01 15:08:03 +02:00
|
|
|
painter.drawRect(bbox.x() * 32, bbox.y() * 32, bbox.width() * 32, bbox.height() * 32);
|
2022-09-01 16:07:36 +02:00
|
|
|
|
|
|
|
//show translation
|
|
|
|
if(shift.x() || shift.y())
|
|
|
|
{
|
|
|
|
painter.setOpacity(0.5);
|
|
|
|
auto newPos = QPoint(obj->getPosition().x, obj->getPosition().y) + shift;
|
|
|
|
main->getMapHandler()->drawObjectAt(painter, obj, newPos.x(), newPos.y());
|
|
|
|
}
|
2022-09-01 15:08:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
CGObjectInstance * SelectionObjectsView::selectObjectAt(int x, int y)
|
|
|
|
{
|
|
|
|
if(!main->getMap() || !main->getMapHandler())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
auto & objects = main->getMapHandler()->getObjects(x, y, scene->level);
|
|
|
|
|
|
|
|
//visitable is most important
|
|
|
|
for(auto & object : objects)
|
|
|
|
{
|
|
|
|
if(!object.obj || selectedObjects.count(object.obj))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(object.obj->visitableAt(x, y))
|
|
|
|
{
|
2022-09-02 23:04:28 +02:00
|
|
|
selectedObjects.insert(object.obj);
|
2022-09-01 15:08:03 +02:00
|
|
|
return object.obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//if not visitable tile - try to get blocked
|
|
|
|
for(auto & object : objects)
|
|
|
|
{
|
|
|
|
if(!object.obj || selectedObjects.count(object.obj))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(object.obj->blockingAt(x, y))
|
|
|
|
{
|
2022-09-02 23:04:28 +02:00
|
|
|
selectedObjects.insert(object.obj);
|
2022-09-01 15:08:03 +02:00
|
|
|
return object.obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//finally, we can take any object
|
|
|
|
for(auto & object : objects)
|
|
|
|
{
|
|
|
|
if(!object.obj || selectedObjects.count(object.obj))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(object.obj->coveringAt(x, y))
|
|
|
|
{
|
2022-09-02 23:04:28 +02:00
|
|
|
selectedObjects.insert(object.obj);
|
2022-09-01 15:08:03 +02:00
|
|
|
return object.obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-09-02 23:04:28 +02:00
|
|
|
bool SelectionObjectsView::applyShift()
|
|
|
|
{
|
|
|
|
if(shift.x() || shift.y())
|
|
|
|
{
|
|
|
|
for(auto * obj : selectedObjects)
|
|
|
|
{
|
|
|
|
int3 pos = obj->pos;
|
|
|
|
pos.x += shift.x(); pos.y += shift.y();
|
|
|
|
main->getMap()->getEditManager()->moveObject(obj, pos);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionObjectsView::deleteSelection()
|
|
|
|
{
|
|
|
|
for(auto * obj : selectedObjects)
|
|
|
|
{
|
|
|
|
main->getMap()->getEditManager()->removeObject(obj);
|
|
|
|
}
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:08:03 +02:00
|
|
|
std::set<CGObjectInstance *> SelectionObjectsView::selectObjects(int x1, int y1, int x2, int y2)
|
|
|
|
{
|
|
|
|
std::set<CGObjectInstance *> result;
|
|
|
|
//TBD
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionObjectsView::clear()
|
|
|
|
{
|
|
|
|
selectedObjects.clear();
|
2022-09-01 16:07:36 +02:00
|
|
|
shift.setX(0);
|
|
|
|
shift.setY(0);
|
2022-09-01 15:08:03 +02:00
|
|
|
}
|