2018-09-23 22:32:07 +01:00
|
|
|
#ifndef METATILESELECTOR_H
|
|
|
|
#define METATILESELECTOR_H
|
|
|
|
|
2020-02-02 22:25:37 +00:00
|
|
|
#include <QPair>
|
2018-09-23 22:32:07 +01:00
|
|
|
#include "selectablepixmapitem.h"
|
2020-07-02 02:19:08 +01:00
|
|
|
#include "map.h"
|
2018-09-25 01:12:29 +01:00
|
|
|
#include "tileset.h"
|
2020-02-02 22:25:37 +00:00
|
|
|
#include "maplayout.h"
|
2018-09-23 22:32:07 +01:00
|
|
|
|
2022-09-05 17:35:17 +01:00
|
|
|
struct MetatileSelectionItem
|
|
|
|
{
|
|
|
|
bool enabled;
|
|
|
|
uint16_t metatileId;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CollisionSelectionItem
|
|
|
|
{
|
|
|
|
bool enabled;
|
|
|
|
uint16_t collision;
|
|
|
|
uint16_t elevation;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MetatileSelection
|
|
|
|
{
|
|
|
|
QPoint dimensions;
|
|
|
|
bool hasCollision;
|
|
|
|
QList<MetatileSelectionItem> metatileItems;
|
|
|
|
QList<CollisionSelectionItem> collisionItems;
|
|
|
|
};
|
|
|
|
|
2018-09-23 22:32:07 +01:00
|
|
|
class MetatileSelector: public SelectablePixmapItem {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-07-02 02:19:08 +01:00
|
|
|
MetatileSelector(int numMetatilesWide, Map *map): SelectablePixmapItem(16, 16) {
|
2018-09-23 22:32:07 +01:00
|
|
|
this->externalSelection = false;
|
2022-09-24 17:16:03 +01:00
|
|
|
this->prefabSelection = false;
|
2018-09-23 22:32:07 +01:00
|
|
|
this->numMetatilesWide = numMetatilesWide;
|
2020-07-02 02:19:08 +01:00
|
|
|
this->map = map;
|
|
|
|
this->primaryTileset = map->layout->tileset_primary;
|
|
|
|
this->secondaryTileset = map->layout->tileset_secondary;
|
2022-09-05 17:35:17 +01:00
|
|
|
this->selection = MetatileSelection{};
|
2018-09-23 22:32:07 +01:00
|
|
|
setAcceptHoverEvents(true);
|
|
|
|
}
|
|
|
|
QPoint getSelectionDimensions();
|
|
|
|
void draw();
|
2020-07-08 08:56:27 +01:00
|
|
|
bool select(uint16_t metatile);
|
|
|
|
bool selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation);
|
2018-09-23 22:32:07 +01:00
|
|
|
void setTilesets(Tileset*, Tileset*);
|
2022-09-05 17:35:17 +01:00
|
|
|
MetatileSelection getMetatileSelection();
|
2022-09-24 17:16:03 +01:00
|
|
|
void setPrefabSelection(MetatileSelection selection);
|
2020-02-02 22:25:37 +00:00
|
|
|
void setExternalSelection(int, int, QList<uint16_t>, QList<QPair<uint16_t, uint16_t>>);
|
2018-10-08 20:42:51 +01:00
|
|
|
QPoint getMetatileIdCoordsOnWidget(uint16_t);
|
2020-07-15 00:10:55 +01:00
|
|
|
void setMap(Map*);
|
2021-11-30 22:24:46 +00:00
|
|
|
Tileset *primaryTileset;
|
|
|
|
Tileset *secondaryTileset;
|
2018-09-23 22:32:07 +01:00
|
|
|
protected:
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
|
|
|
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
|
|
|
|
private:
|
|
|
|
bool externalSelection;
|
2022-09-24 17:16:03 +01:00
|
|
|
bool prefabSelection;
|
2018-09-23 22:32:07 +01:00
|
|
|
int numMetatilesWide;
|
2020-07-02 02:19:08 +01:00
|
|
|
Map *map;
|
2018-09-23 22:32:07 +01:00
|
|
|
int externalSelectionWidth;
|
|
|
|
int externalSelectionHeight;
|
2022-09-05 17:35:17 +01:00
|
|
|
QList<uint16_t> externalSelectedMetatiles;
|
|
|
|
MetatileSelection selection;
|
2018-09-23 22:32:07 +01:00
|
|
|
|
|
|
|
void updateSelectedMetatiles();
|
2021-12-19 22:25:44 +00:00
|
|
|
void updateExternalSelectedMetatiles();
|
2018-09-23 22:32:07 +01:00
|
|
|
uint16_t getMetatileId(int x, int y);
|
|
|
|
QPoint getMetatileIdCoords(uint16_t);
|
2020-04-09 20:12:52 +01:00
|
|
|
bool shouldAcceptEvent(QGraphicsSceneMouseEvent*);
|
2020-07-07 22:52:10 +01:00
|
|
|
bool selectionIsValid();
|
2018-09-23 22:32:07 +01:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void hoveredMetatileSelectionChanged(uint16_t);
|
|
|
|
void hoveredMetatileSelectionCleared();
|
|
|
|
void selectedMetatilesChanged();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // METATILESELECTOR_H
|