2020-09-13 23:37:55 +01:00
|
|
|
#pragma once
|
2018-09-27 00:30:05 +01:00
|
|
|
#ifndef MAP_H
|
|
|
|
#define MAP_H
|
|
|
|
|
|
|
|
#include "blockdata.h"
|
|
|
|
#include "mapconnection.h"
|
|
|
|
#include "maplayout.h"
|
|
|
|
#include "tileset.h"
|
2022-07-19 22:56:12 +01:00
|
|
|
#include "events.h"
|
2018-09-27 00:30:05 +01:00
|
|
|
|
2020-07-29 20:51:04 +01:00
|
|
|
#include <QUndoStack>
|
2018-09-27 00:30:05 +01:00
|
|
|
#include <QPixmap>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QGraphicsPixmapItem>
|
|
|
|
#include <math.h>
|
|
|
|
|
2020-03-13 06:23:47 +00:00
|
|
|
#define DEFAULT_BORDER_WIDTH 2
|
|
|
|
#define DEFAULT_BORDER_HEIGHT 2
|
|
|
|
|
2022-08-29 17:44:17 +01:00
|
|
|
// Maximum based only on data type (u8) of map border width/height
|
|
|
|
#define MAX_BORDER_WIDTH 255
|
|
|
|
#define MAX_BORDER_HEIGHT 255
|
|
|
|
|
2020-04-05 05:03:36 +01:00
|
|
|
// Number of metatiles to draw out from edge of map. Could allow modification of this in the future.
|
2020-03-14 07:44:55 +00:00
|
|
|
// porymap will reflect changes to it, but the value is hard-coded in the projects at the moment
|
2020-04-05 05:03:36 +01:00
|
|
|
#define BORDER_DISTANCE 7
|
2020-03-14 07:44:55 +00:00
|
|
|
|
2020-07-29 20:51:04 +01:00
|
|
|
class MapPixmapItem;
|
2020-08-01 01:30:35 +01:00
|
|
|
class CollisionPixmapItem;
|
2020-07-29 20:51:04 +01:00
|
|
|
class BorderMetatilesPixmapItem;
|
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
class Map : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit Map(QObject *parent = nullptr);
|
2020-08-07 01:39:53 +01:00
|
|
|
~Map();
|
2018-09-27 00:30:05 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
QString name;
|
|
|
|
QString constantName;
|
|
|
|
QString song;
|
2019-02-01 17:43:25 +00:00
|
|
|
QString layoutId;
|
2018-09-27 00:30:05 +01:00
|
|
|
QString location;
|
2022-10-14 23:11:11 +01:00
|
|
|
bool requiresFlash;
|
2018-09-27 00:30:05 +01:00
|
|
|
QString weather;
|
|
|
|
QString type;
|
2022-10-14 23:11:11 +01:00
|
|
|
bool show_location;
|
|
|
|
bool allowRunning;
|
|
|
|
bool allowBiking;
|
|
|
|
bool allowEscaping;
|
2021-02-18 08:51:44 +00:00
|
|
|
int floorNumber = 0;
|
2018-09-27 00:30:05 +01:00
|
|
|
QString battle_scene;
|
2019-02-02 20:56:05 +00:00
|
|
|
QString sharedEventsMap = "";
|
|
|
|
QString sharedScriptsMap = "";
|
2023-12-30 02:54:37 +00:00
|
|
|
QStringList scriptsFileLabels;
|
2022-10-15 08:22:51 +01:00
|
|
|
QMap<QString, QJsonValue> customHeaders;
|
2018-09-27 00:30:05 +01:00
|
|
|
MapLayout *layout;
|
|
|
|
bool isPersistedToFile = true;
|
2021-09-08 03:40:07 +01:00
|
|
|
bool hasUnsavedDataChanges = false;
|
2019-01-07 23:14:44 +00:00
|
|
|
bool needsLayoutDir = true;
|
2022-10-14 23:11:11 +01:00
|
|
|
bool needsHealLocation = false;
|
2024-01-29 19:07:13 +00:00
|
|
|
bool scriptsLoaded = false;
|
2018-09-27 00:30:05 +01:00
|
|
|
QImage collision_image;
|
|
|
|
QPixmap collision_pixmap;
|
|
|
|
QImage image;
|
|
|
|
QPixmap pixmap;
|
2023-01-26 20:02:32 +00:00
|
|
|
|
2022-07-19 22:56:12 +01:00
|
|
|
QMap<Event::Group, QList<Event *>> events;
|
|
|
|
QList<Event *> ownedEvents; // for memory management
|
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
QList<MapConnection*> connections;
|
2020-07-02 02:19:08 +01:00
|
|
|
QList<int> metatileLayerOrder;
|
2020-07-02 02:43:19 +01:00
|
|
|
QList<float> metatileLayerOpacity;
|
2023-12-30 02:54:37 +00:00
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
void setName(QString mapName);
|
2023-12-18 07:19:12 +00:00
|
|
|
static QString mapConstantFromName(QString mapName, bool includePrefix = true);
|
2018-09-27 00:30:05 +01:00
|
|
|
int getWidth();
|
|
|
|
int getHeight();
|
2020-03-13 06:23:47 +00:00
|
|
|
int getBorderWidth();
|
|
|
|
int getBorderHeight();
|
2023-01-07 02:57:42 +00:00
|
|
|
QPixmap render(bool ignoreCache = false, MapLayout *fromLayout = nullptr, QRect bounds = QRect(0, 0, -1, -1));
|
|
|
|
QPixmap renderCollision(bool ignoreCache);
|
2021-02-14 21:56:23 +00:00
|
|
|
bool mapBlockChanged(int i, const Blockdata &cache);
|
|
|
|
bool borderBlockChanged(int i, const Blockdata &cache);
|
2018-09-27 00:30:05 +01:00
|
|
|
void cacheBlockdata();
|
|
|
|
void cacheCollision();
|
2021-02-13 21:16:52 +00:00
|
|
|
bool getBlock(int x, int y, Block *out);
|
2020-04-30 02:41:19 +01:00
|
|
|
void setBlock(int x, int y, Block block, bool enableScriptCallback = false);
|
2022-10-12 03:50:08 +01:00
|
|
|
void setBlockdata(Blockdata blockdata, bool enableScriptCallback = false);
|
2022-08-29 17:44:17 +01:00
|
|
|
uint16_t getBorderMetatileId(int x, int y);
|
|
|
|
void setBorderMetatileId(int x, int y, uint16_t metatileId, bool enableScriptCallback = false);
|
2022-10-12 03:50:08 +01:00
|
|
|
void setBorderBlockData(Blockdata blockdata, bool enableScriptCallback = false);
|
2018-09-27 00:30:05 +01:00
|
|
|
void floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
|
|
|
|
void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
|
2019-01-05 02:49:21 +00:00
|
|
|
void magicFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
|
2022-07-19 22:56:12 +01:00
|
|
|
QList<Event *> getAllEvents() const;
|
2024-01-29 19:07:13 +00:00
|
|
|
QStringList getScriptLabels(Event::Group group = Event::Group::None);
|
2022-07-19 22:56:12 +01:00
|
|
|
void removeEvent(Event *);
|
|
|
|
void addEvent(Event *);
|
2024-08-05 00:11:29 +01:00
|
|
|
bool removeConnection(MapConnection *);
|
|
|
|
void addConnection(MapConnection *);
|
2024-08-04 21:08:16 +01:00
|
|
|
QPixmap renderConnection(const QString &, MapLayout *);
|
2020-05-03 16:00:56 +01:00
|
|
|
QPixmap renderBorder(bool ignoreCache = false);
|
2022-10-12 03:50:08 +01:00
|
|
|
void setDimensions(int newWidth, int newHeight, bool setNewBlockdata = true, bool enableScriptCallback = false);
|
|
|
|
void setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata = true, bool enableScriptCallback = false);
|
2023-01-17 01:16:25 +00:00
|
|
|
void clearBorderCache();
|
2018-09-27 00:30:05 +01:00
|
|
|
void cacheBorder();
|
|
|
|
bool hasUnsavedChanges();
|
2022-02-08 22:40:07 +00:00
|
|
|
bool isWithinBounds(int x, int y);
|
2022-08-29 17:44:17 +01:00
|
|
|
bool isWithinBorderBounds(int x, int y);
|
2022-08-31 23:53:07 +01:00
|
|
|
void openScript(QString label);
|
2023-12-30 02:54:37 +00:00
|
|
|
QString getScriptsFilePath() const;
|
2020-08-07 01:39:53 +01:00
|
|
|
|
2020-07-29 20:51:04 +01:00
|
|
|
MapPixmapItem *mapItem = nullptr;
|
|
|
|
void setMapItem(MapPixmapItem *item) { mapItem = item; }
|
|
|
|
|
2020-08-01 01:30:35 +01:00
|
|
|
CollisionPixmapItem *collisionItem = nullptr;
|
|
|
|
void setCollisionItem(CollisionPixmapItem *item) { collisionItem = item; }
|
|
|
|
|
2020-07-29 20:51:04 +01:00
|
|
|
BorderMetatilesPixmapItem *borderItem = nullptr;
|
|
|
|
void setBorderItem(BorderMetatilesPixmapItem *item) { borderItem = item; }
|
|
|
|
|
|
|
|
QUndoStack editHistory;
|
2022-09-28 05:21:01 +01:00
|
|
|
void modify();
|
|
|
|
void clean();
|
2020-07-29 20:51:04 +01:00
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
private:
|
|
|
|
void setNewDimensionsBlockdata(int newWidth, int newHeight);
|
2020-03-14 07:44:55 +00:00
|
|
|
void setNewBorderDimensionsBlockdata(int newWidth, int newHeight);
|
2018-09-27 00:30:05 +01:00
|
|
|
|
|
|
|
signals:
|
2022-09-28 05:21:01 +01:00
|
|
|
void modified();
|
2020-10-24 12:45:08 +01:00
|
|
|
void mapDimensionsChanged(const QSize &size);
|
2018-09-27 00:30:05 +01:00
|
|
|
void mapNeedsRedrawing();
|
2022-08-31 23:53:07 +01:00
|
|
|
void openScriptRequested(QString label);
|
2024-08-05 00:11:29 +01:00
|
|
|
void connectionAdded(MapConnection*);
|
2018-09-27 00:30:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MAP_H
|