some code cleanup

This commit is contained in:
garak 2023-04-07 21:50:46 -04:00
parent 2d2b7f723b
commit f4cd57c988
16 changed files with 187 additions and 213 deletions

View file

@ -22,9 +22,9 @@ enum CommandId {
ID_PaintCollision,
ID_BucketFillCollision,
ID_MagicFillCollision,
ID_ResizeMap,
ID_ResizeLayout,
ID_PaintBorder,
ID_ScriptEditMap,
ID_ScriptEditLayout,
ID_EventMove,
ID_EventShift,
ID_EventCreate,
@ -194,9 +194,9 @@ private:
/// Implements a command to commit a map or border resize action.
class ResizeMap : public QUndoCommand {
class ResizeLayout : public QUndoCommand {
public:
ResizeMap(Layout *layout, QSize oldMapDimensions, QSize newMapDimensions,
ResizeLayout(Layout *layout, QSize oldLayoutDimensions, QSize newLayoutDimensions,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
QSize oldBorderDimensions, QSize newBorderDimensions,
const Blockdata &oldBorder, const Blockdata &newBorder,
@ -206,15 +206,15 @@ public:
void redo() override;
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_ResizeMap; }
int id() const override { return CommandId::ID_ResizeLayout; }
private:
Layout *layout = nullptr;
int oldMapWidth;
int oldMapHeight;
int newMapWidth;
int newMapHeight;
int oldLayoutWidth;
int oldLayoutHeight;
int newLayoutWidth;
int newLayoutHeight;
int oldBorderWidth;
int oldBorderHeight;
@ -342,13 +342,12 @@ public:
// !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 {
class ScriptEditLayout : public QUndoCommand {
public:
ScriptEditMap(Layout *layout,
QSize oldMapDimensions, QSize newMapDimensions,
ScriptEditLayout(Layout *layout,
QSize oldLayoutDimensions, QSize newLayoutDimensions,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
QSize oldBorderDimensions, QSize newBorderDimensions,
const Blockdata &oldBorder, const Blockdata &newBorder,
@ -358,7 +357,7 @@ public:
void redo() override;
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_ScriptEditMap; }
int id() const override { return CommandId::ID_ScriptEditLayout; }
private:
Layout *layout = nullptr;
@ -369,10 +368,10 @@ private:
Blockdata newBorder;
Blockdata oldBorder;
int oldMapWidth;
int oldMapHeight;
int newMapWidth;
int newMapHeight;
int oldLayoutWidth;
int oldLayoutHeight;
int newLayoutWidth;
int newLayoutHeight;
int oldBorderWidth;
int oldBorderHeight;

View file

@ -55,7 +55,7 @@ public:
Blockdata cached_border;
struct {
Blockdata blocks;
QSize mapDimensions;
QSize layoutDimensions;
Blockdata border;
QSize borderDimensions;
} lastCommitBlocks; // to track map changes

View file

@ -64,9 +64,9 @@ private:
/// Edit Layout Dimensions
class ResizeLayout : public QUndoCommand {
class ResizeRMLayout : public QUndoCommand {
public:
ResizeLayout(RegionMap *map, int oldWidth, int oldHeight, int newWidth, int newHeight,
ResizeRMLayout(RegionMap *map, int oldWidth, int oldHeight, int newWidth, int newHeight,
QMap<QString, QList<LayoutSquare>> oldLayouts, QMap<QString, QList<LayoutSquare>> newLayouts, QUndoCommand *parent = nullptr);
void undo() override;

View file

@ -46,8 +46,8 @@ public:
QObject *parent = nullptr;
Project *project = nullptr;
QPointer<Map> map = nullptr; // !TODO: since removed onMapCacheCleared, make sure this works as intended
QPointer<Layout> layout = nullptr; /* NEW */
QPointer<Map> map = nullptr;
QPointer<Layout> layout = nullptr;
QUndoGroup editGroup; // Manages the undo history for each map
@ -118,8 +118,6 @@ public:
void updateCursorRectPos(int x, int y);
void setCursorRectVisible(bool visible);
QGraphicsScene *scene = nullptr;
QGraphicsPixmapItem *current_view = nullptr;
LayoutPixmapItem *map_item = nullptr;
@ -154,15 +152,18 @@ public:
EditAction mapEditAction = EditAction::Paint;
EditAction objectEditAction = EditAction::Select;
/// !TODO this
enum class EditMode { None, Disabled, Map, Layout, Objects, Connections, Encounters };
EditMode editMode = EditMode::Map;
enum class EditMode { None, Disabled, Metatiles, Collision, Header, Events, Connections, Encounters };
EditMode editMode = EditMode::None;
void setEditMode(EditMode mode) { this->editMode = mode; }
EditMode getEditMode() { return this->editMode; }
void setEditingMap();
bool getEditingLayout();
void setEditorView();
void setEditingMetatiles();
void setEditingCollision();
void setEditingLayout();
void setEditingHeader();
void setEditingObjects();
void setEditingConnections();
void setEditingEncounters();

View file

@ -14,25 +14,16 @@ private:
using QGraphicsPixmapItem::paint;
public:
enum class PaintMode {
Disabled,
Metatiles,
EventObjects
};
LayoutPixmapItem(Layout *layout, MetatileSelector *metatileSelector, Settings *settings) {
this->layout = layout;
// this->map->setMapItem(this);
this->metatileSelector = metatileSelector;
this->settings = settings;
this->paintingMode = PaintMode::Metatiles;
this->lockedAxis = LayoutPixmapItem::Axis::None;
this->prevStraightPathState = false;
setAcceptHoverEvents(true);
}
LayoutPixmapItem::PaintMode paintingMode;
Layout *layout;
MetatileSelector *metatileSelector;
@ -95,12 +86,17 @@ public:
void lockNondominantAxis(QGraphicsSceneMouseEvent *event);
QPoint adjustCoords(QPoint pos);
void setEditsEnabled(bool enabled) { this->editsEnabled = enabled; }
bool getEditsEnabled() { return this->editsEnabled; }
private:
void paintSmartPath(int x, int y, bool fromScriptCall = false);
static QList<int> smartPathTable;
unsigned actionId_ = 0;
bool editsEnabled = true;
signals:
void startPaint(QGraphicsSceneMouseEvent *, LayoutPixmapItem *);
void endPaint(QGraphicsSceneMouseEvent *, LayoutPixmapItem *);

View file

@ -24,7 +24,6 @@ int getEventTypeMask(QList<Event *> events) {
return eventTypeMask;
}
/// !TODO:
void renderBlocks(Layout *layout, bool ignoreCache = false) {
layout->layoutItem->draw(ignoreCache);
layout->collisionItem->draw(ignoreCache);
@ -178,7 +177,7 @@ bool ShiftMetatiles::mergeWith(const QUndoCommand *command) {
************************************************************************
******************************************************************************/
ResizeMap::ResizeMap(Layout *layout, QSize oldMapDimensions, QSize newMapDimensions,
ResizeLayout::ResizeLayout(Layout *layout, QSize oldLayoutDimensions, QSize newLayoutDimensions,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
QSize oldBorderDimensions, QSize newBorderDimensions,
const Blockdata &oldBorder, const Blockdata &newBorder,
@ -187,11 +186,11 @@ ResizeMap::ResizeMap(Layout *layout, QSize oldMapDimensions, QSize newMapDimensi
this->layout = layout;
this->oldMapWidth = oldMapDimensions.width();
this->oldMapHeight = oldMapDimensions.height();
this->oldLayoutWidth = oldLayoutDimensions.width();
this->oldLayoutHeight = oldLayoutDimensions.height();
this->newMapWidth = newMapDimensions.width();
this->newMapHeight = newMapDimensions.height();
this->newLayoutWidth = newLayoutDimensions.width();
this->newLayoutHeight = newLayoutDimensions.height();
this->oldMetatiles = oldMetatiles;
this->newMetatiles = newMetatiles;
@ -206,33 +205,33 @@ ResizeMap::ResizeMap(Layout *layout, QSize oldMapDimensions, QSize newMapDimensi
this->newBorder = newBorder;
}
void ResizeMap::redo() {
void ResizeLayout::redo() {
QUndoCommand::redo();
if (!layout) return;
layout->blockdata = newMetatiles;
layout->setDimensions(newMapWidth, newMapHeight, false, true);
layout->setDimensions(newLayoutWidth, newLayoutHeight, false, true);
layout->border = newBorder;
layout->setBorderDimensions(newBorderWidth, newBorderHeight, false, true);
layout->lastCommitBlocks.mapDimensions = QSize(layout->getWidth(), layout->getHeight());
layout->lastCommitBlocks.layoutDimensions = QSize(layout->getWidth(), layout->getHeight());
layout->lastCommitBlocks.borderDimensions = QSize(layout->getBorderWidth(), layout->getBorderHeight());
layout->needsRedrawing();
}
void ResizeMap::undo() {
void ResizeLayout::undo() {
if (!layout) return;
layout->blockdata = oldMetatiles;
layout->setDimensions(oldMapWidth, oldMapHeight, false, true);
layout->setDimensions(oldLayoutWidth, oldLayoutHeight, false, true);
layout->border = oldBorder;
layout->setBorderDimensions(oldBorderWidth, oldBorderHeight, false, true);
layout->lastCommitBlocks.mapDimensions = QSize(layout->getWidth(), layout->getHeight());
layout->lastCommitBlocks.layoutDimensions = QSize(layout->getWidth(), layout->getHeight());
layout->lastCommitBlocks.borderDimensions = QSize(layout->getBorderWidth(), layout->getBorderHeight());
layout->needsRedrawing();
@ -487,23 +486,23 @@ int EventPaste::id() const {
************************************************************************
******************************************************************************/
ScriptEditMap::ScriptEditMap(Layout *layout,
QSize oldMapDimensions, QSize newMapDimensions,
ScriptEditLayout::ScriptEditLayout(Layout *layout,
QSize oldLayoutDimensions, QSize newLayoutDimensions,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
QSize oldBorderDimensions, QSize newBorderDimensions,
const Blockdata &oldBorder, const Blockdata &newBorder,
QUndoCommand *parent) : QUndoCommand(parent) {
setText("Script Edit Map");
setText("Script Edit Layout");
this->layout = layout;
this->newMetatiles = newMetatiles;
this->oldMetatiles = oldMetatiles;
this->oldMapWidth = oldMapDimensions.width();
this->oldMapHeight = oldMapDimensions.height();
this->newMapWidth = newMapDimensions.width();
this->newMapHeight = newMapDimensions.height();
this->oldLayoutWidth = oldLayoutDimensions.width();
this->oldLayoutHeight = oldLayoutDimensions.height();
this->newLayoutWidth = newLayoutDimensions.width();
this->newLayoutHeight = newLayoutDimensions.height();
this->oldBorder = oldBorder;
this->newBorder = newBorder;
@ -514,14 +513,14 @@ ScriptEditMap::ScriptEditMap(Layout *layout,
this->newBorderHeight = newBorderDimensions.height();
}
void ScriptEditMap::redo() {
void ScriptEditLayout::redo() {
QUndoCommand::redo();
if (!layout) return;
if (newMapWidth != layout->getWidth() || newMapHeight != layout->getHeight()) {
if (newLayoutWidth != layout->getWidth() || newLayoutHeight != layout->getHeight()) {
layout->blockdata = newMetatiles;
layout->setDimensions(newMapWidth, newMapHeight, false);
layout->setDimensions(newLayoutWidth, newLayoutHeight, false);
} else {
layout->setBlockdata(newMetatiles);
}
@ -534,21 +533,20 @@ void ScriptEditMap::redo() {
}
layout->lastCommitBlocks.blocks = newMetatiles;
layout->lastCommitBlocks.mapDimensions = QSize(newMapWidth, newMapHeight);
layout->lastCommitBlocks.layoutDimensions = QSize(newLayoutWidth, newLayoutHeight);
layout->lastCommitBlocks.border = newBorder;
layout->lastCommitBlocks.borderDimensions = QSize(newBorderWidth, newBorderHeight);
// !TODO
renderBlocks(layout);
layout->borderItem->draw();
}
void ScriptEditMap::undo() {
void ScriptEditLayout::undo() {
if (!layout) return;
if (oldMapWidth != layout->getWidth() || oldMapHeight != layout->getHeight()) {
if (oldLayoutWidth != layout->getWidth() || oldLayoutHeight != layout->getHeight()) {
layout->blockdata = oldMetatiles;
layout->setDimensions(oldMapWidth, oldMapHeight, false);
layout->setDimensions(oldLayoutWidth, oldLayoutHeight, false);
} else {
layout->setBlockdata(oldMetatiles);
}
@ -561,11 +559,10 @@ void ScriptEditMap::undo() {
}
layout->lastCommitBlocks.blocks = oldMetatiles;
layout->lastCommitBlocks.mapDimensions = QSize(oldMapWidth, oldMapHeight);
layout->lastCommitBlocks.layoutDimensions = QSize(oldLayoutWidth, oldLayoutHeight);
layout->lastCommitBlocks.border = oldBorder;
layout->lastCommitBlocks.borderDimensions = QSize(oldBorderWidth, oldBorderHeight);
// !TODO
renderBlocks(layout);
layout->borderItem->draw();

View file

@ -90,7 +90,7 @@ bool EditLayout::mergeWith(const QUndoCommand *command) {
///
ResizeLayout::ResizeLayout(RegionMap *map, int oldWidth, int oldHeight, int newWidth, int newHeight,
ResizeRMLayout::ResizeRMLayout(RegionMap *map, int oldWidth, int oldHeight, int newWidth, int newHeight,
QMap<QString, QList<LayoutSquare>> oldLayouts, QMap<QString, QList<LayoutSquare>> newLayouts, QUndoCommand *parent)
: QUndoCommand(parent) {
setText("Change Layout Dimensions");
@ -104,7 +104,7 @@ ResizeLayout::ResizeLayout(RegionMap *map, int oldWidth, int oldHeight, int newW
this->newLayouts = newLayouts;
}
void ResizeLayout::redo() {
void ResizeRMLayout::redo() {
QUndoCommand::redo();
if (!map) return;
@ -113,7 +113,7 @@ void ResizeLayout::redo() {
map->setAllLayouts(this->newLayouts);
}
void ResizeLayout::undo() {
void ResizeRMLayout::undo() {
if (!map) return;
map->setLayoutDimensions(oldWidth, oldHeight, false);
@ -122,8 +122,8 @@ void ResizeLayout::undo() {
QUndoCommand::undo();
}
bool ResizeLayout::mergeWith(const QUndoCommand *command) {
const ResizeLayout *other = static_cast<const ResizeLayout *>(command);
bool ResizeRMLayout::mergeWith(const QUndoCommand *command) {
const ResizeRMLayout *other = static_cast<const ResizeRMLayout *>(command);
if (this->map != other->map)
return false;

View file

@ -83,130 +83,119 @@ void Editor::closeProject() {
}
}
void Editor::setEditingMap() {
current_view = map_item;
if (map_item) {
map_item->paintingMode = LayoutPixmapItem::PaintMode::Metatiles;
displayMapConnections();
map_item->draw();
map_item->setVisible(true);
bool Editor::getEditingLayout() {
return this->editMode == EditMode::Metatiles || this->editMode == EditMode::Collision;
}
if (collision_item) {
void Editor::setEditorView() {
// based on editMode
if (!map_item || !collision_item) return;
if (!this->layout) return;
map_item->setVisible(true); // is map item ever not visible
collision_item->setVisible(false);
}
if (events_group) {
events_group->setVisible(false);
}
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionsEditable(false);
this->cursorMapTileRect->stopSingleTileMode();
this->cursorMapTileRect->setActive(true);
if (this->layout) {
this->editGroup.setActiveStack(&this->layout->editHistory);
}
setMapEditingButtonsEnabled(true);
}
void Editor::setEditingLayout() {
//
}
void Editor::setEditingCollision() {
switch (this->editMode) {
case EditMode::Metatiles:
case EditMode::Connections:
case EditMode::Events:
current_view = map_item;
break;
case EditMode::Collision:
current_view = collision_item;
if (collision_item) {
displayMapConnections();
collision_item->draw();
collision_item->setVisible(true);
break;
default:
current_view = nullptr;
return;
}
if (map_item) {
map_item->paintingMode = LayoutPixmapItem::PaintMode::Metatiles;
map_item->draw();
map_item->setVisible(true);
}
if (events_group) {
events_group->setVisible(false);
}
collision_item->draw();
displayMapConnections();
current_view->setVisible(true);
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionsEditable(false);
this->cursorMapTileRect->setSingleTileMode();
this->cursorMapTileRect->setActive(true);
if (this->layout) {
switch (this->editMode) {
case EditMode::Metatiles:
case EditMode::Collision:
this->editGroup.setActiveStack(&this->layout->editHistory);
}
setMapEditingButtonsEnabled(true);
}
void Editor::setEditingObjects() {
current_view = map_item;
if (events_group) {
events_group->setVisible(true);
}
if (map_item) {
// !TODO: change this pixmapitem paintmode
map_item->paintingMode = LayoutPixmapItem::PaintMode::EventObjects;
displayMapConnections();
map_item->draw();
map_item->setVisible(true);
}
if (collision_item) {
collision_item->setVisible(false);
}
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionsEditable(false);
this->cursorMapTileRect->setSingleTileMode();
this->cursorMapTileRect->setActive(false);
break;
case EditMode::Events:
if (this->map) {
this->editGroup.setActiveStack(&this->map->editHistory);
}
setMapEditingButtonsEnabled(false);
}
void Editor::setEditingConnections() {
current_view = map_item;
if (map_item) {
map_item->paintingMode = LayoutPixmapItem::PaintMode::Disabled;
map_item->draw();
map_item->setVisible(true);
populateConnectionMapPickers();
break;
case EditMode::Connections:
populateConnectionMapPickers(); // !TODO: move to setmap or sumn/ displaymapconnections type ish
ui->label_NumConnections->setText(QString::number(map->connections.length()));
setDiveEmergeControls();
bool controlsEnabled = selected_connection_item != nullptr;
setConnectionEditControlsEnabled(controlsEnabled);
setConnectionEditControlsEnabled(selected_connection_item != nullptr);
if (selected_connection_item) {
onConnectionOffsetChanged(selected_connection_item->connection->offset);
setConnectionMap(selected_connection_item->connection->map_name);
setCurrentConnectionDirection(selected_connection_item->connection->direction);
}
maskNonVisibleConnectionTiles();
}
if (collision_item) {
collision_item->setVisible(false);
}
if (events_group) {
events_group->setVisible(false);
}
setBorderItemsVisible(true, 0.4);
setConnectionItemsVisible(true);
setConnectionsEditable(true);
this->cursorMapTileRect->setSingleTileMode();
this->cursorMapTileRect->setActive(false);
if (this->map) {
this->editGroup.setActiveStack(&this->map->editHistory);
map_item->setEditsEnabled(false); // !TODO
case EditMode::Header:
case EditMode::Encounters:
default:
this->editGroup.setActiveStack(nullptr);
break;
}
if (this->events_group) {
this->events_group->setVisible(this->editMode == EditMode::Events);
}
setMapEditingButtonsEnabled(this->editMode != EditMode::Events);
}
void Editor::setEditingMetatiles() {
this->editMode = EditMode::Metatiles;
setEditorView();
}
void Editor::setEditingCollision() {
this->editMode = EditMode::Collision;
setEditorView();
}
void Editor::setEditingHeader() {
this->editMode = EditMode::Header;
setEditorView();
}
void Editor::setEditingObjects() {
this->editMode = EditMode::Events;
setEditorView();
}
void Editor::setEditingConnections() {
this->editMode = EditMode::Connections;
setEditorView();
}
void Editor::setEditingEncounters() {
//
this->editMode = EditMode::Encounters;
setEditorView();
}
void Editor::setMapEditingButtonsEnabled(bool enabled) {
@ -1048,7 +1037,7 @@ void Editor::onHoveredMapMetatileChanged(const QPoint &pos) {
return;
this->updateCursorRectPos(x, y);
if (map_item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) {
if (this->getEditingLayout()) {
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")
@ -1057,19 +1046,19 @@ void Editor::onHoveredMapMetatileChanged(const QPoint &pos) {
.arg(getMetatileDisplayMessage(metatileId))
.arg(QString::number(zoomLevels[this->scaleIndex], 'g', 2)));
}
else if (map_item->paintingMode == LayoutPixmapItem::PaintMode::EventObjects) {
else if (this->editMode == EditMode::Events) {
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, Scale = %3x")
.arg(x)
.arg(y)
.arg(QString::number(zoomLevels[this->scaleIndex], 'g', 2)));
}
Scripting::cb_BlockHoverChanged(x, y);
}
void Editor::onHoveredMapMetatileCleared() {
this->setCursorRectVisible(false);
if (map_item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles
|| map_item->paintingMode == LayoutPixmapItem::PaintMode::EventObjects) {
if (!map_item->getEditsEnabled()) {
this->ui->statusBar->clearMessage();
}
Scripting::cb_BlockHoverCleared();
@ -1080,7 +1069,7 @@ void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
return;
this->updateCursorRectPos(x, y);
if (map_item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) {
if (this->getEditingLayout()) {
int blockIndex = y * layout->getWidth() + x;
uint16_t collision = layout->blockdata.at(blockIndex).collision;
uint16_t elevation = layout->blockdata.at(blockIndex).elevation;
@ -1095,7 +1084,7 @@ void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
void Editor::onHoveredMapMovementPermissionCleared() {
this->setCursorRectVisible(false);
if (map_item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) {
if (this->getEditingLayout()) {
this->ui->statusBar->clearMessage();
}
Scripting::cb_BlockHoverCleared();
@ -1142,14 +1131,11 @@ bool Editor::setMap(QString map_name) {
this->map = loadedMap;
// remove this
//this->layout = this->map->layout;
setLayout(map->layout->id);
editGroup.addStack(&map->editHistory);
// !TODO: determine which stack is active based on edit mode too since layout will have something different
editGroup.setActiveStack(&map->editHistory);
selected_events->clear();
if (!displayMap()) {
return false;
@ -1163,7 +1149,6 @@ bool Editor::setMap(QString map_name) {
}
bool Editor::setLayout(QString layoutId) {
//
if (layoutId.isEmpty()) return false;
this->layout = this->project->loadLayout(layoutId);
@ -1172,8 +1157,6 @@ bool Editor::setLayout(QString layoutId) {
return false;
}
// !TODO: editGroup addStack
editGroup.addStack(&layout->editHistory);
map_ruler->setMapDimensions(QSize(this->layout->getWidth(), this->layout->getHeight()));
@ -1195,7 +1178,7 @@ bool Editor::setLayout(QString layoutId) {
}
void Editor::onMapStartPaint(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *item) {
if (item->paintingMode != LayoutPixmapItem::PaintMode::Metatiles) {
if (!this->getEditingLayout()) {
return;
}
@ -1208,7 +1191,7 @@ void Editor::onMapStartPaint(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *
}
void Editor::onMapEndPaint(QGraphicsSceneMouseEvent *, LayoutPixmapItem *item) {
if (!(item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles)) {
if (!this->getEditingLayout()) {
return;
}
this->cursorMapTileRect->stopRightClickSelectionAnchor();
@ -1243,13 +1226,13 @@ void Editor::setStraightPathCursorMode(QGraphicsSceneMouseEvent *event) {
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *item) {
// TODO: add event tab object painting tool buttons stuff here
if (item->paintingMode == LayoutPixmapItem::PaintMode::Disabled) {
if (!item->getEditsEnabled()) {
return;
}
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
if (item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) {
if (this->getEditingLayout()) {
if (mapEditAction == EditAction::Paint) {
if (event->buttons() & Qt::RightButton) {
item->updateMetatileSelection(event);
@ -1296,7 +1279,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i
}
item->shift(event);
}
} else if (item->paintingMode == LayoutPixmapItem::PaintMode::EventObjects) {
} else if (this->editMode == EditMode::Events) {
if (objectEditAction == EditAction::Paint && event->type() == QEvent::GraphicsSceneMousePress) {
// Right-clicking while in paint mode will change mode to select.
if (event->buttons() & Qt::RightButton) {
@ -1354,7 +1337,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i
}
void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item) {
if (item->paintingMode != LayoutPixmapItem::PaintMode::Metatiles) {
if (!item->getEditsEnabled()) {
return;
}
@ -1426,7 +1409,6 @@ bool Editor::displayLayout() {
scene->removeItem(this->map_ruler);
}
// !TODO: disassociate these functions from Map
displayMetatileSelector();
displayMapMetatiles();
displayMovementPermissionSelector();
@ -2116,7 +2098,7 @@ void Editor::selectedEventIndexChanged(int index, Event::Group eventGroup) {
}
void Editor::duplicateSelectedEvents() {
if (!selected_events || !selected_events->length() || !map || !current_view || map_item->paintingMode != LayoutPixmapItem::PaintMode::EventObjects)
if (!selected_events || !selected_events->length() || !map || !current_view || this->getEditingLayout())
return;
QList<Event *> selectedEvents;
@ -2288,7 +2270,7 @@ bool Editor::startDetachedProcess(const QString &command, const QString &working
// is clicking on the background instead of an event.
void Editor::objectsView_onMousePress(QMouseEvent *event) {
// make sure we are in object editing mode
if (map_item && map_item->paintingMode != LayoutPixmapItem::PaintMode::EventObjects) {
if (map_item && this->editMode != EditMode::Events) {
return;
}
if (this->objectEditAction == EditAction::Paint && event->buttons() & Qt::RightButton) {

View file

@ -1780,11 +1780,11 @@ void MainWindow::on_mapViewTab_tabBarClicked(int index)
Scripting::cb_MapViewTabChanged(oldIndex, index);
if (index == 0) {
editor->setEditingMap();
editor->setEditingMetatiles();
} else if (index == 1) {
editor->setEditingCollision();
} else if (index == 2) {
editor->setEditingMap();
editor->setEditingMetatiles();
if (projectConfig.getPrefabFilepath().isEmpty() && !projectConfig.getPrefabImportPrompted()) {
// User hasn't set up prefabs and hasn't been prompted before.
// Ask if they'd like to import the default prefabs file.
@ -1802,8 +1802,6 @@ void MainWindow::on_action_Exit_triggered()
void MainWindow::on_mainTabBar_tabBarClicked(int index)
{
//if (!editor->map) return;
int oldIndex = ui->mainTabBar->currentIndex();
ui->mainTabBar->setCurrentIndex(index);
if (index != oldIndex)
@ -1822,6 +1820,8 @@ void MainWindow::on_mainTabBar_tabBarClicked(int index)
clickToolButtonFromEditAction(editor->objectEditAction);
} else if (index == 3) {
editor->setEditingConnections();
} else if (index == 4) {
editor->setEditingEncounters();
}
if (!editor->map) return;
@ -2727,7 +2727,7 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked() {
if (oldMapDimensions != newMapDimensions || oldBorderDimensions != newBorderDimensions) {
layout->setDimensions(newMapDimensions.width(), newMapDimensions.height(), true, true);
layout->setBorderDimensions(newBorderDimensions.width(), newBorderDimensions.height(), true, true);
editor->layout->editHistory.push(new ResizeMap(layout,
editor->layout->editHistory.push(new ResizeLayout(layout,
oldMapDimensions, newMapDimensions,
oldMetatiles, layout->blockdata,
oldBorderDimensions, newBorderDimensions,

View file

@ -1126,7 +1126,7 @@ bool Project::loadBlockdata(Layout *layout) {
QString path = QString("%1/%2").arg(root).arg(layout->blockdata_path);
layout->blockdata = readBlockdata(path);
layout->lastCommitBlocks.blocks = layout->blockdata;
layout->lastCommitBlocks.mapDimensions = QSize(layout->getWidth(), layout->getHeight());
layout->lastCommitBlocks.layoutDimensions = QSize(layout->getWidth(), layout->getHeight());
if (layout->blockdata.count() != layout->getWidth() * layout->getHeight()) {
logWarn(QString("Layout blockdata length %1 does not match dimensions %2x%3 (should be %4). Resizing blockdata.")
@ -1148,7 +1148,7 @@ void Project::setNewMapBlockdata(Map *map) {
map->layout->blockdata.append(block);
}
map->layout->lastCommitBlocks.blocks = map->layout->blockdata;
map->layout->lastCommitBlocks.mapDimensions = QSize(width, height);
map->layout->lastCommitBlocks.layoutDimensions = QSize(width, height);
}
bool Project::loadLayoutBorder(Layout *layout) {

View file

@ -44,8 +44,8 @@ void MainWindow::tryCommitMapChanges(bool commitChanges) {
if (commitChanges) {
Layout *layout = this->editor->layout;
if (layout) {
layout->editHistory.push(new ScriptEditMap(layout,
layout->lastCommitBlocks.mapDimensions, QSize(layout->getWidth(), layout->getHeight()),
layout->editHistory.push(new ScriptEditLayout(layout,
layout->lastCommitBlocks.layoutDimensions, QSize(layout->getWidth(), layout->getHeight()),
layout->lastCommitBlocks.blocks, layout->blockdata,
layout->lastCommitBlocks.borderDimensions, QSize(layout->getBorderWidth(), layout->getBorderHeight()),
layout->lastCommitBlocks.border, layout->border

View file

@ -8,7 +8,7 @@ void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
this->previousPos = pos;
emit this->hoveredMapMovementPermissionChanged(pos.x(), pos.y());
}
if (this->settings->betterCursors && this->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) {
if (this->settings->betterCursors && this->getEditsEnabled()) {
setCursor(this->settings->mapCursor);
}
}
@ -21,7 +21,7 @@ void CollisionPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) {
void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
emit this->hoveredMapMovementPermissionCleared();
if (this->settings->betterCursors && this->paintingMode == LayoutPixmapItem::PaintMode::Metatiles){
if (this->settings->betterCursors && this->getEditsEnabled()){
unsetCursor();
}
this->has_mouse = false;

View file

@ -694,7 +694,7 @@ void LayoutPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
this->metatilePos = pos;
emit this->hoveredMapMetatileChanged(pos);
}
if (this->settings->betterCursors && this->paintingMode != LayoutPixmapItem::PaintMode::Disabled) {
if (this->settings->betterCursors && this->editsEnabled) {
setCursor(this->settings->mapCursor);
}
}
@ -707,7 +707,7 @@ void LayoutPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) {
void LayoutPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
emit this->hoveredMapMetatileCleared();
if (this->settings->betterCursors && this->paintingMode != LayoutPixmapItem::PaintMode::Disabled) {
if (this->settings->betterCursors && this->editsEnabled) {
unsetCursor();
}
this->has_mouse = false;

View file

@ -183,8 +183,8 @@ bool MapImageExporter::historyItemAppliesToFrame(const QUndoCommand *command) {
case CommandId::ID_BucketFillMetatile:
case CommandId::ID_MagicFillMetatile:
case CommandId::ID_ShiftMetatiles:
case CommandId::ID_ResizeMap:
case CommandId::ID_ScriptEditMap:
case CommandId::ID_ResizeLayout:
case CommandId::ID_ScriptEditLayout:
return true;
case CommandId::ID_PaintCollision:
case CommandId::ID_BucketFillCollision:

View file

@ -94,7 +94,6 @@ void NewMapPopup::init() {
ui->spinBox_NewMap_Floor_Number->setValue(settings.floorNumber);
// Connect signals
// !TODO: make sure this doesnt reconnect a million times
connect(ui->spinBox_NewMap_Width, QOverload<int>::of(&QSpinBox::valueChanged), [=](int){checkNewMapDimensions();});
connect(ui->spinBox_NewMap_Height, QOverload<int>::of(&QSpinBox::valueChanged), [=](int){checkNewMapDimensions();});

View file

@ -1101,7 +1101,7 @@ void RegionMapEditor::on_spinBox_RM_LayoutWidth_valueChanged(int value) {
int newHeight = this->region_map->layoutHeight();
QMap<QString, QList<LayoutSquare>> newLayouts = this->region_map->getAllLayouts();
ResizeLayout *commit = new ResizeLayout(this->region_map, oldWidth, oldHeight, newWidth, newHeight, oldLayouts, newLayouts);
ResizeRMLayout *commit = new ResizeRMLayout(this->region_map, oldWidth, oldHeight, newWidth, newHeight, oldLayouts, newLayouts);
this->region_map->editHistory.push(commit);
}
}
@ -1118,7 +1118,7 @@ void RegionMapEditor::on_spinBox_RM_LayoutHeight_valueChanged(int value) {
int newHeight = this->region_map->layoutHeight();
QMap<QString, QList<LayoutSquare>> newLayouts = this->region_map->getAllLayouts();
ResizeLayout *commit = new ResizeLayout(this->region_map, oldWidth, oldHeight, newWidth, newHeight, oldLayouts, newLayouts);
ResizeRMLayout *commit = new ResizeRMLayout(this->region_map, oldWidth, oldHeight, newWidth, newHeight, oldLayouts, newLayouts);
this->region_map->editHistory.push(commit);
}
}