@@ -70,9 +70,6 @@ int diary::set_opened_page( int pagenum )
70
70
opened_page = - 1 ;
71
71
} else if ( pagenum < 0 ) {
72
72
opened_page = pages.size () - 1 ;
73
- } else if ( pagenum == 0 && pagenum != opened_page ) {
74
- opened_page = 0 ;
75
- open_summary_page ();
76
73
} else {
77
74
opened_page = pagenum % pages.size ();
78
75
}
@@ -89,7 +86,7 @@ diary_page *diary::get_page_ptr( int offset, bool allow_summary )
89
86
{
90
87
const int page = offset + opened_page;
91
88
if ( !pages.empty () && page >= 0 && page < static_cast <int >( pages.size () ) ) {
92
- diary_page * const ptr = pages[page].get ();
89
+ diary_page *const ptr = pages[page].get ();
93
90
if ( allow_summary || !ptr->is_summary () ) {
94
91
return ptr;
95
92
}
@@ -110,7 +107,7 @@ size_t diary::add_to_change_list( const std::string &entry, const std::string &d
110
107
void diary::update_change_list ( const size_t index, const std::string &entry,
111
108
const std::string &desc )
112
109
{
113
- if ( index < 0 || index >= change_list.size () ) {
110
+ if ( index >= change_list.size () ) {
114
111
return ;
115
112
}
116
113
if ( desc.empty () ) {
@@ -141,6 +138,7 @@ void diary::open_summary_page()
141
138
142
139
template <typename Container, typename Fn>
143
140
void diary::changes ( Container diary_page::* member, Fn &&get_entry,
141
+ // NOLINTNEXTLINE(cata-use-string_view)
144
142
const std::string &heading_first, const std::string &headings_first,
145
143
const std::string &heading, const std::string &headings,
146
144
diary_page *const currpage, diary_page *const prevpage )
@@ -170,6 +168,7 @@ void diary::changes( Container diary_page::* member, Fn &&get_entry,
170
168
171
169
template <typename Container, typename Fn>
172
170
void diary::changes ( Container diary_page::* member, Fn &&get_entry,
171
+ // NOLINTNEXTLINE(cata-use-string_view)
173
172
const std::string &heading_first, const std::string &headings_first,
174
173
const std::string &heading, const std::string &headings )
175
174
{
@@ -179,6 +178,7 @@ void diary::changes( Container diary_page::* member, Fn &&get_entry,
179
178
180
179
template <typename Container, typename Fn>
181
180
void diary::changes ( Container diary_page::* member, Fn &&get_entry,
181
+ // NOLINTNEXTLINE(cata-use-string_view)
182
182
const std::string &heading_first, const std::string &headings_first )
183
183
{
184
184
changes ( member, get_entry, heading_first, headings_first, heading_first, headings_first );
@@ -232,12 +232,12 @@ void diary::mission_changes()
232
232
_ ( " Active mission: " ), _ ( " Active missions: " ),
233
233
_ ( " New mission: " ), _ ( " New missions: " )
234
234
);
235
- changes ( &diary_page::mission_active ,
235
+ changes ( &diary_page::mission_completed ,
236
236
mission_change,
237
237
_ ( " Completed mission: " ), _ ( " Completed missions: " ),
238
238
_ ( " New completed mission: " ), _ ( " New completed missions: " )
239
239
);
240
- changes ( &diary_page::mission_active ,
240
+ changes ( &diary_page::mission_failed ,
241
241
mission_change,
242
242
_ ( " Failed mission: " ), _ ( " Failed missions: " ),
243
243
_ ( " New failed mission: " ), _ ( " New failed missions: " )
@@ -304,12 +304,12 @@ void diary::npc_kill_changes()
304
304
changes ( &diary_page::npc_kills, npc_kill_change, _ ( " NPC killed: " ), _ ( " NPCs killed: " ) );
305
305
}
306
306
307
- static diary_entry_opt skill_change ( const std::pair<const string_id<Skill> , int > &elem,
307
+ static diary_entry_opt skill_change ( const std::pair<const skill_id , int > &elem,
308
308
diary_page *const prevpage )
309
309
{
310
310
const int prevlvl = prevpage ? prevpage->skillsL [ elem.first ] : 0 ;
311
311
if ( elem.second > prevlvl ) {
312
- Skill s = elem.first .obj ();
312
+ const Skill & s = elem.first .obj ();
313
313
return { {
314
314
prevpage ?
315
315
string_format ( _ ( " <color_light_blue>%s: %d -> %d</color>" ), s.name (),
@@ -350,12 +350,12 @@ void diary::trait_changes()
350
350
);
351
351
}
352
352
353
- static const std::array<std::tuple<const char *, const char * , int diary_page::*>, 4 > diary_stats
353
+ static const std::array<std::tuple<translation, translation , int diary_page::*>, 4 > diary_stats
354
354
= { {
355
- { _ ( " Strength: %d" ), _ ( " Strength: %d -> %d" ), &diary_page::strength },
356
- { _ ( " Dexterity: %d" ), _ ( " Dexterity: %d -> %d" ), &diary_page::dexterity },
357
- { _ ( " Intelligence: %d" ), _ ( " Intelligence: %d -> %d" ), &diary_page::intelligence },
358
- { _ ( " Perception: %d" ), _ ( " Perception: %d -> %d" ), &diary_page::perception }
355
+ { to_translation ( " Strength: %d" ), to_translation ( " Strength: %d -> %d" ), &diary_page::strength },
356
+ { to_translation ( " Dexterity: %d" ), to_translation ( " Dexterity: %d -> %d" ), &diary_page::dexterity },
357
+ { to_translation ( " Intelligence: %d" ), to_translation ( " Intelligence: %d -> %d" ), &diary_page::intelligence },
358
+ { to_translation ( " Perception: %d" ), to_translation ( " Perception: %d -> %d" ), &diary_page::perception }
359
359
}
360
360
};
361
361
@@ -408,10 +408,12 @@ void diary::prof_changes()
408
408
409
409
const std::vector<std::string> &diary::get_change_list ()
410
410
{
411
- if ( !change_list.empty () ) {
411
+ if ( !change_list.empty () || pages. empty () ) {
412
412
return change_list;
413
413
}
414
- if ( !pages.empty () ) {
414
+ if ( get_page_ptr ()->is_summary () ) {
415
+ open_summary_page ();
416
+ } else {
415
417
stat_changes ();
416
418
skill_changes ();
417
419
prof_changes ();
@@ -446,26 +448,40 @@ std::string diary::get_page_text()
446
448
return " " ;
447
449
}
448
450
449
- std::string diary::get_head_text ()
451
+ std::string diary::get_head_text ( bool is_summary )
450
452
{
451
453
452
454
if ( !pages.empty () ) {
453
455
const diary_page *prevpageptr = get_page_ptr ( -1 , false );
454
456
const diary_page *currpageptr = get_page_ptr ();
455
- const time_point prev_turn = ( prevpageptr != nullptr ) ? prevpageptr->turn : calendar::turn_zero;
457
+ const time_point prev_turn = ( prevpageptr != nullptr ) ? prevpageptr->turn :
458
+ calendar::start_of_game;
456
459
const time_duration turn_diff = currpageptr->turn - prev_turn;
457
460
std::string time_diff_text;
458
- if ( opened_page != 0 ) {
461
+ if ( prevpageptr ) {
459
462
time_diff_text = get_diary_time_since_str ( turn_diff, currpageptr->time_acc );
460
463
}
461
- // ~ Head text of a diary page
462
- // ~ %1$d is the current page number, %2$d is the number of pages in total
463
- // ~ %3$s is the time point when the current page was created
464
- // ~ %4$s is time relative to the previous page
465
- return string_format ( _ ( " Entry: %1$d/%2$d, %3$s, %4$s" ),
466
- opened_page + 1 , pages.size (),
467
- get_diary_time_str ( currpageptr->turn , currpageptr->time_acc ),
468
- time_diff_text );
464
+ if ( is_summary ) {
465
+ // ~ Head text of diary summary page
466
+ // ~ %1$d is the number of entries in total
467
+ return string_format ( _ ( " Summary: %1$d entries" ), pages.size () - 1 );
468
+ } else if ( time_diff_text.empty () ) {
469
+ // ~ Head text of first diary entry
470
+ // ~ %1$d is the current entry number, %2$d is the number of entries in total
471
+ // ~ %3$s is the time point when the current entry was created
472
+ return string_format ( _ ( " Entry: %1$d/%2$d, %3$s" ),
473
+ opened_page, pages.size () - 1 ,
474
+ get_diary_time_str ( currpageptr->turn , currpageptr->time_acc ) );
475
+ } else {
476
+ // ~ Head text of second and later diary entries
477
+ // ~ %1$d is the current entry number, %2$d is the number of entries in total
478
+ // ~ %3$s is the time point when the current entry was created
479
+ // ~ %4$s is time relative to the previous entry
480
+ return string_format ( _ ( " Entry: %1$d/%2$d, %3$s, %4$s" ),
481
+ opened_page, pages.size () - 1 ,
482
+ get_diary_time_str ( currpageptr->turn , currpageptr->time_acc ),
483
+ time_diff_text );
484
+ }
469
485
}
470
486
return " " ;
471
487
}
@@ -523,6 +539,7 @@ void diary::new_page()
523
539
page->intelligence = u->get_int_base ();
524
540
page->perception = u->get_per_base ();
525
541
page->traits = u->get_mutations_variants ( false );
542
+ std::sort ( page->traits .begin (), page->traits .end (), trait_var_display_sort );
526
543
const auto spells = u->magic ->get_spells ();
527
544
for ( const spell *spell : spells ) {
528
545
const spell_id &id = spell->id ();
@@ -531,12 +548,13 @@ void diary::new_page()
531
548
}
532
549
page-> bionics = u->get_bionics ();
533
550
for ( Skill &elem : Skill::skills ) {
534
-
535
551
int level = u->get_skill_level_object ( elem.ident () ).level ();
536
552
page->skillsL .insert ( { elem.ident (), level } );
537
553
}
538
554
page -> known_profs = u->_proficiencies ->known_profs ();
555
+ std::sort ( page->known_profs .begin (), page->known_profs .end () );
539
556
page -> learning_profs = u->_proficiencies ->learning_profs ();
557
+ std::sort ( page->learning_profs .begin (), page->learning_profs .end () );
540
558
page->max_power_level = u->get_max_power_level ();
541
559
diary::pages.push_back ( std::move ( page ) );
542
560
}
@@ -560,7 +578,7 @@ void diary::export_to_txt( bool lastexport )
560
578
for ( int i = 0 ; i < static_cast <int >( pages.size () ); i++ ) {
561
579
set_opened_page ( i );
562
580
const diary_page page = *get_page_ptr ();
563
- myfile << get_head_text () + " \n\n " ;
581
+ myfile << get_head_text ( page. is_summary () ) + " \n\n " ;
564
582
for ( const std::string &str : this ->get_change_list () ) {
565
583
myfile << remove_color_tags ( str ) + " \n " ;
566
584
}
0 commit comments