diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c945b8ab8..5fc095f1df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -614,6 +614,10 @@ set(WIDGET_FILES ${PROJECT_SOURCE_DIR}/src/widget/minimap.c ${PROJECT_SOURCE_DIR}/src/widget/top_menu.c ${PROJECT_SOURCE_DIR}/src/widget/top_menu_editor.c + ${PROJECT_SOURCE_DIR}/src/widget/sidebar/collapsed/sidebar.c + ${PROJECT_SOURCE_DIR}/src/widget/sidebar/expanded/sidebar.c + ${PROJECT_SOURCE_DIR}/src/widget/sidebar/advanced/sidebar.c + src/widget/sidebar/advanced/advisors/info.c ${PROJECT_SOURCE_DIR}/src/widget/sidebar/city.c ${PROJECT_SOURCE_DIR}/src/widget/sidebar/common.c ${PROJECT_SOURCE_DIR}/src/widget/sidebar/editor.c diff --git a/src/city/view.c b/src/city/view.c index 8507ccaf62..a59a579e0b 100644 --- a/src/city/view.c +++ b/src/city/view.c @@ -10,6 +10,7 @@ #include "map/grid.h" #include "map/image.h" #include "widget/minimap.h" +#include "widget/sidebar/city.h" #define TILE_WIDTH_PIXELS 60 #define TILE_HEIGHT_PIXELS 30 @@ -22,7 +23,6 @@ static const int Y_DIRECTION_FOR_ORIENTATION[] = {1, -1, -1, 1}; static struct { int screen_width; int screen_height; - int sidebar_collapsed; int orientation; int scale; struct { @@ -43,6 +43,7 @@ static struct { } selected_tile; } data; + static int view_to_grid_offset_lookup[VIEW_X_MAX][VIEW_Y_MAX]; static void check_camera_boundaries(void) @@ -580,35 +581,28 @@ void city_view_rotate_right(void) check_camera_boundaries(); } -static void set_viewport(int x_offset, int y_offset, int width, int height) +static void set_viewport(void) { - data.viewport.x = x_offset; - data.viewport.y = y_offset; + const int sidebar_width = widget_sidebar_city_get_width() - 2; + const int width = data.screen_width - sidebar_width; + const int height = data.screen_height - TOP_MENU_HEIGHT; + + data.viewport.x = 0; + data.viewport.y = TOP_MENU_HEIGHT; data.viewport.width_pixels = width - 2; - data.viewport.height_pixels = height; + data.viewport.height_pixels = data.screen_height - TOP_MENU_HEIGHT; + data.viewport.width_tiles = calc_adjust_with_percentage(width, data.scale) / TILE_WIDTH_PIXELS; data.viewport.height_tiles = calc_adjust_with_percentage(height, data.scale) / HALF_TILE_HEIGHT_PIXELS; } -static void set_viewport_with_sidebar(void) -{ - set_viewport(0, TOP_MENU_HEIGHT, data.screen_width - 160, data.screen_height - TOP_MENU_HEIGHT); -} - -static void set_viewport_without_sidebar(void) -{ - set_viewport(0, TOP_MENU_HEIGHT, data.screen_width - 40, data.screen_height - TOP_MENU_HEIGHT); -} - void city_view_set_scale(int scale) { scale = calc_bound(scale, 50, city_view_get_max_scale()); data.scale = scale; - if (data.sidebar_collapsed) { - set_viewport_without_sidebar(); - } else { - set_viewport_with_sidebar(); - } + + set_viewport(); + check_camera_boundaries(); graphics_renderer()->update_scale(scale); } @@ -617,11 +611,7 @@ void city_view_set_viewport(int screen_width, int screen_height) { data.screen_width = screen_width; data.screen_height = screen_height; - if (data.sidebar_collapsed) { - set_viewport_without_sidebar(); - } else { - set_viewport_with_sidebar(); - } + set_viewport(); check_camera_boundaries(); } @@ -639,26 +629,17 @@ void city_view_get_viewport_size_tiles(int *width, int *height) *height = data.viewport.height_tiles; } -int city_view_is_sidebar_collapsed(void) -{ - return data.sidebar_collapsed; -} - void city_view_start_sidebar_toggle(void) { - set_viewport_without_sidebar(); + set_viewport(); check_camera_boundaries(); } void city_view_toggle_sidebar(void) { - if (data.sidebar_collapsed) { - data.sidebar_collapsed = 0; - set_viewport_with_sidebar(); - } else { - data.sidebar_collapsed = 1; - set_viewport_without_sidebar(); - } + //data.sidebar_collapsed = !data.sidebar_collapsed; + + set_viewport(); check_camera_boundaries(); } diff --git a/src/game/game.c b/src/game/game.c index 145b8b11e6..9392444d1d 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -178,10 +178,6 @@ int game_init_editor(void) game_file_editor_clear_data(); game_file_editor_create_scenario(2); - if (city_view_is_sidebar_collapsed()) { - city_view_toggle_sidebar(); - } - editor_set_active(1); window_editor_map_show(); return 1; diff --git a/src/graphics/image.c b/src/graphics/image.c index b9b543fbd2..cf84b6a16e 100644 --- a/src/graphics/image.c +++ b/src/graphics/image.c @@ -2,6 +2,9 @@ #include "assets/assets.h" #include "core/image.h" + +#include + #include "graphics/renderer.h" #include "graphics/screen.h" @@ -28,6 +31,19 @@ void image_draw_silhouette(int image_id, int x, int y, color_t color, float scal } +void image_draw_scaled_from_corner(const int image_id, const int x, const int y, const color_t color, + const int draw_scale_percent) +{ + const float obj_draw_scale = 100.0f / (float)draw_scale_percent; + + // The draw_image function divides x and y by scale internally. + // Multiply here to cancel (invert) that effect. + const int inverting_scale_x = (int)lroundf((float)x * obj_draw_scale); + const int inverting_scale_y = (int)lroundf((float)y * obj_draw_scale); + + image_draw(image_id, inverting_scale_x, inverting_scale_y, color, obj_draw_scale); +} + void image_draw_scaled_centered(int image_id, int x, int y, color_t color, int draw_scale_percent) { float obj_draw_scale = 100.0f / draw_scale_percent; diff --git a/src/graphics/image.h b/src/graphics/image.h index f85c104e6f..c5b13bcdda 100644 --- a/src/graphics/image.h +++ b/src/graphics/image.h @@ -28,5 +28,6 @@ void image_blend_footprint_color(int x, int y, color_t color, float scale); void image_draw_isometric_top(int image_id, int x, int y, color_t color_mask, float scale); void image_draw_isometric_top_from_draw_tile(int image_id, int x, int y, color_t color_mask, float scale); void image_draw_set_isometric_top_from_draw_tile(int image_id, int x, int y, color_t color_mask, float scale); +void image_draw_scaled_from_corner(int image_id, int x, int y, color_t color, int draw_scale_percent); #endif // GRAPHICS_IMAGE_H diff --git a/src/graphics/screenshot.c b/src/graphics/screenshot.c index e62598ef98..8020b7b55e 100644 --- a/src/graphics/screenshot.c +++ b/src/graphics/screenshot.c @@ -25,6 +25,8 @@ #include #include +#include "widget/sidebar/city.h" + #define TILE_X_SIZE 60 #define TILE_Y_SIZE 30 #define IMAGE_HEIGHT_CHUNK (TILE_Y_SIZE * 15) @@ -300,7 +302,7 @@ static void create_full_city_screenshot(void) graphics_set_clip_rectangle(0, TOP_MENU_HEIGHT, canvas_width, IMAGE_HEIGHT_CHUNK); int viewport_x, viewport_y, viewport_width, viewport_height; city_view_get_viewport(&viewport_x, &viewport_y, &viewport_width, &viewport_height); - city_view_set_viewport(canvas_width + (city_view_is_sidebar_collapsed() ? 42 : 162), + city_view_set_viewport(canvas_width + widget_sidebar_city_get_width(), IMAGE_HEIGHT_CHUNK + TOP_MENU_HEIGHT); int current_height = base_height; while ((size = image_request_rows()) != 0) { @@ -325,7 +327,7 @@ static void create_full_city_screenshot(void) } current_height += IMAGE_HEIGHT_CHUNK; } - city_view_set_viewport(viewport_width + (city_view_is_sidebar_collapsed() ? 42 : 162), viewport_height + TOP_MENU_HEIGHT); + city_view_set_viewport(viewport_width + widget_sidebar_city_get_width(), viewport_height + TOP_MENU_HEIGHT); city_view_set_scale(old_scale); config_set(CONFIG_UI_DRAW_CLOUD_SHADOWS, draw_cloud_shadows); graphics_reset_clip_rectangle(); diff --git a/src/widget/city.c b/src/widget/city.c index 637901a643..6c90e3807c 100644 --- a/src/widget/city.c +++ b/src/widget/city.c @@ -1,4 +1,5 @@ #include "city.h" +#include "sidebar/city.h" #include "building/construction.h" #include "building/properties.h" @@ -185,6 +186,7 @@ static void draw_construction_buttons(void) city_view_get_viewport(&x, &y, &width, &height); int x_offset = width - 4 * BLOCK_SIZE; int y_offset = 40; + if (((sidebar_extra_is_information_displayed(SIDEBAR_EXTRA_DISPLAY_GAME_SPEED) || !mouse_get()->is_touch) && width < 680) && game_state_is_paused()) { y_offset = 100; @@ -201,6 +203,7 @@ static void draw_construction_buttons(void) if ((mouse_get()->is_touch || config_get(CONFIG_UI_ALWAYS_SHOW_ROTATION_BUTTONS)) && building_construction_can_rotate()) { + if (!sidebar_extra_is_information_displayed(SIDEBAR_EXTRA_DISPLAY_GAME_SPEED)) { x_offset = 4 * BLOCK_SIZE + 8; } else { @@ -256,6 +259,7 @@ static int is_rotate_backward_button(int x, int y) int city_x, city_y, width, height; city_view_get_viewport(&city_x, &city_y, &width, &height); + //TODO: config int sidebar_pause_button = sidebar_extra_is_information_displayed(SIDEBAR_EXTRA_DISPLAY_GAME_SPEED); int x_offset = sidebar_pause_button ? 16 : 4 * BLOCK_SIZE + 4; int y_offset = sidebar_pause_button && width < 680 && game_state_is_paused() ? 84 : 24; @@ -268,6 +272,7 @@ static int is_rotate_forward_button(int x, int y) int city_x, city_y, width, height; city_view_get_viewport(&city_x, &city_y, &width, &height); + //TODO: config int sidebar_pause_button = sidebar_extra_is_information_displayed(SIDEBAR_EXTRA_DISPLAY_GAME_SPEED); int x_offset = sidebar_pause_button ? 4 * BLOCK_SIZE + 4 : 7 * BLOCK_SIZE + 4; int y_offset = sidebar_pause_button && width < 680 && game_state_is_paused() ? 84 : 24; @@ -715,7 +720,7 @@ void widget_city_handle_input_military(const mouse *m, const hotkeys *h, int leg { map_tile *tile = &data.current_tile; update_city_view_coords(m->x, m->y, tile); - if (!city_view_is_sidebar_collapsed() && widget_minimap_handle_mouse(m)) { + if (!widget_sidebar_is_collapsed() && widget_minimap_handle_mouse(m)) { return; } scroll_map(m); diff --git a/src/widget/sidebar/advanced/advisors/info.c b/src/widget/sidebar/advanced/advisors/info.c new file mode 100644 index 0000000000..89a5f257e5 --- /dev/null +++ b/src/widget/sidebar/advanced/advisors/info.c @@ -0,0 +1,442 @@ +#include "info.h" + +#include "assets/assets.h" +#include "building/count.h" +#include "building/model.h" +#include "city/culture.h" +#include "city/festival.h" +#include "city/gods.h" +#include "city/health.h" +#include "city/labor.h" +#include "city/population.h" +#include "core/calc.h" +#include "core/image.h" +#include "game/resource.h" +#include "graphics/complex_button.h" +#include "graphics/generic_button.h" +#include "graphics/graphics.h" +#include "graphics/image.h" +#include "graphics/image_button.h" +#include "graphics/lang_text.h" +#include "graphics/panel.h" +#include "graphics/text.h" +#include "window/advisors.h" +#include "window/city.h" +#include "window/message_dialog.h" + +#define SECTION_PADDING 8 +#define LINE_HEIGHT 16 +#define INFO_PANEL_HEIGHT 494 +#define INFO_PANEL_WIDTH 160 +#define INFO_PANEL_LEFT_MARGIN 5 +#define INFO_PANEL_TOP_MARGIN 6 +#define LARARIUM_COVERAGE 10 +#define SHRINE_COVERAGE 50 +#define SMALL_TEMPLE_COVERAGE 750 +#define LARGE_TEMPLE_COVERAGE 3000 +#define ORACLE_COVERAGE 500 +#define LARGE_ORACLE_COVERAGE 750 +#define PANTHEON_COVERAGE 1500 +#define GRAND_TEMPLE_COVERAGE 5000 +#define HEADER_FONT FONT_NORMAL_WHITE +#define VALUE_FONT FONT_NORMAL_GREEN +#define IMAGE_ID_FOR_ADVISOR_BUILDING_WINDOW_BORDER_1_UI 11842 +#define BUTTON_COUNT 2 + +static void button_advisor(int advisor, int param2); +static void button_help(int param1, int param2); + +static image_button health_buttons[] = { + { 0, 0, 27, 27, IB_NORMAL, GROUP_CONTEXT_ICONS, 0,button_help, button_none, 0, 0, 1}, + {0, 0, 27, 27, IB_NORMAL,0, 0, button_advisor, button_none, 0, 0, 1} +}; + +static struct { + int x_offset; + int y_offset; + unsigned int focus_button_id; + int current_advisor; +} data; + + +void draw_info_panel_background(const int x_offset, const int y_offset) +{ + const int panel_blocks = INFO_PANEL_HEIGHT / BLOCK_SIZE; + graphics_draw_line(x_offset, x_offset, y_offset, y_offset + INFO_PANEL_HEIGHT, COLOR_WHITE); + graphics_draw_line(x_offset + INFO_PANEL_WIDTH - 1, x_offset + INFO_PANEL_WIDTH - 1, y_offset, + y_offset + INFO_PANEL_HEIGHT, COLOR_SIDEBAR); + inner_panel_draw(x_offset + 1, y_offset, INFO_PANEL_WIDTH / BLOCK_SIZE, panel_blocks); + + data.x_offset = x_offset + INFO_PANEL_LEFT_MARGIN; + data.y_offset = y_offset + INFO_PANEL_TOP_MARGIN; +} + +static int add_info_header(const uint8_t* header, const int x_offset, const int y_offset) +{ + text_draw(header, x_offset, y_offset, HEADER_FONT, 0); + return y_offset + LINE_HEIGHT; +} + +static int add_info_number(const int value, const int x_offset, const int y_offset) +{ + text_draw_number(value, '@', "", x_offset, y_offset, VALUE_FONT, 0); + return y_offset + LINE_HEIGHT; +} + +static int add_info_number_with_subsection(const int value, const int sub_value, const int x_offset, const int y_offset) +{ + const int text_width = text_draw_number(value,'@', "", x_offset, y_offset, VALUE_FONT, 0); + text_draw_number(sub_value, '(', ")", x_offset + text_width, y_offset, VALUE_FONT, 0); + + return y_offset + LINE_HEIGHT; +} + +static int add_info_section_panel(const uint8_t* header, const int value, const int x_offset, int y_offset) +{ + y_offset = add_info_header(header, x_offset, y_offset); + y_offset = add_info_number(value, x_offset, y_offset); + return y_offset + SECTION_PADDING; +} + +static int add_info_section_panel_with_sub_value(const uint8_t* header, const int value, const int sub_value, const int x_offset, int y_offset) +{ + y_offset = add_info_header(header, x_offset, y_offset); + y_offset = add_info_number_with_subsection(value, sub_value, x_offset, y_offset); + return y_offset + SECTION_PADDING; +} + +static int add_info_section_panel_percentage(const uint8_t* header, const int value, const int sub_value, const int x_offset, int y_offset) +{ + y_offset = add_info_header(header, x_offset, y_offset); + + const int text_width = text_draw_percentage(value, x_offset, y_offset, VALUE_FONT); + + text_draw_number(sub_value, '(', ")", x_offset +text_width, y_offset, VALUE_FONT, 0); + + y_offset += LINE_HEIGHT + SECTION_PADDING; + return y_offset; +} + +int info_panel_mouse_handle(const mouse *m) +{ + return image_buttons_handle_mouse(m, 0,0, health_buttons, BUTTON_COUNT, &data.focus_button_id); +} + +void place_button_at_bottom(const int advisor, const int health_information_dialog) +{ + health_buttons[0].y_offset = data.y_offset + 447; + health_buttons[0].x_offset = data.x_offset + 2; + health_buttons[0].parameter1 = health_information_dialog; + + health_buttons[1].image_offset = IMAGE_ID_FOR_ADVISOR_BUILDING_WINDOW_BORDER_1_UI + advisor * 4; + health_buttons[1].y_offset = data.y_offset + 447; + health_buttons[1].x_offset = data.x_offset + 29; + health_buttons[1].parameter1 = advisor; + + image_buttons_draw(0,0, health_buttons, BUTTON_COUNT); +} + +static int draw_health_building_info(const int x_offset, int y_offset, const building_type type, const int population_served, const int coverage) +{ + static const int BUILDING_ID_TO_STRING_ID[] = { 28, 30, 24, 26 }; + + lang_text_draw_amount(8, BUILDING_ID_TO_STRING_ID[type - BUILDING_DOCTOR], + building_count_total(type), x_offset, y_offset, HEADER_FONT); + + y_offset += LINE_HEIGHT; + + if (coverage == 0) { + lang_text_draw(57, 10, x_offset, y_offset, VALUE_FONT); + } else if (coverage < 100) { + lang_text_draw(57, coverage / 10 + 11, x_offset, y_offset, VALUE_FONT); + } else { + lang_text_draw(57, 21, x_offset, y_offset, VALUE_FONT); + } + + y_offset += LINE_HEIGHT; + + const int width = text_draw_number(population_served, '@', " ", x_offset, y_offset, VALUE_FONT, 0); + + if (type == BUILDING_DOCTOR || type == BUILDING_HOSPITAL) { + lang_text_draw(56, 6, x_offset + width, y_offset, VALUE_FONT); + } else { + lang_text_draw(58, 5, x_offset + width, y_offset, VALUE_FONT); + } + + y_offset += LINE_HEIGHT + SECTION_PADDING; + return y_offset; +} + +void draw_health_table(void) +{ + place_button_at_bottom(ADVISOR_HEALTH, MESSAGE_DIALOG_ADVISOR_HEALTH); + + int y_offset = data.y_offset; + const int population = city_population(); + + int people_covered = city_health_get_population_with_baths_access(); + y_offset = draw_health_building_info(data.x_offset, y_offset, BUILDING_BATHHOUSE, people_covered, calc_percentage(people_covered, population)); + + people_covered = city_health_get_population_with_barber_access(); + y_offset = draw_health_building_info(data.x_offset, y_offset, BUILDING_BARBER, people_covered, calc_percentage(people_covered, population)); + + people_covered = city_health_get_population_with_clinic_access(); + y_offset = draw_health_building_info(data.x_offset, y_offset, BUILDING_DOCTOR, people_covered, calc_percentage(people_covered, population)); + + people_covered = 1000 * building_count_active(BUILDING_HOSPITAL); + y_offset = draw_health_building_info(data.x_offset, y_offset, BUILDING_HOSPITAL, people_covered, city_culture_coverage_hospital()); +} + +static int draw_education_section(const int building_type, const int person_coverage, const int population, const int coverage, int y_offset) +{ + lang_text_draw_amount(8, 18, building_count_total(building_type), data.x_offset, y_offset, FONT_NORMAL_WHITE); + y_offset += LINE_HEIGHT; + + int number = 10; + if (coverage == 0) { + number = 10; + } else if (coverage < 100) { + number = coverage / 10 + 11; + } else { + number = 21; + } + + lang_text_draw(57, number, data.x_offset, y_offset, VALUE_FONT); + y_offset += LINE_HEIGHT; + + y_offset = add_info_number_with_subsection( + person_coverage, + population, + data.x_offset, + y_offset + ); + + y_offset += LINE_HEIGHT; + + return y_offset; +} + +void draw_education_table(void) +{ + place_button_at_bottom(ADVISOR_EDUCATION, MESSAGE_DIALOG_ADVISOR_EDUCATION); + + int y_offset = data.y_offset; + + y_offset = draw_education_section(BUILDING_SCHOOL, city_culture_get_school_person_coverage(), + city_population_school_age(), city_culture_coverage_school(), y_offset); + + y_offset = draw_education_section(BUILDING_ACADEMY, city_culture_get_academy_person_coverage(), + city_population_academy_age(), city_culture_coverage_academy(), y_offset); + + draw_education_section(BUILDING_LIBRARY, city_culture_get_library_person_coverage(), + city_population(), city_culture_coverage_library(), y_offset); +} + +static int draw_entertainment_section(const int building_type, const int building_text_number, const int person_coverage, const int population, const int coverage, int y_offset) +{ + const int group = (building_type == BUILDING_TAVERN || building_type == BUILDING_ARENA) ? CUSTOM_TRANSLATION : 8; + lang_text_draw_amount(group, building_text_number, building_count_total(building_type), data.x_offset, y_offset, FONT_NORMAL_WHITE); + y_offset += LINE_HEIGHT; + + int number = 10; + if (coverage == 0) { + number = 10; + } else if (coverage < 100) { + number = coverage / 10 + 11; + } else { + number = 21; + } + + lang_text_draw(57, number, data.x_offset, y_offset, VALUE_FONT); + y_offset += LINE_HEIGHT; + + y_offset = add_info_number_with_subsection( + person_coverage, + population, + data.x_offset, + y_offset + ); + + y_offset += LINE_HEIGHT; + + return y_offset; +} + +void draw_entertainment_table(void) +{ + place_button_at_bottom(ADVISOR_ENTERTAINMENT, MESSAGE_DIALOG_ADVISOR_ENTERTAINMENT); + int y_offset = data.y_offset; + + const int population = city_population(); + + y_offset = draw_entertainment_section( + BUILDING_THEATER, + 34, + city_culture_get_theatre_person_coverage(), + population, + city_culture_coverage_theater(), + y_offset + ); + + y_offset = draw_entertainment_section( + BUILDING_AMPHITHEATER, + 36, + city_culture_get_ampitheatre_person_coverage(), + population, + city_culture_coverage_amphitheater(), + y_offset + ); + + y_offset = draw_entertainment_section( + BUILDING_ARENA, + TR_WINDOW_ADVISOR_ENTERTAINMENT_ARENA_COVERAGE, + city_culture_get_arena_person_coverage(), + population, + city_culture_coverage_arena(), + y_offset + ); + + draw_entertainment_section( + BUILDING_TAVERN, + TR_WINDOW_ADVISOR_ENTERTAINMENT_TAVERN_COVERAGE, + city_culture_get_tavern_person_coverage(), + population, + city_culture_coverage_tavern(), + y_offset + ); + + // colosseum and hippodrome are not included here as they provider global coverage + // and players are expected to know about them from the city +} + +void draw_housing_table(void) +{ + place_button_at_bottom(ADVISOR_HOUSING, MESSAGE_DIALOG_ADVISOR_POPULATION); + + int y_offset = data.y_offset; + + int total_residences = 0; + + int housing_y_offset = y_offset + (6 * LINE_HEIGHT) + (3 * SECTION_PADDING); + + for (house_level level = HOUSE_MIN; level <= HOUSE_MAX; level++) { + const int residences_at_level = building_count_active(BUILDING_HOUSE_SMALL_TENT + level); + if (!residences_at_level) { + continue; + } + total_residences += residences_at_level; + + add_info_number(residences_at_level, data.x_offset, housing_y_offset); + housing_y_offset = add_info_header( + lang_get_string(29, level), + data.x_offset + 30, + housing_y_offset + ); + } + + y_offset = add_info_section_panel_percentage( + lang_get_string(68, 148), + city_labor_unemployment_percentage(), + city_labor_workers_unemployed() - city_labor_workers_needed(), + data.x_offset, + y_offset + ); + + y_offset = add_info_section_panel( + translation_for(TR_ADVISOR_TOTAL_NUM_HOUSES), + total_residences, + data.x_offset, + y_offset + ); + + y_offset = add_info_section_panel_with_sub_value( + translation_for(TR_ADVISOR_TOTAL_HOUSING_CAPACITY), + city_population_total_housing_capacity(), + city_population_open_housing_capacity(), + data.x_offset, + y_offset + ); +} + +static int draw_god_row(const god_type god, int y_offset, const int base_god_value, + const building_type altar, const building_type small_temple, + const building_type large_temple, const building_type grand_temple) +{ + + const int value = base_god_value + + SHRINE_COVERAGE * building_count_active(altar) + + SMALL_TEMPLE_COVERAGE * building_count_active(small_temple) + + LARGE_TEMPLE_COVERAGE * building_count_active(large_temple) + + GRAND_TEMPLE_COVERAGE * building_count_active(grand_temple); + + const int god_name_width = text_draw(lang_get_string(59,11 + god) + , data.x_offset, + y_offset, HEADER_FONT, 0); + + const int bolts = city_god_wrath_bolts(god); + for (int i = 0; i < bolts / 10; i++) { + image_draw(image_group(GROUP_GOD_BOLT), + data.x_offset + 10 * i + god_name_width, y_offset -2 , COLOR_MASK_NONE, SCALE_NONE); + } + const int happy_bolts = city_god_happy_bolts(god); + for (int i = 0; i < happy_bolts; i++) { + image_draw(assets_get_image_id("UI", "Happy God Icon"), + data.x_offset + 10 * i + god_name_width, y_offset -2 , COLOR_MASK_NONE, SCALE_NONE); + } + + y_offset += LINE_HEIGHT; + y_offset = add_info_number( + value, + data.x_offset, + y_offset); + + lang_text_draw(59, 32 + city_god_happiness(god) / 10, data.x_offset, y_offset, VALUE_FONT); + + y_offset += LINE_HEIGHT + SECTION_PADDING; + + return y_offset; + +} + +void draw_gods_table(void) +{ + place_button_at_bottom(ADVISOR_RELIGION, MESSAGE_DIALOG_ADVISOR_RELIGION); + + int y_offset = data.y_offset; + + const int oracles = building_count_active(BUILDING_ORACLE); + const int larariums = building_count_total(BUILDING_LARARIUM); + const int nymphaeums = building_count_active(BUILDING_NYMPHAEUM); + const int small_mausoleums = building_count_active(BUILDING_SMALL_MAUSOLEUM); + const int large_mausoleums = building_count_active(BUILDING_LARGE_MAUSOLEUM); + + const int base_god_value = + PANTHEON_COVERAGE * building_count_active(BUILDING_PANTHEON) + + LARARIUM_COVERAGE * larariums + + ORACLE_COVERAGE * oracles + + ORACLE_COVERAGE * small_mausoleums + + LARGE_ORACLE_COVERAGE * nymphaeums + + LARGE_ORACLE_COVERAGE * large_mausoleums ; + + y_offset = draw_god_row(GOD_CERES, y_offset, base_god_value, BUILDING_SHRINE_CERES, + BUILDING_SMALL_TEMPLE_CERES, BUILDING_LARGE_TEMPLE_CERES, BUILDING_GRAND_TEMPLE_CERES); + y_offset = draw_god_row(GOD_NEPTUNE, y_offset, base_god_value, BUILDING_SHRINE_NEPTUNE, + BUILDING_SMALL_TEMPLE_NEPTUNE, BUILDING_LARGE_TEMPLE_NEPTUNE, BUILDING_GRAND_TEMPLE_NEPTUNE); + y_offset = draw_god_row(GOD_MERCURY, y_offset, base_god_value, BUILDING_SHRINE_MERCURY, + BUILDING_SMALL_TEMPLE_MERCURY, BUILDING_LARGE_TEMPLE_MERCURY, BUILDING_GRAND_TEMPLE_MERCURY); + y_offset = draw_god_row(GOD_MARS, y_offset, base_god_value, BUILDING_SHRINE_MARS, + BUILDING_SMALL_TEMPLE_MARS, BUILDING_LARGE_TEMPLE_MARS, BUILDING_GRAND_TEMPLE_MARS); + draw_god_row(GOD_VENUS, y_offset, base_god_value, BUILDING_SHRINE_VENUS, + BUILDING_SMALL_TEMPLE_VENUS, BUILDING_LARGE_TEMPLE_VENUS, BUILDING_GRAND_TEMPLE_VENUS); +} + +static void button_advisor(const int advisor, int param2) +{ + window_advisors_show_advisor(advisor); +} + +static void button_help(const int param1, int param2) +{ + window_message_dialog_show(param1, 0); +} + diff --git a/src/widget/sidebar/advanced/advisors/info.h b/src/widget/sidebar/advanced/advisors/info.h new file mode 100644 index 0000000000..689b9fb570 --- /dev/null +++ b/src/widget/sidebar/advanced/advisors/info.h @@ -0,0 +1,19 @@ +#ifndef WIDGET_SIDEBAR_INFO +#define WIDGET_SIDEBAR_INFO +#include "input/mouse.h" + +void draw_info_panel_background(int x_offset, int y_offset); + +void draw_housing_table(void); + +void draw_gods_table(void); + +void draw_health_table(void); + +void draw_education_table(void); + +void draw_entertainment_table(void); + +int info_panel_mouse_handle(const mouse *m); + +#endif diff --git a/src/widget/sidebar/advanced/sidebar.c b/src/widget/sidebar/advanced/sidebar.c new file mode 100644 index 0000000000..b8e018ad12 --- /dev/null +++ b/src/widget/sidebar/advanced/sidebar.c @@ -0,0 +1,410 @@ +#include "sidebar.h" + +#include "advisors/info.h" +#include "building/menu.h" +#include "city/message.h" +#include "city/view.h" +#include "city/warning.h" +#include "core/config.h" +#include "game/campaign.h" +#include "game/orientation.h" +#include "game/state.h" +#include "game/undo.h" +#include "graphics/image.h" +#include "graphics/image_button.h" +#include "graphics/lang_text.h" +#include "graphics/screen.h" +#include "graphics/text.h" +#include "graphics/window.h" +#include "scenario/property.h" +#include "translation/translation.h" +#include "widget/city.h" +#include "widget/minimap.h" +#include "widget/sidebar/city.h" +#include "widget/sidebar/common.h" +#include "widget/sidebar/extra.h" +#include "window/advisors.h" +#include "window/build_menu.h" +#include "window/city.h" +#include "window/empire.h" +#include "window/message_dialog.h" +#include "window/message_list.h" +#include "window/overlay_menu.h" + + +#define MINIMAP_Y_OFFSET 59 +#define SIDEBAR_ADVANCED_WIDTH 204 +#define BUILD_BUTTONS_COUNT 14 +#define TOP_BUTTONS_COUNT 9 + +static void button_overlay_click(int param1, int param2); +static void button_collapse_expand(int param1, int param2); +static void button_build(int submenu, int param2); +static void button_undo(int param1, int param2); +static void button_messages(int param1, int param2); +static void button_help(int param1, int param2); +static void button_go_to_problem(int param1, int param2); +static void button_advisors(int param1, int param2); +static void button_empire(int param1, int param2); +static void button_toggle_grid(int param1, int param2); +static void button_rotate_north(int param1, int param2); +static void button_rotate(int clockwise, int param2); + +/* + reminders + ========= + left and right margins are 4 + button margins are 6 + group margins are 15 +*/ + +static image_button buttons_overlays_collapse_sidebar[] = { + {4, 3, 159, 31, IB_NORMAL, 93, 0, button_overlay_click, button_help, 0, MESSAGE_DIALOG_OVERLAYS, 1}, + {165, 5, 31, 20, IB_NORMAL, 90, 0, button_collapse_expand, button_none, 0, 0, 1}, +// ------------------------- +// ---- minimap ---- +// ---- x:36, y:9 ---- +// ---- height: 143 ---- +// ------------------------- + +// ----- width was 71 now 95 + {4, 183, 95, 23, IB_NORMAL, GROUP_SIDEBAR_ADVISORS_EMPIRE, 0, button_advisors, button_none, 0, 0, 1}, + {105, 183, 95, 23, IB_NORMAL, GROUP_SIDEBAR_ADVISORS_EMPIRE, 3, button_empire, button_help, 0, MESSAGE_DIALOG_EMPIRE_MAP, 1}, +// ---- + {4, 212, 33, 22, IB_NORMAL, 0, 0, button_toggle_grid, button_none, 0, 0, 1, "UI", "Toggle Grid Button" }, + {43, 212, 33, 22, IB_NORMAL, GROUP_SIDEBAR_BRIEFING_ROTATE_BUTTONS, 3, button_rotate_north, button_none, 0, 0, 1}, + {81, 212, 33, 22, IB_NORMAL, GROUP_SIDEBAR_BRIEFING_ROTATE_BUTTONS, 6, button_rotate, button_none, 0, 0, 1}, + {120, 212, 33, 22, IB_NORMAL, GROUP_SIDEBAR_BRIEFING_ROTATE_BUTTONS, 9, button_rotate, button_none, 1, 0, 1}, + {159, 212, 39, 22, IB_NORMAL, GROUP_MESSAGE_ICON, 18, button_messages, button_help, 0, MESSAGE_DIALOG_MESSAGES, 1}, + +}; + +// height for info panel = 494 +// width = 169 + +static image_button buttons_build[] = { + {4, 240, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 0, button_build, button_none, BUILD_MENU_VACANT_HOUSE, 0, 1}, + {4, 275, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 8, button_build, button_none, BUILD_MENU_CLEAR_LAND, 0, 1}, + {4, 310, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 12, button_build, button_none, BUILD_MENU_ROAD, 0, 1}, + {4, 345, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 4, button_build, button_none, BUILD_MENU_WATER, 0, 1}, + {4, 380, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 40, button_build, button_none, BUILD_MENU_HEALTH, 0, 1, "UI", "Asclepius Button"}, + {4, 415, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 28, button_build, button_none, BUILD_MENU_TEMPLES, 0, 1}, + {4, 450, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 24, button_build, button_none, BUILD_MENU_EDUCATION, 0, 1}, + {4, 485, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 20, button_build, button_none, BUILD_MENU_ENTERTAINMENT, 0, 1}, + {4, 520, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 16, button_build, button_none, BUILD_MENU_ADMINISTRATION, 0, 1}, + {4, 555, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 44, button_build, button_none, BUILD_MENU_ENGINEERING, 0, 1}, + {4, 590, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 36, button_build, button_none, BUILD_MENU_SECURITY, 0, 1}, + {4, 625, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 32, button_build, button_none, BUILD_MENU_INDUSTRY, 0, 1}, + {4, 660, 39, 26, IB_BUILD, GROUP_MESSAGE_ICON, 22, button_go_to_problem, button_none, 0, 0, 1}, + {4, 695, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 48, button_undo, button_none, 0, 0, 1}, +}; + +static image_button buttons_top_expanded[] = { + + {7, 184, 33, 22, IB_NORMAL, 0, 0, button_toggle_grid, button_none, 0, 0, 1, "UI", "Toggle Grid Button" }, + {46, 184, 33, 22, IB_NORMAL, GROUP_SIDEBAR_BRIEFING_ROTATE_BUTTONS, 3, button_rotate_north, button_none, 0, 0, 1}, + {84, 184, 33, 22, IB_NORMAL, GROUP_SIDEBAR_BRIEFING_ROTATE_BUTTONS, 6, button_rotate, button_none, 0, 0, 1}, + {123, 184, 33, 22, IB_NORMAL, GROUP_SIDEBAR_BRIEFING_ROTATE_BUTTONS, 9, button_rotate, button_none, 1, 0, 1}, +}; +static struct { + unsigned int focus_button_for_tooltip; + int show_info_for; +} data; + +static void draw_overlay_text(const int x_offset) +{ + if (game_state_overlay()) { + const uint8_t *text = get_current_overlay_text(); + text_draw_centered(text, x_offset, 32, 117, FONT_NORMAL_GREEN, 0); + } else { + lang_text_draw_centered(6, 4, x_offset, 32, 117, FONT_NORMAL_GREEN); + } +} + +static void draw_sidebar_remainder(const int x_offset) +{ + //int width = SIDEBAR_EXPANDED_WIDTH; + const int sidebar_without_icons_width = 162; + + // int available_height = sidebar_common_get_height() - SIDEBAR_MAIN_SECTION_HEIGHT; + const int available_height = sidebar_common_get_height() - MINIMAP_HEIGHT - MINIMAP_Y_OFFSET; + + const int y_offset = 201; + + const int extra_height = sidebar_extra_draw_background(x_offset, y_offset, + sidebar_without_icons_width, available_height, 0, SIDEBAR_EXTRA_DISPLAY_ALL); + sidebar_extra_draw_foreground(); + const int relief_y_offset = SIDEBAR_FILLER_Y_OFFSET + extra_height; + + sidebar_common_draw_relief(x_offset - 42, relief_y_offset, GROUP_SIDE_PANEL, 0, 26); +} + +static void draw_number_of_messages(int x_offset) +{ + const int y = TOP_MENU_HEIGHT + 210 + 8; + x_offset += 159+35; + + int messages = city_message_count(); + int show_messages = game_campaign_is_original() || messages > 0 || scenario_intro_message(); + buttons_overlays_collapse_sidebar[8].enabled = show_messages; + buttons_build[12].enabled = city_message_problem_area_count(); + if (show_messages) { + int width = text_get_number_width(messages, '@', "", FONT_SMALL_PLAIN); + text_draw_number(messages, '@', "", x_offset - width, y, FONT_SMALL_PLAIN, COLOR_BLACK); //top + text_draw_number(messages, '@', "", x_offset - width, y, FONT_SMALL_PLAIN, COLOR_BLACK); //bottom + text_draw_number(messages, '@', "", x_offset + 1 - width, y, FONT_SMALL_PLAIN, COLOR_BLACK); //left + text_draw_number(messages, '@', "", x_offset + 2 - width, y, FONT_SMALL_PLAIN, COLOR_BLACK); //right + text_draw_number(messages, '@', "", x_offset - width, y, FONT_SMALL_PLAIN, COLOR_WHITE); + } +} + +static void draw_buttons(int x_offset) +{ + buttons_build[13].enabled = game_can_undo(); + image_buttons_draw(x_offset, TOP_MENU_HEIGHT, buttons_overlays_collapse_sidebar, TOP_BUTTONS_COUNT); + image_buttons_draw(x_offset, TOP_MENU_HEIGHT, buttons_build, BUILD_BUTTONS_COUNT); + // image_buttons_draw(x_offset, 24, buttons_top_expanded, 6); +} + +static void enable_building_buttons(void) +{ + for (int i = 0; i < 12; i++) { + buttons_build[i].enabled = 1; + if (building_menu_count_items(buttons_build[i].parameter1) <= 0) { + buttons_build[i].enabled = 0; + } + } +} + +int advanced_sidebar_width(void) +{ + return SIDEBAR_ADVANCED_WIDTH; +} + +int calculate_x_offset_sidebar_advanced(void) +{ + return screen_width() - SIDEBAR_ADVANCED_WIDTH; +} + +void draw_advanced_sidebar_background(const int x_offset) +{ + const int info_panel_x_offset = x_offset + 48; + const int info_panel_y_offset = 268; + draw_info_panel_background(info_panel_x_offset, info_panel_y_offset); + + switch (data.show_info_for){ + case BUILD_MENU_HEALTH: + draw_health_table(); + break; + case BUILD_MENU_VACANT_HOUSE: + draw_housing_table(); + break; + case BUILD_MENU_TEMPLES: + draw_gods_table(); + break; + case BUILD_MENU_EDUCATION: + draw_education_table(); + break; + case BUILD_MENU_ENTERTAINMENT: + draw_entertainment_table(); + break; + default: ; + } + + // image_draw(image_group(GROUP_SIDE_PANEL), x_offset, TOP_MENU_HEIGHT, COLOR_MASK_NONE, SCALE_NONE); + draw_buttons(x_offset); + draw_overlay_text(x_offset + 4); + draw_number_of_messages(x_offset); + widget_minimap_update(0); + widget_minimap_draw_decorated(x_offset + 8, 36 + TOP_MENU_HEIGHT, 187, 143); + + // draw_sidebar_remainder(x_offset + 42); +} + +void draw_advanced_sidebar_foreground(void) +{ + const int x_offset = calculate_x_offset_sidebar_advanced(); + + switch (data.show_info_for){ + case BUILD_MENU_HEALTH: + draw_health_table(); + break; + case BUILD_MENU_VACANT_HOUSE: + draw_housing_table(); + break; + case BUILD_MENU_TEMPLES: + draw_gods_table(); + break; + case BUILD_MENU_EDUCATION: + draw_education_table(); + break; + case BUILD_MENU_ENTERTAINMENT: + draw_entertainment_table(); + break; + default: ; + } + + if (building_menu_has_changed()) { + enable_building_buttons(); + } + + draw_buttons(x_offset); + draw_overlay_text(x_offset + 4); + widget_minimap_draw_decorated(x_offset + 8, 36 + TOP_MENU_HEIGHT, 187, 143); + draw_number_of_messages(x_offset); + + + + // sidebar_extra_draw_foreground(); +} + +int handle_advanced_sidebar_mouse(const mouse *m) +{ + if (widget_city_has_input()) { + return 0; + } + int handled = 0; + unsigned int button_id; + data.focus_button_for_tooltip = 0; + // if (city_view_is_sidebar_collapsed()) { + const int x_offset = calculate_x_offset_sidebar_advanced(); + // handled |= image_buttons_handle_mouse(m, x_offset, 24, button_expand_new_sidebar, 1, &button_id); + // if (button_id) { + // data.focus_button_for_tooltip = 12; + // } + handled |= image_buttons_handle_mouse(m, x_offset, TOP_MENU_HEIGHT, buttons_build, 14, &button_id); + if (button_id) { + data.focus_button_for_tooltip = button_id + 19; + } + // } else { + // if (widget_minimap_handle_mouse(m)) { + // return 1; + // } + // int x_offset = new_sidebar_common_get_x_offset_expanded(); + handled |= image_buttons_handle_mouse(m, x_offset, TOP_MENU_HEIGHT, buttons_overlays_collapse_sidebar, 9 , &button_id); + if (button_id) { + data.focus_button_for_tooltip = button_id + 9; + } + + handled |= info_panel_mouse_handle(m); + // handled |= image_buttons_handle_mouse(m, x_offset, 24, buttons_build_expanded, 15, &button_id); + // if (button_id) { + // data.focus_button_for_tooltip = button_id + 19; + // } + // handled |= image_buttons_handle_mouse(m, x_offset, 24, buttons_top_expanded, 6, &button_id); + // if (button_id) { + // data.focus_button_for_tooltip = button_id + 39; + // } + // handled |= new_sidebar_extra_handle_mouse(m); + // } + return handled; +} + +int handle_advanced_sidebar_mouse_build_menu(const mouse *m) +{ + // if (city_view_is_sidebar_collapsed()) { + return image_buttons_handle_mouse(m, + calculate_x_offset_sidebar_advanced(), TOP_MENU_HEIGHT, buttons_build, 12, 0); + // } else { + // return image_buttons_handle_mouse(m, + // new_sidebar_common_get_x_offset_expanded(), 24, buttons_build, 15, 0); + // } +} + +unsigned int get_advanced_sidebar_tooltip_text(tooltip_context *c) +{ + if (data.focus_button_for_tooltip) { + if (data.focus_button_for_tooltip == 42) { + c->translation_key = TR_TOGGLE_GRID; + return 0; + } + return data.focus_button_for_tooltip; + } + return sidebar_extra_get_tooltip(c); +} + +static void button_collapse_expand(int param1, int param2) +{ + sidebar_next(); +} + +static void button_build(const int submenu, int param2) +{ + // TODO: Why? + if (submenu == BUILD_MENU_VACANT_HOUSE || + submenu == BUILD_MENU_TEMPLES || + submenu == BUILD_MENU_HEALTH || + submenu == BUILD_MENU_EDUCATION || + submenu == BUILD_MENU_ENTERTAINMENT){ + data.show_info_for = submenu; + } + + window_build_menu_show(submenu); +} + +static void button_undo(int param1, int param2) +{ + window_build_menu_hide(); + game_undo_perform(); + window_invalidate(); +} + +static void button_messages(int param1, int param2) +{ + window_build_menu_hide(); + window_message_list_show(); +} + +static void button_help(int param1, const int param2) +{ + window_build_menu_hide(); + window_message_dialog_show(param2, window_city_draw_all); +} + +static void button_go_to_problem(int param1, int param2) +{ + window_build_menu_hide(); + const int grid_offset = city_message_next_problem_area_grid_offset(); + if (grid_offset) { + city_view_go_to_grid_offset(grid_offset); + window_city_show(); + } else { + window_invalidate(); + } +} + +static void button_advisors(int param1, int param2) +{ + window_advisors_show_checked(); +} + +static void button_empire(int param1, int param2) +{ + window_empire_show_checked(); +} + +static void button_toggle_grid(int param1, int param2) +{ + config_set(CONFIG_UI_SHOW_GRID, config_get(CONFIG_UI_SHOW_GRID) ^ 1); +} + +static void button_rotate_north(int param1, int param2) +{ + game_orientation_rotate_north(); + window_invalidate(); +} + +static void button_rotate(const int clockwise, int param2) +{ + if (clockwise) { + game_orientation_rotate_right(); + } else { + game_orientation_rotate_left(); + } + window_invalidate(); +} + +static void button_overlay_click(int param1, int param2) +{ + window_overlay_menu_show(); +} \ No newline at end of file diff --git a/src/widget/sidebar/advanced/sidebar.h b/src/widget/sidebar/advanced/sidebar.h new file mode 100644 index 0000000000..404eb95ad1 --- /dev/null +++ b/src/widget/sidebar/advanced/sidebar.h @@ -0,0 +1,19 @@ +#ifndef WIDGET_ADVANCED_SIDEBAR +#define WIDGET_ADVANCED_SIDEBAR + +#include "graphics/tooltip.h" +#include "input/mouse.h" + +int advanced_sidebar_width(void); + +void draw_advanced_sidebar_background(int x_offset); +void draw_advanced_sidebar_foreground(void); + +int handle_advanced_sidebar_mouse(const mouse *m); +int handle_advanced_sidebar_mouse_build_menu( const mouse *m); + +int calculate_x_offset_sidebar_advanced(void); + +unsigned int get_advanced_sidebar_tooltip_text(tooltip_context *c); + +#endif diff --git a/src/widget/sidebar/city.c b/src/widget/sidebar/city.c index 3d86d17ac7..04e97154bb 100644 --- a/src/widget/sidebar/city.c +++ b/src/widget/sidebar/city.c @@ -1,370 +1,203 @@ #include "city.h" -#include "building/menu.h" -#include "city/message.h" #include "city/view.h" -#include "city/warning.h" -#include "core/config.h" -#include "core/direction.h" -#include "game/campaign.h" -#include "game/orientation.h" -#include "game/state.h" -#include "game/undo.h" -#include "graphics/graphics.h" -#include "graphics/image.h" -#include "graphics/image_button.h" -#include "graphics/lang_text.h" -#include "graphics/screen.h" -#include "graphics/text.h" #include "graphics/window.h" -#include "map/orientation.h" -#include "scenario/property.h" -#include "translation/translation.h" #include "widget/city.h" -#include "widget/minimap.h" -#include "widget/sidebar/common.h" -#include "widget/sidebar/extra.h" #include "widget/sidebar/slide.h" -#include "window/advisors.h" -#include "window/build_menu.h" #include "window/city.h" -#include "window/empire.h" -#include "window/message_dialog.h" -#include "window/message_list.h" -#include "window/mission_briefing.h" -#include "window/overlay_menu.h" - -#define MINIMAP_Y_OFFSET 59 - -static void button_overlay(int param1, int param2); -static void button_collapse_expand(int param1, int param2); -static void button_build(int submenu, int param2); -static void button_undo(int param1, int param2); -static void button_messages(int param1, int param2); -static void button_help(int param1, int param2); -static void button_go_to_problem(int param1, int param2); -static void button_advisors(int param1, int param2); -static void button_empire(int param1, int param2); -static void button_toggle_grid(int param1, int param2); -static void button_rotate_north(int param1, int param2); -static void button_rotate(int clockwise, int param2); - -static image_button buttons_overlays_collapse_sidebar[] = { - {127, 5, 31, 20, IB_NORMAL, 90, 0, button_collapse_expand, button_none, 0, 0, 1}, - {4, 3, 117, 31, IB_NORMAL, 93, 0, button_overlay, button_help, 0, MESSAGE_DIALOG_OVERLAYS, 1} -}; - -static image_button button_expand_sidebar[] = { - {6, 4, 31, 20, IB_NORMAL, 90, 4, button_collapse_expand, button_none, 0, 0, 1} -}; -static image_button buttons_build_collapsed[] = { - {2, 32, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 0, button_build, button_none, BUILD_MENU_VACANT_HOUSE, 0, 1}, - {2, 67, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 8, button_build, button_none, BUILD_MENU_CLEAR_LAND, 0, 1}, - {2, 102, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 12, button_build, button_none, BUILD_MENU_ROAD, 0, 1}, - {2, 137, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 4, button_build, button_none, BUILD_MENU_WATER, 0, 1}, - {2, 172, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 40, button_build, button_none, BUILD_MENU_HEALTH, 0, 1, "UI", "Asclepius Button"}, - {2, 207, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 28, button_build, button_none, BUILD_MENU_TEMPLES, 0, 1}, - {2, 242, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 24, button_build, button_none, BUILD_MENU_EDUCATION, 0, 1}, - {2, 277, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 20, button_build, button_none, BUILD_MENU_ENTERTAINMENT, 0, 1}, - {2, 312, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 16, button_build, button_none, BUILD_MENU_ADMINISTRATION, 0, 1}, - {2, 347, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 44, button_build, button_none, BUILD_MENU_ENGINEERING, 0, 1}, - {2, 382, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 36, button_build, button_none, BUILD_MENU_SECURITY, 0, 1}, - {2, 417, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 32, button_build, button_none, BUILD_MENU_INDUSTRY, 0, 1}, -}; - -static image_button buttons_build_expanded[] = { - {13, 277, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 0, button_build, button_none, BUILD_MENU_VACANT_HOUSE, 0, 1}, - {63, 277, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 8, button_build, button_none, BUILD_MENU_CLEAR_LAND, 0, 1}, - {113, 277, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 12, button_build, button_none, BUILD_MENU_ROAD, 0, 1}, - {13, 313, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 4, button_build, button_none, BUILD_MENU_WATER, 0, 1}, - {63, 313, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 40, button_build, button_none, BUILD_MENU_HEALTH, 0, 1, "UI", "Asclepius Button"}, - {113, 313, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 28, button_build, button_none, BUILD_MENU_TEMPLES, 0, 1}, - {13, 349, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 24, button_build, button_none, BUILD_MENU_EDUCATION, 0, 1}, - {63, 349, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 20, button_build, button_none, BUILD_MENU_ENTERTAINMENT, 0, 1}, - {113, 349, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 16, button_build, button_none, BUILD_MENU_ADMINISTRATION, 0, 1}, - {13, 385, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 44, button_build, button_none, BUILD_MENU_ENGINEERING, 0, 1}, - {63, 385, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 36, button_build, button_none, BUILD_MENU_SECURITY, 0, 1}, - {113, 385, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 32, button_build, button_none, BUILD_MENU_INDUSTRY, 0, 1}, - {13, 421, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 48, button_undo, button_none, 0, 0, 1}, - {63, 421, 39, 26, IB_NORMAL, GROUP_MESSAGE_ICON, 18, button_messages, button_help, 0, MESSAGE_DIALOG_MESSAGES, 1}, - {113, 421, 39, 26, IB_BUILD, GROUP_MESSAGE_ICON, 22, button_go_to_problem, button_none, 0, 0, 1}, -}; +#include "advanced/sidebar.h" +#include "collapsed/sidebar.h" +#include "expanded/sidebar.h" +#include "graphics/screen.h" -static image_button buttons_top_expanded[] = { - {7, 155, 71, 23, IB_NORMAL, GROUP_SIDEBAR_ADVISORS_EMPIRE, 0, button_advisors, button_none, 0, 0, 1}, - {84, 155, 71, 23, IB_NORMAL, GROUP_SIDEBAR_ADVISORS_EMPIRE, 3, button_empire, button_help, 0, MESSAGE_DIALOG_EMPIRE_MAP, 1}, - {7, 184, 33, 22, IB_NORMAL, 0, 0, button_toggle_grid, button_none, 0, 0, 1, "UI", "Toggle Grid Button" }, - {46, 184, 33, 22, IB_NORMAL, GROUP_SIDEBAR_BRIEFING_ROTATE_BUTTONS, 3, button_rotate_north, button_none, 0, 0, 1}, - {84, 184, 33, 22, IB_NORMAL, GROUP_SIDEBAR_BRIEFING_ROTATE_BUTTONS, 6, button_rotate, button_none, 0, 0, 1}, - {123, 184, 33, 22, IB_NORMAL, GROUP_SIDEBAR_BRIEFING_ROTATE_BUTTONS, 9, button_rotate, button_none, 1, 0, 1}, -}; +typedef enum {ADVANCED, EXPANDED, COLLAPSED } States; static struct { - int focus_button_for_tooltip; + States currentState; + States previousState; } data; -static void draw_overlay_text(int x_offset) -{ - if (game_state_overlay()) { - const uint8_t *text = get_current_overlay_text(); - text_draw_centered(text, x_offset, 32, 117, FONT_NORMAL_GREEN, 0); - } else { - lang_text_draw_centered(6, 4, x_offset, 32, 117, FONT_NORMAL_GREEN); - } -} -static void draw_sidebar_remainder(int x_offset, int is_collapsed) -{ - int width = SIDEBAR_EXPANDED_WIDTH; - if (is_collapsed) { - width = SIDEBAR_COLLAPSED_WIDTH; +static void draw_slide_old(void) +{ + int x_offset = screen_width(); + + switch (data.previousState) { + case EXPANDED: + x_offset -= expanded_sidebar_width(); + draw_expanded_sidebar_background(x_offset); + break; + case COLLAPSED: + x_offset -= collapsed_sidebar_width(); + draw_collapsed_sidebar_background(x_offset); + break; + case ADVANCED: + x_offset -= advanced_sidebar_width(); + draw_advanced_sidebar_background(x_offset); + break; + default:; } - int available_height = sidebar_common_get_height() - SIDEBAR_MAIN_SECTION_HEIGHT; - int extra_height = sidebar_extra_draw_background(x_offset, SIDEBAR_FILLER_Y_OFFSET, - width, available_height, is_collapsed, SIDEBAR_EXTRA_DISPLAY_ALL); - sidebar_extra_draw_foreground(); - int relief_y_offset = SIDEBAR_FILLER_Y_OFFSET + extra_height; - sidebar_common_draw_relief(x_offset, relief_y_offset, GROUP_SIDE_PANEL, is_collapsed); } -static void draw_number_of_messages(int x_offset) +static void draw_slide_new(const int x_offset) { - int messages = city_message_count(); - int show_messages = game_campaign_is_original() || messages > 0 || scenario_intro_message(); - buttons_build_expanded[13].enabled = show_messages; - buttons_build_expanded[14].enabled = city_message_problem_area_count(); - if (show_messages) { - int width = text_get_number_width(messages, '@', "", FONT_SMALL_PLAIN); - text_draw_number(messages, '@', "", (x_offset + 100) - width, 452, FONT_SMALL_PLAIN, COLOR_BLACK); //top - text_draw_number(messages, '@', "", (x_offset + 100) - width, 454, FONT_SMALL_PLAIN, COLOR_BLACK); //bottom - text_draw_number(messages, '@', "", (x_offset + 99) - width, 453, FONT_SMALL_PLAIN, COLOR_BLACK); //left - text_draw_number(messages, '@', "", (x_offset + 101) - width, 453, FONT_SMALL_PLAIN, COLOR_BLACK); //right - text_draw_number(messages, '@', "", (x_offset + 100) - width, 453, FONT_SMALL_PLAIN, COLOR_WHITE); + switch (data.currentState) { + case EXPANDED: + draw_expanded_sidebar_background(x_offset); + break; + case COLLAPSED: + draw_collapsed_sidebar_background(x_offset); + break; + case ADVANCED: + draw_advanced_sidebar_background(x_offset); + break; + default: ; } } -static void draw_buttons_collapsed(int x_offset) +static void slide_finished(void) { - image_buttons_draw(x_offset, 24, button_expand_sidebar, 1); - image_buttons_draw(x_offset, 24, buttons_build_collapsed, 12); + city_view_toggle_sidebar(); + window_city_show(); } -static void draw_buttons_expanded(int x_offset) +void sidebar_next(void) { - buttons_build_expanded[12].enabled = game_can_undo(); - image_buttons_draw(x_offset, 24, buttons_overlays_collapse_sidebar, 2); - image_buttons_draw(x_offset, 24, buttons_build_expanded, 15); - image_buttons_draw(x_offset, 24, buttons_top_expanded, 6); -} + data.previousState = data.currentState; + const int previous_sidebar_width = widget_sidebar_city_get_width(); + const int previous_sidebar_x_offset = widget_sidebar_calculate_x_offset(); + slide_direction slide_direction = SLIDE_DIRECTION_OUT; -static void draw_collapsed_background(void) -{ - int x_offset = sidebar_common_get_x_offset_collapsed(); - image_draw(image_group(GROUP_SIDE_PANEL), x_offset, 24, COLOR_MASK_NONE, SCALE_NONE); - draw_buttons_collapsed(x_offset); - draw_sidebar_remainder(x_offset, 1); -} + if (data.currentState == COLLAPSED) { + slide_direction = SLIDE_DIRECTION_IN; + data.currentState = ADVANCED; + } else if (data.currentState == ADVANCED) { + data.currentState = EXPANDED; + } else if (data.currentState == EXPANDED) { + slide_direction = SLIDE_DIRECTION_IN; + data.currentState = COLLAPSED; + } -static void draw_expanded_background(int x_offset) -{ - image_draw(image_group(GROUP_SIDE_PANEL) + 1, x_offset, 24, COLOR_MASK_NONE, SCALE_NONE); - draw_buttons_expanded(x_offset); - draw_overlay_text(x_offset + 4); - draw_number_of_messages(x_offset); - image_draw(window_build_menu_image(), x_offset + 6, 239, COLOR_MASK_NONE, SCALE_NONE); - widget_minimap_update(0); - widget_minimap_draw_decorated(x_offset + 8, MINIMAP_Y_OFFSET, MINIMAP_WIDTH, MINIMAP_HEIGHT); + city_view_start_sidebar_toggle(); + sidebar_slide(slide_direction, + draw_slide_old, + draw_slide_new, + slide_finished, + previous_sidebar_width, + previous_sidebar_x_offset); - draw_sidebar_remainder(x_offset, 0); + window_city_show(); } -void widget_sidebar_city_draw_background(void) +int widget_sidebar_city_get_width(void) { - if (city_view_is_sidebar_collapsed()) { - draw_collapsed_background(); - } else { - draw_expanded_background(sidebar_common_get_x_offset_expanded()); + switch (data.currentState) { + case EXPANDED: + return expanded_sidebar_width(); + case COLLAPSED: + return collapsed_sidebar_width(); + case ADVANCED: + return advanced_sidebar_width(); + default: + return 0; } } -static void enable_building_buttons(void) +int widget_sidebar_is_collapsed(void) { - for (int i = 0; i < 12; i++) { - buttons_build_expanded[i].enabled = 1; - if (building_menu_count_items(buttons_build_expanded[i].parameter1) <= 0) { - buttons_build_expanded[i].enabled = 0; - } + return data.currentState == COLLAPSED ? 1 : 0; +} - buttons_build_collapsed[i].enabled = 1; - if (building_menu_count_items(buttons_build_collapsed[i].parameter1) <= 0) { - buttons_build_collapsed[i].enabled = 0; - } +void widget_sidebar_city_draw_background(void) +{ + int x_offset = screen_width(); + + switch (data.currentState) { + case EXPANDED: + x_offset -= expanded_sidebar_width(); + draw_expanded_sidebar_background(x_offset); + break; + case COLLAPSED: + x_offset -= collapsed_sidebar_width(); + draw_collapsed_sidebar_background(x_offset); + break; + case ADVANCED: + x_offset -= advanced_sidebar_width(); + draw_advanced_sidebar_background(x_offset); + break; + default:; } } void widget_sidebar_city_draw_foreground(void) { - if (building_menu_has_changed()) { - enable_building_buttons(); - } - if (city_view_is_sidebar_collapsed()) { - int x_offset = sidebar_common_get_x_offset_collapsed(); - draw_buttons_collapsed(x_offset); - } else { - int x_offset = sidebar_common_get_x_offset_expanded(); - draw_buttons_expanded(x_offset); - draw_overlay_text(x_offset + 4); - widget_minimap_draw_decorated(x_offset + 8, MINIMAP_Y_OFFSET, MINIMAP_WIDTH, MINIMAP_HEIGHT); - draw_number_of_messages(x_offset); + switch (data.currentState) { + case EXPANDED: + draw_expanded_sidebar_foreground(); + break; + case COLLAPSED: + draw_collapsed_sidebar_foreground(); + break; + case ADVANCED: + draw_advanced_sidebar_foreground(); + break; + default:; } - sidebar_extra_draw_foreground(); } int widget_sidebar_city_handle_mouse(const mouse *m) { - if (widget_city_has_input()) { - return 0; - } - int handled = 0; - unsigned int button_id; - data.focus_button_for_tooltip = 0; - if (city_view_is_sidebar_collapsed()) { - int x_offset = sidebar_common_get_x_offset_collapsed(); - handled |= image_buttons_handle_mouse(m, x_offset, 24, button_expand_sidebar, 1, &button_id); - if (button_id) { - data.focus_button_for_tooltip = 12; - } - handled |= image_buttons_handle_mouse(m, x_offset, 24, buttons_build_collapsed, 12, &button_id); - if (button_id) { - data.focus_button_for_tooltip = button_id + 19; - } - } else { - if (widget_minimap_handle_mouse(m)) { - return 1; - } - int x_offset = sidebar_common_get_x_offset_expanded(); - handled |= image_buttons_handle_mouse(m, x_offset, 24, buttons_overlays_collapse_sidebar, 2, &button_id); - if (button_id) { - data.focus_button_for_tooltip = button_id + 9; - } - handled |= image_buttons_handle_mouse(m, x_offset, 24, buttons_build_expanded, 15, &button_id); - if (button_id) { - data.focus_button_for_tooltip = button_id + 19; - } - handled |= image_buttons_handle_mouse(m, x_offset, 24, buttons_top_expanded, 6, &button_id); - if (button_id) { - data.focus_button_for_tooltip = button_id + 39; - } - handled |= sidebar_extra_handle_mouse(m); + switch (data.currentState) { + case EXPANDED: + return handle_expanded_sidebar_mouse(m); + case COLLAPSED: + return handle_collapsed_sidebar_mouse(m); + case ADVANCED: + return handle_advanced_sidebar_mouse(m); + default: + return 0; } - return handled; } int widget_sidebar_city_handle_mouse_build_menu(const mouse *m) { - if (city_view_is_sidebar_collapsed()) { - return image_buttons_handle_mouse(m, - sidebar_common_get_x_offset_collapsed(), 24, buttons_build_collapsed, 12, 0); - } else { - return image_buttons_handle_mouse(m, - sidebar_common_get_x_offset_expanded(), 24, buttons_build_expanded, 15, 0); - } -} - -int widget_sidebar_city_get_tooltip_text(tooltip_context *c) -{ - if (data.focus_button_for_tooltip) { - if (data.focus_button_for_tooltip == 42) { - c->translation_key = TR_TOGGLE_GRID; + switch (data.currentState) { + case EXPANDED: + return handle_expanded_sidebar_mouse_build_menu(m); + case COLLAPSED: + return handle_collapsed_sidebar_mouse_build_menu(m); + case ADVANCED: + return handle_advanced_sidebar_mouse_build_menu(m); + default: return 0; - } - return data.focus_button_for_tooltip; } - return sidebar_extra_get_tooltip(c); -} - -static void slide_finished(void) -{ - city_view_toggle_sidebar(); - window_city_show(); -} - -static void button_overlay(int param1, int param2) -{ - window_overlay_menu_show(); -} - -static void button_collapse_expand(int param1, int param2) -{ - city_view_start_sidebar_toggle(); - sidebar_slide(!city_view_is_sidebar_collapsed(), - draw_collapsed_background, draw_expanded_background, slide_finished); -} - -static void button_build(int submenu, int param2) -{ - window_build_menu_show(submenu); -} - -static void button_undo(int param1, int param2) -{ - window_build_menu_hide(); - game_undo_perform(); - window_invalidate(); -} - -static void button_messages(int param1, int param2) -{ - window_build_menu_hide(); - window_message_list_show(); } -static void button_help(int param1, int param2) +unsigned int widget_sidebar_city_get_tooltip_text(tooltip_context *c) { - window_build_menu_hide(); - window_message_dialog_show(param2, window_city_draw_all); -} - -static void button_go_to_problem(int param1, int param2) -{ - window_build_menu_hide(); - int grid_offset = city_message_next_problem_area_grid_offset(); - if (grid_offset) { - city_view_go_to_grid_offset(grid_offset); - window_city_show(); - } else { - window_invalidate(); + switch (data.currentState) { + case EXPANDED: + return get_expanded_sidebar_tooltip_text(c); + case COLLAPSED: + return get_collapsed_sidebar_tooltip_text(c); + case ADVANCED: + return get_advanced_sidebar_tooltip_text(c); + default: + return 0; } } -static void button_advisors(int param1, int param2) -{ - window_advisors_show_checked(); -} - -static void button_empire(int param1, int param2) -{ - window_empire_show_checked(); -} - -static void button_toggle_grid(int param1, int param2) -{ - config_set(CONFIG_UI_SHOW_GRID, config_get(CONFIG_UI_SHOW_GRID) ^ 1); -} - -static void button_rotate_north(int param1, int param2) +int widget_sidebar_calculate_x_offset(void) { - game_orientation_rotate_north(); - window_invalidate(); -} - -static void button_rotate(int clockwise, int param2) -{ - if (clockwise) { - game_orientation_rotate_right(); - } else { - game_orientation_rotate_left(); + switch (data.currentState) { + case EXPANDED: + return calculate_x_offset_sidebar_expanded(); + case COLLAPSED: + return calculate_x_offset_sidebar_collapsed(); + case ADVANCED: + return calculate_x_offset_sidebar_advanced(); + default: + return 0; } - window_invalidate(); } diff --git a/src/widget/sidebar/city.h b/src/widget/sidebar/city.h index 133d0e39dc..7073a1cc31 100644 --- a/src/widget/sidebar/city.h +++ b/src/widget/sidebar/city.h @@ -4,12 +4,20 @@ #include "graphics/tooltip.h" #include "input/mouse.h" +int widget_sidebar_is_collapsed(void); + +int widget_sidebar_city_get_width(void); + void widget_sidebar_city_draw_background(void); void widget_sidebar_city_draw_foreground(void); int widget_sidebar_city_handle_mouse(const mouse *m); int widget_sidebar_city_handle_mouse_build_menu(const mouse *m); -int widget_sidebar_city_get_tooltip_text(tooltip_context *c); +int widget_sidebar_calculate_x_offset(void); + +unsigned int widget_sidebar_city_get_tooltip_text(tooltip_context *c); + +void sidebar_next(void); #endif // WIDGET_SIDEBAR_CITY_H diff --git a/src/widget/sidebar/collapsed/sidebar.c b/src/widget/sidebar/collapsed/sidebar.c new file mode 100644 index 0000000000..bac36349aa --- /dev/null +++ b/src/widget/sidebar/collapsed/sidebar.c @@ -0,0 +1,155 @@ +#include "sidebar.h" + +#include "building/menu.h" +#include "city/warning.h" +#include "graphics/image.h" +#include "graphics/image_button.h" +#include "graphics/screen.h" +#include "graphics/window.h" +#include "translation/translation.h" +#include "widget/city.h" +#include "widget/sidebar/city.h" +#include "widget/sidebar/common.h" +#include "widget/sidebar/extra.h" +#include "window/build_menu.h" + +#define SIDEBAR_COLLAPSED_WIDTH 42 + +static void button_collapse_expand(int param1, int param2); +static void button_build(int submenu, int param2); + +static image_button button_expand_sidebar[] = { + {6, 4, 31, 20, IB_NORMAL, 90, 4, button_collapse_expand, button_none, 0, 0, 1} +}; + +static image_button buttons_build_collapsed[] = { + {2, 32, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 0, button_build, button_none, BUILD_MENU_VACANT_HOUSE, 0, 1}, + {2, 67, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 8, button_build, button_none, BUILD_MENU_CLEAR_LAND, 0, 1}, + {2, 102, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 12, button_build, button_none, BUILD_MENU_ROAD, 0, 1}, + {2, 137, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 4, button_build, button_none, BUILD_MENU_WATER, 0, 1}, + {2, 172, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 40, button_build, button_none, BUILD_MENU_HEALTH, 0, 1, "UI", "Asclepius Button"}, + {2, 207, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 28, button_build, button_none, BUILD_MENU_TEMPLES, 0, 1}, + {2, 242, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 24, button_build, button_none, BUILD_MENU_EDUCATION, 0, 1}, + {2, 277, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 20, button_build, button_none, BUILD_MENU_ENTERTAINMENT, 0, 1}, + {2, 312, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 16, button_build, button_none, BUILD_MENU_ADMINISTRATION, 0, 1}, + {2, 347, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 44, button_build, button_none, BUILD_MENU_ENGINEERING, 0, 1}, + {2, 382, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 36, button_build, button_none, BUILD_MENU_SECURITY, 0, 1}, + {2, 417, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 32, button_build, button_none, BUILD_MENU_INDUSTRY, 0, 1}, +}; + +static struct { + unsigned int focus_button_for_tooltip; +} data; + + +static void draw_sidebar_remainder(const int x_offset) +{ + const int width = SIDEBAR_COLLAPSED_WIDTH; // still comming from common + + const int available_height = sidebar_common_get_height() - SIDEBAR_MAIN_SECTION_HEIGHT; + const int extra_height = sidebar_extra_draw_background(x_offset, SIDEBAR_FILLER_Y_OFFSET, + width, available_height, 1, SIDEBAR_EXTRA_DISPLAY_ALL); + sidebar_extra_draw_foreground(); + + const int relief_y_offset = SIDEBAR_FILLER_Y_OFFSET + extra_height; + sidebar_common_draw_relief(x_offset, relief_y_offset, GROUP_SIDE_PANEL, 1,0); +} + +static void draw_buttons_collapsed(const int x_offset) +{ + image_buttons_draw(x_offset, 24, button_expand_sidebar, 1); + image_buttons_draw(x_offset, 24, buttons_build_collapsed, 12); +} + +static void enable_building_buttons(void) +{ + for (int i = 0; i < 12; i++) { + buttons_build_collapsed[i].enabled = 1; + if (building_menu_count_items(buttons_build_collapsed[i].parameter1) <= 0) { + buttons_build_collapsed[i].enabled = 0; + } + } +} + +int collapsed_sidebar_width(void) +{ + return SIDEBAR_COLLAPSED_WIDTH; +} + +void draw_collapsed_sidebar_background(int x_offset) +{ + image_draw(image_group(GROUP_SIDE_PANEL), x_offset, 24, COLOR_MASK_NONE, SCALE_NONE); + + draw_buttons_collapsed(x_offset); + draw_sidebar_remainder(x_offset); +} + +int calculate_x_offset_sidebar_collapsed(void) +{ + return screen_width() - SIDEBAR_COLLAPSED_WIDTH; +} + + +void draw_collapsed_sidebar_foreground() +{ + if (building_menu_has_changed()) { + enable_building_buttons(); + } + + const int x_offset = calculate_x_offset_sidebar_collapsed(); + + draw_buttons_collapsed(x_offset); + + sidebar_extra_draw_foreground(); +} + + +int handle_collapsed_sidebar_mouse(const mouse *m) +{ + if (widget_city_has_input()) { + return 0; + } + int handled = 0; + unsigned int button_id; + data.focus_button_for_tooltip = 0; + + const int x_offset = calculate_x_offset_sidebar_collapsed(); + handled |= image_buttons_handle_mouse(m, x_offset, 24, button_expand_sidebar, 1, &button_id); + if (button_id) { + data.focus_button_for_tooltip = 12; + } + handled |= image_buttons_handle_mouse(m, x_offset, 24, buttons_build_collapsed, 12, &button_id); + if (button_id) { + data.focus_button_for_tooltip = button_id + 19; + } + + return handled; +} + +int handle_collapsed_sidebar_mouse_build_menu(const mouse *m) +{ + return image_buttons_handle_mouse(m, + calculate_x_offset_sidebar_collapsed(), 24, buttons_build_collapsed, 12, 0); +} + +unsigned int get_collapsed_sidebar_tooltip_text(tooltip_context *c) +{ + if (data.focus_button_for_tooltip) { + if (data.focus_button_for_tooltip == 42) { + c->translation_key = TR_TOGGLE_GRID; + return 0; + } + return data.focus_button_for_tooltip; + } + return sidebar_extra_get_tooltip(c); +} + +static void button_collapse_expand(int param1, int param2) +{ + sidebar_next(); +} + +static void button_build(const int submenu, int param2) +{ + window_build_menu_show(submenu); +} \ No newline at end of file diff --git a/src/widget/sidebar/collapsed/sidebar.h b/src/widget/sidebar/collapsed/sidebar.h new file mode 100644 index 0000000000..497a2c3936 --- /dev/null +++ b/src/widget/sidebar/collapsed/sidebar.h @@ -0,0 +1,19 @@ +#ifndef WIDGET_COLLAPSED_SIDEBAR +#define WIDGET_COLLAPSED_SIDEBAR + +#include "graphics/tooltip.h" +#include "input/mouse.h" + +int collapsed_sidebar_width(void); + +void draw_collapsed_sidebar_background(int x_offset); +void draw_collapsed_sidebar_foreground(void); + +int handle_collapsed_sidebar_mouse(const mouse *m); +int handle_collapsed_sidebar_mouse_build_menu( const mouse *m); + +int calculate_x_offset_sidebar_collapsed(void); + +unsigned int get_collapsed_sidebar_tooltip_text(tooltip_context *c); + +#endif // WIDGET_COLLAPSED_SIDEBAR diff --git a/src/widget/sidebar/common.c b/src/widget/sidebar/common.c index 2fa096da82..b83ebb3720 100644 --- a/src/widget/sidebar/common.c +++ b/src/widget/sidebar/common.c @@ -5,34 +5,26 @@ #include "graphics/screen.h" #include "widget/minimap.h" -int sidebar_common_get_x_offset_expanded(void) -{ - return screen_width() - SIDEBAR_EXPANDED_WIDTH; -} - -int sidebar_common_get_x_offset_collapsed(void) -{ - return screen_width() - SIDEBAR_COLLAPSED_WIDTH; -} - int sidebar_common_get_height(void) { return screen_height() - TOP_MENU_HEIGHT; } -void sidebar_common_draw_relief(int x_offset, int y_offset, int image_id, int is_collapsed) +void sidebar_common_draw_relief(int x_offset, int y_offset, int image_id, int is_collapsed, int scale_by) { + const int scale = 100 + scale_by; // relief images below panel - int image_base = image_group(image_id); - int image_offset = image_id == GROUP_SIDE_PANEL ? 2 : 1; - int y_max = screen_height(); + const int image_base = image_group(image_id); + const int image_offset = image_id == GROUP_SIDE_PANEL ? 2 : 1; + const int y_max = screen_height(); while (y_offset < y_max) { if (y_max - y_offset <= 120) { - image_draw(image_base + image_offset + is_collapsed, x_offset, y_offset, COLOR_MASK_NONE, SCALE_NONE); + + image_draw_scaled_from_corner(image_base + image_offset + is_collapsed, x_offset, y_offset, COLOR_MASK_NONE, scale); y_offset += 120; } else { - image_draw(image_base + image_offset + image_offset + is_collapsed, x_offset, y_offset, - COLOR_MASK_NONE, SCALE_NONE); + image_draw_scaled_from_corner(image_base + image_offset + image_offset + is_collapsed, x_offset, y_offset, + COLOR_MASK_NONE, scale); y_offset += 285; } } diff --git a/src/widget/sidebar/common.h b/src/widget/sidebar/common.h index 488aa67bec..8dc04ba5cc 100644 --- a/src/widget/sidebar/common.h +++ b/src/widget/sidebar/common.h @@ -3,19 +3,12 @@ #include "graphics/menu.h" -#define SIDEBAR_COLLAPSED_WIDTH 42 -#define SIDEBAR_EXPANDED_WIDTH 162 #define SIDEBAR_MAIN_SECTION_HEIGHT 450 #define SIDEBAR_FILLER_Y_OFFSET (SIDEBAR_MAIN_SECTION_HEIGHT + TOP_MENU_HEIGHT) #define MINIMAP_WIDTH 146 #define MINIMAP_HEIGHT 111 -int sidebar_common_get_x_offset_expanded(void); - -int sidebar_common_get_x_offset_collapsed(void); - int sidebar_common_get_height(void); - -void sidebar_common_draw_relief(int x_offset, int y_offset, int image_id, int is_collapsed); +void sidebar_common_draw_relief(int x_offset, int y_offset, int image_id, int is_collapsed, int scale); #endif // WIDGET_SIDEBAR_COMMON_H diff --git a/src/widget/sidebar/editor.c b/src/widget/sidebar/editor.c index adba67cd78..3fb36d583e 100644 --- a/src/widget/sidebar/editor.c +++ b/src/widget/sidebar/editor.c @@ -11,6 +11,8 @@ #include "graphics/text.h" #include "graphics/window.h" #include "scenario/editor.h" + +#include "expanded/sidebar.h" #include "scenario/editor_events.h" #include "scenario/editor_map.h" #include "scenario/invasion.h" @@ -51,12 +53,12 @@ static image_button buttons_build[] = { static void draw_buttons(void) { - image_buttons_draw(sidebar_common_get_x_offset_expanded(), TOP_MENU_HEIGHT, buttons_build, 17); + image_buttons_draw(calculate_x_offset_sidebar_expanded(), TOP_MENU_HEIGHT, buttons_build, 17); } static void draw_status(void) { - int x_offset = sidebar_common_get_x_offset_expanded(); + int x_offset = calculate_x_offset_sidebar_expanded(); inner_panel_draw(x_offset + 1, 175, 10, 7); int text_offset = x_offset + 6; @@ -137,19 +139,19 @@ static void draw_status(void) void widget_sidebar_editor_draw_background(void) { int image_base = image_group(GROUP_EDITOR_SIDE_PANEL); - int x_offset = sidebar_common_get_x_offset_expanded(); + int x_offset = calculate_x_offset_sidebar_expanded(); image_draw(image_base, x_offset, TOP_MENU_HEIGHT, COLOR_MASK_NONE, SCALE_NONE); draw_buttons(); widget_minimap_update(0); widget_minimap_draw_decorated(x_offset + 8, MINIMAP_Y_OFFSET, MINIMAP_WIDTH, MINIMAP_HEIGHT); - sidebar_common_draw_relief(x_offset, SIDEBAR_FILLER_Y_OFFSET, GROUP_EDITOR_SIDE_PANEL, 0); + sidebar_common_draw_relief(x_offset, SIDEBAR_FILLER_Y_OFFSET, GROUP_EDITOR_SIDE_PANEL, 0, 0); } void widget_sidebar_editor_draw_foreground(void) { draw_buttons(); draw_status(); - widget_minimap_draw_decorated(sidebar_common_get_x_offset_expanded() + 8, + widget_minimap_draw_decorated(calculate_x_offset_sidebar_expanded() + 8, MINIMAP_Y_OFFSET, MINIMAP_WIDTH, MINIMAP_HEIGHT); } @@ -158,17 +160,17 @@ int widget_sidebar_editor_handle_mouse(const mouse *m) if (widget_minimap_handle_mouse(m)) { return 1; } - return image_buttons_handle_mouse(m, sidebar_common_get_x_offset_expanded(), 24, buttons_build, 17, 0); + return image_buttons_handle_mouse(m, calculate_x_offset_sidebar_expanded(), 24, buttons_build, 17, 0); } int widget_sidebar_editor_handle_mouse_build_menu(const mouse *m) { - return image_buttons_handle_mouse(m, sidebar_common_get_x_offset_expanded(), 24, buttons_build, 17, 0); + return image_buttons_handle_mouse(m, calculate_x_offset_sidebar_expanded(), 24, buttons_build, 17, 0); } int widget_sidebar_editor_handle_mouse_attributes(const mouse *m) { - return image_buttons_handle_mouse(m, sidebar_common_get_x_offset_expanded(), 24, buttons_build, 2, 0); + return image_buttons_handle_mouse(m, calculate_x_offset_sidebar_expanded(), 24, buttons_build, 2, 0); } static void button_attributes(int show, int param2) diff --git a/src/widget/sidebar/expanded/sidebar.c b/src/widget/sidebar/expanded/sidebar.c new file mode 100644 index 0000000000..7d3c82315c --- /dev/null +++ b/src/widget/sidebar/expanded/sidebar.c @@ -0,0 +1,306 @@ +#include "sidebar.h" + +#include "building/menu.h" +#include "city/message.h" +#include "city/view.h" +#include "city/warning.h" +#include "core/config.h" +#include "game/campaign.h" +#include "game/orientation.h" +#include "game/state.h" +#include "game/undo.h" +#include "graphics/image.h" +#include "graphics/image_button.h" +#include "graphics/lang_text.h" +#include "graphics/screen.h" +#include "graphics/text.h" +#include "graphics/window.h" +#include "scenario/property.h" +#include "translation/translation.h" +#include "widget/city.h" +#include "widget/minimap.h" +#include "widget/sidebar/common.h" +#include "widget/sidebar/extra.h" +#include "window/advisors.h" +#include "window/build_menu.h" +#include "window/city.h" + +#include "widget/sidebar/city.h" +#include "window/empire.h" +#include "window/message_dialog.h" +#include "window/message_list.h" +#include "window/overlay_menu.h" + +#define MINIMAP_Y_OFFSET 59 +#define SIDEBAR_EXPANDED_WIDTH 162 + +static void button_overlay_click(int param1, int param2); +static void button_collapse(int param1, int param2); +static void button_build(int submenu, int param2); +static void button_undo(int param1, int param2); +static void button_messages(int param1, int param2); +static void button_help(int param1, int param2); +static void button_go_to_problem(int param1, int param2); +static void button_advisors(int param1, int param2); +static void button_empire(int param1, int param2); +static void button_toggle_grid(int param1, int param2); +static void button_rotate_north(int param1, int param2); +static void button_rotate(int clockwise, int param2); + +static image_button buttons_overlays_collapse_sidebar[] = { + {127, 5, 31, 20, IB_NORMAL, 90, 0, button_collapse, button_none, 0, 0, 1}, + {4, 3, 117, 31, IB_NORMAL, 93, 0, button_overlay_click, button_help, 0, MESSAGE_DIALOG_OVERLAYS, 1} +}; + +static image_button buttons_build_expanded[] = { + {13, 277, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 0, button_build, button_none, BUILD_MENU_VACANT_HOUSE, 0, 1}, + {63, 277, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 8, button_build, button_none, BUILD_MENU_CLEAR_LAND, 0, 1}, + {113, 277, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 12, button_build, button_none, BUILD_MENU_ROAD, 0, 1}, + {13, 313, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 4, button_build, button_none, BUILD_MENU_WATER, 0, 1}, + {63, 313, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 40, button_build, button_none, BUILD_MENU_HEALTH, 0, 1, "UI", "Asclepius Button"}, + {113, 313, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 28, button_build, button_none, BUILD_MENU_TEMPLES, 0, 1}, + {13, 349, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 24, button_build, button_none, BUILD_MENU_EDUCATION, 0, 1}, + {63, 349, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 20, button_build, button_none, BUILD_MENU_ENTERTAINMENT, 0, 1}, + {113, 349, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 16, button_build, button_none, BUILD_MENU_ADMINISTRATION, 0, 1}, + {13, 385, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 44, button_build, button_none, BUILD_MENU_ENGINEERING, 0, 1}, + {63, 385, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 36, button_build, button_none, BUILD_MENU_SECURITY, 0, 1}, + {113, 385, 39, 26, IB_BUILD, GROUP_SIDEBAR_BUTTONS, 32, button_build, button_none, BUILD_MENU_INDUSTRY, 0, 1}, + {13, 421, 39, 26, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 48, button_undo, button_none, 0, 0, 1}, + {63, 421, 39, 26, IB_NORMAL, GROUP_MESSAGE_ICON, 18, button_messages, button_help, 0, MESSAGE_DIALOG_MESSAGES, 1}, + {113, 421, 39, 26, IB_BUILD, GROUP_MESSAGE_ICON, 22, button_go_to_problem, button_none, 0, 0, 1}, +}; + +static image_button buttons_top_expanded[] = { + {7, 155, 71, 23, IB_NORMAL, GROUP_SIDEBAR_ADVISORS_EMPIRE, 0, button_advisors, button_none, 0, 0, 1}, + {84, 155, 71, 23, IB_NORMAL, GROUP_SIDEBAR_ADVISORS_EMPIRE, 3, button_empire, button_help, 0, MESSAGE_DIALOG_EMPIRE_MAP, 1}, + {7, 184, 33, 22, IB_NORMAL, 0, 0, button_toggle_grid, button_none, 0, 0, 1, "UI", "Toggle Grid Button" }, + {46, 184, 33, 22, IB_NORMAL, GROUP_SIDEBAR_BRIEFING_ROTATE_BUTTONS, 3, button_rotate_north, button_none, 0, 0, 1}, + {84, 184, 33, 22, IB_NORMAL, GROUP_SIDEBAR_BRIEFING_ROTATE_BUTTONS, 6, button_rotate, button_none, 0, 0, 1}, + {123, 184, 33, 22, IB_NORMAL, GROUP_SIDEBAR_BRIEFING_ROTATE_BUTTONS, 9, button_rotate, button_none, 1, 0, 1}, +}; + +static struct { + unsigned int focus_button_for_tooltip; +} data; + +static void draw_overlay_text(const int x_offset) +{ + if (game_state_overlay()) { + const uint8_t *text = get_current_overlay_text(); + text_draw_centered(text, x_offset, 32, 117, FONT_NORMAL_GREEN, 0); + } else { + lang_text_draw_centered(6, 4, x_offset, 32, 117, FONT_NORMAL_GREEN); + } +} + +static void draw_sidebar_remainder(const int x_offset) +{ + const int width = SIDEBAR_EXPANDED_WIDTH; + + const int available_height = sidebar_common_get_height() - SIDEBAR_MAIN_SECTION_HEIGHT; + const int extra_height = sidebar_extra_draw_background(x_offset, SIDEBAR_FILLER_Y_OFFSET, + width, available_height, 0, SIDEBAR_EXTRA_DISPLAY_ALL); + + sidebar_extra_draw_foreground(); + + const int relief_y_offset = SIDEBAR_FILLER_Y_OFFSET + extra_height; + sidebar_common_draw_relief(x_offset, relief_y_offset, GROUP_SIDE_PANEL, 0, 0); +} + +static void draw_number_of_messages(const int x_offset) +{ + const int messages = city_message_count(); + const int show_messages = game_campaign_is_original() || messages > 0 || scenario_intro_message(); + buttons_build_expanded[13].enabled = show_messages; + buttons_build_expanded[14].enabled = city_message_problem_area_count(); + if (show_messages) { + const int width = text_get_number_width(messages, '@', "", FONT_SMALL_PLAIN); + text_draw_number(messages, '@', "", (x_offset + 100) - width, 452, FONT_SMALL_PLAIN, COLOR_BLACK); //top + text_draw_number(messages, '@', "", (x_offset + 100) - width, 454, FONT_SMALL_PLAIN, COLOR_BLACK); //bottom + text_draw_number(messages, '@', "", (x_offset + 99) - width, 453, FONT_SMALL_PLAIN, COLOR_BLACK); //left + text_draw_number(messages, '@', "", (x_offset + 101) - width, 453, FONT_SMALL_PLAIN, COLOR_BLACK); //right + text_draw_number(messages, '@', "", (x_offset + 100) - width, 453, FONT_SMALL_PLAIN, COLOR_WHITE); + } +} + +static void draw_buttons_expanded(const int x_offset) +{ + buttons_build_expanded[12].enabled = game_can_undo(); + image_buttons_draw(x_offset, 24, buttons_overlays_collapse_sidebar, 2); + image_buttons_draw(x_offset, 24, buttons_build_expanded, 15); + image_buttons_draw(x_offset, 24, buttons_top_expanded, 6); +} + +static void enable_building_buttons(void) +{ + for (int i = 0; i < 12; i++) { + buttons_build_expanded[i].enabled = 1; + if (building_menu_count_items(buttons_build_expanded[i].parameter1) <= 0) { + buttons_build_expanded[i].enabled = 0; + } + } +} + +int expanded_sidebar_width(void) +{ + return SIDEBAR_EXPANDED_WIDTH; +} + +int calculate_x_offset_sidebar_expanded(void) +{ + return screen_width() - SIDEBAR_EXPANDED_WIDTH; +} + +void draw_expanded_sidebar_background(const int x_offset) +{ + image_draw(image_group(GROUP_SIDE_PANEL) + 1, x_offset, 24, COLOR_MASK_NONE, SCALE_NONE); + draw_buttons_expanded(x_offset); + draw_overlay_text(x_offset + 4); + draw_number_of_messages(x_offset); + image_draw(window_build_menu_image(), x_offset + 6, 239, COLOR_MASK_NONE, SCALE_NONE); + widget_minimap_update(0); + widget_minimap_draw_decorated(x_offset + 8, MINIMAP_Y_OFFSET, MINIMAP_WIDTH, MINIMAP_HEIGHT); + + draw_sidebar_remainder(x_offset); +} + +void draw_expanded_sidebar_foreground(void) +{ + if (building_menu_has_changed()) { + enable_building_buttons(); + } + + const int x_offset = calculate_x_offset_sidebar_expanded(); + draw_buttons_expanded(x_offset); + draw_overlay_text(x_offset + 4); + widget_minimap_draw_decorated(x_offset + 8, MINIMAP_Y_OFFSET, MINIMAP_WIDTH, MINIMAP_HEIGHT); + draw_number_of_messages(x_offset); + + sidebar_extra_draw_foreground(); +} + +int handle_expanded_sidebar_mouse(const mouse *m) +{ + if (widget_city_has_input()) { + return 0; + } + int handled = 0; + unsigned int button_id; + data.focus_button_for_tooltip = 0; + + if (widget_minimap_handle_mouse(m)) { + return 1; + } + + const int x_offset = calculate_x_offset_sidebar_expanded(); + handled |= image_buttons_handle_mouse(m, x_offset, 24, buttons_overlays_collapse_sidebar, 2, &button_id); + if (button_id) { + data.focus_button_for_tooltip = button_id + 9; + } + handled |= image_buttons_handle_mouse(m, x_offset, 24, buttons_build_expanded, 15, &button_id); + if (button_id) { + data.focus_button_for_tooltip = button_id + 19; + } + handled |= image_buttons_handle_mouse(m, x_offset, 24, buttons_top_expanded, 6, &button_id); + if (button_id) { + data.focus_button_for_tooltip = button_id + 39; + } + handled |= sidebar_extra_handle_mouse(m); + + return handled; +} + +int handle_expanded_sidebar_mouse_build_menu(const mouse *m) +{ + return image_buttons_handle_mouse(m, + calculate_x_offset_sidebar_expanded(), 24, buttons_build_expanded, 15, 0); +} + +unsigned int get_expanded_sidebar_tooltip_text(tooltip_context *c) +{ + if (data.focus_button_for_tooltip) { + if (data.focus_button_for_tooltip == 42) { + c->translation_key = TR_TOGGLE_GRID; + return 0; + } + return data.focus_button_for_tooltip; + } + return sidebar_extra_get_tooltip(c); +} + +static void button_overlay_click(int param1, int param2) +{ + window_overlay_menu_show(); +} + +static void button_collapse(int param1, int param2) +{ + sidebar_next(); +} + +static void button_build(const int submenu, int param2) +{ + window_build_menu_show(submenu); +} + +static void button_undo(int param1, int param2) +{ + window_build_menu_hide(); + game_undo_perform(); + window_invalidate(); +} + +static void button_messages(int param1, int param2) +{ + window_build_menu_hide(); + window_message_list_show(); +} + +static void button_help(int param1, const int param2) +{ + window_build_menu_hide(); + window_message_dialog_show(param2, window_city_draw_all); +} + +static void button_go_to_problem(int param1, int param2) +{ + window_build_menu_hide(); + const int grid_offset = city_message_next_problem_area_grid_offset(); + if (grid_offset) { + city_view_go_to_grid_offset(grid_offset); + window_city_show(); + } else { + window_invalidate(); + } +} + +static void button_advisors(int param1, int param2) +{ + window_advisors_show_checked(); +} + +static void button_empire(int param1, int param2) +{ + window_empire_show_checked(); +} + +static void button_toggle_grid(int param1, int param2) +{ + config_set(CONFIG_UI_SHOW_GRID, config_get(CONFIG_UI_SHOW_GRID) ^ 1); +} + +static void button_rotate_north(int param1, int param2) +{ + game_orientation_rotate_north(); + window_invalidate(); +} + +static void button_rotate(const int clockwise, int param2) +{ + if (clockwise) { + game_orientation_rotate_right(); + } else { + game_orientation_rotate_left(); + } + window_invalidate(); +} diff --git a/src/widget/sidebar/expanded/sidebar.h b/src/widget/sidebar/expanded/sidebar.h new file mode 100644 index 0000000000..e8b0d7b1e2 --- /dev/null +++ b/src/widget/sidebar/expanded/sidebar.h @@ -0,0 +1,19 @@ +#ifndef WIDGET_EXPANDED_SIDEBAR +#define WIDGET_EXPANDED_SIDEBAR + +#include "graphics/tooltip.h" +#include "input/mouse.h" + +int expanded_sidebar_width(void); + +void draw_expanded_sidebar_background(int x_offset); +void draw_expanded_sidebar_foreground(void); + +int handle_expanded_sidebar_mouse(const mouse *m); +int handle_expanded_sidebar_mouse_build_menu( const mouse *m); + +int calculate_x_offset_sidebar_expanded(void); + +unsigned int get_expanded_sidebar_tooltip_text(tooltip_context *c); + +#endif // WIDGET_EXPANDED_SIDEBAR diff --git a/src/widget/sidebar/military.c b/src/widget/sidebar/military.c index aabf7fae87..37f4b37d86 100644 --- a/src/widget/sidebar/military.c +++ b/src/widget/sidebar/military.c @@ -24,6 +24,8 @@ #include "widget/sidebar/extra.h" #include "widget/sidebar/slide.h" #include "window/building/military.h" + +#include "expanded/sidebar.h" #include "window/city.h" #include "window/military_menu.h" @@ -36,7 +38,8 @@ #define Y_OFFSET_BOTTOM_BUTTONS 257 #define MILITARY_PANEL_BLOCKS 18 #define CONTENT_PADDING 10 -#define CONTENT_WIDTH (SIDEBAR_EXPANDED_WIDTH - 2 * CONTENT_PADDING) +#define PANEL_WIDTH 162 +#define CONTENT_WIDTH (PANEL_WIDTH - 2 * CONTENT_PADDING) static const int IMAGE_OFFSETS_TO_FORMATION[7] = { FORMATION_COLUMN, @@ -372,11 +375,11 @@ static void draw_military_panel_background(int x_offset) { graphics_draw_line(x_offset, x_offset, Y_OFFSET_PANEL_START, Y_OFFSET_PANEL_START + MILITARY_PANEL_BLOCKS * BLOCK_SIZE, COLOR_WHITE); - graphics_draw_line(x_offset + SIDEBAR_EXPANDED_WIDTH - 1, x_offset + SIDEBAR_EXPANDED_WIDTH - 1, + graphics_draw_line(x_offset + PANEL_WIDTH - 1, x_offset + PANEL_WIDTH - 1, Y_OFFSET_PANEL_START, Y_OFFSET_PANEL_START + MILITARY_PANEL_BLOCKS * BLOCK_SIZE, COLOR_SIDEBAR); inner_panel_draw(x_offset + 1, Y_OFFSET_PANEL_START + 10, - SIDEBAR_EXPANDED_WIDTH / BLOCK_SIZE, MILITARY_PANEL_BLOCKS); - inner_panel_draw(x_offset + 1, Y_OFFSET_PANEL_START, SIDEBAR_EXPANDED_WIDTH / BLOCK_SIZE, 1); + PANEL_WIDTH / BLOCK_SIZE, MILITARY_PANEL_BLOCKS); + inner_panel_draw(x_offset + 1, Y_OFFSET_PANEL_START, PANEL_WIDTH / BLOCK_SIZE, 1); draw_military_info_text(x_offset + CONTENT_PADDING, Y_OFFSET_PANEL_START); draw_military_info_buttons(x_offset, Y_OFFSET_PANEL_START); @@ -409,16 +412,17 @@ static void draw_background(int x_offset) draw_military_panel_background(x_offset); draw_legion_buttons(x_offset, Y_OFFSET_PANEL_START); int extra_height = sidebar_extra_draw_background(x_offset, MILITARY_PANEL_HEIGHT, - SIDEBAR_EXPANDED_WIDTH, sidebar_common_get_height() - MILITARY_PANEL_HEIGHT + TOP_MENU_HEIGHT, + PANEL_WIDTH, sidebar_common_get_height() - MILITARY_PANEL_HEIGHT + TOP_MENU_HEIGHT, 0, SIDEBAR_EXTRA_DISPLAY_ALL); sidebar_extra_draw_foreground(); - sidebar_common_draw_relief(x_offset, MILITARY_PANEL_HEIGHT + extra_height, GROUP_SIDE_PANEL, 0); + sidebar_common_draw_relief(x_offset, MILITARY_PANEL_HEIGHT + extra_height, GROUP_SIDE_PANEL, 0, 0); } void widget_sidebar_military_draw_background(void) { - draw_background(sidebar_common_get_x_offset_expanded()); + // todo: this need to change + draw_background(calculate_x_offset_sidebar_expanded()); } static int has_legion_changed(const legion_info *legion, const formation *m) @@ -451,7 +455,8 @@ static void draw_foreground(int x_offset) void widget_sidebar_military_draw_foreground(void) { - draw_foreground(sidebar_common_get_x_offset_expanded()); + // todo: this need to change + draw_foreground(calculate_x_offset_sidebar_expanded()); } static void draw_sliding(int x_offset) @@ -462,7 +467,8 @@ static void draw_sliding(int x_offset) int widget_sidebar_military_handle_input(const mouse *m) { - int x_offset = sidebar_common_get_x_offset_expanded(); + // todo: this need to change + const int x_offset = calculate_x_offset_sidebar_expanded(); if (image_buttons_handle_mouse(m, x_offset, 24, buttons_title_close, 2, &data.top_buttons_focus_id)) { return 1; } @@ -486,7 +492,7 @@ int widget_sidebar_military_handle_input(const mouse *m) return sidebar_extra_handle_mouse(m); } -static int get_layout_text_id(int layout) +static int get_layout_text_id(const int layout) { switch (layout) { case FORMATION_SINGLE_LINE_1: @@ -575,10 +581,12 @@ int widget_sidebar_military_enter(int formation_id) if (had_selected_legions) { return 0; } - data.city_view_was_collapsed = city_view_is_sidebar_collapsed(); - if (data.city_view_was_collapsed) { - city_view_start_sidebar_toggle(); - sidebar_slide(SLIDE_DIRECTION_IN, widget_sidebar_city_draw_background, draw_sliding, slide_in_finished); + + if (widget_sidebar_is_collapsed()) { + sidebar_next(); + //todo: something need to change here + // 0,0 is WRONG -> Temp value CHANGE todo + sidebar_slide(SLIDE_DIRECTION_IN, widget_sidebar_city_draw_background, draw_sliding, slide_in_finished,0 , 0); } else { slide_in_finished(); } @@ -592,9 +600,12 @@ int widget_sidebar_military_exit(void) widget_minimap_invalidate(); return 0; } + + //todo: something need to change here + // 0,0 is WRONG -> Temp value CHANGE todo if (data.city_view_was_collapsed) { city_view_toggle_sidebar(); - sidebar_slide(SLIDE_DIRECTION_OUT, widget_sidebar_city_draw_background, draw_sliding, slide_out_finished); + sidebar_slide(SLIDE_DIRECTION_OUT, widget_sidebar_city_draw_background, draw_sliding, slide_out_finished,0,0); } else { slide_out_finished(); } diff --git a/src/widget/sidebar/slide.c b/src/widget/sidebar/slide.c index b264ff4291..aa0d5b0f66 100644 --- a/src/widget/sidebar/slide.c +++ b/src/widget/sidebar/slide.c @@ -1,5 +1,6 @@ #include "slide.h" +#include "city.h" #include "core/speed.h" #include "graphics/graphics.h" #include "graphics/menu.h" @@ -15,6 +16,8 @@ static struct { int position; + int previous_sidebar_width; + int previous_sidebar_x_offset; speed_type slide_speed; slide_direction direction; back_sidebar_draw_function back_sidebar_draw; @@ -33,19 +36,20 @@ static void draw_sliding_foreground(void) window_request_refresh(); data.position += speed_get_delta(&data.slide_speed); int is_finished = 0; - if (data.position >= SIDEBAR_EXPANDED_WIDTH) { - data.position = SIDEBAR_EXPANDED_WIDTH; + const int sidebar_width = data.previous_sidebar_width; + if (data.position >= sidebar_width) { + data.position = sidebar_width; is_finished = 1; } - int x_offset = sidebar_common_get_x_offset_expanded(); - graphics_set_clip_rectangle(x_offset, TOP_MENU_HEIGHT, SIDEBAR_EXPANDED_WIDTH, sidebar_common_get_height()); + int x_offset = data.previous_sidebar_x_offset; + graphics_set_clip_rectangle(x_offset, TOP_MENU_HEIGHT, sidebar_width, sidebar_common_get_height()); if (data.direction == SLIDE_DIRECTION_IN) { if (data.position > SIDEBAR_DECELERATION_OFFSET) { speed_set_target(&data.slide_speed, 1, SLIDE_ACCELERATION_MILLIS, 1); } - x_offset += SIDEBAR_EXPANDED_WIDTH - data.position; + x_offset += sidebar_width - data.position; } else { x_offset += data.position; } @@ -60,17 +64,21 @@ static void draw_sliding_foreground(void) } } -void sidebar_slide(slide_direction direction, back_sidebar_draw_function back_sidebar_callback, - front_sidebar_draw_function front_sidebar_callback, slide_finished_function finished_callback) +void sidebar_slide(const slide_direction direction, const back_sidebar_draw_function back_sidebar_callback, + const front_sidebar_draw_function front_sidebar_callback, const slide_finished_function finished_callback, + const int previous_sidebar_width, const int previous_sidebar_x_offset) { data.direction = direction; data.position = 0; speed_clear(&data.slide_speed); - speed_set_target(&data.slide_speed, SLIDE_SPEED, - direction == SLIDE_DIRECTION_OUT ? SLIDE_ACCELERATION_MILLIS : SPEED_CHANGE_IMMEDIATE, 1); + speed_set_target(&data.slide_speed, SLIDE_SPEED,SLIDE_ACCELERATION_MILLIS, 1); + //direction == SLIDE_DIRECTION_OUT ? SLIDE_ACCELERATION_MILLIS : SPEED_CHANGE_IMMEDIATE, 1); + // todo fix?? data.back_sidebar_draw = back_sidebar_callback; data.front_sidebar_draw = front_sidebar_callback; data.finished_callback = finished_callback; + data.previous_sidebar_x_offset = previous_sidebar_x_offset; + data.previous_sidebar_width = previous_sidebar_width; sound_effect_play(SOUND_EFFECT_SIDEBAR); window_type window = { diff --git a/src/widget/sidebar/slide.h b/src/widget/sidebar/slide.h index c234f32e20..34755a6e39 100644 --- a/src/widget/sidebar/slide.h +++ b/src/widget/sidebar/slide.h @@ -11,6 +11,7 @@ typedef back_sidebar_draw_function slide_finished_function; typedef void (*front_sidebar_draw_function)(int x_offset); void sidebar_slide(slide_direction direction, back_sidebar_draw_function back_sidebar_callback, - front_sidebar_draw_function front_sidebar_callback, slide_finished_function finished_callback); + front_sidebar_draw_function front_sidebar_callback, slide_finished_function finished_callback, + int previous_sidebar_width, int previous_sidebar_x_offset); #endif // WIDGET_SIDEBAR_SLIDE_H diff --git a/src/window/city.c b/src/window/city.c index 9e168894fc..b3992c02cb 100644 --- a/src/window/city.c +++ b/src/window/city.c @@ -74,6 +74,7 @@ static void draw_background(void) if (window_is(WINDOW_CITY)) { widget_city_setup_routing_preview(); } + widget_sidebar_city_draw_background(); widget_top_menu_draw(1); } @@ -269,7 +270,9 @@ static void draw_foreground(void) { widget_top_menu_draw(0); window_city_draw(); + widget_sidebar_city_draw_foreground(); + draw_speedrun_info(); if (window_is(WINDOW_CITY) || window_is(WINDOW_CITY_MILITARY)) { draw_time_left(); @@ -296,6 +299,7 @@ static void draw_foreground_military(void) } draw_time_left(); widget_city_draw_construction_buttons(); + if (!mouse_get()->is_touch || sidebar_extra_is_information_displayed(SIDEBAR_EXTRA_DISPLAY_GAME_SPEED)) { draw_paused_banner(); } @@ -831,6 +835,7 @@ static void handle_input(const mouse *m, const hotkeys *h) if (widget_top_menu_handle_input(m, h)) { return; } + if (widget_sidebar_city_handle_mouse(m)) { return; } @@ -844,6 +849,7 @@ static void handle_input_military(const mouse *m, const hotkeys *h) if (widget_top_menu_handle_input(m, h)) { return; } + if (config_get(CONFIG_UI_SHOW_MILITARY_SIDEBAR) && widget_sidebar_military_handle_input(m)) { return; } @@ -911,6 +917,7 @@ void window_city_show(void) show_roamers_for_overlay(game_state_overlay()); if (formation_get_selected()) { formation_set_selected(0); + if (config_get(CONFIG_UI_SHOW_MILITARY_SIDEBAR) && widget_sidebar_military_exit()) { return; } @@ -932,6 +939,7 @@ void window_city_military_show(int legion_formation_id) building_construction_clear_type(); } formation_set_selected(legion_formation_id); + if (config_get(CONFIG_UI_SHOW_MILITARY_SIDEBAR) && widget_sidebar_military_enter(legion_formation_id)) { return; } diff --git a/src/window/main_menu.c b/src/window/main_menu.c index b0eca2a7b3..6f1ad59c5e 100644 --- a/src/window/main_menu.c +++ b/src/window/main_menu.c @@ -71,6 +71,7 @@ static void draw_background(void) if (!window_is(WINDOW_FILE_DIALOG)) { graphics_in_dialog(); + outer_panel_draw(162, 32, 20, 22); if (!data.logo_image_id) { data.logo_image_id = assets_get_image_id("UI", "Main Menu Banner");