summaryrefslogtreecommitdiff
path: root/src/scenes
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-12-05 09:45:01 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-12-05 09:45:01 +0100
commit190760b05d943e065cad31a0b983ef7736551feb (patch)
treeaa3486120175a0e2e98d5cabe84ea56e60ca9f58 /src/scenes
parentc1da2426711a4a5e73a46f2cca923df2dc43579a (diff)
close #53, close #52
Diffstat (limited to 'src/scenes')
-rw-r--r--src/scenes/place_detail.c149
1 files changed, 141 insertions, 8 deletions
diff --git a/src/scenes/place_detail.c b/src/scenes/place_detail.c
index 64d1056..d24d449 100644
--- a/src/scenes/place_detail.c
+++ b/src/scenes/place_detail.c
@@ -975,8 +975,9 @@ static bool scheduling_job_is_correct()
return true;
}
-static void draw_duration_of_scheduled_job_entry(scheduled_job job, scheduled_job_time scheduled_time, s32 hour_w, s32 tx, s32 ty, s32 timeslot_w, s32 x, s32 y, s32 timeslot_h, color tile_color)
+static scheduled_job_time draw_duration_of_scheduled_job_entry(scheduled_job job, scheduled_job_time scheduled_time, s32 hour_w, s32 tx, s32 ty, s32 timeslot_w, s32 x, s32 y, s32 timeslot_h, color tile_color, bool do_draw)
{
+ scheduled_job_time result = scheduled_time;
#define TILE_X(_x) (x+hour_w+(timeslot_w*_x)+1)
#define TILE_Y(_y) (y+(timeslot_h*(CDAYTORDAY(_y)))+1)
@@ -994,7 +995,7 @@ static void draw_duration_of_scheduled_job_entry(scheduled_job job, scheduled_jo
s32 highlight_w = timeslot_w*duration_of_job_measured_in_timeslots_max;
if (tx+highlight_w > x+(timeslot_w*(TIME_SLOTS_PER_DAY+TIME_SLOTS_PER_HOUR)))
highlight_w -= (tx+highlight_w) - (x+(timeslot_w*(TIME_SLOTS_PER_DAY+TIME_SLOTS_PER_HOUR)));
- renderer->render_rectangle(tx, ty, highlight_w, timeslot_h, tile_color_bg);
+ if (do_draw) renderer->render_rectangle(tx, ty, highlight_w, timeslot_h, tile_color_bg);
s32 highlight_y = ty+timeslot_h;
if (scheduled_time.day == SUNDAY) highlight_y = TILE_Y(MONDAY);
@@ -1015,13 +1016,75 @@ static void draw_duration_of_scheduled_job_entry(scheduled_job job, scheduled_jo
}
//printf("%d %d %d\n", overflow_to_next_day, extra_days, overflow);
- renderer->render_rectangle(TILE_X(0), highlight_y, timeslot_w*overflow, timeslot_h, tile_color_bg);
+ if (do_draw) renderer->render_rectangle(TILE_X(0), highlight_y, timeslot_w*overflow, timeslot_h, tile_color_bg);
overflow_to_next_day -= TIME_SLOTS_PER_DAY;
- highlight_y += timeslot_h;
curr_day++;
if (curr_day == 7) curr_day = 0;
+
+ if (overflow_to_next_day <= 0) {
+ if (scheduled_time.stay_at_destination) {
+ if (do_draw) {
+ renderer->render_rectangle(TILE_X(0) + timeslot_w*overflow - timeslot_w, highlight_y, timeslot_w, timeslot_h, COLOR_SCHEDULE_TILE_EXIT);
+ renderer->set_render_depth(5);
+ renderer->render_image(img_exit, TILE_X(0) + timeslot_w*overflow - timeslot_w + timeslot_w*1.5f, highlight_y+(timeslot_h/4), timeslot_h/2, timeslot_h/2);
+ renderer->set_render_depth(4);
+ }
+ }
+ }
+ highlight_y += timeslot_h;
+
+ result.day = curr_day;
+ result.timeslot = overflow;
+ }
+ }
+ else {
+ result.timeslot += duration_of_job_measured_in_timeslots_max;
+
+ if (scheduled_time.stay_at_destination) {
+ if (do_draw) {
+ renderer->render_rectangle(tx + highlight_w - timeslot_w, ty, timeslot_w, timeslot_h, COLOR_SCHEDULE_TILE_EXIT);
+ renderer->set_render_depth(5);
+ renderer->render_image(img_exit, tx + highlight_w - timeslot_w + timeslot_w*1.5f, ty+(timeslot_h/4), timeslot_h/2, timeslot_h/2);
+ renderer->set_render_depth(4);
+ }
}
}
+
+
+ return result;
+}
+
+static s32 scheduled_job_times_where_employee_return_to_location(world_location* location_to, employee* emp, scheduled_job_time* buffer, s32 buffer_size)
+{
+ s32 count = 0;
+ for (s32 i = 0; i < _active_world->locations.length; i++)
+ {
+ world_location* location = array_at(&_active_world->locations, i);
+ if (!location->is_owned) continue;
+
+ for (s32 r = 0; r < location->schedule.jobs.length; r++)
+ {
+ scheduled_job* scheduled_job = array_at(&location->schedule.jobs, r);
+ job_endpoints endpoints = job_offer_get_endpoints(&scheduled_job->offer);
+
+ if (endpoints.dest != location_to) continue;
+
+ for (s32 t = 0; t < scheduled_job->offer.shipday_count; t++) {
+ scheduled_job_time scheduled_time = scheduled_job->timeslots[t];
+
+ if (scheduled_time.assignee == emp && scheduled_time.stay_at_destination) {
+
+ scheduled_job_time end_timeslot = draw_duration_of_scheduled_job_entry(*scheduled_job, scheduled_time, 0, 0, 0, 0, 0, 0, 0, rgb(0,0,0), false);
+ //printf("%d %d\n", );
+ buffer[count] = end_timeslot;
+ count++;
+ if (count >= buffer_size) return count;
+ }
+ }
+ }
+ }
+
+ return count;
}
static bool termination_popup_active = false;
@@ -1191,7 +1254,7 @@ static void place_detail_draw_schedule(platform_window* window)
}
// Draw duration of job if dragging.
- draw_duration_of_scheduled_job_entry(_active_scheduling_job, scheduled_time, hour_w, tx, ty, timeslot_w, x, y, timeslot_h, tile_color);
+ draw_duration_of_scheduled_job_entry(_active_scheduling_job, scheduled_time, hour_w, tx, ty, timeslot_w, x, y, timeslot_h, tile_color, true);
// Draw left and right arrow.
s32 icon_s = timeslot_w*0.7f;
@@ -1211,11 +1274,11 @@ static void place_detail_draw_schedule(platform_window* window)
// Highlight duration if selected.
else if (is_selected) {
- draw_duration_of_scheduled_job_entry(_active_scheduling_job, scheduled_time, hour_w, tx, ty, timeslot_w, x, y, timeslot_h, tile_color);
+ draw_duration_of_scheduled_job_entry(_active_scheduling_job, scheduled_time, hour_w, tx, ty, timeslot_w, x, y, timeslot_h, tile_color, true);
}
// Highlight duration if sharing same employee.
else if (scheduled_time.assignee != 0 && scheduled_time.assignee == _active_scheduling_job.timeslots[_active_schedule_selected_job_index].assignee) {
- draw_duration_of_scheduled_job_entry(_active_scheduling_job, scheduled_time, hour_w, tx, ty, timeslot_w, x, y, timeslot_h, tile_color);
+ draw_duration_of_scheduled_job_entry(_active_scheduling_job, scheduled_time, hour_w, tx, ty, timeslot_w, x, y, timeslot_h, tile_color, true);
}
// Draw tile.
@@ -1268,7 +1331,7 @@ static void place_detail_draw_schedule(platform_window* window)
if (scheduled_time.assignee == 0) tc = is_selected ? COLOR_SCHEDULE_TILE_HOVERED : COLOR_SCHEDULE_TILE_INVALID;
if (is_inspecting_employee || is_selected) {
// Draw duration of job.
- draw_duration_of_scheduled_job_entry(*job, scheduled_time, hour_w, tx, ty, timeslot_w, x, y, timeslot_h, tc);
+ draw_duration_of_scheduled_job_entry(*job, scheduled_time, hour_w, tx, ty, timeslot_w, x, y, timeslot_h, tc, true);
}
renderer->render_rectangle(tx, ty, timeslot_w, timeslot_h, tc);
@@ -1332,6 +1395,76 @@ static void place_detail_draw_schedule(platform_window* window)
employee_selector_animation = animation_create(EMPLOYEE_SELECTOR_ANIMATION_DURATION);
employee_selector_animation.started = true;
}
+ }
+ }
+ }
+ }
+
+ // external job re-entries
+ if (_active_schedule_state == SCHEDULING_JOB || _active_schedule_state == RESCHEDULING_JOB) {
+ for (s32 i = _active_scheduling_job.offer.shipday_count-1; i >= 0; i--) {
+ scheduled_job_time scheduled_time = _active_scheduling_job.timeslots[i];
+
+ bool is_selected = _active_schedule_selected_job_index == i;
+ if (!is_selected) continue;
+
+ s32 tx = TILE_X(scheduled_time.timeslot);
+ s32 ty = TILE_Y(scheduled_time.day);
+
+ scheduled_job_time sj = scheduled_time;
+ employee* emp = sj.assignee;
+
+ if (emp) {
+ // find all jobs of employee where they return to current location.
+ scheduled_job_time buffer[10];
+ s32 count = scheduled_job_times_where_employee_return_to_location(_active_location, emp, buffer, 10);
+
+ for (int c = 0; c < count; c++) {
+ scheduled_job_time time = buffer[c];
+ s32 tx = TILE_X(time.timeslot);
+ s32 ty = TILE_Y(time.day);
+
+ renderer->render_rectangle(tx, ty, timeslot_w, timeslot_h, COLOR_SCHEDULE_TILE_ENTRY);
+
+ renderer->set_render_depth(5);
+ renderer->render_image(img_entry, tx - timeslot_w*2, ty+(timeslot_h/4), timeslot_h/2, timeslot_h/2);
+ renderer->set_render_depth(4);
+ }
+ }
+ }
+ }
+
+ for (s32 i = 0; i < _active_location->schedule.jobs.length; i++) {
+ scheduled_job* job = array_at(&_active_location->schedule.jobs, i);
+
+ for (s32 t = 0; t < job->offer.shipday_count; t++) {
+ scheduled_job_time scheduled_time = job->timeslots[t];
+ s32 tx = TILE_X(scheduled_time.timeslot);
+ s32 ty = TILE_Y(scheduled_time.day);
+ bool is_selected_job = (_active_selected_scheduled_job == job);
+ bool is_selected = (is_selected_job && _active_schedule_selected_job_index == t);
+
+ // highlight timeslot where employee returns from external location.
+ if (is_selected_job || is_selected) {
+ scheduled_job_time sj = scheduled_time;
+ employee* emp = sj.assignee;
+
+ if (emp) {
+ // find all jobs of employee where they return to current location.
+ scheduled_job_time buffer[10];
+ s32 count = scheduled_job_times_where_employee_return_to_location(_active_location, emp, buffer, 10);
+
+ for (int c = 0; c < count; c++) {
+ scheduled_job_time time = buffer[c];
+ s32 tx = TILE_X(time.timeslot);
+ s32 ty = TILE_Y(time.day);
+
+ renderer->render_rectangle(tx, ty, timeslot_w, timeslot_h, COLOR_SCHEDULE_TILE_ENTRY);
+
+ renderer->set_render_depth(5);
+ renderer->render_image(img_entry, tx - timeslot_w*2, ty+(timeslot_h/4), timeslot_h/2, timeslot_h/2);
+ renderer->set_render_depth(4);
+ }
}
}
}