11
11
#include " color.h"
12
12
#include " dialogue.h"
13
13
#include " dialogue_helpers.h"
14
+ #include " display.h"
14
15
#include " game_constants.h"
15
16
#include " imgui/imgui.h"
16
17
#include " input_context.h"
18
+ #include " line.h"
17
19
#include " mission.h"
18
20
#include " npc.h"
19
21
#include " faction.h"
20
22
#include " output.h"
21
23
#include " point.h"
22
24
#include " string_formatter.h"
23
25
#include " talker.h"
26
+ #include " timed_event.h"
24
27
#include " translation.h"
25
28
#include " translations.h"
26
29
#include " ui_manager.h"
27
30
#include " units.h"
28
31
#include " units_utility.h"
29
32
33
+ static const faction_id faction_no_faction ( " no_faction" );
34
+
30
35
enum class mission_ui_tab_enum : int {
31
36
ACTIVE = 0 ,
32
37
COMPLETED,
@@ -77,6 +82,8 @@ class mission_ui_impl : public cataimgui::window
77
82
void draw_selected_description ( std::vector<mission *> missions, int &selected_mission );
78
83
void draw_selected_description ( std::vector<point_of_interest> points_of_interest,
79
84
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 ;
80
87
81
88
mission_ui_tab_enum selected_tab = mission_ui_tab_enum::ACTIVE;
82
89
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
352
359
}
353
360
}
354
361
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
+
355
371
void mission_ui_impl::draw_selected_description ( std::vector<mission *> missions,
356
372
int &selected_mission )
357
373
{
@@ -360,12 +376,12 @@ void mission_ui_impl::draw_selected_description( std::vector<mission *> missions
360
376
if ( miss->get_npc_id ().is_valid () ) {
361
377
npc *guy = g->find_npc ( miss->get_npc_id () );
362
378
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 );
366
382
}
367
383
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 );
369
385
}
370
386
}
371
387
ImGui::Separator ();
@@ -423,20 +439,7 @@ void mission_ui_impl::draw_selected_description( std::vector<mission *> missions
423
439
}
424
440
if ( miss->has_target () ) {
425
441
// 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 () );
440
443
}
441
444
}
442
445
@@ -451,20 +454,27 @@ void mission_ui_impl::draw_selected_description( std::vector<point_of_interest>
451
454
// Avoid replacing expanded snippets with other valid snippet text on redraw
452
455
cataimgui::draw_colored_text ( parsed_description, c_unset, table_column_width * 1.15 );
453
456
// 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
+ {
454
463
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 );
462
470
if ( omt_distance > 0 ) {
463
471
// One OMT is 24 tiles across, at 1x1 meters each, so we can simply do number of OMTs * 24
464
472
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 );
468
478
}
469
479
}
470
480
0 commit comments