Truncate alchemy ingredients if overlapping recipe cost

This commit is contained in:
2025-05-06 16:53:32 -05:00
parent 5ea7fcd145
commit 51e6da15e2
4 changed files with 24 additions and 3 deletions

View File

@@ -134,11 +134,14 @@ bool end_scenario = false;
// This is defined in pc.editors.cpp since the PC editor also uses it
extern void edit_stuff_done();
static void init_shopping_rects() {
extern std::vector<int> shop_array;
void init_shopping_rects(bool scrollbar) {
rectangle shop_base = {63,19,99,274};
std::fill(shopping_rects[0].begin(), shopping_rects[0].end(), shop_base);
// Define first row of rectangles for shop item UI
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_KEY].right = shopping_rects[0][SHOPRECT_GRAPHIC].left;
@@ -155,12 +158,26 @@ static void init_shopping_rects() {
shopping_rects[0][SHOPRECT_ITEM_HELP].right -= 19;
shopping_rects[0][SHOPRECT_ITEM_HELP].left = shopping_rects[0][SHOPRECT_ITEM_HELP].right - 14;
// Define rectangles for the next 7 rows by copying and offsetting
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);
}
}
TextStyle style;
style.font = FONT_BOLD;
style.pointSize = 12;
style.lineHeight = 12;
for(short i = 0; i < 8; i++) {
// Truncate item descriptions so the text doesn't clash with the cost number
size_t current_pos = i + shop_sbar->getPosition();
if(current_pos >= shop_array.size() || shop_array[current_pos] < 0)
break; // theoretically, the second condition shouldn't happen
cShopItem item = active_shop.getItem(shop_array[current_pos]);
std::string cur_cost = std::to_string(item.getCost(active_shop.getCostAdjust()));
shopping_rects[i][SHOPRECT_ITEM_EXTRA].right = shopping_rects[i][SHOPRECT_ITEM_COST].right - string_length(cur_cost, style);
}
}
void init_inven_rects() {

View File

@@ -14,6 +14,7 @@ struct key_action_t {
void (*action)();
};
void init_shopping_rects(bool scrollbar);
void init_inven_rects();
void init_screen_locs();
location mouse_window_coords();

View File

@@ -106,6 +106,7 @@ short active_shop_num;
short store_cur_pc = -1;
extern void init_inven_rects();
extern void init_shopping_rects(bool scrollbar);
// For healing shops, other PCs might be able to buy something if
// the active PC can't
@@ -184,6 +185,7 @@ bool start_shop_mode(short which,short cost_adj,std::string store_name, bool can
put_background();
init_shopping_rects(shop_sbar->getMaximum() > 0);
draw_shop_graphics(false,false,area_rect);
put_item_screen(stat_window);

View File

@@ -820,7 +820,7 @@ void draw_shop_graphics(bool item_pressed, bool item_help_pressed, rectangle cli
const cAlchemy& info = *(eAlchemy(base_item.item_level));
cur_info_str = get_str("item-abilities", int(info.ingred1) + 1);
if(info.ingred2 != eItemAbil::NONE) {
cur_info_str += " and " + get_str("item-abilities", int(info.ingred2) + 1);
cur_info_str += " & " + get_str("item-abilities", int(info.ingred2) + 1);
}
} break;
case eShopItemType::MAGE_SPELL:
@@ -862,7 +862,8 @@ void draw_shop_graphics(bool item_pressed, bool item_help_pressed, rectangle cli
cost_rect.height() = 7;
rect_draw_some_item(invenbtn_gworld, {0, 29, 7, 36}, talk_gworld(), cost_rect, sf::BlendAlpha);
style.pointSize = 10;
win_draw_string(talk_gworld(),shopping_rects[i][SHOPRECT_ITEM_EXTRA],cur_info_str,eTextMode::WRAP,style);
// Alchemy ingredients often don't fit
win_draw_string(talk_gworld(),shopping_rects[i][SHOPRECT_ITEM_EXTRA],cur_info_str,eTextMode::ELLIPSIS,style);
rect_draw_some_item(invenbtn_gworld,item_info_from,talk_gworld(),shopping_rects[i][SHOPRECT_ITEM_HELP],item_help_pressed ? sf::BlendNone : sf::BlendAlpha);
}