From e95dd70eea1c10d2d3c37468864ed112c5e4f189 Mon Sep 17 00:00:00 2001 From: Paul Broadhead Date: Sat, 8 Jan 2022 18:28:09 +0000 Subject: [PATCH] Issue #163: Fix storage access inconstancy, more access to closed window. Items lists can access a closed storage window if in range. Now the store all button and alt-click an inventory item can do the same. Added sound and visual indication of when access is not valid for the store all button as already done for alt-click and item lists. Access is not allowed after changing map locations until re-opened via and NPC. Fixed an issue where the storage window could be re-opened after a map change if using alt-d hide all window before changing and then restoring after the map change. --- items.c | 39 +++++++++++++++++++++++---------------- storage.c | 6 ++++++ storage.h | 1 + 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/items.c b/items.c index 0d110e0b4..d57a49c8f 100644 --- a/items.c +++ b/items.c @@ -1322,7 +1322,7 @@ static int click_items_handler(window_info *win, int mx, int my, Uint32 flags) my_tcp_send(str, 6); do_drop_item_sound(); } else if (alt_on && (items_mod_click_any_cursor || (item_action_mode==ACTION_WALK))) { - if ((get_id_MW(MW_STORAGE) >= 0) && (get_show_window_MW(MW_STORAGE)) && (view_only_storage == 0)) { + if ((get_id_MW(MW_STORAGE) >= 0) && (view_only_storage == 0) && storage_use_allowed) { reset_storage_rate_limit(); str[0]=DEPOSITE_ITEM; str[1]=item_list[pos].pos; @@ -1388,25 +1388,32 @@ static int click_items_handler(window_info *win, int mx, int my, Uint32 flags) } // Sto All button - else if(over_button(win, mx, my)==BUT_STORE && get_id_MW(MW_STORAGE) >= 0 && view_only_storage == 0 && get_show_window_MW(MW_STORAGE) /*thanks alberich*/){ - reset_storage_rate_limit(); + else if (over_button(win, mx, my) == BUT_STORE) { + if ((get_id_MW(MW_STORAGE) >= 0) && (view_only_storage == 0) && storage_use_allowed) { + reset_storage_rate_limit(); #ifdef STORE_ALL - /* - * Future code to save server load by having one byte to represent the 36 slot inventory loop. Will need server support. - */ - str[0]=DEPOSITE_ITEM; - str[1]=STORE_ALL; - my_tcp_send(str, 2); + /* + * Future code to save server load by having one byte to represent the 36 slot inventory loop. Will need server support. + */ + str[0]=DEPOSITE_ITEM; + str[1]=STORE_ALL; + my_tcp_send(str, 2); #else - for(pos=((items_stoall_nofirstrow)?6:0);pos<((items_stoall_nolastrow)?30:36);pos++){ - if(item_list[pos].quantity>0){ - str[0]=DEPOSITE_ITEM; - str[1]=item_list[pos].pos; - *((Uint32*)(str+2))=SDL_SwapLE32(item_list[pos].quantity); - my_tcp_send(str, 6); + for(pos=((items_stoall_nofirstrow)?6:0);pos<((items_stoall_nolastrow)?30:36);pos++){ + if(item_list[pos].quantity>0){ + str[0]=DEPOSITE_ITEM; + str[1]=item_list[pos].pos; + *((Uint32*)(str+2))=SDL_SwapLE32(item_list[pos].quantity); + my_tcp_send(str, 6); + } } - } #endif + } + else + { + drop_fail_time = SDL_GetTicks(); + do_alert1_sound(); + } } // Drop All button diff --git a/storage.c b/storage.c index 6bc2ad3c6..00fcb3ae8 100644 --- a/storage.c +++ b/storage.c @@ -39,6 +39,7 @@ struct storage_category { int no_storage_categories=0; int selected_category=-1; int view_only_storage=0; +int storage_use_allowed = 0; Uint32 drop_fail_time = 0; int sort_storage_categories = 0; int sort_storage_items = 0; @@ -936,6 +937,7 @@ void display_storage_menu() cur_item_over = -1; storage_text[0] = '\0'; set_window_name("", ""); + storage_use_allowed = 1; ui_scale_storage_handler(&windows_list.window[storage_win]); check_proportional_move(MW_STORAGE); @@ -944,5 +946,9 @@ void display_storage_menu() void close_storagewin() { if(!view_only_storage) + { hide_window_MW(MW_STORAGE); + clear_was_open_MW(MW_STORAGE); + storage_use_allowed = 0; + } } diff --git a/storage.h b/storage.h index 6fce88a71..0c7b45f09 100644 --- a/storage.h +++ b/storage.h @@ -18,6 +18,7 @@ extern int storage_item_dragged; extern ground_item storage_items[STORAGE_ITEMS_SIZE]; /*!< list of storage items. */ extern int view_only_storage; +extern int storage_use_allowed; extern int sort_storage_categories; extern int sort_storage_items; extern Uint32 drop_fail_time;