/** * \brief Sets the animation set id to use for the shield sprite. * \param sprite_id The shield sprite animation set id. * An empty string means no sword sprite. */ void HeroSprites::set_shield_sprite_id(const std::string& sprite_id) { if (sprite_id == this->shield_sprite_id) { return; } this->shield_sprite_id = sprite_id; std::string animation; int direction = -1; if (shield_sprite != nullptr) { // Delete the previous sprite, but save its animation and direction. if (shield_sprite->is_animation_started()) { animation = shield_sprite->get_current_animation(); direction = shield_sprite->get_current_direction(); } shield_sprite = nullptr; } if (!sprite_id.empty()) { // There is a shield sprite specified. shield_sprite = std::make_shared<Sprite>(sprite_id); shield_sprite->set_synchronized_to(tunic_sprite); if (animation.empty()) { shield_sprite->stop_animation(); } else { shield_sprite->set_current_animation(animation); shield_sprite->set_current_direction(direction); } } has_default_shield_sprite = (sprite_id == get_default_shield_sprite_id()); }
/** * \brief Loads (or reloads) the sprites and sounds of the hero and his * equipment. * * The sprites and sounds loaded may depend on his tunic, sword and shield as * specified in the savegame. * This function must be called at the game beginning * and as soon as the hero's equipment is changed. */ void HeroSprites::rebuild_equipment() { // Make the tunic sprite be the default one. hero.set_default_sprite_name("tunic"); int animation_direction = -1; if (tunic_sprite != nullptr) { // Save the direction. animation_direction = tunic_sprite->get_current_direction(); } // The hero's body. if (has_default_tunic_sprite) { set_tunic_sprite_id(get_default_tunic_sprite_id()); } // The hero's shadow. if (shadow_sprite == nullptr) { shadow_sprite = hero.create_sprite("entities/shadow", "shadow"); shadow_sprite->set_current_animation("big"); } // The hero's sword. if (has_default_sword_sprite) { set_sword_sprite_id(get_default_sword_sprite_id()); } if (has_default_sword_sound) { set_sword_sound_id(get_default_sword_sound_id()); } const int sword_number = equipment.get_ability(Ability::SWORD); if (sword_number > 0) { // TODO make this sprite depend on the sword sprite: sword_sprite_id + "_stars" std::ostringstream oss; oss << "hero/sword_stars" << sword_number; sword_stars_sprite = hero.create_sprite(oss.str(), "sword_stars"); sword_stars_sprite->stop_animation(); } // The hero's shield. if (has_default_shield_sprite) { set_shield_sprite_id(get_default_shield_sprite_id()); } // The trail. trail_sprite = hero.create_sprite("hero/trail", "trail"); trail_sprite->stop_animation(); // Restore the animation direction. if (animation_direction != -1) { set_animation_direction(animation_direction); } reorder_sprites(); }
/** * \brief Sets the animation set id to use for the shield sprite. * \param sprite_id The shield sprite animation set id. * An empty string means no sword sprite. */ void HeroSprites::set_shield_sprite_id(const std::string& sprite_id) { if (sprite_id == this->shield_sprite_id) { return; } this->shield_sprite_id = sprite_id; std::string animation; int direction = -1; if (shield_sprite != nullptr) { // Delete the previous sprite, but save its animation and direction. if (shield_sprite->is_animation_started()) { animation = shield_sprite->get_current_animation(); direction = shield_sprite->get_current_direction(); } hero.remove_sprite(*shield_sprite); shield_sprite = nullptr; } if (!sprite_id.empty()) { // There is a shield sprite specified. shield_sprite = hero.create_sprite(sprite_id, "shield"); shield_sprite->set_synchronized_to(tunic_sprite); if (animation.empty()) { shield_sprite->stop_animation(); } else { shield_sprite->set_current_animation(animation); shield_sprite->set_current_direction(direction); } } has_default_shield_sprite = (sprite_id == get_default_shield_sprite_id()); reorder_sprites(); recompute_sprites_bounding_box(); }