@@ -2633,10 +2633,13 @@ void inventory_selector::highlight()
2633
2633
2634
2634
inventory_multiselector::inventory_multiselector ( Character &p,
2635
2635
const inventory_selector_preset &preset,
2636
- const std::string &selection_column_title, const bool allow_select_contained ) :
2636
+ const std::string &selection_column_title,
2637
+ const GetStats &get_stats,
2638
+ const bool allow_select_contained ) :
2637
2639
inventory_selector( p, preset ),
2638
2640
allow_select_contained( allow_select_contained ),
2639
- selection_col( new selection_column( " SELECTION_COLUMN" , selection_column_title ) )
2641
+ selection_col( new selection_column( " SELECTION_COLUMN" , selection_column_title ) ),
2642
+ get_stats( get_stats )
2640
2643
{
2641
2644
ctxt.register_action ( " TOGGLE_ENTRY" , to_translation ( " Mark/unmark selected item" ) );
2642
2645
ctxt.register_action ( " MARK_WITH_COUNT" ,
@@ -2787,6 +2790,38 @@ void inventory_multiselector::toggle_entries( int &count, const toggle_mode mode
2787
2790
on_toggle ();
2788
2791
}
2789
2792
2793
+ drop_locations inventory_multiselector::execute ()
2794
+ {
2795
+ shared_ptr_fast<ui_adaptor> ui = create_or_get_ui_adaptor ();
2796
+
2797
+ while ( true ) {
2798
+ ui_manager::redraw ();
2799
+
2800
+ const inventory_input input = get_input ();
2801
+
2802
+ if ( input.action == " CONFIRM" ) {
2803
+ if ( to_use.empty () ) {
2804
+ popup_getkey ( _ ( " No items were selected. Use %s to select them." ),
2805
+ ctxt.get_desc ( " TOGGLE_ENTRY" ) );
2806
+ continue ;
2807
+ }
2808
+ break ;
2809
+ }
2810
+
2811
+ if ( input.action == " QUIT" ) {
2812
+ return drop_locations ();
2813
+ }
2814
+
2815
+ on_input ( input );
2816
+ }
2817
+ drop_locations dropped_pos_and_qty;
2818
+ for ( const std::pair<item_location, int > &drop_pair : to_use ) {
2819
+ dropped_pos_and_qty.push_back ( drop_pair );
2820
+ }
2821
+
2822
+ return dropped_pos_and_qty;
2823
+ }
2824
+
2790
2825
inventory_compare_selector::inventory_compare_selector ( Character &p ) :
2791
2826
inventory_multiselector( p, default_preset, _( " ITEMS TO COMPARE" ) ) {}
2792
2827
@@ -2824,7 +2859,7 @@ std::pair<const item *, const item *> inventory_compare_selector::execute()
2824
2859
} else if ( input.action == " TOGGLE_FAVORITE" ) {
2825
2860
// TODO: implement favoriting in multi selection menus while maintaining selection
2826
2861
} else {
2827
- on_input ( input );
2862
+ inventory_selector:: on_input ( input );
2828
2863
}
2829
2864
2830
2865
if ( compared.size () == 2 ) {
@@ -2855,79 +2890,7 @@ void inventory_compare_selector::toggle_entry( inventory_entry *entry )
2855
2890
on_change ( *entry );
2856
2891
}
2857
2892
2858
- inventory_iuse_selector::inventory_iuse_selector (
2859
- Character &p,
2860
- const std::string &selector_title,
2861
- const inventory_selector_preset &preset,
2862
- const GetStats &get_st
2863
- ) :
2864
- inventory_multiselector( p, preset, selector_title, /* allow_select_contained=*/ true ),
2865
- get_stats( get_st )
2866
- {}
2867
-
2868
- drop_locations inventory_iuse_selector::execute ()
2869
- {
2870
- shared_ptr_fast<ui_adaptor> ui = create_or_get_ui_adaptor ();
2871
-
2872
- auto is_entry = []( const inventory_entry & elem ) {
2873
- return elem.is_selectable ();
2874
- };
2875
- for ( inventory_column *col : get_all_columns () ) {
2876
- if ( col->allows_selecting () ) {
2877
- for ( inventory_entry *ie : col->get_entries ( is_entry ) ) {
2878
- for ( item_location const &x : ie->locations ) {
2879
- usable_locs.push_back ( x );
2880
- }
2881
- }
2882
- }
2883
- }
2884
- int count = 0 ;
2885
- while ( true ) {
2886
- ui_manager::redraw ();
2887
-
2888
- const bool noMarkCountBound = ctxt.keys_bound_to ( " MARK_WITH_COUNT" ).empty ();
2889
- const inventory_input input = get_input ();
2890
-
2891
- if ( input.entry != nullptr ) { // Single Item from mouse
2892
- highlight ( input.entry ->any_item () );
2893
- toggle_entries ( count );
2894
- } else if ( input.action == " TOGGLE_NON_FAVORITE" ) {
2895
- toggle_entries ( count, toggle_mode::NON_FAVORITE_NON_WORN );
2896
- } else if ( input.action == " MARK_WITH_COUNT" ) { // Set count and mark selected with specific key
2897
- int query_result = query_count ();
2898
- if ( query_result < 0 ) {
2899
- continue ; // Skip selecting any if invalid result or user canceled prompt
2900
- }
2901
- toggle_entries ( query_result, toggle_mode::SELECTED );
2902
- } else if ( noMarkCountBound && input.ch >= ' 0' && input.ch <= ' 9' ) {
2903
- count = std::min ( count, INT_MAX / 10 - 10 );
2904
- count *= 10 ;
2905
- count += input.ch - ' 0' ;
2906
- } else if ( input.action == " TOGGLE_ENTRY" ) { // Mark selected
2907
- toggle_entries ( count, toggle_mode::SELECTED );
2908
- } else if ( input.action == " CONFIRM" ) {
2909
- if ( to_use.empty () ) {
2910
- popup_getkey ( _ ( " No items were selected. Use %s to select them." ),
2911
- ctxt.get_desc ( " TOGGLE_ENTRY" ) );
2912
- continue ;
2913
- }
2914
- break ;
2915
- } else if ( input.action == " QUIT" ) {
2916
- return drop_locations ();
2917
- } else {
2918
- on_input ( input );
2919
- }
2920
- }
2921
- drop_locations dropped_pos_and_qty;
2922
-
2923
- for ( const std::pair<const item_location, int > use_pair : to_use ) {
2924
- dropped_pos_and_qty.push_back ( use_pair );
2925
- }
2926
-
2927
- return dropped_pos_and_qty;
2928
- }
2929
-
2930
- inventory_selector::stats inventory_iuse_selector::get_raw_stats () const
2893
+ inventory_selector::stats inventory_multiselector::get_raw_stats () const
2931
2894
{
2932
2895
if ( get_stats ) {
2933
2896
return get_stats ( to_use );
@@ -2985,7 +2948,7 @@ void inventory_multiselector::deselect_contained_items()
2985
2948
}
2986
2949
}
2987
2950
2988
- void inventory_drop_selector ::on_input ( const inventory_input &input )
2951
+ void inventory_multiselector ::on_input ( const inventory_input &input )
2989
2952
{
2990
2953
bool const noMarkCountBound = ctxt.keys_bound_to ( " MARK_WITH_COUNT" ).empty ();
2991
2954
@@ -3007,7 +2970,7 @@ void inventory_drop_selector::on_input( const inventory_input &input )
3007
2970
} else if ( input.action == " TOGGLE_ENTRY" ) { // Mark selected
3008
2971
toggle_entries ( count, toggle_mode::SELECTED );
3009
2972
} else {
3010
- inventory_multiselector ::on_input ( input );
2973
+ inventory_selector ::on_input ( input );
3011
2974
}
3012
2975
}
3013
2976
@@ -3104,31 +3067,12 @@ drop_locations pickup_selector::execute()
3104
3067
{
3105
3068
shared_ptr_fast<ui_adaptor> ui = create_or_get_ui_adaptor ();
3106
3069
3107
- int count = 0 ;
3108
3070
while ( true ) {
3109
3071
ui_manager::redraw ();
3110
3072
3111
- const bool noMarkCountBound = ctxt.keys_bound_to ( " MARK_WITH_COUNT" ).empty ();
3112
3073
const inventory_input input = get_input ();
3113
3074
3114
- if ( input.entry != nullptr ) { // Single Item from mouse
3115
- highlight ( input.entry ->any_item () );
3116
- toggle_entries ( count );
3117
- } else if ( input.action == " TOGGLE_NON_FAVORITE" ) {
3118
- toggle_entries ( count, toggle_mode::NON_FAVORITE_NON_WORN );
3119
- } else if ( input.action == " MARK_WITH_COUNT" ) { // Set count and mark selected with specific key
3120
- int query_result = query_count ();
3121
- if ( query_result < 0 ) {
3122
- continue ; // Skip selecting any if invalid result or user canceled prompt
3123
- }
3124
- toggle_entries ( query_result );
3125
- } else if ( noMarkCountBound && input.ch >= ' 0' && input.ch <= ' 9' ) {
3126
- count = std::min ( count, INT_MAX / 10 - 10 );
3127
- count *= 10 ;
3128
- count += input.ch - ' 0' ;
3129
- } else if ( input.action == " TOGGLE_ENTRY" ) { // Mark selected
3130
- toggle_entries ( count );
3131
- } else if ( input.action == " CONFIRM" ) {
3075
+ if ( input.action == " CONFIRM" ) {
3132
3076
if ( to_use.empty () ) {
3133
3077
popup_getkey ( _ ( " No items were selected. Use %s to select them." ),
3134
3078
ctxt.get_desc ( " TOGGLE_ENTRY" ) );
@@ -3145,10 +3089,6 @@ drop_locations pickup_selector::execute()
3145
3089
}
3146
3090
} else if ( input.action == " QUIT" ) {
3147
3091
return drop_locations ();
3148
- } else if ( input.action == " INVENTORY_FILTER" ) {
3149
- query_set_filter ();
3150
- } else if ( input.action == " TOGGLE_FAVORITE" ) {
3151
- // TODO: implement favoriting in multi selection menus while maintaining selection
3152
3092
} else {
3153
3093
on_input ( input );
3154
3094
}
0 commit comments