From ca943ea07d6f97c444f647f72aa82623f150e1ba Mon Sep 17 00:00:00 2001 From: Paul Broadhead Date: Fri, 27 Mar 2020 22:35:09 +0000 Subject: [PATCH] Enable auto equip when using the item keys. This version avoids modifying the items structure which is unfortunately used to save the manufacturing recipes as a binary file. We need to replace such binary formats as they are too fragile.... --- hud_quickbar_window.c | 53 +++++++++++++++++++++++++++++++------------ items.c | 5 +++- items.h | 11 +++++++++ 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/hud_quickbar_window.c b/hud_quickbar_window.c index df085b029..4c345f399 100644 --- a/hud_quickbar_window.c +++ b/hud_quickbar_window.c @@ -498,7 +498,10 @@ static int display_quickbar_handler(window_info *win) glBegin(GL_QUADS); draw_2d_thing(u_start,v_start,u_end,v_end,x_start,y_start,x_end,y_end); glEnd(); - + + if ((_cur_time - item_list_extra[i].slot_busy_start) < 250) + gray_out(x_start,y_start,item_quickbar_slot_size); + if (item_list[i].cooldown_time > _cur_time) { float cooldown = ((float)(item_list[i].cooldown_time - _cur_time)) / ((float)item_list[i].cooldown_rate); @@ -666,24 +669,45 @@ void init_quickbar (void) } -static void quick_use(int use_id) +// try to use or auto equip the item in the slot +static void quick_use(int use_id, size_t *timer) { Uint8 quick_use_str[3]; int i; - for(i=0; i 500)) + { + *timer = SDL_GetTicks(); + try_auto_equip(i); + } + // the slot will shown as busy for sort while + else + { + item_list_extra[i].slot_busy_start = SDL_GetTicks(); + do_alert1_sound(); + } + } + return; } } } @@ -695,10 +719,11 @@ int action_item_keys(SDL_Keycode key_code, Uint16 key_mod) size_t i; el_key_def keys[] = {K_ITEM1, K_ITEM2, K_ITEM3, K_ITEM4, K_ITEM5, K_ITEM6, K_ITEM7, K_ITEM8, K_ITEM9, K_ITEM10, K_ITEM11, K_ITEM12 }; + static size_t timers[sizeof(keys)/sizeof(el_key_def)] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; for (i=0; i _cur_time) { diff --git a/items.h b/items.h index 73fae35e6..fe47b30d5 100644 --- a/items.h +++ b/items.h @@ -34,6 +34,16 @@ typedef struct Uint32 cooldown_rate; /*!< time that the item would need to cool down from full heat */ } item; +/*! + * Extra features for items. + * We can't change the item struct as it used to read/write the manufacture pipeline file. + * Until that is changed, put other stuff here. + */ +typedef struct +{ + Uint32 slot_busy_start; +} item_extra; + /*! * \name Item definition flags */ @@ -77,6 +87,7 @@ struct quantities { /*! @{ */ extern struct quantities quantities; /*!< Quantities displayed in the items window*/ extern item item_list[ITEM_NUM_ITEMS]; /*!< global list of items */ +extern item_extra item_list_extra[ITEM_NUM_ITEMS]; /*!< global list of items extra properties - use with care this is temporary */ extern int item_dragged; /*!< the position of any currently dragged item, or -1 */ extern int item_quantity; /*!< the number of items for and any currently dragged item */ extern int use_item; /*!< the position of any current items used */