Skip to content

Commit

Permalink
Fix group Event selections not clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Aug 21, 2024
1 parent 2f24d45 commit baaf9c8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 55 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
- Fix config files being written before the project is opened successfully.
- Fix the map and other project info still displaying if a new project fails to open.
- Fix unsaved changes being ignored when quitting (such as with Cmd+Q on macOS).
- Fix selections with multiple Events not always clearing when making a new selection.
- Fix `About porymap` opening a new window each time it's activated.
- Fix the `Edit History` window not raising to the front when reactivated.

Expand Down
8 changes: 1 addition & 7 deletions include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private slots:
void on_toolButton_deleteObject_clicked();

void addNewEvent(Event::Type type);
void tryAddEventTab(QWidget * tab, Event::Group group);
void tryAddEventTab(QWidget * tab);
void displayEventTabs();
void updateSelectedObjects();
void updateObjects();
Expand Down Expand Up @@ -328,12 +328,6 @@ private slots:
QAction *copyAction = nullptr;
QAction *pasteAction = nullptr;

QWidget *eventTabObjectWidget;
QWidget *eventTabWarpWidget;
QWidget *eventTabTriggerWidget;
QWidget *eventTabBGWidget;
QWidget *eventTabHealspotWidget;
QWidget *eventTabMultipleWidget;
QMap<Event::Group, DraggablePixmapItem*> lastSelectedEvent;

bool isProgrammaticEventTabChange;
Expand Down
30 changes: 18 additions & 12 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2116,19 +2116,25 @@ void Editor::selectMapEvent(DraggablePixmapItem *object) {
}

void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) {
if (selected_events && object) {
if (selected_events->contains(object)) {
if (toggle) {
selected_events->removeOne(object);
}
} else {
if (!toggle) {
selected_events->clear();
}
selected_events->append(object);
}
updateSelectedEvents();
if (!selected_events || !object)
return;

if (!toggle) {
// Selecting just this event
selected_events->clear();
selected_events->append(object);
} else if (!selected_events->contains(object)) {
// Adding event to selection
selected_events->append(object);
} else if (selected_events->length() > 1) {
// Removing from group selection
selected_events->removeOne(object);
} else {
// Attempting to toggle the only currently-selected event.
// Unselecting an event this way would be unexpected, so we ignore it.
return;
}
updateSelectedEvents();
}

void Editor::selectedEventIndexChanged(int index, Event::Group eventGroup) {
Expand Down
52 changes: 16 additions & 36 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,6 @@ void MainWindow::initMiscHeapObjects() {
mapListProxyModel->setSourceModel(mapListModel);
ui->mapList->setModel(mapListProxyModel);

eventTabObjectWidget = ui->tab_Objects;
eventTabWarpWidget = ui->tab_Warps;
eventTabTriggerWidget = ui->tab_Triggers;
eventTabBGWidget = ui->tab_BGs;
eventTabHealspotWidget = ui->tab_Healspots;
eventTabMultipleWidget = ui->tab_Multiple;
ui->tabWidget_EventType->clear();
}

Expand Down Expand Up @@ -1977,7 +1971,8 @@ void MainWindow::addNewEvent(Event::Type type) {
}
}

void MainWindow::tryAddEventTab(QWidget * tab, Event::Group group) {
void MainWindow::tryAddEventTab(QWidget * tab) {
auto group = getEventGroupFromTabWidget(tab);
if (editor->map->events.value(group).length())
ui->tabWidget_EventType->addTab(tab, QString("%1s").arg(Event::eventGroupToString(group)));
}
Expand All @@ -1986,11 +1981,11 @@ void MainWindow::displayEventTabs() {
const QSignalBlocker blocker(ui->tabWidget_EventType);

ui->tabWidget_EventType->clear();
tryAddEventTab(eventTabObjectWidget, Event::Group::Object);
tryAddEventTab(eventTabWarpWidget, Event::Group::Warp);
tryAddEventTab(eventTabTriggerWidget, Event::Group::Coord);
tryAddEventTab(eventTabBGWidget, Event::Group::Bg);
tryAddEventTab(eventTabHealspotWidget, Event::Group::Heal);
tryAddEventTab(ui->tab_Objects);
tryAddEventTab(ui->tab_Warps);
tryAddEventTab(ui->tab_Triggers);
tryAddEventTab(ui->tab_BGs);
tryAddEventTab(ui->tab_Healspots);
}

void MainWindow::updateObjects() {
Expand Down Expand Up @@ -2150,30 +2145,15 @@ void MainWindow::updateSelectedObjects() {
}
}

Event::Group MainWindow::getEventGroupFromTabWidget(QWidget *tab)
{
Event::Group ret = Event::Group::None;
if (tab == eventTabObjectWidget)
{
ret = Event::Group::Object;
}
else if (tab == eventTabWarpWidget)
{
ret = Event::Group::Warp;
}
else if (tab == eventTabTriggerWidget)
{
ret = Event::Group::Coord;
}
else if (tab == eventTabBGWidget)
{
ret = Event::Group::Bg;
}
else if (tab == eventTabHealspotWidget)
{
ret = Event::Group::Heal;
}
return ret;
Event::Group MainWindow::getEventGroupFromTabWidget(QWidget *tab) {
static const QMap<QWidget*,Event::Group> tabToGroup = {
{ui->tab_Objects, Event::Group::Object},
{ui->tab_Warps, Event::Group::Warp},
{ui->tab_Triggers, Event::Group::Coord},
{ui->tab_BGs, Event::Group::Bg},
{ui->tab_Healspots, Event::Group::Heal},
};
return tabToGroup.value(tab, Event::Group::None);
}

void MainWindow::eventTabChanged(int index) {
Expand Down

0 comments on commit baaf9c8

Please sign in to comment.