From 395aa3f2b53550b9575dde1f5d2fb7494c21addf Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Thu, 5 Dec 2024 13:17:27 +0100 Subject: close #55 --- data/img/reload.png | Bin 0 -> 2910 bytes data/world/locations.json | 6 ------ src/data.c | 1 + src/include/data.h | 1 + src/include/ui/selectors.h | 2 +- src/include/world.h | 1 + src/scenes/place_detail.c | 4 ++-- src/ui/selectors.c | 19 ++++++++++++++----- src/world.c | 19 +++++++++++++++++++ 9 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 data/img/reload.png diff --git a/data/img/reload.png b/data/img/reload.png new file mode 100644 index 0000000..181053e Binary files /dev/null and b/data/img/reload.png differ diff --git a/data/world/locations.json b/data/world/locations.json index 4b2290c..adbe44d 100644 --- a/data/world/locations.json +++ b/data/world/locations.json @@ -245,12 +245,6 @@ "name": "Birmingham", "size": 1 }, - { - "latitude": 32.862217, - "longitude": -91.175179, - "name": "Nashville", - "size": 1 - }, { "latitude": 36.162640, "longitude": -79.470184, diff --git a/src/data.c b/src/data.c index 4eaf7f5..0d3f0bc 100644 --- a/src/data.c +++ b/src/data.c @@ -62,6 +62,7 @@ void data_load() img_resume_action = assets_load_image_from_file("data/img/resume_action.png"); img_entry = assets_load_image_from_file("data/img/entry.png"); + img_refresh = assets_load_image_from_file("data/img/reload.png"); img_exit = assets_load_image_from_file("data/img/exit.png"); img_panel_bottom = assets_load_image_from_file("data/img/panel_bottom.png"); diff --git a/src/include/data.h b/src/include/data.h index cddce51..b10f0c0 100644 --- a/src/include/data.h +++ b/src/include/data.h @@ -64,6 +64,7 @@ image* img_handshake; image* img_resume_action; image* img_entry; image* img_exit; +image* img_refresh; image* img_button_bottom; image* img_button_top; diff --git a/src/include/ui/selectors.h b/src/include/ui/selectors.h index 6832ff7..200d61b 100644 --- a/src/include/ui/selectors.h +++ b/src/include/ui/selectors.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_EMPLOYEE_SELECTOR #define INCLUDE_EMPLOYEE_SELECTOR -employee* employee_selector_render(platform_window* window, float scale, bool enabled, employee* current_val, s32 x, s32 y, s32 w, s32 h, animation an, scheduled_job* offer); +employee* employee_selector_render(platform_window* window, float scale, bool enabled, employee* current_val, s32 x, s32 y, s32 w, s32 h, animation an, scheduled_job* offer, world_location* loc); world_location* location_selector_render(platform_window* window, float scale, bool enabled, world_location* current_val, s32 x, s32 y, s32 w, s32 h); #endif \ No newline at end of file diff --git a/src/include/world.h b/src/include/world.h index 4407fcb..b11f43c 100644 --- a/src/include/world.h +++ b/src/include/world.h @@ -401,6 +401,7 @@ typedef struct t_world struct tm current_time; } world; +employee* world_get_most_available_employee_for_location(world* world, world_location* loc); world* world_create_new(bool create_default_state); void world_report_event(world* world, char* msg, event_type type, void* data); world_location* get_world_location_by_id(world* world, s32 id); diff --git a/src/scenes/place_detail.c b/src/scenes/place_detail.c index d24d449..f3e1223 100644 --- a/src/scenes/place_detail.c +++ b/src/scenes/place_detail.c @@ -685,7 +685,7 @@ void place_detail_show_employee_detail(employee* emp) { s32 location_id_to_inspect; if (_active_location == 0 || (_active_location->id != emp->current_location_id && _active_location->id != emp->original_location_id)) { - s32 location_id_to_inspect = emp->current_location_id; + location_id_to_inspect = emp->current_location_id; if (location_id_to_inspect == INVALID_ID) { location_id_to_inspect = emp->original_location_id; } @@ -960,7 +960,7 @@ static void place_detail_draw_schedule_employee_selector(platform_window* window } _active_scheduling_job.timeslots[_active_schedule_selected_job_index].assignee = - employee_selector_render(window, scale, !is_viewing_existing_timeslot, selected_employee,x,y,w,h, employee_selector_animation, &_active_scheduling_job); + employee_selector_render(window, scale, !is_viewing_existing_timeslot, selected_employee,x,y,w,h, employee_selector_animation, &_active_scheduling_job, _active_location); animation_update(&employee_selector_animation); } } diff --git a/src/ui/selectors.c b/src/ui/selectors.c index 7d55b98..ab4944d 100644 --- a/src/ui/selectors.c +++ b/src/ui/selectors.c @@ -1,5 +1,5 @@ -employee* employee_selector_render(platform_window* window, float scale, bool enabled, employee* current_val, s32 x, s32 y, s32 w, s32 h, animation an, scheduled_job* offer) { +employee* employee_selector_render(platform_window* window, float scale, bool enabled, employee* current_val, s32 x, s32 y, s32 w, s32 h, animation an, scheduled_job* offer, world_location* loc) { #define ANIMATION_OFFSET (-30*scale) color text_color = AN_LI_TINT(COLOR_TEXT, an); color c_tb_tint = AN_LI_TINT(COLOR_TEXTBOX_TINT, an); @@ -80,18 +80,27 @@ employee* employee_selector_render(platform_window* window, float scale, bool en } s32 status_s = tb_height/2; - s32 status_x = tb_x + tb_width - (status_s/4*3); - s32 status_y = tb_y - (status_s/4); + s32 status_x = tb_x + tb_width; + s32 status_y = tb_y; button_draw_background(scale,status_x,status_y,status_s,status_s,c_white,c_btn); s32 status_icon_s = status_s*0.5f; s32 status_icon_offset = (status_s - status_icon_s)/2; renderer->render_image_tint(result ? img_checkmark : img_questionmark, status_x+status_icon_offset, status_y+status_icon_offset, status_icon_s, status_icon_s, result ? c_correct : c_wrong); + + if (enabled) { + if (button_render(scale, BUTTON_ENABLED, 0, status_x,status_y+tb_height-status_s,status_s,status_s)) { + result = world_get_most_available_employee_for_location(_active_world, loc); + } + + renderer->render_image(img_refresh, status_x+status_icon_offset, status_y+tb_height-status_s+status_icon_offset, + status_icon_s, status_icon_s); + } } // Draw employee data if (result) { - s32 por_x = tb_x + tb_width + tb_pad; + s32 por_x = tb_x + tb_width + tb_pad + 20*scale; draw_employee_portrait(result, por_x, tb_y, tb_height, tb_height); s32 text_x = por_x + tb_height + tb_pad; @@ -128,7 +137,7 @@ employee* employee_selector_render(platform_window* window, float scale, bool en color c = COLOR_TEXT; if (overworked) c = COLOR_TEXT_NEGATIVE; char txt_status[50]; - sprintf(txt_status, "Currently scheduled for %.0fh/week", total_hours); + sprintf(txt_status, "Scheduled for %.0fh/week", total_hours); renderer->render_text(fnt_s,text_x,tb_y,txt_status,c); } diff --git a/src/world.c b/src/world.c index bd04a52..a19e924 100644 --- a/src/world.c +++ b/src/world.c @@ -12,6 +12,7 @@ static void end_contract_with_employee(world* world, employee* emp); vec2f px_to_coords(platform_window* window, double x, double y); static bool world_check_location_accessibility(world_location* orig, world_location* source, int depth, double dist); static void world_update_location_scores(world* world); +static float get_worked_hours_per_week_for_employee(world* world, employee* emp, scheduled_job* excluding); float dotsize = 5; @@ -1010,6 +1011,24 @@ static float get_shiptime_factor(employee* emp) return shiptime_factor; } +employee* world_get_most_available_employee_for_location(world* world, world_location* loc) +{ + float best_match_hours = 99999.0f; + employee* best_match = 0; + for (s32 i = 0; i < loc->employees.length; i++) + { + employee* em = *(employee**)array_at(&loc->employees, i); + if (em->assigned_truck == 0) continue; + float hours_worked = get_worked_hours_per_week_for_employee(world, em, 0); + if (hours_worked < best_match_hours) { + best_match_hours = hours_worked; + best_match = em; + } + } + + return best_match; +} + static void world_start_scheduled_job(world* world, scheduled_job* scheduled_job, scheduled_job_time scheduled_time) { if (!scheduled_time.assignee) { -- cgit v1.2.3-70-g09d2