From e5c7ad434966f357bd116c81e5618de5d411365a Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 1 Nov 2019 11:56:30 -0400 Subject: [PATCH 01/10] move save/load pane settings into pane --- src/advanced_inv.cpp | 25 ++----------------------- src/advanced_inv_pane.cpp | 32 ++++++++++++++++++++++++++++++++ src/advanced_inv_pane.h | 5 ++--- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index 5d2e37eb302c1..d4d181b86979a 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -137,10 +137,7 @@ void advanced_inventory::save_settings( bool only_panes ) uistate.adv_inv_dest = dest; } for( int i = 0; i < NUM_PANES; ++i ) { - uistate.adv_inv_in_vehicle[i] = panes[i].in_vehicle(); - uistate.adv_inv_area[i] = panes[i].get_area(); - uistate.adv_inv_index[i] = panes[i].index; - uistate.adv_inv_filter[i] = panes[i].filter; + panes[i].save_settings(i); } } @@ -148,25 +145,7 @@ void advanced_inventory::load_settings() { aim_exit aim_code = static_cast( uistate.adv_inv_exit_code ); for( int i = 0; i < NUM_PANES; ++i ) { - aim_location location; - if( get_option( "OPEN_DEFAULT_ADV_INV" ) ) { - location = static_cast( uistate.adv_inv_default_areas[i] ); - } else { - location = static_cast( uistate.adv_inv_area[i] ); - } - auto square = squares[location]; - // determine the square's vehicle/map item presence - bool has_veh_items = square.can_store_in_vehicle() ? - !square.veh->get_items( square.vstor ).empty() : false; - bool has_map_items = !g->m.i_at( square.pos ).empty(); - // determine based on map items and settings to show cargo - bool show_vehicle = aim_code == exit_re_entry ? - uistate.adv_inv_in_vehicle[i] : has_veh_items ? true : - has_map_items ? false : square.can_store_in_vehicle(); - panes[i].set_area( square, show_vehicle ); - panes[i].sortby = static_cast( uistate.adv_inv_sort[i] ); - panes[i].index = uistate.adv_inv_index[i]; - panes[i].filter = uistate.adv_inv_filter[i]; + panes[i].load_settings(i, squares, aim_code == exit_re_entry); } uistate.adv_inv_exit_code = exit_none; } diff --git a/src/advanced_inv_pane.cpp b/src/advanced_inv_pane.cpp index d16c5a8ed2405..acd04b0adde0e 100644 --- a/src/advanced_inv_pane.cpp +++ b/src/advanced_inv_pane.cpp @@ -27,6 +27,7 @@ #include "advanced_inv_pane.h" #include "vehicle.h" #include "map.h" +#include "options.h" #include #include @@ -40,6 +41,37 @@ #if defined(__ANDROID__) # include #endif +void advanced_inventory_pane::save_settings(int side) +{ + uistate.adv_inv_in_vehicle[side] = in_vehicle(); + uistate.adv_inv_area[side] = get_area(); + uistate.adv_inv_index[side] = index; + uistate.adv_inv_filter[side] = filter; +} + +void advanced_inventory_pane::load_settings(int side, const std::array& squares, bool is_re_enter) +{ + aim_location location; + if (get_option("OPEN_DEFAULT_ADV_INV")) { + location = static_cast(uistate.adv_inv_default_areas[side]); + } + else { + location = static_cast(uistate.adv_inv_area[side]); + } + auto square = squares[location]; + // determine the square's vehicle/map item presence + bool has_veh_items = square.can_store_in_vehicle() ? + !square.veh->get_items(square.vstor).empty() : false; + bool has_map_items = !g->m.i_at(square.pos).empty(); + // determine based on map items and settings to show cargo + bool show_vehicle = is_re_enter ? + uistate.adv_inv_in_vehicle[side] : has_veh_items ? true : + has_map_items ? false : square.can_store_in_vehicle(); + set_area(square, show_vehicle); + sortby = static_cast(uistate.adv_inv_sort[side]); + index = uistate.adv_inv_index[side]; + filter = uistate.adv_inv_filter[side]; +} bool advanced_inventory_pane::is_filtered( const advanced_inv_listitem &it ) const { diff --git a/src/advanced_inv_pane.h b/src/advanced_inv_pane.h index 2105432f6e180..f963091f589ea 100644 --- a/src/advanced_inv_pane.h +++ b/src/advanced_inv_pane.h @@ -59,9 +59,8 @@ class advanced_inventory_pane bool in_vehicle() const { return viewing_cargo; } - bool on_ground() const { - return area > AIM_INVENTORY && area < AIM_DRAGGED; - } + void save_settings(int side); + void load_settings(int side, const std::array& squares, bool is_re_enter); /** * Index of the selected item (index of @ref items), */ From 0855b05cd9ef3402536dc16c26c02cf8ce88cf8d Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 1 Nov 2019 12:01:03 -0400 Subject: [PATCH 02/10] remove unnecessary window fields --- src/advanced_inv.cpp | 11 ++++------- src/advanced_inv.h | 2 -- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index d4d181b86979a..e186898d62c93 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -122,8 +122,8 @@ advanced_inventory::~advanced_inventory() werase( head ); werase( minimap ); werase( mm_border ); - werase( left_window ); - werase( right_window ); + werase(panes[left].window); + werase(panes[right].window); g->refresh_all(); g->u.check_item_encumbrance_flag(); } @@ -223,15 +223,12 @@ void advanced_inventory::init() point( colstart + ( w_width - ( minimap_width + 2 ) ), headstart ) ); minimap = catacurses::newwin( minimap_height, minimap_width, point( colstart + ( w_width - ( minimap_width + 1 ) ), headstart + 1 ) ); - left_window = catacurses::newwin( w_height, w_width / 2, point( colstart, + panes[left].window = catacurses::newwin( w_height, w_width / 2, point( colstart, headstart + head_height ) ); - right_window = catacurses::newwin( w_height, w_width / 2, point( colstart + w_width / 2, + panes[right].window = catacurses::newwin( w_height, w_width / 2, point( colstart + w_width / 2, headstart + head_height ) ); itemsPerPage = w_height - 2 - 5; // 2 for the borders, 5 for the header stuff - - panes[left].window = left_window; - panes[right].window = right_window; } void advanced_inventory::print_items( advanced_inventory_pane &pane, bool active ) diff --git a/src/advanced_inv.h b/src/advanced_inv.h index 2bfc0058ef528..ce7e012f7f0e8 100644 --- a/src/advanced_inv.h +++ b/src/advanced_inv.h @@ -113,8 +113,6 @@ class advanced_inventory std::array squares; catacurses::window head; - catacurses::window left_window; - catacurses::window right_window; bool exit; From 3bf1ef3e6ba22a66e543bb5f8778a3dabed00783 Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 1 Nov 2019 15:42:04 -0400 Subject: [PATCH 03/10] add individual save state object for each pane --- src/advanced_inv.cpp | 23 ++++--- src/advanced_inv.h | 3 +- src/advanced_inv_pane.cpp | 30 ++++----- src/advanced_inv_pane.h | 5 +- src/uistate.h | 125 ++++++++++++++++++++------------------ 5 files changed, 95 insertions(+), 91 deletions(-) diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index e186898d62c93..480c0cb9b7946 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -107,6 +107,7 @@ advanced_inventory::advanced_inventory() } } ) { + save_state = &uistate.transfer_save; } // *INDENT-ON* @@ -137,16 +138,15 @@ void advanced_inventory::save_settings( bool only_panes ) uistate.adv_inv_dest = dest; } for( int i = 0; i < NUM_PANES; ++i ) { - panes[i].save_settings(i); + panes[i].save_settings(); } } void advanced_inventory::load_settings() { aim_exit aim_code = static_cast( uistate.adv_inv_exit_code ); - for( int i = 0; i < NUM_PANES; ++i ) { - panes[i].load_settings(i, squares, aim_code == exit_re_entry); - } + panes[left].load_settings(save_state->saved_area, squares, aim_code == exit_re_entry); + panes[right].load_settings(save_state->saved_area_right, squares, aim_code == exit_re_entry); uistate.adv_inv_exit_code = exit_none; } @@ -206,10 +206,13 @@ void advanced_inventory::init() square.init(); } + panes[left].save_state = &save_state->pane; + panes[right].save_state = &save_state->pane_right; + load_settings(); - src = static_cast( uistate.adv_inv_src ); - dest = static_cast( uistate.adv_inv_dest ); + src = static_cast(uistate.adv_inv_src); + dest = static_cast(uistate.adv_inv_dest); w_height = TERMY < min_w_height + head_height ? min_w_height : TERMY - head_height; w_width = TERMX < min_w_width ? min_w_width : TERMX > max_w_width ? max_w_width : @@ -1065,7 +1068,8 @@ void advanced_inventory::display() left, right } ) { auto &pane = panes[cside]; - aim_location location = static_cast( uistate.adv_inv_default_areas[cside] ); + int i_location = cside == left ? save_state->saved_area : save_state->saved_area_right; + aim_location location = static_cast(i_location); if( pane.get_area() != location || location == AIM_ALL ) { pane.recalc = true; } @@ -1073,8 +1077,8 @@ void advanced_inventory::display() } redraw = true; } else if( action == "SAVE_DEFAULT" ) { - uistate.adv_inv_default_areas[left] = panes[left].get_area(); - uistate.adv_inv_default_areas[right] = panes[right].get_area(); + save_state->saved_area = panes[left].get_area(); + save_state->saved_area_right = panes[right].get_area(); popup( _( "Default layout was saved." ) ); redraw = true; } else if( get_square( action, changeSquare ) ) { @@ -1280,7 +1284,6 @@ void advanced_inventory::display() } else if( action == "SORT" ) { if( show_sort_menu( spane ) ) { recalc = true; - uistate.adv_inv_sort[src] = spane.sortby; } redraw = true; } else if( action == "FILTER" ) { diff --git a/src/advanced_inv.h b/src/advanced_inv.h index ce7e012f7f0e8..d1adb85648c31 100644 --- a/src/advanced_inv.h +++ b/src/advanced_inv.h @@ -116,6 +116,7 @@ class advanced_inventory bool exit; + advanced_inv_save_state* save_state; // store/load settings (such as index, filter, etc) void save_settings( bool only_panes ); void load_settings(); @@ -176,8 +177,6 @@ class advanced_inventory */ bool query_charges( aim_location destarea, const advanced_inv_listitem &sitem, const std::string &action, int &amount ); - - static char get_direction_key( aim_location area ); }; #endif diff --git a/src/advanced_inv_pane.cpp b/src/advanced_inv_pane.cpp index acd04b0adde0e..ecaf20511e9c9 100644 --- a/src/advanced_inv_pane.cpp +++ b/src/advanced_inv_pane.cpp @@ -41,23 +41,19 @@ #if defined(__ANDROID__) # include #endif -void advanced_inventory_pane::save_settings(int side) +void advanced_inventory_pane::save_settings() { - uistate.adv_inv_in_vehicle[side] = in_vehicle(); - uistate.adv_inv_area[side] = get_area(); - uistate.adv_inv_index[side] = index; - uistate.adv_inv_filter[side] = filter; + save_state->in_vehicle = in_vehicle(); + save_state->area_idx = get_area(); + save_state->selected_idx = index; + save_state->filter = filter; + save_state->sort_idx = sortby; } -void advanced_inventory_pane::load_settings(int side, const std::array& squares, bool is_re_enter) +void advanced_inventory_pane::load_settings(int saved_area_idx, const std::array& squares, bool is_re_enter) { - aim_location location; - if (get_option("OPEN_DEFAULT_ADV_INV")) { - location = static_cast(uistate.adv_inv_default_areas[side]); - } - else { - location = static_cast(uistate.adv_inv_area[side]); - } + const int i_location = (get_option("OPEN_DEFAULT_ADV_INV")) ? saved_area_idx : save_state->area_idx; + const aim_location location = static_cast(i_location); auto square = squares[location]; // determine the square's vehicle/map item presence bool has_veh_items = square.can_store_in_vehicle() ? @@ -65,12 +61,12 @@ void advanced_inventory_pane::load_settings(int side, const std::arraym.i_at(square.pos).empty(); // determine based on map items and settings to show cargo bool show_vehicle = is_re_enter ? - uistate.adv_inv_in_vehicle[side] : has_veh_items ? true : + save_state->in_vehicle : has_veh_items ? true : has_map_items ? false : square.can_store_in_vehicle(); set_area(square, show_vehicle); - sortby = static_cast(uistate.adv_inv_sort[side]); - index = uistate.adv_inv_index[side]; - filter = uistate.adv_inv_filter[side]; + sortby = static_cast(save_state->sort_idx); + index = save_state->selected_idx; + filter = save_state->filter; } bool advanced_inventory_pane::is_filtered( const advanced_inv_listitem &it ) const diff --git a/src/advanced_inv_pane.h b/src/advanced_inv_pane.h index f963091f589ea..b13757676e892 100644 --- a/src/advanced_inv_pane.h +++ b/src/advanced_inv_pane.h @@ -59,8 +59,9 @@ class advanced_inventory_pane bool in_vehicle() const { return viewing_cargo; } - void save_settings(int side); - void load_settings(int side, const std::array& squares, bool is_re_enter); + advanced_inv_pane_save_state* save_state; + void save_settings(); + void load_settings(int saved_area_idx, const std::array& squares, bool is_re_enter); /** * Index of the selected item (index of @ref items), */ diff --git a/src/uistate.h b/src/uistate.h index 5df93f9de12c7..9cc5880393749 100644 --- a/src/uistate.h +++ b/src/uistate.h @@ -13,6 +13,58 @@ class item; + +struct advanced_inv_pane_save_state { + public: + int sort_idx = 1; + std::string filter; + int area_idx = 11; + int selected_idx = 0; + + bool in_vehicle = false; + + template + void serialize( JsonStream &json, std::string prefix ) const { + json.member( prefix + "sort_idx", sort_idx ); + json.member( prefix + "filter", filter ); + json.member( prefix + "area_idx", area_idx ); + json.member( prefix + "selected_idx", selected_idx ); + json.member( prefix + "in_vehicle", in_vehicle ); + } + + void deserialize( JsonObject &jo, std::string prefix ) { + jo.read( prefix + "sort_idx", sort_idx ); + jo.read( prefix + "filter", filter ); + jo.read( prefix + "area_idx", area_idx ); + jo.read( prefix + "selected_idx", selected_idx ); + jo.read( prefix + "in_vehicle", in_vehicle ); + } +}; + +struct advanced_inv_save_state { + public: + int saved_area = 11; + int saved_area_right = 0; + advanced_inv_pane_save_state pane; + advanced_inv_pane_save_state pane_right; + + template + void serialize( JsonStream &json, std::string prefix ) const { + json.member(prefix + "saved_area", saved_area); + json.member(prefix + "saved_area_right", saved_area_right); + pane.serialize(json, prefix + "pane_"); + pane_right.serialize( json, prefix + "pane_right_" ); + } + + void deserialize( JsonObject &jo, std::string prefix ) { + jo.read(prefix + "saved_area", saved_area); + jo.read(prefix + "saved_area_right", saved_area_right); + pane.area_idx = saved_area; + pane_right.area_idx = saved_area_right; + pane.deserialize(jo, prefix + "pane_"); + pane_right.deserialize( jo, prefix + "pane_right_" ); + } +}; /* centralized depot for trivial ui data such as sorting, string_input_popup history, etc. To use this, see the ****notes**** below @@ -26,7 +78,7 @@ class uistatedata private: // not needed for compilation, but keeps syntax plugins happy using itype_id = std::string; - enum side { left = 0, right = 1, NUM_PANES = 2 }; + enum side { left = 0, right = 1, NUM_PANES = 2 }; public: int ags_pay_gas_selected_pump = 0; @@ -34,24 +86,23 @@ class uistatedata int wishmutate_selected = 0; int wishmonster_selected = 0; int iexamine_atm_selected = 0; - std::array adv_inv_sort = {{1, 1}}; - std::array adv_inv_area = {{5, 0}}; - std::array adv_inv_index = {{0, 0}}; - std::array adv_inv_in_vehicle = {{false, false}}; - std::array adv_inv_filter = {{"", ""}}; - std::array adv_inv_default_areas = {{11, 0}}; //left: All, right: Inventory + int adv_inv_src = left; int adv_inv_dest = right; int adv_inv_last_popup_dest = 0; + int adv_inv_exit_code = 0; + int adv_inv_container_location = -1; int adv_inv_container_index = 0; - int adv_inv_exit_code = 0; itype_id adv_inv_container_type = "null"; itype_id adv_inv_container_content_type = "null"; + bool adv_inv_container_in_vehicle = false; + int adv_inv_re_enter_move_all = 0; int adv_inv_aim_all_location = 1; std::map> adv_inv_veh_items, adv_inv_map_items; - bool adv_inv_container_in_vehicle = false; + + advanced_inv_save_state transfer_save; bool editmap_nsa_viewmode = false; // true: ignore LOS and lighting bool overmap_blinking = true; // toggles active blinking of overlays. @@ -63,7 +114,7 @@ class uistatedata bool overmap_show_forest_trails = true; bool debug_ranged; - tripoint adv_inv_last_coords = {-999, -999, -999}; + tripoint adv_inv_last_coords = { -999, -999, -999 }; int last_inv_start = -2; int last_inv_sel = -2; @@ -123,13 +174,9 @@ class uistatedata const unsigned int input_history_save_max = 25; json.start_object(); + transfer_save.serialize( json, "transfer_save_" ); + /**** if you want to save whatever so it's whatever when the game is started next, declare here and.... ****/ - serialize_array( json, "adv_inv_sort", adv_inv_sort ); - serialize_array( json, "adv_inv_area", adv_inv_area ); - serialize_array( json, "adv_inv_index", adv_inv_index ); - serialize_array( json, "adv_inv_in_vehicle", adv_inv_in_vehicle ); - serialize_array( json, "adv_inv_filter", adv_inv_filter ); - serialize_array( json, "adv_inv_default_areas", adv_inv_default_areas ); // non array stuffs json.member( "adv_inv_src", adv_inv_src ); json.member( "adv_inv_dest", adv_inv_dest ); @@ -180,50 +227,8 @@ class uistatedata template void deserialize( JsonStream &jsin ) { auto jo = jsin.get_object(); - /**** here ****/ - if( jo.has_array( "adv_inv_sort" ) ) { - auto tmp = jo.get_int_array( "adv_inv_sort" ); - std::move( tmp.begin(), tmp.end(), adv_inv_sort.begin() ); - } else { - jo.read( "adv_inv_leftsort", adv_inv_sort[left] ); - jo.read( "adv_inv_rightsort", adv_inv_sort[right] ); - } - // pane area selected - if( jo.has_array( "adv_inv_area" ) ) { - auto tmp = jo.get_int_array( "adv_inv_area" ); - std::move( tmp.begin(), tmp.end(), adv_inv_area.begin() ); - } else { - jo.read( "adv_inv_leftarea", adv_inv_area[left] ); - jo.read( "adv_inv_rightarea", adv_inv_area[right] ); - } - // pane current index - if( jo.has_array( "adv_inv_index" ) ) { - auto tmp = jo.get_int_array( "adv_inv_index" ); - std::move( tmp.begin(), tmp.end(), adv_inv_index.begin() ); - } else { - jo.read( "adv_inv_leftindex", adv_inv_index[left] ); - jo.read( "adv_inv_rightindex", adv_inv_index[right] ); - } - // viewing vehicle cargo - if( jo.has_array( "adv_inv_in_vehicle" ) ) { - auto ja = jo.get_array( "adv_inv_in_vehicle" ); - for( size_t i = 0; ja.has_more(); ++i ) { - adv_inv_in_vehicle[i] = ja.next_bool(); - } - } - // filter strings - if( jo.has_array( "adv_inv_filter" ) ) { - auto tmp = jo.get_string_array( "adv_inv_filter" ); - std::move( tmp.begin(), tmp.end(), adv_inv_filter.begin() ); - } else { - jo.read( "adv_inv_leftfilter", adv_inv_filter[left] ); - jo.read( "adv_inv_rightfilter", adv_inv_filter[right] ); - } - // default areas - if( jo.has_array( "adv_inv_deafult_areas" ) ) { - auto tmp = jo.get_int_array( "adv_inv_deafult_areas" ); - std::move( tmp.begin(), tmp.end(), adv_inv_default_areas.begin() ); - } + + transfer_save.deserialize( jo, "transfer_save_" ); // the rest jo.read( "adv_inv_src", adv_inv_src ); jo.read( "adv_inv_dest", adv_inv_dest ); From 75e6cf5645873c5dc50031e892db5e0a8a67f3c8 Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 1 Nov 2019 15:46:34 -0400 Subject: [PATCH 04/10] remove unused fields from uistate --- src/advanced_inv.cpp | 1 - src/uistate.h | 6 ------ 2 files changed, 7 deletions(-) diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index 480c0cb9b7946..1f82923c1a985 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -133,7 +133,6 @@ advanced_inventory::~advanced_inventory() void advanced_inventory::save_settings( bool only_panes ) { if( !only_panes ) { - uistate.adv_inv_last_coords = g->u.pos(); uistate.adv_inv_src = src; uistate.adv_inv_dest = dest; } diff --git a/src/uistate.h b/src/uistate.h index 9cc5880393749..e91850999bf3e 100644 --- a/src/uistate.h +++ b/src/uistate.h @@ -100,7 +100,6 @@ class uistatedata int adv_inv_re_enter_move_all = 0; int adv_inv_aim_all_location = 1; - std::map> adv_inv_veh_items, adv_inv_map_items; advanced_inv_save_state transfer_save; @@ -113,11 +112,6 @@ class uistatedata bool overmap_show_hordes = true; bool overmap_show_forest_trails = true; - bool debug_ranged; - tripoint adv_inv_last_coords = { -999, -999, -999 }; - int last_inv_start = -2; - int last_inv_sel = -2; - // V Menu Stuff int list_item_sort = 0; std::string list_item_filter; From e4f0d5581af0e0f7050052214108ef9ff1ee3647 Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 1 Nov 2019 17:25:08 -0400 Subject: [PATCH 05/10] fixing state not saving correctly when swapping panes --- src/advanced_inv.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index 1f82923c1a985..1323a90c9f8ee 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -1753,7 +1753,9 @@ char advanced_inventory::get_minimap_sym( side p ) const void advanced_inventory::swap_panes() { // Switch left and right pane. - std::swap( panes[left], panes[right] ); + std::swap( panes[left], panes[right] ); + // Switch save states + std::swap( panes[left].save_state, panes[right].save_state); // Window pointer must be unchanged! std::swap( panes[left].window, panes[right].window ); // Recalculation required for weight & volume From 05817ec22c5b500f95c5abe56c0726db4b50ff08 Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 1 Nov 2019 17:31:57 -0400 Subject: [PATCH 06/10] moving advanced inventory settings into object + astyle --- src/advanced_inv.cpp | 48 +++++++++++++++++++-------------------- src/advanced_inv.h | 2 +- src/advanced_inv_pane.cpp | 20 ++++++++-------- src/advanced_inv_pane.h | 5 ++-- src/uistate.h | 39 ++++++++++++++++--------------- 5 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index 1323a90c9f8ee..d9149e683a6ce 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -114,17 +114,16 @@ advanced_inventory::advanced_inventory() advanced_inventory::~advanced_inventory() { save_settings( false ); - auto &aim_code = uistate.adv_inv_exit_code; - if( aim_code != exit_re_entry ) { - aim_code = exit_okay; + if( save_state->exit_code != exit_re_entry ) { + save_state->exit_code = exit_okay; } // Only refresh if we exited manually, otherwise we're going to be right back if( exit ) { werase( head ); werase( minimap ); werase( mm_border ); - werase(panes[left].window); - werase(panes[right].window); + werase( panes[left].window ); + werase( panes[right].window ); g->refresh_all(); g->u.check_item_encumbrance_flag(); } @@ -133,8 +132,7 @@ advanced_inventory::~advanced_inventory() void advanced_inventory::save_settings( bool only_panes ) { if( !only_panes ) { - uistate.adv_inv_src = src; - uistate.adv_inv_dest = dest; + save_state->active_left = ( src == left ); } for( int i = 0; i < NUM_PANES; ++i ) { panes[i].save_settings(); @@ -143,10 +141,10 @@ void advanced_inventory::save_settings( bool only_panes ) void advanced_inventory::load_settings() { - aim_exit aim_code = static_cast( uistate.adv_inv_exit_code ); - panes[left].load_settings(save_state->saved_area, squares, aim_code == exit_re_entry); - panes[right].load_settings(save_state->saved_area_right, squares, aim_code == exit_re_entry); - uistate.adv_inv_exit_code = exit_none; + aim_exit aim_code = static_cast( save_state->exit_code ); + panes[left].load_settings( save_state->saved_area, squares, aim_code == exit_re_entry ); + panes[right].load_settings( save_state->saved_area_right, squares, aim_code == exit_re_entry ); + save_state->exit_code = exit_none; } std::string advanced_inventory::get_sortname( advanced_inv_sortby sortby ) @@ -210,8 +208,8 @@ void advanced_inventory::init() load_settings(); - src = static_cast(uistate.adv_inv_src); - dest = static_cast(uistate.adv_inv_dest); + src = ( save_state->active_left ) ? left : right; + dest = ( save_state->active_left ) ? right : left; w_height = TERMY < min_w_height + head_height ? min_w_height : TERMY - head_height; w_width = TERMX < min_w_width ? min_w_width : TERMX > max_w_width ? max_w_width : @@ -226,9 +224,9 @@ void advanced_inventory::init() minimap = catacurses::newwin( minimap_height, minimap_width, point( colstart + ( w_width - ( minimap_width + 1 ) ), headstart + 1 ) ); panes[left].window = catacurses::newwin( w_height, w_width / 2, point( colstart, - headstart + head_height ) ); + headstart + head_height ) ); panes[right].window = catacurses::newwin( w_height, w_width / 2, point( colstart + w_width / 2, - headstart + head_height ) ); + headstart + head_height ) ); itemsPerPage = w_height - 2 - 5; // 2 for the borders, 5 for the header stuff } @@ -751,9 +749,9 @@ bool advanced_inventory::move_all_items( bool nested_call ) auto shadow = panes[src]; // here we recursively call this function with each area in order to // put all items in the proper destination area, with minimal fuss - auto &loc = uistate.adv_inv_aim_all_location; + auto &loc = save_state->aim_all_location; // re-entry nonsense - auto &entry = uistate.adv_inv_re_enter_move_all; + auto &entry = save_state->re_enter_move_all; // if we are just starting out, set entry to initial value switch( static_cast( entry++ ) ) { case ENTRY_START: @@ -1068,7 +1066,7 @@ void advanced_inventory::display() } ) { auto &pane = panes[cside]; int i_location = cside == left ? save_state->saved_area : save_state->saved_area_right; - aim_location location = static_cast(i_location); + aim_location location = static_cast( i_location ); if( pane.get_area() != location || location == AIM_ALL ) { pane.recalc = true; } @@ -1499,7 +1497,7 @@ bool advanced_inventory::query_destination( aim_location &def ) } } // Selected keyed to uilist.entries, which starts at 0. - menu.selected = uistate.adv_inv_last_popup_dest - AIM_SOUTHWEST; + menu.selected = save_state->last_popup_dest - AIM_SOUTHWEST; menu.show(); // generate and show window. while( menu.ret == UILIST_WAIT_INPUT ) { menu.query( false ); // query, but don't loop @@ -1511,7 +1509,7 @@ bool advanced_inventory::query_destination( aim_location &def ) // we have to set the destination pane so that move actions will target it // we can use restore_area later to undo this panes[dest].set_area( squares[def], true ); - uistate.adv_inv_last_popup_dest = menu.ret; + save_state->last_popup_dest = menu.ret; return true; } return false; @@ -1753,9 +1751,9 @@ char advanced_inventory::get_minimap_sym( side p ) const void advanced_inventory::swap_panes() { // Switch left and right pane. - std::swap( panes[left], panes[right] ); + std::swap( panes[left], panes[right] ); // Switch save states - std::swap( panes[left].save_state, panes[right].save_state); + std::swap( panes[left].save_state, panes[right].save_state ); // Window pointer must be unchanged! std::swap( panes[left].window, panes[right].window ); // Recalculation required for weight & volume @@ -1769,15 +1767,15 @@ void advanced_inventory::do_return_entry() save_settings( true ); g->u.assign_activity( activity_id( "ACT_ADV_INVENTORY" ) ); g->u.activity.auto_resume = true; - uistate.adv_inv_exit_code = exit_re_entry; + save_state->exit_code = exit_re_entry; } bool advanced_inventory::is_processing() const { - return uistate.adv_inv_re_enter_move_all != ENTRY_START; + return save_state->re_enter_move_all != ENTRY_START; } void cancel_aim_processing() { - uistate.adv_inv_re_enter_move_all = ENTRY_START; + uistate.transfer_save.re_enter_move_all = ENTRY_START; } diff --git a/src/advanced_inv.h b/src/advanced_inv.h index d1adb85648c31..2a1384acfbded 100644 --- a/src/advanced_inv.h +++ b/src/advanced_inv.h @@ -116,7 +116,7 @@ class advanced_inventory bool exit; - advanced_inv_save_state* save_state; + advanced_inv_save_state *save_state; // store/load settings (such as index, filter, etc) void save_settings( bool only_panes ); void load_settings(); diff --git a/src/advanced_inv_pane.cpp b/src/advanced_inv_pane.cpp index ecaf20511e9c9..7a718f4573c30 100644 --- a/src/advanced_inv_pane.cpp +++ b/src/advanced_inv_pane.cpp @@ -50,21 +50,23 @@ void advanced_inventory_pane::save_settings() save_state->sort_idx = sortby; } -void advanced_inventory_pane::load_settings(int saved_area_idx, const std::array& squares, bool is_re_enter) +void advanced_inventory_pane::load_settings( int saved_area_idx, + const std::array &squares, bool is_re_enter ) { - const int i_location = (get_option("OPEN_DEFAULT_ADV_INV")) ? saved_area_idx : save_state->area_idx; - const aim_location location = static_cast(i_location); + const int i_location = ( get_option( "OPEN_DEFAULT_ADV_INV" ) ) ? saved_area_idx : + save_state->area_idx; + const aim_location location = static_cast( i_location ); auto square = squares[location]; // determine the square's vehicle/map item presence bool has_veh_items = square.can_store_in_vehicle() ? - !square.veh->get_items(square.vstor).empty() : false; - bool has_map_items = !g->m.i_at(square.pos).empty(); + !square.veh->get_items( square.vstor ).empty() : false; + bool has_map_items = !g->m.i_at( square.pos ).empty(); // determine based on map items and settings to show cargo bool show_vehicle = is_re_enter ? - save_state->in_vehicle : has_veh_items ? true : - has_map_items ? false : square.can_store_in_vehicle(); - set_area(square, show_vehicle); - sortby = static_cast(save_state->sort_idx); + save_state->in_vehicle : has_veh_items ? true : + has_map_items ? false : square.can_store_in_vehicle(); + set_area( square, show_vehicle ); + sortby = static_cast( save_state->sort_idx ); index = save_state->selected_idx; filter = save_state->filter; } diff --git a/src/advanced_inv_pane.h b/src/advanced_inv_pane.h index b13757676e892..890ad023b121a 100644 --- a/src/advanced_inv_pane.h +++ b/src/advanced_inv_pane.h @@ -59,9 +59,10 @@ class advanced_inventory_pane bool in_vehicle() const { return viewing_cargo; } - advanced_inv_pane_save_state* save_state; + advanced_inv_pane_save_state *save_state; void save_settings(); - void load_settings(int saved_area_idx, const std::array& squares, bool is_re_enter); + void load_settings( int saved_area_idx, + const std::array &squares, bool is_re_enter ); /** * Index of the selected item (index of @ref items), */ diff --git a/src/uistate.h b/src/uistate.h index e91850999bf3e..fcbc31c3bb152 100644 --- a/src/uistate.h +++ b/src/uistate.h @@ -43,6 +43,13 @@ struct advanced_inv_pane_save_state { struct advanced_inv_save_state { public: + int exit_code = 0; + int re_enter_move_all = 0; + int aim_all_location = 1; + + bool active_left = true; + int last_popup_dest = 0; + int saved_area = 11; int saved_area_right = 0; advanced_inv_pane_save_state pane; @@ -50,18 +57,24 @@ struct advanced_inv_save_state { template void serialize( JsonStream &json, std::string prefix ) const { - json.member(prefix + "saved_area", saved_area); - json.member(prefix + "saved_area_right", saved_area_right); - pane.serialize(json, prefix + "pane_"); + json.member( prefix + "active_left", active_left ); + json.member( prefix + "last_popup_dest", last_popup_dest ); + + json.member( prefix + "saved_area", saved_area ); + json.member( prefix + "saved_area_right", saved_area_right ); + pane.serialize( json, prefix + "pane_" ); pane_right.serialize( json, prefix + "pane_right_" ); } void deserialize( JsonObject &jo, std::string prefix ) { - jo.read(prefix + "saved_area", saved_area); - jo.read(prefix + "saved_area_right", saved_area_right); + jo.read( prefix + "active_left", active_left ); + jo.read( prefix + "last_popup_dest", last_popup_dest ); + + jo.read( prefix + "saved_area", saved_area ); + jo.read( prefix + "saved_area_right", saved_area_right ); pane.area_idx = saved_area; pane_right.area_idx = saved_area_right; - pane.deserialize(jo, prefix + "pane_"); + pane.deserialize( jo, prefix + "pane_" ); pane_right.deserialize( jo, prefix + "pane_right_" ); } }; @@ -87,20 +100,12 @@ class uistatedata int wishmonster_selected = 0; int iexamine_atm_selected = 0; - int adv_inv_src = left; - int adv_inv_dest = right; - int adv_inv_last_popup_dest = 0; - int adv_inv_exit_code = 0; - int adv_inv_container_location = -1; int adv_inv_container_index = 0; itype_id adv_inv_container_type = "null"; itype_id adv_inv_container_content_type = "null"; bool adv_inv_container_in_vehicle = false; - int adv_inv_re_enter_move_all = 0; - int adv_inv_aim_all_location = 1; - advanced_inv_save_state transfer_save; bool editmap_nsa_viewmode = false; // true: ignore LOS and lighting @@ -172,9 +177,6 @@ class uistatedata /**** if you want to save whatever so it's whatever when the game is started next, declare here and.... ****/ // non array stuffs - json.member( "adv_inv_src", adv_inv_src ); - json.member( "adv_inv_dest", adv_inv_dest ); - json.member( "adv_inv_last_popup_dest", adv_inv_last_popup_dest ); json.member( "adv_inv_container_location", adv_inv_container_location ); json.member( "adv_inv_container_index", adv_inv_container_index ); json.member( "adv_inv_container_in_vehicle", adv_inv_container_in_vehicle ); @@ -224,9 +226,6 @@ class uistatedata transfer_save.deserialize( jo, "transfer_save_" ); // the rest - jo.read( "adv_inv_src", adv_inv_src ); - jo.read( "adv_inv_dest", adv_inv_dest ); - jo.read( "adv_inv_last_popup_dest", adv_inv_last_popup_dest ); jo.read( "adv_inv_container_location", adv_inv_container_location ); jo.read( "adv_inv_container_index", adv_inv_container_index ); jo.read( "adv_inv_container_in_vehicle", adv_inv_container_in_vehicle ); From 7372e8e402cc066e4c2f7c312f29ed9576ed68da Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Tue, 17 Mar 2020 10:57:24 +0300 Subject: [PATCH 07/10] Add missing header include --- src/advanced_inv.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/advanced_inv.h b/src/advanced_inv.h index ad70a47d56872..79aeb602c3c7a 100644 --- a/src/advanced_inv.h +++ b/src/advanced_inv.h @@ -12,6 +12,7 @@ #include "advanced_inv_area.h" #include "advanced_inv_listitem.h" #include "advanced_inv_pane.h" +#include "uistate.h" class uilist; class vehicle; From 9373ad53b54effec0f92b604a6ab09c373b84b45 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Tue, 17 Mar 2020 10:57:49 +0300 Subject: [PATCH 08/10] Add missing header include --- src/advanced_inv_pane.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/advanced_inv_pane.h b/src/advanced_inv_pane.h index 338e294b559cd..337e52860643f 100644 --- a/src/advanced_inv_pane.h +++ b/src/advanced_inv_pane.h @@ -4,6 +4,7 @@ #include "cursesdef.h" #include "advanced_inv_listitem.h" +#include "uistate.h" #include #include From 3639103e39e8253dab8b7d10b9db5a516086d9f1 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Tue, 17 Mar 2020 11:09:55 +0300 Subject: [PATCH 09/10] Update advanced_inv.h --- src/advanced_inv.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/advanced_inv.h b/src/advanced_inv.h index 79aeb602c3c7a..ea081c6799dfd 100644 --- a/src/advanced_inv.h +++ b/src/advanced_inv.h @@ -12,12 +12,13 @@ #include "advanced_inv_area.h" #include "advanced_inv_listitem.h" #include "advanced_inv_pane.h" -#include "uistate.h" class uilist; class vehicle; class item; +struct advanced_inv_save_state; + struct sort_case_insensitive_less : public std::binary_function< char, char, bool > { bool operator()( char x, char y ) const { return toupper( static_cast< unsigned char >( x ) ) < toupper( static_cast< unsigned char >( y ) ); From ad983e3555a00fb8d3cbf80f24949f0df78ed018 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Tue, 17 Mar 2020 11:10:14 +0300 Subject: [PATCH 10/10] Update advanced_inv_pane.h --- src/advanced_inv_pane.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/advanced_inv_pane.h b/src/advanced_inv_pane.h index 337e52860643f..86c1e4b672643 100644 --- a/src/advanced_inv_pane.h +++ b/src/advanced_inv_pane.h @@ -4,13 +4,14 @@ #include "cursesdef.h" #include "advanced_inv_listitem.h" -#include "uistate.h" #include #include #include #include +struct advanced_inv_pane_save_state; + enum aim_location : char; enum advanced_inv_sortby {