summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-12-05 13:17:27 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-12-05 13:17:27 +0100
commit395aa3f2b53550b9575dde1f5d2fb7494c21addf (patch)
tree478f5609bd86d9de085d684c374971b6ce913f6a /src
parent0974ff30789a215a31255080251c01eaaf9a5297 (diff)
close #55
Diffstat (limited to 'src')
-rw-r--r--src/data.c1
-rw-r--r--src/include/data.h1
-rw-r--r--src/include/ui/selectors.h2
-rw-r--r--src/include/world.h1
-rw-r--r--src/scenes/place_detail.c4
-rw-r--r--src/ui/selectors.c19
-rw-r--r--src/world.c19
7 files changed, 39 insertions, 8 deletions
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) {