event updates

- select first event in order of tabs and lowest index
  (prev: select top left event)
- maintain current event selection between tab changes
This commit is contained in:
garak 2022-10-16 18:37:51 -04:00
parent dfb6a15379
commit 3f2fea0980
2 changed files with 67 additions and 31 deletions

View file

@ -2034,7 +2034,10 @@ void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) {
void Editor::selectedEventIndexChanged(int index, Event::Group eventGroup) void Editor::selectedEventIndexChanged(int index, Event::Group eventGroup)
{ {
int event_offs = Event::getIndexOffset(eventGroup); int event_offs = Event::getIndexOffset(eventGroup);
Event *event = this->map->events.value(eventGroup).at(index - event_offs); Event *event = nullptr;
if (index < this->map->events.value(eventGroup).length()) {
event = this->map->events.value(eventGroup).at(index - event_offs);
}
DraggablePixmapItem *selectedEvent = nullptr; DraggablePixmapItem *selectedEvent = nullptr;
for (QGraphicsItem *child : this->events_group->childItems()) { for (QGraphicsItem *child : this->events_group->childItems()) {
DraggablePixmapItem *item = static_cast<DraggablePixmapItem *>(child); DraggablePixmapItem *item = static_cast<DraggablePixmapItem *>(child);
@ -2044,7 +2047,11 @@ void Editor::selectedEventIndexChanged(int index, Event::Group eventGroup)
} }
} }
if (selectedEvent) this->selectMapEvent(selectedEvent); if (selectedEvent) {
this->selectMapEvent(selectedEvent);
} else {
updateSelectedEvents();
}
} }
void Editor::duplicateSelectedEvents() { void Editor::duplicateSelectedEvents() {

View file

@ -1934,11 +1934,22 @@ void MainWindow::displayEventTabs() {
} }
void MainWindow::updateObjects() { void MainWindow::updateObjects() {
QList<DraggablePixmapItem *> all_objects = editor->getObjects();
if (selectedObject && !all_objects.contains(selectedObject)) {
selectedObject = nullptr; selectedObject = nullptr;
}
if (selectedWarp && !all_objects.contains(selectedWarp)) {
selectedWarp = nullptr; selectedWarp = nullptr;
}
if (selectedTrigger && !all_objects.contains(selectedTrigger)) {
selectedTrigger = nullptr; selectedTrigger = nullptr;
}
if (selectedBG && !all_objects.contains(selectedBG)) {
selectedBG = nullptr; selectedBG = nullptr;
}
if (selectedHealspot && !all_objects.contains(selectedHealspot)) {
selectedHealspot = nullptr; selectedHealspot = nullptr;
}
displayEventTabs(); displayEventTabs();
@ -1953,13 +1964,19 @@ void MainWindow::updateSelectedObjects() {
events = *editor->selected_events; events = *editor->selected_events;
} }
else { else {
QList<Event *> all_events;
if (editor->map) {
all_events = editor->map->getAllEvents();
}
if (all_events.length()) { if (all_events.length()) {
DraggablePixmapItem *selectedEvent = all_events.first(); DraggablePixmapItem *selectedEvent = all_events.first()->getPixmapItem();
if (selectedEvent) {
editor->selected_events->append(selectedEvent); editor->selected_events->append(selectedEvent);
editor->redrawObject(selectedEvent); editor->redrawObject(selectedEvent);
events.append(selectedEvent); events.append(selectedEvent);
} }
} }
}
QScrollArea *scrollTarget = ui->scrollArea_Multiple; QScrollArea *scrollTarget = ui->scrollArea_Multiple;
QWidget *target = ui->scrollAreaWidgetContents_Multiple; QWidget *target = ui->scrollAreaWidgetContents_Multiple;
@ -1978,6 +1995,8 @@ void MainWindow::updateSelectedObjects() {
target = ui->scrollAreaWidgetContents_Objects; target = ui->scrollAreaWidgetContents_Objects;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Objects); ui->tabWidget_EventType->setCurrentWidget(ui->tab_Objects);
selectedObject = current->getPixmapItem();
this->ui->spinner_ObjectID->setMinimum(event_offs); this->ui->spinner_ObjectID->setMinimum(event_offs);
this->ui->spinner_ObjectID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1); this->ui->spinner_ObjectID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1);
this->ui->spinner_ObjectID->setValue(current->getEventIndex() + event_offs); this->ui->spinner_ObjectID->setValue(current->getEventIndex() + event_offs);
@ -1988,6 +2007,8 @@ void MainWindow::updateSelectedObjects() {
target = ui->scrollAreaWidgetContents_Warps; target = ui->scrollAreaWidgetContents_Warps;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Warps); ui->tabWidget_EventType->setCurrentWidget(ui->tab_Warps);
selectedWarp = current->getPixmapItem();
this->ui->spinner_WarpID->setMinimum(event_offs); this->ui->spinner_WarpID->setMinimum(event_offs);
this->ui->spinner_WarpID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1); this->ui->spinner_WarpID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1);
this->ui->spinner_WarpID->setValue(current->getEventIndex() + event_offs); this->ui->spinner_WarpID->setValue(current->getEventIndex() + event_offs);
@ -1998,6 +2019,8 @@ void MainWindow::updateSelectedObjects() {
target = ui->scrollAreaWidgetContents_Triggers; target = ui->scrollAreaWidgetContents_Triggers;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Triggers); ui->tabWidget_EventType->setCurrentWidget(ui->tab_Triggers);
selectedTrigger = current->getPixmapItem();
this->ui->spinner_TriggerID->setMinimum(event_offs); this->ui->spinner_TriggerID->setMinimum(event_offs);
this->ui->spinner_TriggerID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1); this->ui->spinner_TriggerID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1);
this->ui->spinner_TriggerID->setValue(current->getEventIndex() + event_offs); this->ui->spinner_TriggerID->setValue(current->getEventIndex() + event_offs);
@ -2008,6 +2031,8 @@ void MainWindow::updateSelectedObjects() {
target = ui->scrollAreaWidgetContents_BGs; target = ui->scrollAreaWidgetContents_BGs;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_BGs); ui->tabWidget_EventType->setCurrentWidget(ui->tab_BGs);
selectedBG = current->getPixmapItem();
this->ui->spinner_BgID->setMinimum(event_offs); this->ui->spinner_BgID->setMinimum(event_offs);
this->ui->spinner_BgID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1); this->ui->spinner_BgID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1);
this->ui->spinner_BgID->setValue(current->getEventIndex() + event_offs); this->ui->spinner_BgID->setValue(current->getEventIndex() + event_offs);
@ -2018,6 +2043,8 @@ void MainWindow::updateSelectedObjects() {
target = ui->scrollAreaWidgetContents_Healspots; target = ui->scrollAreaWidgetContents_Healspots;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Healspots); ui->tabWidget_EventType->setCurrentWidget(ui->tab_Healspots);
selectedHealspot = current->getPixmapItem();
this->ui->spinner_HealID->setMinimum(event_offs); this->ui->spinner_HealID->setMinimum(event_offs);
this->ui->spinner_HealID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1); this->ui->spinner_HealID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1);
this->ui->spinner_HealID->setValue(current->getEventIndex() + event_offs); this->ui->spinner_HealID->setValue(current->getEventIndex() + event_offs);
@ -2167,11 +2194,21 @@ void MainWindow::on_toolButton_deleteObject_clicked() {
for (DraggablePixmapItem *item : *editor->selected_events) { for (DraggablePixmapItem *item : *editor->selected_events) {
Event::Group event_group = item->event->getEventGroup(); Event::Group event_group = item->event->getEventGroup();
if (event_group != Event::Group::Heal) { if (event_group != Event::Group::Heal) {
numDeleted++;
item->event->setPixmapItem(item);
selectedEvents.append(item->event);
}
else { // don't allow deletion of heal locations
logWarn(QString("Cannot delete event of type '%1'").arg(Event::eventTypeToString(item->event->getEventType())));
}
}
if (numDeleted) {
// Get the index for the event that should be selected after this event has been deleted. // Get the index for the event that should be selected after this event has been deleted.
// If it's at the end of the list, select the previous event, otherwise select the next one. // Select event at next smallest index when deleting a single event.
// Don't bother getting the event to select if there are still more events to delete // If deleting multiple events, just let editor work out next selected.
if (++numDeleted == numEvents) { if (numDeleted == 1) {
int index = editor->map->events.value(event_group).indexOf(item->event); Event::Group event_group = selectedEvents[0]->getEventGroup();
int index = editor->map->events.value(event_group).indexOf(selectedEvents[0]);
if (index != editor->map->events.value(event_group).size() - 1) if (index != editor->map->events.value(event_group).size() - 1)
index++; index++;
else else
@ -2187,14 +2224,6 @@ void MainWindow::on_toolButton_deleteObject_clicked() {
} }
} }
} }
item->event->setPixmapItem(item);
selectedEvents.append(item->event);
}
else { // don't allow deletion of heal locations
logWarn(QString("Cannot delete event of type '%1'").arg(Event::eventTypeToString(item->event->getEventType())));
}
}
if (numDeleted) {
editor->map->editHistory.push(new EventDelete(editor, editor->map, selectedEvents, nextSelectedEvent ? nextSelectedEvent->event : nullptr)); editor->map->editHistory.push(new EventDelete(editor, editor->map, selectedEvents, nextSelectedEvent ? nextSelectedEvent->event : nullptr));
} }
} }