Skip to content

Commit

Permalink
Add 'Replace Object' to v5 Stage Config editor
Browse files Browse the repository at this point in the history
- '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
  • Loading branch information
Leonx254 committed Jul 19, 2024
1 parent c4be882 commit 652d63a
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 48 deletions.
21 changes: 19 additions & 2 deletions RetroEDv2/tools/sceneeditorv5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};

Expand Down Expand Up @@ -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<GameObjectInfo> 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;
Expand All @@ -1148,6 +1162,7 @@ SceneEditorv5::SceneEditorv5(QWidget *parent) : QWidget(parent), ui(new Ui::Scen

objProp->unsetUI();
CreateEntityList();
viewer->startTimer();
DoAction("Edited StageConfig");
});

Expand Down Expand Up @@ -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);
}
Expand Down
78 changes: 49 additions & 29 deletions RetroEDv2/tools/sceneproperties/objectselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "ui_objectselector.h"
#include "objectselector.hpp"

ObjectSelectorv5::ObjectSelectorv5(QList<QString> list, QList<GameObjectInfo> objList, QWidget *parent)
ObjectSelectorv5::ObjectSelectorv5(QList<QString> list, QList<GameObjectInfo> objList, bool replace, QWidget *parent)
: QDialog(parent), ui(new Ui::ObjectSelectorv5)
{
ui->setupUi(this);
Expand All @@ -18,39 +18,59 @@ ObjectSelectorv5::ObjectSelectorv5(QList<QString> list, QList<GameObjectInfo> 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; }
Expand All @@ -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));
}
}

Expand Down
3 changes: 2 additions & 1 deletion RetroEDv2/tools/sceneproperties/objectselector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ class ObjectSelectorv5 : public QDialog
Q_OBJECT

public:
explicit ObjectSelectorv5(QList<QString> list, QList<GameObjectInfo> objList,
explicit ObjectSelectorv5(QList<QString> list, QList<GameObjectInfo> objList, bool replace = false,
QWidget *parent = nullptr);
~ObjectSelectorv5();

QList<int> objIDList;
QList<bool> objAddList;
QString replacedObj = "";

private:
Ui::ObjectSelectorv5 *ui;
Expand Down
88 changes: 77 additions & 11 deletions RetroEDv2/tools/sceneproperties/stageconfigeditorv5.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#include "includes.hpp"
#include "ui_stageconfigeditorv5.h"
#include "stageconfigeditorv5.hpp"
#include "objectselector.hpp"

#include <RSDKv5/stageconfigv5.hpp>

StageConfigEditorv5::StageConfigEditorv5(RSDKv5::StageConfig *scf, QWidget *parent)
StageConfigEditorv5::StageConfigEditorv5(RSDKv5::StageConfig *scf, QList<SceneObject> &objList, QList<GameObjectInfo> 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);
Expand Down Expand Up @@ -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)
Expand All @@ -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<QString> 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");
});

Expand Down Expand Up @@ -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<QString> 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();

Expand Down Expand Up @@ -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++;
}

Expand Down
10 changes: 6 additions & 4 deletions RetroEDv2/tools/sceneproperties/stageconfigeditorv5.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <QWidget>

#include <QDialog>
#include <RSDKv5/stageconfigv5.hpp>
#include "sceneincludesv5.hpp"

namespace Ui
{
Expand All @@ -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<SceneObject> &objList, QList<GameObjectInfo> gamelinkObjs, bool linkState, QWidget *parent = nullptr);
~StageConfigEditorv5();

QString oldObj = "";
QString replaceObj = "";
void setupUI(bool allowRowChange = true);

protected:
Expand All @@ -41,6 +42,7 @@ class StageConfigEditorv5 : public QDialog

QList<ActionState> actions;
int actionIndex = 0;
bool linkLoaded = false;

Ui::StageConfigEditorv5 *ui;

Expand Down
16 changes: 15 additions & 1 deletion RetroEDv2/tools/sceneproperties/stageconfigeditorv5.ui
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@
</layout>
</item>
<item row="0" column="3">
<widget class="QLineEdit" name="objName"/>
<widget class="QLineEdit" name="objName">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_2">
Expand All @@ -176,6 +180,16 @@
</property>
</spacer>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="replaceObj">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Replace Object</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="sfxPage">
Expand Down

0 comments on commit 652d63a

Please sign in to comment.