From cb6d1a42205950c83c06b55886b3ff87a8085a70 Mon Sep 17 00:00:00 2001 From: garak Date: Wed, 28 Sep 2022 00:21:01 -0400 Subject: [PATCH] indicate map edited when event data is modified --- include/core/events.h | 2 ++ include/core/map.h | 3 +++ src/core/events.cpp | 4 ++++ src/core/map.cpp | 8 ++++++++ src/mainwindow.cpp | 3 +++ src/ui/eventframes.cpp | 35 +++++++++++++++++++++++++++++++++-- 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/include/core/events.h b/include/core/events.h index 9998d630..ef3b6df4 100644 --- a/include/core/events.h +++ b/include/core/events.h @@ -119,6 +119,8 @@ public: void setMap(Map *newMap) { this->map = newMap; } Map *getMap() const { return this->map; } + void modify(); + virtual void accept(EventVisitor *) { } void setX(int newX) { this->x = newX; } diff --git a/include/core/map.h b/include/core/map.h index f9ab2319..2b10e6cf 100644 --- a/include/core/map.h +++ b/include/core/map.h @@ -119,6 +119,8 @@ public: void setBorderItem(BorderMetatilesPixmapItem *item) { borderItem = item; } QUndoStack editHistory; + void modify(); + void clean(); private: void setNewDimensionsBlockdata(int newWidth, int newHeight); @@ -126,6 +128,7 @@ private: signals: void mapChanged(Map *map); + void modified(); void mapDimensionsChanged(const QSize &size); void mapNeedsRedrawing(); void openScriptRequested(QString label); diff --git a/src/core/events.cpp b/src/core/events.cpp index 07617e50..01e78599 100644 --- a/src/core/events.cpp +++ b/src/core/events.cpp @@ -49,6 +49,10 @@ void Event::addCustomValuesTo(OrderedJson::object *obj) { } } +void Event::modify() { + this->map->modify(); +} + QString Event::eventTypeToString(Event::Type type) { switch (type) { case Event::Type::Object: diff --git a/src/core/map.cpp b/src/core/map.cpp index 2e1a2df0..e12793b8 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -515,6 +515,14 @@ void Map::addEvent(Event *event) { if (!ownedEvents.contains(event)) ownedEvents.append(event); } +void Map::modify() { + emit modified(); +} + +void Map::clean() { + this->hasUnsavedDataChanges = false; +} + bool Map::hasUnsavedChanges() { return !editHistory.isClean() || hasUnsavedDataChanges || !isPersistedToFile; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6ed715a9..6ad5b79e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -671,6 +671,7 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) { connect(editor->map, &Map::mapChanged, this, &MainWindow::onMapChanged); connect(editor->map, &Map::mapNeedsRedrawing, this, &MainWindow::onMapNeedsRedrawing); + connect(editor->map, &Map::modified, [this](){ this->markMapEdited(); }); setRecentMap(map_name); updateMapList(); @@ -1452,6 +1453,7 @@ void MainWindow::updateMapList() { void MainWindow::on_action_Save_Project_triggered() { editor->saveProject(); updateMapList(); + showWindowTitle(); } void MainWindow::duplicate() { @@ -1694,6 +1696,7 @@ void MainWindow::paste() { void MainWindow::on_action_Save_triggered() { editor->save(); updateMapList(); + showWindowTitle(); } void MainWindow::on_mapViewTab_tabBarClicked(int index) diff --git a/src/ui/eventframes.cpp b/src/ui/eventframes.cpp index 0165601a..3da845e5 100644 --- a/src/ui/eventframes.cpp +++ b/src/ui/eventframes.cpp @@ -115,7 +115,9 @@ void EventFrame::connectSignals() { this->spinner_x->disconnect(); connect(this->spinner_x, QOverload::of(&QSpinBox::valueChanged), [this](int value) { int delta = value - event->getX(); - if (delta) this->event->getMap()->editHistory.push(new EventMove(QList() << this->event, delta, 0, this->spinner_x->getActionId())); + if (delta) { + this->event->getMap()->editHistory.push(new EventMove(QList() << this->event, delta, 0, this->spinner_x->getActionId())); + } }); // TODO: make sure item is always existing here!, will need to reconnect this when item is deleted? is item ever deleted? connect(this->event->getPixmapItem(), &DraggablePixmapItem::xChanged, this->spinner_x, &NoScrollSpinBox::setValue); @@ -123,7 +125,9 @@ void EventFrame::connectSignals() { this->spinner_y->disconnect(); connect(this->spinner_y, QOverload::of(&QSpinBox::valueChanged), [this](int value) { int delta = value - event->getY(); - if (delta) this->event->getMap()->editHistory.push(new EventMove(QList() << this->event, 0, delta, this->spinner_y->getActionId())); + if (delta) { + this->event->getMap()->editHistory.push(new EventMove(QList() << this->event, 0, delta, this->spinner_y->getActionId())); + } }); connect(this->event->getPixmapItem(), &DraggablePixmapItem::yChanged, this->spinner_y, &NoScrollSpinBox::setValue); @@ -131,6 +135,7 @@ void EventFrame::connectSignals() { this->spinner_z->disconnect(); connect(this->spinner_z, QOverload::of(&QSpinBox::valueChanged), [this](int value) { this->event->setZ(value); + this->event->modify(); }); } @@ -249,6 +254,7 @@ void ObjectFrame::connectSignals() { connect(this->combo_sprite, &QComboBox::currentTextChanged, [this](const QString &text) { this->object->setGfx(text); this->object->getPixmapItem()->updatePixmap(); + this->object->modify(); }); connect(this->object->getPixmapItem(), &DraggablePixmapItem::spriteChanged, this->label_icon, &QLabel::setPixmap); @@ -257,17 +263,20 @@ void ObjectFrame::connectSignals() { connect(this->combo_movement, &QComboBox::currentTextChanged, [this](const QString &text) { this->object->setMovement(text); this->object->getPixmapItem()->updatePixmap(); + this->object->modify(); }); // radii this->spinner_radius_x->disconnect(); connect(this->spinner_radius_x, QOverload::of(&QSpinBox::valueChanged), [this](int value) { this->object->setRadiusX(value); + this->object->modify(); }); this->spinner_radius_y->disconnect(); connect(this->spinner_radius_y, QOverload::of(&QSpinBox::valueChanged), [this](int value) { this->object->setRadiusY(value); + this->object->modify(); }); // script @@ -275,29 +284,34 @@ void ObjectFrame::connectSignals() { this->combo_script->disconnect(); connect(this->combo_script, &QComboBox::currentTextChanged, [this](const QString &text) { this->object->setScript(text); + this->object->modify(); }); this->button_script->disconnect(); connect(this->button_script, &QToolButton::clicked, [this]() { this->object->getMap()->openScript(this->combo_script->currentText()); + this->object->modify(); }); // flag this->combo_flag->disconnect(); connect(this->combo_flag, &QComboBox::currentTextChanged, [this](const QString &text) { this->object->setFlag(text); + this->object->modify(); }); // trainer type this->combo_trainer_type->disconnect(); connect(this->combo_trainer_type, &QComboBox::currentTextChanged, [this](const QString &text) { this->object->setTrainerType(text); + this->object->modify(); }); // sight berry this->combo_radius_treeid->disconnect(); connect(this->combo_radius_treeid, &QComboBox::currentTextChanged, [this](const QString &text) { this->object->setSightRadiusBerryTreeID(text); + this->object->modify(); }); } @@ -404,12 +418,14 @@ void CloneObjectFrame::connectSignals() { this->combo_target_map->disconnect(); connect(this->combo_target_map, &QComboBox::currentTextChanged, [this](const QString &text) { this->clone->setTargetMap(text); + this->clone->modify(); }); // target id this->spinner_target_id->disconnect(); connect(this->spinner_target_id, QOverload::of(&QSpinBox::valueChanged), [this](int value) { this->clone->setTargetID(value); + this->clone->modify(); }); } @@ -476,12 +492,14 @@ void WarpFrame::connectSignals() { this->combo_dest_map->disconnect(); connect(this->combo_dest_map, &QComboBox::currentTextChanged, [this](const QString &text) { this->warp->setDestinationMap(text); + this->warp->modify(); }); // dest id this->spinner_dest_warp->disconnect(); connect(this->spinner_dest_warp, QOverload::of(&QSpinBox::valueChanged), [this](int value) { this->warp->setDestinationWarpID(value); + this->warp->modify(); }); } @@ -550,18 +568,21 @@ void TriggerFrame::connectSignals() { this->combo_script->disconnect(); connect(this->combo_script, &QComboBox::currentTextChanged, [this](const QString &text) { this->trigger->setScriptLabel(text); + this->trigger->modify(); }); // var this->combo_var->disconnect(); connect(this->combo_var, &QComboBox::currentTextChanged, [this](const QString &text) { this->trigger->setScriptVar(text); + this->trigger->modify(); }); // value this->combo_var_value->disconnect(); connect(this->combo_var_value, &QComboBox::currentTextChanged, [this](const QString &text) { this->trigger->setScriptVarValue(text); + this->trigger->modify(); }); } @@ -630,6 +651,7 @@ void WeatherTriggerFrame::connectSignals() { this->combo_weather->disconnect(); connect(this->combo_weather, &QComboBox::currentTextChanged, [this](const QString &text) { this->weatherTrigger->setWeather(text); + this->weatherTrigger->modify(); }); } @@ -688,12 +710,14 @@ void SignFrame::connectSignals() { this->combo_facing_dir->disconnect(); connect(this->combo_facing_dir, &QComboBox::currentTextChanged, [this](const QString &text) { this->sign->setFacingDirection(text); + this->sign->modify(); }); // script this->combo_script->disconnect(); connect(this->combo_script, &QComboBox::currentTextChanged, [this](const QString &text) { this->sign->setScriptLabel(text); + this->sign->modify(); }); } @@ -784,24 +808,28 @@ void HiddenItemFrame::connectSignals() { this->combo_item->disconnect(); connect(this->combo_item, &QComboBox::currentTextChanged, [this](const QString &text) { this->hiddenItem->setItem(text); + this->hiddenItem->modify(); }); // flag this->combo_flag->disconnect(); connect(this->combo_flag, &QComboBox::currentTextChanged, [this](const QString &text) { this->hiddenItem->setFlag(text); + this->hiddenItem->modify(); }); // quantity this->spinner_quantity->disconnect(); connect(this->spinner_quantity, QOverload::of(&QSpinBox::valueChanged), [this](int value) { this->hiddenItem->setQuantity(value); + this->hiddenItem->modify(); }); // underfoot this->check_itemfinder->disconnect(); connect(this->check_itemfinder, &QCheckBox::stateChanged, [=](int state) { this->hiddenItem->setUnderfoot(state == Qt::Checked); + this->hiddenItem->modify(); }); } @@ -875,6 +903,7 @@ void SecretBaseFrame::connectSignals() { this->combo_base_id->disconnect(); connect(this->combo_base_id, &QComboBox::currentTextChanged, [this](const QString &text) { this->secretBase->setBaseID(text); + this->secretBase->modify(); }); } @@ -936,11 +965,13 @@ void HealLocationFrame::connectSignals() { this->combo_respawn_map->disconnect(); connect(this->combo_respawn_map, &QComboBox::currentTextChanged, [this](const QString &text) { this->healLocation->setRespawnMap(text); + this->healLocation->modify(); }); this->spinner_respawn_npc->disconnect(); connect(this->spinner_respawn_npc, QOverload::of(&QSpinBox::valueChanged), [this](int value) { this->healLocation->setRespawnNPC(value); + this->healLocation->modify(); }); } }