From 158de40ce3caa737a1f2f6a16291553905b644be Mon Sep 17 00:00:00 2001 From: x-qq Date: Tue, 11 Feb 2020 11:35:14 +0200 Subject: [PATCH] Fix unclickable shop info icons --- src/game/boe.actions.cpp | 13 ++++++++++--- src/game/boe.consts.hpp | 4 ++++ src/game/boe.dlgutil.cpp | 23 +++++++++++++++-------- src/game/boe.newgraph.cpp | 14 ++------------ src/game/boe.newgraph.hpp | 1 - 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/game/boe.actions.cpp b/src/game/boe.actions.cpp index 79e5ea87..fc3b48ba 100644 --- a/src/game/boe.actions.cpp +++ b/src/game/boe.actions.cpp @@ -121,11 +121,11 @@ static void advance_time(bool did_something, bool need_redraw, bool need_reprint // This is defined in pc.editors.cpp since the PC editor also uses it extern void edit_stuff_done(); -void init_screen_locs() { - rectangle startup_base = {281,1,329,302}; +static void init_shopping_rects() { rectangle shop_base = {63,12,99,267}; std::fill(shopping_rects[0].begin(), shopping_rects[0].end(), shop_base); + shopping_rects[0][SHOPRECT_ACTIVE_AREA].right -= 35; shopping_rects[0][SHOPRECT_GRAPHIC].right = shopping_rects[0][SHOPRECT_GRAPHIC].left + 28; shopping_rects[0][SHOPRECT_ITEM_NAME].top += 4; @@ -139,12 +139,19 @@ void init_screen_locs() { shopping_rects[0][SHOPRECT_ITEM_HELP].bottom -= 21; shopping_rects[0][SHOPRECT_ITEM_HELP].right -= 19; shopping_rects[0][SHOPRECT_ITEM_HELP].left = shopping_rects[0][SHOPRECT_ITEM_HELP].right - 14; - for(short i = 1; i < 8; i++) + + for(short i = 1; i < 8; i++) { for(auto& j : shopping_rects[i].keys()) { shopping_rects[i][j] = shopping_rects[0][j]; shopping_rects[i][j].offset(0,i * 36); } + } +} + +void init_screen_locs() { + init_shopping_rects(); + rectangle startup_base = {281,1,329,302}; for(auto btn : startup_button.keys()) { startup_button[btn] = startup_base; diff --git a/src/game/boe.consts.hpp b/src/game/boe.consts.hpp index c5df6ca8..d5a192d7 100644 --- a/src/game/boe.consts.hpp +++ b/src/game/boe.consts.hpp @@ -162,4 +162,8 @@ const int NUM_PRIEST_SPELLS = 62; const int UI_LAYER_DEFAULT = 1000; const int UI_LAYER_MENUBAR = 1200; +// Offset at which talk_gworld rendering target is drawn in mainPtr. +const int talk_gword_offset_x = 19; +const int talk_gword_offset_y = 7; + #endif diff --git a/src/game/boe.dlgutil.cpp b/src/game/boe.dlgutil.cpp index 0eb630c9..43e3fdc8 100644 --- a/src/game/boe.dlgutil.cpp +++ b/src/game/boe.dlgutil.cpp @@ -16,6 +16,7 @@ #include "boe.townspec.hpp" #include "boe.main.hpp" #include "boe.items.hpp" +#include "boe.consts.hpp" #include "sounds.hpp" #include #include "boe.newgraph.hpp" @@ -216,22 +217,28 @@ void handle_shop_event(location p) { end_shop_mode(); return; } - - p.x -= 5; - p.y -= 5; - + for(short i = 0; i < 8; i++) { unsigned long what_picked = shop_array[i + shop_sbar->getPosition()]; if(what_picked >= active_shop.size()) break; if(active_shop.getItem(what_picked).type == eShopItemType::EMPTY) break; - if(p.in(shopping_rects[i][SHOPRECT_ACTIVE_AREA])) { - click_shop_rect(shopping_rects[i][SHOPRECT_ACTIVE_AREA]); + + // Since shop UI was drawn into the game window with offsets, we need to apply + // the same offsets to event catching areas. + rectangle active_rect { shopping_rects[i][SHOPRECT_ACTIVE_AREA] }; + active_rect.offset(talk_gword_offset_x, talk_gword_offset_y); + + rectangle item_help_rect { shopping_rects[i][SHOPRECT_ITEM_HELP] }; + item_help_rect.offset(talk_gword_offset_x, talk_gword_offset_y); + + if(p.in(active_rect)) { + play_sound(37, time_in_ticks(5)); handle_sale(active_shop.getItem(what_picked), what_picked); set_up_shop_array(); draw_shop_graphics(false, {}); - } else if(p.in(shopping_rects[i][SHOPRECT_ITEM_HELP])){ - click_shop_rect(shopping_rects[i][SHOPRECT_ITEM_HELP]); + } else if(p.in(item_help_rect)){ + play_sound(37, time_in_ticks(5)); handle_info_request(active_shop.getItem(what_picked)); } } diff --git a/src/game/boe.newgraph.cpp b/src/game/boe.newgraph.cpp index bc688799..66dfb90b 100644 --- a/src/game/boe.newgraph.cpp +++ b/src/game/boe.newgraph.cpp @@ -13,6 +13,7 @@ #include "boe.fileio.hpp" #include "boe.locutils.hpp" #include "boe.text.hpp" +#include "boe.consts.hpp" #include "sounds.hpp" #include "mathutil.hpp" #include "render_image.hpp" @@ -592,15 +593,6 @@ void do_explosion_anim(short /*sound_num*/,short special_draw, short snd) { store_booms[i].boom_type = -1; } -void click_shop_rect(rectangle area_rect) { - - draw_shop_graphics(1,area_rect); - mainPtr.display(); - play_sound(37, time_in_ticks(5)); - draw_shop_graphics(0,area_rect); - -} - graf_pos calc_item_rect(int num,rectangle& to_rect) { if(num >= 1000) return spec_scen_g.find_graphic(num - 1000); rectangle from_rect = {0,0,18,18}; @@ -778,7 +770,6 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) { style.pointSize = 10; win_draw_string(talk_gworld,shopping_rects[i][SHOPRECT_ITEM_EXTRA],cur_info_str,eTextMode::WRAP,style); rect_draw_some_item(invenbtn_gworld,item_info_from,talk_gworld,shopping_rects[i][SHOPRECT_ITEM_HELP],pressed ? sf::BlendNone : sf::BlendAlpha); - } // Finally, cost info and help strs @@ -804,9 +795,8 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) { void refresh_shopping() { rectangle from_rect(talk_gworld); rectangle to_rect = from_rect; - to_rect.offset(19,7); + to_rect.offset(talk_gword_offset_x, talk_gword_offset_y); rect_draw_some_item(talk_gworld.getTexture(),from_rect,mainPtr,to_rect); - shop_sbar->draw(); } static void place_talk_face() { diff --git a/src/game/boe.newgraph.hpp b/src/game/boe.newgraph.hpp index 970ac17d..31d57fa9 100644 --- a/src/game/boe.newgraph.hpp +++ b/src/game/boe.newgraph.hpp @@ -56,7 +56,6 @@ void add_missile(location dest,miss_num_t missile_type,short path_type,short x_a void add_explosion(location dest,short val_to_place,short place_type,short boom_type,short x_adj,short y_adj); void do_missile_anim(short num_steps,location missile_origin,short sound_num) ; void do_explosion_anim(short sound_num,short expand,short snd = -1); -void click_shop_rect(rectangle area_rect); void draw_shop_graphics(bool pressed,rectangle clip_area_rect); void refresh_shopping(); std::string get_item_interesting_string(cItem item);