@@ -102,6 +102,10 @@ class path_manager_impl
102
102
* Start recording a new path.
103
103
*/
104
104
void start_recording ();
105
+ /* *
106
+ * Continue recording the first path the player is standing at start or end of.
107
+ */
108
+ void continue_recording ();
105
109
/* *
106
110
* Stop recording path.
107
111
*/
@@ -132,6 +136,8 @@ class path_manager_impl
132
136
void set_recording_path ( int p_index );
133
137
void swap_selected ( int index_a, int index_b );
134
138
int recording_path_index = -1 ;
139
+ // Used when continuing a recording from start
140
+ bool swap_after_recording = false ;
135
141
int selected_id = -1 ;
136
142
std::vector<path> paths;
137
143
};
@@ -274,16 +280,33 @@ void path_manager_impl::start_recording()
274
280
p.set_name_start ();
275
281
}
276
282
283
+ void path_manager_impl::continue_recording ()
284
+ {
285
+ int p_index = player_at_what_start_or_end ();
286
+ cata_assert ( p_index != -1 );
287
+ set_recording_path ( p_index );
288
+ swap_after_recording = paths[recording_path_index].player_at_start ();
289
+ if ( swap_after_recording ) {
290
+ paths[recording_path_index].swap_start_end ();
291
+ }
292
+ }
293
+
277
294
void path_manager_impl::stop_recording ()
278
295
{
279
296
path ¤t_path = paths[recording_path_index];
280
297
if ( current_path.recorded_path .size () <= 1 ) {
281
298
paths.erase ( paths.begin () + recording_path_index );
282
299
popup ( _ ( " Recorded path has no length. Path erased." ) );
300
+ set_recording_path ( -1 );
301
+ return ;
302
+ }
303
+ if ( swap_after_recording ) {
304
+ current_path.swap_start_end ();
305
+ current_path.set_name_start ();
283
306
} else {
284
307
current_path.set_name_end ();
285
- popup ( _ ( " Path saved." ) );
286
308
}
309
+ popup ( _ ( " Path saved." ) );
287
310
288
311
set_recording_path ( -1 );
289
312
// TODO error when starts or stops at the same tile as another path ??
@@ -352,6 +375,9 @@ void path_manager_impl::auto_route_from_path() const
352
375
void path_manager_impl::set_recording_path ( int p_index )
353
376
{
354
377
cata_assert ( -1 <= p_index && p_index < static_cast <int >( paths.size () ) );
378
+ if ( p_index == -1 ) {
379
+ swap_after_recording = false ;
380
+ }
355
381
recording_path_index = p_index;
356
382
}
357
383
@@ -377,6 +403,9 @@ void path_manager_ui::draw_controls()
377
403
ImGui::SameLine ();
378
404
enabled_active_button ( " START_RECORDING" , !pimpl->recording_path () );
379
405
ImGui::SameLine ();
406
+ enabled_active_button ( " CONTINUE_RECORDING" , !pimpl->recording_path ()
407
+ && pimpl->player_at_what_start_or_end () != -1 );
408
+ ImGui::SameLine ();
380
409
enabled_active_button ( " STOP_RECORDING" , pimpl->recording_path () );
381
410
382
411
// buttons related to selected path
@@ -459,6 +488,7 @@ void path_manager_ui::run()
459
488
ctxt.register_action ( " WALK_PATH" );
460
489
ctxt.register_action ( " START_RECORDING" );
461
490
ctxt.register_action ( " STOP_RECORDING" );
491
+ ctxt.register_action ( " CONTINUE_RECORDING" );
462
492
ctxt.register_action ( " DELETE_PATH" );
463
493
ctxt.register_action ( " MOVE_PATH_UP" );
464
494
ctxt.register_action ( " MOVE_PATH_DOWN" );
@@ -483,6 +513,9 @@ void path_manager_ui::run()
483
513
} else if ( action == " START_RECORDING" && !pimpl->recording_path () ) {
484
514
pimpl->start_recording ();
485
515
break ;
516
+ } else if ( action == " CONTINUE_RECORDING" && !pimpl->recording_path ()
517
+ && pimpl->player_at_what_start_or_end () != -1 ) {
518
+ pimpl->continue_recording ();
486
519
} else if ( action == " STOP_RECORDING" && pimpl->recording_path () ) {
487
520
pimpl->stop_recording ();
488
521
break ;
@@ -554,6 +587,7 @@ void path_manager::deserialize( const JsonValue &jsin )
554
587
{
555
588
JsonObject data = jsin.get_object ();
556
589
data.read ( " recording_path_index" , pimpl->recording_path_index );
590
+ data.read ( " swap_after_recording" , pimpl->swap_after_recording );
557
591
558
592
JsonArray data_paths = data.get_array ( " paths" );
559
593
for ( int i = 0 ; data_paths.has_object ( i ); ++i ) {
@@ -567,6 +601,7 @@ void path_manager::deserialize( const JsonValue &jsin )
567
601
void path_manager::serialize ( JsonOut &jsout )
568
602
{
569
603
jsout.member ( " recording_path_index" , pimpl->recording_path_index );
604
+ jsout.member ( " swap_after_recording" , pimpl->swap_after_recording );
570
605
jsout.member ( " paths" );
571
606
jsout.start_array ();
572
607
for ( path &p : pimpl->paths ) {
0 commit comments