Skip to content

Commit

Permalink
Allow map memory drawing mode selection through options
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhilkinSerg committed Jul 29, 2019
1 parent 666b2ec commit 7261932
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 9 deletions.
28 changes: 20 additions & 8 deletions src/cata_tiles.cpp
Expand Up @@ -209,6 +209,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 @@ -366,14 +368,24 @@ void tileset_loader::create_textures_from_tile_atlas( const SDL_Surface_Ptr &til
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, 4> tile_values_data = {
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.get()->memory_map_mode )
};
for( auto &entry : tile_values_data ) {
color_pixel_function_pointer color_pixel_function = get_color_pixel_function( std::get<1>
( entry ) );
std::vector<texture> tile_values = std::get<0>( entry );
if( color_pixel_function == nullptr ) {
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 @@ -497,6 +497,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 @@ -1674,6 +1674,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_gray_out", translate_marker( "Classic (Gray)" ) },
{ "color_pixel_sepia", translate_marker( "Modern (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_gray_out", color_pixel_gray_out },
{ "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 @@ -3,10 +3,16 @@
#define SDL_UTILS_H

#include <algorithm>
#include <unordered_map>

#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 @@ -96,7 +102,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_gray_out( 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

0 comments on commit 7261932

Please sign in to comment.