Skip to content

Commit 86cd2e7

Browse files
committed
Add batch multiplier to crafting UI
1 parent 2160e69 commit 86cd2e7

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

data/raw/keybindings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,13 @@
770770
"name": "Batch crafting",
771771
"bindings": [ { "input_method": "keyboard_any", "key": [ "b" ] } ]
772772
},
773+
{
774+
"type": "keybinding",
775+
"id": "TOGGLE_BATCH_MULTIPLIER",
776+
"category": "CRAFTING",
777+
"name": "Toggle size of batch selection steps between 1 and 10",
778+
"bindings": [ { "input_method": "keyboard_any", "key": [ "b" ] } ]
779+
},
773780
{
774781
"type": "keybinding",
775782
"id": "SCROLL_ITEM_INFO_UP",

src/crafting_gui.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ static input_context make_crafting_context( bool highlight_unread_recipes )
637637
ctxt.register_action( "HELP_RECIPE" );
638638
ctxt.register_action( "HELP_KEYBINDINGS" );
639639
ctxt.register_action( "CYCLE_BATCH" );
640+
ctxt.register_action( "TOGGLE_BATCH_MULTIPLIER" );
640641
ctxt.register_action( "CHOOSE_CRAFTER" );
641642
ctxt.register_action( "RELATED_RECIPES" );
642643
ctxt.register_action( "HIDE_SHOW_RECIPE" );
@@ -1304,6 +1305,7 @@ std::pair<Character *, const recipe *> select_crafter_and_crafting_recipe( int &
13041305
add_action_desc( "RELATED_RECIPES", pgettext( "crafting gui", "Related" ) );
13051306
add_action_desc( "TOGGLE_FAVORITE", pgettext( "crafting gui", "Favorite" ) );
13061307
add_action_desc( "CYCLE_BATCH", pgettext( "crafting gui", "Batch" ) );
1308+
add_action_desc( "TOGGLE_BATCH_MULTIPLIER", pgettext( "crafting gui", "Toggle Batch Multiplier" ) );
13071309
add_action_desc( "CHOOSE_CRAFTER", pgettext( "crafting gui", "Choose crafter" ) );
13081310
add_action_desc( "HELP_KEYBINDINGS", pgettext( "crafting gui", "Keybindings" ) );
13091311
keybinding_x = isWide ? 5 : 2;
@@ -1367,6 +1369,7 @@ std::pair<Character *, const recipe *> select_crafter_and_crafting_recipe( int &
13671369
bool keepline = false;
13681370
bool done = false;
13691371
bool batch = false;
1372+
int batch_multiplier = 1;
13701373
bool show_hidden = false;
13711374
size_t num_hidden = 0;
13721375
int num_recipe = 0;
@@ -1497,7 +1500,7 @@ std::pair<Character *, const recipe *> select_crafter_and_crafting_recipe( int &
14971500
std::string tmp_name = std::string( indent[i],
14981501
' ' ) + current[i]->result_name( /*decorated=*/true );
14991502
if( batch ) {
1500-
tmp_name = string_format( _( "%2dx %s" ), i + 1, tmp_name );
1503+
tmp_name = string_format( _( "%3dx %s" ), ( i + 1 ) * batch_multiplier, tmp_name );
15011504
}
15021505
const bool rcp_read = !highlight_unread_recipes ||
15031506
uistate.read_recipes.count( current[i]->ident() );
@@ -1518,7 +1521,7 @@ std::pair<Character *, const recipe *> select_crafter_and_crafting_recipe( int &
15181521
i - istart ) ) );
15191522
}
15201523

1521-
const int batch_size = batch ? line + 1 : 1;
1524+
const int batch_size = batch ? ( line + 1 ) * batch_multiplier : 1;
15221525
if( !current.empty() ) {
15231526
const recipe &recp = *current[line];
15241527

@@ -1616,7 +1619,7 @@ std::pair<Character *, const recipe *> select_crafter_and_crafting_recipe( int &
16161619
current.clear();
16171620
for( int i = 1; i <= 50; i++ ) {
16181621
current.push_back( chosen );
1619-
available.emplace_back( *crafter, chosen, i, camp_crafting, inventory_override );
1622+
available.emplace_back( *crafter, chosen, i * batch_multiplier, camp_crafting, inventory_override );
16201623
}
16211624
indent.assign( current.size(), 0 );
16221625
} else {
@@ -1888,13 +1891,14 @@ std::pair<Character *, const recipe *> select_crafter_and_crafting_recipe( int &
18881891
!available[line].crafter_has_primary_skill ) {
18891892
popup( _( "Crafter can't craft that!" ) );
18901893
} else if( available[line].inv_override == nullptr &&
1891-
!crafter->check_eligible_containers_for_crafting( *current[line], batch ? line + 1 : 1 ) ) {
1894+
!crafter->check_eligible_containers_for_crafting( *current[line],
1895+
batch ? ( line + 1 ) * batch_multiplier : 1 ) ) {
18921896
// popup is already inside check
18931897
} else if( crafter->lighting_craft_speed_multiplier( *current[line] ) <= 0.0f ) {
18941898
popup( _( "Crafter can't see!" ) );
18951899
} else {
18961900
chosen = current[line];
1897-
batch_size_out = batch ? line + 1 : 1;
1901+
batch_size_out = batch ? ( line + 1 ) * batch_multiplier : 1;
18981902
done = true;
18991903
uistate.read_recipes.insert( chosen->ident() );
19001904
}
@@ -1984,6 +1988,12 @@ std::pair<Character *, const recipe *> select_crafter_and_crafting_recipe( int &
19841988
keepline = true;
19851989
}
19861990
recalc = true;
1991+
} else if( action == "TOGGLE_BATCH_MULTIPLIER" ) {
1992+
if( batch_multiplier == 1 ) {
1993+
batch_multiplier = 10;
1994+
} else {
1995+
batch_multiplier = 1;
1996+
}
19871997
} else if( action == "CHOOSE_CRAFTER" ) {
19881998
// allow for switching crafter when no recipes are shown (e.g. filter)
19891999
bool rec_valid = !current.empty();

0 commit comments

Comments
 (0)