indicate map edited when event data is modified

This commit is contained in:
garak 2022-09-28 00:21:01 -04:00
parent 8ac556c0de
commit cb6d1a4220
6 changed files with 53 additions and 2 deletions

View file

@ -119,6 +119,8 @@ public:
void setMap(Map *newMap) { this->map = newMap; } void setMap(Map *newMap) { this->map = newMap; }
Map *getMap() const { return this->map; } Map *getMap() const { return this->map; }
void modify();
virtual void accept(EventVisitor *) { } virtual void accept(EventVisitor *) { }
void setX(int newX) { this->x = newX; } void setX(int newX) { this->x = newX; }

View file

@ -119,6 +119,8 @@ public:
void setBorderItem(BorderMetatilesPixmapItem *item) { borderItem = item; } void setBorderItem(BorderMetatilesPixmapItem *item) { borderItem = item; }
QUndoStack editHistory; QUndoStack editHistory;
void modify();
void clean();
private: private:
void setNewDimensionsBlockdata(int newWidth, int newHeight); void setNewDimensionsBlockdata(int newWidth, int newHeight);
@ -126,6 +128,7 @@ private:
signals: signals:
void mapChanged(Map *map); void mapChanged(Map *map);
void modified();
void mapDimensionsChanged(const QSize &size); void mapDimensionsChanged(const QSize &size);
void mapNeedsRedrawing(); void mapNeedsRedrawing();
void openScriptRequested(QString label); void openScriptRequested(QString label);

View file

