add methods for updating frame ui

This commit is contained in:
garak 2022-09-29 13:18:46 -04:00
parent 511c6ddb03
commit 00504817db
4 changed files with 83 additions and 33 deletions

View file

@ -84,7 +84,7 @@ public:
None, None,
}; };
// all event groups excepts warps have IDs that start at 1 // all event groups except warps have IDs that start at 1
static int getIndexOffset(Event::Group group) { static int getIndexOffset(Event::Group group) {
return (group == Event::Group::Warp) ? 0 : 1; return (group == Event::Group::Warp) ? 0 : 1;
} }
@ -159,7 +159,7 @@ public:
void setPixmap(QPixmap newPixmap) { this->pixmap = newPixmap; } void setPixmap(QPixmap newPixmap) { this->pixmap = newPixmap; }
QPixmap getPixmap() { return this->pixmap; } QPixmap getPixmap() { return this->pixmap; }
void setPixmapItem(DraggablePixmapItem *item) { this->pixmapItem = item; } void setPixmapItem(DraggablePixmapItem *item);
DraggablePixmapItem *getPixmapItem() { return this->pixmapItem; } DraggablePixmapItem *getPixmapItem() { return this->pixmapItem; }
void setUsingSprite(bool newUsingSprite) { this->usingSprite = newUsingSprite; } void setUsingSprite(bool newUsingSprite) { this->usingSprite = newUsingSprite; }
@ -176,14 +176,6 @@ public:
static QString eventTypeToString(Event::Type type); static QString eventTypeToString(Event::Type type);
static Event::Type eventTypeFromString(QString 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 attributes
protected: protected:
Map *map = nullptr; Map *map = nullptr;
@ -214,10 +206,6 @@ protected:
/// Object Event /// Object Event
/// ///
class ObjectEvent : public 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: public:
ObjectEvent() : Event() { ObjectEvent() : Event() {
this->eventGroup = Event::Group::Object; this->eventGroup = Event::Group::Object;
@ -229,7 +217,6 @@ public:
virtual void accept(EventVisitor *visitor) override { visitor->visitObject(this); } virtual void accept(EventVisitor *visitor) override { visitor->visitObject(this); }
//virtual EventFrame *getEventFrame() override;
virtual EventFrame *createEventFrame() override; virtual EventFrame *createEventFrame() override;
virtual OrderedJson::object buildEventJson(Project *project) override; virtual OrderedJson::object buildEventJson(Project *project) override;
@ -276,7 +263,7 @@ protected:
int radiusX = 0; int radiusX = 0;
int radiusY = 0; int radiusY = 0;
QString trainerType; QString trainerType;
QString sightRadiusBerryTreeID; // TODO: int? QString sightRadiusBerryTreeID;
QString script; QString script;
QString flag; QString flag;

View file

@ -26,6 +26,10 @@ public:
virtual void initialize(); virtual void initialize();
virtual void populate(Project *project); virtual void populate(Project *project);
void invalidateConnections();
void invalidateUi();
void invalidateValues();
virtual void setActive(bool active); virtual void setActive(bool active);
public: public:
@ -48,6 +52,7 @@ public:
protected: protected:
bool populated = false; bool populated = false;
bool initialized = false; bool initialized = false;
bool connected = false;
private: private:
Event *event; Event *event;

View file

@ -17,8 +17,15 @@ EventFrame *Event::getEventFrame() {
} }
void Event::destroyEventFrame() { void Event::destroyEventFrame() {
if (eventFrame) delete eventFrame; if (this->eventFrame) delete this->eventFrame;
eventFrame = nullptr; this->eventFrame = nullptr;
}
void Event::setPixmapItem(DraggablePixmapItem *item) {
this->pixmapItem = item;
if (this->eventFrame) {
this->eventFrame->invalidateConnections();
}
} }
int Event::getEventIndex() { int Event::getEventIndex() {

View file

@ -114,6 +114,8 @@ void EventFrame::initCustomAttributesTable() {
// perhaps connect to object destroyed signal from draggablepixamapitem to signal need reconnect // perhaps connect to object destroyed signal from draggablepixamapitem to signal need reconnect
// ie, mark connections dirty and need redo // ie, mark connections dirty and need redo
void EventFrame::connectSignals() { void EventFrame::connectSignals() {
this->connected = true;
this->spinner_x->disconnect(); this->spinner_x->disconnect();
connect(this->spinner_x, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) { connect(this->spinner_x, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) {
int delta = value - event->getX(); int delta = value - event->getX();
@ -141,8 +143,8 @@ void EventFrame::connectSignals() {
} }
void EventFrame::initialize() { void EventFrame::initialize() {
// this->initialized = true; this->initialized = true;
// TODO: does this signal blocker block spinner signals?
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
this->spinner_x->setValue(this->event->getX()); this->spinner_x->setValue(this->event->getX());
@ -152,14 +154,22 @@ void EventFrame::initialize() {
this->label_icon->setPixmap(this->event->getPixmap()); this->label_icon->setPixmap(this->event->getPixmap());
} }
void EventFrame::populate(Project *project) { void EventFrame::populate(Project *) {
if (this->populated) return;
const QSignalBlocker blocker(this);
this->populated = true; this->populated = true;
} }
// so setProject / populate() doesnt send signals to connections void EventFrame::invalidateConnections() {
this->connected = false;
}
void EventFrame::invalidateUi() {
this->initialized = false;
}
void EventFrame::invalidateValues() {
this->populated = false;
}
void EventFrame::setActive(bool active) { void EventFrame::setActive(bool active) {
this->setEnabled(active); this->setEnabled(active);
this->blockSignals(!active); this->blockSignals(!active);
@ -167,7 +177,6 @@ void EventFrame::setActive(bool active) {
// TODO: spinbox limits
void ObjectFrame::setup() { void ObjectFrame::setup() {
EventFrame::setup(); EventFrame::setup();
@ -191,10 +200,14 @@ void ObjectFrame::setup() {
// movement radii // movement radii
QFormLayout *l_form_radii_xy = new QFormLayout(); QFormLayout *l_form_radii_xy = new QFormLayout();
this->spinner_radius_x = new NoScrollSpinBox(this); this->spinner_radius_x = new NoScrollSpinBox(this);
this->spinner_radius_x->setMinimum(0);
this->spinner_radius_x->setMaximum(255);
this->spinner_radius_x->setToolTip("The maximum number of metatiles this object\n" this->spinner_radius_x->setToolTip("The maximum number of metatiles this object\n"
"is allowed to move left or right during its\n" "is allowed to move left or right during its\n"
"normal movement behavior actions."); "normal movement behavior actions.");
this->spinner_radius_y = new NoScrollSpinBox(this); this->spinner_radius_y = new NoScrollSpinBox(this);
this->spinner_radius_y->setMinimum(0);
this->spinner_radius_y->setMaximum(255);
this->spinner_radius_y->setToolTip("The maximum number of metatiles this object\n" this->spinner_radius_y->setToolTip("The maximum number of metatiles this object\n"
"is allowed to move up or down during its\n" "is allowed to move up or down during its\n"
"normal movement behavior actions."); "normal movement behavior actions.");
@ -250,6 +263,8 @@ void ObjectFrame::setup() {
} }
void ObjectFrame::connectSignals() { void ObjectFrame::connectSignals() {
if (this->connected) return;
EventFrame::connectSignals(); EventFrame::connectSignals();
// sprite update // sprite update
@ -283,7 +298,6 @@ void ObjectFrame::connectSignals() {
}); });
// script // script
// add local event script labels to combo? or
this->combo_script->disconnect(); this->combo_script->disconnect();
connect(this->combo_script, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_script, &QComboBox::currentTextChanged, [this](const QString &text) {
this->object->setScript(text); this->object->setScript(text);
@ -321,7 +335,8 @@ void ObjectFrame::connectSignals() {
// TODO: how often do i really need to call findText() it seems slow // TODO: how often do i really need to call findText() it seems slow
// when the frame has already been initialized, shouldn't need to again // when the frame has already been initialized, shouldn't need to again
void ObjectFrame::initialize() { void ObjectFrame::initialize() {
//if (this->initialized) return; if (this->initialized) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::initialize(); EventFrame::initialize();
@ -364,6 +379,7 @@ void ObjectFrame::initialize() {
void ObjectFrame::populate(Project *project) { void ObjectFrame::populate(Project *project) {
if (this->populated) return; if (this->populated) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::populate(project); EventFrame::populate(project);
@ -374,7 +390,6 @@ void ObjectFrame::populate(Project *project) {
QStringList scriptLabels = this->object->getMap()->eventScriptLabels() + project->getGlobalScriptLabels(); QStringList scriptLabels = this->object->getMap()->eventScriptLabels() + project->getGlobalScriptLabels();
scriptLabels.removeDuplicates(); scriptLabels.removeDuplicates();
// TODO: are there any additional labels?
this->scriptCompleter = new QCompleter(scriptLabels, this); this->scriptCompleter = new QCompleter(scriptLabels, this);
this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive); this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive);
@ -417,6 +432,8 @@ void CloneObjectFrame::setup() {
} }
void CloneObjectFrame::connectSignals() { void CloneObjectFrame::connectSignals() {
if (this->connected) return;
EventFrame::connectSignals(); EventFrame::connectSignals();
// target map // target map
@ -435,7 +452,8 @@ void CloneObjectFrame::connectSignals() {
} }
void CloneObjectFrame::initialize() { void CloneObjectFrame::initialize() {
//if (this->populated) return; if (this->initialized) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::initialize(); EventFrame::initialize();
@ -461,6 +479,7 @@ void CloneObjectFrame::initialize() {
void CloneObjectFrame::populate(Project *project) { void CloneObjectFrame::populate(Project *project) {
if (this->populated) return; if (this->populated) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::populate(project); EventFrame::populate(project);
@ -493,6 +512,8 @@ void WarpFrame::setup() {
} }
void WarpFrame::connectSignals() { void WarpFrame::connectSignals() {
if (this->connected) return;
EventFrame::connectSignals(); EventFrame::connectSignals();
// dest map // dest map
@ -511,7 +532,8 @@ void WarpFrame::connectSignals() {
} }
void WarpFrame::initialize() { void WarpFrame::initialize() {
//if (this->populated) return; if (this->initialized) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::initialize(); EventFrame::initialize();
@ -531,6 +553,7 @@ void WarpFrame::initialize() {
void WarpFrame::populate(Project *project) { void WarpFrame::populate(Project *project) {
if (this->populated) return; if (this->populated) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::populate(project); EventFrame::populate(project);
@ -571,6 +594,8 @@ void TriggerFrame::setup() {
} }
void TriggerFrame::connectSignals() { void TriggerFrame::connectSignals() {
if (this->connected) return;
EventFrame::connectSignals(); EventFrame::connectSignals();
// label // label
@ -596,8 +621,8 @@ void TriggerFrame::connectSignals() {
} }
void TriggerFrame::initialize() { void TriggerFrame::initialize() {
// TODO: make us of this or delete it if (this->initialized) return;
//if (this->populated) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::initialize(); EventFrame::initialize();
@ -620,6 +645,7 @@ void TriggerFrame::initialize() {
void TriggerFrame::populate(Project *project) { void TriggerFrame::populate(Project *project) {
if (this->populated) return; if (this->populated) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::populate(project); EventFrame::populate(project);
@ -656,6 +682,8 @@ void WeatherTriggerFrame::setup() {
} }
void WeatherTriggerFrame::connectSignals() { void WeatherTriggerFrame::connectSignals() {
if (this->connected) return;
EventFrame::connectSignals(); EventFrame::connectSignals();
// weather // weather
@ -667,6 +695,8 @@ void WeatherTriggerFrame::connectSignals() {
} }
void WeatherTriggerFrame::initialize() { void WeatherTriggerFrame::initialize() {
if (this->initialized) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::initialize(); EventFrame::initialize();
@ -683,6 +713,7 @@ void WeatherTriggerFrame::initialize() {
void WeatherTriggerFrame::populate(Project *project) { void WeatherTriggerFrame::populate(Project *project) {
if (this->populated) return; if (this->populated) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::populate(project); EventFrame::populate(project);
@ -717,6 +748,8 @@ void SignFrame::setup() {
} }
void SignFrame::connectSignals() { void SignFrame::connectSignals() {
if (this->connected) return;
EventFrame::connectSignals(); EventFrame::connectSignals();
// facing dir // facing dir
@ -735,6 +768,8 @@ void SignFrame::connectSignals() {
} }
void SignFrame::initialize() { void SignFrame::initialize() {
if (this->initialized) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::initialize(); EventFrame::initialize();
@ -754,6 +789,7 @@ void SignFrame::initialize() {
void SignFrame::populate(Project *project) { void SignFrame::populate(Project *project) {
if (this->populated) return; if (this->populated) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::populate(project); EventFrame::populate(project);
@ -817,6 +853,8 @@ void HiddenItemFrame::setup() {
} }
void HiddenItemFrame::connectSignals() { void HiddenItemFrame::connectSignals() {
if (this->connected) return;
EventFrame::connectSignals(); EventFrame::connectSignals();
// item // item
@ -849,6 +887,8 @@ void HiddenItemFrame::connectSignals() {
} }
void HiddenItemFrame::initialize() { void HiddenItemFrame::initialize() {
if (this->initialized) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::initialize(); EventFrame::initialize();
@ -885,6 +925,7 @@ void HiddenItemFrame::initialize() {
void HiddenItemFrame::populate(Project *project) { void HiddenItemFrame::populate(Project *project) {
if (this->populated) return; if (this->populated) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::populate(project); EventFrame::populate(project);
@ -915,6 +956,8 @@ void SecretBaseFrame::setup() {
} }
void SecretBaseFrame::connectSignals() { void SecretBaseFrame::connectSignals() {
if (this->connected) return;
EventFrame::connectSignals(); EventFrame::connectSignals();
this->combo_base_id->disconnect(); this->combo_base_id->disconnect();
@ -925,6 +968,8 @@ void SecretBaseFrame::connectSignals() {
} }
void SecretBaseFrame::initialize() { void SecretBaseFrame::initialize() {
if (this->initialized) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::initialize(); EventFrame::initialize();
@ -941,6 +986,7 @@ void SecretBaseFrame::initialize() {
void SecretBaseFrame::populate(Project *project) { void SecretBaseFrame::populate(Project *project) {
if (this->populated) return; if (this->populated) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::populate(project); EventFrame::populate(project);
@ -981,6 +1027,8 @@ void HealLocationFrame::setup() {
} }
void HealLocationFrame::connectSignals() { void HealLocationFrame::connectSignals() {
if (this->connected) return;
EventFrame::connectSignals(); EventFrame::connectSignals();
if (projectConfig.getHealLocationRespawnDataEnabled()) { if (projectConfig.getHealLocationRespawnDataEnabled()) {
@ -999,6 +1047,8 @@ void HealLocationFrame::connectSignals() {
} }
void HealLocationFrame::initialize() { void HealLocationFrame::initialize() {
if (this->initialized) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::initialize(); EventFrame::initialize();
@ -1019,6 +1069,7 @@ void HealLocationFrame::initialize() {
void HealLocationFrame::populate(Project *project) { void HealLocationFrame::populate(Project *project) {
if (this->populated) return; if (this->populated) return;
const QSignalBlocker blocker(this); const QSignalBlocker blocker(this);
EventFrame::populate(project); EventFrame::populate(project);