/** * @brief Initializes the sound field. */ void EditEntityDialog::initialize_sound() { QString field_name; if (entity_before.has_field(sound_field_name)) { field_name = sound_field_name; } else if (entity_before.has_field(destruction_sound_field_name)) { ui.sound_checkbox->setText(tr("Play a sound when destroyed")); field_name = destruction_sound_field_name; } else { remove_field(ui.sound_checkbox, ui.sound_field); return; } ui.sound_field->set_quest(get_quest()); ui.sound_field->set_resource_type(ResourceType::SOUND); initialize_possibly_optional_field( field_name, nullptr, nullptr, ui.sound_checkbox, ui.sound_field); QString sound = entity_before.get_field(field_name).toString(); ui.sound_field->set_selected_id(sound); }
/** * @brief Initializes the treasure field. */ void EditEntityDialog::initialize_treasure() { if (!entity_before.has_field(treasure_name_field_name) || !entity_before.has_field(treasure_variant_field_name) || !entity_before.has_field(treasure_savegame_variable_field_name) ) { remove_field(ui.treasure_label, ui.treasure_layout); return; } ui.treasure_name_field->set_quest(get_quest()); ui.treasure_name_field->set_resource_type(ResourceType::ITEM); ui.treasure_name_field->add_special_value("", tr("(None)"), 0); // Add the special value "None". // Only accept valid identifiers as savegame variable names. ui.treasure_savegame_variable_field->setValidator(create_savegame_variable_validator()); QString treasure_name = entity_before.get_field(treasure_name_field_name).toString(); ui.treasure_name_field->set_selected_id(treasure_name); ui.treasure_variant_field->setValue(entity_before.get_field(treasure_variant_field_name).toInt()); QString treasure_savegame_variable = entity_before.get_field(treasure_savegame_variable_field_name).toString(); if (treasure_savegame_variable.isEmpty()) { ui.treasure_savegame_variable_label->setEnabled(false); ui.treasure_savegame_variable_field->setEnabled(false); } else { ui.treasure_savegame_variable_field->setText(treasure_savegame_variable); ui.save_treasure_checkbox->setChecked(true); } connect(ui.save_treasure_checkbox, SIGNAL(toggled(bool)), ui.treasure_savegame_variable_label, SLOT(setEnabled(bool))); connect(ui.save_treasure_checkbox, SIGNAL(toggled(bool)), ui.treasure_savegame_variable_field, SLOT(setEnabled(bool))); }
/** * @brief Initializes the destination map field. */ void EditEntityDialog::initialize_destination_map() { if (!entity_before.has_field(destination_map_field_name)) { remove_field(ui.destination_map_label, ui.destination_map_field); return; } ui.destination_map_field->set_quest(get_quest()); ui.destination_map_field->set_resource_type(ResourceType::MAP); ui.destination_map_field->set_selected_id(entity_before.get_field(destination_map_field_name).toString()); connect(ui.destination_map_field, &QComboBox::currentTextChanged, [&](const QString&) { QString map_id = ui.destination_map_field->currentData().toString(); ui.destination_field->set_map_id(get_quest(), map_id); ui.destination_field->build(); }); }
/** * @brief Initializes the behavior fields. */ void EditEntityDialog::initialize_behavior() { if (!entity_before.has_field(behavior_field_name)) { remove_field(ui.behavior_label, ui.behavior_layout); return; } ui.behavior_item_field->set_quest(get_quest()); ui.behavior_item_field->set_resource_type(ResourceType::ITEM); ui.behavior_dialog_field->setEnabled(false); connect(ui.behavior_dialog_radio, SIGNAL(toggled(bool)), ui.behavior_dialog_field, SLOT(setEnabled(bool))); ui.behavior_item_field->setEnabled(false); connect(ui.behavior_item_radio, SIGNAL(toggled(bool)), ui.behavior_item_field, SLOT(setEnabled(bool))); QString behavior = entity_before.get_field(behavior_field_name).toString(); // behavior can be one of: // - "map", // - "dialog#xxx" where xxx is a dialog id, // - "item#xxx" where xxx is an item id. QStringList parts = behavior.split('#'); if (parts.size() == 2) { QString first = parts.at(0); if (first == "dialog") { // Show a dialog. QString dialog_id = parts.at(1); ui.behavior_dialog_radio->setChecked(true); ui.behavior_dialog_field->setText(dialog_id); ui.behavior_dialog_field->setEnabled(true); } else if (first == "item") { // Call an item script. QString item_id = parts.at(1); ui.behavior_item_radio->setChecked(true); ui.behavior_item_field->set_selected_id(item_id); ui.behavior_item_field->setEnabled(true); } else { // The field is invalid: initialize the dialog with "map". behavior = "map"; } } else if (behavior != "map") { // The field is invalid: initialize the dialog with "map". behavior = "map"; } if (behavior == "map") { // Call the map script. ui.behavior_map_radio->setChecked(true); } }
int init_escort(object me, int exp) { object *team, escortee; int i; // 设置路线 get_quest(query("route")); // 设置escorter/escortee关系 team = me->query_team(); if (!team || !sizeof(team)) { team=({me});
/** * @brief Initializes the breed field. */ void EditEntityDialog::initialize_breed() { if (!entity_before.has_field(breed_field_name)) { remove_field(ui.breed_label, ui.breed_field); return; } ui.breed_field->set_quest(get_quest()); ui.breed_field->set_resource_type(ResourceType::ENEMY); QString breed = entity_before.get_field(breed_field_name).toString(); ui.breed_field->set_selected_id(breed); }
/** * @brief Initializes the font field. */ void EditEntityDialog::initialize_font() { if (!entity_before.has_field(font_field_name)) { remove_field(ui.font_label, ui.font_field); return; } ui.font_field->set_quest(get_quest()); ui.font_field->set_resource_type(ResourceType::FONT); ui.font_field->add_special_value("", tr("(Default)"), 0); QString font = entity_before.get_field(font_field_name).toString(); ui.font_field->set_selected_id(font); }
/** * @brief Initializes the destination field. */ void EditEntityDialog::initialize_destination() { if (!entity_before.has_field(destination_field_name)) { remove_field(ui.destination_label, ui.destination_field); return; } QString destination_map_id = entity_before.get_field(destination_map_field_name).toString(); ui.destination_field->set_map_id(get_quest(), destination_map_id); ui.destination_field->set_filtered_by_entity_type(true); ui.destination_field->set_entity_type_filter(EntityType::DESTINATION); ui.destination_field->add_special_value("", tr("(Default destination)")); ui.destination_field->add_special_value("_same", tr("(Same point)")); ui.destination_field->add_special_value("_side", tr("(Side of the map)")); ui.destination_field->build(); ui.destination_field->set_selected_name(entity_before.get_field(destination_field_name).toString()); }
/** * @brief Initializes the model field. */ void EditEntityDialog::initialize_model() { if (!entity_before.has_field(model_field_name)) { remove_field(ui.model_checkbox, ui.model_field); return; } initialize_possibly_optional_field( model_field_name, nullptr, nullptr, ui.model_checkbox, ui.model_field); ui.model_field->set_quest(get_quest()); ui.model_field->set_resource_type(ResourceType::ENTITY); QString model = entity_before.get_field(model_field_name).toString(); ui.model_field->set_selected_id(model); }
/** * @brief Initializes the sprite field. */ void EditEntityDialog::initialize_sprite() { if (!entity_before.has_field(sprite_field_name)) { remove_field(ui.sprite_label_checkbox, ui.sprite_field); return; } initialize_possibly_optional_field( sprite_field_name, ui.sprite_label_checkbox->layout(), ui.sprite_label, ui.sprite_checkbox, ui.sprite_field); ui.sprite_field->set_resource_type(ResourceType::SPRITE); ui.sprite_field->set_quest(get_quest()); ui.sprite_field->set_tileset_id(get_map().get_tileset_id()); QString sprite = entity_before.get_field(sprite_field_name).toString(); ui.sprite_field->set_selected_id(sprite); }
/** * @brief Slot called when the user wants to create an animation. */ void SpriteEditor::create_animation_requested() { GetAnimationNameDialog dialog(*model, this); int result = dialog.exec(); if (result != QDialog::Accepted) { return; } // Try to guess to source image QString src_img = model->get_sprite_id() + ".png"; QFileInfo file_info(get_quest().get_sprite_image_path(src_img)); if (!file_info.exists()) { src_img = ""; } QString name = dialog.get_animation_name(); try_command(new CreateAnimationCommand(*this, name, src_img)); }
/** * @brief Returns the data of an item. * * Reimplemented from QStandardItemModel to create sprite icons lazily. * * @param index Index of the item to get. * @param role The wanted role. * @return The corresponding data. */ QVariant ResourceModel::data(const QModelIndex& index, int role) const { // Don't use QStandardItemModel storage features for icons. // Load them on-demand instead. if (role == Qt::DecorationRole) { const QStandardItem* item = itemFromIndex(index); if (item == nullptr) { // Invalid index; return QVariant(); } const QString& element_id = item->data(Qt::UserRole).toString(); if (element_id.isEmpty()) { // Not a resource element: maybe a directory. if (rowCount(index) > 0) { return directory_icon; // Directory item. } return QIcon(); } if (!get_quest().get_resources().exists(resource_type, element_id)) { // Special item. return QIcon(); } // Resource elemnt item. Q_ASSERT(!element_id.isEmpty()); auto it = icons.find(element_id); if (it != icons.end()) { // Icon already loaded. return it.value(); } else { // Icon not loaded yet. QIcon icon = create_icon(element_id); icons.insert(element_id, icon); return icon; } } return QStandardItemModel::data(index, role); }
/** * @brief Returns an icon for the given element. * @param element_id Id of a resource element. * @return An appropriate icon. */ QIcon ResourceModel::create_icon(const QString& element_id) const { const Quest& quest = get_quest(); Q_ASSERT(!element_id.isEmpty()); Q_ASSERT(quest.get_resources().exists(resource_type, element_id)); if (resource_type == ResourceType::SPRITE) { // Special case of sprites: show the sprite icon. if (quest.exists(quest.get_sprite_path(element_id))) { SpriteModel sprite(quest, element_id); sprite.set_tileset_id(tileset_id); const QPixmap& pixmap = sprite.get_icon(); if (!pixmap.isNull()) { return QIcon(pixmap); } } } // Return an icon representing the resource type. QString resource_type_name = quest.get_resources().get_lua_name(resource_type); return QIcon(":/images/icon_resource_" + resource_type_name + ".png"); }
/** * @brief Slot called when the user wants to open the selected tileset. */ void MapEditor::open_tileset_requested() { emit open_file_requested( get_quest(), get_quest().get_tileset_data_file_path(map->get_tileset_id())); }
/** * @brief Slot called when the user wants to open the map script. */ void MapEditor::open_script_requested() { emit open_file_requested( get_quest(), get_quest().get_map_script_path(map->get_map_id())); }
/** * @brief Initializes the opening method fields. */ void EditEntityDialog::initialize_opening_method() { if (!entity_before.has_field(opening_method_field_name) || !entity_before.has_field(opening_condition_field_name) || !entity_before.has_field(opening_condition_consumed_field_name)) { remove_field(ui.opening_method_label, ui.opening_method_layout); return; } // Some entity types don't have all values: remove such fields. hide_unexisting_opening_methods(); // Initialize the item selector. ui.opening_condition_item_field->set_resource_type(ResourceType::ITEM); ui.opening_condition_item_field->set_quest(get_quest()); // Put the current values into the widgets. // opening_method is how to open the chest or door, // opening_condition is the required savegame variable or item id depending on the method. QString opening_method = entity_before.get_field(opening_method_field_name).toString(); QString opening_condition = entity_before.get_field(opening_condition_field_name).toString(); bool opening_condition_consumed = entity_before.get_field(opening_condition_consumed_field_name).toBool(); // Check the correct radio button. const QMap<QString, QRadioButton*>& radios = get_opening_method_radio_buttons(); QRadioButton* radio = radios.value(opening_method); if (radio != nullptr) { radio->setChecked(true); } else { // Check a default radio button if the current value is invalid. ui.opening_method_interaction_radio->setChecked(true); } // Prepare the savegame variable fields. if (radio == ui.opening_method_savegame_variable_radio) { ui.opening_condition_savegame_variable_field->setText(opening_condition); ui.opening_condition_savegame_variable_consumed_checkbox->setChecked(opening_condition_consumed); } else { ui.opening_condition_savegame_variable_field->setEnabled(false); ui.opening_condition_savegame_variable_consumed_checkbox->setEnabled(false); } connect(ui.opening_method_savegame_variable_radio, SIGNAL(toggled(bool)), ui.opening_condition_savegame_variable_field, SLOT(setEnabled(bool))); connect(ui.opening_method_savegame_variable_radio, SIGNAL(toggled(bool)), ui.opening_condition_savegame_variable_consumed_checkbox, SLOT(setEnabled(bool))); // Prepare the item fields. if (radio == ui.opening_method_item_radio) { ui.opening_condition_item_field->set_selected_id(opening_condition); ui.opening_condition_item_consumed_checkbox->setChecked(opening_condition_consumed); } else { ui.opening_condition_item_field->setEnabled(false); ui.opening_condition_item_consumed_checkbox->setEnabled(false); } connect(ui.opening_method_item_radio, SIGNAL(toggled(bool)), ui.opening_condition_item_field, SLOT(setEnabled(bool))); connect(ui.opening_method_item_radio, SIGNAL(toggled(bool)), ui.opening_condition_item_consumed_checkbox, SLOT(setEnabled(bool))); }