From 6bfca038ff076bc1af991cc1ff00f727bbe96e61 Mon Sep 17 00:00:00 2001 From: "Clarence \"Sparr\" Risher" Date: Sun, 3 Nov 2024 16:49:57 -0500 Subject: [PATCH] Add optional message to display when choosing map point --- src/computer_session.cpp | 3 ++- src/debug_menu.cpp | 6 +++-- src/faction_camp.cpp | 58 ++++++++++++++++++++-------------------- src/overmap_ui.cpp | 26 +++++++++--------- src/overmap_ui.h | 17 ++++++++---- src/sdltiles.cpp | 14 ++++++++++ 6 files changed, 74 insertions(+), 50 deletions(-) diff --git a/src/computer_session.cpp b/src/computer_session.cpp index e9f826c5d1a30..4819d5aa26402 100644 --- a/src/computer_session.cpp +++ b/src/computer_session.cpp @@ -744,7 +744,8 @@ void computer_session::action_miss_disarm() void computer_session::action_miss_launch() { // Target Acquisition. - const tripoint_abs_omt target( ui::omap::choose_point( 0 ) ); + const tripoint_abs_omt target( ui::omap::choose_point( + _( "Choose a target for the nuclear missile." ), 0 ) ); if( target == overmap::invalid_tripoint ) { add_msg( m_info, _( "Target acquisition canceled." ) ); return; diff --git a/src/debug_menu.cpp b/src/debug_menu.cpp index 03a8c0d2c3539..93848dbf2a7e0 100644 --- a/src/debug_menu.cpp +++ b/src/debug_menu.cpp @@ -1752,7 +1752,8 @@ static void teleport_short() static void teleport_long() { - const tripoint_abs_omt where( ui::omap::choose_point( true ) ); + const tripoint_abs_omt where( ui::omap::choose_point( _( "Choose a teleport destination." ), + true ) ); if( where == overmap::invalid_tripoint ) { return; } @@ -3526,7 +3527,8 @@ static void map_extra() mx_menu.query(); int mx_choice = mx_menu.ret; if( mx_choice >= 0 && mx_choice < static_cast( mx_str.size() ) ) { - const tripoint_abs_omt where_omt( ui::omap::choose_point( true ) ); + const tripoint_abs_omt where_omt( ui::omap::choose_point( + _( "Select location to spawn map extra." ), true ) ); if( where_omt != overmap::invalid_tripoint ) { smallmap mx_map; mx_map.load( where_omt, false ); diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 5e1a30d770a42..9975be0a34e9e 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -285,9 +285,8 @@ static tripoint_abs_omt om_target_tile( const tripoint_abs_omt &omt_pos, int min_range = 1, int range = 1, const std::vector &possible_om_types = {}, ot_match_type match_type = ot_match_type::exact, bool must_see = true, - bool popup_notice = true, const tripoint_abs_omt &source = tripoint_abs_omt( -999, -999, -999 ), - bool bounce = false ); + bool bounce = false, const std::optional message = std::nullopt ); static void om_range_mark( const tripoint_abs_omt &origin, int range, bool add_notes = true, const std::string &message = "Y;X: MAX RANGE" ); static void om_line_mark( @@ -968,7 +967,8 @@ void basecamp::get_available_missions_by_dir( mission_data &mission_key, const p const mission_id miss_id = { Camp_Clearcut, "", {}, dir }; comp_list npc_list = get_mission_workers( miss_id ); entry = string_format( _( "Notes:\n" - "Send a companion to clear a nearby forest.\n\n" + "Send a companion to clear a nearby forest.\n" + "Note that it's likely both forest and field roads look exactly the same after having been cleared.\n\n" "Skill used: fabrication\n" "Difficulty: 1\n" "Effects:\n" @@ -2582,8 +2582,8 @@ void basecamp::start_cut_logs( const mission_id &miss_id, float exertion_level ) std::vector log_sources = { "forest", "forest_thick", "forest_trail", "rural_road_forest", "rural_road_turn_forest", "rural_road_turn1_forest", "rural_road_3way_forest", "dirt_road_forest", "dirt_road_3way_forest", "dirt_road_turn_forest", "forest_trail_intersection", "special_forest", "special_forest_thick", "forest_trail_isolated", "forest_trail_end" }; - popup( _( "Forests are the only valid cutting locations, with forest dirt roads, forest rural roads, and trails being valid as well. Note that it's likely both forest and field roads look exactly the same after having been cleared." ) ); - tripoint_abs_omt forest = om_target_tile( omt_pos, 1, 50, log_sources, ot_match_type::type ); + tripoint_abs_omt forest = om_target_tile( omt_pos, 1, 50, log_sources, ot_match_type::type, + _( "Select a forest (or road/trail) from %d to %d tiles away." ) ); if( forest != tripoint_abs_omt( -999, -999, -999 ) ) { standard_npc sample_npc( "Temp" ); sample_npc.set_fake( true ); @@ -2656,9 +2656,9 @@ void basecamp::start_setup_hide_site( const mission_id &miss_id, float exertion_ std::vector hide_locations = { "forest", "forest_thick", "forest_water", "forest_trail" "field" }; - popup( _( "Forests, swamps, and fields are valid hide site locations." ) ); - tripoint_abs_omt forest = om_target_tile( omt_pos, 10, 90, hide_locations, ot_match_type::type, - true, true, omt_pos, true ); + tripoint_abs_omt forest = om_target_tile( omt_pos, 10, 90, hide_locations, + ot_match_type::type, + true, omt_pos, true, _( "Select an forest, swamp, or field from %d to %d tiles away." ) ); if( forest != tripoint_abs_omt( -999, -999, -999 ) ) { int dist = rl_dist( forest.xy(), omt_pos.xy() ); Character *pc = &get_player_character(); @@ -2703,9 +2703,9 @@ static const tripoint_omt_ms relay_site_stash{ 11, 10, 0 }; void basecamp::start_relay_hide_site( const mission_id &miss_id, float exertion_level ) { std::vector hide_locations = { faction_hide_site_0_string }; - popup( _( "You must select an existing hide site." ) ); tripoint_abs_omt forest = om_target_tile( omt_pos, 10, 90, hide_locations, ot_match_type::exact, - true, true, omt_pos, true ); + true, omt_pos, true, string_format( + _( "Select an existing hide site from %d to %d tiles away." ), 10, 90 ) ); if( forest != tripoint_abs_omt( -999, -999, -999 ) ) { int dist = rl_dist( forest.xy(), omt_pos.xy() ); Character *pc = &get_player_character(); @@ -2833,10 +2833,11 @@ void basecamp::start_fortifications( const mission_id &miss_id, float exertion_l popup( _( "Select a start and end point. Line must be straight. Fields, forests, and " "swamps are valid fortification locations. In addition to existing fortification " "constructions." ) ); - tripoint_abs_omt start = om_target_tile( omt_pos, 2, 90, allowed_locations, ot_match_type::type ); - popup( _( "Select an end point." ) ); - tripoint_abs_omt stop = om_target_tile( omt_pos, 2, 90, allowed_locations, ot_match_type::type, - true, false, start ); + tripoint_abs_omt start = om_target_tile( omt_pos, 2, 90, allowed_locations, + ot_match_type::type, true, omt_pos, _( "Select a start point from %d to %d tiles away." ) ); + tripoint_abs_omt stop = om_target_tile( omt_pos, 2, 90, allowed_locations, + ot_match_type::type, + true, start, _( "Select an end point from %d to %d tiles away." ) ); if( start != tripoint_abs_omt( -999, -999, -999 ) && stop != tripoint_abs_omt( -999, -999, -999 ) ) { const recipe &making = recipe_id( miss_id.parameters ).obj(); @@ -4486,12 +4487,12 @@ bool basecamp::survey_field_return( const mission_id &miss_id ) return false; } - popup( _( "Select a tile up to %d tiles away." ), 1 ); tripoint_abs_omt where( get_player_character().global_omt_location() ); while( true ) { - where = ui::omap::choose_point( where ); + where = ui::omap::choose_point( string_format( + _( "Select a tile up to %d tiles away." ), 1 ) ); if( where == overmap::invalid_tripoint ) { return false; } @@ -4568,12 +4569,12 @@ bool basecamp::survey_return( const mission_id &miss_id ) return false; } - popup( _( "Select a tile up to %d tiles away." ), 1 ); tripoint_abs_omt where( get_player_character().global_omt_location() ); while( true ) { - where = ui::omap::choose_point( where ); + where = ui::omap::choose_point( string_format( + _( "Select a tile up to %d tiles away." ), 1 ) ); if( where == overmap::invalid_tripoint ) { return false; } @@ -4984,22 +4985,20 @@ mass_volume om_harvest_itm( const npc_ptr &comp, const tripoint_abs_omt &omt_tgt tripoint_abs_omt om_target_tile( const tripoint_abs_omt &omt_pos, int min_range, int range, const std::vector &possible_om_types, ot_match_type match_type, bool must_see, - bool popup_notice, const tripoint_abs_omt &source, bool bounce ) + const tripoint_abs_omt &source, bool bounce, const std::optional message ) { bool errors = false; - if( popup_notice ) { - popup( _( "Select a location between %d and %d tiles away." ), min_range, range ); - } - std::vector bounce_locations = { faction_hide_site_0_string }; tripoint_abs_omt where; om_range_mark( omt_pos, range ); om_range_mark( omt_pos, min_range, true, "Y;X: MIN RANGE" ); + const std::string &real_message = string_format( + message ? *message : _( "Select a location from %d to %d tiles away." ), min_range, range ); if( source == tripoint_abs_omt( -999, -999, -999 ) ) { - where = ui::omap::choose_point(); + where = ui::omap::choose_point( real_message ); } else { - where = ui::omap::choose_point( source ); + where = ui::omap::choose_point( real_message, source ); } om_range_mark( omt_pos, range, false ); om_range_mark( omt_pos, min_range, false, "Y;X: MIN RANGE" ); @@ -5009,7 +5008,7 @@ tripoint_abs_omt om_target_tile( const tripoint_abs_omt &omt_pos, int min_range, } int dist = rl_dist( where.xy(), omt_pos.xy() ); if( dist > range || dist < min_range ) { - popup( _( "You must select a target between %d and %d range from the base. Range: %d" ), + popup( _( "You must select a target from %d to %d range. Your selection was range %d." ), min_range, range, dist ); errors = true; } @@ -5029,7 +5028,7 @@ tripoint_abs_omt om_target_tile( const tripoint_abs_omt &omt_pos, int min_range, if( query_yn( _( "Do you want to bounce off this location to extend range?" ) ) ) { om_line_mark( omt_pos, omt_tgt ); tripoint_abs_omt dest = - om_target_tile( omt_tgt, 2, range * .75, possible_om_types, match_type, true, false, + om_target_tile( omt_tgt, 2, range * .75, possible_om_types, match_type, true, omt_tgt, true ); om_line_mark( omt_pos, omt_tgt, false ); return dest; @@ -5048,7 +5047,8 @@ tripoint_abs_omt om_target_tile( const tripoint_abs_omt &omt_pos, int min_range, } } - return om_target_tile( omt_pos, min_range, range, possible_om_types, match_type ); + return om_target_tile( omt_pos, min_range, range, possible_om_types, match_type, must_see, + omt_pos ); } void om_range_mark( const tripoint_abs_omt &origin, int range, bool add_notes, @@ -5221,7 +5221,7 @@ std::vector om_companion_path( const tripoint_abs_omt &start, int range = range_start; int def_range = range_start; while( range > 3 ) { - tripoint_abs_omt spt = om_target_tile( last, 0, range, {}, ot_match_type::exact, false, true, last, + tripoint_abs_omt spt = om_target_tile( last, 0, range, {}, ot_match_type::exact, false, last, false ); if( spt == tripoint_abs_omt( -999, -999, -999 ) ) { scout_points.clear(); diff --git a/src/overmap_ui.cpp b/src/overmap_ui.cpp index 5a0af3d78d620..889b04109067b 100644 --- a/src/overmap_ui.cpp +++ b/src/overmap_ui.cpp @@ -854,6 +854,10 @@ static void draw_ascii( std::vector> corner_text; + if( !data.message.empty() ) { + corner_text.emplace_back( c_white, data.message ); + } + if( uistate.overmap_show_map_notes ) { const std::string ¬e_text = overmap_buffer.note( cursor_pos ); if( !note_text.empty() ) { @@ -1702,8 +1706,8 @@ static void modify_horde_func( tripoint_abs_omt &curs ) chosen_group.set_interest( new_value ); break; case 1: - popup( _( "Select a target destination for the horde." ) ); - horde_destination = ui::omap::choose_point( true ); + horde_destination = ui::omap::choose_point( _( "Select a target destination for the horde." ), + true ); if( horde_destination == overmap::invalid_tripoint || horde_destination == tripoint_abs_omt_zero ) { break; } @@ -2496,30 +2500,26 @@ void ui::omap::display_zones( const tripoint_abs_omt ¢er, const tripoint_abs overmap_ui::display(); } -tripoint_abs_omt ui::omap::choose_point( bool show_debug_info ) +tripoint_abs_omt ui::omap::choose_point( std::string message, bool show_debug_info ) { - g->overmap_data = overmap_ui::overmap_draw_data_t(); - g->overmap_data.origin_pos = get_player_character().global_omt_location(); - g->overmap_data.debug_info = show_debug_info; - return overmap_ui::display(); + return choose_point( message, get_player_character().global_omt_location(), show_debug_info ); } -tripoint_abs_omt ui::omap::choose_point( const tripoint_abs_omt &origin, bool show_debug_info ) +tripoint_abs_omt ui::omap::choose_point( std::string message, const tripoint_abs_omt &origin, + bool show_debug_info ) { g->overmap_data = overmap_ui::overmap_draw_data_t(); + g->overmap_data.message = message; g->overmap_data.origin_pos = origin; g->overmap_data.debug_info = show_debug_info; return overmap_ui::display(); } -tripoint_abs_omt ui::omap::choose_point( int z, bool show_debug_info ) +tripoint_abs_omt ui::omap::choose_point( std::string message, int z, bool show_debug_info ) { - g->overmap_data = overmap_ui::overmap_draw_data_t(); - g->overmap_data.debug_info = show_debug_info; tripoint_abs_omt pos = get_player_character().global_omt_location(); pos.z() = z; - g->overmap_data.origin_pos = pos; - return overmap_ui::display(); + return choose_point( message, pos, show_debug_info ); } void ui::omap::setup_cities_menu( uilist &cities_menu, std::vector &cities_container ) diff --git a/src/overmap_ui.h b/src/overmap_ui.h index 77cc0e94d19b9..33e051f6102a7 100644 --- a/src/overmap_ui.h +++ b/src/overmap_ui.h @@ -75,20 +75,25 @@ void display_editor(); * @returns The absolute coordinates of the chosen point or * invalid_point if canceled with Escape (or similar key). */ -tripoint_abs_omt choose_point( bool show_debug_info = false ); +tripoint_abs_omt choose_point( std::string message = "", bool show_debug_info = false ); /** - * Same as above but start at z-level z instead of players - * current z-level, x and y are taken from the players position. + * Interactive point choosing; used as the map screen. + * The map is initially center at the players x and y + * location and the given z level. + * @returns The absolute coordinates of the chosen point or + * invalid_point if canceled with Escape (or similar key). */ -tripoint_abs_omt choose_point( int z, bool show_debug_info = false ); +tripoint_abs_omt choose_point( std::string message, int z, bool show_debug_info = false ); + /** * Interactive point choosing; used as the map screen. * The map is initially centered on the @ref origin. * @returns The absolute coordinates of the chosen point or * invalid_point if canceled with Escape (or similar key). */ -tripoint_abs_omt choose_point( const tripoint_abs_omt &origin, bool show_debug_info = false ); +tripoint_abs_omt choose_point( std::string message, const tripoint_abs_omt &origin, + bool show_debug_info = false ); void setup_cities_menu( uilist &cities_menu, std::vector &cities_container ); @@ -114,6 +119,8 @@ struct overmap_draw_data_t { bool show_explored = true; // currently fast traveling bool fast_traveling = false; + // message to display while using the map + std::string message; // draw zone location. tripoint_abs_omt select = tripoint_abs_omt( -1, -1, -1 ); diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 9a9a8f0e3706d..944ba29b0c71f 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -1108,6 +1108,20 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ notes_window_text.emplace_back( c_white, v.name ); } + if( ! g->overmap_data.message.empty() ) { + const int padding = 2; + SDL_Rect message_background_rect = { + 0, + 0, + fontwidth * utf8_width( g->overmap_data.message ) + padding * 2, + fontheight + padding * 2 + }; + geometry->rect( renderer, message_background_rect, SDL_Color{ 0, 0, 0, 175 } ); + draw_string( *font, renderer, geometry, g->overmap_data.message, point( padding, padding ), + cata_cursesport::colorpairs[c_white.to_color_pair_index()].FG ); + } + + if( !notes_window_text.empty() && !fast_traveling ) { constexpr int padding = 2;