change Event class design in favor of polymorphism

This commit is contained in:
garak
2022-07-19 17:56:12 -04:00
parent dd66f967f8
commit 582405d68b
34 changed files with 3675 additions and 1661 deletions

View File

@@ -1,123 +0,0 @@
#pragma once
#ifndef EVENT_H
#define EVENT_H
#include <QString>
#include <QPixmap>
#include <QMap>
#include "orderedjson.h"
using OrderedJson = poryjson::Json;
class EventType
{
public:
static QString Object;
static QString CloneObject;
static QString Warp;
static QString Trigger;
static QString WeatherTrigger;
static QString Sign;
static QString HiddenItem;
static QString SecretBase;
static QString HealLocation;
};
class EventGroup
{
public:
static QString Object;
static QString Warp;
static QString Coord;
static QString Bg;
static QString Heal;
};
class DraggablePixmapItem;
class Project;
class Event
{
public:
Event();
Event(const Event&);
Event(QJsonObject, QString);
public:
int x() const {
return getInt("x");
}
int y() const {
return getInt("y");
}
int elevation() {
return getInt("elevation");
}
void setX(int x) {
put("x", x);
}
void setY(int y) {
put("y", y);
}
QString get(const QString &key) const {
return values.value(key);
}
int getInt(const QString &key) const {
return values.value(key).toInt(nullptr, 0);
}
uint16_t getU16(const QString &key) const {
return values.value(key).toUShort(nullptr, 0);
}
int16_t getS16(const QString &key) const {
return values.value(key).toShort(nullptr, 0);
}
void put(QString key, int value) {
put(key, QString("%1").arg(value));
}
void put(QString key, QString value) {
values.insert(key, value);
}
static Event* createNewEvent(QString, QString, Project*);
static Event* createNewObjectEvent(Project*);
static Event* createNewCloneObjectEvent(Project*, QString);
static Event* createNewWarpEvent(QString);
static Event* createNewHealLocationEvent(QString);
static Event* createNewTriggerEvent(Project*);
static Event* createNewWeatherTriggerEvent(Project*);
static Event* createNewSignEvent(Project*);
static Event* createNewHiddenItemEvent(Project*);
static Event* createNewSecretBaseEvent(Project*);
static bool isValidType(QString event_type);
static QString typeToGroup(QString event_type);
static int getIndexOffset(QString group_type);
OrderedJson::object buildObjectEventJSON();
OrderedJson::object buildCloneObjectEventJSON(const QMap<QString, QString> &);
OrderedJson::object buildWarpEventJSON(const QMap<QString, QString> &);
OrderedJson::object buildTriggerEventJSON();
OrderedJson::object buildWeatherTriggerEventJSON();
OrderedJson::object buildSignEventJSON();
OrderedJson::object buildHiddenItemEventJSON();
OrderedJson::object buildSecretBaseEventJSON();
void setPixmapFromSpritesheet(QImage, int, int, bool);
int getPixelX();
int getPixelY();
QSet<QString> getExpectedFields();
void readCustomValues(QJsonObject values);
void addCustomValuesTo(OrderedJson::object *obj);
void setFrameFromMovement(QString);
QMap<QString, QString> values;
QMap<QString, QString> customValues;
QPixmap pixmap;
int spriteWidth;
int spriteHeight;
int frame = 0;
bool hFlip = false;
bool usingSprite;
DraggablePixmapItem *pixmapItem = nullptr;
void setPixmapItem(DraggablePixmapItem *item) { pixmapItem = item; }
};
#endif // EVENT_H

669
include/core/events.h Normal file
View File

