1 #include "special_events.h"
2 
3 #include "graphics/button.h"
4 #include "graphics/generic_button.h"
5 #include "graphics/graphics.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 "scenario/editor_events.h"
13 #include "scenario/property.h"
14 #include "window/editor/attributes.h"
15 #include "window/editor/map.h"
16 #include "window/numeric_input.h"
17 
18 static void button_earthquake_severity(int param1, int param2);
19 static void button_earthquake_year(int param1, int param2);
20 static void button_gladiator_toggle(int param1, int param2);
21 static void button_gladiator_year(int param1, int param2);
22 static void button_emperor_toggle(int param1, int param2);
23 static void button_emperor_year(int param1, int param2);
24 static void button_sea_trade_toggle(int param1, int param2);
25 static void button_land_trade_toggle(int param1, int param2);
26 static void button_raise_wages_toggle(int param1, int param2);
27 static void button_lower_wages_toggle(int param1, int param2);
28 static void button_contamination_toggle(int param1, int param2);
29 static void button_iron_mine_toggle(int param1, int param2);
30 static void button_clay_pit_toggle(int param1, int param2);
31 
32 static generic_button buttons[] = {
33     {216, 106, 100, 24, button_earthquake_severity, button_none},
34     {326, 106, 150, 24, button_earthquake_year, button_none},
35     {216, 136, 100, 24, button_gladiator_toggle,button_none},
36     {326, 136, 150, 24, button_gladiator_year,button_none},
37     {216, 166, 100, 24, button_emperor_toggle,button_none},
38     {326, 166, 150, 24, button_emperor_year, button_none},
39     {216, 196, 100, 24, button_sea_trade_toggle, button_none},
40     {216, 226, 100, 24, button_land_trade_toggle, button_none},
41     {216, 256, 100, 24, button_raise_wages_toggle, button_none},
42     {216, 286, 100, 24, button_lower_wages_toggle, button_none},
43     {216, 316, 100, 24, button_contamination_toggle, button_none},
44     {216, 346, 100, 24, button_iron_mine_toggle, button_none},
45     {216, 376, 100, 24, button_clay_pit_toggle, button_none},
46 };
47 
48 static int focus_button_id;
49 
draw_background(void)50 static void draw_background(void)
51 {
52     window_editor_map_draw_all();
53 }
54 
draw_foreground(void)55 static void draw_foreground(void)
56 {
57     graphics_in_dialog();
58 
59     outer_panel_draw(16, 32, 30, 26);
60 
61     lang_text_draw(38, 0, 32, 48, FONT_LARGE_BLACK);
62     lang_text_draw_centered(13, 3, 16, 424, 480, FONT_NORMAL_BLACK);
63 
64     // table header
65     lang_text_draw(38, 11, 236, 92, FONT_SMALL_PLAIN);
66     lang_text_draw(38, 12, 346, 92, FONT_SMALL_PLAIN);
67 
68     // earthquake
69     lang_text_draw(38, 1, 36, 112, FONT_NORMAL_BLACK);
70     button_border_draw(216, 106, 100, 24, focus_button_id == 1);
71     lang_text_draw_centered(40, scenario_editor_earthquake_severity(), 216, 112, 100, FONT_NORMAL_BLACK);
72 
73     button_border_draw(326, 106, 150, 24, focus_button_id == 2);
74     int width = text_draw_number(scenario_editor_earthquake_year(), '+', " ", 346, 112, FONT_NORMAL_BLACK);
75     lang_text_draw_year(
76         scenario_property_start_year() + scenario_editor_earthquake_year(),
77         356 + width, 112, FONT_NORMAL_BLACK);
78 
79     // gladiator revolt
80     lang_text_draw(38, 2, 36, 142, FONT_NORMAL_BLACK);
81     button_border_draw(216, 136, 100, 24, focus_button_id == 3);
82     lang_text_draw_centered(18, scenario_editor_gladiator_revolt_enabled(), 216, 142, 100, FONT_NORMAL_BLACK);
83 
84     button_border_draw(326, 136, 150, 24, focus_button_id == 4);
85     width = text_draw_number(scenario_editor_gladiator_revolt_year(), '+', " ", 346, 142, FONT_NORMAL_BLACK);
86     lang_text_draw_year(
87         scenario_property_start_year() + scenario_editor_gladiator_revolt_year(),
88         356 + width, 142, FONT_NORMAL_BLACK);
89 
90     // emperor change
91     lang_text_draw(38, 3, 36, 172, FONT_NORMAL_BLACK);
92     button_border_draw(216, 166, 100, 24, focus_button_id == 5);
93     lang_text_draw_centered(18, scenario_editor_emperor_change_enabled(), 216, 172, 100, FONT_NORMAL_BLACK);
94 
95     button_border_draw(326, 166, 150, 24, focus_button_id == 6);
96     width = text_draw_number(scenario_editor_emperor_change_year(), '+', " ", 346, 172, FONT_NORMAL_BLACK);
97     lang_text_draw_year(
98         scenario_property_start_year() + scenario_editor_emperor_change_year(),
99         356 + width, 172, FONT_NORMAL_BLACK);
100 
101     // random events
102     lang_text_draw(38, 4, 36, 202, FONT_NORMAL_BLACK);
103     button_border_draw(216, 196, 100, 24, focus_button_id == 7);
104     lang_text_draw_centered(18, scenario_editor_sea_trade_problem_enabled(), 216, 202, 100, FONT_NORMAL_BLACK);
105     lang_text_draw(38, 13, 346, 204, FONT_SMALL_PLAIN);
106 
107     lang_text_draw(38, 5, 36, 232, FONT_NORMAL_BLACK);
108     button_border_draw(216, 226, 100, 24, focus_button_id == 8);
109     lang_text_draw_centered(18, scenario_editor_land_trade_problem_enabled(), 216, 232, 100, FONT_NORMAL_BLACK);
110     lang_text_draw(38, 13, 346, 234, FONT_SMALL_PLAIN);
111 
112     lang_text_draw(38, 6, 36, 262, FONT_NORMAL_BLACK);
113     button_border_draw(216, 256, 100, 24, focus_button_id == 9);
114     lang_text_draw_centered(18, scenario_editor_raise_wages_enabled(), 216, 262, 100, FONT_NORMAL_BLACK);
115     lang_text_draw(38, 13, 346, 264, FONT_SMALL_PLAIN);
116 
117     lang_text_draw(38, 7, 36, 292, FONT_NORMAL_BLACK);
118     button_border_draw(216, 286, 100, 24, focus_button_id == 10);
119     lang_text_draw_centered(18, scenario_editor_lower_wages_enabled(), 216, 292, 100, FONT_NORMAL_BLACK);
120     lang_text_draw(38, 13, 346, 294, FONT_SMALL_PLAIN);
121 
122     lang_text_draw(38, 8, 36, 322, FONT_NORMAL_BLACK);
123     button_border_draw(216, 316, 100, 24, focus_button_id == 11);
124     lang_text_draw_centered(18, scenario_editor_contaminated_water_enabled(), 216, 322, 100, FONT_NORMAL_BLACK);
125     lang_text_draw(38, 13, 346, 324, FONT_SMALL_PLAIN);
126 
127     lang_text_draw(38, 9, 36, 352, FONT_NORMAL_BLACK);
128     button_border_draw(216, 346, 100, 24, focus_button_id == 12);
129     lang_text_draw_centered(18, scenario_editor_iron_mine_collapse_enabled(), 216, 352, 100, FONT_NORMAL_BLACK);
130     lang_text_draw(38, 13, 346, 354, FONT_SMALL_PLAIN);
131 
132     lang_text_draw(38, 10, 36, 382, FONT_NORMAL_BLACK);
133     button_border_draw(216, 376, 100, 24, focus_button_id == 13);
134     lang_text_draw_centered(18, scenario_editor_clay_pit_flooded_enabled(), 216, 382, 100, FONT_NORMAL_BLACK);
135     lang_text_draw(38, 13, 346, 384, FONT_SMALL_PLAIN);
136 
137     graphics_reset_dialog();
138 }
139 
handle_input(const mouse * m,const hotkeys * h)140 static void handle_input(const mouse *m, const hotkeys *h)
141 {
142     if (generic_buttons_handle_mouse(mouse_in_dialog(m), 0, 0, buttons, 13, &focus_button_id)) {
143         return;
144     }
145     if (input_go_back_requested(m, h)) {
146         window_editor_attributes_show();
147     }
148 }
149 
button_earthquake_severity(int param1,int param2)150 static void button_earthquake_severity(int param1, int param2)
151 {
152     scenario_editor_earthquake_cycle_severity();
153     window_request_refresh();
154 }
155 
button_earthquake_year(int param1,int param2)156 static void button_earthquake_year(int param1, int param2)
157 {
158     window_numeric_input_show(screen_dialog_offset_x() + 190, screen_dialog_offset_y() + 100,
159                               3, 999, scenario_editor_earthquake_set_year);
160 }
161 
button_gladiator_toggle(int param1,int param2)162 static void button_gladiator_toggle(int param1, int param2)
163 {
164     scenario_editor_gladiator_revolt_toggle_enabled();
165     window_request_refresh();
166 }
167 
button_gladiator_year(int param1,int param2)168 static void button_gladiator_year(int param1, int param2)
169 {
170     window_numeric_input_show(screen_dialog_offset_x() + 190, screen_dialog_offset_y() + 100,
171                               3, 999, scenario_editor_gladiator_revolt_set_year);
172 }
173 
button_emperor_toggle(int param1,int param2)174 static void button_emperor_toggle(int param1, int param2)
175 {
176     scenario_editor_emperor_change_toggle_enabled();
177     window_request_refresh();
178 }
179 
button_emperor_year(int param1,int param2)180 static void button_emperor_year(int param1, int param2)
181 {
182     window_numeric_input_show(screen_dialog_offset_x() + 190, screen_dialog_offset_y() + 100,
183                               3, 999, scenario_editor_emperor_change_set_year);
184 }
185 
button_sea_trade_toggle(int param1,int param2)186 static void button_sea_trade_toggle(int param1, int param2)
187 {
188     scenario_editor_sea_trade_problem_toggle_enabled();
189     window_request_refresh();
190 }
191 
button_land_trade_toggle(int param1,int param2)192 static void button_land_trade_toggle(int param1, int param2)
193 {
194     scenario_editor_land_trade_problem_toggle_enabled();
195     window_request_refresh();
196 }
197 
button_raise_wages_toggle(int param1,int param2)198 static void button_raise_wages_toggle(int param1, int param2)
199 {
200     scenario_editor_raise_wages_toggle_enabled();
201     window_request_refresh();
202 }
203 
button_lower_wages_toggle(int param1,int param2)204 static void button_lower_wages_toggle(int param1, int param2)
205 {
206     scenario_editor_lower_wages_toggle_enabled();
207     window_request_refresh();
208 }
209 
button_contamination_toggle(int param1,int param2)210 static void button_contamination_toggle(int param1, int param2)
211 {
212     scenario_editor_contaminated_water_toggle_enabled();
213     window_request_refresh();
214 }
215 
button_iron_mine_toggle(int param1,int param2)216 static void button_iron_mine_toggle(int param1, int param2)
217 {
218     scenario_editor_iron_mine_collapse_toggle_enabled();
219     window_request_refresh();
220 }
221 
button_clay_pit_toggle(int param1,int param2)222 static void button_clay_pit_toggle(int param1, int param2)
223 {
224     scenario_editor_clay_pit_flooded_toggle_enabled();
225     window_request_refresh();
226 }
227 
window_editor_special_events_show(void)228 void window_editor_special_events_show(void)
229 {
230     window_type window = {
231         WINDOW_EDITOR_SPECIAL_EVENTS,
232         draw_background,
233         draw_foreground,
234         handle_input
235     };
236     window_show(&window);
237 }
238