Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(UI): character preview side effects bug fix #5099

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading