|
71 | 71 | static void button_help(int param1, int param2);
|
72 | 72 | static void button_close(int param1, int param2);
|
73 | 73 | static void button_advisor(int advisor, int param2);
|
74 |
| -static void button_mothball(int mothball, int param2); |
75 | 74 |
|
76 | 75 | object_info g_building_info_context;
|
77 | 76 |
|
78 | 77 | struct building_info_data {
|
79 | 78 | int image_button_id = 0;
|
80 |
| - int generic_button_id = 0; |
81 |
| - int debug_path_button_id = 0; |
82 |
| - |
83 |
| - generic_button generic_button_mothball[1] = { |
84 |
| - {400, 3, 24, 24, button_mothball, button_none, 0, 0} |
85 |
| - }; |
86 | 79 |
|
87 | 80 | struct {
|
88 | 81 | image_button advisor = {350, -38, 28, 28, IB_NORMAL, GROUP_MESSAGE_ADVISOR_BUTTONS, 9, button_advisor, button_none, ADVISOR_RATINGS, 0, 1};
|
@@ -202,42 +195,41 @@ static int get_height_id() {
|
202 | 195 |
|
203 | 196 | static void get_tooltip(tooltip_context* c) {
|
204 | 197 | auto &context = g_building_info_context;
|
205 |
| - int text_id = 0, group_id = 0; |
| 198 | + std::pair<int, int> tooltip; |
206 | 199 | if (g_building_info.image_button_id) {
|
207 |
| - text_id = g_building_info.image_button_id; |
| 200 | + tooltip.second = g_building_info.image_button_id; |
208 | 201 |
|
209 |
| - } else if (g_building_info.generic_button_id) { |
210 |
| - if (building_get(context.building_id)->state == BUILDING_STATE_VALID) { |
211 |
| - text_id = 8; |
212 |
| - group_id = 54; |
213 |
| - } else { |
214 |
| - text_id = 10; |
215 |
| - group_id = 54; |
216 |
| - } |
| 202 | + //} else if (g_building_info.generic_button_id) { |
| 203 | + ; |
217 | 204 |
|
218 |
| - } else if (g_building_info.debug_path_button_id) { |
| 205 | + //} else if (g_building_info.debug_path_button_id) { |
219 | 206 | ;
|
220 | 207 |
|
221 | 208 | } else if (context.type == BUILDING_INFO_LEGION) {
|
222 |
| - text_id = window_building_get_legion_info_tooltip_text(&context); |
| 209 | + tooltip.second = window_building_get_legion_info_tooltip_text(&context); |
223 | 210 |
|
224 | 211 | } else if (context.type == BUILDING_INFO_BUILDING && context.storage_show_special_orders) {
|
225 | 212 | switch (building_get(context.building_id)->type) {
|
226 | 213 | case BUILDING_GRANARY:
|
227 |
| - window_building_get_tooltip_granary_orders(&group_id, &text_id); |
| 214 | + window_building_get_tooltip_granary_orders(&tooltip.first, &tooltip.second); |
228 | 215 | break;
|
229 | 216 |
|
230 | 217 | case BUILDING_STORAGE_YARD:
|
231 |
| - window_building_get_tooltip_warehouse_orders(&group_id, &text_id); |
| 218 | + window_building_get_tooltip_warehouse_orders(&tooltip.first, &tooltip.second); |
232 | 219 | break;
|
233 | 220 | }
|
234 | 221 | }
|
235 | 222 |
|
236 |
| - if (text_id || group_id) { |
| 223 | + int button_id = ui::button_hover(mouse_get()); |
| 224 | + if (button_id > 0) { |
| 225 | + tooltip = ui::button(button_id - 1)._tooltip; |
| 226 | + } |
| 227 | + |
| 228 | + if (tooltip.first || tooltip.second) { |
237 | 229 | c->type = TOOLTIP_BUTTON;
|
238 |
| - c->text_id = text_id; |
239 |
| - if (group_id) { |
240 |
| - c->text_group = group_id; |
| 230 | + c->text_id = tooltip.second; |
| 231 | + if (tooltip.first) { |
| 232 | + c->text_group = tooltip.first; |
241 | 233 | }
|
242 | 234 | window_request_refresh_background();
|
243 | 235 | }
|
@@ -559,15 +551,6 @@ static void init(map_point tile) {
|
559 | 551 | }
|
560 | 552 | }
|
561 | 553 |
|
562 |
| -static void draw_mothball_button(int x, int y, int focused) { |
563 |
| - auto &context = g_building_info_context; |
564 |
| - button_border_draw(x, y, 20, 20, focused ? 1 : 0); |
565 |
| - building* b = building_get(context.building_id); |
566 |
| - if (b->state == BUILDING_STATE_VALID) { |
567 |
| - text_draw_centered((uint8_t*)"x", x + 1, y + 4, 20, FONT_NORMAL_BLACK_ON_LIGHT, 0); |
568 |
| - } |
569 |
| -} |
570 |
| - |
571 | 554 | static void draw_refresh_background() {
|
572 | 555 | auto &context = g_building_info_context;
|
573 | 556 | if (context.type == BUILDING_INFO_NONE) {
|
@@ -747,8 +730,9 @@ static void draw_foreground() {
|
747 | 730 | auto &data = g_building_info;
|
748 | 731 |
|
749 | 732 | // building-specific buttons
|
| 733 | + building *b = nullptr; |
750 | 734 | if (context.type == BUILDING_INFO_BUILDING) {
|
751 |
| - building *b = building_get(context.building_id); |
| 735 | + b = building_get(context.building_id); |
752 | 736 | switch (b->type) {
|
753 | 737 | case BUILDING_GRANARY:
|
754 | 738 | if (context.storage_show_special_orders) {
|
@@ -816,17 +800,26 @@ static void draw_foreground() {
|
816 | 800 | image_buttons_draw(context.offset + vec2i(0, 16 * context.height_blocks - 40), g_building_info.buttons.l_advisor_b);
|
817 | 801 | }
|
818 | 802 |
|
819 |
| - if (!context.storage_show_special_orders) { |
820 |
| - int workers_needed = model_get_building(building_get(context.building_id)->type)->laborers; |
| 803 | + if (b) { |
| 804 | + int workers_needed = model_get_building(b->type)->laborers; |
821 | 805 | if (workers_needed) {
|
822 |
| - draw_mothball_button(context.offset.x + 400, context.offset.y + 3 + 16 * context.height_blocks - 40, g_building_info.generic_button_id); |
| 806 | + pcstr label = (b->state == BUILDING_STATE_VALID ? "x" : ""); |
| 807 | + auto tooltip = (b->state == BUILDING_STATE_VALID) ? std::pair{54, 8} : std::pair{53, 10}; |
| 808 | + ui::button(label, {400, 3 + 16 * context.height_blocks - 40}, {20, 20}) |
| 809 | + .onclick([&context, b, workers_needed] (int, int) { |
| 810 | + if (workers_needed) { |
| 811 | + building_mothball_toggle(b); |
| 812 | + window_invalidate(); |
| 813 | + } |
| 814 | + }) |
| 815 | + .tooltip(tooltip); |
823 | 816 | }
|
824 | 817 | }
|
825 | 818 |
|
826 | 819 | if (context.figure.draw_debug_path) {
|
827 | 820 | figure* f = figure_get(context.figure.figure_ids[0]);
|
828 | 821 | pcstr label = (f->draw_debug_mode ? "P" : "p");
|
829 |
| - ui::button(label, {400, 3 + 16 * context.height_blocks - 40}, {24, 24}) |
| 822 | + ui::button(label, {400, 3 + 16 * context.height_blocks - 40}, {20, 20}) |
830 | 823 | .onclick([&context, f] (int, int) {
|
831 | 824 | f->draw_debug_mode = f->draw_debug_mode ? 0 :FIGURE_DRAW_DEBUG_ROUTING;
|
832 | 825 | window_invalidate();
|
@@ -920,8 +913,6 @@ static void handle_input(const mouse* m, const hotkeys* h) {
|
920 | 913 | } else {
|
921 | 914 | button_id |= image_buttons_handle_mouse(m, context.offset + vec2i(0, 16 * context.height_blocks - 40),
|
922 | 915 | g_building_info.image_buttons_help_close, g_building_info.image_button_id);
|
923 |
| - button_id |= generic_buttons_handle_mouse(m, context.offset + vec2i(0, 16 * context.height_blocks - 40), |
924 |
| - g_building_info.generic_button_mothball, g_building_info.generic_button_id); |
925 | 916 | }
|
926 | 917 |
|
927 | 918 | if (context.go_to_advisor.first) {
|
@@ -976,16 +967,6 @@ static void button_advisor(int advisor, int param2) {
|
976 | 967 | window_advisors_show_advisor((e_advisor)advisor);
|
977 | 968 | }
|
978 | 969 |
|
979 |
| -static void button_mothball(int mothball, int param2) { |
980 |
| - auto &context = g_building_info_context; |
981 |
| - building* b = building_get(context.building_id); |
982 |
| - int workers_needed = model_get_building(b->type)->laborers; |
983 |
| - if (workers_needed) { |
984 |
| - building_mothball_toggle(b); |
985 |
| - window_invalidate(); |
986 |
| - } |
987 |
| -} |
988 |
| - |
989 | 970 | void window_building_info_show(const map_point& point) {
|
990 | 971 | window_type window = {
|
991 | 972 | WINDOW_BUILDING_INFO,
|
|
0 commit comments