add region map data to config, fix some bugs

This commit is contained in:
garak 2019-01-15 17:06:18 -05:00
parent c75ce5db1d
commit 41f3780c8a
16 changed files with 399 additions and 154 deletions

View file

@ -1031,8 +1031,15 @@
<addaction name="action_RegionMap_Redo"/> <addaction name="action_RegionMap_Redo"/>
<addaction name="action_RegionMap_Resize"/> <addaction name="action_RegionMap_Resize"/>
</widget> </widget>
<widget class="QMenu" name="menuTools">
<property name="title">
<string>Tools</string>
</property>
<addaction name="action_RegionMap_Generate"/>
</widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
<addaction name="menuEdit"/> <addaction name="menuEdit"/>
<addaction name="menuTools"/>
</widget> </widget>
<widget class="QStatusBar" name="statusbar"/> <widget class="QStatusBar" name="statusbar"/>
<action name="action_RegionMap_Save"> <action name="action_RegionMap_Save">
@ -1067,6 +1074,11 @@
<string>Ctrl+R</string> <string>Ctrl+R</string>
</property> </property>
</action> </action>
<action name="action_RegionMap_Generate">
<property name="text">
<string>Generate...</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>

View file

@ -4,6 +4,7 @@
#include <QString> #include <QString>
#include <QObject> #include <QObject>
#include <QByteArrayList> #include <QByteArrayList>
#include <QSize>
enum MapSortOrder { enum MapSortOrder {
Group = 0, Group = 0,
@ -36,6 +37,7 @@ public:
this->metatilesZoom = 30; this->metatilesZoom = 30;
this->showPlayerView = false; this->showPlayerView = false;
this->showCursorTile = true; this->showCursorTile = true;
this->regionMapDimensions = QSize(32, 20);
} }
void setRecentProject(QString project); void setRecentProject(QString project);
void setRecentMap(QString map); void setRecentMap(QString map);
@ -46,6 +48,7 @@ public:
void setMetatilesZoom(int zoom); void setMetatilesZoom(int zoom);
void setShowPlayerView(bool enabled); void setShowPlayerView(bool enabled);
void setShowCursorTile(bool enabled); void setShowCursorTile(bool enabled);
void setRegionMapDimensions(int width, int height);
QString getRecentProject(); QString getRecentProject();
QString getRecentMap(); QString getRecentMap();
MapSortOrder getMapSortOrder(); MapSortOrder getMapSortOrder();
@ -55,6 +58,7 @@ public:
int getMetatilesZoom(); int getMetatilesZoom();
bool getShowPlayerView(); bool getShowPlayerView();
bool getShowCursorTile(); bool getShowCursorTile();
QSize getRegionMapDimensions();
protected: protected:
QString getConfigFilepath(); QString getConfigFilepath();
void parseConfigKeyValue(QString key, QString value); void parseConfigKeyValue(QString key, QString value);
@ -76,6 +80,7 @@ private:
int metatilesZoom; int metatilesZoom;
bool showPlayerView; bool showPlayerView;
bool showCursorTile; bool showCursorTile;
QSize regionMapDimensions;
}; };
extern PorymapConfig porymapConfig; extern PorymapConfig porymapConfig;

View file

@ -2,6 +2,7 @@
#define MAPCONNECTION_H #define MAPCONNECTION_H
#include <QString> #include <QString>
#include <QHash>
class MapConnection { class MapConnection {
public: public:
@ -10,4 +11,12 @@ public:
QString map_name; QString map_name;
}; };
inline bool operator==(const MapConnection &c1, const MapConnection &c2) {
return c1.map_name == c2.map_name;
}
inline uint qHash(const MapConnection &key) {
return qHash(key.map_name);
}
#endif // MAPCONNECTION_H #endif // MAPCONNECTION_H

View file

@ -61,9 +61,13 @@ public:
Project *project; Project *project;
//QList<RegionMapSquare> map_squares;
QVector<RegionMapSquare> map_squares; QVector<RegionMapSquare> map_squares;
const int padLeft = 1;
const int padRight = 3;
const int padTop = 2;
const int padBottom = 3;
History<RegionMapHistoryItem*> history; History<RegionMapHistoryItem*> history;
QString region_map_png_path; QString region_map_png_path;
@ -115,8 +119,6 @@ public:
void resetSquare(int); void resetSquare(int);
void test();// remove
// TODO: move read / write functions to private (and others) // TODO: move read / write functions to private (and others)
private: private:
int layout_width_; int layout_width_;

View file

@ -0,0 +1,77 @@
#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

View file

@ -47,8 +47,7 @@ public:
Map* loadMap(QString); Map* loadMap(QString);
Map* getMap(QString); Map* getMap(QString);
// other options include: InGameName, PopUpName, ???? QMap<QString, QString> *mapSecToMapHoverName;
QMap<QString, QString> *mapSecToMapHoverName;// {"MAPSEC_LITTLEROOT_TOWN" : "LITTLEROOT{NAME_END} TOWN"}
QMap<QString, Tileset*> *tileset_cache = nullptr; QMap<QString, Tileset*> *tileset_cache = nullptr;
Tileset* loadTileset(QString, Tileset *tileset = nullptr); Tileset* loadTileset(QString, Tileset *tileset = nullptr);

View file

@ -2,6 +2,7 @@
#define CITYMAPPIXMAPITEM_H #define CITYMAPPIXMAPITEM_H
#include "tilemaptileselector.h" #include "tilemaptileselector.h"
#include <QGraphicsPixmapItem> #include <QGraphicsPixmapItem>
#include <QByteArray> #include <QByteArray>
@ -18,10 +19,6 @@ public:
QString file; QString file;
// TODO: make private and use access functions
int width;
int height;
QByteArray data; QByteArray data;
void init(); void init();
@ -30,10 +27,12 @@ public:
virtual void paint(QGraphicsSceneMouseEvent*); virtual void paint(QGraphicsSceneMouseEvent*);
virtual void draw(); virtual void draw();
int getIndexAt(int, int); int getIndexAt(int, int);
int width();
int height();
//private: private:
// int width; int width_;
// int height; int height_;
signals: signals:
void mouseEvent(QGraphicsSceneMouseEvent *, CityMapPixmapItem *); void mouseEvent(QGraphicsSceneMouseEvent *, CityMapPixmapItem *);

