Tabbed events mostly working

This commit is contained in:
Diegoisawesome 2018-11-29 21:59:03 -06:00
parent f0b74ada93
commit 68905aae1c
4 changed files with 150 additions and 55 deletions

View file

@ -84,11 +84,40 @@
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QLabel" name="label_name"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="text"> <item>
<string>Object 1</string> <widget class="QSpinBox" name="spinBox_index">
</property> <property name="sizePolicy">
</widget> <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="toolTip">
<string>The index of the event currently being inspected.</string>
</property>
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_name">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Object 1</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">

View file

@ -1467,7 +1467,7 @@
<item row="2" column="0"> <item row="2" column="0">
<widget class="QTabWidget" name="tabWidget_EventType"> <widget class="QTabWidget" name="tabWidget_EventType">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>5</number>
</property> </property>
<widget class="QWidget" name="tab_Objects"> <widget class="QWidget" name="tab_Objects">
<attribute name="title"> <attribute name="title">
@ -1668,6 +1668,12 @@
</property> </property>
<item> <item>
<widget class="QScrollArea" name="scrollArea_Multiple"> <widget class="QScrollArea" name="scrollArea_Multiple">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="widgetResizable"> <property name="widgetResizable">
<bool>true</bool> <bool>true</bool>
</property> </property>

View file

@ -136,6 +136,8 @@ private slots:
void eventTabChanged(int index); void eventTabChanged(int index);
void selectedEventIndexChanged(int index);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
TilesetEditor *tilesetEditor = nullptr; TilesetEditor *tilesetEditor = nullptr;
@ -195,6 +197,7 @@ private:
void loadUserSettings(); void loadUserSettings();
void openRecentProject(); void openRecentProject();
void updateTilesetEditor(); void updateTilesetEditor();
QString getEventGroupFromTabWidget(QWidget *tab);
bool isProjectOpen(); bool isProjectOpen();
}; };

View file

