further refine region map editor
This commit is contained in:
parent
545e2134d8
commit
a475823fee
9 changed files with 197 additions and 328 deletions
|
@ -61,8 +61,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>384</width>
|
||||
<height>249</height>
|
||||
<width>350</width>
|
||||
<height>225</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_18">
|
||||
|
@ -182,8 +182,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>384</width>
|
||||
<height>249</height>
|
||||
<width>350</width>
|
||||
<height>225</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_19">
|
||||
|
@ -330,10 +330,10 @@
|
|||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<x>8</x>
|
||||
<y>0</y>
|
||||
<width>283</width>
|
||||
<height>275</height>
|
||||
<width>278</width>
|
||||
<height>262</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -487,6 +487,9 @@
|
|||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="insertPolicy">
|
||||
<enum>QComboBox::NoInsert</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
|
@ -518,43 +521,11 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget_5">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>100</y>
|
||||
<width>138</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_RM_Options_xy">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_RM_Options_x">
|
||||
<property name="text">
|
||||
<string>x</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_RM_Options_x"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_RM_Options_y">
|
||||
<property name="text">
|
||||
<string>y</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_RM_Options_y"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_RM_Options_delete">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>190</y>
|
||||
<y>100</y>
|
||||
<width>113</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
|
@ -651,8 +622,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>412</width>
|
||||
<height>249</height>
|
||||
<width>441</width>
|
||||
<height>230</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_20">
|
||||
|
@ -785,10 +756,10 @@
|
|||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<x>8</x>
|
||||
<y>0</y>
|
||||
<width>295</width>
|
||||
<height>283</height>
|
||||
<width>255</width>
|
||||
<height>274</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -1076,7 +1047,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>829</width>
|
||||
<height>21</height>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
@ -1101,7 +1072,8 @@
|
|||
<property name="title">
|
||||
<string>Tools</string>
|
||||
</property>
|
||||
<addaction name="action_RegionMap_Generate"/>
|
||||
<addaction name="action_Import_RegionMap_ImageTiles"/>
|
||||
<addaction name="action_Import_CityMap_ImageTiles"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuEdit"/>
|
||||
|
@ -1160,6 +1132,16 @@
|
|||
<string>Clear Map Layout</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_Import_RegionMap_ImageTiles">
|
||||
<property name="text">
|
||||
<string>Import Region Map Image Tiles...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_Import_CityMap_ImageTiles">
|
||||
<property name="text">
|
||||
<string>Import City Map Image Tiles...</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
void readLayout();
|
||||
|
||||
void save();
|
||||
void saveTileImages();
|
||||
void saveBkgImgBin();
|
||||
void saveLayout();
|
||||
void saveOptions(int id, QString sec, QString name, int x, int y);
|
||||
|
@ -80,7 +81,9 @@ public:
|
|||
unsigned getTileId(int x, int y);
|
||||
int getMapSquareIndex(int x, int y);
|
||||
QString pngPath();
|
||||
void setTemporaryPngPath(QString);
|
||||
QString cityTilesPath();
|
||||
void setTemporaryCityTilesPath(QString);
|
||||
|
||||
QVector<uint8_t> getTiles();
|
||||
void setTiles(QVector<uint8_t> tileIds);
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
#ifndef GUARD_REGIONMAPGENERATOR_H
|
||||
#define GUARD_REGIONMAPGENERATOR_H
|
||||
|
||||
#include "project.h"
|
||||
#include "regionmap.h"
|
||||
#include "map.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <QStack>
|
||||
#include <QPair>
|
||||
#include <QSet>
|
||||
|
||||
class GeneratorEntry
|
||||
{
|
||||
GeneratorEntry(QString name_, int x_, int y_, int width_, int height_) {
|
||||
this->name = name_;
|
||||
this->x = x_;
|
||||
this->y = y_;
|
||||
this->width = width_;
|
||||
this->height = height_;
|
||||
}
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
QString name;
|
||||
friend class RegionMapGenerator;
|
||||
public:
|
||||
friend QDebug operator<<(QDebug, const GeneratorEntry &);
|
||||
};
|
||||
|
||||
class RegionMapGenerator
|
||||
{
|
||||
//
|
||||
public:
|
||||
//
|
||||
RegionMapGenerator() = default;
|
||||
RegionMapGenerator(Project *);
|
||||
~RegionMapGenerator() {};
|
||||
|
||||
Project *project = nullptr;
|
||||
|
||||
QVector<RegionMapSquare> map_squares;
|
||||
|
||||
QStack<QPair<QString, int>> forks;//?
|
||||
QSet<MapConnection> connections;//
|
||||
// <MapConnection>
|
||||
|
||||
void generate(QString);
|
||||
|
||||
void center();// center the map squares so they arent hanging over
|
||||
|
||||
private:
|
||||
//
|
||||
int square_block_width_ = 20;
|
||||
int square_block_height_ = 20;
|
||||
|
||||
int width_;
|
||||
int height_;
|
||||
|
||||
//QPoint
|
||||
|
||||
QList<struct RegionMapEntry> entries_;
|
||||
QMap<QString, GeneratorEntry> entries;
|
||||
|
||||
void bfs(int);// breadth first search of a graph
|
||||
void search(int);
|
||||
void dfs(int, QVector<bool> &);// depth first search
|
||||
void sort();
|
||||
void ts();// topological sort
|
||||
void populateSquares();
|
||||
|
||||
};
|
||||
|
||||
#endif // GUARD_REGIONMAPGENERATOR_H
|
|
@ -83,6 +83,7 @@ private:
|
|||
void displayRegionMapTileSelector();
|
||||
void displayCityMapTileSelector();
|
||||
void displayCityMap(QString name);
|
||||
void importTileImage(bool city = false);//QString path);// what is this path tho?
|
||||
|
||||
bool createCityMap(QString name);
|
||||
|
||||
|
@ -96,7 +97,8 @@ private slots:
|
|||
void on_action_RegionMap_ClearImage_triggered();
|
||||
void on_action_RegionMap_ClearLayout_triggered();
|
||||
void on_action_Swap_triggered();
|
||||
void on_action_RegionMap_Generate_triggered();
|
||||
void on_action_Import_RegionMap_ImageTiles_triggered();
|
||||
void on_action_Import_CityMap_ImageTiles_triggered();
|
||||
void on_tabWidget_Region_Map_currentChanged(int);
|
||||
void on_pushButton_RM_Options_delete_clicked();
|
||||
void on_comboBox_RM_ConnectedMap_activated(const QString &text);
|
||||
|
@ -106,8 +108,6 @@ private slots:
|
|||
void on_verticalSlider_Zoom_City_Map_valueChanged(int);
|
||||
void on_verticalSlider_Zoom_City_Tiles_valueChanged(int);
|
||||
void on_comboBox_CityMap_picker_currentTextChanged(const QString &text);
|
||||
void on_spinBox_RM_Options_x_valueChanged(int val);
|
||||
void on_spinBox_RM_Options_y_valueChanged(int val);
|
||||
void on_lineEdit_RM_MapName_textEdited(const QString &text);
|
||||
void onHoveredRegionMapTileChanged(int x, int y);
|
||||
void onHoveredRegionMapTileCleared();
|
||||
|
|
|
@ -29,7 +29,6 @@ SOURCES += src/core/block.cpp \
|
|||
src/core/tile.cpp \
|
||||
src/core/tileset.cpp \
|
||||
src/core/regionmap.cpp \
|
||||
src/core/regionmapgenerator.cpp \
|
||||
src/ui/aboutporymap.cpp \
|
||||
src/ui/bordermetatilespixmapitem.cpp \
|
||||
src/ui/collisionpixmapitem.cpp \
|
||||
|
@ -86,7 +85,6 @@ HEADERS += include/core/block.h \
|
|||
include/core/tile.h \
|
||||
include/core/tileset.h \
|
||||
include/core/regionmap.h \
|
||||
include/core/regionmapgenerator.h \
|
||||
include/ui/aboutporymap.h \
|
||||
include/ui/bordermetatilespixmapitem.h \
|
||||
include/ui/collisionpixmapitem.h \
|
||||
|
|
|
@ -32,11 +32,29 @@ void RegionMap::init(Project *pro) {
|
|||
|
||||
void RegionMap::save() {
|
||||
logInfo("Saving region map data.");
|
||||
saveTileImages();
|
||||
saveBkgImgBin();
|
||||
saveLayout();
|
||||
porymapConfig.setRegionMapDimensions(this->img_width_, this->img_height_);
|
||||
}
|
||||
|
||||
void RegionMap::saveTileImages() {
|
||||
QFile backgroundTileFile(pngPath());
|
||||
if (backgroundTileFile.open(QIODevice::ReadOnly)) {
|
||||
QByteArray imageData = backgroundTileFile.readAll();
|
||||
QImage pngImage = QImage::fromData(imageData);
|
||||
this->region_map_png_path = project->root + "/graphics/pokenav/region_map.png";
|
||||
pngImage.save(pngPath());
|
||||
}
|
||||
QFile cityTileFile(cityTilesPath());
|
||||
if (cityTileFile.open(QIODevice::ReadOnly)) {
|
||||
QByteArray imageData = cityTileFile.readAll();
|
||||
QImage cityTilesImage = QImage::fromData(imageData);
|
||||
this->city_map_tiles_path = project->root + "/graphics/pokenav/zoom_tiles.png";
|
||||
cityTilesImage.save(cityTilesPath());
|
||||
}
|
||||
}
|
||||
|
||||
void RegionMap::readBkgImgBin() {
|
||||
QFile binFile(region_map_bin_path);
|
||||
if (!binFile.open(QIODevice::ReadOnly)) return;
|
||||
|
@ -168,6 +186,11 @@ void RegionMap::saveOptions(int id, QString sec, QString name, int x, int y) {
|
|||
resetSquare(id);
|
||||
int index = getMapSquareIndex(x + this->padLeft, y + this->padTop);
|
||||
if (!sec.isEmpty()) {
|
||||
// Validate the input section name.
|
||||
if (!project->mapSectionNameToValue.contains(sec)) {
|
||||
sec = "MAPSEC_NONE";
|
||||
name = QString();
|
||||
}
|
||||
this->map_squares[index].has_map = sec == "MAPSEC_NONE" ? false : true;
|
||||
this->map_squares[index].secid = static_cast<uint8_t>(project->mapSectionNameToValue.value(sec));
|
||||
this->map_squares[index].mapsec = sec;
|
||||
|
@ -295,10 +318,18 @@ QString RegionMap::pngPath() {
|
|||
return this->region_map_png_path;
|
||||
}
|
||||
|
||||
void RegionMap::setTemporaryPngPath(QString path) {
|
||||
this->region_map_png_path = path;
|
||||
}
|
||||
|
||||
QString RegionMap::cityTilesPath() {
|
||||
return this->city_map_tiles_path;
|
||||
}
|
||||
|
||||
void RegionMap::setTemporaryCityTilesPath(QString path) {
|
||||
this->city_map_tiles_path = path;
|
||||
}
|
||||
|
||||
// From x, y of image.
|
||||
int RegionMap::getMapSquareIndex(int x, int y) {
|
||||
int index = (x + y * img_width_);
|
||||
|
|
|
@ -1,148 +0,0 @@
|
|||
#include "regionmapgenerator.h"
|
||||
|
||||
|
||||
|
||||
RegionMapGenerator::RegionMapGenerator(Project *project_) {
|
||||
this->project = project_;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, const GeneratorEntry &entry)
|
||||
{
|
||||
debug.nospace() << "Entry_" << entry.name
|
||||
<< " (" << entry.x << ", " << entry.y << ")"
|
||||
<< " [" << entry.width << " x " << entry.height << "]"
|
||||
;
|
||||
return debug;
|
||||
}
|
||||
|
||||
//
|
||||
void RegionMapGenerator::generate(QString mapName) {
|
||||
//
|
||||
int i = project->mapNames->indexOf(mapName);
|
||||
//Map *map = project->loadMap(mapName);
|
||||
qDebug() << "generating region map from:" << mapName;
|
||||
search(i);
|
||||
|
||||
populateSquares();
|
||||
}
|
||||
|
||||
// use a progress bar because this is rather slow (because loadMap)
|
||||
// TODO: use custom functions to load only necessary data from maps?
|
||||
// need connections and dimensions
|
||||
// maybe use gMapGroup0.numMaps as hint for size of progress
|
||||
void RegionMapGenerator::bfs(int start) {
|
||||
//
|
||||
int size = project->mapNames->size();
|
||||
|
||||
//*
|
||||
|
||||
QVector<bool> visited(size, false);
|
||||
QList<int> queue;
|
||||
|
||||
visited[start] = true;
|
||||
queue.append(start);
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
start = queue.first();
|
||||
|
||||
qDebug() << project->mapNames->at(start);
|
||||
Map *map = project->loadMap(project->mapNames->at(start));
|
||||
|
||||
if (!map) break;
|
||||
|
||||
this->entries.insert(map->location, {
|
||||
map->name, 0, 0, map->getWidth() / square_block_width_, map->getHeight() / square_block_height_
|
||||
});
|
||||
|
||||
queue.removeFirst();
|
||||
|
||||
// get all connected map indexes
|
||||
// if not visited, mark it visited and insert into queue
|
||||
for (auto c : map->connections) {
|
||||
int i = project->mapNames->indexOf(c->map_name);
|
||||
if (!visited[i] && c->direction != "dive") {
|
||||
visited[i] = true;
|
||||
queue.append(i);
|
||||
}
|
||||
}
|
||||
//delete map;
|
||||
}
|
||||
//*/
|
||||
qDebug() << "search complete";// << entries.keys();
|
||||
//return;
|
||||
}
|
||||
|
||||
//
|
||||
void RegionMapGenerator::dfs(int start, QVector<bool> &visited) {
|
||||
//
|
||||
visited[start] = true;
|
||||
|
||||
Map *map = project->loadMap(project->mapNames->at(start));
|
||||
//qDebug() << map->name;
|
||||
this->entries.insert(map->location, {
|
||||
map->name, 0, 0, map->getWidth() / square_block_width_, map->getHeight() / square_block_height_
|
||||
});
|
||||
|
||||
// place map on the grid?
|
||||
|
||||
for (auto c : map->connections) {
|
||||
int i = project->mapNames->indexOf(c->map_name);
|
||||
if (!visited[i] && c->direction != "dive") {
|
||||
dfs(i, visited);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RegionMapGenerator::search(int start) {
|
||||
//
|
||||
int size = project->mapNames->size();
|
||||
QVector<bool> visited(size, false);
|
||||
|
||||
dfs(start, visited);
|
||||
}
|
||||
|
||||
void RegionMapGenerator::populateSquares() {
|
||||
//
|
||||
for (auto entry : entries.values()) {
|
||||
qDebug() << entry;//.name << entry.width << "x" << entry.height;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,13 +1,16 @@
|
|||
#include "regionmapeditor.h"
|
||||
#include "ui_regionmapeditor.h"
|
||||
#include "regionmapgenerator.h"
|
||||
#include "imageexport.h"
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFileDialog>
|
||||
#include <QFormLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QSpinBox>
|
||||
#include <QColor>
|
||||
#include <QMessageBox>
|
||||
#include <math.h>
|
||||
|
@ -19,7 +22,7 @@ RegionMapEditor::RegionMapEditor(QWidget *parent, Project *project_) :
|
|||
this->ui->setupUi(this);
|
||||
this->project = project_;
|
||||
this->region_map = new RegionMap;
|
||||
this->ui->action_RegionMap_Generate->setVisible(false);
|
||||
this->ui->action_RegionMap_Resize->setVisible(false);
|
||||
}
|
||||
|
||||
RegionMapEditor::~RegionMapEditor()
|
||||
|
@ -56,8 +59,8 @@ void RegionMapEditor::setCurrentSquareOptions() {
|
|||
this->currIndex,
|
||||
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->map_squares[this->currIndex].x,
|
||||
this->region_map->map_squares[this->currIndex].y
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -153,13 +156,6 @@ void RegionMapEditor::displayRegionMapLayoutOptions() {
|
|||
|
||||
this->ui->frame_RM_Options->setEnabled(true);
|
||||
|
||||
this->ui->spinBox_RM_Options_x->setMaximum(
|
||||
this->region_map->width() - this->region_map->padLeft - this->region_map->padRight - 1
|
||||
);
|
||||
this->ui->spinBox_RM_Options_y->setMaximum(
|
||||
this->region_map->height() - this->region_map->padTop - this->region_map->padBottom - 1
|
||||
);
|
||||
|
||||
updateRegionMapLayoutOptions(this->currIndex);
|
||||
|
||||
// TODO: implement when the code is decompiled
|
||||
|
@ -168,15 +164,9 @@ void RegionMapEditor::displayRegionMapLayoutOptions() {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -355,9 +345,6 @@ void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, Reg
|
|||
item->select(event);
|
||||
//} else if (event->buttons() & Qt::MiddleButton) {// TODO
|
||||
} else {
|
||||
item->paint(event);
|
||||
this->region_map_layout_item->draw();
|
||||
this->hasUnsavedChanges = true;
|
||||
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||
RegionMapHistoryItem *current = history.current();
|
||||
bool addToHistory = !(current && current->tiles == this->region_map->getTiles());
|
||||
|
@ -367,6 +354,10 @@ void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, Reg
|
|||
);
|
||||
history.push(commit);
|
||||
}
|
||||
} else {
|
||||
item->paint(event);
|
||||
this->region_map_layout_item->draw();
|
||||
this->hasUnsavedChanges = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -388,8 +379,6 @@ void RegionMapEditor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityM
|
|||
if (event->buttons() & Qt::RightButton) {// TODO
|
||||
//} else if (event->buttons() & Qt::MiddleButton) {// TODO
|
||||
} else {
|
||||
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());
|
||||
|
@ -399,6 +388,9 @@ void RegionMapEditor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityM
|
|||
);
|
||||
history.push(commit);
|
||||
}
|
||||
} else {
|
||||
item->paint(event);
|
||||
this->hasUnsavedChanges = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -416,23 +408,9 @@ void RegionMapEditor::on_tabWidget_Region_Map_currentChanged(int index) {
|
|||
}
|
||||
}
|
||||
|
||||
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_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
|
||||
this->hasUnsavedChanges = true;// sometimes this is called for unknown reasons
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_lineEdit_RM_MapName_textEdited(const QString &text) {
|
||||
|
@ -441,6 +419,7 @@ void RegionMapEditor::on_lineEdit_RM_MapName_textEdited(const QString &text) {
|
|||
|
||||
void RegionMapEditor::on_pushButton_RM_Options_delete_clicked() {
|
||||
this->region_map->resetSquare(this->region_map_layout_item->selectedTile);
|
||||
updateRegionMapLayoutOptions(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;
|
||||
|
@ -526,6 +505,7 @@ void RegionMapEditor::undo() {
|
|||
this->resize(commit->mapWidth, commit->mapHeight);
|
||||
this->region_map->setTiles(commit->tiles);
|
||||
this->region_map_item->draw();
|
||||
this->region_map_layout_item->draw();
|
||||
break;
|
||||
case RegionMapEditorBox::CityMapImage:
|
||||
if (commit->cityMap == this->city_map_item->file)
|
||||
|
@ -551,6 +531,7 @@ void RegionMapEditor::redo() {
|
|||
this->resize(commit->mapWidth, commit->mapHeight);
|
||||
this->region_map->setTiles(commit->tiles);
|
||||
this->region_map_item->draw();
|
||||
this->region_map_layout_item->draw();
|
||||
break;
|
||||
case RegionMapEditorBox::CityMapImage:
|
||||
this->city_map_item->setTiles(commit->tiles);
|
||||
|
@ -634,6 +615,114 @@ void RegionMapEditor::on_action_RegionMap_ClearLayout_triggered() {
|
|||
}
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_action_Import_RegionMap_ImageTiles_triggered() {
|
||||
importTileImage(false);
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_action_Import_CityMap_ImageTiles_triggered() {
|
||||
importTileImage(true);
|
||||
}
|
||||
|
||||
void RegionMapEditor::importTileImage(bool city) {
|
||||
QString descriptor = city ? "City Map" : "Region Map";
|
||||
|
||||
QString infilepath = QFileDialog::getOpenFileName(this, QString("Import %1 Tiles Image").arg(descriptor),
|
||||
this->project->root, "Image Files (*.png *.bmp *.jpg *.dib)");
|
||||
if (infilepath.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
logInfo(QString("Importing %1 Tiles from '%2'").arg(descriptor).arg(infilepath));
|
||||
|
||||
// Read image data from buffer so that the built-in QImage doesn't try to detect file format
|
||||
// purely from the extension name.
|
||||
QFile file(infilepath);
|
||||
QImage image;
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
QByteArray imageData = file.readAll();
|
||||
image = QImage::fromData(imageData);
|
||||
} else {
|
||||
QString errorMessage = QString("Failed to open image file: '%1'").arg(infilepath);
|
||||
logError(errorMessage);
|
||||
QMessageBox msgBox(this);
|
||||
msgBox.setText("Failed to import tiles.");
|
||||
msgBox.setInformativeText(errorMessage);
|
||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||
msgBox.setIcon(QMessageBox::Icon::Critical);
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
if (image.width() == 0 || image.height() == 0 || image.width() % 8 != 0 || image.height() % 8 != 0) {
|
||||
QString errorMessage = QString("The image dimensions (%1 x %2) are invalid. Width and height must be multiples of 8 pixels.")
|
||||
.arg(image.width())
|
||||
.arg(image.height());
|
||||
logError(errorMessage);
|
||||
QMessageBox msgBox(this);
|
||||
msgBox.setText("Failed to import tiles.");
|
||||
msgBox.setInformativeText(errorMessage);
|
||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||
msgBox.setIcon(QMessageBox::Icon::Critical);
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate total number of tiles in image.
|
||||
int numTilesWide = image.width() / 8;
|
||||
int numTilesHigh = image.height() / 8;
|
||||
int totalTiles = numTilesHigh * numTilesWide;
|
||||
int maxAllowedTiles = 0x100;
|
||||
if (totalTiles > maxAllowedTiles) {
|
||||
QString errorMessage = QString("The total number of tiles in the provided image (%1) is greater than the allowed number (%2).")
|
||||
.arg(maxAllowedTiles)
|
||||
.arg(totalTiles);
|
||||
logError(errorMessage);
|
||||
QMessageBox msgBox(this);
|
||||
msgBox.setText("Failed to import tiles.");
|
||||
msgBox.setInformativeText(errorMessage);
|
||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||
msgBox.setIcon(QMessageBox::Icon::Critical);
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate the image's palette.
|
||||
QString palMessage = QString();
|
||||
bool palError = false;
|
||||
if (image.colorCount() == 0) {
|
||||
palMessage = QString("The provided image is not indexed.");
|
||||
palError = true;
|
||||
} else if (!city && image.colorCount() != 256) {
|
||||
palMessage = QString("The provided image has a palette with %1 colors. You must provide an indexed imaged with a 256 color palette.").arg(image.colorCount());
|
||||
palError = true;
|
||||
} else if (city && image.colorCount() != 16) {
|
||||
palMessage = QString("The provided image has a palette with %1 colors. You must provide an indexed imaged with a 16 color palette.").arg(image.colorCount());
|
||||
palError = true;
|
||||
}
|
||||
|
||||
if (palError) {
|
||||
logError(palMessage);
|
||||
QMessageBox msgBox(this);
|
||||
msgBox.setText("Failed to import tiles.");
|
||||
msgBox.setInformativeText(palMessage);
|
||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||
msgBox.setIcon(QMessageBox::Icon::Critical);
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
// Use the image from the correct path.
|
||||
if (city) {
|
||||
this->region_map->setTemporaryCityTilesPath(infilepath);
|
||||
} else {
|
||||
this->region_map->setTemporaryPngPath(infilepath);
|
||||
}
|
||||
this->hasUnsavedChanges = true;
|
||||
|
||||
// Redload and redraw images.
|
||||
displayRegionMap();
|
||||
displayCityMap(this->ui->comboBox_CityMap_picker->currentText());
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_comboBox_CityMap_picker_currentTextChanged(const QString &file) {
|
||||
this->displayCityMap(file);
|
||||
this->cityMapFirstDraw = true;
|
||||
|
@ -716,9 +805,3 @@ void RegionMapEditor::on_verticalSlider_Zoom_City_Tiles_valueChanged(int val) {
|
|||
ui->graphicsView_City_Map_Tiles->setMatrix(matrix);
|
||||
ui->graphicsView_City_Map_Tiles->setFixedSize(width + 2, height + 2);
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_action_RegionMap_Generate_triggered() {
|
||||
RegionMapGenerator generator(this->project);
|
||||
generator.generate("LittlerootTown");
|
||||
this->hasUnsavedChanges = true;
|
||||
}
|
||||
|
|
|
@ -20,14 +20,11 @@ void RegionMapPixmapItem::draw() {
|
|||
|
||||
void RegionMapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||
if (region_map) {
|
||||
if (event->type() == QEvent::GraphicsSceneMousePress) {
|
||||
} else {
|
||||
QPointF pos = event->pos();
|
||||
int x = static_cast<int>(pos.x()) / 8;
|
||||
int y = static_cast<int>(pos.y()) / 8;
|
||||
int index = x + y * region_map->width();
|
||||
this->region_map->map_squares[index].tile_img_id = this->tile_selector->selectedTile;
|
||||
}
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue