From a951fc85da03951f6aed071d4c3b51b03773706e Mon Sep 17 00:00:00 2001 From: garak Date: Tue, 22 Jan 2019 15:06:49 -0500 Subject: [PATCH] region map ui updates and other fixes --- forms/regionmapeditor.ui | 1898 +++++++++++++------------- include/core/historyitem.h | 15 +- include/core/regionmap.h | 7 +- include/ui/citymappixmapitem.h | 6 + include/ui/regionmapeditor.h | 29 +- include/ui/tilemaptileselector.h | 2 +- src/core/historyitem.cpp | 21 +- src/core/regionmap.cpp | 25 +- src/ui/citymappixmapitem.cpp | 33 + src/ui/regionmapeditor.cpp | 282 ++-- src/ui/regionmaplayoutpixmapitem.cpp | 5 +- src/ui/regionmappixmapitem.cpp | 12 +- 12 files changed, 1267 insertions(+), 1068 deletions(-) diff --git a/forms/regionmapeditor.ui b/forms/regionmapeditor.ui index 010322a1..6e2e06ce 100644 --- a/forms/regionmapeditor.ui +++ b/forms/regionmapeditor.ui @@ -6,133 +6,801 @@ 0 0 - 709 - 619 + 829 + 644 Region Map Editor - - - - - 30 - 250 - 20 - 20 - - - - + - - - - - - 10 - 250 - 20 - 20 - - - - - - - - - - - 10 - 280 - 691 - 271 - - - - Qt::Horizontal - - - - - QLayout::SetDefaultConstraint + + + + + + Qt::Vertical - - - - - - City Map: - - - - - - - - - - - 0 - 0 - - - - <html><head/><body><p>Add a new city map.</p></body></html> - - - - - - - :/icons/add.ico - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - save - - - - - - - + + false + + + + Qt::Horizontal + + + false + + + + + 393 + 251 + + + + 0 + + + + Background Image + + + + + + + 1 + 1 + + + + true + + + + + 0 + 0 + 345 + 188 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 166 + 16 + + + + + + + + + 0 + 0 + + + + false + + + false + + + QAbstractScrollArea::AdjustIgnored + + + QGraphicsView::NoDrag + + + + + + + Qt::Vertical + + + + 16 + 166 + + + + + + + + Qt::Vertical + + + + 16 + 166 + + + + + + + + Qt::Horizontal + + + + 166 + 16 + + + + + + + + + + + + + Map Layout + + + + + + + 1 + 0 + + + + true + + + + + 0 + 0 + 345 + 188 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + false + + + false + + + QAbstractScrollArea::AdjustIgnored + + + QGraphicsView::NoDrag + + + + + + + Qt::Horizontal + + + + 166 + 16 + + + + + + + + Qt::Vertical + + + + 16 + 166 + + + + + + + + Qt::Horizontal + + + + 166 + 16 + + + + + + + + Qt::Vertical + + + + 16 + 166 + + + + + + + + + + + + + + + 320 + 200 + + + + 0 + + + + + + + + 0 + 0 + + + + + 162 + 162 + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAsNeeded + + + QAbstractScrollArea::AdjustIgnored + + + true + + + Qt::AlignHCenter|Qt::AlignTop + + + + true + + + + 8 + 0 + 281 + 225 + + + + + 0 + 0 + + + + + QLayout::SetDefaultConstraint + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + true + + + + 0 + 0 + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustIgnored + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + false + + + + 0 + 0 + + + + + 300 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + 1 + + + + + 13 + 11 + 281 + 91 + + + + + + + Map Section + + + + + + + + 0 + 0 + + + + <html><head/><body><p>The section of the region map which the map is grouped under. This also determines the name of the map that is display when the player enters it.</p></body></html> + + + true + + + + + + + Map Name + + + + + + + + + + City Map + + + + + + + <html><head/><body><p>The map type is a general attribute, which is used for many different things. For example. it determines whether biking or running is allowed.</p></body></html> + + + true + + + + + + + + + 10 + 100 + 138 + 26 + + + + + + + x + + + + + + + + + + y + + + + + + + + + + + + 10 + 190 + 113 + 32 + + + + Delete Square + + + + + + + + + + + Qt::Horizontal + + + false + + + + + QLayout::SetDefaultConstraint + + + + + + + City Map: + + + + + + + + + + + 0 + 0 + + + + <html><head/><body><p>Add a new city map.</p></body></html> + + + + + + + :/icons/add.ico + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 1 + 0 + + + + + 102 + 102 + + + + true + + + + + 0 + 0 + 440 + 267 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 166 + 16 + + + + + + + + Qt::Vertical + + + + 16 + 166 + + + + + + + + + 0 + 0 + + + + false + + + false + + + QAbstractScrollArea::AdjustIgnored + + + QGraphicsView::NoDrag + + + + + + + Qt::Vertical + + + + 16 + 166 + + + + + + + + Qt::Horizontal + + + + 166 + 16 + + + + + + + + + + + - - 1 + + 0 0 + + + 82 + 82 + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAsNeeded + + + QAbstractScrollArea::AdjustIgnored + true - + + Qt::AlignHCenter|Qt::AlignTop + + + + true + - 0 + 8 0 - 420 - 225 + 254 + 311 - + + + 0 + 0 + + + + + QLayout::SetDefaultConstraint + 0 @@ -148,76 +816,66 @@ 0 - - + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 40 + + + + + + Qt::Horizontal - 166 - 16 + 40 + 20 - - - Qt::Vertical + + + true - - - 16 - 166 - - - - - - - - Qt::Vertical - - - - 16 - 166 - - - - - - - + 0 0 - - false + + Qt::ScrollBarAlwaysOff - - false + + Qt::ScrollBarAlwaysOff QAbstractScrollArea::AdjustIgnored - - QGraphicsView::NoDrag - - - + + Qt::Horizontal - 166 - 16 + 40 + 20 @@ -225,795 +883,175 @@ + + + + + + + + + + 30 + 50 + + + + + 30 + 160 + + + + 1 + + + 4 + + + Qt::Vertical + + + QSlider::TicksAbove + + + 1 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 30 + 0 + + + + + 30 + 160 + + + + 1 + + + 4 + + + Qt::Vertical + + + QSlider::TicksAbove + + + 1 + + - - - - - 0 - 0 - - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAsNeeded - - - QAbstractScrollArea::AdjustIgnored - - - true - - - Qt::AlignHCenter|Qt::AlignTop - - - - true - - - - 8 - 0 - 242 - 269 - - - - - 0 - 0 - - - - - QLayout::SetDefaultConstraint - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Vertical - - - QSizePolicy::Preferred - - - - 20 - 40 - - - - - - - - true - - - - 0 - 0 - - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustIgnored - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - 30 - 550 - 20 - 20 - - - - - 0 - 0 - - - - + - - - - - - 10 - 550 - 20 - 20 - - - - - 0 - 0 - - - - - - - - - - - 661 - 550 - 20 - 20 - - - - - 0 - 0 - - - - - - - - - - - 681 - 550 - 20 - 20 - - - - - 0 - 0 - - - - + - - - - - - 681 - 250 - 20 - 20 - - - - + - - - - - - 661 - 250 - 20 - 20 - - - - - - - - - - - 10 - 10 - 691 - 241 - - - - - - - 0 - - - - Background Image - - - - - -1 - -1 - 341 - 213 - - - - - 1 - 0 - - - - true - - - - - 0 - 0 - 339 - 211 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - false - - - false - - - QAbstractScrollArea::AdjustIgnored - - - QGraphicsView::NoDrag - - - - - - - Qt::Horizontal - - - - 166 - 16 - - - - - - - - Qt::Vertical - - - - 16 - 166 - - - - - - - - Qt::Horizontal - - - - 166 - 16 - - - - - - - - Qt::Vertical - - - - 16 - 166 - - - - - - - + + + + + + + + 30 + 50 + + + + + 30 + 160 + + + + 1 + + + 4 + + + Qt::Vertical + + + QSlider::TicksBelow + + + 1 + - - - Map Layout - - - - - -1 - -1 - 341 - 213 - - - - - 1 - 0 - - - - true - - - - - 0 - 0 - 339 - 211 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - false - - - false - - - QAbstractScrollArea::AdjustIgnored - - - QGraphicsView::NoDrag - - - - - - - Qt::Horizontal - - - - 166 - 16 - - - - - - - - Qt::Vertical - - - - 16 - 166 - - - - - - - - Qt::Horizontal - - - - 166 - 16 - - - - - - - - Qt::Vertical - - - - 16 - 166 - - - - - - - + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 30 + 0 + + + + + 30 + 160 + + + + 1 + + + 4 + + + Qt::Vertical + + + QSlider::TicksBelow + + + 1 + - - - - - - 0 - - - - - - 0 - 10 - 342 - 230 - - - - - 0 - 0 - - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAsNeeded - - - QAbstractScrollArea::AdjustIgnored - - - true - - - Qt::AlignHCenter|Qt::AlignTop - - - - true - - - - 8 - 0 - 324 - 228 - - - - - 0 - 0 - - - - - QLayout::SetDefaultConstraint - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - true - - - - 0 - 0 - - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustIgnored - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - false - - - - 0 - 10 - 342 - 230 - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 10 - 170 - 107 - 32 - - - - Set Values - - - - - - 13 - 11 - 301 - 111 - - - - - - - Map Section - - - - - - - <html><head/><body><p>The section of the region map which the map is grouped under. This also determines the name of the map that is display when the player enters it.</p></body></html> - - - true - - - - - - - Map Name - - - - - - - - - - City Map - - - - - - - <html><head/><body><p>The map type is a general attribute, which is used for many different things. For example. it determines whether biking or running is allowed.</p></body></html> - - - true - - - - - - - - - 20 - 130 - 138 - 26 - - - - - - - x - - - - - - - - - - y - - - - - - - - - - - - 210 - 170 - 113 - 32 - - - - Delete Square - - - - - - - - + + + + 0 0 - 709 + 829 22 diff --git a/include/core/historyitem.h b/include/core/historyitem.h index 6ccda292..7d87795d 100644 --- a/include/core/historyitem.h +++ b/include/core/historyitem.h @@ -2,6 +2,7 @@ #define HISTORYITEM_H #include "blockdata.h" +//#include "regionmap.h" class HistoryItem { public: @@ -15,15 +16,19 @@ public: enum RegionMapEditorBox { BackgroundImage = 1, CityMapImage = 2, + BackroundResize = 3, }; class RegionMapHistoryItem { public: - int which;// region map or city map - int index; - unsigned tile; - unsigned prev; - RegionMapHistoryItem(int type, int index, unsigned prev, unsigned tile); + int which; + int mapWidth; + int mapHeight; + QVector tiles; + QString cityMap; + RegionMapHistoryItem(int type, QVector tiles); + RegionMapHistoryItem(int type, QVector tiles, QString cityMap); + RegionMapHistoryItem(int type, QVector tiles, int width, int height); ~RegionMapHistoryItem(); }; diff --git a/include/core/regionmap.h b/include/core/regionmap.h index ae804148..7c4b70a9 100644 --- a/include/core/regionmap.h +++ b/include/core/regionmap.h @@ -1,8 +1,8 @@ #ifndef REGIONMAP_H #define REGIONMAP_H -#include "project.h" #include "map.h" +#include "project.h" #include "tilemaptileselector.h" #include "history.h" #include "historyitem.h" @@ -94,6 +94,7 @@ public: QString newAbbr(QString);// makes a *unique* 5 character abbreviation from mapname to add to mapname_abbr + // TODO: did I use these like, at all? // editing functions // if they are booleans, returns true if successful? bool placeTile(char, int, int);// place tile at x, y @@ -111,12 +112,16 @@ public: void resize(int, int); void setWidth(int); void setHeight(int); + void setBackgroundImageData(QVector *); int width(); int height(); QSize imgSize(); unsigned getTileId(int, int); int getMapSquareIndex(int, int); + QVector getTiles(); + void setTiles(QVector); + void resetSquare(int); // TODO: move read / write functions to private (and others) diff --git a/include/ui/citymappixmapitem.h b/include/ui/citymappixmapitem.h index 0fc461b5..bc82e3c1 100644 --- a/include/ui/citymappixmapitem.h +++ b/include/ui/citymappixmapitem.h @@ -5,6 +5,7 @@ #include #include +#include class CityMapPixmapItem : public QObject, public QGraphicsPixmapItem { Q_OBJECT @@ -30,6 +31,9 @@ public: int width(); int height(); + QVector getTiles(); + void setTiles(QVector); + private: int width_; int height_; @@ -41,6 +45,8 @@ signals: protected: void mousePressEvent(QGraphicsSceneMouseEvent*); + void mouseMoveEvent(QGraphicsSceneMouseEvent*); + void mouseReleaseEvent(QGraphicsSceneMouseEvent*); }; #endif // CITYMAPPIXMAPITEM_H diff --git a/include/ui/regionmapeditor.h b/include/ui/regionmapeditor.h index f1dd6507..1a44a873 100644 --- a/include/ui/regionmapeditor.h +++ b/include/ui/regionmapeditor.h @@ -11,6 +11,7 @@ #include #include #include +#include namespace Ui { class RegionMapEditor; @@ -53,13 +54,15 @@ private: unsigned selectedCityTile; unsigned selectedImageTile; + bool hasUnsavedChanges = false; + double scaleUpFactor = 2.0; double scaleDownFactor = 1.0 / scaleUpFactor; - double scaleRegionMapTiles = 1.0; - double scaleRegionMapImage = 1.0; - double scaleCityMapTiles = 1.0; - double scaleCityMapImage = 1.0; + int scaleRegionMapTiles = 1; + int scaleRegionMapImage = 1; + int scaleCityMapTiles = 1; + int scaleCityMapImage = 1; QGraphicsScene *scene_region_map_image = nullptr; QGraphicsScene *scene_city_map_image = nullptr; @@ -85,6 +88,8 @@ private: bool createCityMap(QString); + void closeEvent(QCloseEvent*); + private slots: void on_action_RegionMap_Save_triggered(); void on_action_RegionMap_Undo_triggered(); @@ -92,21 +97,17 @@ private slots: void on_action_RegionMap_Resize_triggered(); void on_action_RegionMap_Generate_triggered(); void on_tabWidget_Region_Map_currentChanged(int); - void on_pushButton_RM_Options_save_clicked(); void on_pushButton_RM_Options_delete_clicked(); - void on_pushButton_CityMap_save_clicked(); + void on_comboBox_RM_ConnectedMap_activated(const QString &); void on_pushButton_CityMap_add_clicked(); - void on_pushButton_Zoom_In_Image_Tiles_clicked(); - void on_pushButton_Zoom_Out_Image_Tiles_clicked(); - void on_pushButton_Zoom_In_City_Tiles_clicked(); - void on_pushButton_Zoom_Out_City_Tiles_clicked(); - void on_pushButton_Zoom_In_City_Map_clicked(); - void on_pushButton_Zoom_Out_City_Map_clicked(); - void on_pushButton_Zoom_In_Map_Image_clicked(); - void on_pushButton_Zoom_Out_Map_Image_clicked(); + void on_verticalSlider_Zoom_Map_Image_valueChanged(int); + void on_verticalSlider_Zoom_Image_Tiles_valueChanged(int); + void on_verticalSlider_Zoom_City_Map_valueChanged(int); + void on_verticalSlider_Zoom_City_Tiles_valueChanged(int); void on_comboBox_CityMap_picker_currentTextChanged(const QString &); void on_spinBox_RM_Options_x_valueChanged(int); void on_spinBox_RM_Options_y_valueChanged(int); + void on_lineEdit_RM_MapName_textEdited(const QString &); void onHoveredRegionMapTileChanged(int, int); void onHoveredRegionMapTileCleared(); void mouseEvent_region_map(QGraphicsSceneMouseEvent *, RegionMapPixmapItem *); diff --git a/include/ui/tilemaptileselector.h b/include/ui/tilemaptileselector.h index 1bf94984..7bf2b632 100644 --- a/include/ui/tilemaptileselector.h +++ b/include/ui/tilemaptileselector.h @@ -19,7 +19,7 @@ public: int pixelWidth; int pixelHeight; - unsigned selectedTile; + unsigned selectedTile = 0; // TODO: which of these need to be made public? // call this tilemap? or is tilemap the binary file? diff --git a/src/core/historyitem.cpp b/src/core/historyitem.cpp index 1a8c44d2..997de9f6 100644 --- a/src/core/historyitem.cpp +++ b/src/core/historyitem.cpp @@ -10,11 +10,22 @@ HistoryItem::~HistoryItem() { if (this->metatiles) delete this->metatiles; } -RegionMapHistoryItem::RegionMapHistoryItem(int which_, int index_, unsigned prev_, unsigned tile_) { - this->which = which_; - this->index = index_; - this->prev = prev_; - this->tile = tile_; +RegionMapHistoryItem::RegionMapHistoryItem(int which, QVector tiles) { + this->which = which; + this->tiles = tiles; +} + +RegionMapHistoryItem::RegionMapHistoryItem(int which, QVector tiles, QString cityMap) { + this->which = which; + this->tiles = tiles; + this->cityMap = cityMap; +} + +RegionMapHistoryItem::RegionMapHistoryItem(int which, QVector tiles, int width, int height) { + this->which = which; + this->tiles = tiles; + this->mapWidth = width; + this->mapHeight = height; } RegionMapHistoryItem::~RegionMapHistoryItem() {} diff --git a/src/core/regionmap.cpp b/src/core/regionmap.cpp index 7dde15dd..678ed2a2 100644 --- a/src/core/regionmap.cpp +++ b/src/core/regionmap.cpp @@ -79,6 +79,7 @@ void RegionMap::readLayout() { QMap *qmap = new QMap; QTextStream in(&file); + in.setCodec("UTF-8"); while (!in.atEnd()) { line = in.readLine(); if (line.startsWith("static const u8")) { @@ -182,7 +183,29 @@ int RegionMap::height() { } QSize RegionMap::imgSize() { - return QSize(img_width_ * 8 + 2, img_height_ * 8 + 2); + return QSize(img_width_ * 8, img_height_ * 8); +} + +QVector RegionMap::getTiles() { + // + QVector tileIds; + for (auto square : map_squares) { + tileIds.append(square.tile_img_id); + } + return tileIds; +} + +void RegionMap::setTiles(QVector tileIds) { + // + if (tileIds.size() != map_squares.size()) { + qDebug() << "YOU SHOULD RESIZE"; + return; + } + int i = 0; + for (uint8_t tileId : tileIds) { + map_squares[i].tile_img_id = tileId; + i++; + } } // TODO: rename to getTileIdAt()? diff --git a/src/ui/citymappixmapitem.cpp b/src/ui/citymappixmapitem.cpp index b1224aa9..da920ca6 100644 --- a/src/ui/citymappixmapitem.cpp +++ b/src/ui/citymappixmapitem.cpp @@ -62,6 +62,39 @@ void CityMapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { emit mouseEvent(event, this); } +void CityMapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + QPointF pos = event->pos(); + int x = static_cast(pos.x()) / 8; + int y = static_cast(pos.y()) / 8; + if (x < width_ && x >= 0 + && y < height_ && y >= 0) { + emit this->hoveredRegionMapTileChanged(x, y); + emit mouseEvent(event, this); + } +} + +void CityMapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + emit mouseEvent(event, this); +} + +QVector CityMapPixmapItem::getTiles() { + // + QVector tiles; + for (auto tile : data) { + tiles.append(tile); + } + return tiles; +} + +void CityMapPixmapItem::setTiles(QVector tiles) { + // + QByteArray newData; + for (auto tile : tiles) { + newData.append(tile); + } + this->data = newData; +} + int CityMapPixmapItem::getIndexAt(int x, int y) { return 2 * (x + y * this->width_); } diff --git a/src/ui/regionmapeditor.cpp b/src/ui/regionmapeditor.cpp index 226e7bd0..3c9ea146 100644 --- a/src/ui/regionmapeditor.cpp +++ b/src/ui/regionmapeditor.cpp @@ -9,15 +9,16 @@ #include #include #include +#include +#include -RegionMapEditor::RegionMapEditor(QWidget *parent, Project *pro) : +RegionMapEditor::RegionMapEditor(QWidget *parent, Project *project_) : QMainWindow(parent), ui(new Ui::RegionMapEditor) { this->ui->setupUi(this); - this->project = pro; + this->project = project_; this->region_map = new RegionMap; - this->setFixedSize(this->size()); } RegionMapEditor::~RegionMapEditor() @@ -39,8 +40,18 @@ RegionMapEditor::~RegionMapEditor() void RegionMapEditor::on_action_RegionMap_Save_triggered() { if (project && region_map) { region_map->save(); + this->city_map_item->save(); + this->region_map->saveOptions( + this->region_map_layout_item->selectedTile, + this->ui->comboBox_RM_ConnectedMap->currentText(), + this->ui->lineEdit_RM_MapName->text(), + this->ui->spinBox_RM_Options_x->value(), + this->ui->spinBox_RM_Options_y->value() + ); + this->region_map_layout_item->highlightedTile = -1; displayRegionMap(); } + this->hasUnsavedChanges = false; } void RegionMapEditor::loadRegionMapData() { @@ -90,7 +101,11 @@ void RegionMapEditor::displayRegionMapImage() { this->scene_region_map_image->setSceneRect(this->scene_region_map_image->itemsBoundingRect()); this->ui->graphicsView_Region_Map_BkgImg->setScene(this->scene_region_map_image); - this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage); + this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize().width() * scaleRegionMapImage + 2, + this->region_map->imgSize().height() * scaleRegionMapImage + 2); + + RegionMapHistoryItem *commit = new RegionMapHistoryItem(RegionMapEditorBox::BackgroundImage, this->region_map->getTiles()); + history.push(commit); } void RegionMapEditor::displayRegionMapLayout() { @@ -118,7 +133,8 @@ void RegionMapEditor::displayRegionMapLayout() { this->scene_region_map_layout->setSceneRect(this->scene_region_map_layout->itemsBoundingRect()); this->ui->graphicsView_Region_Map_Layout->setScene(this->scene_region_map_layout); - this->ui->graphicsView_Region_Map_Layout->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage); + this->ui->graphicsView_Region_Map_Layout->setFixedSize(this->region_map->imgSize().width() * scaleRegionMapImage + 2, + this->region_map->imgSize().height() * scaleRegionMapImage + 2); } void RegionMapEditor::displayRegionMapLayoutOptions() { @@ -135,17 +151,23 @@ void RegionMapEditor::displayRegionMapLayoutOptions() { ); updateRegionMapLayoutOptions(currIndex); + + // TODO: implement when the code is decompiled + this->ui->label_RM_CityMap->setVisible(false); + this->ui->comboBox_RM_CityMap->setVisible(false); } void RegionMapEditor::updateRegionMapLayoutOptions(int index) { this->ui->spinBox_RM_Options_x->blockSignals(true); this->ui->spinBox_RM_Options_y->blockSignals(true); + this->ui->comboBox_RM_ConnectedMap->blockSignals(true); this->ui->lineEdit_RM_MapName->setText(this->project->mapSecToMapHoverName->value(this->region_map->map_squares[index].mapsec)); this->ui->comboBox_RM_ConnectedMap->setCurrentText(this->region_map->map_squares[index].mapsec); this->ui->spinBox_RM_Options_x->setValue(this->region_map->map_squares[index].x); this->ui->spinBox_RM_Options_y->setValue(this->region_map->map_squares[index].y); this->ui->spinBox_RM_Options_x->blockSignals(false); this->ui->spinBox_RM_Options_y->blockSignals(false); + this->ui->comboBox_RM_ConnectedMap->blockSignals(false); } void RegionMapEditor::displayRegionMapTileSelector() { @@ -223,6 +245,11 @@ void RegionMapEditor::displayCityMap(QString f) { this->ui->graphicsView_City_Map->setScene(scene_city_map_image); this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width() * scaleCityMapImage + 2, 8 * city_map_item->height() * scaleCityMapImage + 2); + + RegionMapHistoryItem *commit = new RegionMapHistoryItem( + RegionMapEditorBox::CityMapImage, this->city_map_item->getTiles(), this->city_map_item->file + ); + history.push(commit); } bool RegionMapEditor::createCityMap(QString name) { @@ -313,35 +340,53 @@ void RegionMapEditor::onHoveredRegionMapTileCleared() { } void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, RegionMapPixmapItem *item) { + QPointF pos = event->pos(); + int x = static_cast(pos.x()) / 8; + int y = static_cast(pos.y()) / 8; + int index = this->region_map->getMapSquareIndex(x, y); + if (index > this->region_map->map_squares.size() - 1) return; + if (event->buttons() & Qt::RightButton) { item->select(event); //} else if (event->buttons() & Qt::MiddleButton) {// TODO } else { - QPointF pos = event->pos(); - int x = static_cast(pos.x()) / 8; - int y = static_cast(pos.y()) / 8; - int index = this->region_map->getMapSquareIndex(x, y); - if (index > this->region_map->map_squares.size() - 1) return; - RegionMapHistoryItem *commit = new RegionMapHistoryItem(RegionMapEditorBox::BackgroundImage, index, - this->region_map->map_squares[index].tile_img_id, this->mapsquare_selector_item->getSelectedTile()); - history.push(commit); item->paint(event); + this->hasUnsavedChanges = true; + if (event->type() == QEvent::GraphicsSceneMouseRelease) { + RegionMapHistoryItem *current = history.current(); + bool addToHistory = !(current && current->tiles == this->region_map->getTiles()); + if (addToHistory) { + RegionMapHistoryItem *commit = new RegionMapHistoryItem( + RegionMapEditorBox::BackgroundImage, this->region_map->getTiles() + ); + history.push(commit); + } + } } } void RegionMapEditor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityMapPixmapItem *item) { // + QPointF pos = event->pos(); + int x = static_cast(pos.x()) / 8; + int y = static_cast(pos.y()) / 8; + int index = this->city_map_item->getIndexAt(x, y); + if (event->buttons() & Qt::RightButton) {// TODO //} else if (event->buttons() & Qt::MiddleButton) {// TODO } else { - QPointF pos = event->pos(); - int x = static_cast(pos.x()) / 8; - int y = static_cast(pos.y()) / 8; - int index = this->city_map_item->getIndexAt(x, y); - RegionMapHistoryItem *commit = new RegionMapHistoryItem(RegionMapEditorBox::CityMapImage, index, - this->city_map_item->data[index], this->city_map_selector_item->getSelectedTile()); - history.push(commit); item->paint(event); + this->hasUnsavedChanges = true; + if (event->type() == QEvent::GraphicsSceneMouseRelease) { + RegionMapHistoryItem *current = history.current(); + bool addToHistory = !(current && current->tiles == this->city_map_item->getTiles()); + if (addToHistory) { + RegionMapHistoryItem *commit = new RegionMapHistoryItem( + RegionMapEditorBox::CityMapImage, this->city_map_item->getTiles(), this->city_map_item->file + ); + history.push(commit); + } + } } } @@ -350,12 +395,10 @@ void RegionMapEditor::on_tabWidget_Region_Map_currentChanged(int index) { switch (index) { case 0: - this->ui->pushButton_Zoom_In_Image_Tiles->setVisible(true); - this->ui->pushButton_Zoom_Out_Image_Tiles->setVisible(true); + this->ui->verticalSlider_Zoom_Image_Tiles->setVisible(true); break; case 1: - this->ui->pushButton_Zoom_In_Image_Tiles->setVisible(false); - this->ui->pushButton_Zoom_Out_Image_Tiles->setVisible(false); + this->ui->verticalSlider_Zoom_Image_Tiles->setVisible(false); break; } } @@ -364,34 +407,30 @@ void RegionMapEditor::on_spinBox_RM_Options_x_valueChanged(int x) { int y = this->ui->spinBox_RM_Options_y->value(); int red = this->region_map->getMapSquareIndex(x + this->region_map->padLeft, y + this->region_map->padTop); this->region_map_layout_item->highlight(x, y, red); + this->hasUnsavedChanges = true; } void RegionMapEditor::on_spinBox_RM_Options_y_valueChanged(int y) { int x = this->ui->spinBox_RM_Options_x->value(); int red = this->region_map->getMapSquareIndex(x + this->region_map->padLeft, y + this->region_map->padTop); this->region_map_layout_item->highlight(x, y, red); + this->hasUnsavedChanges = true; } -void RegionMapEditor::on_pushButton_RM_Options_save_clicked() { - this->region_map->saveOptions( - this->region_map_layout_item->selectedTile, - this->ui->comboBox_RM_ConnectedMap->currentText(), - this->ui->lineEdit_RM_MapName->text(), - this->ui->spinBox_RM_Options_x->value(), - this->ui->spinBox_RM_Options_y->value() - ); - this->region_map_layout_item->highlightedTile = -1; - this->region_map_layout_item->draw(); +void RegionMapEditor::on_comboBox_RM_ConnectedMap_activated(const QString &mapsec) { + this->ui->lineEdit_RM_MapName->setText(this->project->mapSecToMapHoverName->value(mapsec)); + //this->hasUnsavedChanges = true;// sometimes this is called for unknown reasons } -void RegionMapEditor::on_pushButton_CityMap_save_clicked() { - this->city_map_item->save(); +void RegionMapEditor::on_lineEdit_RM_MapName_textEdited(const QString &text) { + this->hasUnsavedChanges = true; } void RegionMapEditor::on_pushButton_RM_Options_delete_clicked() { this->region_map->resetSquare(this->region_map_layout_item->selectedTile); this->region_map_layout_item->draw(); this->region_map_layout_item->select(this->region_map_layout_item->selectedTile); + this->hasUnsavedChanges = true; } void RegionMapEditor::on_pushButton_CityMap_add_clicked() { @@ -419,6 +458,8 @@ void RegionMapEditor::on_pushButton_CityMap_add_clicked() { if (popup.exec() == QDialog::Accepted) { createCityMap(name); } + + this->hasUnsavedChanges = true; } void RegionMapEditor::on_action_RegionMap_Resize_triggered() { @@ -448,59 +489,75 @@ void RegionMapEditor::on_action_RegionMap_Resize_triggered() { if (popup.exec() == QDialog::Accepted) { resize(widthSpinBox->value(), heightSpinBox->value()); } + + this->hasUnsavedChanges = true; } void RegionMapEditor::on_action_RegionMap_Undo_triggered() { undo(); + this->hasUnsavedChanges = true; } +// TODO: add resizing void RegionMapEditor::undo() { - RegionMapHistoryItem *commit = history.current(); + RegionMapHistoryItem *commit = history.back(); if (!commit) return; - uint8_t tile = static_cast(commit->prev); - - history.back(); - switch (commit->which) { case RegionMapEditorBox::BackgroundImage: - history.back();// TODO: why do I need to do this? - this->region_map->map_squares[commit->index].tile_img_id = tile; + this->region_map->setTiles(commit->tiles); this->region_map_item->draw(); break; case RegionMapEditorBox::CityMapImage: - this->city_map_item->data[commit->index] = tile; + if (commit->cityMap == this->city_map_item->file) + this->city_map_item->setTiles(commit->tiles); this->city_map_item->draw(); break; + case RegionMapEditorBox::BackroundResize: + this->region_map->resize(commit->mapWidth, commit->mapHeight); + displayRegionMap(); + break; } } void RegionMapEditor::on_action_RegionMap_Redo_triggered() { redo(); + this->hasUnsavedChanges = true; } void RegionMapEditor::redo() { RegionMapHistoryItem *commit = history.next(); if (!commit) return; - uint8_t tile = static_cast(commit->tile); - switch (commit->which) { case RegionMapEditorBox::BackgroundImage: - history.next();// TODO: why do I need to do this? - this->region_map->map_squares[commit->index].tile_img_id = tile; + this->region_map->setTiles(commit->tiles); this->region_map_item->draw(); break; case RegionMapEditorBox::CityMapImage: - this->city_map_item->data[commit->index] = tile; + this->city_map_item->setTiles(commit->tiles); this->city_map_item->draw(); break; + case RegionMapEditorBox::BackroundResize: + this->region_map->resize(commit->mapWidth, commit->mapHeight); + displayRegionMap(); + break; } } void RegionMapEditor::resize(int w, int h) { + RegionMapHistoryItem *commitOld = new RegionMapHistoryItem( + RegionMapEditorBox::BackroundResize, this->region_map->getTiles(), this->region_map->width(), this->region_map->height() + ); + RegionMapHistoryItem *commitNew = new RegionMapHistoryItem( + RegionMapEditorBox::BackroundResize, this->region_map->getTiles(), w, h + ); + history.push(commitOld); + history.push(commitNew); + history.back(); + this->region_map->resize(w, h); this->currIndex = 2 * w + 1; displayRegionMap(); @@ -510,74 +567,93 @@ void RegionMapEditor::on_comboBox_CityMap_picker_currentTextChanged(const QStrin this->displayCityMap(file); } -void RegionMapEditor::on_pushButton_Zoom_In_Image_Tiles_clicked() { - if (scaleRegionMapTiles >= 8.0) return; - scaleRegionMapTiles *= 2.0; - this->ui->graphicsView_RegionMap_Tiles->setFixedSize(this->mapsquare_selector_item->pixelWidth * scaleRegionMapTiles + 2, - this->mapsquare_selector_item->pixelHeight * scaleRegionMapTiles + 2); - this->ui->graphicsView_RegionMap_Tiles->scale(2.0, 2.0); +void RegionMapEditor::closeEvent(QCloseEvent *event) +{ + if (this->hasUnsavedChanges) { + QMessageBox::StandardButton result = QMessageBox::question( + this, + "porymap", + "The region map has been modified, save changes?", + QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, + QMessageBox::Yes); + + if (result == QMessageBox::Yes) { + this->on_action_RegionMap_Save_triggered(); + event->accept(); + } else if (result == QMessageBox::No) { + event->accept(); + } else if (result == QMessageBox::Cancel) { + event->ignore(); + } + } else { + event->accept(); + } } -void RegionMapEditor::on_pushButton_Zoom_Out_Image_Tiles_clicked() { - if (scaleRegionMapTiles <= 1.0) return; - scaleRegionMapTiles /= 2.0; - this->ui->graphicsView_RegionMap_Tiles->setFixedSize(this->mapsquare_selector_item->pixelWidth * scaleRegionMapTiles + 2, - this->mapsquare_selector_item->pixelHeight * scaleRegionMapTiles + 2); - this->ui->graphicsView_RegionMap_Tiles->scale(0.5, 0.5); +void RegionMapEditor::on_verticalSlider_Zoom_Map_Image_valueChanged(int val) { + bool zoom_in = val > scaleRegionMapImage ? true : false; + scaleRegionMapImage = val; + + this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize().width() * pow(scaleUpFactor, scaleRegionMapImage - 1) + 2, + this->region_map->imgSize().height() * pow(scaleUpFactor, scaleRegionMapImage - 1) + 2); + this->ui->graphicsView_Region_Map_Layout->setFixedSize(this->region_map->imgSize().width() * pow(scaleUpFactor, scaleRegionMapImage - 1) + 2, + this->region_map->imgSize().height() * pow(scaleUpFactor, scaleRegionMapImage - 1) + 2); + + if (zoom_in) { + this->ui->graphicsView_Region_Map_BkgImg->scale(scaleUpFactor, scaleUpFactor); + this->ui->graphicsView_Region_Map_Layout->scale(scaleUpFactor, scaleUpFactor); + } else { + // + this->ui->graphicsView_Region_Map_BkgImg->scale(scaleDownFactor, scaleDownFactor); + this->ui->graphicsView_Region_Map_Layout->scale(scaleDownFactor, scaleDownFactor); + } } -void RegionMapEditor::on_pushButton_Zoom_In_City_Tiles_clicked() { - if (scaleCityMapTiles >= 8.0) return; - scaleCityMapTiles *= 2.0; - this->ui->graphicsView_City_Map_Tiles->setFixedSize(this->city_map_selector_item->pixelWidth * scaleCityMapTiles + 2, - this->city_map_selector_item->pixelHeight * scaleCityMapTiles + 2); - this->ui->graphicsView_City_Map_Tiles->scale(2.0,2.0); +void RegionMapEditor::on_verticalSlider_Zoom_Image_Tiles_valueChanged(int val) { + bool zoom_in = val > scaleRegionMapTiles ? true : false; + scaleRegionMapTiles = val; + + this->ui->graphicsView_RegionMap_Tiles->setFixedSize(this->mapsquare_selector_item->pixelWidth * pow(scaleUpFactor, scaleRegionMapTiles - 1) + 2, + this->mapsquare_selector_item->pixelHeight * pow(scaleUpFactor, scaleRegionMapTiles - 1) + 2); + + if (zoom_in) { + this->ui->graphicsView_RegionMap_Tiles->scale(scaleUpFactor, scaleUpFactor); + } else { + this->ui->graphicsView_RegionMap_Tiles->scale(scaleDownFactor, scaleDownFactor); + } } -void RegionMapEditor::on_pushButton_Zoom_Out_City_Tiles_clicked() { - if (scaleCityMapTiles <= 1.0) return; - scaleCityMapTiles /= 2.0; - this->ui->graphicsView_City_Map_Tiles->setFixedSize(this->city_map_selector_item->pixelWidth * scaleCityMapTiles + 2, - this->city_map_selector_item->pixelHeight * scaleCityMapTiles + 2); - this->ui->graphicsView_City_Map_Tiles->scale(0.5,0.5); +void RegionMapEditor::on_verticalSlider_Zoom_City_Map_valueChanged(int val) { + bool zoom_in = val > scaleCityMapImage ? true : false; + scaleCityMapImage = val; + + this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width() * pow(scaleUpFactor, scaleCityMapImage - 1) + 2, + 8 * city_map_item->height() * pow(scaleUpFactor, scaleCityMapImage - 1) + 2); + + if (zoom_in) { + this->ui->graphicsView_City_Map->scale(scaleUpFactor, scaleUpFactor); + } else { + this->ui->graphicsView_City_Map->scale(scaleDownFactor, scaleDownFactor); + } } -void RegionMapEditor::on_pushButton_Zoom_In_City_Map_clicked() { - if (scaleCityMapImage >= 8.0) return; - scaleCityMapImage *= 2.0; - this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width() * scaleCityMapImage + 2, - 8 * city_map_item->height() * scaleCityMapImage + 2); - this->ui->graphicsView_City_Map->scale(2.0,2.0); -} +void RegionMapEditor::on_verticalSlider_Zoom_City_Tiles_valueChanged(int val) { + bool zoom_in = val > scaleCityMapTiles ? true : false; + scaleCityMapTiles = val; -void RegionMapEditor::on_pushButton_Zoom_Out_City_Map_clicked() { - if (scaleCityMapImage <= 1.0) return; - scaleCityMapImage /= 2.0; - this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width() * scaleCityMapImage + 2, - 8 * city_map_item->height() * scaleCityMapImage + 2); - this->ui->graphicsView_City_Map->scale(0.5,0.5); -} + this->ui->graphicsView_City_Map_Tiles->setFixedSize(this->city_map_selector_item->pixelWidth * pow(scaleUpFactor, scaleCityMapTiles - 1) + 2, + this->city_map_selector_item->pixelHeight * pow(scaleUpFactor, scaleCityMapTiles - 1) + 2); -void RegionMapEditor::on_pushButton_Zoom_In_Map_Image_clicked() { - if (scaleRegionMapImage >= 8.0) return; - scaleRegionMapImage *= 2.0; - this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage); - this->ui->graphicsView_Region_Map_Layout->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage); - this->ui->graphicsView_Region_Map_BkgImg->scale(2.0,2.0); - this->ui->graphicsView_Region_Map_Layout->scale(2.0,2.0); -} - -void RegionMapEditor::on_pushButton_Zoom_Out_Map_Image_clicked() { - if (scaleRegionMapImage <= 1.0) return; - scaleRegionMapImage /= 2.0; - this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage); - this->ui->graphicsView_Region_Map_Layout->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage); - this->ui->graphicsView_Region_Map_BkgImg->scale(0.5,0.5); - this->ui->graphicsView_Region_Map_Layout->scale(0.5,0.5); + if (zoom_in) { + this->ui->graphicsView_City_Map_Tiles->scale(scaleUpFactor, scaleUpFactor); + } else { + this->ui->graphicsView_City_Map_Tiles->scale(scaleDownFactor, scaleDownFactor); + } } void RegionMapEditor::on_action_RegionMap_Generate_triggered() { // RegionMapGenerator generator(this->project); generator.generate("LittlerootTown"); + this->hasUnsavedChanges = true; } diff --git a/src/ui/regionmaplayoutpixmapitem.cpp b/src/ui/regionmaplayoutpixmapitem.cpp index 2da3ae5d..8654b66b 100644 --- a/src/ui/regionmaplayoutpixmapitem.cpp +++ b/src/ui/regionmaplayoutpixmapitem.cpp @@ -73,10 +73,7 @@ void RegionMapLayoutPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) } void RegionMapLayoutPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - SelectablePixmapItem::mouseMoveEvent(event); - this->updateSelectedTile(); - emit hoveredTileChanged(this->selectedTile); - emit selectedTileChanged(this->selectedTile); + mousePressEvent(event); } void RegionMapLayoutPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { diff --git a/src/ui/regionmappixmapitem.cpp b/src/ui/regionmappixmapitem.cpp index c75341d7..6f3886c7 100644 --- a/src/ui/regionmappixmapitem.cpp +++ b/src/ui/regionmappixmapitem.cpp @@ -60,10 +60,14 @@ void RegionMapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { } void RegionMapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - int x = static_cast(event->pos().x()) / 8; - int y = static_cast(event->pos().y()) / 8; - emit this->hoveredRegionMapTileChanged(x, y); - emit mouseEvent(event, this); + QPointF pos = event->pos(); + int x = static_cast(pos.x()) / 8; + int y = static_cast(pos.y()) / 8; + if (x < this->region_map->width() && x >= 0 + && y < this->region_map->height() && y >= 0) { + emit this->hoveredRegionMapTileChanged(x, y); + emit mouseEvent(event, this); + } } void RegionMapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {