mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-07 15:10:43 +02:00
Passability view and grid view
This commit is contained in:
parent
f3caa3d7bb
commit
c096b8dd00
@ -12,6 +12,7 @@ set(editor_SRCS
|
||||
spoiler.cpp
|
||||
windownewmap.cpp
|
||||
generatorprogress.cpp
|
||||
mapview.cpp
|
||||
)
|
||||
|
||||
set(editor_HEADERS
|
||||
@ -27,6 +28,7 @@ set(editor_HEADERS
|
||||
spoiler.h
|
||||
windownewmap.h
|
||||
generatorprogress.h
|
||||
mapview.h
|
||||
)
|
||||
|
||||
set(editor_FORMS
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include "../lib/GameConstants.h"
|
||||
#include "../lib/mapping/CMapService.h"
|
||||
#include "../lib/mapping/CMap.h"
|
||||
#include "../lib/Terrain.h"
|
||||
#include "../lib/mapObjects/CObjectClassesHandler.h"
|
||||
|
||||
|
||||
#include "CGameInfo.h"
|
||||
@ -37,6 +39,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->mapView->setMain(this);
|
||||
|
||||
//configure logging
|
||||
const boost::filesystem::path logPath = VCMIDirs::get().userCachePath() / "VCMI_Editor_log.txt";
|
||||
console = new CConsoleHandler();
|
||||
@ -86,15 +90,21 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
//now let's try to draw
|
||||
auto resPath = *CResourceHandler::get()->getResourceName(ResourceID("DATA/new-menu/Background.png"));
|
||||
|
||||
scene = new QGraphicsScene(this);
|
||||
ui->graphicsView->setScene(scene);
|
||||
scenes[0] = new MapScene(this, 0);
|
||||
scenes[1] = new MapScene(this, 1);
|
||||
ui->mapView->setScene(scenes[0]);
|
||||
|
||||
sceneMini = new QGraphicsScene(this);
|
||||
ui->minimapView->setScene(sceneMini);
|
||||
|
||||
scene->addPixmap(QPixmap(QString::fromStdString(resPath.native())));
|
||||
scenes[0]->addPixmap(QPixmap(QString::fromStdString(resPath.native())));
|
||||
|
||||
//loading objects
|
||||
loadObjectsTree();
|
||||
|
||||
show();
|
||||
|
||||
setStatusMessage("privet");
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -102,6 +112,11 @@ MainWindow::~MainWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::setStatusMessage(const QString & status)
|
||||
{
|
||||
statusBar()->showMessage(status);
|
||||
}
|
||||
|
||||
void MainWindow::reloadMap(int level)
|
||||
{
|
||||
MapHandler mapHandler(map.get());
|
||||
@ -116,16 +131,19 @@ void MainWindow::reloadMap(int level)
|
||||
}
|
||||
|
||||
auto mapSizePx = mapHandler.surface.rect();
|
||||
float ratio = std::fmin(mapSizePx.width() / 256., mapSizePx.height() / 256.);
|
||||
float ratio = std::fmin(mapSizePx.width() / 192., mapSizePx.height() / 192.);
|
||||
minimap = mapHandler.surface;
|
||||
minimap.setDevicePixelRatio(ratio);
|
||||
|
||||
scene->clear();
|
||||
scene->addPixmap(mapHandler.surface);
|
||||
//ui->graphicsView->setSceneRect(mapHandler.surface.rect());
|
||||
scenes[level]->updateViews(mapHandler.surface);
|
||||
|
||||
sceneMini->clear();
|
||||
sceneMini->addPixmap(minimap);
|
||||
//sceneMini->clear();
|
||||
//sceneMini->addPixmap(minimap);
|
||||
}
|
||||
|
||||
CMap * MainWindow::getMap()
|
||||
{
|
||||
return map.get();
|
||||
}
|
||||
|
||||
void MainWindow::setMapRaw(std::unique_ptr<CMap> cmap)
|
||||
@ -133,12 +151,19 @@ void MainWindow::setMapRaw(std::unique_ptr<CMap> cmap)
|
||||
map = std::move(cmap);
|
||||
}
|
||||
|
||||
void MainWindow::setMap()
|
||||
void MainWindow::setMap(bool isNew)
|
||||
{
|
||||
unsaved = true;
|
||||
filename.clear();
|
||||
setWindowTitle("* - VCMI Map Editor");
|
||||
unsaved = isNew;
|
||||
if(isNew)
|
||||
filename.clear();
|
||||
|
||||
setWindowTitle(filename + "* - VCMI Map Editor");
|
||||
reloadMap();
|
||||
if(map->twoLevel)
|
||||
reloadMap(1);
|
||||
|
||||
mapLevel = 0;
|
||||
ui->mapView->setScene(scenes[mapLevel]);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionOpen_triggered()
|
||||
@ -170,11 +195,7 @@ void MainWindow::on_actionOpen_triggered()
|
||||
QMessageBox::critical(this, "Failed to open map", e.what());
|
||||
}
|
||||
|
||||
unsaved = false;
|
||||
filename = filenameSelect;
|
||||
setWindowTitle(filename + " - VCMI Map Editor");
|
||||
|
||||
reloadMap();
|
||||
setMap(false);
|
||||
}
|
||||
|
||||
void MainWindow::saveMap()
|
||||
@ -223,17 +244,6 @@ void MainWindow::on_actionNew_triggered()
|
||||
auto newMapDialog = new WindowNewMap(this);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionLevel_triggered()
|
||||
{
|
||||
if(map && map->twoLevel)
|
||||
{
|
||||
mapLevel = mapLevel ? 0 : 1;
|
||||
reloadMap(mapLevel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionSave_triggered()
|
||||
{
|
||||
if(!map)
|
||||
@ -252,3 +262,91 @@ void MainWindow::on_actionSave_triggered()
|
||||
saveMap();
|
||||
}
|
||||
|
||||
void MainWindow::loadObjectsTree()
|
||||
{
|
||||
for(auto & terrain : Terrain::Manager::terrains())
|
||||
{
|
||||
ui->listTerrains->addItem(QString::fromStdString(terrain));
|
||||
}
|
||||
/*
|
||||
createHandler(bth, "Bonus type", pomtime);
|
||||
createHandler(generaltexth, "General text", pomtime);
|
||||
createHandler(heroh, "Hero", pomtime);
|
||||
createHandler(arth, "Artifact", pomtime);
|
||||
createHandler(creh, "Creature", pomtime);
|
||||
createHandler(townh, "Town", pomtime);
|
||||
createHandler(objh, "Object", pomtime);
|
||||
createHandler(objtypeh, "Object types information", pomtime);
|
||||
createHandler(spellh, "Spell", pomtime);
|
||||
createHandler(skillh, "Skill", pomtime);
|
||||
createHandler(terviewh, "Terrain view pattern", pomtime);
|
||||
createHandler(tplh, "Template", pomtime); //templates need already resolved identifiers (refactor?)
|
||||
createHandler(scriptHandler, "Script", pomtime);
|
||||
createHandler(battlefieldsHandler, "Battlefields", pomtime);
|
||||
createHandler(obstacleHandler, "Obstacles", pomtime);*/
|
||||
|
||||
std::map<std::string, std::vector<std::string>> identifiers;
|
||||
|
||||
for(auto primaryID : VLC->objtypeh->knownObjects())
|
||||
{
|
||||
//QList<QStandardItem*> objTypes;
|
||||
|
||||
for(auto secondaryID : VLC->objtypeh->knownSubObjects(primaryID))
|
||||
{
|
||||
//QList<QStandardItem*> objSubTypes;
|
||||
auto handler = VLC->objtypeh->getHandlerFor(primaryID, secondaryID);
|
||||
|
||||
/*if(handler->isStaticObject())
|
||||
{
|
||||
for(auto temp : handler->getTemplates())
|
||||
{
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
identifiers[handler->typeName].push_back(handler->subTypeName);
|
||||
}
|
||||
}
|
||||
|
||||
objectsModel.setHorizontalHeaderLabels(QStringList() << QStringLiteral("Type"));
|
||||
QList<QStandardItem*> objTypes;
|
||||
for(auto & el1 : identifiers)
|
||||
{
|
||||
auto * objTypei = new QStandardItem(QString::fromStdString(el1.first));
|
||||
for(auto & el2 : el1.second)
|
||||
{
|
||||
objTypei->appendRow(new QStandardItem(QString::fromStdString(el2)));
|
||||
}
|
||||
objectsModel.appendRow(objTypei);
|
||||
}
|
||||
ui->treeView->setModel(&objectsModel);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionLevel_triggered()
|
||||
{
|
||||
if(map && map->twoLevel)
|
||||
{
|
||||
mapLevel = mapLevel ? 0 : 1;
|
||||
ui->mapView->setScene(scenes[mapLevel]);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionPass_triggered(bool checked)
|
||||
{
|
||||
if(map)
|
||||
{
|
||||
scenes[0]->passabilityView.show(checked);
|
||||
scenes[1]->passabilityView.show(checked);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionGrid_triggered(bool checked)
|
||||
{
|
||||
if(map)
|
||||
{
|
||||
scenes[0]->gridView.show(checked);
|
||||
scenes[1]->gridView.show(checked);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,11 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QGraphicsScene>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
#include "maphandler.h"
|
||||
|
||||
#include "mapview.h"
|
||||
class CMap;
|
||||
|
||||
namespace Ui {
|
||||
@ -21,10 +23,16 @@ public:
|
||||
~MainWindow();
|
||||
|
||||
void setMapRaw(std::unique_ptr<CMap> cmap);
|
||||
void setMap();
|
||||
void setMap(bool isNew);
|
||||
void reloadMap(int level = 0);
|
||||
void saveMap();
|
||||
|
||||
CMap * getMap();
|
||||
|
||||
void loadObjectsTree();
|
||||
|
||||
void setStatusMessage(const QString & status);
|
||||
|
||||
private slots:
|
||||
void on_actionOpen_triggered();
|
||||
|
||||
@ -36,10 +44,14 @@ private slots:
|
||||
|
||||
void on_actionSave_triggered();
|
||||
|
||||
void on_actionPass_triggered(bool checked);
|
||||
|
||||
void on_actionGrid_triggered(bool checked);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
QGraphicsScene * scene;
|
||||
std::array<MapScene *, 2> scenes;
|
||||
QGraphicsScene * sceneMini;
|
||||
QPixmap minimap;
|
||||
|
||||
@ -47,6 +59,8 @@ private:
|
||||
QString filename;
|
||||
bool unsaved = false;
|
||||
|
||||
QStandardItemModel objectsModel;
|
||||
|
||||
int mapLevel = 0;
|
||||
};
|
||||
|
||||
|
@ -15,30 +15,8 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="1">
|
||||
<widget class="QGraphicsView" name="minimapView">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>256</width>
|
||||
<height>256</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>256</width>
|
||||
<height>256</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="2">
|
||||
<widget class="QGraphicsView" name="graphicsView">
|
||||
<item row="0" column="0">
|
||||
<widget class="MapView" name="mapView">
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||
</property>
|
||||
@ -66,7 +44,6 @@
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<widget class="QToolBar" name="toolBar">
|
||||
<property name="windowTitle">
|
||||
<string>toolBar</string>
|
||||
@ -82,7 +59,235 @@
|
||||
<addaction name="actionSave"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionLevel"/>
|
||||
<addaction name="actionGrid"/>
|
||||
<addaction name="actionPass"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionCut"/>
|
||||
<addaction name="actionCopy"/>
|
||||
<addaction name="actionPaste"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionFill"/>
|
||||
</widget>
|
||||
<widget class="QDockWidget" name="dockWidget_2">
|
||||
<attribute name="dockWidgetArea">
|
||||
<number>2</number>
|
||||
</attribute>
|
||||
<widget class="QWidget" name="dockWidgetContents_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<widget class="QGraphicsView" name="minimapView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>192</width>
|
||||
<height>192</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>192</width>
|
||||
<height>192</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QDockWidget" name="dockWidget_3">
|
||||
<attribute name="dockWidgetArea">
|
||||
<number>2</number>
|
||||
</attribute>
|
||||
<widget class="QWidget" name="dockWidgetContents_3">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<attribute name="title">
|
||||
<string>Surface</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolBox" name="toolBox">
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page_5">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>262</width>
|
||||
<height>170</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
<string>Terrains</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QListWidget" name="listTerrains"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_6">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>262</width>
|
||||
<height>170</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
<string>Roads</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QListWidget" name="listRoads"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_7">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>262</width>
|
||||
<height>170</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
<string>Rivers</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QListWidget" name="listRivers"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<attribute name="title">
|
||||
<string>Objects</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="terrainFilterCombo"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeView" name="treeView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<action name="actionOpen">
|
||||
<property name="text">
|
||||
<string>Open</string>
|
||||
@ -108,7 +313,93 @@
|
||||
<string>U/G</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action1x1">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>1x1</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action2x2">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>2x2</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action3x3">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>3x3</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action4x4">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>4x4</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionErase">
|
||||
<property name="text">
|
||||
<string>Erase</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPass">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Pass</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCut">
|
||||
<property name="text">
|
||||
<string>Cut</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCopy">
|
||||
<property name="text">
|
||||
<string>Copy</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPaste">
|
||||
<property name="text">
|
||||
<string>Paste</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionFill">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fill</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Fills the selection with obstacles</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionGrid">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Grid</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>MapView</class>
|
||||
<extends>QGraphicsView</extends>
|
||||
<header>mapview.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
135
mapeditor/mapview.cpp
Normal file
135
mapeditor/mapview.cpp
Normal file
@ -0,0 +1,135 @@
|
||||
#include "mapview.h"
|
||||
#include "mainwindow.h"
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
MapView::MapView(QWidget *parent):
|
||||
QGraphicsView(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void MapView::setMain(MainWindow * m)
|
||||
{
|
||||
main = m;
|
||||
}
|
||||
|
||||
void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
||||
{
|
||||
this->update();
|
||||
|
||||
auto pos = mouseEvent->pos();
|
||||
|
||||
main->setStatusMessage(QString("x: %1 y: %2").arg(QString::number(pos.x()), QString::number(pos.y())));
|
||||
}
|
||||
|
||||
void MapView::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
this->update();
|
||||
}
|
||||
|
||||
void MapView::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
this->update();
|
||||
}
|
||||
|
||||
MapScene::MapScene(MainWindow *parent, int l):
|
||||
QGraphicsScene(parent),
|
||||
gridView(parent, this),
|
||||
passabilityView(parent, this),
|
||||
main(parent),
|
||||
level(l)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MapScene::updateViews(const QPixmap & surface)
|
||||
{
|
||||
if(item)
|
||||
removeItem(item.get());
|
||||
item.reset(addPixmap(surface));
|
||||
|
||||
gridView.update();
|
||||
passabilityView.update();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if(item)
|
||||
scene->addItem(item.get());
|
||||
else
|
||||
item.reset(scene->addPixmap(*pixmap));
|
||||
}
|
||||
else
|
||||
{
|
||||
scene->removeItem(item.get());
|
||||
}
|
||||
|
||||
isShown = show;
|
||||
}
|
||||
|
||||
GridView::GridView(MainWindow * m, MapScene * s): BasicView(m, s)
|
||||
{
|
||||
}
|
||||
|
||||
void GridView::update()
|
||||
{
|
||||
show(false);
|
||||
auto map = main->getMap();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
show(isShown);
|
||||
}
|
||||
|
||||
PassabilityView::PassabilityView(MainWindow * m, MapScene * s): BasicView(m, s)
|
||||
{
|
||||
}
|
||||
|
||||
void PassabilityView::update()
|
||||
{
|
||||
show(false);
|
||||
auto map = main->getMap();
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
show(isShown);
|
||||
}
|
79
mapeditor/mapview.h
Normal file
79
mapeditor/mapview.h
Normal file
@ -0,0 +1,79 @@
|
||||
#ifndef MAPVIEW_H
|
||||
#define MAPVIEW_H
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
|
||||
class MainWindow;
|
||||
class MapScene;
|
||||
|
||||
class BasicView
|
||||
{
|
||||
public:
|
||||
BasicView(MainWindow * m, MapScene * s);
|
||||
|
||||
virtual void update() = 0;
|
||||
|
||||
void show(bool show);
|
||||
|
||||
protected:
|
||||
MainWindow * main;
|
||||
MapScene * scene;
|
||||
bool isShown = false;
|
||||
|
||||
std::unique_ptr<QPixmap> pixmap;
|
||||
|
||||
private:
|
||||
std::unique_ptr<QGraphicsPixmapItem> item;
|
||||
};
|
||||
|
||||
class MapView : public QGraphicsView
|
||||
{
|
||||
public:
|
||||
MapView(QWidget *parent);
|
||||
|
||||
void setMain(MainWindow * m);
|
||||
|
||||
public slots:
|
||||
void mouseMoveEvent(QMouseEvent * mouseEvent) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
MainWindow * main;
|
||||
};
|
||||
|
||||
class GridView: public BasicView
|
||||
{
|
||||
public:
|
||||
GridView(MainWindow * m, MapScene * s);
|
||||
|
||||
void update() override;
|
||||
};
|
||||
|
||||
class PassabilityView: public BasicView
|
||||
{
|
||||
public:
|
||||
PassabilityView(MainWindow * m, MapScene * s);
|
||||
|
||||
void update() override;
|
||||
};
|
||||
|
||||
class MapScene : public QGraphicsScene
|
||||
{
|
||||
public:
|
||||
MapScene(MainWindow *parent, int l);
|
||||
|
||||
void updateViews(const QPixmap & surface);
|
||||
|
||||
GridView gridView;
|
||||
PassabilityView passabilityView;
|
||||
|
||||
const int level;
|
||||
|
||||
private:
|
||||
std::unique_ptr<QGraphicsPixmapItem> item;
|
||||
MainWindow * main;
|
||||
};
|
||||
|
||||
#endif // MAPVIEW_H
|
@ -71,7 +71,7 @@ void WindowNewMap::on_okButtong_clicked()
|
||||
generate.join();
|
||||
}
|
||||
|
||||
static_cast<MainWindow*>(parent())->setMap();
|
||||
static_cast<MainWindow*>(parent())->setMap(true);
|
||||
close();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user