Skip to content

Commit

Permalink
fix(UI): character preview side effects bug fix (cataclysmbnteam#5099)
Browse files Browse the repository at this point in the history
character preview side effects bug fix
  • Loading branch information
4nonch authored Jul 29, 2024
1 parent 6f11fd7 commit 0475716
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/character_preview.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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<const spell_id, int> &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
Expand Down Expand Up @@ -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<known_magic>();
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 );
}

Expand Down
2 changes: 2 additions & 0 deletions src/character_preview.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "cursesdef.h"
#include "detached_ptr.h"
#include "type_id.h"

class item;
class Character;
Expand Down Expand Up @@ -57,6 +58,7 @@ struct character_preview_window {
int nlines_width = 0;
Character *character = nullptr;
std::vector<detached_ptr<item>> clothes;
std::vector<trait_id> spells;
bool show_clothes = true;

auto calc_character_pos() const -> point ;
Expand Down

0 comments on commit 0475716

Please sign in to comment.