|
11 | 11 | #include "graphics/window.h"
|
12 | 12 | #include "input/input.h"
|
13 | 13 | #include "window/advisors.h"
|
| 14 | +#include "window/autoconfig_window.h" |
14 | 15 | #include "io/gamefiles/lang.h"
|
15 | 16 | #include "game/game.h"
|
16 | 17 |
|
17 |
| -static void draw_background() { |
| 18 | +struct trade_prices_window : autoconfig_window_t<trade_prices_window> { |
| 19 | + virtual int handle_mouse(const mouse *m) override { return 0; } |
| 20 | + virtual int get_tooltip_text() override { return 0; } |
| 21 | + virtual void draw_foreground() override {} |
| 22 | + virtual int draw_background() override; |
| 23 | + virtual void ui_draw_foreground() override; |
| 24 | + virtual int ui_handle_mouse(const mouse *m) override; |
| 25 | + virtual void init() {} |
| 26 | + |
| 27 | + virtual void load(archive arch, pcstr section) override { |
| 28 | + autoconfig_window::load(arch, section); |
| 29 | + |
| 30 | + next_row_offset = arch.r_vec2i("next_row_offset"); |
| 31 | + next_item_offset = arch.r_vec2i("next_item_offset"); |
| 32 | + receive_offset = arch.r_vec2i("receive_offset"); |
| 33 | + buyer_offset = arch.r_vec2i("buyer_offset"); |
| 34 | + next = arch.r_int("next"); |
| 35 | + } |
| 36 | + |
| 37 | + vec2i next_row_offset; |
| 38 | + vec2i next_item_offset; |
| 39 | + vec2i receive_offset; |
| 40 | + vec2i buyer_offset; |
| 41 | + int next; |
| 42 | +}; |
| 43 | + |
| 44 | +trade_prices_window trade_prices_w; |
| 45 | + |
| 46 | +int trade_prices_window::draw_background() { |
18 | 47 | window_draw_underlying_window();
|
19 | 48 |
|
20 |
| - graphics_set_to_dialog(); |
| 49 | + return 0; |
| 50 | +} |
| 51 | + |
| 52 | +void trade_prices_window::ui_draw_foreground() { |
| 53 | + ui.begin_widget(ui.pos); |
| 54 | + ui.draw(); |
21 | 55 |
|
22 |
| - graphics_shade_rect(vec2i{33, 53}, vec2i{574, 334}, 0x80); |
23 |
| - outer_panel_draw(vec2i{16, 144}, 38, 11); |
24 |
| - lang_text_draw(54, 21, 26, 153, FONT_LARGE_BLACK_ON_LIGHT); |
25 |
| - lang_text_draw(54, 22, 26, 228, FONT_NORMAL_BLACK_ON_LIGHT); |
26 |
| - lang_text_draw(54, 23, 26, 253, FONT_NORMAL_BLACK_ON_LIGHT); |
| 56 | + vec2i items_pos = ui["items"].pos; |
| 57 | + vec2i current_pos = items_pos; |
| 58 | + int start_i = 0; |
| 59 | + for (int i = 1; (start_i + i) < RESOURCES_MAX; i++) { |
| 60 | + int image_offset = i; |
| 61 | + if (i >= next) { |
| 62 | + start_i += next; |
| 63 | + i = 0; |
| 64 | + items_pos += next_row_offset; |
| 65 | + current_pos = items_pos; |
| 66 | + } |
27 | 67 |
|
28 |
| - painter ctx = game.painter(); |
29 |
| - for (int i = 1; i < 16; i++) { |
30 |
| - int image_offset = i + resource_image_offset(i, RESOURCE_IMAGE_ICON); |
31 |
| - ImageDraw::img_generic(ctx, image_id_resource_icon(image_offset), vec2i{126 + 30 * i, 194}); |
32 |
| - text_draw_number_centered(trade_price_buy(i), 120 + 30 * i, 229, 30, FONT_SMALL_OUTLINED); |
33 |
| - text_draw_number_centered(trade_price_sell(i), 120 + 30 * i, 254, 30, FONT_SMALL_OUTLINED); |
| 68 | + e_resource resource = e_resource(start_i + i); |
| 69 | + if (resource == RESOURCE_UNUSED12) { |
| 70 | + continue; |
| 71 | + } |
| 72 | + |
| 73 | + ui.icon(current_pos, resource); |
| 74 | + |
| 75 | + const int buy_price = trade_price_buy(i); |
| 76 | + const int sell_price = trade_price_sell(i); |
| 77 | + ui.label(bstring32(buy_price), current_pos + buyer_offset , FONT_NORMAL_BLACK_ON_LIGHT); |
| 78 | + ui.label(bstring32(sell_price), current_pos + receive_offset, FONT_NORMAL_BLACK_ON_LIGHT); |
| 79 | + |
| 80 | + current_pos += next_item_offset; |
34 | 81 | }
|
35 |
| - lang_text_draw_centered(13, 1, 16, 296, 608, FONT_NORMAL_BLACK_ON_LIGHT); |
36 | 82 |
|
37 |
| - graphics_reset_dialog(); |
| 83 | + ui.end_widget(); |
38 | 84 | }
|
39 | 85 |
|
40 |
| -static void handle_input(const mouse* m, const hotkeys* h) { |
41 |
| - if (input_go_back_requested(m, h)) |
| 86 | +int trade_prices_window::ui_handle_mouse(const mouse *m) { |
| 87 | + const hotkeys *h = hotkey_state(); |
| 88 | + if (input_go_back_requested(m, h)) { |
42 | 89 | window_advisors_show();
|
| 90 | + return 0; |
| 91 | + } |
| 92 | + |
| 93 | + return autoconfig_window::ui_handle_mouse(m); |
43 | 94 | }
|
44 | 95 |
|
45 | 96 | static int get_tooltip_resource(tooltip_context* c) {
|
@@ -68,10 +119,11 @@ static void get_tooltip(tooltip_context* c) {
|
68 | 119 | void window_trade_prices_show(void) {
|
69 | 120 | static window_type window = {
|
70 | 121 | WINDOW_TRADE_PRICES,
|
71 |
| - draw_background, |
72 |
| - 0, |
73 |
| - handle_input, |
74 |
| - get_tooltip |
| 122 | + [] { trade_prices_w.draw_background(); }, |
| 123 | + [] { trade_prices_w.ui_draw_foreground(); }, |
| 124 | + [] (const mouse *m, const hotkeys *h) { trade_prices_w.ui_handle_mouse(m); }, |
| 125 | + nullptr |
75 | 126 | };
|
| 127 | + |
76 | 128 | window_show(&window);
|
77 | 129 | }
|
0 commit comments