porymap/include/editor.h

214 lines
7.9 KiB
C
Raw Normal View History

2020-09-13 23:37:55 +01:00
#pragma once
2018-09-27 00:33:08 +01:00
#ifndef EDITOR_H
#define EDITOR_H
#include <QGraphicsScene>
#include <QGraphicsItemGroup>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsItemAnimation>
#include <QComboBox>
#include <QCheckBox>
#include <QCursor>
2020-07-29 20:51:04 +01:00
#include <QUndoGroup>
2018-09-27 00:33:08 +01:00
#include "mapconnection.h"
#include "metatileselector.h"
#include "movementpermissionsselector.h"
#include "project.h"
#include "ui_mainwindow.h"
#include "bordermetatilespixmapitem.h"
#include "connectionpixmapitem.h"
#include "currentselectedmetatilespixmapitem.h"
#include "collisionpixmapitem.h"
#include "mappixmapitem.h"
#include "settings.h"
#include "movablerect.h"
#include "cursortilerect.h"
#include "mapruler.h"
2018-09-27 00:33:08 +01:00
class DraggablePixmapItem;
class MetatilesPixmapItem;
2021-02-18 00:20:14 +00:00
class Editor : public QObject {
2018-09-27 00:33:08 +01:00
Q_OBJECT
public:
Editor(Ui::MainWindow* ui);
~Editor();
Editor() = delete;
2021-02-18 00:20:14 +00:00
Editor(const Editor&) = delete;
Editor& operator=(const Editor&) = delete;
2018-09-27 00:33:08 +01:00
public:
Ui::MainWindow* ui;
2021-02-18 00:20:14 +00:00
QObject* parent = nullptr;
Project* project = nullptr;
Map* map = nullptr;
Settings* settings;
2018-09-27 00:33:08 +01:00
void saveProject();
void save();
void closeProject();
bool setMap(QString map_name);
void saveUiFields();
void saveEncounterTabData();
bool displayMap();
2018-09-27 00:33:08 +01:00
void displayMetatileSelector();
void displayMapMetatiles();
void displayMapMovementPermissions();
void displayBorderMetatiles();
void displayCurrentMetatilesSelection();
void redrawCurrentMetatilesSelection();
void displayMovementPermissionSelector();
void displayMapEvents();
void displayMapConnections();
void displayMapBorder();
void displayMapGrid();
void displayWildMonTables();
2018-09-27 00:33:08 +01:00
2020-05-03 16:00:56 +01:00
void updateMapBorder();
void updateMapConnections();
2018-09-27 00:33:08 +01:00
void setEditingMap();
void setEditingCollision();
void setEditingObjects();
void setEditingConnections();
void setMapEditingButtonsEnabled(bool enabled);
2018-09-27 00:33:08 +01:00
void setCurrentConnectionDirection(QString curDirection);
void updateCurrentConnectionDirection(QString curDirection);
void setConnectionsVisibility(bool visible);
void updateConnectionOffset(int offset);
void setConnectionMap(QString mapName);
void addNewConnection();
void removeCurrentConnection();
2021-02-18 00:20:14 +00:00
void addNewWildMonGroup(QWidget* window);
void deleteWildMonGroup();
2018-09-27 00:33:08 +01:00
void updateDiveMap(QString mapName);
void updateEmergeMap(QString mapName);
void setSelectedConnectionFromMap(QString mapName);
2018-10-03 01:01:15 +01:00
void updatePrimaryTileset(QString tilesetLabel, bool forceLoad = false);
void updateSecondaryTileset(QString tilesetLabel, bool forceLoad = false);
2018-09-27 00:33:08 +01:00
void toggleBorderVisibility(bool visible);
2021-02-18 00:20:14 +00:00
void updateCustomMapHeaderValues(QTableWidget*);
void configureEncounterJSON(QWidget*);
Tileset* getCurrentMapPrimaryTileset();
DraggablePixmapItem* addMapEvent(Event* event);
void selectMapEvent(DraggablePixmapItem* object);
void selectMapEvent(DraggablePixmapItem* object, bool toggle);
DraggablePixmapItem* addNewEvent(QString event_type);
void deleteEvent(Event*);
2018-09-27 00:33:08 +01:00
void updateSelectedEvents();
2020-07-09 23:31:35 +01:00
void duplicateSelectedEvents();
2021-02-18 00:20:14 +00:00
void redrawObject(DraggablePixmapItem* item);
QList<DraggablePixmapItem*> getObjects();
2018-09-27 00:33:08 +01:00
2021-02-18 00:20:14 +00:00
QGraphicsScene* scene = nullptr;
QGraphicsPixmapItem* current_view = nullptr;
MapPixmapItem* map_item = nullptr;
2018-09-27 00:33:08 +01:00
ConnectionPixmapItem* selected_connection_item = nullptr;
QList<QGraphicsPixmapItem*> connection_items;
QList<ConnectionPixmapItem*> connection_edit_items;
2021-02-18 00:20:14 +00:00
QGraphicsPathItem* connection_mask = nullptr;
CollisionPixmapItem* collision_item = nullptr;
QGraphicsItemGroup* events_group = nullptr;
2018-09-27 00:33:08 +01:00
QList<QGraphicsPixmapItem*> borderItems;
QList<QGraphicsLineItem*> gridLines;
2021-02-18 00:20:14 +00:00
MovableRect* playerViewRect = nullptr;
CursorTileRect* cursorMapTileRect = nullptr;
MapRuler* map_ruler = nullptr;
2018-09-27 00:33:08 +01:00
2021-02-18 00:20:14 +00: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-27 00:33:08 +01:00
2021-02-18 00:20:14 +00:00
BorderMetatilesPixmapItem* selected_border_metatiles_item = nullptr;
CurrentSelectedMetatilesPixmapItem* current_metatile_selection_item = nullptr;
MovementPermissionsSelector* movement_permissions_selector_item = nullptr;
2018-09-27 00:33:08 +01:00
2021-02-18 00:20:14 +00:00
QList<DraggablePixmapItem*>* events = nullptr;
QList<DraggablePixmapItem*>* selected_events = nullptr;
2018-09-27 00:33:08 +01:00
2020-05-18 02:25:28 +01:00
QString map_edit_mode = "paint";
QString obj_edit_mode = "select";
2018-09-27 19:27:57 +01:00
int scale_exp = 0;
double scale_base = sqrt(2); // adjust scale factor with this
qreal collisionOpacity = 0.5;
2018-09-27 00:33:08 +01:00
2021-02-18 00:20:14 +00:00
void objectsView_onMousePress(QMouseEvent* event);
2018-09-27 00:33:08 +01:00
int getBorderDrawDistance(int dimension);
2020-07-29 20:51:04 +01:00
QUndoGroup editGroup; // Manages the undo history for each map
bool selectingEvent = false;
void shouldReselectEvents();
2020-10-13 11:07:31 +01:00
void scaleMapView(int);
2021-02-18 00:20:14 +00:00
void openInTextEditor(const QString& path, int lineNum = 0) const;
2020-11-16 14:35:55 +00:00
public slots:
void openMapScripts() const;
2021-02-18 00:20:14 +00:00
void openScript(const QString& scriptLabel) const;
void openProjectInTextEditor() const;
2020-11-16 14:35:55 +00:00
void maskNonVisibleConnectionTiles();
2018-09-27 00:33:08 +01:00
private:
void setConnectionItemsVisible(bool);
void setBorderItemsVisible(bool, qreal = 1);
void setConnectionEditControlValues(MapConnection*);
void setConnectionEditControlsEnabled(bool);
void createConnectionItem(MapConnection* connection, bool hide);
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);
void updateEncounterFields(EncounterFields newFields);
2018-09-27 00:33:08 +01:00
QString getMovementPermissionText(uint16_t collision, uint16_t elevation);
QString getMetatileDisplayMessage(uint16_t metatileId);
2021-02-18 00:20:14 +00:00
bool eventLimitReached(Map*, QString);
bool startDetachedProcess(const QString& command, const QString& workingDirectory = QString(), qint64* pid = nullptr) const;
2018-09-27 00:33:08 +01:00
private slots:
2021-02-18 00:20:14 +00:00
void onMapStartPaint(QGraphicsSceneMouseEvent* event, MapPixmapItem* item);
void onMapEndPaint(QGraphicsSceneMouseEvent* event, MapPixmapItem* item);
void setSmartPathCursorMode(QGraphicsSceneMouseEvent* event);
void setStraightPathCursorMode(QGraphicsSceneMouseEvent* event);
void mouseEvent_map(QGraphicsSceneMouseEvent* event, MapPixmapItem* item);
void mouseEvent_collision(QGraphicsSceneMouseEvent* event, CollisionPixmapItem* item);
2018-09-27 00:33:08 +01:00
void onConnectionMoved(MapConnection*);
void onConnectionItemSelected(ConnectionPixmapItem* connectionItem);
void onConnectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
void onConnectionDirectionChanged(QString newDirection);
void onBorderMetatilesChanged();
void onHoveredMovementPermissionChanged(uint16_t, uint16_t);
void onHoveredMovementPermissionCleared();
void onHoveredMetatileSelectionChanged(uint16_t);
void onHoveredMetatileSelectionCleared();
2021-02-18 00:20:14 +00:00
void onHoveredMapMetatileChanged(const QPoint& pos);
2018-09-27 00:33:08 +01:00
void onHoveredMapMetatileCleared();
void onHoveredMapMovementPermissionChanged(int, int);
void onHoveredMapMovementPermissionCleared();
void onSelectedMetatilesChanged();
2020-10-13 11:07:31 +01:00
void onWheelZoom(int);
2018-09-27 00:33:08 +01:00
signals:
void objectsChanged();
void selectedObjectsChanged();
void loadMapRequested(QString, QString);
void wildMonDataChanged();
2018-09-27 00:33:08 +01:00
void warpEventDoubleClicked(QString mapName, QString warpNum);
void currentMetatilesSelectionChanged();
2021-02-18 00:20:14 +00:00
void mapRulerStatusChanged(const QString&);
2018-09-27 00:33:08 +01:00
};
#endif // EDITOR_H