mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-18 17:40:48 +02:00
Merge branch 'cpp-map-editor' into Actions
This commit is contained in:
commit
4793ed9679
@ -46,7 +46,7 @@ void TownPlacer::init()
|
|||||||
|
|
||||||
void TownPlacer::placeTowns(ObjectManager & manager)
|
void TownPlacer::placeTowns(ObjectManager & manager)
|
||||||
{
|
{
|
||||||
if((zone.getType() == ETemplateZoneType::CPU_START) || (zone.getType() == ETemplateZoneType::PLAYER_START))
|
if(zone.getOwner() && ((zone.getType() == ETemplateZoneType::CPU_START) || (zone.getType() == ETemplateZoneType::PLAYER_START)))
|
||||||
{
|
{
|
||||||
//set zone types to player faction, generate main town
|
//set zone types to player faction, generate main town
|
||||||
logGlobal->info("Preparing playing zone");
|
logGlobal->info("Preparing playing zone");
|
||||||
|
@ -120,8 +120,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui->mapView->setController(&controller);
|
ui->mapView->setController(&controller);
|
||||||
connect(ui->mapView, &MapView::openObjectProperties, this, &MainWindow::loadInspector);
|
connect(ui->mapView, &MapView::openObjectProperties, this, &MainWindow::loadInspector);
|
||||||
|
|
||||||
sceneMini = new QGraphicsScene(this);
|
ui->minimapView->setScene(controller.miniScene(0));
|
||||||
ui->minimapView->setScene(sceneMini);
|
ui->minimapView->setController(&controller);
|
||||||
|
connect(ui->minimapView, &MinimapView::cameraPositionChanged, ui->mapView, &MapView::cameraChanged);
|
||||||
|
|
||||||
scenePreview = new QGraphicsScene(this);
|
scenePreview = new QGraphicsScene(this);
|
||||||
ui->objectPreview->setScene(scenePreview);
|
ui->objectPreview->setScene(scenePreview);
|
||||||
@ -176,6 +177,8 @@ void MainWindow::initializeMap(bool isNew)
|
|||||||
|
|
||||||
mapLevel = 0;
|
mapLevel = 0;
|
||||||
ui->mapView->setScene(controller.scene(mapLevel));
|
ui->mapView->setScene(controller.scene(mapLevel));
|
||||||
|
ui->minimapView->setScene(controller.miniScene(mapLevel));
|
||||||
|
ui->minimapView->dimensions();
|
||||||
|
|
||||||
setStatusMessage(QString("Scene objects: %1").arg(ui->mapView->scene()->items().size()));
|
setStatusMessage(QString("Scene objects: %1").arg(ui->mapView->scene()->items().size()));
|
||||||
|
|
||||||
@ -227,7 +230,7 @@ void MainWindow::saveMap()
|
|||||||
CMapService mapService;
|
CMapService mapService;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mapService.saveMap(std::unique_ptr<CMap>(controller.map()), filename.toStdString());
|
mapService.saveMap(controller.getMapUniquePtr(), filename.toStdString());
|
||||||
}
|
}
|
||||||
catch(const std::exception & e)
|
catch(const std::exception & e)
|
||||||
{
|
{
|
||||||
@ -551,6 +554,7 @@ void MainWindow::on_actionLevel_triggered()
|
|||||||
{
|
{
|
||||||
mapLevel = mapLevel ? 0 : 1;
|
mapLevel = mapLevel ? 0 : 1;
|
||||||
ui->mapView->setScene(controller.scene(mapLevel));
|
ui->mapView->setScene(controller.scene(mapLevel));
|
||||||
|
ui->minimapView->setScene(controller.miniScene(mapLevel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -780,15 +784,17 @@ void MainWindow::on_inspectorWidget_itemChanged(QTableWidgetItem *item)
|
|||||||
|
|
||||||
void MainWindow::on_actionMapSettings_triggered()
|
void MainWindow::on_actionMapSettings_triggered()
|
||||||
{
|
{
|
||||||
auto mapSettingsDialog = new MapSettings(controller, this);
|
auto settingsDialog = new MapSettings(controller, this);
|
||||||
mapSettingsDialog->setModal(true);
|
settingsDialog->setWindowModality(Qt::WindowModal);
|
||||||
|
settingsDialog->setModal(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_actionPlayers_settings_triggered()
|
void MainWindow::on_actionPlayers_settings_triggered()
|
||||||
{
|
{
|
||||||
auto mapSettingsDialog = new PlayerSettings(*controller.map(), this);
|
auto settingsDialog = new PlayerSettings(*controller.map(), this);
|
||||||
mapSettingsDialog->setModal(true);
|
settingsDialog->setWindowModality(Qt::WindowModal);
|
||||||
|
settingsDialog->setModal(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::enableUndo(bool enable)
|
void MainWindow::enableUndo(bool enable)
|
||||||
@ -799,4 +805,5 @@ void MainWindow::enableUndo(bool enable)
|
|||||||
void MainWindow::enableRedo(bool enable)
|
void MainWindow::enableRedo(bool enable)
|
||||||
{
|
{
|
||||||
ui->actionRedo->setEnabled(enable);
|
ui->actionRedo->setEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,9 +101,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
ObjectBrowser * objectBrowser = nullptr;
|
ObjectBrowser * objectBrowser = nullptr;
|
||||||
QGraphicsScene * sceneMini;
|
|
||||||
QGraphicsScene * scenePreview;
|
QGraphicsScene * scenePreview;
|
||||||
QPixmap minimap;
|
|
||||||
|
|
||||||
QString filename;
|
QString filename;
|
||||||
bool unsaved = false;
|
bool unsaved = false;
|
||||||
|
@ -77,9 +77,16 @@
|
|||||||
<addaction name="actionUndo"/>
|
<addaction name="actionUndo"/>
|
||||||
<addaction name="actionRedo"/>
|
<addaction name="actionRedo"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuPlayer">
|
||||||
|
<property name="title">
|
||||||
|
<string>Player</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionNeutral"/>
|
||||||
|
</widget>
|
||||||
<addaction name="menuFile"/>
|
<addaction name="menuFile"/>
|
||||||
<addaction name="menuEdit"/>
|
<addaction name="menuEdit"/>
|
||||||
<addaction name="menuMap"/>
|
<addaction name="menuMap"/>
|
||||||
|
<addaction name="menuPlayer"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QToolBar" name="toolBar">
|
<widget class="QToolBar" name="toolBar">
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -148,7 +155,7 @@
|
|||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGraphicsView" name="minimapView">
|
<widget class="MinimapView" name="minimapView">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@ -862,6 +869,14 @@
|
|||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionNeutral">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Neutral</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
@ -869,6 +884,11 @@
|
|||||||
<extends>QGraphicsView</extends>
|
<extends>QGraphicsView</extends>
|
||||||
<header>mapview.h</header>
|
<header>mapview.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>MinimapView</class>
|
||||||
|
<extends>QGraphicsView</extends>
|
||||||
|
<header>mapview.h</header>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
@ -18,12 +18,19 @@ MapController::MapController(MainWindow * m): main(m)
|
|||||||
{
|
{
|
||||||
_scenes[0].reset(new MapScene(0));
|
_scenes[0].reset(new MapScene(0));
|
||||||
_scenes[1].reset(new MapScene(1));
|
_scenes[1].reset(new MapScene(1));
|
||||||
|
_miniscenes[0].reset(new MinimapScene(0));
|
||||||
|
_miniscenes[1].reset(new MinimapScene(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
MapController::~MapController()
|
MapController::~MapController()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::unique_ptr<CMap> & MapController::getMapUniquePtr() const
|
||||||
|
{
|
||||||
|
return _map;
|
||||||
|
}
|
||||||
|
|
||||||
CMap * MapController::map()
|
CMap * MapController::map()
|
||||||
{
|
{
|
||||||
return _map.get();
|
return _map.get();
|
||||||
@ -39,11 +46,18 @@ MapScene * MapController::scene(int level)
|
|||||||
return _scenes[level].get();
|
return _scenes[level].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MinimapScene * MapController::miniScene(int level)
|
||||||
|
{
|
||||||
|
return _miniscenes[level].get();
|
||||||
|
}
|
||||||
|
|
||||||
void MapController::setMap(std::unique_ptr<CMap> cmap)
|
void MapController::setMap(std::unique_ptr<CMap> cmap)
|
||||||
{
|
{
|
||||||
_map = std::move(cmap);
|
_map = std::move(cmap);
|
||||||
_scenes[0].reset(new MapScene(0));
|
_scenes[0].reset(new MapScene(0));
|
||||||
_scenes[1].reset(new MapScene(1));
|
_scenes[1].reset(new MapScene(1));
|
||||||
|
_miniscenes[0].reset(new MinimapScene(0));
|
||||||
|
_miniscenes[1].reset(new MinimapScene(1));
|
||||||
resetMapHandler();
|
resetMapHandler();
|
||||||
sceneForceUpdate();
|
sceneForceUpdate();
|
||||||
|
|
||||||
@ -58,13 +72,18 @@ void MapController::setMap(std::unique_ptr<CMap> cmap)
|
|||||||
void MapController::sceneForceUpdate()
|
void MapController::sceneForceUpdate()
|
||||||
{
|
{
|
||||||
_scenes[0]->updateViews();
|
_scenes[0]->updateViews();
|
||||||
|
_miniscenes[0]->updateViews();
|
||||||
if(_map->twoLevel)
|
if(_map->twoLevel)
|
||||||
|
{
|
||||||
_scenes[1]->updateViews();
|
_scenes[1]->updateViews();
|
||||||
|
_miniscenes[1]->updateViews();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapController::sceneForceUpdate(int level)
|
void MapController::sceneForceUpdate(int level)
|
||||||
{
|
{
|
||||||
_scenes[level]->updateViews();
|
_scenes[level]->updateViews();
|
||||||
|
_miniscenes[level]->updateViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapController::resetMapHandler()
|
void MapController::resetMapHandler()
|
||||||
@ -72,6 +91,8 @@ void MapController::resetMapHandler()
|
|||||||
_mapHandler.reset(new MapHandler(_map.get()));
|
_mapHandler.reset(new MapHandler(_map.get()));
|
||||||
_scenes[0]->initialize(*this);
|
_scenes[0]->initialize(*this);
|
||||||
_scenes[1]->initialize(*this);
|
_scenes[1]->initialize(*this);
|
||||||
|
_miniscenes[0]->initialize(*this);
|
||||||
|
_miniscenes[1]->initialize(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapController::commitTerrainChange(int level, const Terrain & terrain)
|
void MapController::commitTerrainChange(int level, const Terrain & terrain)
|
||||||
@ -91,6 +112,7 @@ void MapController::commitTerrainChange(int level, const Terrain & terrain)
|
|||||||
_scenes[level]->terrainView.setDirty(t);
|
_scenes[level]->terrainView.setDirty(t);
|
||||||
_scenes[level]->terrainView.draw();
|
_scenes[level]->terrainView.draw();
|
||||||
|
|
||||||
|
_miniscenes[level]->updateViews();
|
||||||
main->mapChanged();
|
main->mapChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +127,7 @@ void MapController::commitObjectErase(int level)
|
|||||||
resetMapHandler();
|
resetMapHandler();
|
||||||
_scenes[level]->updateViews();
|
_scenes[level]->updateViews();
|
||||||
|
|
||||||
|
_miniscenes[level]->updateViews();
|
||||||
main->mapChanged();
|
main->mapChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,6 +179,7 @@ void MapController::commitObstacleFill(int level)
|
|||||||
resetMapHandler();
|
resetMapHandler();
|
||||||
_scenes[level]->updateViews();
|
_scenes[level]->updateViews();
|
||||||
|
|
||||||
|
_miniscenes[level]->updateViews();
|
||||||
main->mapChanged();
|
main->mapChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,6 +189,7 @@ void MapController::commitObjectChange(int level)
|
|||||||
_scenes[level]->objectsView.draw();
|
_scenes[level]->objectsView.draw();
|
||||||
_scenes[level]->selectionObjectsView.draw();
|
_scenes[level]->selectionObjectsView.draw();
|
||||||
|
|
||||||
|
_miniscenes[level]->updateViews();
|
||||||
main->mapChanged();
|
main->mapChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,6 +230,7 @@ void MapController::commitObjectShiftOrCreate(int level)
|
|||||||
resetMapHandler();
|
resetMapHandler();
|
||||||
_scenes[level]->updateViews();
|
_scenes[level]->updateViews();
|
||||||
|
|
||||||
|
_miniscenes[level]->updateViews();
|
||||||
main->mapChanged();
|
main->mapChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,11 @@ public:
|
|||||||
|
|
||||||
void setMap(std::unique_ptr<CMap>);
|
void setMap(std::unique_ptr<CMap>);
|
||||||
|
|
||||||
|
const std::unique_ptr<CMap> & getMapUniquePtr() const; //to be used for map saving
|
||||||
CMap * map();
|
CMap * map();
|
||||||
MapHandler * mapHandler();
|
MapHandler * mapHandler();
|
||||||
MapScene * scene(int level);
|
MapScene * scene(int level);
|
||||||
|
MinimapScene * miniScene(int level);
|
||||||
|
|
||||||
void resetMapHandler();
|
void resetMapHandler();
|
||||||
|
|
||||||
@ -46,6 +48,7 @@ private:
|
|||||||
std::unique_ptr<MapHandler> _mapHandler;
|
std::unique_ptr<MapHandler> _mapHandler;
|
||||||
MainWindow * main;
|
MainWindow * main;
|
||||||
mutable std::array<std::unique_ptr<MapScene>, 2> _scenes;
|
mutable std::array<std::unique_ptr<MapScene>, 2> _scenes;
|
||||||
|
mutable std::array<std::unique_ptr<MinimapScene>, 2> _miniscenes;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAPCONTROLLER_H
|
#endif // MAPCONTROLLER_H
|
||||||
|
@ -502,3 +502,39 @@ void MapHandler::drawObjectAt(QPainter & painter, const CGObjectInstance * obj,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRgb MapHandler::getTileColor(int x, int y, int z)
|
||||||
|
{
|
||||||
|
// if object at tile is owned - it will be colored as its owner
|
||||||
|
for(auto & object : getObjects(x, y, z))
|
||||||
|
{
|
||||||
|
//heroes will be blitted later
|
||||||
|
switch (object.obj->ID)
|
||||||
|
{
|
||||||
|
case Obj::HERO:
|
||||||
|
case Obj::PRISON:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerColor player = object.obj->getOwner();
|
||||||
|
if(player == PlayerColor::NEUTRAL)
|
||||||
|
return graphics->neutralColor;
|
||||||
|
else
|
||||||
|
if (player < PlayerColor::PLAYER_LIMIT)
|
||||||
|
return graphics->playerColors[player.getNum()];
|
||||||
|
}
|
||||||
|
|
||||||
|
// else - use terrain color (blocked version or normal)
|
||||||
|
auto & tile = map->getTile(int3(x, y, z));
|
||||||
|
auto color = Terrain::Manager::getInfo(tile.terType).minimapUnblocked;
|
||||||
|
if (tile.blocked && (!tile.visitable))
|
||||||
|
color = Terrain::Manager::getInfo(tile.terType).minimapBlocked;
|
||||||
|
|
||||||
|
return qRgb(color[0], color[1], color[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapHandler::drawMinimapTile(QPainter & painter, int x, int y, int z)
|
||||||
|
{
|
||||||
|
painter.setPen(getTileColor(x, y, z));
|
||||||
|
painter.drawPoint(x, y);
|
||||||
|
}
|
||||||
|
@ -98,7 +98,9 @@ public:
|
|||||||
std::vector<TerrainTileObject> & getObjects(int x, int y, int z);
|
std::vector<TerrainTileObject> & getObjects(int x, int y, int z);
|
||||||
//void drawObject(SDL_Surface * targetSurf, std::shared_ptr<IImage> source, SDL_Rect * sourceRect, bool moving) const;
|
//void drawObject(SDL_Surface * targetSurf, std::shared_ptr<IImage> source, SDL_Rect * sourceRect, bool moving) const;
|
||||||
//void drawHeroFlag(SDL_Surface * targetSurf, std::shared_ptr<IImage> source, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const;
|
//void drawHeroFlag(SDL_Surface * targetSurf, std::shared_ptr<IImage> source, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const;
|
||||||
|
QRgb getTileColor(int x, int y, int z);
|
||||||
|
void drawMinimapTile(QPainter & painter, int x, int y, int z);
|
||||||
|
|
||||||
mutable std::map<const CGObjectInstance*, ui8> animationPhase;
|
mutable std::map<const CGObjectInstance*, ui8> animationPhase;
|
||||||
|
|
||||||
MapHandler(const CMap * Map);
|
MapHandler(const CMap * Map);
|
||||||
|
@ -4,12 +4,62 @@
|
|||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include "mapcontroller.h"
|
#include "mapcontroller.h"
|
||||||
|
|
||||||
|
MinimapView::MinimapView(QWidget * parent):
|
||||||
|
QGraphicsView(parent)
|
||||||
|
{
|
||||||
|
// Disable scrollbars
|
||||||
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinimapView::dimensions()
|
||||||
|
{
|
||||||
|
fitInView(0, 0, controller->map()->width, controller->map()->height, Qt::KeepAspectRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinimapView::setController(MapController * ctrl)
|
||||||
|
{
|
||||||
|
controller = ctrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinimapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
||||||
|
{
|
||||||
|
this->update();
|
||||||
|
|
||||||
|
auto * sc = static_cast<MinimapScene*>(scene());
|
||||||
|
if(!sc)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int w = sc->viewport.viewportWidth();
|
||||||
|
int h = sc->viewport.viewportHeight();
|
||||||
|
auto pos = mapToScene(mouseEvent->pos());
|
||||||
|
pos.setX(pos.x() - w / 2);
|
||||||
|
pos.setY(pos.y() - h / 2);
|
||||||
|
|
||||||
|
QPointF point = pos * 32;
|
||||||
|
|
||||||
|
emit cameraPositionChanged(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinimapView::mousePressEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
mouseMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
MapView::MapView(QWidget * parent):
|
MapView::MapView(QWidget * parent):
|
||||||
QGraphicsView(parent),
|
QGraphicsView(parent),
|
||||||
selectionTool(MapView::SelectionTool::None)
|
selectionTool(MapView::SelectionTool::None)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapView::cameraChanged(const QPointF & pos)
|
||||||
|
{
|
||||||
|
//ui->mapView->translate(pos.x(), pos.y());
|
||||||
|
horizontalScrollBar()->setValue(pos.x());
|
||||||
|
verticalScrollBar()->setValue(pos.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MapView::setController(MapController * ctrl)
|
void MapView::setController(MapController * ctrl)
|
||||||
{
|
{
|
||||||
controller = ctrl;
|
controller = ctrl;
|
||||||
@ -273,15 +323,43 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MapScene::MapScene(int lev):
|
bool MapView::viewportEvent(QEvent *event)
|
||||||
|
{
|
||||||
|
if(auto * sc = static_cast<MapScene*>(scene()))
|
||||||
|
{
|
||||||
|
//auto rect = sceneRect();
|
||||||
|
auto rect = mapToScene(viewport()->geometry()).boundingRect();
|
||||||
|
controller->miniScene(sc->level)->viewport.setViewport(rect.x() / 32, rect.y() / 32, rect.width() / 32, rect.height() / 32);
|
||||||
|
}
|
||||||
|
return QGraphicsView::viewportEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
MapSceneBase::MapSceneBase(int lvl):
|
||||||
QGraphicsScene(nullptr),
|
QGraphicsScene(nullptr),
|
||||||
|
level(lvl)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapSceneBase::initialize(MapController & controller)
|
||||||
|
{
|
||||||
|
for(auto * layer : getAbstractLayers())
|
||||||
|
layer->initialize(controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapSceneBase::updateViews()
|
||||||
|
{
|
||||||
|
for(auto * layer : getAbstractLayers())
|
||||||
|
layer->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
MapScene::MapScene(int lvl):
|
||||||
|
MapSceneBase(lvl),
|
||||||
gridView(this),
|
gridView(this),
|
||||||
passabilityView(this),
|
passabilityView(this),
|
||||||
selectionTerrainView(this),
|
selectionTerrainView(this),
|
||||||
terrainView(this),
|
terrainView(this),
|
||||||
objectsView(this),
|
objectsView(this),
|
||||||
selectionObjectsView(this),
|
selectionObjectsView(this)
|
||||||
level(lev)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,19 +376,36 @@ std::list<AbstractLayer *> MapScene::getAbstractLayers()
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapScene::initialize(MapController & controller)
|
|
||||||
{
|
|
||||||
for(auto * layer : getAbstractLayers())
|
|
||||||
layer->initialize(controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MapScene::updateViews()
|
void MapScene::updateViews()
|
||||||
{
|
{
|
||||||
for(auto * layer : getAbstractLayers())
|
MapSceneBase::updateViews();
|
||||||
layer->update();
|
|
||||||
|
|
||||||
terrainView.show(true);
|
terrainView.show(true);
|
||||||
objectsView.show(true);
|
objectsView.show(true);
|
||||||
selectionTerrainView.show(true);
|
selectionTerrainView.show(true);
|
||||||
selectionObjectsView.show(true);
|
selectionObjectsView.show(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MinimapScene::MinimapScene(int lvl):
|
||||||
|
MapSceneBase(lvl),
|
||||||
|
minimapView(this),
|
||||||
|
viewport(this)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<AbstractLayer *> MinimapScene::getAbstractLayers()
|
||||||
|
{
|
||||||
|
//sequence is important because it defines rendering order
|
||||||
|
return {
|
||||||
|
&minimapView,
|
||||||
|
&viewport
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinimapScene::updateViews()
|
||||||
|
{
|
||||||
|
MapSceneBase::updateViews();
|
||||||
|
|
||||||
|
minimapView.show(true);
|
||||||
|
viewport.show(true);
|
||||||
|
}
|
||||||
|
@ -11,13 +11,40 @@ class CGObjectInstance;
|
|||||||
class MainWindow;
|
class MainWindow;
|
||||||
class MapController;
|
class MapController;
|
||||||
|
|
||||||
class MapScene : public QGraphicsScene
|
class MapSceneBase : public QGraphicsScene
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MapScene(int lev);
|
MapSceneBase(int lvl);
|
||||||
|
|
||||||
void updateViews();
|
const int level;
|
||||||
void initialize(MapController &);
|
|
||||||
|
virtual void updateViews();
|
||||||
|
virtual void initialize(MapController &);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual std::list<AbstractLayer *> getAbstractLayers() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MinimapScene : public MapSceneBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MinimapScene(int lvl);
|
||||||
|
|
||||||
|
void updateViews() override;
|
||||||
|
|
||||||
|
MinimapLayer minimapView;
|
||||||
|
MinimapViewLayer viewport;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual std::list<AbstractLayer *> getAbstractLayers();
|
||||||
|
};
|
||||||
|
|
||||||
|
class MapScene : public MapSceneBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MapScene(int lvl);
|
||||||
|
|
||||||
|
void updateViews() override;
|
||||||
|
|
||||||
GridLayer gridView;
|
GridLayer gridView;
|
||||||
PassabilityLayer passabilityView;
|
PassabilityLayer passabilityView;
|
||||||
@ -26,10 +53,8 @@ public:
|
|||||||
ObjectsLayer objectsView;
|
ObjectsLayer objectsView;
|
||||||
SelectionObjectsLayer selectionObjectsView;
|
SelectionObjectsLayer selectionObjectsView;
|
||||||
|
|
||||||
const int level;
|
protected:
|
||||||
|
std::list<AbstractLayer *> getAbstractLayers() override;
|
||||||
private:
|
|
||||||
std::list<AbstractLayer *> getAbstractLayers();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MapView : public QGraphicsView
|
class MapView : public QGraphicsView
|
||||||
@ -52,9 +77,15 @@ public slots:
|
|||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
|
void cameraChanged(const QPointF & pos);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void openObjectProperties(CGObjectInstance *);
|
void openObjectProperties(CGObjectInstance *);
|
||||||
|
//void viewportChanged(const QRectF & rect);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool viewportEvent(QEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MapController * controller = nullptr;
|
MapController * controller = nullptr;
|
||||||
QPointF mouseStart;
|
QPointF mouseStart;
|
||||||
@ -63,4 +94,27 @@ private:
|
|||||||
bool pressedOnSelected;
|
bool pressedOnSelected;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MinimapView : public QGraphicsView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MinimapView(QWidget * parent);
|
||||||
|
void setController(MapController *);
|
||||||
|
|
||||||
|
void dimensions();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void mouseMoveEvent(QMouseEvent * mouseEvent) override;
|
||||||
|
void mousePressEvent(QMouseEvent* event) override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void cameraPositionChanged(const QPointF & newPosition);
|
||||||
|
|
||||||
|
private:
|
||||||
|
MapController * controller = nullptr;
|
||||||
|
|
||||||
|
int displayWidth = 192;
|
||||||
|
int displayHeight = 192;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // MAPVIEW_H
|
#endif // MAPVIEW_H
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>PlayerSettings</class>
|
<class>PlayerSettings</class>
|
||||||
<widget class="QDialog" name="PlayerSettings">
|
<widget class="QDialog" name="PlayerSettings">
|
||||||
|
<property name="windowModality">
|
||||||
|
<enum>Qt::WindowModal</enum>
|
||||||
|
</property>
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
@ -10,8 +13,14 @@
|
|||||||
<height>283</height>
|
<height>283</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Player settings</string>
|
||||||
|
</property>
|
||||||
|
<property name="modal">
|
||||||
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="0" colspan="8">
|
<item row="1" column="0" colspan="8">
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include "mapview.h"
|
#include "mapview.h"
|
||||||
#include "mapcontroller.h"
|
#include "mapcontroller.h"
|
||||||
|
|
||||||
AbstractLayer::AbstractLayer(MapScene * s): scene(s)
|
AbstractLayer::AbstractLayer(MapSceneBase * s): scene(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,29 +21,9 @@ void AbstractLayer::show(bool show)
|
|||||||
if(isShown == show)
|
if(isShown == show)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(show)
|
|
||||||
{
|
|
||||||
if(pixmap)
|
|
||||||
{
|
|
||||||
if(item)
|
|
||||||
item->setPixmap(*pixmap);
|
|
||||||
else
|
|
||||||
item.reset(scene->addPixmap(*pixmap));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(item)
|
|
||||||
item->setPixmap(emptyPixmap);
|
|
||||||
else
|
|
||||||
item.reset(scene->addPixmap(emptyPixmap));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
item->setPixmap(emptyPixmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
isShown = show;
|
isShown = show;
|
||||||
|
|
||||||
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractLayer::redraw()
|
void AbstractLayer::redraw()
|
||||||
@ -64,7 +44,7 @@ void AbstractLayer::redraw()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GridLayer::GridLayer(MapScene * s): AbstractLayer(s)
|
GridLayer::GridLayer(MapSceneBase * s): AbstractLayer(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +70,7 @@ void GridLayer::update()
|
|||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
PassabilityLayer::PassabilityLayer(MapScene * s): AbstractLayer(s)
|
PassabilityLayer::PassabilityLayer(MapSceneBase * s): AbstractLayer(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +101,7 @@ void PassabilityLayer::update()
|
|||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectionTerrainLayer::SelectionTerrainLayer(MapScene * s): AbstractLayer(s)
|
SelectionTerrainLayer::SelectionTerrainLayer(MapSceneBase * s): AbstractLayer(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +180,7 @@ const std::set<int3> & SelectionTerrainLayer::selection() const
|
|||||||
return area;
|
return area;
|
||||||
}
|
}
|
||||||
|
|
||||||
TerrainLayer::TerrainLayer(MapScene * s): AbstractLayer(s)
|
TerrainLayer::TerrainLayer(MapSceneBase * s): AbstractLayer(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,7 +255,7 @@ void TerrainLayer::draw(bool onlyDirty)
|
|||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectsLayer::ObjectsLayer(MapScene * s): AbstractLayer(s)
|
ObjectsLayer::ObjectsLayer(MapSceneBase * s): AbstractLayer(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +322,7 @@ void ObjectsLayer::setDirty(const CGObjectInstance * object)
|
|||||||
dirty.insert(object);
|
dirty.insert(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectionObjectsLayer::SelectionObjectsLayer(MapScene * s): AbstractLayer(s), newObject(nullptr)
|
SelectionObjectsLayer::SelectionObjectsLayer(MapSceneBase * s): AbstractLayer(s), newObject(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,3 +471,71 @@ void SelectionObjectsLayer::clear()
|
|||||||
shift.setX(0);
|
shift.setX(0);
|
||||||
shift.setY(0);
|
shift.setY(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MinimapLayer::MinimapLayer(MapSceneBase * s): AbstractLayer(s)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinimapLayer::update()
|
||||||
|
{
|
||||||
|
if(!map)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pixmap.reset(new QPixmap(map->width, map->height));
|
||||||
|
|
||||||
|
QPainter painter(pixmap.get());
|
||||||
|
//coordinate transfomation
|
||||||
|
for(int j = 0; j < map->height; ++j)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < map->width; ++i)
|
||||||
|
{
|
||||||
|
handler->drawMinimapTile(painter, i, j, scene->level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
MinimapViewLayer::MinimapViewLayer(MapSceneBase * s): AbstractLayer(s)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinimapViewLayer::update()
|
||||||
|
{
|
||||||
|
if(!map)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pixmap.reset(new QPixmap(map->width, map->height));
|
||||||
|
pixmap->fill(QColor(0, 0, 0, 0));
|
||||||
|
|
||||||
|
QPainter painter(pixmap.get());
|
||||||
|
painter.setPen(QColor(255, 255, 255));
|
||||||
|
painter.drawRect(x, y, w, h);
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinimapViewLayer::draw()
|
||||||
|
{
|
||||||
|
if(!map)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pixmap->fill(QColor(0, 0, 0, 0));
|
||||||
|
|
||||||
|
//maybe not optimal but ok
|
||||||
|
QPainter painter(pixmap.get());
|
||||||
|
painter.setPen(QColor(255, 255, 255));
|
||||||
|
painter.drawRect(x, y, w, h);
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinimapViewLayer::setViewport(int _x, int _y, int _w, int _h)
|
||||||
|
{
|
||||||
|
x = _x;
|
||||||
|
y = _y;
|
||||||
|
w = _w;
|
||||||
|
h = _h;
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "../lib/int3.h"
|
#include "../lib/int3.h"
|
||||||
|
|
||||||
class MapScene;
|
class MapSceneBase;
|
||||||
class CGObjectInstance;
|
class CGObjectInstance;
|
||||||
class MapController;
|
class MapController;
|
||||||
class CMap;
|
class CMap;
|
||||||
@ -12,7 +12,7 @@ class MapHandler;
|
|||||||
class AbstractLayer
|
class AbstractLayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AbstractLayer(MapScene * s);
|
AbstractLayer(MapSceneBase * s);
|
||||||
|
|
||||||
virtual void update() = 0;
|
virtual void update() = 0;
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ public:
|
|||||||
void initialize(MapController & controller);
|
void initialize(MapController & controller);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MapScene * scene;
|
MapSceneBase * scene;
|
||||||
CMap * map = nullptr;
|
CMap * map = nullptr;
|
||||||
MapHandler * handler = nullptr;
|
MapHandler * handler = nullptr;
|
||||||
bool isShown = false;
|
bool isShown = false;
|
||||||
@ -37,7 +37,7 @@ private:
|
|||||||
class GridLayer: public AbstractLayer
|
class GridLayer: public AbstractLayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GridLayer(MapScene * s);
|
GridLayer(MapSceneBase * s);
|
||||||
|
|
||||||
void update() override;
|
void update() override;
|
||||||
};
|
};
|
||||||
@ -45,7 +45,7 @@ public:
|
|||||||
class PassabilityLayer: public AbstractLayer
|
class PassabilityLayer: public AbstractLayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PassabilityLayer(MapScene * s);
|
PassabilityLayer(MapSceneBase * s);
|
||||||
|
|
||||||
void update() override;
|
void update() override;
|
||||||
};
|
};
|
||||||
@ -54,7 +54,7 @@ public:
|
|||||||
class SelectionTerrainLayer: public AbstractLayer
|
class SelectionTerrainLayer: public AbstractLayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SelectionTerrainLayer(MapScene * s);
|
SelectionTerrainLayer(MapSceneBase * s);
|
||||||
|
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ private:
|
|||||||
class TerrainLayer: public AbstractLayer
|
class TerrainLayer: public AbstractLayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TerrainLayer(MapScene * s);
|
TerrainLayer(MapSceneBase * s);
|
||||||
|
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ private:
|
|||||||
class ObjectsLayer: public AbstractLayer
|
class ObjectsLayer: public AbstractLayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ObjectsLayer(MapScene * s);
|
ObjectsLayer(MapSceneBase * s);
|
||||||
|
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ private:
|
|||||||
class SelectionObjectsLayer: public AbstractLayer
|
class SelectionObjectsLayer: public AbstractLayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SelectionObjectsLayer(MapScene * s);
|
SelectionObjectsLayer(MapSceneBase * s);
|
||||||
|
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
@ -127,4 +127,32 @@ private:
|
|||||||
std::set<CGObjectInstance *> selectedObjects;
|
std::set<CGObjectInstance *> selectedObjects;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MinimapLayer: public AbstractLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MinimapLayer(MapSceneBase * s);
|
||||||
|
|
||||||
|
void update() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MinimapViewLayer: public AbstractLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MinimapViewLayer(MapSceneBase * s);
|
||||||
|
|
||||||
|
void setViewport(int x, int y, int w, int h);
|
||||||
|
|
||||||
|
void draw();
|
||||||
|
void update() override;
|
||||||
|
|
||||||
|
int viewportX() const {return x;}
|
||||||
|
int viewportY() const {return y;}
|
||||||
|
int viewportWidth() const {return w;}
|
||||||
|
int viewportHeight() const {return h;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int x = 0, y = 0, w = 1, h = 1;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
#endif // SCENELAYER_H
|
#endif // SCENELAYER_H
|
||||||
|
@ -250,15 +250,23 @@ void WindowNewMap::on_templateCombo_activated(int index)
|
|||||||
|
|
||||||
void WindowNewMap::on_widthTxt_textChanged(const QString &arg1)
|
void WindowNewMap::on_widthTxt_textChanged(const QString &arg1)
|
||||||
{
|
{
|
||||||
mapGenOptions.setWidth(arg1.toInt());
|
int sz = arg1.toInt();
|
||||||
updateTemplateList();
|
if(sz > 1)
|
||||||
|
{
|
||||||
|
mapGenOptions.setWidth(arg1.toInt());
|
||||||
|
updateTemplateList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WindowNewMap::on_heightTxt_textChanged(const QString &arg1)
|
void WindowNewMap::on_heightTxt_textChanged(const QString &arg1)
|
||||||
{
|
{
|
||||||
mapGenOptions.setHeight(arg1.toInt());
|
int sz = arg1.toInt();
|
||||||
updateTemplateList();
|
if(sz > 1)
|
||||||
|
{
|
||||||
|
mapGenOptions.setHeight(arg1.toInt());
|
||||||
|
updateTemplateList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowNewMap::updateTemplateList()
|
void WindowNewMap::updateTemplateList()
|
||||||
|
Loading…
Reference in New Issue
Block a user