move map pixmap item and metatile rendering from Map to Layout
This commit is contained in:
parent
917e61b98a
commit
2bc51f1c29
27 changed files with 1115 additions and 444 deletions
|
@ -180,7 +180,7 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="mapListContainerPage2" native="true">
|
||||
<widget class="QWidget" name="mapListContainerPage2">
|
||||
<attribute name="title">
|
||||
<string>Areas</string>
|
||||
</attribute>
|
||||
|
@ -443,6 +443,9 @@
|
|||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectItems</enum>
|
||||
</property>
|
||||
<property name="expandsOnDoubleClick">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
#define CONFIG_BACKWARDS_COMPATABILITY
|
||||
|
||||
enum MapSortOrder {
|
||||
Group = 0,
|
||||
Area = 1,
|
||||
Layout = 2,
|
||||
SortByGroup = 0,
|
||||
SortByArea = 1,
|
||||
SortByLayout = 2,
|
||||
};
|
||||
|
||||
class KeyValueConfigBase
|
||||
|
@ -51,7 +51,7 @@ public:
|
|||
virtual void reset() override {
|
||||
this->recentProject = "";
|
||||
this->reopenOnLaunch = true;
|
||||
this->mapSortOrder = MapSortOrder::Group;
|
||||
this->mapSortOrder = MapSortOrder::SortByGroup;
|
||||
this->prettyCursors = true;
|
||||
this->collisionOpacity = 50;
|
||||
this->metatilesZoom = 30;
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
#include <QUndoCommand>
|
||||
#include <QList>
|
||||
|
||||
class MapPixmapItem;
|
||||
class Map;
|
||||
class Layout;
|
||||
class Blockdata;
|
||||
class Event;
|
||||
class DraggablePixmapItem;
|
||||
|
@ -43,7 +43,7 @@ enum CommandId {
|
|||
/// onto the map using the pencil tool.
|
||||
class PaintMetatile : public QUndoCommand {
|
||||
public:
|
||||
PaintMetatile(Map *map,
|
||||
PaintMetatile(Layout *layout,
|
||||
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
|
||||
unsigned actionId, QUndoCommand *parent = nullptr);
|
||||
|
||||
|
@ -54,7 +54,7 @@ public:
|
|||
int id() const override { return CommandId::ID_PaintMetatile; }
|
||||
|
||||
private:
|
||||
Map *map;
|
||||
Layout *layout;
|
||||
|
||||
Blockdata newMetatiles;
|
||||
Blockdata oldMetatiles;
|
||||
|
@ -68,10 +68,10 @@ private:
|
|||
/// on the metatile collision and elevation.
|
||||
class PaintCollision : public PaintMetatile {
|
||||
public:
|
||||
PaintCollision(Map *map,
|
||||
PaintCollision(Layout *layout,
|
||||
const Blockdata &oldCollision, const Blockdata &newCollision,
|
||||
unsigned actionId, QUndoCommand *parent = nullptr)
|
||||
: PaintMetatile(map, oldCollision, newCollision, actionId, parent) {
|
||||
: PaintMetatile(layout, oldCollision, newCollision, actionId, parent) {
|
||||
setText("Paint Collision");
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ public:
|
|||
/// Implements a command to commit paint actions on the map border.
|
||||
class PaintBorder : public QUndoCommand {
|
||||
public:
|
||||
PaintBorder(Map *map,
|
||||
PaintBorder(Layout *layout,
|
||||
const Blockdata &oldBorder, const Blockdata &newBorder,
|
||||
unsigned actionId, QUndoCommand *parent = nullptr);
|
||||
|
||||
|
@ -94,7 +94,7 @@ public:
|
|||
int id() const override { return CommandId::ID_PaintBorder; }
|
||||
|
||||
private:
|
||||
Map *map;
|
||||
Layout *layout;
|
||||
|
||||
Blockdata newBorder;
|
||||
Blockdata oldBorder;
|
||||
|
@ -108,10 +108,10 @@ private:
|
|||
/// with the bucket tool onto the map.
|
||||
class BucketFillMetatile : public PaintMetatile {
|
||||
public:
|
||||
BucketFillMetatile(Map *map,
|
||||
BucketFillMetatile(Layout *layout,
|
||||
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
|
||||
unsigned actionId, QUndoCommand *parent = nullptr)
|
||||
: PaintMetatile(map, oldMetatiles, newMetatiles, actionId, parent) {
|
||||
: PaintMetatile(layout, oldMetatiles, newMetatiles, actionId, parent) {
|
||||
setText("Bucket Fill Metatiles");
|
||||
}
|
||||
|
||||
|
@ -124,10 +124,10 @@ public:
|
|||
/// on the metatile collision and elevation.
|
||||
class BucketFillCollision : public PaintCollision {
|
||||
public:
|
||||
BucketFillCollision(Map *map,
|
||||
BucketFillCollision(Layout *layout,
|
||||
const Blockdata &oldCollision, const Blockdata &newCollision,
|
||||
QUndoCommand *parent = nullptr)
|
||||
: PaintCollision(map, oldCollision, newCollision, -1, parent) {
|
||||
: PaintCollision(layout, oldCollision, newCollision, -1, parent) {
|
||||
setText("Flood Fill Collision");
|
||||
}
|
||||
|
||||
|
@ -141,10 +141,10 @@ public:
|
|||
/// with the bucket or paint tool onto the map.
|
||||
class MagicFillMetatile : public PaintMetatile {
|
||||
public:
|
||||
MagicFillMetatile(Map *map,
|
||||
MagicFillMetatile(Layout *layout,
|
||||
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
|
||||
unsigned actionId, QUndoCommand *parent = nullptr)
|
||||
: PaintMetatile(map, oldMetatiles, newMetatiles, actionId, parent) {
|
||||
: PaintMetatile(layout, oldMetatiles, newMetatiles, actionId, parent) {
|
||||
setText("Magic Fill Metatiles");
|
||||
}
|
||||
|
||||
|
@ -156,10 +156,10 @@ public:
|
|||
/// Implements a command to commit magic fill collision actions.
|
||||
class MagicFillCollision : public PaintCollision {
|
||||
public:
|
||||
MagicFillCollision(Map *map,
|
||||
MagicFillCollision(Layout *layout,
|
||||
const Blockdata &oldCollision, const Blockdata &newCollision,
|
||||
QUndoCommand *parent = nullptr)
|
||||
: PaintCollision(map, oldCollision, newCollision, -1, parent) {
|
||||
: PaintCollision(layout, oldCollision, newCollision, -1, parent) {
|
||||
setText("Magic Fill Collision");
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ public:
|
|||
/// Implements a command to commit metatile shift actions.
|
||||
class ShiftMetatiles : public QUndoCommand {
|
||||
public:
|
||||
ShiftMetatiles(Map *map,
|
||||
ShiftMetatiles(Layout *layout,
|
||||
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
|
||||
unsigned actionId, QUndoCommand *parent = nullptr);
|
||||
|
||||
|
@ -183,7 +183,7 @@ public:
|
|||
int id() const override { return CommandId::ID_ShiftMetatiles; }
|
||||
|
||||
private:
|
||||
Map *map;
|
||||
Layout *layout= nullptr;
|
||||
|
||||
Blockdata newMetatiles;
|
||||
Blockdata oldMetatiles;
|
||||
|
@ -196,7 +196,7 @@ private:
|
|||
/// Implements a command to commit a map or border resize action.
|
||||
class ResizeMap : public QUndoCommand {
|
||||
public:
|
||||
ResizeMap(Map *map, QSize oldMapDimensions, QSize newMapDimensions,
|
||||
ResizeMap(Layout *layout, QSize oldMapDimensions, QSize newMapDimensions,
|
||||
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
|
||||
QSize oldBorderDimensions, QSize newBorderDimensions,
|
||||
const Blockdata &oldBorder, const Blockdata &newBorder,
|
||||
|
@ -209,7 +209,7 @@ public:
|
|||
int id() const override { return CommandId::ID_ResizeMap; }
|
||||
|
||||
private:
|
||||
Map *map;
|
||||
Layout *layout = nullptr;
|
||||
|
||||
int oldMapWidth;
|
||||
int oldMapHeight;
|
||||
|
@ -342,6 +342,7 @@ public:
|
|||
|
||||
|
||||
|
||||
// !TODO
|
||||
/// Implements a command to commit map edits from the scripting API.
|
||||
/// The scripting api can edit map/border blocks and dimensions.
|
||||
class ScriptEditMap : public QUndoCommand {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
// porymap will reflect changes to it, but the value is hard-coded in the projects at the moment
|
||||
#define BORDER_DISTANCE 7
|
||||
|
||||
class MapPixmapItem;
|
||||
class LayoutPixmapItem;
|
||||
class CollisionPixmapItem;
|
||||
class BorderMetatilesPixmapItem;
|
||||
|
||||
|
@ -58,7 +58,7 @@ public:
|
|||
|
||||
QMap<QString, QJsonValue> customHeaders;
|
||||
|
||||
MapLayout *layout;
|
||||
Layout *layout = nullptr;
|
||||
|
||||
bool isPersistedToFile = true;
|
||||
bool hasUnsavedDataChanges = false;
|
||||
|
@ -76,6 +76,7 @@ public:
|
|||
|
||||
QList<MapConnection*> connections;
|
||||
|
||||
// !TODO
|
||||
QList<int> metatileLayerOrder;
|
||||
QList<float> metatileLayerOpacity;
|
||||
|
||||
|
@ -92,17 +93,19 @@ public:
|
|||
void modify();
|
||||
void clean();
|
||||
|
||||
QPixmap render(bool ignoreCache = false, MapLayout *fromLayout = nullptr, QRect bounds = QRect(0, 0, -1, -1));
|
||||
QPixmap render(bool ignoreCache = false, Layout *fromLayout = nullptr, QRect bounds = QRect(0, 0, -1, -1));
|
||||
QPixmap renderCollision(bool ignoreCache);
|
||||
QPixmap renderConnection(MapConnection, MapLayout *);
|
||||
QPixmap renderConnection(MapConnection, Layout *);
|
||||
QPixmap renderBorder(bool ignoreCache = false);
|
||||
|
||||
bool mapBlockChanged(int i, const Blockdata &cache);
|
||||
bool borderBlockChanged(int i, const Blockdata &cache);
|
||||
|
||||
// !TODO: remove
|
||||
void cacheBlockdata();
|
||||
void cacheCollision();
|
||||
|
||||
/// !TODO: remove this
|
||||
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);
|
||||
|
@ -133,8 +136,11 @@ public:
|
|||
|
||||
void openScript(QString label);
|
||||
|
||||
MapPixmapItem *mapItem = nullptr;
|
||||
void setMapItem(MapPixmapItem *item) { mapItem = item; }
|
||||
private:
|
||||
LayoutPixmapItem *mapItem = nullptr;
|
||||
|
||||
public:
|
||||
void setMapItem(LayoutPixmapItem *item) { mapItem = item; }
|
||||
|
||||
CollisionPixmapItem *collisionItem = nullptr;
|
||||
void setCollisionItem(CollisionPixmapItem *item) { collisionItem = item; }
|
||||
|
|
|
@ -7,12 +7,17 @@
|
|||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
#include <QUndoStack>
|
||||
|
||||
class Map;
|
||||
class LayoutPixmapItem;
|
||||
class CollisionPixmapItem;
|
||||
class BorderMetatilesPixmapItem;
|
||||
|
||||
class MapLayout {
|
||||
class Layout : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
MapLayout() {}
|
||||
Layout() {}
|
||||
|
||||
static QString layoutConstantFromName(QString mapName);
|
||||
|
||||
|
@ -39,8 +44,12 @@ public:
|
|||
|
||||
Blockdata blockdata;
|
||||
|
||||
QImage image;
|
||||
QPixmap pixmap;
|
||||
QImage border_image;
|
||||
QPixmap border_pixmap;
|
||||
QImage collision_image;
|
||||
QPixmap collision_pixmap;
|
||||
|
||||
Blockdata border;
|
||||
Blockdata cached_blockdata;
|
||||
|
@ -53,10 +62,67 @@ public:
|
|||
QSize borderDimensions;
|
||||
} lastCommitBlocks; // to track map changes
|
||||
|
||||
QList<int> metatileLayerOrder;
|
||||
QList<float> metatileLayerOpacity;
|
||||
|
||||
LayoutPixmapItem *layoutItem = nullptr;
|
||||
CollisionPixmapItem *collisionItem = nullptr;
|
||||
BorderMetatilesPixmapItem *borderItem = nullptr;
|
||||
|
||||
QUndoStack editHistory;
|
||||
|
||||
public:
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
int getBorderWidth();
|
||||
int getBorderHeight();
|
||||
|
||||
bool isWithinBounds(int x, int y) {
|
||||
return (x >= 0 && x < this->getWidth() && y >= 0 && y < this->getHeight());
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
void modified();
|
||||
void layoutDimensionsChanged(const QSize &size);
|
||||
void needsRedrawing();
|
||||
};
|
||||
|
||||
using MapLayout = Layout;
|
||||
|
||||
#endif // MAPLAYOUT_H
|
||||
|
|
|
@ -10,7 +10,7 @@ class MapParser
|
|||
{
|
||||
public:
|
||||
MapParser();
|
||||
MapLayout *parse(QString filepath, bool *error, Project *project);
|
||||
Layout *parse(QString filepath, bool *error, Project *project);
|
||||
};
|
||||
|
||||
#endif // MAPPARSER_H
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "connectionpixmapitem.h"
|
||||
#include "currentselectedmetatilespixmapitem.h"
|
||||
#include "collisionpixmapitem.h"
|
||||
#include "mappixmapitem.h"
|
||||
#include "layoutpixmapitem.h"
|
||||
#include "settings.h"
|
||||
#include "movablerect.h"
|
||||
#include "cursortilerect.h"
|
||||
|
@ -46,7 +46,7 @@ public:
|
|||
|
||||
Project *project = nullptr;
|
||||
Map *map = nullptr;
|
||||
MapLayout *layout = nullptr; /* NEW */
|
||||
Layout *layout = nullptr; /* NEW */
|
||||
|
||||
QUndoGroup editGroup; // Manages the undo history for each map
|
||||
|
||||
|
@ -60,6 +60,7 @@ public:
|
|||
void closeProject();
|
||||
|
||||
bool setMap(QString map_name);
|
||||
void unsetMap();
|
||||
|
||||
Tileset *getCurrentMapPrimaryTileset();
|
||||
|
||||
|
@ -123,7 +124,7 @@ public:
|
|||
|
||||
QGraphicsScene *scene = nullptr;
|
||||
QGraphicsPixmapItem *current_view = nullptr;
|
||||
MapPixmapItem *map_item = nullptr;
|
||||
LayoutPixmapItem *map_item = nullptr;
|
||||
ConnectionPixmapItem* selected_connection_item = nullptr;
|
||||
QList<ConnectionPixmapItem*> connection_items;
|
||||
QGraphicsPathItem *connection_mask = nullptr;
|
||||
|
@ -201,11 +202,11 @@ private:
|
|||
qint64 *pid = nullptr);
|
||||
|
||||
private slots:
|
||||
void onMapStartPaint(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
||||
void onMapEndPaint(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
||||
void onMapStartPaint(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *item);
|
||||
void onMapEndPaint(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *item);
|
||||
void setSmartPathCursorMode(QGraphicsSceneMouseEvent *event);
|
||||
void setStraightPathCursorMode(QGraphicsSceneMouseEvent *event);
|
||||
void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
||||
void mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *item);
|
||||
void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item);
|
||||
void onConnectionMoved(MapConnection*);
|
||||
void onConnectionItemSelected(ConnectionPixmapItem* connectionItem);
|
||||
|
|
|
@ -164,8 +164,13 @@ public slots:
|
|||
private slots:
|
||||
void on_action_Open_Project_triggered();
|
||||
void on_action_Reload_Project_triggered();
|
||||
|
||||
void on_mapList_activated(const QModelIndex &index);
|
||||
void on_areaList_activated(const QModelIndex &index);
|
||||
void on_layoutList_activated(const QModelIndex &index);
|
||||
|
||||
void on_action_Save_Project_triggered();
|
||||
|
||||
void openWarpMap(QString map_name, int event_id, Event::Group event_group);
|
||||
|
||||
void duplicate();
|
||||
|
@ -229,6 +234,7 @@ private slots:
|
|||
void on_toolButton_Move_clicked();
|
||||
void on_toolButton_Shift_clicked();
|
||||
|
||||
void on_mapListContainer_currentChanged(int index);
|
||||
void onOpenMapListContextMenu(const QPoint &point);
|
||||
void onAddNewMapToGroupClick(QAction* triggeredAction);
|
||||
void onAddNewMapToAreaClick(QAction* triggeredAction);
|
||||
|
@ -310,6 +316,11 @@ private:
|
|||
|
||||
FilterChildrenProxyModel *groupListProxyModel;
|
||||
MapGroupModel *mapGroupModel;
|
||||
|
||||
FilterChildrenProxyModel *layoutListProxyModel;
|
||||
LayoutTreeModel *layoutTreeModel;
|
||||
|
||||
|
||||
// QStandardItemModel *mapListModel;
|
||||
// QList<QStandardItem*> *mapGroupItemsList;
|
||||
// QMap<QString, QModelIndex> mapListIndexes;
|
||||
|
@ -342,10 +353,14 @@ private:
|
|||
bool newMapDefaultsSet = false;
|
||||
|
||||
MapSortOrder mapSortOrder;
|
||||
enum MapListTab { Groups, Areas, Layouts };
|
||||
|
||||
bool tilesetNeedsRedraw = false;
|
||||
|
||||
bool setLayout(QString layoutName);
|
||||
|
||||
bool setMap(QString, bool scrollTreeView = false);
|
||||
void unsetMap();
|
||||
void redrawMapScene();
|
||||
void refreshMapScene();
|
||||
bool loadDataStructures();
|
||||
|
|
|
@ -56,8 +56,9 @@ public:
|
|||
QStringList mapLayoutsTable;
|
||||
QStringList mapLayoutsTableMaster;
|
||||
QString layoutsLabel;
|
||||
QMap<QString, MapLayout*> mapLayouts;
|
||||
QMap<QString, MapLayout*> mapLayoutsMaster;
|
||||
QMap<QString, QString> layoutIdsToNames;
|
||||
QMap<QString, Layout*> mapLayouts;
|
||||
QMap<QString, Layout*> mapLayoutsMaster;
|
||||
QMap<QString, QString> mapSecToMapHoverName;
|
||||
QMap<QString, int> mapSectionNameToValue;
|
||||
QMap<int, QString> mapSectionValueToName;
|
||||
|
@ -115,8 +116,8 @@ public:
|
|||
QStringList tilesetLabelsOrdered;
|
||||
|
||||
Blockdata readBlockdata(QString);
|
||||
bool loadBlockdata(MapLayout*);
|
||||
bool loadLayoutBorder(MapLayout*);
|
||||
bool loadBlockdata(Layout *);
|
||||
bool loadLayoutBorder(Layout *);
|
||||
|
||||
void saveTextFile(QString path, QString text);
|
||||
void appendTextFile(QString path, QString text);
|
||||
|
@ -128,6 +129,7 @@ public:
|
|||
QString getProjectTitle();
|
||||
|
||||
QString readMapLayoutId(QString map_name);
|
||||
QString readMapLayoutName(QString mapName);
|
||||
QString readMapLocation(QString map_name);
|
||||
|
||||
bool readWildMonData();
|
||||
|
@ -143,9 +145,9 @@ public:
|
|||
QSet<QString> getTopLevelMapFields();
|
||||
bool loadMapData(Map*);
|
||||
bool readMapLayouts();
|
||||
bool loadLayout(MapLayout *);
|
||||
bool loadLayout(Layout *);
|
||||
bool loadMapLayout(Map*);
|
||||
bool loadLayoutTilesets(MapLayout*);
|
||||
bool loadLayoutTilesets(Layout *);
|
||||
void loadTilesetAssets(Tileset*);
|
||||
void loadTilesetTiles(Tileset*, QImage);
|
||||
void loadTilesetMetatiles(Tileset*);
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
#ifndef BORDERMETATILESPIXMAPITEM_H
|
||||
#define BORDERMETATILESPIXMAPITEM_H
|
||||
|
||||
#include "map.h"
|
||||
#include "maplayout.h"
|
||||
#include "metatileselector.h"
|
||||
#include <QGraphicsPixmapItem>
|
||||
|
||||
class BorderMetatilesPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
BorderMetatilesPixmapItem(Map *map_, MetatileSelector *metatileSelector) {
|
||||
this->map = map_;
|
||||
this->map->setBorderItem(this);
|
||||
BorderMetatilesPixmapItem(Layout *layout, MetatileSelector *metatileSelector) {
|
||||
this->layout = layout;
|
||||
this->layout->setBorderItem(this);
|
||||
this->metatileSelector = metatileSelector;
|
||||
setAcceptHoverEvents(true);
|
||||
}
|
||||
MetatileSelector *metatileSelector;
|
||||
Map *map;
|
||||
Layout *layout;
|
||||
void draw();
|
||||
signals:
|
||||
void hoveredBorderMetatileSelectionChanged(uint16_t);
|
||||
|
|
|
@ -3,18 +3,18 @@
|
|||
|
||||
#include "metatileselector.h"
|
||||
#include "movementpermissionsselector.h"
|
||||
#include "mappixmapitem.h"
|
||||
#include "layoutpixmapitem.h"
|
||||
#include "map.h"
|
||||
#include "settings.h"
|
||||
|
||||
class CollisionPixmapItem : public MapPixmapItem {
|
||||
class CollisionPixmapItem : public LayoutPixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
CollisionPixmapItem(Map *map, MovementPermissionsSelector *movementPermissionsSelector, MetatileSelector *metatileSelector, Settings *settings, qreal *opacity)
|
||||
: MapPixmapItem(map, metatileSelector, settings){
|
||||
CollisionPixmapItem(Layout *layout, MovementPermissionsSelector *movementPermissionsSelector, MetatileSelector *metatileSelector, Settings *settings, qreal *opacity)
|
||||
: LayoutPixmapItem(layout, metatileSelector, settings){
|
||||
this->movementPermissionsSelector = movementPermissionsSelector;
|
||||
this->opacity = opacity;
|
||||
map->setCollisionItem(this);
|
||||
layout->setCollisionItem(this);
|
||||
}
|
||||
MovementPermissionsSelector *movementPermissionsSelector;
|
||||
qreal *opacity;
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#ifndef MAPPIXMAPITEM_H
|
||||
#define MAPPIXMAPITEM_H
|
||||
|
||||
#include "map.h"
|
||||
#include "settings.h"
|
||||
#include "metatileselector.h"
|
||||
#include <QGraphicsPixmapItem>
|
||||
|
||||
class MapPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
class Layout;
|
||||
|
||||
class LayoutPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
@ -18,37 +19,49 @@ public:
|
|||
Metatiles,
|
||||
EventObjects
|
||||
};
|
||||
MapPixmapItem(Map *map_, MetatileSelector *metatileSelector, Settings *settings) {
|
||||
this->map = map_;
|
||||
this->map->setMapItem(this);
|
||||
|
||||
LayoutPixmapItem(Layout *layout, MetatileSelector *metatileSelector, Settings *settings) {
|
||||
this->layout = layout;
|
||||
// this->map->setMapItem(this);
|
||||
this->metatileSelector = metatileSelector;
|
||||
this->settings = settings;
|
||||
this->paintingMode = PaintMode::Metatiles;
|
||||
this->lockedAxis = MapPixmapItem::Axis::None;
|
||||
this->lockedAxis = LayoutPixmapItem::Axis::None;
|
||||
this->prevStraightPathState = false;
|
||||
setAcceptHoverEvents(true);
|
||||
}
|
||||
MapPixmapItem::PaintMode paintingMode;
|
||||
Map *map;
|
||||
|
||||
LayoutPixmapItem::PaintMode paintingMode;
|
||||
|
||||
Layout *layout;
|
||||
|
||||
MetatileSelector *metatileSelector;
|
||||
|
||||
Settings *settings;
|
||||
|
||||
bool active;
|
||||
bool has_mouse = false;
|
||||
bool right_click;
|
||||
|
||||
int paint_tile_initial_x;
|
||||
int paint_tile_initial_y;
|
||||
bool prevStraightPathState;
|
||||
int straight_path_initial_x;
|
||||
int straight_path_initial_y;
|
||||
|
||||
QPoint metatilePos;
|
||||
|
||||
enum Axis {
|
||||
None = 0,
|
||||
X,
|
||||
Y
|
||||
};
|
||||
MapPixmapItem::Axis lockedAxis;
|
||||
|
||||
LayoutPixmapItem::Axis lockedAxis;
|
||||
|
||||
QPoint selection_origin;
|
||||
QList<QPoint> selection;
|
||||
|
||||
virtual void paint(QGraphicsSceneMouseEvent*);
|
||||
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
||||
virtual void magicFill(QGraphicsSceneMouseEvent*);
|
||||
|
@ -70,11 +83,13 @@ public:
|
|||
QList<CollisionSelectionItem> selectedCollisions,
|
||||
bool fromScriptCall = false);
|
||||
void floodFillSmartPath(int initialX, int initialY, bool fromScriptCall = false);
|
||||
|
||||
virtual void pick(QGraphicsSceneMouseEvent*);
|
||||
virtual void select(QGraphicsSceneMouseEvent*);
|
||||
virtual void shift(QGraphicsSceneMouseEvent*);
|
||||
void shift(int xDelta, int yDelta, bool fromScriptCall = false);
|
||||
virtual void draw(bool ignoreCache = false);
|
||||
|
||||
void updateMetatileSelection(QGraphicsSceneMouseEvent *event);
|
||||
void paintNormal(int x, int y, bool fromScriptCall = false);
|
||||
void lockNondominantAxis(QGraphicsSceneMouseEvent *event);
|
||||
|
@ -87,9 +102,9 @@ private:
|
|||
unsigned actionId_ = 0;
|
||||
|
||||
signals:
|
||||
void startPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *);
|
||||
void endPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *);
|
||||
void mouseEvent(QGraphicsSceneMouseEvent *, MapPixmapItem *);
|
||||
void startPaint(QGraphicsSceneMouseEvent *, LayoutPixmapItem *);
|
||||
void endPaint(QGraphicsSceneMouseEvent *, LayoutPixmapItem *);
|
||||
void mouseEvent(QGraphicsSceneMouseEvent *, LayoutPixmapItem *);
|
||||
void hoveredMapMetatileChanged(const QPoint &pos);
|
||||
void hoveredMapMetatileCleared();
|
||||
|
|
@ -46,10 +46,40 @@ private:
|
|||
|
||||
QString openMap;
|
||||
|
||||
// QIcon *mapIcon = nullptr;
|
||||
// QIcon *mapEditedIcon = nullptr;
|
||||
// QIcon *mapOpenedIcon = nullptr;
|
||||
// QIcon *mapFolderIcon = nullptr;
|
||||
signals:
|
||||
void edited();
|
||||
};
|
||||
|
||||
|
||||
|
||||
class LayoutTreeModel : public QStandardItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LayoutTreeModel(Project *project, QObject *parent = nullptr);
|
||||
~LayoutTreeModel() {}
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
public:
|
||||
void setLayout(QString layoutName) { this->openLayout = layoutName; }
|
||||
|
||||
QStandardItem *createLayoutItem(QString layoutName);
|
||||
QStandardItem *createMapItem(QString mapName);
|
||||
|
||||
QStandardItem *getItem(const QModelIndex &index) const;
|
||||
QModelIndex indexOfLayout(QString layoutName);
|
||||
|
||||
void initialize();
|
||||
|
||||
private:
|
||||
Project *project;
|
||||
QStandardItem *root = nullptr;
|
||||
|
||||
QMap<QString, QStandardItem *> layoutItems;
|
||||
QMap<QString, QStandardItem *> mapItems;
|
||||
|
||||
QString openLayout;
|
||||
|
||||
signals:
|
||||
void edited();
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
QString layoutId;
|
||||
void init();
|
||||
void init(MapSortOrder type, QVariant data);
|
||||
void init(MapLayout *);
|
||||
void init(Layout *);
|
||||
static void setDefaultSettings(Project *project);
|
||||
|
||||
signals:
|
||||
|
@ -37,7 +37,7 @@ private:
|
|||
bool checkNewMapGroup();
|
||||
void saveSettings();
|
||||
void useLayout(QString layoutId);
|
||||
void useLayoutSettings(MapLayout *mapLayout);
|
||||
void useLayoutSettings(Layout *mapLayout);
|
||||
|
||||
struct Settings {
|
||||
QString group;
|
||||
|
|
|
@ -61,7 +61,7 @@ SOURCES += src/core/block.cpp \
|
|||
src/ui/maplistmodels.cpp \
|
||||
src/ui/graphicsview.cpp \
|
||||
src/ui/imageproviders.cpp \
|
||||
src/ui/mappixmapitem.cpp \
|
||||
src/ui/layoutpixmapitem.cpp \
|
||||
src/ui/prefabcreationdialog.cpp \
|
||||
src/ui/regionmappixmapitem.cpp \
|
||||
src/ui/citymappixmapitem.cpp \
|
||||
|
@ -151,7 +151,7 @@ HEADERS += include/core/block.h \
|
|||
include/ui/maplistmodels.h \
|
||||
include/ui/graphicsview.h \
|
||||
include/ui/imageproviders.h \
|
||||
include/ui/mappixmapitem.h \
|
||||
include/ui/layoutpixmapitem.h \
|
||||
include/ui/mapview.h \
|
||||
include/ui/prefabcreationdialog.h \
|
||||
include/ui/regionmappixmapitem.h \
|
||||
|
|
|
@ -172,15 +172,15 @@ void KeyValueConfigBase::setSaveDisabled(bool disabled) {
|
|||
}
|
||||
|
||||
const QMap<MapSortOrder, QString> mapSortOrderMap = {
|
||||
{MapSortOrder::Group, "group"},
|
||||
{MapSortOrder::Layout, "layout"},
|
||||
{MapSortOrder::Area, "area"},
|
||||
{MapSortOrder::SortByGroup, "group"},
|
||||
{MapSortOrder::SortByLayout, "layout"},
|
||||
{MapSortOrder::SortByArea, "area"},
|
||||
};
|
||||
|
||||
const QMap<QString, MapSortOrder> mapSortOrderReverseMap = {
|
||||
{"group", MapSortOrder::Group},
|
||||
{"layout", MapSortOrder::Layout},
|
||||
{"area", MapSortOrder::Area},
|
||||
{"group", MapSortOrder::SortByGroup},
|
||||
{"layout", MapSortOrder::SortByLayout},
|
||||
{"area", MapSortOrder::SortByArea},
|
||||
};
|
||||
|
||||
PorymapConfig porymapConfig;
|
||||
|
@ -209,7 +209,7 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
|
|||
if (mapSortOrderReverseMap.contains(sortOrder)) {
|
||||
this->mapSortOrder = mapSortOrderReverseMap.value(sortOrder);
|
||||
} else {
|
||||
this->mapSortOrder = MapSortOrder::Group;
|
||||
this->mapSortOrder = MapSortOrder::SortByGroup;
|
||||
logWarn(QString("Invalid config value for map_sort_order: '%1'. Must be 'group', 'area', or 'layout'.").arg(value));
|
||||
}
|
||||
} else if (key == "main_window_geometry") {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "editcommands.h"
|
||||
#include "mappixmapitem.h"
|
||||
#include "draggablepixmapitem.h"
|
||||
#include "bordermetatilespixmapitem.h"
|
||||
#include "editor.h"
|
||||
|
@ -25,17 +24,18 @@ int getEventTypeMask(QList<Event *> events) {
|
|||
return eventTypeMask;
|
||||
}
|
||||
|
||||
void renderMapBlocks(Map *map, bool ignoreCache = false) {
|
||||
map->mapItem->draw(ignoreCache);
|
||||
map->collisionItem->draw(ignoreCache);
|
||||
/// !TODO:
|
||||
void renderBlocks(Layout *layout, bool ignoreCache = false) {
|
||||
layout->layoutItem->draw(ignoreCache);
|
||||
layout->collisionItem->draw(ignoreCache);
|
||||
}
|
||||
|
||||
PaintMetatile::PaintMetatile(Map *map,
|
||||
PaintMetatile::PaintMetatile(Layout *layout,
|
||||
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
|
||||
unsigned actionId, QUndoCommand *parent) : QUndoCommand(parent) {
|
||||
setText("Paint Metatiles");
|
||||
|
||||
this->map = map;
|
||||
this->layout = layout;
|
||||
this->oldMetatiles = oldMetatiles;
|
||||
this->newMetatiles = newMetatiles;
|
||||
|
||||
|
@ -45,23 +45,23 @@ PaintMetatile::PaintMetatile(Map *map,
|
|||
void PaintMetatile::redo() {
|
||||
QUndoCommand::redo();
|
||||
|
||||
if (!map) return;
|
||||
if (!layout) return;
|
||||
|
||||
map->setBlockdata(newMetatiles, true);
|
||||
layout->setBlockdata(newMetatiles, true);
|
||||
|
||||
map->layout->lastCommitBlocks.blocks = map->layout->blockdata;
|
||||
layout->lastCommitBlocks.blocks = layout->blockdata;
|
||||
|
||||
renderMapBlocks(map);
|
||||
renderBlocks(layout);
|
||||
}
|
||||
|
||||
void PaintMetatile::undo() {
|
||||
if (!map) return;
|
||||
if (!layout) return;
|
||||
|
||||
map->setBlockdata(oldMetatiles, true);
|
||||
layout->setBlockdata(oldMetatiles, true);
|
||||
|
||||
map->layout->lastCommitBlocks.blocks = map->layout->blockdata;
|
||||
layout->lastCommitBlocks.blocks = layout->blockdata;
|
||||
|
||||
renderMapBlocks(map);
|
||||
renderBlocks(layout);
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ void PaintMetatile::undo() {
|
|||
bool PaintMetatile::mergeWith(const QUndoCommand *command) {
|
||||
const PaintMetatile *other = static_cast<const PaintMetatile *>(command);
|
||||
|
||||
if (map != other->map)
|
||||
if (layout != other->layout)
|
||||
return false;
|
||||
|
||||
if (actionId != other->actionId)
|
||||
|
@ -84,12 +84,12 @@ bool PaintMetatile::mergeWith(const QUndoCommand *command) {
|
|||
************************************************************************
|
||||
******************************************************************************/
|
||||
|
||||
PaintBorder::PaintBorder(Map *map,
|
||||
PaintBorder::PaintBorder(Layout *layout,
|
||||
const Blockdata &oldBorder, const Blockdata &newBorder,
|
||||
unsigned actionId, QUndoCommand *parent) : QUndoCommand(parent) {
|
||||
setText("Paint Border");
|
||||
|
||||
this->map = map;
|
||||
this->layout = layout;
|
||||
this->oldBorder = oldBorder;
|
||||
this->newBorder = newBorder;
|
||||
|
||||
|
@ -99,23 +99,23 @@ PaintBorder::PaintBorder(Map *map,
|
|||
void PaintBorder::redo() {
|
||||
QUndoCommand::redo();
|
||||
|
||||
if (!map) return;
|
||||
if (!layout) return;
|
||||
|
||||
map->setBorderBlockData(newBorder, true);
|
||||
layout->setBorderBlockData(newBorder, true);
|
||||
|
||||
map->layout->lastCommitBlocks.border = map->layout->border;
|
||||
layout->lastCommitBlocks.border = layout->border;
|
||||
|
||||
map->borderItem->draw();
|
||||
layout->borderItem->draw();
|
||||
}
|
||||
|
||||
void PaintBorder::undo() {
|
||||
if (!map) return;
|
||||
if (!layout) return;
|
||||
|
||||
map->setBorderBlockData(oldBorder, true);
|
||||
layout->setBorderBlockData(oldBorder, true);
|
||||
|
||||
map->layout->lastCommitBlocks.border = map->layout->border;
|
||||
layout->lastCommitBlocks.border = layout->border;
|
||||
|
||||
map->borderItem->draw();
|
||||
layout->borderItem->draw();
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
@ -124,12 +124,12 @@ void PaintBorder::undo() {
|
|||
************************************************************************
|
||||
******************************************************************************/
|
||||
|
||||
ShiftMetatiles::ShiftMetatiles(Map *map,
|
||||
ShiftMetatiles::ShiftMetatiles(Layout *layout,
|
||||
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
|
||||
unsigned actionId, QUndoCommand *parent) : QUndoCommand(parent) {
|
||||
setText("Shift Metatiles");
|
||||
|
||||
this->map = map;
|
||||
this->layout = layout;
|
||||
this->oldMetatiles = oldMetatiles;
|
||||
this->newMetatiles = newMetatiles;
|
||||
|
||||
|
@ -139,23 +139,23 @@ ShiftMetatiles::ShiftMetatiles(Map *map,
|
|||
void ShiftMetatiles::redo() {
|
||||
QUndoCommand::redo();
|
||||
|
||||
if (!map) return;
|
||||
if (!layout) return;
|
||||
|
||||
map->setBlockdata(newMetatiles, true);
|
||||
layout->setBlockdata(newMetatiles, true);
|
||||
|
||||
map->layout->lastCommitBlocks.blocks = map->layout->blockdata;
|
||||
layout->lastCommitBlocks.blocks = layout->blockdata;
|
||||
|
||||
renderMapBlocks(map, true);
|
||||
renderBlocks(layout, true);
|
||||
}
|
||||
|
||||
void ShiftMetatiles::undo() {
|
||||
if (!map) return;
|
||||
if (!layout) return;
|
||||
|
||||
map->setBlockdata(oldMetatiles, true);
|
||||
layout->setBlockdata(oldMetatiles, true);
|
||||
|
||||
map->layout->lastCommitBlocks.blocks = map->layout->blockdata;
|
||||
layout->lastCommitBlocks.blocks = layout->blockdata;
|
||||
|
||||
renderMapBlocks(map, true);
|
||||
renderBlocks(layout, true);
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ void ShiftMetatiles::undo() {
|
|||
bool ShiftMetatiles::mergeWith(const QUndoCommand *command) {
|
||||
const ShiftMetatiles *other = static_cast<const ShiftMetatiles *>(command);
|
||||
|
||||
if (this->map != other->map)
|
||||
if (this->layout != other->layout)
|
||||
return false;
|
||||
|
||||
if (actionId != other->actionId)
|
||||
|
@ -178,14 +178,14 @@ bool ShiftMetatiles::mergeWith(const QUndoCommand *command) {
|
|||
************************************************************************
|
||||
******************************************************************************/
|
||||
|
||||
ResizeMap::ResizeMap(Map *map, QSize oldMapDimensions, QSize newMapDimensions,
|
||||
ResizeMap::ResizeMap(Layout *layout, QSize oldMapDimensions, QSize newMapDimensions,
|
||||
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
|
||||
QSize oldBorderDimensions, QSize newBorderDimensions,
|
||||
const Blockdata &oldBorder, const Blockdata &newBorder,
|
||||
QUndoCommand *parent) : QUndoCommand(parent) {
|
||||
setText("Resize Map");
|
||||
|
||||
this->map = map;
|
||||
this->layout = layout;
|
||||
|
||||
this->oldMapWidth = oldMapDimensions.width();
|
||||
this->oldMapHeight = oldMapDimensions.height();
|
||||
|
@ -209,33 +209,33 @@ ResizeMap::ResizeMap(Map *map, QSize oldMapDimensions, QSize newMapDimensions,
|
|||
void ResizeMap::redo() {
|
||||
QUndoCommand::redo();
|
||||
|
||||
if (!map) return;
|
||||
if (!layout) return;
|
||||
|
||||
map->layout->blockdata = newMetatiles;
|
||||
map->setDimensions(newMapWidth, newMapHeight, false, true);
|
||||
layout->blockdata = newMetatiles;
|
||||
layout->setDimensions(newMapWidth, newMapHeight, false, true);
|
||||
|
||||
map->layout->border = newBorder;
|
||||
map->setBorderDimensions(newBorderWidth, newBorderHeight, false, true);
|
||||
layout->border = newBorder;
|
||||
layout->setBorderDimensions(newBorderWidth, newBorderHeight, false, true);
|
||||
|
||||
map->layout->lastCommitBlocks.mapDimensions = QSize(map->getWidth(), map->getHeight());
|
||||
map->layout->lastCommitBlocks.borderDimensions = QSize(map->getBorderWidth(), map->getBorderHeight());
|
||||
layout->lastCommitBlocks.mapDimensions = QSize(layout->getWidth(), layout->getHeight());
|
||||
layout->lastCommitBlocks.borderDimensions = QSize(layout->getBorderWidth(), layout->getBorderHeight());
|
||||
|
||||
map->mapNeedsRedrawing();
|
||||
layout->needsRedrawing();
|
||||
}
|
||||
|
||||
void ResizeMap::undo() {
|
||||
if (!map) return;
|
||||
if (!layout) return;
|
||||
|
||||
map->layout->blockdata = oldMetatiles;
|
||||
map->setDimensions(oldMapWidth, oldMapHeight, false, true);
|
||||
layout->blockdata = oldMetatiles;
|
||||
layout->setDimensions(oldMapWidth, oldMapHeight, false, true);
|
||||
|
||||
map->layout->border = oldBorder;
|
||||
map->setBorderDimensions(oldBorderWidth, oldBorderHeight, false, true);
|
||||
layout->border = oldBorder;
|
||||
layout->setBorderDimensions(oldBorderWidth, oldBorderHeight, false, true);
|
||||
|
||||
map->layout->lastCommitBlocks.mapDimensions = QSize(map->getWidth(), map->getHeight());
|
||||
map->layout->lastCommitBlocks.borderDimensions = QSize(map->getBorderWidth(), map->getBorderHeight());
|
||||
layout->lastCommitBlocks.mapDimensions = QSize(layout->getWidth(), layout->getHeight());
|
||||
layout->lastCommitBlocks.borderDimensions = QSize(layout->getBorderWidth(), layout->getBorderHeight());
|
||||
|
||||
map->mapNeedsRedrawing();
|
||||
layout->needsRedrawing();
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
@ -538,7 +538,8 @@ void ScriptEditMap::redo() {
|
|||
map->layout->lastCommitBlocks.border = newBorder;
|
||||
map->layout->lastCommitBlocks.borderDimensions = QSize(newBorderWidth, newBorderHeight);
|
||||
|
||||
renderMapBlocks(map);
|
||||
// !TODO
|
||||
renderBlocks(map->layout);
|
||||
map->borderItem->draw();
|
||||
}
|
||||
|
||||
|
@ -564,7 +565,8 @@ void ScriptEditMap::undo() {
|
|||
map->layout->lastCommitBlocks.border = oldBorder;
|
||||
map->layout->lastCommitBlocks.borderDimensions = QSize(oldBorderWidth, oldBorderHeight);
|
||||
|
||||
renderMapBlocks(map);
|
||||
// !TODO
|
||||
renderBlocks(map->layout);
|
||||
map->borderItem->draw();
|
||||
|
||||
QUndoCommand::undo();
|
||||
|
|
|
@ -133,48 +133,8 @@ QPixmap Map::renderCollision(bool ignoreCache) {
|
|||
return collision_pixmap;
|
||||
}
|
||||
|
||||
QPixmap Map::render(bool ignoreCache, MapLayout * fromLayout, QRect bounds) {
|
||||
bool changed_any = false;
|
||||
int width_ = getWidth();
|
||||
int height_ = getHeight();
|
||||
if (image.isNull() || image.width() != width_ * 16 || image.height() != height_ * 16) {
|
||||
image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||
changed_any = true;
|
||||
}
|
||||
if (layout->blockdata.isEmpty() || !width_ || !height_) {
|
||||
pixmap = pixmap.fromImage(image);
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
QPainter painter(&image);
|
||||
for (int i = 0; i < layout->blockdata.length(); i++) {
|
||||
if (!ignoreCache && !mapBlockChanged(i, layout->cached_blockdata)) {
|
||||
continue;
|
||||
}
|
||||
changed_any = true;
|
||||
int map_y = width_ ? i / width_ : 0;
|
||||
int map_x = width_ ? i % width_ : 0;
|
||||
if (bounds.isValid() && !bounds.contains(map_x, map_y)) {
|
||||
continue;
|
||||
}
|
||||
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
|
||||
Block block = layout->blockdata.at(i);
|
||||
QImage metatile_image = getMetatileImage(
|
||||
block.metatileId,
|
||||
fromLayout ? fromLayout->tileset_primary : layout->tileset_primary,
|
||||
fromLayout ? fromLayout->tileset_secondary : layout->tileset_secondary,
|
||||
metatileLayerOrder,
|
||||
metatileLayerOpacity
|
||||
);
|
||||
painter.drawImage(metatile_origin, metatile_image);
|
||||
}
|
||||
painter.end();
|
||||
if (changed_any) {
|
||||
cacheBlockdata();
|
||||
pixmap = pixmap.fromImage(image);
|
||||
}
|
||||
|
||||
return pixmap;
|
||||
QPixmap Map::render(bool ignoreCache, Layout *fromLayout, QRect bounds) {
|
||||
return this->layout->render(ignoreCache, fromLayout, bounds);
|
||||
}
|
||||
|
||||
QPixmap Map::renderBorder(bool ignoreCache) {
|
||||
|
@ -215,7 +175,7 @@ QPixmap Map::renderBorder(bool ignoreCache) {
|
|||
return layout->border_pixmap;
|
||||
}
|
||||
|
||||
QPixmap Map::renderConnection(MapConnection connection, MapLayout * fromLayout) {
|
||||
QPixmap Map::renderConnection(MapConnection connection, Layout *fromLayout) {
|
||||
int x, y, w, h;
|
||||
if (connection.direction == "up") {
|
||||
x = 0;
|
||||
|
@ -245,9 +205,10 @@ QPixmap Map::renderConnection(MapConnection connection, MapLayout * fromLayout)
|
|||
h = getHeight();
|
||||
}
|
||||
|
||||
render(true, fromLayout, QRect(x, y, w, h));
|
||||
QImage connection_image = image.copy(x * 16, y * 16, w * 16, h * 16);
|
||||
return QPixmap::fromImage(connection_image);
|
||||
//render(true, fromLayout, QRect(x, y, w, h));
|
||||
//QImage connection_image = image.copy(x * 16, y * 16, w * 16, h * 16);
|
||||
return render(true, fromLayout, QRect(x, y, w, h)).copy(x * 16, y * 16, w * 16, h * 16);
|
||||
//return QPixmap::fromImage(connection_image);
|
||||
}
|
||||
|
||||
void Map::setNewDimensionsBlockdata(int newWidth, int newHeight) {
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
#include <QRegularExpression>
|
||||
|
||||
QString MapLayout::layoutConstantFromName(QString mapName) {
|
||||
#include "scripting.h"
|
||||
#include "imageproviders.h"
|
||||
|
||||
QString Layout::layoutConstantFromName(QString mapName) {
|
||||
// Transform map names of the form 'GraniteCave_B1F` into layout constants like 'LAYOUT_GRANITE_CAVE_B1F'.
|
||||
static const QRegularExpression caseChange("([a-z])([A-Z])");
|
||||
QString nameWithUnderscores = mapName.replace(caseChange, "\\1_\\2");
|
||||
|
@ -17,18 +20,363 @@ QString MapLayout::layoutConstantFromName(QString mapName) {
|
|||
return constantName;
|
||||
}
|
||||
|
||||
int MapLayout::getWidth() {
|
||||
int Layout::getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
int MapLayout::getHeight() {
|
||||
int Layout::getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
int MapLayout::getBorderWidth() {
|
||||
int Layout::getBorderWidth() {
|
||||
return border_width;
|
||||
}
|
||||
|
||||
int MapLayout::getBorderHeight() {
|
||||
int Layout::getBorderHeight() {
|
||||
return border_height;
|
||||
}
|
||||
|
||||
bool Layout::getBlock(int x, int y, Block *out) {
|
||||
if (isWithinBounds(x, y)) {
|
||||
int i = y * getWidth() + x;
|
||||
*out = this->blockdata.value(i);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Layout::setBlock(int x, int y, Block block, bool enableScriptCallback) {
|
||||
if (!isWithinBounds(x, y)) return;
|
||||
int i = y * getWidth() + x;
|
||||
if (i < this->blockdata.size()) {
|
||||
Block prevBlock = this->blockdata.at(i);
|
||||
this->blockdata.replace(i, block);
|
||||
if (enableScriptCallback) {
|
||||
Scripting::cb_MetatileChanged(x, y, prevBlock, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Layout::setBlockdata(Blockdata newBlockdata, bool enableScriptCallback) {
|
||||
int width = getWidth();
|
||||
int size = qMin(newBlockdata.size(), this->blockdata.size());
|
||||
for (int i = 0; i < size; i++) {
|
||||
Block prevBlock = this->blockdata.at(i);
|
||||
Block newBlock = newBlockdata.at(i);
|
||||
if (prevBlock != newBlock) {
|
||||
this->blockdata.replace(i, newBlock);
|
||||
if (enableScriptCallback)
|
||||
Scripting::cb_MetatileChanged(i % width, i / width, prevBlock, newBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Layout::clearBorderCache() {
|
||||
this->cached_border.clear();
|
||||
}
|
||||
|
||||
void Layout::cacheBorder() {
|
||||
this->cached_border.clear();
|
||||
for (const auto &block : this->border)
|
||||
this->cached_border.append(block);
|
||||
}
|
||||
|
||||
void Layout::cacheBlockdata() {
|
||||
this->cached_blockdata.clear();
|
||||
for (const auto &block : this->blockdata)
|
||||
this->cached_blockdata.append(block);
|
||||
}
|
||||
|
||||
void Layout::cacheCollision() {
|
||||
this->cached_collision.clear();
|
||||
for (const auto &block : this->blockdata)
|
||||
this->cached_collision.append(block);
|
||||
}
|
||||
|
||||
bool Layout::layoutBlockChanged(int i, const Blockdata &cache) {
|
||||
if (cache.length() <= i)
|
||||
return true;
|
||||
if (this->blockdata.length() <= i)
|
||||
return true;
|
||||
|
||||
return this->blockdata.at(i) != cache.at(i);
|
||||
}
|
||||
|
||||
uint16_t Layout::getBorderMetatileId(int x, int y) {
|
||||
int i = y * getBorderWidth() + x;
|
||||
return this->border[i].metatileId;
|
||||
}
|
||||
|
||||
void Layout::setBorderMetatileId(int x, int y, uint16_t metatileId, bool enableScriptCallback) {
|
||||
int i = y * getBorderWidth() + x;
|
||||
if (i < this->border.size()) {
|
||||
uint16_t prevMetatileId = this->border[i].metatileId;
|
||||
this->border[i].metatileId = metatileId;
|
||||
if (prevMetatileId != metatileId && enableScriptCallback) {
|
||||
Scripting::cb_BorderMetatileChanged(x, y, prevMetatileId, metatileId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Layout::setBorderBlockData(Blockdata newBlockdata, bool enableScriptCallback) {
|
||||
int width = getBorderWidth();
|
||||
int size = qMin(newBlockdata.size(), this->border.size());
|
||||
for (int i = 0; i < size; i++) {
|
||||
Block prevBlock = this->border.at(i);
|
||||
Block newBlock = newBlockdata.at(i);
|
||||
if (prevBlock != newBlock) {
|
||||
this->border.replace(i, newBlock);
|
||||
if (enableScriptCallback)
|
||||
Scripting::cb_BorderMetatileChanged(i % width, i / width, prevBlock.metatileId, newBlock.metatileId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Layout::setDimensions(int newWidth, int newHeight, bool setNewBlockdata, bool enableScriptCallback) {
|
||||
if (setNewBlockdata) {
|
||||
setNewDimensionsBlockdata(newWidth, newHeight);
|
||||
}
|
||||
|
||||
int oldWidth = this->width;
|
||||
int oldHeight = this->height;
|
||||
this->width = newWidth;
|
||||
this->height = newHeight;
|
||||
|
||||
if (enableScriptCallback && (oldWidth != newWidth || oldHeight != newHeight)) {
|
||||
Scripting::cb_MapResized(oldWidth, oldHeight, newWidth, newHeight);
|
||||
}
|
||||
|
||||
emit layoutChanged(this);
|
||||
emit layoutDimensionsChanged(QSize(getWidth(), getHeight()));
|
||||
}
|
||||
|
||||
void Layout::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata, bool enableScriptCallback) {
|
||||
if (setNewBlockdata) {
|
||||
setNewBorderDimensionsBlockdata(newWidth, newHeight);
|
||||
}
|
||||
|
||||
int oldWidth = this->border_width;
|
||||
int oldHeight = this->border_height;
|
||||
this->border_width = newWidth;
|
||||
this->border_height = newHeight;
|
||||
|
||||
if (enableScriptCallback && (oldWidth != newWidth || oldHeight != newHeight)) {
|
||||
Scripting::cb_BorderResized(oldWidth, oldHeight, newWidth, newHeight);
|
||||
}
|
||||
|
||||
emit layoutChanged(this);
|
||||
}
|
||||
|
||||
void Layout::setNewDimensionsBlockdata(int newWidth, int newHeight) {
|
||||
int oldWidth = getWidth();
|
||||
int oldHeight = getHeight();
|
||||
|
||||
Blockdata newBlockdata;
|
||||
|
||||
for (int y = 0; y < newHeight; y++)
|
||||
for (int x = 0; x < newWidth; x++) {
|
||||
if (x < oldWidth && y < oldHeight) {
|
||||
int index = y * oldWidth + x;
|
||||
newBlockdata.append(this->blockdata.value(index));
|
||||
} else {
|
||||
newBlockdata.append(0);
|
||||
}
|
||||
}
|
||||
|
||||
this->blockdata = newBlockdata;
|
||||
}
|
||||
|
||||
void Layout::setNewBorderDimensionsBlockdata(int newWidth, int newHeight) {
|
||||
int oldWidth = getBorderWidth();
|
||||
int oldHeight = getBorderHeight();
|
||||
|
||||
Blockdata newBlockdata;
|
||||
|
||||
for (int y = 0; y < newHeight; y++)
|
||||
for (int x = 0; x < newWidth; x++) {
|
||||
if (x < oldWidth && y < oldHeight) {
|
||||
int index = y * oldWidth + x;
|
||||
newBlockdata.append(this->border.value(index));
|
||||
} else {
|
||||
newBlockdata.append(0);
|
||||
}
|
||||
}
|
||||
|
||||
this->border = newBlockdata;
|
||||
}
|
||||
|
||||
void Layout::_floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation) {
|
||||
QList<QPoint> todo;
|
||||
todo.append(QPoint(x, y));
|
||||
while (todo.length()) {
|
||||
QPoint point = todo.takeAt(0);
|
||||
x = point.x();
|
||||
y = point.y();
|
||||
Block block;
|
||||
if (!getBlock(x, y, &block)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
uint old_coll = block.collision;
|
||||
uint old_elev = block.elevation;
|
||||
if (old_coll == collision && old_elev == elevation) {
|
||||
continue;
|
||||
}
|
||||
|
||||
block.collision = collision;
|
||||
block.elevation = elevation;
|
||||
setBlock(x, y, block, true);
|
||||
if (getBlock(x + 1, y, &block) && block.collision == old_coll && block.elevation == old_elev) {
|
||||
todo.append(QPoint(x + 1, y));
|
||||
}
|
||||
if (getBlock(x - 1, y, &block) && block.collision == old_coll && block.elevation == old_elev) {
|
||||
todo.append(QPoint(x - 1, y));
|
||||
}
|
||||
if (getBlock(x, y + 1, &block) && block.collision == old_coll && block.elevation == old_elev) {
|
||||
todo.append(QPoint(x, y + 1));
|
||||
}
|
||||
if (getBlock(x, y - 1, &block) && block.collision == old_coll && block.elevation == old_elev) {
|
||||
todo.append(QPoint(x, y - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Layout::floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation) {
|
||||
Block block;
|
||||
if (getBlock(x, y, &block) && (block.collision != collision || block.elevation != elevation)) {
|
||||
_floodFillCollisionElevation(x, y, collision, elevation);
|
||||
}
|
||||
}
|
||||
|
||||
void Layout::magicFillCollisionElevation(int initialX, int initialY, uint16_t collision, uint16_t elevation) {
|
||||
Block block;
|
||||
if (getBlock(initialX, initialY, &block) && (block.collision != collision || block.elevation != elevation)) {
|
||||
uint old_coll = block.collision;
|
||||
uint old_elev = block.elevation;
|
||||
|
||||
for (int y = 0; y < getHeight(); y++) {
|
||||
for (int x = 0; x < getWidth(); x++) {
|
||||
if (getBlock(x, y, &block) && block.collision == old_coll && block.elevation == old_elev) {
|
||||
block.collision = collision;
|
||||
block.elevation = elevation;
|
||||
setBlock(x, y, block, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QPixmap Layout::render(bool ignoreCache, Layout *fromLayout, QRect bounds) {
|
||||
bool changed_any = false;
|
||||
int width_ = getWidth();
|
||||
int height_ = getHeight();
|
||||
if (image.isNull() || image.width() != width_ * 16 || image.height() != height_ * 16) {
|
||||
image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||
changed_any = true;
|
||||
}
|
||||
if (this->blockdata.isEmpty() || !width_ || !height_) {
|
||||
pixmap = pixmap.fromImage(image);
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
QPainter painter(&image);
|
||||
for (int i = 0; i < this->blockdata.length(); i++) {
|
||||
if (!ignoreCache && !layoutBlockChanged(i, this->cached_blockdata)) {
|
||||
continue;
|
||||
}
|
||||
changed_any = true;
|
||||
int map_y = width_ ? i / width_ : 0;
|
||||
int map_x = width_ ? i % width_ : 0;
|
||||
if (bounds.isValid() && !bounds.contains(map_x, map_y)) {
|
||||
continue;
|
||||
}
|
||||
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
|
||||
Block block = this->blockdata.at(i);
|
||||
QImage metatile_image = getMetatileImage(
|
||||
block.metatileId,
|
||||
fromLayout ? fromLayout->tileset_primary : this->tileset_primary,
|
||||
fromLayout ? fromLayout->tileset_secondary : this->tileset_secondary,
|
||||
metatileLayerOrder,
|
||||
metatileLayerOpacity
|
||||
);
|
||||
painter.drawImage(metatile_origin, metatile_image);
|
||||
}
|
||||
painter.end();
|
||||
if (changed_any) {
|
||||
cacheBlockdata();
|
||||
pixmap = pixmap.fromImage(image);
|
||||
}
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
QPixmap Layout::renderCollision(bool ignoreCache) {
|
||||
bool changed_any = false;
|
||||
int width_ = getWidth();
|
||||
int height_ = getHeight();
|
||||
if (collision_image.isNull() || collision_image.width() != width_ * 16 || collision_image.height() != height_ * 16) {
|
||||
collision_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||
changed_any = true;
|
||||
}
|
||||
if (this->blockdata.isEmpty() || !width_ || !height_) {
|
||||
collision_pixmap = collision_pixmap.fromImage(collision_image);
|
||||
return collision_pixmap;
|
||||
}
|
||||
QPainter painter(&collision_image);
|
||||
for (int i = 0; i < this->blockdata.length(); i++) {
|
||||
if (!ignoreCache && !layoutBlockChanged(i, this->cached_collision)) {
|
||||
continue;
|
||||
}
|
||||
changed_any = true;
|
||||
Block block = this->blockdata.at(i);
|
||||
QImage collision_metatile_image = getCollisionMetatileImage(block);
|
||||
int map_y = width_ ? i / width_ : 0;
|
||||
int map_x = width_ ? i % width_ : 0;
|
||||
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
|
||||
painter.drawImage(metatile_origin, collision_metatile_image);
|
||||
}
|
||||
painter.end();
|
||||
cacheCollision();
|
||||
if (changed_any) {
|
||||
collision_pixmap = collision_pixmap.fromImage(collision_image);
|
||||
}
|
||||
return collision_pixmap;
|
||||
}
|
||||
|
||||
QPixmap Layout::renderBorder(bool ignoreCache) {
|
||||
bool changed_any = false, border_resized = false;
|
||||
int width_ = getBorderWidth();
|
||||
int height_ = getBorderHeight();
|
||||
if (this->border_image.isNull()) {
|
||||
this->border_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||
changed_any = true;
|
||||
}
|
||||
if (this->border_image.width() != width_ * 16 || this->border_image.height() != height_ * 16) {
|
||||
this->border_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||
border_resized = true;
|
||||
}
|
||||
if (this->border.isEmpty()) {
|
||||
this->border_pixmap = this->border_pixmap.fromImage(this->border_image);
|
||||
return this->border_pixmap;
|
||||
}
|
||||
QPainter painter(&this->border_image);
|
||||
for (int i = 0; i < this->border.length(); i++) {
|
||||
if (!ignoreCache && (!border_resized && !layoutBlockChanged(i, this->cached_border))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
changed_any = true;
|
||||
Block block = this->border.at(i);
|
||||
uint16_t metatileId = block.metatileId;
|
||||
QImage metatile_image = getMetatileImage(metatileId, this->tileset_primary, this->tileset_secondary, metatileLayerOrder, metatileLayerOpacity);
|
||||
int map_y = width_ ? i / width_ : 0;
|
||||
int map_x = width_ ? i % width_ : 0;
|
||||
painter.drawImage(QPoint(map_x * 16, map_y * 16), metatile_image);
|
||||
}
|
||||
painter.end();
|
||||
if (changed_any) {
|
||||
cacheBorder();
|
||||
this->border_pixmap = this->border_pixmap.fromImage(this->border_image);
|
||||
}
|
||||
return this->border_pixmap;
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ void Editor::closeProject() {
|
|||
void Editor::setEditingMap() {
|
||||
current_view = map_item;
|
||||
if (map_item) {
|
||||
map_item->paintingMode = MapPixmapItem::PaintMode::Metatiles;
|
||||
map_item->paintingMode = LayoutPixmapItem::PaintMode::Metatiles;
|
||||
displayMapConnections();
|
||||
map_item->draw();
|
||||
map_item->setVisible(true);
|
||||
|
@ -133,7 +133,8 @@ void Editor::setEditingObjects() {
|
|||
events_group->setVisible(true);
|
||||
}
|
||||
if (map_item) {
|
||||
map_item->paintingMode = MapPixmapItem::PaintMode::EventObjects;
|
||||
// !TODO: change this pixmapitem paintmode
|
||||
map_item->paintingMode = LayoutPixmapItem::PaintMode::EventObjects;
|
||||
displayMapConnections();
|
||||
map_item->draw();
|
||||
map_item->setVisible(true);
|
||||
|
@ -169,7 +170,7 @@ void Editor::setMapEditingButtonsEnabled(bool enabled) {
|
|||
void Editor::setEditingConnections() {
|
||||
current_view = map_item;
|
||||
if (map_item) {
|
||||
map_item->paintingMode = MapPixmapItem::PaintMode::Disabled;
|
||||
map_item->paintingMode = LayoutPixmapItem::PaintMode::Disabled;
|
||||
map_item->draw();
|
||||
map_item->setVisible(true);
|
||||
populateConnectionMapPickers();
|
||||
|
@ -1020,7 +1021,7 @@ void Editor::onHoveredMapMetatileChanged(const QPoint &pos) {
|
|||
return;
|
||||
|
||||
this->updateCursorRectPos(x, y);
|
||||
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles) {
|
||||
if (map_item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) {
|
||||
int blockIndex = y * map->getWidth() + x;
|
||||
int metatileId = map->layout->blockdata.at(blockIndex).metatileId;
|
||||
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, %3, Scale = %4x")
|
||||
|
@ -1029,7 +1030,7 @@ void Editor::onHoveredMapMetatileChanged(const QPoint &pos) {
|
|||
.arg(getMetatileDisplayMessage(metatileId))
|
||||
.arg(QString::number(zoomLevels[this->scaleIndex], 'g', 2)));
|
||||
}
|
||||
else if (map_item->paintingMode == MapPixmapItem::PaintMode::EventObjects) {
|
||||
else if (map_item->paintingMode == LayoutPixmapItem::PaintMode::EventObjects) {
|
||||
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, Scale = %3x")
|
||||
.arg(x)
|
||||
.arg(y)
|
||||
|
@ -1040,8 +1041,8 @@ void Editor::onHoveredMapMetatileChanged(const QPoint &pos) {
|
|||
|
||||
void Editor::onHoveredMapMetatileCleared() {
|
||||
this->setCursorRectVisible(false);
|
||||
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles
|
||||
|| map_item->paintingMode == MapPixmapItem::PaintMode::EventObjects) {
|
||||
if (map_item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles
|
||||
|| map_item->paintingMode == LayoutPixmapItem::PaintMode::EventObjects) {
|
||||
this->ui->statusBar->clearMessage();
|
||||
}
|
||||
Scripting::cb_BlockHoverCleared();
|
||||
|
@ -1052,7 +1053,7 @@ void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
|
|||
return;
|
||||
|
||||
this->updateCursorRectPos(x, y);
|
||||
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles) {
|
||||
if (map_item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) {
|
||||
int blockIndex = y * map->getWidth() + x;
|
||||
uint16_t collision = map->layout->blockdata.at(blockIndex).collision;
|
||||
uint16_t elevation = map->layout->blockdata.at(blockIndex).elevation;
|
||||
|
@ -1067,7 +1068,7 @@ void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
|
|||
|
||||
void Editor::onHoveredMapMovementPermissionCleared() {
|
||||
this->setCursorRectVisible(false);
|
||||
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles) {
|
||||
if (map_item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) {
|
||||
this->ui->statusBar->clearMessage();
|
||||
}
|
||||
Scripting::cb_BlockHoverCleared();
|
||||
|
@ -1089,16 +1090,22 @@ QString Editor::getMovementPermissionText(uint16_t collision, uint16_t elevation
|
|||
return message;
|
||||
}
|
||||
|
||||
void Editor::unsetMap() {
|
||||
// disconnect previous map's signals so they are not firing
|
||||
// multiple times if set again in the future
|
||||
if (this->map) {
|
||||
this->map->disconnect(this);
|
||||
}
|
||||
|
||||
this->map = nullptr;
|
||||
}
|
||||
|
||||
bool Editor::setMap(QString map_name) {
|
||||
if (map_name.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// disconnect previous map's signals so they are not firing
|
||||
// multiple times if set again in the future
|
||||
if (map) {
|
||||
map->disconnect(this);
|
||||
}
|
||||
unsetMap();
|
||||
|
||||
if (project) {
|
||||
Map *loadedMap = project->loadMap(map_name);
|
||||
|
@ -1107,6 +1114,7 @@ bool Editor::setMap(QString map_name) {
|
|||
}
|
||||
|
||||
map = loadedMap;
|
||||
this->layout = map->layout; // !TODO:
|
||||
|
||||
editGroup.addStack(&map->editHistory);
|
||||
editGroup.setActiveStack(&map->editHistory);
|
||||
|
@ -1123,8 +1131,8 @@ bool Editor::setMap(QString map_name) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Editor::onMapStartPaint(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) {
|
||||
if (item->paintingMode != MapPixmapItem::PaintMode::Metatiles) {
|
||||
void Editor::onMapStartPaint(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *item) {
|
||||
if (item->paintingMode != LayoutPixmapItem::PaintMode::Metatiles) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1136,8 +1144,8 @@ void Editor::onMapStartPaint(QGraphicsSceneMouseEvent *event, MapPixmapItem *ite
|
|||
}
|
||||
}
|
||||
|
||||
void Editor::onMapEndPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *item) {
|
||||
if (!(item->paintingMode == MapPixmapItem::PaintMode::Metatiles)) {
|
||||
void Editor::onMapEndPaint(QGraphicsSceneMouseEvent *, LayoutPixmapItem *item) {
|
||||
if (!(item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles)) {
|
||||
return;
|
||||
}
|
||||
this->cursorMapTileRect->stopRightClickSelectionAnchor();
|
||||
|
@ -1170,15 +1178,15 @@ void Editor::setStraightPathCursorMode(QGraphicsSceneMouseEvent *event) {
|
|||
}
|
||||
}
|
||||
|
||||
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) {
|
||||
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *item) {
|
||||
// TODO: add event tab object painting tool buttons stuff here
|
||||
if (item->paintingMode == MapPixmapItem::PaintMode::Disabled) {
|
||||
if (item->paintingMode == LayoutPixmapItem::PaintMode::Disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
|
||||
if (item->paintingMode == MapPixmapItem::PaintMode::Metatiles) {
|
||||
if (item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) {
|
||||
if (map_edit_mode == "paint") {
|
||||
if (event->buttons() & Qt::RightButton) {
|
||||
item->updateMetatileSelection(event);
|
||||
|
@ -1225,7 +1233,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
|||
}
|
||||
item->shift(event);
|
||||
}
|
||||
} else if (item->paintingMode == MapPixmapItem::PaintMode::EventObjects) {
|
||||
} else if (item->paintingMode == LayoutPixmapItem::PaintMode::EventObjects) {
|
||||
if (obj_edit_mode == "paint" && event->type() == QEvent::GraphicsSceneMousePress) {
|
||||
// Right-clicking while in paint mode will change mode to select.
|
||||
if (event->buttons() & Qt::RightButton) {
|
||||
|
@ -1253,7 +1261,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
|||
}
|
||||
} else if (obj_edit_mode == "select") {
|
||||
// do nothing here, at least for now
|
||||
} else if (obj_edit_mode == "shift" && item->map) {
|
||||
} else if (obj_edit_mode == "shift") {
|
||||
static QPoint selection_origin;
|
||||
static unsigned actionId = 0;
|
||||
|
||||
|
@ -1269,8 +1277,8 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
|||
|
||||
QList<Event *> selectedEvents;
|
||||
|
||||
for (DraggablePixmapItem *item : getObjects()) {
|
||||
selectedEvents.append(item->event);
|
||||
for (DraggablePixmapItem *pixmapItem : getObjects()) {
|
||||
selectedEvents.append(pixmapItem->event);
|
||||
}
|
||||
selection_origin = QPoint(pos.x(), pos.y());
|
||||
|
||||
|
@ -1283,7 +1291,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
|||
}
|
||||
|
||||
void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item) {
|
||||
if (item->paintingMode != MapPixmapItem::PaintMode::Metatiles) {
|
||||
if (item->paintingMode != LayoutPixmapItem::PaintMode::Metatiles) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1400,12 +1408,12 @@ void Editor::displayMetatileSelector() {
|
|||
}
|
||||
|
||||
void Editor::displayMapMetatiles() {
|
||||
map_item = new MapPixmapItem(map, this->metatile_selector_item, this->settings);
|
||||
connect(map_item, &MapPixmapItem::mouseEvent, this, &Editor::mouseEvent_map);
|
||||
connect(map_item, &MapPixmapItem::startPaint, this, &Editor::onMapStartPaint);
|
||||
connect(map_item, &MapPixmapItem::endPaint, this, &Editor::onMapEndPaint);
|
||||
connect(map_item, &MapPixmapItem::hoveredMapMetatileChanged, this, &Editor::onHoveredMapMetatileChanged);
|
||||
connect(map_item, &MapPixmapItem::hoveredMapMetatileCleared, this, &Editor::onHoveredMapMetatileCleared);
|
||||
map_item = new LayoutPixmapItem(this->layout, this->metatile_selector_item, this->settings);
|
||||
connect(map_item, &LayoutPixmapItem::mouseEvent, this, &Editor::mouseEvent_map);
|
||||
connect(map_item, &LayoutPixmapItem::startPaint, this, &Editor::onMapStartPaint);
|
||||
connect(map_item, &LayoutPixmapItem::endPaint, this, &Editor::onMapEndPaint);
|
||||
connect(map_item, &LayoutPixmapItem::hoveredMapMetatileChanged, this, &Editor::onHoveredMapMetatileChanged);
|
||||
connect(map_item, &LayoutPixmapItem::hoveredMapMetatileCleared, this, &Editor::onHoveredMapMetatileCleared);
|
||||
|
||||
map_item->draw(true);
|
||||
scene->addItem(map_item);
|
||||
|
@ -1425,7 +1433,7 @@ void Editor::displayMapMovementPermissions() {
|
|||
scene->removeItem(collision_item);
|
||||
delete collision_item;
|
||||
}
|
||||
collision_item = new CollisionPixmapItem(map, this->movement_permissions_selector_item,
|
||||
collision_item = new CollisionPixmapItem(this->layout, this->movement_permissions_selector_item,
|
||||
this->metatile_selector_item, this->settings, &this->collisionOpacity);
|
||||
connect(collision_item, &CollisionPixmapItem::mouseEvent, this, &Editor::mouseEvent_collision);
|
||||
connect(collision_item, &CollisionPixmapItem::hoveredMapMovementPermissionChanged,
|
||||
|
@ -1444,7 +1452,7 @@ void Editor::displayBorderMetatiles() {
|
|||
}
|
||||
|
||||
scene_selected_border_metatiles = new QGraphicsScene;
|
||||
selected_border_metatiles_item = new BorderMetatilesPixmapItem(map, this->metatile_selector_item);
|
||||
selected_border_metatiles_item = new BorderMetatilesPixmapItem(this->layout, this->metatile_selector_item);
|
||||
selected_border_metatiles_item->draw();
|
||||
scene_selected_border_metatiles->addItem(selected_border_metatiles_item);
|
||||
|
||||
|
@ -2035,7 +2043,7 @@ void Editor::selectedEventIndexChanged(int index, Event::Group eventGroup) {
|
|||
}
|
||||
|
||||
void Editor::duplicateSelectedEvents() {
|
||||
if (!selected_events || !selected_events->length() || !map || !current_view || map_item->paintingMode != MapPixmapItem::PaintMode::EventObjects)
|
||||
if (!selected_events || !selected_events->length() || !map || !current_view || map_item->paintingMode != LayoutPixmapItem::PaintMode::EventObjects)
|
||||
return;
|
||||
|
||||
QList<Event *> selectedEvents;
|
||||
|
@ -2207,7 +2215,7 @@ bool Editor::startDetachedProcess(const QString &command, const QString &working
|
|||
// is clicking on the background instead of an event.
|
||||
void Editor::objectsView_onMousePress(QMouseEvent *event) {
|
||||
// make sure we are in object editing mode
|
||||
if (map_item && map_item->paintingMode != MapPixmapItem::PaintMode::EventObjects) {
|
||||
if (map_item && map_item->paintingMode != LayoutPixmapItem::PaintMode::EventObjects) {
|
||||
return;
|
||||
}
|
||||
if (this->obj_edit_mode == "paint" && event->buttons() & Qt::RightButton) {
|
||||
|
|
|
@ -617,12 +617,32 @@ void MainWindow::on_action_Reload_Project_triggered() {
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::unsetMap() {
|
||||
//
|
||||
logInfo("Disabling map-related edits");
|
||||
|
||||
//
|
||||
this->editor->unsetMap();
|
||||
|
||||
// disable other tabs
|
||||
this->ui->mainTabBar->setTabEnabled(0, true);
|
||||
this->ui->mainTabBar->setTabEnabled(1, false);
|
||||
this->ui->mainTabBar->setTabEnabled(2, false);
|
||||
this->ui->mainTabBar->setTabEnabled(3, false);
|
||||
this->ui->mainTabBar->setTabEnabled(4, false);
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
|
||||
logInfo(QString("Setting map to '%1'").arg(map_name));
|
||||
// if map name is empty, clear & disable map ui
|
||||
if (map_name.isEmpty()) {
|
||||
unsetMap();
|
||||
return false;
|
||||
}
|
||||
|
||||
logInfo(QString("Setting map to '%1'").arg(map_name));
|
||||
|
||||
if (!editor->setMap(map_name)) {
|
||||
logWarn(QString("Failed to set map to '%1'").arg(map_name));
|
||||
return false;
|
||||
|
@ -965,6 +985,13 @@ bool MainWindow::populateMapList() {
|
|||
groupListProxyModel->setSourceModel(this->mapGroupModel);
|
||||
ui->mapList->setModel(groupListProxyModel);
|
||||
|
||||
this->layoutTreeModel = new LayoutTreeModel(editor->project);
|
||||
this->layoutListProxyModel = new FilterChildrenProxyModel();
|
||||
this->layoutListProxyModel->setSourceModel(this->layoutTreeModel);
|
||||
ui->layoutList->setModel(layoutListProxyModel);
|
||||
|
||||
//connect(this->ui->layoutList, &QTreeView::doubleClicked, this, &MainWindow::on_layoutList_activated);
|
||||
|
||||
// ui->mapList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
// ui->mapList->setDragEnabled(true);
|
||||
// ui->mapList->setAcceptDrops(true);
|
||||
|
@ -993,7 +1020,7 @@ void MainWindow::sortMapList() {
|
|||
|
||||
// switch (mapSortOrder)
|
||||
// {
|
||||
// case MapSortOrder::Group:
|
||||
// case MapSortOrder::SortByGroup:
|
||||
// for (int i = 0; i < project->groupNames.length(); i++) {
|
||||
// QString group_name = project->groupNames.value(i);
|
||||
// QStandardItem *group = new QStandardItem;
|
||||
|
@ -1014,7 +1041,7 @@ void MainWindow::sortMapList() {
|
|||
// }
|
||||
// }
|
||||
// break;
|
||||
// case MapSortOrder::Area:
|
||||
// case MapSortOrder::SortByArea:
|
||||
// {
|
||||
// QMap<QString, int> mapsecToGroupNum;
|
||||
// for (int i = 0; i < project->mapSectionNameToValue.size(); i++) {
|
||||
|
@ -1044,7 +1071,7 @@ void MainWindow::sortMapList() {
|
|||
// }
|
||||
// break;
|
||||
// }
|
||||
// case MapSortOrder::Layout:
|
||||
// case MapSortOrder::SortByLayout:
|
||||
// {
|
||||
// QMap<QString, int> layoutIndices;
|
||||
// for (int i = 0; i < project->mapLayoutsTable.length(); i++) {
|
||||
|
@ -1137,19 +1164,19 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point)
|
|||
void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction)
|
||||
{
|
||||
openNewMapPopupWindow();
|
||||
this->newMapPrompt->init(MapSortOrder::Group, triggeredAction->data());
|
||||
this->newMapPrompt->init(MapSortOrder::SortByGroup, triggeredAction->data());
|
||||
}
|
||||
|
||||
void MainWindow::onAddNewMapToAreaClick(QAction* triggeredAction)
|
||||
{
|
||||
openNewMapPopupWindow();
|
||||
this->newMapPrompt->init(MapSortOrder::Area, triggeredAction->data());
|
||||
this->newMapPrompt->init(MapSortOrder::SortByArea, triggeredAction->data());
|
||||
}
|
||||
|
||||
void MainWindow::onAddNewMapToLayoutClick(QAction* triggeredAction)
|
||||
{
|
||||
openNewMapPopupWindow();
|
||||
this->newMapPrompt->init(MapSortOrder::Layout, triggeredAction->data());
|
||||
this->newMapPrompt->init(MapSortOrder::SortByLayout, triggeredAction->data());
|
||||
}
|
||||
|
||||
void MainWindow::onNewMapCreated() {
|
||||
|
@ -1359,9 +1386,23 @@ void MainWindow::currentMetatilesSelectionChanged()
|
|||
}
|
||||
}
|
||||
|
||||
// !TODO
|
||||
void MainWindow::on_mapListContainer_currentChanged(int index) {
|
||||
//
|
||||
switch (index) {
|
||||
case MapListTab::Groups:
|
||||
break;
|
||||
case MapListTab::Areas:
|
||||
break;
|
||||
case MapListTab::Layouts:
|
||||
//setMap(nullptr);
|
||||
//setLayout(nullptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// !TODO
|
||||
void MainWindow::on_mapList_activated(const QModelIndex &index)
|
||||
{
|
||||
void MainWindow::on_mapList_activated(const QModelIndex &index) {
|
||||
QVariant data = index.data(Qt::UserRole);
|
||||
if (index.data(MapListRoles::TypeRole) == "map_name" && !data.isNull()) {
|
||||
QString mapName = data.toString();
|
||||
|
@ -1376,6 +1417,24 @@ void MainWindow::on_mapList_activated(const QModelIndex &index)
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_areaList_activated(const QModelIndex &index) {
|
||||
//
|
||||
}
|
||||
|
||||
void MainWindow::on_layoutList_activated(const QModelIndex &index) {
|
||||
if (!index.isValid()) return;
|
||||
|
||||
QVariant data = index.data(Qt::UserRole);
|
||||
if (index.data(MapListRoles::TypeRole) == "map_layout" && !data.isNull()) {
|
||||
QString layoutName = data.toString();
|
||||
//
|
||||
logInfo("Switching to a layout-only editing mode");
|
||||
setMap(QString());
|
||||
// setLayout(layout)
|
||||
qDebug() << "set layout" << layoutName;
|
||||
}
|
||||
}
|
||||
|
||||
/// !TODO something with the projectHasUnsavedChanges var
|
||||
void MainWindow::drawMapListIcons(QAbstractItemModel *model) {
|
||||
// projectHasUnsavedChanges = false;
|
||||
|
@ -2616,21 +2675,21 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked()
|
|||
form.addRow(errorLabel);
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
Map *map = editor->map;
|
||||
Blockdata oldMetatiles = map->layout->blockdata;
|
||||
Blockdata oldBorder = map->layout->border;
|
||||
QSize oldMapDimensions(map->getWidth(), map->getHeight());
|
||||
QSize oldBorderDimensions(map->getBorderWidth(), map->getBorderHeight());
|
||||
Layout *layout = editor->layout;
|
||||
Blockdata oldMetatiles = layout->blockdata;
|
||||
Blockdata oldBorder = layout->border;
|
||||
QSize oldMapDimensions(layout->getWidth(), layout->getHeight());
|
||||
QSize oldBorderDimensions(layout->getBorderWidth(), layout->getBorderHeight());
|
||||
QSize newMapDimensions(widthSpinBox->value(), heightSpinBox->value());
|
||||
QSize newBorderDimensions(bwidthSpinBox->value(), bheightSpinBox->value());
|
||||
if (oldMapDimensions != newMapDimensions || oldBorderDimensions != newBorderDimensions) {
|
||||
editor->map->setDimensions(newMapDimensions.width(), newMapDimensions.height(), true, true);
|
||||
editor->map->setBorderDimensions(newBorderDimensions.width(), newBorderDimensions.height(), true, true);
|
||||
editor->map->editHistory.push(new ResizeMap(map,
|
||||
layout->setDimensions(newMapDimensions.width(), newMapDimensions.height(), true, true);
|
||||
layout->setBorderDimensions(newBorderDimensions.width(), newBorderDimensions.height(), true, true);
|
||||
editor->map->editHistory.push(new ResizeMap(layout,
|
||||
oldMapDimensions, newMapDimensions,
|
||||
oldMetatiles, map->layout->blockdata,
|
||||
oldMetatiles, layout->blockdata,
|
||||
oldBorderDimensions, newBorderDimensions,
|
||||
oldBorder, map->layout->border
|
||||
oldBorder, layout->border
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -2670,42 +2729,40 @@ void MainWindow::initTilesetEditor() {
|
|||
connect(this->tilesetEditor, &TilesetEditor::tilesetsSaved, this, &MainWindow::onTilesetsSaved);
|
||||
}
|
||||
|
||||
// void MainWindow::on_toolButton_ExpandAll_clicked()
|
||||
// {
|
||||
// if (ui->mapList) {
|
||||
// ui->mapList->expandToDepth(0);
|
||||
// }
|
||||
// }
|
||||
|
||||
// void MainWindow::on_toolButton_CollapseAll_clicked()
|
||||
// {
|
||||
// if (ui->mapList) {
|
||||
// ui->mapList->collapseAll();
|
||||
// }
|
||||
// }
|
||||
|
||||
void MainWindow::on_toolButton_ExpandAll_Groups_clicked() {
|
||||
//
|
||||
if (ui->mapList) {
|
||||
ui->mapList->expandToDepth(0);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_toolButton_CollapseAll_Groups_clicked() {
|
||||
//
|
||||
if (ui->mapList) {
|
||||
ui->mapList->collapseAll();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_toolButton_ExpandAll_Areas_clicked() {
|
||||
//
|
||||
if (ui->areaList) {
|
||||
ui->areaList->expandToDepth(0);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_toolButton_CollapseAll_Areas_clicked() {
|
||||
//
|
||||
if (ui->areaList) {
|
||||
ui->areaList->collapseAll();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_toolButton_ExpandAll_Layouts_clicked() {
|
||||
//
|
||||
if (ui->layoutList) {
|
||||
ui->layoutList->expandToDepth(0);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_toolButton_CollapseAll_Layouts_clicked() {
|
||||
//
|
||||
if (ui->layoutList) {
|
||||
ui->layoutList->collapseAll();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAbout_Porymap_triggered()
|
||||
|
|
|
@ -359,6 +359,10 @@ QString Project::readMapLayoutId(QString map_name) {
|
|||
return ParseUtil::jsonToQString(mapObj["layout"]);
|
||||
}
|
||||
|
||||
QString Project::readMapLayoutName(QString mapName) {
|
||||
return this->layoutIdsToNames[readMapLayoutId(mapName)];
|
||||
}
|
||||
|
||||
QString Project::readMapLocation(QString map_name) {
|
||||
if (mapCache.contains(map_name)) {
|
||||
return mapCache.value(map_name)->location;
|
||||
|
@ -408,6 +412,7 @@ bool Project::loadMapLayout(Map* map) {
|
|||
bool Project::readMapLayouts() {
|
||||
mapLayouts.clear();
|
||||
mapLayoutsTable.clear();
|
||||
layoutIdsToNames.clear();
|
||||
|
||||
QString layoutsFilepath = projectConfig.getFilePath(ProjectFilePath::json_layouts);
|
||||
QString fullFilepath = QString("%1/%2").arg(root).arg(layoutsFilepath);
|
||||
|
@ -529,6 +534,7 @@ bool Project::readMapLayouts() {
|
|||
}
|
||||
mapLayouts.insert(layout->id, layout);
|
||||
mapLayoutsTable.append(layout->id);
|
||||
layoutIdsToNames.insert(layout->id, layout->name);
|
||||
}
|
||||
|
||||
// Deep copy
|
||||
|
@ -1336,11 +1342,12 @@ void Project::updateMapLayout(Map* map) {
|
|||
mapLayoutsTableMaster.append(map->layoutId);
|
||||
}
|
||||
|
||||
// !TODO
|
||||
// Deep copy
|
||||
MapLayout *layout = mapLayouts.value(map->layoutId);
|
||||
MapLayout *newLayout = new MapLayout();
|
||||
*newLayout = *layout;
|
||||
mapLayoutsMaster.insert(map->layoutId, newLayout);
|
||||
// MapLayout *layout = mapLayouts.value(map->layoutId);
|
||||
// MapLayout *newLayout = new MapLayout();
|
||||
// *newLayout = *layout;
|
||||
// mapLayoutsMaster.insert(map->layoutId, newLayout);
|
||||
}
|
||||
|
||||
void Project::saveAllDataStructures() {
|
||||
|
|
|
@ -7,30 +7,30 @@
|
|||
void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
int width = map->getBorderWidth();
|
||||
int height = map->getBorderHeight();
|
||||
int width = layout->getBorderWidth();
|
||||
int height = layout->getBorderHeight();
|
||||
|
||||
Blockdata oldBorder = map->layout->border;
|
||||
Blockdata oldBorder = layout->border;
|
||||
|
||||
for (int i = 0; i < selection.dimensions.x() && (i + pos.x()) < width; i++) {
|
||||
for (int j = 0; j < selection.dimensions.y() && (j + pos.y()) < height; j++) {
|
||||
MetatileSelectionItem item = selection.metatileItems.at(j * selection.dimensions.x() + i);
|
||||
map->setBorderMetatileId(pos.x() + i, pos.y() + j, item.metatileId, true);
|
||||
layout->setBorderMetatileId(pos.x() + i, pos.y() + j, item.metatileId, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (map->layout->border != oldBorder) {
|
||||
map->editHistory.push(new PaintBorder(map, oldBorder, map->layout->border, 0));
|
||||
if (layout->border != oldBorder) {
|
||||
layout->editHistory.push(new PaintBorder(layout, oldBorder, layout->border, 0));
|
||||
}
|
||||
|
||||
emit borderMetatilesChanged();
|
||||
}
|
||||
|
||||
void BorderMetatilesPixmapItem::draw() {
|
||||
map->setBorderItem(this);
|
||||
layout->setBorderItem(this);
|
||||
|
||||
int width = map->getBorderWidth();
|
||||
int height = map->getBorderHeight();
|
||||
int width = layout->getBorderWidth();
|
||||
int height = layout->getBorderHeight();
|
||||
QImage image(16 * width, 16 * height, QImage::Format_RGBA8888);
|
||||
QPainter painter(&image);
|
||||
|
||||
|
@ -39,11 +39,11 @@ void BorderMetatilesPixmapItem::draw() {
|
|||
int x = i * 16;
|
||||
int y = j * 16;
|
||||
QImage metatile_image = getMetatileImage(
|
||||
map->getBorderMetatileId(i, j),
|
||||
map->layout->tileset_primary,
|
||||
map->layout->tileset_secondary,
|
||||
map->metatileLayerOrder,
|
||||
map->metatileLayerOpacity);
|
||||
layout->getBorderMetatileId(i, j),
|
||||
layout->tileset_primary,
|
||||
layout->tileset_secondary,
|
||||
layout->metatileLayerOrder,
|
||||
layout->metatileLayerOpacity);
|
||||
QPoint metatile_origin = QPoint(x, y);
|
||||
painter.drawImage(metatile_origin, metatile_image);
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ void BorderMetatilesPixmapItem::draw() {
|
|||
|
||||
void BorderMetatilesPixmapItem::hoverUpdate(const QPointF &pixmapPos) {
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(pixmapPos);
|
||||
uint16_t metatileId = this->map->getBorderMetatileId(pos.x(), pos.y());
|
||||
uint16_t metatileId = this->layout->getBorderMetatileId(pos.x(), pos.y());
|
||||
emit this->hoveredBorderMetatileSelectionChanged(metatileId);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
|||
this->previousPos = pos;
|
||||
emit this->hoveredMapMovementPermissionChanged(pos.x(), pos.y());
|
||||
}
|
||||
if (this->settings->betterCursors && this->paintingMode == MapPixmapItem::PaintMode::Metatiles) {
|
||||
if (this->settings->betterCursors && this->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) {
|
||||
setCursor(this->settings->mapCursor);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ void CollisionPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) {
|
|||
|
||||
void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||
emit this->hoveredMapMovementPermissionCleared();
|
||||
if (this->settings->betterCursors && this->paintingMode == MapPixmapItem::PaintMode::Metatiles){
|
||||
if (this->settings->betterCursors && this->paintingMode == LayoutPixmapItem::PaintMode::Metatiles){
|
||||
unsetCursor();
|
||||
}
|
||||
this->has_mouse = false;
|
||||
|
@ -49,9 +49,10 @@ void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
|||
}
|
||||
|
||||
void CollisionPixmapItem::draw(bool ignoreCache) {
|
||||
if (map) {
|
||||
map->setCollisionItem(this);
|
||||
setPixmap(map->renderCollision(ignoreCache));
|
||||
if (this->layout) {
|
||||
// !TODO
|
||||
// this->layout->setCollisionItem(this);
|
||||
setPixmap(this->layout->renderCollision(ignoreCache));
|
||||
setOpacity(*this->opacity);
|
||||
}
|
||||
}
|
||||
|
@ -59,8 +60,8 @@ void CollisionPixmapItem::draw(bool ignoreCache) {
|
|||
void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||
actionId_++;
|
||||
} else if (map) {
|
||||
Blockdata oldCollision = map->layout->blockdata;
|
||||
} else if (this->layout) {
|
||||
Blockdata oldCollision = this->layout->blockdata;
|
||||
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
|
||||
|
@ -70,18 +71,18 @@ void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
|||
pos = this->adjustCoords(pos);
|
||||
} else {
|
||||
this->prevStraightPathState = false;
|
||||
this->lockedAxis = MapPixmapItem::Axis::None;
|
||||
this->lockedAxis = LayoutPixmapItem::Axis::None;
|
||||
}
|
||||
|
||||
Block block;
|
||||
if (map->getBlock(pos.x(), pos.y(), &block)) {
|
||||
if (this->layout->getBlock(pos.x(), pos.y(), &block)) {
|
||||
block.collision = this->movementPermissionsSelector->getSelectedCollision();
|
||||
block.elevation = this->movementPermissionsSelector->getSelectedElevation();
|
||||
map->setBlock(pos.x(), pos.y(), block, true);
|
||||
this->layout->setBlock(pos.x(), pos.y(), block, true);
|
||||
}
|
||||
|
||||
if (map->layout->blockdata != oldCollision) {
|
||||
map->editHistory.push(new PaintCollision(map, oldCollision, map->layout->blockdata, actionId_));
|
||||
if (this->layout->blockdata != oldCollision) {
|
||||
this->layout->editHistory.push(new PaintCollision(this->layout, oldCollision, this->layout->blockdata, actionId_));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,16 +90,16 @@ void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
|||
void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
||||
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||
this->actionId_++;
|
||||
} else if (map) {
|
||||
Blockdata oldCollision = map->layout->blockdata;
|
||||
} else if (this->layout) {
|
||||
Blockdata oldCollision = this->layout->blockdata;
|
||||
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
uint16_t collision = this->movementPermissionsSelector->getSelectedCollision();
|
||||
uint16_t elevation = this->movementPermissionsSelector->getSelectedElevation();
|
||||
map->floodFillCollisionElevation(pos.x(), pos.y(), collision, elevation);
|
||||
this->layout->floodFillCollisionElevation(pos.x(), pos.y(), collision, elevation);
|
||||
|
||||
if (map->layout->blockdata != oldCollision) {
|
||||
map->editHistory.push(new BucketFillCollision(map, oldCollision, map->layout->blockdata));
|
||||
if (this->layout->blockdata != oldCollision) {
|
||||
this->layout->editHistory.push(new BucketFillCollision(this->layout, oldCollision, this->layout->blockdata));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,15 +107,15 @@ void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
|||
void CollisionPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) {
|
||||
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||
this->actionId_++;
|
||||
} else if (map) {
|
||||
Blockdata oldCollision = map->layout->blockdata;
|
||||
} else if (this->layout) {
|
||||
Blockdata oldCollision = this->layout->blockdata;
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
uint16_t collision = this->movementPermissionsSelector->getSelectedCollision();
|
||||
uint16_t elevation = this->movementPermissionsSelector->getSelectedElevation();
|
||||
map->magicFillCollisionElevation(pos.x(), pos.y(), collision, elevation);
|
||||
this->layout->magicFillCollisionElevation(pos.x(), pos.y(), collision, elevation);
|
||||
|
||||
if (map->layout->blockdata != oldCollision) {
|
||||
map->editHistory.push(new MagicFillCollision(map, oldCollision, map->layout->blockdata));
|
||||
if (this->layout->blockdata != oldCollision) {
|
||||
this->layout->editHistory.push(new MagicFillCollision(this->layout, oldCollision, this->layout->blockdata));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +123,7 @@ void CollisionPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) {
|
|||
void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
Block block;
|
||||
if (map->getBlock(pos.x(), pos.y(), &block)) {
|
||||
if (this->layout->getBlock(pos.x(), pos.y(), &block)) {
|
||||
this->movementPermissionsSelector->select(block.collision, block.elevation);
|
||||
}
|
||||
}
|
||||
|
@ -132,12 +133,12 @@ void CollisionPixmapItem::updateMovementPermissionSelection(QGraphicsSceneMouseE
|
|||
|
||||
// Snap point to within map bounds.
|
||||
if (pos.x() < 0) pos.setX(0);
|
||||
if (pos.x() >= map->getWidth()) pos.setX(map->getWidth() - 1);
|
||||
if (pos.x() >= this->layout->getWidth()) pos.setX(this->layout->getWidth() - 1);
|
||||
if (pos.y() < 0) pos.setY(0);
|
||||
if (pos.y() >= map->getHeight()) pos.setY(map->getHeight() - 1);
|
||||
if (pos.y() >= this->layout->getHeight()) pos.setY(this->layout->getHeight() - 1);
|
||||
|
||||
Block block;
|
||||
if (map->getBlock(pos.x(), pos.y(), &block)) {
|
||||
if (this->layout->getBlock(pos.x(), pos.y(), &block)) {
|
||||
this->movementPermissionsSelector->select(block.collision, block.elevation);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "mappixmapitem.h"
|
||||
#include "layoutpixmapitem.h"
|
||||
#include "metatile.h"
|
||||
#include "log.h"
|
||||
#include "scripting.h"
|
||||
|
@ -7,8 +7,8 @@
|
|||
|
||||
#define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0)
|
||||
|
||||
void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||
if (map) {
|
||||
void LayoutPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||
if (layout) {
|
||||
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||
actionId_++;
|
||||
} else {
|
||||
|
@ -20,7 +20,7 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
|||
pos = this->adjustCoords(pos);
|
||||
} else {
|
||||
this->prevStraightPathState = false;
|
||||
this->lockedAxis = MapPixmapItem::Axis::None;
|
||||
this->lockedAxis = LayoutPixmapItem::Axis::None;
|
||||
}
|
||||
|
||||
// Paint onto the map.
|
||||
|
@ -43,8 +43,8 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
|||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::shift(QGraphicsSceneMouseEvent *event) {
|
||||
if (map) {
|
||||
void LayoutPixmapItem::shift(QGraphicsSceneMouseEvent *event) {
|
||||
if (layout) {
|
||||
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||
actionId_++;
|
||||
} else {
|
||||
|
@ -56,7 +56,7 @@ void MapPixmapItem::shift(QGraphicsSceneMouseEvent *event) {
|
|||
pos = this->adjustCoords(pos);
|
||||
} else {
|
||||
this->prevStraightPathState = false;
|
||||
this->lockedAxis = MapPixmapItem::Axis::None;
|
||||
this->lockedAxis = LayoutPixmapItem::Axis::None;
|
||||
}
|
||||
|
||||
if (event->type() == QEvent::GraphicsSceneMousePress) {
|
||||
|
@ -76,32 +76,32 @@ void MapPixmapItem::shift(QGraphicsSceneMouseEvent *event) {
|
|||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::shift(int xDelta, int yDelta, bool fromScriptCall) {
|
||||
Blockdata oldMetatiles = map->layout->blockdata;
|
||||
void LayoutPixmapItem::shift(int xDelta, int yDelta, bool fromScriptCall) {
|
||||
Blockdata oldMetatiles = this->layout->blockdata;
|
||||
|
||||
for (int i = 0; i < map->getWidth(); i++)
|
||||
for (int j = 0; j < map->getHeight(); j++) {
|
||||
for (int i = 0; i < this->layout->getWidth(); i++)
|
||||
for (int j = 0; j < this->layout->getHeight(); j++) {
|
||||
int destX = i + xDelta;
|
||||
int destY = j + yDelta;
|
||||
if (destX < 0)
|
||||
do { destX += map->getWidth(); } while (destX < 0);
|
||||
do { destX += this->layout->getWidth(); } while (destX < 0);
|
||||
if (destY < 0)
|
||||
do { destY += map->getHeight(); } while (destY < 0);
|
||||
destX %= map->getWidth();
|
||||
destY %= map->getHeight();
|
||||
do { destY += this->layout->getHeight(); } while (destY < 0);
|
||||
destX %= this->layout->getWidth();
|
||||
destY %= this->layout->getHeight();
|
||||
|
||||
int blockIndex = j * map->getWidth() + i;
|
||||
int blockIndex = j * this->layout->getWidth() + i;
|
||||
Block srcBlock = oldMetatiles.at(blockIndex);
|
||||
map->setBlock(destX, destY, srcBlock);
|
||||
this->layout->setBlock(destX, destY, srcBlock);
|
||||
}
|
||||
|
||||
if (!fromScriptCall && map->layout->blockdata != oldMetatiles) {
|
||||
map->editHistory.push(new ShiftMetatiles(map, oldMetatiles, map->layout->blockdata, actionId_));
|
||||
if (!fromScriptCall && this->layout->blockdata != oldMetatiles) {
|
||||
this->layout->editHistory.push(new ShiftMetatiles(this->layout, oldMetatiles, this->layout->blockdata, actionId_));
|
||||
Scripting::cb_MapShifted(xDelta, yDelta);
|
||||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
|
||||
void LayoutPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
|
||||
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
||||
int initialX = fromScriptCall ? x : this->paint_tile_initial_x;
|
||||
int initialY = fromScriptCall ? y : this->paint_tile_initial_y;
|
||||
|
@ -117,14 +117,14 @@ void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
|
|||
y = initialY + (yDiff / selection.dimensions.y()) * selection.dimensions.y();
|
||||
|
||||
// for edit history
|
||||
Blockdata oldMetatiles = !fromScriptCall ? map->layout->blockdata : Blockdata();
|
||||
Blockdata oldMetatiles = !fromScriptCall ? this->layout->blockdata : Blockdata();
|
||||
|
||||
for (int i = 0; i < selection.dimensions.x() && i + x < map->getWidth(); i++)
|
||||
for (int j = 0; j < selection.dimensions.y() && j + y < map->getHeight(); j++) {
|
||||
for (int i = 0; i < selection.dimensions.x() && i + x < this->layout->getWidth(); i++)
|
||||
for (int j = 0; j < selection.dimensions.y() && j + y < this->layout->getHeight(); j++) {
|
||||
int actualX = i + x;
|
||||
int actualY = j + y;
|
||||
Block block;
|
||||
if (map->getBlock(actualX, actualY, &block)) {
|
||||
if (this->layout->getBlock(actualX, actualY, &block)) {
|
||||
int index = j * selection.dimensions.x() + i;
|
||||
MetatileSelectionItem item = selection.metatileItems.at(index);
|
||||
if (!item.enabled)
|
||||
|
@ -135,19 +135,19 @@ void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
|
|||
block.collision = collisionItem.collision;
|
||||
block.elevation = collisionItem.elevation;
|
||||
}
|
||||
map->setBlock(actualX, actualY, block, !fromScriptCall);
|
||||
this->layout->setBlock(actualX, actualY, block, !fromScriptCall);
|
||||
}
|
||||
}
|
||||
|
||||
if (!fromScriptCall && map->layout->blockdata != oldMetatiles) {
|
||||
map->editHistory.push(new PaintMetatile(map, oldMetatiles, map->layout->blockdata, actionId_));
|
||||
if (!fromScriptCall && this->layout->blockdata != oldMetatiles) {
|
||||
this->layout->editHistory.push(new PaintMetatile(this->layout, oldMetatiles, this->layout->blockdata, actionId_));
|
||||
}
|
||||
}
|
||||
|
||||
// These are tile offsets from the top-left tile in the 3x3 smart path selection.
|
||||
// Each entry is for one possibility from the marching squares value for a tile.
|
||||
// (Marching Squares: https://en.wikipedia.org/wiki/Marching_squares)
|
||||
QList<int> MapPixmapItem::smartPathTable = QList<int>({
|
||||
QList<int> LayoutPixmapItem::smartPathTable = QList<int>({
|
||||
4, // 0000
|
||||
4, // 0001
|
||||
4, // 0010
|
||||
|
@ -189,7 +189,7 @@ bool isValidSmartPathSelection(MetatileSelection selection) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
||||
void LayoutPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
||||
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
||||
if (!isValidSmartPathSelection(selection))
|
||||
return;
|
||||
|
@ -206,30 +206,30 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
|||
}
|
||||
|
||||
// for edit history
|
||||
Blockdata oldMetatiles = !fromScriptCall ? map->layout->blockdata : Blockdata();
|
||||
Blockdata oldMetatiles = !fromScriptCall ? this->layout->blockdata : Blockdata();
|
||||
|
||||
// Fill the region with the open tile.
|
||||
for (int i = 0; i <= 1; i++)
|
||||
for (int j = 0; j <= 1; j++) {
|
||||
if (!map->isWithinBounds(x + i, y + j))
|
||||
if (!this->layout->isWithinBounds(x + i, y + j))
|
||||
continue;
|
||||
int actualX = i + x;
|
||||
int actualY = j + y;
|
||||
Block block;
|
||||
if (map->getBlock(actualX, actualY, &block)) {
|
||||
if (this->layout->getBlock(actualX, actualY, &block)) {
|
||||
block.metatileId = openTile;
|
||||
if (setCollisions) {
|
||||
block.collision = openTileCollision;
|
||||
block.elevation = openTileElevation;
|
||||
}
|
||||
map->setBlock(actualX, actualY, block, !fromScriptCall);
|
||||
this->layout->setBlock(actualX, actualY, block, !fromScriptCall);
|
||||
}
|
||||
}
|
||||
|
||||
// Go back and resolve the edge tiles
|
||||
for (int i = -1; i <= 2; i++)
|
||||
for (int j = -1; j <= 2; j++) {
|
||||
if (!map->isWithinBounds(x + i, y + j))
|
||||
if (!this->layout->isWithinBounds(x + i, y + j))
|
||||
continue;
|
||||
// Ignore the corners, which can't possible be affected by the smart path.
|
||||
if ((i == -1 && j == -1) || (i == 2 && j == -1) ||
|
||||
|
@ -240,7 +240,7 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
|||
int actualX = i + x;
|
||||
int actualY = j + y;
|
||||
Block block;
|
||||
if (!map->getBlock(actualX, actualY, &block) || !isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
if (!this->layout->getBlock(actualX, actualY, &block) || !isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -251,13 +251,13 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
|||
Block left;
|
||||
|
||||
// Get marching squares value, to determine which tile to use.
|
||||
if (map->getBlock(actualX, actualY - 1, &top) && isSmartPathTile(selection.metatileItems, top.metatileId))
|
||||
if (this->layout->getBlock(actualX, actualY - 1, &top) && isSmartPathTile(selection.metatileItems, top.metatileId))
|
||||
id += 1;
|
||||
if (map->getBlock(actualX + 1, actualY, &right) && isSmartPathTile(selection.metatileItems, right.metatileId))
|
||||
if (this->layout->getBlock(actualX + 1, actualY, &right) && isSmartPathTile(selection.metatileItems, right.metatileId))
|
||||
id += 2;
|
||||
if (map->getBlock(actualX, actualY + 1, &bottom) && isSmartPathTile(selection.metatileItems, bottom.metatileId))
|
||||
if (this->layout->getBlock(actualX, actualY + 1, &bottom) && isSmartPathTile(selection.metatileItems, bottom.metatileId))
|
||||
id += 4;
|
||||
if (map->getBlock(actualX - 1, actualY, &left) && isSmartPathTile(selection.metatileItems, left.metatileId))
|
||||
if (this->layout->getBlock(actualX - 1, actualY, &left) && isSmartPathTile(selection.metatileItems, left.metatileId))
|
||||
id += 8;
|
||||
|
||||
block.metatileId = selection.metatileItems.at(smartPathTable[id]).metatileId;
|
||||
|
@ -266,19 +266,19 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
|||
block.collision = collisionItem.collision;
|
||||
block.elevation = collisionItem.elevation;
|
||||
}
|
||||
map->setBlock(actualX, actualY, block, !fromScriptCall);
|
||||
this->layout->setBlock(actualX, actualY, block, !fromScriptCall);
|
||||
}
|
||||
|
||||
if (!fromScriptCall && map->layout->blockdata != oldMetatiles) {
|
||||
map->editHistory.push(new PaintMetatile(map, oldMetatiles, map->layout->blockdata, actionId_));
|
||||
if (!fromScriptCall && this->layout->blockdata != oldMetatiles) {
|
||||
this->layout->editHistory.push(new PaintMetatile(this->layout, oldMetatiles, this->layout->blockdata, actionId_));
|
||||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::lockNondominantAxis(QGraphicsSceneMouseEvent *event) {
|
||||
void LayoutPixmapItem::lockNondominantAxis(QGraphicsSceneMouseEvent *event) {
|
||||
/* Return if an axis is already locked, or if the mouse has been released. The mouse release check is necessary
|
||||
* because MapPixmapItem::mouseReleaseEvent seems to get called before this function, which would unlock the axis
|
||||
* because LayoutPixmapItem::mouseReleaseEvent seems to get called before this function, which would unlock the axis
|
||||
* and then get immediately re-locked here until the next ctrl-click. */
|
||||
if (this->lockedAxis != MapPixmapItem::Axis::None || event->type() == QEvent::GraphicsSceneMouseRelease)
|
||||
if (this->lockedAxis != LayoutPixmapItem::Axis::None || event->type() == QEvent::GraphicsSceneMouseRelease)
|
||||
return;
|
||||
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
|
@ -293,31 +293,31 @@ void MapPixmapItem::lockNondominantAxis(QGraphicsSceneMouseEvent *event) {
|
|||
int yDiff = pos.y() - this->straight_path_initial_y;
|
||||
if (xDiff || yDiff) {
|
||||
if (abs(xDiff) < abs(yDiff)) {
|
||||
this->lockedAxis = MapPixmapItem::Axis::X;
|
||||
this->lockedAxis = LayoutPixmapItem::Axis::X;
|
||||
} else {
|
||||
this->lockedAxis = MapPixmapItem::Axis::Y;
|
||||
this->lockedAxis = LayoutPixmapItem::Axis::Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust the cooresponding coordinate when it is locked
|
||||
QPoint MapPixmapItem::adjustCoords(QPoint pos) {
|
||||
if (this->lockedAxis == MapPixmapItem::Axis::X) {
|
||||
QPoint LayoutPixmapItem::adjustCoords(QPoint pos) {
|
||||
if (this->lockedAxis == LayoutPixmapItem::Axis::X) {
|
||||
pos.setX(this->straight_path_initial_x);
|
||||
} else if (this->lockedAxis == MapPixmapItem::Axis::Y) {
|
||||
} else if (this->lockedAxis == LayoutPixmapItem::Axis::Y) {
|
||||
pos.setY(this->straight_path_initial_y);
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) {
|
||||
void LayoutPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) {
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
|
||||
// Snap point to within map bounds.
|
||||
// Snap point to within layout bounds.
|
||||
if (pos.x() < 0) pos.setX(0);
|
||||
if (pos.x() >= map->getWidth()) pos.setX(map->getWidth() - 1);
|
||||
if (pos.x() >= this->layout->getWidth()) pos.setX(this->layout->getWidth() - 1);
|
||||
if (pos.y() < 0) pos.setY(0);
|
||||
if (pos.y() >= map->getHeight()) pos.setY(map->getHeight() - 1);
|
||||
if (pos.y() >= this->layout->getHeight()) pos.setY(this->layout->getHeight() - 1);
|
||||
|
||||
// Update/apply copied metatiles.
|
||||
if (event->type() == QEvent::GraphicsSceneMousePress) {
|
||||
|
@ -325,7 +325,7 @@ void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) {
|
|||
selection.clear();
|
||||
selection.append(QPoint(pos.x(), pos.y()));
|
||||
Block block;
|
||||
if (map->getBlock(pos.x(), pos.y(), &block)) {
|
||||
if (this->layout->getBlock(pos.x(), pos.y(), &block)) {
|
||||
this->metatileSelector->selectFromMap(block.metatileId, block.collision, block.elevation);
|
||||
}
|
||||
} else if (event->type() == QEvent::GraphicsSceneMouseMove) {
|
||||
|
@ -348,11 +348,11 @@ void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) {
|
|||
int x = point.x();
|
||||
int y = point.y();
|
||||
Block block;
|
||||
if (map->getBlock(x, y, &block)) {
|
||||
if (this->layout->getBlock(x, y, &block)) {
|
||||
metatiles.append(block.metatileId);
|
||||
}
|
||||
int blockIndex = y * map->getWidth() + x;
|
||||
block = map->layout->blockdata.at(blockIndex);
|
||||
int blockIndex = y * this->layout->getWidth() + x;
|
||||
block = this->layout->blockdata.at(blockIndex);
|
||||
auto collision = block.collision;
|
||||
auto elevation = block.elevation;
|
||||
collisions.append(QPair<uint16_t, uint16_t>(collision, elevation));
|
||||
|
@ -362,8 +362,8 @@ void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) {
|
|||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
||||
if (map) {
|
||||
void LayoutPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
||||
if (this->layout) {
|
||||
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||
actionId_++;
|
||||
} else {
|
||||
|
@ -371,7 +371,7 @@ void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
|||
Block block;
|
||||
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
||||
int metatileId = selection.metatileItems.first().metatileId;
|
||||
if (selection.metatileItems.count() > 1 || (map->getBlock(pos.x(), pos.y(), &block) && block.metatileId != metatileId)) {
|
||||
if (selection.metatileItems.count() > 1 || (this->layout->getBlock(pos.x(), pos.y(), &block) && block.metatileId != metatileId)) {
|
||||
bool smartPathsEnabled = event->modifiers() & Qt::ShiftModifier;
|
||||
if ((this->settings->smartPathsEnabled || smartPathsEnabled) && selection.dimensions.x() == 3 && selection.dimensions.y() == 3)
|
||||
this->floodFillSmartPath(pos.x(), pos.y());
|
||||
|
@ -382,8 +382,8 @@ void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
|||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) {
|
||||
if (map) {
|
||||
void LayoutPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) {
|
||||
if (this->layout) {
|
||||
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||
actionId_++;
|
||||
} else {
|
||||
|
@ -393,18 +393,18 @@ void MapPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) {
|
|||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::magicFill(int x, int y, uint16_t metatileId, bool fromScriptCall) {
|
||||
void LayoutPixmapItem::magicFill(int x, int y, uint16_t metatileId, bool fromScriptCall) {
|
||||
QPoint selectionDimensions(1, 1);
|
||||
QList<MetatileSelectionItem> selectedMetatiles = QList<MetatileSelectionItem>({MetatileSelectionItem{ true, metatileId }});
|
||||
this->magicFill(x, y, selectionDimensions, selectedMetatiles, QList<CollisionSelectionItem>(), fromScriptCall);
|
||||
}
|
||||
|
||||
void MapPixmapItem::magicFill(int x, int y, bool fromScriptCall) {
|
||||
void LayoutPixmapItem::magicFill(int x, int y, bool fromScriptCall) {
|
||||
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
||||
this->magicFill(x, y, selection.dimensions, selection.metatileItems, selection.collisionItems, fromScriptCall);
|
||||
}
|
||||
|
||||
void MapPixmapItem::magicFill(
|
||||
void LayoutPixmapItem::magicFill(
|
||||
int initialX,
|
||||
int initialY,
|
||||
QPoint selectionDimensions,
|
||||
|
@ -412,18 +412,18 @@ void MapPixmapItem::magicFill(
|
|||
QList<CollisionSelectionItem> selectedCollisions,
|
||||
bool fromScriptCall) {
|
||||
Block block;
|
||||
if (map->getBlock(initialX, initialY, &block)) {
|
||||
if (this->layout->getBlock(initialX, initialY, &block)) {
|
||||
if (selectedMetatiles.length() == 1 && selectedMetatiles.at(0).metatileId == block.metatileId) {
|
||||
return;
|
||||
}
|
||||
|
||||
Blockdata oldMetatiles = !fromScriptCall ? map->layout->blockdata : Blockdata();
|
||||
Blockdata oldMetatiles = !fromScriptCall ? this->layout->blockdata : Blockdata();
|
||||
|
||||
bool setCollisions = selectedCollisions.length() == selectedMetatiles.length();
|
||||
uint16_t metatileId = block.metatileId;
|
||||
for (int y = 0; y < map->getHeight(); y++) {
|
||||
for (int x = 0; x < map->getWidth(); x++) {
|
||||
if (map->getBlock(x, y, &block) && block.metatileId == metatileId) {
|
||||
for (int y = 0; y < this->layout->getHeight(); y++) {
|
||||
for (int x = 0; x < this->layout->getWidth(); x++) {
|
||||
if (this->layout->getBlock(x, y, &block) && block.metatileId == metatileId) {
|
||||
int xDiff = x - initialX;
|
||||
int yDiff = y - initialY;
|
||||
int i = xDiff % selectionDimensions.x();
|
||||
|
@ -438,30 +438,30 @@ void MapPixmapItem::magicFill(
|
|||
block.collision = item.collision;
|
||||
block.elevation = item.elevation;
|
||||
}
|
||||
map->setBlock(x, y, block, !fromScriptCall);
|
||||
this->layout->setBlock(x, y, block, !fromScriptCall);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!fromScriptCall && map->layout->blockdata != oldMetatiles) {
|
||||
map->editHistory.push(new MagicFillMetatile(map, oldMetatiles, map->layout->blockdata, actionId_));
|
||||
if (!fromScriptCall && this->layout->blockdata != oldMetatiles) {
|
||||
this->layout->editHistory.push(new MagicFillMetatile(this->layout, oldMetatiles, this->layout->blockdata, actionId_));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::floodFill(int initialX, int initialY, bool fromScriptCall) {
|
||||
void LayoutPixmapItem::floodFill(int initialX, int initialY, bool fromScriptCall) {
|
||||
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
||||
this->floodFill(initialX, initialY, selection.dimensions, selection.metatileItems, selection.collisionItems, fromScriptCall);
|
||||
}
|
||||
|
||||
void MapPixmapItem::floodFill(int initialX, int initialY, uint16_t metatileId, bool fromScriptCall) {
|
||||
void LayoutPixmapItem::floodFill(int initialX, int initialY, uint16_t metatileId, bool fromScriptCall) {
|
||||
QPoint selectionDimensions(1, 1);
|
||||
QList<MetatileSelectionItem> selectedMetatiles = QList<MetatileSelectionItem>({MetatileSelectionItem{true, metatileId}});
|
||||
this->floodFill(initialX, initialY, selectionDimensions, selectedMetatiles, QList<CollisionSelectionItem>(), fromScriptCall);
|
||||
}
|
||||
|
||||
void MapPixmapItem::floodFill(
|
||||
void LayoutPixmapItem::floodFill(
|
||||
int initialX,
|
||||
int initialY,
|
||||
QPoint selectionDimensions,
|
||||
|
@ -469,7 +469,7 @@ void MapPixmapItem::floodFill(
|
|||
QList<CollisionSelectionItem> selectedCollisions,
|
||||
bool fromScriptCall) {
|
||||
bool setCollisions = selectedCollisions.length() == selectedMetatiles.length();
|
||||
Blockdata oldMetatiles = !fromScriptCall ? map->layout->blockdata : Blockdata();
|
||||
Blockdata oldMetatiles = !fromScriptCall ? this->layout->blockdata : Blockdata();
|
||||
|
||||
QSet<int> visited;
|
||||
QList<QPoint> todo;
|
||||
|
@ -479,11 +479,11 @@ void MapPixmapItem::floodFill(
|
|||
int x = point.x();
|
||||
int y = point.y();
|
||||
Block block;
|
||||
if (!map->getBlock(x, y, &block)) {
|
||||
if (!this->layout->getBlock(x, y, &block)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
visited.insert(x + y * map->getWidth());
|
||||
visited.insert(x + y * this->layout->getWidth());
|
||||
int xDiff = x - initialX;
|
||||
int yDiff = y - initialY;
|
||||
int i = xDiff % selectionDimensions.x();
|
||||
|
@ -500,32 +500,32 @@ void MapPixmapItem::floodFill(
|
|||
block.collision = item.collision;
|
||||
block.elevation = item.elevation;
|
||||
}
|
||||
map->setBlock(x, y, block, !fromScriptCall);
|
||||
this->layout->setBlock(x, y, block, !fromScriptCall);
|
||||
}
|
||||
if (!visited.contains(x + 1 + y * map->getWidth()) && map->getBlock(x + 1, y, &block) && block.metatileId == old_metatileId) {
|
||||
if (!visited.contains(x + 1 + y * this->layout->getWidth()) && this->layout->getBlock(x + 1, y, &block) && block.metatileId == old_metatileId) {
|
||||
todo.append(QPoint(x + 1, y));
|
||||
visited.insert(x + 1 + y * map->getWidth());
|
||||
visited.insert(x + 1 + y * this->layout->getWidth());
|
||||
}
|
||||
if (!visited.contains(x - 1 + y * map->getWidth()) && map->getBlock(x - 1, y, &block) && block.metatileId == old_metatileId) {
|
||||
if (!visited.contains(x - 1 + y * this->layout->getWidth()) && this->layout->getBlock(x - 1, y, &block) && block.metatileId == old_metatileId) {
|
||||
todo.append(QPoint(x - 1, y));
|
||||
visited.insert(x - 1 + y * map->getWidth());
|
||||
visited.insert(x - 1 + y * this->layout->getWidth());
|
||||
}
|
||||
if (!visited.contains(x + (y + 1) * map->getWidth()) && map->getBlock(x, y + 1, &block) && block.metatileId == old_metatileId) {
|
||||
if (!visited.contains(x + (y + 1) * this->layout->getWidth()) && this->layout->getBlock(x, y + 1, &block) && block.metatileId == old_metatileId) {
|
||||
todo.append(QPoint(x, y + 1));
|
||||
visited.insert(x + (y + 1) * map->getWidth());
|
||||
visited.insert(x + (y + 1) * this->layout->getWidth());
|
||||
}
|
||||
if (!visited.contains(x + (y - 1) * map->getWidth()) && map->getBlock(x, y - 1, &block) && block.metatileId == old_metatileId) {
|
||||
if (!visited.contains(x + (y - 1) * this->layout->getWidth()) && this->layout->getBlock(x, y - 1, &block) && block.metatileId == old_metatileId) {
|
||||
todo.append(QPoint(x, y - 1));
|
||||
visited.insert(x + (y - 1) * map->getWidth());
|
||||
visited.insert(x + (y - 1) * this->layout->getWidth());
|
||||
}
|
||||
}
|
||||
|
||||
if (!fromScriptCall && map->layout->blockdata != oldMetatiles) {
|
||||
map->editHistory.push(new BucketFillMetatile(map, oldMetatiles, map->layout->blockdata, actionId_));
|
||||
if (!fromScriptCall && this->layout->blockdata != oldMetatiles) {
|
||||
this->layout->editHistory.push(new BucketFillMetatile(this->layout, oldMetatiles, this->layout->blockdata, actionId_));
|
||||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScriptCall) {
|
||||
void LayoutPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScriptCall) {
|
||||
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
||||
if (!isValidSmartPathSelection(selection))
|
||||
return;
|
||||
|
@ -542,7 +542,7 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri
|
|||
setCollisions = true;
|
||||
}
|
||||
|
||||
Blockdata oldMetatiles = !fromScriptCall ? map->layout->blockdata : Blockdata();
|
||||
Blockdata oldMetatiles = !fromScriptCall ? this->layout->blockdata : Blockdata();
|
||||
|
||||
// Flood fill the region with the open tile.
|
||||
QList<QPoint> todo;
|
||||
|
@ -552,7 +552,7 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri
|
|||
int x = point.x();
|
||||
int y = point.y();
|
||||
Block block;
|
||||
if (!map->getBlock(x, y, &block)) {
|
||||
if (!this->layout->getBlock(x, y, &block)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -566,17 +566,17 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri
|
|||
block.collision = openTileCollision;
|
||||
block.elevation = openTileElevation;
|
||||
}
|
||||
map->setBlock(x, y, block, !fromScriptCall);
|
||||
if (map->getBlock(x + 1, y, &block) && block.metatileId == old_metatileId) {
|
||||
this->layout->setBlock(x, y, block, !fromScriptCall);
|
||||
if (this->layout->getBlock(x + 1, y, &block) && block.metatileId == old_metatileId) {
|
||||
todo.append(QPoint(x + 1, y));
|
||||
}
|
||||
if (map->getBlock(x - 1, y, &block) && block.metatileId == old_metatileId) {
|
||||
if (this->layout->getBlock(x - 1, y, &block) && block.metatileId == old_metatileId) {
|
||||
todo.append(QPoint(x - 1, y));
|
||||
}
|
||||
if (map->getBlock(x, y + 1, &block) && block.metatileId == old_metatileId) {
|
||||
if (this->layout->getBlock(x, y + 1, &block) && block.metatileId == old_metatileId) {
|
||||
todo.append(QPoint(x, y + 1));
|
||||
}
|
||||
if (map->getBlock(x, y - 1, &block) && block.metatileId == old_metatileId) {
|
||||
if (this->layout->getBlock(x, y - 1, &block) && block.metatileId == old_metatileId) {
|
||||
todo.append(QPoint(x, y - 1));
|
||||
}
|
||||
}
|
||||
|
@ -590,11 +590,11 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri
|
|||
int x = point.x();
|
||||
int y = point.y();
|
||||
Block block;
|
||||
if (!map->getBlock(x, y, &block)) {
|
||||
if (!this->layout->getBlock(x, y, &block)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
visited.insert(x + y * map->getWidth());
|
||||
visited.insert(x + y * this->layout->getWidth());
|
||||
int id = 0;
|
||||
Block top;
|
||||
Block right;
|
||||
|
@ -602,13 +602,13 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri
|
|||
Block left;
|
||||
|
||||
// Get marching squares value, to determine which tile to use.
|
||||
if (map->getBlock(x, y - 1, &top) && isSmartPathTile(selection.metatileItems, top.metatileId))
|
||||
if (this->layout->getBlock(x, y - 1, &top) && isSmartPathTile(selection.metatileItems, top.metatileId))
|
||||
id += 1;
|
||||
if (map->getBlock(x + 1, y, &right) && isSmartPathTile(selection.metatileItems, right.metatileId))
|
||||
if (this->layout->getBlock(x + 1, y, &right) && isSmartPathTile(selection.metatileItems, right.metatileId))
|
||||
id += 2;
|
||||
if (map->getBlock(x, y + 1, &bottom) && isSmartPathTile(selection.metatileItems, bottom.metatileId))
|
||||
if (this->layout->getBlock(x, y + 1, &bottom) && isSmartPathTile(selection.metatileItems, bottom.metatileId))
|
||||
id += 4;
|
||||
if (map->getBlock(x - 1, y, &left) && isSmartPathTile(selection.metatileItems, left.metatileId))
|
||||
if (this->layout->getBlock(x - 1, y, &left) && isSmartPathTile(selection.metatileItems, left.metatileId))
|
||||
id += 8;
|
||||
|
||||
block.metatileId = selection.metatileItems.at(smartPathTable[id]).metatileId;
|
||||
|
@ -617,41 +617,41 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri
|
|||
block.collision = item.collision;
|
||||
block.elevation = item.elevation;
|
||||
}
|
||||
map->setBlock(x, y, block, !fromScriptCall);
|
||||
this->layout->setBlock(x, y, block, !fromScriptCall);
|
||||
|
||||
// Visit neighbors if they are smart-path tiles, and don't revisit any.
|
||||
if (!visited.contains(x + 1 + y * map->getWidth()) && map->getBlock(x + 1, y, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
if (!visited.contains(x + 1 + y * this->layout->getWidth()) && this->layout->getBlock(x + 1, y, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
todo.append(QPoint(x + 1, y));
|
||||
visited.insert(x + 1 + y * map->getWidth());
|
||||
visited.insert(x + 1 + y * this->layout->getWidth());
|
||||
}
|
||||
if (!visited.contains(x - 1 + y * map->getWidth()) && map->getBlock(x - 1, y, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
if (!visited.contains(x - 1 + y * this->layout->getWidth()) && this->layout->getBlock(x - 1, y, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
todo.append(QPoint(x - 1, y));
|
||||
visited.insert(x - 1 + y * map->getWidth());
|
||||
visited.insert(x - 1 + y * this->layout->getWidth());
|
||||
}
|
||||
if (!visited.contains(x + (y + 1) * map->getWidth()) && map->getBlock(x, y + 1, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
if (!visited.contains(x + (y + 1) * this->layout->getWidth()) && this->layout->getBlock(x, y + 1, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
todo.append(QPoint(x, y + 1));
|
||||
visited.insert(x + (y + 1) * map->getWidth());
|
||||
visited.insert(x + (y + 1) * this->layout->getWidth());
|
||||
}
|
||||
if (!visited.contains(x + (y - 1) * map->getWidth()) && map->getBlock(x, y - 1, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
if (!visited.contains(x + (y - 1) * this->layout->getWidth()) && this->layout->getBlock(x, y - 1, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
todo.append(QPoint(x, y - 1));
|
||||
visited.insert(x + (y - 1) * map->getWidth());
|
||||
visited.insert(x + (y - 1) * this->layout->getWidth());
|
||||
}
|
||||
}
|
||||
|
||||
if (!fromScriptCall && map->layout->blockdata != oldMetatiles) {
|
||||
map->editHistory.push(new BucketFillMetatile(map, oldMetatiles, map->layout->blockdata, actionId_));
|
||||
if (!fromScriptCall && this->layout->blockdata != oldMetatiles) {
|
||||
this->layout->editHistory.push(new BucketFillMetatile(this->layout, oldMetatiles, this->layout->blockdata, actionId_));
|
||||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
|
||||
void LayoutPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
Block block;
|
||||
if (map->getBlock(pos.x(), pos.y(), &block)) {
|
||||
if (this->layout->getBlock(pos.x(), pos.y(), &block)) {
|
||||
this->metatileSelector->selectFromMap(block.metatileId, block.collision, block.elevation);
|
||||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::select(QGraphicsSceneMouseEvent *event) {
|
||||
void LayoutPixmapItem::select(QGraphicsSceneMouseEvent *event) {
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
if (event->type() == QEvent::GraphicsSceneMousePress) {
|
||||
selection_origin = QPoint(pos.x(), pos.y());
|
||||
|
@ -681,43 +681,47 @@ void MapPixmapItem::select(QGraphicsSceneMouseEvent *event) {
|
|||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::draw(bool ignoreCache) {
|
||||
if (map) {
|
||||
map->setMapItem(this);
|
||||
setPixmap(map->render(ignoreCache));
|
||||
void LayoutPixmapItem::draw(bool ignoreCache) {
|
||||
if (this->layout) {
|
||||
layout->setLayoutItem(this);
|
||||
setPixmap(this->layout->render(ignoreCache));
|
||||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
||||
void LayoutPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
if (pos != this->metatilePos) {
|
||||
this->metatilePos = pos;
|
||||
emit this->hoveredMapMetatileChanged(pos);
|
||||
}
|
||||
if (this->settings->betterCursors && this->paintingMode != MapPixmapItem::PaintMode::Disabled) {
|
||||
if (this->settings->betterCursors && this->paintingMode != LayoutPixmapItem::PaintMode::Disabled) {
|
||||
setCursor(this->settings->mapCursor);
|
||||
}
|
||||
}
|
||||
void MapPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) {
|
||||
|
||||
void LayoutPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) {
|
||||
this->has_mouse = true;
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
emit this->hoveredMapMetatileChanged(pos);
|
||||
}
|
||||
void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||
|
||||
void LayoutPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||
emit this->hoveredMapMetatileCleared();
|
||||
if (this->settings->betterCursors && this->paintingMode != MapPixmapItem::PaintMode::Disabled) {
|
||||
if (this->settings->betterCursors && this->paintingMode != LayoutPixmapItem::PaintMode::Disabled) {
|
||||
unsetCursor();
|
||||
}
|
||||
this->has_mouse = false;
|
||||
}
|
||||
void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
|
||||
void LayoutPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
this->paint_tile_initial_x = this->straight_path_initial_x = pos.x();
|
||||
this->paint_tile_initial_y = this->straight_path_initial_y = pos.y();
|
||||
emit startPaint(event, this);
|
||||
emit mouseEvent(event, this);
|
||||
}
|
||||
void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
|
||||
void LayoutPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
if (pos != this->metatilePos) {
|
||||
this->metatilePos = pos;
|
||||
|
@ -725,8 +729,9 @@ void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
|||
}
|
||||
emit mouseEvent(event, this);
|
||||
}
|
||||
void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
this->lockedAxis = MapPixmapItem::Axis::None;
|
||||
|
||||
void LayoutPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
this->lockedAxis = LayoutPixmapItem::Axis::None;
|
||||
emit endPaint(event, this);
|
||||
emit mouseEvent(event, this);
|
||||
}
|
|
@ -217,3 +217,146 @@ QVariant MapGroupModel::data(const QModelIndex &index, int role) const {
|
|||
|
||||
return QStandardItemModel::data(index, role);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// case MapSortOrder::Layout:
|
||||
// {
|
||||
// QMap<QString, int> layoutIndices;
|
||||
// for (int i = 0; i < project->mapLayoutsTable.length(); i++) {
|
||||
// QString layoutId = project->mapLayoutsTable.value(i);
|
||||
// MapLayout *layout = project->mapLayouts.value(layoutId);
|
||||
// QStandardItem *layoutItem = new QStandardItem;
|
||||
// layoutItem->setText(layout->name);
|
||||
// layoutItem->setIcon(folderIcon);
|
||||
// layoutItem->setEditable(false);
|
||||
// layoutItem->setData(layout->name, Qt::UserRole);
|
||||
// layoutItem->setData("map_layout", MapListUserRoles::TypeRole);
|
||||
// layoutItem->setData(layout->id, MapListUserRoles::TypeRole2);
|
||||
// layoutItem->setData(i, MapListUserRoles::GroupRole);
|
||||
// root->appendRow(layoutItem);
|
||||
// mapGroupItemsList->append(layoutItem);
|
||||
// layoutIndices[layoutId] = i;
|
||||
// }
|
||||
// for (int i = 0; i < project->groupNames.length(); i++) {
|
||||
// QStringList names = project->groupedMapNames.value(i);
|
||||
// for (int j = 0; j < names.length(); j++) {
|
||||
// QString map_name = names.value(j);
|
||||
// QStandardItem *map = createMapItem(map_name, i, j);
|
||||
// QString layoutId = project->readMapLayoutId(map_name);
|
||||
// QStandardItem *layoutItem = mapGroupItemsList->at(layoutIndices.value(layoutId));
|
||||
// layoutItem->setIcon(mapFolderIcon);
|
||||
// layoutItem->appendRow(map);
|
||||
// mapListIndexes.insert(map_name, map->index());
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
LayoutTreeModel::LayoutTreeModel(Project *project, QObject *parent) : QStandardItemModel(parent) {
|
||||
//
|
||||
|
||||
this->project = project;
|
||||
this->root = this->invisibleRootItem();
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
QStandardItem *LayoutTreeModel::createLayoutItem(QString layoutName) {
|
||||
QStandardItem *layout = new QStandardItem;
|
||||
layout->setText(layoutName);
|
||||
layout->setEditable(false);
|
||||
layout->setData(layoutName, Qt::UserRole);
|
||||
layout->setData("map_layout", MapListRoles::TypeRole);
|
||||
// // group->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
|
||||
this->layoutItems.insert(layoutName, layout);
|
||||
return layout;
|
||||
}
|
||||
|
||||
QStandardItem *LayoutTreeModel::createMapItem(QString mapName) {
|
||||
QStandardItem *map = new QStandardItem;
|
||||
map->setText(mapName);
|
||||
map->setEditable(false);
|
||||
map->setData(mapName, Qt::UserRole);
|
||||
map->setData("map_name", MapListRoles::TypeRole);
|
||||
map->setFlags(Qt::NoItemFlags | Qt::ItemNeverHasChildren);
|
||||
this->mapItems.insert(mapName, map);
|
||||
return map;
|
||||
}
|
||||
|
||||
void LayoutTreeModel::initialize() {
|
||||
for (int i = 0; i < this->project->mapLayoutsTable.length(); i++) {
|
||||
//
|
||||
QString layoutId = project->mapLayoutsTable.value(i);
|
||||
MapLayout *layout = project->mapLayouts.value(layoutId);
|
||||
QStandardItem *layoutItem = createLayoutItem(layout->name);
|
||||
this->root->appendRow(layoutItem);
|
||||
}
|
||||
|
||||
for (auto mapList : this->project->groupedMapNames) {
|
||||
for (auto mapName : mapList) {
|
||||
//
|
||||
QString layoutName = project->readMapLayoutName(mapName);
|
||||
QStandardItem *map = createMapItem(mapName);
|
||||
this->layoutItems[layoutName]->appendRow(map);
|
||||
}
|
||||
}
|
||||
|
||||
// // project->readMapLayoutName
|
||||
}
|
||||
|
||||
QStandardItem *LayoutTreeModel::getItem(const QModelIndex &index) const {
|
||||
if (index.isValid()) {
|
||||
QStandardItem *item = static_cast<QStandardItem*>(index.internalPointer());
|
||||
if (item)
|
||||
return item;
|
||||
}
|
||||
return this->root;
|
||||
}
|
||||
|
||||
QModelIndex LayoutTreeModel::indexOfLayout(QString layoutName) {
|
||||
if (this->layoutItems.contains(layoutName)) {
|
||||
return this->layoutItems[layoutName]->index();
|
||||
}
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QVariant LayoutTreeModel::data(const QModelIndex &index, int role) const {
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
|
||||
if (role == Qt::DecorationRole) {
|
||||
static QIcon mapIcon = QIcon(QStringLiteral(":/icons/map.ico"));
|
||||
static QIcon mapEditedIcon = QIcon(QStringLiteral(":/icons/map_edited.ico"));
|
||||
static QIcon mapOpenedIcon = QIcon(QStringLiteral(":/icons/map_opened.ico"));
|
||||
|
||||
QStandardItem *item = this->getItem(index)->child(row, col);
|
||||
QString type = item->data(MapListRoles::TypeRole).toString();
|
||||
|
||||
if (type == "map_layout") {
|
||||
return mapIcon;
|
||||
}
|
||||
else if (type == "map_name") {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
||||
// check if map or group
|
||||
// if map, check if edited or open
|
||||
//return QIcon(":/icons/porymap-icon-2.ico");
|
||||
}
|
||||
|
||||
return QStandardItemModel::data(index, role);
|
||||
}
|
||||
|
||||
|
|
|
@ -96,13 +96,13 @@ void NewMapPopup::init() {
|
|||
void NewMapPopup::init(MapSortOrder type, QVariant data) {
|
||||
switch (type)
|
||||
{
|
||||
case MapSortOrder::Group:
|
||||
case MapSortOrder::SortByGroup:
|
||||
settings.group = project->groupNames.at(data.toInt());
|
||||
break;
|
||||
case MapSortOrder::Area:
|
||||
case MapSortOrder::SortByArea:
|
||||
settings.location = data.toString();
|
||||
break;
|
||||
case MapSortOrder::Layout:
|
||||
case MapSortOrder::SortByLayout:
|
||||
useLayout(data.toString());
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue