1 #include "trade_prices.h"
2 
3 #include "empire/trade_prices.h"
4 #include "graphics/graphics.h"
5 #include "graphics/image.h"
6 #include "graphics/lang_text.h"
7 #include "graphics/panel.h"
8 #include "graphics/screen.h"
9 #include "graphics/text.h"
10 #include "graphics/window.h"
11 #include "input/input.h"
12 #include "window/advisors.h"
13 
draw_background(void)14 static void draw_background(void)
15 {
16     window_draw_underlying_window();
17 
18     graphics_in_dialog();
19 
20     graphics_shade_rect(33, 53, 574, 334, 0);
21     outer_panel_draw(16, 144, 38, 11);
22     lang_text_draw(54, 21, 26, 153, FONT_LARGE_BLACK);
23     lang_text_draw(54, 22, 26, 228, FONT_NORMAL_BLACK);
24     lang_text_draw(54, 23, 26, 253, FONT_NORMAL_BLACK);
25     for (int i = RESOURCE_MIN; i < RESOURCE_MAX; i++) {
26         int image_offset = i + resource_image_offset(i, RESOURCE_IMAGE_ICON);
27         image_draw(image_group(GROUP_RESOURCE_ICONS) + image_offset, 126 + 30 * i, 194);
28         text_draw_number_centered(trade_price_buy(i), 120 + 30 * i, 229, 30, FONT_SMALL_PLAIN);
29         text_draw_number_centered(trade_price_sell(i), 120 + 30 * i, 254, 30, FONT_SMALL_PLAIN);
30     }
31     lang_text_draw_centered(13, 1, 16, 296, 608, FONT_NORMAL_BLACK);
32 
33     graphics_reset_dialog();
34 }
35 
handle_input(const mouse * m,const hotkeys * h)36 static void handle_input(const mouse *m, const hotkeys *h)
37 {
38     if (input_go_back_requested(m, h)) {
39         window_advisors_show();
40     }
41 }
42 
get_tooltip_resource(tooltip_context * c)43 static int get_tooltip_resource(tooltip_context *c)
44 {
45     int x_base = screen_dialog_offset_x() + 124;
46     int y = screen_dialog_offset_y() + 192;
47     int x_mouse = c->mouse_x;
48     int y_mouse = c->mouse_y;
49 
50     for (int i = RESOURCE_MIN; i < RESOURCE_MAX; i++) {
51         int x = x_base + 30 * i;
52         if (x <= x_mouse && x + 24 > x_mouse && y <= y_mouse && y + 24 > y_mouse) {
53             return i;
54         }
55     }
56     return 0;
57 }
58 
get_tooltip(tooltip_context * c)59 static void get_tooltip(tooltip_context *c)
60 {
61     int resource = get_tooltip_resource(c);
62     if (!resource) {
63         return;
64     }
65     c->type = TOOLTIP_BUTTON;
66     c->text_id = 131 + resource;
67 }
68 
window_trade_prices_show(void)69 void window_trade_prices_show(void)
70 {
71     window_type window = {
72         WINDOW_TRADE_PRICES,
73         draw_background,
74         0,
75         handle_input,
76         get_tooltip
77     };
78     window_show(&window);
79 }
80