Skip to content

Commit 846b1fe

Browse files
authored
Merge pull request #82528 from inogenous/mission-ui-coords
Mission UI: Update how locations are displayed
2 parents abcc146 + 5443ca7 commit 846b1fe

File tree

6 files changed

+47
-35
lines changed

6 files changed

+47
-35
lines changed

src/avatar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ bool avatar::is_map_memory_valid() const
234234

235235
bool avatar::should_show_map_memory() const
236236
{
237-
if( get_timed_events().get( timed_event_type::OVERRIDE_PLACE ) ) {
237+
if( !you_know_where_you_are() ) {
238238
return false;
239239
}
240240
return show_map_memory;

src/display.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,11 +1232,7 @@ std::string display::colorized_overmap_text( const avatar &u, const int width, c
12321232

12331233
std::string display::overmap_position_text( const tripoint_abs_omt &loc )
12341234
{
1235-
point_abs_omt abs_omt = loc.xy();
1236-
point_abs_om om;
1237-
point_om_omt omt;
1238-
std::tie( om, omt ) = project_remain<coords::om>( abs_omt );
1239-
return string_format( _( "LEVEL %i, %d'%d, %d'%d" ), loc.z(), om.x(), omt.x(), om.y(), omt.y() );
1235+
return loc.to_string();
12401236
}
12411237

12421238
std::string display::current_position_text( const tripoint_abs_omt &loc )

src/handle_action.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2940,7 +2940,7 @@ bool game::do_regular_action( action_id &act, avatar &player_character,
29402940
if( !here.is_outside( player_character.pos_bub() ) ) {
29412941
uistate.overmap_visible_weather = false;
29422942
}
2943-
if( !get_timed_events().get( timed_event_type::OVERRIDE_PLACE ) ) {
2943+
if( you_know_where_you_are() ) {
29442944
ui::omap::display();
29452945
} else {
29462946
add_msg( m_info, _( "You have no idea where you are." ) );

src/mission_ui.cpp

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,27 @@
1111
#include "color.h"
1212
#include "dialogue.h"
1313
#include "dialogue_helpers.h"
14+
#include "display.h"
1415
#include "game_constants.h"
1516
#include "imgui/imgui.h"
1617
#include "input_context.h"
18+
#include "line.h"
1719
#include "mission.h"
1820
#include "npc.h"
1921
#include "faction.h"
2022
#include "output.h"
2123
#include "point.h"
2224
#include "string_formatter.h"
2325
#include "talker.h"
26+
#include "timed_event.h"
2427
#include "translation.h"
2528
#include "translations.h"
2629
#include "ui_manager.h"
2730
#include "units.h"
2831
#include "units_utility.h"
2932

33+
static const faction_id faction_no_faction( "no_faction" );
34+
3035
enum class mission_ui_tab_enum : int {
3136
ACTIVE = 0,
3237
COMPLETED,
@@ -77,6 +82,8 @@ class mission_ui_impl : public cataimgui::window
7782
void draw_selected_description( std::vector<mission *> missions, int &selected_mission );
7883
void draw_selected_description( std::vector<point_of_interest> points_of_interest,
7984
const int &selected_mission ) const;
85+
void draw_label_with_value( const std::string &label, const std::string &value ) const;
86+
void draw_location( const std::string &label, const tripoint_abs_omt &loc ) const;
8087

8188
mission_ui_tab_enum selected_tab = mission_ui_tab_enum::ACTIVE;
8289
mission_ui_tab_enum switch_tab = mission_ui_tab_enum::num_tabs;
@@ -352,6 +359,15 @@ void mission_ui_impl::draw_point_of_interest_names( std::vector<point_of_interes
352359
}
353360
}
354361

362+
void mission_ui_impl::draw_label_with_value( const std::string &label,
363+
const std::string &value ) const
364+
{
365+
ImGui::TextColored( c_white, "%s", label.c_str() );
366+
const float label_width = table_column_width * 0.3f;
367+
ImGui::SameLine( label_width );
368+
ImGui::TextColored( c_light_gray, "%s", value.c_str() );
369+
}
370+
355371
void mission_ui_impl::draw_selected_description( std::vector<mission *> missions,
356372
int &selected_mission )
357373
{
@@ -360,12 +376,12 @@ void mission_ui_impl::draw_selected_description( std::vector<mission *> missions
360376
if( miss->get_npc_id().is_valid() ) {
361377
npc *guy = g->find_npc( miss->get_npc_id() );
362378
if( guy ) {
363-
ImGui::TextWrapped( _( "Given by: %s" ), guy->disp_name().c_str() );
364-
if( guy->get_faction() ) {
365-
ImGui::TextWrapped( _( "Faction: %s" ), guy->get_faction()->name.c_str() );
379+
draw_label_with_value( _( "Given by:" ), guy->disp_name() );
380+
if( guy->get_faction() && guy->get_fac_id() != faction_no_faction ) {
381+
draw_label_with_value( _( "Faction:" ), guy->get_faction()->name );
366382
}
367383
const tripoint_abs_omt npc_location = guy->pos_abs_omt();
368-
ImGui::TextWrapped( _( "Map location: %s" ), npc_location.to_string().c_str() );
384+
draw_location( _( "Map location:" ), npc_location );
369385
}
370386
}
371387
ImGui::Separator();
@@ -423,20 +439,7 @@ void mission_ui_impl::draw_selected_description( std::vector<mission *> missions
423439
}
424440
if( miss->has_target() ) {
425441
// TODO: target does not contain a z-component, targets are assumed to be on z=0
426-
const tripoint_abs_omt pos = get_player_character().pos_abs_omt();
427-
cataimgui::draw_colored_text( string_format( _( "Target: %s" ), miss->get_target().to_string() ),
428-
c_white );
429-
// Below is done instead of a table for the benefit of right-to-left languages
430-
//~Extra padding spaces in the English text are so that the replaced string vertically aligns with the one above
431-
cataimgui::draw_colored_text( string_format( _( "You: %s" ), pos.to_string() ), c_white );
432-
int omt_distance = rl_dist( pos, miss->get_target() );
433-
if( omt_distance > 0 ) {
434-
// One OMT is 24 tiles across, at 1x1 meters each, so we can simply do number of OMTs * 24
435-
units::length actual_distance = omt_distance * 24_meter;
436-
//~Parenthesis is a real-world value for distance. Example string: "Distance: 223 tiles (5352 m)"
437-
cataimgui::draw_colored_text( string_format( _( "Distance: %1$s tiles (%2$s)" ),
438-
omt_distance, length_to_string_approx( actual_distance ) ), c_white );
439-
}
442+
draw_location( _( "Target:" ), miss->get_target() );
440443
}
441444
}
442445

@@ -451,20 +454,27 @@ void mission_ui_impl::draw_selected_description( std::vector<point_of_interest>
451454
// Avoid replacing expanded snippets with other valid snippet text on redraw
452455
cataimgui::draw_colored_text( parsed_description, c_unset, table_column_width * 1.15 );
453456
// TODO: target does not contain a z-component, targets are assumed to be on z=0
457+
draw_location( _( "Target:" ), selected_point_of_interest.pos );
458+
}
459+
460+
void mission_ui_impl::draw_location( const std::string &label,
461+
const tripoint_abs_omt &loc ) const
462+
{
454463
const tripoint_abs_omt pos = get_player_character().pos_abs_omt();
455-
cataimgui::draw_colored_text( string_format( _( "Target: %s" ),
456-
selected_point_of_interest.pos.to_string() ),
457-
c_white );
458-
// Below is done instead of a table for the benefit of right-to-left languages
459-
//~Extra padding spaces in the English text are so that the replaced string vertically aligns with the one above
460-
cataimgui::draw_colored_text( string_format( _( "You: %s" ), pos.to_string() ), c_white );
461-
int omt_distance = rl_dist( pos, selected_point_of_interest.pos );
464+
draw_label_with_value( label, display::overmap_position_text( loc ) );
465+
if( !you_know_where_you_are() ) {
466+
// Don't display "Distance:" or direction arrow if we don't know where we are
467+
return;
468+
}
469+
int omt_distance = rl_dist( pos, loc );
462470
if( omt_distance > 0 ) {
463471
// One OMT is 24 tiles across, at 1x1 meters each, so we can simply do number of OMTs * 24
464472
units::length actual_distance = omt_distance * 24_meter;
465-
//~Parenthesis is a real-world value for distance. Example string: "Distance: 223 tiles (5352 m)"
466-
cataimgui::draw_colored_text( string_format( _( "Distance: %1$s tiles (%2$s)" ),
467-
omt_distance, length_to_string_approx( actual_distance ) ), c_white );
473+
const std::string dir_arrow = direction_arrow( direction_from( pos.xy(), loc.xy() ) );
474+
//~Parenthesis is a real-world value for distance. Example string: "223 tiles (5.35km) ⇗"
475+
const std::string distance_str = string_format( _( "%1$s tiles (%2$s) %3$s" ),
476+
omt_distance, length_to_string_approx( actual_distance ), dir_arrow );
477+
draw_label_with_value( _( "Distance:" ), distance_str );
468478
}
469479
}
470480

src/timed_event.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,3 +485,8 @@ void timed_event_manager::set_all( const std::string &key, time_duration time_in
485485
}
486486
}
487487
}
488+
489+
bool you_know_where_you_are()
490+
{
491+
return !get_timed_events().get( timed_event_type::OVERRIDE_PLACE );
492+
}

src/timed_event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,6 @@ class timed_event_manager
118118
};
119119

120120
timed_event_manager &get_timed_events();
121+
bool you_know_where_you_are();
121122

122123
#endif // CATA_SRC_TIMED_EVENT_H

0 commit comments

Comments
 (0)