porymap/map.h

233 lines
6.2 KiB
C
Raw Normal View History

2016-09-07 04:50:47 +01:00
#ifndef MAP_H
#define MAP_H
#include "tileset.h"
#include "blockdata.h"
#include "event.h"
#include <QPixmap>
#include <QObject>
#include <QDebug>
#include <QGraphicsPixmapItem>
2016-09-07 04:50:47 +01:00
class HistoryItem {
public:
Blockdata *metatiles;
short layoutWidth;
short layoutHeight;
HistoryItem(Blockdata *metatiles_, short layoutWidth_, short layoutHeight_) {
this->metatiles = metatiles_;
this->layoutWidth = layoutWidth_;
this->layoutHeight = layoutHeight_;
}
};
2016-09-07 04:50:47 +01:00
template <typename T>
class History {
public:
History() {
2017-11-28 04:46:27 +00:00
2016-09-07 04:50:47 +01:00
}
T back() {
2016-09-07 04:50:47 +01:00
if (head > 0) {
return history.at(--head);
}
return NULL;
}
T next() {
if (head + 1 < history.length()) {
return history.at(++head);
}
return NULL;
}
void push(T commit) {
while (head + 1 < history.length()) {
history.removeLast();
}
2017-11-28 04:46:27 +00:00
if (saved > head) {
saved = -1;
}
2016-09-07 04:50:47 +01:00
history.append(commit);
head++;
}
T current() {
if (head < 0 || history.length() == 0) {
return NULL;
}
return history.at(head);
}
2017-11-28 04:46:27 +00:00
void save() {
saved = head;
}
bool isSaved() {
return saved == head;
}
private:
QList<T> history;
int head = -1;
int saved = -1;
2016-09-07 04:50:47 +01:00
};
class Connection {
public:
Connection() {
}
public:
QString direction;
QString offset;
QString map_name;
};
2018-06-20 23:43:20 +01:00
class MapLayout {
public:
MapLayout() {}
int index;
QString name;
QString label;
QString width;
QString height;
QString border_label;
QString border_path;
QString blockdata_label;
QString blockdata_path;
QString tileset_primary_label;
QString tileset_secondary_label;
Tileset *tileset_primary = NULL;
Tileset *tileset_secondary = NULL;
Blockdata* blockdata = NULL;
QImage border_image;
QPixmap border_pixmap;
Blockdata *border = NULL;
Blockdata *cached_blockdata = NULL;
Blockdata *cached_collision = NULL;
Blockdata *cached_border = NULL;
bool has_unsaved_changes = false;
public:
static QString getNameFromLabel(QString label) {
// ASSUMPTION: strip off "_Layout" from layout label. Directories in 'data/layouts/' must be well-formed.
return label.replace(label.lastIndexOf("_Layout"), label.length(), "");
}
};
2016-09-07 04:50:47 +01:00
class Map : public QObject
{
Q_OBJECT
public:
explicit Map(QObject *parent = 0);
public:
QString name;
QString constantName;
QString group_num;
2018-06-20 23:43:20 +01:00
QString layout_label;
2016-09-07 04:50:47 +01:00
QString events_label;
QString scripts_label;
QString connections_label;
QString song;
2018-06-20 23:43:20 +01:00
QString layout_id;
2016-09-07 04:50:47 +01:00
QString location;
QString visibility;
QString weather;
QString type;
QString unknown;
QString show_location;
QString battle_scene;
2018-06-20 23:43:20 +01:00
MapLayout *layout;
2016-09-07 04:50:47 +01:00
bool isPersistedToFile = true;
2016-09-07 04:50:47 +01:00
public:
void setName(QString mapName);
static QString mapConstantFromName(QString mapName);
2018-07-07 17:57:44 +01:00
static QString objectEventsLabelFromName(QString mapName);
static QString warpEventsLabelFromName(QString mapName);
static QString coordEventsLabelFromName(QString mapName);
static QString bgEventsLabelFromName(QString mapName);
2016-09-07 04:50:47 +01:00
int getWidth();
int getHeight();
2018-07-07 17:57:44 +01:00
int getSelectedBlockIndex(int);
int getDisplayedBlockIndex(int);
2018-06-20 23:43:20 +01:00
QPixmap render(bool ignoreCache);
2016-09-07 04:50:47 +01:00
QPixmap renderMetatiles();
2018-06-20 23:43:20 +01:00
QPixmap renderCollision(bool ignoreCache);
2016-09-07 04:50:47 +01:00
QImage collision_image;
QPixmap collision_pixmap;
QImage getCollisionMetatileImage(Block);
QImage getElevationMetatileImage(Block);
QImage getCollisionMetatileImage(int);
QImage getElevationMetatileImage(int);
QPixmap renderCollisionMetatiles();
QPixmap renderElevationMetatiles();
void drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter);
2016-09-07 04:50:47 +01:00
bool blockChanged(int, Blockdata*);
void cacheBlockdata();
void cacheCollision();
QImage image;
QPixmap pixmap;
QList<QImage> metatile_images;
2018-03-06 00:47:00 +00:00
bool smart_paths_enabled = false;
2018-03-05 22:47:46 +00:00
int paint_metatile_initial_x;
int paint_metatile_initial_y;
int paint_tile_index;
2018-03-05 22:47:46 +00:00
int paint_tile_width = 1;
int paint_tile_height = 1;
int paint_tile_initial_x;
int paint_tile_initial_y;
2016-09-07 04:50:47 +01:00
int paint_collision;
int paint_elevation;
Block *getBlock(int x, int y);
void setBlock(int x, int y, Block block);
void _setBlock(int x, int y, Block block);
void floodFillCollision(int x, int y, uint collision);
void _floodFillCollision(int x, int y, uint collision);
void floodFillElevation(int x, int y, uint elevation);
void _floodFillElevation(int x, int y, uint elevation);
void floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
void _floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
History<HistoryItem*> history;
2016-09-07 04:50:47 +01:00
void undo();
void redo();
void commit();
2017-11-28 04:46:27 +00:00
QList<Event*> getAllEvents();
void removeEvent(Event *event);
void addEvent(Event *event);
QMap<QString, QList<Event*>> events;
2016-09-07 04:50:47 +01:00
QList<Connection*> connections;
QPixmap renderConnection(Connection);
void setNewDimensionsBlockdata(int newWidth, int newHeight);
void setDimensions(int newWidth, int newHeight, bool setNewBlockData = true);
2016-09-07 04:50:47 +01:00
QPixmap renderBorder();
void cacheBorder();
2017-11-28 04:46:27 +00:00
bool hasUnsavedChanges();
void hoveredTileChanged(int x, int y, int block);
void clearHoveredTile();
void hoveredMetatileChanged(int block);
void clearHoveredMetatile();
void hoveredCollisionTileChanged(int collision);
void clearHoveredCollisionTile();
void hoveredElevationTileChanged(int elevation);
void clearHoveredElevationTile();
2017-11-28 04:46:27 +00:00
2016-09-07 04:50:47 +01:00
signals:
2017-11-28 04:46:27 +00:00
void paintTileChanged(Map *map);
void paintCollisionChanged(Map *map);
void mapChanged(Map *map);
void mapNeedsRedrawing(Map *map);
void statusBarMessage(QString);
2016-09-07 04:50:47 +01:00
public slots:
};
#endif // MAP_H