add region map image editor with basic functionality

This commit is contained in:
garak
2018-12-28 13:26:18 -05:00
parent c3e41976e8
commit 7cffe07579
13 changed files with 1783 additions and 8 deletions

View File

@@ -0,0 +1,179 @@
#ifndef REGIONMAP_H
#define REGIONMAP_H
#include "project.h"
#include "map.h"
#include "tilemaptileselector.h"
//#include "block.h"
#include <QStringList>
#include <QString>
#include <QList>
#include <QMap>
#include <QGraphicsScene>
#include <QGraphicsView>
// if editing map bins, will need to remake the graphics when editing
// are the scenes set in the editor / project / mainwindow files?
/*
* - display the region map background image
* - edit the region_map_layout.h layout
* - edit city maps metatile layout and JUST save the mapname_num.bin
* - edit
* who edits pokenav_city_maps 1 and 2?
* users can: - add the incbins probably themselves
* - add
* - edit region map background image
*
*
*
*
* Editor:
* - void displayCityMapMetatileSelector
* - void displayRegionMapTileSelector
* - void selectRegionMapTile(QString mapname)
* - QGraphicsScene *scene_city_map_metatiles
* - TilemapTileSelector *city_map_metatile_selector_item
* - Tileset *city_map_squares (or tileset_city_map?)
* - Tileset *tileset_region_map
*
* MainWindow:
*
*
* Project:
*
*/
// rename this struct
struct CityMapPosition
{
//
//QString filename; // eg. dewford_0
QString tilemap;// eg. "dewford_0"
int x;
int y;
};
// class that holds data for each square in this project
// struct?
// TODO: change char / uint8_t to unsigned
class RegionMapSquare
{
public:
//
// are positions layout positions? (yes) so out of bounds are all (-1, -1) <-- how it's used in code
// (GetRegionMapLocationPosition)
// or image positions
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"
// ^ use project mapsec to names table
bool has_city_map;// whether there is a city map on this grid
//QList<struct CityMapPosition> city_maps;
QString city_map_name;// filename of the city_map tilemap
//bool is_flyable;//? needed ?
friend class RegionMap;// not necessary if instance? what
};
class RegionMap : public QObject
{
Q_OBJECT
//public:
// explicit Map(QObject *parent = nullptr);
public:
RegionMap() = default;
~RegionMap() {
delete mapname_abbr;
delete layout_map_names;
//delete background_image_tiles;
//delete map_squares;
//delete background_image_selector_item;
};
static QMap<QString, QList<struct CityMapPosition>> ruby_city_maps_;
static QString mapSecToMapConstant(QString);
//RegionMapSquare *map_squares = nullptr;// array of RegionMapSquares
QList<RegionMapSquare> map_squares;
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;
//QMap<QString, somthing> something;// name of map : info about city map, position in layoit, etc.
//QMap<QString, TilemapTile*> regionMapLayoutTng; // mapName : tilemaptileselector
// maybe position data to select correct square when changing map on side but only if map is a valid
//QList<uint8_t> *background_image_tiles;// the visible ones anyways // using list because replace
//TilemapTileSelector *background_image_selector_item;// ?
QMap<QString, QString> *mapname_abbr;// layout shortcuts mapname:region_map_layout defines (both ways)
// make this a QHash?? <-- no because something
QStringList *layout_map_names;
// uint8_t border_tile;
bool hasUnsavedChanges();
void init(Project*);//QString);
// parseutil.cpp ?
void readBkgImgBin();
void readCityMaps();// more complicated
void readLayout(QMap<QString, QString>*);
QString newAbbr(QString);// makes a *unique* 5 character abbreviation from mapname to add to mapname_abbr
// editing functions
// if they are booleans, returns true if successful?
bool placeTile(char, int, int);// place tile at x, y
bool removeTile(char, int, int);// replaces with 0x00 byte at x,y
bool placeMap(QString, int, int);
bool removeMap(QString, int, int);
bool removeMap(QString);// remove all instances of map
void save();
void saveBkgImgBin();
void saveLayout();
void saveCityMaps();
void update();// update the view in case something is broken?
void resize(int, int);
void setWidth(int);
void setHeight(int);
int width();
int height();
QSize imgSize();
unsigned getTileId(int, int);
// implement these here?
void undo();
void redo();
void test(QMap<QString, QString>*);// remove when done testing obvi
// TODO: move read / write functions to private (and others)
private:
//
int layout_width_;
int layout_height_;
int img_width_;
int img_height_;
int img_index_(int, int);// returns index int at x,y args (x + y * width_ * 2) // 2 because
int layout_index_(int, int);
//protected:
//
//signals:
//
};
//TilemapTileSelector *city_map_metatile_selector_item = nullptr;
#endif // REGIONMAP_H

View File