@@ -0,0 +1,669 @@
#pragma once
#ifndef EVENTS_H
#define EVENTS_H
#include <QString>
#include <QMap>
#include <QSet>
#include <QPixmap>
#include <QJsonObject>
#include "orderedjson.h"
using OrderedJson = poryjson::Json;
class Project;
class Map;
class EventFrame;
class ObjectFrame;
class CloneObjectFrame;
class WarpFrame;
class DraggablePixmapItem;
class Event;
class ObjectEvent;
class CloneObjectEvent;
class WarpEvent;
class CoordEvent;
class TriggerEvent;
class WeatherTriggerEvent;
class BgEvent;
class SignEvent;
class HiddenItemEvent;
class SecretBaseEvent;
class HealLocationEvent;
class EventVisitor {
public:
virtual void nothing() { }
virtual void visitObject(ObjectEvent *) = 0;
virtual void visitTrigger(TriggerEvent *) = 0;
virtual void visitSign(SignEvent *) = 0;
};
///
/// Event base class -- purely virtual
///
class Event {
public:
virtual ~Event();
// disable copy constructor
Event(const Event &other) = delete;
// disable assignment operator
Event& operator=(const Event &other) = delete;
protected:
Event() {
this->spriteWidth = 16;
this->spriteHeight = 16;
this->usingSprite = false;
}
// public enums & static methods
public:
enum class Type {
Object, CloneObject,
Warp,
Trigger, WeatherTrigger,
Sign, HiddenItem, SecretBase,
HealLocation,
Generic,
None,
};
enum class Group {
Object,
Warp,
Coord,
Bg,
Heal,
None,
};
// all event groups excepts warps have IDs that start at 1
static int getIndexOffset(Event::Group group) {
return (group == Event::Group::Warp) ? 0 : 1;
}
static Event::Group typeToGroup(Event::Type type) {
switch (type) {
case Event::Type::Object:
case Event::Type::CloneObject:
return Event::Group::Object;
case Event::Type::Warp:
return Event::Group::Warp;
case Event::Type::Trigger:
case Event::Type::WeatherTrigger:
return Event::Group::Coord;
case Event::Type::Sign:
case Event::Type::HiddenItem:
case Event::Type::SecretBase:
return Event::Group::Bg;
case Event::Type::HealLocation:
return Event::Group::Heal;
default:
return Event::Group::None;
}
}
// standard public methods
public:
virtual Event *duplicate() = 0;
void setMap(Map *newMap) { this->map = newMap; }
Map *getMap() const { return this->map; }
virtual void accept(EventVisitor *) { }
void setX(int newX) { this->x = newX; }
void setY(int newY) { this->y = newY; }
void setZ(int newZ) { this->elevation = newZ; }
void setElevation(int newElevation) { this->elevation = newElevation; }
int getX() const { return this->x; }
int getY() const { return this->y; }
int getZ() const { return this->elevation; }
int getElevation() const { return this->elevation; }
int getPixelX() const { return (this->x * 16) - qMax(0, (this->spriteWidth - 16) / 2); }
int getPixelY() const { return (this->y * 16) - qMax(0, this->spriteHeight - 16); }
virtual EventFrame *getEventFrame();
virtual EventFrame *createEventFrame() = 0;
void destroyEventFrame();
Event::Group getEventGroup() const { return this->eventGroup; }
Event::Type getEventType() const { return this->eventType; }
virtual OrderedJson::object buildEventJson(Project *project) = 0;
virtual bool loadFromJson(QJsonObject json, Project *project) = 0;
virtual void setDefaultValues(Project *project);
virtual QSet<QString> getExpectedFields() = 0;
void readCustomValues(QJsonObject values);
void addCustomValuesTo(OrderedJson::object *obj);
QMap<QString, QString> getCustomValues() { return this->customValues; }
void setCustomValues(QMap<QString, QString> newCustomValues) { this->customValues = newCustomValues; }
virtual void loadPixmap(Project *project) = 0;
void setPixmap(QPixmap newPixmap) { this->pixmap = newPixmap; }
QPixmap getPixmap() { return this->pixmap; }
void setPixmapItem(DraggablePixmapItem *item) { this->pixmapItem = item; }
DraggablePixmapItem *getPixmapItem() { return this->pixmapItem; }
void setUsingSprite(bool newUsingSprite) { this->usingSprite = newUsingSprite; }
bool getUsingSprite() const { return this->usingSprite; }
void setSpriteWidth(int newSpriteWidth) { this->spriteWidth = newSpriteWidth; }
int getspriteWidth() const { return this->spriteWidth; }
void setSpriteHeight(int newSpriteHeight) { this->spriteHeight = newSpriteHeight; }
int getspriteHeight() const { return this->spriteHeight; }
int getEventIndex();
static QString eventTypeToString(Event::Type type);
static Event::Type eventTypeFromString(QString type);
// pure virtual public methods
public:
// // update spinbox values, etc, combo indices
// virtual void updateFrame(); // setFrameFromMovement, (aka redisplay?)
// virtual void disableFrame(); // setParrent(nullptr), disconnectSignals()
// protected attributes
protected:
Map *map = nullptr;
Type eventType = Event::Type::None;
Group eventGroup = Event::Group::None;
// could be private?
int x = 0;
int y = 0;
int elevation = 0;
int spriteWidth = 16;
int spriteHeight = 16;
bool usingSprite = false;
QMap<QString, QString> customValues;
QPixmap pixmap;
DraggablePixmapItem *pixmapItem = nullptr;
EventFrame *eventFrame = nullptr;
};
///
/// Object Event
///
class ObjectEvent : public Event {
//
// in each derived class constructor, need to createEventFrame, since not
// doing that in base class. make sure to upcall though
public:
ObjectEvent() : Event() {
this->eventGroup = Event::Group::Object;
this->eventType = Event::Type::Object;
}
virtual ~ObjectEvent() {}
virtual Event *duplicate() override;
virtual void accept(EventVisitor *visitor) override { visitor->visitObject(this); }
//virtual EventFrame *getEventFrame() override;
virtual EventFrame *createEventFrame() override;
virtual OrderedJson::object buildEventJson(Project *project) override;
virtual bool loadFromJson(QJsonObject json, Project *project) override;
virtual void setDefaultValues(Project *project) override;
virtual QSet<QString> getExpectedFields() override;
virtual void loadPixmap(Project *project) override;
void setGfx(QString newGfx) { this->gfx = newGfx; }
QString getGfx() { return this->gfx; }
void setMovement(QString newMovement) { this->movement = newMovement; }
QString getMovement() { return this->movement; }
void setRadiusX(int newRadiusX) { this->radiusX = newRadiusX; }
int getRadiusX() { return this->radiusX; }
void setRadiusY(int newRadiusY) { this->radiusY = newRadiusY; }
int getRadiusY() { return this->radiusY; }
void setTrainerType(QString newTrainerType) { this->trainerType = newTrainerType; }
QString getTrainerType() { return this->trainerType; }
void setSightRadiusBerryTreeID(QString newValue) { this->sightRadiusBerryTreeID = newValue; }
QString getSightRadiusBerryTreeID() { return this->sightRadiusBerryTreeID; }
void setScript(QString newScript) { this->script = newScript; }
QString getScript() { return this->script; }
void setFlag(QString newFlag) { this->flag = newFlag; }
QString getFlag() { return this->flag; }
public:
void setFrameFromMovement(QString movement);
void setPixmapFromSpritesheet(QImage, int, int, bool);
protected:
QString gfx;
QString movement;
int radiusX = 0;
int radiusY = 0;
QString trainerType;
QString sightRadiusBerryTreeID; // TODO: int?
QString script;
QString flag;
int frame = 0;
bool hFlip = false;
bool vFlip = false;
};
///
/// Clone Object Event
///
class CloneObjectEvent : public ObjectEvent {
public:
CloneObjectEvent() : ObjectEvent() {
this->eventGroup = Event::Group::Object;
this->eventType = Event::Type::CloneObject;
}
virtual ~CloneObjectEvent() {}
virtual Event *duplicate() override;
virtual EventFrame *createEventFrame() override;
virtual OrderedJson::object buildEventJson(Project *project) override;
virtual bool loadFromJson(QJsonObject json, Project *project) override;
virtual void setDefaultValues(Project *project) override;
virtual QSet<QString> getExpectedFields() override;
virtual void loadPixmap(Project *project) override;
void setTargetMap(QString newTargetMap) { this->targetMap = newTargetMap; }
QString getTargetMap() { return this->targetMap; }
void setTargetID(int newTargetID) { this->targetID = newTargetID; }
int getTargetID() { return this->targetID; }
private:
QString targetMap;
int targetID = 0;
};
///
/// Warp Event
///
class WarpEvent : public Event {
public:
WarpEvent() : Event() {
this->eventGroup = Event::Group::Warp;
this->eventType = Event::Type::Warp;
}
virtual ~WarpEvent() {}
virtual Event *duplicate() override;
virtual EventFrame *createEventFrame() override;
virtual OrderedJson::object buildEventJson(Project *project) override;
virtual bool loadFromJson(QJsonObject json, Project *project) override;
virtual void setDefaultValues(Project *project) override;
virtual QSet<QString> getExpectedFields() override;
virtual void loadPixmap(Project *) override;
void setDestinationMap(QString newDestinationMap) { this->destinationMap = newDestinationMap; }
QString getDestinationMap() { return this->destinationMap; }
void setDestinationWarpID(int newDestinationWarpID) { this->destinationWarpID = newDestinationWarpID; }
int getDestinationWarpID() { return this->destinationWarpID; }
private:
QString destinationMap;
int destinationWarpID = 0;
};
///
/// Coord Event
///
class CoordEvent : public Event {
public:
CoordEvent() : Event() {}
virtual ~CoordEvent() {}
virtual Event *duplicate() override = 0;
virtual EventFrame *createEventFrame() override = 0;
virtual OrderedJson::object buildEventJson(Project *project) override = 0;
virtual bool loadFromJson(QJsonObject json, Project *project) override = 0;
virtual void setDefaultValues(Project *project) override = 0;
virtual QSet<QString> getExpectedFields() override = 0;
virtual void loadPixmap(Project *) override;
};
///
/// Trigger Event
///
class TriggerEvent : public CoordEvent {
public:
TriggerEvent() : CoordEvent() {
this->eventGroup = Event::Group::Coord;
this->eventType = Event::Type::Trigger;
}
virtual ~TriggerEvent() {}
virtual Event *duplicate() override;
virtual void accept(EventVisitor *visitor) override { visitor->visitTrigger(this); }
virtual EventFrame *createEventFrame() override;
virtual OrderedJson::object buildEventJson(Project *project) override;
virtual bool loadFromJson(QJsonObject json, Project *project) override;
virtual void setDefaultValues(Project *project) override;
virtual QSet<QString> getExpectedFields() override;
void setScriptVar(QString newScriptVar) { this->scriptVar = newScriptVar; }
QString getScriptVar() { return this->scriptVar; }
void setScriptVarValue(QString newScriptVarValue) { this->scriptVarValue = newScriptVarValue; }
QString getScriptVarValue() { return this->scriptVarValue; }
void setScriptLabel(QString newScriptLabel) { this->scriptLabel = newScriptLabel; }
QString getScriptLabel() { return this->scriptLabel; }
private:
QString scriptVar;
QString scriptVarValue;
QString scriptLabel;
};
///
/// Weather Trigger Event
///
class WeatherTriggerEvent : public CoordEvent {
public:
WeatherTriggerEvent() : CoordEvent() {
this->eventGroup = Event::Group::Coord;
this->eventType = Event::Type::WeatherTrigger;
}
virtual ~WeatherTriggerEvent() {}
virtual Event *duplicate() override;
virtual EventFrame *createEventFrame() override;
virtual OrderedJson::object buildEventJson(Project *project) override;
virtual bool loadFromJson(QJsonObject json, Project *project) override;
virtual void setDefaultValues(Project *project) override;
virtual QSet<QString> getExpectedFields() override;
void setWeather(QString newWeather) { this->weather = newWeather; }
QString getWeather() { return this->weather; }
private:
QString weather;
};
///
/// BG Event
///
class BGEvent : public Event {
public:
BGEvent() : Event() {
this->eventGroup = Event::Group::Bg;
}
virtual ~BGEvent() {}
virtual Event *duplicate() override = 0;
virtual EventFrame *createEventFrame() override = 0;
virtual OrderedJson::object buildEventJson(Project *project) override = 0;
virtual bool loadFromJson(QJsonObject json, Project *project) override = 0;
virtual void setDefaultValues(Project *project) override = 0;
virtual QSet<QString> getExpectedFields() override = 0;
virtual void loadPixmap(Project *project) override;
};
///
/// Sign Event
///
class SignEvent : public BGEvent {
public:
SignEvent() : BGEvent() {
this->eventType = Event::Type::Sign;
}
virtual ~SignEvent() {}
virtual Event *duplicate() override;
virtual void accept(EventVisitor *visitor) override { visitor->visitSign(this); }
virtual EventFrame *createEventFrame() override;
virtual OrderedJson::object buildEventJson(Project *project) override;
virtual bool loadFromJson(QJsonObject json, Project *project) override;
virtual void setDefaultValues(Project *project) override;
virtual QSet<QString> getExpectedFields() override;
void setFacingDirection(QString newFacingDirection) { this->facingDirection = newFacingDirection; }
QString getFacingDirection() { return this->facingDirection; }
void setScriptLabel(QString newScriptLabel) { this->scriptLabel = newScriptLabel; }
QString getScriptLabel() { return this->scriptLabel; }
private:
QString facingDirection;
QString scriptLabel;
};
///
/// Hidden Item Event
///
class HiddenItemEvent : public BGEvent {
public:
HiddenItemEvent() : BGEvent() {
this->eventType = Event::Type::HiddenItem;
}
virtual ~HiddenItemEvent() {}
virtual Event *duplicate() override;
virtual EventFrame *createEventFrame() override;
virtual OrderedJson::object buildEventJson(Project *project) override;
virtual bool loadFromJson(QJsonObject json, Project *project) override;
virtual void setDefaultValues(Project *project) override;
virtual QSet<QString> getExpectedFields() override;
void setItem(QString newItem) { this->item = newItem; }
QString getItem() { return this->item; }
void setFlag(QString newFlag) { this->flag = newFlag; }
QString getFlag() { return this->flag; }
void setQuantity(int newQuantity) { this->quantity = newQuantity; }
int getQuantity() { return this->quantity; }
void setUnderfoot(bool newUnderfoot) { this->underfoot = newUnderfoot; }
bool getUnderfoot() { return this->underfoot; }
private:
QString item;
QString flag;
// optional
int quantity = 0;
bool underfoot = false;
};
///
/// Secret Base Event
///
class SecretBaseEvent : public BGEvent {
public:
SecretBaseEvent() : BGEvent() {
this->eventType = Event::Type::SecretBase;
}
virtual ~SecretBaseEvent() {}
virtual Event *duplicate() override;
virtual EventFrame *createEventFrame() override;
virtual OrderedJson::object buildEventJson(Project *project) override;
virtual bool loadFromJson(QJsonObject json, Project *project) override;
virtual void setDefaultValues(Project *project) override;
virtual QSet<QString> getExpectedFields() override;
void setBaseID(QString newBaseID) { this->baseID = newBaseID; }
QString getBaseID() { return this->baseID; }
private:
QString baseID;
};
///
/// Heal Location Event
///
class HealLocationEvent : public Event {
public:
HealLocationEvent() : Event() {
this->eventGroup = Event::Group::Heal;
this->eventType = Event::Type::HealLocation;
}
virtual ~HealLocationEvent() {}
virtual Event *duplicate() override { return nullptr; }
virtual EventFrame *createEventFrame() override;
virtual OrderedJson::object buildEventJson(Project *project) override;
virtual bool loadFromJson(QJsonObject, Project *) override { return false; }
virtual void setDefaultValues(Project *project) override;
virtual QSet<QString> getExpectedFields() override { return QSet<QString>(); }
virtual void loadPixmap(Project *project) override;
void setIndex(int newIndex) { this->index = newIndex; }
int getIndex() { return this->index; }
void setLocationName(QString newLocationName) { this->locationName = newLocationName; }
QString getLocationName() { return this->locationName; }
void setIdName(QString newIdName) { this->idName = newIdName; }
QString getIdName() { return this->idName; }
void setRespawnMap(QString newRespawnMap) { this->respawnMap = newRespawnMap; }
QString getRespawnMap() { return this->respawnMap; }
void setRespawnNPC(uint16_t newRespawnNPC) { this->respawnNPC = newRespawnNPC; }
uint16_t getRespawnNPC() { return this->respawnNPC; }
private:
int index = -1;
QString locationName;
QString idName;
QString respawnMap;
uint16_t respawnNPC = 0;
};
///
/// Keeps track of scripts
///
class ScriptTracker : public EventVisitor {
public:
virtual void visitObject(ObjectEvent *object) override { this->scripts << object->getScript(); };
virtual void visitTrigger(TriggerEvent *trigger) override { this->scripts << trigger->getScriptLabel(); };
virtual void visitSign(SignEvent *sign) override { this->scripts << sign->getScriptLabel(); };
QStringList getScripts() { return this->scripts; }
private:
QStringList scripts;
};
#endif // EVENTS_H

