Skip to content

Commit

Permalink
migrate extended description to imgui
Browse files Browse the repository at this point in the history
  • Loading branch information
mqrause committed Sep 9, 2024
1 parent 1a13be3 commit 195e383
Show file tree
Hide file tree
Showing 17 changed files with 521 additions and 342 deletions.
41 changes: 24 additions & 17 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6091,17 +6091,17 @@ float Character::rest_quality() const
return rest;
}

std::string Character::extended_description() const
std::vector<std::string> Character::extended_description() const
{
std::string ss;
std::vector<std::string> tmp;
if( is_avatar() ) {
// <bad>This is me, <player_name>.</bad>
ss += string_format( _( "This is you - %s." ), get_name() );
tmp.emplace_back( string_format( _( "This is you - %s." ), get_name() ) );
} else {
ss += string_format( _( "This is %s." ), get_name() );
tmp.emplace_back( string_format( _( "This is %s." ), get_name() ) );
}

ss += "\n--\n";
tmp.emplace_back( "--" );

const std::vector<bodypart_id> &bps = get_all_body_parts( get_body_part_flags::only_main );
// Find length of bp names, to align
Expand All @@ -6121,33 +6121,40 @@ std::string Character::extended_description() const
std::pair<std::string, nc_color> hp_bar = get_hp_bar( get_part_hp_cur( bp ), get_part_hp_max( bp ),
false );

ss += colorize( left_justify( bp_heading, longest ), name_color );
ss += colorize( hp_bar.first, hp_bar.second );
std::string bp_stat = colorize( left_justify( bp_heading, longest ), name_color );
bp_stat += colorize( hp_bar.first, hp_bar.second );
// Trailing bars. UGLY!
// TODO: Integrate into get_hp_bar somehow
ss += colorize( std::string( 5 - utf8_width( hp_bar.first ), '.' ), c_white );
ss += "\n";
bp_stat += colorize( std::string( 5 - utf8_width( hp_bar.first ), '.' ), c_white );
tmp.emplace_back( bp_stat );
}

ss += "--\n";
ss += _( "Wielding:" ) + std::string( " " );
tmp.emplace_back( "--" );
std::string wielding = _( "Wielding:" ) + std::string( " " );
if( weapon.is_null() ) {
ss += _( "Nothing" );
wielding += _( "Nothing" );
} else {
ss += weapon.tname();
wielding += weapon.tname();
}

ss += "\n";
ss += _( "Wearing:" ) + std::string( " " );
tmp.emplace_back( wielding );
std::string wearing = _( "Wearing:" ) + std::string( " " );

const std::list<item_location> visible_worn_items = get_visible_worn_items();
std::string worn_string = enumerate_as_string( visible_worn_items.begin(), visible_worn_items.end(),
[]( const item_location & it ) {
return it.get_item()->tname();
} );
ss += !worn_string.empty() ? worn_string : _( "Nothing" );
wearing += !worn_string.empty() ? worn_string : _( "Nothing" );
tmp.emplace_back( wearing );

return replace_colors( ss );
std::vector<std::string> ret;
ret.reserve( tmp.size() );
for( std::string s : tmp ) {
ret.emplace_back( replace_colors( s ) );
}

return ret;
}

social_modifiers Character::get_mutation_bionic_social_mods() const
Expand Down
2 changes: 1 addition & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -2635,7 +2635,7 @@ class Character : public Creature, public visitable
nc_color symbol_color() const override;
const std::string &symbol() const override;

std::string extended_description() const override;
std::vector<std::string> extended_description() const override;

std::string mutation_name( const trait_id &mut ) const;
std::string mutation_desc( const trait_id &mut ) const;
Expand Down
2 changes: 1 addition & 1 deletion src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ class Creature : public viewer
string_format( npc_speech, std::forward<Args>( args )... ) );
}

virtual std::string extended_description() const = 0;
virtual std::vector<std::string> extended_description() const = 0;

/** Creature symbol background color */
virtual nc_color symbol_color() const = 0;
Expand Down
229 changes: 0 additions & 229 deletions src/descriptions.cpp

This file was deleted.

5 changes: 3 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
#include "translations.h"
#include "trap.h"
#include "ui.h"
#include "ui_extended_description.h"
#include "ui_manager.h"
#include "uistate.h"
#include "units.h"
Expand Down Expand Up @@ -7632,8 +7633,8 @@ look_around_result game::look_around(
} else if( action == "debug_hour_timer" ) {
toggle_debug_hour_timer();
} else if( action == "EXTENDED_DESCRIPTION" ) {
// TODO: fix point types
extended_description( lp.raw() );
extended_description_window ext_desc( lp );
ext_desc.show();
} else if( action == "CHANGE_MONSTER_NAME" ) {
creature_tracker &creatures = get_creature_tracker();
monster *const mon = creatures.creature_at<monster>( lp, true );
Expand Down
Loading

0 comments on commit 195e383

Please sign in to comment.