@@ -83,6 +83,18 @@ class path_manager_impl
83
83
* Stop recording path.
84
84
*/
85
85
void stop_recording ();
86
+ /* *
87
+ * Delete path selected by `select_id`.
88
+ */
89
+ void delete_selected ();
90
+ /* *
91
+ * Move path selected by `select_id` up.
92
+ */
93
+ void move_selected_up ();
94
+ /* *
95
+ * Move path selected by `select_id` down.
96
+ */
97
+ void move_selected_down ();
86
98
private:
87
99
bool recording_path ();
88
100
// todo int or size_t?
@@ -91,6 +103,7 @@ class path_manager_impl
91
103
* -1 means not recording.
92
104
*/
93
105
void set_recording_path ( int p_index );
106
+ void swap_selected ( int index_a, int index_b );
94
107
int recording_path_index = -1 ;
95
108
int selected_id = -1 ;
96
109
std::vector<path> paths;
@@ -102,6 +115,8 @@ class path_manager_ui : public cataimgui::window
102
115
explicit path_manager_ui ( path_manager_impl *pimpl_in );
103
116
void run ();
104
117
118
+ input_context ctxt = input_context( " PATH_MANAGER" );
119
+ void enabled_active_button ( const std::string action, bool enabled );
105
120
protected:
106
121
void draw_controls () override ;
107
122
cataimgui::bounds get_bounds () override ;
@@ -160,10 +175,10 @@ void path_manager_impl::stop_recording()
160
175
const path ¤t_path = paths[recording_path_index];
161
176
const std::vector<tripoint_abs_ms> &curr_path = current_path.recorded_path ;
162
177
if ( curr_path.size () <= 1 ) {
163
- add_msg ( m_info, _ ( " Auto path: Recorded path has no lenght. Path erased." ) );
164
178
paths.erase ( paths.begin () + recording_path_index );
179
+ popup ( _ ( " Recorded path has no lenght. Path erased." ) );
165
180
} else {
166
- add_msg ( m_info, _ ( " Auto path: Path saved." ) );
181
+ popup ( _ ( " Path saved." ) );
167
182
}
168
183
169
184
set_recording_path ( -1 );
@@ -172,6 +187,42 @@ void path_manager_impl::stop_recording()
172
187
// more flexibility, but it needs to be documented
173
188
}
174
189
190
+ void path_manager_impl::delete_selected ()
191
+ {
192
+ cata_assert ( 0 <= selected_id && selected_id < static_cast <int >( paths.size () ) );
193
+ if ( selected_id == recording_path_index ) {
194
+ set_recording_path ( -1 );
195
+ } else if ( selected_id < recording_path_index ) {
196
+ set_recording_path ( recording_path_index - 1 );
197
+ }
198
+ paths.erase ( paths.begin () + selected_id );
199
+ selected_id = std::min ( selected_id, static_cast <int >( paths.size () ) - 1 );
200
+ }
201
+
202
+ void path_manager_impl::swap_selected ( int index_a, int index_b )
203
+ {
204
+ cata_assert ( 0 <= index_a && index_a < static_cast <int >( paths.size () ) );
205
+ cata_assert ( 0 <= index_b && index_b < static_cast <int >( paths.size () ) );
206
+ if ( index_a == recording_path_index ) {
207
+ set_recording_path ( index_b );
208
+ } else if ( index_b == recording_path_index ) {
209
+ set_recording_path ( index_a );
210
+ }
211
+ std::swap ( paths[index_a], paths[index_b] );
212
+ }
213
+
214
+ void path_manager_impl::move_selected_up ()
215
+ {
216
+ swap_selected ( selected_id, selected_id - 1 );
217
+ --selected_id;
218
+ }
219
+
220
+ void path_manager_impl::move_selected_down ()
221
+ {
222
+ swap_selected ( selected_id, selected_id + 1 );
223
+ ++selected_id;
224
+ }
225
+
175
226
bool path_manager_impl::recording_path ()
176
227
{
177
228
return recording_path_index != -1 ;
@@ -189,9 +240,7 @@ void path_manager_impl::auto_route_from_path()
189
240
return ;
190
241
}
191
242
}
192
- add_msg ( m_info,
193
- _ ( " Auto path: Player doesn't stand at start or end of existing path. Recording new path." ) );
194
- start_recording ();
243
+ popup ( _ ( " Player doesn't stand at start or end of existing path." ) );
195
244
}
196
245
197
246
void path_manager_impl::set_recording_path ( int p_index )
@@ -208,9 +257,34 @@ cataimgui::bounds path_manager_ui::get_bounds()
208
257
return { -1 .f , -1 .f , float ( str_width_to_pixels ( TERMX ) ), float ( str_height_to_pixels ( TERMY ) ) };
209
258
}
210
259
260
+ void path_manager_ui::enabled_active_button ( const std::string action, bool enabled )
261
+ {
262
+ ImGui::BeginDisabled ( !enabled );
263
+ action_button ( action, ctxt.get_button_text ( action ) );
264
+ ImGui::EndDisabled ();
265
+ }
266
+
211
267
void path_manager_ui::draw_controls ()
212
268
{
213
- if ( ! ImGui::BeginTable ( " PATH_MANAGER" , 5 , ImGuiTableFlags_Resizable )) {
269
+ // general buttons
270
+ enabled_active_button ( " WALK_PATH" , true );
271
+ ImGui::SameLine ();
272
+ enabled_active_button ( " START_RECORDING" , !pimpl->recording_path () );
273
+ ImGui::SameLine ();
274
+ enabled_active_button ( " STOP_RECORDING" , pimpl->recording_path () );
275
+
276
+ // buttons related to selected path
277
+ draw_colored_text ( _ ( " Selected path:" ), c_white );
278
+ ImGui::SameLine ();
279
+ enabled_active_button ( " DELETE_PATH" , pimpl->selected_id != -1 );
280
+ ImGui::SameLine ();
281
+ enabled_active_button ( " MOVE_PATH_UP" , pimpl->selected_id > 0 );
282
+ ImGui::SameLine ();
283
+ enabled_active_button ( " MOVE_PATH_DOWN" , pimpl->selected_id != -1 &&
284
+ pimpl->selected_id + 1 < static_cast <int >( pimpl->paths .size () ) );
285
+
286
+ ImGui::BeginChild ( " table" );
287
+ if ( ! ImGui::BeginTable ( " PATH_MANAGER" , 5 , ImGuiTableFlags_Resizable ) ) {
214
288
return ;
215
289
}
216
290
// TODO invlet
@@ -253,24 +327,53 @@ void path_manager_ui::draw_controls()
253
327
}
254
328
}
255
329
ImGui::EndTable ();
330
+ ImGui::EndChild ();
256
331
}
257
332
258
333
void path_manager_ui::run ()
259
334
{
260
- input_context ctxt ( " HELP_KEYBINDINGS" );
261
335
ctxt.register_action ( " QUIT" );
262
336
ctxt.register_action ( " SELECT" );
263
337
ctxt.register_action ( " MOUSE_MOVE" );
264
338
ctxt.register_action ( " ANY_INPUT" );
265
339
ctxt.register_action ( " HELP_KEYBINDINGS" );
340
+
341
+ ctxt.register_action ( " WALK_PATH" );
342
+ ctxt.register_action ( " START_RECORDING" );
343
+ ctxt.register_action ( " STOP_RECORDING" );
344
+ ctxt.register_action ( " DELETE_PATH" );
345
+ ctxt.register_action ( " MOVE_PATH_UP" );
346
+ ctxt.register_action ( " MOVE_PATH_DOWN" );
266
347
std::string action;
267
348
268
349
ui_manager::redraw ();
269
350
270
351
while ( is_open ) {
271
352
ui_manager::redraw ();
272
- action = ctxt.handle_input ( 17 );
273
- if ( action == " QUIT" ) {
353
+ if ( has_button_action () ) {
354
+ action = get_button_action ();
355
+ } else {
356
+ action = ctxt.handle_input ( 17 );
357
+ }
358
+
359
+ if ( action == " WALK_PATH" ) {
360
+ pimpl->auto_route_from_path ();
361
+ break ;
362
+ } else if ( action == " START_RECORDING" && !pimpl->recording_path () ) {
363
+ pimpl->start_recording ();
364
+ break ;
365
+ } else if ( action == " STOP_RECORDING" && pimpl->recording_path () ) {
366
+ pimpl->stop_recording ();
367
+ break ;
368
+ } else if ( action == " DELETE_PATH" && pimpl->selected_id != -1 ) {
369
+ pimpl->delete_selected ();
370
+ } else if ( action == " MOVE_PATH_UP" && pimpl->selected_id > 0 ) {
371
+ pimpl->move_selected_up ();
372
+ } else if ( action == " MOVE_PATH_DOWN" && pimpl->selected_id != -1 &&
373
+ pimpl->selected_id + 1 < static_cast <int >( pimpl->paths .size () )
374
+ ) {
375
+ pimpl->move_selected_down ();
376
+ } else if ( action == " QUIT" ) {
274
377
break ;
275
378
}
276
379
}
@@ -349,14 +452,6 @@ void path_manager::serialize( JsonOut &jsout )
349
452
void path_manager::show ()
350
453
{
351
454
path_manager_ui ( pimpl.get () ).run ();
352
- // todo move to GUI
353
- if ( pimpl->recording_path () ) {
354
- pimpl->stop_recording ();
355
- return ;
356
- }
357
-
358
- pimpl->auto_route_from_path ();
359
-
360
455
// todo activity title and progress
361
456
// player_character.assign_activity( workout_activity_actor( player_character.pos() ) );
362
457
}
0 commit comments