View File

@@ -2,10 +2,11 @@
#ifndef HEALLOCATION_H
#define HEALLOCATION_H
#include "event.h"
#include <QString>
#include <QDebug>
class Event;
class HealLocation {
public:
@@ -21,7 +22,7 @@ public:
uint16_t y;
QString respawnMap;
uint16_t respawnNPC;
static HealLocation fromEvent(Event*);
static HealLocation fromEvent(Event *);
};
#endif // HEALLOCATION_H

View File

@@ -6,7 +6,7 @@
#include "mapconnection.h"
#include "maplayout.h"
#include "tileset.h"
#include "event.h"
#include "events.h"
#include <QUndoStack>
#include <QPixmap>
@@ -63,7 +63,10 @@ public:
QPixmap collision_pixmap;
QImage image;
QPixmap pixmap;
QMap<QString, QList<Event*>> events;
QMap<Event::Group, QList<Event *>> events;
QList<Event *> ownedEvents; // for memory management
QList<MapConnection*> connections;
QList<int> metatileLayerOrder;
QList<float> metatileLayerOpacity;
@@ -92,10 +95,10 @@ public:
void floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
void magicFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
QList<Event*> getAllEvents() const;
QStringList eventScriptLabels(const QString &event_group_type = QString()) const;
void removeEvent(Event*);
void addEvent(Event*);
QList<Event *> getAllEvents() const;
QStringList eventScriptLabels(Event::Group group = Event::Group::None) const;
void removeEvent(Event *);
void addEvent(Event *);
QPixmap renderConnection(MapConnection, MapLayout *);
QPixmap renderBorder(bool ignoreCache = false);
void setDimensions(int newWidth, int newHeight, bool setNewBlockdata = true, bool enableScriptCallback = false);
@@ -105,9 +108,6 @@ public:
bool isWithinBounds(int x, int y);
bool isWithinBorderBounds(int x, int y);
// for memory management
QVector<Event *> ownedEvents;
MapPixmapItem *mapItem = nullptr;
void setMapItem(MapPixmapItem *item) { mapItem = item; }

