Skip to content

Commit 63b3b35

Browse files
committed
ui: show tooltip for trade prices window items
1 parent 5414e86 commit 63b3b35

File tree

2 files changed

+7
-24
lines changed

2 files changed

+7
-24
lines changed

src/scripts/ui.js

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ trade_prices_window = {
191191
title : text_center({pos:[0, 12], size:[px(56), 20], text:[54, 21], font : FONT_LARGE_BLACK_ON_LIGHT }),
192192

193193
items : dummy({pos:[156, 44]}),
194+
item_button : dummy({pos:[-7, -7], size:[38, 74]}),
194195

195196
buyers_pay1 : text({text:[54, 22], pos:[26, 72], font: FONT_NORMAL_BLACK_ON_LIGHT}),
196197
sellers_receive1 : text({text:[54, 23], pos:[26, 92], font:FONT_NORMAL_BLACK_ON_LIGHT}),

src/window/trade_prices.cpp

+6-24
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void trade_prices_window::ui_draw_foreground() {
5555

5656
vec2i items_pos = ui["items"].pos;
5757
vec2i current_pos = items_pos;
58+
const auto &item_button = ui["item_button"];
5859
int start_i = 0;
5960
for (int i = 1; (start_i + i) < RESOURCES_MAX; i++) {
6061
int image_offset = i;
@@ -71,6 +72,10 @@ void trade_prices_window::ui_draw_foreground() {
7172
}
7273

7374
ui.icon(current_pos, resource);
75+
const auto &btn = ui.button("", current_pos + item_button.pos, item_button.size, fonts_vec{}, UiFlags_NoBody);
76+
if (btn.hovered) {
77+
ui::set_tooltip((pcstr)lang_get_string(23, resource));
78+
}
7479

7580
const int buy_price = trade_price_buy(i);
7681
const int sell_price = trade_price_sell(i);
@@ -93,36 +98,13 @@ int trade_prices_window::ui_handle_mouse(const mouse *m) {
9398
return autoconfig_window::ui_handle_mouse(m);
9499
}
95100

96-
static int get_tooltip_resource(tooltip_context* c) {
97-
int x_base = screen_dialog_offset_x() + 124;
98-
int y = screen_dialog_offset_y() + 192;
99-
int x_mouse = c->mpos.x;
100-
int y_mouse = c->mpos.y;
101-
102-
for (int i = 1; i < 16; i++) {
103-
int x = x_base + 30 * i;
104-
if (x <= x_mouse && x + 24 > x_mouse && y <= y_mouse && y + 24 > y_mouse)
105-
return i;
106-
}
107-
return 0;
108-
}
109-
110-
static void get_tooltip(tooltip_context* c) {
111-
int resource = get_tooltip_resource(c);
112-
if (!resource) {
113-
return;
114-
}
115-
116-
c->text = (pcstr)lang_get_string(0, 131 + resource);
117-
}
118-
119101
void window_trade_prices_show(void) {
120102
static window_type window = {
121103
WINDOW_TRADE_PRICES,
122104
[] { trade_prices_w.draw_background(); },
123105
[] { trade_prices_w.ui_draw_foreground(); },
124106
[] (const mouse *m, const hotkeys *h) { trade_prices_w.ui_handle_mouse(m); },
125-
nullptr
107+
[] (tooltip_context *) { trade_prices_w.get_tooltip_text(); }
126108
};
127109

128110
window_show(&window);

0 commit comments

Comments
 (0)