porymap/editor.h

260 lines
9.1 KiB
C
Raw Normal View History

2016-09-07 04:50:47 +01:00
#ifndef EDITOR_H
#define EDITOR_H
#include <QGraphicsScene>
#include <QGraphicsItemGroup>
#include <QGraphicsSceneMouseEvent>
2017-11-28 04:46:27 +00:00
#include <QGraphicsItemAnimation>
#include <QComboBox>
2018-03-05 00:20:18 +00:00
#include <QCheckBox>
#include <QCursor>
2016-09-07 04:50:47 +01:00
2018-09-25 01:12:29 +01:00
#include "mapconnection.h"
#include "metatileselector.h"
#include "movementpermissionsselector.h"
2016-09-07 04:50:47 +01:00
#include "project.h"
#include "ui_mainwindow.h"
2018-09-27 00:30:05 +01:00
#include "bordermetatilespixmapitem.h"
#include "connectionpixmapitem.h"
#include "currentselectedmetatilespixmapitem.h"
#include "collisionpixmapitem.h"
#include "mappixmapitem.h"
#include "settings.h"
2016-09-07 04:50:47 +01:00
2017-11-28 04:46:27 +00:00
class DraggablePixmapItem;
class MetatilesPixmapItem;
2017-11-28 04:46:27 +00:00
class Editor : public QObject
{
Q_OBJECT
public:
Editor(Ui::MainWindow* ui);
2017-11-28 04:46:27 +00:00
public:
Ui::MainWindow* ui;
2018-09-15 00:37:36 +01:00
QObject *parent = nullptr;
Project *project = nullptr;
Map *map = nullptr;
2018-09-27 00:30:05 +01:00
Settings *settings;
2017-11-28 04:46:27 +00:00
void saveProject();
void save();
void undo();
void redo();
void setMap(QString map_name);
void displayMap();
void displayMetatileSelector();
2018-09-27 00:30:05 +01:00
void displayMapMetatiles();
void displayMapMovementPermissions();
2018-07-07 23:32:54 +01:00
void displayBorderMetatiles();
void displayCurrentMetatilesSelection();
void redrawCurrentMetatilesSelection();
void displayMovementPermissionSelector();
2017-11-28 04:46:27 +00:00
void displayElevationMetatiles();
void displayMapEvents();
2017-11-28 04:46:27 +00:00
void displayMapConnections();
void displayMapBorder();
2018-03-05 00:07:52 +00:00
void displayMapGrid();
2017-11-28 04:46:27 +00:00
void setEditingMap();
void setEditingCollision();
void setEditingObjects();
void setEditingConnections();
void setCurrentConnectionDirection(QString curDirection);
void updateCurrentConnectionDirection(QString curDirection);
void setConnectionsVisibility(bool visible);
void updateConnectionOffset(int offset);
void setConnectionMap(QString mapName);
void addNewConnection();
void removeCurrentConnection();
2018-03-10 19:25:34 +00:00
void updateDiveMap(QString mapName);
void updateEmergeMap(QString mapName);
void setSelectedConnectionFromMap(QString mapName);
2018-07-08 17:17:43 +01:00
void updatePrimaryTileset(QString tilesetLabel);
void updateSecondaryTileset(QString tilesetLabel);
void toggleBorderVisibility(bool visible);
2017-11-28 04:46:27 +00:00
DraggablePixmapItem *addMapEvent(Event *event);
void selectMapEvent(DraggablePixmapItem *object);
void selectMapEvent(DraggablePixmapItem *object, bool toggle);
2017-11-28 04:46:27 +00:00
DraggablePixmapItem *addNewEvent(QString event_type);
2018-07-07 16:58:25 +01:00
Event* createNewEvent(QString event_type);
2017-11-28 04:46:27 +00:00
void deleteEvent(Event *);
void updateSelectedEvents();
2017-11-28 04:46:27 +00:00
void redrawObject(DraggablePixmapItem *item);
QList<DraggablePixmapItem *> *getObjects();
2018-09-15 00:37:36 +01:00
QGraphicsScene *scene = nullptr;
QGraphicsPixmapItem *current_view = nullptr;
MapPixmapItem *map_item = nullptr;
ConnectionPixmapItem* selected_connection_item = nullptr;
2018-07-08 17:17:43 +01:00
QList<QGraphicsPixmapItem*> connection_items;
QList<ConnectionPixmapItem*> connection_edit_items;
2018-09-15 00:37:36 +01:00
CollisionPixmapItem *collision_item = nullptr;
QGraphicsItemGroup *events_group = nullptr;
QList<QGraphicsPixmapItem*> borderItems;
2018-07-08 17:17:43 +01:00
QList<QGraphicsLineItem*> gridLines;
2017-11-28 04:46:27 +00:00
2018-09-15 00:37:36 +01:00
QGraphicsScene *scene_metatiles = nullptr;
QGraphicsScene *scene_current_metatile_selection = nullptr;
QGraphicsScene *scene_selected_border_metatiles = nullptr;
QGraphicsScene *scene_collision_metatiles = nullptr;
QGraphicsScene *scene_elevation_metatiles = nullptr;
MetatileSelector *metatile_selector_item = nullptr;
2018-09-15 00:37:36 +01:00
BorderMetatilesPixmapItem *selected_border_metatiles_item = nullptr;
CurrentSelectedMetatilesPixmapItem *scene_current_metatile_selection_item = nullptr;
MovementPermissionsSelector *movement_permissions_selector_item = nullptr;
2017-11-28 04:46:27 +00:00
2018-09-15 00:37:36 +01:00
QList<DraggablePixmapItem*> *events = nullptr;
QList<DraggablePixmapItem*> *selected_events = nullptr;
2017-11-28 04:46:27 +00:00
QString map_edit_mode;
QString prev_edit_mode;
2017-11-28 04:46:27 +00:00
void objectsView_onMousePress(QMouseEvent *event);
void objectsView_onMouseMove(QMouseEvent *event);
void objectsView_onMouseRelease(QMouseEvent *event);
private:
void setConnectionItemsVisible(bool);
void setBorderItemsVisible(bool, qreal = 1);
void setConnectionEditControlValues(MapConnection*);
void setConnectionEditControlsEnabled(bool);
void createConnectionItem(MapConnection* connection, bool hide);
2018-03-10 19:25:34 +00:00
void populateConnectionMapPickers();
void setDiveEmergeControls();
void updateDiveEmergeMap(QString mapName, QString direction);
void onConnectionOffsetChanged(int newOffset);
void removeMirroredConnection(MapConnection*);
void updateMirroredConnectionOffset(MapConnection*);
void updateMirroredConnectionDirection(MapConnection*, QString);
void updateMirroredConnectionMap(MapConnection*, QString);
void updateMirroredConnection(MapConnection*, QString, QString, bool isDelete = false);
2018-07-07 16:58:25 +01:00
Event* createNewObjectEvent();
Event* createNewWarpEvent();
2018-09-12 01:37:36 +01:00
Event* createNewHealLocationEvent();
2018-07-07 16:58:25 +01:00
Event* createNewCoordScriptEvent();
Event* createNewCoordWeatherEvent();
Event* createNewSignEvent();
Event* createNewHiddenItemEvent();
Event* createNewSecretBaseEvent();
QString getMovementPermissionText(uint16_t collision, uint16_t elevation);
2017-11-28 04:46:27 +00:00
private slots:
void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item);
void onConnectionMoved(MapConnection*);
void onConnectionItemSelected(ConnectionPixmapItem* connectionItem);
void onConnectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
void onConnectionDirectionChanged(QString newDirection);
2018-07-07 23:32:54 +01:00
void onBorderMetatilesChanged();
void onHoveredMovementPermissionChanged(uint16_t, uint16_t);
void onHoveredMovementPermissionCleared();
void onHoveredMetatileSelectionChanged(uint16_t);
void onHoveredMetatileSelectionCleared();
void onHoveredMapMetatileChanged(int, int);
void onHoveredMapMetatileCleared();
void onHoveredMapMovementPermissionChanged(int, int);
void onHoveredMapMovementPermissionCleared();
void onSelectedMetatilesChanged();
2017-11-28 04:46:27 +00:00
signals:
void objectsChanged();
void selectedObjectsChanged();
void loadMapRequested(QString, QString);
2018-07-08 17:17:43 +01:00
void tilesetChanged(QString);
void warpEventDoubleClicked(QString mapName, QString warpNum);
void currentMetatilesSelectionChanged();
2017-11-28 04:46:27 +00:00
};
class DraggablePixmapItem : public QObject, public QGraphicsPixmapItem {
Q_OBJECT
2016-09-07 04:50:47 +01:00
public:
DraggablePixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {
}
2018-09-15 00:37:36 +01:00
Editor *editor = nullptr;
Event *event = nullptr;
QGraphicsItemAnimation *pos_anim = nullptr;
DraggablePixmapItem(Event *event_, Editor *editor_) : QGraphicsPixmapItem(event_->pixmap) {
2016-09-07 04:50:47 +01:00
event = event_;
editor = editor_;
2017-11-28 04:46:27 +00:00
updatePosition();
2016-09-07 04:50:47 +01:00
}
bool active;
int last_x;
int last_y;
2017-11-28 04:46:27 +00:00
void updatePosition() {
int x = event->getPixelX();
int y = event->getPixelY();
2016-09-07 04:50:47 +01:00
setX(x);
setY(y);
setZValue(event->y());
}
2017-11-28 04:46:27 +00:00
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();
2017-11-28 04:46:27 +00:00
editor->redrawObject(this);
emit spriteChanged(event->pixmap);
}
void bind(QComboBox *combo, QString key) {
connect(combo, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
2017-11-28 04:46:27 +00:00
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);
}
});
}
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);
}
2016-09-07 04:50:47 +01:00
protected:
void mousePressEvent(QGraphicsSceneMouseEvent*);
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);
2016-09-07 04:50:47 +01:00
};
#endif // EDITOR_H