@@ -19,6 +19,8 @@
#include "currentselectedmetatilespixmapitem.h"
#include "collisionpixmapitem.h"
#include "mappixmapitem.h"
#include "regionmappixmapitem.h"
#include "regionmapeditor.h"
#include "settings.h"
#include "movablerect.h"
#include "cursortilerect.h"
@@ -77,6 +79,33 @@ public:
void updateCustomMapHeaderValues(QTableWidget *);
Tileset *getCurrentMapPrimaryTileset();
//
RegionMap *region_map;
void loadRegionMapData();
QGraphicsScene *scene_region_map_image = nullptr;
QGraphicsScene *scene_region_map_layout = nullptr;//?
QGraphicsScene *scene_region_map_tiles = nullptr;
TilemapTileSelector *mapsquare_selector_item = nullptr;
RegionMapPixmapItem *region_map_item = nullptr;
void displayRegionMap();
void displayRegionMapTileSelector();
// selectedTileChanged, hoveredTileChanged, hoveredTileCleared
void onRegionMapTileSelectorSelectedTileChanged();
void onRegionMapTileSelectorHoveredTileChanged(unsigned);
void onRegionMapTileSelectorHoveredTileCleared();
private slots:
void onHoveredRegionMapTileChanged(int, int);
void onHoveredRegionMapTileCleared();
void mouseEvent_region_map(QGraphicsSceneMouseEvent *, RegionMapPixmapItem *);
public:
QString regionMapTabStatusbarMessage;// TODO: make this name not terrible
//
DraggablePixmapItem *addMapEvent(Event *event);
void selectMapEvent(DraggablePixmapItem *object);
void selectMapEvent(DraggablePixmapItem *object, bool toggle);
@@ -105,6 +134,7 @@ public:
QGraphicsScene *scene_selected_border_metatiles = nullptr;
QGraphicsScene *scene_collision_metatiles = nullptr;
QGraphicsScene *scene_elevation_metatiles = nullptr;
MetatileSelector *metatile_selector_item = nullptr;
BorderMetatilesPixmapItem *selected_border_metatiles_item = nullptr;

View File

@@ -65,6 +65,8 @@ private slots:
void on_checkBox_AllowBiking_clicked(bool checked);
void on_checkBox_AllowEscapeRope_clicked(bool checked);
void on_tabWidget_Region_Map_currentChanged(int);
void on_tabWidget_currentChanged(int index);
void on_actionUndo_triggered();

View File

@@ -0,0 +1,36 @@
#ifndef REGIONMAPPIXMAPITEM_H
#define REGIONMAPPIXMAPITEM_H
#include "regionmapeditor.h"
#include "tilemaptileselector.h"
#include <QGraphicsPixmapItem>
class RegionMapPixmapItem : public QObject, public QGraphicsPixmapItem {
Q_OBJECT
public:
RegionMapPixmapItem(RegionMap *rmap, TilemapTileSelector *tile_selector) {
this->region_map = rmap;
this->tile_selector = tile_selector;
setAcceptHoverEvents(true);
}
RegionMap *region_map;
TilemapTileSelector *tile_selector;
virtual void paint(QGraphicsSceneMouseEvent*);
virtual void select(QGraphicsSceneMouseEvent*);
virtual void draw();
signals:
void mouseEvent(QGraphicsSceneMouseEvent *, RegionMapPixmapItem *);
void hoveredRegionMapTileChanged(int x, int y);
void hoveredRegionMapTileCleared();
protected:
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
void mousePressEvent(QGraphicsSceneMouseEvent*);
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
};
#endif // REGIONMAPPIXMAPITEM_H

View File

@@ -0,0 +1,51 @@
#ifndef TILEMAPTILESELECTOR_H
#define TILEMAPTILESELECTOR_H
#include "selectablepixmapitem.h"
class TilemapTileSelector: public SelectablePixmapItem {
Q_OBJECT
public:
TilemapTileSelector(QPixmap pixmap): SelectablePixmapItem(8, 8, 1, 1) {
this->pixmap = pixmap;
this->numTilesWide = 16;
this->selectedTile = 0x00;
setAcceptHoverEvents(true);
}
void draw();
void select(unsigned tileId);
unsigned getSelectedTile();
int pixelWidth;
int pixelHeight;
unsigned selectedTile;
// TODO: which of these need to be made public?
// call this tilemap? or is tilemap the binary file?
QPixmap pixmap;// pointer?
QImage currTile;// image of just the currently selected tile to draw onto graphicsview
QImage tileImg(unsigned tileId);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent*);
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
private:
int numTilesWide;
int numTiles;
void updateSelectedTile();
unsigned getTileId(int x, int y);
QPoint getTileIdCoords(unsigned);
unsigned getValidTileId(unsigned);// TODO: implement this to prevent segfaults
signals:
void hoveredTileChanged(unsigned);
void hoveredTileCleared();
void selectedTileChanged(unsigned);
};
#endif // TILEMAPTILESELECTOR_H