Skip to content

Commit

Permalink
Fix event group tab selection
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Jan 3, 2024
1 parent a0069b6 commit 0b2a526
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,7 @@ private slots:
QWidget *eventTabBGWidget;
QWidget *eventTabHealspotWidget;
QWidget *eventTabMultipleWidget;

DraggablePixmapItem *selectedObject;
DraggablePixmapItem *selectedWarp;
DraggablePixmapItem *selectedTrigger;
DraggablePixmapItem *selectedBG;
DraggablePixmapItem *selectedHealspot;
QMap<Event::Group, DraggablePixmapItem*> lastSelectedEvent;

bool isProgrammaticEventTabChange;
bool projectHasUnsavedChanges;
Expand Down
2 changes: 1 addition & 1 deletion src/core/metatile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
47 changes: 8 additions & 39 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -1929,24 +1925,11 @@ void MainWindow::displayEventTabs() {

void MainWindow::updateObjects() {
QList<DraggablePixmapItem *> 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();
}

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

0 comments on commit 0b2a526

Please sign in to comment.