Change trainer checkbox to a combobox

This commit is contained in:
Marcus Huderle 2019-01-20 10:42:01 -06:00
parent 2f21465d8d
commit 228b646b0e
4 changed files with 31 additions and 21 deletions

View file

@ -233,6 +233,12 @@ public:
} }
}); });
} }
void bindToUserData(QComboBox *combo, QString key) {
connect(combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, [this, combo, key](int index) {
this->event->put(key, combo->itemData(index).toString());
});
}
signals: signals:
void positionChanged(Event *event); void positionChanged(Event *event);

View file

@ -56,7 +56,7 @@ Event* Event::createNewObjectEvent()
event->put("script_label", "NULL"); event->put("script_label", "NULL");
event->put("event_flag", "0"); event->put("event_flag", "0");
event->put("replacement", "0"); event->put("replacement", "0");
event->put("is_trainer", "FALSE"); event->put("trainer_type", "0");
event->put("sight_radius_tree_id", 0); event->put("sight_radius_tree_id", 0);
return event; return event;
} }
@ -156,7 +156,7 @@ QString Event::buildObjectEventMacro(int item_index)
text += QString(", %1").arg(this->get("movement_type")); text += QString(", %1").arg(this->get("movement_type"));
text += QString(", %1").arg(radius_x); text += QString(", %1").arg(radius_x);
text += QString(", %1").arg(radius_y); 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("sight_radius_tree_id"));
text += QString(", %1").arg(this->get("script_label")); text += QString(", %1").arg(this->get("script_label"));
text += QString(", %1").arg(this->get("event_flag")); text += QString(", %1").arg(this->get("event_flag"));

View file

@ -1194,7 +1194,7 @@ void MainWindow::updateSelectedObjects() {
field_labels["movement_type"] = "Movement"; field_labels["movement_type"] = "Movement";
field_labels["radius_x"] = "Movement Radius X"; field_labels["radius_x"] = "Movement Radius X";
field_labels["radius_y"] = "Movement Radius Y"; 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["sight_radius_tree_id"] = "Sight Radius / Berry Tree ID";
field_labels["destination_warp"] = "Destination Warp"; field_labels["destination_warp"] = "Destination Warp";
field_labels["destination_map_name"] = "Destination Map"; field_labels["destination_map_name"] = "Destination Map";
@ -1232,7 +1232,7 @@ void MainWindow::updateSelectedObjects() {
fields << "radius_y"; fields << "radius_y";
fields << "script_label"; fields << "script_label";
fields << "event_flag"; fields << "event_flag";
fields << "is_trainer"; fields << "trainer_type";
fields << "sight_radius_tree_id"; fields << "sight_radius_tree_id";
} }
else if (event_type == EventType::Warp) { else if (event_type == EventType::Warp) {
@ -1266,25 +1266,29 @@ void MainWindow::updateSelectedObjects() {
fl->setContentsMargins(9, 0, 9, 0); fl->setContentsMargins(9, 0, 9, 0);
fl->setRowWrapPolicy(QFormLayout::WrapLongRows); 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); NoScrollComboBox *combo = new NoScrollComboBox(widget);
combo->setEditable(true); 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 (key == "destination_map_name") {
if (!editor->project->mapNames->contains(value)) { if (!editor->project->mapNames->contains(value)) {
combo->addItem(value); combo->addItem(value);

View file

@ -1775,7 +1775,7 @@ void Project::readMapEvents(Map *map) {
object->put("movement_type", command.value(i++)); object->put("movement_type", command.value(i++));
object->put("radius_x", command.value(i++).toInt(nullptr, 0)); object->put("radius_x", command.value(i++).toInt(nullptr, 0));
object->put("radius_y", 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("sight_radius_tree_id", command.value(i++));
object->put("script_label", command.value(i++)); object->put("script_label", command.value(i++));
object->put("event_flag", command.value(i++)); object->put("event_flag", command.value(i++));