mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-15 13:26:53 -05:00
Merge pull request #719 from GriffinRichards/local-id
Support local ID strings, misc event fixes
This commit is contained in:
@@ -14,7 +14,7 @@ class Map;
|
||||
class Layout;
|
||||
class Blockdata;
|
||||
class Event;
|
||||
class DraggablePixmapItem;
|
||||
class EventPixmapItem;
|
||||
class Editor;
|
||||
|
||||
enum CommandId {
|
||||
|
||||
@@ -19,7 +19,7 @@ class EventFrame;
|
||||
class ObjectFrame;
|
||||
class CloneObjectFrame;
|
||||
class WarpFrame;
|
||||
class DraggablePixmapItem;
|
||||
class EventPixmapItem;
|
||||
|
||||
class Event;
|
||||
class ObjectEvent;
|
||||
@@ -79,9 +79,13 @@ public:
|
||||
None,
|
||||
};
|
||||
|
||||
// all event groups except warps have IDs that start at 1
|
||||
// Normally we refer to events using their index in the list of that group's events.
|
||||
// Object events often get referred to with a special "local ID", which is really just the index + 1.
|
||||
// We use this local ID number in the index spinner for object events instead of the actual index.
|
||||
// This distinction is only really important for object and warp events, because these are normally
|
||||
// the only two groups of events that need to be explicitly referred to.
|
||||
static int getIndexOffset(Event::Group group) {
|
||||
return (group == Event::Group::Warp) ? 0 : 1;
|
||||
return (group == Event::Group::Object) ? 1 : 0;
|
||||
}
|
||||
|
||||
static Event::Group typeToGroup(Event::Type type) {
|
||||
@@ -149,13 +153,13 @@ public:
|
||||
QJsonObject getCustomAttributes() const { return this->customAttributes; }
|
||||
void setCustomAttributes(const QJsonObject &newCustomAttributes) { this->customAttributes = newCustomAttributes; }
|
||||
|
||||
virtual void loadPixmap(Project *project);
|
||||
virtual QPixmap loadPixmap(Project *project);
|
||||
|
||||
void setPixmap(QPixmap newPixmap) { this->pixmap = newPixmap; }
|
||||
QPixmap getPixmap() const { return this->pixmap; }
|
||||
|
||||
void setPixmapItem(DraggablePixmapItem *item);
|
||||
DraggablePixmapItem *getPixmapItem() const { return this->pixmapItem; }
|
||||
void setPixmapItem(EventPixmapItem *item);
|
||||
EventPixmapItem *getPixmapItem() const { return this->pixmapItem; }
|
||||
|
||||
void setUsesDefaultPixmap(bool newUsesDefaultPixmap) { this->usesDefaultPixmap = newUsesDefaultPixmap; }
|
||||
bool getUsesDefaultPixmap() const { return this->usesDefaultPixmap; }
|
||||
@@ -194,7 +198,7 @@ protected:
|
||||
QJsonObject customAttributes;
|
||||
|
||||
QPixmap pixmap;
|
||||
DraggablePixmapItem *pixmapItem = nullptr;
|
||||
EventPixmapItem *pixmapItem = nullptr;
|
||||
|
||||
QPointer<EventFrame> eventFrame;
|
||||
|
||||
@@ -229,7 +233,7 @@ public:
|
||||
|
||||
virtual QSet<QString> getExpectedFields() override;
|
||||
|
||||
virtual void loadPixmap(Project *project) override;
|
||||
virtual QPixmap loadPixmap(Project *project) override;
|
||||
|
||||
void setGfx(QString newGfx) { this->gfx = newGfx; }
|
||||
QString getGfx() const { return this->gfx; }
|
||||
@@ -296,17 +300,17 @@ public:
|
||||
|
||||
virtual QSet<QString> getExpectedFields() override;
|
||||
|
||||
virtual void loadPixmap(Project *project) override;
|
||||
virtual QPixmap loadPixmap(Project *project) override;
|
||||
|
||||
void setTargetMap(QString newTargetMap) { this->targetMap = newTargetMap; }
|
||||
QString getTargetMap() const { return this->targetMap; }
|
||||
|
||||
void setTargetID(int newTargetID) { this->targetID = newTargetID; }
|
||||
int getTargetID() const { return this->targetID; }
|
||||
void setTargetID(QString newTargetID) { this->targetID = newTargetID; }
|
||||
QString getTargetID() const { return this->targetID; }
|
||||
|
||||
private:
|
||||
QString targetMap;
|
||||
int targetID = 0;
|
||||
QString targetID;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -72,6 +72,8 @@ public:
|
||||
void resetEvents();
|
||||
QList<Event *> getEvents(Event::Group group = Event::Group::None) const;
|
||||
Event* getEvent(Event::Group group, int index) const;
|
||||
Event* getEvent(Event::Group group, const QString &idName) const;
|
||||
QStringList getEventIdNames(Event::Group group) const;
|
||||
int getNumEvents(Event::Group group = Event::Group::None) const;
|
||||
QStringList getScriptLabels(Event::Group group = Event::Group::None);
|
||||
QString getScriptsFilePath() const;
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "mapruler.h"
|
||||
#include "encountertablemodel.h"
|
||||
|
||||
class DraggablePixmapItem;
|
||||
class EventPixmapItem;
|
||||
class MetatilesPixmapItem;
|
||||
|
||||
class Editor : public QObject
|
||||
@@ -109,7 +109,7 @@ public:
|
||||
void toggleBorderVisibility(bool visible, bool enableScriptCallback = true);
|
||||
void updateCustomMapAttributes();
|
||||
|
||||
DraggablePixmapItem *addEventPixmapItem(Event *event);
|
||||
EventPixmapItem *addEventPixmapItem(Event *event);
|
||||
void removeEventPixmapItem(Event *event);
|
||||
bool canAddEvents(const QList<Event*> &events);
|
||||
void selectMapEvent(Event *event, bool toggle = false);
|
||||
@@ -118,13 +118,16 @@ public:
|
||||
void duplicateSelectedEvents();
|
||||
void redrawAllEvents();
|
||||
void redrawEvents(const QList<Event*> &events);
|
||||
void redrawEventPixmapItem(DraggablePixmapItem *item);
|
||||
void redrawEventPixmapItem(EventPixmapItem *item);
|
||||
void updateEventPixmapItemZValue(EventPixmapItem *item);
|
||||
qreal getEventOpacity(const Event *event) const;
|
||||
|
||||
void setPlayerViewRect(const QRectF &rect);
|
||||
void updateCursorRectPos(int x, int y);
|
||||
void setCursorRectVisible(bool visible);
|
||||
|
||||
void onEventDragged(Event *event, const QPoint &oldPosition, const QPoint &newPosition);
|
||||
void onEventReleased(Event *event, const QPoint &position);
|
||||
void updateWarpEventWarning(Event *event);
|
||||
void updateWarpEventWarnings();
|
||||
|
||||
@@ -175,10 +178,7 @@ public:
|
||||
static QList<QList<const QImage*>> collisionIcons;
|
||||
|
||||
int eventShiftActionId = 0;
|
||||
|
||||
void eventsView_onMousePress(QMouseEvent *event);
|
||||
|
||||
bool selectingEvent = false;
|
||||
int eventMoveActionId = 0;
|
||||
|
||||
void deleteSelectedEvents();
|
||||
void shouldReselectEvents();
|
||||
@@ -186,6 +186,22 @@ public:
|
||||
static void openInTextEditor(const QString &path, int lineNum = 0);
|
||||
void setCollisionGraphics();
|
||||
|
||||
enum ZValue {
|
||||
MapBorder = -4,
|
||||
MapConnectionInactive = -3,
|
||||
MapConnectionActive = -2,
|
||||
MapConnectionMask = -1,
|
||||
|
||||
// Event pixmaps set their z value to be their y position on the map.
|
||||
// Their y value is int16_t, so we have enough space to allocate the
|
||||
// full range + 1 for the selected event (which should always be on top).
|
||||
EventMinimum = 1,
|
||||
EventMaximum = EventMinimum + 0x10000,
|
||||
|
||||
Ruler,
|
||||
ResizeLayoutPopup
|
||||
};
|
||||
|
||||
public slots:
|
||||
void openMapScripts() const;
|
||||
void openScript(const QString &scriptLabel) const;
|
||||
@@ -253,11 +269,11 @@ private slots:
|
||||
|
||||
signals:
|
||||
void eventsChanged();
|
||||
void openEventMap(Event*);
|
||||
void openConnectedMap(MapConnection*);
|
||||
void wildMonTableOpened(EncounterTableModel*);
|
||||
void wildMonTableClosed();
|
||||
void wildMonTableEdited();
|
||||
void warpEventDoubleClicked(QString, int, Event::Group);
|
||||
void currentMetatilesSelectionChanged();
|
||||
void mapRulerStatusChanged(const QString &);
|
||||
void tilesetUpdated(QString);
|
||||
|
||||
@@ -177,7 +177,7 @@ private slots:
|
||||
void on_action_Save_Project_triggered();
|
||||
bool save(bool currentOnly = false);
|
||||
|
||||
void openWarpMap(QString map_name, int event_id, Event::Group event_group);
|
||||
void openEventMap(Event *event);
|
||||
|
||||
void duplicate();
|
||||
void setClipboardData(poryjson::Json::object);
|
||||
@@ -197,8 +197,7 @@ private slots:
|
||||
void onMapLoaded(Map *map);
|
||||
void onMapRulerStatusChanged(const QString &);
|
||||
void applyUserShortcuts();
|
||||
void markMapEdited();
|
||||
void markSpecificMapEdited(Map*);
|
||||
void markMapEdited(Map*);
|
||||
void markLayoutEdited();
|
||||
|
||||
void on_actionNew_Tileset_triggered();
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
#ifndef DRAGGABLEPIXMAPITEM_H
|
||||
#define DRAGGABLEPIXMAPITEM_H
|
||||
|
||||
#include <QString>
|
||||
#include <QGraphicsItemGroup>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsItemAnimation>
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "events.h"
|
||||
|
||||
class Editor;
|
||||
|
||||
class DraggablePixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DraggablePixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {}
|
||||
|
||||
DraggablePixmapItem(Event *event, Editor *editor) : QGraphicsPixmapItem(event->getPixmap()) {
|
||||
this->event = event;
|
||||
event->setPixmapItem(this);
|
||||
this->editor = editor;
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
Event *event = nullptr;
|
||||
|
||||
void updatePosition();
|
||||
void move(int dx, int dy);
|
||||
void moveTo(const QPoint &pos);
|
||||
void emitPositionChanged();
|
||||
void updatePixmap();
|
||||
|
||||
private:
|
||||
Editor *editor = nullptr;
|
||||
QPoint lastPos;
|
||||
bool active = false;
|
||||
bool releaseSelectionQueued = false;
|
||||
|
||||
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(int x) {
|
||||
event->setX(x);
|
||||
updatePosition();
|
||||
}
|
||||
void set_y(int y) {
|
||||
event->setY(y);
|
||||
updatePosition();
|
||||
}
|
||||
void set_elevation(int z) {
|
||||
event->setElevation(z);
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);
|
||||
};
|
||||
|
||||
#endif // DRAGGABLEPIXMAPITEM_H
|
||||
@@ -57,7 +57,9 @@ protected:
|
||||
bool initialized = false;
|
||||
bool connected = false;
|
||||
|
||||
void populateDropdown(NoScrollComboBox * combo, const QStringList &items);
|
||||
void populateScriptDropdown(NoScrollComboBox * combo, Project * project);
|
||||
void populateIdNameDropdown(NoScrollComboBox * combo, Project * project, const QString &mapName, Event::Group group);
|
||||
|
||||
private:
|
||||
Event *event;
|
||||
@@ -78,6 +80,7 @@ public:
|
||||
virtual void populate(Project *project) override;
|
||||
|
||||
public:
|
||||
QLineEdit *line_edit_local_id;
|
||||
NoScrollComboBox *combo_sprite;
|
||||
NoScrollComboBox *combo_movement;
|
||||
NoScrollSpinBox *spinner_radius_x;
|
||||
@@ -108,12 +111,15 @@ public:
|
||||
virtual void populate(Project *project) override;
|
||||
|
||||
public:
|
||||
QLineEdit *line_edit_local_id;
|
||||
NoScrollComboBox *combo_sprite;
|
||||
NoScrollSpinBox *spinner_target_id;
|
||||
NoScrollComboBox *combo_target_id;
|
||||
NoScrollComboBox *combo_target_map;
|
||||
|
||||
private:
|
||||
CloneObjectEvent *clone;
|
||||
|
||||
void tryInvalidateIdDropdown(Map *map);
|
||||
};
|
||||
|
||||
|
||||
@@ -131,12 +137,15 @@ public:
|
||||
virtual void populate(Project *project) override;
|
||||
|
||||
public:
|
||||
QLineEdit *line_edit_id;
|
||||
NoScrollComboBox *combo_dest_map;
|
||||
NoScrollComboBox *combo_dest_warp;
|
||||
QPushButton *warning;
|
||||
|
||||
private:
|
||||
WarpEvent *warp;
|
||||
|
||||
void tryInvalidateIdDropdown(Map *map);
|
||||
};
|
||||
|
||||
|
||||
@@ -275,6 +284,8 @@ public:
|
||||
|
||||
private:
|
||||
HealLocationEvent *healLocation;
|
||||
|
||||
void tryInvalidateIdDropdown(Map *map);
|
||||
};
|
||||
|
||||
#endif // EVENTRAMES_H
|
||||
|
||||
58
include/ui/eventpixmapitem.h
Normal file
58
include/ui/eventpixmapitem.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef EVENTPIXMAPITEM_H
|
||||
#define EVENTPIXMAPITEM_H
|
||||
|
||||
#include <QString>
|
||||
#include <QGraphicsItemGroup>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsItemAnimation>
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "events.h"
|
||||
|
||||
class Project;
|
||||
|
||||
class EventPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit EventPixmapItem(Event *event);
|
||||
|
||||
void render(Project *project);
|
||||
|
||||
bool isSelected() const { return m_selected; }
|
||||
void setSelected(bool selected) { m_selected = selected; }
|
||||
|
||||
Event * getEvent() const { return m_event; }
|
||||
|
||||
void move(int dx, int dy);
|
||||
void moveTo(int x, int y);
|
||||
void moveTo(const QPoint &pos);
|
||||
|
||||
private:
|
||||
QPixmap m_basePixmap;
|
||||
Event *const m_event = nullptr;
|
||||
QPoint m_lastPos;
|
||||
bool m_active = false;
|
||||
bool m_selected = false;
|
||||
bool m_releaseSelectionQueued = false;
|
||||
|
||||
void updatePixelPosition();
|
||||
|
||||
signals:
|
||||
void xChanged(int x);
|
||||
void yChanged(int y);
|
||||
void posChanged(int x, int y);
|
||||
void rendered(const QPixmap &pixmap);
|
||||
void selected(Event *event, bool toggle);
|
||||
void dragged(Event *event, const QPoint &oldPosition, const QPoint &newPosition);
|
||||
void released(Event *event, const QPoint &position);
|
||||
void doubleClicked(Event *event);
|
||||
|
||||
protected:
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent*) override;
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*) override;
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override;
|
||||
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) override { emit doubleClicked(m_event); }
|
||||
};
|
||||
|
||||
#endif // EVENTPIXMAPITEM_H
|
||||
@@ -45,25 +45,4 @@ protected:
|
||||
virtual void keyPressEvent(QKeyEvent *event) override;
|
||||
};
|
||||
|
||||
class Editor;
|
||||
|
||||
// TODO: This should just be MapView. It makes map-based assumptions, and no other class inherits GraphicsView.
|
||||
class GraphicsView : public QGraphicsView
|
||||
{
|
||||
public:
|
||||
GraphicsView() : QGraphicsView() {}
|
||||
GraphicsView(QWidget *parent) : QGraphicsView(parent) {}
|
||||
|
||||
public:
|
||||
// GraphicsView_Object object;
|
||||
Editor *editor;
|
||||
protected:
|
||||
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent *event) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
virtual void moveEvent(QMoveEvent *event) override;
|
||||
};
|
||||
|
||||
//Q_DECLARE_METATYPE(GraphicsView)
|
||||
|
||||
#endif // GRAPHICSVIEW_H
|
||||
|
||||
@@ -5,13 +5,17 @@
|
||||
#include "graphicsview.h"
|
||||
#include "overlay.h"
|
||||
|
||||
class MapView : public GraphicsView
|
||||
class Editor;
|
||||
|
||||
class MapView : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MapView() : GraphicsView() {}
|
||||
MapView(QWidget *parent) : GraphicsView(parent) {}
|
||||
MapView() : QGraphicsView() {}
|
||||
MapView(QWidget *parent) : QGraphicsView(parent) {}
|
||||
|
||||
Editor *editor;
|
||||
|
||||
Overlay * getOverlay(int layer);
|
||||
void clearOverlayMap();
|
||||
@@ -73,6 +77,7 @@ public:
|
||||
protected:
|
||||
virtual void drawForeground(QPainter *painter, const QRectF &rect) override;
|
||||
virtual void keyPressEvent(QKeyEvent*) override;
|
||||
virtual void moveEvent(QMoveEvent *event) override;
|
||||
private:
|
||||
QMap<int, Overlay*> overlayMap;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user