View File

@@ -4,6 +4,7 @@
#include "heallocation.h"
#include "log.h"
#include "orderedjson.h"
#include <QString>
#include <QList>

View File

@@ -158,7 +158,7 @@ public:
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *command) override { return false; }
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return RMCommandId::ID_ClearEntries; }
private:

View File

@@ -96,7 +96,7 @@ public:
DraggablePixmapItem *addMapEvent(Event *event);
void selectMapEvent(DraggablePixmapItem *object);
void selectMapEvent(DraggablePixmapItem *object, bool toggle);
DraggablePixmapItem *addNewEvent(QString event_type);
DraggablePixmapItem *addNewEvent(Event::Type type);
void deleteEvent(Event *);
void updateSelectedEvents();
void duplicateSelectedEvents();
@@ -131,8 +131,7 @@ public:
CurrentSelectedMetatilesPixmapItem *current_metatile_selection_item = nullptr;
MovementPermissionsSelector *movement_permissions_selector_item = nullptr;
QList<DraggablePixmapItem*> *events = nullptr;
QList<DraggablePixmapItem*> *selected_events = nullptr;
QList<DraggablePixmapItem *> *selected_events = nullptr;
QString map_edit_mode = "paint";
QString obj_edit_mode = "select";
@@ -151,7 +150,7 @@ public:
void shouldReselectEvents();
void scaleMapView(int);
void openInTextEditor(const QString &path, int lineNum = 0) const;
bool eventLimitReached(QString event_type);
bool eventLimitReached(Event::Type type);
public slots:
void openMapScripts() const;
@@ -159,6 +158,7 @@ public slots:
void openProjectInTextEditor() const;
void maskNonVisibleConnectionTiles();
void onBorderMetatilesChanged();
void selectedEventIndexChanged(int index, Event::Group eventGroup);
private:
void setConnectionItemsVisible(bool);
@@ -210,7 +210,7 @@ signals:
void selectedObjectsChanged();
void loadMapRequested(QString, QString);
void wildMonDataChanged();
void warpEventDoubleClicked(QString, QString, QString);
void warpEventDoubleClicked(QString, int, Event::Group);
void currentMetatilesSelectionChanged();
void mapRulerStatusChanged(const QString &);
void editedMapData();