@ -49,6 +49,10 @@ void Event::addCustomValuesTo(OrderedJson::object *obj) {
} }
} }
void Event::modify() {
this->map->modify();
}
QString Event::eventTypeToString(Event::Type type) { QString Event::eventTypeToString(Event::Type type) {
switch (type) { switch (type) {
case Event::Type::Object: case Event::Type::Object:

View file

@ -515,6 +515,14 @@ void Map::addEvent(Event *event) {
if (!ownedEvents.contains(event)) ownedEvents.append(event); if (!ownedEvents.contains(event)) ownedEvents.append(event);
} }
void Map::modify() {
emit modified();
}
void Map::clean() {
this->hasUnsavedDataChanges = false;
}
bool Map::hasUnsavedChanges() { bool Map::hasUnsavedChanges() {
return !editHistory.isClean() || hasUnsavedDataChanges || !isPersistedToFile; return !editHistory.isClean() || hasUnsavedDataChanges || !isPersistedToFile;
} }

View file

@ -671,6 +671,7 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
connect(editor->map, &Map::mapChanged, this, &MainWindow::onMapChanged); connect(editor->map, &Map::mapChanged, this, &MainWindow::onMapChanged);
connect(editor->map, &Map::mapNeedsRedrawing, this, &MainWindow::onMapNeedsRedrawing); connect(editor->map, &Map::mapNeedsRedrawing, this, &MainWindow::onMapNeedsRedrawing);
connect(editor->map, &Map::modified, [this](){ this->markMapEdited(); });
setRecentMap(map_name); setRecentMap(map_name);
updateMapList(); updateMapList();
@ -1452,6 +1453,7 @@ void MainWindow::updateMapList() {
void MainWindow::on_action_Save_Project_triggered() { void MainWindow::on_action_Save_Project_triggered() {
editor->saveProject(); editor->saveProject();
updateMapList(); updateMapList();
showWindowTitle();
} }
void MainWindow::duplicate() { void MainWindow::duplicate() {
@ -1694,6 +1696,7 @@ void MainWindow::paste() {
void MainWindow::on_action_Save_triggered() { void MainWindow::on_action_Save_triggered() {
editor->save(); editor->save();
updateMapList(); updateMapList();
showWindowTitle();
} }
void MainWindow::on_mapViewTab_tabBarClicked(int index) void MainWindow::on_mapViewTab_tabBarClicked(int index)

View file

@ -115,7 +115,9 @@ void EventFrame::connectSignals() {
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();
if (delta) this->event->getMap()->editHistory.push(new EventMove(QList<Event *>() << this->event, delta, 0, this->spinner_x->getActionId())); if (delta) {
this->event->getMap()->editHistory.push(new EventMove(QList<Event *>() << 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? // 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); connect(this->event->getPixmapItem(), &DraggablePixmapItem::xChanged, this->spinner_x, &NoScrollSpinBox::setValue);
@ -123,7 +125,9 @@ void EventFrame::connectSignals() {
this->spinner_y->disconnect(); this->spinner_y->disconnect();
connect(this->spinner_y, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) { connect(this->spinner_y, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) {
int delta = value - event->getY(); int delta = value - event->getY();
if (delta) this->event->getMap()->editHistory.push(new EventMove(QList<Event *>() << this->event, 0, delta, this->spinner_y->getActionId())); if (delta) {
this->event->getMap()->editHistory.push(new EventMove(QList<Event *>() << this->event, 0, delta, this->spinner_y->getActionId()));
}
}); });
connect(this->event->getPixmapItem(), &DraggablePixmapItem::yChanged, this->spinner_y, &NoScrollSpinBox::setValue); connect(this->event->getPixmapItem(), &DraggablePixmapItem::yChanged, this->spinner_y, &NoScrollSpinBox::setValue);
@ -131,6 +135,7 @@ void EventFrame::connectSignals() {
this->spinner_z->disconnect(); this->spinner_z->disconnect();
connect(this->spinner_z, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) { connect(this->spinner_z, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) {
this->event->setZ(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) { connect(this->combo_sprite, &QComboBox::currentTextChanged, [this](const QString &text) {
this->object->setGfx(text); this->object->setGfx(text);
this->object->getPixmapItem()->updatePixmap(); this->object->getPixmapItem()->updatePixmap();
this->object->modify();
}); });
connect(this->object->getPixmapItem(), &DraggablePixmapItem::spriteChanged, this->label_icon, &QLabel::setPixmap); 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) { connect(this->combo_movement, &QComboBox::currentTextChanged, [this](const QString &text) {
this->object->setMovement(text); this->object->setMovement(text);
this->object->getPixmapItem()->updatePixmap(); this->object->getPixmapItem()->updatePixmap();
this->object->modify();
}); });
// radii // radii
this->spinner_radius_x->disconnect(); this->spinner_radius_x->disconnect();
connect(this->spinner_radius_x, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) { connect(this->spinner_radius_x, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) {
this->object->setRadiusX(value); this->object->setRadiusX(value);
this->object->modify();
}); });
this->spinner_radius_y->disconnect(); this->spinner_radius_y->disconnect();
connect(this->spinner_radius_y, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) { connect(this->spinner_radius_y, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) {
this->object->setRadiusY(value); this->object->setRadiusY(value);
this->object->modify();
}); });
// script // script
@ -275,29 +284,34 @@ void ObjectFrame::connectSignals() {
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);
this->object->modify();
}); });
this->button_script->disconnect(); this->button_script->disconnect();
connect(this->button_script, &QToolButton::clicked, [this]() { connect(this->button_script, &QToolButton::clicked, [this]() {
this->object->getMap()->openScript(this->combo_script->currentText()); this->object->getMap()->openScript(this->combo_script->currentText());
this->object->modify();
}); });
// flag // flag
this->combo_flag->disconnect(); this->combo_flag->disconnect();
connect(this->combo_flag, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_flag, &QComboBox::currentTextChanged, [this](const QString &text) {
this->object->setFlag(text); this->object->setFlag(text);
this->object->modify();
}); });
// trainer type // trainer type
this->combo_trainer_type->disconnect(); this->combo_trainer_type->disconnect();
connect(this->combo_trainer_type, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_trainer_type, &QComboBox::currentTextChanged, [this](const QString &text) {
this->object->setTrainerType(text); this->object->setTrainerType(text);
this->object->modify();
}); });
// sight berry // sight berry
this->combo_radius_treeid->disconnect(); this->combo_radius_treeid->disconnect();
connect(this->combo_radius_treeid, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_radius_treeid, &QComboBox::currentTextChanged, [this](const QString &text) {
this->object->setSightRadiusBerryTreeID(text); this->object->setSightRadiusBerryTreeID(text);
this->object->modify();
}); });
} }
@ -404,12 +418,14 @@ void CloneObjectFrame::connectSignals() {
this->combo_target_map->disconnect(); this->combo_target_map->disconnect();
connect(this->combo_target_map, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_target_map, &QComboBox::currentTextChanged, [this](const QString &text) {
this->clone->setTargetMap(text); this->clone->setTargetMap(text);
this->clone->modify();
}); });
// target id // target id
this->spinner_target_id->disconnect(); this->spinner_target_id->disconnect();
connect(this->spinner_target_id, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) { connect(this->spinner_target_id, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) {
this->clone->setTargetID(value); this->clone->setTargetID(value);
this->clone->modify();
}); });
} }
@ -476,12 +492,14 @@ void WarpFrame::connectSignals() {
this->combo_dest_map->disconnect(); this->combo_dest_map->disconnect();
connect(this->combo_dest_map, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_dest_map, &QComboBox::currentTextChanged, [this](const QString &text) {
this->warp->setDestinationMap(text); this->warp->setDestinationMap(text);
this->warp->modify();
}); });
// dest id // dest id
this->spinner_dest_warp->disconnect(); this->spinner_dest_warp->disconnect();
connect(this->spinner_dest_warp, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) { connect(this->spinner_dest_warp, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) {
this->warp->setDestinationWarpID(value); this->warp->setDestinationWarpID(value);
this->warp->modify();
}); });
} }
@ -550,18 +568,21 @@ void TriggerFrame::connectSignals() {
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->trigger->setScriptLabel(text); this->trigger->setScriptLabel(text);
this->trigger->modify();
}); });
// var // var
this->combo_var->disconnect(); this->combo_var->disconnect();
connect(this->combo_var, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_var, &QComboBox::currentTextChanged, [this](const QString &text) {
this->trigger->setScriptVar(text); this->trigger->setScriptVar(text);
this->trigger->modify();
}); });
// value // value
this->combo_var_value->disconnect(); this->combo_var_value->disconnect();
connect(this->combo_var_value, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_var_value, &QComboBox::currentTextChanged, [this](const QString &text) {
this->trigger->setScriptVarValue(text); this->trigger->setScriptVarValue(text);
this->trigger->modify();
}); });
} }
@ -630,6 +651,7 @@ void WeatherTriggerFrame::connectSignals() {
this->combo_weather->disconnect(); this->combo_weather->disconnect();
connect(this->combo_weather, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_weather, &QComboBox::currentTextChanged, [this](const QString &text) {
this->weatherTrigger->setWeather(text); this->weatherTrigger->setWeather(text);
this->weatherTrigger->modify();
}); });
} }
@ -688,12 +710,14 @@ void SignFrame::connectSignals() {
this->combo_facing_dir->disconnect(); this->combo_facing_dir->disconnect();
connect(this->combo_facing_dir, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_facing_dir, &QComboBox::currentTextChanged, [this](const QString &text) {
this->sign->setFacingDirection(text); this->sign->setFacingDirection(text);
this->sign->modify();
}); });
// script // script
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->sign->setScriptLabel(text); this->sign->setScriptLabel(text);
this->sign->modify();
}); });
} }
@ -784,24 +808,28 @@ void HiddenItemFrame::connectSignals() {
this->combo_item->disconnect(); this->combo_item->disconnect();
connect(this->combo_item, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_item, &QComboBox::currentTextChanged, [this](const QString &text) {
this->hiddenItem->setItem(text); this->hiddenItem->setItem(text);
this->hiddenItem->modify();
}); });
// flag // flag
this->combo_flag->disconnect(); this->combo_flag->disconnect();
connect(this->combo_flag, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_flag, &QComboBox::currentTextChanged, [this](const QString &text) {
this->hiddenItem->setFlag(text); this->hiddenItem->setFlag(text);
this->hiddenItem->modify();
}); });
// quantity // quantity
this->spinner_quantity->disconnect(); this->spinner_quantity->disconnect();
connect(this->spinner_quantity, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) { connect(this->spinner_quantity, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) {
this->hiddenItem->setQuantity(value); this->hiddenItem->setQuantity(value);
this->hiddenItem->modify();
}); });
// underfoot // underfoot
this->check_itemfinder->disconnect(); this->check_itemfinder->disconnect();
connect(this->check_itemfinder, &QCheckBox::stateChanged, [=](int state) { connect(this->check_itemfinder, &QCheckBox::stateChanged, [=](int state) {
this->hiddenItem->setUnderfoot(state == Qt::Checked); this->hiddenItem->setUnderfoot(state == Qt::Checked);
this->hiddenItem->modify();
}); });
} }
@ -875,6 +903,7 @@ void SecretBaseFrame::connectSignals() {
this->combo_base_id->disconnect(); this->combo_base_id->disconnect();
connect(this->combo_base_id, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_base_id, &QComboBox::currentTextChanged, [this](const QString &text) {
this->secretBase->setBaseID(text); this->secretBase->setBaseID(text);
this->secretBase->modify();
}); });
} }
@ -936,11 +965,13 @@ void HealLocationFrame::connectSignals() {
this->combo_respawn_map->disconnect(); this->combo_respawn_map->disconnect();
connect(this->combo_respawn_map, &QComboBox::currentTextChanged, [this](const QString &text) { connect(this->combo_respawn_map, &QComboBox::currentTextChanged, [this](const QString &text) {
this->healLocation->setRespawnMap(text); this->healLocation->setRespawnMap(text);
this->healLocation->modify();
}); });
this->spinner_respawn_npc->disconnect(); this->spinner_respawn_npc->disconnect();
connect(this->spinner_respawn_npc, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) { connect(this->spinner_respawn_npc, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) {
this->healLocation->setRespawnNPC(value); this->healLocation->setRespawnNPC(value);
this->healLocation->modify();
}); });
} }
} }