68
68
#include < functional>
69
69
#include < utility>
70
70
71
- static void button_help (int param1, int param2);
72
- static void button_close (int param1, int param2);
73
- static void button_advisor (int advisor, int param2);
74
-
75
71
object_info g_building_info_context;
76
72
77
- struct building_info_data {
78
- int image_button_id = 0 ;
79
-
80
- struct {
81
- image_button l_advisor_b = {65 , 0 , 28 , 28 , IB_NORMAL, GROUP_MESSAGE_ADVISOR_BUTTONS, 9 , button_advisor, button_none, ADVISOR_RATINGS, 0 , 1 };
82
- } buttons;
83
-
84
- image_button image_buttons_help_close[2 ] = {
85
- {14 , 0 , 27 , 27 , IB_NORMAL, GROUP_CONTEXT_ICONS, 0 , button_help, button_none, 0 , 0 , 1 },
86
- {424 , 3 , 24 , 24 , IB_NORMAL, GROUP_CONTEXT_ICONS, 4 , button_close, button_none, 0 , 0 , 1 }
87
- };
88
- };
89
-
90
- building_info_data g_building_info;
91
-
92
73
static int get_height_id () {
93
74
auto &context = g_building_info_context;
94
75
if (context.type == BUILDING_INFO_TERRAIN) {
@@ -194,16 +175,7 @@ static int get_height_id() {
194
175
static void get_tooltip (tooltip_context* c) {
195
176
auto &context = g_building_info_context;
196
177
std::pair<int , int > tooltip;
197
- if (g_building_info.image_button_id ) {
198
- tooltip.second = g_building_info.image_button_id ;
199
-
200
- // } else if (g_building_info.generic_button_id) {
201
- ;
202
-
203
- // } else if (g_building_info.debug_path_button_id) {
204
- ;
205
-
206
- } else if (context.type == BUILDING_INFO_LEGION) {
178
+ if (context.type == BUILDING_INFO_LEGION) {
207
179
tooltip.second = window_building_get_legion_info_tooltip_text (&context);
208
180
209
181
} else if (context.type == BUILDING_INFO_BUILDING && context.storage_show_special_orders ) {
@@ -725,7 +697,6 @@ static void draw_background() {
725
697
static void draw_foreground () {
726
698
ui::begin_window (g_building_info_context.offset );
727
699
auto &context = g_building_info_context;
728
- auto &data = g_building_info;
729
700
730
701
// building-specific buttons
731
702
building *b = nullptr ;
@@ -774,32 +745,52 @@ static void draw_foreground() {
774
745
}
775
746
776
747
// general buttons
777
- if (context.storage_show_special_orders ) {
778
- image_buttons_draw (vec2i (context.offset .x , context.y_offset_submenu + 16 * context.height_blocks_submenu - 40 ), g_building_info.image_buttons_help_close );
779
- } else {
780
- image_buttons_draw (context.offset + vec2i (0 , 16 * context.height_blocks - 40 ), g_building_info.image_buttons_help_close );
781
- }
748
+ int y_offset = (context.storage_show_special_orders ) ? context.y_offset_submenu : 0 ;
749
+ int height_blocks = (context.storage_show_special_orders ) ? context.height_blocks_submenu : context.height_blocks ;
750
+
751
+ ui::img_button (GROUP_CONTEXT_ICONS, vec2i (14 , y_offset + 16 * height_blocks - 40 ), {28 , 28 }, 0 )
752
+ .onclick ([&context] (int , int ) {
753
+ if (context.help_id > 0 ) {
754
+ window_message_dialog_show (context.help_id , -1 , window_city_draw_all);
755
+ } else {
756
+ window_message_dialog_show (MESSAGE_DIALOG_HELP, -1 , window_city_draw_all);
757
+ }
758
+ window_invalidate ();
759
+ });
760
+
761
+ ui::img_button (GROUP_CONTEXT_ICONS, vec2i (16 * context.width_blocks - 40 , y_offset + 16 * height_blocks - 40 ), {28 , 28 }, 4 )
762
+ .onclick ([&context] (int , int ) {
763
+ if (context.storage_show_special_orders ) {
764
+ context.storage_show_special_orders = 0 ;
765
+ storage_settings_backup_reset ();
766
+ window_invalidate ();
767
+ } else {
768
+ window_city_show ();
769
+ }
770
+ });
782
771
783
772
if (context.go_to_advisor .first ) {
784
773
int img_offset = (context.go_to_advisor .left_a - 1 ) * 3 ;
785
774
ui::img_button (GROUP_MESSAGE_ADVISOR_BUTTONS, vec2i (40 , 16 * context.height_blocks - 40 ), {28 , 28 }, img_offset)
786
- .onclick ([&context] (int , int ) {
787
- window_advisors_show_advisor (context.go_to_advisor .first );
788
- });
775
+ .onclick ([&context] (int , int ) {
776
+ window_advisors_show_advisor (context.go_to_advisor .first );
777
+ });
789
778
}
790
779
791
780
if (context.go_to_advisor .left_a ) {
792
781
int img_offset = (context.go_to_advisor .left_a - 1 ) * 3 ;
793
782
ui::img_button (GROUP_MESSAGE_ADVISOR_BUTTONS, vec2i (40 , 16 * context.height_blocks - 40 ), {28 , 28 }, img_offset)
794
- .onclick ([&context] (int , int ) {
795
- window_advisors_show_advisor (context.go_to_advisor .left_a );
796
- });
783
+ .onclick ([&context] (int , int ) {
784
+ window_advisors_show_advisor (context.go_to_advisor .left_a );
785
+ });
797
786
}
798
787
799
788
if (context.go_to_advisor .left_b ) {
800
- g_building_info.buttons .l_advisor_b .parameter1 = context.go_to_advisor .left_b ;
801
- g_building_info.buttons .l_advisor_b .image_offset = (context.go_to_advisor .left_b - 1 ) * 3 ;
802
- image_buttons_draw (context.offset + vec2i (0 , 16 * context.height_blocks - 40 ), g_building_info.buttons .l_advisor_b );
789
+ int img_offset = (context.go_to_advisor .left_b - 1 ) * 3 ;
790
+ ui::img_button (GROUP_MESSAGE_ADVISOR_BUTTONS, vec2i (65 , 16 * context.height_blocks - 40 ), {28 , 28 }, img_offset)
791
+ .onclick ([&context] (int , int ) {
792
+ window_advisors_show_advisor (context.go_to_advisor .left_b );
793
+ });
803
794
}
804
795
805
796
if (b) {
@@ -808,24 +799,24 @@ static void draw_foreground() {
808
799
pcstr label = (b->state == BUILDING_STATE_VALID ? " x" : " " );
809
800
auto tooltip = (b->state == BUILDING_STATE_VALID) ? std::pair{54 , 8 } : std::pair{53 , 10 };
810
801
ui::button (label, {400 , 3 + 16 * context.height_blocks - 40 }, {20 , 20 })
811
- .onclick ([&context, b, workers_needed] (int , int ) {
812
- if (workers_needed) {
813
- building_mothball_toggle (b);
814
- window_invalidate ();
815
- }
816
- })
817
- .tooltip (tooltip);
802
+ .onclick ([&context, b, workers_needed] (int , int ) {
803
+ if (workers_needed) {
804
+ building_mothball_toggle (b);
805
+ window_invalidate ();
806
+ }
807
+ })
808
+ .tooltip (tooltip);
818
809
}
819
810
}
820
811
821
812
if (context.figure .draw_debug_path ) {
822
813
figure* f = figure_get (context.figure .figure_ids [0 ]);
823
814
pcstr label = (f->draw_debug_mode ? " P" : " p" );
824
815
ui::button (label, {400 , 3 + 16 * context.height_blocks - 40 }, {20 , 20 })
825
- .onclick ([&context, f] (int , int ) {
826
- f->draw_debug_mode = f->draw_debug_mode ? 0 :FIGURE_DRAW_DEBUG_ROUTING;
827
- window_invalidate ();
828
- });
816
+ .onclick ([&context, f] (int , int ) {
817
+ f->draw_debug_mode = f->draw_debug_mode ? 0 :FIGURE_DRAW_DEBUG_ROUTING;
818
+ window_invalidate ();
819
+ });
829
820
}
830
821
831
822
if (context.show_overlay != OVERLAY_NONE) {
@@ -904,29 +895,13 @@ static int handle_specific_building_info_mouse(const mouse *m) {
904
895
905
896
static void handle_input (const mouse* m, const hotkeys* h) {
906
897
auto &context = g_building_info_context;
907
- auto &data = g_building_info;
908
-
909
- bool button_id = 0 ;
910
- int tmp_btn_id;
911
- // general buttons
912
- if (context.storage_show_special_orders ) {
913
- button_id |= image_buttons_handle_mouse (m, vec2i (context.offset .x , context.y_offset_submenu + 16 * context.height_blocks_submenu - 40 ),
914
- g_building_info.image_buttons_help_close , g_building_info.image_button_id );
915
- } else {
916
- button_id |= image_buttons_handle_mouse (m, context.offset + vec2i (0 , 16 * context.height_blocks - 40 ),
917
- g_building_info.image_buttons_help_close , g_building_info.image_button_id );
918
- }
919
-
920
- if (context.go_to_advisor .left_b ) {
921
- button_id |= image_buttons_handle_mouse (m, context.offset + vec2i (0 , 16 * context.height_blocks - 40 ), g_building_info.buttons .l_advisor_b , tmp_btn_id);
922
- }
923
898
899
+ bool button_id = ui::handle_mouse (m);
900
+
924
901
if (!button_id) {
925
902
button_id |= !!handle_specific_building_info_mouse (m);
926
903
}
927
904
928
- button_id |= ui::handle_mouse (m);
929
-
930
905
if (!button_id && input_go_back_requested (m, h)) {
931
906
if (context.storage_show_special_orders ) {
932
907
storage_settings_backup_check ();
@@ -936,31 +911,6 @@ static void handle_input(const mouse* m, const hotkeys* h) {
936
911
}
937
912
}
938
913
939
- static void button_help (int param1, int param2) {
940
- auto &context = g_building_info_context;
941
- if (context.help_id > 0 ) {
942
- window_message_dialog_show (context.help_id , -1 , window_city_draw_all);
943
- } else {
944
- window_message_dialog_show (MESSAGE_DIALOG_HELP, -1 , window_city_draw_all);
945
- }
946
- window_invalidate ();
947
- }
948
-
949
- static void button_close (int param1, int param2) {
950
- auto &context = g_building_info_context;
951
- if (context.storage_show_special_orders ) {
952
- context.storage_show_special_orders = 0 ;
953
- storage_settings_backup_reset ();
954
- window_invalidate ();
955
- } else {
956
- window_city_show ();
957
- }
958
- }
959
-
960
- static void button_advisor (int advisor, int param2) {
961
- window_advisors_show_advisor ((e_advisor)advisor);
962
- }
963
-
964
914
void window_building_info_show (const map_point& point) {
965
915
window_type window = {
966
916
WINDOW_BUILDING_INFO,
0 commit comments