From 97be172fa33162acb2f6c12b18d781a65961ca0a Mon Sep 17 00:00:00 2001 From: EmilyV99 Date: Tue, 15 Aug 2023 17:34:17 -0400 Subject: [PATCH] chore: clean up some subscreen item animation code/replay errors --- src/new_subscr.cpp | 18 ++++++++++++++++-- src/new_subscr.h | 1 + src/subscr.cpp | 9 +-------- src/subscr.h | 7 ++++--- src/zc/ending.cpp | 2 ++ src/zc/hero.cpp | 29 ++++++++++++++++++++--------- src/zc/zc_subscr.cpp | 6 +++--- src/zc/zc_sys.cpp | 17 +++++++++++------ src/zc/zelda.cpp | 13 +++++++------ src/zq/zq_subscr.cpp | 2 +- 10 files changed, 66 insertions(+), 38 deletions(-) diff --git a/src/new_subscr.cpp b/src/new_subscr.cpp index 827d2f005b..881426b061 100644 --- a/src/new_subscr.cpp +++ b/src/new_subscr.cpp @@ -34,10 +34,11 @@ void magicgauge(BITMAP *dest,int32_t x,int32_t y, int32_t container, int32_t not int32_t cap_tile, int32_t cap_cset, bool cap_mod, int32_t aftercap_tile, int32_t aftercap_cset, bool aftercap_mod, int32_t frames, int32_t speed, int32_t delay, bool unique_last, int32_t show); int subscr_item_clk = 0; +bool subscr_itemless = false; int btnitem_clks[4] = {0}; int btnitem_ids[4] = {0}; -void reset_subscr_items() +void refresh_subscr_buttonitems() { for(int q = 0; q < 4; ++q) { @@ -46,7 +47,7 @@ void reset_subscr_items() } } -void update_subscr_items() +void animate_subscr_buttonitems() { int nullval = get_qr(qr_ITM_0_INVIS_ON_BTNS) ? 0 : -1; int ids[] = {Awpn,Bwpn,Xwpn,Ywpn}; @@ -62,6 +63,17 @@ void update_subscr_items() } } +void refresh_subscr_items() +{ + subscr_item_clk = 0; + subscr_itemless = false; +} + +void kill_subscr_items() +{ + subscr_itemless = true; +} + int32_t to_real_font(int32_t ss_font) { switch(ss_font) @@ -1190,6 +1202,7 @@ byte SW_ButtonItem::getType() const } void SW_ButtonItem::draw(BITMAP* dest, int32_t xofs, int32_t yofs, SubscrPage& page) const { + if(!show_subscreen_items) return; if(flags&SUBSCR_BTNITM_TRANSP) drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); @@ -2186,6 +2199,7 @@ int32_t SW_ItemSlot::getDisplayItem() const } void SW_ItemSlot::draw(BITMAP* dest, int32_t xofs, int32_t yofs, SubscrPage& page) const { + if(subscr_itemless) return; #ifdef IS_PLAYER if(flags&SUBSCR_CURITM_INVIS) return; diff --git a/src/new_subscr.h b/src/new_subscr.h index b3e0bdbe17..b42e093121 100644 --- a/src/new_subscr.h +++ b/src/new_subscr.h @@ -13,6 +13,7 @@ struct PACKFILE; #define NEG_OR_MASK(v,mask) (v < 0 ? v : (v&mask)) extern int subscr_item_clk; +extern bool subscr_itemless; //Old subscreen stuff struct subscreen_object diff --git a/src/subscr.cpp b/src/subscr.cpp index 792d5fbafd..26019ff68a 100644 --- a/src/subscr.cpp +++ b/src/subscr.cpp @@ -29,7 +29,6 @@ bool show_subscreen_dmap_dots=true; bool show_subscreen_numbers=true; bool show_subscreen_items=true; bool show_subscreen_life=true; -bool new_sel=false; extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations; extern HeroClass Hero; @@ -3396,7 +3395,7 @@ void minimaptitle(BITMAP *dest, int32_t x, int32_t y, FONT *tempfont, int32_t co void put_passive_subscr(BITMAP *dest,int32_t x,int32_t y,bool showtime,int32_t pos2) { ++subscr_item_clk; - update_subscr_items(); + animate_subscr_buttonitems(); BITMAP *subscr = create_sub_bitmap(dest,x,y,256,passive_subscreen_height); if(no_subscreen()) @@ -3766,12 +3765,6 @@ void putBmap(BITMAP *dest, int32_t x, int32_t y,bool showmap, bool showrooms, bo } } -void load_Sitems() -{ - subscr_item_clk = 0; - new_sel=true; -} - void update_subscreens(int32_t dmap) { if(dmap<0) diff --git a/src/subscr.h b/src/subscr.h index ec4edc4d86..64dc4bf875 100644 --- a/src/subscr.h +++ b/src/subscr.h @@ -167,8 +167,10 @@ const byte bmaptiles_bs[5][6] = {40,41,42,43,43,44} }; -void reset_subscr_items(); -void update_subscr_items(); +void refresh_subscr_buttonitems(); +void animate_subscr_buttonitems(); +void refresh_subscr_items(); +void kill_subscr_items(); int32_t stripspaces(char *source, char *target, int32_t stop); void put_passive_subscr(BITMAP *dest,int32_t x,int32_t y,bool showtime,int32_t pos2); void puttriframe(BITMAP *dest, int32_t x, int32_t y, int32_t triframecolor, int32_t numbercolor, int32_t triframetile, int32_t triframecset, int32_t triforcetile, int32_t triforcecset, bool showframe, bool showpieces, bool largepieces); @@ -176,7 +178,6 @@ void puttriforce(BITMAP *dest, int32_t x, int32_t y, int32_t tile, int32_t cset, void draw_block(BITMAP *dest,int32_t x,int32_t y,int32_t tile,int32_t cset,int32_t w,int32_t h); void draw_block_flip(BITMAP *dest,int32_t x,int32_t y,int32_t tile,int32_t cset,int32_t w,int32_t h,int32_t flip,bool overlay,bool trans); void putBmap(BITMAP *dest, int32_t x, int32_t y,bool showmap, bool showrooms, bool showhero, int32_t roomcolor, int32_t herocolor, bool large); -void load_Sitems(); void textout_styled_aligned_ex(BITMAP *bmp, const FONT *f, const char *s, int32_t x, int32_t y, int32_t textstyle, int32_t alignment, int32_t color, int32_t shadow, int32_t bg); void textprintf_styled_aligned_ex(BITMAP *bmp, const FONT *f, int32_t x, int32_t y, int32_t textstyle, int32_t alignment, int32_t color, int32_t shadow, int32_t bg, const char *format, ...); void update_subscreens(int32_t dmap=-1); diff --git a/src/zc/ending.cpp b/src/zc/ending.cpp index 34593660a6..cc549e823d 100644 --- a/src/zc/ending.cpp +++ b/src/zc/ending.cpp @@ -212,6 +212,7 @@ void ending() Lwpns.clear(); chainlinks.clear(); decorations.clear(); + kill_subscr_items(); set_uformat(U_ASCII); kill_sfx(); @@ -648,6 +649,7 @@ void ending_scripted() guys.clear(); chainlinks.clear(); decorations.clear(); + kill_subscr_items(); clear_bitmap(msg_txt_display_buf); clear_bitmap(msg_bg_display_buf); dismissmsg(); diff --git a/src/zc/hero.cpp b/src/zc/hero.cpp index cc147041ae..cfb9f7a205 100644 --- a/src/zc/hero.cpp +++ b/src/zc/hero.cpp @@ -10214,7 +10214,10 @@ static void deselectbombsWPN(word& wpos, int32_t& BTNwpn, int32_t& directItemBTN return; } - auto temp = pg->movepos_legacy(SEL_VERIFY_LEFT, wpos, f1, f2, f3); + auto fp1 = ((f1&0xFF)==255) ? 255 : ((empty || (f1&0xFF)==(wpos&0xFF)) ? f1 : 255); + auto fp2 = ((f2&0xFF)==255) ? 255 : ((empty || (f2&0xFF)==(wpos&0xFF)) ? f2 : 255); + auto fp3 = ((f3&0xFF)==255) ? 255 : ((empty || (f3&0xFF)==(wpos&0xFF)) ? f3 : 255); + auto temp = pg->movepos_legacy(SEL_VERIFY_LEFT, wpos, fp1, fp2, fp3); BTNwpn = pg->get_item_pos(temp>>8); directItemBTN = NEG_OR_MASK(BTNwpn,0xFFF); wpos = temp; @@ -28617,10 +28620,13 @@ static void selectNextBTNWpn(int32_t type, word& wpos, int32_t& BTNwpn, SubscrPage* pg = new_subscreen_active->get_page(pgn==255?new_subscreen_active->curpage:pgn); if(!pg) return; - auto ret = pg->movepos_legacy(type, wpos, f1, f2, f3); - BTNwpn = pg->get_item_pos(ret>>8); - directItemBTN = NEG_OR_MASK(BTNwpn,0xFFF); - wpos = ret; + auto fp1 = ((f1&0xFF)==255) ? 255 : ((empty || (f1&0xFF)==(wpos&0xFF)) ? f1 : 255); + auto fp2 = ((f2&0xFF)==255) ? 255 : ((empty || (f2&0xFF)==(wpos&0xFF)) ? f2 : 255); + auto fp3 = ((f3&0xFF)==255) ? 255 : ((empty || (f3&0xFF)==(wpos&0xFF)) ? f3 : 255); + auto ret = pg->movepos_legacy(type, wpos, fp1, fp2, fp3); + BTNwpn = pg->get_item_pos(ret>>8); + directItemBTN = NEG_OR_MASK(BTNwpn,0xFFF); + wpos = ret; } void selectNextAWpn(int32_t type) { @@ -28663,9 +28669,9 @@ static void verifyWpn(word& wpos, int32_t& BTNwpn, int32_t& directItemBTN, word SubscrPage* pg = new_subscreen_active->get_page(pgn==255?new_subscreen_active->curpage:pgn); if(!pg) return; - auto fp1 = ((f1&0xFF)==255) ? 255 : ((empty || (f1&0xFF)==(wpos&0xFF)) ? f1>>8 : 255); - auto fp2 = ((f2&0xFF)==255) ? 255 : ((empty || (f2&0xFF)==(wpos&0xFF)) ? f2>>8 : 255); - auto fp3 = ((f3&0xFF)==255) ? 255 : ((empty || (f3&0xFF)==(wpos&0xFF)) ? f3>>8 : 255); + auto fp1 = ((f1&0xFF)==255) ? 255 : ((empty || (f1&0xFF)==(wpos&0xFF)) ? f1 : 255); + auto fp2 = ((f2&0xFF)==255) ? 255 : ((empty || (f2&0xFF)==(wpos&0xFF)) ? f2 : 255); + auto fp3 = ((f3&0xFF)==255) ? 255 : ((empty || (f3&0xFF)==(wpos&0xFF)) ? f3 : 255); wpos = pg->movepos_legacy(SEL_VERIFY_RIGHT, wpos, fp1, fp2, fp3); BTNwpn = pg->get_item_pos(wpos>>8); directItemBTN = NEG_OR_MASK(BTNwpn,0xFFF); @@ -29197,7 +29203,7 @@ void getitem(int32_t id, bool nosound, bool doRunPassive) flushItemCache(); update_subscreens(); - load_Sitems(); + refresh_subscr_items(); verifyBothWeapons(); } @@ -30012,6 +30018,8 @@ void HeroClass::getTriforce(int32_t id2) Lwpns.clear(); chainlinks.clear(); + kill_subscr_items(); + //decorations.clear(); if(!COOLSCROLL) { @@ -30467,6 +30475,9 @@ void HeroClass::heroDeathAnimation() Lwpns.clear(); chainlinks.clear(); decorations.clear(); + + kill_subscr_items(); + Playing = false; game->set_deaths(zc_min(game->get_deaths()+1,USHRT_MAX)); diff --git a/src/zc/zc_subscr.cpp b/src/zc/zc_subscr.cpp index bb0dc615d1..85b8fc33e5 100644 --- a/src/zc/zc_subscr.cpp +++ b/src/zc/zc_subscr.cpp @@ -55,7 +55,7 @@ void dosubscr() int32_t miny; bool showtime = game->should_show_time(); if(replay_version_check(0,19)) - load_Sitems(); + refresh_subscr_items(); else flushItemCache(); pause_sfx(WAV_BRANG); @@ -154,14 +154,14 @@ void dosubscr() { if (!get_qr(qr_NO_L_R_BUTTON_INVENTORY_SWAP)) { - pg.cursor_pos = pg.movepos_legacy(SEL_LEFT, (pos<<8)|pg.getIndex(), -1, -1, -1, false, true); + pg.cursor_pos = pg.movepos_legacy(SEL_LEFT, (pos<<8)|pg.getIndex(), 255, 255, 255, false, true); } } else if(rRbtn() ) { if (!get_qr(qr_NO_L_R_BUTTON_INVENTORY_SWAP)) { - pg.cursor_pos = pg.movepos_legacy(SEL_RIGHT, (pos<<8)|pg.getIndex(), -1, -1, -1, false, true); + pg.cursor_pos = pg.movepos_legacy(SEL_RIGHT, (pos<<8)|pg.getIndex(), 255, 255, 255, false, true); } } else if(rEx3btn() ) diff --git a/src/zc/zc_sys.cpp b/src/zc/zc_sys.cpp index b55ab957bd..581fa88d89 100644 --- a/src/zc/zc_sys.cpp +++ b/src/zc/zc_sys.cpp @@ -2263,24 +2263,24 @@ void removeFromItemCache(int32_t itemclass) void flushItemCache(bool justcost) { - if(justcost && replay_version_check(0,19)) - return; + itemcache_cost.clear(); if(!justcost) itemcache.clear(); - itemcache_cost.clear(); + else if(replay_version_check(0,19)) + return; //also fix the active subscreen if items were deleted -DD if(game != NULL) { verifyBothWeapons(); - load_Sitems(); + refresh_subscr_items(); } } // This is used often, so it should be as direct as possible. int32_t _c_item_id_internal(int32_t itemtype, bool checkmagic, bool jinx_check) { - bool use_cost_cache = replay_version_check(19); + bool use_cost_cache = true;//replay_version_check(19); if(jinx_check) { if(!(HeroSwordClk() || HeroItemClk())) @@ -2329,11 +2329,16 @@ int32_t _c_item_id_internal(int32_t itemtype, bool checkmagic, bool jinx_check) if (use_cost_cache) { if (!checkmagic) + { itemcache[itemtype] = result; + } if (checkmagic || result < 0 || checkmagiccost(result)) itemcache_cost[itemtype] = result; } - else itemcache[itemtype] = result; + else + { + itemcache[itemtype] = result; + } } return result; } diff --git a/src/zc/zelda.cpp b/src/zc/zelda.cpp index 28ba6991b1..b71e33a293 100644 --- a/src/zc/zelda.cpp +++ b/src/zc/zelda.cpp @@ -2170,7 +2170,7 @@ int32_t init_game() update_subscreens(); - load_Sitems(); + refresh_subscr_items(); //load the previous weapons -DD @@ -2223,9 +2223,9 @@ int32_t init_game() Ywpn = pg.get_item_pos(ypos>>8); directItemY = NEG_OR_MASK(Ywpn,0xFF); - update_subscr_items(); + animate_subscr_buttonitems(); - reset_subscr_items(); + refresh_subscr_buttonitems(); } else { @@ -2255,9 +2255,9 @@ int32_t init_game() game->bwpn = bpos; Bwpn = pg.get_item_pos(bpos>>8); directItemB = NEG_OR_MASK(Bwpn,0xFF); - update_subscr_items(); + animate_subscr_buttonitems(); - reset_subscr_items(); + refresh_subscr_buttonitems(); } } else if(new_subscreen_active) @@ -5671,7 +5671,8 @@ void remove_installed_timers() void delete_everything_else() //blarg. { delete_combo_aliases(); - reset_subscr_items(); + refresh_subscr_buttonitems(); + kill_subscr_items(); } void quit_game() diff --git a/src/zq/zq_subscr.cpp b/src/zq/zq_subscr.cpp index 49f91149e1..87f542745b 100644 --- a/src/zq/zq_subscr.cpp +++ b/src/zq/zq_subscr.cpp @@ -2150,7 +2150,7 @@ void update_subscr_dlg(bool start) if(start) { subscreen_dlg[0].dp2=get_zc_font(font_lfont); - load_Sitems(); + refresh_subscr_items(); curr_subscreen_object=0; if(subscr_edit.pages.empty())