Better handling of generic PaintSelection, and accurate selection cursor size
This commit is contained in:
parent
64004a68f2
commit
23747d9822
17 changed files with 147 additions and 124 deletions
|
@ -164,6 +164,8 @@ public slots:
|
|||
void maskNonVisibleConnectionTiles();
|
||||
void onBorderMetatilesChanged();
|
||||
void selectedEventIndexChanged(int index, Event::Group eventGroup);
|
||||
void onSelectedMetatilesChanged();
|
||||
void onSelectedStampsChanged();
|
||||
|
||||
private:
|
||||
void setConnectionItemsVisible(bool);
|
||||
|
@ -207,7 +209,6 @@ private slots:
|
|||
void onHoveredMapMetatileCleared();
|
||||
void onHoveredMapMovementPermissionChanged(int, int);
|
||||
void onHoveredMapMovementPermissionCleared();
|
||||
void onSelectedMetatilesChanged();
|
||||
void onWheelZoom(int);
|
||||
void onToggleGridClicked(bool);
|
||||
|
||||
|
|
|
@ -18,6 +18,6 @@ public:
|
|||
void setMap(Map *map) { this->map = map; }
|
||||
};
|
||||
|
||||
QPixmap drawMetatileSelection(MetatileSelection selection, Map *map);
|
||||
QPixmap drawMetatileSelection(MetatileSelection *selection, Map *map);
|
||||
|
||||
#endif // CURRENTSELECTEDMETATILESPIXMAPITEM_H
|
||||
|
|
|
@ -91,6 +91,7 @@ public:
|
|||
QPoint adjustCoords(QPoint pos);
|
||||
|
||||
private:
|
||||
PaintSelection* getActiveSelection();
|
||||
void paintSmartPath(int x, int y, bool fromScriptCall = false);
|
||||
static QList<int> smartPathTable;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
this->map = map;
|
||||
this->primaryTileset = map->layout->tileset_primary;
|
||||
this->secondaryTileset = map->layout->tileset_secondary;
|
||||
this->selection = MetatileSelection();
|
||||
this->selection = new MetatileSelection();
|
||||
setAcceptHoverEvents(true);
|
||||
}
|
||||
QPoint getSelectionDimensions();
|
||||
|
@ -26,7 +26,7 @@ public:
|
|||
bool select(uint16_t metatile);
|
||||
bool selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation);
|
||||
void setTilesets(Tileset*, Tileset*);
|
||||
MetatileSelection getMetatileSelection();
|
||||
MetatileSelection* getMetatileSelection();
|
||||
void setPrefabSelection(MetatileSelection selection);
|
||||
void setExternalSelection(int, int, QList<uint16_t>, QList<QPair<uint16_t, uint16_t>>);
|
||||
QPoint getMetatileIdCoordsOnWidget(uint16_t);
|
||||
|
@ -47,7 +47,7 @@ private:
|
|||
int externalSelectionWidth;
|
||||
int externalSelectionHeight;
|
||||
QList<uint16_t> externalSelectedMetatiles;
|
||||
MetatileSelection selection;
|
||||
MetatileSelection *selection;
|
||||
|
||||
void updateSelectedMetatiles();
|
||||
void updateExternalSelectedMetatiles();
|
||||
|
|
|
@ -31,6 +31,12 @@ class MetatileSelection: public PaintSelection
|
|||
{
|
||||
public:
|
||||
MetatileSelection() {}
|
||||
void clone(MetatileSelection other) {
|
||||
this->dimensions = other.dimensions;
|
||||
this->hasCollision = other.hasCollision;
|
||||
this->metatileItems = other.metatileItems;
|
||||
this->collisionItems = other.collisionItems;
|
||||
}
|
||||
bool paintNormal(int index, Block *block) override;
|
||||
bool hasCollision = false;
|
||||
QList<MetatileSelectionItem> metatileItems;
|
||||
|
|
|
@ -21,7 +21,7 @@ class Prefab
|
|||
{
|
||||
public:
|
||||
void initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Map *map);
|
||||
void addPrefab(MetatileSelection selection, Map *map, QString name);
|
||||
void addPrefab(MetatileSelection *selection, Map *map, QString name);
|
||||
void updatePrefabUi(Map *map);
|
||||
void tryImportDefaultPrefabs(Map *map);
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
private:
|
||||
Map *map;
|
||||
Ui::PrefabCreationDialog *ui;
|
||||
MetatileSelection selection;
|
||||
MetatileSelection *selection;
|
||||
};
|
||||
|
||||
#endif // PREFABCREATIONDIALOG_H
|
||||
|
|
|
@ -15,13 +15,13 @@ public:
|
|||
this->map = map;
|
||||
this->primaryTileset = map->layout->tileset_primary;
|
||||
this->secondaryTileset = map->layout->tileset_secondary;
|
||||
this->selection = StampSelection{};
|
||||
this->selection = new StampSelection();
|
||||
}
|
||||
QPoint getSelectionDimensions();
|
||||
void draw();
|
||||
bool select(uint16_t stampId);
|
||||
void setTilesets(Tileset*, Tileset*);
|
||||
StampSelection getStampSelection();
|
||||
StampSelection* getStampSelection();
|
||||
QPoint getStampIdCoordsOnWidget(uint16_t);
|
||||
void setMap(Map*);
|
||||
Tileset *primaryTileset;
|
||||
|
@ -33,7 +33,7 @@ protected:
|
|||
private:
|
||||
int numStampsWide;
|
||||
Map *map;
|
||||
StampSelection selection;
|
||||
StampSelection *selection;
|
||||
|
||||
void updateSelectedStamps();
|
||||
uint16_t getStampId(int x, int y);
|
||||
|
|
|
@ -957,6 +957,12 @@ void Editor::onSelectedMetatilesChanged() {
|
|||
this->redrawCurrentMetatilesSelection();
|
||||
}
|
||||
|
||||
void Editor::onSelectedStampsChanged() {
|
||||
QPoint size = this->stamp_selector_item->getSelectionDimensions();
|
||||
this->cursorMapTileRect->updateSelectionSize(size.x(), size.y());
|
||||
this->redrawCurrentMetatilesSelection();
|
||||
}
|
||||
|
||||
void Editor::onWheelZoom(int s) {
|
||||
// Don't zoom the map when the user accidentally scrolls while performing a magic fill. (ctrl + middle button click)
|
||||
if (!(QApplication::mouseButtons() & Qt::MiddleButton)) {
|
||||
|
@ -1410,6 +1416,8 @@ void Editor::displayStampSelector() {
|
|||
scene_stamps = new QGraphicsScene;
|
||||
if (!stamp_selector_item) {
|
||||
stamp_selector_item = new StampSelector(8, map);
|
||||
connect(stamp_selector_item, &StampSelector::selectedStampsChanged,
|
||||
this, &Editor::onSelectedStampsChanged);
|
||||
stamp_selector_item->select(0);
|
||||
} else {
|
||||
stamp_selector_item->setMap(map);
|
||||
|
|
|
@ -1334,8 +1334,8 @@ void MainWindow::redrawMetatileSelection()
|
|||
|
||||
QPoint size = editor->metatile_selector_item->getSelectionDimensions();
|
||||
if (size.x() == 1 && size.y() == 1) {
|
||||
MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection();
|
||||
QPoint pos = editor->metatile_selector_item->getMetatileIdCoordsOnWidget(selection.metatileItems.first().metatileId);
|
||||
MetatileSelection *selection = editor->metatile_selector_item->getMetatileSelection();
|
||||
QPoint pos = editor->metatile_selector_item->getMetatileIdCoordsOnWidget(selection->metatileItems.first().metatileId);
|
||||
pos *= scale;
|
||||
ui->scrollArea_2->ensureVisible(pos.x(), pos.y(), 8 * scale, 8 * scale);
|
||||
}
|
||||
|
@ -1345,8 +1345,8 @@ void MainWindow::currentMetatilesSelectionChanged()
|
|||
{
|
||||
redrawMetatileSelection();
|
||||
if (this->tilesetEditor) {
|
||||
MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection();
|
||||
this->tilesetEditor->selectMetatile(selection.metatileItems.first().metatileId);
|
||||
MetatileSelection *selection = editor->metatile_selector_item->getMetatileSelection();
|
||||
this->tilesetEditor->selectMetatile(selection->metatileItems.first().metatileId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1419,13 +1419,13 @@ void MainWindow::copy() {
|
|||
OrderedJson::object copyObject;
|
||||
copyObject["object"] = "metatile_selection";
|
||||
OrderedJson::array metatiles;
|
||||
MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection();
|
||||
for (auto item : selection.metatileItems) {
|
||||
MetatileSelection *selection = editor->metatile_selector_item->getMetatileSelection();
|
||||
for (auto item : selection->metatileItems) {
|
||||
metatiles.append(static_cast<int>(item.metatileId));
|
||||
}
|
||||
OrderedJson::array collisions;
|
||||
if (selection.hasCollision) {
|
||||
for (auto item : selection.collisionItems) {
|
||||
if (selection->hasCollision) {
|
||||
for (auto item : selection->collisionItems) {
|
||||
OrderedJson::object collision;
|
||||
collision["collision"] = item.collision;
|
||||
collision["elevation"] = item.elevation;
|
||||
|
@ -1673,12 +1673,16 @@ void MainWindow::on_mapViewTab_tabBarClicked(int index)
|
|||
|
||||
if (index == 0) {
|
||||
editor->setEditingMap();
|
||||
editor->onSelectedMetatilesChanged();
|
||||
} else if (index == 1) {
|
||||
editor->setEditingCollision();
|
||||
editor->onSelectedMetatilesChanged();
|
||||
} else if (index == 2) {
|
||||
editor->setEditingMap();
|
||||
editor->onSelectedStampsChanged();
|
||||
} else if (index == 3) {
|
||||
editor->setEditingMap();
|
||||
editor->onSelectedMetatilesChanged();
|
||||
prefab.tryImportDefaultPrefabs(this->editor->map);
|
||||
}
|
||||
editor->setCursorRectVisible(false);
|
||||
|
@ -2684,8 +2688,8 @@ void MainWindow::on_actionTileset_Editor_triggered()
|
|||
this->tilesetEditor->activateWindow();
|
||||
}
|
||||
|
||||
MetatileSelection selection = this->editor->metatile_selector_item->getMetatileSelection();
|
||||
this->tilesetEditor->selectMetatile(selection.metatileItems.first().metatileId);
|
||||
MetatileSelection *selection = this->editor->metatile_selector_item->getMetatileSelection();
|
||||
this->tilesetEditor->selectMetatile(selection->metatileItems.first().metatileId);
|
||||
}
|
||||
|
||||
void MainWindow::initTilesetEditor() {
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
#include <QPainter>
|
||||
|
||||
void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
||||
MetatileSelection *selection = this->metatileSelector->getMetatileSelection();
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
int width = map->getBorderWidth();
|
||||
int height = map->getBorderHeight();
|
||||
|
||||
Blockdata oldBorder = map->layout->border;
|
||||
|
||||
for (int i = 0; i < selection.dimensions.x() && (i + pos.x()) < width; i++) {
|
||||
for (int j = 0; j < selection.dimensions.y() && (j + pos.y()) < height; j++) {
|
||||
MetatileSelectionItem item = selection.metatileItems.at(j * selection.dimensions.x() + i);
|
||||
for (int i = 0; i < selection->dimensions.x() && (i + pos.x()) < width; i++) {
|
||||
for (int j = 0; j < selection->dimensions.y() && (j + pos.y()) < height; j++) {
|
||||
MetatileSelectionItem item = selection->metatileItems.at(j * selection->dimensions.x() + i);
|
||||
map->setBorderMetatileId(pos.x() + i, pos.y() + j, item.metatileId, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,20 +2,20 @@
|
|||
#include "imageproviders.h"
|
||||
#include <QPainter>
|
||||
|
||||
QPixmap drawMetatileSelection(MetatileSelection selection, Map *map) {
|
||||
int width = selection.dimensions.x() * 16;
|
||||
int height = selection.dimensions.y() * 16;
|
||||
QPixmap drawMetatileSelection(MetatileSelection *selection, Map *map) {
|
||||
int width = selection->dimensions.x() * 16;
|
||||
int height = selection->dimensions.y() * 16;
|
||||
QImage image(width, height, QImage::Format_RGBA8888);
|
||||
image.fill(QColor(0, 0, 0, 0));
|
||||
QPainter painter(&image);
|
||||
|
||||
for (int i = 0; i < selection.dimensions.x(); i++) {
|
||||
for (int j = 0; j < selection.dimensions.y(); j++) {
|
||||
for (int i = 0; i < selection->dimensions.x(); i++) {
|
||||
for (int j = 0; j < selection->dimensions.y(); j++) {
|
||||
int x = i * 16;
|
||||
int y = j * 16;
|
||||
QPoint metatile_origin = QPoint(x, y);
|
||||
int index = j * selection.dimensions.x() + i;
|
||||
MetatileSelectionItem item = selection.metatileItems.at(index);
|
||||
int index = j * selection->dimensions.x() + i;
|
||||
MetatileSelectionItem item = selection->metatileItems.at(index);
|
||||
if (item.enabled) {
|
||||
QImage metatile_image = getMetatileImage(
|
||||
item.metatileId,
|
||||
|
@ -33,6 +33,6 @@ QPixmap drawMetatileSelection(MetatileSelection selection, Map *map) {
|
|||
}
|
||||
|
||||
void CurrentSelectedMetatilesPixmapItem::draw() {
|
||||
MetatileSelection selection = metatileSelector->getMetatileSelection();
|
||||
MetatileSelection *selection = metatileSelector->getMetatileSelection();
|
||||
setPixmap(drawMetatileSelection(selection, this->map));
|
||||
}
|
||||
|
|
|
@ -25,7 +25,8 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
|||
|
||||
// Paint onto the map.
|
||||
bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
|
||||
QPoint selectionDimensions = this->metatileSelector->getSelectionDimensions();
|
||||
PaintSelection *selection = this->getActiveSelection();
|
||||
QPoint selectionDimensions = selection->dimensions;
|
||||
if (settings->smartPathsEnabled) {
|
||||
if (!shiftPressed && selectionDimensions.x() == 3 && selectionDimensions.y() == 3) {
|
||||
paintSmartPath(pos.x(), pos.y());
|
||||
|
@ -101,15 +102,16 @@ void MapPixmapItem::shift(int xDelta, int yDelta, bool fromScriptCall) {
|
|||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
|
||||
PaintSelection *selection = nullptr;
|
||||
PaintSelection* MapPixmapItem::getActiveSelection() {
|
||||
if (this->getActivePaintType() == PaintType::PaintTypeMetatile) {
|
||||
MetatileSelection metatileSelection = this->metatileSelector->getMetatileSelection();
|
||||
selection = &metatileSelection;
|
||||
return this->metatileSelector->getMetatileSelection();
|
||||
} else {
|
||||
StampSelection stampSelection = this->stampSelector->getStampSelection();
|
||||
selection = &stampSelection;
|
||||
return this->stampSelector->getStampSelection();
|
||||
}
|
||||
}
|
||||
|
||||
void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
|
||||
PaintSelection *selection = this->getActiveSelection();
|
||||
int initialX = fromScriptCall ? x : this->paint_tile_initial_x;
|
||||
int initialY = fromScriptCall ? y : this->paint_tile_initial_y;
|
||||
int selectionWidth = selection->dimensions.x();
|
||||
|
@ -179,12 +181,12 @@ bool isSmartPathTile(QList<MetatileSelectionItem> metatileItems, uint16_t metati
|
|||
return false;
|
||||
}
|
||||
|
||||
bool isValidSmartPathSelection(MetatileSelection selection) {
|
||||
if (selection.dimensions.x() != 3 || selection.dimensions.y() != 3)
|
||||
bool isValidSmartPathSelection(MetatileSelection *selection) {
|
||||
if (selection->dimensions.x() != 3 || selection->dimensions.y() != 3)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < selection.metatileItems.length(); i++) {
|
||||
if (!selection.metatileItems.at(i).enabled)
|
||||
for (int i = 0; i < selection->metatileItems.length(); i++) {
|
||||
if (!selection->metatileItems.at(i).enabled)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -192,18 +194,21 @@ bool isValidSmartPathSelection(MetatileSelection selection) {
|
|||
}
|
||||
|
||||
void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
||||
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
||||
if (this->getActivePaintType() != PaintType::PaintTypeMetatile) {
|
||||
return;
|
||||
}
|
||||
MetatileSelection *selection = this->metatileSelector->getMetatileSelection();
|
||||
if (!isValidSmartPathSelection(selection))
|
||||
return;
|
||||
|
||||
// Shift to the middle tile of the smart path selection.
|
||||
uint16_t openTile = selection.metatileItems.at(4).metatileId;
|
||||
uint16_t openTile = selection->metatileItems.at(4).metatileId;
|
||||
uint16_t openTileCollision = 0;
|
||||
uint16_t openTileElevation = 0;
|
||||
bool setCollisions = false;
|
||||
if (selection.hasCollision && selection.collisionItems.length() == selection.metatileItems.length()) {
|
||||
openTileCollision = selection.collisionItems.at(4).collision;
|
||||
openTileElevation = selection.collisionItems.at(4).elevation;
|
||||
if (selection->hasCollision && selection->collisionItems.length() == selection->metatileItems.length()) {
|
||||
openTileCollision = selection->collisionItems.at(4).collision;
|
||||
openTileElevation = selection->collisionItems.at(4).elevation;
|
||||
setCollisions = true;
|
||||
}
|
||||
|
||||
|
@ -242,7 +247,7 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
|||
int actualX = i + x;
|
||||
int actualY = j + y;
|
||||
Block block;
|
||||
if (!map->getBlock(actualX, actualY, &block) || !isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
if (!map->getBlock(actualX, actualY, &block) || !isSmartPathTile(selection->metatileItems, block.metatileId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -253,18 +258,18 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
|||
Block left;
|
||||
|
||||
// Get marching squares value, to determine which tile to use.
|
||||
if (map->getBlock(actualX, actualY - 1, &top) && isSmartPathTile(selection.metatileItems, top.metatileId))
|
||||
if (map->getBlock(actualX, actualY - 1, &top) && isSmartPathTile(selection->metatileItems, top.metatileId))
|
||||
id += 1;
|
||||
if (map->getBlock(actualX + 1, actualY, &right) && isSmartPathTile(selection.metatileItems, right.metatileId))
|
||||
if (map->getBlock(actualX + 1, actualY, &right) && isSmartPathTile(selection->metatileItems, right.metatileId))
|
||||
id += 2;
|
||||
if (map->getBlock(actualX, actualY + 1, &bottom) && isSmartPathTile(selection.metatileItems, bottom.metatileId))
|
||||
if (map->getBlock(actualX, actualY + 1, &bottom) && isSmartPathTile(selection->metatileItems, bottom.metatileId))
|
||||
id += 4;
|
||||
if (map->getBlock(actualX - 1, actualY, &left) && isSmartPathTile(selection.metatileItems, left.metatileId))
|
||||
if (map->getBlock(actualX - 1, actualY, &left) && isSmartPathTile(selection->metatileItems, left.metatileId))
|
||||
id += 8;
|
||||
|
||||
block.metatileId = selection.metatileItems.at(smartPathTable[id]).metatileId;
|
||||
block.metatileId = selection->metatileItems.at(smartPathTable[id]).metatileId;
|
||||
if (setCollisions) {
|
||||
CollisionSelectionItem collisionItem = selection.collisionItems.at(smartPathTable[id]);
|
||||
CollisionSelectionItem collisionItem = selection->collisionItems.at(smartPathTable[id]);
|
||||
block.collision = collisionItem.collision;
|
||||
block.elevation = collisionItem.elevation;
|
||||
}
|
||||
|
@ -371,11 +376,11 @@ void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
|||
} else {
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
Block block;
|
||||
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
||||
int metatileId = selection.metatileItems.first().metatileId;
|
||||
if (selection.metatileItems.count() > 1 || (map->getBlock(pos.x(), pos.y(), &block) && block.metatileId != metatileId)) {
|
||||
MetatileSelection *selection = this->metatileSelector->getMetatileSelection();
|
||||
int metatileId = selection->metatileItems.first().metatileId;
|
||||
if (selection->metatileItems.count() > 1 || (map->getBlock(pos.x(), pos.y(), &block) && block.metatileId != metatileId)) {
|
||||
bool smartPathsEnabled = event->modifiers() & Qt::ShiftModifier;
|
||||
if ((this->settings->smartPathsEnabled || smartPathsEnabled) && selection.dimensions.x() == 3 && selection.dimensions.y() == 3)
|
||||
if ((this->settings->smartPathsEnabled || smartPathsEnabled) && selection->dimensions.x() == 3 && selection->dimensions.y() == 3)
|
||||
this->floodFillSmartPath(pos.x(), pos.y());
|
||||
else
|
||||
this->floodFill(pos.x(), pos.y());
|
||||
|
@ -402,8 +407,8 @@ void MapPixmapItem::magicFill(int x, int y, uint16_t metatileId, bool fromScript
|
|||
}
|
||||
|
||||
void MapPixmapItem::magicFill(int x, int y, bool fromScriptCall) {
|
||||
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
||||
this->magicFill(x, y, selection.dimensions, selection.metatileItems, selection.collisionItems, fromScriptCall);
|
||||
MetatileSelection *selection = this->metatileSelector->getMetatileSelection();
|
||||
this->magicFill(x, y, selection->dimensions, selection->metatileItems, selection->collisionItems, fromScriptCall);
|
||||
}
|
||||
|
||||
void MapPixmapItem::magicFill(
|
||||
|
@ -453,8 +458,8 @@ void MapPixmapItem::magicFill(
|
|||
}
|
||||
|
||||
void MapPixmapItem::floodFill(int initialX, int initialY, bool fromScriptCall) {
|
||||
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
||||
this->floodFill(initialX, initialY, selection.dimensions, selection.metatileItems, selection.collisionItems, fromScriptCall);
|
||||
MetatileSelection *selection = this->metatileSelector->getMetatileSelection();
|
||||
this->floodFill(initialX, initialY, selection->dimensions, selection->metatileItems, selection->collisionItems, fromScriptCall);
|
||||
}
|
||||
|
||||
void MapPixmapItem::floodFill(int initialX, int initialY, uint16_t metatileId, bool fromScriptCall) {
|
||||
|
@ -528,17 +533,17 @@ void MapPixmapItem::floodFill(
|
|||
}
|
||||
|
||||
void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScriptCall) {
|
||||
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
||||
MetatileSelection *selection = this->metatileSelector->getMetatileSelection();
|
||||
if (!isValidSmartPathSelection(selection))
|
||||
return;
|
||||
|
||||
// Shift to the middle tile of the smart path selection.
|
||||
uint16_t openTile = selection.metatileItems.at(4).metatileId;
|
||||
uint16_t openTile = selection->metatileItems.at(4).metatileId;
|
||||
uint16_t openTileCollision = 0;
|
||||
uint16_t openTileElevation = 0;
|
||||
bool setCollisions = false;
|
||||
if (selection.hasCollision && selection.collisionItems.length() == selection.metatileItems.length()) {
|
||||
CollisionSelectionItem item = selection.collisionItems.at(4);
|
||||
if (selection->hasCollision && selection->collisionItems.length() == selection->metatileItems.length()) {
|
||||
CollisionSelectionItem item = selection->collisionItems.at(4);
|
||||
openTileCollision = item.collision;
|
||||
openTileElevation = item.elevation;
|
||||
setCollisions = true;
|
||||
|
@ -604,37 +609,37 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri
|
|||
Block left;
|
||||
|
||||
// Get marching squares value, to determine which tile to use.
|
||||
if (map->getBlock(x, y - 1, &top) && isSmartPathTile(selection.metatileItems, top.metatileId))
|
||||
if (map->getBlock(x, y - 1, &top) && isSmartPathTile(selection->metatileItems, top.metatileId))
|
||||
id += 1;
|
||||
if (map->getBlock(x + 1, y, &right) && isSmartPathTile(selection.metatileItems, right.metatileId))
|
||||
if (map->getBlock(x + 1, y, &right) && isSmartPathTile(selection->metatileItems, right.metatileId))
|
||||
id += 2;
|
||||
if (map->getBlock(x, y + 1, &bottom) && isSmartPathTile(selection.metatileItems, bottom.metatileId))
|
||||
if (map->getBlock(x, y + 1, &bottom) && isSmartPathTile(selection->metatileItems, bottom.metatileId))
|
||||
id += 4;
|
||||
if (map->getBlock(x - 1, y, &left) && isSmartPathTile(selection.metatileItems, left.metatileId))
|
||||
if (map->getBlock(x - 1, y, &left) && isSmartPathTile(selection->metatileItems, left.metatileId))
|
||||
id += 8;
|
||||
|
||||
block.metatileId = selection.metatileItems.at(smartPathTable[id]).metatileId;
|
||||
block.metatileId = selection->metatileItems.at(smartPathTable[id]).metatileId;
|
||||
if (setCollisions) {
|
||||
CollisionSelectionItem item = selection.collisionItems.at(smartPathTable[id]);
|
||||
CollisionSelectionItem item = selection->collisionItems.at(smartPathTable[id]);
|
||||
block.collision = item.collision;
|
||||
block.elevation = item.elevation;
|
||||
}
|
||||
map->setBlock(x, y, block, !fromScriptCall);
|
||||
|
||||
// Visit neighbors if they are smart-path tiles, and don't revisit any.
|
||||
if (!visited.contains(x + 1 + y * map->getWidth()) && map->getBlock(x + 1, y, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
if (!visited.contains(x + 1 + y * map->getWidth()) && map->getBlock(x + 1, y, &block) && isSmartPathTile(selection->metatileItems, block.metatileId)) {
|
||||
todo.append(QPoint(x + 1, y));
|
||||
visited.insert(x + 1 + y * map->getWidth());
|
||||
}
|
||||
if (!visited.contains(x - 1 + y * map->getWidth()) && map->getBlock(x - 1, y, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
if (!visited.contains(x - 1 + y * map->getWidth()) && map->getBlock(x - 1, y, &block) && isSmartPathTile(selection->metatileItems, block.metatileId)) {
|
||||
todo.append(QPoint(x - 1, y));
|
||||
visited.insert(x - 1 + y * map->getWidth());
|
||||
}
|
||||
if (!visited.contains(x + (y + 1) * map->getWidth()) && map->getBlock(x, y + 1, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
if (!visited.contains(x + (y + 1) * map->getWidth()) && map->getBlock(x, y + 1, &block) && isSmartPathTile(selection->metatileItems, block.metatileId)) {
|
||||
todo.append(QPoint(x, y + 1));
|
||||
visited.insert(x + (y + 1) * map->getWidth());
|
||||
}
|
||||
if (!visited.contains(x + (y - 1) * map->getWidth()) && map->getBlock(x, y - 1, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
|
||||
if (!visited.contains(x + (y - 1) * map->getWidth()) && map->getBlock(x, y - 1, &block) && isSmartPathTile(selection->metatileItems, block.metatileId)) {
|
||||
todo.append(QPoint(x, y - 1));
|
||||
visited.insert(x + (y - 1) * map->getWidth());
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <QPainter>
|
||||
|
||||
QPoint MetatileSelector::getSelectionDimensions() {
|
||||
return selection.dimensions;
|
||||
return selection->dimensions;
|
||||
}
|
||||
|
||||
void MetatileSelector::draw() {
|
||||
|
@ -45,11 +45,10 @@ bool MetatileSelector::select(uint16_t metatileId) {
|
|||
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) return false;
|
||||
this->externalSelection = false;
|
||||
this->prefabSelection = false;
|
||||
this->selection = MetatileSelection();
|
||||
this->selection.dimensions = QPoint(1, 1);
|
||||
this->selection.hasCollision = false;
|
||||
this->selection.metatileItems = QList<MetatileSelectionItem>({MetatileSelectionItem{true, metatileId}});
|
||||
this->selection.collisionItems = QList<CollisionSelectionItem>();
|
||||
this->selection->dimensions = QPoint(1, 1);
|
||||
this->selection->hasCollision = false;
|
||||
this->selection->metatileItems = QList<MetatileSelectionItem>({MetatileSelectionItem{true, metatileId}});
|
||||
this->selection->collisionItems = QList<CollisionSelectionItem>();
|
||||
QPoint coords = this->getMetatileIdCoords(metatileId);
|
||||
SelectablePixmapItem::select(coords.x(), coords.y(), 0, 0);
|
||||
this->updateSelectedMetatiles();
|
||||
|
@ -59,8 +58,8 @@ bool MetatileSelector::select(uint16_t metatileId) {
|
|||
bool MetatileSelector::selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation) {
|
||||
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) return false;
|
||||
this->select(metatileId);
|
||||
this->selection.collisionItems.append(CollisionSelectionItem{true, collision, elevation});
|
||||
this->selection.hasCollision = true;
|
||||
this->selection->collisionItems.append(CollisionSelectionItem{true, collision, elevation});
|
||||
this->selection->hasCollision = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -74,7 +73,7 @@ void MetatileSelector::setTilesets(Tileset *primaryTileset, Tileset *secondaryTi
|
|||
this->draw();
|
||||
}
|
||||
|
||||
MetatileSelection MetatileSelector::getMetatileSelection() {
|
||||
MetatileSelection* MetatileSelector::getMetatileSelection() {
|
||||
return selection;
|
||||
}
|
||||
|
||||
|
@ -84,18 +83,18 @@ void MetatileSelector::setExternalSelection(int width, int height, QList<uint16_
|
|||
this->externalSelectionWidth = width;
|
||||
this->externalSelectionHeight = height;
|
||||
this->externalSelectedMetatiles.clear();
|
||||
this->selection.metatileItems.clear();
|
||||
this->selection.collisionItems.clear();
|
||||
this->selection.hasCollision = true;
|
||||
this->selection.dimensions = QPoint(width, height);
|
||||
this->selection->metatileItems.clear();
|
||||
this->selection->collisionItems.clear();
|
||||
this->selection->hasCollision = true;
|
||||
this->selection->dimensions = QPoint(width, height);
|
||||
for (int i = 0; i < metatiles.length(); i++) {
|
||||
auto collision = collisions.at(i);
|
||||
this->selection.collisionItems.append(CollisionSelectionItem{true, collision.first, collision.second});
|
||||
this->selection->collisionItems.append(CollisionSelectionItem{true, collision.first, collision.second});
|
||||
uint16_t metatileId = metatiles.at(i);
|
||||
this->externalSelectedMetatiles.append(metatileId);
|
||||
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset))
|
||||
metatileId = 0;
|
||||
this->selection.metatileItems.append(MetatileSelectionItem{true, metatileId});
|
||||
this->selection->metatileItems.append(MetatileSelectionItem{true, metatileId});
|
||||
}
|
||||
|
||||
this->draw();
|
||||
|
@ -106,7 +105,7 @@ void MetatileSelector::setPrefabSelection(MetatileSelection selection) {
|
|||
this->externalSelection = false;
|
||||
this->prefabSelection = true;
|
||||
this->externalSelectedMetatiles.clear();
|
||||
this->selection = selection;
|
||||
this->selection->clone(selection);
|
||||
this->draw();
|
||||
emit selectedMetatilesChanged();
|
||||
}
|
||||
|
@ -151,30 +150,30 @@ void MetatileSelector::hoverLeaveEvent(QGraphicsSceneHoverEvent*) {
|
|||
void MetatileSelector::updateSelectedMetatiles() {
|
||||
this->externalSelection = false;
|
||||
this->prefabSelection = false;
|
||||
this->selection.metatileItems.clear();
|
||||
this->selection.collisionItems.clear();
|
||||
this->selection.hasCollision = false;
|
||||
this->selection.dimensions = SelectablePixmapItem::getSelectionDimensions();
|
||||
this->selection->metatileItems.clear();
|
||||
this->selection->collisionItems.clear();
|
||||
this->selection->hasCollision = false;
|
||||
this->selection->dimensions = SelectablePixmapItem::getSelectionDimensions();
|
||||
QPoint origin = this->getSelectionStart();
|
||||
for (int j = 0; j < this->selection.dimensions.y(); j++) {
|
||||
for (int i = 0; i < this->selection.dimensions.x(); i++) {
|
||||
for (int j = 0; j < this->selection->dimensions.y(); j++) {
|
||||
for (int i = 0; i < this->selection->dimensions.x(); i++) {
|
||||
uint16_t metatileId = this->getMetatileId(origin.x() + i, origin.y() + j);
|
||||
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset))
|
||||
metatileId = 0;
|
||||
this->selection.metatileItems.append(MetatileSelectionItem{true, metatileId});
|
||||
this->selection->metatileItems.append(MetatileSelectionItem{true, metatileId});
|
||||
}
|
||||
}
|
||||
emit selectedMetatilesChanged();
|
||||
}
|
||||
|
||||
void MetatileSelector::updateExternalSelectedMetatiles() {
|
||||
this->selection.metatileItems.clear();
|
||||
this->selection.dimensions = QPoint(this->externalSelectionWidth, this->externalSelectionHeight);
|
||||
this->selection->metatileItems.clear();
|
||||
this->selection->dimensions = QPoint(this->externalSelectionWidth, this->externalSelectionHeight);
|
||||
for (int i = 0; i < this->externalSelectedMetatiles.count(); ++i) {
|
||||
uint16_t metatileId = this->externalSelectedMetatiles.at(i);
|
||||
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset))
|
||||
metatileId = 0;
|
||||
this->selection.metatileItems.append(MetatileSelectionItem{true, metatileId});
|
||||
this->selection->metatileItems.append(MetatileSelectionItem{true, metatileId});
|
||||
}
|
||||
emit selectedMetatilesChanged();
|
||||
}
|
||||
|
|
|
@ -199,7 +199,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, map));
|
||||
scene->setSceneRect(scene->itemsBoundingRect());
|
||||
frame->ui->graphicsView_Prefab->setScene(scene);
|
||||
frame->ui->graphicsView_Prefab->setFixedSize(scene->itemsBoundingRect().width() + 2,
|
||||
|
@ -243,12 +243,12 @@ void Prefab::updatePrefabUi(Map *map) {
|
|||
prefabWidget->layout()->addItem(verticalSpacer);
|
||||
}
|
||||
|
||||
void Prefab::addPrefab(MetatileSelection selection, Map *map, QString name) {
|
||||
void Prefab::addPrefab(MetatileSelection *selection, Map *map, QString name) {
|
||||
// First, determine which tilesets are actually used in this new prefab,
|
||||
// based on the metatile ids.
|
||||
bool usesPrimaryTileset = false;
|
||||
bool usesSecondaryTileset = false;
|
||||
for (auto metatile : selection.metatileItems) {
|
||||
for (auto metatile : selection->metatileItems) {
|
||||
if (!metatile.enabled)
|
||||
continue;
|
||||
if (metatile.metatileId < Project::getNumMetatilesPrimary()) {
|
||||
|
@ -263,7 +263,7 @@ void Prefab::addPrefab(MetatileSelection selection, Map *map, QString name) {
|
|||
name,
|
||||
usesPrimaryTileset ? map->layout->tileset_primary_label : "",
|
||||
usesSecondaryTileset ? map->layout->tileset_secondary_label: "",
|
||||
selection
|
||||
*selection
|
||||
});
|
||||
this->savePrefabs();
|
||||
this->updatePrefabUi(map);
|
||||
|
|
|
@ -23,17 +23,17 @@ PrefabCreationDialog::PrefabCreationDialog(QWidget *parent, MetatileSelector *me
|
|||
|
||||
QObject::connect(this->ui->graphicsView_Prefab, &ClickableGraphicsView::clicked, [=](QMouseEvent *event){
|
||||
auto pos = event->pos();
|
||||
int selectionWidth = this->selection.dimensions.x() * 16;
|
||||
int selectionHeight = this->selection.dimensions.y() * 16;
|
||||
int selectionWidth = this->selection->dimensions.x() * 16;
|
||||
int selectionHeight = this->selection->dimensions.y() * 16;
|
||||
if (pos.x() < 0 || pos.x() >= selectionWidth || pos.y() < 0 || pos.y() >= selectionHeight)
|
||||
return;
|
||||
int metatileX = pos.x() / 16;
|
||||
int metatileY = pos.y() / 16;
|
||||
int index = metatileY * this->selection.dimensions.x() + metatileX;
|
||||
bool toggledState = !this->selection.metatileItems[index].enabled;
|
||||
this->selection.metatileItems[index].enabled = toggledState;
|
||||
if (this->selection.hasCollision) {
|
||||
this->selection.collisionItems[index].enabled = toggledState;
|
||||
int index = metatileY * this->selection->dimensions.x() + metatileX;
|
||||
bool toggledState = !this->selection->metatileItems[index].enabled;
|
||||
this->selection->metatileItems[index].enabled = toggledState;
|
||||
if (this->selection->hasCollision) {
|
||||
this->selection->collisionItems[index].enabled = toggledState;
|
||||
}
|
||||
pixmapItem->setPixmap(drawMetatileSelection(this->selection, map));
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <QPainter>
|
||||
|
||||
QPoint StampSelector::getSelectionDimensions() {
|
||||
return selection.dimensions;
|
||||
return selection->dimensions;
|
||||
}
|
||||
|
||||
void StampSelector::draw() {
|
||||
|
@ -43,9 +43,8 @@ bool StampSelector::select(uint16_t stampId) {
|
|||
// TODO:
|
||||
if (stampId > 9999999999999) return false;
|
||||
|
||||
this->selection = StampSelection();
|
||||
this->selection.dimensions = QPoint(1, 1);
|
||||
this->selection.stampIds = QList<uint16_t>(stampId);
|
||||
this->selection->dimensions = QPoint(1, 1);
|
||||
this->selection->stampIds = QList<uint16_t>(stampId);
|
||||
|
||||
QPoint coords = this->getStampIdCoords(stampId);
|
||||
SelectablePixmapItem::select(coords.x(), coords.y(), 0, 0);
|
||||
|
@ -60,7 +59,7 @@ void StampSelector::setTilesets(Tileset *primaryTileset, Tileset *secondaryTiles
|
|||
this->draw();
|
||||
}
|
||||
|
||||
StampSelection StampSelector::getStampSelection() {
|
||||
StampSelection* StampSelector::getStampSelection() {
|
||||
return selection;
|
||||
}
|
||||
|
||||
|
@ -90,16 +89,16 @@ void StampSelector::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
|||
}
|
||||
|
||||
void StampSelector::updateSelectedStamps() {
|
||||
this->selection.stampIds.clear();
|
||||
this->selection.dimensions = SelectablePixmapItem::getSelectionDimensions();
|
||||
this->selection->stampIds.clear();
|
||||
this->selection->dimensions = SelectablePixmapItem::getSelectionDimensions();
|
||||
QPoint origin = this->getSelectionStart();
|
||||
for (int j = 0; j < this->selection.dimensions.y(); j++) {
|
||||
for (int i = 0; i < this->selection.dimensions.x(); i++) {
|
||||
for (int j = 0; j < this->selection->dimensions.y(); j++) {
|
||||
for (int i = 0; i < this->selection->dimensions.x(); i++) {
|
||||
uint16_t stampId = this->getStampId(origin.x() + i, origin.y() + j);
|
||||
// TODO: check if stamp id is valid
|
||||
if (false)
|
||||
stampId = 0;
|
||||
this->selection.stampIds.append(stampId);
|
||||
this->selection->stampIds.append(stampId);
|
||||
}
|
||||
}
|
||||
emit selectedStampsChanged();
|
||||
|
|
Loading…
Reference in a new issue