From 74040d0dc6127154db83b4c6294a9f84c0fa89b2 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Tue, 11 Feb 2020 08:15:39 +0300 Subject: [PATCH] Don't add duplicate options to the page (#37548) --- src/cata_tiles.cpp | 15 +++++++++++++++ src/cata_tiles.h | 1 + src/options.cpp | 14 ++++++++++++-- src/sdltiles.cpp | 21 +-------------------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index dc11f3da4cf7a..a27c515e949b7 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -3618,4 +3618,19 @@ std::vector cata_tiles::build_renderer_list() return renderer_names.empty() ? default_renderer_names : renderer_names; } +std::vector cata_tiles::build_display_list() +{ + std::vector display_names; + std::vector 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 diff --git a/src/cata_tiles.h b/src/cata_tiles.h index 36d5c869b5e41..45ec9194ce19c 100644 --- a/src/cata_tiles.h +++ b/src/cata_tiles.h @@ -476,6 +476,7 @@ class cata_tiles void do_tile_loading_report(); point player_to_screen( const point & ) const; static std::vector build_renderer_list(); + static std::vector build_display_list(); protected: template void tile_loading_report( const maptype &tiletypemap, const std::string &label, diff --git a/src/options.cpp b/src/options.cpp index c57a5fc7fd5f4..a18bd1ed94b57 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -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 &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) @@ -1806,10 +1813,13 @@ void options_manager::add_options_graphics() add_empty_line(); +#if defined(TILES) + std::vector 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" ), diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index f25b50c083f70..c9ee7420a7d51 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -390,7 +390,7 @@ static void WinCreate() } #endif - int display = get_option( "DISPLAY" ); + int display = std::stoi( get_option( "DISPLAY" ) ); if( display < 0 || display >= SDL_GetNumVideoDisplays() ) { display = 0; } @@ -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 > 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( "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 @@ -3529,8 +3512,6 @@ void catacurses::init_interface() InitSDL(); - find_videodisplays(); - init_term_size_and_scaling_factor(); WinCreate();