diff --git a/forms/regionmapeditor.ui b/forms/regionmapeditor.ui index 932a8d0d..19a8f45c 100644 --- a/forms/regionmapeditor.ui +++ b/forms/regionmapeditor.ui @@ -17,7 +17,7 @@ - 10 + 30 250 20 20 @@ -30,7 +30,7 @@ - 30 + 10 250 20 20 @@ -358,7 +358,7 @@ - 10 + 30 550 20 20 @@ -377,7 +377,7 @@ - 30 + 10 550 20 20 @@ -396,7 +396,7 @@ - 681 + 661 550 20 20 @@ -415,7 +415,7 @@ - 661 + 681 550 20 20 @@ -434,7 +434,7 @@ - 661 + 681 250 20 20 @@ -447,7 +447,7 @@ - 681 + 661 250 20 20 @@ -457,7 +457,7 @@ - - + 10 @@ -727,7 +727,7 @@ - 1 + 0 @@ -1029,6 +1029,7 @@ + @@ -1058,6 +1059,14 @@ Ctrl+Y + + + Resize + + + Ctrl+R + + diff --git a/include/core/regionmap.h b/include/core/regionmap.h index 7584a41d..733c8462 100644 --- a/include/core/regionmap.h +++ b/include/core/regionmap.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -16,91 +17,75 @@ -// rename this struct? struct CityMapPosition { - // - //QString filename; // eg. dewford_0 ? - QString tilemap;// eg. "dewford_0" + QString tilemap; int x; int y; }; struct RegionMapEntry { - // int x; int y; int width; int height; - QString name;// mapsection + QString name; }; -// class that holds data for each square in this project -// struct? -// TODO: change char / uint8_t to unsigned class RegionMapSquare { public: - // - int x = -1;// x position, 0-indexed from top left - int y = -1;// y position, 0-indexed from top left - uint8_t tile_img_id;// tilemap ids for the background image - bool has_map = false;// whether this square is linked to a map or is empty - QString map_name;// name of the map associated with this square (if has_map is true): eg. "MAUVILLE_CITY" (TODO: REMOVE) + int x = -1; + int y = -1; + uint8_t tile_img_id; + bool has_map = false; + QString map_name; QString mapsec; uint8_t secid; - bool has_city_map = false;// whether there is a city map on this grid - QString city_map_name;// filename of the city_map tilemap - //bool is_flyable;//? needed ? - friend class RegionMap;// not necessary if instance? what + bool has_city_map = false; + QString city_map_name; + bool duplicated = false; }; class RegionMap : public QObject { Q_OBJECT -//public: -// explicit Map(QObject *parent = nullptr); public: RegionMap() = default; ~RegionMap() {}; - static QMap> ruby_city_maps_; static QString mapSecToMapConstant(QString); Project *project; - //RegionMapSquare *map_squares = nullptr;// array of RegionMapSquares - QList map_squares; + //QList map_squares; + QVector map_squares; History history; - QString temp_path;// delete this - QString city_map_squares_path; QString region_map_png_path; - QString region_map_bin_path;// = QString::null; - QString city_map_header_path;//dafuq is this? - QString region_map_layout_path; + QString region_map_bin_path; QString region_map_entries_path; QString region_map_layout_bin_path; - QString region_map_city_map_tiles_path; + QString city_map_tiles_path; QByteArray mapBinData; - QMap sMapNames;// {"{/sMapName_/}LittlerootTown" : "LITTLEROOT{NAME_END} TOWN"} + QMap sMapNamesMap;// {"{/sMapName_/}LittlerootTown" : "LITTLEROOT{NAME_END} TOWN"} QMap mapSecToMapName;// {"MAPSEC_LITTLEROOT_TOWN" : "LITTLEROOT{NAME_END} TOWN"} - //QList> mapSecToMapEntry; QMap mapSecToMapEntry;// TODO: add to this on creation of new map + QVector sMapNames; + bool hasUnsavedChanges(); - void init(Project*);//QString); + void init(Project*); - // parseutil.cpp ? void readBkgImgBin(); - void readCityMaps();// more complicated + void readCityMaps(); void readLayout(); QString newAbbr(QString);// makes a *unique* 5 character abbreviation from mapname to add to mapname_abbr @@ -119,7 +104,6 @@ public: void saveOptions(int, QString, QString, int, int); void saveCityMaps(); - void update();// update the view in case something is broken? void resize(int, int); void setWidth(int); void setHeight(int); @@ -129,18 +113,12 @@ public: unsigned getTileId(int, int); int getMapSquareIndex(int, int); - void deleteLayoutSquare(int); + void resetSquare(int); - // implement these here? - void undo(); - void redo(); - - void test();// remove when done testing obvi + void test();// remove // TODO: move read / write functions to private (and others) private: - // - //History> *history;// (index, tile) int layout_width_; int layout_height_; int img_width_; @@ -150,13 +128,6 @@ private: void fillMapSquaresFromLayout(); QString fix_case(QString);// CAPS_WITH_UNDERSCORE to CamelCase -//protected: - // - -//signals: - // }; -//TilemapTileSelector *city_map_metatile_selector_item = nullptr; - #endif // REGIONMAP_H diff --git a/include/ui/regionmapeditor.h b/include/ui/regionmapeditor.h index ffc2bd3d..e41abd13 100644 --- a/include/ui/regionmapeditor.h +++ b/include/ui/regionmapeditor.h @@ -24,32 +24,11 @@ public: explicit RegionMapEditor(QWidget *parent = 0, Project *pro = nullptr); ~RegionMapEditor(); -// TODO: make members that are not called outside of this private RegionMap *region_map; - QGraphicsScene *scene_region_map_image = nullptr; - QGraphicsScene *scene_city_map_image = nullptr; - QGraphicsScene *scene_region_map_layout = nullptr; - QGraphicsScene *scene_region_map_tiles = nullptr; - QGraphicsScene *scene_city_map_tiles = nullptr; - TilemapTileSelector *mapsquare_selector_item = nullptr; - TilemapTileSelector *city_map_selector_item = nullptr; - RegionMapPixmapItem *region_map_item = nullptr; - CityMapPixmapItem *city_map_item = nullptr; - RegionMapLayoutPixmapItem *region_map_layout_item = nullptr; - void loadRegionMapData(); - void displayRegionMap(); - void displayRegionMapImage(); - void displayRegionMapLayout(); - void displayRegionMapLayoutOptions(); - void updateRegionMapLayoutOptions(int); - void displayRegionMapTileSelector(); - void displayCityMapTileSelector(); - void displayCityMap(QString); void loadCityMaps(); - void onRegionMapTileSelectorSelectedTileChanged(); void onRegionMapTileSelectorHoveredTileChanged(unsigned); void onRegionMapTileSelectorHoveredTileCleared(); @@ -60,14 +39,17 @@ public: void undo(); void redo(); + void resize(int, int); + private: Ui::RegionMapEditor *ui; Project *project; - QString rmStatusbarMessage; History history; - double scaleUpFactor = 2.0; + int currIndex = 65;// TODO: automatic this from width * 2 + 1 + + double scaleUpFactor = 2.0;// TODO double scaleDownFactor = 1.0 / scaleUpFactor; double scaleRegionMapTiles = 1.0; @@ -75,7 +57,27 @@ private: double scaleCityMapTiles = 1.0; double scaleCityMapImage = 1.0; - void scaleUp(QGraphicsView *, qreal factor, qreal width, qreal height); + QGraphicsScene *scene_region_map_image = nullptr; + QGraphicsScene *scene_city_map_image = nullptr; + QGraphicsScene *scene_region_map_layout = nullptr; + QGraphicsScene *scene_region_map_tiles = nullptr; + QGraphicsScene *scene_city_map_tiles = nullptr; + + TilemapTileSelector *mapsquare_selector_item = nullptr; + TilemapTileSelector *city_map_selector_item = nullptr; + + RegionMapLayoutPixmapItem *region_map_layout_item = nullptr; + RegionMapPixmapItem *region_map_item = nullptr; + CityMapPixmapItem *city_map_item = nullptr; + + void displayRegionMap(); + void displayRegionMapImage(); + void displayRegionMapLayout(); + void displayRegionMapLayoutOptions(); + void updateRegionMapLayoutOptions(int); + void displayRegionMapTileSelector(); + void displayCityMapTileSelector(); + void displayCityMap(QString); bool createCityMap(QString); @@ -83,20 +85,23 @@ private slots: void on_action_RegionMap_Save_triggered(); void on_action_RegionMap_Undo_triggered(); void on_action_RegionMap_Redo_triggered(); + void on_action_RegionMap_Resize_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_pushButton_CityMap_add_clicked();// + 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_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_pushButton_Zoom_Out_Map_Image_clicked(); 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 onHoveredRegionMapTileChanged(int, int); void onHoveredRegionMapTileCleared(); void mouseEvent_region_map(QGraphicsSceneMouseEvent *, RegionMapPixmapItem *); diff --git a/include/ui/regionmaplayoutpixmapitem.h b/include/ui/regionmaplayoutpixmapitem.h index 8031f475..f3d2a258 100644 --- a/include/ui/regionmaplayoutpixmapitem.h +++ b/include/ui/regionmaplayoutpixmapitem.h @@ -8,22 +8,22 @@ class RegionMapLayoutPixmapItem : public SelectablePixmapItem { Q_OBJECT public: RegionMapLayoutPixmapItem(RegionMap *rmap, TilemapTileSelector *ts) : SelectablePixmapItem(8, 8, 1, 1) { - // this->region_map = rmap; this->tile_selector = ts; setAcceptHoverEvents(true); } - RegionMap *region_map;// inherited from RegionMapPixmapItem? + RegionMap *region_map; TilemapTileSelector *tile_selector; - int selectedTile;// index in map_squares + int selectedTile; + int highlightedTile; void draw(); void select(int, int); - void setDefaultSelection(); + void select(int); + void highlight(int, int, int); private: void updateSelectedTile(); -// can I implement these if they are virtual? signals: void mouseEvent(QGraphicsSceneMouseEvent *, RegionMapLayoutPixmapItem *); void hoveredTileChanged(int); diff --git a/src/core/regionmap.cpp b/src/core/regionmap.cpp index 061f1550..bc70d329 100644 --- a/src/core/regionmap.cpp +++ b/src/core/regionmap.cpp @@ -1,117 +1,41 @@ #include "regionmap.h" +#include "log.h" #include #include #include #include - #include -// TODO: add logging / config stuff - -// IN: ROUTE_101 ... OUT: MAP_ROUTE101 -// eg. SOUTHERN_ISLAND -> MAP_SOUTHERN_ISLAND -> SouthernIsland(n) -> SouthernIsland_Exterior -// MT_CHIMNEY -> MAP_MT_CHIMNEY -> MtChimney(y) -// ROUTE_101 -> MAP_ROUTE101 -> Route101(y) -// TODO: move this maybe? would I be able to call it from this file if it was in map.cpp? -QString RegionMap::mapSecToMapConstant(QString mapSectionName) { - // - QString mapConstantName = "MAP_"; - QString sectionNameTemp = mapSectionName.replace("ROUTE_","ROUTE"); - mapConstantName += sectionNameTemp; - return mapConstantName; -} - -// TODO: verify these are in the correct order -// also TODO: read this from the project somehow -QMap> RegionMap::ruby_city_maps_ = QMap>({ - {"LavaridgeTown", { - {"lavaridge_0.bin", 5, 3}, - }}, - {"FallarborTown", { - {"fallarbor_0.bin", 3, 0}, - }}, - {"FortreeCity", { - {"fortree_0.bin", 12, 0}, - }}, - {"SlateportCity", { - {"slateport_0.bin", 8, 10}, - {"slateport_1.bin", 8, 11}, - }}, - {"RustboroCity", { - {"rustboro_0.bin", 0, 5}, - {"rustboro_1.bin", 0, 6}, - }}, - {"PacifidlogTown", { - {"pacifidlog_0.bin", 17, 10}, - }}, - {"MauvilleCity", { - {"mauville_0.bin", 8, 6}, - {"mauville_1.bin", 9, 6}, - }}, - {"OldaleTown", { - {"oldale_0.bin", 4, 9}, - }}, - {"LilycoveCity", { - {"lilycove_0.bin", 18, 3}, - {"lilycove_1.bin", 19, 3}, - }}, - {"LittlerootTown", { - {"littleroot_0.bin", 4, 11}, - }}, - {"DewfordTown", { - {"dewford_0.bin", 2, 14}, - }}, - {"SootopolisCity", { - {"sootopolis_0.bin", 21, 7}, - }}, - {"EverGrandeCity", { - {"ever_grande_0.bin", 27, 8}, - {"ever_grande_1.bin", 27, 9}, - }}, - {"VerdanturfTown", { - {"verdanturf_0.bin", 4, 6}, - }}, - {"MossdeepCity", { - {"mossdeep_0.bin", 24, 5}, - {"mossdeep_1.bin", 25, 5}, - }}, - {"PetalburgCity", { - {"petalburg_0.bin", 1, 9}, - }}, -}); - // TODO: add version arg to this from Editor Setings void RegionMap::init(Project *pro) { QString path = pro->root; this->project = pro; - // + // TODO: in the future, allow these to be adjustable (and save values) - // possibly use a config file? - layout_width_ = 28; - layout_height_ = 15; + // possibly use a config file? save to include/constants/region_map.h? + layout_width_ = 36;//28; + layout_height_ = 25;//15; img_width_ = layout_width_ + 4; img_height_ = layout_height_ + 5; - //city_map_squares_path = QString(); - temp_path = path;// delete this - region_map_bin_path = path + "/graphics/pokenav/region_map_map.bin"; - region_map_png_path = path + "/graphics/pokenav/region_map.png"; - region_map_layout_path = path + "/src/data/region_map_layout.h"; - region_map_entries_path = path + "/src/data/region_map/region_map_entries.h"; + region_map_bin_path = path + "/graphics/pokenav/region_map_map.bin"; + 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_layout_bin_path = path + "/graphics/pokenav/region_map_section_layout.bin"; - region_map_city_map_tiles_path = path + "/graphics/pokenav/zoom_tiles.png";// TODO: rename png to map_squares in pokeemerald + city_map_tiles_path = path + "/graphics/pokenav/zoom_tiles.png"; + // TODO: rename png to map_squares in pokeemerald readBkgImgBin(); readLayout(); readCityMaps(); + + //resize(40,30); } -// as of now, this needs to be called first because it initializes all the -// `RegionMapSquare`s in the list // TODO: if the tileId is not valid for the provided image, make sure it does not crash void RegionMap::readBkgImgBin() { QFile binFile(region_map_bin_path); @@ -120,12 +44,13 @@ void RegionMap::readBkgImgBin() { QByteArray mapBinData = binFile.readAll(); binFile.close(); - // the two multiplier is because lines are skipped for some reason - // (maybe that is because there could be multiple layers?) - // background image is also 32x20 + if (mapBinData.size() < img_height_ * img_width_) { + logError(QString("The region map tilemap at %1 is too small.").arg(region_map_bin_path)); + return; + } for (int m = 0; m < img_height_; m++) { for (int n = 0; n < img_width_; n++) { - RegionMapSquare square;// = + RegionMapSquare square; square.tile_img_id = mapBinData.at(n + m * img_width_ * 2); map_squares.append(square); } @@ -155,7 +80,7 @@ void RegionMap::readLayout() { QString line; // TODO: put these in Project, and keep in order - //QMap sMapNames;// {"sMapName_LittlerootTown" : "LITTLEROOT{NAME_END} TOWN"} + //QMap sMapNamesMap;// {"sMapName_LittlerootTown" : "LITTLEROOT{NAME_END} TOWN"} //QMap mapSecToMapName;// {"MAPSEC_LITTLEROOT_TOWN" : "LITTLEROOT{NAME_END} TOWN"} //QList<> mapSecToMapEntry;// {"MAPSEC_LITTLEROOT_TOWN" : } @@ -170,14 +95,15 @@ void RegionMap::readLayout() { QRegularExpression reAfter("_\\(\"(.*)\""); QString const_name = reBefore.match(line).captured(1); QString full_name = reAfter.match(line).captured(1); - sMapNames.insert(const_name, full_name); + sMapNames.append(const_name); + sMapNamesMap.insert(const_name, full_name); } else if (line.contains("MAPSEC")) { QRegularExpression reBefore("\\[(.*)\\]"); QRegularExpression reAfter("{(.*)}"); QStringList entry = reAfter.match(line).captured(1).remove(" ").split(","); QString mapsec = reBefore.match(line).captured(1); QString insertion = entry[4].remove("sMapName_"); - qmap->insert(mapsec, sMapNames[insertion]); + qmap->insert(mapsec, sMapNamesMap[insertion]); // can make this a map, the order doesn't really matter mapSecToMapEntry[mapsec] = // x y width height name @@ -191,7 +117,9 @@ void RegionMap::readLayout() { } file.close(); - project->mapSecToMapHoverName = qmap; + //qDebug() << "sMapNames" << sMapNames; + + project->mapSecToMapHoverName = qmap;// TODO: is this map necessary? QFile binFile(region_map_layout_bin_path); if (!binFile.open(QIODevice::ReadOnly)) return; @@ -206,18 +134,13 @@ void RegionMap::readLayout() { QString secname = (*(project->regionMapSections))[static_cast(mapBinData.at(layout_index_(n,m)))]; if (secname != "MAPSEC_NONE") map_squares[i].has_map = true; map_squares[i].mapsec = secname; - map_squares[i].map_name = sMapNames.value(mapSecToMapEntry.value(secname).name); + map_squares[i].map_name = sMapNamesMap.value(mapSecToMapEntry.value(secname).name);// TODO: this is atrocious map_squares[i].x = n; map_squares[i].y = m; } } } -/// saves: -// region_map_entries_path -// region_map_layout_bin_path (layout as tilemap instead of how it is in ruby) -// done -// TODO: consider keeping QMaps in order void RegionMap::saveLayout() { QString entries_text; QString layout_text; @@ -225,9 +148,8 @@ void RegionMap::saveLayout() { entries_text += "#ifndef GUARD_DATA_REGION_MAP_REGION_MAP_ENTRIES_H\n"; entries_text += "#define GUARD_DATA_REGION_MAP_REGION_MAP_ENTRIES_H\n\n"; - // note: this doesn't necessarily keep order because it is a QMap - for (auto it : this->project->mapSecToMapHoverName->keys()) { - entries_text += "static const u8 sMapName_" + fix_case(it) + "[] = _(\"" + this->project->mapSecToMapHoverName->value(it) + "\");\n"; + for (auto sName : sMapNames) { + entries_text += "static const u8 sMapName_" + sName + "[] = _(\"" + sMapNamesMap.value(sName) + "\");\n"; } entries_text += "\nconst struct RegionMapLocation gRegionMapEntries[] = {\n"; @@ -235,7 +157,7 @@ void RegionMap::saveLayout() { for (auto sec : mapSecToMapEntry.keys()) { struct RegionMapEntry entry = mapSecToMapEntry.value(sec); entries_text += " [" + sec + "] = {" + QString::number(entry.x) + ", " + QString::number(entry.y) + ", " - + QString::number(entry.width) + ", " + QString::number(entry.height) + ", sMapName_" + fix_case(sec) + "},\n";//entry.name + + QString::number(entry.width) + ", " + QString::number(entry.height) + ", sMapName_" + entry.name + "},\n"; } entries_text += "};\n\n#endif // GUARD_DATA_REGION_MAP_REGION_MAP_ENTRIES_H\n"; @@ -254,29 +176,7 @@ void RegionMap::saveLayout() { bfile.close(); } -// beyond broken -void RegionMap::readCityMaps() { - // - for (int map = 0; map < map_squares.size(); map++) { - // - if (map_squares[map].has_map) { - // - if (ruby_city_maps_.contains(map_squares[map].map_name)) { - //map_squares[map].has_city_map = true; - //map_squares[map].city_map_name = ruby_city_maps_.value(map_squares[map].map_name)[0].tilemap; - QList city_maps = ruby_city_maps_.value(map_squares[map].map_name); - for (auto city_map : city_maps) { - // - if (city_map.x == map_squares[map].x - && city_map.y == map_squares[map].y) - // - map_squares[map].has_city_map = true; - map_squares[map].city_map_name = city_map.tilemap; - } - } - } - } -} +void RegionMap::readCityMaps() {} // layout coords to image index int RegionMap::img_index_(int x, int y) { @@ -316,53 +216,53 @@ int RegionMap::height() { return this->img_height_; } -// TODO: remove +2 and put elsewhere QSize RegionMap::imgSize() { return QSize(img_width_ * 8 + 2, img_height_ * 8 + 2); } // TODO: rename to getTileIdAt()? unsigned RegionMap::getTileId(int x, int y) { - // return map_squares[x + y * img_width_].tile_img_id; } -// TODO: change debugs to logs void RegionMap::save() { - // - qDebug() << "saving region map image tilemap at" << region_map_bin_path << "\n" - << "saving region map layout at" << region_map_layout_path << "\n" - ; - + logInfo("Saving region map info."); saveBkgImgBin(); saveLayout(); + // TODO: re-select proper tile + // TODO: add region map dimensions to config } -// save Options (temp) -void RegionMap::saveOptions(int index, QString sec, QString name, int x, int y) { - // - // TODO:req need to reindex in city_maps if changing x and y - // TODO: save [sec] sMapName_ properly - // so instead of taking index, maybe go by img_index_(x,y) +void RegionMap::saveOptions(int id, QString sec, QString name, int x, int y) { + int index = getMapSquareIndex(x + 1, y + 2); if (!sec.isEmpty()) { this->map_squares[index].has_map = true; this->map_squares[index].secid = static_cast(project->regionMapSections->indexOf(sec)); + this->map_squares[index].mapsec = sec; + if (!name.isEmpty()) { + this->map_squares[index].map_name = name; + this->project->mapSecToMapHoverName->insert(sec, name); + if (!mapSecToMapEntry.keys().contains(sec)) { + QString sName = fix_case(sec); + sMapNames.append(sName); + sMapNamesMap.insert(sName, name); + struct RegionMapEntry entry = {x, y, 1, 1, sName};// TODO: change width, height? + mapSecToMapEntry.insert(sec, entry); + } + } + this->map_squares[index].x = x; + this->map_squares[index].y = y; + this->map_squares[index].duplicated = false; } - this->map_squares[index].mapsec = sec; - if (!name.isEmpty()) { - this->map_squares[index].map_name = name;// TODO: display in editor with this map & remove this field - this->project->mapSecToMapHoverName->insert(sec, name); - } - this->map_squares[index].x = x; - this->map_squares[index].y = y; + resetSquare(id); } // from x, y of image -// TODO: make sure this returns a valid index int RegionMap::getMapSquareIndex(int x, int y) { // int index = (x + y * img_width_); - return index < map_squares.length() - 1 ? index : 0; + //qDebug() << "index:" << index; + return index < map_squares.length() ? index : 0; } // For turning a MAPSEC_NAME into a unique identifier sMapName-style variable. @@ -384,9 +284,44 @@ QString RegionMap::fix_case(QString caps) { return camel; } - - - +void RegionMap::resetSquare(int index) { + this->map_squares[index].mapsec = "MAPSEC_NONE"; + this->map_squares[index].map_name = QString(); + this->map_squares[index].has_map = false; + this->map_squares[index].secid = static_cast(project->regionMapSections->indexOf("MAPSEC_NONE")); + this->map_squares[index].has_city_map = false; + this->map_squares[index].city_map_name = QString(); + this->map_squares[index].duplicated = false; + logInfo(QString("Reset map square at (%1, %2).").arg(this->map_squares[index].x).arg(this->map_squares[index].y)); +} + +void RegionMap::resize(int newWidth, int newHeight) { + // + QVector new_squares; + + for (int y = 0; y < newHeight; y++) { + for (int x = 0; x < newWidth; x++) { + RegionMapSquare square; + if (x < img_width_ && y < img_height_) { + square = map_squares[getMapSquareIndex(x, y)]; + } else if (x < newWidth - 3 && y < newHeight - 3) { + square.tile_img_id = 0; + square.x = x; + square.y = y; + square.mapsec = "MAPSEC_NONE"; + } else { + square.tile_img_id = 0; + } + new_squares.append(square); + } + } + + this->map_squares = new_squares; + this->img_width_ = newWidth; + this->img_height_ = newHeight; + this->layout_width_ = newWidth - 4; + this->layout_height_ = newHeight - 5; +} diff --git a/src/ui/regionmapeditor.cpp b/src/ui/regionmapeditor.cpp index 2f0303fa..bde1e97e 100644 --- a/src/ui/regionmapeditor.cpp +++ b/src/ui/regionmapeditor.cpp @@ -7,7 +7,6 @@ #include #include #include -#include RegionMapEditor::RegionMapEditor(QWidget *parent, Project *pro) : QMainWindow(parent), @@ -16,34 +15,39 @@ RegionMapEditor::RegionMapEditor(QWidget *parent, Project *pro) : this->ui->setupUi(this); this->project = pro; this->region_map = new RegionMap; - this->setFixedSize(this->size());//statusbar->setSizeGripEnabled(false); + this->setFixedSize(this->size()); } RegionMapEditor::~RegionMapEditor() { delete ui; + delete region_map; + delete region_map_item; + delete mapsquare_selector_item; + delete region_map_layout_item; + delete scene_region_map_image; + delete city_map_selector_item; + delete city_map_item; + delete scene_city_map_tiles; + delete scene_city_map_image; + delete scene_region_map_layout; + delete scene_region_map_tiles; } - - void RegionMapEditor::on_action_RegionMap_Save_triggered() { - qDebug() << "Region Map Save Triggered"; if (project && region_map) { - qDebug() << "actually saving"; region_map->save(); displayRegionMap(); } } - void RegionMapEditor::loadRegionMapData() { - // this->region_map->init(project); + this->currIndex = this->region_map->width() * 2 + 1; displayRegionMap(); } void RegionMapEditor::loadCityMaps() { - // QDir directory(project->root + "/graphics/pokenav/city_maps"); QStringList files = directory.entryList(QStringList() << "*.bin", QDir::Files); QStringList without_bin; @@ -61,115 +65,134 @@ void RegionMapEditor::displayRegionMap() { displayRegionMapLayoutOptions(); } -// TODO: change the signal slot to new syntax -// TODO: add scalability? void RegionMapEditor::displayRegionMapImage() { - // + if (!scene_region_map_image) { + this->scene_region_map_image = new QGraphicsScene; + } + if (region_map_item && scene_region_map_image) { + scene_region_map_image->removeItem(region_map_item); + delete region_map_item; + } + this->region_map_item = new RegionMapPixmapItem(this->region_map, this->mapsquare_selector_item); - connect(region_map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*, RegionMapPixmapItem*)), - this, SLOT(mouseEvent_region_map(QGraphicsSceneMouseEvent*, RegionMapPixmapItem*))); - connect(region_map_item, SIGNAL(hoveredRegionMapTileChanged(int, int)), - this, SLOT(onHoveredRegionMapTileChanged(int, int))); - connect(region_map_item, SIGNAL(hoveredRegionMapTileCleared()), - this, SLOT(onHoveredRegionMapTileCleared())); this->region_map_item->draw(); - this->scene_region_map_image = new QGraphicsScene; + connect(this->region_map_item, &RegionMapPixmapItem::mouseEvent, + this, &RegionMapEditor::mouseEvent_region_map); + connect(this->region_map_item, &RegionMapPixmapItem::hoveredRegionMapTileChanged, + this, &RegionMapEditor::onHoveredRegionMapTileChanged); + connect(this->region_map_item, &RegionMapPixmapItem::hoveredRegionMapTileCleared, + this, &RegionMapEditor::onHoveredRegionMapTileCleared); + 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->sceneRect()); this->ui->graphicsView_Region_Map_BkgImg->setScene(this->scene_region_map_image); - this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize()); + this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage); } -// TODO: add if (item) and if(scene) checks because called more than once per instance void RegionMapEditor::displayRegionMapLayout() { - // + if (!scene_region_map_layout) { + this->scene_region_map_layout = new QGraphicsScene; + } + if (region_map_layout_item && scene_region_map_layout) { + this->scene_region_map_layout->removeItem(region_map_layout_item); + delete region_map_layout_item; + } + this->region_map_layout_item = new RegionMapLayoutPixmapItem(this->region_map, this->mapsquare_selector_item); - //* + connect(this->region_map_layout_item, &RegionMapLayoutPixmapItem::selectedTileChanged, - this, &RegionMapEditor::onRegionMapLayoutSelectedTileChanged);// TODO: remove this? + this, &RegionMapEditor::onRegionMapLayoutSelectedTileChanged); connect(this->region_map_layout_item, &RegionMapLayoutPixmapItem::hoveredTileChanged, this, &RegionMapEditor::onRegionMapLayoutHoveredTileChanged); connect(this->region_map_layout_item, &RegionMapLayoutPixmapItem::hoveredTileCleared, this, &RegionMapEditor::onRegionMapLayoutHoveredTileCleared); - //*/ - this->region_map_layout_item->draw(); - this->region_map_layout_item->setDefaultSelection(); - this->scene_region_map_layout = new QGraphicsScene; + this->region_map_layout_item->draw(); + this->region_map_layout_item->select(this->currIndex); + 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->sceneRect()); this->ui->graphicsView_Region_Map_Layout->setScene(this->scene_region_map_layout); - this->ui->graphicsView_Region_Map_Layout->setFixedSize(this->region_map->imgSize()); + this->ui->graphicsView_Region_Map_Layout->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage); } void RegionMapEditor::displayRegionMapLayoutOptions() { - // this->ui->comboBox_RM_ConnectedMap->addItems(*(this->project->regionMapSections)); this->ui->frame_RM_Options->setEnabled(true); // TODO: change these values to variables - this->ui->spinBox_RM_Options_x->setMaximum(27); - this->ui->spinBox_RM_Options_y->setMaximum(14); + this->ui->spinBox_RM_Options_x->setMaximum(this->region_map->width() - 5); + this->ui->spinBox_RM_Options_y->setMaximum(this->region_map->height() - 4); - updateRegionMapLayoutOptions(65); + updateRegionMapLayoutOptions(currIndex); } void RegionMapEditor::updateRegionMapLayoutOptions(int index) { - // + this->ui->spinBox_RM_Options_x->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->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); } -// TODO: get this to display on a decent scale void RegionMapEditor::displayRegionMapTileSelector() { - // + if (!scene_region_map_tiles) { + this->scene_region_map_tiles = new QGraphicsScene; + } + if (mapsquare_selector_item && scene_region_map_tiles) { + this->scene_region_map_tiles->removeItem(mapsquare_selector_item); + delete mapsquare_selector_item; + } + this->mapsquare_selector_item = new TilemapTileSelector(QPixmap(this->region_map->region_map_png_path)); this->mapsquare_selector_item->draw(); - this->scene_region_map_tiles = new QGraphicsScene; this->scene_region_map_tiles->addItem(this->mapsquare_selector_item); - connect(this->mapsquare_selector_item, &TilemapTileSelector::selectedTileChanged, - this, &RegionMapEditor::onRegionMapTileSelectorSelectedTileChanged);// TODO: remove this? connect(this->mapsquare_selector_item, &TilemapTileSelector::hoveredTileChanged, this, &RegionMapEditor::onRegionMapTileSelectorHoveredTileChanged); connect(this->mapsquare_selector_item, &TilemapTileSelector::hoveredTileCleared, this, &RegionMapEditor::onRegionMapTileSelectorHoveredTileCleared); this->ui->graphicsView_RegionMap_Tiles->setScene(this->scene_region_map_tiles); - this->ui->graphicsView_RegionMap_Tiles->setFixedSize(this->mapsquare_selector_item->pixelWidth + 2, - this->mapsquare_selector_item->pixelHeight + 2); + this->ui->graphicsView_RegionMap_Tiles->setFixedSize(this->mapsquare_selector_item->pixelWidth * scaleRegionMapTiles + 2, + this->mapsquare_selector_item->pixelHeight * scaleRegionMapTiles + 2); } void RegionMapEditor::displayCityMapTileSelector() { - // city_map_selector_item - this->city_map_selector_item = new TilemapTileSelector(QPixmap(this->region_map->region_map_city_map_tiles_path)); + if (!scene_city_map_tiles) { + this->scene_city_map_tiles = new QGraphicsScene; + } + if (city_map_selector_item && scene_city_map_tiles) { + scene_city_map_tiles->removeItem(city_map_selector_item); + delete city_map_selector_item; + } + + this->city_map_selector_item = new TilemapTileSelector(QPixmap(this->region_map->city_map_tiles_path)); this->city_map_selector_item->draw(); - this->scene_city_map_tiles = new QGraphicsScene; this->scene_city_map_tiles->addItem(this->city_map_selector_item); + this->scene_city_map_tiles->setSceneRect(this->scene_city_map_tiles->sceneRect());// ? - /*connect(this->city_map_selector_item, &TilemapTileSelector::selectedTileChanged, - this, &RegionMapEditor::onRegionMapTileSelectorSelectedTileChanged);// TODO: remove this? - connect(this->city_map_selector_item, &TilemapTileSelector::hoveredTileChanged, + // TODO: + /*connect(this->city_map_selector_item, &TilemapTileSelector::hoveredTileChanged, 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->setFixedSize(this->city_map_selector_item->pixelWidth + 2, - this->city_map_selector_item->pixelHeight + 2); - //this->ui->graphicsView_City_Map_Tiles->scale(2,2); + this->ui->graphicsView_City_Map_Tiles->setFixedSize(this->city_map_selector_item->pixelWidth * scaleCityMapTiles + 2, + this->city_map_selector_item->pixelHeight * scaleCityMapTiles + 2); } void RegionMapEditor::displayCityMap(QString f) { - // QString file = this->project->root + "/graphics/pokenav/city_maps/" + f + ".bin"; if (!scene_city_map_image) { @@ -183,22 +206,23 @@ void RegionMapEditor::displayCityMap(QString f) { city_map_item = new CityMapPixmapItem(file, this->city_map_selector_item); city_map_item->draw(); - connect(city_map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*, CityMapPixmapItem*)), - this, SLOT(mouseEvent_city_map(QGraphicsSceneMouseEvent*, CityMapPixmapItem*))); + connect(this->city_map_item, &CityMapPixmapItem::mouseEvent, + this, &RegionMapEditor::mouseEvent_city_map); scene_city_map_image->addItem(city_map_item); 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->setFixedSize(QSize(8 * city_map_item->width + 2, 8 * city_map_item->height + 2)); + this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width * scaleCityMapImage + 2, + 8 * city_map_item->height * scaleCityMapImage + 2); } bool RegionMapEditor::createCityMap(QString name) { - // bool errored = false; QString file = this->project->root + "/graphics/pokenav/city_maps/" + name + ".bin"; + // TODO: use project config for these values? uint8_t filler = 0x30; uint8_t border = 0x7; uint8_t blank = 0x1; @@ -224,32 +248,21 @@ bool RegionMapEditor::createCityMap(QString name) { return !errored; } - - -//// - -void RegionMapEditor::onRegionMapTileSelectorSelectedTileChanged() { - // -} - void RegionMapEditor::onRegionMapTileSelectorHoveredTileChanged(unsigned tileId) { QString message = QString("Tile: 0x") + QString("%1").arg(tileId, 4, 16, QChar('0')).toUpper(); this->ui->statusbar->showMessage(message); } void RegionMapEditor::onRegionMapTileSelectorHoveredTileCleared() { - // - //QString message = QString("Selected Tile: 0x") + QString("%1").arg(this->region_map_layout_item->selectedTile, 4, 16, QChar('0')).toUpper(); - //this->ui->statusbar->showMessage(message); + this->ui->statusbar->clearMessage(); } void RegionMapEditor::onRegionMapLayoutSelectedTileChanged(int index) { - // QString message = QString(); + this->currIndex = index; if (this->region_map->map_squares[index].has_map) { - // message = QString("\t %1").arg(this->project->mapSecToMapHoverName->value( - this->region_map->map_squares[index].mapsec)).remove("{NAME_END}");//.remove("{NAME_END}") + this->region_map->map_squares[index].mapsec)).remove("{NAME_END}");// ruby-specific } this->ui->statusbar->showMessage(message); @@ -264,7 +277,6 @@ void RegionMapEditor::onRegionMapLayoutHoveredTileChanged(int index) { if (x >= 0 && y >= 0) { message = QString("(%1, %2)").arg(x).arg(y); if (this->region_map->map_squares[index].has_map) { - // message += QString("\t %1").arg(this->project->mapSecToMapHoverName->value( this->region_map->map_squares[index].mapsec)).remove("{NAME_END}"); } @@ -273,25 +285,12 @@ void RegionMapEditor::onRegionMapLayoutHoveredTileChanged(int index) { } void RegionMapEditor::onRegionMapLayoutHoveredTileCleared() { - // - int index = this->region_map_layout_item->selectedTile; - QString message = QString(); - int x = this->region_map->map_squares[index].x; - int y = this->region_map->map_squares[index].y; - if (x >= 0 && y >= 0) { - message = QString("(%1, %2)").arg(x).arg(y); - if (this->region_map->map_squares[index].has_map) { - // - message += QString("\t %1").arg(this->project->mapSecToMapHoverName->value( - this->region_map->map_squares[index].mapsec)).remove("{NAME_END}"); - } - } - this->ui->statusbar->showMessage(message); + this->ui->statusbar->clearMessage(); } void RegionMapEditor::onHoveredRegionMapTileChanged(int x, int y) { - rmStatusbarMessage = 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(rmStatusbarMessage); + 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); } void RegionMapEditor::onHoveredRegionMapTileCleared() { @@ -299,34 +298,27 @@ void RegionMapEditor::onHoveredRegionMapTileCleared() { } void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, RegionMapPixmapItem *item) { - // if (event->buttons() & Qt::RightButton) { - // item->select(event); - } else if (event->buttons() & Qt::MiddleButton) { - // TODO: add functionality here? replace or? + } else if (event->buttons() & Qt::MiddleButton) {// TODO } else { - // QPointF pos = event->pos(); int x = static_cast(pos.x()) / 8; int y = static_cast(pos.y()) / 8; int index = this->region_map->getMapSquareIndex(x, y); + if (index > this->region_map->map_squares.size() - 1) return; RegionMapHistoryItem *commit = new RegionMapHistoryItem(RegionMapEditorBox::BackgroundImage, index, this->region_map->map_squares[index].tile_img_id, this->mapsquare_selector_item->getSelectedTile()); history.push(commit); - item->paint(event); + item->paint(event);//*/ } } void RegionMapEditor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityMapPixmapItem *item) { // - if (event->buttons() & Qt::RightButton) { - // - //item->select(event); - } else if (event->buttons() & Qt::MiddleButton) { - // TODO: add functionality here? replace or? + if (event->buttons() & Qt::RightButton) {// TODO + } else if (event->buttons() & Qt::MiddleButton) {// TODO } else { - // QPointF pos = event->pos(); int x = static_cast(pos.x()) / 8; int y = static_cast(pos.y()) / 8; @@ -338,31 +330,33 @@ void RegionMapEditor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityM } } - - - - - - - -//// - void RegionMapEditor::on_tabWidget_Region_Map_currentChanged(int index) { - // this->ui->stackedWidget_RM_Options->setCurrentIndex(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 + 1, y + 2); + this->region_map_layout_item->highlight(x, y, red); +} + +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 + 1, y + 2); + this->region_map_layout_item->highlight(x, y, red); +} + void RegionMapEditor::on_pushButton_RM_Options_save_clicked() { - // this->region_map->saveOptions( - // - this->region_map_layout_item->selectedTile, + this->region_map_layout_item->selectedTile,// TODO: remove 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(); + // TODO: update selected tile index } void RegionMapEditor::on_pushButton_CityMap_save_clicked() { @@ -370,7 +364,9 @@ void RegionMapEditor::on_pushButton_CityMap_save_clicked() { } void RegionMapEditor::on_pushButton_RM_Options_delete_clicked() { - qDebug() << "delete it fat"; + 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); } void RegionMapEditor::on_pushButton_CityMap_add_clicked() { @@ -400,7 +396,40 @@ void RegionMapEditor::on_pushButton_CityMap_add_clicked() { } } +void RegionMapEditor::on_action_RegionMap_Resize_triggered() { + QDialog popup(this, Qt::WindowTitleHint | Qt::WindowCloseButtonHint); + popup.setWindowTitle("New Region Map Dimensions"); + popup.setWindowModality(Qt::NonModal); + + QFormLayout form(&popup); + + QSpinBox *widthSpinBox = new QSpinBox(); + QSpinBox *heightSpinBox = new QSpinBox(); + widthSpinBox->setMinimum(32); + heightSpinBox->setMinimum(20); + widthSpinBox->setMaximum(64);// TODO: come up with real (meaningful) limits? + heightSpinBox->setMaximum(40); + widthSpinBox->setValue(this->region_map->width()); + heightSpinBox->setValue(this->region_map->height()); + form.addRow(new QLabel("Width"), widthSpinBox); + form.addRow(new QLabel("Height"), heightSpinBox); + + QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &popup); + + form.addRow(&buttonBox); + connect(&buttonBox, SIGNAL(rejected()), &popup, SLOT(reject())); + connect(&buttonBox, SIGNAL(accepted()), &popup, SLOT(accept())); + + if (popup.exec() == QDialog::Accepted) { + resize(widthSpinBox->value(), heightSpinBox->value()); + } +} + void RegionMapEditor::on_action_RegionMap_Undo_triggered() { + undo(); +} + +void RegionMapEditor::undo() { RegionMapHistoryItem *commit = history.current(); if (!commit) return; @@ -423,6 +452,10 @@ void RegionMapEditor::on_action_RegionMap_Undo_triggered() { } void RegionMapEditor::on_action_RegionMap_Redo_triggered() { + redo(); +} + +void RegionMapEditor::redo() { RegionMapHistoryItem *commit = history.next(); if (!commit) return; @@ -442,15 +475,18 @@ void RegionMapEditor::on_action_RegionMap_Redo_triggered() { } } +void RegionMapEditor::resize(int w, int h) { + this->region_map->resize(w, h); + this->currIndex = 2 * w + 1; + displayRegionMap(); +} + void RegionMapEditor::on_comboBox_CityMap_picker_currentTextChanged(const QString &file) { this->displayCityMap(file); } - - -// TODO: prevent huge images with limits on zoom 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); @@ -458,7 +494,7 @@ void RegionMapEditor::on_pushButton_Zoom_In_Image_Tiles_clicked() { } 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); @@ -466,7 +502,7 @@ void RegionMapEditor::on_pushButton_Zoom_Out_Image_Tiles_clicked() { } 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); @@ -474,7 +510,7 @@ void RegionMapEditor::on_pushButton_Zoom_In_City_Tiles_clicked() { } 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); @@ -482,22 +518,25 @@ void RegionMapEditor::on_pushButton_Zoom_Out_City_Tiles_clicked() { } void RegionMapEditor::on_pushButton_Zoom_In_City_Map_clicked() { - // + if (scaleCityMapImage >= 8.0) return; scaleCityMapImage *= 2.0; - this->ui->graphicsView_City_Map->setFixedSize(QSize(8 * city_map_item->width * scaleCityMapImage + 2, 8 * city_map_item->height * scaleCityMapImage + 2)); + 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_pushButton_Zoom_Out_City_Map_clicked() { - // + if (scaleCityMapImage <= 1.0) return; scaleCityMapImage /= 2.0; - this->ui->graphicsView_City_Map->setFixedSize(QSize(8 * city_map_item->width * scaleCityMapImage + 2, 8 * city_map_item->height * scaleCityMapImage + 2)); + 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); } void RegionMapEditor::on_pushButton_Zoom_In_Map_Image_clicked() { - // - //qDebug() << "scale:" << scaleRegionMapImage; + resize(40,30);// test + return; + 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); @@ -506,7 +545,6 @@ void RegionMapEditor::on_pushButton_Zoom_In_Map_Image_clicked() { } 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); @@ -514,23 +552,3 @@ 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_Layout->scale(0.5,0.5); } - - - - - - - - - - - - - - - - - - - - diff --git a/src/ui/regionmaplayoutpixmapitem.cpp b/src/ui/regionmaplayoutpixmapitem.cpp index 24de0e53..5f97e529 100644 --- a/src/ui/regionmaplayoutpixmapitem.cpp +++ b/src/ui/regionmaplayoutpixmapitem.cpp @@ -2,8 +2,6 @@ -// TODO: make this connected (by duplicating scene rect maybe?) to background image tab -// void RegionMapLayoutPixmapItem::draw() { if (!region_map) return; @@ -14,7 +12,11 @@ void RegionMapLayoutPixmapItem::draw() { QImage bottom_img = this->tile_selector->tileImg(region_map->map_squares[i].tile_img_id); QImage top_img(8, 8, QImage::Format_RGBA8888); if (region_map->map_squares[i].has_map) { - top_img.fill(Qt::gray); + if (i == highlightedTile) { + top_img.fill(Qt::red); + } else { + top_img.fill(Qt::gray); + } } else { top_img.fill(Qt::black); } @@ -34,10 +36,6 @@ void RegionMapLayoutPixmapItem::draw() { this->drawSelection(); } -void RegionMapLayoutPixmapItem::setDefaultSelection() { - this->select(1,2); -} - void RegionMapLayoutPixmapItem::select(int x, int y) { int index = this->region_map->getMapSquareIndex(x, y); SelectablePixmapItem::select(x, y, 0, 0); @@ -47,11 +45,30 @@ void RegionMapLayoutPixmapItem::select(int x, int y) { emit selectedTileChanged(index); } +void RegionMapLayoutPixmapItem::select(int index) { + int x = index % this->region_map->width(); + int y = index / this->region_map->width(); + SelectablePixmapItem::select(x, y, 0, 0); + this->selectedTile = index; + this->updateSelectedTile(); + + emit selectedTileChanged(index); +} + +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; + draw(); + SelectablePixmapItem::select(x + 1, y + 2, 0, 0); +} + void RegionMapLayoutPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { QPoint pos = this->getCellPos(event->pos()); int index = this->region_map->getMapSquareIndex(pos.x(), pos.y()); if (this->region_map->map_squares[index].x >= 0 && this->region_map->map_squares[index].y >= 0) { + //if (index > this->region_map->width() * 2) { SelectablePixmapItem::mousePressEvent(event); this->updateSelectedTile(); emit selectedTileChanged(this->selectedTile);