From 228b646b0ecd12804d8602e9f52ef8b7aadbfc39 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Sun, 20 Jan 2019 10:42:01 -0600 Subject: [PATCH] Change trainer checkbox to a combobox --- include/editor.h | 6 ++++++ src/core/event.cpp | 4 ++-- src/mainwindow.cpp | 40 ++++++++++++++++++++++------------------ src/project.cpp | 2 +- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/include/editor.h b/include/editor.h index 510d942e..57131830 100644 --- a/include/editor.h +++ b/include/editor.h @@ -233,6 +233,12 @@ public: } }); } + void bindToUserData(QComboBox *combo, QString key) { + connect(combo, static_cast(&QComboBox::currentIndexChanged), + this, [this, combo, key](int index) { + this->event->put(key, combo->itemData(index).toString()); + }); + } signals: void positionChanged(Event *event); diff --git a/src/core/event.cpp b/src/core/event.cpp index 30eda083..c24f5bee 100644 --- a/src/core/event.cpp +++ b/src/core/event.cpp @@ -56,7 +56,7 @@ Event* Event::createNewObjectEvent() event->put("script_label", "NULL"); event->put("event_flag", "0"); event->put("replacement", "0"); - event->put("is_trainer", "FALSE"); + event->put("trainer_type", "0"); event->put("sight_radius_tree_id", 0); return event; } @@ -156,7 +156,7 @@ QString Event::buildObjectEventMacro(int item_index) text += QString(", %1").arg(this->get("movement_type")); text += QString(", %1").arg(radius_x); text += QString(", %1").arg(radius_y); - text += QString(", %1").arg(this->get("is_trainer")); + text += QString(", %1").arg(this->get("trainer_type")); text += QString(", %1").arg(this->get("sight_radius_tree_id")); text += QString(", %1").arg(this->get("script_label")); text += QString(", %1").arg(this->get("event_flag")); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8759c319..99174263 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1194,7 +1194,7 @@ void MainWindow::updateSelectedObjects() { field_labels["movement_type"] = "Movement"; field_labels["radius_x"] = "Movement Radius X"; field_labels["radius_y"] = "Movement Radius Y"; - field_labels["is_trainer"] = "Trainer"; + field_labels["trainer_type"] = "Trainer Type"; field_labels["sight_radius_tree_id"] = "Sight Radius / Berry Tree ID"; field_labels["destination_warp"] = "Destination Warp"; field_labels["destination_map_name"] = "Destination Map"; @@ -1232,7 +1232,7 @@ void MainWindow::updateSelectedObjects() { fields << "radius_y"; fields << "script_label"; fields << "event_flag"; - fields << "is_trainer"; + fields << "trainer_type"; fields << "sight_radius_tree_id"; } else if (event_type == EventType::Warp) { @@ -1266,25 +1266,29 @@ void MainWindow::updateSelectedObjects() { fl->setContentsMargins(9, 0, 9, 0); fl->setRowWrapPolicy(QFormLayout::WrapLongRows); - // is_trainer is the only non-combobox item. - if (key == "is_trainer") { - QCheckBox *checkbox = new QCheckBox(widget); - checkbox->setEnabled(true); - checkbox->setChecked(value.toInt() != 0 && value != "FALSE"); - checkbox->setToolTip("Whether or not this object is trainer."); - fl->addRow(new QLabel(field_labels[key], widget), checkbox); - widget->setLayout(fl); - frame->layout()->addWidget(widget); - connect(checkbox, &QCheckBox::stateChanged, [=](int state) { - QString isTrainer = state == Qt::Checked ? "TRUE" : "FALSE"; - item->event->put("is_trainer", isTrainer); - }); - continue; - } - NoScrollComboBox *combo = new NoScrollComboBox(widget); combo->setEditable(true); + // trainer_type has custom values, so it has special signal logic. + if (key == "trainer_type") { + combo->setEditable(false); + combo->addItem("NONE", "0"); + combo->addItem("NORMAL", "1"); + combo->addItem("SEE ALL DIRECTIONS", "3"); + combo->setToolTip("The trainer type of this event object. If it is not a trainer, use NONE. SEE ALL DIRECTIONS should only be used with a sight radius of 1."); + + int index = combo->findData(value); + if (index != -1) { + combo->setCurrentIndex(index); + } + + fl->addRow(new QLabel(field_labels[key], widget), combo); + widget->setLayout(fl); + frame->layout()->addWidget(widget); + item->bindToUserData(combo, key); + continue; + } + if (key == "destination_map_name") { if (!editor->project->mapNames->contains(value)) { combo->addItem(value); diff --git a/src/project.cpp b/src/project.cpp index 84d77da6..a95d42a0 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1775,7 +1775,7 @@ void Project::readMapEvents(Map *map) { object->put("movement_type", command.value(i++)); object->put("radius_x", command.value(i++).toInt(nullptr, 0)); object->put("radius_y", command.value(i++).toInt(nullptr, 0)); - object->put("is_trainer", command.value(i++)); + object->put("trainer_type", command.value(i++)); object->put("sight_radius_tree_id", command.value(i++)); object->put("script_label", command.value(i++)); object->put("event_flag", command.value(i++));