View file

@ -29,6 +29,8 @@ public:
void loadRegionMapData(); void loadRegionMapData();
void loadCityMaps(); void loadCityMaps();
void onRegionMapTileSelectorSelectedTileChanged(unsigned);
void onCityMapTileSelectorSelectedTileChanged(unsigned);
void onRegionMapTileSelectorHoveredTileChanged(unsigned); void onRegionMapTileSelectorHoveredTileChanged(unsigned);
void onRegionMapTileSelectorHoveredTileCleared(); void onRegionMapTileSelectorHoveredTileCleared();
@ -47,9 +49,11 @@ private:
History<RegionMapHistoryItem*> history; History<RegionMapHistoryItem*> history;
int currIndex = 65;// TODO: automatic this from width * 2 + 1 int currIndex;
unsigned selectedCityTile;
unsigned selectedImageTile;
double scaleUpFactor = 2.0;// TODO double scaleUpFactor = 2.0;
double scaleDownFactor = 1.0 / scaleUpFactor; double scaleDownFactor = 1.0 / scaleUpFactor;
double scaleRegionMapTiles = 1.0; double scaleRegionMapTiles = 1.0;
@ -86,6 +90,7 @@ private slots:
void on_action_RegionMap_Undo_triggered(); void on_action_RegionMap_Undo_triggered();
void on_action_RegionMap_Redo_triggered(); void on_action_RegionMap_Redo_triggered();
void on_action_RegionMap_Resize_triggered(); void on_action_RegionMap_Resize_triggered();
void on_action_RegionMap_Generate_triggered();
void on_tabWidget_Region_Map_currentChanged(int); void on_tabWidget_Region_Map_currentChanged(int);
void on_pushButton_RM_Options_save_clicked(); void on_pushButton_RM_Options_save_clicked();
void on_pushButton_RM_Options_delete_clicked(); void on_pushButton_RM_Options_delete_clicked();

View file

@ -30,6 +30,7 @@ SOURCES += src/core/block.cpp \
src/core/tileset.cpp \ src/core/tileset.cpp \
src/core/regionmapeditor.cpp \ src/core/regionmapeditor.cpp \
src/core/regionmap.cpp \ src/core/regionmap.cpp \
src/core/regionmapgenerator.cpp \
src/ui/aboutporymap.cpp \ src/ui/aboutporymap.cpp \
src/ui/bordermetatilespixmapitem.cpp \ src/ui/bordermetatilespixmapitem.cpp \
src/ui/collisionpixmapitem.cpp \ src/ui/collisionpixmapitem.cpp \
@ -87,6 +88,7 @@ HEADERS += include/core/block.h \
include/core/tileset.h \ include/core/tileset.h \
include/core/regionmapeditor.h \ include/core/regionmapeditor.h \
include/core/regionmap.h \ include/core/regionmap.h \
include/core/regionmapgenerator.h \
include/ui/aboutporymap.h \ include/ui/aboutporymap.h \
include/ui/bordermetatilespixmapitem.h \ include/ui/bordermetatilespixmapitem.h \
include/ui/collisionpixmapitem.h \ include/ui/collisionpixmapitem.h \

View file

