1 #include "mission_briefing.h"
2 
3 #include "city/mission.h"
4 #include "core/image_group.h"
5 #include "core/lang.h"
6 #include "game/file.h"
7 #include "game/mission.h"
8 #include "game/tutorial.h"
9 #include "graphics/graphics.h"
10 #include "graphics/image_button.h"
11 #include "graphics/lang_text.h"
12 #include "graphics/panel.h"
13 #include "graphics/rich_text.h"
14 #include "graphics/text.h"
15 #include "graphics/window.h"
16 #include "scenario/criteria.h"
17 #include "scenario/property.h"
18 #include "sound/music.h"
19 #include "sound/speech.h"
20 #include "window/city.h"
21 #include "window/intermezzo.h"
22 #include "window/mission_selection.h"
23 
24 static void button_back(int param1, int param2);
25 static void button_start_mission(int param1, int param2);
26 
27 static const int GOAL_OFFSETS_X[] = {32, 288, 32, 288, 288, 288};
28 static const int GOAL_OFFSETS_Y[] = {95, 95, 117, 117, 73, 135};
29 
30 static image_button image_button_back = {
31     0, 0, 31, 20, IB_NORMAL, GROUP_ARROW_MESSAGE_PROBLEMS, 8, button_back, button_none, 0, 0, 1
32 };
33 static image_button image_button_start_mission = {
34     0, 0, 27, 27, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 56, button_start_mission, button_none, 1, 0, 1
35 };
36 
37 static struct {
38     int is_review;
39     int focus_button;
40     int campaign_mission_loaded;
41 } data;
42 
init(void)43 static void init(void)
44 {
45     data.focus_button = 0;
46     rich_text_reset(0);
47 }
48 
draw_background(void)49 static void draw_background(void)
50 {
51     if (!data.campaign_mission_loaded) {
52         data.campaign_mission_loaded = 1;
53         if (!game_file_start_scenario_by_name(scenario_name())) {
54             window_city_show();
55             return;
56         }
57     }
58 
59     window_draw_underlying_window();
60 
61     graphics_in_dialog();
62     int text_id = 200 + scenario_campaign_mission();
63     const lang_message *msg = lang_get_message(text_id);
64 
65     outer_panel_draw(16, 32, 38, 27);
66     text_draw(msg->title.text, 32, 48, FONT_LARGE_BLACK, 0);
67     text_draw(msg->subtitle.text, 32, 78, FONT_NORMAL_BLACK, 0);
68 
69     lang_text_draw(62, 7, 376, 433, FONT_NORMAL_BLACK);
70     if (!data.is_review && game_mission_has_choice()) {
71         lang_text_draw(13, 4, 66, 435, FONT_NORMAL_BLACK);
72     }
73 
74     inner_panel_draw(32, 96, 33, 5);
75     lang_text_draw(62, 10, 48, 104, FONT_NORMAL_WHITE);
76     int goal_index = 0;
77     if (scenario_criteria_population_enabled()) {
78         int x = GOAL_OFFSETS_X[goal_index];
79         int y = GOAL_OFFSETS_Y[goal_index];
80         goal_index++;
81         label_draw(16 + x, 32 + y, 15, 1);
82         int width = lang_text_draw(62, 11, 16 + x + 8, 32 + y + 3, FONT_NORMAL_RED);
83         text_draw_number(scenario_criteria_population(), '@', " ", 16 + x + 8 + width, 32 + y + 3, FONT_NORMAL_RED);
84     }
85     if (scenario_criteria_culture_enabled()) {
86         int x = GOAL_OFFSETS_X[goal_index];
87         int y = GOAL_OFFSETS_Y[goal_index];
88         goal_index++;
89         label_draw(16 + x, 32 + y, 15, 1);
90         int width = lang_text_draw(62, 12, 16 + x + 8, 32 + y + 3, FONT_NORMAL_RED);
91         text_draw_number(scenario_criteria_culture(), '@', " ", 16 + x + 8 + width, 32 + y + 3, FONT_NORMAL_RED);
92     }
93     if (scenario_criteria_prosperity_enabled()) {
94         int x = GOAL_OFFSETS_X[goal_index];
95         int y = GOAL_OFFSETS_Y[goal_index];
96         goal_index++;
97         label_draw(16 + x, 32 + y, 15, 1);
98         int width = lang_text_draw(62, 13, 16 + x + 8, 32 + y + 3, FONT_NORMAL_RED);
99         text_draw_number(scenario_criteria_prosperity(), '@', " ", 16 + x + 8 + width, 32 + y + 3, FONT_NORMAL_RED);
100     }
101     if (scenario_criteria_peace_enabled()) {
102         int x = GOAL_OFFSETS_X[goal_index];
103         int y = GOAL_OFFSETS_Y[goal_index];
104         goal_index++;
105         label_draw(16 + x, 32 + y, 15, 1);
106         int width = lang_text_draw(62, 14, 16 + x + 8, 32 + y + 3, FONT_NORMAL_RED);
107         text_draw_number(scenario_criteria_peace(), '@', " ", 16 + x + 8 + width, 32 + y + 3, FONT_NORMAL_RED);
108     }
109     if (scenario_criteria_favor_enabled()) {
110         int x = GOAL_OFFSETS_X[goal_index];
111         int y = GOAL_OFFSETS_Y[goal_index];
112         goal_index++;
113         label_draw(16 + x, 32 + y, 15, 1);
114         int width = lang_text_draw(62, 15, 16 + x + 8, 32 + y + 3, FONT_NORMAL_RED);
115         text_draw_number(scenario_criteria_favor(), '@', " ", 16 + x + 8 + width, 32 + y + 3, FONT_NORMAL_RED);
116     }
117     int immediate_goal_text = tutorial_get_immediate_goal_text();
118     if (immediate_goal_text) {
119         int x = GOAL_OFFSETS_X[2];
120         int y = GOAL_OFFSETS_Y[2];
121         label_draw(16 + x, 32 + y, 31, 1);
122         lang_text_draw(62, immediate_goal_text, 16 + x + 8, 32 + y + 3, FONT_NORMAL_RED);
123     }
124 
125     inner_panel_draw(32, 184, 33, 15);
126 
127     rich_text_set_fonts(FONT_NORMAL_WHITE, FONT_NORMAL_RED, 5);
128     rich_text_init(msg->content.text, 64, 184, 31, 15, 0);
129 
130     graphics_set_clip_rectangle(35, 187, 522, 234);
131     rich_text_draw(msg->content.text, 48, 196, 496, 14, 0);
132     graphics_reset_clip_rectangle();
133 
134     graphics_reset_dialog();
135 }
136 
draw_foreground(void)137 static void draw_foreground(void)
138 {
139     graphics_in_dialog();
140 
141     rich_text_draw_scrollbar();
142     image_buttons_draw(516, 426, &image_button_start_mission, 1);
143     if (!data.is_review && game_mission_has_choice()) {
144         image_buttons_draw(26, 428, &image_button_back, 1);
145     }
146 
147     graphics_reset_dialog();
148 }
149 
handle_input(const mouse * m,const hotkeys * h)150 static void handle_input(const mouse *m, const hotkeys *h)
151 {
152     const mouse *m_dialog = mouse_in_dialog(m);
153 
154     if (image_buttons_handle_mouse(m_dialog, 516, 426, &image_button_start_mission, 1, 0)) {
155         return;
156     }
157     if (!data.is_review && game_mission_has_choice()) {
158         if (image_buttons_handle_mouse(m_dialog, 26, 428, &image_button_back, 1, 0)) {
159             return;
160         }
161     }
162     rich_text_handle_mouse(m_dialog);
163 }
164 
button_back(int param1,int param2)165 static void button_back(int param1, int param2)
166 {
167     if (!data.is_review) {
168         sound_speech_stop();
169         window_mission_selection_show();
170     }
171 }
172 
button_start_mission(int param1,int param2)173 static void button_start_mission(int param1, int param2)
174 {
175     sound_speech_stop();
176     sound_music_update(1);
177     window_city_show();
178     city_mission_reset_save_start();
179 }
180 
show(void)181 static void show(void)
182 {
183     window_type window = {
184         WINDOW_MISSION_BRIEFING,
185         draw_background,
186         draw_foreground,
187         handle_input
188     };
189     init();
190     window_show(&window);
191 }
192 
window_mission_briefing_show(void)193 void window_mission_briefing_show(void)
194 {
195     data.is_review = 0;
196     data.campaign_mission_loaded = 0;
197     window_intermezzo_show(INTERMEZZO_MISSION_BRIEFING, show);
198 }
199 
window_mission_briefing_show_review(void)200 void window_mission_briefing_show_review(void)
201 {
202     data.is_review = 1;
203     data.campaign_mission_loaded = 1;
204     window_intermezzo_show(INTERMEZZO_MISSION_BRIEFING, show);
205 }
206