From 9faacca17b5ac34b469c227b4159362b23d8325a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mu=C3=B1oz?= Date: Sat, 24 Jul 2021 15:25:45 +0200 Subject: [PATCH 01/13] Fix graphical overmap notes display & mission arrow --- src/overmap_ui.cpp | 8 +++++- src/sdltiles.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/overmap_ui.cpp b/src/overmap_ui.cpp index 0a375abb828c4..2ba3bb7df7bc1 100644 --- a/src/overmap_ui.cpp +++ b/src/overmap_ui.cpp @@ -99,6 +99,8 @@ static const int npm_width = 3; /** Note preview map height without borders. Odd number. */ static const int npm_height = 3; +static bool creating_note = false; + namespace overmap_ui { // {note symbol, note color, offset to text} @@ -1144,7 +1146,9 @@ void draw( } else { #ifdef TILES cata_cursesport::WINDOW *const win = w.get(); - tilecontext->draw_om( win->pos, center, blink ); + if( !creating_note ) { + tilecontext->draw_om( win->pos, center, blink ); + } #endif // TILES } } @@ -1184,6 +1188,7 @@ void create_note( const tripoint_abs_omt &curs ) std::tuple preview_windows; ui_adaptor ui; + creating_note = true; ui.on_screen_resize( [&]( ui_adaptor & ui ) { w_preview = catacurses::newwin( npm_height + 2, max_note_display_length - npm_width - 1, @@ -1233,6 +1238,7 @@ void create_note( const tripoint_abs_omt &curs ) } else if( !esc_pressed && old_note != new_note ) { overmap_buffer.add_note( curs, new_note ); } + creating_note = false; } // if false, search yielded no results diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 8a0d109937d8b..aebabd9e31ec7 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -698,7 +698,8 @@ static cata::optional> get_mission_arro return std::make_pair( mission_target, mission_arrow_variant ); } - const std::vector mission_trajectory = line_to( center.raw(), mission_target.raw() ); + const std::vector mission_trajectory = line_to( center.raw(), + tripoint( mission_target.raw().xy(), center.raw().z ) ); cata::optional prev; int z = 0; @@ -1080,6 +1081,66 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ } } } + + std::vector> notes_window_text; + + if( uistate.overmap_show_map_notes ) { + const std::string ¬e_text = overmap_buffer.note( center_abs_omt ); + if( !note_text.empty() ) { + const std::tuple note_info = overmap_ui::get_note_display_info( + note_text ); + const size_t pos = std::get<2>( note_info ); + if( pos != std::string::npos ) { + notes_window_text.emplace_back( std::get<1>( note_info ), note_text.substr( pos ) ); + } + if( overmap_buffer.is_marked_dangerous( center_abs_omt ) ) { + notes_window_text.emplace_back( c_red, _( "DANGEROUS AREA!" ) ); + } + } + } + + for( const auto &npc : overmap_buffer.get_npcs_near_omt( center_abs_omt, 0 ) ) { + if( !npc->marked_for_death ) { + notes_window_text.emplace_back( npc->basic_symbol_color(), npc->name ); + } + } + + for( auto &v : overmap_buffer.get_vehicle( center_abs_omt ) ) { + notes_window_text.emplace_back( c_white, v.name ); + } + + if( !notes_window_text.empty() ) { + constexpr int padding = 2; + + const auto note_bg = [&]( const point & draw_pos, const std::string & name, nc_color & color ) { + const int name_length = name.length(); + SDL_Rect clipRect = { draw_pos.x - padding, draw_pos.y - padding, name_length *fontwidth + padding * 2, fontheight + padding * 2}; + printErrorIf( SDL_RenderSetClipRect( renderer.get(), &clipRect ) != 0, + "SDL_RenderSetClipRect failed" ); + + geometry->rect( renderer, clipRect, SDL_Color{0, 0, 0, 175} ); + + const point label_pos( draw_pos + point( -( name.length() * fontwidth / 2 ), 0 ) ); + char note_fg_color = color == c_yellow ? 11 : + cata_cursesport::colorpairs[color.to_color_pair_index()].FG; + map_font->OutputChar( renderer, geometry, name, label_pos, note_fg_color ); + }; + + auto center_sm = coords::project_to( tripoint_abs_omt( center_abs_omt.x() + 1, + center_abs_omt.y(), center_abs_omt.z() ) ); + const tripoint tile_draw_pos = global_omt_to_draw_position( project_to + ( center_sm ) ) - o; + point draw_point( tile_draw_pos.x * width / max_col, tile_draw_pos.y * height / max_row ); + draw_point.x += width / max_col; + + nc_color header_color = c_white; + note_bg( draw_point, "Notes:", header_color ); + draw_point.y += fontheight + padding * 2; + for( auto &line : notes_window_text ) { + note_bg( draw_point, line.second, line.first ); + draw_point.y += fontheight + padding; + } + } } static bool draw_window( Font_Ptr &font, const catacurses::window &w, const point &offset ) From 9b72a715d40017c13bbd75e755f6858070283886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mu=C3=B1oz?= Date: Sat, 24 Jul 2021 18:25:15 +0200 Subject: [PATCH 02/13] Invalidate region to properly refresh overmap windows --- src/overmap_ui.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/overmap_ui.cpp b/src/overmap_ui.cpp index 2ba3bb7df7bc1..904e87e194635 100644 --- a/src/overmap_ui.cpp +++ b/src/overmap_ui.cpp @@ -99,8 +99,6 @@ static const int npm_width = 3; /** Note preview map height without borders. Odd number. */ static const int npm_height = 3; -static bool creating_note = false; - namespace overmap_ui { // {note symbol, note color, offset to text} @@ -1146,9 +1144,10 @@ void draw( } else { #ifdef TILES cata_cursesport::WINDOW *const win = w.get(); - if( !creating_note ) { - tilecontext->draw_om( win->pos, center, blink ); - } + tilecontext->draw_om( win->pos, center, blink ); + ui_manager::invalidate( rectangle( win->pos, point( win->pos.x + win->width, + win->pos.y + win->height ) ), false ); + #endif // TILES } } @@ -1187,8 +1186,7 @@ void create_note( const tripoint_abs_omt &curs ) catacurses::window w_preview_map; std::tuple preview_windows; - ui_adaptor ui; - creating_note = true; + ui_adaptor ui( ui_adaptor::disable_uis_below{} ); ui.on_screen_resize( [&]( ui_adaptor & ui ) { w_preview = catacurses::newwin( npm_height + 2, max_note_display_length - npm_width - 1, @@ -1238,7 +1236,6 @@ void create_note( const tripoint_abs_omt &curs ) } else if( !esc_pressed && old_note != new_note ) { overmap_buffer.add_note( curs, new_note ); } - creating_note = false; } // if false, search yielded no results From 7a760cfff1bfdb2da8eab501eb210b57f5dec1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mu=C3=B1oz?= Date: Sat, 24 Jul 2021 19:27:43 +0200 Subject: [PATCH 03/13] Avoid SDL_RenderSetClipRect() calls --- src/overmap_ui.cpp | 5 +---- src/sdltiles.cpp | 4 ---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/overmap_ui.cpp b/src/overmap_ui.cpp index 904e87e194635..0a375abb828c4 100644 --- a/src/overmap_ui.cpp +++ b/src/overmap_ui.cpp @@ -1145,9 +1145,6 @@ void draw( #ifdef TILES cata_cursesport::WINDOW *const win = w.get(); tilecontext->draw_om( win->pos, center, blink ); - ui_manager::invalidate( rectangle( win->pos, point( win->pos.x + win->width, - win->pos.y + win->height ) ), false ); - #endif // TILES } } @@ -1186,7 +1183,7 @@ void create_note( const tripoint_abs_omt &curs ) catacurses::window w_preview_map; std::tuple preview_windows; - ui_adaptor ui( ui_adaptor::disable_uis_below{} ); + ui_adaptor ui; ui.on_screen_resize( [&]( ui_adaptor & ui ) { w_preview = catacurses::newwin( npm_height + 2, max_note_display_length - npm_width - 1, diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index aebabd9e31ec7..bad882246c446 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -1051,8 +1051,6 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ const int name_length = name.length(); const point draw_pos = abs_sm_to_draw_label( pos, name_length ); SDL_Rect clipRect = { draw_pos.x, draw_pos.y, name_length * fontwidth, fontheight }; - printErrorIf( SDL_RenderSetClipRect( renderer.get(), &clipRect ) != 0, - "SDL_RenderSetClipRect failed" ); geometry->rect( renderer, clipRect, SDL_Color() ); @@ -1115,8 +1113,6 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ const auto note_bg = [&]( const point & draw_pos, const std::string & name, nc_color & color ) { const int name_length = name.length(); SDL_Rect clipRect = { draw_pos.x - padding, draw_pos.y - padding, name_length *fontwidth + padding * 2, fontheight + padding * 2}; - printErrorIf( SDL_RenderSetClipRect( renderer.get(), &clipRect ) != 0, - "SDL_RenderSetClipRect failed" ); geometry->rect( renderer, clipRect, SDL_Color{0, 0, 0, 175} ); From 3c92e3f62468376c80139fd2fd2a6eb6332ea2f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mu=C3=B1oz?= Date: Sat, 24 Jul 2021 19:49:10 +0200 Subject: [PATCH 04/13] Draw NPCs only on their Z level --- src/sdltiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index bad882246c446..6b1fdc25725cc 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -1011,7 +1011,7 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ // draw nearby seen npcs for( const shared_ptr_fast &guy : overmap_buffer.get_npcs_near_player( sight_points ) ) { const tripoint_abs_omt &guy_loc = guy->global_omt_location(); - if( overmap_buffer.seen( guy_loc ) ) { + if( overmap_buffer.seen( guy_loc ) && guy_loc.z() == center_abs_omt.z() ) { draw_entity_with_overlays( *guy, global_omt_to_draw_position( guy_loc ), lit_level::LIT, height_3d ); } From 95e024f0d614a3e90a369c5ff5da39f0b89f10db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mu=C3=B1oz?= Date: Sat, 24 Jul 2021 19:51:53 +0200 Subject: [PATCH 05/13] Add missing SDL_RenderSetClipRect() reset at the end of draw_om() --- src/sdltiles.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 6b1fdc25725cc..d63c95da627f8 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -1137,6 +1137,8 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ draw_point.y += fontheight + padding; } } + + SDL_RenderSetClipRect( renderer.get(), nullptr ); } static bool draw_window( Font_Ptr &font, const catacurses::window &w, const point &offset ) From 4edf4b6859cd9153d93a780ec983d4f899bbca57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro?= Date: Sat, 24 Jul 2021 20:10:56 +0200 Subject: [PATCH 06/13] Update src/sdltiles.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jianxiang Wang (王健翔) --- src/sdltiles.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index d63c95da627f8..f744aad6cf9df 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -1138,7 +1138,8 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ } } - SDL_RenderSetClipRect( renderer.get(), nullptr ); + printErrorIf( SDL_RenderSetClipRect( renderer.get(), nullptr ) != 0, + "SDL_RenderSetClipRect failed" ); } static bool draw_window( Font_Ptr &font, const catacurses::window &w, const point &offset ) From 396501193f4087fc4d084765553dcb5bb70d81de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mu=C3=B1oz?= Date: Sat, 24 Jul 2021 20:13:31 +0200 Subject: [PATCH 07/13] Remove unneeded comment --- src/sdltiles.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index f744aad6cf9df..be0ec927b78cf 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -1034,7 +1034,6 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ } } - // Labels need to be drawn last, as anything that attempts to draw a sprite after will fail. if( !viewing_weather && uistate.overmap_show_city_labels ) { const auto abs_sm_to_draw_label = [&]( const tripoint_abs_sm & city_pos, const int label_length ) { From 250f9b12418fce9c2fade762e37e81eed7f6ac3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mu=C3=B1oz?= Date: Sat, 24 Jul 2021 22:01:02 +0200 Subject: [PATCH 08/13] Add color tag support to graphical overmap notes --- src/output.cpp | 6 ++--- src/output.h | 15 ++++++++++++- src/sdltiles.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/output.cpp b/src/output.cpp index 9797bf8f664c6..f6d340d5c6a66 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -61,8 +61,6 @@ int OVERMAP_WINDOW_TERM_HEIGHT; int OVERMAP_LEGEND_WIDTH; -static std::string rm_prefix( std::string str, char c1 = '<', char c2 = '>' ); - scrollingcombattext SCT; // utf8 version @@ -162,9 +160,9 @@ std::string remove_color_tags( const std::string &s ) return ret; } -static color_tag_parse_result::tag_type update_color_stack( +color_tag_parse_result::tag_type update_color_stack( std::stack &color_stack, const std::string &seg, - const report_color_error color_error = report_color_error::yes ) + const report_color_error color_error ) { color_tag_parse_result tag = get_color_from_tag( seg, color_error ); switch( tag.type ) { diff --git a/src/output.h b/src/output.h index aabed23bdf32b..91c5e07608d8b 100644 --- a/src/output.h +++ b/src/output.h @@ -199,8 +199,21 @@ nc_color msgtype_to_color( game_message_type type, bool bOldMsg = false ); * color tags. For example `utf8_width("text")` would return 23, but * `utf8_width("text", true)` returns 4 (the length of "text"). */ - /*@{*/ + +/** + * Removes the prefix starting at the first occurrence of c1 until the first occurrence of c2 + */ +std::string rm_prefix( std::string str, char c1 = '<', char c2 = '>' ); + +/** + * Adds the color represented by the next color tag found in the string to the top of the stack. + * If color_error == report_color_error::yes a debugmsg will be shown when the tag is not valid. + */ +color_tag_parse_result::tag_type update_color_stack( + std::stack &color_stack, const std::string &seg, + const report_color_error color_error = report_color_error::yes ); + /** * Removes the color tags from the input string. This might be required when the string is to * be used for functions that don't handle color tags. diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index be0ec927b78cf..dfa4593839f62 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -1109,18 +1110,16 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ if( !notes_window_text.empty() ) { constexpr int padding = 2; - const auto note_bg = [&]( const point & draw_pos, const std::string & name, nc_color & color ) { + const auto draw_note_text = [&]( const point & draw_pos, const std::string & name, + nc_color & color ) { const int name_length = name.length(); - SDL_Rect clipRect = { draw_pos.x - padding, draw_pos.y - padding, name_length *fontwidth + padding * 2, fontheight + padding * 2}; - - geometry->rect( renderer, clipRect, SDL_Color{0, 0, 0, 175} ); - const point label_pos( draw_pos + point( -( name.length() * fontwidth / 2 ), 0 ) ); char note_fg_color = color == c_yellow ? 11 : cata_cursesport::colorpairs[color.to_color_pair_index()].FG; map_font->OutputChar( renderer, geometry, name, label_pos, note_fg_color ); }; + // Find screen coordinates to the right of the center tile auto center_sm = coords::project_to( tripoint_abs_omt( center_abs_omt.x() + 1, center_abs_omt.y(), center_abs_omt.z() ) ); const tripoint tile_draw_pos = global_omt_to_draw_position( project_to @@ -1128,11 +1127,55 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ point draw_point( tile_draw_pos.x * width / max_col, tile_draw_pos.y * height / max_row ); draw_point.x += width / max_col; + // Draw notes header. Very simple label at the moment nc_color header_color = c_white; - note_bg( draw_point, "Notes:", header_color ); + const std::string header_string = "-- Notes: --"; + SDL_Rect header_background_rect = { draw_point.x - padding, draw_point.y - padding, fontwidth *static_cast( header_string.length() ) + padding * 2, fontheight + padding * 2 }; + geometry->rect( renderer, header_background_rect, SDL_Color{ 0, 0, 0, 175 } ); + draw_note_text( draw_point, "header_string", header_color ); draw_point.y += fontheight + padding * 2; + + const int starting_x = draw_point.x; + for( auto &line : notes_window_text ) { - note_bg( draw_point, line.second, line.first ); + const auto color_segments = split_by_color( line.second ); + std::stack color_stack; + nc_color default_color = std::get<0>( line ); + color_stack.push( default_color ); + std::vector> colored_lines; + + draw_point.x = starting_x; + + int line_length = 0; + for( auto seg : color_segments ) { + if( seg.empty() ) { + continue; + } + + if( seg[0] == '<' ) { + const color_tag_parse_result::tag_type type = update_color_stack( + color_stack, seg, report_color_error::no ); + if( type != color_tag_parse_result::non_color_tag ) { + seg = rm_prefix( seg ); + } + } + + nc_color &color = color_stack.empty() ? default_color : color_stack.top(); + colored_lines.emplace_back( color, seg ); + line_length += seg.length(); + } + + // Draw background first for the whole line + SDL_Rect background_rect = { draw_point.x - padding, draw_point.y - padding, fontwidth *line_length + padding * 2, fontheight + padding * 2 }; + geometry->rect( renderer, background_rect, SDL_Color{ 0, 0, 0, 175 } ); + + // Draw colored text segments + for( auto &colored_line : colored_lines ) { + std::string &text = std::get<1>( colored_line ); + draw_note_text( draw_point, text, std::get<0>( colored_line ) ); + draw_point.x += fontwidth * text.length(); + } + draw_point.y += fontheight + padding; } } From f3c1e7145cb484ec4dcfcb9c06fb63a60f5a2c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mu=C3=B1oz?= Date: Sat, 24 Jul 2021 22:02:30 +0200 Subject: [PATCH 09/13] You didn't see this. Don't make me rebase. --- src/sdltiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index dfa4593839f62..89f68b97fae98 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -1132,7 +1132,7 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ const std::string header_string = "-- Notes: --"; SDL_Rect header_background_rect = { draw_point.x - padding, draw_point.y - padding, fontwidth *static_cast( header_string.length() ) + padding * 2, fontheight + padding * 2 }; geometry->rect( renderer, header_background_rect, SDL_Color{ 0, 0, 0, 175 } ); - draw_note_text( draw_point, "header_string", header_color ); + draw_note_text( draw_point, header_string, header_color ); draw_point.y += fontheight + padding * 2; const int starting_x = draw_point.x; From 71dd903d342794708ef4f3f6fe14f69c3da7a467 Mon Sep 17 00:00:00 2001 From: Qrox Date: Sun, 25 Jul 2021 12:36:38 +0800 Subject: [PATCH 10/13] Remove unused variables --- src/sdltiles.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 89f68b97fae98..41e07918a3d56 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -833,10 +833,6 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ geometry->rect( renderer, clipRect, SDL_Color() ); } - // color blocks overlay; drawn on top of tiles and on top of overlay strings (if any). - color_block_overlay_container color_blocks; - // Strings with colors do be drawn with map_font on top of tiles. - std::multimap overlay_strings; point s; get_window_tile_counts( width, height, s.x, s.y ); From a35585384a35655574abf3cfb68211021bca54bf Mon Sep 17 00:00:00 2001 From: Qrox Date: Sun, 25 Jul 2021 13:17:01 +0800 Subject: [PATCH 11/13] Fix city label & note position --- src/output.h | 1 + src/sdltiles.cpp | 62 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/output.h b/src/output.h index 91c5e07608d8b..6a6b1108833a5 100644 --- a/src/output.h +++ b/src/output.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 41e07918a3d56..cac04320e9859 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -806,6 +806,24 @@ std::string cata_tiles::get_omt_id_rotation_and_subtile( return ot_type_id.id().str(); } +static point draw_string( Font &font, + const SDL_Renderer_Ptr &renderer, + const GeometryRenderer_Ptr &geometry, + const std::string &str, + point p, + const unsigned char color ) +{ + const char *cstr = str.c_str(); + int len = str.length(); + while( len > 0 ) { + const uint32_t ch32 = UTF8_getch( &cstr, &len ); + const std::string ch = utf32_to_utf8( ch32 ); + font.OutputChar( renderer, geometry, ch, p, color ); + p.x += mk_wcwidth( ch32 ) * font.width; + } + return p; +} + void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_omt, bool blink ) { if( !g ) { @@ -1036,22 +1054,23 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ const auto abs_sm_to_draw_label = [&]( const tripoint_abs_sm & city_pos, const int label_length ) { const tripoint tile_draw_pos = global_omt_to_draw_position( project_to ( city_pos ) ) - o; - point draw_point( tile_draw_pos.x * width / max_col, tile_draw_pos.y * height / max_row ); - draw_point.x -= label_length * font->width; - draw_point.x += width / max_col; + point draw_point( tile_draw_pos.x * tile_width + dest.x, + tile_draw_pos.y * tile_height + dest.y ); + // center text on the tile + draw_point += point( ( tile_width - label_length * fontwidth ) / 2, + ( tile_height - fontheight ) / 2 ); return draw_point; }; // draws a black rectangle behind a label for visibility and legibility const auto label_bg = [&]( const tripoint_abs_sm & pos, const std::string & name ) { - const int name_length = name.length(); + const int name_length = utf8_width( name ); const point draw_pos = abs_sm_to_draw_label( pos, name_length ); SDL_Rect clipRect = { draw_pos.x, draw_pos.y, name_length * fontwidth, fontheight }; geometry->rect( renderer, clipRect, SDL_Color() ); - const point label_pos( draw_pos + point( -( name.length() * fontwidth / 2 ), 0 ) ); - map_font->OutputChar( renderer, geometry, name, label_pos, 11 ); + draw_string( *font, renderer, geometry, name, draw_pos, 11 ); }; // the tiles on the overmap are overmap tiles, so we need to use @@ -1108,11 +1127,9 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ const auto draw_note_text = [&]( const point & draw_pos, const std::string & name, nc_color & color ) { - const int name_length = name.length(); - const point label_pos( draw_pos + point( -( name.length() * fontwidth / 2 ), 0 ) ); char note_fg_color = color == c_yellow ? 11 : cata_cursesport::colorpairs[color.to_color_pair_index()].FG; - map_font->OutputChar( renderer, geometry, name, label_pos, note_fg_color ); + return draw_string( *font, renderer, geometry, name, draw_pos, note_fg_color ); }; // Find screen coordinates to the right of the center tile @@ -1120,13 +1137,19 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ center_abs_omt.y(), center_abs_omt.z() ) ); const tripoint tile_draw_pos = global_omt_to_draw_position( project_to ( center_sm ) ) - o; - point draw_point( tile_draw_pos.x * width / max_col, tile_draw_pos.y * height / max_row ); - draw_point.x += width / max_col; + point draw_point( tile_draw_pos.x * tile_width + dest.x, + tile_draw_pos.y * tile_height + dest.y ); + draw_point += point( padding, padding ); // Draw notes header. Very simple label at the moment nc_color header_color = c_white; - const std::string header_string = "-- Notes: --"; - SDL_Rect header_background_rect = { draw_point.x - padding, draw_point.y - padding, fontwidth *static_cast( header_string.length() ) + padding * 2, fontheight + padding * 2 }; + const std::string header_string = _( "-- Notes: --" ); + SDL_Rect header_background_rect = { + draw_point.x - padding, + draw_point.y - padding, + fontwidth * utf8_width( header_string ) + padding * 2, + fontheight + padding * 2 + }; geometry->rect( renderer, header_background_rect, SDL_Color{ 0, 0, 0, 175 } ); draw_note_text( draw_point, header_string, header_color ); draw_point.y += fontheight + padding * 2; @@ -1158,18 +1181,22 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ nc_color &color = color_stack.empty() ? default_color : color_stack.top(); colored_lines.emplace_back( color, seg ); - line_length += seg.length(); + line_length += utf8_width( seg ); } // Draw background first for the whole line - SDL_Rect background_rect = { draw_point.x - padding, draw_point.y - padding, fontwidth *line_length + padding * 2, fontheight + padding * 2 }; + SDL_Rect background_rect = { + draw_point.x - padding, + draw_point.y - padding, + fontwidth *line_length + padding * 2, + fontheight + padding * 2 + }; geometry->rect( renderer, background_rect, SDL_Color{ 0, 0, 0, 175 } ); // Draw colored text segments for( auto &colored_line : colored_lines ) { std::string &text = std::get<1>( colored_line ); - draw_note_text( draw_point, text, std::get<0>( colored_line ) ); - draw_point.x += fontwidth * text.length(); + draw_point.x = draw_note_text( draw_point, text, std::get<0>( colored_line ) ).x; } draw_point.y += fontheight + padding; @@ -2405,6 +2432,7 @@ void draw_quick_shortcuts() text_x = ( ( i + 0.5f ) * width - ( font->width * utf8_width( text ) ) * text_scale * 0.5f ) / text_scale; } + // TODO use draw_string instead text_y = ( WindowHeight - ( height + font->height * text_scale ) * 0.5f ) / text_scale; font->OutputChar( renderer, geometry, text, point( text_x + 1, text_y + 1 ), 0, get_option( "ANDROID_SHORTCUT_OPACITY_SHADOW" ) * 0.01f ); From af19abd23dbd8ae72fd054a9f4f7d13e4333b14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mu=C3=B1oz?= Date: Sun, 25 Jul 2021 13:52:01 +0200 Subject: [PATCH 12/13] Fix NPC notes displaying when NPCs aren't visible --- src/overmap_ui.cpp | 12 +++++++----- src/sdltiles.cpp | 21 ++++++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/overmap_ui.cpp b/src/overmap_ui.cpp index 0a375abb828c4..bafe65d3c21c2 100644 --- a/src/overmap_ui.cpp +++ b/src/overmap_ui.cpp @@ -617,10 +617,10 @@ static void draw_ascii( std::vector path_route; std::vector player_path_route; std::unordered_map npc_color; + auto npcs_near_player = overmap_buffer.get_npcs_near_player( sight_points ); if( blink ) { // get seen NPCs - const auto &npcs = overmap_buffer.get_npcs_near_player( sight_points ); - for( const auto &np : npcs ) { + for( const auto &np : npcs_near_player ) { if( np->posz() != center.z() ) { continue; } @@ -900,9 +900,11 @@ static void draw_ascii( } } - for( const auto &npc : overmap_buffer.get_npcs_near_omt( center, 0 ) ) { - if( !npc->marked_for_death ) { - corner_text.emplace_back( npc->basic_symbol_color(), npc->name ); + if( has_debug_vision || overmap_buffer.seen( center ) ) { + for( const auto &npc : npcs_near_player ) { + if( !npc->marked_for_death && npc->global_omt_location() == center ) { + corner_text.emplace_back( npc->basic_symbol_color(), npc->name ); + } } } diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index cac04320e9859..06a93622fa0f3 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -1023,10 +1023,12 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ } } + auto npcs_near_player = overmap_buffer.get_npcs_near_player( sight_points ); + // draw nearby seen npcs - for( const shared_ptr_fast &guy : overmap_buffer.get_npcs_near_player( sight_points ) ) { + for( const shared_ptr_fast &guy : npcs_near_player ) { const tripoint_abs_omt &guy_loc = guy->global_omt_location(); - if( overmap_buffer.seen( guy_loc ) && guy_loc.z() == center_abs_omt.z() ) { + if( guy_loc.z() == center_abs_omt.z() && ( has_debug_vision || overmap_buffer.seen( guy_loc ) ) ) { draw_entity_with_overlays( *guy, global_omt_to_draw_position( guy_loc ), lit_level::LIT, height_3d ); } @@ -1038,6 +1040,13 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ false ); if( blink ) { + // Draw path for auto-travel + for( auto &elem : you.omt_path ) { + tripoint_abs_omt pos( elem.xy(), you.posz() ); + draw_from_id_string( "cursor", global_omt_to_draw_position( pos ), 0, 0, lit_level::LIT, + false ); + } + // reduce the area where the map cursor is drawn so it doesn't get cut off inclusive_cuboid map_cursor_area = overmap_area; map_cursor_area.p_max.y--; @@ -1112,9 +1121,11 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ } } - for( const auto &npc : overmap_buffer.get_npcs_near_omt( center_abs_omt, 0 ) ) { - if( !npc->marked_for_death ) { - notes_window_text.emplace_back( npc->basic_symbol_color(), npc->name ); + if( has_debug_vision || overmap_buffer.seen( center_abs_omt ) ) { + for( const auto &npc : npcs_near_player ) { + if( !npc->marked_for_death && npc->global_omt_location() == center_abs_omt ) { + notes_window_text.emplace_back( npc->basic_symbol_color(), npc->name ); + } } } From 04ba48ded0873993bd06f3c034581566c1474daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mu=C3=B1oz?= Date: Sun, 25 Jul 2021 17:01:31 +0200 Subject: [PATCH 13/13] Change auto-travel path to use higlight instead of cursor sprite --- src/sdltiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 06a93622fa0f3..56fb5fc866e66 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -1043,7 +1043,7 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ // Draw path for auto-travel for( auto &elem : you.omt_path ) { tripoint_abs_omt pos( elem.xy(), you.posz() ); - draw_from_id_string( "cursor", global_omt_to_draw_position( pos ), 0, 0, lit_level::LIT, + draw_from_id_string( "highlight", global_omt_to_draw_position( pos ), 0, 0, lit_level::LIT, false ); }