2020-09-13 23:37:55 +01:00
|
|
|
#pragma once
|
2018-09-23 22:32:07 +01:00
|
|
|
#ifndef MAPLAYOUT_H
|
|
|
|
#define MAPLAYOUT_H
|
|
|
|
|
|
|
|
#include "blockdata.h"
|
|
|
|
#include "tileset.h"
|
|
|
|
#include <QImage>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QString>
|
2023-02-01 15:09:50 +00:00
|
|
|
#include <QUndoStack>
|
2018-09-23 22:32:07 +01:00
|
|
|
|
2023-01-23 17:19:21 +00:00
|
|
|
class Map;
|
2023-02-01 15:09:50 +00:00
|
|
|
class LayoutPixmapItem;
|
|
|
|
class CollisionPixmapItem;
|
|
|
|
class BorderMetatilesPixmapItem;
|
2023-01-23 17:19:21 +00:00
|
|
|
|
2023-02-01 15:09:50 +00:00
|
|
|
class Layout : public QObject {
|
|
|
|
Q_OBJECT
|
2018-09-23 22:32:07 +01:00
|
|
|
public:
|
2023-02-01 15:09:50 +00:00
|
|
|
Layout() {}
|
2023-01-23 17:19:21 +00:00
|
|
|
|
2019-02-01 17:43:25 +00:00
|
|
|
static QString layoutConstantFromName(QString mapName);
|
2023-01-23 17:19:21 +00:00
|
|
|
|
2023-02-07 18:04:52 +00:00
|
|
|
bool loaded = false;
|
|
|
|
|
2019-02-01 17:43:25 +00:00
|
|
|
QString id;
|
2018-09-23 22:32:07 +01:00
|
|
|
QString name;
|
2023-01-23 17:19:21 +00:00
|
|
|
|
2022-10-16 07:49:42 +01:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int border_width;
|
|
|
|
int border_height;
|
2023-01-23 17:19:21 +00:00
|
|
|
|
2018-09-23 22:32:07 +01:00
|
|
|
QString border_path;
|
|
|
|
QString blockdata_path;
|
2023-01-23 17:19:21 +00:00
|
|
|
|
2018-09-23 22:32:07 +01:00
|
|
|
QString tileset_primary_label;
|
|
|
|
QString tileset_secondary_label;
|
2023-01-23 17:19:21 +00:00
|
|
|
|
2018-09-23 22:32:07 +01:00
|
|
|
Tileset *tileset_primary = nullptr;
|
|
|
|
Tileset *tileset_secondary = nullptr;
|
2023-01-23 17:19:21 +00:00
|
|
|
|
2021-02-14 21:34:17 +00:00
|
|
|
Blockdata blockdata;
|
2023-01-23 17:19:21 +00:00
|
|
|
|
2023-02-01 15:09:50 +00:00
|
|
|
QImage image;
|
|
|
|
QPixmap pixmap;
|
2018-09-23 22:32:07 +01:00
|
|
|
QImage border_image;
|
|
|
|
QPixmap border_pixmap;
|
2023-02-01 15:09:50 +00:00
|
|
|
QImage collision_image;
|
|
|
|
QPixmap collision_pixmap;
|
2023-01-23 17:19:21 +00:00
|
|
|
|
2021-02-14 21:34:17 +00:00
|
|
|
Blockdata border;
|
|
|
|
Blockdata cached_blockdata;
|
|
|
|
Blockdata cached_collision;
|
|
|
|
Blockdata cached_border;
|
2020-08-04 01:49:00 +01:00
|
|
|
struct {
|
2021-02-14 21:34:17 +00:00
|
|
|
Blockdata blocks;
|
2023-04-08 02:50:46 +01:00
|
|
|
QSize layoutDimensions;
|
2022-08-29 19:48:16 +01:00
|
|
|
Blockdata border;
|
|
|
|
QSize borderDimensions;
|
|
|
|
} lastCommitBlocks; // to track map changes
|
2021-07-20 03:02:31 +01:00
|
|
|
|
2023-02-01 15:09:50 +00:00
|
|
|
QList<int> metatileLayerOrder;
|
|
|
|
QList<float> metatileLayerOpacity;
|
|
|
|
|
|
|
|
LayoutPixmapItem *layoutItem = nullptr;
|
|
|
|
CollisionPixmapItem *collisionItem = nullptr;
|
|
|
|
BorderMetatilesPixmapItem *borderItem = nullptr;
|
|
|
|
|
|
|
|
QUndoStack editHistory;
|
|
|
|
|
2024-02-16 03:19:49 +00:00
|
|
|
// to simplify new layout settings transfer between functions
|
|
|
|
struct SimpleSettings {
|
|
|
|
QString id;
|
|
|
|
QString name;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
QString tileset_primary_label;
|
|
|
|
QString tileset_secondary_label;
|
|
|
|
QString from_id = QString();
|
|
|
|
};
|
|
|
|
|
2023-02-01 15:09:50 +00:00
|
|
|
public:
|
2023-02-14 17:09:22 +00:00
|
|
|
Layout *copy();
|
|
|
|
void copyFrom(Layout *other);
|
|
|
|
|
2021-07-20 03:02:31 +01:00
|
|
|
int getWidth();
|
|
|
|
int getHeight();
|
|
|
|
int getBorderWidth();
|
|
|
|
int getBorderHeight();
|
2023-02-01 15:09:50 +00:00
|
|
|
|
2023-02-01 20:02:26 +00:00
|
|
|
bool isWithinBounds(int x, int y);
|
|
|
|
bool isWithinBorderBounds(int x, int y);
|
2023-02-01 15:09:50 +00:00
|
|
|
|
|
|
|
bool getBlock(int x, int y, Block *out);
|
|
|
|
void setBlock(int x, int y, Block block, bool enableScriptCallback = false);
|
|
|
|
void setBlockdata(Blockdata blockdata, bool enableScriptCallback = false);
|
|
|
|
|
|
|
|
void setDimensions(int newWidth, int newHeight, bool setNewBlockdata = true, bool enableScriptCallback = false);
|
|
|
|
void setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata = true, bool enableScriptCallback = false);
|
|
|
|
|
|
|
|
void cacheBlockdata();
|
|
|
|
void cacheCollision();
|
|
|
|
void clearBorderCache();
|
|
|
|
void cacheBorder();
|
|
|
|
|
2024-10-30 01:51:05 +00:00
|
|
|
bool hasUnsavedChanges() const;
|
2023-02-02 01:28:54 +00:00
|
|
|
|
2023-02-01 15:09:50 +00:00
|
|
|
bool layoutBlockChanged(int i, const Blockdata &cache);
|
|
|
|
|
|
|
|
uint16_t getBorderMetatileId(int x, int y);
|
|
|
|
void setBorderMetatileId(int x, int y, uint16_t metatileId, bool enableScriptCallback = false);
|
|
|
|
void setBorderBlockData(Blockdata blockdata, bool enableScriptCallback = false);
|
|
|
|
|
|
|
|
void floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
|
|
|
|
void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
|
|
|
|
void magicFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
|
|
|
|
|
|
|
|
QPixmap render(bool ignoreCache = false, Layout *fromLayout = nullptr, QRect bounds = QRect(0, 0, -1, -1));
|
|
|
|
QPixmap renderCollision(bool ignoreCache);
|
|
|
|
// QPixmap renderConnection(MapConnection, Layout *);
|
|
|
|
QPixmap renderBorder(bool ignoreCache = false);
|
|
|
|
|
2023-02-08 16:48:42 +00:00
|
|
|
QPixmap getLayoutItemPixmap();
|
|
|
|
|
2023-02-01 15:09:50 +00:00
|
|
|
void setLayoutItem(LayoutPixmapItem *item) { layoutItem = item; }
|
|
|
|
void setCollisionItem(CollisionPixmapItem *item) { collisionItem = item; }
|
|
|
|
void setBorderItem(BorderMetatilesPixmapItem *item) { borderItem = item; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void setNewDimensionsBlockdata(int newWidth, int newHeight);
|
|
|
|
void setNewBorderDimensionsBlockdata(int newWidth, int newHeight);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void layoutChanged(Layout *layout);
|
2023-02-07 18:04:52 +00:00
|
|
|
//void modified();
|
2023-02-01 15:09:50 +00:00
|
|
|
void layoutDimensionsChanged(const QSize &size);
|
|
|
|
void needsRedrawing();
|
2018-09-23 22:32:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MAPLAYOUT_H
|