Update orders window when renaming/removing dispatch schedule

pull/519/head
Jonathan G Rennison 1 year ago
parent 2abdd27d02
commit c4fc71339a

@ -1378,7 +1378,7 @@ enum {
*
* For vehicles of other companies, both button rows are not displayed.
*/
struct OrdersWindow : public Window {
struct OrdersWindow : public GeneralVehicleWindow {
private:
/** Under what reason are we using the PlaceObject functionality? */
enum OrderPlaceObjectState {
@ -1462,7 +1462,6 @@ private:
int selected_order;
VehicleOrderID order_over; ///< Order over which another order is dragged, \c INVALID_VEH_ORDER_ID if none.
OrderPlaceObjectState goto_type;
const Vehicle *vehicle; ///< Vehicle owning the orders being displayed and manipulated.
Scrollbar *vscroll;
bool can_do_refit; ///< Vehicle chain can be refitted in depot.
bool can_do_autorefit; ///< Vehicle chain can be auto-refitted.
@ -1812,10 +1811,8 @@ private:
}
public:
OrdersWindow(WindowDesc *desc, const Vehicle *v) : Window(desc)
OrdersWindow(WindowDesc *desc, const Vehicle *v) : GeneralVehicleWindow(desc, v)
{
this->vehicle = v;
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
this->GetWidget<NWidgetStacked>(WID_O_SEL_OCCUPANCY)->SetDisplayedPlane(_settings_client.gui.show_order_occupancy_by_default ? 0 : SZSP_NONE);

@ -55,7 +55,7 @@ CommandCost CmdScheduledDispatch(TileIndex tile, DoCommandFlag flags, uint32 p1,
ClrBit(v2->vehicle_flags, VF_SCHEDULED_DISPATCH);
}
}
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();
@ -101,7 +101,7 @@ CommandCost CmdScheduledDispatchAdd(TileIndex tile, DoCommandFlag flags, uint32
if (p2 >= ds.GetScheduledDispatchDuration()) p2 -= ds.GetScheduledDispatchDuration();
ds.AddScheduledDispatch(p2);
}
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();
@ -133,7 +133,7 @@ CommandCost CmdScheduledDispatchRemove(TileIndex tile, DoCommandFlag flags, uint
if (flags & DC_EXEC) {
v->orders->GetDispatchScheduleByIndex(schedule_index).RemoveScheduledDispatch(p2);
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();
@ -168,7 +168,7 @@ CommandCost CmdScheduledDispatchSetDuration(TileIndex tile, DoCommandFlag flags,
DispatchSchedule &ds = v->orders->GetDispatchScheduleByIndex(schedule_index);
ds.SetScheduledDispatchDuration(p2);
ds.UpdateScheduledDispatch(nullptr);
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();
@ -208,7 +208,7 @@ CommandCost CmdScheduledDispatchSetStartDate(TileIndex tile, DoCommandFlag flags
DispatchSchedule &ds = v->orders->GetDispatchScheduleByIndex(schedule_index);
ds.SetScheduledDispatchStartDate(date, full_date_fract);
ds.UpdateScheduledDispatch(nullptr);
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();
@ -241,7 +241,7 @@ CommandCost CmdScheduledDispatchSetDelay(TileIndex tile, DoCommandFlag flags, ui
if (flags & DC_EXEC) {
v->orders->GetDispatchScheduleByIndex(schedule_index).SetScheduledDispatchDelay(p2);
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();
@ -279,7 +279,7 @@ CommandCost CmdScheduledDispatchResetLastDispatch(TileIndex tile, DoCommandFlag
if (flags & DC_EXEC) {
v->orders->GetDispatchScheduleByIndex(schedule_index).SetScheduledDispatchLastDispatch(0);
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();
@ -312,7 +312,7 @@ CommandCost CmdScheduledDispatchClear(TileIndex tile, DoCommandFlag flags, uint3
if (flags & DC_EXEC) {
v->orders->GetDispatchScheduleByIndex(schedule_index).ClearScheduledDispatch();
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();
@ -353,7 +353,7 @@ CommandCost CmdScheduledDispatchAddNewSchedule(TileIndex tile, DoCommandFlag fla
ds.SetScheduledDispatchDuration(p2);
ds.SetScheduledDispatchStartDate(date, full_date_fract);
ds.UpdateScheduledDispatch(nullptr);
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();
@ -448,7 +448,7 @@ CommandCost CmdScheduledDispatchRenameSchedule(TileIndex tile, DoCommandFlag fla
} else {
v->orders->GetDispatchScheduleByIndex(schedule_index).ScheduleName() = text;
}
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH | STWDF_ORDERS);
}
return CommandCost();
@ -484,7 +484,7 @@ CommandCost CmdScheduledDispatchDuplicateSchedule(TileIndex tile, DoCommandFlag
DispatchSchedule &ds = v->orders->GetScheduledDispatchScheduleSet().emplace_back(v->orders->GetDispatchScheduleByIndex(schedule_index));
ds.SetScheduledDispatchLastDispatch(0);
ds.UpdateScheduledDispatch(nullptr);
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();
@ -524,7 +524,7 @@ CommandCost CmdScheduledDispatchAppendVehicleSchedules(TileIndex tile, DoCommand
ds.SetScheduledDispatchLastDispatch(0);
ds.UpdateScheduledDispatch(nullptr);
}
SetTimetableWindowsDirty(v1, true);
SetTimetableWindowsDirty(v1, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();
@ -563,7 +563,7 @@ CommandCost CmdScheduledDispatchAdjust(TileIndex tile, DoCommandFlag flags, uint
if (flags & DC_EXEC) {
ds.AdjustScheduledDispatch(adjustment);
ds.UpdateScheduledDispatch(nullptr);
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();
@ -670,6 +670,6 @@ bool DispatchSchedule::UpdateScheduledDispatchToDate(DateTicksScaled now)
void DispatchSchedule::UpdateScheduledDispatch(const Vehicle *v)
{
if (this->UpdateScheduledDispatchToDate(_scaled_date_ticks) && v != nullptr) {
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
}

@ -1256,7 +1256,7 @@ void SchdispatchInvalidateWindows(const Vehicle *v)
if (w->window_class == WC_VEHICLE_TIMETABLE) {
if (static_cast<GeneralVehicleWindow *>(w)->vehicle->FirstShared() == v) w->SetDirty();
}
if (w->window_class == WC_SCHDISPATCH_SLOTS) {
if (w->window_class == WC_SCHDISPATCH_SLOTS || w->window_class == WC_VEHICLE_ORDERS) {
if (static_cast<GeneralVehicleWindow *>(w)->vehicle->FirstShared() == v) w->InvalidateData(VIWD_MODIFY_ORDERS, false);
}
}

@ -19,7 +19,14 @@ void ShowTimetableWindow(const Vehicle *v);
void UpdateVehicleTimetable(Vehicle *v, bool travelling);
void SetTimetableParams(int first_param, Ticks ticks, bool long_mode = false);
Ticks ParseTimetableDuration(const char *str);
void SetTimetableWindowsDirty(const Vehicle *v, bool include_scheduled_dispatch = false);
enum SetTimetableWindowsDirtyFlags {
STWDF_NONE = 0,
STWDF_SCHEDULED_DISPATCH = 1 << 0,
STWDF_ORDERS = 1 << 1,
};
DECLARE_ENUM_AS_BIT_SET(SetTimetableWindowsDirtyFlags)
void SetTimetableWindowsDirty(const Vehicle *v, SetTimetableWindowsDirtyFlags flags = STWDF_NONE);
struct TimetableProgress {
VehicleID id;

@ -105,7 +105,7 @@ static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint32 val,
v->orders->UpdateTotalDuration(total_delta);
v->orders->UpdateTimetableDuration(timetable_delta);
SetTimetableWindowsDirty(v, mtf == MTF_ASSIGN_SCHEDULE);
SetTimetableWindowsDirty(v, (mtf == MTF_ASSIGN_SCHEDULE) ? STWDF_SCHEDULED_DISPATCH : STWDF_NONE);
for (v = v->FirstShared(); v != nullptr; v = v->NextShared()) {
if (v->cur_real_order_index == order_number && v->current_order.Equals(*order)) {
@ -655,7 +655,7 @@ CommandCost CmdTimetableSeparation(TileIndex tile, DoCommandFlag flags, uint32 p
}
v2->ClearSeparation();
}
SetTimetableWindowsDirty(v, true);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();

@ -1250,11 +1250,13 @@ void ShowTimetableWindow(const Vehicle *v)
AllocateWindowDescFront<TimetableWindow>(&_timetable_desc, v->index);
}
void SetTimetableWindowsDirty(const Vehicle *v, bool include_scheduled_dispatch)
void SetTimetableWindowsDirty(const Vehicle *v, SetTimetableWindowsDirtyFlags flags)
{
v = v->FirstShared();
for (Window *w : Window::IterateFromBack()) {
if (w->window_class == WC_VEHICLE_TIMETABLE || (include_scheduled_dispatch && w->window_class == WC_SCHDISPATCH_SLOTS)) {
if (w->window_class == WC_VEHICLE_TIMETABLE ||
((flags & STWDF_SCHEDULED_DISPATCH) && w->window_class == WC_SCHDISPATCH_SLOTS) ||
((flags & STWDF_ORDERS) && w->window_class == WC_VEHICLE_ORDERS)) {
if (static_cast<GeneralVehicleWindow *>(w)->vehicle->FirstShared() == v) w->SetDirty();
}
}

Loading…
Cancel
Save