porymap/include/editor.h

273 lines
9.5 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>
2023-02-08 14:31:39 +00:00
#include <QPointer>
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"
2024-08-09 06:29:28 +01:00
#include "divingmappixmapitem.h"
2018-09-27 00:33:08 +01:00
#include "currentselectedmetatilespixmapitem.h"
#include "collisionpixmapitem.h"
#include "layoutpixmapitem.h"
2018-09-27 00:33:08 +01:00
#include "settings.h"
#include "gridsettings.h"
#include "movablerect.h"
#include "cursortilerect.h"
#include "mapruler.h"
2024-08-27 04:53:08 +01:00
#include "encountertablemodel.h"
2018-09-27 00:33:08 +01:00
class DraggablePixmapItem;
class MetatilesPixmapItem;
class Editor : public QObject
{
Q_OBJECT
public:
Editor(Ui::MainWindow* ui);
~Editor();
Editor() = delete;
Editor(const Editor &) = delete;
Editor & operator = (const Editor &) = delete;
2018-09-27 00:33:08 +01:00
public:
Ui::MainWindow* ui;
QObject *parent = nullptr;
2023-01-23 17:19:21 +00:00
QPointer<Project> project = nullptr;
2023-04-08 02:50:46 +01:00
QPointer<Map> map = nullptr;
QPointer<Layout> layout = nullptr;
2023-01-23 17:19:21 +00:00
QUndoGroup editGroup; // Manages the undo history for each map
2018-09-27 00:33:08 +01:00
Settings *settings;
2024-09-27 16:31:55 +01:00
GridSettings gridSettings;
2023-01-23 17:19:21 +00:00
void setProject(Project * project);
2018-09-27 00:33:08 +01:00
void save();
2023-01-23 17:19:21 +00:00
void saveProject();
void saveUiFields();
void saveEncounterTabData();
2023-01-23 17:19:21 +00:00
void closeProject();
bool setMap(QString map_name);
bool setLayout(QString layoutName);
void unsetMap();
2023-01-23 17:19:21 +00:00
Tileset *getCurrentMapPrimaryTileset();
bool displayMap();
bool displayLayout();
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 updateMapGrid();
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 setConnectionsVisibility(bool visible);
2024-08-09 06:29:28 +01:00
void updateDivingMapsVisibility();
2024-08-15 03:22:54 +01:00
void renderDivingConnections();
2024-08-09 06:29:28 +01:00
void addConnection(MapConnection* connection);
void removeConnection(MapConnection* connection);
2023-01-23 17:19:21 +00:00
void addNewWildMonGroup(QWidget *window);
void deleteWildMonGroup();
void configureEncounterJSON(QWidget *);
2024-08-27 04:53:08 +01:00
EncounterTableModel* getCurrentWildMonTable();
2018-09-27 00:33:08 +01:00
void updateDiveMap(QString mapName);
void updateEmergeMap(QString mapName);
2024-08-09 06:29:28 +01:00
void setSelectedConnection(MapConnection *connection);
2023-01-23 17:19:21 +00:00
2018-10-03 01:01:15 +01:00
void updatePrimaryTileset(QString tilesetLabel, bool forceLoad = false);
void updateSecondaryTileset(QString tilesetLabel, bool forceLoad = false);
2022-08-30 17:53:33 +01:00
void toggleBorderVisibility(bool visible, bool enableScriptCallback = true);
void updateCustomMapHeaderValues(QTableWidget *);
2018-09-27 00:33:08 +01:00
DraggablePixmapItem *addMapEvent(Event *event);
2023-01-23 17:19:21 +00:00
bool eventLimitReached(Map *, Event::Type);
void selectMapEvent(DraggablePixmapItem *object, bool toggle = false);
DraggablePixmapItem *addNewEvent(Event::Type type);
2018-09-27 00:33:08 +01:00
void updateSelectedEvents();
2020-07-09 23:31:35 +01:00
void duplicateSelectedEvents();
2018-09-27 00:33:08 +01:00
void redrawObject(DraggablePixmapItem *item);
QList<DraggablePixmapItem *> getObjects();
2023-01-23 17:19:21 +00:00
void updateCursorRectPos(int x, int y);
void setCursorRectVisible(bool visible);
2018-09-27 00:33:08 +01:00
2023-11-07 17:35:31 +00:00
void updateWarpEventWarning(Event *event);
void updateWarpEventWarnings();
2024-07-16 21:26:59 +01:00
QPointer<QGraphicsScene> scene = nullptr;
2018-09-27 00:33:08 +01:00
QGraphicsPixmapItem *current_view = nullptr;
QPointer<LayoutPixmapItem> map_item = nullptr;
2024-08-09 06:29:28 +01:00
QList<QPointer<ConnectionPixmapItem>> connection_items;
QMap<QString, QPointer<DivingMapPixmapItem>> diving_map_items;
QGraphicsPathItem *connection_mask = nullptr;
2024-07-16 21:26:59 +01:00
QPointer<CollisionPixmapItem> collision_item = nullptr;
2018-09-27 00:33:08 +01:00
QGraphicsItemGroup *events_group = nullptr;
2023-01-23 17:19:21 +00:00
2018-09-27 00:33:08 +01:00
QList<QGraphicsPixmapItem*> borderItems;
2024-09-27 16:31:55 +01:00
QGraphicsItemGroup *mapGrid = nullptr;
2023-01-23 17:19:21 +00:00
MapRuler *map_ruler = nullptr;
MovableRect *playerViewRect = nullptr;
CursorTileRect *cursorMapTileRect = nullptr;
2018-09-27 00:33:08 +01:00
2024-07-16 21:26:59 +01:00
QPointer<QGraphicsScene> scene_metatiles = nullptr;
QPointer<QGraphicsScene> scene_current_metatile_selection = nullptr;
QPointer<QGraphicsScene> scene_selected_border_metatiles = nullptr;
QPointer<QGraphicsScene> scene_collision_metatiles = nullptr;
QPointer<MetatileSelector> metatile_selector_item = nullptr;
2018-09-27 00:33:08 +01:00
2024-07-16 21:26:59 +01:00
QPointer<BorderMetatilesPixmapItem> selected_border_metatiles_item = nullptr;
CurrentSelectedMetatilesPixmapItem *current_metatile_selection_item = nullptr;
2024-07-16 21:26:59 +01:00
QPointer<MovementPermissionsSelector> movement_permissions_selector_item = nullptr;
2018-09-27 00:33:08 +01:00
QList<DraggablePixmapItem *> *selected_events = nullptr;
2024-08-15 03:22:54 +01:00
QPointer<ConnectionPixmapItem> selected_connection_item = nullptr;
QPointer<MapConnection> connection_to_select = nullptr;
2018-09-27 00:33:08 +01:00
2023-02-03 18:09:25 +00:00
enum class EditAction { None, Paint, Select, Fill, Shift, Pick, Move };
EditAction mapEditAction = EditAction::Paint;
EditAction objectEditAction = EditAction::Select;
2023-04-08 02:50:46 +01:00
enum class EditMode { None, Disabled, Metatiles, Collision, Header, Events, Connections, Encounters };
EditMode editMode = EditMode::None;
2023-02-05 19:52:40 +00:00
void setEditMode(EditMode mode) { this->editMode = mode; }
EditMode getEditMode() { return this->editMode; }
2023-04-08 02:50:46 +01:00
bool getEditingLayout();
void setEditorView();
void setEditingMetatiles();
2023-02-05 19:52:40 +00:00
void setEditingCollision();
2023-04-08 02:50:46 +01:00
void setEditingHeader();
2023-02-05 19:52:40 +00:00
void setEditingObjects();
void setEditingConnections();
void setEditingEncounters();
void setMapEditingButtonsEnabled(bool enabled);
int scaleIndex = 2;
qreal collisionOpacity = 0.5;
2023-12-06 21:01:02 +00:00
static QList<QList<const QImage*>> collisionIcons;
2018-09-27 00:33:08 +01:00
void objectsView_onMousePress(QMouseEvent *event);
int getBorderDrawDistance(int dimension);
bool selectingEvent = false;
void deleteSelectedEvents();
void shouldReselectEvents();
2020-10-13 11:07:31 +01:00
void scaleMapView(int);
2023-09-01 19:00:09 +01:00
static void openInTextEditor(const QString &path, int lineNum = 0);
bool eventLimitReached(Event::Type type);
2023-12-07 18:45:08 +00:00
void setCollisionGraphics();
2020-11-16 14:35:55 +00:00
public slots:
void openMapScripts() const;
void openScript(const QString &scriptLabel) const;
void openProjectInTextEditor() const;
2020-11-16 14:35:55 +00:00
void maskNonVisibleConnectionTiles();
void onBorderMetatilesChanged();
void selectedEventIndexChanged(int index, Event::Group eventGroup);
2024-09-27 16:31:55 +01:00
void toggleGrid(bool);
2020-11-16 14:35:55 +00:00
2018-09-27 00:33:08 +01:00
private:
2023-12-07 18:45:08 +00:00
const QImage defaultCollisionImgSheet = QImage(":/images/collisions.png");
const QImage collisionPlaceholder = QImage(":/images/collisions_unknown.png");
QPixmap collisionSheetPixmap;
2024-07-16 21:26:59 +01:00
void clearMap();
void clearMetatileSelector();
void clearMovementPermissionSelector();
void clearMapMetatiles();
void clearMapMovementPermissions();
void clearBorderMetatiles();
void clearCurrentMetatilesSelection();
void clearMapEvents();
void clearMapConnections();
void clearConnectionMask();
2024-07-16 21:26:59 +01:00
void clearMapBorder();
void clearMapGrid();
void clearWildMonTables();
2024-07-03 16:34:27 +01:00
void updateBorderVisibility();
2024-08-20 02:31:36 +01:00
void disconnectMapConnection(MapConnection *connection);
2024-08-15 03:22:54 +01:00
QPoint getConnectionOrigin(MapConnection *connection);
2024-08-20 02:31:36 +01:00
void removeConnectionPixmap(MapConnection *connection);
void updateConnectionPixmap(ConnectionPixmapItem *connectionItem);
void displayConnection(MapConnection *connection);
void displayDivingConnection(MapConnection *connection);
2024-08-09 06:29:28 +01:00
void setDivingMapName(QString mapName, QString direction);
2024-08-20 02:31:36 +01:00
void removeDivingMapPixmap(MapConnection *connection);
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);
2023-12-07 18:45:08 +00:00
void setCollisionTabSpinBoxes(uint16_t collision, uint16_t elevation);
2023-09-01 19:00:09 +01:00
static bool startDetachedProcess(const QString &command,
const QString &workingDirectory = QString(),
qint64 *pid = nullptr);
2018-09-27 00:33:08 +01:00
private slots:
void onMapStartPaint(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *item);
void onMapEndPaint(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *item);
void setSmartPathCursorMode(QGraphicsSceneMouseEvent *event);
void setStraightPathCursorMode(QGraphicsSceneMouseEvent *event);
void mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *item);
2018-09-27 00:33:08 +01:00
void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item);
2024-08-20 02:31:36 +01:00
void setSelectedConnectionItem(ConnectionPixmapItem *connectionItem);
2018-09-27 00:33:08 +01:00
void onHoveredMovementPermissionChanged(uint16_t, uint16_t);
void onHoveredMovementPermissionCleared();
void onHoveredMetatileSelectionChanged(uint16_t);
void onHoveredMetatileSelectionCleared();
2020-10-24 12:45:08 +01: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();
2024-08-09 06:29:28 +01:00
void openConnectedMap(MapConnection*);
2024-08-27 04:53:08 +01:00
void wildMonTableOpened(EncounterTableModel*);
void wildMonTableClosed();
void wildMonTableEdited();
void warpEventDoubleClicked(QString, int, Event::Group);
2018-09-27 00:33:08 +01:00
void currentMetatilesSelectionChanged();
void mapRulerStatusChanged(const QString &);
void tilesetUpdated(QString);
2024-09-27 16:31:55 +01:00
void gridToggled(bool);
2018-09-27 00:33:08 +01:00
};
#endif // EDITOR_H