region map ui updates and other fixes
This commit is contained in:
parent
41f3780c8a
commit
a951fc85da
12 changed files with 1267 additions and 1068 deletions
File diff suppressed because it is too large
Load diff
|
@ -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<uint8_t> tiles;
|
||||
QString cityMap;
|
||||
RegionMapHistoryItem(int type, QVector<uint8_t> tiles);
|
||||
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, QString cityMap);
|
||||
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, int width, int height);
|
||||
~RegionMapHistoryItem();
|
||||
};
|
||||
|
||||
|
|
|
@ -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<uint8_t> *);
|
||||
int width();
|
||||
int height();
|
||||
QSize imgSize();
|
||||
unsigned getTileId(int, int);
|
||||
int getMapSquareIndex(int, int);
|
||||
|
||||
QVector<uint8_t> getTiles();
|
||||
void setTiles(QVector<uint8_t>);
|
||||
|
||||
void resetSquare(int);
|
||||
|
||||
// TODO: move read / write functions to private (and others)
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QByteArray>
|
||||
#include <QVector>
|
||||
|
||||
class CityMapPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
Q_OBJECT
|
||||
|
@ -30,6 +31,9 @@ public:
|
|||
int width();
|
||||
int height();
|
||||
|
||||
QVector<uint8_t> getTiles();
|
||||
void setTiles(QVector<uint8_t>);
|
||||
|
||||
private:
|
||||
int width_;
|
||||
int height_;
|
||||
|
@ -41,6 +45,8 @@ signals:
|
|||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||
};
|
||||
|
||||
#endif // CITYMAPPIXMAPITEM_H
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <QMainWindow>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QCloseEvent>
|
||||
#include <QResizeEvent>
|
||||
|
||||
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 *);
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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<uint8_t> tiles) {
|
||||
this->which = which;
|
||||
this->tiles = tiles;
|
||||
}
|
||||
|
||||
RegionMapHistoryItem::RegionMapHistoryItem(int which, QVector<uint8_t> tiles, QString cityMap) {
|
||||
this->which = which;
|
||||
this->tiles = tiles;
|
||||
this->cityMap = cityMap;
|
||||
}
|
||||
|
||||
RegionMapHistoryItem::RegionMapHistoryItem(int which, QVector<uint8_t> tiles, int width, int height) {
|
||||
this->which = which;
|
||||
this->tiles = tiles;
|
||||
this->mapWidth = width;
|
||||
this->mapHeight = height;
|
||||
}
|
||||
|
||||
RegionMapHistoryItem::~RegionMapHistoryItem() {}
|
||||
|
|
|
@ -79,6 +79,7 @@ void RegionMap::readLayout() {
|
|||
QMap<QString, QString> *qmap = new QMap<QString, QString>;
|
||||
|
||||
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<uint8_t> RegionMap::getTiles() {
|
||||
//
|
||||
QVector<uint8_t> tileIds;
|
||||
for (auto square : map_squares) {
|
||||
tileIds.append(square.tile_img_id);
|
||||
}
|
||||
return tileIds;
|
||||
}
|
||||
|
||||
void RegionMap::setTiles(QVector<uint8_t> 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()?
|
||||
|
|
|
@ -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<int>(pos.x()) / 8;
|
||||
int y = static_cast<int>(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<uint8_t> CityMapPixmapItem::getTiles() {
|
||||
//
|
||||
QVector<uint8_t> tiles;
|
||||
for (auto tile : data) {
|
||||
tiles.append(tile);
|
||||
}
|
||||
return tiles;
|
||||
}
|
||||
|
||||
void CityMapPixmapItem::setTiles(QVector<uint8_t> 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_);
|
||||
}
|
||||
|
|
|
@ -9,15 +9,16 @@
|
|||
#include <QFormLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QColor>
|
||||
#include <QMessageBox>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
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<int>(pos.x()) / 8;
|
||||
int y = static_cast<int>(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<int>(pos.x()) / 8;
|
||||
int y = static_cast<int>(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<int>(pos.x()) / 8;
|
||||
int y = static_cast<int>(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<int>(pos.x()) / 8;
|
||||
int y = static_cast<int>(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<uint8_t>(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<uint8_t>(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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -60,10 +60,14 @@ void RegionMapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
|||
}
|
||||
|
||||
void RegionMapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
int x = static_cast<int>(event->pos().x()) / 8;
|
||||
int y = static_cast<int>(event->pos().y()) / 8;
|
||||
emit this->hoveredRegionMapTileChanged(x, y);
|
||||
emit mouseEvent(event, this);
|
||||
QPointF pos = event->pos();
|
||||
int x = static_cast<int>(pos.x()) / 8;
|
||||
int y = static_cast<int>(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) {
|
||||
|
|
Loading…
Reference in a new issue