From 04757160c55696ff602af8055140cf19e6556408 Mon Sep 17 00:00:00 2001 From: 4nonch <73679117+4nonch@users.noreply.github.com> Date: Mon, 29 Jul 2024 19:30:56 +0300 Subject: [PATCH] fix(UI): character preview side effects bug fix (#5099) character preview side effects bug fix --- src/character_preview.cpp | 20 ++++++++++++++++++++ src/character_preview.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/character_preview.cpp b/src/character_preview.cpp index d7e1cbb43366..34adb0c4dda9 100644 --- a/src/character_preview.cpp +++ b/src/character_preview.cpp @@ -1,5 +1,8 @@ #if defined(TILES) #include "character_preview.h" +#include "bionics.h" +#include "magic.h" +#include "messages.h" #include "type_id.h" #include "character.h" #include "profession.h" @@ -26,6 +29,13 @@ void character_preview_window::init( Character *character ) // Setting bionics for( const bionic_id &bio : character->prof->CBMs() ) { character->add_bionic( bio ); + // Saving possible spells to cancell them later + for( const std::pair &spell_pair : bio->learned_spells ) { + const spell_id learned_spell = spell_pair.first; + if( learned_spell->spell_class != trait_id( "NONE" ) ) { + spells.push_back( learned_spell->spell_class ); + } + } } // Collecting profession clothes @@ -150,6 +160,16 @@ void character_preview_window::clear() const { character->worn.clear(); character->clear_bionics(); + character->set_max_power_level( 0_kJ ); + character->set_power_level( character->get_max_power_level() ); + character->magic = pimpl(); + for( const trait_id &spell : spells ) { + if( character->has_trait( spell ) ) { + character->remove_mutation( spell ); + } + } + character->clear_morale(); + Messages::clear_messages(); tilecontext->set_draw_scale( DEFAULT_TILESET_ZOOM ); } diff --git a/src/character_preview.h b/src/character_preview.h index b64028c8d7b8..7ef348d01adb 100644 --- a/src/character_preview.h +++ b/src/character_preview.h @@ -4,6 +4,7 @@ #include "cursesdef.h" #include "detached_ptr.h" +#include "type_id.h" class item; class Character; @@ -57,6 +58,7 @@ struct character_preview_window { int nlines_width = 0; Character *character = nullptr; std::vector> clothes; + std::vector spells; bool show_clothes = true; auto calc_character_pos() const -> point ;