fix outstanding rme bugs and history
This commit is contained in:
parent
a951fc85da
commit
38cb97793d
15 changed files with 235 additions and 286 deletions
|
@ -2976,6 +2976,7 @@
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Cursor Tile Outline</string>
|
<string>Cursor Tile Outline</string>
|
||||||
</property>
|
</property>
|
||||||
|
</action>
|
||||||
<action name="actionRegion_Map_Editor">
|
<action name="actionRegion_Map_Editor">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Region Map Editor</string>
|
<string>Region Map Editor</string>
|
||||||
|
|
|
@ -61,8 +61,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>345</width>
|
<width>348</width>
|
||||||
<height>188</height>
|
<height>225</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_18">
|
<layout class="QGridLayout" name="gridLayout_18">
|
||||||
|
@ -182,8 +182,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>345</width>
|
<width>348</width>
|
||||||
<height>188</height>
|
<height>225</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_19">
|
<layout class="QGridLayout" name="gridLayout_19">
|
||||||
|
@ -332,8 +332,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>8</x>
|
<x>8</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>281</width>
|
<width>278</width>
|
||||||
<height>225</height>
|
<height>262</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -652,7 +652,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>440</width>
|
<width>440</width>
|
||||||
<height>267</height>
|
<height>230</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_20">
|
<layout class="QGridLayout" name="gridLayout_20">
|
||||||
|
@ -788,7 +788,7 @@
|
||||||
<x>8</x>
|
<x>8</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>254</width>
|
<width>254</width>
|
||||||
<height>311</height>
|
<height>274</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -902,6 +902,9 @@
|
||||||
<height>160</height>
|
<height>160</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::StrongFocus</enum>
|
||||||
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -946,6 +949,9 @@
|
||||||
<height>160</height>
|
<height>160</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::StrongFocus</enum>
|
||||||
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -981,6 +987,9 @@
|
||||||
<height>160</height>
|
<height>160</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::StrongFocus</enum>
|
||||||
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -1025,6 +1034,9 @@
|
||||||
<height>160</height>
|
<height>160</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::StrongFocus</enum>
|
||||||
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define HISTORYITEM_H
|
#define HISTORYITEM_H
|
||||||
|
|
||||||
#include "blockdata.h"
|
#include "blockdata.h"
|
||||||
//#include "regionmap.h"
|
|
||||||
|
|
||||||
class HistoryItem {
|
class HistoryItem {
|
||||||
public:
|
public:
|
||||||
|
@ -16,17 +15,15 @@ public:
|
||||||
enum RegionMapEditorBox {
|
enum RegionMapEditorBox {
|
||||||
BackgroundImage = 1,
|
BackgroundImage = 1,
|
||||||
CityMapImage = 2,
|
CityMapImage = 2,
|
||||||
BackroundResize = 3,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RegionMapHistoryItem {
|
class RegionMapHistoryItem {
|
||||||
public:
|
public:
|
||||||
int which;
|
int which;
|
||||||
int mapWidth;
|
int mapWidth = 0;
|
||||||
int mapHeight;
|
int mapHeight = 0;
|
||||||
QVector<uint8_t> tiles;
|
QVector<uint8_t> tiles;
|
||||||
QString cityMap;
|
QString cityMap;
|
||||||
RegionMapHistoryItem(int type, QVector<uint8_t> tiles);
|
|
||||||
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, QString cityMap);
|
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, QString cityMap);
|
||||||
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, int width, int height);
|
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, int width, int height);
|
||||||
~RegionMapHistoryItem();
|
~RegionMapHistoryItem();
|
||||||
|
|
|
@ -15,15 +15,6 @@
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct CityMapPosition
|
|
||||||
{
|
|
||||||
QString tilemap;
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct RegionMapEntry
|
struct RegionMapEntry
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
@ -38,14 +29,14 @@ class RegionMapSquare
|
||||||
public:
|
public:
|
||||||
int x = -1;
|
int x = -1;
|
||||||
int y = -1;
|
int y = -1;
|
||||||
uint8_t tile_img_id;
|
uint8_t tile_img_id = 0x00;
|
||||||
|
uint8_t secid = 0x00;
|
||||||
bool has_map = false;
|
bool has_map = false;
|
||||||
|
bool has_city_map = false;
|
||||||
|
bool duplicated = false;
|
||||||
QString map_name;
|
QString map_name;
|
||||||
QString mapsec;
|
QString mapsec;
|
||||||
uint8_t secid;
|
|
||||||
bool has_city_map = false;
|
|
||||||
QString city_map_name;
|
QString city_map_name;
|
||||||
bool duplicated = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RegionMap : public QObject
|
class RegionMap : public QObject
|
||||||
|
@ -57,18 +48,45 @@ public:
|
||||||
|
|
||||||
~RegionMap() {};
|
~RegionMap() {};
|
||||||
|
|
||||||
static QString mapSecToMapConstant(QString);
|
|
||||||
|
|
||||||
Project *project;
|
Project *project;
|
||||||
|
|
||||||
QVector<RegionMapSquare> map_squares;
|
QVector<RegionMapSquare> map_squares;
|
||||||
|
History<RegionMapHistoryItem*> history;
|
||||||
|
|
||||||
const int padLeft = 1;
|
const int padLeft = 1;
|
||||||
const int padRight = 3;
|
const int padRight = 3;
|
||||||
const int padTop = 2;
|
const int padTop = 2;
|
||||||
const int padBottom = 3;
|
const int padBottom = 3;
|
||||||
|
|
||||||
History<RegionMapHistoryItem*> history;
|
void init(Project*);
|
||||||
|
|
||||||
|
void readBkgImgBin();
|
||||||
|
void readLayout();
|
||||||
|
|
||||||
|
void save();
|
||||||
|
void saveBkgImgBin();
|
||||||
|
void saveLayout();
|
||||||
|
void saveOptions(int id, QString sec, QString name, int x, int y);
|
||||||
|
|
||||||
|
void resize(int width, int height);
|
||||||
|
void resetSquare(int index);
|
||||||
|
|
||||||
|
int width();
|
||||||
|
int height();
|
||||||
|
QSize imgSize();
|
||||||
|
unsigned getTileId(int x, int y);
|
||||||
|
int getMapSquareIndex(int x, int y);
|
||||||
|
QString pngPath();
|
||||||
|
QString cityTilesPath();
|
||||||
|
|
||||||
|
QVector<uint8_t> getTiles();
|
||||||
|
void setTiles(QVector<uint8_t> tileIds);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int layout_width_;
|
||||||
|
int layout_height_;
|
||||||
|
int img_width_;
|
||||||
|
int img_height_;
|
||||||
|
|
||||||
QString region_map_png_path;
|
QString region_map_png_path;
|
||||||
QString region_map_bin_path;
|
QString region_map_bin_path;
|
||||||
|
@ -76,65 +94,14 @@ public:
|
||||||
QString region_map_layout_bin_path;
|
QString region_map_layout_bin_path;
|
||||||
QString city_map_tiles_path;
|
QString city_map_tiles_path;
|
||||||
|
|
||||||
QByteArray mapBinData;
|
QMap<QString, QString> sMapNamesMap;
|
||||||
|
QMap<QString, struct RegionMapEntry> mapSecToMapEntry;
|
||||||
QMap<QString, QString> sMapNamesMap;// {"{/sMapName_/}LittlerootTown" : "LITTLEROOT{NAME_END} TOWN"}
|
|
||||||
QMap<QString, QString> mapSecToMapName;// {"MAPSEC_LITTLEROOT_TOWN" : "LITTLEROOT{NAME_END} TOWN"}
|
|
||||||
QMap<QString, struct RegionMapEntry> mapSecToMapEntry;// TODO: add to this on creation of new map
|
|
||||||
|
|
||||||
QVector<QString> sMapNames;
|
QVector<QString> sMapNames;
|
||||||
|
|
||||||
bool hasUnsavedChanges();
|
int img_index_(int x, int y);
|
||||||
|
int layout_index_(int x, int y);
|
||||||
void init(Project*);
|
|
||||||
|
|
||||||
void readBkgImgBin();
|
|
||||||
void readCityMaps();
|
|
||||||
void readLayout();
|
|
||||||
|
|
||||||
QString newAbbr(QString);// makes a *unique* 5 character abbreviation from mapname to add to mapname_abbr
|
|
||||||
|
|
||||||
// TODO: did I use these like, at all?
|
|
||||||
// editing functions
|
|
||||||
// if they are booleans, returns true if successful?
|
|
||||||
bool placeTile(char, int, int);// place tile at x, y
|
|
||||||
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 saveOptions(int, QString, QString, int, int);
|
|
||||||
void saveCityMaps();
|
|
||||||
|
|
||||||
void resize(int, int);
|
|
||||||
void setWidth(int);
|
|
||||||
void setHeight(int);
|
|
||||||
void setBackgroundImageData(QVector<uint8_t> *);
|
|
||||||
int width();
|
|
||||||
int height();
|
|
||||||
QSize imgSize();
|
|
||||||
unsigned getTileId(int, int);
|
|
||||||
int getMapSquareIndex(int, int);
|
|
||||||
|
|
||||||
QVector<uint8_t> getTiles();
|
|
||||||
void setTiles(QVector<uint8_t>);
|
|
||||||
|
|
||||||
void resetSquare(int);
|
|
||||||
|
|
||||||
// TODO: move read / write functions to private (and others)
|
|
||||||
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);
|
|
||||||
void fillMapSquaresFromLayout();
|
|
||||||
QString fix_case(QString);// CAPS_WITH_UNDERSCORE to CamelCase
|
|
||||||
|
|
||||||
|
QString fix_case(QString);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REGIONMAP_H
|
#endif // REGIONMAP_H
|
||||||
|
|
|
@ -30,19 +30,19 @@ public:
|
||||||
void loadRegionMapData();
|
void loadRegionMapData();
|
||||||
void loadCityMaps();
|
void loadCityMaps();
|
||||||
|
|
||||||
void onRegionMapTileSelectorSelectedTileChanged(unsigned);
|
void onRegionMapTileSelectorSelectedTileChanged(unsigned id);
|
||||||
void onCityMapTileSelectorSelectedTileChanged(unsigned);
|
void onCityMapTileSelectorSelectedTileChanged(unsigned id);
|
||||||
void onRegionMapTileSelectorHoveredTileChanged(unsigned);
|
void onRegionMapTileSelectorHoveredTileChanged(unsigned id);
|
||||||
void onRegionMapTileSelectorHoveredTileCleared();
|
void onRegionMapTileSelectorHoveredTileCleared();
|
||||||
|
|
||||||
void onRegionMapLayoutSelectedTileChanged(int);
|
void onRegionMapLayoutSelectedTileChanged(int index);
|
||||||
void onRegionMapLayoutHoveredTileChanged(int);
|
void onRegionMapLayoutHoveredTileChanged(int index);
|
||||||
void onRegionMapLayoutHoveredTileCleared();
|
void onRegionMapLayoutHoveredTileCleared();
|
||||||
|
|
||||||
void undo();
|
void undo();
|
||||||
void redo();
|
void redo();
|
||||||
|
|
||||||
void resize(int, int);
|
void resize(int width, int height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::RegionMapEditor *ui;
|
Ui::RegionMapEditor *ui;
|
||||||
|
@ -55,6 +55,8 @@ private:
|
||||||
unsigned selectedImageTile;
|
unsigned selectedImageTile;
|
||||||
|
|
||||||
bool hasUnsavedChanges = false;
|
bool hasUnsavedChanges = false;
|
||||||
|
bool cityMapFirstDraw = true;
|
||||||
|
bool regionMapFirstDraw = true;
|
||||||
|
|
||||||
double scaleUpFactor = 2.0;
|
double scaleUpFactor = 2.0;
|
||||||
double scaleDownFactor = 1.0 / scaleUpFactor;
|
double scaleDownFactor = 1.0 / scaleUpFactor;
|
||||||
|
@ -81,14 +83,14 @@ private:
|
||||||
void displayRegionMapImage();
|
void displayRegionMapImage();
|
||||||
void displayRegionMapLayout();
|
void displayRegionMapLayout();
|
||||||
void displayRegionMapLayoutOptions();
|
void displayRegionMapLayoutOptions();
|
||||||
void updateRegionMapLayoutOptions(int);
|
void updateRegionMapLayoutOptions(int index);
|
||||||
void displayRegionMapTileSelector();
|
void displayRegionMapTileSelector();
|
||||||
void displayCityMapTileSelector();
|
void displayCityMapTileSelector();
|
||||||
void displayCityMap(QString);
|
void displayCityMap(QString name);
|
||||||
|
|
||||||
bool createCityMap(QString);
|
bool createCityMap(QString name);
|
||||||
|
|
||||||
void closeEvent(QCloseEvent*);
|
void closeEvent(QCloseEvent* event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_action_RegionMap_Save_triggered();
|
void on_action_RegionMap_Save_triggered();
|
||||||
|
@ -98,20 +100,20 @@ private slots:
|
||||||
void on_action_RegionMap_Generate_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_delete_clicked();
|
void on_pushButton_RM_Options_delete_clicked();
|
||||||
void on_comboBox_RM_ConnectedMap_activated(const QString &);
|
void on_comboBox_RM_ConnectedMap_activated(const QString &text);
|
||||||
void on_pushButton_CityMap_add_clicked();
|
void on_pushButton_CityMap_add_clicked();
|
||||||
void on_verticalSlider_Zoom_Map_Image_valueChanged(int);
|
void on_verticalSlider_Zoom_Map_Image_valueChanged(int);
|
||||||
void on_verticalSlider_Zoom_Image_Tiles_valueChanged(int);
|
void on_verticalSlider_Zoom_Image_Tiles_valueChanged(int);
|
||||||
void on_verticalSlider_Zoom_City_Map_valueChanged(int);
|
void on_verticalSlider_Zoom_City_Map_valueChanged(int);
|
||||||
void on_verticalSlider_Zoom_City_Tiles_valueChanged(int);
|
void on_verticalSlider_Zoom_City_Tiles_valueChanged(int);
|
||||||
void on_comboBox_CityMap_picker_currentTextChanged(const QString &);
|
void on_comboBox_CityMap_picker_currentTextChanged(const QString &text);
|
||||||
void on_spinBox_RM_Options_x_valueChanged(int);
|
void on_spinBox_RM_Options_x_valueChanged(int val);
|
||||||
void on_spinBox_RM_Options_y_valueChanged(int);
|
void on_spinBox_RM_Options_y_valueChanged(int val);
|
||||||
void on_lineEdit_RM_MapName_textEdited(const QString &);
|
void on_lineEdit_RM_MapName_textEdited(const QString &text);
|
||||||
void onHoveredRegionMapTileChanged(int, int);
|
void onHoveredRegionMapTileChanged(int x, int y);
|
||||||
void onHoveredRegionMapTileCleared();
|
void onHoveredRegionMapTileCleared();
|
||||||
void mouseEvent_region_map(QGraphicsSceneMouseEvent *, RegionMapPixmapItem *);
|
void mouseEvent_region_map(QGraphicsSceneMouseEvent *event, RegionMapPixmapItem *item);
|
||||||
void mouseEvent_city_map(QGraphicsSceneMouseEvent *, CityMapPixmapItem *);
|
void mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityMapPixmapItem *item);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REGIONMAPEDITOR_H
|
#endif // REGIONMAPEDITOR_H
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
class TilemapTileSelector: public SelectablePixmapItem {
|
class TilemapTileSelector: public SelectablePixmapItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
TilemapTileSelector(QPixmap pixmap): SelectablePixmapItem(8, 8, 1, 1) {
|
TilemapTileSelector(QPixmap pixmap_): SelectablePixmapItem(8, 8, 1, 1) {
|
||||||
this->pixmap = pixmap;
|
this->tilemap = pixmap_;
|
||||||
this->numTilesWide = pixmap.width() / 8;
|
this->setPixmap(this->tilemap);
|
||||||
|
this->numTilesWide = tilemap.width() / 8;
|
||||||
this->selectedTile = 0x00;
|
this->selectedTile = 0x00;
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
}
|
}
|
||||||
|
@ -21,10 +22,7 @@ public:
|
||||||
|
|
||||||
unsigned selectedTile = 0;
|
unsigned selectedTile = 0;
|
||||||
|
|
||||||
// TODO: which of these need to be made public?
|
QPixmap tilemap;
|
||||||
// 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);
|
QImage tileImg(unsigned tileId);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -40,7 +38,6 @@ private:
|
||||||
void updateSelectedTile();
|
void updateSelectedTile();
|
||||||
unsigned getTileId(int x, int y);
|
unsigned getTileId(int x, int y);
|
||||||
QPoint getTileIdCoords(unsigned);
|
QPoint getTileIdCoords(unsigned);
|
||||||
unsigned getValidTileId(unsigned);// TODO: implement this to prevent segfaults
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void hoveredTileChanged(unsigned);
|
void hoveredTileChanged(unsigned);
|
||||||
|
|
|
@ -28,7 +28,6 @@ SOURCES += src/core/block.cpp \
|
||||||
src/core/parseutil.cpp \
|
src/core/parseutil.cpp \
|
||||||
src/core/tile.cpp \
|
src/core/tile.cpp \
|
||||||
src/core/tileset.cpp \
|
src/core/tileset.cpp \
|
||||||
src/core/regionmapeditor.cpp \
|
|
||||||
src/core/regionmap.cpp \
|
src/core/regionmap.cpp \
|
||||||
src/core/regionmapgenerator.cpp \
|
src/core/regionmapgenerator.cpp \
|
||||||
src/ui/aboutporymap.cpp \
|
src/ui/aboutporymap.cpp \
|
||||||
|
@ -86,7 +85,6 @@ HEADERS += include/core/block.h \
|
||||||
include/core/parseutil.h \
|
include/core/parseutil.h \
|
||||||
include/core/tile.h \
|
include/core/tile.h \
|
||||||
include/core/tileset.h \
|
include/core/tileset.h \
|
||||||
include/core/regionmapeditor.h \
|
|
||||||
include/core/regionmap.h \
|
include/core/regionmap.h \
|
||||||
include/core/regionmapgenerator.h \
|
include/core/regionmapgenerator.h \
|
||||||
include/ui/aboutporymap.h \
|
include/ui/aboutporymap.h \
|
||||||
|
|
|
@ -10,11 +10,6 @@ HistoryItem::~HistoryItem() {
|
||||||
if (this->metatiles) delete this->metatiles;
|
if (this->metatiles) delete this->metatiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegionMapHistoryItem::RegionMapHistoryItem(int which, QVector<uint8_t> tiles) {
|
|
||||||
this->which = which;
|
|
||||||
this->tiles = tiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
RegionMapHistoryItem::RegionMapHistoryItem(int which, QVector<uint8_t> tiles, QString cityMap) {
|
RegionMapHistoryItem::RegionMapHistoryItem(int which, QVector<uint8_t> tiles, QString cityMap) {
|
||||||
this->which = which;
|
this->which = which;
|
||||||
this->tiles = tiles;
|
this->tiles = tiles;
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
void RegionMap::init(Project *pro) {
|
void RegionMap::init(Project *pro) {
|
||||||
QString path = pro->root;
|
QString path = pro->root;
|
||||||
|
@ -29,10 +28,15 @@ void RegionMap::init(Project *pro) {
|
||||||
|
|
||||||
readBkgImgBin();
|
readBkgImgBin();
|
||||||
readLayout();
|
readLayout();
|
||||||
readCityMaps();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: if the tileId is not valid for the provided image, make sure it does not crash
|
void RegionMap::save() {
|
||||||
|
logInfo("Saving region map data.");
|
||||||
|
saveBkgImgBin();
|
||||||
|
saveLayout();
|
||||||
|
porymapConfig.setRegionMapDimensions(this->img_width_, this->img_height_);
|
||||||
|
}
|
||||||
|
|
||||||
void RegionMap::readBkgImgBin() {
|
void RegionMap::readBkgImgBin() {
|
||||||
QFile binFile(region_map_bin_path);
|
QFile binFile(region_map_bin_path);
|
||||||
if (!binFile.open(QIODevice::ReadOnly)) return;
|
if (!binFile.open(QIODevice::ReadOnly)) return;
|
||||||
|
@ -54,7 +58,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(pow(img_width_ * 2, 2),0);
|
||||||
|
|
||||||
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++) {
|
||||||
|
@ -68,9 +72,7 @@ void RegionMap::saveBkgImgBin() {
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: reorganize this into project? the i/o stuff. use regionMapSections
|
|
||||||
void RegionMap::readLayout() {
|
void RegionMap::readLayout() {
|
||||||
//
|
|
||||||
QFile file(region_map_entries_path);
|
QFile file(region_map_entries_path);
|
||||||
if (!file.open(QIODevice::ReadOnly)) return;
|
if (!file.open(QIODevice::ReadOnly)) return;
|
||||||
|
|
||||||
|
@ -111,17 +113,16 @@ void RegionMap::readLayout() {
|
||||||
QByteArray mapBinData = binFile.readAll();
|
QByteArray mapBinData = binFile.readAll();
|
||||||
binFile.close();
|
binFile.close();
|
||||||
|
|
||||||
// TODO: improve this?
|
for (int y = 0; y < layout_height_; y++) {
|
||||||
for (int m = 0; m < layout_height_; m++) {
|
for (int x = 0; x < layout_width_; x++) {
|
||||||
for (int n = 0; n < layout_width_; n++) {
|
int i = img_index_(x,y);
|
||||||
int i = img_index_(n,m);
|
map_squares[i].secid = static_cast<uint8_t>(mapBinData.at(layout_index_(x,y)));
|
||||||
map_squares[i].secid = static_cast<uint8_t>(mapBinData.at(layout_index_(n,m)));
|
QString secname = (*(project->regionMapSections))[static_cast<uint8_t>(mapBinData.at(layout_index_(x,y)))];
|
||||||
QString secname = (*(project->regionMapSections))[static_cast<uint8_t>(mapBinData.at(layout_index_(n,m)))];
|
|
||||||
if (secname != "MAPSEC_NONE") map_squares[i].has_map = true;
|
if (secname != "MAPSEC_NONE") map_squares[i].has_map = true;
|
||||||
map_squares[i].mapsec = secname;
|
map_squares[i].mapsec = secname;
|
||||||
map_squares[i].map_name = sMapNamesMap.value(mapSecToMapEntry.value(secname).name);// TODO: this is atrocious
|
map_squares[i].map_name = sMapNamesMap.value(mapSecToMapEntry.value(secname).name);
|
||||||
map_squares[i].x = n;
|
map_squares[i].x = x;
|
||||||
map_squares[i].y = m;
|
map_squares[i].y = y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,69 +163,11 @@ void RegionMap::saveLayout() {
|
||||||
bfile.close();
|
bfile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMap::readCityMaps() {}
|
|
||||||
|
|
||||||
// layout coords to image index
|
|
||||||
int RegionMap::img_index_(int x, int y) {
|
|
||||||
return ((x + this->padLeft) + (y + this->padTop) * img_width_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// layout coords to layout index
|
|
||||||
int RegionMap::layout_index_(int x, int y) {
|
|
||||||
return (x + y * layout_width_);
|
|
||||||
}
|
|
||||||
|
|
||||||
int RegionMap::width() {
|
|
||||||
return this->img_width_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int RegionMap::height() {
|
|
||||||
return this->img_height_;
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize RegionMap::imgSize() {
|
|
||||||
return QSize(img_width_ * 8, img_height_ * 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
QVector<uint8_t> RegionMap::getTiles() {
|
|
||||||
//
|
|
||||||
QVector<uint8_t> tileIds;
|
|
||||||
for (auto square : map_squares) {
|
|
||||||
tileIds.append(square.tile_img_id);
|
|
||||||
}
|
|
||||||
return tileIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegionMap::setTiles(QVector<uint8_t> tileIds) {
|
|
||||||
//
|
|
||||||
if (tileIds.size() != map_squares.size()) {
|
|
||||||
qDebug() << "YOU SHOULD RESIZE";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int i = 0;
|
|
||||||
for (uint8_t tileId : tileIds) {
|
|
||||||
map_squares[i].tile_img_id = tileId;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: rename to getTileIdAt()?
|
|
||||||
unsigned RegionMap::getTileId(int x, int y) {
|
|
||||||
return map_squares[x + y * img_width_].tile_img_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegionMap::save() {
|
|
||||||
logInfo("Saving region map info.");
|
|
||||||
saveBkgImgBin();
|
|
||||||
saveLayout();
|
|
||||||
porymapConfig.setRegionMapDimensions(this->img_width_, this->img_height_);
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
||||||
resetSquare(id);
|
resetSquare(id);
|
||||||
int index = getMapSquareIndex(x + this->padLeft, y + this->padTop);
|
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 = sec == "MAPSEC_NONE" ? false : 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));
|
||||||
this->map_squares[index].mapsec = sec;
|
this->map_squares[index].mapsec = sec;
|
||||||
if (!name.isEmpty()) {
|
if (!name.isEmpty()) {
|
||||||
|
@ -234,7 +177,7 @@ void RegionMap::saveOptions(int id, QString sec, QString name, int x, int y) {
|
||||||
QString sName = fix_case(sec);
|
QString sName = fix_case(sec);
|
||||||
sMapNames.append(sName);
|
sMapNames.append(sName);
|
||||||
sMapNamesMap.insert(sName, name);
|
sMapNamesMap.insert(sName, name);
|
||||||
struct RegionMapEntry entry = {x, y, 1, 1, sName};// TODO: change width, height?
|
struct RegionMapEntry entry = {x, y, 1, 1, sName};
|
||||||
mapSecToMapEntry.insert(sec, entry);
|
mapSecToMapEntry.insert(sec, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,32 +185,6 @@ 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// from x, y of image
|
|
||||||
int RegionMap::getMapSquareIndex(int x, int y) {
|
|
||||||
int index = (x + y * img_width_);
|
|
||||||
return index < map_squares.length() ? index : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For turning a MAPSEC_NAME into a unique identifier sMapName-style variable.
|
|
||||||
QString RegionMap::fix_case(QString caps) {
|
|
||||||
bool big = true;
|
|
||||||
QString camel;
|
|
||||||
|
|
||||||
for (auto ch : caps.remove(QRegularExpression("({.*})")).remove("MAPSEC")) {
|
|
||||||
if (ch == '_' || ch == ' ') {
|
|
||||||
big = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (big) {
|
|
||||||
camel += ch.toUpper();
|
|
||||||
big = false;
|
|
||||||
}
|
|
||||||
else camel += ch.toLower();
|
|
||||||
}
|
|
||||||
return camel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMap::resetSquare(int index) {
|
void RegionMap::resetSquare(int index) {
|
||||||
|
@ -282,7 +199,6 @@ void RegionMap::resetSquare(int index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMap::resize(int newWidth, int newHeight) {
|
void RegionMap::resize(int newWidth, int newHeight) {
|
||||||
//
|
|
||||||
QVector<RegionMapSquare> new_squares;
|
QVector<RegionMapSquare> new_squares;
|
||||||
|
|
||||||
for (int y = 0; y < newHeight; y++) {
|
for (int y = 0; y < newHeight; y++) {
|
||||||
|
@ -301,10 +217,87 @@ void RegionMap::resize(int newWidth, int newHeight) {
|
||||||
new_squares.append(square);
|
new_squares.append(square);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 - this->padLeft - this->padRight;
|
this->layout_width_ = newWidth - this->padLeft - this->padRight;
|
||||||
this->layout_height_ = newHeight - this->padTop - this->padBottom;
|
this->layout_height_ = newHeight - this->padTop - this->padBottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<uint8_t> RegionMap::getTiles() {
|
||||||
|
QVector<uint8_t> tileIds;
|
||||||
|
for (auto square : map_squares) {
|
||||||
|
tileIds.append(square.tile_img_id);
|
||||||
|
}
|
||||||
|
return tileIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegionMap::setTiles(QVector<uint8_t> tileIds) {
|
||||||
|
if (tileIds.size() != map_squares.size()) return;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (uint8_t tileId : tileIds) {
|
||||||
|
map_squares[i].tile_img_id = tileId;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Layout coords to image index.
|
||||||
|
int RegionMap::img_index_(int x, int y) {
|
||||||
|
return ((x + this->padLeft) + (y + this->padTop) * img_width_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Layout coords to layout index.
|
||||||
|
int RegionMap::layout_index_(int x, int y) {
|
||||||
|
return (x + y * layout_width_);
|
||||||
|
}
|
||||||
|
|
||||||
|
int RegionMap::width() {
|
||||||
|
return this->img_width_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int RegionMap::height() {
|
||||||
|
return this->img_height_;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize RegionMap::imgSize() {
|
||||||
|
return QSize(img_width_ * 8, img_height_ * 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned RegionMap::getTileId(int x, int y) {
|
||||||
|
return map_squares.at(x + y * img_width_).tile_img_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString RegionMap::pngPath() {
|
||||||
|
return this->region_map_png_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString RegionMap::cityTilesPath() {
|
||||||
|
return this->city_map_tiles_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// From x, y of image.
|
||||||
|
int RegionMap::getMapSquareIndex(int x, int y) {
|
||||||
|
int index = (x + y * img_width_);
|
||||||
|
return index < map_squares.length() ? index : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For turning a MAPSEC_NAME into a unique identifier sMapName-style variable.
|
||||||
|
// CAPS_WITH_UNDERSCORE to CamelCase
|
||||||
|
QString RegionMap::fix_case(QString caps) {
|
||||||
|
bool big = true;
|
||||||
|
QString camel;
|
||||||
|
|
||||||
|
for (auto ch : caps.remove(QRegularExpression("({.*})")).remove("MAPSEC")) {
|
||||||
|
if (ch == '_' || ch == ' ') {
|
||||||
|
big = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (big) {
|
||||||
|
camel += ch.toUpper();
|
||||||
|
big = false;
|
||||||
|
}
|
||||||
|
else camel += ch.toLower();
|
||||||
|
}
|
||||||
|
return camel;
|
||||||
|
}
|
||||||
|
|
|
@ -1512,7 +1512,6 @@ void Project::readRegionMapSections() {
|
||||||
QString filepath = root + "/include/constants/region_map_sections.h";
|
QString filepath = root + "/include/constants/region_map_sections.h";
|
||||||
QStringList prefixes = (QStringList() << "MAPSEC_");
|
QStringList prefixes = (QStringList() << "MAPSEC_");
|
||||||
readCDefinesSorted(filepath, prefixes, regionMapSections);
|
readCDefinesSorted(filepath, prefixes, regionMapSections);
|
||||||
regionMapSections->removeAll("MAPSEC_SUBTRACT_KANTO");// TODO: fix this (in repos?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::readItemNames() {
|
void Project::readItemNames() {
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CityMapPixmapItem::init() {
|
void CityMapPixmapItem::init() {
|
||||||
width_ = 10;
|
width_ = 10;
|
||||||
height_ = 10;
|
height_ = 10;
|
||||||
|
@ -78,7 +76,6 @@ void CityMapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<uint8_t> CityMapPixmapItem::getTiles() {
|
QVector<uint8_t> CityMapPixmapItem::getTiles() {
|
||||||
//
|
|
||||||
QVector<uint8_t> tiles;
|
QVector<uint8_t> tiles;
|
||||||
for (auto tile : data) {
|
for (auto tile : data) {
|
||||||
tiles.append(tile);
|
tiles.append(tile);
|
||||||
|
@ -87,7 +84,6 @@ QVector<uint8_t> CityMapPixmapItem::getTiles() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CityMapPixmapItem::setTiles(QVector<uint8_t> tiles) {
|
void CityMapPixmapItem::setTiles(QVector<uint8_t> tiles) {
|
||||||
//
|
|
||||||
QByteArray newData;
|
QByteArray newData;
|
||||||
for (auto tile : tiles) {
|
for (auto tile : tiles) {
|
||||||
newData.append(tile);
|
newData.append(tile);
|
||||||
|
|
|
@ -19,6 +19,7 @@ RegionMapEditor::RegionMapEditor(QWidget *parent, Project *project_) :
|
||||||
this->ui->setupUi(this);
|
this->ui->setupUi(this);
|
||||||
this->project = project_;
|
this->project = project_;
|
||||||
this->region_map = new RegionMap;
|
this->region_map = new RegionMap;
|
||||||
|
this->ui->action_RegionMap_Generate->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
RegionMapEditor::~RegionMapEditor()
|
RegionMapEditor::~RegionMapEditor()
|
||||||
|
@ -48,6 +49,7 @@ void RegionMapEditor::on_action_RegionMap_Save_triggered() {
|
||||||
this->ui->spinBox_RM_Options_x->value(),
|
this->ui->spinBox_RM_Options_x->value(),
|
||||||
this->ui->spinBox_RM_Options_y->value()
|
this->ui->spinBox_RM_Options_y->value()
|
||||||
);
|
);
|
||||||
|
this->currIndex = this->region_map_layout_item->highlightedTile;
|
||||||
this->region_map_layout_item->highlightedTile = -1;
|
this->region_map_layout_item->highlightedTile = -1;
|
||||||
displayRegionMap();
|
displayRegionMap();
|
||||||
}
|
}
|
||||||
|
@ -104,8 +106,13 @@ void RegionMapEditor::displayRegionMapImage() {
|
||||||
this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize().width() * scaleRegionMapImage + 2,
|
this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize().width() * scaleRegionMapImage + 2,
|
||||||
this->region_map->imgSize().height() * scaleRegionMapImage + 2);
|
this->region_map->imgSize().height() * scaleRegionMapImage + 2);
|
||||||
|
|
||||||
RegionMapHistoryItem *commit = new RegionMapHistoryItem(RegionMapEditorBox::BackgroundImage, this->region_map->getTiles());
|
if (regionMapFirstDraw) {
|
||||||
|
RegionMapHistoryItem *commit = new RegionMapHistoryItem(
|
||||||
|
RegionMapEditorBox::BackgroundImage, this->region_map->getTiles(), this->region_map->width(), this->region_map->height()
|
||||||
|
);
|
||||||
history.push(commit);
|
history.push(commit);
|
||||||
|
regionMapFirstDraw = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMapEditor::displayRegionMapLayout() {
|
void RegionMapEditor::displayRegionMapLayout() {
|
||||||
|
@ -179,7 +186,7 @@ void RegionMapEditor::displayRegionMapTileSelector() {
|
||||||
delete 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 = new TilemapTileSelector(QPixmap(this->region_map->pngPath()));
|
||||||
this->mapsquare_selector_item->draw();
|
this->mapsquare_selector_item->draw();
|
||||||
|
|
||||||
this->scene_region_map_tiles->addItem(this->mapsquare_selector_item);
|
this->scene_region_map_tiles->addItem(this->mapsquare_selector_item);
|
||||||
|
@ -207,7 +214,7 @@ void RegionMapEditor::displayCityMapTileSelector() {
|
||||||
delete 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 = new TilemapTileSelector(QPixmap(this->region_map->cityTilesPath()));
|
||||||
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);
|
||||||
|
@ -245,11 +252,6 @@ void RegionMapEditor::displayCityMap(QString f) {
|
||||||
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);
|
||||||
|
|
||||||
RegionMapHistoryItem *commit = new RegionMapHistoryItem(
|
|
||||||
RegionMapEditorBox::CityMapImage, this->city_map_item->getTiles(), this->city_map_item->file
|
|
||||||
);
|
|
||||||
history.push(commit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RegionMapEditor::createCityMap(QString name) {
|
bool RegionMapEditor::createCityMap(QString name) {
|
||||||
|
@ -302,9 +304,10 @@ void RegionMapEditor::onRegionMapTileSelectorHoveredTileCleared() {
|
||||||
void RegionMapEditor::onRegionMapLayoutSelectedTileChanged(int index) {
|
void RegionMapEditor::onRegionMapLayoutSelectedTileChanged(int index) {
|
||||||
QString message = QString();
|
QString message = QString();
|
||||||
this->currIndex = index;
|
this->currIndex = index;
|
||||||
|
this->region_map_layout_item->highlightedTile = index;
|
||||||
if (this->region_map->map_squares[index].has_map) {
|
if (this->region_map->map_squares[index].has_map) {
|
||||||
message = QString("\t %1").arg(this->project->mapSecToMapHoverName->value(
|
message = QString("\t %1").arg(this->project->mapSecToMapHoverName->value(
|
||||||
this->region_map->map_squares[index].mapsec)).remove("{NAME_END}");// ruby-specific
|
this->region_map->map_squares[index].mapsec)).remove("{NAME_END}");
|
||||||
}
|
}
|
||||||
this->ui->statusbar->showMessage(message);
|
this->ui->statusbar->showMessage(message);
|
||||||
|
|
||||||
|
@ -357,7 +360,7 @@ void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, Reg
|
||||||
bool addToHistory = !(current && current->tiles == this->region_map->getTiles());
|
bool addToHistory = !(current && current->tiles == this->region_map->getTiles());
|
||||||
if (addToHistory) {
|
if (addToHistory) {
|
||||||
RegionMapHistoryItem *commit = new RegionMapHistoryItem(
|
RegionMapHistoryItem *commit = new RegionMapHistoryItem(
|
||||||
RegionMapEditorBox::BackgroundImage, this->region_map->getTiles()
|
RegionMapEditorBox::BackgroundImage, this->region_map->getTiles(), this->region_map->width(), this->region_map->height()
|
||||||
);
|
);
|
||||||
history.push(commit);
|
history.push(commit);
|
||||||
}
|
}
|
||||||
|
@ -366,12 +369,19 @@ void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, Reg
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMapEditor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityMapPixmapItem *item) {
|
void RegionMapEditor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityMapPixmapItem *item) {
|
||||||
//
|
|
||||||
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;
|
||||||
int index = this->city_map_item->getIndexAt(x, y);
|
int index = this->city_map_item->getIndexAt(x, y);
|
||||||
|
|
||||||
|
if (cityMapFirstDraw) {
|
||||||
|
RegionMapHistoryItem *commit = new RegionMapHistoryItem(
|
||||||
|
RegionMapEditorBox::CityMapImage, this->city_map_item->getTiles(), this->city_map_item->file
|
||||||
|
);
|
||||||
|
history.push(commit);
|
||||||
|
cityMapFirstDraw = false;
|
||||||
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
@ -473,7 +483,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(60);// w * h * 2 <= 4960
|
widthSpinBox->setMaximum(60);// TODO: find real limits
|
||||||
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());
|
||||||
|
@ -488,6 +498,10 @@ void RegionMapEditor::on_action_RegionMap_Resize_triggered() {
|
||||||
|
|
||||||
if (popup.exec() == QDialog::Accepted) {
|
if (popup.exec() == QDialog::Accepted) {
|
||||||
resize(widthSpinBox->value(), heightSpinBox->value());
|
resize(widthSpinBox->value(), heightSpinBox->value());
|
||||||
|
RegionMapHistoryItem *commit = new RegionMapHistoryItem(
|
||||||
|
RegionMapEditorBox::BackgroundImage, this->region_map->getTiles(), widthSpinBox->value(), heightSpinBox->value()
|
||||||
|
);
|
||||||
|
history.push(commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->hasUnsavedChanges = true;
|
this->hasUnsavedChanges = true;
|
||||||
|
@ -498,7 +512,6 @@ void RegionMapEditor::on_action_RegionMap_Undo_triggered() {
|
||||||
this->hasUnsavedChanges = true;
|
this->hasUnsavedChanges = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add resizing
|
|
||||||
void RegionMapEditor::undo() {
|
void RegionMapEditor::undo() {
|
||||||
RegionMapHistoryItem *commit = history.back();
|
RegionMapHistoryItem *commit = history.back();
|
||||||
if (!commit) return;
|
if (!commit) return;
|
||||||
|
@ -506,6 +519,8 @@ void RegionMapEditor::undo() {
|
||||||
switch (commit->which)
|
switch (commit->which)
|
||||||
{
|
{
|
||||||
case RegionMapEditorBox::BackgroundImage:
|
case RegionMapEditorBox::BackgroundImage:
|
||||||
|
if (commit->mapWidth != this->region_map->width() || commit->mapHeight != this->region_map->height())
|
||||||
|
this->resize(commit->mapWidth, commit->mapHeight);
|
||||||
this->region_map->setTiles(commit->tiles);
|
this->region_map->setTiles(commit->tiles);
|
||||||
this->region_map_item->draw();
|
this->region_map_item->draw();
|
||||||
break;
|
break;
|
||||||
|
@ -514,10 +529,6 @@ void RegionMapEditor::undo() {
|
||||||
this->city_map_item->setTiles(commit->tiles);
|
this->city_map_item->setTiles(commit->tiles);
|
||||||
this->city_map_item->draw();
|
this->city_map_item->draw();
|
||||||
break;
|
break;
|
||||||
case RegionMapEditorBox::BackroundResize:
|
|
||||||
this->region_map->resize(commit->mapWidth, commit->mapHeight);
|
|
||||||
displayRegionMap();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,6 +544,8 @@ void RegionMapEditor::redo() {
|
||||||
switch (commit->which)
|
switch (commit->which)
|
||||||
{
|
{
|
||||||
case RegionMapEditorBox::BackgroundImage:
|
case RegionMapEditorBox::BackgroundImage:
|
||||||
|
if (commit->mapWidth != this->region_map->width() || commit->mapHeight != this->region_map->height())
|
||||||
|
this->resize(commit->mapWidth, commit->mapHeight);
|
||||||
this->region_map->setTiles(commit->tiles);
|
this->region_map->setTiles(commit->tiles);
|
||||||
this->region_map_item->draw();
|
this->region_map_item->draw();
|
||||||
break;
|
break;
|
||||||
|
@ -540,31 +553,20 @@ void RegionMapEditor::redo() {
|
||||||
this->city_map_item->setTiles(commit->tiles);
|
this->city_map_item->setTiles(commit->tiles);
|
||||||
this->city_map_item->draw();
|
this->city_map_item->draw();
|
||||||
break;
|
break;
|
||||||
case RegionMapEditorBox::BackroundResize:
|
|
||||||
this->region_map->resize(commit->mapWidth, commit->mapHeight);
|
|
||||||
displayRegionMap();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMapEditor::resize(int w, int h) {
|
void RegionMapEditor::resize(int w, int h) {
|
||||||
RegionMapHistoryItem *commitOld = new RegionMapHistoryItem(
|
|
||||||
RegionMapEditorBox::BackroundResize, this->region_map->getTiles(), this->region_map->width(), this->region_map->height()
|
|
||||||
);
|
|
||||||
RegionMapHistoryItem *commitNew = new RegionMapHistoryItem(
|
|
||||||
RegionMapEditorBox::BackroundResize, this->region_map->getTiles(), w, h
|
|
||||||
);
|
|
||||||
history.push(commitOld);
|
|
||||||
history.push(commitNew);
|
|
||||||
history.back();
|
|
||||||
|
|
||||||
this->region_map->resize(w, h);
|
this->region_map->resize(w, h);
|
||||||
this->currIndex = 2 * w + 1;
|
this->currIndex = this->region_map->padLeft * w + this->region_map->padTop;
|
||||||
displayRegionMap();
|
displayRegionMapImage();
|
||||||
|
displayRegionMapLayout();
|
||||||
|
displayRegionMapLayoutOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMapEditor::on_comboBox_CityMap_picker_currentTextChanged(const QString &file) {
|
void RegionMapEditor::on_comboBox_CityMap_picker_currentTextChanged(const QString &file) {
|
||||||
this->displayCityMap(file);
|
this->displayCityMap(file);
|
||||||
|
this->cityMapFirstDraw = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMapEditor::closeEvent(QCloseEvent *event)
|
void RegionMapEditor::closeEvent(QCloseEvent *event)
|
||||||
|
@ -652,7 +654,6 @@ void RegionMapEditor::on_verticalSlider_Zoom_City_Tiles_valueChanged(int val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMapEditor::on_action_RegionMap_Generate_triggered() {
|
void RegionMapEditor::on_action_RegionMap_Generate_triggered() {
|
||||||
//
|
|
||||||
RegionMapGenerator generator(this->project);
|
RegionMapGenerator generator(this->project);
|
||||||
generator.generate("LittlerootTown");
|
generator.generate("LittlerootTown");
|
||||||
this->hasUnsavedChanges = true;
|
this->hasUnsavedChanges = true;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#include "regionmaplayoutpixmapitem.h"
|
#include "regionmaplayoutpixmapitem.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void RegionMapLayoutPixmapItem::draw() {
|
void RegionMapLayoutPixmapItem::draw() {
|
||||||
if (!region_map) return;
|
if (!region_map) return;
|
||||||
|
|
||||||
|
@ -76,9 +74,7 @@ void RegionMapLayoutPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
mousePressEvent(event);
|
mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMapLayoutPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
void RegionMapLayoutPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {}
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegionMapLayoutPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
void RegionMapLayoutPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
||||||
QPoint pos = this->getCellPos(event->pos());
|
QPoint pos = this->getCellPos(event->pos());
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
#include "regionmappixmapitem.h"
|
#include "regionmappixmapitem.h"
|
||||||
#include "imageproviders.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void RegionMapPixmapItem::draw() {
|
void RegionMapPixmapItem::draw() {
|
||||||
if (!region_map) return;
|
if (!region_map) return;
|
||||||
|
|
|
@ -3,16 +3,15 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
void TilemapTileSelector::draw() {
|
void TilemapTileSelector::draw() {
|
||||||
size_t width_ = this->pixmap.width();
|
size_t width_ = this->tilemap.width();
|
||||||
this->pixelWidth = width_;
|
this->pixelWidth = width_;
|
||||||
size_t height_ = this->pixmap.height();
|
size_t height_ = this->tilemap.height();
|
||||||
this->pixelHeight = height_;
|
this->pixelHeight = height_;
|
||||||
size_t ntiles_ = (width_/8) * (height_/8);
|
size_t ntiles_ = (width_/8) * (height_/8);
|
||||||
|
|
||||||
this->numTilesWide = width_ / 8;
|
this->numTilesWide = width_ / 8;
|
||||||
this->numTiles = ntiles_;
|
this->numTiles = ntiles_;
|
||||||
|
|
||||||
this->setPixmap(this->pixmap);
|
|
||||||
this->drawSelection();
|
this->drawSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +36,16 @@ unsigned TilemapTileSelector::getTileId(int x, int y) {
|
||||||
return index < this->numTiles ? index : this->numTiles % index;
|
return index < this->numTiles ? index : this->numTiles % index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPoint TilemapTileSelector::getTileIdCoords(unsigned tileId) {
|
||||||
|
int index = tileId < this->numTiles ? tileId : this->numTiles % tileId;
|
||||||
|
return QPoint(index % this->numTilesWide, index / this->numTilesWide);
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage TilemapTileSelector::tileImg(unsigned tileId) {
|
||||||
|
QPoint pos = getTileIdCoords(tileId);
|
||||||
|
return this->tilemap.copy(pos.x() * 8, pos.y() * 8, 8, 8).toImage();
|
||||||
|
}
|
||||||
|
|
||||||
void TilemapTileSelector::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
void TilemapTileSelector::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
SelectablePixmapItem::mousePressEvent(event);
|
SelectablePixmapItem::mousePressEvent(event);
|
||||||
this->updateSelectedTile();
|
this->updateSelectedTile();
|
||||||
|
@ -65,14 +74,3 @@ void TilemapTileSelector::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
||||||
void TilemapTileSelector::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) {
|
void TilemapTileSelector::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) {
|
||||||
emit this->hoveredTileCleared();
|
emit this->hoveredTileCleared();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPoint TilemapTileSelector::getTileIdCoords(unsigned tileId) {
|
|
||||||
int index = tileId < this->numTiles ? tileId : this->numTiles % tileId;
|
|
||||||
return QPoint(index % this->numTilesWide, index / this->numTilesWide);
|
|
||||||
}
|
|
||||||
|
|
||||||
QImage TilemapTileSelector::tileImg(unsigned tileId) {
|
|
||||||
//
|
|
||||||
QPoint pos = getTileIdCoords(tileId);
|
|
||||||
return pixmap.copy(pos.x() * 8, pos.y() * 8, 8, 8).toImage();
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue