From ae2c4eb13c652fde7fb755acfc61025231855597 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 21 Nov 2024 00:04:24 +0000 Subject: [PATCH 1/5] Add an option to show/hide overlay icons over creatures Works but isn't easily cacheable so I think I'll drop the tileset field which'll have the benefit of making this alot neater too --- src/cata_tiles.cpp | 21 +++++++++++++++++++-- src/cata_tiles.h | 6 ++++++ src/character.cpp | 22 +++++++++++++--------- src/character.h | 6 ++++-- src/options.cpp | 7 +++++++ 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index a8a75c0b4ecf7..e55f48366c6eb 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -687,6 +687,7 @@ void tileset_cache::loader::load( const std::string &tileset_id, const bool prec ts.tile_pixelscale = curr_info.get_float( "pixelscale", 1.0f ); ts.prevent_occlusion_min_dist = curr_info.get_float( "retract_dist_min", -1.0f ); ts.prevent_occlusion_max_dist = curr_info.get_float( "retract_dist_max", 0.0f ); + ts.show_creature_overlay_icons = curr_info.get_bool( "show_creature_overlay_icons", true ); } if( precheck ) { @@ -4160,7 +4161,7 @@ bool cata_tiles::draw_critter_at( const tripoint &p, lit_level ll, int &height_3 } } - if( result && !is_player ) { + if( result && !is_player && get_show_creature_overlay_icons() ) { std::string draw_id = "overlay_" + Creature::attitude_raw_string( attitude ); if( sees_player && !you.has_trait( trait_INATTENTIVE ) ) { draw_id += "_sees_player"; @@ -4173,6 +4174,21 @@ bool cata_tiles::draw_critter_at( const tripoint &p, lit_level ll, int &height_3 return result; } +bool cata_tiles::get_show_creature_overlay_icons() +{ + const int &user_option = get_option( "CREATURE_OVERLAY_ICONS" ); + switch( user_option ) { + case 0: + return false; + case 1: + return true; + case 2: + return tileset_ptr->get_show_creature_overlay_icons(); + default: + cata_fatal( "Invalid CREATURE_OVERLAY_ICONS option" ); + } +} + bool cata_tiles::draw_critter_above( const tripoint &p, lit_level ll, int &height_3d, const std::array &invisible ) { @@ -4388,7 +4404,8 @@ void cata_tiles::draw_entity_with_overlays( const Character &ch, const tripoint // next up, draw all the overlays std::vector> overlays = override_look_muts.empty() ? - ch.get_overlay_ids() : ch.get_overlay_ids_when_override_look(); + ch.get_overlay_ids( get_show_creature_overlay_icons() ) : + ch.get_overlay_ids_when_override_look( get_show_creature_overlay_icons() ); for( const std::pair &overlay : overlays ) { std::string draw_id = overlay.first; if( find_overlay_looks_like( ch.male, overlay.first, overlay.second, draw_id ) ) { diff --git a/src/cata_tiles.h b/src/cata_tiles.h index d875a4dc1de97..b94384a24c150 100644 --- a/src/cata_tiles.h +++ b/src/cata_tiles.h @@ -177,6 +177,8 @@ class tileset // multiplier for pixel-doubling tilesets float tile_pixelscale = 1.0f; + bool show_creature_overlay_icons = true; + std::vector tile_values; std::vector shadow_tile_values; std::vector night_tile_values; @@ -232,6 +234,9 @@ class tileset const std::string &get_tileset_id() const { return tileset_id; } + bool get_show_creature_overlay_icons() const { + return show_creature_overlay_icons; + } const texture *get_tile( const size_t index ) const { return get_if_available( index, tile_values ); @@ -723,6 +728,7 @@ class cata_tiles private: std::pair get_omt_id_rotation_and_subtile( const tripoint_abs_omt &omp, int &rota, int &subtile ); + bool get_show_creature_overlay_icons(); protected: template void tile_loading_report_map( const maptype &tiletypemap, TILE_CATEGORY category, diff --git a/src/character.cpp b/src/character.cpp index c3101d18c32dd..2045085cd10fb 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -3421,7 +3421,8 @@ bool Character::is_wielding( const item &target ) const return &weapon == ⌖ } -std::vector> Character::get_overlay_ids() const +std::vector> Character::get_overlay_ids( + const bool show_creature_overlay_icons /*= true*/ ) const { std::vector> rval; std::multimap> mutation_sorting; @@ -3430,8 +3431,10 @@ std::vector> Character::get_overlay_ids() co std::string variant; // first get effects - for( const auto &eff_pr : *effects ) { - rval.emplace_back( "effect_" + eff_pr.first.str(), "" ); + if( show_creature_overlay_icons ) { + for( const auto &eff_pr : *effects ) { + rval.emplace_back( "effect_" + eff_pr.first.str(), "" ); + } } // then get mutations @@ -3480,21 +3483,22 @@ std::vector> Character::get_overlay_ids() co rval.emplace_back( "wielded_" + weapon.typeId().str(), variant ); } - if( !is_walking() ) { + if( !is_walking() && show_creature_overlay_icons ) { rval.emplace_back( move_mode.str(), "" ); } return rval; } -std::vector> Character::get_overlay_ids_when_override_look() +std::vector> Character::get_overlay_ids_when_override_look( + const bool show_creature_overlay_icons /*= true*/ ) const { - std::vector> rval; - std::multimap> mutation_sorting; - std::string overlay_id; - std::string variant; + std::vector> rval; + if( !show_creature_overlay_icons ) { + return rval; + } // first get effects for( const auto &eff_pr : *effects ) { rval.emplace_back( "effect_" + eff_pr.first.str(), "" ); diff --git a/src/character.h b/src/character.h index 83169225be830..672f5264fcda3 100644 --- a/src/character.h +++ b/src/character.h @@ -2428,14 +2428,16 @@ class Character : public Creature, public visitable * * Only required for rendering. */ - std::vector> get_overlay_ids() const; + std::vector> get_overlay_ids( const bool + show_creature_overlay_icons = true ) const; /** * Returns a list of the IDs of overlays on this character if the character has override look mutations * sorted from "lowest" to "highest". * * Only required for rendering. */ - std::vector> get_overlay_ids_when_override_look() const; + std::vector> get_overlay_ids_when_override_look( + const bool show_creature_overlay_icons = true ) const; // --------------- Skill Stuff --------------- diff --git a/src/options.cpp b/src/options.cpp index 584fc9455f03e..ded24344907ba 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -2198,6 +2198,13 @@ void options_manager::add_options_interface() { { "prefix", to_translation( "Prefix" ) }, { "suffix", to_translation( "Suffix" ) } }, "right" ); + + add( "CREATURE_OVERLAY_ICONS", page_id, to_translation( "Show overlay icons over creatures" ), + to_translation( "Show, Hide, or let the tileset decide (Auto)." ), { + { 0, to_translation( "Hide" ) }, { 1, to_translation( "Show" ) }, + { 2, to_translation( "Auto" ) } + }, 2, 2 + ); } ); add_empty_line(); From de2a5d9c0ca1b0bb75200a998419cfa1ee525ca2 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 21 Nov 2024 09:26:59 +0000 Subject: [PATCH 2/5] Remove auto option that used a tileset field --- src/cata_tiles.cpp | 21 ++------------------- src/cata_tiles.h | 6 ------ src/character.cpp | 11 ++++------- src/character.h | 6 ++---- src/options.cpp | 6 ++---- 5 files changed, 10 insertions(+), 40 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index e55f48366c6eb..ea9d4c8a26bb0 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -687,7 +687,6 @@ void tileset_cache::loader::load( const std::string &tileset_id, const bool prec ts.tile_pixelscale = curr_info.get_float( "pixelscale", 1.0f ); ts.prevent_occlusion_min_dist = curr_info.get_float( "retract_dist_min", -1.0f ); ts.prevent_occlusion_max_dist = curr_info.get_float( "retract_dist_max", 0.0f ); - ts.show_creature_overlay_icons = curr_info.get_bool( "show_creature_overlay_icons", true ); } if( precheck ) { @@ -4161,7 +4160,7 @@ bool cata_tiles::draw_critter_at( const tripoint &p, lit_level ll, int &height_3 } } - if( result && !is_player && get_show_creature_overlay_icons() ) { + if( result && !is_player && get_option( "CREATURE_OVERLAY_ICONS" ) ) { std::string draw_id = "overlay_" + Creature::attitude_raw_string( attitude ); if( sees_player && !you.has_trait( trait_INATTENTIVE ) ) { draw_id += "_sees_player"; @@ -4174,21 +4173,6 @@ bool cata_tiles::draw_critter_at( const tripoint &p, lit_level ll, int &height_3 return result; } -bool cata_tiles::get_show_creature_overlay_icons() -{ - const int &user_option = get_option( "CREATURE_OVERLAY_ICONS" ); - switch( user_option ) { - case 0: - return false; - case 1: - return true; - case 2: - return tileset_ptr->get_show_creature_overlay_icons(); - default: - cata_fatal( "Invalid CREATURE_OVERLAY_ICONS option" ); - } -} - bool cata_tiles::draw_critter_above( const tripoint &p, lit_level ll, int &height_3d, const std::array &invisible ) { @@ -4404,8 +4388,7 @@ void cata_tiles::draw_entity_with_overlays( const Character &ch, const tripoint // next up, draw all the overlays std::vector> overlays = override_look_muts.empty() ? - ch.get_overlay_ids( get_show_creature_overlay_icons() ) : - ch.get_overlay_ids_when_override_look( get_show_creature_overlay_icons() ); + ch.get_overlay_ids() : ch.get_overlay_ids_when_override_look(); for( const std::pair &overlay : overlays ) { std::string draw_id = overlay.first; if( find_overlay_looks_like( ch.male, overlay.first, overlay.second, draw_id ) ) { diff --git a/src/cata_tiles.h b/src/cata_tiles.h index b94384a24c150..d875a4dc1de97 100644 --- a/src/cata_tiles.h +++ b/src/cata_tiles.h @@ -177,8 +177,6 @@ class tileset // multiplier for pixel-doubling tilesets float tile_pixelscale = 1.0f; - bool show_creature_overlay_icons = true; - std::vector tile_values; std::vector shadow_tile_values; std::vector night_tile_values; @@ -234,9 +232,6 @@ class tileset const std::string &get_tileset_id() const { return tileset_id; } - bool get_show_creature_overlay_icons() const { - return show_creature_overlay_icons; - } const texture *get_tile( const size_t index ) const { return get_if_available( index, tile_values ); @@ -728,7 +723,6 @@ class cata_tiles private: std::pair get_omt_id_rotation_and_subtile( const tripoint_abs_omt &omp, int &rota, int &subtile ); - bool get_show_creature_overlay_icons(); protected: template void tile_loading_report_map( const maptype &tiletypemap, TILE_CATEGORY category, diff --git a/src/character.cpp b/src/character.cpp index 2045085cd10fb..0d52d7ca7fd1d 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -3421,15 +3421,14 @@ bool Character::is_wielding( const item &target ) const return &weapon == ⌖ } -std::vector> Character::get_overlay_ids( - const bool show_creature_overlay_icons /*= true*/ ) const +std::vector> Character::get_overlay_ids() const { std::vector> rval; std::multimap> mutation_sorting; int order; std::string overlay_id; std::string variant; - + const bool &show_creature_overlay_icons = get_option( "CREATURE_OVERLAY_ICONS" ); // first get effects if( show_creature_overlay_icons ) { for( const auto &eff_pr : *effects ) { @@ -3490,13 +3489,11 @@ std::vector> Character::get_overlay_ids( return rval; } -std::vector> Character::get_overlay_ids_when_override_look( - const bool show_creature_overlay_icons /*= true*/ ) +std::vector> Character::get_overlay_ids_when_override_look() const { - std::vector> rval; - if( !show_creature_overlay_icons ) { + if( !get_option( "CREATURE_OVERLAY_ICONS" ) ) { return rval; } // first get effects diff --git a/src/character.h b/src/character.h index 672f5264fcda3..83169225be830 100644 --- a/src/character.h +++ b/src/character.h @@ -2428,16 +2428,14 @@ class Character : public Creature, public visitable * * Only required for rendering. */ - std::vector> get_overlay_ids( const bool - show_creature_overlay_icons = true ) const; + std::vector> get_overlay_ids() const; /** * Returns a list of the IDs of overlays on this character if the character has override look mutations * sorted from "lowest" to "highest". * * Only required for rendering. */ - std::vector> get_overlay_ids_when_override_look( - const bool show_creature_overlay_icons = true ) const; + std::vector> get_overlay_ids_when_override_look() const; // --------------- Skill Stuff --------------- diff --git a/src/options.cpp b/src/options.cpp index ded24344907ba..9f46be576163b 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -2200,10 +2200,8 @@ void options_manager::add_options_interface() ); add( "CREATURE_OVERLAY_ICONS", page_id, to_translation( "Show overlay icons over creatures" ), - to_translation( "Show, Hide, or let the tileset decide (Auto)." ), { - { 0, to_translation( "Hide" ) }, { 1, to_translation( "Show" ) }, - { 2, to_translation( "Auto" ) } - }, 2, 2 + to_translation( "If true, show overlay icons over creatures such as effects, move mode and whether creatures can see the player." ), + true ); } ); From 3dfd92a2ec7295c1ee3320737ff9e229e22826d2 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 21 Nov 2024 09:54:43 +0000 Subject: [PATCH 3/5] Cache the option --- src/cached_options.cpp | 1 + src/cached_options.h | 1 + src/cata_tiles.cpp | 2 +- src/character.cpp | 3 +-- src/options.cpp | 1 + 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cached_options.cpp b/src/cached_options.cpp index 01e316ab5a9db..29d9bcc70d4ce 100644 --- a/src/cached_options.cpp +++ b/src/cached_options.cpp @@ -11,6 +11,7 @@ bool prevent_occlusion_retract; bool prevent_occlusion_transp; float prevent_occlusion_min_dist; float prevent_occlusion_max_dist; +bool show_creature_overlay_icons; bool use_tiles; bool use_far_tiles; bool use_pinyin_search; diff --git a/src/cached_options.h b/src/cached_options.h index 9831b40f1d2b4..bb707626c1d9c 100644 --- a/src/cached_options.h +++ b/src/cached_options.h @@ -20,6 +20,7 @@ extern bool prevent_occlusion_retract; extern bool prevent_occlusion_transp; extern float prevent_occlusion_min_dist; extern float prevent_occlusion_max_dist; +extern bool show_creature_overlay_icons; extern bool use_tiles; extern bool use_far_tiles; extern bool use_pinyin_search; diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index ea9d4c8a26bb0..821aa79e8f6ea 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -4160,7 +4160,7 @@ bool cata_tiles::draw_critter_at( const tripoint &p, lit_level ll, int &height_3 } } - if( result && !is_player && get_option( "CREATURE_OVERLAY_ICONS" ) ) { + if( result && !is_player && show_creature_overlay_icons ) { std::string draw_id = "overlay_" + Creature::attitude_raw_string( attitude ); if( sees_player && !you.has_trait( trait_INATTENTIVE ) ) { draw_id += "_sees_player"; diff --git a/src/character.cpp b/src/character.cpp index 0d52d7ca7fd1d..927bae129f6e7 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -3428,7 +3428,6 @@ std::vector> Character::get_overlay_ids() co int order; std::string overlay_id; std::string variant; - const bool &show_creature_overlay_icons = get_option( "CREATURE_OVERLAY_ICONS" ); // first get effects if( show_creature_overlay_icons ) { for( const auto &eff_pr : *effects ) { @@ -3493,7 +3492,7 @@ std::vector> Character::get_overlay_ids_when const { std::vector> rval; - if( !get_option( "CREATURE_OVERLAY_ICONS" ) ) { + if( !show_creature_overlay_icons ) { return rval; } // first get effects diff --git a/src/options.cpp b/src/options.cpp index 9f46be576163b..399a37dc75168 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -4106,6 +4106,7 @@ void options_manager::update_options_cache() prevent_occlusion_transp = ::get_option( "PREVENT_OCCLUSION_TRANSP" ); prevent_occlusion_min_dist = ::get_option( "PREVENT_OCCLUSION_MIN_DIST" ); prevent_occlusion_max_dist = ::get_option( "PREVENT_OCCLUSION_MAX_DIST" ); + show_creature_overlay_icons = ::get_option( "CREATURE_OVERLAY_ICONS" ); // if the tilesets are identical don't duplicate use_far_tiles = ::get_option( "USE_DISTANT_TILES" ) || From 73ffb6d72f0257d62e57c8fd51328000ff7e9421 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:13:30 +0000 Subject: [PATCH 4/5] Move the option --- src/options.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/options.cpp b/src/options.cpp index 399a37dc75168..e67e1b1ec5e52 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -2198,11 +2198,6 @@ void options_manager::add_options_interface() { { "prefix", to_translation( "Prefix" ) }, { "suffix", to_translation( "Suffix" ) } }, "right" ); - - add( "CREATURE_OVERLAY_ICONS", page_id, to_translation( "Show overlay icons over creatures" ), - to_translation( "If true, show overlay icons over creatures such as effects, move mode and whether creatures can see the player." ), - true - ); } ); add_empty_line(); @@ -2434,6 +2429,11 @@ void options_manager::add_options_graphics() build_tilesets_list(), "UltimateCataclysm", COPT_CURSES_HIDE ); // populate the options dynamically + add( "CREATURE_OVERLAY_ICONS", page_id, to_translation( "Show overlay icons over creatures" ), + to_translation( "If true, show overlay icons over creatures such as effects, move mode and whether creatures can see the player." ), + true + ); + add( "SWAP_ZOOM", page_id, to_translation( "Zoom Threshold" ), to_translation( "Choose when you should swap tileset (lower is more zoomed out)." ), 1, 4, 2, COPT_CURSES_HIDE @@ -2443,6 +2443,7 @@ void options_manager::add_options_graphics() get_option( "USE_DISTANT_TILES" ).setPrerequisite( "USE_TILES" ); get_option( "DISTANT_TILES" ).setPrerequisite( "USE_DISTANT_TILES" ); get_option( "SWAP_ZOOM" ).setPrerequisite( "USE_DISTANT_TILES" ); + get_option( "CREATURE_OVERLAY_ICONS" ).setPrerequisite( "USE_TILES" ); add( "USE_OVERMAP_TILES", page_id, to_translation( "Use tiles to display overmap" ), to_translation( "If true, replaces some TTF-rendered text with tiles for overmap display." ), From 040cf528664d68f6efc0605254281ef8e86e6128 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:24:14 +0000 Subject: [PATCH 5/5] Update options.cpp --- src/options.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/options.cpp b/src/options.cpp index e67e1b1ec5e52..6a704d737dfcb 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -2431,7 +2431,7 @@ void options_manager::add_options_graphics() add( "CREATURE_OVERLAY_ICONS", page_id, to_translation( "Show overlay icons over creatures" ), to_translation( "If true, show overlay icons over creatures such as effects, move mode and whether creatures can see the player." ), - true + true, COPT_CURSES_HIDE ); add( "SWAP_ZOOM", page_id, to_translation( "Zoom Threshold" ),