mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-12 20:05:55 -05:00
Update script dropdowns when a map's scripts file is edited
This commit is contained in:
@@ -34,15 +34,6 @@ 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
|
||||
///
|
||||
@@ -121,8 +112,6 @@ public:
|
||||
|
||||
void modify();
|
||||
|
||||
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; }
|
||||
@@ -150,6 +139,8 @@ public:
|
||||
|
||||
virtual QSet<QString> getExpectedFields() = 0;
|
||||
|
||||
virtual QStringList getScripts() const { return QStringList(); }
|
||||
|
||||
QJsonObject getCustomAttributes() const { return this->customAttributes; }
|
||||
void setCustomAttributes(const QJsonObject &newCustomAttributes) { this->customAttributes = newCustomAttributes; }
|
||||
|
||||
@@ -222,8 +213,6 @@ public:
|
||||
|
||||
virtual Event *duplicate() const override;
|
||||
|
||||
virtual void accept(EventVisitor *visitor) override { visitor->visitObject(this); }
|
||||
|
||||
virtual EventFrame *createEventFrame() override;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override;
|
||||
@@ -233,6 +222,8 @@ public:
|
||||
|
||||
virtual QSet<QString> getExpectedFields() override;
|
||||
|
||||
virtual QStringList getScripts() const override { return {getScript()}; }
|
||||
|
||||
virtual QPixmap loadPixmap(Project *project) override;
|
||||
|
||||
void setGfx(QString newGfx) { this->gfx = newGfx; }
|
||||
@@ -392,8 +383,6 @@ public:
|
||||
|
||||
virtual Event *duplicate() const override;
|
||||
|
||||
virtual void accept(EventVisitor *visitor) override { visitor->visitTrigger(this); }
|
||||
|
||||
virtual EventFrame *createEventFrame() override;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override;
|
||||
@@ -403,6 +392,8 @@ public:
|
||||
|
||||
virtual QSet<QString> getExpectedFields() override;
|
||||
|
||||
virtual QStringList getScripts() const override { return {getScriptLabel()}; }
|
||||
|
||||
void setScriptVar(QString newScriptVar) { this->scriptVar = newScriptVar; }
|
||||
QString getScriptVar() const { return this->scriptVar; }
|
||||
|
||||
@@ -490,8 +481,6 @@ public:
|
||||
|
||||
virtual Event *duplicate() const override;
|
||||
|
||||
virtual void accept(EventVisitor *visitor) override { visitor->visitSign(this); }
|
||||
|
||||
virtual EventFrame *createEventFrame() override;
|
||||
|
||||
virtual OrderedJson::object buildEventJson(Project *project) override;
|
||||
@@ -501,6 +490,8 @@ public:
|
||||
|
||||
virtual QSet<QString> getExpectedFields() override;
|
||||
|
||||
virtual QStringList getScripts() const override { return {getScriptLabel()}; }
|
||||
|
||||
void setFacingDirection(QString newFacingDirection) { this->facingDirection = newFacingDirection; }
|
||||
QString getFacingDirection() const { return this->facingDirection; }
|
||||
|
||||
@@ -633,21 +624,4 @@ inline uint qHash(const Event::Group &key, uint seed = 0) {
|
||||
return qHash(static_cast<int>(key), seed);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// 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() const { return this->scripts; }
|
||||
|
||||
private:
|
||||
QStringList scripts;
|
||||
};
|
||||
|
||||
|
||||
#endif // EVENTS_H
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <QPixmap>
|
||||
#include <QObject>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <math.h>
|
||||
|
||||
#define DEFAULT_BORDER_WIDTH 2
|
||||
@@ -56,7 +57,7 @@ public:
|
||||
MapHeader* header() const { return m_header; }
|
||||
|
||||
void setSharedEventsMap(const QString &sharedEventsMap) { m_sharedEventsMap = sharedEventsMap; }
|
||||
void setSharedScriptsMap(const QString &sharedScriptsMap) { m_sharedScriptsMap = sharedScriptsMap; }
|
||||
void setSharedScriptsMap(const QString &sharedScriptsMap);
|
||||
|
||||
QString sharedEventsMap() const { return m_sharedEventsMap; }
|
||||
QString sharedScriptsMap() const { return m_sharedScriptsMap; }
|
||||
@@ -75,14 +76,15 @@ public:
|
||||
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;
|
||||
void openScript(QString label);
|
||||
void removeEvent(Event *);
|
||||
void addEvent(Event *);
|
||||
int getIndexOfEvent(Event *) const;
|
||||
bool hasEvent(Event *) const;
|
||||
|
||||
QStringList getScriptLabels(Event::Group group = Event::Group::None);
|
||||
QString getScriptsFilePath() const;
|
||||
void openScript(const QString &label);
|
||||
|
||||
void deleteConnections();
|
||||
QList<MapConnection*> getConnections() const { return m_connections; }
|
||||
MapConnection* getConnection(const QString &direction) const;
|
||||
@@ -108,7 +110,7 @@ private:
|
||||
QString m_sharedEventsMap = "";
|
||||
QString m_sharedScriptsMap = "";
|
||||
|
||||
QStringList m_scriptsFileLabels;
|
||||
QStringList m_scriptLabels;
|
||||
QJsonObject m_customAttributes;
|
||||
|
||||
MapHeader *m_header = nullptr;
|
||||
@@ -131,10 +133,14 @@ private:
|
||||
QList<MapConnection*> m_connections;
|
||||
QSet<MapConnection*> m_ownedConnections;
|
||||
|
||||
QUndoStack *m_editHistory = nullptr;
|
||||
QPointer<QUndoStack> m_editHistory;
|
||||
QPointer<QFileSystemWatcher> m_scriptFileWatcher;
|
||||
|
||||
void invalidateScripts();
|
||||
|
||||
signals:
|
||||
void modified();
|
||||
void scriptsModified();
|
||||
void mapDimensionsChanged(const QSize &size);
|
||||
void openScriptRequested(QString label);
|
||||
void connectionAdded(MapConnection*);
|
||||
|
||||
@@ -56,9 +56,11 @@ protected:
|
||||
bool populated = false;
|
||||
bool initialized = false;
|
||||
bool connected = false;
|
||||
QPointer<Project> project;
|
||||
|
||||
void populateDropdown(NoScrollComboBox * combo, const QStringList &items);
|
||||
void populateScriptDropdown(NoScrollComboBox * combo, Project * project);
|
||||
void populateMapNameDropdown(NoScrollComboBox * combo, Project * project);
|
||||
void populateIdNameDropdown(NoScrollComboBox * combo, Project * project, const QString &mapName, Event::Group group);
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user