From b478028206d9c5f5a54e2eb8be8084fe7272612d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Cadete?= Date: Fri, 11 Oct 2024 23:29:01 +0100 Subject: [PATCH] Refactor generic button code --- src/graphics/generic_button.c | 18 +- src/graphics/generic_button.h | 14 +- src/widget/city_pause_menu.c | 19 +- src/widget/map_editor_pause_menu.c | 17 +- src/widget/sidebar/extra.c | 15 +- src/widget/sidebar/military.c | 47 ++--- src/window/advisor/entertainment.c | 7 +- src/window/advisor/imperial.c | 39 ++-- src/window/advisor/labor.c | 24 +-- src/window/advisor/military.c | 60 ++++--- src/window/advisor/population.c | 24 +-- src/window/advisor/ratings.c | 14 +- src/window/advisor/religion.c | 7 +- src/window/advisor/trade.c | 22 +-- src/window/advisors.c | 33 ++-- src/window/asset_previewer.c | 135 +++++++------- src/window/build_menu.c | 67 +++---- src/window/building/culture.c | 37 ++-- src/window/building/depot.c | 153 ++++++++-------- src/window/building/distribution.c | 168 ++++++++++-------- src/window/building/figures.c | 27 +-- src/window/building/industry.c | 9 +- src/window/building/military.c | 47 ++--- src/window/building/utility.c | 45 +++-- src/window/building_info.c | 7 +- src/window/cck_selection.c | 6 +- src/window/config.c | 62 ++++--- src/window/donate_to_city.c | 28 +-- src/window/editor/attributes.c | 106 +++++------ src/window/editor/build_menu.c | 36 ++-- src/window/editor/custom_messages.c | 38 ++-- src/window/editor/custom_variables.c | 50 +++--- src/window/editor/demand_changes.c | 6 +- src/window/editor/edit_demand_change.c | 38 ++-- src/window/editor/edit_invasion.c | 112 ++++++------ src/window/editor/edit_price_change.c | 38 ++-- src/window/editor/edit_request.c | 62 +++---- src/window/editor/empire.c | 31 ++-- src/window/editor/invasions.c | 7 +- src/window/editor/price_changes.c | 6 +- src/window/editor/requests.c | 6 +- src/window/editor/scenario_action_edit.c | 28 +-- src/window/editor/scenario_condition_edit.c | 27 +-- src/window/editor/scenario_event_details.c | 52 +++--- src/window/editor/scenario_events.c | 41 ++--- src/window/editor/select_city_by_type.c | 34 ++-- src/window/editor/select_city_trade_route.c | 34 ++-- src/window/editor/select_custom_message.c | 21 +-- .../editor/select_scenario_action_type.c | 25 +-- .../editor/select_scenario_condition_type.c | 25 +-- .../editor/select_special_attribute_mapping.c | 32 ++-- src/window/editor/special_events.c | 90 +++++----- src/window/editor/start_year.c | 12 +- src/window/editor/starting_conditions.c | 84 ++++----- src/window/editor/win_criteria.c | 68 +++---- src/window/empire.c | 12 +- src/window/file_dialog.c | 7 +- src/window/gift_to_emperor.c | 24 +-- src/window/hold_festival.c | 27 +-- src/window/hold_games.c | 15 +- src/window/hotkey_config.c | 79 ++++---- src/window/hotkey_editor.c | 17 +- src/window/labor_priority.c | 25 +-- src/window/main_menu.c | 18 +- src/window/message_list.c | 45 ++--- src/window/military_menu.c | 17 +- src/window/mission_end.c | 6 +- src/window/mission_list.c | 17 +- src/window/numeric_input.c | 49 ++--- src/window/option_popup.c | 17 +- src/window/overlay_menu.c | 64 +++---- src/window/popup_dialog.c | 6 +- src/window/race_bet.c | 19 +- src/window/resource_settings.c | 22 +-- src/window/select_campaign.c | 25 +-- src/window/select_list.c | 87 ++++----- src/window/set_salary.c | 35 ++-- src/window/user_path_setup.c | 6 +- src/window/victory_dialog.c | 15 +- 79 files changed, 1516 insertions(+), 1398 deletions(-) diff --git a/src/graphics/generic_button.c b/src/graphics/generic_button.c index 408843040d..e059b359c6 100644 --- a/src/graphics/generic_button.c +++ b/src/graphics/generic_button.c @@ -1,7 +1,5 @@ #include "generic_button.h" -#include "graphics/lang_text.h" - static unsigned int get_button(const mouse *m, int x, int y, generic_button *buttons, unsigned int num_buttons) { for (unsigned int i = 0; i < num_buttons; i++) { @@ -27,11 +25,19 @@ int generic_buttons_handle_mouse(const mouse *m, int x, int y, generic_button *b } generic_button *button = &buttons[button_id - 1]; if (m->left.went_up) { - button->left_click_handler(button->parameter1, button->parameter2); - return button->left_click_handler != button_none; + if (button->left_click_handler) { + button->left_click_handler(button); + return 1; + } else { + return 0; + } } else if (m->right.went_up) { - button->right_click_handler(button->parameter1, button->parameter2); - return button->right_click_handler != button_none; + if (button->right_click_handler) { + button->right_click_handler(button); + return 1; + } else { + return 0; + } } else { return 0; } diff --git a/src/graphics/generic_button.h b/src/graphics/generic_button.h index 6bb0b1a623..68982dd9e9 100644 --- a/src/graphics/generic_button.h +++ b/src/graphics/generic_button.h @@ -1,17 +1,15 @@ -#ifndef GRAPHICS_CUSTOM_BUTTON_H -#define GRAPHICS_CUSTOM_BUTTON_H +#ifndef GRAPHICS_GENERIC_BUTTON_H +#define GRAPHICS_GENERIC_BUTTON_H -#include "graphics/button.h" -#include "graphics/font.h" #include "input/mouse.h" -typedef struct { +typedef struct generic_button { short x; short y; short width; short height; - void (*left_click_handler)(int param1, int param2); - void (*right_click_handler)(int param1, int param2); + void (*left_click_handler)(const struct generic_button *button); + void (*right_click_handler)(const struct generic_button *button); int parameter1; int parameter2; } generic_button; @@ -19,4 +17,4 @@ typedef struct { int generic_buttons_handle_mouse(const mouse *m, int x, int y, generic_button *buttons, unsigned int num_buttons, unsigned int *focus_button_id); -#endif // GRAPHICS_CUSTOM_BUTTON_H +#endif // GRAPHICS_GENERIC_BUTTON_H diff --git a/src/widget/city_pause_menu.c b/src/widget/city_pause_menu.c index d2adc8c714..521374f00d 100644 --- a/src/widget/city_pause_menu.c +++ b/src/widget/city_pause_menu.c @@ -24,18 +24,18 @@ #include "window/mission_selection.h" #include "window/plain_message_dialog.h" -static void button_click(int type, int param2); +static void button_click(const generic_button *button); static unsigned int focus_button_id; static generic_button buttons[] = { - {192, 100, 192, 25, button_click, button_none, 1, 0}, - {192, 140, 192, 25, button_click, button_none, 2, 0}, - {192, 180, 192, 25, button_click, button_none, 3, 0}, - {192, 220, 192, 25, button_click, button_none, 4, 0}, - {192, 260, 192, 25, button_click, button_none, 5, 0}, - {192, 300, 192, 25, button_click, button_none, 6, 0}, - {192, 340, 192, 25, button_click, button_none, 7, 0}, + {192, 100, 192, 25, button_click, 0, 1}, + {192, 140, 192, 25, button_click, 0, 2}, + {192, 180, 192, 25, button_click, 0, 3}, + {192, 220, 192, 25, button_click, 0, 4}, + {192, 260, 192, 25, button_click, 0, 5}, + {192, 300, 192, 25, button_click, 0, 6}, + {192, 340, 192, 25, button_click, 0, 7}, }; #define MAX_BUTTONS (sizeof(buttons) / sizeof(generic_button)) @@ -116,8 +116,9 @@ static void confirm_exit(int accepted, int checked) } } -static void button_click(int type, int param2) +static void button_click(const generic_button *button) { + int type = button->parameter1; if (type == 1) { window_go_back(); } else if (type == 2) { diff --git a/src/widget/map_editor_pause_menu.c b/src/widget/map_editor_pause_menu.c index d74f4af298..f7b1a232d2 100644 --- a/src/widget/map_editor_pause_menu.c +++ b/src/widget/map_editor_pause_menu.c @@ -35,17 +35,17 @@ static void menu_file_confirm_exit(int accepted, int checked) } } -static void button_click(int type, int param2); +static void button_click(const generic_button *button); static unsigned int focus_button_id; static generic_button buttons[] = { - {192, 100, 192, 25, button_click, button_none, 1, 0}, - {192, 140, 192, 25, button_click, button_none, 2, 0}, - {192, 180, 192, 25, button_click, button_none, 3, 0}, - {192, 220, 192, 25, button_click, button_none, 4, 0}, - {192, 260, 192, 25, button_click, button_none, 5, 0}, - {192, 300, 192, 25, button_click, button_none, 6, 0}, + {192, 100, 192, 25, button_click, 0, 1}, + {192, 140, 192, 25, button_click, 0, 2}, + {192, 180, 192, 25, button_click, 0, 3}, + {192, 220, 192, 25, button_click, 0, 4}, + {192, 260, 192, 25, button_click, 0, 5}, + {192, 300, 192, 25, button_click, 0, 6}, }; static void draw_foreground(void) @@ -97,8 +97,9 @@ static void main_menu_confirmed(int confirmed, int checked) } } -static void button_click(int type, int param2) +static void button_click(const generic_button *button) { + int type = button->parameter1; if (type == 1) { window_go_back(); } else if (type == 2) { diff --git a/src/widget/sidebar/extra.c b/src/widget/sidebar/extra.c index b105c5c093..4754a2330d 100644 --- a/src/widget/sidebar/extra.c +++ b/src/widget/sidebar/extra.c @@ -54,7 +54,7 @@ static void button_game_speed(int is_down, int param2); static void button_toggle_play_paused(int param1, int param2); -static void button_handle_request(int index, int param2); +static void button_handle_request(const generic_button *button); static arrow_button arrow_buttons_speed[] = { {11, 30, 17, 24, button_game_speed, 1, 0}, @@ -66,11 +66,11 @@ static image_button play_paused_button = { }; static generic_button buttons_emperor_requests[] = { - {2, 28, 158, 20, button_handle_request, button_none, 0, 0}, - {2, 76, 158, 20, button_handle_request, button_none, 1, 0}, - {2, 124, 158, 20, button_handle_request, button_none, 2, 0}, - {2, 172, 158, 20, button_handle_request, button_none, 3, 0}, - {2, 220, 158, 20, button_handle_request, button_none, 4, 0} + {2, 28, 158, 20, button_handle_request}, + {2, 76, 158, 20, button_handle_request, 0, 1}, + {2, 124, 158, 20, button_handle_request, 0, 2}, + {2, 172, 158, 20, button_handle_request, 0, 3}, + {2, 220, 158, 20, button_handle_request, 0, 4} }; static const char *play_pause_button_image_names[] = { "Pause Button", "Play Button" }; @@ -747,8 +747,9 @@ static void confirm_send_goods(int accepted, int checked) } } -static void button_handle_request(int index, int param2) +static void button_handle_request(const generic_button *button) { + int index = button->parameter1; if (data.active_requests > data.visible_requests && index == (int) data.visible_requests - 1) { window_advisors_show_advisor(ADVISOR_IMPERIAL); return; diff --git a/src/widget/sidebar/military.c b/src/widget/sidebar/military.c index de2efc4df0..39e900c975 100644 --- a/src/widget/sidebar/military.c +++ b/src/widget/sidebar/military.c @@ -90,10 +90,10 @@ static const int LAYOUT_BUTTON_INDEXES_AUXILIARY[2][LAYOUTS_PER_LEGION] = { static void button_military_menu(int param1, int param2); static void button_close_military_sidebar(int param1, int param2); static void button_cycle_legion(int cycle_forward, int param2); -static void button_select_formation_layout(int index, int param2); -static void button_go_to_legion(int param1, int param2); -static void button_return_to_fort(int param1, int param2); -static void button_empire_service(int param1, int param2); +static void button_select_formation_layout(const generic_button *button); +static void button_go_to_legion(const generic_button *button); +static void button_return_to_fort(const generic_button *button); +static void button_empire_service(const generic_button *button); static image_button buttons_title_close[] = { {123, 4, 39, 26, IB_NORMAL, GROUP_OK_CANCEL_SCROLL_BUTTONS, 4, @@ -108,29 +108,29 @@ static arrow_button buttons_cycle_legion[] = { static generic_button buttons_formation_layout[LAYOUTS_PER_LEGION - 2][LAYOUTS_PER_LEGION] = { { - {8, 0, 46, 46, button_select_formation_layout, button_none, 0, 0}, - {58, 0, 46, 46, button_select_formation_layout, button_none, 1, 0}, - {108, 0, 46, 46, button_select_formation_layout, button_none, 2, 0} + {8, 0, 46, 46, button_select_formation_layout}, + {58, 0, 46, 46, button_select_formation_layout, 0, 1}, + {108, 0, 46, 46, button_select_formation_layout, 0, 2} }, { - {33, 50, 46, 46, button_select_formation_layout, button_none, 0, 0}, - {33, 0, 46, 46, button_select_formation_layout, button_none, 1, 0}, - {83, 0, 46, 46, button_select_formation_layout, button_none, 2, 0}, - {83, 50, 46, 46, button_select_formation_layout, button_none, 3, 0} + {33, 50, 46, 46, button_select_formation_layout}, + {33, 0, 46, 46, button_select_formation_layout, 0, 1}, + {83, 0, 46, 46, button_select_formation_layout, 0, 2}, + {83, 50, 46, 46, button_select_formation_layout, 0, 3} }, { - {33, 0, 46, 46, button_select_formation_layout, button_none, 0, 0}, - {83, 0, 46, 46, button_select_formation_layout, button_none, 1, 0}, - {8, 50, 46, 46, button_select_formation_layout, button_none, 2, 0}, - {58, 50, 46, 46, button_select_formation_layout, button_none, 3, 0}, - {108, 50, 46, 46, button_select_formation_layout, button_none, 4, 0} + {33, 0, 46, 46, button_select_formation_layout}, + {83, 0, 46, 46, button_select_formation_layout, 0, 1}, + {8, 50, 46, 46, button_select_formation_layout, 0, 2}, + {58, 50, 46, 46, button_select_formation_layout, 0, 3}, + {108, 50, 46, 46, button_select_formation_layout, 0, 4} } }; static generic_button buttons_bottom[] = { - {16, 0, 30, 30, button_go_to_legion, button_none, 0, 0}, - {66, 0, 30, 30, button_return_to_fort, button_none, 0, 0}, - {116, 0, 30, 30, button_empire_service, button_none, 0, 0}, + {16, 0, 30, 30, button_go_to_legion}, + {66, 0, 30, 30, button_return_to_fort}, + {116, 0, 30, 30, button_empire_service}, }; typedef struct { @@ -584,8 +584,9 @@ static void button_cycle_legion(int cycle_forward, int param2) set_formation_id(legion->formation_id); } -static void button_select_formation_layout(int index, int param2) +static void button_select_formation_layout(const generic_button *button) { + int index = button->parameter1; formation *m = formation_get(data.active_legion.formation_id); if (m->in_distant_battle) { return; @@ -612,13 +613,13 @@ static void button_select_formation_layout(int index, int param2) } } -static void button_go_to_legion(int param1, int param2) +static void button_go_to_legion(const generic_button *button) { const formation *m = formation_get(data.active_legion.formation_id); city_view_go_to_grid_offset(map_grid_offset(m->x_home, m->y_home)); } -static void button_return_to_fort(int param1, int param2) +static void button_return_to_fort(const generic_button *button) { formation *m = formation_get(data.active_legion.formation_id); if (!m->in_distant_battle) { @@ -626,7 +627,7 @@ static void button_return_to_fort(int param1, int param2) } } -static void button_empire_service(int param1, int param2) +static void button_empire_service(const generic_button *button) { formation_toggle_empire_service(data.active_legion.formation_id); formation_calculate_figures(); diff --git a/src/window/advisor/entertainment.c b/src/window/advisor/entertainment.c index 3fa7be5a2c..8ac8b3abb3 100644 --- a/src/window/advisor/entertainment.c +++ b/src/window/advisor/entertainment.c @@ -10,6 +10,7 @@ #include "city/gods.h" #include "city/houses.h" #include "core/calc.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/image.h" #include "graphics/lang_text.h" @@ -27,10 +28,10 @@ static unsigned int focus_button_id; -static void button_hold_games(int param1, int param2); +static void button_hold_games(const generic_button *button); static generic_button hold_games_button[] = { - {102, 370, 300, 20, button_hold_games, button_none, 0, 0}, + {102, 370, 300, 20, button_hold_games}, }; struct games_text { @@ -207,7 +208,7 @@ static int handle_mouse(const mouse *m) return generic_buttons_handle_mouse(m, 0, 0, hold_games_button, 1, &focus_button_id); } -static void button_hold_games(int param1, int param2) +static void button_hold_games(const generic_button *button) { window_hold_games_show(0); } diff --git a/src/window/advisor/imperial.c b/src/window/advisor/imperial.c index 047e627ca0..502c2b65c2 100644 --- a/src/window/advisor/imperial.c +++ b/src/window/advisor/imperial.c @@ -11,6 +11,7 @@ #include "core/string.h" #include "empire/city.h" #include "figure/formation_legion.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/image.h" #include "graphics/lang_text.h" @@ -30,21 +31,21 @@ #define ADVISOR_HEIGHT 27 #define RESOURCE_INFO_MAX_TEXT 200 -static void button_donate_to_city(int param1, int param2); -static void button_set_salary(int param1, int param2); -static void button_gift_to_emperor(int param1, int param2); -static void button_request(int index, int param2); -static void button_request_resource(int index, int param2); +static void button_donate_to_city(const generic_button *button); +static void button_set_salary(const generic_button *button); +static void button_gift_to_emperor(const generic_button *button); +static void button_request(const generic_button *button); +static void button_request_resource(const generic_button *button); static generic_button imperial_buttons[] = { - {320, 367, 250, 20, button_donate_to_city, button_none, 0, 0}, - {70, 393, 500, 20, button_set_salary, button_none, 0, 0}, - {320, 341, 250, 20, button_gift_to_emperor, button_none, 0, 0}, - {38, 96, 560, 40, button_request, button_request_resource, 0, 0}, - {38, 138, 560, 40, button_request, button_request_resource, 1, 0}, - {38, 180, 560, 40, button_request, button_request_resource, 2, 0}, - {38, 222, 560, 40, button_request, button_request_resource, 3, 0}, - {38, 264, 560, 40, button_request, button_request_resource, 4, 0}, + {320, 367, 250, 20, button_donate_to_city}, + {70, 393, 500, 20, button_set_salary}, + {320, 341, 250, 20, button_gift_to_emperor}, + {38, 96, 560, 40, button_request, button_request_resource, 0}, + {38, 138, 560, 40, button_request, button_request_resource, 1}, + {38, 180, 560, 40, button_request, button_request_resource, 2}, + {38, 222, 560, 40, button_request, button_request_resource, 3}, + {38, 264, 560, 40, button_request, button_request_resource, 4}, }; static unsigned int focus_button_id; @@ -177,17 +178,17 @@ static int handle_mouse(const mouse *m) return generic_buttons_handle_mouse(m, 0, 0, imperial_buttons, 3 + request_count, &focus_button_id); } -static void button_donate_to_city(int param1, int param2) +static void button_donate_to_city(const generic_button *button) { window_donate_to_city_show(); } -static void button_set_salary(int param1, int param2) +static void button_set_salary(const generic_button *button) { window_set_salary_show(); } -static void button_gift_to_emperor(int param1, int param2) +static void button_gift_to_emperor(const generic_button *button) { window_gift_to_emperor_show(); } @@ -213,8 +214,9 @@ static void confirm_send_goods(int accepted, int checked) } } -void button_request(int index, int param2) +void button_request(const generic_button *button) { + int index = button->parameter1; int status = city_request_get_status(index); if (!status) { return; @@ -254,8 +256,9 @@ void button_request(int index, int param2) } // Used for showing the resource settings window on right click -void button_request_resource(int index, int param2) +void button_request_resource(const generic_button *button) { + int index = button->parameter1; // Make sure there's a request pending at this index if (!city_request_get_status(index)) { return; diff --git a/src/window/advisor/labor.c b/src/window/advisor/labor.c index 6f75c20061..05d8aca75b 100644 --- a/src/window/advisor/labor.c +++ b/src/window/advisor/labor.c @@ -4,6 +4,7 @@ #include "city/labor.h" #include "core/calc.h" #include "graphics/arrow_button.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/image.h" #include "graphics/lang_text.h" @@ -15,18 +16,18 @@ #define ADVISOR_HEIGHT 26 static void arrow_button_wages(int is_down, int param2); -static void button_priority(int category, int param2); +static void button_priority(const generic_button *button); static generic_button category_buttons[] = { - {40, 77, 560, 22, button_priority, button_none, 0, 0}, - {40, 102, 560, 22, button_priority, button_none, 1, 0}, - {40, 127, 560, 22, button_priority, button_none, 2, 0}, - {40, 152, 560, 22, button_priority, button_none, 3, 0}, - {40, 177, 560, 22, button_priority, button_none, 4, 0}, - {40, 202, 560, 22, button_priority, button_none, 5, 0}, - {40, 227, 560, 22, button_priority, button_none, 6, 0}, - {40, 252, 560, 22, button_priority, button_none, 7, 0}, - {40, 277, 560, 22, button_priority, button_none, 8, 0}, + {40, 77, 560, 22, button_priority}, + {40, 102, 560, 22, button_priority, 0, 1}, + {40, 127, 560, 22, button_priority, 0, 2}, + {40, 152, 560, 22, button_priority, 0, 3}, + {40, 177, 560, 22, button_priority, 0, 4}, + {40, 202, 560, 22, button_priority, 0, 5}, + {40, 227, 560, 22, button_priority, 0, 6}, + {40, 252, 560, 22, button_priority, 0, 7}, + {40, 277, 560, 22, button_priority, 0, 8}, }; static arrow_button wage_buttons[] = { @@ -113,8 +114,9 @@ static void arrow_button_wages(int is_down, int param2) window_invalidate(); } -static void button_priority(int category, int param2) +static void button_priority(const generic_button *button) { + int category = button->parameter1; window_labor_priority_show(category); } diff --git a/src/window/advisor/military.c b/src/window/advisor/military.c index a9392b8ef9..1d7aece4a4 100644 --- a/src/window/advisor/military.c +++ b/src/window/advisor/military.c @@ -6,6 +6,7 @@ #include "city/view.h" #include "core/calc.h" #include "figure/formation_legion.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/image.h" #include "graphics/lang_text.h" @@ -24,37 +25,37 @@ #define MAX_VISIBLE_LEGIONS 6 -static void button_go_to_legion(int legion_id, int param2); -static void button_return_to_fort(int legion_id, int param2); -static void button_empire_service(int legion_id, int param2); -static void button_return_all_to_fort(int param1, int param2); +static void button_go_to_legion(const generic_button *button); +static void button_return_to_fort(const generic_button *button); +static void button_empire_service(const generic_button *button); +static void button_return_all_to_fort(const generic_button *button); static void on_scroll(void); static scrollbar_type scrollbar = { 592, 70, 272, 576, MAX_VISIBLE_LEGIONS, on_scroll }; static generic_button fort_buttons[] = { - {384, 83, 30, 30, button_go_to_legion, button_none, 1, 0}, - {464, 83, 30, 30, button_return_to_fort, button_none, 1, 0}, - {544, 83, 30, 30, button_empire_service, button_none, 1, 0}, - {384, 127, 30, 30, button_go_to_legion, button_none, 2, 0}, - {464, 127, 30, 30, button_return_to_fort, button_none, 2, 0}, - {544, 127, 30, 30, button_empire_service, button_none, 2, 0}, - {384, 171, 30, 30, button_go_to_legion, button_none, 3, 0}, - {464, 171, 30, 30, button_return_to_fort, button_none, 3, 0}, - {544, 171, 30, 30, button_empire_service, button_none, 3, 0}, - {384, 215, 30, 30, button_go_to_legion, button_none, 4, 0}, - {464, 215, 30, 30, button_return_to_fort, button_none, 4, 0}, - {544, 215, 30, 30, button_empire_service, button_none, 4, 0}, - {384, 259, 30, 30, button_go_to_legion, button_none, 5, 0}, - {464, 259, 30, 30, button_return_to_fort, button_none, 5, 0}, - {544, 259, 30, 30, button_empire_service, button_none, 5, 0}, - {384, 303, 30, 30, button_go_to_legion, button_none, 6, 0}, - {464, 303, 30, 30, button_return_to_fort, button_none, 6, 0}, - {544, 303, 30, 30, button_empire_service, button_none, 6, 0}, + {384, 83, 30, 30, button_go_to_legion, 0, 1}, + {464, 83, 30, 30, button_return_to_fort, 0, 1}, + {544, 83, 30, 30, button_empire_service, 0, 1}, + {384, 127, 30, 30, button_go_to_legion, 0, 2}, + {464, 127, 30, 30, button_return_to_fort, 0, 2}, + {544, 127, 30, 30, button_empire_service, 0, 2}, + {384, 171, 30, 30, button_go_to_legion, 0, 3}, + {464, 171, 30, 30, button_return_to_fort, 0, 3}, + {544, 171, 30, 30, button_empire_service, 0, 3}, + {384, 215, 30, 30, button_go_to_legion, 0, 4}, + {464, 215, 30, 30, button_return_to_fort, 0, 4}, + {544, 215, 30, 30, button_empire_service, 0, 4}, + {384, 259, 30, 30, button_go_to_legion, 0, 5}, + {464, 259, 30, 30, button_return_to_fort, 0, 5}, + {544, 259, 30, 30, button_empire_service, 0, 5}, + {384, 303, 30, 30, button_go_to_legion, 0, 6}, + {464, 303, 30, 30, button_return_to_fort, 0, 6}, + {544, 303, 30, 30, button_empire_service, 0, 6}, }; static generic_button additional_buttons[] = { - {445, 28, 60, 40, button_return_all_to_fort, button_none, 0, 0} + {445, 28, 60, 40, button_return_all_to_fort} }; static unsigned int focus_button_id; @@ -247,9 +248,10 @@ static int handle_mouse(const mouse *m) return result; } -static void button_go_to_legion(int legion_id, int param2) +static void button_go_to_legion(const generic_button *button) { - const formation *m = formation_get(formation_for_legion(legion_id+scrollbar.scroll_position)); + int legion_id = button->parameter1; + const formation *m = formation_get(formation_for_legion(legion_id + scrollbar.scroll_position)); city_view_go_to_grid_offset(map_grid_offset(m->x_home, m->y_home)); window_city_show(); } @@ -263,20 +265,22 @@ static void return_legion_to_fort(int legion_id) } } -static void button_return_to_fort(int legion_id, int param2) +static void button_return_to_fort(const generic_button *button) { + int legion_id = button->parameter1; return_legion_to_fort(legion_id + scrollbar.scroll_position); } -static void button_empire_service(int legion_id, int param2) +static void button_empire_service(const generic_button *button) { + int legion_id = button->parameter1; int formation_id = formation_for_legion(legion_id + scrollbar.scroll_position); formation_toggle_empire_service(formation_id); formation_calculate_figures(); window_invalidate(); } -static void button_return_all_to_fort(int param1, int param2) +static void button_return_all_to_fort(const generic_button *button) { unsigned int num_legions_not_at_fort = get_num_legions_not_at_fort(); if (num_legions_not_at_fort > 0) { diff --git a/src/window/advisor/population.c b/src/window/advisor/population.c index a8b6d83359..4575864e1c 100644 --- a/src/window/advisor/population.c +++ b/src/window/advisor/population.c @@ -11,6 +11,7 @@ #include "city/ratings.h" #include "city/resource.h" #include "game/time.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -23,11 +24,11 @@ #define ADVISOR_HEIGHT 27 -static void button_graph(int param1, int param2); +static void button_graph(const generic_button *button); static generic_button graph_buttons[] = { - { 509, 61, 104, 55, button_graph, button_none, 0, 0 }, - { 509, 161, 104, 55, button_graph, button_none, 1, 0 } + { 509, 61, 104, 55, button_graph}, + { 509, 161, 104, 55, button_graph, 0, 1 } }; static unsigned int focus_button_id; @@ -505,29 +506,30 @@ static int handle_mouse(const mouse *m) return generic_buttons_handle_mouse(m, 0, 0, graph_buttons, 2, &focus_button_id); } -static void button_graph(int param1, int param2) +static void button_graph(const generic_button *button) { + int button_id = button->parameter1; int new_order; - + switch (city_population_graph_order()) { default: case 0: - new_order = param1 ? 5 : 2; + new_order = button_id ? 5 : 2; break; case 1: - new_order = param1 ? 3 : 4; + new_order = button_id ? 3 : 4; break; case 2: - new_order = param1 ? 4 : 0; + new_order = button_id ? 4 : 0; break; case 3: - new_order = param1 ? 1 : 5; + new_order = button_id ? 1 : 5; break; case 4: - new_order = param1 ? 2 : 1; + new_order = button_id ? 2 : 1; break; case 5: - new_order = param1 ? 0 : 3; + new_order = button_id ? 0 : 3; break; } city_population_set_graph_order(new_order); diff --git a/src/window/advisor/ratings.c b/src/window/advisor/ratings.c index 735a8a0d9d..f76bcaf2da 100644 --- a/src/window/advisor/ratings.c +++ b/src/window/advisor/ratings.c @@ -4,6 +4,7 @@ #include "core/calc.h" #include "core/config.h" #include "core/lang.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/image.h" #include "graphics/image_button.h" @@ -16,13 +17,13 @@ #define ADVISOR_HEIGHT 27 -static void button_rating(int rating, int param2); +static void button_rating(const generic_button *button); static generic_button rating_buttons[] = { - { 80, 286, 110, 66, button_rating, button_none, SELECTED_RATING_CULTURE, 0}, - {200, 286, 110, 66, button_rating, button_none, SELECTED_RATING_PROSPERITY, 0}, - {320, 286, 110, 66, button_rating, button_none, SELECTED_RATING_PEACE, 0}, - {440, 286, 110, 66, button_rating, button_none, SELECTED_RATING_FAVOR, 0}, + { 80, 286, 110, 66, button_rating, 0, SELECTED_RATING_CULTURE}, + {200, 286, 110, 66, button_rating, 0, SELECTED_RATING_PROSPERITY}, + {320, 286, 110, 66, button_rating, 0, SELECTED_RATING_PEACE}, + {440, 286, 110, 66, button_rating, 0, SELECTED_RATING_FAVOR}, }; static unsigned int focus_button_id; @@ -179,8 +180,9 @@ static int handle_mouse(const mouse *m) return generic_buttons_handle_mouse(m, 0, 0, rating_buttons, 4, &focus_button_id); } -static void button_rating(int rating, int param2) +static void button_rating(const generic_button *button) { + int rating = button->parameter1; city_rating_select(rating); window_invalidate(); } diff --git a/src/window/advisor/religion.c b/src/window/advisor/religion.c index 0a2116c6e6..6677a123d6 100644 --- a/src/window/advisor/religion.c +++ b/src/window/advisor/religion.c @@ -6,6 +6,7 @@ #include "city/gods.h" #include "city/houses.h" #include "game/settings.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/image.h" #include "graphics/lang_text.h" @@ -13,10 +14,10 @@ #include "graphics/text.h" #include "window/hold_festival.h" -static void button_hold_festival(int param1, int param2); +static void button_hold_festival(const generic_button *button); static generic_button hold_festival_button[] = { - {102, 340, 300, 20, button_hold_festival, button_none, 0, 0}, + {102, 340, 300, 20, button_hold_festival}, }; static unsigned int focus_button_id; @@ -177,7 +178,7 @@ static int handle_mouse(const mouse *m) return generic_buttons_handle_mouse(m, 0, 0, hold_festival_button, 1, &focus_button_id); } -static void button_hold_festival(int param1, int param2) +static void button_hold_festival(const generic_button *button) { if (!city_festival_is_planned()) { window_hold_festival_show(); diff --git a/src/window/advisor/trade.c b/src/window/advisor/trade.c index a29ffc6559..2ef82965b8 100644 --- a/src/window/advisor/trade.c +++ b/src/window/advisor/trade.c @@ -11,6 +11,7 @@ #include "core/string.h" #include "empire/city.h" #include "game/resource.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/grid_box.h" @@ -36,9 +37,9 @@ static void draw_resource_info(const grid_box_item *item); static void resource_item_tooltip(const grid_box_item *item, tooltip_context *c); -static void button_prices(int param1, int param2); -static void button_empire(int param1, int param2); -static void button_policy(int param1, int param2); +static void button_prices(const generic_button *button); +static void button_empire(const generic_button *button); +static void button_policy(const generic_button *button); static void button_resource(unsigned int index, unsigned int mouse_x, unsigned int mouse_y); static grid_box_type resource_grid = { @@ -56,10 +57,10 @@ static grid_box_type resource_grid = { }; static generic_button resource_buttons[] = { - {375, 392, 200, 24, button_prices, button_none, 1, 0}, - {160, 392, 200, 24, button_empire, button_none, 1, 0}, - {45, 390, 40, 30, button_policy, button_none, LAND_TRADE_POLICY, 0}, - {95, 390, 40, 30, button_policy, button_none, SEA_TRADE_POLICY, 0} + {375, 392, 200, 24, button_prices}, + {160, 392, 200, 24, button_empire}, + {45, 390, 40, 30, button_policy, 0, LAND_TRADE_POLICY}, + {95, 390, 40, 30, button_policy, 0, SEA_TRADE_POLICY} }; static struct { @@ -299,18 +300,19 @@ static void show_policy(trade_policy_type policy_type) TRADE_POLICY_COST, OPTION_MENU_SMALL_ROW); } -static void button_prices(int param1, int param2) +static void button_prices(const generic_button *button) { window_trade_prices_show(17, 53, 622, 334); } -static void button_empire(int param1, int param2) +static void button_empire(const generic_button *button) { window_empire_show(); } -static void button_policy(int policy_type, int param2) +static void button_policy(const generic_button *button) { + int policy_type = button->parameter1; if ((policy_type == LAND_TRADE_POLICY && !building_monument_working(BUILDING_CARAVANSERAI)) || (policy_type == SEA_TRADE_POLICY && !building_monument_working(BUILDING_LIGHTHOUSE))) { return; diff --git a/src/window/advisors.c b/src/window/advisors.c index 6bc59171e6..7ec1767ede 100644 --- a/src/window/advisors.c +++ b/src/window/advisors.c @@ -38,7 +38,7 @@ #include "window/advisor/trade.h" #include "window/advisor/housing.h" -static void button_change_advisor(int advisor, int param2); +static void button_change_advisor(const generic_button *button); static void button_help(int param1, int param2); static image_button help_button = { @@ -46,20 +46,20 @@ static image_button help_button = { }; static generic_button advisor_buttons[ADVISOR_MAX] = { - {9, 1, 40, 40, button_change_advisor, button_none, ADVISOR_LABOR, 0}, - {54, 1, 40, 40, button_change_advisor, button_none, ADVISOR_MILITARY, 0}, - {99, 1, 40, 40, button_change_advisor, button_none, ADVISOR_IMPERIAL, 0}, - {144, 1, 40, 40, button_change_advisor, button_none, ADVISOR_RATINGS, 0}, - {189, 1, 40, 40, button_change_advisor, button_none, ADVISOR_TRADE, 0}, - {234, 1, 40, 40, button_change_advisor, button_none, ADVISOR_POPULATION, 0}, - {279, 1, 40, 40, button_change_advisor, button_none, ADVISOR_HOUSING, 0}, - {324, 1, 40, 40, button_change_advisor, button_none, ADVISOR_HEALTH, 0}, - {369, 1, 40, 40, button_change_advisor, button_none, ADVISOR_EDUCATION, 0}, - {414, 1, 40, 40, button_change_advisor, button_none, ADVISOR_ENTERTAINMENT, 0}, - {459, 1, 40, 40, button_change_advisor, button_none, ADVISOR_RELIGION, 0}, - {504, 1, 40, 40, button_change_advisor, button_none, ADVISOR_FINANCIAL, 0}, - {549, 1, 40, 40, button_change_advisor, button_none, ADVISOR_CHIEF, 0}, - {594, 1, 40, 40, button_change_advisor, button_none, 0, 0}, + {9, 1, 40, 40, button_change_advisor, 0, ADVISOR_LABOR}, + {54, 1, 40, 40, button_change_advisor, 0, ADVISOR_MILITARY}, + {99, 1, 40, 40, button_change_advisor, 0, ADVISOR_IMPERIAL}, + {144, 1, 40, 40, button_change_advisor, 0, ADVISOR_RATINGS}, + {189, 1, 40, 40, button_change_advisor, 0, ADVISOR_TRADE}, + {234, 1, 40, 40, button_change_advisor, 0, ADVISOR_POPULATION}, + {279, 1, 40, 40, button_change_advisor, 0, ADVISOR_HOUSING}, + {324, 1, 40, 40, button_change_advisor, 0, ADVISOR_HEALTH}, + {369, 1, 40, 40, button_change_advisor, 0, ADVISOR_EDUCATION}, + {414, 1, 40, 40, button_change_advisor, 0, ADVISOR_ENTERTAINMENT}, + {459, 1, 40, 40, button_change_advisor, 0, ADVISOR_RELIGION}, + {504, 1, 40, 40, button_change_advisor, 0, ADVISOR_FINANCIAL}, + {549, 1, 40, 40, button_change_advisor, 0, ADVISOR_CHIEF}, + {594, 1, 40, 40, button_change_advisor}, }; static const advisor_window_type *(*sub_advisors[])(void) = { @@ -249,8 +249,9 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_change_advisor(int advisor, int param2) +static void button_change_advisor(const generic_button *button) { + int advisor = button->parameter1; if (advisor) { window_advisors_set_advisor(advisor); window_invalidate(); diff --git a/src/window/asset_previewer.c b/src/window/asset_previewer.c index 4d73b16538..67d462203f 100644 --- a/src/window/asset_previewer.c +++ b/src/window/asset_previewer.c @@ -15,6 +15,7 @@ #include "game/animation.h" #include "game/settings.h" #include "game/system.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -64,20 +65,20 @@ typedef enum { static void draw_asset_entry(const list_box_item *item); static void select_asset(unsigned int index, int unused); static void handle_tooltip(const list_box_item *item, tooltip_context *c); -static void button_top(int option, int param2); -static void button_toggle_animation_frames(int param1, int param2); +static void button_top(const generic_button *button); +static void button_toggle_animation_frames(const generic_button *button); static generic_button buttons[NUM_BUTTONS] = { - { 0, 25, 180, 20, button_top, button_none, BUTTON_CHANGE_ASSET_GROUP }, - { 200, 25, 140, 20, button_top, button_none, BUTTON_CHANGE_TERRAIN }, - { 360, 5, 160, 20, button_top, button_none, BUTTON_CHANGE_ZOOM }, - { 360, 25, 160, 20, button_top, button_none, BUTTON_TOGGLE_ANIMATIONS }, - { 530, -40, 80, 40, button_top, button_none, BUTTON_REFRESH }, - { 530, 5, 80, 40, button_top, button_none, BUTTON_QUIT }, + { 0, 25, 180, 20, button_top, 0, BUTTON_CHANGE_ASSET_GROUP }, + { 200, 25, 140, 20, button_top, 0, BUTTON_CHANGE_TERRAIN }, + { 360, 5, 160, 20, button_top, 0, BUTTON_CHANGE_ZOOM }, + { 360, 25, 160, 20, button_top, 0, BUTTON_TOGGLE_ANIMATIONS }, + { 530, -40, 80, 40, button_top, 0, BUTTON_REFRESH }, + { 530, 5, 80, 40, button_top, 0, BUTTON_QUIT }, }; static generic_button toggle_animation_button = { - 0, 0, 0, 20, button_toggle_animation_frames, button_none, 0, 0 + 0, 0, 0, 20, button_toggle_animation_frames }; static const int ZOOM_VALUES[] = { 50, 100, 200, 400 }; @@ -563,10 +564,61 @@ static void draw_foreground(void) } } +static void recalculate_selected_index(void) +{ + int selected_index = list_box_get_selected_index(&list_box); + int total_entries = list_box_get_total_items(&list_box); + if (selected_index != LIST_BOX_NO_SELECTION) { + if (selected_index < total_entries) { + const asset_image *img = + asset_image_get_from_id(get_current_asset_index()); + if (img->id && strcmp(data.selected_asset_id, img->id) == 0) { + return; + } + } + for (int i = 0; i < total_entries; i++) { + const asset_image *img = + asset_image_get_from_id(data.active_group->first_image_index + data.entries[i].index); + if (img->id && data.selected_asset_id && strcmp(data.selected_asset_id, img->id) == 0) { + list_box_select_index(&list_box, i); + return; + } + } + } + if (selected_index >= total_entries) { + list_box_select_index(&list_box, total_entries - 1); + } else { + list_box_select_index(&list_box, selected_index); + } +} + +static void refresh_window(void) +{ + int asset_index = list_box_get_total_items(&list_box) > 0 ? + data.entries[list_box_get_scroll_position(&list_box)].index : 0; + int group_changed = update_asset_groups_list(); + load_assets(group_changed); + if (group_changed) { + asset_index = 0; + } + recalculate_selected_index(); + window_invalidate(); + data.last_refresh = time_get_millis(); + data.showing_refresh_info = 0; + int total_entries = list_box_get_total_items(&list_box); + for (int i = 0; i < total_entries; i++) { + if (data.entries[i].index == asset_index) { + list_box_show_index(&list_box, i); + return; + } + } + list_box_show_index(&list_box, total_entries); +} + static void handle_input(const mouse *m, const hotkeys *h) { if (h->f5_pressed) { - button_top(BUTTON_REFRESH, 0); + refresh_window(); } if (list_box_handle_input(&list_box, m, 0)) { return; @@ -639,73 +691,22 @@ static void confirm_exit(int accepted, int checked) } } -static void recalculate_selected_index(void) -{ - int selected_index = list_box_get_selected_index(&list_box); - int total_entries = list_box_get_total_items(&list_box); - if (selected_index != LIST_BOX_NO_SELECTION) { - if (selected_index < total_entries) { - const asset_image *img = - asset_image_get_from_id(get_current_asset_index()); - if (img->id && strcmp(data.selected_asset_id, img->id) == 0) { - return; - } - } - for (int i = 0; i < total_entries; i++) { - const asset_image *img = - asset_image_get_from_id(data.active_group->first_image_index + data.entries[i].index); - if (img->id && data.selected_asset_id && strcmp(data.selected_asset_id, img->id) == 0) { - list_box_select_index(&list_box, i); - return; - } - } - } - if (selected_index >= total_entries) { - list_box_select_index(&list_box, total_entries - 1); - } else { - list_box_select_index(&list_box, selected_index); - } -} - -static void refresh_window(void) -{ - int asset_index = list_box_get_total_items(&list_box) > 0 ? - data.entries[list_box_get_scroll_position(&list_box)].index : 0; - int group_changed = update_asset_groups_list(); - load_assets(group_changed); - if (group_changed) { - asset_index = 0; - } - recalculate_selected_index(); - window_invalidate(); - data.last_refresh = time_get_millis(); - data.showing_refresh_info = 0; - int total_entries = list_box_get_total_items(&list_box); - for (int i = 0; i < total_entries; i++) { - if (data.entries[i].index == asset_index) { - list_box_show_index(&list_box, i); - return; - } - } - list_box_show_index(&list_box, total_entries); -} - -static void button_top(int option, int param2) +static void button_top(const generic_button *button) { - generic_button *btn = &buttons[option]; + int option = button->parameter1; switch (option) { case BUTTON_CHANGE_ASSET_GROUP: if (data.xml_files->num_files > 0) { - window_select_list_show_text(btn->x + data.x_offset_top + 16, btn->y + 60 + btn->height, + window_select_list_show_text(button->x + data.x_offset_top + 16, button->y + 60 + button->height, data.xml_file_names, data.xml_files->num_files, change_asset_group); } return; case BUTTON_CHANGE_TERRAIN: - window_select_list_show_text(btn->x + data.x_offset_top + 16, btn->y + 60 + btn->height, + window_select_list_show_text(button->x + data.x_offset_top + 16, button->y + 60 + button->height, data.terrain_texts, TERRAIN_MAX, set_terrain); return; case BUTTON_CHANGE_ZOOM: - window_select_list_show_text(btn->x + data.x_offset_top + 16, btn->y + 60 + btn->height, + window_select_list_show_text(button->x + data.x_offset_top + 16, button->y + 60 + button->height, data.zoom_texts, TOTAL_ZOOM_VALUES, set_zoom); return; case BUTTON_TOGGLE_ANIMATIONS: @@ -726,7 +727,7 @@ static void button_top(int option, int param2) } } -static void button_toggle_animation_frames(int param1, int param2) +static void button_toggle_animation_frames(const generic_button *button) { data.hide_animation_frames ^= 1; int asset_index = 0; diff --git a/src/window/build_menu.c b/src/window/build_menu.c index 75236f5fcf..8268f9b3f3 100644 --- a/src/window/build_menu.c +++ b/src/window/build_menu.c @@ -40,40 +40,40 @@ static uint8_t tooltip_text[TOOLTIP_TEXT_LENGTH]; -static void button_menu_index(int param1, int param2); +static void button_menu_index(const generic_button *button); static void button_menu_item(int item); static generic_button build_menu_buttons[] = { - {0, 0, 290, 20, button_menu_index, button_none, 1, 0}, - {0, 24, 290, 20, button_menu_index, button_none, 2, 0}, - {0, 48, 290, 20, button_menu_index, button_none, 3, 0}, - {0, 72, 290, 20, button_menu_index, button_none, 4, 0}, - {0, 96, 290, 20, button_menu_index, button_none, 5, 0}, - {0, 120, 290, 20, button_menu_index, button_none, 6, 0}, - {0, 144, 290, 20, button_menu_index, button_none, 7, 0}, - {0, 168, 290, 20, button_menu_index, button_none, 8, 0}, - {0, 192, 290, 20, button_menu_index, button_none, 9, 0}, - {0, 216, 290, 20, button_menu_index, button_none, 10, 0}, - {0, 240, 290, 20, button_menu_index, button_none, 11, 0}, - {0, 264, 290, 20, button_menu_index, button_none, 12, 0}, - {0, 288, 290, 20, button_menu_index, button_none, 13, 0}, - {0, 312, 290, 20, button_menu_index, button_none, 14, 0}, - {0, 336, 290, 20, button_menu_index, button_none, 15, 0}, - {0, 360, 290, 20, button_menu_index, button_none, 16, 0}, - {0, 384, 290, 20, button_menu_index, button_none, 17, 0}, - {0, 408, 290, 20, button_menu_index, button_none, 18, 0}, - {0, 432, 290, 20, button_menu_index, button_none, 19, 0}, - {0, 456, 290, 20, button_menu_index, button_none, 20, 0}, - {0, 480, 290, 20, button_menu_index, button_none, 21, 0}, - {0, 504, 290, 20, button_menu_index, button_none, 22, 0}, - {0, 528, 290, 20, button_menu_index, button_none, 23, 0}, - {0, 552, 290, 20, button_menu_index, button_none, 24, 0}, - {0, 576, 290, 20, button_menu_index, button_none, 25, 0}, - {0, 600, 290, 20, button_menu_index, button_none, 26, 0}, - {0, 624, 290, 20, button_menu_index, button_none, 27, 0}, - {0, 648, 290, 20, button_menu_index, button_none, 28, 0}, - {0, 672, 290, 20, button_menu_index, button_none, 29, 0}, - {0, 696, 290, 20, button_menu_index, button_none, 30, 0}, + {0, 0, 290, 20, button_menu_index, 0, 1}, + {0, 24, 290, 20, button_menu_index, 0, 2}, + {0, 48, 290, 20, button_menu_index, 0, 3}, + {0, 72, 290, 20, button_menu_index, 0, 4}, + {0, 96, 290, 20, button_menu_index, 0, 5}, + {0, 120, 290, 20, button_menu_index, 0, 6}, + {0, 144, 290, 20, button_menu_index, 0, 7}, + {0, 168, 290, 20, button_menu_index, 0, 8}, + {0, 192, 290, 20, button_menu_index, 0, 9}, + {0, 216, 290, 20, button_menu_index, 0, 10}, + {0, 240, 290, 20, button_menu_index, 0, 11}, + {0, 264, 290, 20, button_menu_index, 0, 12}, + {0, 288, 290, 20, button_menu_index, 0, 13}, + {0, 312, 290, 20, button_menu_index, 0, 14}, + {0, 336, 290, 20, button_menu_index, 0, 15}, + {0, 360, 290, 20, button_menu_index, 0, 16}, + {0, 384, 290, 20, button_menu_index, 0, 17}, + {0, 408, 290, 20, button_menu_index, 0, 18}, + {0, 432, 290, 20, button_menu_index, 0, 19}, + {0, 456, 290, 20, button_menu_index, 0, 20}, + {0, 480, 290, 20, button_menu_index, 0, 21}, + {0, 504, 290, 20, button_menu_index, 0, 22}, + {0, 528, 290, 20, button_menu_index, 0, 23}, + {0, 552, 290, 20, button_menu_index, 0, 24}, + {0, 576, 290, 20, button_menu_index, 0, 25}, + {0, 600, 290, 20, button_menu_index, 0, 26}, + {0, 624, 290, 20, button_menu_index, 0, 27}, + {0, 648, 290, 20, button_menu_index, 0, 28}, + {0, 672, 290, 20, button_menu_index, 0, 29}, + {0, 696, 290, 20, button_menu_index, 0, 30}, }; static const int Y_MENU_OFFSETS[] = { @@ -284,9 +284,10 @@ static int button_index_to_submenu_item(int index) return item; } -static void button_menu_index(int param1, int param2) +static void button_menu_index(const generic_button *button) { - button_menu_item(button_index_to_submenu_item(param1 - 1)); + int index = button->parameter1 - 1; + button_menu_item(button_index_to_submenu_item(index)); } static int set_submenu_for_type(building_type type) diff --git a/src/window/building/culture.c b/src/window/building/culture.c index 3d226e24a8..7bdbc705f6 100644 --- a/src/window/building/culture.c +++ b/src/window/building/culture.c @@ -10,6 +10,7 @@ #include "city/festival.h" #include "city/finance.h" #include "city/trade_policy.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/image.h" #include "graphics/lang_text.h" @@ -27,14 +28,13 @@ #define GOD_PANTHEON 5 #define MODULE_COST 1000 -static void add_module_prompt(int param1, int param2); -static void hold_games(int param1, int param2); -static void race_bet(int param1, int param2); +static void button_add_module_prompt(const generic_button *button); +static void button_hold_games(const generic_button *button); +static void button_race_bet(const generic_button *button); +static void button_lighthouse_policy(const generic_button *button); static void draw_temple(building_info_context *c, const char *sound_file, int group_id); -static void button_lighthouse_policy(int selected_policy, int param2); - static struct { int title; int subtitle; @@ -54,27 +54,26 @@ static struct { "wavs/dock1.wav" }; -static int god_id; - static generic_button add_module_button[] = { - { 0, 0, 304, 20, add_module_prompt, button_none, 0, 0 } + { 0, 0, 304, 20, button_add_module_prompt} }; static generic_button go_to_lighthouse_action_button[] = { - {0, 0, 400, 100, button_lighthouse_policy, button_none, 0, 0} + {0, 0, 400, 100, button_lighthouse_policy} }; static generic_button race_bet_button[] = { - {0, 0, 300, 20, race_bet, button_none, 0, 0} + {0, 0, 300, 20, button_race_bet} }; static generic_button hold_games_button[] = { - { 0, 0, 300, 20, hold_games, button_none, 0, 0 } + { 0, 0, 300, 20, button_hold_games} }; static struct { unsigned int focus_button_id; int building_id; + int god_id; unsigned int lighthouse_focus_button_id; int module_choices[2]; } data; @@ -761,7 +760,7 @@ static void draw_grand_temple(building_info_context *c, const char *sound_file, { building *b = building_get(c->building_id); window_building_play_sound(c, sound_file); - god_id = temple_god_id; + data.god_id = temple_god_id; if (b->monument.phase == MONUMENT_FINISHED) { outer_panel_draw(c->x_offset, c->y_offset, c->width_blocks, c->height_blocks); c->advisor_button = ADVISOR_RELIGION; @@ -770,7 +769,7 @@ static void draw_grand_temple(building_info_context *c, const char *sound_file, window_building_draw_monument_temple_construction_process(c); } if (b->monument.upgrades) { - int module_name = temple_module_options[god_id * 2 + (b->monument.upgrades - 1)].option.header; + int module_name = temple_module_options[data.god_id * 2 + (b->monument.upgrades - 1)].option.header; text_draw_centered(translation_for(module_name), c->x_offset, c->y_offset + 12, BLOCK_SIZE * c->width_blocks, FONT_LARGE_BLACK, 0); } else { @@ -786,7 +785,7 @@ static void draw_grand_temple(building_info_context *c, const char *sound_file, height = text_draw_multiline(translation_for(bonus_desc), c->x_offset + 22, c->y_offset + 56 + extra_y, 15 * c->width_blocks, 0, FONT_NORMAL_BLACK, 0); if (b->monument.upgrades) { - int module_desc = temple_module_options[god_id * 2 + (b->monument.upgrades - 1)].option.desc; + int module_desc = temple_module_options[data.god_id * 2 + (b->monument.upgrades - 1)].option.desc; height += text_draw_multiline(translation_for(module_desc), c->x_offset + 22, c->y_offset + 66 + height + extra_y, 15 * c->width_blocks, 0, FONT_NORMAL_BLACK, 0); @@ -1188,7 +1187,7 @@ static void apply_policy(int selected_policy) city_finance_process_sundry(TRADE_POLICY_COST); } -static void button_lighthouse_policy(int param1, int param2) +static void button_lighthouse_policy(const generic_button *button) { if (building_monument_working(BUILDING_LIGHTHOUSE)) { window_option_popup_show(sea_trade_policy.title, sea_trade_policy.subtitle, @@ -1454,10 +1453,10 @@ static void generate_module_image_id(int index) temple_module_options[index].image_id); } -static void add_module_prompt(int param1, int param2) +static void button_add_module_prompt(const generic_button *button) { int num_options = 0; - int option_id = god_id * 2; + int option_id = data.god_id * 2; static option_menu_item options[2]; @@ -1478,14 +1477,14 @@ static void add_module_prompt(int param1, int param2) } } -static void hold_games(int param1, int param2) +static void button_hold_games(const generic_button *button) { if (!city_festival_games_active() && !city_festival_games_planning_time() && !city_festival_games_cooldown()) { window_hold_games_show(1); } } -static void race_bet(int param1, int param2) +static void button_race_bet(const generic_button *button) { window_race_bet_show(); } diff --git a/src/window/building/depot.c b/src/window/building/depot.c index 764394f224..560f6b8a05 100644 --- a/src/window/building/depot.c +++ b/src/window/building/depot.c @@ -8,6 +8,7 @@ #include "city/resource.h" #include "city/view.h" #include "figure/figure.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/image.h" #include "graphics/lang_text.h" @@ -19,13 +20,13 @@ #include "translation/translation.h" #include "window/building_info.h" -static void order_set_source(int param1, int param2); -static void order_set_destination(int param1, int param2); -static void order_set_resource(int param1, int param2); -static void order_set_condition_type(int param1, int param2); -static void order_set_condition_threshold(int param1, int param2); -static void set_order_resource(int depot_building_id, int resource_id); -static void set_camera_position(int building_id, int param2); +static void order_set_source(const generic_button *button); +static void order_set_destination(const generic_button *button); +static void order_set_resource(const generic_button *button); +static void order_set_condition_type(const generic_button *button); +static void order_set_condition_threshold(const generic_button *button); +static void set_order_resource(const generic_button *button); +static void set_camera_position(const generic_button *button); #define DEPOT_BUTTONS_X_OFFSET 32 #define DEPOT_BUTTONS_Y_OFFSET 204 @@ -52,82 +53,67 @@ static void on_scroll(void); static scrollbar_type scrollbar = { 0, 0, ROW_HEIGHT * MAX_VISIBLE_ROWS, 432, MAX_VISIBLE_ROWS, on_scroll, 0, 4 }; // field values will be overwritten in window_building_draw_depot_select_source_destination -static generic_button depot_select_storage_buttons[] = { - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, button_none, button_none, 0, 0}, -}; +static generic_button depot_select_storage_buttons[MAX_VISIBLE_ROWS]; static generic_button depot_view_storage_buttons[] = { - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, - {0, 0, 0, ROW_HEIGHT, set_camera_position, button_none, 0, 0}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, + {0, 0, 0, ROW_HEIGHT, set_camera_position}, }; static generic_button depot_select_resource_buttons[] = { - {18, 0, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18 + ROW_WIDTH_RESOURCE, 0, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18, ROW_HEIGHT_RESOURCE * 1, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 1, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18, ROW_HEIGHT_RESOURCE * 2, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 2, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18, ROW_HEIGHT_RESOURCE * 3, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 3, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18, ROW_HEIGHT_RESOURCE * 4, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 4, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18, ROW_HEIGHT_RESOURCE * 5, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 5, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18, ROW_HEIGHT_RESOURCE * 6, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 6, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18, ROW_HEIGHT_RESOURCE * 7, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 7, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18, ROW_HEIGHT_RESOURCE * 8, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 8, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18, ROW_HEIGHT_RESOURCE * 9, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 9, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18, ROW_HEIGHT_RESOURCE * 10, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 10, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18, ROW_HEIGHT_RESOURCE * 11, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, - {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 11, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource, button_none, 0, 0}, + {18, 0, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18 + ROW_WIDTH_RESOURCE, 0, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18, ROW_HEIGHT_RESOURCE * 1, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 1, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18, ROW_HEIGHT_RESOURCE * 2, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 2, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18, ROW_HEIGHT_RESOURCE * 3, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 3, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18, ROW_HEIGHT_RESOURCE * 4, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 4, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18, ROW_HEIGHT_RESOURCE * 5, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 5, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18, ROW_HEIGHT_RESOURCE * 6, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 6, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18, ROW_HEIGHT_RESOURCE * 7, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 7, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18, ROW_HEIGHT_RESOURCE * 8, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 8, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18, ROW_HEIGHT_RESOURCE * 9, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 9, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18, ROW_HEIGHT_RESOURCE * 10, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 10, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18, ROW_HEIGHT_RESOURCE * 11, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, + {18 + ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE * 11, ROW_WIDTH_RESOURCE, ROW_HEIGHT_RESOURCE, set_order_resource}, }; static generic_button depot_order_buttons[] = { - {100, 0, 284, 26, order_set_resource, button_none, 1, 0}, - {100, 56, 284, 22, order_set_source, button_none, 2, 0}, - {100, 82, 284, 22, order_set_destination, button_none, 3, 0}, - {100, 30, 284, 22, order_set_condition_type, button_none, 4, 0}, - {384, 30, 32, 22, order_set_condition_threshold, button_none, 5, 0}, - {384, 56, 32, 22, set_camera_position, button_none, 0, 0}, - {384, 82, 32, 22, set_camera_position, button_none, 0, 0}, + {100, 0, 284, 26, order_set_resource, 0, 1}, + {100, 56, 284, 22, order_set_source, 0, 2}, + {100, 82, 284, 22, order_set_destination, 0, 3}, + {100, 30, 284, 22, order_set_condition_type, 0, 4}, + {384, 30, 32, 22, order_set_condition_threshold, 0, 5}, + {384, 56, 32, 22, set_camera_position}, + {384, 82, 32, 22, set_camera_position}, }; static void setup_buttons_for_selected_depot(void) { for (int i = 0; i < MAX_VISIBLE_ROWS; i++) { + depot_select_storage_buttons[i].height = ROW_HEIGHT; depot_select_storage_buttons[i].parameter1 = data.depot_building_id; depot_select_storage_buttons[i].parameter2 = 0; depot_view_storage_buttons[i].parameter1 = 0; @@ -358,26 +344,26 @@ int window_building_handle_mouse_depot(const mouse *m, building_info_context *c) depot_order_buttons, 7, &data.focus_button_id); } -static void order_set_source(int param1, int param2) +static void order_set_source(const generic_button *button) { if (data.available_storages > 1) { window_building_info_depot_select_source(); } } -static void order_set_destination(int param1, int param2) +static void order_set_destination(const generic_button *button) { if (data.available_storages > 1) { window_building_info_depot_select_destination(); } } -static void order_set_condition_type(int param1, int param2) +static void order_set_condition_type(const generic_button *button) { window_building_info_depot_toggle_condition_type(); } -static void order_set_condition_threshold(int param1, int param2) +static void order_set_condition_threshold(const generic_button *button) { window_building_info_depot_toggle_condition_threshold(); } @@ -429,8 +415,11 @@ void window_building_draw_depot_select_source_destination(building_info_context } } -static void set_order_source(int depot_building_id, int building_id) +static void set_order_source(const generic_button *button) { + int depot_building_id = button->parameter1; + int building_id = button->parameter2; + if (!building_id) { return; } @@ -442,8 +431,11 @@ static void set_order_source(int depot_building_id, int building_id) window_building_info_depot_return_to_main_window(); } -static void set_order_destination(int depot_building_id, int building_id) +static void set_order_destination(const generic_button *button) { + int depot_building_id = button->parameter1; + int building_id = button->parameter2; + if (!building_id) { return; } @@ -455,8 +447,9 @@ static void set_order_destination(int depot_building_id, int building_id) window_building_info_depot_return_to_main_window(); } -static void set_camera_position(int building_id, int param2) +static void set_camera_position(const generic_button *button) { + int building_id = button->parameter1; const building *b = building_get(building_id); if (!b || b->id == 0) { return; @@ -502,7 +495,7 @@ int window_building_handle_mouse_depot_select_destination(const mouse *m, buildi return handle_mouse_depot_select_source_destination(m, c, 0); } -static void order_set_resource(int param1, int param2) +static void order_set_resource(const generic_button *button) { window_building_info_depot_select_resource(); } @@ -530,8 +523,10 @@ void window_building_depot_get_tooltip_source_destination(int *translation) } } -static void set_order_resource(int depot_building_id, int resource_id) +static void set_order_resource(const generic_button *button) { + int depot_building_id = button->parameter1; + resource_type resource_id = button->parameter2; if (resource_id >= RESOURCE_MIN && resource_id < RESOURCE_MAX && resource_is_storable(resource_id)) { building *b = building_get(depot_building_id); b->data.depot.current_order.resource_type = resource_id; diff --git a/src/window/building/distribution.c b/src/window/building/distribution.c index 8c27424c35..5521bc1469 100644 --- a/src/window/building/distribution.c +++ b/src/window/building/distribution.c @@ -21,6 +21,7 @@ #include "empire/object.h" #include "empire/trade_route.h" #include "figure/figure.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/image.h" #include "graphics/image_button.h" @@ -37,80 +38,81 @@ #include -static void go_to_orders(int param1, int param2); -static void toggle_resource_state(int index, int param2); -static void toggle_partial_resource_state(int index, int param2); -static void granary_orders(int index, int param2); -static void dock_toggle_route(int route_id, int param2); -static void warehouse_orders(int index, int param2); -static void market_orders(int index, int param2); -static void storage_toggle_permissions(int index, int param2); -static void button_stockpiling(int param1, int param2); +static void go_to_orders(const generic_button *button); +static void toggle_resource_state(const generic_button *button); +static void toggle_partial_resource_state(const generic_button *button); +static void granary_orders(const generic_button *button); +static void dock_toggle_route(const generic_button *button); +static void warehouse_orders(const generic_button *button); +static void market_orders(const generic_button *button); +static void storage_toggle_permissions(const generic_button *button); +static void button_stockpiling(const generic_button *button); +static void toggle_mantain(int param1, int param2); static void init_dock_permission_buttons(void); static void draw_dock_permission_buttons(int x_offset, int y_offset, int dock_id); static void on_scroll(void); -static void button_caravanserai_policy(int param1, int param2); +static void button_caravanserai_policy(const generic_button *button); static generic_button go_to_orders_button[] = { - {0, 0, 304, 20, go_to_orders, button_none, 0, 0} + {0, 0, 304, 20, go_to_orders} }; static generic_button orders_resource_buttons[] = { - {0, 0, 210, 22, toggle_resource_state, button_none, 1, 0}, - {0, 22, 210, 22, toggle_resource_state, button_none, 2, 0}, - {0, 44, 210, 22, toggle_resource_state, button_none, 3, 0}, - {0, 66, 210, 22, toggle_resource_state, button_none, 4, 0}, - {0, 88, 210, 22, toggle_resource_state, button_none, 5, 0}, - {0, 110, 210, 22, toggle_resource_state, button_none, 6, 0}, - {0, 132, 210, 22, toggle_resource_state, button_none, 7, 0}, - {0, 154, 210, 22, toggle_resource_state, button_none, 8, 0}, - {0, 176, 210, 22, toggle_resource_state, button_none, 9, 0}, - {0, 198, 210, 22, toggle_resource_state, button_none, 10, 0}, - {0, 220, 210, 22, toggle_resource_state, button_none, 11, 0}, - {0, 242, 210, 22, toggle_resource_state, button_none, 12, 0}, - {0, 264, 210, 22, toggle_resource_state, button_none, 13, 0}, - {0, 286, 210, 22, toggle_resource_state, button_none, 14, 0}, - {0, 308, 210, 22, toggle_resource_state, button_none, 15, 0}, - {0, 330, 210, 22, toggle_resource_state, button_none, 16, 0}, + {0, 0, 210, 22, toggle_resource_state, 0, 1}, + {0, 22, 210, 22, toggle_resource_state, 0, 2}, + {0, 44, 210, 22, toggle_resource_state, 0, 3}, + {0, 66, 210, 22, toggle_resource_state, 0, 4}, + {0, 88, 210, 22, toggle_resource_state, 0, 5}, + {0, 110, 210, 22, toggle_resource_state, 0, 6}, + {0, 132, 210, 22, toggle_resource_state, 0, 7}, + {0, 154, 210, 22, toggle_resource_state, 0, 8}, + {0, 176, 210, 22, toggle_resource_state, 0, 9}, + {0, 198, 210, 22, toggle_resource_state, 0, 10}, + {0, 220, 210, 22, toggle_resource_state, 0, 11}, + {0, 242, 210, 22, toggle_resource_state, 0, 12}, + {0, 264, 210, 22, toggle_resource_state, 0, 13}, + {0, 286, 210, 22, toggle_resource_state, 0, 14}, + {0, 308, 210, 22, toggle_resource_state, 0, 15}, + {0, 330, 210, 22, toggle_resource_state, 0, 16}, }; static generic_button orders_partial_resource_buttons[] = { - {210, 0, 28, 22, toggle_partial_resource_state, button_none, 1, 0}, - {210, 22, 28, 22, toggle_partial_resource_state, button_none, 2, 0}, - {210, 44, 28, 22, toggle_partial_resource_state, button_none, 3, 0}, - {210, 66, 28, 22, toggle_partial_resource_state, button_none, 4, 0}, - {210, 88, 28, 22, toggle_partial_resource_state, button_none, 5, 0}, - {210, 110, 28, 22, toggle_partial_resource_state, button_none, 6, 0}, - {210, 132, 28, 22, toggle_partial_resource_state, button_none, 7, 0}, - {210, 154, 28, 22, toggle_partial_resource_state, button_none, 8, 0}, - {210, 176, 28, 22, toggle_partial_resource_state, button_none, 9, 0}, - {210, 198, 28, 22, toggle_partial_resource_state, button_none, 10, 0}, - {210, 220, 28, 22, toggle_partial_resource_state, button_none, 11, 0}, - {210, 242, 28, 22, toggle_partial_resource_state, button_none, 12, 0}, - {210, 264, 28, 22, toggle_partial_resource_state, button_none, 13, 0}, - {210, 286, 28, 22, toggle_partial_resource_state, button_none, 14, 0}, - {210, 308, 28, 22, toggle_partial_resource_state, button_none, 15, 0}, - {210, 330, 28, 22, toggle_partial_resource_state, button_none, 16, 0}, + {210, 0, 28, 22, toggle_partial_resource_state, 0, 1}, + {210, 22, 28, 22, toggle_partial_resource_state, 0, 2}, + {210, 44, 28, 22, toggle_partial_resource_state, 0, 3}, + {210, 66, 28, 22, toggle_partial_resource_state, 0, 4}, + {210, 88, 28, 22, toggle_partial_resource_state, 0, 5}, + {210, 110, 28, 22, toggle_partial_resource_state, 0, 6}, + {210, 132, 28, 22, toggle_partial_resource_state, 0, 7}, + {210, 154, 28, 22, toggle_partial_resource_state, 0, 8}, + {210, 176, 28, 22, toggle_partial_resource_state, 0, 9}, + {210, 198, 28, 22, toggle_partial_resource_state, 0, 10}, + {210, 220, 28, 22, toggle_partial_resource_state, 0, 11}, + {210, 242, 28, 22, toggle_partial_resource_state, 0, 12}, + {210, 264, 28, 22, toggle_partial_resource_state, 0, 13}, + {210, 286, 28, 22, toggle_partial_resource_state, 0, 14}, + {210, 308, 28, 22, toggle_partial_resource_state, 0, 15}, + {210, 330, 28, 22, toggle_partial_resource_state, 0, 16}, }; static generic_button warehouse_distribution_permissions_buttons[] = { - {0, 0, 52, 52, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_MARKET, 0}, - {62, 0, 52, 52, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_TRADERS, 0}, - {124, 0, 52, 52, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_DOCK, 0}, - {186, 0, 52, 52, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_BARKEEP, 0}, - {248, 0, 52, 52, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_WORKCAMP, 0}, - {310, 0, 52, 52, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_ARMOURY, 0}, - {372, 0, 52, 52, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_LIGHTHOUSE, 0}, + {0, 0, 52, 52, storage_toggle_permissions, 0, BUILDING_STORAGE_PERMISSION_MARKET}, + {62, 0, 52, 52, storage_toggle_permissions, 0, BUILDING_STORAGE_PERMISSION_TRADERS}, + {124, 0, 52, 52, storage_toggle_permissions, 0, BUILDING_STORAGE_PERMISSION_DOCK}, + {186, 0, 52, 52, storage_toggle_permissions, 0, BUILDING_STORAGE_PERMISSION_BARKEEP}, + {248, 0, 52, 52, storage_toggle_permissions, 0, BUILDING_STORAGE_PERMISSION_WORKCAMP}, + {310, 0, 52, 52, storage_toggle_permissions, 0, BUILDING_STORAGE_PERMISSION_ARMOURY}, + {372, 0, 52, 52, storage_toggle_permissions, 0, BUILDING_STORAGE_PERMISSION_LIGHTHOUSE}, }; static generic_button granary_distribution_permissions_buttons[] = { - {0, 0, 52, 52, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_MARKET, 0}, - {76, 0, 52, 52, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_TRADERS, 0}, - {152, 0, 52, 52, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_DOCK, 0}, - {228, 0, 52, 52, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_BARKEEP, 0}, - {304, 0, 52, 52, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_QUARTERMASTER, 0}, - {380, 0, 52, 52, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_CARAVANSERAI, 0}, + {0, 0, 52, 52, storage_toggle_permissions, 0, BUILDING_STORAGE_PERMISSION_MARKET}, + {76, 0, 52, 52, storage_toggle_permissions, 0, BUILDING_STORAGE_PERMISSION_TRADERS}, + {152, 0, 52, 52, storage_toggle_permissions, 0, BUILDING_STORAGE_PERMISSION_DOCK}, + {228, 0, 52, 52, storage_toggle_permissions, 0, BUILDING_STORAGE_PERMISSION_BARKEEP}, + {304, 0, 52, 52, storage_toggle_permissions, 0, BUILDING_STORAGE_PERMISSION_QUARTERMASTER}, + {380, 0, 52, 52, storage_toggle_permissions, 0, BUILDING_STORAGE_PERMISSION_CARAVANSERAI}, }; static generic_button dock_distribution_permissions_buttons[20]; @@ -120,26 +122,26 @@ static unsigned int dock_distribution_permissions_buttons_count; static scrollbar_type scrollbar = { .on_scroll_callback = on_scroll }; static generic_button granary_order_buttons[] = { - {0, 0, 304, 20, granary_orders, button_none, 0, 0}, - {314, 0, 20, 20, granary_orders, button_none, 1, 0}, + {0, 0, 304, 20, granary_orders}, + {314, 0, 20, 20, granary_orders, 0, 1}, }; static generic_button market_order_buttons[] = { - {314, 0, 20, 20, market_orders, button_none, 0, 0}, + {314, 0, 20, 20, market_orders}, }; static generic_button warehouse_order_buttons[] = { - {0, 0, 304, 20, warehouse_orders, button_none, 0, 0}, - {314, 0, 20, 20, warehouse_orders, button_none, 1, 0}, + {0, 0, 304, 20, warehouse_orders}, + {314, 0, 20, 20, warehouse_orders, 0, 1}, }; static generic_button go_to_caravanserai_action_button[] = { - {0, 0, 400, 100, button_caravanserai_policy, button_none, 0, 0} + {0, 0, 400, 100, button_caravanserai_policy} }; static image_button image_buttons_maintain[] = { - {0, 0, 30, 19, IB_NORMAL, 0, 0, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_WORKER, 0, 1, "UI", "Maintain_1"}, - {0, 0, 30, 19, IB_NORMAL, 0, 0, storage_toggle_permissions, button_none, BUILDING_STORAGE_PERMISSION_WORKER, 0, 1, "UI", "Stop_Maintain_1"}, + {0, 0, 30, 19, IB_NORMAL, 0, 0, toggle_mantain, button_none, 0, 0, 1, "UI", "Maintain_1"}, + {0, 0, 30, 19, IB_NORMAL, 0, 0, toggle_mantain, button_none, 0, 0, 1, "UI", "Stop_Maintain_1"}, }; static struct { @@ -162,7 +164,7 @@ static struct { }; static generic_button primary_product_producer_button_stockpiling[] = { - {0, 0, 24, 24, button_stockpiling, button_none, 0, 0} + {0, 0, 24, 24, button_stockpiling, 0, 0, 0} }; static struct { @@ -319,7 +321,7 @@ static void init_dock_permission_buttons(void) if (is_sea_trade_route(route_id) && empire_city_is_trade_route_open(route_id)) { city_id = empire_city_get_for_trade_route(route_id); if (city_id != -1) { - generic_button button = { 0, 0, 210, 22, dock_toggle_route, button_none, route_id, city_id }; + generic_button button = { 0, 0, 210, 22, dock_toggle_route, 0, route_id, city_id }; dock_distribution_permissions_buttons[dock_distribution_permissions_buttons_count] = button; dock_distribution_permissions_buttons_count++; } @@ -1329,13 +1331,14 @@ static void on_scroll(void) window_invalidate(); } -static void go_to_orders(int param1, int param2) +static void go_to_orders(const generic_button *button) { window_building_info_show_storage_orders(); } -static void toggle_resource_state(int index, int param2) +static void toggle_resource_state(const generic_button *button) { + int index = button->parameter1; building *b = building_get(data.building_id); index += scrollbar.scroll_position - 1; resource_type resource; @@ -1353,8 +1356,9 @@ static void toggle_resource_state(int index, int param2) window_invalidate(); } -static void market_orders(int index, int param2) +static void market_orders(const generic_button *button) { + int index = button->parameter1; building *b = building_get(data.building_id); if (index == 0) { if (affect_all_button_distribution_state() == ACCEPT_ALL) { @@ -1366,15 +1370,24 @@ static void market_orders(int index, int param2) window_invalidate(); } -static void storage_toggle_permissions(int index, int param2) +static void storage_toggle_permissions(const generic_button *button) { + int index = button->parameter1; building *b = building_get(data.building_id); building_storage_set_permission(index, b); window_invalidate(); } -static void toggle_partial_resource_state(int index, int param2) +static void toggle_mantain(int param1, int param2) { + building *b = building_get(data.building_id); + building_storage_set_permission(BUILDING_STORAGE_PERMISSION_WORKER, b); + window_invalidate(); +} + +static void toggle_partial_resource_state(const generic_button *button) +{ + int index = button->parameter1; building *b = building_get(data.building_id); int resource; if (b->type == BUILDING_WAREHOUSE) { @@ -1386,7 +1399,7 @@ static void toggle_partial_resource_state(int index, int param2) window_invalidate(); } -static void button_stockpiling(int param1, int param2) +static void button_stockpiling(const generic_button *button) { building *b = building_get(data.building_id); if (building_is_primary_product_producer(b->type)) { @@ -1395,15 +1408,17 @@ static void button_stockpiling(int param1, int param2) window_invalidate(); } -static void dock_toggle_route(int route_id, int param2) +static void dock_toggle_route(const generic_button *button) { + int route_id = button->parameter1; int can_trade = building_dock_can_trade_with_route(route_id, data.building_id); building_dock_set_can_trade_with_route(route_id, data.building_id, !can_trade); window_invalidate(); } -static void granary_orders(int index, int param2) +static void granary_orders(const generic_button *button) { + int index = button->parameter1; int storage_id = building_get(data.building_id)->storage_id; if (index == 0) { building_storage_toggle_empty_all(storage_id); @@ -1417,8 +1432,9 @@ static void granary_orders(int index, int param2) window_invalidate(); } -static void warehouse_orders(int index, int param2) +static void warehouse_orders(const generic_button *button) { + int index = button->parameter1; if (index == 0) { int storage_id = building_get(data.building_id)->storage_id; building_storage_toggle_empty_all(storage_id); @@ -1535,7 +1551,7 @@ static void apply_policy(int selected_policy) city_finance_process_sundry(TRADE_POLICY_COST); } -static void button_caravanserai_policy(int param1, int param2) +static void button_caravanserai_policy(const generic_button *button) { if (building_monument_working(BUILDING_CARAVANSERAI)) { window_option_popup_show(land_trade_policy.title, land_trade_policy.subtitle, diff --git a/src/window/building/figures.c b/src/window/building/figures.c index a25afb7aa1..6050c2ff68 100644 --- a/src/window/building/figures.c +++ b/src/window/building/figures.c @@ -17,6 +17,7 @@ #include "figure/trader.h" #include "figuretype/depot.h" #include "figuretype/trader.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -32,8 +33,8 @@ #define CAMEL_PORTRAIT 59 -static void select_figure(int index, int param2); -static void depot_recall(int figure_id, int param2); +static void select_figure(const generic_button *button); +static void depot_recall(const generic_button *button); static const int FIGURE_TYPE_TO_BIG_FIGURE_IMAGE[] = { 8, 4, 4, 9, 51, 13, 8, 16, 7, 4, // 0-9 @@ -56,17 +57,17 @@ static const int NEW_FIGURE_TYPES[] = { }; static generic_button figure_buttons[] = { - {26, 46, 50, 50, select_figure, button_none, 0, 0}, - {86, 46, 50, 50, select_figure, button_none, 1, 0}, - {146, 46, 50, 50, select_figure, button_none, 2, 0}, - {206, 46, 50, 50, select_figure, button_none, 3, 0}, - {266, 46, 50, 50, select_figure, button_none, 4, 0}, - {326, 46, 50, 50, select_figure, button_none, 5, 0}, - {386, 46, 50, 50, select_figure, button_none, 6, 0}, + {26, 46, 50, 50, select_figure}, + {86, 46, 50, 50, select_figure, 0, 1}, + {146, 46, 50, 50, select_figure, 0, 2}, + {206, 46, 50, 50, select_figure, 0, 3}, + {266, 46, 50, 50, select_figure, 0, 4}, + {326, 46, 50, 50, select_figure, 0, 5}, + {386, 46, 50, 50, select_figure, 0, 6}, }; static generic_button depot_figure_buttons[] = { - {90, 160, 100, 22, depot_recall, button_none, 0, 0}, + {90, 160, 100, 22, depot_recall}, }; static struct { @@ -633,8 +634,9 @@ int window_building_handle_mouse_figure_list(const mouse *m, building_info_conte return handled; } -static void select_figure(int index, int param2) +static void select_figure(const generic_button *button) { + int index = button->parameter1; data.context_for_callback->figure.selected_index = index; window_building_play_figure_phrase(data.context_for_callback); window_invalidate(); @@ -648,8 +650,9 @@ void window_building_play_figure_phrase(building_info_context *c) c->figure.phrase_id = f->phrase_id; } -static void depot_recall(int figure_id, int param2) +static void depot_recall(const generic_button *button) { + int figure_id = button->parameter1; figure_depot_recall(figure_get(figure_id)); window_city_show(); } diff --git a/src/window/building/industry.c b/src/window/building/industry.c index 0ab782e1a5..9f9cd15907 100644 --- a/src/window/building/industry.c +++ b/src/window/building/industry.c @@ -27,11 +27,11 @@ #include -static void set_city_mint_conversion(int resource, int param2); +static void set_city_mint_conversion(const generic_button *button); static generic_button mint_conversion_buttons[] = { - {0, 0, 432, 24, set_city_mint_conversion, button_none, RESOURCE_DENARII}, - {0, 24, 432, 24, set_city_mint_conversion, button_none, RESOURCE_GOLD}, + {0, 0, 432, 24, set_city_mint_conversion, 0, RESOURCE_DENARII}, + {0, 24, 432, 24, set_city_mint_conversion, 0, RESOURCE_GOLD}, }; static struct { @@ -571,8 +571,9 @@ static void city_mint_conversion_changed(int accepted, int checked) city_mint->data.industry.production_current_month = 0; } -static void set_city_mint_conversion(int resource, int param2) +static void set_city_mint_conversion(const generic_button *button) { + resource_type resource = button->parameter1; if (building_get(data.city_mint_id)->output_resource_id != resource) { window_popup_dialog_show_confirmation(translation_for(TR_BUILDING_CITY_MINT_CHANGE_PRODUCTION), translation_for(TR_BUILDING_CITY_MINT_PROGRESS_WILL_BE_LOST), 0, city_mint_conversion_changed); diff --git a/src/window/building/military.c b/src/window/building/military.c index 59d83495a6..d2b458ca79 100644 --- a/src/window/building/military.c +++ b/src/window/building/military.c @@ -12,6 +12,7 @@ #include "core/log.h" #include "core/string.h" #include "figure/formation_legion.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/image.h" #include "graphics/lang_text.h" @@ -23,35 +24,35 @@ #include "window/city.h" #include "window/building/culture.h" -static void button_return_to_fort(int param1, int param2); -static void button_layout(int index, int param2); -static void button_priority(int index, int param2); -static void button_delivery(int index, int param2); +static void button_return_to_fort(const generic_button *button); +static void button_layout(const generic_button *button); +static void button_priority(const generic_button *button); +static void button_delivery(const generic_button *button); static generic_button layout_buttons[] = { - {19, 179, 84, 84, button_layout, button_none, 0, 0}, - {104, 179, 84, 84, button_layout, button_none, 1, 0}, - {189, 179, 84, 84, button_layout, button_none, 2, 0}, - {274, 179, 84, 84, button_layout, button_none, 3, 0}, - {359, 179, 84, 84, button_layout, button_none, 4, 0} + {19, 179, 84, 84, button_layout}, + {104, 179, 84, 84, button_layout, 0, 1}, + {189, 179, 84, 84, button_layout, 0, 2}, + {274, 179, 84, 84, button_layout, 0, 3}, + {359, 179, 84, 84, button_layout, 0, 4} }; static generic_button priority_buttons[] = { - {0, 0, 40, 40, button_priority, button_none, 0, 0}, - {56, 0, 40, 40, button_priority, button_none, 1, 0}, - {112, 0, 40, 40, button_priority, button_none, 2, 0}, - {168, 0, 40, 40, button_priority, button_none, 3, 0}, - {224, 0, 40, 40, button_priority, button_none, 4, 0}, - {280, 0, 40, 40, button_priority, button_none, 5, 0}, - {336, 0, 40, 40, button_priority, button_none, 6, 0}, + {0, 0, 40, 40, button_priority, 0, 0}, + {56, 0, 40, 40, button_priority, 0, 1}, + {112, 0, 40, 40, button_priority, 0, 2}, + {168, 0, 40, 40, button_priority, 0, 3}, + {224, 0, 40, 40, button_priority, 0, 4}, + {280, 0, 40, 40, button_priority, 0, 5}, + {336, 0, 40, 40, button_priority, 0, 6}, }; static generic_button delivery_buttons[] = { - {0, 0, 52, 52, button_delivery, button_none, 0, 0}, + {0, 0, 52, 52, button_delivery}, }; static generic_button return_button[] = { - {0, 0, 288, 32, button_return_to_fort, button_none, 0, 0}, + {0, 0, 288, 32, button_return_to_fort}, }; static struct { @@ -646,7 +647,7 @@ void window_building_barracks_get_tooltip_priority(int *translation) } } -static void button_return_to_fort(int param1, int param2) +static void button_return_to_fort(const generic_button *button) { formation *m = formation_get(data.context_for_callback->formation_id); if (!m->in_distant_battle && m->is_at_fort != 1) { @@ -655,8 +656,9 @@ static void button_return_to_fort(int param1, int param2) } } -static void button_layout(int index, int param2) +static void button_layout(const generic_button *button) { + int index = button->parameter1; formation *m = formation_get(data.context_for_callback->formation_id); if (m->in_distant_battle) { return; @@ -697,13 +699,14 @@ static void button_layout(int index, int param2) window_city_military_show(data.context_for_callback->formation_id); } -static void button_priority(int index, int param2) +static void button_priority(const generic_button *button) { + int index = button->parameter1; building *barracks = building_get(data.building_id); building_barracks_set_priority(barracks, index); } -static void button_delivery(int index, int param2) +static void button_delivery(const generic_button *button) { building *barracks = building_get(data.building_id); building_barracks_toggle_delivery(barracks); diff --git a/src/window/building/utility.c b/src/window/building/utility.c index 33d453e75c..c5fadb113d 100644 --- a/src/window/building/utility.c +++ b/src/window/building/utility.c @@ -6,6 +6,7 @@ #include "city/constants.h" #include "city/finance.h" #include "core/image.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/image.h" #include "graphics/lang_text.h" @@ -17,11 +18,9 @@ #include "window/building_info.h" #include "window/building/figures.h" -static void go_to_orders(int param1, int param2); -static void toggle_figure_state(int index, int param2); -static void roadblock_orders(int index, int param2); - - +static void button_go_to_orders(const generic_button *button); +static void button_toggle_figure_state(const generic_button *button); +static void button_roadblock_orders(const generic_button *button); static struct { unsigned int focus_button_id; @@ -31,24 +30,21 @@ static struct { int tooltip_id; } data = { 0, 0, 0, 0, 0 }; - - static generic_button go_to_orders_button[] = { - {0, 0, 304, 20, go_to_orders, button_none, 0, 0}, + {0, 0, 304, 20, button_go_to_orders}, }; - static generic_button orders_permission_buttons[] = { - {0, 4, 210, 22, toggle_figure_state, button_none, PERMISSION_MAINTENANCE, 0}, - {0, 36, 210, 22, toggle_figure_state, button_none, PERMISSION_PRIEST, 0}, - {0, 68, 210, 22, toggle_figure_state, button_none, PERMISSION_MARKET, 0}, - {0, 100, 210, 22, toggle_figure_state, button_none, PERMISSION_ENTERTAINER, 0}, - {0, 132, 210, 22, toggle_figure_state, button_none, PERMISSION_EDUCATION, 0}, - {0, 164, 210, 22, toggle_figure_state, button_none, PERMISSION_MEDICINE, 0}, - {0, 192, 210, 22, toggle_figure_state, button_none, PERMISSION_TAX_COLLECTOR, 0}, - {0, 224, 210, 22, toggle_figure_state, button_none, PERMISSION_LABOR_SEEKER, 0}, - {0, 256, 210, 22, toggle_figure_state, button_none, PERMISSION_MISSIONARY, 0}, - {0, 288, 210, 22, toggle_figure_state, button_none, PERMISSION_WATCHMAN, 0}, + {0, 4, 210, 22, button_toggle_figure_state, 0, PERMISSION_MAINTENANCE}, + {0, 36, 210, 22, button_toggle_figure_state, 0, PERMISSION_PRIEST}, + {0, 68, 210, 22, button_toggle_figure_state, 0, PERMISSION_MARKET}, + {0, 100, 210, 22, button_toggle_figure_state, 0, PERMISSION_ENTERTAINER}, + {0, 132, 210, 22, button_toggle_figure_state, 0, PERMISSION_EDUCATION}, + {0, 164, 210, 22, button_toggle_figure_state, 0, PERMISSION_MEDICINE}, + {0, 192, 210, 22, button_toggle_figure_state, 0, PERMISSION_TAX_COLLECTOR}, + {0, 224, 210, 22, button_toggle_figure_state, 0, PERMISSION_LABOR_SEEKER}, + {0, 256, 210, 22, button_toggle_figure_state, 0, PERMISSION_MISSIONARY}, + {0, 288, 210, 22, button_toggle_figure_state, 0, PERMISSION_WATCHMAN}, }; static int permission_tooltip_translations[] = { 0, @@ -63,7 +59,7 @@ static int permission_orders_tooltip_translations[] = { TR_TOOLTIP_BUTTON_ROADBLOCK_ORDER_REJECT_ALL, TR_TOOLTIP_BUTTON_ROADBLOCK_ORDER_ACCEPT_ALL }; static generic_button roadblock_orders_buttons[] = { - {309, 0, 20, 20, roadblock_orders, button_none, 1, 0 }, + {309, 0, 20, 20, button_roadblock_orders}, }; static unsigned int size_of_orders_permission_buttons = sizeof(orders_permission_buttons) / sizeof(*orders_permission_buttons); @@ -73,8 +69,6 @@ typedef enum { ACCEPT_ALL = 1, } affect_all_button_current_state; - - void window_building_draw_engineers_post(building_info_context *c) { c->advisor_button = ADVISOR_CHIEF; @@ -395,8 +389,9 @@ void window_building_draw_highway(building_info_context *c) window_building_draw_levy(HIGHWAY_LEVY_MONTHLY, c->x_offset + 30, c->y_offset + BLOCK_SIZE * c->height_blocks - 110); } -static void toggle_figure_state(int index, int param2) +static void button_toggle_figure_state(const generic_button *button) { + int index = button->parameter1; building *b = building_get(data.building_id); if (building_type_is_roadblock(b->type)) { building_roadblock_set_permission(index, b); @@ -406,7 +401,7 @@ static void toggle_figure_state(int index, int param2) -static void roadblock_orders(int index, int param2) +static void button_roadblock_orders(const generic_button *button) { building *b = building_get(data.building_id); if (affect_all_button_state() == REJECT_ALL) { @@ -418,7 +413,7 @@ static void roadblock_orders(int index, int param2) } -static void go_to_orders(int param1, int param2) +static void button_go_to_orders(const generic_button *button) { window_building_info_show_storage_orders(); } diff --git a/src/window/building_info.c b/src/window/building_info.c index bb4df40aa5..192af10eb0 100644 --- a/src/window/building_info.c +++ b/src/window/building_info.c @@ -18,6 +18,7 @@ #include "figure/roamer_preview.h" #include "figure/phrase.h" #include "game/state.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/image.h" #include "graphics/image_button.h" @@ -54,7 +55,7 @@ static void button_help(int param1, int param2); static void button_close(int param1, int param2); static void button_advisor(int advisor, int param2); static void button_mothball(int mothball, int param2); -static void button_monument_construction(int param1, int param2); +static void button_monument_construction(const generic_button *button); static image_button image_buttons_help_advisor_close[] = { {14, 3, 24, 24, IB_NORMAL, GROUP_CONTEXT_ICONS, 0, button_help, button_none, 0, 0, 1}, @@ -68,7 +69,7 @@ static image_button image_button_mothball[] = { }; static generic_button generic_button_monument_construction[] = { - {80, 3, 304, 24, button_monument_construction, button_none, 0, 0} + {80, 3, 304, 24, button_monument_construction} }; static building_info_context context; @@ -1144,7 +1145,7 @@ static void button_mothball(int param1, int param2) } } -static void button_monument_construction(int param1, int param2) +static void button_monument_construction(const generic_button *button) { building *b = building_get(context.building_id); building_monument_toggle_construction_halted(b); diff --git a/src/window/cck_selection.c b/src/window/cck_selection.c index 96e1cf7339..6b006ded2d 100644 --- a/src/window/cck_selection.c +++ b/src/window/cck_selection.c @@ -34,7 +34,7 @@ static void select_scenario(unsigned int index, int is_double_click); static void button_start_scenario(int param1, int param2); static void button_back(int param1, int param2); -static void button_toggle_minimap(int param1, int param2); +static void button_toggle_minimap(const generic_button *button); static void draw_scenario_item(const list_box_item *item); static void file_tooltip(const list_box_item *item, tooltip_context *c); @@ -44,7 +44,7 @@ static image_button start_button = static image_button back_button = { 330, 440, 39, 26, IB_NORMAL, GROUP_OK_CANCEL_SCROLL_BUTTONS, 4, button_back, button_none, 1, 0, 1 }; static generic_button toggle_minimap_button = -{ 570, 87, 39, 28, button_toggle_minimap, button_none, 0, 0 }; +{ 570, 87, 39, 28, button_toggle_minimap }; static list_box_type list_box = { .x = 16, @@ -298,7 +298,7 @@ static void button_start_scenario(int param1, int param2) window_mission_briefing_show(); } -static void button_toggle_minimap(int param1, int param2) +static void button_toggle_minimap(const generic_button *button) { data.show_minimap = !data.show_minimap; window_invalidate(); diff --git a/src/window/config.c b/src/window/config.c index 84a8909e48..d31aadc48c 100644 --- a/src/window/config.c +++ b/src/window/config.c @@ -57,13 +57,13 @@ static void on_scroll(void); static void toggle_switch(int key); -static void button_language_select(int height, int param2); -static void button_edit_player_name(int param1, int param2); -static void button_change_user_directory(int param1, int param2); -static void button_reset_defaults(int param1, int param2); -static void button_hotkeys(int param1, int param2); -static void button_close(int save, int param2); -static void button_page(int page, int param2); +static void button_language_select(const generic_button *button); +static void button_edit_player_name(const generic_button *button); +static void button_change_user_directory(const generic_button *button); +static void button_reset_defaults(const generic_button *button); +static void button_hotkeys(const generic_button *button); +static void button_close(const generic_button *button); +static void button_page(const generic_button *button); static const uint8_t *display_text_language(void); static const uint8_t *display_text_user_directory(void); @@ -272,9 +272,9 @@ static const int game_speeds[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, static resolution available_resolutions[sizeof(resolutions) / sizeof(resolution) + 2]; static generic_button select_buttons[] = { - {225, 0, 200, 24, button_language_select, button_none}, - {225, 0, 200, 24, button_edit_player_name, button_none}, - {225, 0, 200, 24, button_change_user_directory, button_none}, + {225, 0, 200, 24, button_language_select}, + {225, 0, 200, 24, button_edit_player_name}, + {225, 0, 200, 24, button_change_user_directory}, }; static numerical_range_widget ranges[] = { @@ -294,18 +294,18 @@ static numerical_range_widget ranges[] = { }; static generic_button bottom_buttons[NUM_BOTTOM_BUTTONS] = { - { 20, 436, 120, 30, button_hotkeys, button_none, 0, TR_BUTTON_CONFIGURE_HOTKEYS }, - { 170, 436, 150, 30, button_reset_defaults, button_none, 0, TR_BUTTON_RESET_DEFAULTS }, - { 330, 436, 90, 30, button_close, button_none, 0, TR_BUTTON_CANCEL }, - { 430, 436, 90, 30, button_close, button_none, 1, TR_BUTTON_OK }, - { 530, 436, 90, 30, button_close, button_none, 2, TR_OPTION_MENU_APPLY } + { 20, 436, 120, 30, button_hotkeys, 0, 0, TR_BUTTON_CONFIGURE_HOTKEYS }, + { 170, 436, 150, 30, button_reset_defaults, 0, 0, TR_BUTTON_RESET_DEFAULTS }, + { 330, 436, 90, 30, button_close, 0, 0, TR_BUTTON_CANCEL }, + { 430, 436, 90, 30, button_close, 0, 1, TR_BUTTON_OK }, + { 530, 436, 90, 30, button_close, 0, 2, TR_OPTION_MENU_APPLY } }; static generic_button page_buttons[] = { - { 0, 48, 0, 30, button_page, button_none, 0 }, - { 0, 48, 0, 30, button_page, button_none, 1 }, - { 0, 48, 0, 30, button_page, button_none, 2 }, - { 0, 48, 0, 30, button_page, button_none, 3 }, + { 0, 48, 0, 30, button_page, 0, 0 }, + { 0, 48, 0, 30, button_page, 0, 1 }, + { 0, 48, 0, 30, button_page, 0, 2 }, + { 0, 48, 0, 30, button_page, 0, 3 }, }; static translation_key page_names[CONFIG_PAGES] = { @@ -1086,17 +1086,18 @@ static void set_language(int index) data.language_options.selected = index; } -static void button_hotkeys(int param1, int param2) +static void button_hotkeys(const generic_button *button) { window_hotkey_config_show(); } -static void button_language_select(int height, int param2) +static void button_language_select(const generic_button *button) { - const generic_button *btn = &select_buttons[SELECT_LANGUAGE]; + int height = button->parameter1; + window_select_list_show_text( - screen_dialog_offset_x() + btn->x, - screen_dialog_offset_y() + height + btn->height, + screen_dialog_offset_x() + button->x, + screen_dialog_offset_y() + height + button->height, data.language_options.options, data.language_options.total, set_language ); } @@ -1113,7 +1114,7 @@ static void set_player_name(const uint8_t *name) window_invalidate(); } -static void button_edit_player_name(int param1, int param2) +static void button_edit_player_name(const generic_button *button) { uint8_t player_name[PLAYER_NAME_LENGTH]; encoding_from_utf8(data.config_string_values[CONFIG_STRING_ORIGINAL_PLAYER_NAME].new_value, @@ -1122,12 +1123,12 @@ static void button_edit_player_name(int param1, int param2) PLAYER_NAME_LENGTH, set_player_name); } -static void button_change_user_directory(int param1, int param2) +static void button_change_user_directory(const generic_button *button) { window_user_path_setup_show(0); } -static void button_reset_defaults(int param1, int param2) +static void button_reset_defaults(const generic_button *button) { for (int i = 0; i < CONFIG_MAX_ENTRIES; ++i) { data.config_values[i].new_value = config_get_default_value(i); @@ -1443,8 +1444,10 @@ static int apply_changed_configs(void) return 1; } -static void button_close(int save, int param2) +static void button_close(const generic_button *button) { + int save = button->parameter1; + if (!save) { cancel_values(); window_go_back(); @@ -1458,8 +1461,9 @@ static void button_close(int save, int param2) window_request_refresh(); } -static void button_page(int page, int param2) +static void button_page(const generic_button *button) { + int page = button->parameter1; set_page(page); window_invalidate(); } diff --git a/src/window/donate_to_city.c b/src/window/donate_to_city.c index 682d2225ae..a1811ae246 100644 --- a/src/window/donate_to_city.c +++ b/src/window/donate_to_city.c @@ -4,6 +4,7 @@ #include "core/calc.h" #include "game/resource.h" #include "graphics/arrow_button.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -14,19 +15,19 @@ #include "input/input.h" #include "window/advisors.h" -static void button_set_amount(int amount_id, int param2); -static void button_donate(int param1, int param2); -static void button_cancel(int param1, int param2); +static void button_set_amount(const generic_button *button); +static void button_donate(const generic_button *button); +static void button_cancel(const generic_button *button); static void arrow_button_amount(int is_down, int param2); static generic_button buttons[] = { - {336, 283, 160, 20, button_cancel, button_none, 0, 0}, - {144, 283, 160, 20, button_donate, button_none, 0, 0}, - {128, 216, 64, 20, button_set_amount, button_none, 0, 0}, - {208, 216, 64, 20, button_set_amount, button_none, 1, 0}, - {288, 216, 64, 20, button_set_amount, button_none, 2, 0}, - {368, 216, 64, 20, button_set_amount, button_none, 3, 0}, - {448, 216, 64, 20, button_set_amount, button_none, 4, 0}, + {336, 283, 160, 20, button_cancel}, + {144, 283, 160, 20, button_donate}, + {128, 216, 64, 20, button_set_amount}, + {208, 216, 64, 20, button_set_amount, 0, 1}, + {288, 216, 64, 20, button_set_amount, 0, 2}, + {368, 216, 64, 20, button_set_amount, 0, 3}, + {448, 216, 64, 20, button_set_amount, 0, 4}, }; static arrow_button arrow_buttons[] = { @@ -107,8 +108,9 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_set_amount(int amount_id, int param2) +static void button_set_amount(const generic_button *button) { + int amount_id = button->parameter1; int amount; switch (amount_id) { case 0: amount = 0; break; @@ -122,13 +124,13 @@ static void button_set_amount(int amount_id, int param2) window_invalidate(); } -static void button_donate(int param1, int param2) +static void button_donate(const generic_button *button) { city_emperor_donate_savings_to_city(); window_advisors_show(); } -static void button_cancel(int param1, int param2) +static void button_cancel(const generic_button *button) { window_advisors_show(); } diff --git a/src/window/editor/attributes.c b/src/window/editor/attributes.c index 1ceb2e7827..c6f8ee1c8d 100644 --- a/src/window/editor/attributes.c +++ b/src/window/editor/attributes.c @@ -40,47 +40,47 @@ #define BRIEF_DESC_LENGTH 64 -static void button_starting_conditions(int param1, int param2); -static void button_requests(int param1, int param2); -static void button_enemy(int param1, int param2); -static void button_invasions(int param1, int param2); -static void button_allowed_buildings(int param1, int param2); -static void button_win_criteria(int param1, int param2); -static void button_special_events(int param1, int param2); -static void button_price_changes(int param1, int param2); -static void button_demand_changes(int param1, int param2); -static void button_scenario_events(int param1, int param2); -static void button_custom_messages(int param1, int param2); -static void button_change_intro(int param1, int param2); -static void button_delete_intro(int param1, int param2); -static void button_change_victory(int param1, int param2); -static void button_delete_victory(int param1, int param2); -static void button_return_to_city(int param1, int param2); -static void change_climate(int param1, int param2); -static void change_image(int forward, int param2); +static void button_starting_conditions(const generic_button *button); +static void button_requests(const generic_button *button); +static void button_enemy(const generic_button *button); +static void button_invasions(const generic_button *button); +static void button_allowed_buildings(const generic_button *button); +static void button_win_criteria(const generic_button *button); +static void button_special_events(const generic_button *button); +static void button_price_changes(const generic_button *button); +static void button_demand_changes(const generic_button *button); +static void button_scenario_events(const generic_button *button); +static void button_custom_messages(const generic_button *button); +static void button_change_intro(const generic_button *button); +static void button_delete_intro(const generic_button *button); +static void button_change_victory(const generic_button *button); +static void button_delete_victory(const generic_button *button); +static void button_return_to_city(const generic_button *button); +static void button_change_climate(const generic_button *button); +static void button_change_image(int forward, int param2); static generic_button buttons[] = { - {212, 76, 250, 30, button_starting_conditions, button_none, 1, 0}, - {212, 116, 250, 30, change_climate, button_none, 2, 0}, - {212, 156, 250, 30, button_requests, button_none, 3, 0}, - {212, 196, 250, 30, button_enemy, button_none, 4, 0}, - {212, 236, 250, 30, button_invasions, button_none, 5, 0}, - {212, 276, 250, 30, button_allowed_buildings, button_none, 6, 0}, - {212, 316, 250, 30, button_win_criteria, button_none, 7, 0}, - {212, 356, 250, 30, button_special_events, button_none, 8, 0}, - {212, 396, 250, 30, button_price_changes, button_none, 9, 0}, - {212, 436, 250, 30, button_demand_changes, button_none, 10, 0}, - {470, 76, 250, 30, button_scenario_events, button_none, 11, 0}, - {470, 116, 250, 30, button_custom_messages, button_none, 12, 0}, - {470, 156, 250, 30, button_change_intro, button_delete_intro, 13, 0}, - {470, 196, 250, 30, button_change_victory, button_delete_victory, 14, 0}, - {470, 436, 250, 30, button_return_to_city, button_none, 0, 0}, + {212, 76, 250, 30, button_starting_conditions, 0, 1}, + {212, 116, 250, 30, button_change_climate, 0, 2}, + {212, 156, 250, 30, button_requests, 0, 3}, + {212, 196, 250, 30, button_enemy, 0, 4}, + {212, 236, 250, 30, button_invasions, 0, 5}, + {212, 276, 250, 30, button_allowed_buildings, 0, 6}, + {212, 316, 250, 30, button_win_criteria, 0, 7}, + {212, 356, 250, 30, button_special_events, 0, 8}, + {212, 396, 250, 30, button_price_changes, 0, 9}, + {212, 436, 250, 30, button_demand_changes, 0, 10}, + {470, 76, 250, 30, button_scenario_events, 0, 11}, + {470, 116, 250, 30, button_custom_messages, 0, 12}, + {470, 156, 250, 30, button_change_intro, button_delete_intro, 13}, + {470, 196, 250, 30, button_change_victory, button_delete_victory, 14}, + {470, 436, 250, 30, button_return_to_city}, }; #define NUMBER_OF_BUTTONS (sizeof(buttons) / sizeof(generic_button)) static arrow_button image_arrows[] = { - {20, 424, 19, 24, change_image, 0, 0}, - {44, 424, 21, 24, change_image, 1, 0}, + {20, 424, 19, 24, button_change_image, 0, 0}, + {44, 424, 21, 24, button_change_image, 1, 0}, }; static struct { @@ -236,13 +236,13 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_starting_conditions(int param1, int param2) +static void button_starting_conditions(const generic_button *button) { stop(1); window_editor_starting_conditions_show(); } -static void button_requests(int param1, int param2) +static void button_requests(const generic_button *button) { stop(1); window_editor_requests_show(); @@ -254,61 +254,61 @@ static void set_enemy(int enemy) start(); } -static void button_enemy(int param1, int param2) +static void button_enemy(const generic_button *button) { stop(1); window_select_list_show(screen_dialog_offset_x() + 12, screen_dialog_offset_y() + 40, 37, 20, set_enemy); } -static void button_invasions(int param1, int param2) +static void button_invasions(const generic_button *button) { stop(1); window_editor_invasions_show(); } -static void button_allowed_buildings(int param1, int param2) +static void button_allowed_buildings(const generic_button *button) { stop(1); window_editor_allowed_buildings_show(); } -static void button_win_criteria(int param1, int param2) +static void button_win_criteria(const generic_button *button) { stop(1); window_editor_win_criteria_show(); } -static void button_special_events(int param1, int param2) +static void button_special_events(const generic_button *button) { stop(1); window_editor_special_events_show(); } -static void button_price_changes(int param1, int param2) +static void button_price_changes(const generic_button *button) { stop(1); window_editor_price_changes_show(); } -static void button_demand_changes(int param1, int param2) +static void button_demand_changes(const generic_button *button) { stop(1); window_editor_demand_changes_show(); } -static void button_scenario_events(int param1, int param2) +static void button_scenario_events(const generic_button *button) { stop(0); window_editor_scenario_events_show(); } -static void button_custom_messages(int param1, int param2) +static void button_custom_messages(const generic_button *button) { stop(0); window_editor_custom_messages_show(); } -static void button_change_intro(int param1, int param2) +static void button_change_intro(const generic_button *button) { stop(0); if (!scenario_editor_get_custom_message_introduction()) { @@ -319,13 +319,13 @@ static void button_change_intro(int param1, int param2) } } -static void button_delete_intro(int param1, int param2) +static void button_delete_intro(const generic_button *button) { stop(0); scenario_editor_set_custom_message_introduction(0); } -static void button_change_victory(int param1, int param2) +static void button_change_victory(const generic_button *button) { stop(0); if (!scenario_editor_get_custom_victory_message()) { @@ -336,19 +336,19 @@ static void button_change_victory(int param1, int param2) } } -static void button_delete_victory(int param1, int param2) +static void button_delete_victory(const generic_button *button) { stop(0); scenario_editor_set_custom_victory_message(0); } -static void button_return_to_city(int param1, int param2) +static void button_return_to_city(const generic_button *button) { stop(0); window_city_show(); } -static void change_climate(int param1, int param2) +static void button_change_climate(const generic_button *button) { scenario_editor_cycle_climate(); image_load_climate(scenario_property_climate(), editor_is_active(), 0, 0); @@ -356,7 +356,7 @@ static void change_climate(int param1, int param2) window_request_refresh(); } -static void change_image(int forward, int param2) +static void button_change_image(int forward, int param2) { scenario_editor_cycle_image(forward); window_request_refresh(); diff --git a/src/window/editor/build_menu.c b/src/window/editor/build_menu.c index e1e0e3cdbd..1268ab7e99 100644 --- a/src/window/editor/build_menu.c +++ b/src/window/editor/build_menu.c @@ -17,24 +17,24 @@ #define MENU_ITEM_WIDTH 160 #define MENU_CLICK_MARGIN 20 -static void button_menu_item(int index, int param2); +static void button_menu_item(const generic_button *button); static generic_button build_menu_buttons[] = { - {0, 0, 160, 20, button_menu_item, button_none, 0, 0}, - {0, 24, 160, 20, button_menu_item, button_none, 1, 0}, - {0, 48, 160, 20, button_menu_item, button_none, 2, 0}, - {0, 72, 160, 20, button_menu_item, button_none, 3, 0}, - {0, 96, 160, 20, button_menu_item, button_none, 4, 0}, - {0, 120, 160, 20, button_menu_item, button_none, 5, 0}, - {0, 144, 160, 20, button_menu_item, button_none, 6, 0}, - {0, 168, 160, 20, button_menu_item, button_none, 7, 0}, - {0, 192, 160, 20, button_menu_item, button_none, 8, 0}, - {0, 216, 160, 20, button_menu_item, button_none, 9, 0}, - {0, 240, 160, 20, button_menu_item, button_none, 10, 0}, - {0, 264, 160, 20, button_menu_item, button_none, 11, 0}, - {0, 288, 160, 20, button_menu_item, button_none, 12, 0}, - {0, 312, 160, 20, button_menu_item, button_none, 13, 0}, - {0, 336, 160, 20, button_menu_item, button_none, 14, 0} + {0, 0, 160, 20, button_menu_item}, + {0, 24, 160, 20, button_menu_item, 0, 1}, + {0, 48, 160, 20, button_menu_item, 0, 2}, + {0, 72, 160, 20, button_menu_item, 0, 3}, + {0, 96, 160, 20, button_menu_item, 0, 4}, + {0, 120, 160, 20, button_menu_item, 0, 5}, + {0, 144, 160, 20, button_menu_item, 0, 6}, + {0, 168, 160, 20, button_menu_item, 0, 7}, + {0, 192, 160, 20, button_menu_item, 0, 8}, + {0, 216, 160, 20, button_menu_item, 0, 9}, + {0, 240, 160, 20, button_menu_item, 0, 10}, + {0, 264, 160, 20, button_menu_item, 0, 11}, + {0, 288, 160, 20, button_menu_item, 0, 12}, + {0, 312, 160, 20, button_menu_item, 0, 13}, + {0, 336, 160, 20, button_menu_item, 0, 14} }; static const int Y_MENU_OFFSETS[16] = { @@ -134,8 +134,10 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_menu_item(int index, int param2) +static void button_menu_item(const generic_button *button) { + int index = button->parameter1; + widget_map_editor_clear_current_tile(); switch (data.selected_submenu) { diff --git a/src/window/editor/custom_messages.c b/src/window/editor/custom_messages.c index b652eb79ca..e165e6b68a 100644 --- a/src/window/editor/custom_messages.c +++ b/src/window/editor/custom_messages.c @@ -33,8 +33,8 @@ static void on_scroll(void); -static void button_click(int type, int param2); -static void button_event(int button_index, int param2); +static void button_click(const generic_button *button); +static void button_event(const generic_button *button); static void populate_list(int offset); static scrollbar_type scrollbar = { @@ -42,17 +42,17 @@ static scrollbar_type scrollbar = { }; static generic_button buttons[] = { - {48, MESSAGES_Y_OFFSET + (0 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, button_none, 1, 0}, - {48, MESSAGES_Y_OFFSET + (1 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, button_none, 2, 0}, - {48, MESSAGES_Y_OFFSET + (2 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, button_none, 3, 0}, - {48, MESSAGES_Y_OFFSET + (3 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, button_none, 4, 0}, - {48, MESSAGES_Y_OFFSET + (4 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, button_none, 5, 0}, - {48, MESSAGES_Y_OFFSET + (5 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, button_none, 6, 0}, - {48, MESSAGES_Y_OFFSET + (6 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, button_none, 7, 0}, - {48, MESSAGES_Y_OFFSET + (7 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, button_none, 8, 0}, - {48, MESSAGES_Y_OFFSET + (9 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, button_none, 9, 0}, - {48, MESSAGES_Y_OFFSET + (10 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, button_none, 10, 0}, - {48, MESSAGES_Y_OFFSET + (11 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, button_none, 11, 0} + {48, MESSAGES_Y_OFFSET + (0 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, 0, 1}, + {48, MESSAGES_Y_OFFSET + (1 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, 0, 2}, + {48, MESSAGES_Y_OFFSET + (2 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, 0, 3}, + {48, MESSAGES_Y_OFFSET + (3 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, 0, 4}, + {48, MESSAGES_Y_OFFSET + (4 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, 0, 5}, + {48, MESSAGES_Y_OFFSET + (5 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, 0, 6}, + {48, MESSAGES_Y_OFFSET + (6 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, 0, 7}, + {48, MESSAGES_Y_OFFSET + (7 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_event, 0, 8}, + {48, MESSAGES_Y_OFFSET + (9 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, 0, 9}, + {48, MESSAGES_Y_OFFSET + (10 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, 0, 10}, + {48, MESSAGES_Y_OFFSET + (11 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, 0, 11} }; #define MAX_BUTTONS (sizeof(buttons) / sizeof(generic_button)) @@ -139,13 +139,13 @@ static void draw_foreground(void) graphics_reset_dialog(); } -static void button_event(int button_index, int param2) +static void button_event(const generic_button *button) { - int target_index = button_index - 1; - if (!data.list[target_index]) { + int index = button->parameter1 - 1; + if (!data.list[index]) { return; }; - window_message_dialog_show_custom_message(data.list[target_index]->id, 0, 0); + window_message_dialog_show_custom_message(data.list[index]->id, 0, 0); } static void on_scroll(void) @@ -166,8 +166,10 @@ static void handle_input(const mouse *m, const hotkeys *h) populate_list(scrollbar.scroll_position); } -static void button_click(int type, int param2) +static void button_click(const generic_button *button) { + int type = button->parameter1; + if (type == 9) { window_file_dialog_show(FILE_TYPE_CUSTOM_MESSAGES, FILE_DIALOG_LOAD); } else if (type == 10) { diff --git a/src/window/editor/custom_variables.c b/src/window/editor/custom_variables.c index 58642f2c34..ea30787489 100644 --- a/src/window/editor/custom_variables.c +++ b/src/window/editor/custom_variables.c @@ -35,9 +35,9 @@ #define MAX_VARIABLE_NAME_SIZE 50 static void on_scroll(void); -static void button_variable(int button_index, int param2); -static void button_name_click(int button_index, int param2); -static void button_delete_variable(int button_index, int param2); +static void button_variable(const generic_button *button); +static void button_name_click(const generic_button *button); +static void button_delete_variable(const generic_button *button); static void populate_list(int offset); static scrollbar_type scrollbar = { @@ -45,22 +45,22 @@ static scrollbar_type scrollbar = { }; static generic_button buttons[] = { - {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (0 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 0, 1}, - {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (0 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, button_none, 0, 0}, - {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (1 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 1, 1}, - {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (1 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, button_none, 1, 0}, - {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (2 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 2, 1}, - {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (2 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, button_none, 2, 0}, - {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (3 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 3, 1}, - {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (3 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, button_none, 3, 0}, - {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (4 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 4, 1}, - {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (4 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, button_none, 4, 0}, - {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (5 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 5, 1}, - {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (5 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, button_none, 5, 0}, - {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (6 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 6, 1}, - {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (6 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, button_none, 6, 0}, - {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (7 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 7, 1}, - {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (7 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, button_none, 7, 0} + {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (0 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable}, + {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (0 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable}, + {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (1 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 1}, + {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (1 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, 0, 1}, + {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (2 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 2}, + {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (2 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, 0, 2}, + {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (3 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 3}, + {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (3 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, 0, 3}, + {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (4 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 4}, + {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (4 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, 0, 4}, + {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (5 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 5}, + {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (5 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, 0, 5}, + {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (6 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 6}, + {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (6 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, 0, 6}, + {BUTTONS_X_OFFSET_NAME, BUTTONS_Y_OFFSET + (7 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_NAME, BUTTONS_ROW_HEIGHT - 2, button_name_click, button_delete_variable, 7}, + {BUTTONS_X_OFFSET_VALUE, BUTTONS_Y_OFFSET + (7 * BUTTONS_ROW_HEIGHT), BUTTON_WIDTH_VALUE, BUTTONS_ROW_HEIGHT - 2, button_variable, 0, 7} }; #define MAX_BUTTONS (sizeof(buttons) / sizeof(generic_button)) @@ -149,8 +149,10 @@ static void set_variable_value(int value) scenario_set_custom_variable_value(data.target_variable, value); } -static void button_variable(int button_index, int param2) +static void button_variable(const generic_button *button) { + int button_index = button->parameter1; + if (data.select_only) { return; } @@ -177,8 +179,10 @@ static void show_used_event_popup_dialog(const scenario_event_t *event) TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_TEXT, 0, event_id_text); } -static void button_name_click(int button_index, int param2) +static void button_name_click(const generic_button *button) { + int button_index = button->parameter1; + if (!data.list[button_index]) { return; }; @@ -207,8 +211,10 @@ static void button_name_click(int button_index, int param2) } } -static void button_delete_variable(int button_index, int param2) +static void button_delete_variable(const generic_button *button) { + int button_index = button->parameter1; + if (data.select_only) { return; } diff --git a/src/window/editor/demand_changes.c b/src/window/editor/demand_changes.c index decd6d8561..5b0aa32843 100644 --- a/src/window/editor/demand_changes.c +++ b/src/window/editor/demand_changes.c @@ -23,7 +23,7 @@ #include static void button_demand_change(unsigned int id, unsigned int mouse_x, unsigned int mouse_y); -static void button_new_demand_change(int param0, int param1); +static void button_new_demand_change(const generic_button *button); static void draw_demand_change_button(const grid_box_item *item); typedef struct { @@ -39,7 +39,7 @@ static struct { } data; static generic_button new_demand_change_button = { - 195, 340, 250, 25, button_new_demand_change, button_none + 195, 340, 250, 25, button_new_demand_change }; static grid_box_type demand_change_buttons = { @@ -212,7 +212,7 @@ static void button_demand_change(unsigned int id, unsigned int mouse_x, unsigned window_editor_edit_demand_change_show(data.demand_changes[id]->id); } -static void button_new_demand_change(int param0, int param1) +static void button_new_demand_change(const generic_button *button) { int new_demand_change_id = scenario_demand_change_new(); if (new_demand_change_id >= 0) { diff --git a/src/window/editor/edit_demand_change.c b/src/window/editor/edit_demand_change.c index 1c5cd147f7..1e359629ad 100644 --- a/src/window/editor/edit_demand_change.c +++ b/src/window/editor/edit_demand_change.c @@ -25,22 +25,22 @@ #include #include -static void button_year(int param1, int param2); -static void button_resource(int param1, int param2); -static void button_route(int param1, int param2); -static void button_amount(int param1, int param2); -static void button_delete(int param1, int param2); -static void button_save(int param1, int param2); +static void button_year(const generic_button *button); +static void button_resource(const generic_button *button); +static void button_route(const generic_button *button); +static void button_amount(const generic_button *button); +static void button_delete(const generic_button *button); +static void button_save(const generic_button *button); #define NUM_BUTTONS (sizeof(buttons) / sizeof(generic_button)) static generic_button buttons[] = { - {30, 152, 60, 25, button_year, button_none}, - {190, 152, 120, 25, button_resource, button_none}, - {420, 152, 200, 25, button_route, button_none}, - {350, 192, 100, 25, button_amount, button_none}, - {30, 230, 250, 25, button_delete, button_none}, - {320, 230, 100, 25, button_save, button_none} + {30, 152, 60, 25, button_year}, + {190, 152, 120, 25, button_resource}, + {420, 152, 200, 25, button_route}, + {350, 192, 100, 25, button_amount}, + {30, 230, 250, 25, button_delete}, + {320, 230, 100, 25, button_save} }; static struct { @@ -166,7 +166,7 @@ static void handle_input(const mouse *m, const hotkeys *h) return; } if (input_go_back_requested(m, h)) { - button_save(0, 0); + button_save(0); } } @@ -175,7 +175,7 @@ static void set_year(int value) data.demand_change.year = value; } -static void button_year(int param1, int param2) +static void button_year(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 100, screen_dialog_offset_y() + 50, 3, 999, set_year); } @@ -185,7 +185,7 @@ static void set_resource(int value) data.demand_change.resource = data.available_resources[value]; } -static void button_resource(int param1, int param2) +static void button_resource(const generic_button *button) { static const uint8_t *resource_texts[RESOURCE_MAX]; static int total_resources = 0; @@ -208,7 +208,7 @@ static void set_route_id(int index) data.demand_change.route_id = data.route_ids[index]; } -static void button_route(int param1, int param2) +static void button_route(const generic_button *button) { window_select_list_show_text(screen_dialog_offset_x() + 200, screen_dialog_offset_y() + 50, data.route_names, data.num_routes, set_route_id); @@ -219,19 +219,19 @@ static void set_change_amount(int value) data.demand_change.amount = value; } -static void button_amount(int param1, int param2) +static void button_amount(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 100, screen_dialog_offset_y() + 50, 3, 999, set_change_amount); } -static void button_delete(int param1, int param2) +static void button_delete(const generic_button *button) { scenario_demand_change_delete(data.demand_change.id); scenario_editor_set_as_unsaved(); window_editor_demand_changes_show(); } -static void button_save(int param1, int param2) +static void button_save(const generic_button *button) { scenario_demand_change_update(&data.demand_change); scenario_editor_set_as_unsaved(); diff --git a/src/window/editor/edit_invasion.c b/src/window/editor/edit_invasion.c index aeba78027a..88dcd8fcd9 100644 --- a/src/window/editor/edit_invasion.c +++ b/src/window/editor/edit_invasion.c @@ -40,39 +40,39 @@ enum { #define BASE_Y_OFFSET 20 #define SECTION_CONTENT_LEFT_OFFSET 96 -static void button_year(int param1, int param2); -static void button_amount(int amount_type, int param2); -static void button_type(int param1, int param2); -static void button_from(int param1, int param2); -static void button_attack(int param1, int param2); -static void button_repeat_type(int repeat_type, int param2); -static void button_repeat_times(int param1, int param2); -static void button_repeat_between(int amount_type, int param2); -static void button_delete(int param1, int param2); -static void button_save(int param1, int param2); +static void button_year(const generic_button *button); +static void button_amount(const generic_button *button); +static void button_type(const generic_button *button); +static void button_from(const generic_button *button); +static void button_attack(const generic_button *button); +static void button_repeat_type(const generic_button *button); +static void button_repeat_times(const generic_button *button); +static void button_repeat_between(const generic_button *button); +static void button_delete(const generic_button *button); +static void button_save(const generic_button *button); #define NUMBER_OF_EDIT_BUTTONS (sizeof(edit_buttons) / sizeof(generic_button)) static generic_button edit_buttons[] = { - {0, 52, 60, 25, button_year, button_none}, - {80, 90, 50, 25, button_amount, button_none, AMOUNT_MIN}, - {170, 90, 50, 25, button_amount, button_none, AMOUNT_MAX}, - {0, 128, 220, 25, button_type, button_none}, - {0, 166, 220, 25, button_from, button_none, 0, DISABLE_ON_DISTANT_BATTLE }, - {0, 204, 220, 25, button_attack, button_none, 0, DISABLE_ON_DISTANT_BATTLE }, - {0, 244, 220, 20, button_repeat_type, button_none, INVASION_REPEAT_NEVER}, - {0, 274, 220, 20, button_repeat_type, button_none, INVASION_REPEAT_FOREVER}, - {0, 304, 20, 20, button_repeat_type, button_none, INVASION_REPEAT_TIMES}, - {30, 302, 190, 25, button_repeat_times, button_none}, - {80, 340, 50, 25, button_repeat_between, button_none, AMOUNT_MIN, DISABLE_ON_NO_REPEAT}, - {170, 340, 50, 25, button_repeat_between, button_none, AMOUNT_MAX, DISABLE_ON_NO_REPEAT}, + {0, 52, 60, 25, button_year}, + {80, 90, 50, 25, button_amount, 0, AMOUNT_MIN}, + {170, 90, 50, 25, button_amount, 0, AMOUNT_MAX}, + {0, 128, 220, 25, button_type}, + {0, 166, 220, 25, button_from, 0, 0, DISABLE_ON_DISTANT_BATTLE}, + {0, 204, 220, 25, button_attack, 0, 0, DISABLE_ON_DISTANT_BATTLE}, + {0, 244, 220, 20, button_repeat_type, 0, INVASION_REPEAT_NEVER}, + {0, 274, 220, 20, button_repeat_type, 0, INVASION_REPEAT_FOREVER}, + {0, 304, 20, 20, button_repeat_type, 0, INVASION_REPEAT_TIMES}, + {30, 302, 190, 25, button_repeat_times}, + {80, 340, 50, 25, button_repeat_between, 0, AMOUNT_MIN, DISABLE_ON_NO_REPEAT}, + {170, 340, 50, 25, button_repeat_between, 0, AMOUNT_MAX, DISABLE_ON_NO_REPEAT}, }; #define NUMBER_OF_BOTTOM_BUTTONS (sizeof(bottom_buttons) / sizeof(generic_button)) static generic_button bottom_buttons[] = { - {242, 378, 250, 25, button_delete, button_none}, - {508, 378, 100, 25, button_save, button_none}, + {242, 378, 250, 25, button_delete}, + {508, 378, 100, 25, button_save}, }; static struct { @@ -287,7 +287,7 @@ static void handle_input(const mouse *m, const hotkeys *h) return; } if (input_go_back_requested(m, h)) { - button_save(0, 0); + button_save(0); } } @@ -296,11 +296,10 @@ static void set_year(int value) data.invasion.year = value; } -static void button_year(int param1, int param2) +static void button_year(const generic_button *button) { - const generic_button *btn = &edit_buttons[0]; - int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + btn->x; - int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + btn->y + btn->height; + int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + button->x; + int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + button->y + button->height; window_numeric_input_show(x_offset, y_offset, 3, 999, set_year); } @@ -321,11 +320,11 @@ static void set_amount_max(int value) } } -static void button_amount(int amount_type, int param2) +static void button_amount(const generic_button *button) { - const generic_button *btn = &edit_buttons[1 + amount_type]; - int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + btn->x; - int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + btn->y + btn->height; + int amount_type = button->parameter1; + int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + button->x; + int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + button->y + button->height; window_numeric_input_show(x_offset, y_offset, 3, 200, amount_type == AMOUNT_MIN ? set_amount_min : set_amount_max); } @@ -335,11 +334,10 @@ static void set_type(int value) data.invasion.type = value == 3 ? 4 : value; } -static void button_type(int param1, int param2) +static void button_type(const generic_button *button) { - const generic_button *btn = &edit_buttons[3]; - int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + btn->x; - int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + btn->y + btn->height; + int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + button->x; + int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + button->y + button->height; window_select_list_show(x_offset, y_offset, 34, 4, set_type); } @@ -349,14 +347,13 @@ static void set_from(int value) data.invasion.from = value; } -static void button_from(int param1, int param2) +static void button_from(const generic_button *button) { if (data.invasion.type == INVASION_TYPE_DISTANT_BATTLE) { return; } - const generic_button *btn = &edit_buttons[4]; - int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + btn->x; - int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + btn->y + btn->height; + int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + button->x; + int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + button->y + button->height; window_select_list_show(x_offset, y_offset, 35, 9, set_from); } @@ -366,20 +363,20 @@ static void set_attack(int value) data.invasion.attack_type = value; } -static void button_attack(int param1, int param2) +static void button_attack(const generic_button *button) { if (data.invasion.type == INVASION_TYPE_DISTANT_BATTLE) { return; } - const generic_button *btn = &edit_buttons[5]; - int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + btn->x; - int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + btn->y + btn->height; + int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + button->x; + int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + button->y + button->height; window_select_list_show(x_offset, y_offset, 36, 5, set_attack); } -static void button_repeat_type(int repeat_type, int param2) +static void button_repeat_type(const generic_button *button) { + int repeat_type = button->parameter1; if (data.repeat_type == repeat_type) { return; } @@ -397,13 +394,12 @@ static void set_repeat_times(int value) } } -static void button_repeat_times(int param1, int param2) +static void button_repeat_times(const generic_button *button) { - const generic_button *btn = &edit_buttons[9]; - int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + btn->x; - int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + btn->y + btn->height; + int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + button->x; + int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + button->y + button->height; if (y_offset + 15 * BLOCK_SIZE > screen_height()) { - y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + btn->y - 15 * BLOCK_SIZE; + y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + button->y - 15 * BLOCK_SIZE; } window_numeric_input_bound_show(x_offset, y_offset, 3, 1, 999, set_repeat_times); @@ -425,30 +421,30 @@ static void set_repeat_interval_max(int value) } } -static void button_repeat_between(int amount_type, int param2) +static void button_repeat_between(const generic_button *button) { + int amount_type = button->parameter1; if (data.repeat_type == INVASION_REPEAT_NEVER) { return; } - const generic_button *btn = &edit_buttons[10 + amount_type]; - int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + btn->x; - int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + btn->y + btn->height; + int x_offset = screen_dialog_offset_x() + data.section_title_width + SECTION_CONTENT_LEFT_OFFSET + button->x; + int y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + button->y + button->height; if (y_offset + 15 * BLOCK_SIZE > screen_height()) { - y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + btn->y - 15 * BLOCK_SIZE; + y_offset = screen_dialog_offset_y() + BASE_Y_OFFSET + button->y - 15 * BLOCK_SIZE; } window_numeric_input_bound_show(x_offset, y_offset, 2, 3, 50, amount_type == AMOUNT_MIN ? set_repeat_interval_min : set_repeat_interval_max); } -static void button_delete(int param1, int param2) +static void button_delete(const generic_button *button) { scenario_invasion_delete(data.invasion.id); scenario_editor_set_as_unsaved(); window_editor_invasions_show(); } -static void button_save(int param1, int param2) +static void button_save(const generic_button *button) { if (data.repeat_type == INVASION_REPEAT_NEVER) { data.invasion.repeat.times = 0; diff --git a/src/window/editor/edit_price_change.c b/src/window/editor/edit_price_change.c index 549138d005..7615bfa52b 100644 --- a/src/window/editor/edit_price_change.c +++ b/src/window/editor/edit_price_change.c @@ -18,22 +18,22 @@ #include "window/numeric_input.h" #include "window/select_list.h" -static void button_year(int param1, int param2); -static void button_resource(int param1, int param2); -static void button_toggle_rise(int param1, int param2); -static void button_amount(int param1, int param2); -static void button_delete(int param1, int param2); -static void button_save(int param1, int param2); +static void button_year(const generic_button *button); +static void button_resource(const generic_button *button); +static void button_toggle_rise(const generic_button *button); +static void button_amount(const generic_button *button); +static void button_delete(const generic_button *button); +static void button_save(const generic_button *button); #define NUM_BUTTONS (sizeof(buttons) / sizeof(generic_button)) static generic_button buttons[] = { - {30, 152, 60, 25, button_year, button_none}, - {240, 152, 120, 25, button_resource, button_none}, - {100, 192, 200, 25, button_toggle_rise, button_none}, - {350, 192, 100, 25, button_amount, button_none}, - {30, 230, 250, 25, button_delete, button_none}, - {320, 230, 100, 25, button_save, button_none} + {30, 152, 60, 25, button_year}, + {240, 152, 120, 25, button_resource}, + {100, 192, 200, 25, button_toggle_rise}, + {350, 192, 100, 25, button_amount}, + {30, 230, 250, 25, button_delete}, + {320, 230, 100, 25, button_save} }; static struct { @@ -92,7 +92,7 @@ static void handle_input(const mouse *m, const hotkeys *h) return; } if (input_go_back_requested(m, h)) { - button_save(0, 0); + button_save(0); } } @@ -101,7 +101,7 @@ static void set_year(int value) data.price_change.year = value; } -static void button_year(int param1, int param2) +static void button_year(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 100, screen_dialog_offset_y() + 50, 3, 999, set_year); } @@ -111,7 +111,7 @@ static void set_resource(int value) data.price_change.resource = data.available_resources[value]; } -static void button_resource(int param1, int param2) +static void button_resource(const generic_button *button) { static const uint8_t *resource_texts[RESOURCE_MAX]; static int total_resources = 0; @@ -129,7 +129,7 @@ static void button_resource(int param1, int param2) resource_texts, total_resources, set_resource); } -static void button_toggle_rise(int param1, int param2) +static void button_toggle_rise(const generic_button *button) { data.price_change.is_rise = !data.price_change.is_rise; window_request_refresh(); @@ -140,19 +140,19 @@ static void set_amount(int value) data.price_change.amount = value; } -static void button_amount(int param1, int param2) +static void button_amount(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 460, screen_dialog_offset_y() + 50, 2, 99, set_amount); } -static void button_delete(int param1, int param2) +static void button_delete(const generic_button *button) { scenario_price_change_delete(data.price_change.id); scenario_editor_set_as_unsaved(); window_editor_price_changes_show(); } -static void button_save(int param1, int param2) +static void button_save(const generic_button *button) { scenario_price_change_update(&data.price_change); scenario_editor_set_as_unsaved(); diff --git a/src/window/editor/edit_request.c b/src/window/editor/edit_request.c index d6d4e71844..9ab0883671 100644 --- a/src/window/editor/edit_request.c +++ b/src/window/editor/edit_request.c @@ -18,16 +18,16 @@ #include "window/numeric_input.h" #include "window/select_list.h" -static void button_year(int param1, int param2); -static void button_amount(int param1, int param2); -static void button_resource(int param1, int param2); -static void button_deadline_years(int param1, int param2); -static void button_favor(int param1, int param2); -static void button_extension_months(int param1, int param2); -static void button_extension_disfavor(int param1, int param2); -static void button_ignored_disfavor(int param1, int param2); -static void button_delete(int param1, int param2); -static void button_save(int param1, int param2); +static void button_year(const generic_button *button); +static void button_amount(const generic_button *button); +static void button_resource(const generic_button *button); +static void button_deadline_years(const generic_button *button); +static void button_favor(const generic_button *button); +static void button_extension_months(const generic_button *button); +static void button_extension_disfavor(const generic_button *button); +static void button_ignored_disfavor(const generic_button *button); +static void button_delete(const generic_button *button); +static void button_save(const generic_button *button); static struct { scenario_request request; @@ -38,16 +38,16 @@ static struct { #define NUM_BUTTONS (sizeof(buttons) / sizeof(generic_button)) static generic_button buttons[] = { - {30, 186, 60, 25, button_year, button_none}, - {330, 186, 80, 25, button_amount, button_none}, - {430, 186, 100, 25, button_resource, button_none}, - {70, 224, 140, 25, button_deadline_years, button_none}, - {400, 224, 80, 25, button_favor, button_none}, - {400, 264, 80, 25, button_extension_months, button_none}, - {400, 304, 80, 25, button_extension_disfavor, button_none}, - {400, 344, 80, 25, button_ignored_disfavor, button_none}, - {110, 384, 250, 25, button_delete, button_none}, - {400, 384, 100, 25, button_save, button_none} + {30, 186, 60, 25, button_year}, + {330, 186, 80, 25, button_amount}, + {430, 186, 100, 25, button_resource}, + {70, 224, 140, 25, button_deadline_years}, + {400, 224, 80, 25, button_favor}, + {400, 264, 80, 25, button_extension_months}, + {400, 304, 80, 25, button_extension_disfavor}, + {400, 344, 80, 25, button_ignored_disfavor}, + {110, 384, 250, 25, button_delete}, + {400, 384, 100, 25, button_save} }; static void init(int id) @@ -121,7 +121,7 @@ static void handle_input(const mouse *m, const hotkeys *h) return; } if (input_go_back_requested(m, h)) { - button_save(0, 0); + button_save(0); } } @@ -130,7 +130,7 @@ static void set_year(int value) data.request.year = value; } -static void button_year(int param1, int param2) +static void button_year(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 100, screen_dialog_offset_y() + 50, 3, 999, set_year); } @@ -140,7 +140,7 @@ static void set_amount(int value) data.request.amount = value; } -static void button_amount(int param1, int param2) +static void button_amount(const generic_button *button) { int max_amount = 999; int max_digits = 3; @@ -162,7 +162,7 @@ static void set_resource(int value) } } -static void button_resource(int param1, int param2) +static void button_resource(const generic_button *button) { static const uint8_t *resource_texts[RESOURCE_MAX + RESOURCE_TOTAL_SPECIAL]; static int total_resources = 0; @@ -185,7 +185,7 @@ static void set_deadline_years(int value) data.request.deadline_years = value; } -static void button_deadline_years(int param1, int param2) +static void button_deadline_years(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 220, screen_dialog_offset_y() + 100, 3, 999, set_deadline_years); @@ -196,7 +196,7 @@ static void set_favor(int value) data.request.favor = value; } -static void button_favor(int param1, int param2) +static void button_favor(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 260, screen_dialog_offset_y() + 100, 3, 100, set_favor); } @@ -206,7 +206,7 @@ static void set_extension_months(int value) data.request.extension_months_to_comply = value; } -static void button_extension_months(int param1, int param2) +static void button_extension_months(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 260, screen_dialog_offset_y() + 100, 3, 120, set_extension_months); } @@ -216,7 +216,7 @@ static void set_extension_disfavor(int value) data.request.extension_disfavor = value; } -static void button_extension_disfavor(int param1, int param2) +static void button_extension_disfavor(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 260, screen_dialog_offset_y() + 100, 3, 100, set_extension_disfavor); } @@ -226,19 +226,19 @@ static void set_ignored_disfavor(int value) data.request.ignored_disfavor = value; } -static void button_ignored_disfavor(int param1, int param2) +static void button_ignored_disfavor(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 260, screen_dialog_offset_y() + 100, 3, 100, set_ignored_disfavor); } -static void button_delete(int param1, int param2) +static void button_delete(const generic_button *button) { scenario_request_delete(data.request.id); scenario_editor_set_as_unsaved(); window_go_back(); } -static void button_save(int param1, int param2) +static void button_save(const generic_button *button) { scenario_request_update(&data.request); scenario_editor_set_as_unsaved(); diff --git a/src/window/editor/empire.c b/src/window/editor/empire.c index ff8e57af9f..25fda949b3 100644 --- a/src/window/editor/empire.c +++ b/src/window/editor/empire.c @@ -10,6 +10,7 @@ #include "empire/type.h" #include "empire/xml.h" #include "graphics/arrow_button.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -31,23 +32,23 @@ #define OUR_CITY -1 -static void button_change_empire(int is_up, int param2); -static void button_ok(int param1, int param2); -static void button_toggle_invasions(int param1, int param2); -static void button_refresh(int param1, int param2); -static void button_cycle_preview(int param1, int param2); +static void button_change_empire(int is_down, int param2); +static void button_ok(const generic_button *button); +static void button_toggle_invasions(const generic_button *button); +static void button_refresh(const generic_button *button); +static void button_cycle_preview(const generic_button *button); static arrow_button arrow_buttons_empire[] = { - {8, 48, 17, 24, button_change_empire, 1, 0}, - {32, 48, 15, 24, button_change_empire, 0, 0} + {8, 48, 17, 24, button_change_empire, 1}, + {32, 48, 15, 24, button_change_empire} }; static generic_button generic_buttons[] = { - {4, 48, 100, 24, button_ok, button_none, 0, 0}, - {124, 48, 150, 24, button_toggle_invasions, button_none, 0, 0}, - {294, 48, 150, 24, button_refresh, button_none, 0, 0}, + {4, 48, 100, 24, button_ok}, + {124, 48, 150, 24, button_toggle_invasions}, + {294, 48, 150, 24, button_refresh}, }; static generic_button preview_button[] = { - {0, 0, 72, 72, button_cycle_preview, button_none, 0, 0}, + {0, 0, 72, 72, button_cycle_preview}, }; static struct { @@ -596,17 +597,17 @@ static void button_change_empire(int is_down, int param2) window_request_refresh(); } -static void button_ok(int param1, int param2) +static void button_ok(const generic_button *button) { window_editor_map_show(); } -static void button_toggle_invasions(int param1, int param2) +static void button_toggle_invasions(const generic_button *button) { data.show_battle_objects = !data.show_battle_objects; } -static void button_cycle_preview(int param1, int param2) +static void button_cycle_preview(const generic_button *button) { switch (data.preview_image_group) { case GROUP_EMPIRE_CITY: @@ -628,7 +629,7 @@ static void button_cycle_preview(int param1, int param2) window_request_refresh(); } -static void button_refresh(int param1, int param2) +static void button_refresh(const generic_button *button) { refresh_empire(); } diff --git a/src/window/editor/invasions.c b/src/window/editor/invasions.c index 8a47466d7f..3224e9a86b 100644 --- a/src/window/editor/invasions.c +++ b/src/window/editor/invasions.c @@ -1,5 +1,6 @@ #include "invasions.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/grid_box.h" @@ -17,7 +18,7 @@ #include "window/editor/map.h" static void button_invasion(unsigned int id, unsigned int mouse_x, unsigned int mouse_y); -static void button_new_invasion(int param0, int param1); +static void button_new_invasion(const generic_button *button); static void draw_invasion_button(const grid_box_item *item); static struct { @@ -29,7 +30,7 @@ static struct { } data; static generic_button new_invasion_button = { - 195, 340, 250, 25, button_new_invasion, button_none + 195, 340, 250, 25, button_new_invasion }; static grid_box_type invasion_buttons = { @@ -156,7 +157,7 @@ static void button_invasion(unsigned int id, unsigned int mouse_x, unsigned int window_editor_edit_invasion_show(data.invasions[id]->id); } -static void button_new_invasion(int param0, int param1) +static void button_new_invasion(const generic_button *button) { int new_invasion_id = scenario_invasion_new(); if (new_invasion_id >= 0) { diff --git a/src/window/editor/price_changes.c b/src/window/editor/price_changes.c index 7501025980..f899fb7a02 100644 --- a/src/window/editor/price_changes.c +++ b/src/window/editor/price_changes.c @@ -22,7 +22,7 @@ #include static void button_price_change(unsigned int id, unsigned int mouse_x, unsigned int mouse_y); -static void button_new_price_change(int param0, int param1); +static void button_new_price_change(const generic_button *button); static void draw_price_change_button(const grid_box_item *item); static struct { @@ -47,7 +47,7 @@ static grid_box_type price_change_buttons = { }; static generic_button new_price_change_button = { - 195, 340, 250, 25, button_new_price_change, button_none + 195, 340, 250, 25, button_new_price_change }; static void limit_and_sort_list(void) @@ -164,7 +164,7 @@ static void button_price_change(unsigned int id, unsigned int mouse_x, unsigned window_editor_edit_price_change_show(id); } -static void button_new_price_change(int param0, int param1) +static void button_new_price_change(const generic_button *button) { int new_price_change_id = scenario_price_change_new(); if (new_price_change_id >= 0) { diff --git a/src/window/editor/requests.c b/src/window/editor/requests.c index 1d9ed94ede..620c4d136f 100644 --- a/src/window/editor/requests.c +++ b/src/window/editor/requests.c @@ -21,7 +21,7 @@ #include "window/editor/map.h" static void button_edit_request(unsigned int id, unsigned int mouse_x, unsigned int mouse_y); -static void button_new_request(int param0, int param1); +static void button_new_request(const generic_button *button); static void draw_request_button(const grid_box_item *item); static struct { @@ -33,7 +33,7 @@ static struct { } data; static generic_button new_request_button = { - 195, 340, 250, 25, button_new_request, button_none + 195, 340, 250, 25, button_new_request }; static grid_box_type request_buttons = { @@ -177,7 +177,7 @@ static void button_edit_request(unsigned int id, unsigned int mouse_x, unsigned window_go_back(); } -static void button_new_request(int param0, int param1) +static void button_new_request(const generic_button *button) { if (data.on_select) { return; diff --git a/src/window/editor/scenario_action_edit.c b/src/window/editor/scenario_action_edit.c index acb0cc1357..4e3982ab4d 100644 --- a/src/window/editor/scenario_action_edit.c +++ b/src/window/editor/scenario_action_edit.c @@ -31,9 +31,9 @@ #define MAX_TEXT_LENGTH 50 static void init(scenario_action_t *action); -static void button_amount(int param1, int param2); -static void button_delete(int param1, int param2); -static void button_change_type(int param1, int param2); +static void button_amount(const generic_button *button); +static void button_delete(const generic_button *button); +static void button_change_type(const generic_button *button); static void set_param_value(int value); static void set_parameter_being_edited(int value); static void set_resource_value(int value); @@ -42,14 +42,15 @@ static void custom_message_selection(void); static void change_parameter(xml_data_attribute_t *parameter, int param1); static generic_button buttons[] = { - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, button_none, 1, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, button_none, 2, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, button_none, 3, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, button_none, 4, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, button_none, 5, 0}, - {288, 32, 64, 14, button_delete, button_none, 0, 0}, - {32, 64, BUTTON_WIDTH, 32, button_change_type, button_none, 0, 0} + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, 0, 1}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, 0, 2}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, 0, 3}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, 0, 4}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, 0, 5}, + {288, 32, 64, 14, button_delete}, + {32, 64, BUTTON_WIDTH, 32, button_change_type} }; + #define MAX_BUTTONS (sizeof(buttons) / sizeof(generic_button)) static struct { @@ -177,19 +178,20 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_delete(int param1, int param2) +static void button_delete(const generic_button *button) { scenario_action_type_delete(data.action); close_window(); } -static void button_change_type(int param1, int param2) +static void button_change_type(const generic_button *button) { window_editor_select_scenario_action_type_show(data.action); } -static void button_amount(int param1, int param2) +static void button_amount(const generic_button *button) { + int param1 = button->parameter1; switch (param1) { case 1: change_parameter(&data.xml_info->xml_parm1, param1); break; case 2: change_parameter(&data.xml_info->xml_parm2, param1); break; diff --git a/src/window/editor/scenario_condition_edit.c b/src/window/editor/scenario_condition_edit.c index 670e792d7d..7c590745fd 100644 --- a/src/window/editor/scenario_condition_edit.c +++ b/src/window/editor/scenario_condition_edit.c @@ -31,9 +31,9 @@ #define MAX_TEXT_LENGTH 50 static void init(scenario_condition_t *condition); -static void button_amount(int param1, int param2); -static void button_delete(int param1, int param2); -static void button_change_type(int param1, int param2); +static void button_amount(const generic_button *button); +static void button_delete(const generic_button *button); +static void button_change_type(const generic_button *button); static void set_param_value(int value); static void set_resource_value(int value); static void set_parameter_being_edited(int value); @@ -42,13 +42,13 @@ static void custom_message_selection(void); static void change_parameter(xml_data_attribute_t *parameter, int param1); static generic_button buttons[] = { - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, button_none, 1, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, button_none, 2, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, button_none, 3, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, button_none, 4, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, button_none, 5, 0}, - {288, 32, 64, 14, button_delete, button_none, 0, 0}, - {32, 64, BUTTON_WIDTH, 32, button_change_type, button_none, 0, 0} + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, 0, 1}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, 0, 2}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, 0, 3}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, 0, 4}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_amount, 0, 5}, + {288, 32, 64, 14, button_delete}, + {32, 64, BUTTON_WIDTH, 32, button_change_type} }; #define MAX_BUTTONS (sizeof(buttons) / sizeof(generic_button)) @@ -177,19 +177,20 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_delete(int param1, int param2) +static void button_delete(const generic_button *button) { scenario_condition_type_delete(data.condition); close_window(); } -static void button_change_type(int param1, int param2) +static void button_change_type(const generic_button *button) { window_editor_select_scenario_condition_type_show(data.condition); } -static void button_amount(int param1, int param2) +static void button_amount(const generic_button *button) { + int param1 = button->parameter1; switch (param1) { case 1: change_parameter(&data.xml_info->xml_parm1, param1); break; case 2: change_parameter(&data.xml_info->xml_parm2, param1); break; diff --git a/src/window/editor/scenario_event_details.c b/src/window/editor/scenario_event_details.c index 9c66288b8b..fa15e9b5a3 100644 --- a/src/window/editor/scenario_event_details.c +++ b/src/window/editor/scenario_event_details.c @@ -41,10 +41,10 @@ enum { static void init(int event_id); static void init_scroll_list(void); static void on_scroll(void); -static void button_click(int index, int param2); -static void button_amount(int param1, int param2); -static void button_add(int param1, int param2); -static void button_delete_event(int param1, int param2); +static void button_click(const generic_button *button); +static void button_amount(const generic_button *button); +static void button_add(const generic_button *button); +static void button_delete_event(const generic_button *button); static void add_new_condition(void); static void add_new_action(void); @@ -53,22 +53,22 @@ static scrollbar_type scrollbar = { }; static generic_button buttons[] = { - {580, 32, 64, 14, button_delete_event, button_none, 10, 0}, - {SHORT_BUTTON_LEFT_PADDING, EVENT_REPEAT_Y_OFFSET, SHORT_BUTTON_WIDTH, 14, button_amount, button_none, SCENARIO_EVENT_DETAILS_SET_MAX_REPEATS, 0}, - {SHORT_BUTTON_LEFT_PADDING, EVENT_REPEAT_Y_OFFSET + 32, SHORT_BUTTON_WIDTH, 14, button_amount, button_none, SCENARIO_EVENT_DETAILS_SET_REPEAT_MIN, 0}, - {SHORT_BUTTON_LEFT_PADDING, EVENT_REPEAT_Y_OFFSET + 64, SHORT_BUTTON_WIDTH, 14, button_amount, button_none, SCENARIO_EVENT_DETAILS_SET_REPEAT_MAX, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 0, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 1, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 2, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 3, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 4, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (5 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 5, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (6 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 6, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (7 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 7, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (8 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 8, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (9 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 9, 0}, - {SHORT_BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (10 * DETAILS_ROW_HEIGHT), SHORT_BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_add, button_none, SCENARIO_EVENT_DETAILS_ADD_CONDITION, 0}, - {SHORT_BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (11 * DETAILS_ROW_HEIGHT), SHORT_BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_add, button_none, SCENARIO_EVENT_DETAILS_ADD_ACTION, 0} + {580, 32, 64, 14, button_delete_event}, + {SHORT_BUTTON_LEFT_PADDING, EVENT_REPEAT_Y_OFFSET, SHORT_BUTTON_WIDTH, 14, button_amount, 0, SCENARIO_EVENT_DETAILS_SET_MAX_REPEATS}, + {SHORT_BUTTON_LEFT_PADDING, EVENT_REPEAT_Y_OFFSET + 32, SHORT_BUTTON_WIDTH, 14, button_amount, 0, SCENARIO_EVENT_DETAILS_SET_REPEAT_MIN}, + {SHORT_BUTTON_LEFT_PADDING, EVENT_REPEAT_Y_OFFSET + 64, SHORT_BUTTON_WIDTH, 14, button_amount, 0, SCENARIO_EVENT_DETAILS_SET_REPEAT_MAX}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 1}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 2}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 3}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 4}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (5 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 5}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (6 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 6}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (7 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 7}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (8 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 8}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (9 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 9}, + {SHORT_BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (10 * DETAILS_ROW_HEIGHT), SHORT_BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_add, 0, SCENARIO_EVENT_DETAILS_ADD_CONDITION}, + {SHORT_BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (11 * DETAILS_ROW_HEIGHT), SHORT_BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_add, 0, SCENARIO_EVENT_DETAILS_ADD_ACTION} }; #define MAX_BUTTONS (sizeof(buttons) / sizeof(generic_button)) @@ -360,14 +360,16 @@ static void add_new_action(void) window_request_refresh(); } -static void button_delete_event(int param1, int param2) +static void button_delete_event(const generic_button *button) { scenario_event_delete(data.event); window_go_back(); } -static void button_click(int index, int param2) +static void button_click(const generic_button *button) { + int index = button->parameter1; + if (index > MAX_VISIBLE_ROWS || index >= (int) data.total_sub_items) { return; @@ -386,8 +388,9 @@ static void button_click(int index, int param2) } } -static void button_amount(int param1, int param2) +static void button_amount(const generic_button *button) { + int param1 = button->parameter1; if (param1 == SCENARIO_EVENT_DETAILS_SET_MAX_REPEATS) { window_numeric_input_show(screen_dialog_offset_x() + 60, screen_dialog_offset_y() + 50, 3, 100000, set_amount_max_repeats); } else if (param1 == SCENARIO_EVENT_DETAILS_SET_REPEAT_MIN) { @@ -397,8 +400,9 @@ static void button_amount(int param1, int param2) } } -static void button_add(int param1, int param2) +static void button_add(const generic_button *button) { + int param1 = button->parameter1; if (param1 == SCENARIO_EVENT_DETAILS_ADD_CONDITION) { add_new_condition(); } else if (param1 == SCENARIO_EVENT_DETAILS_ADD_ACTION) { diff --git a/src/window/editor/scenario_events.c b/src/window/editor/scenario_events.c index 178c9fdf81..87eb9bed34 100644 --- a/src/window/editor/scenario_events.c +++ b/src/window/editor/scenario_events.c @@ -32,9 +32,9 @@ static void on_scroll(void); -static void button_click(int type, int param2); -static void button_event(int button_index, int param2); -static void button_open_variables(int param1, int param2); +static void button_click(const generic_button *button); +static void button_event(const generic_button *button); +static void button_open_variables(const generic_button *button); static void populate_list(int offset); static void add_new_event(void); @@ -43,19 +43,19 @@ static scrollbar_type scrollbar = { }; static generic_button buttons[] = { - {48, EVENTS_Y_OFFSET + (0 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, button_none, 1, 0}, - {48, EVENTS_Y_OFFSET + (1 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, button_none, 2, 0}, - {48, EVENTS_Y_OFFSET + (2 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, button_none, 3, 0}, - {48, EVENTS_Y_OFFSET + (3 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, button_none, 4, 0}, - {48, EVENTS_Y_OFFSET + (4 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, button_none, 5, 0}, - {48, EVENTS_Y_OFFSET + (5 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, button_none, 6, 0}, - {48, EVENTS_Y_OFFSET + (6 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, button_none, 7, 0}, - {48, EVENTS_Y_OFFSET + (7 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, button_none, 8, 0}, - {48, EVENTS_Y_OFFSET + (9 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_click, button_none, 9, 0}, - {48, EVENTS_Y_OFFSET + (11 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_click, button_none, 10, 0}, - {48, EVENTS_Y_OFFSET + (12 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_click, button_none, 11, 0}, - {48, EVENTS_Y_OFFSET + (13 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_click, button_none, 12, 0}, - {210, 100, BUTTON_WIDTH / 2, EVENTS_ROW_HEIGHT, button_open_variables, button_none, 0, 0} + {48, EVENTS_Y_OFFSET + (0 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, 0, 1}, + {48, EVENTS_Y_OFFSET + (1 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, 0, 2}, + {48, EVENTS_Y_OFFSET + (2 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, 0, 3}, + {48, EVENTS_Y_OFFSET + (3 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, 0, 4}, + {48, EVENTS_Y_OFFSET + (4 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, 0, 5}, + {48, EVENTS_Y_OFFSET + (5 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, 0, 6}, + {48, EVENTS_Y_OFFSET + (6 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, 0, 7}, + {48, EVENTS_Y_OFFSET + (7 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_event, 0, 8}, + {48, EVENTS_Y_OFFSET + (9 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_click, 0, 9}, + {48, EVENTS_Y_OFFSET + (11 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_click, 0, 10}, + {48, EVENTS_Y_OFFSET + (12 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_click, 0, 11}, + {48, EVENTS_Y_OFFSET + (13 * EVENTS_ROW_HEIGHT), BUTTON_WIDTH, EVENTS_ROW_HEIGHT, button_click, 0, 12}, + {210, 100, BUTTON_WIDTH / 2, EVENTS_ROW_HEIGHT, button_open_variables} }; #define MAX_BUTTONS (sizeof(buttons) / sizeof(generic_button)) @@ -176,9 +176,9 @@ static void draw_foreground(void) graphics_reset_dialog(); } -static void button_event(int button_index, int param2) +static void button_event(const generic_button *button) { - int target_index = button_index - 1; + int target_index = button->parameter1 - 1; if (!data.list[target_index]) { return; } @@ -205,8 +205,9 @@ static void handle_input(const mouse *m, const hotkeys *h) populate_list(scrollbar.scroll_position); } -static void button_click(int type, int param2) +static void button_click(const generic_button *button) { + int type = button->parameter1; if (type == 9) { add_new_event(); } else if (type == 10) { @@ -219,7 +220,7 @@ static void button_click(int type, int param2) } } -static void button_open_variables(int param1, int param2) +static void button_open_variables(const generic_button *button) { window_editor_custom_variables_show(); } diff --git a/src/window/editor/select_city_by_type.c b/src/window/editor/select_city_by_type.c index 84266d9cca..a13f965f4d 100644 --- a/src/window/editor/select_city_by_type.c +++ b/src/window/editor/select_city_by_type.c @@ -29,7 +29,7 @@ #define INITIAL_ID_LIST_SIZE 20 static void on_scroll(void); -static void button_click(int index, int param2); +static void button_click(const generic_button *button); static const uint8_t UNKNOWN[4] = { '?', '?', '?', 0 }; @@ -38,20 +38,20 @@ static scrollbar_type scrollbar = { }; static generic_button buttons[] = { - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 0, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 1, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 2, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 3, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 4, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (5 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 5, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (6 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 6, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (7 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 7, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (8 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 8, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (9 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 9, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (10 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 10, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (11 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 11, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (12 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 12, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (13 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 13, 0} + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 0}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 1}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 2}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 3}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 4}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (5 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 5}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (6 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 6}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (7 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 7}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (8 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 8}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (9 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 9}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (10 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 10}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (11 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 11}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (12 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 12}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (13 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 13} }; typedef struct { @@ -182,8 +182,10 @@ static void handle_input(const mouse *m, const hotkeys *h) populate_list(scrollbar.scroll_position); } -static void button_click(int index, int param2) +static void button_click(const generic_button *button) { + int index = button->parameter1; + if (index >= (int) data.list_size) { return; } diff --git a/src/window/editor/select_city_trade_route.c b/src/window/editor/select_city_trade_route.c index 03cc098528..af01d6766c 100644 --- a/src/window/editor/select_city_trade_route.c +++ b/src/window/editor/select_city_trade_route.c @@ -27,7 +27,7 @@ #define MAX_VISIBLE_ROWS 14 static void on_scroll(void); -static void button_click(int index, int param2); +static void button_click(const generic_button *button); static const uint8_t UNKNOWN[4] = { '?', '?', '?', 0 }; @@ -36,20 +36,20 @@ static scrollbar_type scrollbar = { }; static generic_button buttons[] = { - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 0, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 1, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 2, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 3, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 4, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (5 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 5, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (6 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 6, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (7 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 7, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (8 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 8, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (9 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 9, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (10 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 10, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (11 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 11, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (12 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 12, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (13 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 13, 0} + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 0}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 1}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 2}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 3}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 4}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (5 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 5}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (6 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 6}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (7 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 7}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (8 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 8}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (9 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 9}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (10 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 10}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (11 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 11}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (12 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 12}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (13 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 13} }; typedef struct { @@ -151,8 +151,10 @@ static void handle_input(const mouse *m, const hotkeys *h) populate_list(scrollbar.scroll_position); } -static void button_click(int index, int param2) +static void button_click(const generic_button *button) { + int index = button->parameter1; + if (index >= (int) data.list_size) { return; } diff --git a/src/window/editor/select_custom_message.c b/src/window/editor/select_custom_message.c index b53587c4d5..35bbb11077 100644 --- a/src/window/editor/select_custom_message.c +++ b/src/window/editor/select_custom_message.c @@ -28,7 +28,7 @@ static void on_scroll(void); -static void button_click(int button_index, int param2); +static void button_click(const generic_button *button); static void populate_list(int offset); static scrollbar_type scrollbar = { @@ -36,14 +36,14 @@ static scrollbar_type scrollbar = { }; static generic_button buttons[] = { - {48, MESSAGES_Y_OFFSET + (0 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, button_none, 0, 0}, - {48, MESSAGES_Y_OFFSET + (1 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, button_none, 1, 0}, - {48, MESSAGES_Y_OFFSET + (2 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, button_none, 2, 0}, - {48, MESSAGES_Y_OFFSET + (3 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, button_none, 3, 0}, - {48, MESSAGES_Y_OFFSET + (4 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, button_none, 4, 0}, - {48, MESSAGES_Y_OFFSET + (5 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, button_none, 5, 0}, - {48, MESSAGES_Y_OFFSET + (6 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, button_none, 6, 0}, - {48, MESSAGES_Y_OFFSET + (7 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, button_none, 7, 0}, + {48, MESSAGES_Y_OFFSET + (0 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, 0, 0}, + {48, MESSAGES_Y_OFFSET + (1 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, 0, 1}, + {48, MESSAGES_Y_OFFSET + (2 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, 0, 2}, + {48, MESSAGES_Y_OFFSET + (3 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, 0, 3}, + {48, MESSAGES_Y_OFFSET + (4 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, 0, 4}, + {48, MESSAGES_Y_OFFSET + (5 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, 0, 5}, + {48, MESSAGES_Y_OFFSET + (6 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, 0, 6}, + {48, MESSAGES_Y_OFFSET + (7 * MESSAGES_ROW_HEIGHT), BUTTON_WIDTH, MESSAGES_ROW_HEIGHT - 2, button_click, 0, 7}, }; #define MAX_BUTTONS (sizeof(buttons) / sizeof(generic_button)) @@ -120,8 +120,9 @@ static void draw_foreground(void) graphics_reset_dialog(); } -static void button_click(int button_index, int param2) +static void button_click(const generic_button *button) { + int button_index = button->parameter1; if (!data.list[button_index]) { return; }; diff --git a/src/window/editor/select_scenario_action_type.c b/src/window/editor/select_scenario_action_type.c index 56cbb0e17a..d36d3b1986 100644 --- a/src/window/editor/select_scenario_action_type.c +++ b/src/window/editor/select_scenario_action_type.c @@ -25,23 +25,23 @@ static void init(scenario_action_t *action); static void on_scroll(void); static void populate_list(int offset); -static void button_click(int param1, int param2); +static void button_click(const generic_button *button); static scrollbar_type scrollbar = { 640, DETAILS_Y_OFFSET, DETAILS_ROW_HEIGHT * MAX_VISIBLE_ROWS, BUTTON_WIDTH, MAX_VISIBLE_ROWS, on_scroll, 0, 4 }; static generic_button buttons[] = { - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 0, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 1, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 2, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 3, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 4, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (5 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 5, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (6 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 6, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (7 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 7, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (8 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 8, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (9 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 9, 0} + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 1}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 2}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 3}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 4}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (5 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 5}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (6 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 6}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (7 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 7}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (8 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 8}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (9 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 9} }; static struct { @@ -126,8 +126,9 @@ static void handle_input(const mouse *m, const hotkeys *h) populate_list(scrollbar.scroll_position); } -static void button_click(int param1, int param2) +static void button_click(const generic_button *button) { + int param1 = button->parameter1; data.action->type = data.list[param1]->type; data.action->parameter1 = scenario_events_parameter_data_get_default_value_for_parameter(&data.list[param1]->xml_parm1); data.action->parameter2 = scenario_events_parameter_data_get_default_value_for_parameter(&data.list[param1]->xml_parm2); diff --git a/src/window/editor/select_scenario_condition_type.c b/src/window/editor/select_scenario_condition_type.c index 3e780fb391..66662eb635 100644 --- a/src/window/editor/select_scenario_condition_type.c +++ b/src/window/editor/select_scenario_condition_type.c @@ -25,23 +25,23 @@ static void init(scenario_condition_t *condition); static void on_scroll(void); static void populate_list(int offset); -static void button_click(int param1, int param2); +static void button_click(const generic_button *button); static scrollbar_type scrollbar = { 640, DETAILS_Y_OFFSET, DETAILS_ROW_HEIGHT * MAX_VISIBLE_ROWS, BUTTON_WIDTH, MAX_VISIBLE_ROWS, on_scroll, 0, 4 }; static generic_button buttons[] = { - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 0, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 1, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 2, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 3, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 4, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (5 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 5, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (6 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 6, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (7 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 7, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (8 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 8, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (9 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 9, 0} + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 1}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 2}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 3}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 4}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (5 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 5}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (6 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 6}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (7 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 7}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (8 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 8}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (9 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 9} }; static struct { @@ -126,8 +126,9 @@ static void handle_input(const mouse *m, const hotkeys *h) populate_list(scrollbar.scroll_position); } -static void button_click(int param1, int param2) +static void button_click(const generic_button *button) { + int param1 = button->parameter1; data.condition->type = data.list[param1]->type; data.condition->parameter1 = scenario_events_parameter_data_get_default_value_for_parameter(&data.list[param1]->xml_parm1); data.condition->parameter2 = scenario_events_parameter_data_get_default_value_for_parameter(&data.list[param1]->xml_parm2); diff --git a/src/window/editor/select_special_attribute_mapping.c b/src/window/editor/select_special_attribute_mapping.c index acea30ca8c..2021d86fff 100644 --- a/src/window/editor/select_special_attribute_mapping.c +++ b/src/window/editor/select_special_attribute_mapping.c @@ -23,26 +23,26 @@ #define MAX_VISIBLE_ROWS 13 static void on_scroll(void); -static void button_click(int index, int param2); +static void button_click(const generic_button *button); static scrollbar_type scrollbar = { 640, DETAILS_Y_OFFSET, DETAILS_ROW_HEIGHT * MAX_VISIBLE_ROWS, BUTTON_WIDTH, MAX_VISIBLE_ROWS, on_scroll, 0, 4 }; static generic_button buttons[] = { - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 0, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 1, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 2, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 3, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 4, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (5 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 5, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (6 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 6, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (7 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 7, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (8 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 8, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (9 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 9, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (10 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 10, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (11 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 11, 0}, - {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (12 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, button_none, 12, 0} + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (0 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 0}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (1 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 1}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (2 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 2}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (3 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 3}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (4 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 4}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (5 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 5}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (6 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 6}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (7 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 7}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (8 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 8}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (9 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 9}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (10 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 10}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (11 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 11}, + {BUTTON_LEFT_PADDING, DETAILS_Y_OFFSET + (12 * DETAILS_ROW_HEIGHT), BUTTON_WIDTH, DETAILS_ROW_HEIGHT - 2, button_click, 0, 12} }; static struct { @@ -180,8 +180,10 @@ static void handle_input(const mouse *m, const hotkeys *h) populate_list(scrollbar.scroll_position); } -static void button_click(int index, int param2) +static void button_click(const generic_button *button) { + int index = button->parameter1; + if (index >= (int) data.list_size) { return; } diff --git a/src/window/editor/special_events.c b/src/window/editor/special_events.c index 42281b3ba1..d0d4182c7f 100644 --- a/src/window/editor/special_events.c +++ b/src/window/editor/special_events.c @@ -15,38 +15,38 @@ #include "window/editor/map.h" #include "window/numeric_input.h" -static void button_earthquake_severity(int param1, int param2); -static void button_earthquake_year(int param1, int param2); -static void button_gladiator_toggle(int param1, int param2); -static void button_gladiator_year(int param1, int param2); -static void button_emperor_toggle(int param1, int param2); -static void button_emperor_year(int param1, int param2); -static void button_sea_trade_toggle(int param1, int param2); -static void button_land_trade_toggle(int param1, int param2); -static void button_raise_wages_toggle(int param1, int param2); -static void button_max_wages(int param1, int param2); -static void button_lower_wages_toggle(int param1, int param2); -static void button_min_wages(int param1, int param2); -static void button_contamination_toggle(int param1, int param2); -static void button_iron_mine_toggle(int param1, int param2); -static void button_clay_pit_toggle(int param1, int param2); +static void button_earthquake_severity(const generic_button *button); +static void button_earthquake_year(const generic_button *button); +static void button_gladiator_toggle(const generic_button *button); +static void button_gladiator_year(const generic_button *button); +static void button_emperor_toggle(const generic_button *button); +static void button_emperor_year(const generic_button *button); +static void button_sea_trade_toggle(const generic_button *button); +static void button_land_trade_toggle(const generic_button *button); +static void button_raise_wages_toggle(const generic_button *button); +static void button_max_wages(const generic_button *button); +static void button_lower_wages_toggle(const generic_button *button); +static void button_min_wages(const generic_button *button); +static void button_contamination_toggle(const generic_button *button); +static void button_iron_mine_toggle(const generic_button *button); +static void button_clay_pit_toggle(const generic_button *button); static generic_button buttons[] = { - {216, 106, 100, 24, button_earthquake_severity, button_none}, - {326, 106, 150, 24, button_earthquake_year, button_none}, - {216, 136, 100, 24, button_gladiator_toggle,button_none}, - {326, 136, 150, 24, button_gladiator_year,button_none}, - {216, 166, 100, 24, button_emperor_toggle,button_none}, - {326, 166, 150, 24, button_emperor_year, button_none}, - {216, 196, 100, 24, button_sea_trade_toggle, button_none}, - {216, 226, 100, 24, button_land_trade_toggle, button_none}, - {216, 256, 100, 24, button_raise_wages_toggle, button_none}, - {465, 256, 100, 24, button_max_wages, button_none}, - {216, 286, 100, 24, button_lower_wages_toggle, button_none}, - {465, 286, 100, 24, button_min_wages, button_none}, - {216, 316, 100, 24, button_contamination_toggle, button_none}, - {216, 346, 100, 24, button_iron_mine_toggle, button_none}, - {216, 376, 100, 24, button_clay_pit_toggle, button_none}, + {216, 106, 100, 24, button_earthquake_severity}, + {326, 106, 150, 24, button_earthquake_year}, + {216, 136, 100, 24, button_gladiator_toggle}, + {326, 136, 150, 24, button_gladiator_year}, + {216, 166, 100, 24, button_emperor_toggle}, + {326, 166, 150, 24, button_emperor_year}, + {216, 196, 100, 24, button_sea_trade_toggle}, + {216, 226, 100, 24, button_land_trade_toggle}, + {216, 256, 100, 24, button_raise_wages_toggle}, + {465, 256, 100, 24, button_max_wages}, + {216, 286, 100, 24, button_lower_wages_toggle}, + {465, 286, 100, 24, button_min_wages}, + {216, 316, 100, 24, button_contamination_toggle}, + {216, 346, 100, 24, button_iron_mine_toggle}, + {216, 376, 100, 24, button_clay_pit_toggle}, }; static unsigned int focus_button_id; @@ -157,55 +157,55 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_earthquake_severity(int param1, int param2) +static void button_earthquake_severity(const generic_button *button) { scenario_editor_earthquake_cycle_severity(); window_request_refresh(); } -static void button_earthquake_year(int param1, int param2) +static void button_earthquake_year(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 190, screen_dialog_offset_y() + 100, 3, 999, scenario_editor_earthquake_set_year); } -static void button_gladiator_toggle(int param1, int param2) +static void button_gladiator_toggle(const generic_button *button) { scenario_editor_gladiator_revolt_toggle_enabled(); window_request_refresh(); } -static void button_gladiator_year(int param1, int param2) +static void button_gladiator_year(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 190, screen_dialog_offset_y() + 100, 3, 999, scenario_editor_gladiator_revolt_set_year); } -static void button_emperor_toggle(int param1, int param2) +static void button_emperor_toggle(const generic_button *button) { scenario_editor_emperor_change_toggle_enabled(); window_request_refresh(); } -static void button_emperor_year(int param1, int param2) +static void button_emperor_year(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 190, screen_dialog_offset_y() + 100, 3, 999, scenario_editor_emperor_change_set_year); } -static void button_sea_trade_toggle(int param1, int param2) +static void button_sea_trade_toggle(const generic_button *button) { scenario_editor_sea_trade_problem_toggle_enabled(); window_request_refresh(); } -static void button_land_trade_toggle(int param1, int param2) +static void button_land_trade_toggle(const generic_button *button) { scenario_editor_land_trade_problem_toggle_enabled(); window_request_refresh(); } -static void button_raise_wages_toggle(int param1, int param2) +static void button_raise_wages_toggle(const generic_button *button) { scenario_editor_raise_wages_toggle_enabled(); window_request_refresh(); @@ -216,12 +216,12 @@ static void set_max_wages(int amount) scenario_editor_set_max_wages(amount); } -static void button_max_wages(int param1, int param2) +static void button_max_wages(const generic_button *button) { window_numeric_input_show(400, 256, 2, 99, set_max_wages); } -static void button_lower_wages_toggle(int param1, int param2) +static void button_lower_wages_toggle(const generic_button *button) { scenario_editor_lower_wages_toggle_enabled(); window_request_refresh(); @@ -232,24 +232,24 @@ static void set_min_wages(int amount) scenario_editor_set_min_wages(amount); } -static void button_min_wages(int param1, int param2) +static void button_min_wages(const generic_button *button) { window_numeric_input_show(400, 286, 2, 99, set_min_wages); } -static void button_contamination_toggle(int param1, int param2) +static void button_contamination_toggle(const generic_button *button) { scenario_editor_contaminated_water_toggle_enabled(); window_request_refresh(); } -static void button_iron_mine_toggle(int param1, int param2) +static void button_iron_mine_toggle(const generic_button *button) { scenario_editor_iron_mine_collapse_toggle_enabled(); window_request_refresh(); } -static void button_clay_pit_toggle(int param1, int param2) +static void button_clay_pit_toggle(const generic_button *button) { scenario_editor_clay_pit_flooded_toggle_enabled(); window_request_refresh(); diff --git a/src/window/editor/start_year.c b/src/window/editor/start_year.c index b4a4b9c9ca..be462ed9e5 100644 --- a/src/window/editor/start_year.c +++ b/src/window/editor/start_year.c @@ -15,12 +15,12 @@ #include "window/editor/starting_conditions.h" #include "window/numeric_input.h" -static void button_era(int param1, int param2); -static void button_year(int param1, int param2); +static void button_era(const generic_button *button); +static void button_year(const generic_button *button); static generic_button buttons[] = { - {158, 100, 100, 30, button_era, button_none}, - {278, 100, 120, 30, button_year, button_none}, + {158, 100, 100, 30, button_era}, + {278, 100, 120, 30, button_year}, }; static unsigned int focus_button_id; @@ -59,7 +59,7 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_era(int param1, int param2) +static void button_era(const generic_button *button) { scenario_editor_set_start_year(-scenario_property_start_year()); } @@ -72,7 +72,7 @@ static void set_year(int value) scenario_editor_set_start_year(value); } -static void button_year(int param1, int param2) +static void button_year(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 140, screen_dialog_offset_y() + 80, 4, 9999, set_year); diff --git a/src/window/editor/starting_conditions.c b/src/window/editor/starting_conditions.c index 1ce941f8d8..85afba40b7 100644 --- a/src/window/editor/starting_conditions.c +++ b/src/window/editor/starting_conditions.c @@ -18,29 +18,32 @@ #include "window/numeric_input.h" #include "window/select_list.h" -static void button_rank(int param1, int param2); -static void button_caesar_salary(int param1, int param2); -static void button_start_year(int param1, int param2); -static void button_initial_funds(int param1, int param2); -static void button_rescue_loan(int param1, int param2); -static void button_wheat(int param1, int param2); -static void button_flotsam(int param1, int param2); -static void button_milestone(int milestone_pct, int param2); +static void button_rank(const generic_button *button); +static void button_caesar_salary(const generic_button *button); +static void button_start_year(const generic_button *button); +static void button_initial_funds(const generic_button *button); +static void button_rescue_loan(const generic_button *button); +static void button_wheat(const generic_button *button); +static void button_flotsam(const generic_button *button); +static void button_milestone(const generic_button *button); static generic_button buttons[] = { - {262, 48, 200, 30, button_rank, button_none}, - {262, 88, 200, 30, button_caesar_salary, button_none}, - {262, 128, 200, 30, button_start_year, button_none}, - {262, 168, 200, 30, button_initial_funds,button_none}, - {262, 208, 200, 30, button_rescue_loan,button_none}, - {262, 248, 200, 30, button_wheat,button_none}, - {262, 288, 200, 30, button_flotsam, button_none, 0}, - {262, 328, 200, 30, button_milestone, button_none, 25}, - {262, 368, 200, 30, button_milestone, button_none, 50}, - {262, 408, 200, 30, button_milestone, button_none, 75} + {262, 48, 200, 30, button_rank}, + {262, 88, 200, 30, button_caesar_salary}, + {262, 128, 200, 30, button_start_year}, + {262, 168, 200, 30, button_initial_funds}, + {262, 208, 200, 30, button_rescue_loan}, + {262, 248, 200, 30, button_wheat}, + {262, 288, 200, 30, button_flotsam}, + {262, 328, 200, 30, button_milestone, 0, 25}, + {262, 368, 200, 30, button_milestone, 0, 50}, + {262, 408, 200, 30, button_milestone, 0, 75} }; -static unsigned int focus_button_id; +static struct { + int dialog_milestone_pct; + unsigned int focus_button_id; +} data; static void draw_background(void) { @@ -57,47 +60,47 @@ static void draw_foreground(void) lang_text_draw_centered(13, 3, 12, 452, 480, FONT_NORMAL_BLACK); lang_text_draw(44, 108, 32, 57, FONT_NORMAL_BLACK); - button_border_draw(262, 48, 200, 30, focus_button_id == 1); + button_border_draw(262, 48, 200, 30, data.focus_button_id == 1); lang_text_draw_centered(32, scenario_property_player_rank(), 262, 57, 200, FONT_NORMAL_BLACK); lang_text_draw(CUSTOM_TRANSLATION, TR_EDITOR_CAESAR_SALARY, 32, 97, FONT_NORMAL_BLACK); - button_border_draw(262, 88, 200, 30, focus_button_id == 2); + button_border_draw(262, 88, 200, 30, data.focus_button_id == 2); text_draw_number_centered(scenario_property_caesar_salary(), 262, 97, 200, FONT_NORMAL_BLACK); lang_text_draw(44, 89, 32, 137, FONT_NORMAL_BLACK); - button_border_draw(262, 128, 200, 30, focus_button_id == 3); + button_border_draw(262, 128, 200, 30, data.focus_button_id == 3); lang_text_draw_year(scenario_property_start_year(), 330, 137, FONT_NORMAL_BLACK); lang_text_draw(44, 39, 32, 177, FONT_NORMAL_BLACK); - button_border_draw(262, 168, 200, 30, focus_button_id == 4); + button_border_draw(262, 168, 200, 30, data.focus_button_id == 4); text_draw_number_centered(scenario_initial_funds(), 262, 177, 200, FONT_NORMAL_BLACK); lang_text_draw(44, 68, 32, 217, FONT_NORMAL_BLACK); - button_border_draw(262, 208, 200, 30, focus_button_id == 5); + button_border_draw(262, 208, 200, 30, data.focus_button_id == 5); text_draw_number_centered(scenario_rescue_loan(), 262, 217, 200, FONT_NORMAL_BLACK); lang_text_draw(44, 43, 32, 257, FONT_NORMAL_BLACK); - button_border_draw(262, 248, 200, 30, focus_button_id == 6); + button_border_draw(262, 248, 200, 30, data.focus_button_id == 6); lang_text_draw_centered(18, scenario_property_rome_supplies_wheat(), 262, 257, 200, FONT_NORMAL_BLACK); lang_text_draw(44, 80, 32, 297, FONT_NORMAL_BLACK); - button_border_draw(262, 288, 200, 30, focus_button_id == 7); + button_border_draw(262, 288, 200, 30, data.focus_button_id == 7); lang_text_draw_centered(18, scenario_map_has_flotsam(), 262, 297, 200, FONT_NORMAL_BLACK); lang_text_draw(44, 91, 32, 337, FONT_NORMAL_BLACK); - button_border_draw(262, 328, 200, 30, focus_button_id == 8); + button_border_draw(262, 328, 200, 30, data.focus_button_id == 8); int width = text_draw_number(scenario_editor_milestone_year(25), '+', " ", 297, 339, FONT_NORMAL_BLACK, 0); lang_text_draw_year(scenario_property_start_year() + scenario_editor_milestone_year(25), 307 + width, 339, FONT_SMALL_PLAIN); lang_text_draw(44, 92, 32, 377, FONT_NORMAL_BLACK); - button_border_draw(262, 368, 200, 30, focus_button_id == 9); + button_border_draw(262, 368, 200, 30, data.focus_button_id == 9); width = text_draw_number(scenario_editor_milestone_year(50), '+', " ", 297, 379, FONT_NORMAL_BLACK, 0); lang_text_draw_year(scenario_property_start_year() + scenario_editor_milestone_year(50), 307 + width, 379, FONT_SMALL_PLAIN); lang_text_draw(44, 93, 32, 417, FONT_NORMAL_BLACK); - button_border_draw(262, 408, 200, 30, focus_button_id == 10); + button_border_draw(262, 408, 200, 30, data.focus_button_id == 10); width = text_draw_number(scenario_editor_milestone_year(75), '+', " ", 297, 419, FONT_NORMAL_BLACK, 0); lang_text_draw_year(scenario_property_start_year() + scenario_editor_milestone_year(75), 307 + width, 419, FONT_SMALL_PLAIN); @@ -107,7 +110,7 @@ static void draw_foreground(void) static void handle_input(const mouse *m, const hotkeys *h) { - if (generic_buttons_handle_mouse(mouse_in_dialog(m), 0, 0, buttons, 10, &focus_button_id)) { + if (generic_buttons_handle_mouse(mouse_in_dialog(m), 0, 0, buttons, 10, &data.focus_button_id)) { return; } if (input_go_back_requested(m, h)) { @@ -115,54 +118,53 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_rank(int param1, int param2) +static void button_rank(const generic_button *button) { window_select_list_show(screen_dialog_offset_x() + 40, screen_dialog_offset_y() + 56, 32, 11, scenario_editor_set_player_rank); } -static void button_caesar_salary(int param1, int param2) +static void button_caesar_salary(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 120, screen_dialog_offset_y() + 56, 5, 60000, scenario_editor_set_caesar_salary); } -static void button_start_year(int param1, int param2) +static void button_start_year(const generic_button *button) { window_editor_start_year_show(); } -static void button_initial_funds(int param1, int param2) +static void button_initial_funds(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 120, screen_dialog_offset_y() + 56, 5, 99999, scenario_editor_set_initial_funds); } -static void button_rescue_loan(int param1, int param2) +static void button_rescue_loan(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 120, screen_dialog_offset_y() + 56, 5, 99999, scenario_editor_set_rescue_loan); } -static void button_wheat(int param1, int param2) +static void button_wheat(const generic_button *button) { scenario_editor_toggle_rome_supplies_wheat(); } -static void button_flotsam(int param1, int param2) +static void button_flotsam(const generic_button *button) { scenario_editor_toggle_flotsam(); } -static int dialog_milestone_pct; static void set_milestone_year(int value) { - scenario_editor_set_milestone_year(dialog_milestone_pct, value); + scenario_editor_set_milestone_year(data.dialog_milestone_pct, value); } -static void button_milestone(int milestone_pct, int param2) +static void button_milestone(const generic_button *button) { - dialog_milestone_pct = milestone_pct; + data.dialog_milestone_pct = button->parameter1; window_numeric_input_show(screen_dialog_offset_x() + 120, screen_dialog_offset_y() + 210, 3, 999, set_milestone_year); } diff --git a/src/window/editor/win_criteria.c b/src/window/editor/win_criteria.c index 165aa483b2..3595948639 100644 --- a/src/window/editor/win_criteria.c +++ b/src/window/editor/win_criteria.c @@ -23,32 +23,32 @@ enum { RATING_FAVOR }; -static void button_rating_toggle(int rating, int param2); -static void button_rating_value(int rating, int param2); -static void button_time_limit_toggle(int param1, int param2); -static void button_time_limit_years(int param1, int param2); -static void button_survival_toggle(int param1, int param2); -static void button_survival_years(int param1, int param2); -static void button_population_toggle(int param1, int param2); -static void button_population_value(int param1, int param2); -static void button_open_play_toggle(int param1, int param2); +static void button_rating_toggle(const generic_button *button); +static void button_rating_value(const generic_button *button); +static void button_time_limit_toggle(const generic_button *button); +static void button_time_limit_years(const generic_button *button); +static void button_survival_toggle(const generic_button *button); +static void button_survival_years(const generic_button *button); +static void button_population_toggle(const generic_button *button); +static void button_population_value(const generic_button *button); +static void button_open_play_toggle(const generic_button *button); static generic_button buttons[] = { - {316, 132, 80, 30, button_rating_toggle, button_none, RATING_CULTURE}, - {416, 132, 180, 30, button_rating_value, button_none, RATING_CULTURE}, - {316, 172, 80, 30, button_rating_toggle, button_none, RATING_PROSPERITY}, - {416, 172, 180, 30, button_rating_value, button_none, RATING_PROSPERITY}, - {316, 212, 80, 30, button_rating_toggle, button_none, RATING_PEACE}, - {416, 212, 180, 30, button_rating_value, button_none, RATING_PEACE}, - {316, 252, 80, 30, button_rating_toggle, button_none, RATING_FAVOR}, - {416, 252, 180, 30, button_rating_value, button_none, RATING_FAVOR}, - {316, 292, 80, 30, button_time_limit_toggle, button_none}, - {416, 292, 180, 30, button_time_limit_years, button_none}, - {316, 332, 80, 30, button_survival_toggle, button_none}, - {416, 332, 180, 30, button_survival_years, button_none}, - {316, 372, 80, 30, button_population_toggle, button_none}, - {416, 372, 180, 30, button_population_value, button_none}, - {316, 92, 80, 30, button_open_play_toggle, button_none}, + {316, 132, 80, 30, button_rating_toggle, 0, RATING_CULTURE}, + {416, 132, 180, 30, button_rating_value, 0, RATING_CULTURE}, + {316, 172, 80, 30, button_rating_toggle, 0, RATING_PROSPERITY}, + {416, 172, 180, 30, button_rating_value, 0, RATING_PROSPERITY}, + {316, 212, 80, 30, button_rating_toggle, 0, RATING_PEACE}, + {416, 212, 180, 30, button_rating_value, 0, RATING_PEACE}, + {316, 252, 80, 30, button_rating_toggle, 0, RATING_FAVOR}, + {416, 252, 180, 30, button_rating_value, 0, RATING_FAVOR}, + {316, 292, 80, 30, button_time_limit_toggle}, + {416, 292, 180, 30, button_time_limit_years}, + {316, 332, 80, 30, button_survival_toggle}, + {416, 332, 180, 30, button_survival_years}, + {316, 372, 80, 30, button_population_toggle}, + {416, 372, 180, 30, button_population_value}, + {316, 92, 80, 30, button_open_play_toggle}, }; static unsigned int focus_button_id; @@ -141,8 +141,9 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_rating_toggle(int rating, int param2) +static void button_rating_toggle(const generic_button *button) { + int rating = button->parameter1; switch (rating) { case RATING_CULTURE: scenario_editor_toggle_culture(); @@ -159,8 +160,9 @@ static void button_rating_toggle(int rating, int param2) } } -static void button_rating_value(int rating, int param2) +static void button_rating_value(const generic_button *button) { + int rating = button->parameter1; void (*callback)(int); switch (rating) { case RATING_CULTURE: @@ -182,40 +184,40 @@ static void button_rating_value(int rating, int param2) 3, 100, callback); } -static void button_time_limit_toggle(int param1, int param2) +static void button_time_limit_toggle(const generic_button *button) { scenario_editor_toggle_time_limit(); } -static void button_time_limit_years(int param1, int param2) +static void button_time_limit_years(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 280, screen_dialog_offset_y() + 200, 3, 999, scenario_editor_set_time_limit); } -static void button_survival_toggle(int param1, int param2) +static void button_survival_toggle(const generic_button *button) { scenario_editor_toggle_survival_time(); } -static void button_survival_years(int param1, int param2) +static void button_survival_years(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 280, screen_dialog_offset_y() + 200, 3, 999, scenario_editor_set_survival_time); } -static void button_population_toggle(int param1, int param2) +static void button_population_toggle(const generic_button *button) { scenario_editor_toggle_population(); } -static void button_population_value(int param1, int param2) +static void button_population_value(const generic_button *button) { window_numeric_input_show(screen_dialog_offset_x() + 280, screen_dialog_offset_y() + 200, 5, 99999, scenario_editor_set_population); } -static void button_open_play_toggle(int param1, int param2) +static void button_open_play_toggle(const generic_button *button) { scenario_editor_toggle_open_play(); } diff --git a/src/window/empire.c b/src/window/empire.c index 2b1d3a42f8..87cd80407c 100644 --- a/src/window/empire.c +++ b/src/window/empire.c @@ -55,8 +55,8 @@ static void button_help(int param1, int param2); static void button_return_to_city(int param1, int param2); static void button_advisor(int advisor, int param2); static void button_show_prices(int param1, int param2); -static void button_open_trade(int param1, int param2); -static void button_show_resource_window(int resource, int param2); +static void button_open_trade(const generic_button *button); +static void button_show_resource_window(const generic_button *button); static image_button image_button_help[] = { {0, 0, 27, 27, IB_NORMAL, GROUP_CONTEXT_ICONS, 0, button_help, button_none, 0, 0, 1} @@ -72,11 +72,11 @@ static image_button image_button_show_prices[] = { }; static generic_button generic_button_trade_resource[] = { - {0, 0, 101, 27, button_show_resource_window, button_none, 0, 0}, + {0, 0, 101, 27, button_show_resource_window}, }; static generic_button generic_button_open_trade[] = { - {30, 56, 440, 26, button_open_trade, button_none, 0, 0} + {30, 56, 440, 26, button_open_trade} }; static struct { @@ -914,7 +914,7 @@ static void button_show_prices(int param1, int param2) window_trade_prices_show(0, 0, screen_width(), screen_height()); } -static void button_show_resource_window(int param1, int param2) +static void button_show_resource_window(const generic_button *button) { window_resource_settings_show(data.focus_resource); } @@ -928,7 +928,7 @@ static void confirmed_open_trade(int accepted, int checked) } } -static void button_open_trade(int param1, int param2) +static void button_open_trade(const generic_button *button2) { window_popup_dialog_show(POPUP_DIALOG_OPEN_TRADE, confirmed_open_trade, 2); } diff --git a/src/window/file_dialog.c b/src/window/file_dialog.c index b5e786b0e1..3719e7d4d0 100644 --- a/src/window/file_dialog.c +++ b/src/window/file_dialog.c @@ -15,6 +15,7 @@ #include "game/file_editor.h" #include "game/file_io.h" #include "game/save_version.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -48,7 +49,7 @@ #define FILTER_TEXT_SIZE 16 #define MIN_FILTER_SIZE 2 -static void button_toggle_sort_type(int param1, int param2); +static void button_toggle_sort_type(const generic_button *button); static void button_ok_cancel(int is_ok, int param2); static void input_box_changed(int is_addition_at_end); static void draw_file(const list_box_item *item); @@ -61,7 +62,7 @@ static image_button image_buttons[] = { }; static generic_button sort_by_button[] = { - {16, 437, 288, 26, button_toggle_sort_type, button_none, 0, 0} + {16, 437, 288, 26, button_toggle_sort_type} }; typedef struct { @@ -685,7 +686,7 @@ static void button_ok_cancel(int is_ok, int param2) } } -static void button_toggle_sort_type(int param1, int param2) +static void button_toggle_sort_type(const generic_button *button) { if (data.sort_type == SORT_BY_NAME) { data.sort_type = SORT_BY_DATE; diff --git a/src/window/gift_to_emperor.c b/src/window/gift_to_emperor.c index 297e553273..c40e4089fe 100644 --- a/src/window/gift_to_emperor.c +++ b/src/window/gift_to_emperor.c @@ -2,6 +2,7 @@ #include "city/emperor.h" #include "game/resource.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -12,16 +13,16 @@ #include "input/input.h" #include "window/advisors.h" -static void button_set_gift(int gift_id, int param2); -static void button_send_gift(int param1, int param2); -static void button_cancel(int param1, int param2); +static void button_set_gift(const generic_button *button); +static void button_send_gift(const generic_button *button); +static void button_cancel(const generic_button *button); static generic_button buttons[] = { - {208, 213, 300, 20, button_set_gift, button_none, 1, 0}, - {208, 233, 300, 20, button_set_gift, button_none, 2, 0}, - {208, 253, 300, 20, button_set_gift, button_none, 3, 0}, - {118, 336, 260, 20, button_send_gift, button_none, 0, 0}, - {400, 336, 160, 20, button_cancel, button_none, 0, 0}, + {208, 213, 300, 20, button_set_gift, 0, 1}, + {208, 233, 300, 20, button_set_gift, 0, 2}, + {208, 253, 300, 20, button_set_gift, 0, 3}, + {118, 336, 260, 20, button_send_gift}, + {400, 336, 160, 20, button_cancel}, }; static unsigned int focus_button_id; @@ -97,14 +98,15 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_set_gift(int gift_id, int param2) +static void button_set_gift(const generic_button *button) { + int gift_id = button->parameter1; if (city_emperor_set_gift_size(gift_id - 1)) { window_invalidate(); } } -static void button_send_gift(int param1, int param2) +static void button_send_gift(const generic_button *button) { if (city_emperor_can_send_gift(GIFT_MODEST)) { city_emperor_send_gift(); @@ -112,7 +114,7 @@ static void button_send_gift(int param1, int param2) } } -static void button_cancel(int param1, int param2) +static void button_cancel(const generic_button *button) { window_advisors_show(); } diff --git a/src/window/hold_festival.c b/src/window/hold_festival.c index 61a399f6c4..4c44e29ef6 100644 --- a/src/window/hold_festival.c +++ b/src/window/hold_festival.c @@ -7,6 +7,7 @@ #include "city/gods.h" #include "core/image_group.h" #include "game/resource.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -18,8 +19,8 @@ #include "window/advisors.h" #include "window/message_dialog.h" -static void button_god(int god, int param2); -static void button_size(int size, int param2); +static void button_god(const generic_button *button); +static void button_size(const generic_button *button); static void button_help(int param1, int param2); static void button_close(int param1, int param2); static void button_hold_festival(int param1, int param2); @@ -32,14 +33,14 @@ static image_button image_buttons_bottom[] = { }; static generic_button buttons_gods_size[] = { - {70, 96, 80, 90, button_god, button_none, 0, 0}, - {170, 96, 80, 90, button_god, button_none, 1, 0}, - {270, 96, 80, 90, button_god, button_none, 2, 0}, - {370, 96, 80, 90, button_god, button_none, 3, 0}, - {470, 96, 80, 90, button_god, button_none, 4, 0}, - {102, 216, 430, 26, button_size, button_none, 1, 0}, - {102, 246, 430, 26, button_size, button_none, 2, 0}, - {102, 276, 430, 26, button_size, button_none, 3, 0}, + {70, 96, 80, 90, button_god}, + {170, 96, 80, 90, button_god, 0, 1}, + {270, 96, 80, 90, button_god, 0, 2}, + {370, 96, 80, 90, button_god, 0, 3}, + {470, 96, 80, 90, button_god, 0, 4}, + {102, 216, 430, 26, button_size, 0, 1}, + {102, 246, 430, 26, button_size, 0, 2}, + {102, 276, 430, 26, button_size, 0, 3}, }; static unsigned int focus_button_id; @@ -146,14 +147,16 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_god(int god, int param2) +static void button_god(const generic_button *button) { + int god = button->parameter1; city_festival_select_god(god); window_invalidate(); } -static void button_size(int size, int param2) +static void button_size(const generic_button *button) { + int size = button->parameter1; if (!city_finance_out_of_money()) { if (city_festival_select_size(size)) { window_invalidate(); diff --git a/src/window/hold_games.c b/src/window/hold_games.c index 81bc44a0ae..12e15a6c9a 100644 --- a/src/window/hold_games.c +++ b/src/window/hold_games.c @@ -11,6 +11,7 @@ #include "city/gods.h" #include "core/image_group.h" #include "game/resource.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -25,7 +26,7 @@ #include "window/city.h" #include "window/message_dialog.h" -static void button_game(int god, int param2); +static void button_game(const generic_button *button); static void button_help(int param1, int param2); static void button_close(int param1, int param2); static void button_hold_games(int param1, int param2); @@ -41,10 +42,10 @@ static image_button action_button[] = { }; static generic_button buttons_games_size[] = { - {170, 96, 80, 90, button_game, button_none, 1, 0}, - {270, 96, 80, 90, button_game, button_none, 2, 0}, - {370, 96, 80, 90, button_game, button_none, 3, 0}, - //{370, 96, 80, 90, button_game, button_none, 4, 0}, + {170, 96, 80, 90, button_game, 0, 1}, + {270, 96, 80, 90, button_game, 0, 2}, + {370, 96, 80, 90, button_game, 0, 3}, + //{370, 96, 80, 90, button_game, 0, 4}, }; static struct { @@ -159,9 +160,9 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_game(int game, int param2) +static void button_game(const generic_button *button) { - city_data.games.selected_games_id = game; + city_data.games.selected_games_id = button->parameter1; window_invalidate(); } diff --git a/src/window/hotkey_config.c b/src/window/hotkey_config.c index 7617238959..973d1d97d7 100644 --- a/src/window/hotkey_config.c +++ b/src/window/hotkey_config.c @@ -5,6 +5,7 @@ #include "core/image_group.h" #include "core/lang.h" #include "core/string.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -27,9 +28,9 @@ static void on_scroll(void); -static void button_hotkey(int row, int is_alternative); -static void button_reset_defaults(int param1, int param2); -static void button_close(int save, int param2); +static void button_hotkey(const generic_button *button); +static void button_reset_defaults(const generic_button *button); +static void button_close(const generic_button *button); static scrollbar_type scrollbar = {580, 72, 352, 560, NUM_VISIBLE_OPTIONS, on_scroll, 1}; @@ -163,40 +164,40 @@ static hotkey_widget hotkey_widgets[] = { #define HOTKEY_BTN_HEIGHT 22 static generic_button hotkey_buttons[] = { - {HOTKEY_X_OFFSET_1, 80 + 24 * 0, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 0, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 0, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 0, 1}, - {HOTKEY_X_OFFSET_1, 80 + 24 * 1, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 1, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 1, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 1, 1}, - {HOTKEY_X_OFFSET_1, 80 + 24 * 2, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 2, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 2, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 2, 1}, - {HOTKEY_X_OFFSET_1, 80 + 24 * 3, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 3, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 3, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 3, 1}, - {HOTKEY_X_OFFSET_1, 80 + 24 * 4, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 4, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 4, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 4, 1}, - {HOTKEY_X_OFFSET_1, 80 + 24 * 5, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 5, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 5, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 5, 1}, - {HOTKEY_X_OFFSET_1, 80 + 24 * 6, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 6, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 6, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 6, 1}, - {HOTKEY_X_OFFSET_1, 80 + 24 * 7, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 7, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 7, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 7, 1}, - {HOTKEY_X_OFFSET_1, 80 + 24 * 8, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 8, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 8, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 8, 1}, - {HOTKEY_X_OFFSET_1, 80 + 24 * 9, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 9, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 9, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 9, 1}, - {HOTKEY_X_OFFSET_1, 80 + 24 * 10, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 10, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 10, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 10, 1}, - {HOTKEY_X_OFFSET_1, 80 + 24 * 11, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 11, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 11, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 11, 1}, - {HOTKEY_X_OFFSET_1, 80 + 24 * 12, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 12, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 12, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 12, 1}, - {HOTKEY_X_OFFSET_1, 80 + 24 * 13, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 13, 0}, - {HOTKEY_X_OFFSET_2, 80 + 24 * 13, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, button_none, 13, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 0, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 0, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 0, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 0, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 1, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 1, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 1, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 1, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 2, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 2, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 2, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 2, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 3, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 3, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 3, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 3, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 4, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 4, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 4, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 4, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 5, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 5, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 5, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 5, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 6, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 6, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 6, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 6, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 7, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 7, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 7, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 7, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 8, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 8, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 8, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 8, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 9, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 9, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 9, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 9, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 10, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 10, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 10, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 10, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 11, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 11, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 11, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 11, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 12, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 12, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 12, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 12, 1}, + {HOTKEY_X_OFFSET_1, 80 + 24 * 13, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 13, 0}, + {HOTKEY_X_OFFSET_2, 80 + 24 * 13, HOTKEY_BTN_WIDTH, HOTKEY_BTN_HEIGHT, button_hotkey, 0, 13, 1}, }; static generic_button bottom_buttons[] = { - {230, 430, 180, 30, button_reset_defaults, button_none}, - {415, 430, 100, 30, button_close, button_none, 0}, - {520, 430, 100, 30, button_close, button_none, 1}, + {230, 430, 180, 30, button_reset_defaults}, + {415, 430, 100, 30, button_close}, + {520, 430, 100, 30, button_close, 0, 1}, }; static translation_key bottom_button_texts[] = { @@ -379,8 +380,10 @@ static void set_hotkey(hotkey_action action, int index, key_type key, key_modifi } } -static void button_hotkey(int row, int is_alternative) +static void button_hotkey(const generic_button *button) { + int row = button->parameter1; + int is_alternative = button->parameter2; hotkey_widget *widget = &hotkey_widgets[row + scrollbar.scroll_position]; if (widget->action == HOTKEY_HEADER) { return; @@ -388,7 +391,7 @@ static void button_hotkey(int row, int is_alternative) window_hotkey_editor_show(widget->action, is_alternative, set_hotkey); } -static void button_reset_defaults(int param1, int param2) +static void button_reset_defaults(const generic_button *button) { for (int action = 0; action < HOTKEY_MAX_ITEMS; action++) { for (int index = 0; index < 2; index++) { @@ -403,8 +406,10 @@ static void on_scroll(void) window_invalidate(); } -static void button_close(int save, int param2) +static void button_close(const generic_button *button) { + int save = button->parameter1; + if (!save) { window_go_back(); return; diff --git a/src/window/hotkey_editor.c b/src/window/hotkey_editor.c index 167fc56c1d..a4c90d9cd5 100644 --- a/src/window/hotkey_editor.c +++ b/src/window/hotkey_editor.c @@ -3,6 +3,7 @@ #include "core/hotkey_config.h" #include "core/image_group.h" #include "core/string.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -13,11 +14,11 @@ #define NUM_BOTTOM_BUTTONS 2 -static void button_close(int save, int param2); +static void button_close(const generic_button *button); static generic_button bottom_buttons[] = { - {192, 228, 120, 24, button_close, button_none, 0}, - {328, 228, 120, 24, button_close, button_none, 1}, + {192, 228, 120, 24, button_close}, + {328, 228, 120, 24, button_close, 0, 1}, }; static translation_key bottom_button_texts[] = { @@ -86,12 +87,13 @@ static void handle_input(const mouse *m, const hotkeys *h) int handled = 0; handled |= generic_buttons_handle_mouse(m_dialog, 0, 0, bottom_buttons, NUM_BOTTOM_BUTTONS, &data.focus_button); if (!handled && m->right.went_up) { - button_close(0, 0); + window_go_back(); } } -static void button_close(int ok, int param2) +static void button_close(const generic_button *button) { + int ok = button->parameter1; // destroy window before callback call, because there may appear another popup window // by design new popup window can't be showed over another popup window window_go_back(); @@ -103,9 +105,10 @@ static void button_close(int ok, int param2) void window_hotkey_editor_key_pressed(key_type key, key_modifier_type modifiers) { if (key == KEY_TYPE_ENTER && modifiers == KEY_MOD_NONE) { - button_close(1, 0); + window_go_back(); + data.callback(data.action, data.index, data.key, data.modifiers); } else if (key == KEY_TYPE_ESCAPE && modifiers == KEY_MOD_NONE) { - button_close(0, 0); + window_go_back(); } else { if (key != KEY_TYPE_NONE) { data.key = key; diff --git a/src/window/labor_priority.c b/src/window/labor_priority.c index 0b2abf6261..814d3c8f8f 100644 --- a/src/window/labor_priority.c +++ b/src/window/labor_priority.c @@ -10,7 +10,7 @@ #define MIN_DIALOG_WIDTH 320 -static void button_set_priority(int new_priority, int param2); +static void button_set_priority(const generic_button *button); static struct { int category; @@ -19,16 +19,16 @@ static struct { } data; static generic_button priority_buttons[] = { - {180, 256, 280, 25, button_set_priority, button_none, 0, 0}, // no prio - {178, 221, 27, 27, button_set_priority, button_none, 1, 0}, - {210, 221, 27, 27, button_set_priority, button_none, 2, 0}, - {242, 221, 27, 27, button_set_priority, button_none, 3, 0}, - {274, 221, 27, 27, button_set_priority, button_none, 4, 0}, - {306, 221, 27, 27, button_set_priority, button_none, 5, 0}, - {338, 221, 27, 27, button_set_priority, button_none, 6, 0}, - {370, 221, 27, 27, button_set_priority, button_none, 7, 0}, - {402, 221, 27, 27, button_set_priority, button_none, 8, 0}, - {434, 221, 27, 27, button_set_priority, button_none, 9, 0}, + {180, 256, 280, 25, button_set_priority}, // no priority + {178, 221, 27, 27, button_set_priority, 0, 1}, + {210, 221, 27, 27, button_set_priority, 0, 2}, + {242, 221, 27, 27, button_set_priority, 0, 3}, + {274, 221, 27, 27, button_set_priority, 0, 4}, + {306, 221, 27, 27, button_set_priority, 0, 5}, + {338, 221, 27, 27, button_set_priority, 0, 6}, + {370, 221, 27, 27, button_set_priority, 0, 7}, + {402, 221, 27, 27, button_set_priority, 0, 8}, + {434, 221, 27, 27, button_set_priority, 0, 9}, }; static void init(int category) @@ -109,8 +109,9 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_set_priority(int new_priority, int param2) +static void button_set_priority(const generic_button *button) { + int new_priority = button->parameter1; city_labor_set_priority(data.category, new_priority); window_go_back(); } diff --git a/src/window/main_menu.c b/src/window/main_menu.c index 8f53439450..a633dd99ac 100644 --- a/src/window/main_menu.c +++ b/src/window/main_menu.c @@ -26,7 +26,7 @@ #define MAX_BUTTONS 6 -static void button_click(int type, int param2); +static void button_click(const generic_button *button); static struct { unsigned int focus_button_id; @@ -34,12 +34,12 @@ static struct { } data; static generic_button buttons[] = { - {192, 130, 256, 25, button_click, button_none, 1, 0}, - {192, 170, 256, 25, button_click, button_none, 2, 0}, - {192, 210, 256, 25, button_click, button_none, 3, 0}, - {192, 250, 256, 25, button_click, button_none, 4, 0}, - {192, 290, 256, 25, button_click, button_none, 5, 0}, - {192, 330, 256, 25, button_click, button_none, 6, 0}, + {192, 130, 256, 25, button_click, 0, 1}, + {192, 170, 256, 25, button_click, 0, 2}, + {192, 210, 256, 25, button_click, 0, 3}, + {192, 250, 256, 25, button_click, 0, 4}, + {192, 290, 256, 25, button_click, 0, 5}, + {192, 330, 256, 25, button_click, 0, 6}, }; static void draw_version_string(void) @@ -115,8 +115,10 @@ static void confirm_exit(int accepted, int checked) } } -static void button_click(int type, int param2) +static void button_click(const generic_button *button) { + int type = button->parameter1; + if (type == 1) { window_select_campaign_show(); } else if (type == 2) { diff --git a/src/window/message_list.c b/src/window/message_list.c index 29b654277b..c2d6db26f6 100644 --- a/src/window/message_list.c +++ b/src/window/message_list.c @@ -6,6 +6,7 @@ #include "core/lang.h" #include "game/campaign.h" #include "game/time.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -27,10 +28,10 @@ static void button_help(int param1, int param2); static void button_close(int param1, int param2); -static void button_message(int param1, int param2); -static void button_delete(int param1, int param2); -static void button_delete_all_read(int param1, int param2); -static void button_delete_all_common(int param1, int param2); +static void button_message(const generic_button *button); +static void button_delete(const generic_button *button); +static void button_delete_all_read(const generic_button *button); +static void button_delete_all_common(const generic_button *button); static void button_mission_briefing(int param1, int param2); static void on_scroll(void); @@ -44,24 +45,24 @@ static image_button show_briefing_button = { 0, 0, 33, 22, IB_NORMAL, GROUP_SIDEBAR_BRIEFING_ROTATE_BUTTONS, 0, button_mission_briefing, button_none, 0, 0, 1 }; static generic_button generic_buttons_messages[] = { - {0, 0, 412, 18, button_message, button_delete, 0, 0}, - {0, 20, 412, 18, button_message, button_delete, 1, 0}, - {0, 40, 412, 18, button_message, button_delete, 2, 0}, - {0, 60, 412, 18, button_message, button_delete, 3, 0}, - {0, 80, 412, 18, button_message, button_delete, 4, 0}, - {0, 100, 412, 18, button_message, button_delete, 5, 0}, - {0, 120, 412, 18, button_message, button_delete, 6, 0}, - {0, 140, 412, 18, button_message, button_delete, 7, 0}, - {0, 160, 412, 18, button_message, button_delete, 8, 0}, - {0, 180, 412, 18, button_message, button_delete, 9, 0}, + {0, 0, 412, 18, button_message, button_delete}, + {0, 20, 412, 18, button_message, button_delete, 1}, + {0, 40, 412, 18, button_message, button_delete, 2}, + {0, 60, 412, 18, button_message, button_delete, 3}, + {0, 80, 412, 18, button_message, button_delete, 4}, + {0, 100, 412, 18, button_message, button_delete, 5}, + {0, 120, 412, 18, button_message, button_delete, 6}, + {0, 140, 412, 18, button_message, button_delete, 7}, + {0, 160, 412, 18, button_message, button_delete, 8}, + {0, 180, 412, 18, button_message, button_delete, 9}, }; static generic_button generic_button_delete_read[] = { - { 0, 0, 20, 20, button_delete_all_read, button_none, 0, 0 } + { 0, 0, 20, 20, button_delete_all_read } }; static generic_button generic_button_delete_common[] = { - { 0, 0, 20, 20, button_delete_all_common, button_none, 0, 0 } + { 0, 0, 20, 20, button_delete_all_common } }; @@ -285,9 +286,10 @@ static void button_close(int param1, int param2) window_city_show(); } -static void button_message(int param1, int param2) +static void button_message(const generic_button *button) { - int id = city_message_set_current(scrollbar.scroll_position + param1); + int index = button->parameter1; + int id = city_message_set_current(scrollbar.scroll_position + index); if (id < city_message_count()) { const city_message *msg = city_message_get(id); city_message_mark_read(id); @@ -303,8 +305,9 @@ static void button_message(int param1, int param2) } } -static void button_delete(int id_to_delete, int param2) +static void button_delete(const generic_button *button) { + int id_to_delete = button->parameter1; int id = city_message_set_current(scrollbar.scroll_position + id_to_delete); if (id < city_message_count()) { city_message_delete(id); @@ -313,7 +316,7 @@ static void button_delete(int id_to_delete, int param2) } } -static void button_delete_all_common(int param1, int param2) +static void button_delete_all_common(const generic_button *button) { for (int id = 0; id < city_message_count();) { const city_message *msg = city_message_get(id); @@ -327,7 +330,7 @@ static void button_delete_all_common(int param1, int param2) window_invalidate(); } -static void button_delete_all_read(int param1, int param2) +static void button_delete_all_read(const generic_button *button) { for (int id = 0; id < city_message_count();) { const city_message* msg = city_message_get(id); diff --git a/src/window/military_menu.c b/src/window/military_menu.c index a05548846f..43dd5a6750 100644 --- a/src/window/military_menu.c +++ b/src/window/military_menu.c @@ -21,15 +21,15 @@ static struct { unsigned int focus_button_id; } data; -static void button_menu_item(int index, int param2); +static void button_menu_item(const generic_button *button); static generic_button menu_buttons[] = { - {0, 0, 160, 24, button_menu_item, button_none, 1, 0}, - {0, 24, 160, 24, button_menu_item, button_none, 2, 0}, - {0, 48, 160, 24, button_menu_item, button_none, 3, 0}, - {0, 72, 160, 24, button_menu_item, button_none, 4, 0}, - {0, 96, 160, 24, button_menu_item, button_none, 5, 0}, - {0, 120, 160, 24, button_menu_item, button_none, 6, 0}, + {0, 0, 160, 24, button_menu_item, 0, 1}, + {0, 24, 160, 24, button_menu_item, 0, 2}, + {0, 48, 160, 24, button_menu_item, 0, 3}, + {0, 72, 160, 24, button_menu_item, 0, 4}, + {0, 96, 160, 24, button_menu_item, 0, 5}, + {0, 120, 160, 24, button_menu_item, 0, 6}, }; static int get_sidebar_x_offset(void) @@ -84,8 +84,9 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_menu_item(int index, int param2) +static void button_menu_item(const generic_button *button) { + int index = button->parameter1; int formation_id = formation_for_legion(index); const formation *m = formation_get(formation_id); city_view_go_to_grid_offset(map_grid_offset(m->x_home, m->y_home)); diff --git a/src/window/mission_end.c b/src/window/mission_end.c index daa4f07ac2..359c04edd2 100644 --- a/src/window/mission_end.c +++ b/src/window/mission_end.c @@ -37,10 +37,10 @@ #include -static void button_fired(int param1, int param2); +static void button_fired(const generic_button *button); static generic_button fired_buttons[] = { - {80, 224, 480, 25, button_fired, button_none, 0, 0}, + {80, 224, 480, 25, button_fired}, }; static struct { @@ -327,7 +327,7 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_fired(int param1, int param2) +static void button_fired(const generic_button *button) { sound_music_stop(); sound_speech_stop(); diff --git a/src/window/mission_list.c b/src/window/mission_list.c index cb26bbf9cd..5731e3bfe9 100644 --- a/src/window/mission_list.c +++ b/src/window/mission_list.c @@ -7,6 +7,7 @@ #include "game/campaign.h" #include "game/file.h" #include "game/file_io.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -30,8 +31,8 @@ #define SELECTED_ITEM_INFO_X_OFFSET 272 #define SELECTED_ITEM_INFO_WIDTH ((int) (MISSION_MAP_MAX_WIDTH)) -static void start_scenario(int param1, int param2); -static void button_back(int param1, int param2); +static void button_start_scenario(const generic_button *button); +static void button_back(const generic_button *button); static void draw_item(const list_box_item *item); static void select_item(unsigned int index, int is_double_click); static void item_tooltip(const list_box_item *item, tooltip_context *c); @@ -76,8 +77,8 @@ static struct { } data; static generic_button bottom_buttons[] = { - {344, 436, 90, 30, button_back, button_none, TR_BUTTON_CANCEL }, - {444, 436, 180, 30, start_scenario, button_none, TR_WINDOW_MISSION_LIST_BUTTON_BEGIN_SCENARIO }, + {344, 436, 90, 30, button_back, 0, TR_BUTTON_CANCEL }, + {444, 436, 180, 30, button_start_scenario, 0, TR_WINDOW_MISSION_LIST_BUTTON_BEGIN_SCENARIO }, }; static list_box_type list_box = { @@ -382,11 +383,11 @@ static void handle_input(const mouse *m, const hotkeys *h) return; } if (input_go_back_requested(m, h)) { - button_back(0, 0); + button_back(0); } } -static void button_back(int param1, int param2) +static void button_back(const generic_button *button) { window_select_campaign_show(); } @@ -399,7 +400,7 @@ static void select_item(unsigned int index, int is_double_click) } if (is_double_click) { - start_scenario(0, 0); + button_start_scenario(0); return; } @@ -415,7 +416,7 @@ static void select_item(unsigned int index, int is_double_click) } } -static void start_scenario(int param1, int param2) +static void button_start_scenario(const generic_button *button) { if (data.selected_item->type == ITEM_TYPE_NONE) { return; diff --git a/src/window/numeric_input.c b/src/window/numeric_input.c index f46510f18a..385c105d8e 100644 --- a/src/window/numeric_input.c +++ b/src/window/numeric_input.c @@ -14,31 +14,31 @@ #include -static void button_number(int number, int param2); -static void button_accept(int param1, int param2); -static void button_negative(int param1, int param2); -static void button_delete(int param1, int param2); -static void button_cancel(int param1, int param2); +static void button_number(const generic_button *button); +static void button_accept(const generic_button *button); +static void button_negative(const generic_button *button); +static void button_delete(const generic_button *button); +static void button_cancel(const generic_button *button); static void input_number(int number, int minus); static void input_accept(void); static void input_delete(void); static generic_button buttons[] = { - {21, 51, 25, 25, button_number, button_none, 1, 0}, - {51, 51, 25, 25, button_number, button_none, 2, 0}, - {81, 51, 25, 25, button_number, button_none, 3, 0}, - {21, 81, 25, 25, button_number, button_none, 4, 0}, - {51, 81, 25, 25, button_number, button_none, 5, 0}, - {81, 81, 25, 25, button_number, button_none, 6, 0}, - {21, 111, 25, 25, button_number, button_none, 7, 0}, - {51, 111, 25, 25, button_number, button_none, 8, 0}, - {81, 111, 25, 25, button_number, button_none, 9, 0}, - {21, 141, 25, 25, button_number, button_none, 0, 0}, - {51, 141, 25, 25, button_negative, button_none, 0, 0}, - {51, 171, 55, 25, button_accept, button_none, 1, 0}, - {21, 201, 25, 25, button_delete, button_none, 1, 0}, - {51, 201, 55, 25, button_cancel, button_none, 1, 0} + {21, 51, 25, 25, button_number, 0, 1}, + {51, 51, 25, 25, button_number, 0, 2}, + {81, 51, 25, 25, button_number, 0, 3}, + {21, 81, 25, 25, button_number, 0, 4}, + {51, 81, 25, 25, button_number, 0, 5}, + {81, 81, 25, 25, button_number, 0, 6}, + {21, 111, 25, 25, button_number, 0, 7}, + {51, 111, 25, 25, button_number, 0, 8}, + {81, 111, 25, 25, button_number, 0, 9}, + {21, 141, 25, 25, button_number, 0, 0}, + {51, 141, 25, 25, button_negative}, + {51, 171, 55, 25, button_accept}, + {21, 201, 25, 25, button_delete}, + {51, 201, 55, 25, button_cancel} }; static struct { @@ -143,12 +143,13 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_number(int number, int param2) +static void button_number(const generic_button *button) { + int number = button->parameter1; input_number(number, 0); } -static void button_accept(int param1, int param2) +static void button_accept(const generic_button *button) { input_accept(); } @@ -163,17 +164,17 @@ static void input_negative(void) } } -static void button_negative(int param1, int param2) +static void button_negative(const generic_button *button) { input_negative(); } -static void button_delete(int param1, int param2) +static void button_delete(const generic_button *button) { input_delete(); } -static void button_cancel(int param1, int param2) +static void button_cancel(const generic_button *button) { close(); } diff --git a/src/window/option_popup.c b/src/window/option_popup.c index 187a353b94..2f9cb3d939 100644 --- a/src/window/option_popup.c +++ b/src/window/option_popup.c @@ -2,6 +2,7 @@ #include "assets/assets.h" #include "core/image_group.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -24,14 +25,14 @@ static int border_image_ids[2]; static void on_scroll(void); -static void button_select_option(int option, int param2); +static void button_select_option(const generic_button *button); static generic_button buttons[] = { - {40, 0, 180, 20, button_select_option, button_none, CANCEL_BUTTON, 0}, - {260, 0, 180, 20, button_select_option, button_none, CONFIRM_BUTTON, 0}, - {20, 0, 0, 0, button_select_option, button_none, 2, 0}, - {20, 0, 0, 0, button_select_option, button_none, 3, 0}, - {20, 0, 0, 0, button_select_option, button_none, 4, 0} + {40, 0, 180, 20, button_select_option, 0, CANCEL_BUTTON}, + {260, 0, 180, 20, button_select_option, 0, CONFIRM_BUTTON}, + {20, 0, 0, 0, button_select_option, 0, 2}, + {20, 0, 0, 0, button_select_option, 0, 3}, + {20, 0, 0, 0, button_select_option, 0, 4} }; static scrollbar_type scrollbar = { 420, START_Y_OFFSET + 40, 0, 400, 0, on_scroll, 0, 4 }; @@ -214,8 +215,10 @@ static void on_scroll(void) window_invalidate(); } -static void button_select_option(int option, int param2) +static void button_select_option(const generic_button *button) { + int option = button->parameter1; + switch (option) { case CANCEL_BUTTON: data.close_func(0); diff --git a/src/window/overlay_menu.c b/src/window/overlay_menu.c index 12577262ac..ed12cb25fc 100644 --- a/src/window/overlay_menu.c +++ b/src/window/overlay_menu.c @@ -21,35 +21,35 @@ #define MAX_BUTTONS 8 -static void button_menu_item(int index, int param2); -static void button_submenu_item(int index, int param2); +static void button_menu_item(const generic_button *button); +static void button_submenu_item(const generic_button *button); #define OVERLAY_BUTTONS 11 static generic_button menu_buttons[] = { - {0, 0, 160, 24, button_menu_item, button_none, 0, 0}, - {0, 24, 160, 24, button_menu_item, button_none, 1, 0}, - {0, 48, 160, 24, button_menu_item, button_none, 2, 0}, - {0, 72, 160, 24, button_menu_item, button_none, 3, 0}, - {0, 96, 160, 24, button_menu_item, button_none, 4, 0}, - {0, 120, 160, 24, button_menu_item, button_none, 5, 0}, - {0, 144, 160, 24, button_menu_item, button_none, 6, 0}, - {0, 168, 160, 24, button_menu_item, button_none, 7, 0}, - {0, 192, 160, 24, button_menu_item, button_none, 8, 0}, - {0, 216, 160, 24, button_menu_item, button_none, 9, 0}, - {0, 240, 160, 24, button_menu_item, button_none, 10, 0}, + {0, 0, 160, 24, button_menu_item, 0, 0}, + {0, 24, 160, 24, button_menu_item, 0, 1}, + {0, 48, 160, 24, button_menu_item, 0, 2}, + {0, 72, 160, 24, button_menu_item, 0, 3}, + {0, 96, 160, 24, button_menu_item, 0, 4}, + {0, 120, 160, 24, button_menu_item, 0, 5}, + {0, 144, 160, 24, button_menu_item, 0, 6}, + {0, 168, 160, 24, button_menu_item, 0, 7}, + {0, 192, 160, 24, button_menu_item, 0, 8}, + {0, 216, 160, 24, button_menu_item, 0, 9}, + {0, 240, 160, 24, button_menu_item, 0, 10}, }; static generic_button submenu_buttons[] = { - {0, 0, 160, 24, button_submenu_item, button_none, 0, 0}, - {0, 24, 160, 24, button_submenu_item, button_none, 1, 0}, - {0, 48, 160, 24, button_submenu_item, button_none, 2, 0}, - {0, 72, 160, 24, button_submenu_item, button_none, 3, 0}, - {0, 96, 160, 24, button_submenu_item, button_none, 4, 0}, - {0, 120, 160, 24, button_submenu_item, button_none, 5, 0}, - {0, 144, 160, 24, button_submenu_item, button_none, 6, 0}, - {0, 168, 160, 24, button_submenu_item, button_none, 7, 0}, - {0, 192, 160, 24, button_submenu_item, button_none, 8, 0}, - {0, 216, 160, 24, button_submenu_item, button_none, 9, 0}, + {0, 0, 160, 24, button_submenu_item, 0, 0}, + {0, 24, 160, 24, button_submenu_item, 0, 1}, + {0, 48, 160, 24, button_submenu_item, 0, 2}, + {0, 72, 160, 24, button_submenu_item, 0, 3}, + {0, 96, 160, 24, button_submenu_item, 0, 4}, + {0, 120, 160, 24, button_submenu_item, 0, 5}, + {0, 144, 160, 24, button_submenu_item, 0, 6}, + {0, 168, 160, 24, button_submenu_item, 0, 7}, + {0, 192, 160, 24, button_submenu_item, 0, 8}, + {0, 216, 160, 24, button_submenu_item, 0, 9}, }; static const int MENU_ID_TO_OVERLAY[OVERLAY_BUTTONS] = { OVERLAY_NONE, OVERLAY_WATER, 1, 3, 5, 6, 7, OVERLAY_RELIGION, OVERLAY_DESIRABILITY, OVERLAY_SENTIMENT, OVERLAY_ROADS }; @@ -58,11 +58,11 @@ static const int ADDITIONAL_OVERLAY_TR[] = { TR_OVERLAY_ROADS, TR_OVERLAY_LEVY, static const int SUBMENU_ID_TO_OVERLAY[6][OVERLAY_BUTTONS] = { {0}, - {OVERLAY_FIRE, OVERLAY_DAMAGE, OVERLAY_CRIME, OVERLAY_NATIVE, OVERLAY_PROBLEMS, OVERLAY_ENEMY, 0}, - {OVERLAY_ENTERTAINMENT, OVERLAY_TAVERN, OVERLAY_THEATER, OVERLAY_AMPHITHEATER, OVERLAY_ARENA, OVERLAY_COLOSSEUM, OVERLAY_HIPPODROME, 0}, - {OVERLAY_EDUCATION, OVERLAY_SCHOOL, OVERLAY_LIBRARY, OVERLAY_ACADEMY, 0}, - {OVERLAY_HEALTH, OVERLAY_BARBER, OVERLAY_BATHHOUSE, OVERLAY_CLINIC, OVERLAY_HOSPITAL, OVERLAY_SICKNESS, 0}, - {OVERLAY_LOGISTICS, OVERLAY_FOOD_STOCKS, OVERLAY_EFFICIENCY, OVERLAY_MOTHBALL, OVERLAY_TAX_INCOME, OVERLAY_LEVY, OVERLAY_EMPLOYMENT, 0}, + {OVERLAY_FIRE, OVERLAY_DAMAGE, OVERLAY_CRIME, OVERLAY_NATIVE, OVERLAY_PROBLEMS, OVERLAY_ENEMY}, + {OVERLAY_ENTERTAINMENT, OVERLAY_TAVERN, OVERLAY_THEATER, OVERLAY_AMPHITHEATER, OVERLAY_ARENA, OVERLAY_COLOSSEUM, OVERLAY_HIPPODROME}, + {OVERLAY_EDUCATION, OVERLAY_SCHOOL, OVERLAY_LIBRARY, OVERLAY_ACADEMY}, + {OVERLAY_HEALTH, OVERLAY_BARBER, OVERLAY_BATHHOUSE, OVERLAY_CLINIC, OVERLAY_HOSPITAL, OVERLAY_SICKNESS}, + {OVERLAY_LOGISTICS, OVERLAY_FOOD_STOCKS, OVERLAY_EFFICIENCY, OVERLAY_MOTHBALL, OVERLAY_TAX_INCOME, OVERLAY_LEVY, OVERLAY_EMPLOYMENT}, }; static struct { @@ -205,8 +205,10 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_menu_item(int index, int param2) +static void button_menu_item(const generic_button *button) { + int index = button->parameter1; + if (MENU_ID_TO_SUBMENU_ID[index] == 0) { game_state_set_overlay(MENU_ID_TO_OVERLAY[index]); close_submenu(); @@ -220,8 +222,10 @@ static void button_menu_item(int index, int param2) } } -static void button_submenu_item(int index, int param2) +static void button_submenu_item(const generic_button *button) { + int index = button->parameter1; + int overlay = SUBMENU_ID_TO_OVERLAY[data.selected_submenu][index]; if (overlay) { game_state_set_overlay(overlay); diff --git a/src/window/popup_dialog.c b/src/window/popup_dialog.c index 5e5fd3c896..6283b08c4a 100644 --- a/src/window/popup_dialog.c +++ b/src/window/popup_dialog.c @@ -20,7 +20,7 @@ #define PROCEED_TEXT 5 #define CHECKBOX_CHECK_SIZE 20 -static void button_checkbox(int param1, int param2); +static void button_checkbox(const generic_button *button); static void button_ok(int param1, int param2); static void button_cancel(int param1, int param2); static void confirm(void); @@ -30,7 +30,7 @@ static image_button buttons[] = { {256, 100, 39, 26, IB_NORMAL, GROUP_OK_CANCEL_SCROLL_BUTTONS, 4, button_cancel, button_none, 0, 0, 1}, }; -static generic_button checkbox = { 160, 180, 360, 20, button_checkbox, button_none }; +static generic_button checkbox = { 160, 180, 360, 20, button_checkbox }; static struct { int ok_clicked; @@ -133,7 +133,7 @@ static void button_cancel(int param1, int param2) data.close_func(0, 0); } -static void button_checkbox(int param1, int param2) +static void button_checkbox(const generic_button *button) { data.checked ^= 1; window_request_refresh(); diff --git a/src/window/race_bet.c b/src/window/race_bet.c index 2890621c47..804f3dc686 100644 --- a/src/window/race_bet.c +++ b/src/window/race_bet.c @@ -16,15 +16,15 @@ #include "translation/translation.h" static void arrow_button_bet(int is_down, int param2); -static void button_horse_selection(int option, int param2); -static void button_confirm(int option, int param2); +static void button_horse_selection(const generic_button *button); +static void button_confirm(const generic_button *button); static void button_close(int param1, int param2); static generic_button buttons[] = { - {34, 145, 81, 91, button_horse_selection, button_none, BLUE_HORSE, 0}, - {144, 145, 81, 91, button_horse_selection, button_none, RED_HORSE, 0}, - {254, 145, 81, 91, button_horse_selection, button_none, WHITE_HORSE, 0}, - {364, 145, 81, 91, button_horse_selection, button_none, GREEN_HORSE, 0} + {34, 145, 81, 91, button_horse_selection, 0, BLUE_HORSE}, + {144, 145, 81, 91, button_horse_selection, 0, RED_HORSE}, + {254, 145, 81, 91, button_horse_selection, 0, WHITE_HORSE}, + {364, 145, 81, 91, button_horse_selection, 0, GREEN_HORSE} }; static arrow_button amount_buttons[] = { @@ -32,7 +32,7 @@ static arrow_button amount_buttons[] = { {130, 306, 15, 24, arrow_button_bet, 0, 0} }; static generic_button bet_buttons[] = { - {90, 354, 300, 20, button_confirm, button_none, 1, 0}, + {90, 354, 300, 20, button_confirm}, }; static image_button image_button_close[] = { @@ -166,15 +166,16 @@ static void arrow_button_bet(int is_down, int param2) } } -static void button_horse_selection(int option, int param2) +static void button_horse_selection(const generic_button *button) { + int option = button->parameter1; if (!data.in_progress_bet) { data.chosen_horse = option; window_request_refresh(); } } -static void button_confirm(int option, int param2) +static void button_confirm(const generic_button *button) { // save bet and go back if (!city_data.games.chosen_horse && data.chosen_horse && data.bet_amount) { diff --git a/src/window/resource_settings.c b/src/window/resource_settings.c index 371f52328a..6cad6202a3 100644 --- a/src/window/resource_settings.c +++ b/src/window/resource_settings.c @@ -25,9 +25,9 @@ static void button_help(int param1, int param2); static void button_ok(int param1, int param2); static void button_trade_up_down(int trade_type, int is_down); -static void button_toggle_industry(int param1, int param2); -static void button_toggle_trade(int status, int param2); -static void button_toggle_stockpile(int param1, int param2); +static void button_toggle_industry(const generic_button *button); +static void button_toggle_trade(const generic_button *button); +static void button_toggle_stockpile(const generic_button *button); static image_button resource_image_buttons[] = { {26, 332, 27, 27, IB_NORMAL, GROUP_CONTEXT_ICONS, 0, button_help, button_none, 0, 0, 1}, @@ -45,10 +45,10 @@ static arrow_button export_amount_arrow_buttons[] = { }; static generic_button resource_generic_buttons[] = { - {66, 250, 496, 30, button_toggle_industry, button_none, 0, 0}, - {30, 212, 286, 30, button_toggle_trade, button_none, TRADE_STATUS_IMPORT, 0}, - {322, 212, 286, 30, button_toggle_trade, button_none, TRADE_STATUS_EXPORT, 0}, - {66, 288, 496, 50, button_toggle_stockpile, button_none, 0, 0}, + {66, 250, 496, 30, button_toggle_industry}, + {30, 212, 286, 30, button_toggle_trade, 0, TRADE_STATUS_IMPORT}, + {322, 212, 286, 30, button_toggle_trade, 0, TRADE_STATUS_EXPORT}, + {66, 288, 496, 50, button_toggle_stockpile}, }; static struct { @@ -258,15 +258,17 @@ static void button_trade_up_down(int trade_type, int is_down) } } -static void button_toggle_industry(int param1, int param2) +static void button_toggle_industry(const generic_button *button) { if (building_count_total(resource_get_data(data.resource)->industry) > 0) { city_resource_toggle_mothballed(data.resource); } } -static void button_toggle_trade(int status, int param2) +static void button_toggle_trade(const generic_button *button) { + int status = button->parameter1; + if (!resource_is_storable(data.resource)) { return; } @@ -277,7 +279,7 @@ static void button_toggle_trade(int status, int param2) city_resource_cycle_trade_status(data.resource, status); } -static void button_toggle_stockpile(int param1, int param2) +static void button_toggle_stockpile(const generic_button *button) { if (resource_is_storable(data.resource)) { city_resource_toggle_stockpiled(data.resource); diff --git a/src/window/select_campaign.c b/src/window/select_campaign.c index 679abffc14..583aa21b5c 100644 --- a/src/window/select_campaign.c +++ b/src/window/select_campaign.c @@ -8,6 +8,7 @@ #include "core/string.h" #include "game/campaign.h" #include "game/settings.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -31,17 +32,17 @@ #define CAMPAIGN_LIST_Y_POSITION 96 #define ORIGINAL_CAMPAIGN_ID 0 -static void start_mission(int param1, int param2); -static void button_mission_list(int param1, int param2); -static void button_back(int param1, int param2); +static void button_start_mission(const generic_button *button); +static void button_mission_list(const generic_button *button); +static void button_back(const generic_button *button); static void draw_campaign_item(const list_box_item *item); static void select_campaign(unsigned int index, int is_double_click); static void campaign_name_tooltip(const list_box_item *item, tooltip_context *c); static generic_button bottom_buttons[] = { - {16, 436, 90, 30, button_back, button_none, TR_BUTTON_CANCEL }, - {444, 436, 180, 30, start_mission, button_none, TR_WINDOW_CAMPAIGN_BUTTON_BEGIN_CAMPAIGN }, - {234, 436, 200, 30, button_mission_list, button_none, TR_WINDOW_CAMPAIGN_BUTTON_MISSION_LIST } + {16, 436, 90, 30, button_back, 0, TR_BUTTON_CANCEL }, + {444, 436, 180, 30, button_start_mission, 0, TR_WINDOW_CAMPAIGN_BUTTON_BEGIN_CAMPAIGN }, + {234, 436, 200, 30, button_mission_list, 0, TR_WINDOW_CAMPAIGN_BUTTON_MISSION_LIST } }; #define NUM_BOTTOM_BUTTONS (sizeof(bottom_buttons) / sizeof(generic_button)) @@ -189,7 +190,7 @@ static void draw_foreground(void) static void handle_input(const mouse *m, const hotkeys *h) { if (input_box_is_accepted()) { - start_mission(0, 0); + button_start_mission(0); return; } @@ -203,11 +204,11 @@ static void handle_input(const mouse *m, const hotkeys *h) return; } if (input_go_back_requested(m, h)) { - button_back(0, 0); + button_back(0); } } -static void button_back(int param1, int param2) +static void button_back(const generic_button *button) { input_box_stop(&player_name_input); game_campaign_clear(); @@ -229,11 +230,11 @@ static void select_campaign(unsigned int index, int is_double_click) window_request_refresh(); if (is_double_click) { - start_mission(0, 0); + button_start_mission(0); } } -static void start_mission(int param1, int param2) +static void button_start_mission(const generic_button *button) { const campaign_info *info = game_campaign_get_info(); if (!info) { @@ -252,7 +253,7 @@ static void start_mission(int param1, int param2) window_mission_selection_show(); } -static void button_mission_list(int param1, int param2) +static void button_mission_list(const generic_button *button) { const campaign_info *info = game_campaign_get_info(); if (!info || !info->current_mission) { diff --git a/src/window/select_list.c b/src/window/select_list.c index d533da1bd7..f4489b382c 100644 --- a/src/window/select_list.c +++ b/src/window/select_list.c @@ -18,52 +18,52 @@ enum { MODE_GROUP, }; -static void select_item(int id, int list_id); +static void button_select_item(const generic_button *button); static generic_button buttons_list1[MAX_ITEMS_PER_LIST] = { - {5, 8, 190, 18, select_item, button_none, 0, 0}, - {5, 28, 190, 18, select_item, button_none, 1, 0}, - {5, 48, 190, 18, select_item, button_none, 2, 0}, - {5, 68, 190, 18, select_item, button_none, 3, 0}, - {5, 88, 190, 18, select_item, button_none, 4, 0}, - {5, 108, 190, 18, select_item, button_none, 5, 0}, - {5, 128, 190, 18, select_item, button_none, 6, 0}, - {5, 148, 190, 18, select_item, button_none, 7, 0}, - {5, 168, 190, 18, select_item, button_none, 8, 0}, - {5, 188, 190, 18, select_item, button_none, 9, 0}, - {5, 208, 190, 18, select_item, button_none, 10, 0}, - {5, 228, 190, 18, select_item, button_none, 11, 0}, - {5, 248, 190, 18, select_item, button_none, 12, 0}, - {5, 268, 190, 18, select_item, button_none, 13, 0}, - {5, 288, 190, 18, select_item, button_none, 14, 0}, - {5, 308, 190, 18, select_item, button_none, 15, 0}, - {5, 328, 190, 18, select_item, button_none, 16, 0}, - {5, 348, 190, 18, select_item, button_none, 17, 0}, - {5, 368, 190, 18, select_item, button_none, 18, 0}, - {5, 388, 190, 18, select_item, button_none, 19, 0}, + {5, 8, 190, 18, button_select_item, 0, 0}, + {5, 28, 190, 18, button_select_item, 0, 1}, + {5, 48, 190, 18, button_select_item, 0, 2}, + {5, 68, 190, 18, button_select_item, 0, 3}, + {5, 88, 190, 18, button_select_item, 0, 4}, + {5, 108, 190, 18, button_select_item, 0, 5}, + {5, 128, 190, 18, button_select_item, 0, 6}, + {5, 148, 190, 18, button_select_item, 0, 7}, + {5, 168, 190, 18, button_select_item, 0, 8}, + {5, 188, 190, 18, button_select_item, 0, 9}, + {5, 208, 190, 18, button_select_item, 0, 10}, + {5, 228, 190, 18, button_select_item, 0, 11}, + {5, 248, 190, 18, button_select_item, 0, 12}, + {5, 268, 190, 18, button_select_item, 0, 13}, + {5, 288, 190, 18, button_select_item, 0, 14}, + {5, 308, 190, 18, button_select_item, 0, 15}, + {5, 328, 190, 18, button_select_item, 0, 16}, + {5, 348, 190, 18, button_select_item, 0, 17}, + {5, 368, 190, 18, button_select_item, 0, 18}, + {5, 388, 190, 18, button_select_item, 0, 19}, }; static generic_button buttons_list2[MAX_ITEMS_PER_LIST] = { - {205, 8, 190, 18, select_item, button_none, 0, 1}, - {205, 28, 190, 18, select_item, button_none, 1, 1}, - {205, 48, 190, 18, select_item, button_none, 2, 1}, - {205, 68, 190, 18, select_item, button_none, 3, 1}, - {205, 88, 190, 18, select_item, button_none, 4, 1}, - {205, 108, 190, 18, select_item, button_none, 5, 1}, - {205, 128, 190, 18, select_item, button_none, 6, 1}, - {205, 148, 190, 18, select_item, button_none, 7, 1}, - {205, 168, 190, 18, select_item, button_none, 8, 1}, - {205, 188, 190, 18, select_item, button_none, 9, 1}, - {205, 208, 190, 18, select_item, button_none, 10, 1}, - {205, 228, 190, 18, select_item, button_none, 11, 1}, - {205, 248, 190, 18, select_item, button_none, 12, 1}, - {205, 268, 190, 18, select_item, button_none, 13, 1}, - {205, 288, 190, 18, select_item, button_none, 14, 1}, - {205, 308, 190, 18, select_item, button_none, 15, 1}, - {205, 328, 190, 18, select_item, button_none, 16, 1}, - {205, 348, 190, 18, select_item, button_none, 17, 1}, - {205, 368, 190, 18, select_item, button_none, 18, 1}, - {205, 388, 190, 18, select_item, button_none, 19, 1}, + {205, 8, 190, 18, button_select_item, 0, 0, 1}, + {205, 28, 190, 18, button_select_item, 0, 1, 1}, + {205, 48, 190, 18, button_select_item, 0, 2, 1}, + {205, 68, 190, 18, button_select_item, 0, 3, 1}, + {205, 88, 190, 18, button_select_item, 0, 4, 1}, + {205, 108, 190, 18, button_select_item, 0, 5, 1}, + {205, 128, 190, 18, button_select_item, 0, 6, 1}, + {205, 148, 190, 18, button_select_item, 0, 7, 1}, + {205, 168, 190, 18, button_select_item, 0, 8, 1}, + {205, 188, 190, 18, button_select_item, 0, 9, 1}, + {205, 208, 190, 18, button_select_item, 0, 10, 1}, + {205, 228, 190, 18, button_select_item, 0, 11, 1}, + {205, 248, 190, 18, button_select_item, 0, 12, 1}, + {205, 268, 190, 18, button_select_item, 0, 13, 1}, + {205, 288, 190, 18, button_select_item, 0, 14, 1}, + {205, 308, 190, 18, button_select_item, 0, 15, 1}, + {205, 328, 190, 18, button_select_item, 0, 16, 1}, + {205, 348, 190, 18, button_select_item, 0, 17, 1}, + {205, 368, 190, 18, button_select_item, 0, 18, 1}, + {205, 388, 190, 18, button_select_item, 0, 19, 1}, }; static struct { @@ -199,8 +199,11 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -void select_item(int id, int list_id) +void button_select_item(const generic_button *button) { + int id = button->parameter1; + int list_id = button->parameter2; + window_go_back(); if (list_id == 0) { data.callback(id); diff --git a/src/window/set_salary.c b/src/window/set_salary.c index c84c33dc4f..d18c73dcff 100644 --- a/src/window/set_salary.c +++ b/src/window/set_salary.c @@ -5,6 +5,7 @@ #include "city/ratings.h" #include "city/victory.h" #include "game/resource.h" +#include "graphics/button.h" #include "graphics/generic_button.h" #include "graphics/graphics.h" #include "graphics/image.h" @@ -17,22 +18,22 @@ #define MIN_DIALOG_WIDTH 384 -static void button_cancel(int param1, int param2); -static void button_set_salary(int rank, int param2); +static void button_cancel(const generic_button *button); +static void button_set_salary(const generic_button *button); static generic_button buttons[] = { - {240, 395, 160, 20, button_cancel, button_none, 0, 0}, - {144, 85, 352, 20, button_set_salary, button_none, 0, 0}, - {144, 105, 352, 20, button_set_salary, button_none, 1, 0}, - {144, 125, 352, 20, button_set_salary, button_none, 2, 0}, - {144, 145, 352, 20, button_set_salary, button_none, 3, 0}, - {144, 165, 352, 20, button_set_salary, button_none, 4, 0}, - {144, 185, 352, 20, button_set_salary, button_none, 5, 0}, - {144, 205, 352, 20, button_set_salary, button_none, 6, 0}, - {144, 225, 352, 20, button_set_salary, button_none, 7, 0}, - {144, 245, 352, 20, button_set_salary, button_none, 8, 0}, - {144, 265, 352, 20, button_set_salary, button_none, 9, 0}, - {144, 285, 352, 20, button_set_salary, button_none, 10, 0}, + {240, 395, 160, 20, button_cancel}, + {144, 85, 352, 20, button_set_salary, 0, 0}, + {144, 105, 352, 20, button_set_salary, 0, 1}, + {144, 125, 352, 20, button_set_salary, 0, 2}, + {144, 145, 352, 20, button_set_salary, 0, 3}, + {144, 165, 352, 20, button_set_salary, 0, 4}, + {144, 185, 352, 20, button_set_salary, 0, 5}, + {144, 205, 352, 20, button_set_salary, 0, 6}, + {144, 225, 352, 20, button_set_salary, 0, 7}, + {144, 245, 352, 20, button_set_salary, 0, 8}, + {144, 265, 352, 20, button_set_salary, 0, 9}, + {144, 285, 352, 20, button_set_salary, 0, 10}, }; static unsigned int focus_button_id; @@ -93,13 +94,15 @@ static void handle_input(const mouse *m, const hotkeys *h) } } -static void button_cancel(int param1, int param2) +static void button_cancel(const generic_button *button) { window_advisors_show(); } -static void button_set_salary(int rank, int param2) +static void button_set_salary(const generic_button *button) { + int rank = button->parameter1; + if (!city_victory_has_won()) { city_emperor_set_salary_rank(rank); city_finance_update_salary(); diff --git a/src/window/user_path_setup.c b/src/window/user_path_setup.c index c8687b07a8..264499dff0 100644 --- a/src/window/user_path_setup.c +++ b/src/window/user_path_setup.c @@ -30,11 +30,11 @@ static struct { char user_path[FILE_NAME_MAX]; } data; -static void button_pick_option(int param1, int param2); +static void button_pick_option(const generic_button *button); static void button_ok_cancel(int is_ok, int param2); static generic_button path_button = { - 150, 55, 458, 30, button_pick_option, button_none + 150, 55, 458, 30, button_pick_option }; static image_button ok_cancel_buttons[] = { @@ -201,7 +201,7 @@ static void set_paths(int index) } } -static void button_pick_option(int param1, int param2) +static void button_pick_option(const generic_button *button) { static const uint8_t *texts[4]; static uint8_t recommended_text[FILE_NAME_MAX]; diff --git a/src/window/victory_dialog.c b/src/window/victory_dialog.c index 156726e646..d1d3bea20a 100644 --- a/src/window/victory_dialog.c +++ b/src/window/victory_dialog.c @@ -16,13 +16,13 @@ #define MAX_RANK 10 -static void button_accept(int param1, int param2); -static void button_continue_governing(int months, int param2); +static void button_accept(const generic_button *button); +static void button_continue_governing(const generic_button *button); static generic_button victory_buttons[] = { - {32, 112, 480, 20, button_accept, button_none, 0, 0}, - {32, 144, 480, 20, button_continue_governing, button_none, 24, 0}, - {32, 176, 480, 20, button_continue_governing, button_none, 60, 0}, + {32, 112, 480, 20, button_accept}, + {32, 144, 480, 20, button_continue_governing, 0, 24, 0}, + {32, 176, 480, 20, button_continue_governing, 0, 60, 0}, }; static unsigned int focus_button_id = 0; @@ -97,13 +97,14 @@ static void handle_input(const mouse *m, const hotkeys *h) generic_buttons_handle_mouse(mouse_in_dialog(m), 48, 128, victory_buttons, num_buttons, &focus_button_id); } -static void button_accept(int param1, int param2) +static void button_accept(const generic_button *button) { window_city_show(); } -static void button_continue_governing(int months, int param2) +static void button_continue_governing(const generic_button *button) { + int months = button->parameter1; city_victory_continue_governing(months); window_city_show(); city_victory_reset();