@ -156,6 +156,17 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
if (!ok) { if (!ok) {
logWarn(QString("Invalid config value for show_cursor_tile: '%1'. Must be 0 or 1.").arg(value)); logWarn(QString("Invalid config value for show_cursor_tile: '%1'. Must be 0 or 1.").arg(value));
} }
} else if (key == "region_map_dimensions") {
bool ok1, ok2;
QStringList dims = value.split("x");
int w = dims[0].toInt(&ok1);
int h = dims[1].toInt(&ok2);
if (!ok1 || !ok2) {
logWarn("Cannot parse region map dimensions. Using default values instead.");
this->regionMapDimensions = QSize(32, 20);
} else {
this->regionMapDimensions = QSize(w, h);
}
} else { } else {
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key)); logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
} }
@ -176,6 +187,8 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
map.insert("metatiles_zoom", QString("%1").arg(this->metatilesZoom)); map.insert("metatiles_zoom", QString("%1").arg(this->metatilesZoom));
map.insert("show_player_view", this->showPlayerView ? "1" : "0"); map.insert("show_player_view", this->showPlayerView ? "1" : "0");
map.insert("show_cursor_tile", this->showCursorTile ? "1" : "0"); map.insert("show_cursor_tile", this->showCursorTile ? "1" : "0");
map.insert("region_map_dimensions", QString("%1x%2").arg(this->regionMapDimensions.width())
.arg(this->regionMapDimensions.height()));
return map; return map;
} }
@ -246,6 +259,10 @@ void PorymapConfig::setShowCursorTile(bool enabled) {
this->save(); this->save();
} }
void PorymapConfig::setRegionMapDimensions(int width, int height) {
this->regionMapDimensions = QSize(width, height);//QString("%1x%2").arg(width).arg(height);
}
QString PorymapConfig::getRecentProject() { QString PorymapConfig::getRecentProject() {
return this->recentProject; return this->recentProject;
} }
@ -290,6 +307,10 @@ bool PorymapConfig::getShowCursorTile() {
return this->showCursorTile; return this->showCursorTile;
} }
QSize PorymapConfig::getRegionMapDimensions() {
return this->regionMapDimensions;
}
const QMap<BaseGameVersion, QString> baseGameVersionMap = { const QMap<BaseGameVersion, QString> baseGameVersionMap = {
{BaseGameVersion::pokeruby, "pokeruby"}, {BaseGameVersion::pokeruby, "pokeruby"},
{BaseGameVersion::pokeemerald, "pokeemerald"}, {BaseGameVersion::pokeemerald, "pokeemerald"},

View file

@ -1,5 +1,6 @@
#include "regionmap.h" #include "regionmap.h"
#include "log.h" #include "log.h"
#include "config.h"
#include <QByteArray> #include <QByteArray>
#include <QFile> #include <QFile>
@ -9,31 +10,26 @@
// TODO: add version arg to this from Editor Setings
void RegionMap::init(Project *pro) { void RegionMap::init(Project *pro) {
QString path = pro->root; QString path = pro->root;
this->project = pro; this->project = pro;
// TODO: in the future, allow these to be adjustable (and save values) QSize dimensions = porymapConfig.getRegionMapDimensions();
// possibly use a config file? save to include/constants/region_map.h? img_width_ = dimensions.width();
layout_width_ = 36;//28; img_height_ = dimensions.height();
layout_height_ = 25;//15;
img_width_ = layout_width_ + 4; layout_width_ = img_width_ - this->padLeft - this->padRight;
img_height_ = layout_height_ + 5; layout_height_ = img_height_ - this->padTop - this->padBottom;
region_map_bin_path = path + "/graphics/pokenav/region_map_map.bin"; region_map_bin_path = path + "/graphics/pokenav/region_map_map.bin";
region_map_png_path = path + "/graphics/pokenav/region_map.png"; region_map_png_path = path + "/graphics/pokenav/region_map.png";
region_map_entries_path = path + "/src/data/region_map/region_map_entries.h"; region_map_entries_path = path + "/src/data/region_map/region_map_entries.h";
region_map_layout_bin_path = path + "/graphics/pokenav/region_map_section_layout.bin"; region_map_layout_bin_path = path + "/graphics/pokenav/region_map_section_layout.bin";
city_map_tiles_path = path + "/graphics/pokenav/zoom_tiles.png"; city_map_tiles_path = path + "/graphics/pokenav/zoom_tiles.png";
// TODO: rename png to map_squares in pokeemerald
readBkgImgBin(); readBkgImgBin();
readLayout(); readLayout();
readCityMaps(); readCityMaps();
//resize(40,30);
} }
// TODO: if the tileId is not valid for the provided image, make sure it does not crash // TODO: if the tileId is not valid for the provided image, make sure it does not crash
@ -58,7 +54,7 @@ void RegionMap::readBkgImgBin() {
} }
void RegionMap::saveBkgImgBin() { void RegionMap::saveBkgImgBin() {
QByteArray data(4096,0);// use a constant here? maybe read the original size? QByteArray data(4096,0);// use a constant here? maybe read the original size?
for (int m = 0; m < img_height_; m++) { for (int m = 0; m < img_height_; m++) {
for (int n = 0; n < img_width_; n++) { for (int n = 0; n < img_width_; n++) {
@ -79,12 +75,7 @@ void RegionMap::readLayout() {
if (!file.open(QIODevice::ReadOnly)) return; if (!file.open(QIODevice::ReadOnly)) return;
QString line; QString line;
// TODO: put these in Project, and keep in order
//QMap<QString, QString> sMapNamesMap;// {"sMapName_LittlerootTown" : "LITTLEROOT{NAME_END} TOWN"}
//QMap<QString, QString> mapSecToMapName;// {"MAPSEC_LITTLEROOT_TOWN" : "LITTLEROOT{NAME_END} TOWN"}
//QList<> mapSecToMapEntry;// {"MAPSEC_LITTLEROOT_TOWN" : }
// new map ffor mapSecToMapHoverName
QMap<QString, QString> *qmap = new QMap<QString, QString>; QMap<QString, QString> *qmap = new QMap<QString, QString>;
QTextStream in(&file); QTextStream in(&file);
@ -103,23 +94,16 @@ void RegionMap::readLayout() {
QStringList entry = reAfter.match(line).captured(1).remove(" ").split(","); QStringList entry = reAfter.match(line).captured(1).remove(" ").split(",");
QString mapsec = reBefore.match(line).captured(1); QString mapsec = reBefore.match(line).captured(1);
QString insertion = entry[4].remove("sMapName_"); QString insertion = entry[4].remove("sMapName_");
qmap->insert(mapsec, sMapNamesMap[insertion]); qmap->insert(mapsec, sMapNamesMap.value(insertion));
// can make this a map, the order doesn't really matter mapSecToMapEntry[mapsec] = {
mapSecToMapEntry[mapsec] = // x y width height name
// x y width height name entry[0].toInt(), entry[1].toInt(), entry[2].toInt(), entry[3].toInt(), insertion
{entry[0].toInt(), entry[1].toInt(), entry[2].toInt(), entry[3].toInt(), insertion} };
;
// ^ when loading this info to city maps, loop over mapSecToMapEntry and
// add x and y map sqyare when width or height >1
// indexOf because mapsecs is just a qstringlist
//text += line.remove(" ");
} }
} }
file.close(); file.close();
//qDebug() << "sMapNames" << sMapNames; project->mapSecToMapHoverName = qmap;
project->mapSecToMapHoverName = qmap;// TODO: is this map necessary?
QFile binFile(region_map_layout_bin_path); QFile binFile(region_map_layout_bin_path);
if (!binFile.open(QIODevice::ReadOnly)) return; if (!binFile.open(QIODevice::ReadOnly)) return;
@ -154,7 +138,8 @@ void RegionMap::saveLayout() {
entries_text += "\nconst struct RegionMapLocation gRegionMapEntries[] = {\n"; entries_text += "\nconst struct RegionMapLocation gRegionMapEntries[] = {\n";
for (auto sec : mapSecToMapEntry.keys()) { for (auto sec : *(project->regionMapSections)) {
if (!mapSecToMapEntry.contains(sec)) continue;
struct RegionMapEntry entry = mapSecToMapEntry.value(sec); struct RegionMapEntry entry = mapSecToMapEntry.value(sec);
entries_text += " [" + sec + "] = {" + QString::number(entry.x) + ", " + QString::number(entry.y) + ", " entries_text += " [" + sec + "] = {" + QString::number(entry.x) + ", " + QString::number(entry.y) + ", "
+ QString::number(entry.width) + ", " + QString::number(entry.height) + ", sMapName_" + entry.name + "},\n"; + QString::number(entry.width) + ", " + QString::number(entry.height) + ", sMapName_" + entry.name + "},\n";
@ -180,7 +165,7 @@ void RegionMap::readCityMaps() {}
// layout coords to image index // layout coords to image index
int RegionMap::img_index_(int x, int y) { int RegionMap::img_index_(int x, int y) {
return ((x + 1) + (y + 2) * img_width_); return ((x + this->padLeft) + (y + this->padTop) * img_width_);
} }
// layout coords to layout index // layout coords to layout index
@ -188,26 +173,6 @@ int RegionMap::layout_index_(int x, int y) {
return (x + y * layout_width_); return (x + y * layout_width_);
} }
void RegionMap::test() {
//
bool debug_rmap = false;
if (debug_rmap) {
for (auto square : map_squares) {
qDebug() << "(" << square.x << "," << square.y << ")"
<< square.tile_img_id
<< square.has_map
<< square.map_name
<< square.has_city_map
<< square.city_map_name
;
}
QPixmap png(region_map_png_path);
qDebug() << "png num 8x8 tiles" << QString("0x%1").arg((png.width()/8) * (png.height() / 8), 2, 16, QChar('0'));
}
}
int RegionMap::width() { int RegionMap::width() {
return this->img_width_; return this->img_width_;
} }
@ -229,12 +194,12 @@ void RegionMap::save() {
logInfo("Saving region map info."); logInfo("Saving region map info.");
saveBkgImgBin(); saveBkgImgBin();
saveLayout(); saveLayout();
// TODO: re-select proper tile porymapConfig.setRegionMapDimensions(this->img_width_, this->img_height_);
// TODO: add region map dimensions to config
} }
void RegionMap::saveOptions(int id, QString sec, QString name, int x, int y) { void RegionMap::saveOptions(int id, QString sec, QString name, int x, int y) {
int index = getMapSquareIndex(x + 1, y + 2); resetSquare(id);
int index = getMapSquareIndex(x + this->padLeft, y + this->padTop);
if (!sec.isEmpty()) { if (!sec.isEmpty()) {
this->map_squares[index].has_map = true; this->map_squares[index].has_map = true;
this->map_squares[index].secid = static_cast<uint8_t>(project->regionMapSections->indexOf(sec)); this->map_squares[index].secid = static_cast<uint8_t>(project->regionMapSections->indexOf(sec));
@ -254,14 +219,12 @@ void RegionMap::saveOptions(int id, QString sec, QString name, int x, int y) {
this->map_squares[index].y = y; this->map_squares[index].y = y;
this->map_squares[index].duplicated = false; this->map_squares[index].duplicated = false;
} }
resetSquare(id); //resetSquare(id);
} }
// from x, y of image // from x, y of image
int RegionMap::getMapSquareIndex(int x, int y) { int RegionMap::getMapSquareIndex(int x, int y) {
//
int index = (x + y * img_width_); int index = (x + y * img_width_);
//qDebug() << "index:" << index;
return index < map_squares.length() ? index : 0; return index < map_squares.length() ? index : 0;
} }
@ -304,7 +267,7 @@ void RegionMap::resize(int newWidth, int newHeight) {
RegionMapSquare square; RegionMapSquare square;
if (x < img_width_ && y < img_height_) { if (x < img_width_ && y < img_height_) {
square = map_squares[getMapSquareIndex(x, y)]; square = map_squares[getMapSquareIndex(x, y)];
} else if (x < newWidth - 3 && y < newHeight - 3) { } else if (x < newWidth - this->padRight && y < newHeight - this->padBottom) {
square.tile_img_id = 0; square.tile_img_id = 0;
square.x = x; square.x = x;
square.y = y; square.y = y;
@ -319,34 +282,6 @@ void RegionMap::resize(int newWidth, int newHeight) {
this->map_squares = new_squares; this->map_squares = new_squares;
this->img_width_ = newWidth; this->img_width_ = newWidth;
this->img_height_ = newHeight; this->img_height_ = newHeight;
this->layout_width_ = newWidth - 4; this->layout_width_ = newWidth - this->padLeft - this->padRight;
this->layout_height_ = newHeight - 5; this->layout_height_ = newHeight - this->padTop - this->padBottom;
} }

View file

@ -0,0 +1,148 @@
#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;
}
}

View file

@ -1,5 +1,6 @@
#include "citymappixmapitem.h" #include "citymappixmapitem.h"
#include "imageproviders.h" #include "imageproviders.h"
#include "log.h"
#include <QFile> #include <QFile>
#include <QPainter> #include <QPainter>
@ -7,11 +8,9 @@
// read to byte array from filename
void CityMapPixmapItem::init() { void CityMapPixmapItem::init() {
// TODO: are they always 10x10 squares? width_ = 10;
width = 10; height_ = 10;
height = 10;
QFile binFile(file); QFile binFile(file);
if (!binFile.open(QIODevice::ReadOnly)) return; if (!binFile.open(QIODevice::ReadOnly)) return;
@ -21,13 +20,13 @@ void CityMapPixmapItem::init() {
} }
void CityMapPixmapItem::draw() { void CityMapPixmapItem::draw() {
QImage image(width * 8, height * 8, QImage::Format_RGBA8888); QImage image(width_ * 8, height_ * 8, QImage::Format_RGBA8888);
QPainter painter(&image); QPainter painter(&image);
for (int i = 0; i < data.size() / 2; i++) { for (int i = 0; i < data.size() / 2; i++) {
QImage img = this->tile_selector->tileImg(data[i * 2]);// need to skip every other tile QImage img = this->tile_selector->tileImg(data[i * 2]);// need to skip every other tile
int x = i % width; int x = i % width_;
int y = i / width; int y = i / width_;
QPoint pos = QPoint(x * 8, y * 8); QPoint pos = QPoint(x * 8, y * 8);
painter.drawImage(pos, img); painter.drawImage(pos, img);
} }
@ -37,15 +36,16 @@ void CityMapPixmapItem::draw() {
} }
void CityMapPixmapItem::save() { void CityMapPixmapItem::save() {
// TODO: logError / logWarn if fail
QFile binFile(file); QFile binFile(file);
if (!binFile.open(QIODevice::WriteOnly)) return; if (!binFile.open(QIODevice::WriteOnly)) {
logError(QString("Cannot save city map tilemap to %1.").arg(file));
return;
}
binFile.write(data); binFile.write(data);
binFile.close(); binFile.close();
} }
void CityMapPixmapItem::paint(QGraphicsSceneMouseEvent *event) { void CityMapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
//
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = static_cast<int>(pos.x()) / 8; int x = static_cast<int>(pos.x()) / 8;
int y = static_cast<int>(pos.y()) / 8; int y = static_cast<int>(pos.y()) / 8;
@ -63,6 +63,13 @@ void CityMapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
} }
int CityMapPixmapItem::getIndexAt(int x, int y) { int CityMapPixmapItem::getIndexAt(int x, int y) {
// return 2 * (x + y * this->width_);
return 2 * (x + y * width); }
int CityMapPixmapItem::width() {
return this->width_;
}
int CityMapPixmapItem::height() {
return this->height_;
} }

View file

@ -1,5 +1,7 @@
#include "regionmapeditor.h" #include "regionmapeditor.h"
#include "ui_regionmapeditor.h" #include "ui_regionmapeditor.h"
#include "regionmapgenerator.h"
#include "config.h"
#include <QDir> #include <QDir>
#include <QDialog> #include <QDialog>
@ -43,7 +45,7 @@ void RegionMapEditor::on_action_RegionMap_Save_triggered() {
void RegionMapEditor::loadRegionMapData() { void RegionMapEditor::loadRegionMapData() {
this->region_map->init(project); this->region_map->init(project);
this->currIndex = this->region_map->width() * 2 + 1; this->currIndex = this->region_map->width() * this->region_map->padTop + this->region_map->padLeft;
displayRegionMap(); displayRegionMap();
} }
@ -85,7 +87,7 @@ void RegionMapEditor::displayRegionMapImage() {
this, &RegionMapEditor::onHoveredRegionMapTileCleared); this, &RegionMapEditor::onHoveredRegionMapTileCleared);
this->scene_region_map_image->addItem(this->region_map_item); this->scene_region_map_image->addItem(this->region_map_item);
//this->scene_region_map_image->setSceneRect(this->scene_region_map_image->sceneRect()); 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->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() * scaleRegionMapImage);
@ -113,20 +115,24 @@ void RegionMapEditor::displayRegionMapLayout() {
this->region_map_layout_item->select(this->currIndex); this->region_map_layout_item->select(this->currIndex);
this->scene_region_map_layout->addItem(region_map_layout_item); this->scene_region_map_layout->addItem(region_map_layout_item);
//this->scene_region_map_layout->setSceneRect(this->scene_region_map_layout->sceneRect()); 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->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() * scaleRegionMapImage);
} }
void RegionMapEditor::displayRegionMapLayoutOptions() { void RegionMapEditor::displayRegionMapLayoutOptions() {
this->ui->comboBox_RM_ConnectedMap->clear();
this->ui->comboBox_RM_ConnectedMap->addItems(*(this->project->regionMapSections)); this->ui->comboBox_RM_ConnectedMap->addItems(*(this->project->regionMapSections));
this->ui->frame_RM_Options->setEnabled(true); this->ui->frame_RM_Options->setEnabled(true);
// TODO: change these values to variables this->ui->spinBox_RM_Options_x->setMaximum(
this->ui->spinBox_RM_Options_x->setMaximum(this->region_map->width() - 5); this->region_map->width() - this->region_map->padLeft - this->region_map->padRight - 1
this->ui->spinBox_RM_Options_y->setMaximum(this->region_map->height() - 4); );
this->ui->spinBox_RM_Options_y->setMaximum(
this->region_map->height() - this->region_map->padTop - this->region_map->padBottom - 1
);
updateRegionMapLayoutOptions(currIndex); updateRegionMapLayoutOptions(currIndex);
} }
@ -134,7 +140,7 @@ void RegionMapEditor::displayRegionMapLayoutOptions() {
void RegionMapEditor::updateRegionMapLayoutOptions(int index) { void RegionMapEditor::updateRegionMapLayoutOptions(int index) {
this->ui->spinBox_RM_Options_x->blockSignals(true); this->ui->spinBox_RM_Options_x->blockSignals(true);
this->ui->spinBox_RM_Options_y->blockSignals(true); this->ui->spinBox_RM_Options_y->blockSignals(true);
this->ui->lineEdit_RM_MapName->setText(this->project->mapSecToMapHoverName->value(this->region_map->map_squares[index].mapsec));//this->region_map->map_squares[index].map_name); 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->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_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_y->setValue(this->region_map->map_squares[index].y);
@ -156,6 +162,8 @@ void RegionMapEditor::displayRegionMapTileSelector() {
this->scene_region_map_tiles->addItem(this->mapsquare_selector_item); this->scene_region_map_tiles->addItem(this->mapsquare_selector_item);
connect(this->mapsquare_selector_item, &TilemapTileSelector::selectedTileChanged,
this, &RegionMapEditor::onRegionMapTileSelectorSelectedTileChanged);
connect(this->mapsquare_selector_item, &TilemapTileSelector::hoveredTileChanged, connect(this->mapsquare_selector_item, &TilemapTileSelector::hoveredTileChanged,
this, &RegionMapEditor::onRegionMapTileSelectorHoveredTileChanged); this, &RegionMapEditor::onRegionMapTileSelectorHoveredTileChanged);
connect(this->mapsquare_selector_item, &TilemapTileSelector::hoveredTileCleared, connect(this->mapsquare_selector_item, &TilemapTileSelector::hoveredTileCleared,
@ -164,6 +172,8 @@ void RegionMapEditor::displayRegionMapTileSelector() {
this->ui->graphicsView_RegionMap_Tiles->setScene(this->scene_region_map_tiles); this->ui->graphicsView_RegionMap_Tiles->setScene(this->scene_region_map_tiles);
this->ui->graphicsView_RegionMap_Tiles->setFixedSize(this->mapsquare_selector_item->pixelWidth * scaleRegionMapTiles + 2, this->ui->graphicsView_RegionMap_Tiles->setFixedSize(this->mapsquare_selector_item->pixelWidth * scaleRegionMapTiles + 2,
this->mapsquare_selector_item->pixelHeight * scaleRegionMapTiles + 2); this->mapsquare_selector_item->pixelHeight * scaleRegionMapTiles + 2);
this->mapsquare_selector_item->select(this->selectedImageTile);
} }
void RegionMapEditor::displayCityMapTileSelector() { void RegionMapEditor::displayCityMapTileSelector() {
@ -179,17 +189,15 @@ void RegionMapEditor::displayCityMapTileSelector() {
this->city_map_selector_item->draw(); this->city_map_selector_item->draw();
this->scene_city_map_tiles->addItem(this->city_map_selector_item); this->scene_city_map_tiles->addItem(this->city_map_selector_item);
this->scene_city_map_tiles->setSceneRect(this->scene_city_map_tiles->sceneRect());// ?
// TODO: connect(this->city_map_selector_item, &TilemapTileSelector::selectedTileChanged,
/*connect(this->city_map_selector_item, &TilemapTileSelector::hoveredTileChanged, this, &RegionMapEditor::onCityMapTileSelectorSelectedTileChanged);
this, &RegionMapEditor::onRegionMapTileSelectorHoveredTileChanged);
connect(this->city_map_selector_item, &TilemapTileSelector::hoveredTileCleared,
this, &RegionMapEditor::onRegionMapTileSelectorHoveredTileCleared);*/
this->ui->graphicsView_City_Map_Tiles->setScene(this->scene_city_map_tiles); this->ui->graphicsView_City_Map_Tiles->setScene(this->scene_city_map_tiles);
this->ui->graphicsView_City_Map_Tiles->setFixedSize(this->city_map_selector_item->pixelWidth * scaleCityMapTiles + 2, this->ui->graphicsView_City_Map_Tiles->setFixedSize(this->city_map_selector_item->pixelWidth * scaleCityMapTiles + 2,
this->city_map_selector_item->pixelHeight * scaleCityMapTiles + 2); this->city_map_selector_item->pixelHeight * scaleCityMapTiles + 2);
this->city_map_selector_item->select(this->selectedCityTile);
} }
void RegionMapEditor::displayCityMap(QString f) { void RegionMapEditor::displayCityMap(QString f) {
@ -213,8 +221,8 @@ void RegionMapEditor::displayCityMap(QString f) {
scene_city_map_image->setSceneRect(this->scene_city_map_image->sceneRect()); scene_city_map_image->setSceneRect(this->scene_city_map_image->sceneRect());
this->ui->graphicsView_City_Map->setScene(scene_city_map_image); this->ui->graphicsView_City_Map->setScene(scene_city_map_image);
this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width * scaleCityMapImage + 2, this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width() * scaleCityMapImage + 2,
8 * city_map_item->height * scaleCityMapImage + 2); 8 * city_map_item->height() * scaleCityMapImage + 2);
} }
bool RegionMapEditor::createCityMap(QString name) { bool RegionMapEditor::createCityMap(QString name) {
@ -222,7 +230,6 @@ bool RegionMapEditor::createCityMap(QString name) {
QString file = this->project->root + "/graphics/pokenav/city_maps/" + name + ".bin"; QString file = this->project->root + "/graphics/pokenav/city_maps/" + name + ".bin";
// TODO: use project config for these values?
uint8_t filler = 0x30; uint8_t filler = 0x30;
uint8_t border = 0x7; uint8_t border = 0x7;
uint8_t blank = 0x1; uint8_t blank = 0x1;
@ -248,6 +255,14 @@ bool RegionMapEditor::createCityMap(QString name) {
return !errored; return !errored;
} }
void RegionMapEditor::onRegionMapTileSelectorSelectedTileChanged(unsigned id) {
this->selectedImageTile = id;
}
void RegionMapEditor::onCityMapTileSelectorSelectedTileChanged(unsigned id) {
this->selectedCityTile = id;
}
void RegionMapEditor::onRegionMapTileSelectorHoveredTileChanged(unsigned tileId) { void RegionMapEditor::onRegionMapTileSelectorHoveredTileChanged(unsigned tileId) {
QString message = QString("Tile: 0x") + QString("%1").arg(tileId, 4, 16, QChar('0')).toUpper(); QString message = QString("Tile: 0x") + QString("%1").arg(tileId, 4, 16, QChar('0')).toUpper();
this->ui->statusbar->showMessage(message); this->ui->statusbar->showMessage(message);
@ -270,7 +285,6 @@ void RegionMapEditor::onRegionMapLayoutSelectedTileChanged(int index) {
} }
void RegionMapEditor::onRegionMapLayoutHoveredTileChanged(int index) { void RegionMapEditor::onRegionMapLayoutHoveredTileChanged(int index) {
// TODO: change to x, y coords not index
QString message = QString(); QString message = QString();
int x = this->region_map->map_squares[index].x; int x = this->region_map->map_squares[index].x;
int y = this->region_map->map_squares[index].y; int y = this->region_map->map_squares[index].y;
@ -289,7 +303,8 @@ void RegionMapEditor::onRegionMapLayoutHoveredTileCleared() {
} }
void RegionMapEditor::onHoveredRegionMapTileChanged(int x, int y) { void RegionMapEditor::onHoveredRegionMapTileChanged(int x, int y) {
QString message = QString("x: %1, y: %2 Tile: 0x").arg(x).arg(y) + QString("%1").arg(this->region_map->getTileId(x, y), 4, 16, QChar('0')).toUpper(); QString message = QString("x: %1, y: %2 Tile: 0x").arg(x).arg(y)
+ QString("%1").arg(this->region_map->getTileId(x, y), 4, 16, QChar('0')).toUpper();
this->ui->statusbar->showMessage(message); this->ui->statusbar->showMessage(message);
} }
@ -300,7 +315,7 @@ void RegionMapEditor::onHoveredRegionMapTileCleared() {
void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, RegionMapPixmapItem *item) { void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, RegionMapPixmapItem *item) {
if (event->buttons() & Qt::RightButton) { if (event->buttons() & Qt::RightButton) {
item->select(event); item->select(event);
} else if (event->buttons() & Qt::MiddleButton) {// TODO //} else if (event->buttons() & Qt::MiddleButton) {// TODO
} else { } else {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = static_cast<int>(pos.x()) / 8; int x = static_cast<int>(pos.x()) / 8;
@ -310,14 +325,14 @@ void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, Reg
RegionMapHistoryItem *commit = new RegionMapHistoryItem(RegionMapEditorBox::BackgroundImage, index, RegionMapHistoryItem *commit = new RegionMapHistoryItem(RegionMapEditorBox::BackgroundImage, index,
this->region_map->map_squares[index].tile_img_id, this->mapsquare_selector_item->getSelectedTile()); this->region_map->map_squares[index].tile_img_id, this->mapsquare_selector_item->getSelectedTile());
history.push(commit); history.push(commit);
item->paint(event);//*/ item->paint(event);
} }
} }
void RegionMapEditor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityMapPixmapItem *item) { void RegionMapEditor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityMapPixmapItem *item) {
// //
if (event->buttons() & Qt::RightButton) {// TODO if (event->buttons() & Qt::RightButton) {// TODO
} else if (event->buttons() & Qt::MiddleButton) {// TODO //} else if (event->buttons() & Qt::MiddleButton) {// TODO
} else { } else {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = static_cast<int>(pos.x()) / 8; int x = static_cast<int>(pos.x()) / 8;
@ -332,23 +347,34 @@ void RegionMapEditor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityM
void RegionMapEditor::on_tabWidget_Region_Map_currentChanged(int index) { void RegionMapEditor::on_tabWidget_Region_Map_currentChanged(int index) {
this->ui->stackedWidget_RM_Options->setCurrentIndex(index); this->ui->stackedWidget_RM_Options->setCurrentIndex(index);
switch (index)
{
case 0:
this->ui->pushButton_Zoom_In_Image_Tiles->setVisible(true);
this->ui->pushButton_Zoom_Out_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);
break;
}
} }
void RegionMapEditor::on_spinBox_RM_Options_x_valueChanged(int x) { void RegionMapEditor::on_spinBox_RM_Options_x_valueChanged(int x) {
int y = this->ui->spinBox_RM_Options_y->value(); int y = this->ui->spinBox_RM_Options_y->value();
int red = this->region_map->getMapSquareIndex(x + 1, y + 2); 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->region_map_layout_item->highlight(x, y, red);
} }
void RegionMapEditor::on_spinBox_RM_Options_y_valueChanged(int y) { void RegionMapEditor::on_spinBox_RM_Options_y_valueChanged(int y) {
int x = this->ui->spinBox_RM_Options_x->value(); int x = this->ui->spinBox_RM_Options_x->value();
int red = this->region_map->getMapSquareIndex(x + 1, y + 2); 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->region_map_layout_item->highlight(x, y, red);
} }
void RegionMapEditor::on_pushButton_RM_Options_save_clicked() { void RegionMapEditor::on_pushButton_RM_Options_save_clicked() {
this->region_map->saveOptions( this->region_map->saveOptions(
this->region_map_layout_item->selectedTile,// TODO: remove this->region_map_layout_item->selectedTile,
this->ui->comboBox_RM_ConnectedMap->currentText(), this->ui->comboBox_RM_ConnectedMap->currentText(),
this->ui->lineEdit_RM_MapName->text(), this->ui->lineEdit_RM_MapName->text(),
this->ui->spinBox_RM_Options_x->value(), this->ui->spinBox_RM_Options_x->value(),
@ -356,7 +382,6 @@ void RegionMapEditor::on_pushButton_RM_Options_save_clicked() {
); );
this->region_map_layout_item->highlightedTile = -1; this->region_map_layout_item->highlightedTile = -1;
this->region_map_layout_item->draw(); this->region_map_layout_item->draw();
// TODO: update selected tile index
} }
void RegionMapEditor::on_pushButton_CityMap_save_clicked() { void RegionMapEditor::on_pushButton_CityMap_save_clicked() {
@ -407,7 +432,7 @@ void RegionMapEditor::on_action_RegionMap_Resize_triggered() {
QSpinBox *heightSpinBox = new QSpinBox(); QSpinBox *heightSpinBox = new QSpinBox();
widthSpinBox->setMinimum(32); widthSpinBox->setMinimum(32);
heightSpinBox->setMinimum(20); heightSpinBox->setMinimum(20);
widthSpinBox->setMaximum(64);// TODO: come up with real (meaningful) limits? widthSpinBox->setMaximum(60);// w * h * 2 <= 4960
heightSpinBox->setMaximum(40); heightSpinBox->setMaximum(40);
widthSpinBox->setValue(this->region_map->width()); widthSpinBox->setValue(this->region_map->width());
heightSpinBox->setValue(this->region_map->height()); heightSpinBox->setValue(this->region_map->height());
@ -520,22 +545,20 @@ void RegionMapEditor::on_pushButton_Zoom_Out_City_Tiles_clicked() {
void RegionMapEditor::on_pushButton_Zoom_In_City_Map_clicked() { void RegionMapEditor::on_pushButton_Zoom_In_City_Map_clicked() {
if (scaleCityMapImage >= 8.0) return; if (scaleCityMapImage >= 8.0) return;
scaleCityMapImage *= 2.0; scaleCityMapImage *= 2.0;
this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width * scaleCityMapImage + 2, this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width() * scaleCityMapImage + 2,
8 * city_map_item->height * scaleCityMapImage + 2); 8 * city_map_item->height() * scaleCityMapImage + 2);
this->ui->graphicsView_City_Map->scale(2.0,2.0); this->ui->graphicsView_City_Map->scale(2.0,2.0);
} }
void RegionMapEditor::on_pushButton_Zoom_Out_City_Map_clicked() { void RegionMapEditor::on_pushButton_Zoom_Out_City_Map_clicked() {
if (scaleCityMapImage <= 1.0) return; if (scaleCityMapImage <= 1.0) return;
scaleCityMapImage /= 2.0; scaleCityMapImage /= 2.0;
this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width * scaleCityMapImage + 2, this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width() * scaleCityMapImage + 2,
8 * city_map_item->height * scaleCityMapImage + 2); 8 * city_map_item->height() * scaleCityMapImage + 2);
this->ui->graphicsView_City_Map->scale(0.5,0.5); this->ui->graphicsView_City_Map->scale(0.5,0.5);
} }
void RegionMapEditor::on_pushButton_Zoom_In_Map_Image_clicked() { void RegionMapEditor::on_pushButton_Zoom_In_Map_Image_clicked() {
resize(40,30);// test
return;
if (scaleRegionMapImage >= 8.0) return; if (scaleRegionMapImage >= 8.0) return;
scaleRegionMapImage *= 2.0; scaleRegionMapImage *= 2.0;
this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage); this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage);
@ -552,3 +575,9 @@ void RegionMapEditor::on_pushButton_Zoom_Out_Map_Image_clicked() {
this->ui->graphicsView_Region_Map_BkgImg->scale(0.5,0.5); this->ui->graphicsView_Region_Map_BkgImg->scale(0.5,0.5);
this->ui->graphicsView_Region_Map_Layout->scale(0.5,0.5); this->ui->graphicsView_Region_Map_Layout->scale(0.5,0.5);
} }
void RegionMapEditor::on_action_RegionMap_Generate_triggered() {
//
RegionMapGenerator generator(this->project);
generator.generate("LittlerootTown");
}

View file

@ -56,11 +56,9 @@ void RegionMapLayoutPixmapItem::select(int index) {
} }
void RegionMapLayoutPixmapItem::highlight(int x, int y, int red) { void RegionMapLayoutPixmapItem::highlight(int x, int y, int red) {
// TODO: check if out of bounds and return
// if it is not empty, color it red
this->highlightedTile = red; this->highlightedTile = red;
draw(); draw();
SelectablePixmapItem::select(x + 1, y + 2, 0, 0); SelectablePixmapItem::select(x + this->region_map->padLeft, y + this->region_map->padTop, 0, 0);
} }
void RegionMapLayoutPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { void RegionMapLayoutPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
@ -68,7 +66,6 @@ void RegionMapLayoutPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
int index = this->region_map->getMapSquareIndex(pos.x(), pos.y()); int index = this->region_map->getMapSquareIndex(pos.x(), pos.y());
if (this->region_map->map_squares[index].x >= 0 if (this->region_map->map_squares[index].x >= 0
&& this->region_map->map_squares[index].y >= 0) { && this->region_map->map_squares[index].y >= 0) {
//if (index > this->region_map->width() * 2) {
SelectablePixmapItem::mousePressEvent(event); SelectablePixmapItem::mousePressEvent(event);
this->updateSelectedTile(); this->updateSelectedTile();
emit selectedTileChanged(this->selectedTile); emit selectedTileChanged(this->selectedTile);
@ -99,4 +96,6 @@ void RegionMapLayoutPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
void RegionMapLayoutPixmapItem::updateSelectedTile() { void RegionMapLayoutPixmapItem::updateSelectedTile() {
QPoint origin = this->getSelectionStart(); QPoint origin = this->getSelectionStart();
this->selectedTile = this->region_map->getMapSquareIndex(origin.x(), origin.y()); this->selectedTile = this->region_map->getMapSquareIndex(origin.x(), origin.y());
this->highlightedTile = -1;
draw();
} }

View file

@ -3,10 +3,6 @@
// the function that draws the map on the scene
// (qnqlogous to Map::render)
// TODO: figure out why this is being called twice!!
// (this also affects the history)
void RegionMapPixmapItem::draw() { void RegionMapPixmapItem::draw() {
if (!region_map) return; if (!region_map) return;