View File

@@ -104,8 +104,8 @@ public:
Json(double value); // NUMBER
Json(int value); // NUMBER
Json(bool value); // BOOL
Json(const QString &value); // STRING
Json(QString &&value); // STRING
Json(const QString &value); // STRING
Json(QString &&value); // STRING
Json(const char * value); // STRING
Json(const array &values); // ARRAY
Json(array &&values); // ARRAY

View File

@@ -26,6 +26,8 @@
#include "shortcutseditor.h"
#include "preferenceeditor.h"
namespace Ui {
class MainWindow;
}
@@ -161,7 +163,7 @@ private slots:
void on_action_Reload_Project_triggered();
void on_mapList_activated(const QModelIndex &index);
void on_action_Save_Project_triggered();
void openWarpMap(QString map_name, QString event_id, QString event_group);
void openWarpMap(QString map_name, int event_id, Event::Group event_group);
void duplicate();
void setClipboardData(poryjson::Json::object);
@@ -216,7 +218,7 @@ private slots:
void on_toolButton_deleteObject_clicked();
void addNewEvent(QString);
void addNewEvent(Event::Type type);
void updateSelectedObjects();
void updateObjects();
@@ -265,8 +267,6 @@ private slots:
void eventTabChanged(int index);
void selectedEventIndexChanged(int index);
void on_horizontalSlider_CollisionTransparency_valueChanged(int value);
void on_toolButton_ExpandAll_clicked();
void on_toolButton_CollapseAll_clicked();
@@ -374,7 +374,7 @@ private:
void setTheme(QString);
bool openRecentProject();
void updateTilesetEditor();
QString getEventGroupFromTabWidget(QWidget *tab);
Event::Group getEventGroupFromTabWidget(QWidget *tab);
void closeSupplementaryWindows();
void setWindowDisabled(bool);

