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

Allow map memory drawing mode selection through options #32713

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/cata_tiles.cpp
Expand Up @@ -206,6 +206,8 @@ cata_tiles::~cata_tiles() = default;

void cata_tiles::on_options_changed()
{
memory_map_mode = get_option <std::string>( "MEMORY_MAP_MODE" );

pixel_minimap_settings settings;

settings.mode = pixel_minimap_mode_from_string( get_option<std::string>( "PIXEL_MINIMAP_MODE" ) );
Expand Down Expand Up @@ -360,17 +362,28 @@ void tileset_loader::create_textures_from_tile_atlas( const SDL_Surface_Ptr &til
const point &offset )
{
assert( tile_atlas );
copy_surface_to_texture( tile_atlas, offset, ts.tile_values );

/** perform color filter conversion here */
copy_surface_to_texture( apply_color_filter( tile_atlas, color_pixel_grayscale ), offset,
ts.shadow_tile_values );
copy_surface_to_texture( apply_color_filter( tile_atlas, color_pixel_nightvision ), offset,
ts.night_tile_values );
copy_surface_to_texture( apply_color_filter( tile_atlas, color_pixel_overexposed ), offset,
ts.overexposed_tile_values );
copy_surface_to_texture( apply_color_filter( tile_atlas, color_pixel_memorized ), offset,
ts.memory_tile_values );
using tiles_pixel_color_entry = std::tuple<std::vector<texture>*, std::string>;
std::array<tiles_pixel_color_entry, 5> tile_values_data = {
std::make_tuple( &ts.tile_values, "color_pixel_none" ),
std::make_tuple( &ts.shadow_tile_values, "color_pixel_grayscale" ),
std::make_tuple( &ts.night_tile_values, "color_pixel_nightvision" ),
std::make_tuple( &ts.overexposed_tile_values, "color_pixel_overexposed" ),
std::make_tuple( &ts.memory_tile_values, tilecontext->memory_map_mode )
};
for( tiles_pixel_color_entry &entry : tile_values_data ) {
std::vector<texture> *tile_values = std::get<0>( entry );
color_pixel_function_pointer color_pixel_function = get_color_pixel_function( std::get<1>
( entry ) );
if( !color_pixel_function ) {
// TODO: Move it inside apply_color_filter.
copy_surface_to_texture( tile_atlas, offset, *tile_values );
} else {
copy_surface_to_texture( apply_color_filter( tile_atlas, color_pixel_function ), offset,
*tile_values );
}
}
}

template<typename T>
Expand Down
3 changes: 3 additions & 0 deletions src/cata_tiles.h
Expand Up @@ -492,6 +492,9 @@ class cata_tiles
bool nv_goggles_activated;

std::unique_ptr<pixel_minimap> minimap;

public:
std::string memory_map_mode = "color_pixel_sepia";
};

#endif
11 changes: 11 additions & 0 deletions src/options.cpp
Expand Up @@ -1671,6 +1671,17 @@ void options_manager::add_options_graphics()

get_option( "TILES" ).setPrerequisite( "USE_TILES" );

mOptionsSort["graphics"]++;

add( "MEMORY_MAP_MODE", "graphics", translate_marker( "Memory map drawing mode" ),
translate_marker( "Specified the mode in which the memory map is drawn. Requires restart." ), {
{ "color_pixel_darken", translate_marker( "Darkened" ) },
{ "color_pixel_sepia", translate_marker( "Sepia" ) }
}, "color_pixel_sepia", COPT_CURSES_HIDE
);

mOptionsSort["graphics"]++;

add( "PIXEL_MINIMAP", "graphics", translate_marker( "Pixel minimap" ),
translate_marker( "If true, shows the pixel-detail minimap in game after the save is loaded. Use the 'Toggle Pixel Minimap' action key to change its visibility during gameplay." ),
true, COPT_CURSES_HIDE
Expand Down
19 changes: 19 additions & 0 deletions src/sdl_utils.cpp
Expand Up @@ -10,6 +10,25 @@
#include "cursesport.h"
#include "sdltiles.h"

color_pixel_function_map builtin_color_pixel_functions = {
{ "color_pixel_none", nullptr },
{ "color_pixel_darken", color_pixel_darken },
{ "color_pixel_sepia", color_pixel_sepia },
{ "color_pixel_grayscale", color_pixel_grayscale },
{ "color_pixel_nightvision", color_pixel_nightvision },
{ "color_pixel_overexposed", color_pixel_overexposed },
};

color_pixel_function_pointer get_color_pixel_function( const std::string &name )
{
const auto iter = builtin_color_pixel_functions.find( name );
if( iter == builtin_color_pixel_functions.end() ) {
debugmsg( "no color pixel function with name %s", name );
return nullptr;
}
return iter->second;
}

SDL_Color curses_color_to_SDL( const nc_color &color )
{
const int pair_id = color.to_color_pair_index();
Expand Down
24 changes: 23 additions & 1 deletion src/sdl_utils.h
Expand Up @@ -4,10 +4,16 @@

#include <algorithm>
#include <cmath>
#include <unordered_map>
ZhilkinSerg marked this conversation as resolved.
Show resolved Hide resolved

#include "color.h"
#include "sdl_wrappers.h"

using color_pixel_function_pointer = SDL_Color( * )( const SDL_Color &color );
using color_pixel_function_map = std::unordered_map<std::string, color_pixel_function_pointer>;

color_pixel_function_pointer get_color_pixel_function( const std::string &name );

inline SDL_Color adjust_color_brightness( const SDL_Color &color, int percent )
{
if( percent <= 0 ) {
Expand Down Expand Up @@ -97,7 +103,23 @@ inline SDL_Color color_pixel_overexposed( const SDL_Color &color )
};
}

inline SDL_Color color_pixel_memorized( const SDL_Color &color )
inline SDL_Color color_pixel_darken( const SDL_Color &color )
{
if( is_black( color ) ) {
return color;
}

// 85/256 ~ 1/3
return {
std::max<Uint8>( 85 * color.r >> 8, 0x01 ),
std::max<Uint8>( 85 * color.g >> 8, 0x01 ),
std::max<Uint8>( 85 * color.b >> 8, 0x01 ),
color.a
};

}

inline SDL_Color color_pixel_sepia( const SDL_Color &color )
{
if( is_black( color ) ) {
return color;
Expand Down