@ -1007,12 +1007,16 @@ void MainWindow::updateSelectedObjects() {
if (event_type == "event_warp") { event_offs = 0; } if (event_type == "event_warp") { event_offs = 0; }
else { event_offs = 1; } else { event_offs = 1; }
frame->ui->label_name->setText( frame->ui->label_name->setText(
QString("%1: %2 %3") QString("%1 %2")
.arg(editor->project->getMap(map_name)->events.value(event_group_type).indexOf(item->event) + event_offs)
.arg(map_name) .arg(map_name)
.arg(event_type) .arg(event_type)
); );
frame->ui->spinBox_index->setValue(editor->project->getMap(map_name)->events.value(event_group_type).indexOf(item->event) + event_offs);
frame->ui->spinBox_index->setMinimum(event_offs);
frame->ui->spinBox_index->setMaximum(editor->project->getMap(map_name)->events.value(event_group_type).length() + event_offs - 1);
connect(frame->ui->spinBox_index, QOverload<int>::of(&QSpinBox::valueChanged), this, &MainWindow::selectedEventIndexChanged);
frame->ui->label_spritePixmap->setPixmap(item->event->pixmap); frame->ui->label_spritePixmap->setPixmap(item->event->pixmap);
connect(item, SIGNAL(spriteChanged(QPixmap)), frame->ui->label_spritePixmap, SLOT(setPixmap(QPixmap))); connect(item, SIGNAL(spriteChanged(QPixmap)), frame->ui->label_spritePixmap, SLOT(setPixmap(QPixmap)));
@ -1194,37 +1198,41 @@ void MainWindow::updateSelectedObjects() {
//int scroll = ui->scrollArea_4->verticalScrollBar()->value(); //int scroll = ui->scrollArea_4->verticalScrollBar()->value();
QScrollArea *scrollTarget = ui->scrollArea_Multiple;
QWidget *target = ui->scrollAreaWidgetContents_Multiple; QWidget *target = ui->scrollAreaWidgetContents_Multiple;
isProgrammaticEventTabChange = true;
if (events->length() == 1) if (events->length() == 1)
{ {
QString event_type = (*events)[0]->event->get("event_type"); QString event_group_type = (*events)[0]->event->get("event_group_type");
isProgrammaticEventTabChange = true; if (event_group_type == "object_event_group") {
scrollTarget = ui->scrollArea_Objects;
if (event_type == EventType::Object) {
target = ui->scrollAreaWidgetContents_Objects; target = ui->scrollAreaWidgetContents_Objects;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Objects); ui->tabWidget_EventType->setCurrentWidget(ui->tab_Objects);
} }
else if (event_type == EventType::Warp) { else if (event_group_type == "warp_event_group") {
scrollTarget = ui->scrollArea_Warps;
target = ui->scrollAreaWidgetContents_Warps; target = ui->scrollAreaWidgetContents_Warps;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Warps); ui->tabWidget_EventType->setCurrentWidget(ui->tab_Warps);
} }
else if (event_type == EventType::CoordScript || event_type == EventType::CoordWeather) { else if (event_group_type == "coord_event_group") {
scrollTarget = ui->scrollArea_Triggers;
target = ui->scrollAreaWidgetContents_Triggers; target = ui->scrollAreaWidgetContents_Triggers;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Triggers); ui->tabWidget_EventType->setCurrentWidget(ui->tab_Triggers);
} }
else if (event_type == EventType::Sign || event_type == EventType::HiddenItem || event_type == EventType::SecretBase) { else if (event_group_type == "bg_event_group") {
scrollTarget = ui->scrollArea_BGs;
target = ui->scrollAreaWidgetContents_BGs; target = ui->scrollAreaWidgetContents_BGs;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_BGs); ui->tabWidget_EventType->setCurrentWidget(ui->tab_BGs);
} }
else if (event_type == EventType::HealLocation) { else if (event_group_type == "heal_event_group") {
scrollTarget = ui->scrollArea_Healspots;
target = ui->scrollAreaWidgetContents_Healspots; target = ui->scrollAreaWidgetContents_Healspots;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Healspots); ui->tabWidget_EventType->setCurrentWidget(ui->tab_Healspots);
} }
ui->tabWidget_EventType->removeTab(ui->tabWidget_EventType->indexOf(ui->tab_Multiple)); ui->tabWidget_EventType->removeTab(ui->tabWidget_EventType->indexOf(ui->tab_Multiple));
isProgrammaticEventTabChange = false;
} }
else if (events->length() > 1) else if (events->length() > 1)
{ {
@ -1232,16 +1240,24 @@ void MainWindow::updateSelectedObjects() {
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Multiple); ui->tabWidget_EventType->setCurrentWidget(ui->tab_Multiple);
} }
isProgrammaticEventTabChange = false;
if (events->length() != 0) if (events->length() != 0)
{ {
if (target->children().length()) { if (target->children().length())
qDeleteAll(target->children()); {
for (QObject *obj : target->children())
{
obj->deleteLater();
}
delete target->layout();
} }
QVBoxLayout *layout = new QVBoxLayout(target); QVBoxLayout *layout = new QVBoxLayout(target);
target->setLayout(layout); target->setLayout(layout);
//ui->scrollArea_4->setWidgetResizable(true); scrollTarget->setWidgetResizable(true);
//ui->scrollArea_4->setWidget(target); scrollTarget->setWidget(target);
for (EventPropertiesFrame *frame : frames) { for (EventPropertiesFrame *frame : frames) {
layout->addWidget(frame); layout->addWidget(frame);
@ -1263,22 +1279,47 @@ void MainWindow::updateSelectedObjects() {
} }
} }
QString MainWindow::getEventGroupFromTabWidget(QWidget *tab)
{
QString ret = "";
if (tab == eventTabObjectWidget)
{
ret = "object_event_group";
}
else if (tab == eventTabWarpWidget)
{
ret = "warp_event_group";
}
else if (tab == eventTabTriggerWidget)
{
ret = "coord_event_group";
}
else if (tab == eventTabBGWidget)
{
ret = "bg_event_group";
}
else if (tab == eventTabHealspotWidget)
{
ret = "heal_event_group";
}
return ret;
}
void MainWindow::eventTabChanged(int index) void MainWindow::eventTabChanged(int index)
{ {
if (!isProgrammaticEventTabChange && editor->map != nullptr) if (!isProgrammaticEventTabChange && editor->map != nullptr)
{ {
QWidget *tab = ui->tabWidget_EventType->widget(index); QString group = getEventGroupFromTabWidget(ui->tabWidget_EventType->widget(index));
DraggablePixmapItem *selectedEvent = nullptr; DraggablePixmapItem *selectedEvent = nullptr;
if (tab == eventTabObjectWidget) if (group == "object_event_group")
{ {
if (selectedObject == nullptr) if (selectedObject == nullptr)
{ {
for (DraggablePixmapItem *item : *editor->getObjects()) Event *event = editor->map->events.value(group).at(0);
{ for (QGraphicsItem *child : editor->events_group->childItems()) {
QString event_type = item->event->get("event_type"); DraggablePixmapItem *item = static_cast<DraggablePixmapItem *>(child);
if (event_type == EventType::Object) if (item->event == event) {
{
selectedObject = item; selectedObject = item;
break; break;
} }
@ -1287,15 +1328,14 @@ void MainWindow::eventTabChanged(int index)
selectedEvent = selectedObject; selectedEvent = selectedObject;
} }
else if (tab == eventTabWarpWidget) else if (group == "warp_event_group")
{ {
if (selectedWarp == nullptr) if (selectedWarp == nullptr)
{ {
for (DraggablePixmapItem *item : *editor->getObjects()) Event *event = editor->map->events.value(group).at(0);
{ for (QGraphicsItem *child : editor->events_group->childItems()) {
QString event_type = item->event->get("event_type"); DraggablePixmapItem *item = static_cast<DraggablePixmapItem *>(child);
if (event_type == EventType::Warp) if (item->event == event) {
{
selectedWarp = item; selectedWarp = item;
break; break;
} }
@ -1304,15 +1344,14 @@ void MainWindow::eventTabChanged(int index)
selectedEvent = selectedWarp; selectedEvent = selectedWarp;
} }
else if (tab == eventTabTriggerWidget) else if (group == "coord_event_group")
{ {
if (selectedTrigger == nullptr) if (selectedTrigger == nullptr)
{ {
for (DraggablePixmapItem *item : *editor->getObjects()) Event *event = editor->map->events.value(group).at(0);
{ for (QGraphicsItem *child : editor->events_group->childItems()) {
QString event_type = item->event->get("event_type"); DraggablePixmapItem *item = static_cast<DraggablePixmapItem *>(child);
if (event_type == EventType::CoordScript || event_type == EventType::CoordWeather) if (item->event == event) {
{
selectedTrigger = item; selectedTrigger = item;
break; break;
} }
@ -1321,15 +1360,14 @@ void MainWindow::eventTabChanged(int index)
selectedEvent = selectedTrigger; selectedEvent = selectedTrigger;
} }
else if (tab == eventTabBGWidget) else if (group == "bg_event_group")
{ {
if (selectedBG == nullptr) if (selectedBG == nullptr)
{ {
for (DraggablePixmapItem *item : *editor->getObjects()) Event *event = editor->map->events.value(group).at(0);
{ for (QGraphicsItem *child : editor->events_group->childItems()) {
QString event_type = item->event->get("event_type"); DraggablePixmapItem *item = static_cast<DraggablePixmapItem *>(child);
if (event_type == EventType::Sign || event_type == EventType::HiddenItem || event_type == EventType::SecretBase) if (item->event == event) {
{
selectedBG = item; selectedBG = item;
break; break;
} }
@ -1338,15 +1376,14 @@ void MainWindow::eventTabChanged(int index)
selectedEvent = selectedBG; selectedEvent = selectedBG;
} }
else if (tab == eventTabHealspotWidget) else if (group == "heal_event_group")
{ {
if (selectedHealspot == nullptr) if (selectedHealspot == nullptr)
{ {
for (DraggablePixmapItem *item : *editor->getObjects()) Event *event = editor->map->events.value(group).at(0);
{ for (QGraphicsItem *child : editor->events_group->childItems()) {
QString event_type = item->event->get("event_type"); DraggablePixmapItem *item = static_cast<DraggablePixmapItem *>(child);
if (event_type == EventType::HealLocation) if (item->event == event) {
{
selectedHealspot = item; selectedHealspot = item;
break; break;
} }
@ -1356,19 +1393,39 @@ void MainWindow::eventTabChanged(int index)
selectedEvent = selectedHealspot; selectedEvent = selectedHealspot;
} }
if (selectedObject != nullptr) if (selectedEvent != nullptr)
editor->selectMapEvent(selectedEvent); editor->selectMapEvent(selectedEvent);
} }
isProgrammaticEventTabChange = false; isProgrammaticEventTabChange = false;
} }
void MainWindow::selectedEventIndexChanged(int index)
{
QString group = getEventGroupFromTabWidget(ui->tabWidget_EventType->currentWidget());
int event_offs;
if (group == "warp_event_group") { event_offs = 0; }
else { event_offs = 1; }
Event *event = editor->map->events.value(group).at(index - event_offs);
DraggablePixmapItem *selectedEvent = nullptr;
for (QGraphicsItem *child : editor->events_group->childItems()) {
DraggablePixmapItem *item = static_cast<DraggablePixmapItem *>(child);
if (item->event == event) {
selectedEvent = item;
break;
}
}
if (selectedEvent != nullptr)
editor->selectMapEvent(selectedEvent);
}
void MainWindow::on_toolButton_deleteObject_clicked() void MainWindow::on_toolButton_deleteObject_clicked()
{ {
if (editor && editor->selected_events) { if (editor && editor->selected_events) {
if (editor->selected_events->length()) { if (editor->selected_events->length()) {
for (DraggablePixmapItem *item : *editor->selected_events) { for (DraggablePixmapItem *item : *editor->selected_events) {
if (item->event->get("event_type") != EventType::HealLocation) { if (item->event->get("event_group_type") != "heal_event_group") {
editor->deleteEvent(item->event); editor->deleteEvent(item->event);
if (editor->scene->items().contains(item)) { if (editor->scene->items().contains(item)) {
editor->scene->removeItem(item); editor->scene->removeItem(item);