View File

@@ -5,7 +5,6 @@
#include "map.h"
#include "blockdata.h"
#include "heallocation.h"
#include "event.h"
#include "wildmoninfo.h"
#include "parseutil.h"
#include "orderedjson.h"
@@ -83,6 +82,8 @@ public:
QMap<QString, qint64> modifiedFileTimestamps;
bool usingAsmTilesets;
const QPixmap entitiesPixmap = QPixmap(":/images/Entities_16x16.png");
void set_root(QString);
void initSignals();
@@ -194,7 +195,7 @@ public:
bool readEventGraphics();
QMap<QString, QMap<QString, QString>> readObjEventGfxInfo();
void setEventPixmap(Event * event, bool forceLoad = false);
void setEventPixmap(Event *event, bool forceLoad = false);
QString fixPalettePath(QString path);
QString fixGraphicPath(QString path);
@@ -204,6 +205,7 @@ public:
QString getMapScriptsFilePath(const QString &mapName) const;
QStringList getEventScriptsFilePaths() const;
QCompleter *getEventScriptLabelCompleter(QStringList additionalScriptLabels);
QStringList getGlobalScriptLabels();
void saveMapHealEvents(Map *map);

View File

@@ -1,7 +1,7 @@
#ifndef CUSTOMATTRIBUTESTABLE_H
#define CUSTOMATTRIBUTESTABLE_H
#include "event.h"
#include "events.h"
#include <QObject>
#include <QFrame>
#include <QTableWidget>

