Skip to content

Commit

Permalink
Don't add duplicate options to the page (#37548)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhilkinSerg authored Feb 11, 2020
1 parent 0dcf11e commit 74040d0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
15 changes: 15 additions & 0 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3618,4 +3618,19 @@ std::vector<options_manager::id_and_option> cata_tiles::build_renderer_list()
return renderer_names.empty() ? default_renderer_names : renderer_names;
}

std::vector<options_manager::id_and_option> cata_tiles::build_display_list()
{
std::vector<options_manager::id_and_option> display_names;
std::vector<options_manager::id_and_option> default_display_names = {
{ "0", translate_marker( "Display 0" ) }
};

int numdisplays = SDL_GetNumVideoDisplays();
for( int i = 0 ; i < numdisplays ; i++ ) {
display_names.emplace_back( std::to_string( i ), std::string( SDL_GetDisplayName( i ) ) );
}

return display_names.empty() ? default_display_names : display_names;
}

#endif // SDL_TILES
1 change: 1 addition & 0 deletions src/cata_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ class cata_tiles
void do_tile_loading_report();
point player_to_screen( const point & ) const;
static std::vector<options_manager::id_and_option> build_renderer_list();
static std::vector<options_manager::id_and_option> build_display_list();
protected:
template <typename maptype>
void tile_loading_report( const maptype &tiletypemap, const std::string &label,
Expand Down
14 changes: 12 additions & 2 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@ void options_manager::addOptionToPage( const std::string &name, const std::strin
{
for( Page &p : pages_ ) {
if( p.id_ == page ) {
// Don't add duplicate options to the page
for( const cata::optional<std::string> &i : p.items_ ) {
if( i.has_value() && i.value() == name ) {
return;
}
}
p.items_.emplace_back( name );
return;
}
}
// @TODO handle the case when an option has no valid page id (note: consider hidden external options as well)
Expand Down Expand Up @@ -1806,10 +1813,13 @@ void options_manager::add_options_graphics()

add_empty_line();

#if defined(TILES)
std::vector<options_manager::id_and_option> display_list = cata_tiles::build_display_list();
add( "DISPLAY", "graphics", translate_marker( "Display" ),
translate_marker( "Sets which video display will be used to show the game. Requires restart." ),
0, 10000, 0, COPT_CURSES_HIDE
);
display_list,
display_list.front().first, COPT_CURSES_HIDE );
#endif

#if !defined(__ANDROID__) // Android is always fullscreen
add( "FULLSCREEN", "graphics", translate_marker( "Fullscreen" ),
Expand Down
21 changes: 1 addition & 20 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ static void WinCreate()
}
#endif

int display = get_option<int>( "DISPLAY" );
int display = std::stoi( get_option<std::string>( "DISPLAY" ) );
if( display < 0 || display >= SDL_GetNumVideoDisplays() ) {
display = 0;
}
Expand Down Expand Up @@ -925,23 +925,6 @@ void set_displaybuffer_rendertarget()
SetRenderTarget( renderer, display_buffer );
}

// Populate a map with the available video displays and their name
static void find_videodisplays()
{
std::vector< std::tuple<int, std::string> > displays;

int numdisplays = SDL_GetNumVideoDisplays();
for( int i = 0 ; i < numdisplays ; i++ ) {
displays.push_back( std::make_tuple( i, std::string( SDL_GetDisplayName( i ) ) ) );
}

int current_display = get_option<int>( "DISPLAY" );
get_options().add( "DISPLAY", "graphics", translate_marker( "Display" ),
translate_marker( "Sets which video display will be used to show the game. Requires restart." ),
displays, current_display, 0, options_manager::COPT_CURSES_HIDE, true
);
}

// line_id is one of the LINE_*_C constants
// FG is a curses color
void Font::draw_ascii_lines( unsigned char line_id, int drawx, int drawy, int FG ) const
Expand Down Expand Up @@ -3529,8 +3512,6 @@ void catacurses::init_interface()

InitSDL();

find_videodisplays();

init_term_size_and_scaling_factor();

WinCreate();
Expand Down

0 comments on commit 74040d0

Please sign in to comment.