diff --git a/src/scenario/editor.c b/src/scenario/editor.c index 06070c90e2..ef8799ab66 100644 --- a/src/scenario/editor.c +++ b/src/scenario/editor.c @@ -124,7 +124,7 @@ static void sort_invasions(void) for (int i = 0; i < MAX_INVASIONS; i++) { for (int j = MAX_INVASIONS - 1; j > 0; j--) { invasion_t *current = &scenario.invasions[j]; - invasion_t *prev = &scenario.invasions[j-1]; + invasion_t *prev = &scenario.invasions[j - 1]; if (current->type && (!prev->type || prev->year > current->year)) { invasion_t tmp = *current; *current = *prev; diff --git a/src/scenario/scenario_events_parameter_data.c b/src/scenario/scenario_events_parameter_data.c index 01f5f1dc6e..86f87a2a6a 100644 --- a/src/scenario/scenario_events_parameter_data.c +++ b/src/scenario/scenario_events_parameter_data.c @@ -10,6 +10,7 @@ #include "game/resource.h" #include "scenario/custom_messages.h" #include "scenario/invasion.h" +#include "scenario/request.h" #include "scenario/scenario.h" #define UNLIMITED 1000000000 @@ -84,7 +85,7 @@ static scenario_condition_data_t scenario_condition_data[CONDITION_TYPE_MAX] = { .xml_parm3 = { .name = "in_city_only", .type = PARAMETER_TYPE_BOOLEAN, .min_limit = 0, .max_limit = 1, .key = TR_PARAMETER_IN_CITY_ONLY }, }, [CONDITION_TYPE_REQUEST_IS_ONGOING] = { .type = CONDITION_TYPE_REQUEST_IS_ONGOING, .xml_attr = { .name = "request_is_ongoing", .type = PARAMETER_TYPE_TEXT, .key = TR_CONDITION_TYPE_REQUEST_IS_ONGOING }, - .xml_parm1 = { .name = "request_id", .type = PARAMETER_TYPE_NUMBER, .min_limit = 0, .max_limit = 19, .key = TR_PARAMETER_TYPE_NUMBER }, + .xml_parm1 = { .name = "request_id", .type = PARAMETER_TYPE_REQUEST, .min_limit = 0, .max_limit = UNLIMITED, .key = TR_PARAMETER_TYPE_REQUEST }, .xml_parm2 = { .name = "check_for_ongoing", .type = PARAMETER_TYPE_BOOLEAN, .min_limit = 0, .max_limit = 1, .key = TR_PARAMETER_CHECK_FOR_ONGOING }, }, [CONDITION_TYPE_TAX_RATE] = { .type = CONDITION_TYPE_TAX_RATE, .xml_attr = { .name = "tax_rate", .type = PARAMETER_TYPE_TEXT, .key = TR_CONDITION_TYPE_TAX_RATE }, @@ -200,7 +201,7 @@ static scenario_action_data_t scenario_action_data[ACTION_TYPE_MAX] = { .xml_parm2 = { .name = "show_message", .type = PARAMETER_TYPE_BOOLEAN, .min_limit = 0, .max_limit = 1, .key = TR_PARAMETER_SHOW_MESSAGE }, }, [ACTION_TYPE_REQUEST_IMMEDIATELY_START] = { .type = ACTION_TYPE_REQUEST_IMMEDIATELY_START, .xml_attr = { .name = "request_immediately_start", .type = PARAMETER_TYPE_TEXT, .key = TR_ACTION_TYPE_REQUEST_IMMEDIATELY_START }, - .xml_parm1 = { .name = "request_id", .type = PARAMETER_TYPE_NUMBER, .min_limit = 0, .max_limit = 19, .key = TR_PARAMETER_TYPE_NUMBER }, }, + .xml_parm1 = { .name = "request_id", .type = PARAMETER_TYPE_REQUEST, .min_limit = 0, .max_limit = UNLIMITED, .key = TR_PARAMETER_TYPE_REQUEST }, }, [ACTION_TYPE_SHOW_CUSTOM_MESSAGE] = { .type = ACTION_TYPE_SHOW_CUSTOM_MESSAGE, .xml_attr = { .name = "show_custom_message", .type = PARAMETER_TYPE_TEXT, .key = TR_ACTION_TYPE_SHOW_CUSTOM_MESSAGE }, .xml_parm1 = { .name = "message_uid", .type = PARAMETER_TYPE_CUSTOM_MESSAGE, .key = TR_PARAMETER_TYPE_CUSTOM_MESSAGE }, }, @@ -948,7 +949,58 @@ const uint8_t *scenario_events_parameter_data_get_display_string(special_attribu } } -void scenario_events_parameter_data_get_display_string_for_value(parameter_type type, int value, uint8_t *result_text, int maxlength) +static uint8_t *string_from_year(uint8_t *dst, int year, int *maxlength) +{ + uint8_t *cursor = dst; + if (year >= 0) { + int use_year_ad = locale_year_before_ad(); + if (use_year_ad) { + cursor += string_from_int(cursor, year, 0); + *cursor = ' '; + cursor++; + cursor = string_copy(lang_get_string(20, 1), cursor, *maxlength - 10); + } else { + string_copy(lang_get_string(20, 1), cursor, *maxlength - 10); + *cursor = ' '; + cursor++; + cursor += string_from_int(cursor, year, 0); + } + } else { + cursor += string_from_int(cursor, -year, 0); + *cursor = ' '; + cursor++; + cursor = string_copy(lang_get_string(20, 0), cursor, *maxlength - 10); + } + int total_chars = (int) (cursor - dst); + *maxlength -= total_chars; + return cursor; +} + +static uint8_t *translation_for_request_value(int value, uint8_t *result_text, int *maxlength) +{ + if (value < 0 || value >= scenario_request_count_total()) { + return string_copy(translation_for(TR_PARAMETER_VALUE_NONE), result_text, *maxlength); + } + const scenario_request *request = scenario_request_get(value); + if (!request || request->resource == RESOURCE_NONE) { + return string_copy(translation_for(TR_PARAMETER_VALUE_NONE), result_text, *maxlength); + } + uint8_t *cursor = result_text; + cursor = string_from_year(cursor, scenario_property_start_year() + request->year, maxlength); + cursor = string_copy(string_from_ascii(", "), cursor, *maxlength); + *maxlength -= 2; + int numbers = string_from_int(cursor, request->amount, 0); + *maxlength -= numbers; + cursor += numbers; + cursor = string_copy(string_from_ascii(" "), cursor, *maxlength); + *maxlength -= 1; + cursor = string_copy(resource_get_data(request->resource)->text, cursor, *maxlength); + + return cursor; +} + +void scenario_events_parameter_data_get_display_string_for_value(parameter_type type, int value, + uint8_t *result_text, int maxlength) { switch (type) { case PARAMETER_TYPE_NUMBER: @@ -966,6 +1018,11 @@ void scenario_events_parameter_data_get_display_string_for_value(parameter_type } return; } + case PARAMETER_TYPE_REQUEST: + { + translation_for_request_value(value, result_text, &maxlength); + return; + } case PARAMETER_TYPE_CUSTOM_MESSAGE: { custom_message_t *message = custom_messages_get(value); @@ -1202,7 +1259,8 @@ void scenario_events_parameter_data_get_display_string_for_action(scenario_actio case ACTION_TYPE_REQUEST_IMMEDIATELY_START: case ACTION_TYPE_TAX_RATE_SET: { - result_text = translation_for_number_value(action->parameter1, result_text, &maxlength); + result_text = append_text(string_from_ascii(" "), result_text, &maxlength); + result_text = translation_for_request_value(action->parameter1, result_text, &maxlength); return; } case ACTION_TYPE_TRADE_PROBLEM_LAND: @@ -1369,7 +1427,8 @@ void scenario_events_parameter_data_get_display_string_for_condition(scenario_co } case CONDITION_TYPE_REQUEST_IS_ONGOING: { - result_text = translation_for_number_value(condition->parameter1, result_text, &maxlength); + result_text = append_text(string_from_ascii(" "), result_text, &maxlength); + result_text = translation_for_request_value(condition->parameter1, result_text, &maxlength); result_text = translation_for_boolean_text(condition->parameter2, TR_PARAMETER_DISPLAY_ONGOING, TR_PARAMETER_DISPLAY_NOT_ONGOING, result_text, &maxlength); return; } diff --git a/src/scenario/scenario_events_parameter_data.h b/src/scenario/scenario_events_parameter_data.h index 9e928dc7a6..cba778ee00 100644 --- a/src/scenario/scenario_events_parameter_data.h +++ b/src/scenario/scenario_events_parameter_data.h @@ -11,6 +11,7 @@ typedef enum { PARAMETER_TYPE_UNDEFINED = 0, PARAMETER_TYPE_NUMBER, + PARAMETER_TYPE_REQUEST, PARAMETER_TYPE_TEXT, PARAMETER_TYPE_CHECK, PARAMETER_TYPE_DIFFICULTY, diff --git a/src/translation/english.c b/src/translation/english.c index ee138cf597..d6b279f784 100644 --- a/src/translation/english.c +++ b/src/translation/english.c @@ -1134,6 +1134,7 @@ static translation_string all_strings[] = { {TR_PARAMETER_TYPE_ENEMY_TYPE, "Enemy type"}, {TR_PARAMETER_TYPE_GOD, "God" }, {TR_PARAMETER_TYPE_CLIMATE, "Climate" }, + {TR_PARAMETER_TYPE_REQUEST, "Request" }, {TR_CONDITION_TYPE_TIME_PASSED, "Time passed"}, {TR_CONDITION_TYPE_DIFFICULTY, "Difficulty"}, {TR_CONDITION_TYPE_MONEY, "City money"}, diff --git a/src/translation/translation.h b/src/translation/translation.h index d3fcfa373c..cc3b35d139 100644 --- a/src/translation/translation.h +++ b/src/translation/translation.h @@ -1110,6 +1110,7 @@ typedef enum { TR_PARAMETER_TYPE_STORAGE_TYPE, TR_PARAMETER_TYPE_GOD, TR_PARAMETER_TYPE_CLIMATE, + TR_PARAMETER_TYPE_REQUEST, TR_PARAMETER_USE_PERCENTAGE, TR_PARAMETER_IN_CITY_ONLY, TR_PARAMETER_CHECK_FOR_ONGOING, diff --git a/src/window/editor/edit_request.c b/src/window/editor/edit_request.c index be53927e91..7ace7d6043 100644 --- a/src/window/editor/edit_request.c +++ b/src/window/editor/edit_request.c @@ -234,13 +234,13 @@ static void button_ignored_disfavor(int param1, int param2) static void button_delete(int param1, int param2) { scenario_request_delete(data.id); - window_editor_requests_show(); + window_go_back(); } static void button_save(int param1, int param2) { scenario_request_update(data.id, &data.request); - window_editor_requests_show(); + window_go_back(); } void window_editor_edit_request_show(int id) diff --git a/src/window/editor/requests.c b/src/window/editor/requests.c index 46f4c1dc27..f80c393f6d 100644 --- a/src/window/editor/requests.c +++ b/src/window/editor/requests.c @@ -29,6 +29,7 @@ static struct { unsigned int total_requests; unsigned int requests_in_use; unsigned int new_request_button_focused; + void (*on_select)(int); } data; static generic_button new_request_button = { @@ -103,10 +104,13 @@ static void draw_background(void) outer_panel_draw(0, 0, 40, 30); lang_text_draw(44, 14, 20, 12, FONT_LARGE_BLACK); - lang_text_draw_centered(13, 3, 0, 456, 640, FONT_NORMAL_BLACK); - lang_text_draw_multiline(152, 1, 32, 376, 576, FONT_NORMAL_BLACK); - lang_text_draw_centered(CUSTOM_TRANSLATION, TR_EDITOR_NEW_REQUEST, new_request_button.x + 8, - new_request_button.y + 8, new_request_button.width - 16, FONT_NORMAL_BLACK); + + if (!data.on_select) { + lang_text_draw_centered(13, 3, 0, 456, 640, FONT_NORMAL_BLACK); + lang_text_draw_multiline(152, 1, 32, 376, 576, FONT_NORMAL_BLACK); + lang_text_draw_centered(CUSTOM_TRANSLATION, TR_EDITOR_NEW_REQUEST, new_request_button.x + 8, + new_request_button.y + 8, new_request_button.width - 16, FONT_NORMAL_BLACK); + } graphics_reset_dialog(); @@ -138,8 +142,10 @@ static void draw_foreground(void) lang_text_draw_centered(44, 19, 0, 165, 640, FONT_LARGE_BLACK); } - button_border_draw(new_request_button.x, new_request_button.y, new_request_button.width, new_request_button.height, - data.new_request_button_focused); + if (!data.on_select) { + button_border_draw(new_request_button.x, new_request_button.y, new_request_button.width, new_request_button.height, + data.new_request_button_focused); + } graphics_reset_dialog(); } @@ -147,29 +153,43 @@ static void draw_foreground(void) static void handle_input(const mouse *m, const hotkeys *h) { const mouse *m_dialog = mouse_in_dialog(m); - if (grid_box_handle_input(&request_buttons, m_dialog, 1) || + if (grid_box_handle_input(&request_buttons, m_dialog, 1)) { + return; + } + if (!data.on_select && generic_buttons_handle_mouse(m_dialog, 0, 0, &new_request_button, 1, &data.new_request_button_focused)) { return; } if (input_go_back_requested(m, h)) { - window_editor_attributes_show(); + window_go_back(); } } static void button_edit_request(unsigned int id, unsigned int mouse_x, unsigned int mouse_y) { - window_editor_edit_request_show(data.requests[id]->id); + if (!data.on_select) { + window_editor_edit_request_show(data.requests[id]->id); + return; + } + if (data.requests[id]->resource == RESOURCE_NONE) { + return; + } + data.on_select(data.requests[id]->id); + window_go_back(); } static void button_new_request(int param0, int param1) { + if (data.on_select) { + return; + } int new_request_id = scenario_request_new(); if (new_request_id >= 0) { window_editor_edit_request_show(new_request_id); } } -void window_editor_requests_show(void) +static void show_window(void (*on_select)(int)) { window_type window = { WINDOW_EDITOR_REQUESTS, @@ -177,6 +197,17 @@ void window_editor_requests_show(void) draw_foreground, handle_input }; + data.on_select = on_select; grid_box_init(&request_buttons, scenario_request_count_total()); window_show(&window); } + +void window_editor_requests_show(void) +{ + show_window(0); +} + +void window_editor_requests_show_with_callback(void (*on_select_callback)(int)) +{ + show_window(on_select_callback); +} diff --git a/src/window/editor/requests.h b/src/window/editor/requests.h index 2d71481681..e7748a3468 100644 --- a/src/window/editor/requests.h +++ b/src/window/editor/requests.h @@ -3,4 +3,6 @@ void window_editor_requests_show(void); +void window_editor_requests_show_with_callback(void (*on_select_callback)(int)); + #endif // WINDOW_EDITOR_REQUESTS_H diff --git a/src/window/editor/scenario_action_edit.c b/src/window/editor/scenario_action_edit.c index b15593081c..acb0cc1357 100644 --- a/src/window/editor/scenario_action_edit.c +++ b/src/window/editor/scenario_action_edit.c @@ -15,6 +15,7 @@ #include "scenario/action_types/action_handler.h" #include "window/editor/custom_variables.h" #include "window/editor/map.h" +#include "window/editor/requests.h" #include "window/editor/select_scenario_action_type.h" #include "window/editor/select_city_by_type.h" #include "window/editor/select_city_trade_route.h" @@ -336,6 +337,9 @@ static void change_parameter(xml_data_attribute_t *parameter, int param1) case PARAMETER_TYPE_CLIMATE: window_editor_select_special_attribute_mapping_show(parameter->type, set_param_value, data.parameter_being_edited_current_value); return; + case PARAMETER_TYPE_REQUEST: + window_editor_requests_show_with_callback(set_param_value); + return; case PARAMETER_TYPE_ROUTE: window_editor_select_city_trade_route_show(set_param_value); return; diff --git a/src/window/editor/scenario_condition_edit.c b/src/window/editor/scenario_condition_edit.c index 05143ec2db..670e792d7d 100644 --- a/src/window/editor/scenario_condition_edit.c +++ b/src/window/editor/scenario_condition_edit.c @@ -15,6 +15,7 @@ #include "scenario/condition_types/condition_handler.h" #include "window/editor/custom_variables.h" #include "window/editor/map.h" +#include "window/editor/requests.h" #include "window/editor/select_scenario_condition_type.h" #include "window/editor/select_city_by_type.h" #include "window/editor/select_city_trade_route.h" @@ -334,6 +335,9 @@ static void change_parameter(xml_data_attribute_t *parameter, int param1) case PARAMETER_TYPE_TARGET_TYPE: window_editor_select_special_attribute_mapping_show(parameter->type, set_param_value, data.parameter_being_edited_current_value); return; + case PARAMETER_TYPE_REQUEST: + window_editor_requests_show_with_callback(set_param_value); + return; case PARAMETER_TYPE_ROUTE: window_editor_select_city_trade_route_show(set_param_value); return;