Skip to content

Commit

Permalink
Merge pull request #77573 from sparr/set_all_job_priorities
Browse files Browse the repository at this point in the history
Add interface to set all companion job priorities at once
  • Loading branch information
Maleclypse authored Nov 5, 2024
2 parents 6b98896 + 2ef326b commit c878dbb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2446,8 +2446,8 @@ void basecamp::job_assignment_ui()
smenu.text = _( "Assign job priority (0 to disable)" );
int count = 0;
std::vector<activity_id> job_vec = cur_npc->job.get_prioritised_vector();
smenu.addentry( count, true, 'C', _( "Clear all priorities" ) );
count++;
smenu.addentry( count++, true, 'C', _( "Clear all priorities" ) );
smenu.addentry( count++, true, 'S', _( "Set all priorities" ) );
for( const activity_id &elem : job_vec ) {
player_activity test_act = player_activity( elem );
const int priority = cur_npc->job.get_priority_of_job( elem );
Expand All @@ -2461,16 +2461,23 @@ void basecamp::job_assignment_ui()
}
if( smenu.ret == 0 ) {
cur_npc->job.clear_all_priorities();
} else if( smenu.ret > 0 && smenu.ret <= static_cast<int>( job_vec.size() ) ) {
activity_id sel_job = job_vec[size_t( smenu.ret - 1 )];
} else if( smenu.ret == 1 ) {
const int priority = string_input_popup()
.title( _( "Priority for all jobs " ) )
.width( 20 )
.only_digits( true )
.query_int();
cur_npc->job.set_all_priorities( priority );
} else if( smenu.ret > 1 && smenu.ret <= static_cast<int>( job_vec.size() ) + 1 ) {
activity_id sel_job = job_vec[size_t( smenu.ret - 2 )];
player_activity test_act = player_activity( sel_job );
const std::string formatted = string_format( _( "Priority for %s " ), test_act.get_verb() );
const int amount = string_input_popup()
.title( formatted )
.width( 20 )
.only_digits( true )
.query_int();
cur_npc->job.set_task_priority( sel_job, amount );
const int priority = string_input_popup()
.title( formatted )
.width( 20 )
.only_digits( true )
.query_int();
cur_npc->job.set_task_priority( sel_job, priority );
} else {
break;
}
Expand Down
6 changes: 6 additions & 0 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ bool job_data::set_task_priority( const activity_id &task, int new_priority )
}
return false;
}
void job_data::set_all_priorities( int new_priority )
{
for( auto &elem : task_priorities ) {
elem.second = new_priority;
}
}
void job_data::clear_all_priorities()
{
for( auto &elem : task_priorities ) {
Expand Down
1 change: 1 addition & 0 deletions src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class job_data
std::unordered_map<std::string, time_point> fetch_history;

bool set_task_priority( const activity_id &task, int new_priority );
void set_all_priorities( int new_priority );
void clear_all_priorities();
bool has_job() const;
int get_priority_of_job( const activity_id &req_job ) const;
Expand Down

0 comments on commit c878dbb

Please sign in to comment.