Skip to content

Commit

Permalink
Merge pull request #76308 from mqrause/imgui_extended_description
Browse files Browse the repository at this point in the history
Migrate extended description (`x`->`e`) to imgui
  • Loading branch information
Maleclypse authored Sep 17, 2024
2 parents 435bd97 + a060ef9 commit e40a6ef
Show file tree
Hide file tree
Showing 18 changed files with 604 additions and 351 deletions.
48 changes: 31 additions & 17 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6091,17 +6091,18 @@ 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;
std::string name_str = colorize( get_name(), basic_symbol_color() );
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." ), name_str ) );
} else {
ss += string_format( _( "This is %s." ), get_name() );
tmp.emplace_back( string_format( _( "This is %s." ), name_str ) );
}

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 +6122,46 @@ 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;
if( weapon.is_null() ) {
ss += _( "Nothing" );
wielding = _( "Nothing" );
} else {
ss += weapon.tname();
wielding = weapon.tname();
}

ss += "\n";
ss += _( "Wearing:" ) + std::string( " " );
tmp.emplace_back( string_format( _( "Wielding: %s" ), colorize( wielding, c_red ) ) );
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 );
int visibility_cap = get_player_character().get_mutation_visibility_cap( this );
const std::string trait_str = visible_mutations( visibility_cap );
if( !trait_str.empty() ) {
tmp.emplace_back( string_format( _( "Traits: %s" ), trait_str ) );
}

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

return ret;
}

social_modifiers Character::get_mutation_bionic_social_mods() const
Expand Down
4 changes: 2 additions & 2 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "city.h" // IWYU pragma: keep
#include "compatibility.h"
#include "coords_fwd.h"
#include "craft_command.h"
#include "creature.h"
#include "damage.h"
#include "enums.h"
Expand Down Expand Up @@ -68,6 +67,7 @@ class activity_actor;
class basecamp;
class bionic_collection;
class character_martial_arts;
class craft_command;
class dispersion_sources;
class effect;
class effect_source;
Expand Down Expand Up @@ -2642,7 +2642,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 @@ -7639,8 +7640,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
1 change: 1 addition & 0 deletions src/iexamine_actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "itype.h"
#include "map.h"
#include "mapgen_functions.h"
#include "mapgendata.h"
#include "map_iterator.h"
#include "messages.h"
#include "mtype.h"
Expand Down
Loading

0 comments on commit e40a6ef

Please sign in to comment.