From 0b2a526e3d0c75c72cd1ad303b587b964b9fd96c Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 3 Jan 2024 15:09:12 -0500 Subject: [PATCH] Fix event group tab selection --- CHANGELOG.md | 1 + include/mainwindow.h | 7 +------ src/core/metatile.cpp | 2 +- src/mainwindow.cpp | 47 ++++++++----------------------------------- 4 files changed, 11 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9565411c..6eea8f05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - Metatile ID strings are now padded to their current max, not the overall max. ### Fixed +- Fix the event group tabs sometimes showing an event from the wrong group - Fix API error reporting ## [5.2.0] - 2024-01-02 diff --git a/include/mainwindow.h b/include/mainwindow.h index 6ff8a1d3..8eb9cefb 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -325,12 +325,7 @@ private slots: QWidget *eventTabBGWidget; QWidget *eventTabHealspotWidget; QWidget *eventTabMultipleWidget; - - DraggablePixmapItem *selectedObject; - DraggablePixmapItem *selectedWarp; - DraggablePixmapItem *selectedTrigger; - DraggablePixmapItem *selectedBG; - DraggablePixmapItem *selectedHealspot; + QMap lastSelectedEvent; bool isProgrammaticEventTabChange; bool projectHasUnsavedChanges; diff --git a/src/core/metatile.cpp b/src/core/metatile.cpp index 1b4a74c5..1a3dc11b 100644 --- a/src/core/metatile.cpp +++ b/src/core/metatile.cpp @@ -106,7 +106,7 @@ uint32_t Metatile::getMaxAttributesMask() { void Metatile::setLayout(Project * project) { // Calculate the number of hex characters needed to display a metatile ID. numMetatileIdChars = 0; - for (uint16_t i = Block::getMaxMetatileId(); i > 1; i /= 0xF) + for (uint16_t i = Block::getMaxMetatileId(); i > 0; i /= 16) numMetatileIdChars++; uint32_t behaviorMask = projectConfig.getMetatileBehaviorMask(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 94b6937e..49dd4ac1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -49,11 +49,6 @@ using OrderedJsonDoc = poryjson::JsonDoc; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), - selectedObject(nullptr), - selectedWarp(nullptr), - selectedTrigger(nullptr), - selectedBG(nullptr), - selectedHealspot(nullptr), isProgrammaticEventTabChange(false) { QCoreApplication::setOrganizationName("pret"); @@ -694,6 +689,7 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) { ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), false); } + this->lastSelectedEvent.clear(); refreshMapScene(); displayMapProperties(); @@ -1929,24 +1925,11 @@ void MainWindow::displayEventTabs() { void MainWindow::updateObjects() { QList all_objects = editor->getObjects(); - if (selectedObject && !all_objects.contains(selectedObject)) { - selectedObject = nullptr; + for (auto i = this->lastSelectedEvent.cbegin(), end = this->lastSelectedEvent.cend(); i != end; i++) { + if (i.value() && !all_objects.contains(i.value())) + this->lastSelectedEvent.insert(i.key(), nullptr); } - if (selectedWarp && !all_objects.contains(selectedWarp)) { - selectedWarp = nullptr; - } - if (selectedTrigger && !all_objects.contains(selectedTrigger)) { - selectedTrigger = nullptr; - } - if (selectedBG && !all_objects.contains(selectedBG)) { - selectedBG = nullptr; - } - if (selectedHealspot && !all_objects.contains(selectedHealspot)) { - selectedHealspot = nullptr; - } - displayEventTabs(); - updateSelectedObjects(); } @@ -1983,14 +1966,15 @@ void MainWindow::updateSelectedObjects() { Event::Group eventGroup = current->getEventGroup(); int event_offs = Event::getIndexOffset(eventGroup); + if (eventGroup != Event::Group::None) + this->lastSelectedEvent.insert(eventGroup, current->getPixmapItem()); + switch (eventGroup) { case Event::Group::Object: { scrollTarget = ui->scrollArea_Objects; target = ui->scrollAreaWidgetContents_Objects; ui->tabWidget_EventType->setCurrentWidget(ui->tab_Objects); - selectedObject = current->getPixmapItem(); - QSignalBlocker b(this->ui->spinner_ObjectID); this->ui->spinner_ObjectID->setMinimum(event_offs); this->ui->spinner_ObjectID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1); @@ -2002,8 +1986,6 @@ void MainWindow::updateSelectedObjects() { target = ui->scrollAreaWidgetContents_Warps; ui->tabWidget_EventType->setCurrentWidget(ui->tab_Warps); - selectedWarp = current->getPixmapItem(); - QSignalBlocker b(this->ui->spinner_WarpID); this->ui->spinner_WarpID->setMinimum(event_offs); this->ui->spinner_WarpID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1); @@ -2015,8 +1997,6 @@ void MainWindow::updateSelectedObjects() { target = ui->scrollAreaWidgetContents_Triggers; ui->tabWidget_EventType->setCurrentWidget(ui->tab_Triggers); - selectedTrigger = current->getPixmapItem(); - QSignalBlocker b(this->ui->spinner_TriggerID); this->ui->spinner_TriggerID->setMinimum(event_offs); this->ui->spinner_TriggerID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1); @@ -2028,8 +2008,6 @@ void MainWindow::updateSelectedObjects() { target = ui->scrollAreaWidgetContents_BGs; ui->tabWidget_EventType->setCurrentWidget(ui->tab_BGs); - selectedBG = current->getPixmapItem(); - QSignalBlocker b(this->ui->spinner_BgID); this->ui->spinner_BgID->setMinimum(event_offs); this->ui->spinner_BgID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1); @@ -2041,8 +2019,6 @@ void MainWindow::updateSelectedObjects() { target = ui->scrollAreaWidgetContents_Healspots; ui->tabWidget_EventType->setCurrentWidget(ui->tab_Healspots); - selectedHealspot = current->getPixmapItem(); - QSignalBlocker b(this->ui->spinner_HealID); this->ui->spinner_HealID->setMinimum(event_offs); this->ui->spinner_HealID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1); @@ -2133,28 +2109,21 @@ Event::Group MainWindow::getEventGroupFromTabWidget(QWidget *tab) void MainWindow::eventTabChanged(int index) { if (editor->map) { Event::Group group = getEventGroupFromTabWidget(ui->tabWidget_EventType->widget(index)); - DraggablePixmapItem *selectedEvent = nullptr; + DraggablePixmapItem *selectedEvent = this->lastSelectedEvent.value(group, nullptr); switch (group) { case Event::Group::Object: - selectedEvent = selectedObject; ui->newEventToolButton->setDefaultAction(ui->newEventToolButton->newObjectAction); break; case Event::Group::Warp: - selectedEvent = selectedWarp; ui->newEventToolButton->setDefaultAction(ui->newEventToolButton->newWarpAction); break; case Event::Group::Coord: - selectedEvent = selectedTrigger; ui->newEventToolButton->setDefaultAction(ui->newEventToolButton->newTriggerAction); break; case Event::Group::Bg: - selectedEvent = selectedBG; ui->newEventToolButton->setDefaultAction(ui->newEventToolButton->newSignAction); break; - case Event::Group::Heal: - selectedEvent = selectedHealspot; - break; default: break; }