fix edit commands and ui things to use layout instead of map
This commit is contained in:
parent
2bc51f1c29
commit
90f8218c32
24 changed files with 315 additions and 674 deletions
|
@ -342,12 +342,12 @@ public:
|
|||
|
||||
|
||||
|
||||
// !TODO
|
||||
// !TODO: rename map vars to layout
|
||||
/// 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 {
|
||||
public:
|
||||
ScriptEditMap(Map *map,
|
||||
ScriptEditMap(Layout *layout,
|
||||
QSize oldMapDimensions, QSize newMapDimensions,
|
||||
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
|
||||
QSize oldBorderDimensions, QSize newBorderDimensions,
|
||||
|
@ -361,7 +361,7 @@ public:
|
|||
int id() const override { return CommandId::ID_ScriptEditMap; }
|
||||
|
||||
private:
|
||||
Map *map;
|
||||
Layout *layout = nullptr;
|
||||
|
||||
Blockdata newMetatiles;
|
||||
Blockdata oldMetatiles;
|
||||
|
|
|
@ -66,20 +66,11 @@ public:
|
|||
bool needsLayoutDir = true;
|
||||
bool needsHealLocation = false;
|
||||
|
||||
QImage collision_image;
|
||||
QPixmap collision_pixmap;
|
||||
QImage image;
|
||||
QPixmap pixmap;
|
||||
|
||||
QMap<Event::Group, QList<Event *>> events;
|
||||
QList<Event *> ownedEvents; // for memory management
|
||||
|
||||
QList<MapConnection*> connections;
|
||||
|
||||
// !TODO
|
||||
QList<int> metatileLayerOrder;
|
||||
QList<float> metatileLayerOpacity;
|
||||
|
||||
void setName(QString mapName);
|
||||
static QString mapConstantFromName(QString mapName);
|
||||
|
||||
|
@ -89,68 +80,21 @@ public:
|
|||
int getBorderWidth();
|
||||
int getBorderHeight();
|
||||
|
||||
QUndoStack editHistory;
|
||||
void modify();
|
||||
void clean();
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
QList<Event *> getAllEvents() const;
|
||||
QStringList eventScriptLabels(Event::Group group = Event::Group::None) const;
|
||||
void removeEvent(Event *);
|
||||
void addEvent(Event *);
|
||||
|
||||
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 clearBorderCache();
|
||||
void cacheBorder();
|
||||
|
||||
bool hasUnsavedChanges();
|
||||
|
||||
bool isWithinBounds(int x, int y);
|
||||
bool isWithinBorderBounds(int x, int y);
|
||||
|
||||
void openScript(QString label);
|
||||
|
||||
private:
|
||||
LayoutPixmapItem *mapItem = nullptr;
|
||||
QUndoStack editHistory;
|
||||
void modify();
|
||||
void clean();
|
||||
bool hasUnsavedChanges();
|
||||
|
||||
public:
|
||||
void setMapItem(LayoutPixmapItem *item) { mapItem = item; }
|
||||
QPixmap renderConnection(MapConnection, Layout *);
|
||||
|
||||
CollisionPixmapItem *collisionItem = nullptr;
|
||||
void setCollisionItem(CollisionPixmapItem *item) { collisionItem = item; }
|
||||
|
||||
BorderMetatilesPixmapItem *borderItem = nullptr;
|
||||
void setBorderItem(BorderMetatilesPixmapItem *item) { borderItem = item; }
|
||||
|
||||
private:
|
||||
void setNewDimensionsBlockdata(int newWidth, int newHeight);
|
||||
void setNewBorderDimensionsBlockdata(int newWidth, int newHeight);
|
||||
|
||||
signals:
|
||||
void mapChanged(Map *map);
|
||||
|
|
|
@ -77,9 +77,8 @@ public:
|
|||
int getBorderWidth();
|
||||
int getBorderHeight();
|
||||
|
||||
bool isWithinBounds(int x, int y) {
|
||||
return (x >= 0 && x < this->getWidth() && y >= 0 && y < this->getHeight());
|
||||
}
|
||||
bool isWithinBounds(int x, int y);
|
||||
bool isWithinBorderBounds(int x, int y);
|
||||
|
||||
bool getBlock(int x, int y, Block *out);
|
||||
void setBlock(int x, int y, Block block, bool enableScriptCallback = false);
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
#ifndef CURRENTSELECTEDMETATILESPIXMAPITEM_H
|
||||
#define CURRENTSELECTEDMETATILESPIXMAPITEM_H
|
||||
|
||||
#include "map.h"
|
||||
#include "metatileselector.h"
|
||||
#include <QGraphicsPixmapItem>
|
||||
|
||||
class Layout;
|
||||
|
||||
class CurrentSelectedMetatilesPixmapItem : public QGraphicsPixmapItem {
|
||||
public:
|
||||
CurrentSelectedMetatilesPixmapItem(Map *map, MetatileSelector *metatileSelector) {
|
||||
this->map = map;
|
||||
CurrentSelectedMetatilesPixmapItem(Layout *layout, MetatileSelector *metatileSelector) {
|
||||
this->layout = layout;
|
||||
this->metatileSelector = metatileSelector;
|
||||
}
|
||||
Map* map = nullptr;
|
||||
Layout *layout = nullptr;
|
||||
MetatileSelector *metatileSelector;
|
||||
void draw();
|
||||
|
||||
void setMap(Map *map) { this->map = map; }
|
||||
void setLayout(Layout *layout) { this->layout = layout; }
|
||||
};
|
||||
|
||||
QPixmap drawMetatileSelection(MetatileSelection selection, Map *map);
|
||||
QPixmap drawMetatileSelection(MetatileSelection selection, Layout *layout);
|
||||
|
||||
#endif // CURRENTSELECTEDMETATILESPIXMAPITEM_H
|
||||
|
|
|
@ -31,13 +31,13 @@ struct MetatileSelection
|
|||
class MetatileSelector: public SelectablePixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
MetatileSelector(int numMetatilesWide, Map *map): SelectablePixmapItem(16, 16) {
|
||||
MetatileSelector(int numMetatilesWide, Layout *layout): SelectablePixmapItem(16, 16) {
|
||||
this->externalSelection = false;
|
||||
this->prefabSelection = false;
|
||||
this->numMetatilesWide = numMetatilesWide;
|
||||
this->map = map;
|
||||
this->primaryTileset = map->layout->tileset_primary;
|
||||
this->secondaryTileset = map->layout->tileset_secondary;
|
||||
this->layout = layout;
|
||||
this->primaryTileset = layout->tileset_primary;
|
||||
this->secondaryTileset = layout->tileset_secondary;
|
||||
this->selection = MetatileSelection{};
|
||||
setAcceptHoverEvents(true);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public:
|
|||
void setPrefabSelection(MetatileSelection selection);
|
||||
void setExternalSelection(int, int, QList<uint16_t>, QList<QPair<uint16_t, uint16_t>>);
|
||||
QPoint getMetatileIdCoordsOnWidget(uint16_t);
|
||||
void setMap(Map*);
|
||||
void setLayout(Layout *layout);
|
||||
Tileset *primaryTileset;
|
||||
Tileset *secondaryTileset;
|
||||
protected:
|
||||
|
@ -63,7 +63,7 @@ private:
|
|||
bool externalSelection;
|
||||
bool prefabSelection;
|
||||
int numMetatilesWide;
|
||||
Map *map;
|
||||
Layout *layout;
|
||||
int externalSelectionWidth;
|
||||
int externalSelectionHeight;
|
||||
QList<uint16_t> externalSelectedMetatiles;
|
||||
|
|
|
@ -20,9 +20,9 @@ struct PrefabItem
|
|||
class Prefab
|
||||
{
|
||||
public:
|
||||
void initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Map *map);
|
||||
void addPrefab(MetatileSelection selection, Map *map, QString name);
|
||||
void updatePrefabUi(Map *map);
|
||||
void initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Layout *layout);
|
||||
void addPrefab(MetatileSelection selection, Layout *layout, QString name);
|
||||
void updatePrefabUi(Layout *layout);
|
||||
bool tryImportDefaultPrefabs(QWidget * parent, BaseGameVersion version, QString filepath = "");
|
||||
|
||||
private:
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
#define PREFABCREATIONDIALOG_H
|
||||
|
||||
#include "metatileselector.h"
|
||||
#include "map.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class Layout;
|
||||
|
||||
namespace Ui {
|
||||
class PrefabCreationDialog;
|
||||
}
|
||||
|
@ -15,12 +16,12 @@ class PrefabCreationDialog : public QDialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PrefabCreationDialog(QWidget *parent, MetatileSelector *metatileSelector, Map *map);
|
||||
explicit PrefabCreationDialog(QWidget *parent, MetatileSelector *metatileSelector, Layout *layout);
|
||||
~PrefabCreationDialog();
|
||||
void savePrefab();
|
||||
|
||||
private:
|
||||
Map *map;
|
||||
Layout *layout = nullptr;
|
||||
Ui::PrefabCreationDialog *ui;
|
||||
MetatileSelection selection;
|
||||
};
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
#include "tileseteditormetatileselector.h"
|
||||
#include "tileseteditortileselector.h"
|
||||
#include "metatilelayersitem.h"
|
||||
#include "map.h"
|
||||
|
||||
class Layout;
|
||||
|
||||
namespace Ui {
|
||||
class TilesetEditor;
|
||||
|
@ -39,10 +40,10 @@ class TilesetEditor : public QMainWindow
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TilesetEditor(Project*, Map*, QWidget *parent = nullptr);
|
||||
explicit TilesetEditor(Project *project, Layout *layout, QWidget *parent = nullptr);
|
||||
~TilesetEditor();
|
||||
void update(Map *map, QString primaryTilsetLabel, QString secondaryTilesetLabel);
|
||||
void updateMap(Map *map);
|
||||
void update(Layout *layout, QString primaryTilsetLabel, QString secondaryTilesetLabel);
|
||||
void updateLayout(Layout *layout);
|
||||
void updateTilesets(QString primaryTilsetLabel, QString secondaryTilesetLabel);
|
||||
bool selectMetatile(uint16_t metatileId);
|
||||
uint16_t getSelectedMetatileId();
|
||||
|
@ -148,7 +149,7 @@ private:
|
|||
MetatileLayersItem *metatileLayersItem = nullptr;
|
||||
PaletteEditor *paletteEditor = nullptr;
|
||||
Project *project = nullptr;
|
||||
Map *map = nullptr;
|
||||
Layout *layout = nullptr;
|
||||
Metatile *metatile = nullptr;
|
||||
Metatile *copiedMetatile = nullptr;
|
||||
QString copiedMetatileLabel;
|
||||
|
|
|
@ -3,13 +3,14 @@
|
|||
|
||||
#include "selectablepixmapitem.h"
|
||||
#include "tileset.h"
|
||||
#include "map.h"
|
||||
|
||||
class Layout;
|
||||
|
||||
class TilesetEditorMetatileSelector: public SelectablePixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TilesetEditorMetatileSelector(Tileset *primaryTileset, Tileset *secondaryTileset, Map *map);
|
||||
Map *map = nullptr;
|
||||
TilesetEditorMetatileSelector(Tileset *primaryTileset, Tileset *secondaryTileset, Layout *layout);
|
||||
Layout *layout = nullptr;
|
||||
void draw();
|
||||
bool select(uint16_t metatileId);
|
||||
void setTilesets(Tileset*, Tileset*, bool draw = true);
|
||||
|
|
|
@ -487,7 +487,7 @@ int EventPaste::id() const {
|
|||
************************************************************************
|
||||
******************************************************************************/
|
||||
|
||||
ScriptEditMap::ScriptEditMap(Map *map,
|
||||
ScriptEditMap::ScriptEditMap(Layout *layout,
|
||||
QSize oldMapDimensions, QSize newMapDimensions,
|
||||
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
|
||||
QSize oldBorderDimensions, QSize newBorderDimensions,
|
||||
|
@ -495,7 +495,7 @@ ScriptEditMap::ScriptEditMap(Map *map,
|
|||
QUndoCommand *parent) : QUndoCommand(parent) {
|
||||
setText("Script Edit Map");
|
||||
|
||||
this->map = map;
|
||||
this->layout = layout;
|
||||
|
||||
this->newMetatiles = newMetatiles;
|
||||
this->oldMetatiles = oldMetatiles;
|
||||
|
@ -517,57 +517,57 @@ ScriptEditMap::ScriptEditMap(Map *map,
|
|||
void ScriptEditMap::redo() {
|
||||
QUndoCommand::redo();
|
||||
|
||||
if (!map) return;
|
||||
if (!layout) return;
|
||||
|
||||
if (newMapWidth != map->getWidth() || newMapHeight != map->getHeight()) {
|
||||
map->layout->blockdata = newMetatiles;
|
||||
map->setDimensions(newMapWidth, newMapHeight, false);
|
||||
if (newMapWidth != layout->getWidth() || newMapHeight != layout->getHeight()) {
|
||||
layout->blockdata = newMetatiles;
|
||||
layout->setDimensions(newMapWidth, newMapHeight, false);
|
||||
} else {
|
||||
map->setBlockdata(newMetatiles);
|
||||
layout->setBlockdata(newMetatiles);
|
||||
}
|
||||
|
||||
if (newBorderWidth != map->getBorderWidth() || newBorderHeight != map->getBorderHeight()) {
|
||||
map->layout->border = newBorder;
|
||||
map->setBorderDimensions(newBorderWidth, newBorderHeight, false);
|
||||
if (newBorderWidth != layout->getBorderWidth() || newBorderHeight != layout->getBorderHeight()) {
|
||||
layout->border = newBorder;
|
||||
layout->setBorderDimensions(newBorderWidth, newBorderHeight, false);
|
||||
} else {
|
||||
map->setBorderBlockData(newBorder);
|
||||
layout->setBorderBlockData(newBorder);
|
||||
}
|
||||
|
||||
map->layout->lastCommitBlocks.blocks = newMetatiles;
|
||||
map->layout->lastCommitBlocks.mapDimensions = QSize(newMapWidth, newMapHeight);
|
||||
map->layout->lastCommitBlocks.border = newBorder;
|
||||
map->layout->lastCommitBlocks.borderDimensions = QSize(newBorderWidth, newBorderHeight);
|
||||
layout->lastCommitBlocks.blocks = newMetatiles;
|
||||
layout->lastCommitBlocks.mapDimensions = QSize(newMapWidth, newMapHeight);
|
||||
layout->lastCommitBlocks.border = newBorder;
|
||||
layout->lastCommitBlocks.borderDimensions = QSize(newBorderWidth, newBorderHeight);
|
||||
|
||||
// !TODO
|
||||
renderBlocks(map->layout);
|
||||
map->borderItem->draw();
|
||||
renderBlocks(layout);
|
||||
layout->borderItem->draw();
|
||||
}
|
||||
|
||||
void ScriptEditMap::undo() {
|
||||
if (!map) return;
|
||||
if (!layout) return;
|
||||
|
||||
if (oldMapWidth != map->getWidth() || oldMapHeight != map->getHeight()) {
|
||||
map->layout->blockdata = oldMetatiles;
|
||||
map->setDimensions(oldMapWidth, oldMapHeight, false);
|
||||
if (oldMapWidth != layout->getWidth() || oldMapHeight != layout->getHeight()) {
|
||||
layout->blockdata = oldMetatiles;
|
||||
layout->setDimensions(oldMapWidth, oldMapHeight, false);
|
||||
} else {
|
||||
map->setBlockdata(oldMetatiles);
|
||||
layout->setBlockdata(oldMetatiles);
|
||||
}
|
||||
|
||||
if (oldBorderWidth != map->getBorderWidth() || oldBorderHeight != map->getBorderHeight()) {
|
||||
map->layout->border = oldBorder;
|
||||
map->setBorderDimensions(oldBorderWidth, oldBorderHeight, false);
|
||||
if (oldBorderWidth != layout->getBorderWidth() || oldBorderHeight != layout->getBorderHeight()) {
|
||||
layout->border = oldBorder;
|
||||
layout->setBorderDimensions(oldBorderWidth, oldBorderHeight, false);
|
||||
} else {
|
||||
map->setBorderBlockData(oldBorder);
|
||||
layout->setBorderBlockData(oldBorder);
|
||||
}
|
||||
|
||||
map->layout->lastCommitBlocks.blocks = oldMetatiles;
|
||||
map->layout->lastCommitBlocks.mapDimensions = QSize(oldMapWidth, oldMapHeight);
|
||||
map->layout->lastCommitBlocks.border = oldBorder;
|
||||
map->layout->lastCommitBlocks.borderDimensions = QSize(oldBorderWidth, oldBorderHeight);
|
||||
layout->lastCommitBlocks.blocks = oldMetatiles;
|
||||
layout->lastCommitBlocks.mapDimensions = QSize(oldMapWidth, oldMapHeight);
|
||||
layout->lastCommitBlocks.border = oldBorder;
|
||||
layout->lastCommitBlocks.borderDimensions = QSize(oldBorderWidth, oldBorderHeight);
|
||||
|
||||
// !TODO
|
||||
renderBlocks(map->layout);
|
||||
map->borderItem->draw();
|
||||
renderBlocks(layout);
|
||||
layout->borderItem->draw();
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
|
326
src/core/map.cpp
326
src/core/map.cpp
|
@ -60,121 +60,6 @@ int Map::getBorderHeight() {
|
|||
return layout->getBorderHeight();
|
||||
}
|
||||
|
||||
bool Map::mapBlockChanged(int i, const Blockdata &cache) {
|
||||
if (cache.length() <= i)
|
||||
return true;
|
||||
if (layout->blockdata.length() <= i)
|
||||
return true;
|
||||
|
||||
return layout->blockdata.at(i) != cache.at(i);
|
||||
}
|
||||
|
||||
bool Map::borderBlockChanged(int i, const Blockdata &cache) {
|
||||
if (cache.length() <= i)
|
||||
return true;
|
||||
if (layout->border.length() <= i)
|
||||
return true;
|
||||
|
||||
return layout->border.at(i) != cache.at(i);
|
||||
}
|
||||
|
||||
void Map::clearBorderCache() {
|
||||
layout->cached_border.clear();
|
||||
}
|
||||
|
||||
void Map::cacheBorder() {
|
||||
layout->cached_border.clear();
|
||||
for (const auto &block : layout->border)
|
||||
layout->cached_border.append(block);
|
||||
}
|
||||
|
||||
void Map::cacheBlockdata() {
|
||||
layout->cached_blockdata.clear();
|
||||
for (const auto &block : layout->blockdata)
|
||||
layout->cached_blockdata.append(block);
|
||||
}
|
||||
|
||||
void Map::cacheCollision() {
|
||||
layout->cached_collision.clear();
|
||||
for (const auto &block : layout->blockdata)
|
||||
layout->cached_collision.append(block);
|
||||
}
|
||||
|
||||
QPixmap Map::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 (layout->blockdata.isEmpty() || !width_ || !height_) {
|
||||
collision_pixmap = collision_pixmap.fromImage(collision_image);
|
||||
return collision_pixmap;
|
||||
}
|
||||
QPainter painter(&collision_image);
|
||||
for (int i = 0; i < layout->blockdata.length(); i++) {
|
||||
if (!ignoreCache && !mapBlockChanged(i, layout->cached_collision)) {
|
||||
continue;
|
||||
}
|
||||
changed_any = true;
|
||||
Block block = layout->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 Map::render(bool ignoreCache, Layout *fromLayout, QRect bounds) {
|
||||
return this->layout->render(ignoreCache, fromLayout, bounds);
|
||||
}
|
||||
|
||||
QPixmap Map::renderBorder(bool ignoreCache) {
|
||||
bool changed_any = false, border_resized = false;
|
||||
int width_ = getBorderWidth();
|
||||
int height_ = getBorderHeight();
|
||||
if (layout->border_image.isNull()) {
|
||||
layout->border_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||
changed_any = true;
|
||||
}
|
||||
if (layout->border_image.width() != width_ * 16 || layout->border_image.height() != height_ * 16) {
|
||||
layout->border_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||
border_resized = true;
|
||||
}
|
||||
if (layout->border.isEmpty()) {
|
||||
layout->border_pixmap = layout->border_pixmap.fromImage(layout->border_image);
|
||||
return layout->border_pixmap;
|
||||
}
|
||||
QPainter painter(&layout->border_image);
|
||||
for (int i = 0; i < layout->border.length(); i++) {
|
||||
if (!ignoreCache && (!border_resized && !borderBlockChanged(i, layout->cached_border))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
changed_any = true;
|
||||
Block block = layout->border.at(i);
|
||||
uint16_t metatileId = block.metatileId;
|
||||
QImage metatile_image = getMetatileImage(metatileId, layout->tileset_primary, layout->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();
|
||||
layout->border_pixmap = layout->border_pixmap.fromImage(layout->border_image);
|
||||
}
|
||||
return layout->border_pixmap;
|
||||
}
|
||||
|
||||
QPixmap Map::renderConnection(MapConnection connection, Layout *fromLayout) {
|
||||
int x, y, w, h;
|
||||
if (connection.direction == "up") {
|
||||
|
@ -207,213 +92,14 @@ QPixmap Map::renderConnection(MapConnection connection, Layout *fromLayout) {
|
|||
|
||||
//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 this->layout->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) {
|
||||
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(layout->blockdata.value(index));
|
||||
} else {
|
||||
newBlockdata.append(0);
|
||||
}
|
||||
}
|
||||
|
||||
layout->blockdata = newBlockdata;
|
||||
}
|
||||
|
||||
void Map::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(layout->border.value(index));
|
||||
} else {
|
||||
newBlockdata.append(0);
|
||||
}
|
||||
}
|
||||
|
||||
layout->border = newBlockdata;
|
||||
}
|
||||
|
||||
void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata, bool enableScriptCallback) {
|
||||
if (setNewBlockdata) {
|
||||
setNewDimensionsBlockdata(newWidth, newHeight);
|
||||
}
|
||||
|
||||
int oldWidth = layout->width;
|
||||
int oldHeight = layout->height;
|
||||
layout->width = newWidth;
|
||||
layout->height = newHeight;
|
||||
|
||||
if (enableScriptCallback && (oldWidth != newWidth || oldHeight != newHeight)) {
|
||||
Scripting::cb_MapResized(oldWidth, oldHeight, newWidth, newHeight);
|
||||
}
|
||||
|
||||
emit mapChanged(this);
|
||||
emit mapDimensionsChanged(QSize(getWidth(), getHeight()));
|
||||
}
|
||||
|
||||
void Map::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata, bool enableScriptCallback) {
|
||||
if (setNewBlockdata) {
|
||||
setNewBorderDimensionsBlockdata(newWidth, newHeight);
|
||||
}
|
||||
|
||||
int oldWidth = layout->border_width;
|
||||
int oldHeight = layout->border_height;
|
||||
layout->border_width = newWidth;
|
||||
layout->border_height = newHeight;
|
||||
|
||||
if (enableScriptCallback && (oldWidth != newWidth || oldHeight != newHeight)) {
|
||||
Scripting::cb_BorderResized(oldWidth, oldHeight, newWidth, newHeight);
|
||||
}
|
||||
|
||||
emit mapChanged(this);
|
||||
}
|
||||
|
||||
void Map::openScript(QString label) {
|
||||
emit openScriptRequested(label);
|
||||
}
|
||||
|
||||
bool Map::getBlock(int x, int y, Block *out) {
|
||||
if (isWithinBounds(x, y)) {
|
||||
int i = y * getWidth() + x;
|
||||
*out = layout->blockdata.value(i);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Map::setBlock(int x, int y, Block block, bool enableScriptCallback) {
|
||||
if (!isWithinBounds(x, y)) return;
|
||||
int i = y * getWidth() + x;
|
||||
if (i < layout->blockdata.size()) {
|
||||
Block prevBlock = layout->blockdata.at(i);
|
||||
layout->blockdata.replace(i, block);
|
||||
if (enableScriptCallback) {
|
||||
Scripting::cb_MetatileChanged(x, y, prevBlock, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Map::setBlockdata(Blockdata blockdata, bool enableScriptCallback) {
|
||||
int width = getWidth();
|
||||
int size = qMin(blockdata.size(), layout->blockdata.size());
|
||||
for (int i = 0; i < size; i++) {
|
||||
Block prevBlock = layout->blockdata.at(i);
|
||||
Block newBlock = blockdata.at(i);
|
||||
if (prevBlock != newBlock) {
|
||||
layout->blockdata.replace(i, newBlock);
|
||||
if (enableScriptCallback)
|
||||
Scripting::cb_MetatileChanged(i % width, i / width, prevBlock, newBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t Map::getBorderMetatileId(int x, int y) {
|
||||
int i = y * getBorderWidth() + x;
|
||||
return layout->border[i].metatileId;
|
||||
}
|
||||
|
||||
void Map::setBorderMetatileId(int x, int y, uint16_t metatileId, bool enableScriptCallback) {
|
||||
int i = y * getBorderWidth() + x;
|
||||
if (i < layout->border.size()) {
|
||||
uint16_t prevMetatileId = layout->border[i].metatileId;
|
||||
layout->border[i].metatileId = metatileId;
|
||||
if (prevMetatileId != metatileId && enableScriptCallback) {
|
||||
Scripting::cb_BorderMetatileChanged(x, y, prevMetatileId, metatileId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Map::setBorderBlockData(Blockdata blockdata, bool enableScriptCallback) {
|
||||
int width = getBorderWidth();
|
||||
int size = qMin(blockdata.size(), layout->border.size());
|
||||
for (int i = 0; i < size; i++) {
|
||||
Block prevBlock = layout->border.at(i);
|
||||
Block newBlock = blockdata.at(i);
|
||||
if (prevBlock != newBlock) {
|
||||
layout->border.replace(i, newBlock);
|
||||
if (enableScriptCallback)
|
||||
Scripting::cb_BorderMetatileChanged(i % width, i / width, prevBlock.metatileId, newBlock.metatileId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Map::_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 Map::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 Map::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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QList<Event *> Map::getAllEvents() const {
|
||||
QList<Event *> all_events;
|
||||
for (const auto &event_list : events) {
|
||||
|
@ -468,13 +154,5 @@ void Map::clean() {
|
|||
}
|
||||
|
||||
bool Map::hasUnsavedChanges() {
|
||||
return !editHistory.isClean() || hasUnsavedDataChanges || !isPersistedToFile;
|
||||
}
|
||||
|
||||
bool Map::isWithinBounds(int x, int y) {
|
||||
return (x >= 0 && x < this->getWidth() && y >= 0 && y < this->getHeight());
|
||||
}
|
||||
|
||||
bool Map::isWithinBorderBounds(int x, int y) {
|
||||
return (x >= 0 && x < this->getBorderWidth() && y >= 0 && y < this->getBorderHeight());
|
||||
return !editHistory.isClean() /* || !this->layout->editHistory.isClean() */ || hasUnsavedDataChanges || !isPersistedToFile;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,14 @@ int Layout::getBorderHeight() {
|
|||
return border_height;
|
||||
}
|
||||
|
||||
bool Layout::isWithinBounds(int x, int y) {
|
||||
return (x >= 0 && x < this->getWidth() && y >= 0 && y < this->getHeight());
|
||||
}
|
||||
|
||||
bool Layout::isWithinBorderBounds(int x, int y) {
|
||||
return (x >= 0 && x < this->getBorderWidth() && y >= 0 && y < this->getBorderHeight());
|
||||
}
|
||||
|
||||
bool Layout::getBlock(int x, int y, Block *out) {
|
||||
if (isWithinBounds(x, y)) {
|
||||
int i = y * getWidth() + x;
|
||||
|
|
|
@ -111,7 +111,7 @@ void Editor::setEditingCollision() {
|
|||
collision_item->setVisible(true);
|
||||
}
|
||||
if (map_item) {
|
||||
map_item->paintingMode = MapPixmapItem::PaintMode::Metatiles;
|
||||
map_item->paintingMode = LayoutPixmapItem::PaintMode::Metatiles;
|
||||
map_item->draw();
|
||||
map_item->setVisible(true);
|
||||
}
|
||||
|
@ -1017,13 +1017,13 @@ void Editor::setCursorRectVisible(bool visible) {
|
|||
void Editor::onHoveredMapMetatileChanged(const QPoint &pos) {
|
||||
int x = pos.x();
|
||||
int y = pos.y();
|
||||
if (!map->isWithinBounds(x, y))
|
||||
if (!layout->isWithinBounds(x, y))
|
||||
return;
|
||||
|
||||
this->updateCursorRectPos(x, y);
|
||||
if (map_item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) {
|
||||
int blockIndex = y * map->getWidth() + x;
|
||||
int metatileId = map->layout->blockdata.at(blockIndex).metatileId;
|
||||
int blockIndex = y * layout->getWidth() + x;
|
||||
int metatileId = layout->blockdata.at(blockIndex).metatileId;
|
||||
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, %3, Scale = %4x")
|
||||
.arg(x)
|
||||
.arg(y)
|
||||
|
@ -1049,14 +1049,14 @@ void Editor::onHoveredMapMetatileCleared() {
|
|||
}
|
||||
|
||||
void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
|
||||
if (!map->isWithinBounds(x, y))
|
||||
if (!layout->isWithinBounds(x, y))
|
||||
return;
|
||||
|
||||
this->updateCursorRectPos(x, y);
|
||||
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;
|
||||
int blockIndex = y * layout->getWidth() + x;
|
||||
uint16_t collision = layout->blockdata.at(blockIndex).collision;
|
||||
uint16_t elevation = layout->blockdata.at(blockIndex).elevation;
|
||||
QString message = QString("X: %1, Y: %2, %3")
|
||||
.arg(x)
|
||||
.arg(y)
|
||||
|
@ -1385,7 +1385,7 @@ void Editor::displayMetatileSelector() {
|
|||
}
|
||||
scene_metatiles = new QGraphicsScene;
|
||||
if (!metatile_selector_item) {
|
||||
metatile_selector_item = new MetatileSelector(8, map);
|
||||
metatile_selector_item = new MetatileSelector(8, this->layout);
|
||||
connect(metatile_selector_item, &MetatileSelector::hoveredMetatileSelectionChanged,
|
||||
this, &Editor::onHoveredMetatileSelectionChanged);
|
||||
connect(metatile_selector_item, &MetatileSelector::hoveredMetatileSelectionCleared,
|
||||
|
@ -1394,7 +1394,7 @@ void Editor::displayMetatileSelector() {
|
|||
this, &Editor::onSelectedMetatilesChanged);
|
||||
metatile_selector_item->select(0);
|
||||
} else {
|
||||
metatile_selector_item->setMap(map);
|
||||
metatile_selector_item->setLayout(this->layout);
|
||||
if (metatile_selector_item->primaryTileset
|
||||
&& metatile_selector_item->primaryTileset != map->layout->tileset_primary)
|
||||
emit tilesetUpdated(map->layout->tileset_primary->name);
|
||||
|
@ -1471,14 +1471,14 @@ void Editor::displayCurrentMetatilesSelection() {
|
|||
}
|
||||
|
||||
scene_current_metatile_selection = new QGraphicsScene;
|
||||
current_metatile_selection_item = new CurrentSelectedMetatilesPixmapItem(map, this->metatile_selector_item);
|
||||
current_metatile_selection_item = new CurrentSelectedMetatilesPixmapItem(this->layout, this->metatile_selector_item);
|
||||
current_metatile_selection_item->draw();
|
||||
scene_current_metatile_selection->addItem(current_metatile_selection_item);
|
||||
}
|
||||
|
||||
void Editor::redrawCurrentMetatilesSelection() {
|
||||
if (current_metatile_selection_item) {
|
||||
current_metatile_selection_item->setMap(map);
|
||||
current_metatile_selection_item->setLayout(this->layout);
|
||||
current_metatile_selection_item->draw();
|
||||
emit currentMetatilesSelectionChanged();
|
||||
}
|
||||
|
@ -1635,7 +1635,7 @@ void Editor::displayMapBorder() {
|
|||
int borderHeight = map->getBorderHeight();
|
||||
int borderHorzDist = getBorderDrawDistance(borderWidth);
|
||||
int borderVertDist = getBorderDrawDistance(borderHeight);
|
||||
QPixmap pixmap = map->renderBorder();
|
||||
QPixmap pixmap = this->layout->renderBorder();
|
||||
for (int y = -borderVertDist; y < map->getHeight() + borderVertDist; y += borderHeight)
|
||||
for (int x = -borderHorzDist; x < map->getWidth() + borderHorzDist; x += borderWidth) {
|
||||
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
||||
|
@ -1648,7 +1648,7 @@ void Editor::displayMapBorder() {
|
|||
}
|
||||
|
||||
void Editor::updateMapBorder() {
|
||||
QPixmap pixmap = this->map->renderBorder(true);
|
||||
QPixmap pixmap = this->layout->renderBorder(true);
|
||||
for (auto item : this->borderItems) {
|
||||
item->setPixmap(pixmap);
|
||||
}
|
||||
|
@ -1925,7 +1925,7 @@ void Editor::updatePrimaryTileset(QString tilesetLabel, bool forceLoad)
|
|||
{
|
||||
map->layout->tileset_primary_label = tilesetLabel;
|
||||
map->layout->tileset_primary = project->getTileset(tilesetLabel, forceLoad);
|
||||
map->clearBorderCache();
|
||||
layout->clearBorderCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1935,7 +1935,7 @@ void Editor::updateSecondaryTileset(QString tilesetLabel, bool forceLoad)
|
|||
{
|
||||
map->layout->tileset_secondary_label = tilesetLabel;
|
||||
map->layout->tileset_secondary = project->getTileset(tilesetLabel, forceLoad);
|
||||
map->clearBorderCache();
|
||||
layout->clearBorderCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -536,7 +536,7 @@ bool MainWindow::openProject(QString dir) {
|
|||
editor->metatile_selector_item,
|
||||
ui->scrollAreaWidgetContents_Prefabs,
|
||||
ui->label_prefabHelp,
|
||||
editor->map);
|
||||
editor->layout);
|
||||
Scripting::cb_ProjectOpened(dir);
|
||||
return true;
|
||||
}
|
||||
|
@ -674,7 +674,7 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
|
|||
updateMapList();
|
||||
|
||||
Scripting::cb_MapOpened(map_name);
|
||||
prefab.updatePrefabUi(editor->map);
|
||||
prefab.updatePrefabUi(editor->layout);
|
||||
updateTilesetEditor();
|
||||
return true;
|
||||
}
|
||||
|
@ -1352,7 +1352,7 @@ void MainWindow::on_actionNew_Tileset_triggered() {
|
|||
void MainWindow::updateTilesetEditor() {
|
||||
if (this->tilesetEditor) {
|
||||
this->tilesetEditor->update(
|
||||
this->editor->map,
|
||||
this->editor->layout,
|
||||
editor->ui->comboBox_PrimaryTileset->currentText(),
|
||||
editor->ui->comboBox_SecondaryTileset->currentText()
|
||||
);
|
||||
|
@ -1532,7 +1532,7 @@ void MainWindow::copy() {
|
|||
case 0:
|
||||
{
|
||||
// copy the map image
|
||||
QPixmap pixmap = editor->map ? editor->map->render(true) : QPixmap();
|
||||
QPixmap pixmap = editor->layout ? editor->layout->render(true) : QPixmap();
|
||||
setClipboardData(pixmap.toImage());
|
||||
logInfo("Copied current map image to clipboard");
|
||||
break;
|
||||
|
@ -1755,7 +1755,7 @@ void MainWindow::on_mapViewTab_tabBarClicked(int index)
|
|||
// User hasn't set up prefabs and hasn't been prompted before.
|
||||
// Ask if they'd like to import the default prefabs file.
|
||||
if (prefab.tryImportDefaultPrefabs(this, projectConfig.getBaseGameVersion()))
|
||||
prefab.updatePrefabUi(this->editor->map);
|
||||
prefab.updatePrefabUi(this->editor->layout);
|
||||
}
|
||||
}
|
||||
editor->setCursorRectVisible(false);
|
||||
|
@ -2442,9 +2442,11 @@ void MainWindow::onTilesetsSaved(QString primaryTilesetLabel, QString secondaryT
|
|||
} else {
|
||||
this->editor->project->getTileset(secondaryTilesetLabel, true);
|
||||
}
|
||||
if (updated)
|
||||
if (updated) {
|
||||
this->editor->layout->clearBorderCache();
|
||||
redrawMapScene();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onWildMonDataChanged() {
|
||||
editor->saveEncounterTabData();
|
||||
|
@ -2592,7 +2594,7 @@ void MainWindow::on_comboBox_PrimaryTileset_currentTextChanged(const QString &ti
|
|||
redrawMapScene();
|
||||
on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value());
|
||||
updateTilesetEditor();
|
||||
prefab.updatePrefabUi(editor->map);
|
||||
prefab.updatePrefabUi(editor->layout);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
@ -2604,7 +2606,7 @@ void MainWindow::on_comboBox_SecondaryTileset_currentTextChanged(const QString &
|
|||
redrawMapScene();
|
||||
on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value());
|
||||
updateTilesetEditor();
|
||||
prefab.updatePrefabUi(editor->map);
|
||||
prefab.updatePrefabUi(editor->layout);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
@ -2725,7 +2727,7 @@ void MainWindow::on_actionTileset_Editor_triggered()
|
|||
}
|
||||
|
||||
void MainWindow::initTilesetEditor() {
|
||||
this->tilesetEditor = new TilesetEditor(this->editor->project, this->editor->map, this);
|
||||
this->tilesetEditor = new TilesetEditor(this->editor->project, this->editor->layout, this);
|
||||
connect(this->tilesetEditor, &TilesetEditor::tilesetsSaved, this, &MainWindow::onTilesetsSaved);
|
||||
}
|
||||
|
||||
|
@ -2889,7 +2891,7 @@ void MainWindow::on_actionRegion_Map_Editor_triggered() {
|
|||
}
|
||||
|
||||
void MainWindow::on_pushButton_CreatePrefab_clicked() {
|
||||
PrefabCreationDialog dialog(this, this->editor->metatile_selector_item, this->editor->map);
|
||||
PrefabCreationDialog dialog(this, this->editor->metatile_selector_item, this->editor->layout);
|
||||
dialog.setWindowTitle("Create Prefab");
|
||||
dialog.setWindowModality(Qt::NonModal);
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
|
|
|
@ -42,13 +42,13 @@ void MainWindow::tryRedrawMapArea(bool forceRedraw) {
|
|||
|
||||
void MainWindow::tryCommitMapChanges(bool commitChanges) {
|
||||
if (commitChanges) {
|
||||
Map *map = this->editor->map;
|
||||
if (map) {
|
||||
map->editHistory.push(new ScriptEditMap(map,
|
||||
map->layout->lastCommitBlocks.mapDimensions, QSize(map->getWidth(), map->getHeight()),
|
||||
map->layout->lastCommitBlocks.blocks, map->layout->blockdata,
|
||||
map->layout->lastCommitBlocks.borderDimensions, QSize(map->getBorderWidth(), map->getBorderHeight()),
|
||||
map->layout->lastCommitBlocks.border, map->layout->border
|
||||
Layout *layout = this->editor->layout;
|
||||
if (layout) {
|
||||
layout->editHistory.push(new ScriptEditMap(layout,
|
||||
layout->lastCommitBlocks.mapDimensions, QSize(layout->getWidth(), layout->getHeight()),
|
||||
layout->lastCommitBlocks.blocks, layout->blockdata,
|
||||
layout->lastCommitBlocks.borderDimensions, QSize(layout->getBorderWidth(), layout->getBorderHeight()),
|
||||
layout->lastCommitBlocks.border, layout->border
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -59,27 +59,27 @@ void MainWindow::tryCommitMapChanges(bool commitChanges) {
|
|||
//=====================
|
||||
|
||||
QJSValue MainWindow::getBlock(int x, int y) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return QJSValue();
|
||||
Block block;
|
||||
if (!this->editor->map->getBlock(x, y, &block)) {
|
||||
if (!this->editor->layout->getBlock(x, y, &block)) {
|
||||
return Scripting::fromBlock(Block());
|
||||
}
|
||||
return Scripting::fromBlock(block);
|
||||
}
|
||||
|
||||
void MainWindow::setBlock(int x, int y, int metatileId, int collision, int elevation, bool forceRedraw, bool commitChanges) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
this->editor->map->setBlock(x, y, Block(metatileId, collision, elevation));
|
||||
this->editor->layout->setBlock(x, y, Block(metatileId, collision, elevation));
|
||||
this->tryCommitMapChanges(commitChanges);
|
||||
this->tryRedrawMapArea(forceRedraw);
|
||||
}
|
||||
|
||||
void MainWindow::setBlock(int x, int y, int rawValue, bool forceRedraw, bool commitChanges) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
this->editor->map->setBlock(x, y, Block(static_cast<uint16_t>(rawValue)));
|
||||
this->editor->layout->setBlock(x, y, Block(static_cast<uint16_t>(rawValue)));
|
||||
this->tryCommitMapChanges(commitChanges);
|
||||
this->tryRedrawMapArea(forceRedraw);
|
||||
}
|
||||
|
@ -93,73 +93,73 @@ void MainWindow::setBlocksFromSelection(int x, int y, bool forceRedraw, bool com
|
|||
}
|
||||
|
||||
int MainWindow::getMetatileId(int x, int y) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return 0;
|
||||
Block block;
|
||||
if (!this->editor->map->getBlock(x, y, &block)) {
|
||||
if (!this->editor->layout->getBlock(x, y, &block)) {
|
||||
return 0;
|
||||
}
|
||||
return block.metatileId;
|
||||
}
|
||||
|
||||
void MainWindow::setMetatileId(int x, int y, int metatileId, bool forceRedraw, bool commitChanges) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
Block block;
|
||||
if (!this->editor->map->getBlock(x, y, &block)) {
|
||||
if (!this->editor->layout->getBlock(x, y, &block)) {
|
||||
return;
|
||||
}
|
||||
this->editor->map->setBlock(x, y, Block(metatileId, block.collision, block.elevation));
|
||||
this->editor->layout->setBlock(x, y, Block(metatileId, block.collision, block.elevation));
|
||||
this->tryCommitMapChanges(commitChanges);
|
||||
this->tryRedrawMapArea(forceRedraw);
|
||||
}
|
||||
|
||||
int MainWindow::getCollision(int x, int y) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return 0;
|
||||
Block block;
|
||||
if (!this->editor->map->getBlock(x, y, &block)) {
|
||||
if (!this->editor->layout->getBlock(x, y, &block)) {
|
||||
return 0;
|
||||
}
|
||||
return block.collision;
|
||||
}
|
||||
|
||||
void MainWindow::setCollision(int x, int y, int collision, bool forceRedraw, bool commitChanges) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
Block block;
|
||||
if (!this->editor->map->getBlock(x, y, &block)) {
|
||||
if (!this->editor->layout->getBlock(x, y, &block)) {
|
||||
return;
|
||||
}
|
||||
this->editor->map->setBlock(x, y, Block(block.metatileId, collision, block.elevation));
|
||||
this->editor->layout->setBlock(x, y, Block(block.metatileId, collision, block.elevation));
|
||||
this->tryCommitMapChanges(commitChanges);
|
||||
this->tryRedrawMapArea(forceRedraw);
|
||||
}
|
||||
|
||||
int MainWindow::getElevation(int x, int y) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return 0;
|
||||
Block block;
|
||||
if (!this->editor->map->getBlock(x, y, &block)) {
|
||||
if (!this->editor->layout->getBlock(x, y, &block)) {
|
||||
return 0;
|
||||
}
|
||||
return block.elevation;
|
||||
}
|
||||
|
||||
void MainWindow::setElevation(int x, int y, int elevation, bool forceRedraw, bool commitChanges) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
Block block;
|
||||
if (!this->editor->map->getBlock(x, y, &block)) {
|
||||
if (!this->editor->layout->getBlock(x, y, &block)) {
|
||||
return;
|
||||
}
|
||||
this->editor->map->setBlock(x, y, Block(block.metatileId, block.collision, elevation));
|
||||
this->editor->layout->setBlock(x, y, Block(block.metatileId, block.collision, elevation));
|
||||
this->tryCommitMapChanges(commitChanges);
|
||||
this->tryRedrawMapArea(forceRedraw);
|
||||
}
|
||||
|
||||
void MainWindow::bucketFill(int x, int y, int metatileId, bool forceRedraw, bool commitChanges) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
this->editor->map_item->floodFill(x, y, metatileId, true);
|
||||
this->tryCommitMapChanges(commitChanges);
|
||||
|
@ -167,7 +167,7 @@ void MainWindow::bucketFill(int x, int y, int metatileId, bool forceRedraw, bool
|
|||
}
|
||||
|
||||
void MainWindow::bucketFillFromSelection(int x, int y, bool forceRedraw, bool commitChanges) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
this->editor->map_item->floodFill(x, y, true);
|
||||
this->tryCommitMapChanges(commitChanges);
|
||||
|
@ -175,7 +175,7 @@ void MainWindow::bucketFillFromSelection(int x, int y, bool forceRedraw, bool co
|
|||
}
|
||||
|
||||
void MainWindow::magicFill(int x, int y, int metatileId, bool forceRedraw, bool commitChanges) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
this->editor->map_item->magicFill(x, y, metatileId, true);
|
||||
this->tryCommitMapChanges(commitChanges);
|
||||
|
@ -183,7 +183,7 @@ void MainWindow::magicFill(int x, int y, int metatileId, bool forceRedraw, bool
|
|||
}
|
||||
|
||||
void MainWindow::magicFillFromSelection(int x, int y, bool forceRedraw, bool commitChanges) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
this->editor->map_item->magicFill(x, y, true);
|
||||
this->tryCommitMapChanges(commitChanges);
|
||||
|
@ -191,7 +191,7 @@ void MainWindow::magicFillFromSelection(int x, int y, bool forceRedraw, bool com
|
|||
}
|
||||
|
||||
void MainWindow::shift(int xDelta, int yDelta, bool forceRedraw, bool commitChanges) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
this->editor->map_item->shift(xDelta, yDelta, true);
|
||||
this->tryCommitMapChanges(commitChanges);
|
||||
|
@ -207,49 +207,49 @@ void MainWindow::commit() {
|
|||
}
|
||||
|
||||
QJSValue MainWindow::getDimensions() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return QJSValue();
|
||||
return Scripting::dimensions(this->editor->map->getWidth(), this->editor->map->getHeight());
|
||||
return Scripting::dimensions(this->editor->layout->getWidth(), this->editor->layout->getHeight());
|
||||
}
|
||||
|
||||
int MainWindow::getWidth() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return 0;
|
||||
return this->editor->map->getWidth();
|
||||
return this->editor->layout->getWidth();
|
||||
}
|
||||
|
||||
int MainWindow::getHeight() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return 0;
|
||||
return this->editor->map->getHeight();
|
||||
return this->editor->layout->getHeight();
|
||||
}
|
||||
|
||||
void MainWindow::setDimensions(int width, int height) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
if (!Project::mapDimensionsValid(width, height))
|
||||
return;
|
||||
this->editor->map->setDimensions(width, height);
|
||||
this->editor->layout->setDimensions(width, height);
|
||||
this->tryCommitMapChanges(true);
|
||||
this->onMapNeedsRedrawing();
|
||||
}
|
||||
|
||||
void MainWindow::setWidth(int width) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
if (!Project::mapDimensionsValid(width, this->editor->map->getHeight()))
|
||||
if (!Project::mapDimensionsValid(width, this->editor->layout->getHeight()))
|
||||
return;
|
||||
this->editor->map->setDimensions(width, this->editor->map->getHeight());
|
||||
this->editor->layout->setDimensions(width, this->editor->layout->getHeight());
|
||||
this->tryCommitMapChanges(true);
|
||||
this->onMapNeedsRedrawing();
|
||||
}
|
||||
|
||||
void MainWindow::setHeight(int height) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
if (!Project::mapDimensionsValid(this->editor->map->getWidth(), height))
|
||||
if (!Project::mapDimensionsValid(this->editor->layout->getWidth(), height))
|
||||
return;
|
||||
this->editor->map->setDimensions(this->editor->map->getWidth(), height);
|
||||
this->editor->layout->setDimensions(this->editor->layout->getWidth(), height);
|
||||
this->tryCommitMapChanges(true);
|
||||
this->onMapNeedsRedrawing();
|
||||
}
|
||||
|
@ -259,67 +259,67 @@ void MainWindow::setHeight(int height) {
|
|||
//=====================
|
||||
|
||||
int MainWindow::getBorderMetatileId(int x, int y) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return 0;
|
||||
if (!this->editor->map->isWithinBorderBounds(x, y))
|
||||
if (!this->editor->layout->isWithinBorderBounds(x, y))
|
||||
return 0;
|
||||
return this->editor->map->getBorderMetatileId(x, y);
|
||||
return this->editor->layout->getBorderMetatileId(x, y);
|
||||
}
|
||||
|
||||
void MainWindow::setBorderMetatileId(int x, int y, int metatileId, bool forceRedraw, bool commitChanges) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return;
|
||||
if (!this->editor->map->isWithinBorderBounds(x, y))
|
||||
if (!this->editor->layout->isWithinBorderBounds(x, y))
|
||||
return;
|
||||
this->editor->map->setBorderMetatileId(x, y, metatileId);
|
||||
this->editor->layout->setBorderMetatileId(x, y, metatileId);
|
||||
this->tryCommitMapChanges(commitChanges);
|
||||
this->tryRedrawMapArea(forceRedraw);
|
||||
}
|
||||
|
||||
QJSValue MainWindow::getBorderDimensions() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return QJSValue();
|
||||
return Scripting::dimensions(this->editor->map->getBorderWidth(), this->editor->map->getBorderHeight());
|
||||
return Scripting::dimensions(this->editor->layout->getBorderWidth(), this->editor->layout->getBorderHeight());
|
||||
}
|
||||
|
||||
int MainWindow::getBorderWidth() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return 0;
|
||||
return this->editor->map->getBorderWidth();
|
||||
return this->editor->layout->getBorderWidth();
|
||||
}
|
||||
|
||||
int MainWindow::getBorderHeight() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
if (!this->editor || !this->editor->layout)
|
||||
return 0;
|
||||
return this->editor->map->getBorderHeight();
|
||||
return this->editor->layout->getBorderHeight();
|
||||
}
|
||||
|
||||
void MainWindow::setBorderDimensions(int width, int height) {
|
||||
if (!this->editor || !this->editor->map || !projectConfig.getUseCustomBorderSize())
|
||||
if (!this->editor || !this->editor->layout || !projectConfig.getUseCustomBorderSize())
|
||||
return;
|
||||
if (width < 1 || height < 1 || width > MAX_BORDER_WIDTH || height > MAX_BORDER_HEIGHT)
|
||||
return;
|
||||
this->editor->map->setBorderDimensions(width, height);
|
||||
this->editor->layout->setBorderDimensions(width, height);
|
||||
this->tryCommitMapChanges(true);
|
||||
this->onMapNeedsRedrawing();
|
||||
}
|
||||
|
||||
void MainWindow::setBorderWidth(int width) {
|
||||
if (!this->editor || !this->editor->map || !projectConfig.getUseCustomBorderSize())
|
||||
if (!this->editor || !this->editor->layout || !projectConfig.getUseCustomBorderSize())
|
||||
return;
|
||||
if (width < 1 || width > MAX_BORDER_WIDTH)
|
||||
return;
|
||||
this->editor->map->setBorderDimensions(width, this->editor->map->getBorderHeight());
|
||||
this->editor->layout->setBorderDimensions(width, this->editor->layout->getBorderHeight());
|
||||
this->tryCommitMapChanges(true);
|
||||
this->onMapNeedsRedrawing();
|
||||
}
|
||||
|
||||
void MainWindow::setBorderHeight(int height) {
|
||||
if (!this->editor || !this->editor->map || !projectConfig.getUseCustomBorderSize())
|
||||
if (!this->editor || !this->editor->layout || !projectConfig.getUseCustomBorderSize())
|
||||
return;
|
||||
if (height < 1 || height > MAX_BORDER_HEIGHT)
|
||||
return;
|
||||
this->editor->map->setBorderDimensions(this->editor->map->getBorderWidth(), height);
|
||||
this->editor->layout->setBorderDimensions(this->editor->layout->getBorderWidth(), height);
|
||||
this->tryCommitMapChanges(true);
|
||||
this->onMapNeedsRedrawing();
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ void MainWindow::setBorderHeight(int height) {
|
|||
|
||||
void MainWindow::refreshAfterPaletteChange(Tileset *tileset) {
|
||||
if (this->tilesetEditor) {
|
||||
this->tilesetEditor->updateTilesets(this->editor->map->layout->tileset_primary_label, this->editor->map->layout->tileset_secondary_label);
|
||||
this->tilesetEditor->updateTilesets(this->editor->layout->tileset_primary_label, this->editor->layout->tileset_secondary_label);
|
||||
}
|
||||
this->editor->metatile_selector_item->draw();
|
||||
this->editor->selected_border_metatiles_item->draw();
|
||||
|
@ -341,7 +341,7 @@ void MainWindow::refreshAfterPaletteChange(Tileset *tileset) {
|
|||
}
|
||||
|
||||
void MainWindow::setTilesetPalette(Tileset *tileset, int paletteIndex, QList<QList<int>> colors) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout)
|
||||
return;
|
||||
if (paletteIndex >= tileset->palettes.size())
|
||||
return;
|
||||
|
@ -357,42 +357,42 @@ void MainWindow::setTilesetPalette(Tileset *tileset, int paletteIndex, QList<QLi
|
|||
}
|
||||
|
||||
void MainWindow::setPrimaryTilesetPalette(int paletteIndex, QList<QList<int>> colors, bool forceRedraw) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_primary)
|
||||
return;
|
||||
this->setTilesetPalette(this->editor->map->layout->tileset_primary, paletteIndex, colors);
|
||||
this->setTilesetPalette(this->editor->layout->tileset_primary, paletteIndex, colors);
|
||||
if (forceRedraw) {
|
||||
this->refreshAfterPaletteChange(this->editor->map->layout->tileset_primary);
|
||||
this->refreshAfterPaletteChange(this->editor->layout->tileset_primary);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setPrimaryTilesetPalettes(QList<QList<QList<int>>> palettes, bool forceRedraw) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_primary)
|
||||
return;
|
||||
for (int i = 0; i < palettes.size(); i++) {
|
||||
this->setTilesetPalette(this->editor->map->layout->tileset_primary, i, palettes[i]);
|
||||
this->setTilesetPalette(this->editor->layout->tileset_primary, i, palettes[i]);
|
||||
}
|
||||
if (forceRedraw) {
|
||||
this->refreshAfterPaletteChange(this->editor->map->layout->tileset_primary);
|
||||
this->refreshAfterPaletteChange(this->editor->layout->tileset_primary);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setSecondaryTilesetPalette(int paletteIndex, QList<QList<int>> colors, bool forceRedraw) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_secondary)
|
||||
return;
|
||||
this->setTilesetPalette(this->editor->map->layout->tileset_secondary, paletteIndex, colors);
|
||||
this->setTilesetPalette(this->editor->layout->tileset_secondary, paletteIndex, colors);
|
||||
if (forceRedraw) {
|
||||
this->refreshAfterPaletteChange(this->editor->map->layout->tileset_secondary);
|
||||
this->refreshAfterPaletteChange(this->editor->layout->tileset_secondary);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setSecondaryTilesetPalettes(QList<QList<QList<int>>> palettes, bool forceRedraw) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_secondary)
|
||||
return;
|
||||
for (int i = 0; i < palettes.size(); i++) {
|
||||
this->setTilesetPalette(this->editor->map->layout->tileset_secondary, i, palettes[i]);
|
||||
this->setTilesetPalette(this->editor->layout->tileset_secondary, i, palettes[i]);
|
||||
}
|
||||
if (forceRedraw) {
|
||||
this->refreshAfterPaletteChange(this->editor->map->layout->tileset_secondary);
|
||||
this->refreshAfterPaletteChange(this->editor->layout->tileset_secondary);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -420,27 +420,27 @@ QJSValue MainWindow::getTilesetPalettes(const QList<QList<QRgb>> &palettes) {
|
|||
}
|
||||
|
||||
QJSValue MainWindow::getPrimaryTilesetPalette(int paletteIndex) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_primary)
|
||||
return QJSValue();
|
||||
return this->getTilesetPalette(this->editor->map->layout->tileset_primary->palettes, paletteIndex);
|
||||
return this->getTilesetPalette(this->editor->layout->tileset_primary->palettes, paletteIndex);
|
||||
}
|
||||
|
||||
QJSValue MainWindow::getPrimaryTilesetPalettes() {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_primary)
|
||||
return QJSValue();
|
||||
return this->getTilesetPalettes(this->editor->map->layout->tileset_primary->palettes);
|
||||
return this->getTilesetPalettes(this->editor->layout->tileset_primary->palettes);
|
||||
}
|
||||
|
||||
QJSValue MainWindow::getSecondaryTilesetPalette(int paletteIndex) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_secondary)
|
||||
return QJSValue();
|
||||
return this->getTilesetPalette(this->editor->map->layout->tileset_secondary->palettes, paletteIndex);
|
||||
return this->getTilesetPalette(this->editor->layout->tileset_secondary->palettes, paletteIndex);
|
||||
}
|
||||
|
||||
QJSValue MainWindow::getSecondaryTilesetPalettes() {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_secondary)
|
||||
return QJSValue();
|
||||
return this->getTilesetPalettes(this->editor->map->layout->tileset_secondary->palettes);
|
||||
return this->getTilesetPalettes(this->editor->layout->tileset_secondary->palettes);
|
||||
}
|
||||
|
||||
void MainWindow::refreshAfterPalettePreviewChange() {
|
||||
|
@ -452,7 +452,7 @@ void MainWindow::refreshAfterPalettePreviewChange() {
|
|||
}
|
||||
|
||||
void MainWindow::setTilesetPalettePreview(Tileset *tileset, int paletteIndex, QList<QList<int>> colors) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout)
|
||||
return;
|
||||
if (paletteIndex >= tileset->palettePreviews.size())
|
||||
return;
|
||||
|
@ -467,19 +467,19 @@ void MainWindow::setTilesetPalettePreview(Tileset *tileset, int paletteIndex, QL
|
|||
}
|
||||
|
||||
void MainWindow::setPrimaryTilesetPalettePreview(int paletteIndex, QList<QList<int>> colors, bool forceRedraw) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_primary)
|
||||
return;
|
||||
this->setTilesetPalettePreview(this->editor->map->layout->tileset_primary, paletteIndex, colors);
|
||||
this->setTilesetPalettePreview(this->editor->layout->tileset_primary, paletteIndex, colors);
|
||||
if (forceRedraw) {
|
||||
this->refreshAfterPalettePreviewChange();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setPrimaryTilesetPalettesPreview(QList<QList<QList<int>>> palettes, bool forceRedraw) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_primary)
|
||||
return;
|
||||
for (int i = 0; i < palettes.size(); i++) {
|
||||
this->setTilesetPalettePreview(this->editor->map->layout->tileset_primary, i, palettes[i]);
|
||||
this->setTilesetPalettePreview(this->editor->layout->tileset_primary, i, palettes[i]);
|
||||
}
|
||||
if (forceRedraw) {
|
||||
this->refreshAfterPalettePreviewChange();
|
||||
|
@ -487,19 +487,19 @@ void MainWindow::setPrimaryTilesetPalettesPreview(QList<QList<QList<int>>> palet
|
|||
}
|
||||
|
||||
void MainWindow::setSecondaryTilesetPalettePreview(int paletteIndex, QList<QList<int>> colors, bool forceRedraw) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_secondary)
|
||||
return;
|
||||
this->setTilesetPalettePreview(this->editor->map->layout->tileset_secondary, paletteIndex, colors);
|
||||
this->setTilesetPalettePreview(this->editor->layout->tileset_secondary, paletteIndex, colors);
|
||||
if (forceRedraw) {
|
||||
this->refreshAfterPalettePreviewChange();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setSecondaryTilesetPalettesPreview(QList<QList<QList<int>>> palettes, bool forceRedraw) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_secondary)
|
||||
return;
|
||||
for (int i = 0; i < palettes.size(); i++) {
|
||||
this->setTilesetPalettePreview(this->editor->map->layout->tileset_secondary, i, palettes[i]);
|
||||
this->setTilesetPalettePreview(this->editor->layout->tileset_secondary, i, palettes[i]);
|
||||
}
|
||||
if (forceRedraw) {
|
||||
this->refreshAfterPalettePreviewChange();
|
||||
|
@ -507,63 +507,63 @@ void MainWindow::setSecondaryTilesetPalettesPreview(QList<QList<QList<int>>> pal
|
|||
}
|
||||
|
||||
QJSValue MainWindow::getPrimaryTilesetPalettePreview(int paletteIndex) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_primary)
|
||||
return QJSValue();
|
||||
return this->getTilesetPalette(this->editor->map->layout->tileset_primary->palettePreviews, paletteIndex);
|
||||
return this->getTilesetPalette(this->editor->layout->tileset_primary->palettePreviews, paletteIndex);
|
||||
}
|
||||
|
||||
QJSValue MainWindow::getPrimaryTilesetPalettesPreview() {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_primary)
|
||||
return QJSValue();
|
||||
return this->getTilesetPalettes(this->editor->map->layout->tileset_primary->palettePreviews);
|
||||
return this->getTilesetPalettes(this->editor->layout->tileset_primary->palettePreviews);
|
||||
}
|
||||
|
||||
QJSValue MainWindow::getSecondaryTilesetPalettePreview(int paletteIndex) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_secondary)
|
||||
return QJSValue();
|
||||
return this->getTilesetPalette(this->editor->map->layout->tileset_secondary->palettePreviews, paletteIndex);
|
||||
return this->getTilesetPalette(this->editor->layout->tileset_secondary->palettePreviews, paletteIndex);
|
||||
}
|
||||
|
||||
QJSValue MainWindow::getSecondaryTilesetPalettesPreview() {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_secondary)
|
||||
return QJSValue();
|
||||
return this->getTilesetPalettes(this->editor->map->layout->tileset_secondary->palettePreviews);
|
||||
return this->getTilesetPalettes(this->editor->layout->tileset_secondary->palettePreviews);
|
||||
}
|
||||
|
||||
int MainWindow::getNumPrimaryTilesetMetatiles() {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_primary)
|
||||
return 0;
|
||||
return this->editor->map->layout->tileset_primary->metatiles.length();
|
||||
return this->editor->layout->tileset_primary->metatiles.length();
|
||||
}
|
||||
|
||||
int MainWindow::getNumSecondaryTilesetMetatiles() {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_secondary)
|
||||
return 0;
|
||||
return this->editor->map->layout->tileset_secondary->metatiles.length();
|
||||
return this->editor->layout->tileset_secondary->metatiles.length();
|
||||
}
|
||||
|
||||
int MainWindow::getNumPrimaryTilesetTiles() {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_primary)
|
||||
return 0;
|
||||
return this->editor->map->layout->tileset_primary->tiles.length();
|
||||
return this->editor->layout->tileset_primary->tiles.length();
|
||||
}
|
||||
|
||||
int MainWindow::getNumSecondaryTilesetTiles() {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_secondary)
|
||||
return 0;
|
||||
return this->editor->map->layout->tileset_secondary->tiles.length();
|
||||
return this->editor->layout->tileset_secondary->tiles.length();
|
||||
}
|
||||
|
||||
QString MainWindow::getPrimaryTileset() {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_primary)
|
||||
return QString();
|
||||
return this->editor->map->layout->tileset_primary->name;
|
||||
return this->editor->layout->tileset_primary->name;
|
||||
}
|
||||
|
||||
QString MainWindow::getSecondaryTileset() {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout || !this->editor->layout->tileset_secondary)
|
||||
return QString();
|
||||
return this->editor->map->layout->tileset_secondary->name;
|
||||
return this->editor->layout->tileset_secondary->name;
|
||||
}
|
||||
|
||||
void MainWindow::setPrimaryTileset(QString tileset) {
|
||||
|
@ -575,13 +575,13 @@ void MainWindow::setSecondaryTileset(QString tileset) {
|
|||
}
|
||||
|
||||
void MainWindow::saveMetatilesByMetatileId(int metatileId) {
|
||||
Tileset * tileset = Tileset::getMetatileTileset(metatileId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
Tileset * tileset = Tileset::getMetatileTileset(metatileId, this->editor->layout->tileset_primary, this->editor->layout->tileset_secondary);
|
||||
if (this->editor->project && tileset)
|
||||
this->editor->project->saveTilesetMetatiles(tileset);
|
||||
}
|
||||
|
||||
void MainWindow::saveMetatileAttributesByMetatileId(int metatileId) {
|
||||
Tileset * tileset = Tileset::getMetatileTileset(metatileId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
Tileset * tileset = Tileset::getMetatileTileset(metatileId, this->editor->layout->tileset_primary, this->editor->layout->tileset_secondary);
|
||||
if (this->editor->project && tileset)
|
||||
this->editor->project->saveTilesetMetatileAttributes(tileset);
|
||||
|
||||
|
@ -591,9 +591,9 @@ void MainWindow::saveMetatileAttributesByMetatileId(int metatileId) {
|
|||
}
|
||||
|
||||
Metatile * MainWindow::getMetatile(int metatileId) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout)
|
||||
return nullptr;
|
||||
return Tileset::getMetatile(metatileId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
return Tileset::getMetatile(metatileId, this->editor->layout->tileset_primary, this->editor->layout->tileset_secondary);
|
||||
}
|
||||
|
||||
QString MainWindow::getMetatileLabel(int metatileId) {
|
||||
|
@ -603,7 +603,7 @@ QString MainWindow::getMetatileLabel(int metatileId) {
|
|||
}
|
||||
|
||||
void MainWindow::setMetatileLabel(int metatileId, QString label) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout)
|
||||
return;
|
||||
|
||||
// If the Tileset Editor is opened on this metatile we need to update the text box
|
||||
|
@ -612,13 +612,13 @@ void MainWindow::setMetatileLabel(int metatileId, QString label) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!Tileset::setMetatileLabel(metatileId, label, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary)) {
|
||||
if (!Tileset::setMetatileLabel(metatileId, label, this->editor->layout->tileset_primary, this->editor->map->layout->tileset_secondary)) {
|
||||
logError("Failed to set metatile label. Must be a valid metatile id and a label containing only letters, numbers, and underscores.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->editor->project)
|
||||
this->editor->project->saveTilesetMetatileLabels(this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
this->editor->project->saveTilesetMetatileLabels(this->editor->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
}
|
||||
|
||||
int MainWindow::getMetatileLayerType(int metatileId) {
|
||||
|
@ -769,9 +769,9 @@ void MainWindow::setMetatileTile(int metatileId, int tileIndex, QJSValue tileObj
|
|||
}
|
||||
|
||||
QJSValue MainWindow::getTilePixels(int tileId) {
|
||||
if (tileId < 0 || !this->editor || !this->editor->project || !this->editor->map || !this->editor->map->layout)
|
||||
if (tileId < 0 || !this->editor || !this->editor->project || !this->editor->map || !this->editor->layout)
|
||||
return QJSValue();
|
||||
QImage tileImage = getTileImage(tileId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
QImage tileImage = getTileImage(tileId, this->editor->layout->tileset_primary, this->editor->layout->tileset_secondary);
|
||||
if (tileImage.isNull() || tileImage.sizeInBytes() < 64)
|
||||
return QJSValue();
|
||||
const uchar * pixels = tileImage.constBits();
|
||||
|
|
|
@ -254,23 +254,23 @@ void MapView::addImage(int x, int y, QString filepath, int layer, bool useCache)
|
|||
}
|
||||
|
||||
void MapView::createImage(int x, int y, QString filepath, int width, int height, int xOffset, int yOffset, qreal hScale, qreal vScale, int paletteId, bool setTransparency, int layer, bool useCache) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout
|
||||
|| !this->editor->map->layout->tileset_primary || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout
|
||||
|| !this->editor->layout->tileset_primary || !this->editor->layout->tileset_secondary)
|
||||
return;
|
||||
QList<QRgb> palette;
|
||||
if (paletteId != -1)
|
||||
palette = Tileset::getPalette(paletteId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
palette = Tileset::getPalette(paletteId, this->editor->layout->tileset_primary, this->editor->layout->tileset_secondary);
|
||||
if (this->getOverlay(layer)->addImage(x, y, filepath, useCache, width, height, xOffset, yOffset, hScale, vScale, palette, setTransparency))
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MapView::addTileImage(int x, int y, int tileId, bool xflip, bool yflip, int paletteId, bool setTransparency, int layer) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout
|
||||
|| !this->editor->map->layout->tileset_primary || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout
|
||||
|| !this->editor->layout->tileset_primary || !this->editor->layout->tileset_secondary)
|
||||
return;
|
||||
QImage image = getPalettedTileImage(tileId,
|
||||
this->editor->map->layout->tileset_primary,
|
||||
this->editor->map->layout->tileset_secondary,
|
||||
this->editor->layout->tileset_primary,
|
||||
this->editor->layout->tileset_secondary,
|
||||
paletteId)
|
||||
.mirrored(xflip, yflip);
|
||||
if (setTransparency)
|
||||
|
@ -285,14 +285,14 @@ void MapView::addTileImage(int x, int y, QJSValue tileObj, bool setTransparency,
|
|||
}
|
||||
|
||||
void MapView::addMetatileImage(int x, int y, int metatileId, bool setTransparency, int layer) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout
|
||||
|| !this->editor->map->layout->tileset_primary || !this->editor->map->layout->tileset_secondary)
|
||||
if (!this->editor || !this->editor->map || !this->editor->layout
|
||||
|| !this->editor->layout->tileset_primary || !this->editor->layout->tileset_secondary)
|
||||
return;
|
||||
QImage image = getMetatileImage(static_cast<uint16_t>(metatileId),
|
||||
this->editor->map->layout->tileset_primary,
|
||||
this->editor->map->layout->tileset_secondary,
|
||||
this->editor->map->metatileLayerOrder,
|
||||
this->editor->map->metatileLayerOpacity);
|
||||
this->editor->layout->tileset_primary,
|
||||
this->editor->layout->tileset_secondary,
|
||||
this->editor->layout->metatileLayerOrder,
|
||||
this->editor->layout->metatileLayerOpacity);
|
||||
if (setTransparency)
|
||||
image.setColor(0, qRgba(0, 0, 0, 0));
|
||||
if (this->getOverlay(layer)->addImage(x, y, image))
|
||||
|
|
|
@ -188,13 +188,13 @@ QList<QString> ScriptUtility::getCustomScripts() {
|
|||
}
|
||||
|
||||
QList<int> ScriptUtility::getMetatileLayerOrder() {
|
||||
if (!window || !window->editor || !window->editor->map)
|
||||
if (!window || !window->editor || !window->editor->layout)
|
||||
return QList<int>();
|
||||
return window->editor->map->metatileLayerOrder;
|
||||
return window->editor->layout->metatileLayerOrder;
|
||||
}
|
||||
|
||||
void ScriptUtility::setMetatileLayerOrder(QList<int> order) {
|
||||
if (!window || !window->editor || !window->editor->map)
|
||||
if (!window || !window->editor || !window->editor->layout)
|
||||
return;
|
||||
|
||||
const int numLayers = 3;
|
||||
|
@ -213,20 +213,20 @@ void ScriptUtility::setMetatileLayerOrder(QList<int> order) {
|
|||
}
|
||||
if (invalid) return;
|
||||
|
||||
window->editor->map->metatileLayerOrder = order;
|
||||
window->editor->layout->metatileLayerOrder = order;
|
||||
window->refreshAfterPalettePreviewChange();
|
||||
}
|
||||
|
||||
QList<float> ScriptUtility::getMetatileLayerOpacity() {
|
||||
if (!window || !window->editor || !window->editor->map)
|
||||
if (!window || !window->editor || !window->editor->layout)
|
||||
return QList<float>();
|
||||
return window->editor->map->metatileLayerOpacity;
|
||||
return window->editor->layout->metatileLayerOpacity;
|
||||
}
|
||||
|
||||
void ScriptUtility::setMetatileLayerOpacity(QList<float> order) {
|
||||
if (!window || !window->editor || !window->editor->map)
|
||||
if (!window || !window->editor || !window->editor->layout)
|
||||
return;
|
||||
window->editor->map->metatileLayerOpacity = order;
|
||||
window->editor->layout->metatileLayerOpacity = order;
|
||||
window->refreshAfterPalettePreviewChange();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "imageproviders.h"
|
||||
#include <QPainter>
|
||||
|
||||
QPixmap drawMetatileSelection(MetatileSelection selection, Map *map) {
|
||||
QPixmap drawMetatileSelection(MetatileSelection selection, Layout *layout) {
|
||||
int width = selection.dimensions.x() * 16;
|
||||
int height = selection.dimensions.y() * 16;
|
||||
QImage image(width, height, QImage::Format_RGBA8888);
|
||||
|
@ -19,10 +19,10 @@ QPixmap drawMetatileSelection(MetatileSelection selection, Map *map) {
|
|||
if (item.enabled) {
|
||||
QImage metatile_image = getMetatileImage(
|
||||
item.metatileId,
|
||||
map->layout->tileset_primary,
|
||||
map->layout->tileset_secondary,
|
||||
map->metatileLayerOrder,
|
||||
map->metatileLayerOpacity);
|
||||
layout->tileset_primary,
|
||||
layout->tileset_secondary,
|
||||
layout->metatileLayerOrder,
|
||||
layout->metatileLayerOpacity);
|
||||
painter.drawImage(metatile_origin, metatile_image);
|
||||
}
|
||||
}
|
||||
|
@ -34,5 +34,5 @@ QPixmap drawMetatileSelection(MetatileSelection selection, Map *map) {
|
|||
|
||||
void CurrentSelectedMetatilesPixmapItem::draw() {
|
||||
MetatileSelection selection = metatileSelector->getMetatileSelection();
|
||||
setPixmap(drawMetatileSelection(selection, this->map));
|
||||
setPixmap(drawMetatileSelection(selection, this->layout));
|
||||
}
|
||||
|
|
|
@ -90,6 +90,7 @@ void MapImageExporter::saveImage() {
|
|||
break;
|
||||
}
|
||||
case ImageExporterMode::Timelapse:
|
||||
// !TODO: also need layout editHistory!
|
||||
QProgressDialog progress("Building map timelapse...", "Cancel", 0, 1, this);
|
||||
progress.setAutoClose(true);
|
||||
progress.setWindowModality(Qt::WindowModal);
|
||||
|
@ -358,14 +359,19 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
|
|||
QPixmap pixmap;
|
||||
|
||||
// draw background layer / base image
|
||||
map->render(true);
|
||||
pixmap = map->pixmap;
|
||||
Layout *layout = map->layout;
|
||||
if (!layout) {
|
||||
return QPixmap();
|
||||
}
|
||||
|
||||
layout->render(true);
|
||||
pixmap = layout->pixmap;
|
||||
|
||||
if (showCollision) {
|
||||
QPainter collisionPainter(&pixmap);
|
||||
map->renderCollision(true);
|
||||
layout->renderCollision(true);
|
||||
collisionPainter.setOpacity(editor->collisionOpacity);
|
||||
collisionPainter.drawPixmap(0, 0, map->collision_pixmap);
|
||||
collisionPainter.drawPixmap(0, 0, layout->collision_pixmap);
|
||||
collisionPainter.end();
|
||||
}
|
||||
|
||||
|
@ -375,16 +381,16 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
|
|||
bool forceDrawBorder = showUpConnections || showDownConnections || showLeftConnections || showRightConnections;
|
||||
if (!ignoreBorder && (showBorder || forceDrawBorder)) {
|
||||
int borderDistance = this->mode ? STITCH_MODE_BORDER_DISTANCE : BORDER_DISTANCE;
|
||||
map->renderBorder();
|
||||
int borderHorzDist = editor->getBorderDrawDistance(map->getBorderWidth());
|
||||
int borderVertDist = editor->getBorderDrawDistance(map->getBorderHeight());
|
||||
layout->renderBorder();
|
||||
int borderHorzDist = editor->getBorderDrawDistance(layout->getBorderWidth());
|
||||
int borderVertDist = editor->getBorderDrawDistance(layout->getBorderHeight());
|
||||
borderWidth = borderDistance * 16;
|
||||
borderHeight = borderDistance * 16;
|
||||
QPixmap newPixmap = QPixmap(map->pixmap.width() + borderWidth * 2, map->pixmap.height() + borderHeight * 2);
|
||||
QPixmap newPixmap = QPixmap(layout->pixmap.width() + borderWidth * 2, layout->pixmap.height() + borderHeight * 2);
|
||||
QPainter borderPainter(&newPixmap);
|
||||
for (int y = borderDistance - borderVertDist; y < map->getHeight() + borderVertDist * 2; y += map->getBorderHeight()) {
|
||||
for (int x = borderDistance - borderHorzDist; x < map->getWidth() + borderHorzDist * 2; x += map->getBorderWidth()) {
|
||||
borderPainter.drawPixmap(x * 16, y * 16, map->layout->border_pixmap);
|
||||
for (int y = borderDistance - borderVertDist; y < layout->getHeight() + borderVertDist * 2; y += layout->getBorderHeight()) {
|
||||
for (int x = borderDistance - borderHorzDist; x < layout->getWidth() + borderHorzDist * 2; x += layout->getBorderWidth()) {
|
||||
borderPainter.drawPixmap(x * 16, y * 16, layout->border_pixmap);
|
||||
}
|
||||
}
|
||||
borderPainter.drawImage(borderWidth, borderHeight, pixmap.toImage());
|
||||
|
|
|
@ -26,7 +26,7 @@ void MetatileSelector::draw() {
|
|||
if (i >= primaryLength) {
|
||||
tile += Project::getNumMetatilesPrimary() - primaryLength;
|
||||
}
|
||||
QImage metatile_image = getMetatileImage(tile, this->primaryTileset, this->secondaryTileset, map->metatileLayerOrder, map->metatileLayerOpacity);
|
||||
QImage metatile_image = getMetatileImage(tile, this->primaryTileset, this->secondaryTileset, layout->metatileLayerOrder, layout->metatileLayerOpacity);
|
||||
int map_y = i / this->numMetatilesWide;
|
||||
int map_x = i % this->numMetatilesWide;
|
||||
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
|
||||
|
@ -209,6 +209,6 @@ QPoint MetatileSelector::getMetatileIdCoordsOnWidget(uint16_t metatileId) {
|
|||
return pos;
|
||||
}
|
||||
|
||||
void MetatileSelector::setMap(Map *map) {
|
||||
this->map = map;
|
||||
void MetatileSelector::setLayout(Layout *layout) {
|
||||
this->layout = layout;
|
||||
}
|
||||
|
|
|
@ -160,32 +160,32 @@ QList<PrefabItem> Prefab::getPrefabsForTilesets(QString primaryTileset, QString
|
|||
return filteredPrefabs;
|
||||
}
|
||||
|
||||
void Prefab::initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Map *map) {
|
||||
void Prefab::initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Layout *layout) {
|
||||
this->selector = selector;
|
||||
this->prefabWidget = prefabWidget;
|
||||
this->emptyPrefabLabel = emptyPrefabLabel;
|
||||
this->loadPrefabs();
|
||||
this->updatePrefabUi(map);
|
||||
this->updatePrefabUi(layout);
|
||||
}
|
||||
|
||||
// This function recreates the UI state for the prefab tab.
|
||||
// We completely delete all the prefab widgets, and recreate new widgets
|
||||
// from the relevant list of prefab items.
|
||||
// This is not very efficient, but it gets the job done.
|
||||
void Prefab::updatePrefabUi(Map *map) {
|
||||
void Prefab::updatePrefabUi(Layout *layout) {
|
||||
if (!this->selector)
|
||||
return;
|
||||
// Cleanup the PrefabFrame to have a clean slate.
|
||||
auto layout = this->prefabWidget->layout();
|
||||
while (layout && layout->count() > 1) {
|
||||
auto child = layout->takeAt(1);
|
||||
auto uiLayout = this->prefabWidget->layout();
|
||||
while (uiLayout && uiLayout->count() > 1) {
|
||||
auto child = uiLayout->takeAt(1);
|
||||
if (child->widget()) {
|
||||
delete child->widget();
|
||||
}
|
||||
delete child;
|
||||
}
|
||||
|
||||
QList<PrefabItem> prefabs = this->getPrefabsForTilesets(map->layout->tileset_primary_label, map->layout->tileset_secondary_label);
|
||||
QList<PrefabItem> prefabs = this->getPrefabsForTilesets(layout->tileset_primary_label, layout->tileset_secondary_label);
|
||||
if (prefabs.isEmpty()) {
|
||||
emptyPrefabLabel->setVisible(true);
|
||||
return;
|
||||
|
@ -204,7 +204,7 @@ void Prefab::updatePrefabUi(Map *map) {
|
|||
frame->ui->label_Name->setText(item.name);
|
||||
|
||||
auto scene = new QGraphicsScene;
|
||||
scene->addPixmap(drawMetatileSelection(item.selection, map));
|
||||
scene->addPixmap(drawMetatileSelection(item.selection, layout));
|
||||
scene->setSceneRect(scene->itemsBoundingRect());
|
||||
frame->ui->graphicsView_Prefab->setScene(scene);
|
||||
frame->ui->graphicsView_Prefab->setFixedSize(scene->itemsBoundingRect().width() + 2,
|
||||
|
@ -218,7 +218,7 @@ void Prefab::updatePrefabUi(Map *map) {
|
|||
});
|
||||
|
||||
// Clicking the delete button removes it from the list of known prefabs and updates the UI.
|
||||
QObject::connect(frame->ui->pushButton_DeleteItem, &QPushButton::clicked, [this, item, map](){
|
||||
QObject::connect(frame->ui->pushButton_DeleteItem, &QPushButton::clicked, [this, item, layout](){
|
||||
for (int i = 0; i < this->items.size(); i++) {
|
||||
if (this->items[i].id == item.id) {
|
||||
QMessageBox msgBox;
|
||||
|
@ -236,7 +236,7 @@ void Prefab::updatePrefabUi(Map *map) {
|
|||
if (msgBox.clickedButton() == deleteButton) {
|
||||
this->items.removeAt(i);
|
||||
this->savePrefabs();
|
||||
this->updatePrefabUi(map);
|
||||
this->updatePrefabUi(layout);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ void Prefab::updatePrefabUi(Map *map) {
|
|||
prefabWidget->layout()->addItem(verticalSpacer);
|
||||
}
|
||||
|
||||
void Prefab::addPrefab(MetatileSelection selection, Map *map, QString name) {
|
||||
void Prefab::addPrefab(MetatileSelection selection, Layout *layout, QString name) {
|
||||
// First, determine which tilesets are actually used in this new prefab,
|
||||
// based on the metatile ids.
|
||||
bool usesPrimaryTileset = false;
|
||||
|
@ -266,12 +266,12 @@ void Prefab::addPrefab(MetatileSelection selection, Map *map, QString name) {
|
|||
this->items.append(PrefabItem{
|
||||
QUuid::createUuid(),
|
||||
name,
|
||||
usesPrimaryTileset ? map->layout->tileset_primary_label : "",
|
||||
usesSecondaryTileset ? map->layout->tileset_secondary_label: "",
|
||||
usesPrimaryTileset ? layout->tileset_primary_label : "",
|
||||
usesSecondaryTileset ? layout->tileset_secondary_label: "",
|
||||
selection
|
||||
});
|
||||
this->savePrefabs();
|
||||
this->updatePrefabUi(map);
|
||||
this->updatePrefabUi(layout);
|
||||
}
|
||||
|
||||
bool Prefab::tryImportDefaultPrefabs(QWidget * parent, BaseGameVersion version, QString filepath) {
|
||||
|
|
|
@ -6,16 +6,16 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
PrefabCreationDialog::PrefabCreationDialog(QWidget *parent, MetatileSelector *metatileSelector, Map *map) :
|
||||
PrefabCreationDialog::PrefabCreationDialog(QWidget *parent, MetatileSelector *metatileSelector, Layout *layout) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::PrefabCreationDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
this->map = map;
|
||||
this->layout = layout;
|
||||
this->selection = metatileSelector->getMetatileSelection();
|
||||
QGraphicsScene *scene = new QGraphicsScene;
|
||||
QGraphicsPixmapItem *pixmapItem = scene->addPixmap(drawMetatileSelection(this->selection, map));
|
||||
QGraphicsPixmapItem *pixmapItem = scene->addPixmap(drawMetatileSelection(this->selection, layout));
|
||||
scene->setSceneRect(scene->itemsBoundingRect());
|
||||
this->ui->graphicsView_Prefab->setScene(scene);
|
||||
this->ui->graphicsView_Prefab->setFixedSize(scene->itemsBoundingRect().width() + 2,
|
||||
|
@ -35,7 +35,7 @@ PrefabCreationDialog::PrefabCreationDialog(QWidget *parent, MetatileSelector *me
|
|||
if (this->selection.hasCollision) {
|
||||
this->selection.collisionItems[index].enabled = toggledState;
|
||||
}
|
||||
pixmapItem->setPixmap(drawMetatileSelection(this->selection, map));
|
||||
pixmapItem->setPixmap(drawMetatileSelection(this->selection, layout));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -45,5 +45,5 @@ PrefabCreationDialog::~PrefabCreationDialog()
|
|||
}
|
||||
|
||||
void PrefabCreationDialog::savePrefab() {
|
||||
prefab.addPrefab(this->selection, this->map, this->ui->lineEdit_PrefabName->text());
|
||||
prefab.addPrefab(this->selection, this->layout, this->ui->lineEdit_PrefabName->text());
|
||||
}
|
||||
|
|
|
@ -13,14 +13,14 @@
|
|||
#include <QCloseEvent>
|
||||
#include <QImageReader>
|
||||
|
||||
TilesetEditor::TilesetEditor(Project *project, Map *map, QWidget *parent) :
|
||||
TilesetEditor::TilesetEditor(Project *project, Layout *layout, QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::TilesetEditor),
|
||||
project(project),
|
||||
map(map),
|
||||
layout(layout),
|
||||
hasUnsavedChanges(false)
|
||||
{
|
||||
this->setTilesets(this->map->layout->tileset_primary_label, this->map->layout->tileset_secondary_label);
|
||||
this->setTilesets(this->layout->tileset_primary_label, this->layout->tileset_secondary_label);
|
||||
this->initUi();
|
||||
}
|
||||
|
||||
|
@ -42,14 +42,14 @@ TilesetEditor::~TilesetEditor()
|
|||
delete copiedMetatile;
|
||||
}
|
||||
|
||||
void TilesetEditor::update(Map *map, QString primaryTilesetLabel, QString secondaryTilesetLabel) {
|
||||
this->updateMap(map);
|
||||
void TilesetEditor::update(Layout *layout, QString primaryTilesetLabel, QString secondaryTilesetLabel) {
|
||||
this->updateLayout(layout);
|
||||
this->updateTilesets(primaryTilesetLabel, secondaryTilesetLabel);
|
||||
}
|
||||
|
||||
void TilesetEditor::updateMap(Map *map) {
|
||||
this->map = map;
|
||||
this->metatileSelector->map = map;
|
||||
void TilesetEditor::updateLayout(Layout *layout) {
|
||||
this->layout = layout;
|
||||
this->metatileSelector->layout = layout;
|
||||
}
|
||||
|
||||
void TilesetEditor::updateTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) {
|
||||
|
@ -178,7 +178,7 @@ void TilesetEditor::setMetatileLabelValidator() {
|
|||
|
||||
void TilesetEditor::initMetatileSelector()
|
||||
{
|
||||
this->metatileSelector = new TilesetEditorMetatileSelector(this->primaryTileset, this->secondaryTileset, this->map);
|
||||
this->metatileSelector = new TilesetEditorMetatileSelector(this->primaryTileset, this->secondaryTileset, this->layout);
|
||||
connect(this->metatileSelector, &TilesetEditorMetatileSelector::hoveredMetatileChanged,
|
||||
this, &TilesetEditor::onHoveredMetatileChanged);
|
||||
connect(this->metatileSelector, &TilesetEditorMetatileSelector::hoveredMetatileCleared,
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
#include "project.h"
|
||||
#include <QPainter>
|
||||
|
||||
TilesetEditorMetatileSelector::TilesetEditorMetatileSelector(Tileset *primaryTileset, Tileset *secondaryTileset, Map *map)
|
||||
TilesetEditorMetatileSelector::TilesetEditorMetatileSelector(Tileset *primaryTileset, Tileset *secondaryTileset, Layout *layout)
|
||||
: SelectablePixmapItem(32, 32, 1, 1) {
|
||||
this->setTilesets(primaryTileset, secondaryTileset, false);
|
||||
this->numMetatilesWide = 8;
|
||||
this->map = map;
|
||||
this->layout = layout;
|
||||
setAcceptHoverEvents(true);
|
||||
this->usedMetatiles.resize(Project::getNumMetatilesTotal());
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ QImage TilesetEditorMetatileSelector::buildImage(int metatileIdStart, int numMet
|
|||
metatileId,
|
||||
this->primaryTileset,
|
||||
this->secondaryTileset,
|
||||
map->metatileLayerOrder,
|
||||
map->metatileLayerOpacity,
|
||||
this->layout->metatileLayerOrder,
|
||||
this->layout->metatileLayerOpacity,
|
||||
true)
|
||||
.scaled(32, 32);
|
||||
int map_y = i / this->numMetatilesWide;
|
||||
|
|
Loading…
Reference in a new issue