From 652d63af74d4ee1a888cba352568b8cd358a0667 Mon Sep 17 00:00:00 2001 From: Leonx254 Date: Fri, 19 Jul 2024 04:54:27 -0300 Subject: [PATCH] Add 'Replace Object' to v5 Stage Config editor - 'Replace Object' button added to v5 Stage Config, only enabled if a gamelink is loaded - Object Selector search bar is no longer case sensitive -'Add Object' in v5 Stage Config editor now prompts the Object Selector if a gamelink is loaded - Is no longer possible to edit object names if a gamelink is loaded - Fixed bug where resyncing the objects (via the buttons or by editing stage config) would add way more values than intended to any dropdown in an object --- RetroEDv2/tools/sceneeditorv5.cpp | 21 ++++- .../tools/sceneproperties/objectselector.cpp | 78 ++++++++++------ .../tools/sceneproperties/objectselector.hpp | 3 +- .../sceneproperties/stageconfigeditorv5.cpp | 88 ++++++++++++++++--- .../sceneproperties/stageconfigeditorv5.hpp | 10 ++- .../sceneproperties/stageconfigeditorv5.ui | 16 +++- 6 files changed, 168 insertions(+), 48 deletions(-) diff --git a/RetroEDv2/tools/sceneeditorv5.cpp b/RetroEDv2/tools/sceneeditorv5.cpp index 1100b78..d274098 100644 --- a/RetroEDv2/tools/sceneeditorv5.cpp +++ b/RetroEDv2/tools/sceneeditorv5.cpp @@ -421,8 +421,15 @@ SceneEditorv5::SceneEditorv5(QWidget *parent) : QWidget(parent), ui(new Ui::Scen if (useLoadEvent){ // idk why do i need to call every object again but otherwise references to the added object are ignored // (Fixes LSelect visual bugs) - for (int i = 0; i <= objectID; ++i) + // There's probably a better way of doing this + for (int i = 0; i <= objectID; ++i){ + for (int v = viewer->objects[i].variables.count() - 1; v >= 0; --v) { + if (viewer->objects[i].variables[v].values.count()){ + viewer->objects[i].variables[v].values.clear(); + } + } CallGameEvent(viewer->objects[i].name, SceneViewer::EVENT_LOAD, NULL); + } } }; @@ -1131,7 +1138,14 @@ SceneEditorv5::SceneEditorv5(QWidget *parent) : QWidget(parent), ui(new Ui::Scen }); connect(scnProp->editSCF, &QPushButton::clicked, [this, reSyncGameObject] { - StageConfigEditorv5 *edit = new StageConfigEditorv5(&stageConfig, this); + QList objList; + for (auto &link : gameLinks) { + for (int o = 0; o < link.gameObjectList.count(); ++o) { + objList.append(link.gameObjectList[o]); + } + } + viewer->stopTimer(); + StageConfigEditorv5 *edit = new StageConfigEditorv5(&stageConfig, viewer->objects, objList, viewer->linkError == 0, this); edit->exec(); int oldListCount = ui->objectList->count() - 1; @@ -1148,6 +1162,7 @@ SceneEditorv5::SceneEditorv5(QWidget *parent) : QWidget(parent), ui(new Ui::Scen objProp->unsetUI(); CreateEntityList(); + viewer->startTimer(); DoAction("Edited StageConfig"); }); @@ -1766,9 +1781,11 @@ void SceneEditorv5::updateTileSel(){ &tile, viewer->tiles[tile & 0x3FF]); copiedTile = false; } + void SceneEditorv5::updateStampName(QString name){ ui->stampList->currentItem()->setText(name); } + void SceneEditorv5::updateLayerName(QString name){ ui->layerList->currentItem()->setText(name); } diff --git a/RetroEDv2/tools/sceneproperties/objectselector.cpp b/RetroEDv2/tools/sceneproperties/objectselector.cpp index f3c648c..5ec1cb6 100644 --- a/RetroEDv2/tools/sceneproperties/objectselector.cpp +++ b/RetroEDv2/tools/sceneproperties/objectselector.cpp @@ -2,7 +2,7 @@ #include "ui_objectselector.h" #include "objectselector.hpp" -ObjectSelectorv5::ObjectSelectorv5(QList list, QList objList, QWidget *parent) +ObjectSelectorv5::ObjectSelectorv5(QList list, QList objList, bool replace, QWidget *parent) : QDialog(parent), ui(new Ui::ObjectSelectorv5) { ui->setupUi(this); @@ -18,39 +18,59 @@ ObjectSelectorv5::ObjectSelectorv5(QList list, QList ob connect(ui->buttonBox, &QDialogButtonBox::rejected, [this] { this->reject(); }); disconnect(ui->objList, nullptr, nullptr, nullptr); - connect(ui->objList, &QListWidget::itemChanged, [this, list](QListWidgetItem *item) { - int r = ui->objList->row(item) - list.count(); - if (r >= 0 && r < objAddList.count()) - objAddList[r] = item->checkState() != Qt::Unchecked; - }); - - disconnect(ui->objectFilter, nullptr, nullptr, nullptr); - connect(ui->objectFilter, &QLineEdit::textChanged, [this](QString s) { filterObjectList(s); }); - - for (QString &obj : list) { - // object already exists - QListWidgetItem *item = new QListWidgetItem(); - item->setFlags(item->flags() | Qt::ItemIsUserCheckable); - item->setFlags(item->flags() & ~Qt::ItemIsEnabled); - item->setCheckState(Qt::Checked); - item->setText(obj); - ui->objList->addItem(item); - } + if (!replace){ + connect(ui->objList, &QListWidget::itemChanged, [this, list](QListWidgetItem *item) { + int r = ui->objList->row(item) - list.count(); + if (r >= 0 && r < objAddList.count()) + objAddList[r] = item->checkState() != Qt::Unchecked; + }); + + disconnect(ui->objectFilter, nullptr, nullptr, nullptr); + connect(ui->objectFilter, &QLineEdit::textChanged, [this](QString s) { filterObjectList(s.toUpper()); }); - int id = 0; - for (auto &obj : objList) { - if (list.indexOf(obj.name) == -1) { // new object perhaps???? + for (QString &obj : list) { + // object already exists QListWidgetItem *item = new QListWidgetItem(); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); - item->setCheckState(Qt::Unchecked); - item->setText(obj.name); + item->setFlags(item->flags() & ~Qt::ItemIsEnabled); + item->setCheckState(Qt::Checked); + item->setText(obj); ui->objList->addItem(item); + } + + int id = 0; + for (auto &obj : objList) { + if (list.indexOf(obj.name) == -1) { // new object perhaps???? + QListWidgetItem *item = new QListWidgetItem(); + item->setFlags(item->flags() | Qt::ItemIsUserCheckable); + item->setCheckState(Qt::Unchecked); + item->setText(obj.name); + ui->objList->addItem(item); - objIDList.append(id); - objAddList.append(false); + objIDList.append(id); + objAddList.append(false); + } + id++; } - id++; - } + } else{ + this->setWindowTitle("Choose object to replace with..."); + connect(ui->objList, &QListWidget::currentItemChanged, [this](QListWidgetItem *c) { replacedObj = c->text(); }); + + disconnect(ui->objectFilter, nullptr, nullptr, nullptr); + connect(ui->objectFilter, &QLineEdit::textChanged, [this](QString s) { filterObjectList(s.toUpper()); }); + + int id = 0; + for (auto &obj : objList) { + if (list.indexOf(obj.name) == -1){ + QListWidgetItem *item = new QListWidgetItem(); + item->setText(obj.name); + ui->objList->addItem(item); + + objIDList.append(id); + objAddList.append(false); + id++; + } + }} } ObjectSelectorv5::~ObjectSelectorv5() { delete ui; } @@ -61,7 +81,7 @@ void ObjectSelectorv5::filterObjectList(QString filter) for (int row = 0; row < ui->objList->count(); ++row) { auto *item = ui->objList->item(row); - item->setHidden(!showAll && !item->text().contains(filter)); + item->setHidden(!showAll && !item->text().toUpper().contains(filter)); } } diff --git a/RetroEDv2/tools/sceneproperties/objectselector.hpp b/RetroEDv2/tools/sceneproperties/objectselector.hpp index d3a67a3..ad2f07c 100644 --- a/RetroEDv2/tools/sceneproperties/objectselector.hpp +++ b/RetroEDv2/tools/sceneproperties/objectselector.hpp @@ -12,12 +12,13 @@ class ObjectSelectorv5 : public QDialog Q_OBJECT public: - explicit ObjectSelectorv5(QList list, QList objList, + explicit ObjectSelectorv5(QList list, QList objList, bool replace = false, QWidget *parent = nullptr); ~ObjectSelectorv5(); QList objIDList; QList objAddList; + QString replacedObj = ""; private: Ui::ObjectSelectorv5 *ui; diff --git a/RetroEDv2/tools/sceneproperties/stageconfigeditorv5.cpp b/RetroEDv2/tools/sceneproperties/stageconfigeditorv5.cpp index fe6651c..7ad1d46 100644 --- a/RetroEDv2/tools/sceneproperties/stageconfigeditorv5.cpp +++ b/RetroEDv2/tools/sceneproperties/stageconfigeditorv5.cpp @@ -1,19 +1,21 @@ #include "includes.hpp" #include "ui_stageconfigeditorv5.h" #include "stageconfigeditorv5.hpp" +#include "objectselector.hpp" #include -StageConfigEditorv5::StageConfigEditorv5(RSDKv5::StageConfig *scf, QWidget *parent) +StageConfigEditorv5::StageConfigEditorv5(RSDKv5::StageConfig *scf, QList &objList, QList gamelinkObjs, bool linkState, QWidget *parent) : QDialog(parent), ui(new Ui::StageConfigEditorv5), stageConfig(scf) { ui->setupUi(this); this->setWindowTitle("StageConfig Editor"); - // remove question mark from the title bar setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + int gcCount = objList.count() - stageConfig->objects.count(); + linkLoaded = linkState; setupUI(); ui->sectionList->blockSignals(true); @@ -49,11 +51,14 @@ StageConfigEditorv5::StageConfigEditorv5(RSDKv5::StageConfig *scf, QWidget *pare ui->objName->setDisabled(c == -1); + ui->replaceObj->setDisabled(!linkLoaded || c == -1); + if (c == -1) return; ui->objName->blockSignals(true); ui->objName->setText(stageConfig->objects[c]); + ui->objName->setEnabled(!linkLoaded); ui->objName->blockSignals(false); if (ui->downObj) @@ -62,15 +67,39 @@ StageConfigEditorv5::StageConfigEditorv5(RSDKv5::StageConfig *scf, QWidget *pare ui->upObj->setDisabled(c == 0); }); - connect(ui->addObj, &QToolButton::clicked, [this] { + connect(ui->addObj, &QToolButton::clicked, [this, gcCount, &objList, gamelinkObjs] { uint c = ui->objList->currentRow() + 1; - stageConfig->objects.insert(c, "New Object"); - auto *item = new QListWidgetItem(); - item->setText(stageConfig->objects[c]); - ui->objList->insertItem(c, item); - - item->setFlags(item->flags() | Qt::ItemIsEditable); - ui->objList->setCurrentItem(item); + if (!linkLoaded){ + stageConfig->objects.insert(c, "New Object"); + auto *item = new QListWidgetItem(); + item->setText(stageConfig->objects[c]); + ui->objList->insertItem(c, item); + + item->setFlags(item->flags() | Qt::ItemIsEditable); + ui->objList->setCurrentItem(item); + } else{ + QList nameList; + for (int s = 0; s < gcCount; s++){ + nameList.append(objList[s].name); + } + for (int s = 0; s < ui->objList->count(); s++){ + nameList.append(ui->objList->item(s)->text()); + } + + ObjectSelectorv5 *selector = new ObjectSelectorv5(nameList, gamelinkObjs); + if (selector->exec() == QDialog::Accepted) { + for (int i = selector->objAddList.count() - 1; i >= 0; --i) { + if (selector->objAddList[i]) { + stageConfig->objects.insert(c, gamelinkObjs[selector->objIDList[i]].name); + + auto *item = new QListWidgetItem(); + item->setText(stageConfig->objects[c]); + ui->objList->insertItem(c, item); + } + } + + } + } DoAction("Added Object"); }); @@ -103,6 +132,42 @@ StageConfigEditorv5::StageConfigEditorv5(RSDKv5::StageConfig *scf, QWidget *pare DoAction("Removed Object"); }); + connect(ui->replaceObj, &QToolButton::clicked, [this, gcCount, &objList, gamelinkObjs] { + oldObj = ui->objList->currentItem()->text(); + QList nameList; + for (int s = 0; s < gcCount; s++){ + nameList.append(objList[s].name); + } + for (int s = 0; s < ui->objList->count(); s++){ + nameList.append(ui->objList->item(s)->text()); + } + + ObjectSelectorv5 *replacer = new ObjectSelectorv5(nameList, gamelinkObjs, true); + if (replacer->exec() == QDialog::Accepted) { + ui->objList->currentItem()->setText(replacer->replacedObj); + stageConfig->objects[ui->objList->currentRow()] = replacer->replacedObj; + + int replacedID = 0; + for (int i = 0; i < objList.count(); i++){ + if (objList[i].name == oldObj){ + replacedID = i; + break; + } + } + + for (int o = 0; o < gamelinkObjs.count(); ++o) { + if (gamelinkObjs[o].name == replacer->replacedObj){ + SceneObject obj; + obj.name = replacer->replacedObj; + objList[replacedID].name = replacer->replacedObj; + break; + } + } + } + DoAction("Replaced Object"); + }); + + connect(ui->objList, &QListWidget::itemChanged, [this](QListWidgetItem *item) { stageConfig->objects[ui->objList->row(item)] = item->text(); @@ -265,7 +330,8 @@ void StageConfigEditorv5::setupUI(bool allowRowChange) int id = 0; for (QString &obj : stageConfig->objects) { ui->objList->addItem(obj); - ui->objList->item(id)->setFlags(ui->objList->item(id)->flags() | Qt::ItemIsEditable); + if (!linkLoaded) + ui->objList->item(id)->setFlags(ui->objList->item(id)->flags() | Qt::ItemIsEditable); id++; } diff --git a/RetroEDv2/tools/sceneproperties/stageconfigeditorv5.hpp b/RetroEDv2/tools/sceneproperties/stageconfigeditorv5.hpp index 54a1dd0..5556544 100644 --- a/RetroEDv2/tools/sceneproperties/stageconfigeditorv5.hpp +++ b/RetroEDv2/tools/sceneproperties/stageconfigeditorv5.hpp @@ -1,8 +1,8 @@ #pragma once -#include - +#include #include +#include "sceneincludesv5.hpp" namespace Ui { @@ -22,9 +22,10 @@ class StageConfigEditorv5 : public QDialog RSDKv5::StageConfig stageConfig; }; - explicit StageConfigEditorv5(RSDKv5::StageConfig *scf, QWidget *parent = nullptr); + explicit StageConfigEditorv5(RSDKv5::StageConfig *scf, QList &objList, QList gamelinkObjs, bool linkState, QWidget *parent = nullptr); ~StageConfigEditorv5(); - + QString oldObj = ""; + QString replaceObj = ""; void setupUI(bool allowRowChange = true); protected: @@ -41,6 +42,7 @@ class StageConfigEditorv5 : public QDialog QList actions; int actionIndex = 0; + bool linkLoaded = false; Ui::StageConfigEditorv5 *ui; diff --git a/RetroEDv2/tools/sceneproperties/stageconfigeditorv5.ui b/RetroEDv2/tools/sceneproperties/stageconfigeditorv5.ui index d49370e..81d8911 100644 --- a/RetroEDv2/tools/sceneproperties/stageconfigeditorv5.ui +++ b/RetroEDv2/tools/sceneproperties/stageconfigeditorv5.ui @@ -154,7 +154,11 @@ - + + + false + + @@ -176,6 +180,16 @@ + + + + false + + + Replace Object + + +