From d433641beeb5dfa50a2438a98b6de1d975a2e59d Mon Sep 17 00:00:00 2001 From: garak Date: Thu, 13 Oct 2022 21:03:26 -0400 Subject: [PATCH] allow numbers for gfx constants, code cleanup --- src/core/events.cpp | 11 ++++++++++- src/editor.cpp | 2 -- src/mainwindow.cpp | 5 ----- src/ui/eventframes.cpp | 10 +--------- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/core/events.cpp b/src/core/events.cpp index 755b67c1..a7b03b53 100644 --- a/src/core/events.cpp +++ b/src/core/events.cpp @@ -215,7 +215,16 @@ QSet ObjectEvent::getExpectedFields() { } void ObjectEvent::loadPixmap(Project *project) { - EventGraphics *eventGfx = project->eventGraphicsMap.value(gfx, nullptr); + EventGraphics *eventGfx = project->eventGraphicsMap.value(this->gfx, nullptr); + if (!eventGfx) { + // Invalid gfx constant. + // If this is a number, try to use that instead. + bool ok; + int altGfx = this->gfx.toInt(&ok); + if (ok && (altGfx < project->gfxDefines.count())) { + eventGfx = project->eventGraphicsMap.value(project->gfxDefines.key(altGfx, "NULL"), nullptr); + } + } if (!eventGfx || eventGfx->spritesheet.isNull()) { // No sprite associated with this gfx constant. // Use default sprite instead. diff --git a/src/editor.cpp b/src/editor.cpp index ea9a9885..6f636975 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1973,7 +1973,6 @@ Tileset* Editor::getCurrentMapPrimaryTileset() } QList Editor::getObjects() { - // TODO: why using this instead of map->getAllEvents()? QList list; for (QGraphicsItem *child : events_group->childItems()) { list.append(static_cast(child)); @@ -2231,7 +2230,6 @@ void Editor::objectsView_onMousePress(QMouseEvent *event) { this->ui->toolButton_Select->setChecked(true); } - // TODO: why do the old objects not get cleared? bool multiSelect = event->modifiers() & Qt::ControlModifier; if (!selectingEvent && !multiSelect && selected_events->length() > 1) { DraggablePixmapItem *first = selected_events->first(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 15313a62..29b6244a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1946,10 +1946,6 @@ void MainWindow::updateObjects() { } void MainWindow::updateSelectedObjects() { - // TODO: make events and/or frames list static? don't want to clear and - // re-add children frames if they are already there in a multi-select - // because QVBoxLayout::addWidget() is taking a lot of time - // TODO: frame->setActive(false) on old frames, (true) on active ones QList all_events = editor->getObjects(); QList events; @@ -2057,7 +2053,6 @@ void MainWindow::updateSelectedObjects() { delete target->layout(); } - // TODO: necessary? keep layout just remove widgets? if (!events.empty()) { QVBoxLayout *layout = new QVBoxLayout; target->setLayout(layout); diff --git a/src/ui/eventframes.cpp b/src/ui/eventframes.cpp index a7d52dae..71c6a4e6 100644 --- a/src/ui/eventframes.cpp +++ b/src/ui/eventframes.cpp @@ -110,9 +110,6 @@ void EventFrame::initCustomAttributesTable() { this->layout_contents->addWidget(customAttributes); } -// TODO: only do this when pixmap item is deleted (ie, when switching between maps or in displayMapEvents()) -// perhaps connect to object destroyed signal from draggablepixamapitem to signal need reconnect -// ie, mark connections dirty and need redo void EventFrame::connectSignals() { this->connected = true; @@ -123,7 +120,7 @@ void EventFrame::connectSignals() { 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); this->spinner_y->disconnect(); @@ -332,8 +329,6 @@ void ObjectFrame::connectSignals() { }); } -// 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 void ObjectFrame::initialize() { if (this->initialized) return; @@ -461,7 +456,6 @@ void CloneObjectFrame::initialize() { // sprite this->combo_sprite->setCurrentText(this->clone->getGfx()); - // TODO: update this with object gfx change? // target id this->spinner_target_id->setMinimum(1); @@ -655,7 +649,6 @@ void TriggerFrame::populate(Project *project) { // script QStringList scriptLabels = this->trigger->getMap()->eventScriptLabels() + project->getGlobalScriptLabels(); scriptLabels.removeDuplicates(); - // TODO: are there any additional labels? this->scriptCompleter = new QCompleter(scriptLabels, this); this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive); @@ -799,7 +792,6 @@ void SignFrame::populate(Project *project) { // script QStringList scriptLabels = this->sign->getMap()->eventScriptLabels() + project->getGlobalScriptLabels(); scriptLabels.removeDuplicates(); - // TODO: are there any additional labels? this->scriptCompleter = new QCompleter(scriptLabels, this); this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive);