mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-09 01:15:35 -05:00
add EventMove command, fix extra signal call in map border resize
This commit is contained in:
@@ -2,10 +2,13 @@
|
||||
#define EDITCOMMANDS_H
|
||||
|
||||
#include <QUndoCommand>
|
||||
#include <QList>
|
||||
|
||||
class MapPixmapItem;
|
||||
class Map;
|
||||
class Blockdata;
|
||||
class Event;
|
||||
class DraggablePixmapItem;
|
||||
|
||||
enum CommandId {
|
||||
ID_PaintMetatile, // - done
|
||||
@@ -14,10 +17,11 @@ enum CommandId {
|
||||
ID_ShiftMetatiles, // - done
|
||||
ID_ResizeMap, // - done
|
||||
ID_PaintBorder, // - done
|
||||
ID_EventMove, // -
|
||||
ID_EventMove, // - done
|
||||
ID_EventShift, // -
|
||||
ID_EventCreate, // -
|
||||
ID_EventDelete, // -
|
||||
ID_EventSetData, // -
|
||||
ID_EventSetData, // - ?
|
||||
// Tileset editor history commands
|
||||
// Region map editor history commands
|
||||
};
|
||||
@@ -165,4 +169,28 @@ private:
|
||||
Blockdata *oldBorder;
|
||||
};
|
||||
|
||||
|
||||
|
||||
///
|
||||
class EventMove : public QUndoCommand {
|
||||
public:
|
||||
EventMove(QList<Event *> events,
|
||||
int deltaX, int deltaY, unsigned actionId,
|
||||
QUndoCommand *parent = nullptr);
|
||||
~EventMove();
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
bool mergeWith(const QUndoCommand *command) override;
|
||||
int id() const override { return CommandId::ID_EventMove; }
|
||||
|
||||
private:
|
||||
QList<Event *> events;
|
||||
int deltaX;
|
||||
int deltaY;
|
||||
|
||||
unsigned actionId;
|
||||
};
|
||||
|
||||
#endif // EDITCOMMANDS_H
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
static QString HealLocation;
|
||||
};
|
||||
|
||||
class DraggablePixmapItem;
|
||||
class Project;
|
||||
class Event
|
||||
{
|
||||
@@ -97,6 +98,9 @@ public:
|
||||
int frame = 0;
|
||||
bool hFlip = false;
|
||||
bool usingSprite;
|
||||
|
||||
DraggablePixmapItem *pixmapItem = nullptr;
|
||||
void setPixmapItem(DraggablePixmapItem *item) { pixmapItem = item; }
|
||||
};
|
||||
|
||||
#endif // EVENT_H
|
||||
|
||||
102
include/editor.h
102
include/editor.h
@@ -145,6 +145,8 @@ public:
|
||||
|
||||
QUndoGroup editGroup; // Manages the undo history for each map
|
||||
|
||||
bool selectingEvent = false;
|
||||
|
||||
private:
|
||||
void setConnectionItemsVisible(bool);
|
||||
void setBorderItemsVisible(bool, qreal = 1);
|
||||
@@ -204,104 +206,4 @@ signals:
|
||||
void wheelZoom(int delta);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class DraggablePixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DraggablePixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {
|
||||
}
|
||||
Editor *editor = nullptr;
|
||||
Event *event = nullptr;
|
||||
QGraphicsItemAnimation *pos_anim = nullptr;
|
||||
DraggablePixmapItem(Event *event_, Editor *editor_) : QGraphicsPixmapItem(event_->pixmap) {
|
||||
event = event_;
|
||||
editor = editor_;
|
||||
updatePosition();
|
||||
}
|
||||
bool active;
|
||||
int last_x;
|
||||
int last_y;
|
||||
void updatePosition() {
|
||||
int x = event->getPixelX();
|
||||
int y = event->getPixelY();
|
||||
setX(x);
|
||||
setY(y);
|
||||
if (editor->selected_events && editor->selected_events->contains(this)) {
|
||||
setZValue(event->y() + 1);
|
||||
} else {
|
||||
setZValue(event->y());
|
||||
}
|
||||
}
|
||||
void move(int x, int y);
|
||||
void emitPositionChanged() {
|
||||
emit xChanged(event->x());
|
||||
emit yChanged(event->y());
|
||||
emit elevationChanged(event->elevation());
|
||||
}
|
||||
void updatePixmap() {
|
||||
QList<Event*> objects;
|
||||
objects.append(event);
|
||||
event->pixmap = QPixmap();
|
||||
editor->project->loadEventPixmaps(objects);
|
||||
this->updatePosition();
|
||||
editor->redrawObject(this);
|
||||
emit spriteChanged(event->pixmap);
|
||||
}
|
||||
void bind(QComboBox *combo, QString key) {
|
||||
connect(combo, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
|
||||
this, [this, key](QString value){
|
||||
this->event->put(key, value);
|
||||
});
|
||||
connect(this, &DraggablePixmapItem::onPropertyChanged,
|
||||
this, [combo, key](QString key2, QString value){
|
||||
if (key2 == key) {
|
||||
combo->addItem(value);
|
||||
combo->setCurrentText(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
void bindToUserData(QComboBox *combo, QString key) {
|
||||
connect(combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||
this, [this, combo, key](int index) {
|
||||
this->event->put(key, combo->itemData(index).toString());
|
||||
});
|
||||
}
|
||||
|
||||
signals:
|
||||
void positionChanged(Event *event);
|
||||
void xChanged(int);
|
||||
void yChanged(int);
|
||||
void elevationChanged(int);
|
||||
void spriteChanged(QPixmap pixmap);
|
||||
void onPropertyChanged(QString key, QString value);
|
||||
|
||||
public slots:
|
||||
void set_x(const QString &text) {
|
||||
event->put("x", text);
|
||||
updatePosition();
|
||||
}
|
||||
void set_y(const QString &text) {
|
||||
event->put("y", text);
|
||||
updatePosition();
|
||||
}
|
||||
void set_elevation(const QString &text) {
|
||||
event->put("elevation", text);
|
||||
updatePosition();
|
||||
}
|
||||
void set_sprite(const QString &text) {
|
||||
event->put("sprite", text);
|
||||
updatePixmap();
|
||||
}
|
||||
void set_script(const QString &text) {
|
||||
event->put("script_label", text);
|
||||
}
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);
|
||||
};
|
||||
|
||||
#endif // EDITOR_H
|
||||
|
||||
78
include/ui/draggablepixmapitem.h
Normal file
78
include/ui/draggablepixmapitem.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef DRAGGABLEPIXMAPITEM_H
|
||||
#define DRAGGABLEPIXMAPITEM_H
|
||||
|
||||
#include <QString>
|
||||
#include <QGraphicsItemGroup>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsItemAnimation>
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "event.h"
|
||||
|
||||
class Editor;
|
||||
|
||||
class DraggablePixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DraggablePixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {}
|
||||
|
||||
DraggablePixmapItem(Event *event_, Editor *editor_) : QGraphicsPixmapItem(event_->pixmap) {
|
||||
event = event_;
|
||||
event->setPixmapItem(this);
|
||||
editor = editor_;
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
Editor *editor = nullptr;
|
||||
Event *event = nullptr;
|
||||
QGraphicsItemAnimation *pos_anim = nullptr;
|
||||
|
||||
bool active;
|
||||
int last_x;
|
||||
int last_y;
|
||||
|
||||
void updatePosition();
|
||||
void move(int x, int y);
|
||||
void emitPositionChanged();
|
||||
void updatePixmap();
|
||||
void bind(QComboBox *combo, QString key);
|
||||
void bindToUserData(QComboBox *combo, QString key);
|
||||
|
||||
signals:
|
||||
void positionChanged(Event *event);
|
||||
void xChanged(int);
|
||||
void yChanged(int);
|
||||
void elevationChanged(int);
|
||||
void spriteChanged(QPixmap pixmap);
|
||||
void onPropertyChanged(QString key, QString value);
|
||||
|
||||
public slots:
|
||||
void set_x(const QString &text) {
|
||||
event->put("x", text);
|
||||
updatePosition();
|
||||
}
|
||||
void set_y(const QString &text) {
|
||||
event->put("y", text);
|
||||
updatePosition();
|
||||
}
|
||||
void set_elevation(const QString &text) {
|
||||
event->put("elevation", text);
|
||||
updatePosition();
|
||||
}
|
||||
void set_sprite(const QString &text) {
|
||||
event->put("sprite", text);
|
||||
updatePixmap();
|
||||
}
|
||||
void set_script(const QString &text) {
|
||||
event->put("script_label", text);
|
||||
}
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);
|
||||
};
|
||||
|
||||
#endif // DRAGGABLEPIXMAPITEM_H
|
||||
Reference in New Issue
Block a user