View File

@@ -8,7 +8,7 @@
#include <QtWidgets>
#include "event.h"
#include "events.h"
class Editor;
@@ -17,10 +17,10 @@ class DraggablePixmapItem : public QObject, public QGraphicsPixmapItem {
public:
DraggablePixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {}
DraggablePixmapItem(Event *event_, Editor *editor_) : QGraphicsPixmapItem(event_->pixmap) {
event = event_;
DraggablePixmapItem(Event *event, Editor *editor) : QGraphicsPixmapItem(event->getPixmap()) {
this->event = event;
event->setPixmapItem(this);
editor = editor_;
this->editor = editor;
updatePosition();
}
@@ -37,8 +37,6 @@ public:
void moveTo(const QPoint &pos);
void emitPositionChanged();
void updatePixmap();
void bind(QComboBox *combo, QString key);
void bindToUserData(QComboBox *combo, QString key);
signals:
void positionChanged(Event *event);
@@ -49,25 +47,18 @@ signals:
void onPropertyChanged(QString key, QString value);
public slots:
void set_x(const QString &text) {
event->put("x", text);
void set_x(int x) {
event->setX(x);
updatePosition();
}
void set_y(const QString &text) {
event->put("y", text);
void set_y(int y) {
event->setY(y);
updatePosition();
}
void set_elevation(const QString &text) {
event->put("elevation", text);
void set_elevation(int z) {
event->setElevation(z);
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*);

272
include/ui/eventframes.h Normal file
View File

@@ -0,0 +1,272 @@
#pragma once
#ifndef EVENTRAMES_H
#define EVENTRAMES_H
#include <QtWidgets>
#include "noscrollspinbox.h"
#include "noscrollcombobox.h"
#include "events.h"
class Project;
class EventFrame : public QFrame {
Q_OBJECT
public:
EventFrame(Event *event, QWidget *parent = nullptr)
: QFrame(parent), event(event) { }
virtual void setup();
void initCustomAttributesTable();
virtual void connectSignals();
virtual void initialize();
virtual void populate(Project *project);
virtual void setActive(bool active);
public:
QLabel *label_id;
QVBoxLayout *layout_main;
QSpinBox *spinner_id;
NoScrollSpinBox *spinner_x;
NoScrollSpinBox *spinner_y;
NoScrollSpinBox *spinner_z;
QLabel *label_icon;
QFrame *frame_contents;
QVBoxLayout *layout_contents;
protected:
bool populated = false;
bool initialized = false;
private:
Event *event;
};
class ObjectFrame : public EventFrame {
Q_OBJECT
public:
ObjectFrame(ObjectEvent *object, QWidget *parent = nullptr)
: EventFrame(object, parent), object(object) {}
virtual ~ObjectFrame() {
delete this->scriptCompleter;
}
virtual void setup() override;
virtual void initialize() override;
virtual void connectSignals() override;
virtual void populate(Project *project) override;
public:
NoScrollComboBox *combo_sprite;
NoScrollComboBox *combo_movement;
NoScrollSpinBox *spinner_radius_x;
NoScrollSpinBox *spinner_radius_y;
NoScrollComboBox *combo_script;
NoScrollComboBox *combo_flag;
NoScrollComboBox *combo_trainer_type;
NoScrollComboBox *combo_radius_treeid;
QCheckBox *check_in_connection;
private:
ObjectEvent *object;
QCompleter *scriptCompleter = nullptr;
};
class CloneObjectFrame : public EventFrame {
Q_OBJECT
public:
CloneObjectFrame(CloneObjectEvent *clone, QWidget *parent = nullptr)
: EventFrame(clone, parent), clone(clone) {}
virtual void setup() override;
virtual void initialize() override;
virtual void connectSignals() override;
virtual void populate(Project *project) override;
public:
NoScrollComboBox *combo_sprite;
NoScrollSpinBox *spinner_target_id;
NoScrollComboBox *combo_target_map;
private:
CloneObjectEvent *clone;
};
class WarpFrame : public EventFrame {
Q_OBJECT
public:
WarpFrame(WarpEvent *warp, QWidget *parent = nullptr)
: EventFrame(warp, parent), warp(warp) {}
virtual void setup() override;
virtual void initialize() override;
virtual void connectSignals() override;
virtual void populate(Project *project) override;
public:
NoScrollComboBox *combo_dest_map;
NoScrollSpinBox *spinner_dest_warp;
private:
WarpEvent *warp;
};
class TriggerFrame : public EventFrame {
Q_OBJECT
public:
TriggerFrame(TriggerEvent *trigger, QWidget *parent = nullptr)
: EventFrame(trigger, parent), trigger(trigger) {}
virtual void setup() override;
virtual void initialize() override;
virtual void connectSignals() override;
virtual void populate(Project *project) override;
public:
NoScrollComboBox *combo_script;
NoScrollComboBox *combo_var;
NoScrollComboBox *combo_var_value;
private:
TriggerEvent *trigger;
QCompleter *scriptCompleter = nullptr;
};
class WeatherTriggerFrame : public EventFrame {
Q_OBJECT
public:
WeatherTriggerFrame(WeatherTriggerEvent *weatherTrigger, QWidget *parent = nullptr)
: EventFrame(weatherTrigger, parent), weatherTrigger(weatherTrigger) {}
virtual void setup() override;
virtual void initialize() override;
virtual void connectSignals() override;
virtual void populate(Project *project) override;
public:
NoScrollComboBox *combo_weather;
private:
WeatherTriggerEvent *weatherTrigger;
};
class SignFrame : public EventFrame {
Q_OBJECT
public:
SignFrame(SignEvent *sign, QWidget *parent = nullptr)
: EventFrame(sign, parent), sign(sign) {}
virtual void setup() override;
virtual void initialize() override;
virtual void connectSignals() override;
virtual void populate(Project *project) override;
public:
NoScrollComboBox *combo_facing_dir;
NoScrollComboBox *combo_script;
private:
SignEvent *sign;
QCompleter *scriptCompleter = nullptr;
};
class HiddenItemFrame : public EventFrame {
Q_OBJECT
public:
HiddenItemFrame(HiddenItemEvent *hiddenItem, QWidget *parent = nullptr)
: EventFrame(hiddenItem, parent), hiddenItem(hiddenItem) {}
virtual void setup() override;
virtual void initialize() override;
virtual void connectSignals() override;
virtual void populate(Project *project) override;
public:
NoScrollComboBox *combo_item;
NoScrollComboBox *combo_flag;
NoScrollSpinBox *spinner_quantity;
QCheckBox *check_itemfinder;
private:
HiddenItemEvent *hiddenItem;
};
class SecretBaseFrame : public EventFrame {
Q_OBJECT
public:
SecretBaseFrame(SecretBaseEvent *secretBase, QWidget *parent = nullptr)
: EventFrame(secretBase, parent), secretBase(secretBase) {}
virtual void setup() override;
virtual void initialize() override;
virtual void connectSignals() override;
virtual void populate(Project *project) override;
public:
NoScrollComboBox *combo_base_id;
private:
SecretBaseEvent *secretBase;
};
class HealLocationFrame : public EventFrame {
Q_OBJECT
public:
HealLocationFrame(HealLocationEvent *healLocation, QWidget *parent = nullptr)
: EventFrame(healLocation, parent), healLocation(healLocation) {}
virtual void setup() override;
virtual void initialize() override;
virtual void connectSignals() override;
virtual void populate(Project *project) override;
public:
NoScrollComboBox *combo_respawn_map;
NoScrollSpinBox *spinner_respawn_npc;
private:
HealLocationEvent *healLocation;
};
#endif // EVENTRAMES_H

View File

@@ -1,29 +0,0 @@
#ifndef EVENTPROPERTIESFRAME_H
#define EVENTPROPERTIESFRAME_H
#include "event.h"
#include <QFrame>
namespace Ui {
class EventPropertiesFrame;
}
class EventPropertiesFrame : public QFrame
{
Q_OBJECT
public:
explicit EventPropertiesFrame(Event *event, QWidget *parent = nullptr);
~EventPropertiesFrame();
void paintEvent(QPaintEvent*);
public:
Ui::EventPropertiesFrame *ui;
private:
Event *event;
bool firstShow = true;
};
#endif // EVENTPROPERTIESFRAME_H

View File

@@ -1,7 +1,7 @@
#ifndef NEWEVENTTOOLBUTTON_H
#define NEWEVENTTOOLBUTTON_H
#include "event.h"
#include "events.h"
#include <QToolButton>
class NewEventToolButton : public QToolButton
@@ -9,7 +9,7 @@ class NewEventToolButton : public QToolButton
Q_OBJECT
public:
explicit NewEventToolButton(QWidget *parent = nullptr);
QString getSelectedEventType();
Event::Type getSelectedEventType();
QAction *newObjectAction;
QAction *newCloneObjectAction;
QAction *newWarpAction;
@@ -30,9 +30,9 @@ public slots:
void newHiddenItem();
void newSecretBase();
signals:
void newEventAdded(QString);
void newEventAdded(Event::Type);
private:
QString selectedEventType;
Event::Type selectedEventType;
void init();
};