2017-05-29 18:37:08 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file schdispatch_gui.cpp GUI code for Scheduled Dispatch */
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "command_func.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "window_gui.h"
|
|
|
|
#include "window_func.h"
|
|
|
|
#include "textbuf_gui.h"
|
|
|
|
#include "strings_func.h"
|
|
|
|
#include "vehicle_base.h"
|
|
|
|
#include "string_func.h"
|
|
|
|
#include "spritecache.h"
|
|
|
|
#include "gfx_func.h"
|
2023-12-28 13:28:55 +00:00
|
|
|
#include "company_base.h"
|
2017-05-29 18:37:08 +00:00
|
|
|
#include "company_func.h"
|
|
|
|
#include "date_func.h"
|
|
|
|
#include "date_gui.h"
|
|
|
|
#include "vehicle_gui.h"
|
|
|
|
#include "settings_type.h"
|
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "zoom_func.h"
|
2021-11-28 02:25:42 +00:00
|
|
|
#include "core/geometry_func.hpp"
|
2023-05-07 19:06:47 +00:00
|
|
|
#include "tilehighlight_func.h"
|
2017-05-29 18:37:08 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/string_colours.h"
|
|
|
|
#include "table/sprites.h"
|
|
|
|
|
|
|
|
#include "safeguards.h"
|
|
|
|
|
|
|
|
enum SchdispatchWidgets {
|
|
|
|
WID_SCHDISPATCH_CAPTION, ///< Caption of window.
|
2023-04-29 11:19:28 +00:00
|
|
|
WID_SCHDISPATCH_RENAME, ///< Rename button.
|
2023-09-23 11:05:05 +00:00
|
|
|
WID_SCHDISPATCH_MOVE_LEFT, ///< Move current schedule left (-1).
|
|
|
|
WID_SCHDISPATCH_MOVE_RIGHT, ///< Move current schedule right (+1).
|
2017-05-29 18:37:08 +00:00
|
|
|
WID_SCHDISPATCH_MATRIX, ///< Matrix of vehicles.
|
|
|
|
WID_SCHDISPATCH_V_SCROLL, ///< Vertical scrollbar.
|
2023-09-23 11:05:05 +00:00
|
|
|
WID_SCHDISPATCH_SUMMARY_PANEL, ///< Summary panel
|
2017-05-29 18:37:08 +00:00
|
|
|
|
|
|
|
WID_SCHDISPATCH_ENABLED, ///< Enable button.
|
2022-01-13 19:46:43 +00:00
|
|
|
WID_SCHDISPATCH_HEADER, ///< Header text.
|
|
|
|
WID_SCHDISPATCH_PREV, ///< Previous schedule.
|
|
|
|
WID_SCHDISPATCH_NEXT, ///< Next schedule.
|
|
|
|
WID_SCHDISPATCH_ADD_SCHEDULE, ///< Add schedule.
|
|
|
|
|
2017-05-29 18:37:08 +00:00
|
|
|
WID_SCHDISPATCH_ADD, ///< Add Departure Time button
|
|
|
|
WID_SCHDISPATCH_SET_DURATION, ///< Duration button
|
|
|
|
WID_SCHDISPATCH_SET_START_DATE, ///< Start Date button
|
2023-05-09 19:16:36 +00:00
|
|
|
WID_SCHDISPATCH_SET_DELAY, ///< Delay button
|
2021-12-18 12:46:25 +00:00
|
|
|
WID_SCHDISPATCH_MANAGEMENT, ///< Management button
|
2023-05-09 19:16:36 +00:00
|
|
|
WID_SCHDISPATCH_ADJUST, ///< Adjust departure times
|
2024-01-27 21:31:40 +00:00
|
|
|
WID_SCHDISPATCH_REMOVE, ///< Remove departure times
|
2024-01-28 01:48:54 +00:00
|
|
|
WID_SCHDISPATCH_MANAGE_SLOT, ///< Manage slot button
|
2017-05-29 18:37:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for when a time has been chosen to start the schedule
|
2022-01-13 19:46:43 +00:00
|
|
|
* @param p1 The p1 parameter to send to CmdScheduledDispatchSetStartDate
|
2017-05-29 18:37:08 +00:00
|
|
|
* @param date the actually chosen date
|
|
|
|
*/
|
2024-02-07 18:36:47 +00:00
|
|
|
static void SetScheduleStartDateIntl(uint32_t p1, StateTicks date)
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
2024-01-07 16:41:53 +00:00
|
|
|
DoCommandPEx(0, p1, 0, (uint64_t)date.base(), CMD_SCHEDULED_DISPATCH_SET_START_DATE | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE), nullptr, nullptr, 0);
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for when a time has been chosen to start the schedule
|
|
|
|
* @param window the window related to the setting of the date
|
|
|
|
* @param date the actually chosen date
|
|
|
|
*/
|
2024-02-07 18:36:47 +00:00
|
|
|
static void SetScheduleStartDateCallback(const Window *w, StateTicks date)
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
SetScheduleStartDateIntl(w->window_number, date);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for when a time has been chosen to add to the schedule
|
|
|
|
* @param p1 The p1 parameter to send to CmdScheduledDispatchAdd
|
|
|
|
* @param date the actually chosen date
|
|
|
|
*/
|
2024-02-07 18:36:47 +00:00
|
|
|
static void ScheduleAddIntl(uint32_t p1, StateTicks date, uint extra_slots, uint offset, bool wrap_mode = false)
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
VehicleID veh = GB(p1, 0, 20);
|
2022-01-13 19:46:43 +00:00
|
|
|
uint schedule_index = GB(p1, 20, 12);
|
2017-05-29 18:37:08 +00:00
|
|
|
Vehicle *v = Vehicle::GetIfValid(veh);
|
2022-03-04 18:17:44 +00:00
|
|
|
if (v == nullptr || !v->IsPrimaryVehicle() || schedule_index >= v->orders->GetScheduledDispatchScheduleCount()) return;
|
2022-01-13 19:46:43 +00:00
|
|
|
|
2022-03-04 18:17:44 +00:00
|
|
|
const DispatchSchedule &ds = v->orders->GetDispatchScheduleByIndex(schedule_index);
|
2017-05-29 18:37:08 +00:00
|
|
|
|
|
|
|
/* Make sure the time is the closest future to the timetable start */
|
2024-02-07 18:36:47 +00:00
|
|
|
StateTicks start_tick = ds.GetScheduledDispatchStartTick();
|
2024-01-07 16:41:53 +00:00
|
|
|
uint32_t duration = ds.GetScheduledDispatchDuration();
|
2021-11-28 02:25:42 +00:00
|
|
|
while (date > start_tick) date -= duration;
|
|
|
|
while (date < start_tick) date += duration;
|
|
|
|
|
2022-12-27 00:13:37 +00:00
|
|
|
if (extra_slots > 0 && offset > 0 && !wrap_mode) {
|
2024-02-07 18:36:47 +00:00
|
|
|
StateTicks end_tick = start_tick + duration;
|
2024-01-07 16:41:53 +00:00
|
|
|
int64_t max_extra_slots = (end_tick - 1 - date).base() / offset;
|
|
|
|
if (max_extra_slots < extra_slots) extra_slots = static_cast<uint>(std::max<int64_t>(0, max_extra_slots));
|
2021-11-28 02:25:42 +00:00
|
|
|
extra_slots = std::min<uint>(extra_slots, UINT16_MAX);
|
|
|
|
}
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
DoCommandPEx(0, p1, (uint32_t)(date - start_tick).base(), (((uint64_t)extra_slots) << 32) | offset, CMD_SCHEDULED_DISPATCH_ADD | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE), nullptr, nullptr, 0);
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for when a time has been chosen to add to the schedule
|
|
|
|
* @param window the window related to the setting of the date
|
|
|
|
* @param date the actually chosen date
|
|
|
|
*/
|
2024-02-07 18:36:47 +00:00
|
|
|
static void ScheduleAddCallback(const Window *w, StateTicks date)
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
2021-11-28 02:25:42 +00:00
|
|
|
ScheduleAddIntl(w->window_number, date, 0, 0);
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the maximum number of vehicle required to run this timetable according to the dispatch schedule
|
|
|
|
* @param timetable_duration timetable duration in scaled tick
|
|
|
|
* @param schedule_duration scheduled dispatch duration in scaled tick
|
|
|
|
* @param offsets list of all dispatch offsets in the schedule
|
|
|
|
* @return maxinum number of vehicle required
|
|
|
|
*/
|
2024-01-28 01:48:54 +00:00
|
|
|
static int CalculateMaxRequiredVehicle(Ticks timetable_duration, uint32_t schedule_duration, const std::vector<DispatchSlot> &slots)
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
if (timetable_duration == INVALID_TICKS) return -1;
|
2024-01-28 01:48:54 +00:00
|
|
|
if (slots.size() == 0) return -1;
|
2017-05-29 18:37:08 +00:00
|
|
|
|
|
|
|
/* Number of time required to ensure all vehicle are counted */
|
|
|
|
int required_loop = CeilDiv(timetable_duration, schedule_duration) + 1;
|
|
|
|
|
|
|
|
/* Create indice array to count maximum overlapping range */
|
2024-01-07 16:41:53 +00:00
|
|
|
std::vector<std::pair<uint32_t, int>> indices;
|
2017-05-29 18:37:08 +00:00
|
|
|
for (int i = 0; i < required_loop; i++) {
|
2024-01-28 01:48:54 +00:00
|
|
|
for (const DispatchSlot &slot : slots) {
|
|
|
|
if (slot.offset >= schedule_duration) continue;
|
|
|
|
indices.push_back(std::make_pair(i * schedule_duration + slot.offset, 1));
|
|
|
|
indices.push_back(std::make_pair(i * schedule_duration + slot.offset + timetable_duration, -1));
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-09 23:17:19 +00:00
|
|
|
if (indices.empty()) return -1;
|
2017-05-29 18:37:08 +00:00
|
|
|
std::sort(indices.begin(), indices.end());
|
|
|
|
int current_count = 0;
|
|
|
|
int vehicle_count = 0;
|
|
|
|
for (const auto& inc : indices) {
|
|
|
|
current_count += inc.second;
|
|
|
|
if (current_count > vehicle_count) vehicle_count = current_count;
|
|
|
|
}
|
|
|
|
return vehicle_count;
|
|
|
|
}
|
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
static void AddNewScheduledDispatchSchedule(VehicleID vindex)
|
|
|
|
{
|
2024-02-07 18:36:47 +00:00
|
|
|
StateTicks start_tick;
|
2024-01-07 16:41:53 +00:00
|
|
|
uint32_t duration;
|
2022-01-13 19:46:43 +00:00
|
|
|
|
2023-12-28 13:28:55 +00:00
|
|
|
const Company *c = Company::GetIfValid(_local_company);
|
|
|
|
if (c != nullptr && c->settings.default_sched_dispatch_duration != 0) {
|
|
|
|
/* Use duration from setting, set start time to be integer multiple of duration */
|
|
|
|
|
|
|
|
const TickMinutes now = _settings_time.NowInTickMinutes();
|
|
|
|
start_tick = _settings_time.FromTickMinutes(now - (now.base() % c->settings.default_sched_dispatch_duration));
|
|
|
|
|
|
|
|
duration = c->settings.default_sched_dispatch_duration * _settings_time.ticks_per_minute;
|
|
|
|
} else if (_settings_time.time_in_minutes) {
|
2022-01-13 19:46:43 +00:00
|
|
|
/* Set to 00:00 of today, and 1 day */
|
|
|
|
|
2023-12-19 01:03:18 +00:00
|
|
|
start_tick = _settings_time.FromTickMinutes(_settings_time.NowInTickMinutes().ToSameDayClockTime(0, 0));
|
2022-01-13 19:46:43 +00:00
|
|
|
|
|
|
|
duration = 24 * 60 * _settings_time.ticks_per_minute;
|
|
|
|
} else {
|
2024-02-13 21:34:09 +00:00
|
|
|
/* Set Jan 1st and 365 day, calendar and economy time must be locked together for this to result in a useful schedule */
|
|
|
|
start_tick = DateToStateTicks(CalTime::DateAtStartOfYear(CalTime::CurYear()).base());
|
2022-01-13 19:46:43 +00:00
|
|
|
duration = 365 * DAY_TICKS;
|
|
|
|
}
|
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
DoCommandPEx(0, vindex, duration, (uint64_t)start_tick.base(), CMD_SCHEDULED_DISPATCH_ADD_NEW_SCHEDULE | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE), CcAddNewSchDispatchSchedule, nullptr, 0);
|
2022-01-13 19:46:43 +00:00
|
|
|
}
|
|
|
|
|
2022-01-15 00:21:31 +00:00
|
|
|
struct SchdispatchWindow : GeneralVehicleWindow {
|
2022-01-13 19:46:43 +00:00
|
|
|
int schedule_index;
|
2017-05-29 18:37:08 +00:00
|
|
|
int clicked_widget; ///< The widget that was clicked (used to determine what to do in OnQueryTextFinished)
|
|
|
|
Scrollbar *vscroll; ///< Verticle scrollbar
|
|
|
|
uint num_columns; ///< Number of columns.
|
|
|
|
|
|
|
|
uint item_count = 0; ///< Number of scheduled item
|
2024-02-07 18:36:47 +00:00
|
|
|
StateTicks next_departure_update = INT64_MAX; ///< Time after which the last departure value should be re-drawn
|
2020-02-09 23:17:19 +00:00
|
|
|
uint warning_count = 0;
|
2024-01-22 18:28:01 +00:00
|
|
|
uint extra_line_count = 0;
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2024-01-27 21:31:40 +00:00
|
|
|
int base_width = 0;
|
|
|
|
int header_width = 0;
|
|
|
|
int delete_flag_width = 0;
|
|
|
|
int delete_flag_height = 0;
|
|
|
|
int arrow_flag_width = 0;
|
|
|
|
int arrow_flag_height = 0;
|
|
|
|
|
|
|
|
bool remove_slot_mode = false;
|
2024-01-28 01:48:54 +00:00
|
|
|
uint32_t selected_slot = UINT32_MAX;
|
2024-01-27 21:31:40 +00:00
|
|
|
|
|
|
|
enum ManagementDropdown {
|
|
|
|
SCH_MD_RESET_LAST_DISPATCHED,
|
|
|
|
SCH_MD_CLEAR_SCHEDULE,
|
|
|
|
SCH_MD_REMOVE_SCHEDULE,
|
|
|
|
SCH_MD_DUPLICATE_SCHEDULE,
|
|
|
|
SCH_MD_APPEND_VEHICLE_SCHEDULES,
|
|
|
|
SCH_MD_REUSE_DEPARTURE_SLOTS,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-29 18:37:08 +00:00
|
|
|
SchdispatchWindow(WindowDesc *desc, WindowNumber window_number) :
|
2022-01-15 00:21:31 +00:00
|
|
|
GeneralVehicleWindow(desc, Vehicle::Get(window_number))
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
this->CreateNestedTree();
|
|
|
|
this->vscroll = this->GetScrollbar(WID_SCHDISPATCH_V_SCROLL);
|
|
|
|
this->FinishInitNested(window_number);
|
|
|
|
|
|
|
|
this->owner = this->vehicle->owner;
|
2022-01-13 19:46:43 +00:00
|
|
|
this->schedule_index = -1;
|
|
|
|
this->AutoSelectSchedule();
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
|
2023-11-25 13:29:58 +00:00
|
|
|
void Close(int data = 0) override
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
if (!FocusWindowById(WC_VEHICLE_VIEW, this->window_number)) {
|
2023-05-06 18:14:39 +00:00
|
|
|
MarkDirtyFocusedRoutePaths(this->vehicle);
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
2023-09-15 22:56:33 +00:00
|
|
|
this->GeneralVehicleWindow::Close();
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
|
2024-02-22 21:53:54 +00:00
|
|
|
bool TimeUnitsUsable() const
|
|
|
|
{
|
|
|
|
return _settings_time.time_in_minutes || !EconTime::UsingWallclockUnits();
|
|
|
|
}
|
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
bool IsScheduleSelected() const
|
|
|
|
{
|
2022-03-04 18:17:44 +00:00
|
|
|
return this->vehicle->orders != nullptr && this->schedule_index >= 0 && (uint)this->schedule_index < this->vehicle->orders->GetScheduledDispatchScheduleCount();
|
2022-01-13 19:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AutoSelectSchedule()
|
|
|
|
{
|
|
|
|
if (!this->IsScheduleSelected()) {
|
2022-03-04 18:17:44 +00:00
|
|
|
if (this->vehicle->orders != nullptr && this->vehicle->orders->GetScheduledDispatchScheduleCount() > 0) {
|
|
|
|
this->schedule_index = Clamp<int>(this->schedule_index, 0, this->vehicle->orders->GetScheduledDispatchScheduleCount() - 1);
|
2022-01-13 19:46:43 +00:00
|
|
|
} else {
|
|
|
|
this->schedule_index = -1;
|
|
|
|
}
|
2024-01-28 01:48:54 +00:00
|
|
|
this->selected_slot = UINT32_MAX;
|
2022-01-13 19:46:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const DispatchSchedule &GetSelectedSchedule() const
|
|
|
|
{
|
2022-03-04 18:17:44 +00:00
|
|
|
return this->vehicle->orders->GetDispatchScheduleByIndex(this->schedule_index);
|
2022-01-13 19:46:43 +00:00
|
|
|
}
|
|
|
|
|
2024-01-28 01:48:54 +00:00
|
|
|
const DispatchSlot *GetSelectedDispatchSlot() const
|
|
|
|
{
|
|
|
|
if (!this->IsScheduleSelected()) return nullptr;
|
|
|
|
|
|
|
|
const DispatchSchedule &ds = this->GetSelectedSchedule();
|
|
|
|
if (this->selected_slot != UINT32_MAX) {
|
|
|
|
for (const DispatchSlot &slot : ds.GetScheduledDispatch()) {
|
|
|
|
if (slot.offset == this->selected_slot) {
|
|
|
|
return &slot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2024-01-02 14:31:56 +00:00
|
|
|
virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case WID_SCHDISPATCH_MATRIX: {
|
|
|
|
uint min_height = 0;
|
|
|
|
|
2024-02-13 21:34:09 +00:00
|
|
|
SetDParamMaxValue(0, _settings_time.time_in_minutes ? 0 : EconTime::MAX_YEAR.base() * DAYS_IN_YEAR);
|
2024-01-28 01:48:54 +00:00
|
|
|
Dimension unumber = GetStringBoundingBox(STR_SCHDISPATCH_DATE_WALLCLOCK_TINY_FLAGGED);
|
2024-01-27 21:31:40 +00:00
|
|
|
|
2023-08-22 21:16:04 +00:00
|
|
|
const Sprite *spr = GetSprite(SPR_FLAG_VEH_STOPPED, SpriteType::Normal, ZoomMask(ZOOM_LVL_GUI));
|
2024-01-27 21:31:40 +00:00
|
|
|
this->delete_flag_width = UnScaleGUI(spr->width);
|
|
|
|
this->delete_flag_height = UnScaleGUI(spr->height);
|
|
|
|
|
|
|
|
const Sprite *spr_left_arrow = GetSprite(SPR_ARROW_LEFT, SpriteType::Normal, ZoomMask(ZOOM_LVL_GUI));
|
|
|
|
const Sprite *spr_right_arrow = GetSprite(SPR_ARROW_RIGHT, SpriteType::Normal, ZoomMask(ZOOM_LVL_GUI));
|
|
|
|
this->arrow_flag_width = UnScaleGUI(std::max(spr_left_arrow->width, spr_right_arrow->width));
|
|
|
|
this->arrow_flag_height = UnScaleGUI(std::max(spr_left_arrow->height, spr_right_arrow->height));
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2022-12-04 20:25:38 +00:00
|
|
|
min_height = std::max<uint>(unumber.height + WidgetDimensions::scaled.matrix.top, UnScaleGUI(spr->height));
|
2024-01-27 21:31:40 +00:00
|
|
|
this->header_width = std::max(this->delete_flag_width, this->arrow_flag_width);
|
2017-05-29 18:37:08 +00:00
|
|
|
this->base_width = unumber.width + this->header_width + 4;
|
|
|
|
|
|
|
|
resize->height = min_height;
|
2024-01-27 21:31:40 +00:00
|
|
|
resize->width = base_width + WidgetDimensions::scaled.framerect.left + WidgetDimensions::scaled.framerect.right;
|
2017-05-29 18:37:08 +00:00
|
|
|
size->width = resize->width * 3;
|
|
|
|
size->height = resize->height * 3;
|
2017-06-06 17:27:00 +00:00
|
|
|
|
2017-05-29 18:37:08 +00:00
|
|
|
fill->width = resize->width;
|
|
|
|
fill->height = resize->height;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_SUMMARY_PANEL:
|
2024-01-22 18:28:01 +00:00
|
|
|
size->height = (5 + this->extra_line_count) * GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical() + (WidgetDimensions::scaled.vsep_wide * 2);
|
2022-01-13 23:04:38 +00:00
|
|
|
uint warning_count = this->warning_count;
|
2020-02-09 23:17:19 +00:00
|
|
|
if (warning_count > 0) {
|
|
|
|
const Dimension warning_dimensions = GetSpriteSize(SPR_WARNING_SIGN);
|
2023-12-17 01:16:40 +00:00
|
|
|
size->height += warning_count * std::max<int>(warning_dimensions.height, GetCharacterHeight(FS_NORMAL));
|
2020-02-09 23:17:19 +00:00
|
|
|
}
|
2017-05-29 18:37:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set proper item_count to number of offsets in the schedule.
|
|
|
|
*/
|
|
|
|
void CountItem()
|
|
|
|
{
|
|
|
|
this->item_count = 0;
|
2022-01-13 19:46:43 +00:00
|
|
|
if (this->IsScheduleSelected()) {
|
|
|
|
this->item_count = (uint)this->GetSelectedSchedule().GetScheduledDispatch().size();
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Some data on this window has become invalid.
|
|
|
|
* @param data Information about the changed data.
|
|
|
|
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
|
|
|
|
*/
|
2019-04-28 10:05:14 +00:00
|
|
|
virtual void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
switch (data) {
|
|
|
|
case VIWD_MODIFY_ORDERS:
|
|
|
|
if (!gui_scope) break;
|
2022-01-13 19:46:43 +00:00
|
|
|
this->AutoSelectSchedule();
|
2017-05-29 18:37:08 +00:00
|
|
|
this->ReInit();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-28 10:05:14 +00:00
|
|
|
virtual void OnPaint() override
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
const Vehicle *v = this->vehicle;
|
|
|
|
CountItem();
|
|
|
|
|
2024-02-22 21:53:54 +00:00
|
|
|
const bool unviewable = (v->orders == nullptr) || !this->TimeUnitsUsable();
|
|
|
|
const bool uneditable = (v->orders == nullptr) || (v->owner != _local_company);
|
|
|
|
const bool unusable = unviewable || uneditable;
|
2022-01-13 19:46:43 +00:00
|
|
|
|
2024-02-22 21:53:54 +00:00
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_ENABLED, uneditable || (!HasBit(v->vehicle_flags, VF_SCHEDULED_DISPATCH) && (unviewable || HasBit(v->vehicle_flags, VF_TIMETABLE_SEPARATION) || v->HasUnbunchingOrder())));
|
2021-04-20 17:42:57 +00:00
|
|
|
|
2023-04-29 11:19:28 +00:00
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_RENAME, unusable || v->orders->GetScheduledDispatchScheduleCount() == 0);
|
2024-02-22 21:53:54 +00:00
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_PREV, unviewable || this->schedule_index <= 0);
|
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_NEXT, unviewable || this->schedule_index >= (int)(v->orders->GetScheduledDispatchScheduleCount() - 1));
|
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_MOVE_LEFT, unviewable || this->schedule_index <= 0);
|
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_MOVE_RIGHT, unviewable || this->schedule_index >= (int)(v->orders->GetScheduledDispatchScheduleCount() - 1));
|
2022-03-04 18:17:44 +00:00
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_ADD_SCHEDULE, unusable || v->orders->GetScheduledDispatchScheduleCount() >= 4096);
|
2022-01-13 19:46:43 +00:00
|
|
|
|
2024-01-27 21:31:40 +00:00
|
|
|
const bool disabled = unusable || !HasBit(v->vehicle_flags, VF_SCHEDULED_DISPATCH) || !this->IsScheduleSelected();
|
|
|
|
const bool no_editable_slots = disabled || this->GetSelectedSchedule().GetScheduledDispatch().empty();
|
2021-04-20 17:42:57 +00:00
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_ADD, disabled);
|
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_SET_DURATION, disabled);
|
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_SET_START_DATE, disabled);
|
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_SET_DELAY, disabled);
|
2021-12-18 12:46:25 +00:00
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_MANAGEMENT, disabled);
|
2024-01-27 21:31:40 +00:00
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_ADJUST, no_editable_slots);
|
|
|
|
|
2024-01-28 01:48:54 +00:00
|
|
|
if (no_editable_slots || this->GetSelectedDispatchSlot() == nullptr) {
|
|
|
|
this->selected_slot = UINT32_MAX;
|
|
|
|
}
|
|
|
|
this->SetWidgetDisabledState(WID_SCHDISPATCH_MANAGE_SLOT, this->selected_slot == UINT32_MAX);
|
|
|
|
|
2024-01-27 21:31:40 +00:00
|
|
|
NWidgetCore *remove_slot_widget = this->GetWidget<NWidgetCore>(WID_SCHDISPATCH_REMOVE);
|
|
|
|
remove_slot_widget->SetDisabled(no_editable_slots);
|
|
|
|
if (no_editable_slots) {
|
|
|
|
remove_slot_widget->SetLowered(false);
|
|
|
|
this->remove_slot_mode = false;
|
|
|
|
}
|
2017-06-06 17:27:00 +00:00
|
|
|
|
2024-01-23 17:45:32 +00:00
|
|
|
NWidgetCore *start_date_widget = this->GetWidget<NWidgetCore>(WID_SCHDISPATCH_SET_START_DATE);
|
|
|
|
start_date_widget->widget_data = _settings_time.time_in_minutes ? STR_SCHDISPATCH_START_TIME : STR_SCHDISPATCH_START;
|
|
|
|
start_date_widget->tool_tip = _settings_time.time_in_minutes ? STR_SCHDISPATCH_SET_START_TIME : STR_SCHDISPATCH_SET_START;
|
|
|
|
|
2017-05-29 18:37:08 +00:00
|
|
|
this->vscroll->SetCount(CeilDiv(this->item_count, this->num_columns));
|
|
|
|
|
|
|
|
this->SetWidgetLoweredState(WID_SCHDISPATCH_ENABLED, HasBit(v->vehicle_flags, VF_SCHEDULED_DISPATCH));
|
|
|
|
this->DrawWidgets();
|
|
|
|
}
|
|
|
|
|
2024-01-02 14:31:56 +00:00
|
|
|
virtual void SetStringParameters(WidgetID widget) const override
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2022-01-13 19:46:43 +00:00
|
|
|
case WID_SCHDISPATCH_CAPTION:
|
|
|
|
SetDParam(0, this->vehicle->index);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_HEADER:
|
|
|
|
if (this->IsScheduleSelected()) {
|
2023-04-29 11:19:28 +00:00
|
|
|
const DispatchSchedule &ds = this->GetSelectedSchedule();
|
|
|
|
if (ds.ScheduleName().empty()) {
|
|
|
|
SetDParam(0, STR_SCHDISPATCH_SCHEDULE_ID);
|
|
|
|
SetDParam(1, this->schedule_index + 1);
|
|
|
|
SetDParam(2, this->vehicle->orders->GetScheduledDispatchScheduleCount());
|
|
|
|
} else {
|
|
|
|
SetDParam(0, STR_SCHDISPATCH_NAMED_SCHEDULE_ID);
|
|
|
|
SetDParamStr(1, ds.ScheduleName().c_str());
|
|
|
|
SetDParam(2, this->schedule_index + 1);
|
|
|
|
SetDParam(3, this->vehicle->orders->GetScheduledDispatchScheduleCount());
|
|
|
|
}
|
2022-01-13 19:46:43 +00:00
|
|
|
} else {
|
|
|
|
SetDParam(0, STR_SCHDISPATCH_NO_SCHEDULES);
|
|
|
|
}
|
|
|
|
break;
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-02 14:31:56 +00:00
|
|
|
virtual bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
|
2021-11-28 02:25:42 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2024-02-18 23:11:00 +00:00
|
|
|
case WID_SCHDISPATCH_ENABLED: {
|
2024-02-22 21:53:54 +00:00
|
|
|
if (!this->TimeUnitsUsable()) {
|
|
|
|
SetDParam(0, STR_SCHDISPATCH_ENABLED_TOOLTIP);
|
|
|
|
SetDParam(1, STR_CANNOT_ENABLE_BECAUSE_TIME_UNITS_UNUSABLE);
|
|
|
|
GuiShowTooltips(this, STR_TOOLTIP_SEPARATION_CANNOT_ENABLE, close_cond, 2);
|
|
|
|
} else if (HasBit(this->vehicle->vehicle_flags, VF_TIMETABLE_SEPARATION)) {
|
2024-02-18 23:11:00 +00:00
|
|
|
SetDParam(0, STR_SCHDISPATCH_ENABLED_TOOLTIP);
|
|
|
|
SetDParam(1, STR_CANNOT_ENABLE_BECAUSE_AUTO_SEPARATION);
|
|
|
|
GuiShowTooltips(this, STR_TOOLTIP_SEPARATION_CANNOT_ENABLE, close_cond, 2);
|
|
|
|
} else if (this->vehicle->HasUnbunchingOrder()) {
|
|
|
|
SetDParam(0, STR_SCHDISPATCH_ENABLED_TOOLTIP);
|
|
|
|
SetDParam(1, STR_CANNOT_ENABLE_BECAUSE_UNBUNCHING);
|
|
|
|
GuiShowTooltips(this, STR_TOOLTIP_SEPARATION_CANNOT_ENABLE, close_cond, 2);
|
|
|
|
} else {
|
|
|
|
GuiShowTooltips(this, STR_SCHDISPATCH_ENABLED_TOOLTIP, close_cond);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-11-28 02:25:42 +00:00
|
|
|
case WID_SCHDISPATCH_ADD: {
|
|
|
|
if (_settings_time.time_in_minutes) {
|
2023-11-17 17:26:57 +00:00
|
|
|
SetDParam(0, STR_SCHDISPATCH_ADD_TOOLTIP);
|
|
|
|
GuiShowTooltips(this, STR_SCHDISPATCH_ADD_TOOLTIP_EXTRA, close_cond, 1);
|
2021-11-28 02:25:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-12-18 12:46:25 +00:00
|
|
|
case WID_SCHDISPATCH_MANAGEMENT: {
|
2023-05-07 19:06:47 +00:00
|
|
|
_temp_special_strings[0] = GetString(STR_SCHDISPATCH_RESET_LAST_DISPATCH_TOOLTIP);
|
|
|
|
auto add_suffix = [&](StringID str) {
|
|
|
|
SetDParam(0, str);
|
|
|
|
_temp_special_strings[0] += GetString(STR_SCHDISPATCH_MANAGE_TOOLTIP_SUFFIX);
|
|
|
|
};
|
|
|
|
add_suffix(STR_SCHDISPATCH_CLEAR_TOOLTIP);
|
|
|
|
add_suffix(STR_SCHDISPATCH_REMOVE_SCHEDULE_TOOLTIP);
|
|
|
|
add_suffix(STR_SCHDISPATCH_DUPLICATE_SCHEDULE_TOOLTIP);
|
|
|
|
add_suffix(STR_SCHDISPATCH_APPEND_VEHICLE_SCHEDULES_TOOLTIP);
|
2024-01-28 01:48:54 +00:00
|
|
|
add_suffix(STR_SCHDISPATCH_REUSE_DEPARTURE_SLOTS_TOOLTIP);
|
|
|
|
GuiShowTooltips(this, SPECSTR_TEMP_START, close_cond);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_MANAGE_SLOT: {
|
|
|
|
_temp_special_strings[0] = GetString(STR_SCHDISPATCH_REUSE_THIS_DEPARTURE_SLOT_TOOLTIP);
|
2024-01-28 17:14:03 +00:00
|
|
|
auto add_suffix = [&](StringID str) {
|
|
|
|
SetDParam(0, str);
|
|
|
|
_temp_special_strings[0] += GetString(STR_SCHDISPATCH_MANAGE_TOOLTIP_SUFFIX);
|
|
|
|
};
|
|
|
|
add_suffix(STR_SCHDISPATCH_REUSE_THIS_DEPARTURE_TAG_TOOLTIP);
|
2023-11-17 17:26:57 +00:00
|
|
|
GuiShowTooltips(this, SPECSTR_TEMP_START, close_cond);
|
2021-12-18 12:46:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-01-28 11:50:44 +00:00
|
|
|
case WID_SCHDISPATCH_MATRIX: {
|
2024-02-22 21:53:54 +00:00
|
|
|
if (!this->TimeUnitsUsable()) return false;
|
2024-01-28 11:50:44 +00:00
|
|
|
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_SCHDISPATCH_MATRIX);
|
|
|
|
const DispatchSlot *slot;
|
|
|
|
bool is_header;
|
|
|
|
std::tie(slot, is_header) = this->GetSlotFromMatrixPoint(pt.x - nwi->pos_x, pt.y - nwi->pos_y);
|
|
|
|
if (slot == nullptr) return false;
|
|
|
|
|
|
|
|
if (is_header && this->remove_slot_mode) {
|
|
|
|
GuiShowTooltips(this, STR_SCHDISPATCH_REMOVE_SLOT, close_cond);
|
|
|
|
} else {
|
|
|
|
const DispatchSchedule &ds = this->GetSelectedSchedule();
|
2024-02-07 18:36:47 +00:00
|
|
|
const StateTicks start_tick = ds.GetScheduledDispatchStartTick();
|
2024-01-28 11:50:44 +00:00
|
|
|
|
|
|
|
SetDParam(0, start_tick + slot->offset);
|
|
|
|
_temp_special_strings[0] = GetString(STR_SCHDISPATCH_SLOT_TOOLTIP);
|
|
|
|
if (_settings_time.time_in_minutes) {
|
|
|
|
ClockFaceMinutes start_minutes = _settings_time.ToTickMinutes(start_tick).ToClockFaceMinutes();
|
|
|
|
if (start_minutes != 0) {
|
|
|
|
TickMinutes offset_minutes = slot->offset / _settings_time.ticks_per_minute;
|
|
|
|
SetDParam(0, offset_minutes.ClockHHMM());
|
|
|
|
_temp_special_strings[0] += GetString(STR_SCHDISPATCH_SLOT_TOOLTIP_RELATIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool have_last = false;
|
2024-03-13 17:34:17 +00:00
|
|
|
int32_t last_dispatch = ds.GetScheduledDispatchLastDispatch();
|
|
|
|
if (last_dispatch != INVALID_SCHEDULED_DISPATCH_OFFSET && (last_dispatch % ds.GetScheduledDispatchDuration() == slot->offset)) {
|
2024-01-28 11:50:44 +00:00
|
|
|
_temp_special_strings[0] += '\n';
|
|
|
|
_temp_special_strings[0] += GetString(STR_SCHDISPATCH_SLOT_TOOLTIP_LAST);
|
|
|
|
if (_settings_time.time_in_minutes) {
|
|
|
|
ClockFaceMinutes mins = _settings_time.ToTickMinutes(start_tick + ds.GetScheduledDispatchLastDispatch()).ToClockFaceMinutes();
|
|
|
|
if (mins != _settings_time.ToTickMinutes(start_tick + slot->offset).ToClockFaceMinutes()) {
|
|
|
|
SetDParam(0, start_tick + ds.GetScheduledDispatchLastDispatch());
|
|
|
|
_temp_special_strings[0] += GetString(STR_SCHDISPATCH_SLOT_TOOLTIP_TIME_SUFFIX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
have_last = true;
|
|
|
|
}
|
2024-02-07 18:36:47 +00:00
|
|
|
StateTicks next_slot = GetScheduledDispatchTime(ds, _state_ticks);
|
2024-03-13 17:34:17 +00:00
|
|
|
if (next_slot != INVALID_STATE_TICKS && ((next_slot - ds.GetScheduledDispatchStartTick()).AsTicks() % ds.GetScheduledDispatchDuration() == slot->offset)) {
|
2024-01-28 11:50:44 +00:00
|
|
|
if (!have_last) _temp_special_strings[0] += '\n';
|
|
|
|
_temp_special_strings[0] += GetString(STR_SCHDISPATCH_SLOT_TOOLTIP_NEXT);
|
|
|
|
if (_settings_time.time_in_minutes) {
|
|
|
|
ClockFaceMinutes mins = _settings_time.ToTickMinutes(next_slot).ToClockFaceMinutes();
|
|
|
|
if (mins != _settings_time.ToTickMinutes(start_tick + slot->offset).ToClockFaceMinutes()) {
|
|
|
|
SetDParam(0, next_slot);
|
|
|
|
_temp_special_strings[0] += GetString(STR_SCHDISPATCH_SLOT_TOOLTIP_TIME_SUFFIX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto flags = slot->flags;
|
|
|
|
if (ds.GetScheduledDispatchReuseSlots()) ClrBit(flags, DispatchSlot::SDSF_REUSE_SLOT);
|
|
|
|
if (flags != 0) {
|
|
|
|
_temp_special_strings[0] += '\n';
|
|
|
|
if (HasBit(flags, DispatchSlot::SDSF_REUSE_SLOT)) {
|
|
|
|
_temp_special_strings[0] += GetString(STR_SCHDISPATCH_SLOT_TOOLTIP_REUSE);
|
|
|
|
}
|
2024-01-28 17:14:03 +00:00
|
|
|
|
|
|
|
for (uint8_t flag_bit = DispatchSlot::SDSF_FIRST_TAG; flag_bit <= DispatchSlot::SDSF_LAST_TAG; flag_bit++) {
|
|
|
|
if (HasBit(flags, flag_bit)) {
|
|
|
|
SetDParam(0, 1 + flag_bit - DispatchSlot::SDSF_FIRST_TAG);
|
|
|
|
_temp_special_strings[0] += GetString(STR_SCHDISPATCH_SLOT_TOOLTIP_TAG);
|
|
|
|
}
|
|
|
|
}
|
2024-01-28 11:50:44 +00:00
|
|
|
}
|
|
|
|
GuiShowTooltips(this, SPECSTR_TEMP_START, close_cond);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-11-28 02:25:42 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-29 18:37:08 +00:00
|
|
|
/**
|
|
|
|
* Draw a time in the box with the top left corner at x,y.
|
|
|
|
* @param time Time to draw.
|
|
|
|
* @param left Left side of the box to draw in.
|
|
|
|
* @param right Right side of the box to draw in.
|
|
|
|
* @param y Top of the box to draw in.
|
|
|
|
*/
|
2024-02-07 18:36:47 +00:00
|
|
|
void DrawScheduledTime(const StateTicks time, int left, int right, int y, TextColour colour, bool last, bool next, bool flagged) const
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
bool rtl = _current_text_dir == TD_RTL;
|
|
|
|
|
2024-01-27 21:31:40 +00:00
|
|
|
int text_left = rtl ? right - this->base_width - 1 : left + this->header_width;
|
|
|
|
int text_right = rtl ? right - this->header_width : left + this->base_width - 1;
|
|
|
|
|
|
|
|
if (this->remove_slot_mode) {
|
|
|
|
int diff_y = (this->resize.step_height - this->delete_flag_height) / 2 - 2;
|
|
|
|
int offset_x = (this->header_width - this->delete_flag_width) / 2;
|
|
|
|
DrawSprite(SPR_FLAG_VEH_STOPPED, PAL_NONE, offset_x + (rtl ? right - this->delete_flag_width : left), y + diff_y);
|
|
|
|
} else {
|
|
|
|
auto draw_arrow = [&](bool right_arrow) {
|
|
|
|
SpriteID sprite = right_arrow ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT;
|
|
|
|
int diff_y = (this->resize.step_height - this->arrow_flag_height) / 2;
|
|
|
|
int offset_x = (this->header_width - this->arrow_flag_width) / 2;
|
|
|
|
DrawSprite(sprite, PAL_NONE, offset_x + (rtl ? right - this->delete_flag_width : left), y + diff_y);
|
|
|
|
};
|
|
|
|
if (next) {
|
|
|
|
draw_arrow(!rtl);
|
|
|
|
} else if (last) {
|
|
|
|
draw_arrow(rtl);
|
|
|
|
}
|
|
|
|
}
|
2017-05-29 18:37:08 +00:00
|
|
|
|
|
|
|
SetDParam(0, time);
|
2024-02-13 22:08:15 +00:00
|
|
|
DrawString(text_left, text_right, y + 2, flagged ? STR_SCHDISPATCH_DATE_WALLCLOCK_TINY_FLAGGED : STR_JUST_TT_TIME, colour, SA_HOR_CENTER);
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 00:01:44 +00:00
|
|
|
virtual void OnGameTick() override
|
2017-06-06 19:05:13 +00:00
|
|
|
{
|
2024-02-07 18:36:47 +00:00
|
|
|
if (_state_ticks >= this->next_departure_update) {
|
2024-01-13 23:44:39 +00:00
|
|
|
this->next_departure_update = INT64_MAX;
|
|
|
|
SetWidgetDirty(WID_SCHDISPATCH_SUMMARY_PANEL);
|
2017-06-06 19:05:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-02 14:31:56 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, WidgetID widget) const override
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
const Vehicle *v = this->vehicle;
|
|
|
|
|
|
|
|
switch (widget) {
|
|
|
|
case WID_SCHDISPATCH_MATRIX: {
|
|
|
|
/* If order is not initialized, don't draw */
|
2024-02-22 21:53:54 +00:00
|
|
|
if (!this->IsScheduleSelected() || !this->TimeUnitsUsable()) break;
|
2017-05-29 18:37:08 +00:00
|
|
|
|
|
|
|
bool rtl = _current_text_dir == TD_RTL;
|
|
|
|
|
|
|
|
/* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
|
|
|
|
const NWidgetCore *wid = this->GetWidget<NWidgetCore>(WID_SCHDISPATCH_MATRIX);
|
2024-01-07 16:41:53 +00:00
|
|
|
const uint16_t rows_in_display = wid->current_y / wid->resize_y;
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
const DispatchSchedule &ds = this->GetSelectedSchedule();
|
|
|
|
|
2020-11-15 09:37:11 +00:00
|
|
|
uint num = this->vscroll->GetPosition() * this->num_columns;
|
2022-01-13 19:46:43 +00:00
|
|
|
if (num >= ds.GetScheduledDispatch().size()) break;
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2021-02-01 17:07:34 +00:00
|
|
|
const uint maxval = std::min<uint>(this->item_count, num + (rows_in_display * this->num_columns));
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
auto current_schedule = ds.GetScheduledDispatch().begin() + num;
|
2024-02-07 18:36:47 +00:00
|
|
|
const StateTicks start_tick = ds.GetScheduledDispatchStartTick();
|
|
|
|
const StateTicks end_tick = ds.GetScheduledDispatchStartTick() + ds.GetScheduledDispatchDuration();
|
2020-11-15 09:37:11 +00:00
|
|
|
|
2024-02-07 18:36:47 +00:00
|
|
|
StateTicks slot = GetScheduledDispatchTime(ds, _state_ticks);
|
2024-03-13 17:34:17 +00:00
|
|
|
int32_t next_offset = (slot != INVALID_STATE_TICKS) ? (slot - ds.GetScheduledDispatchStartTick()).AsTicks() % ds.GetScheduledDispatchDuration() : INT32_MIN;
|
2024-01-27 21:31:40 +00:00
|
|
|
|
2024-03-13 17:34:17 +00:00
|
|
|
int32_t last_dispatch;
|
|
|
|
if (ds.GetScheduledDispatchLastDispatch() != INVALID_SCHEDULED_DISPATCH_OFFSET) {
|
|
|
|
last_dispatch = ds.GetScheduledDispatchLastDispatch() % ds.GetScheduledDispatchDuration();
|
|
|
|
} else {
|
|
|
|
last_dispatch = INT32_MIN;
|
|
|
|
}
|
2024-01-28 01:48:54 +00:00
|
|
|
|
2020-11-15 09:37:11 +00:00
|
|
|
for (int y = r.top + 1; num < maxval; y += this->resize.step_height) { /* Draw the rows */
|
2023-02-15 22:03:29 +00:00
|
|
|
for (uint i = 0; i < this->num_columns && num < maxval; i++, num++) {
|
2017-05-29 18:37:08 +00:00
|
|
|
/* Draw all departure time in the current row */
|
2022-01-13 19:46:43 +00:00
|
|
|
if (current_schedule != ds.GetScheduledDispatch().end()) {
|
2017-05-29 18:37:08 +00:00
|
|
|
int x = r.left + (rtl ? (this->num_columns - i - 1) : i) * this->resize.step_width;
|
2024-02-07 18:36:47 +00:00
|
|
|
StateTicks draw_time = start_tick + current_schedule->offset;
|
2024-01-28 01:48:54 +00:00
|
|
|
bool last = last_dispatch == (int32_t)current_schedule->offset;
|
|
|
|
bool next = next_offset == (int32_t)current_schedule->offset;
|
|
|
|
TextColour colour;
|
|
|
|
if (this->selected_slot == current_schedule->offset) {
|
|
|
|
colour = TC_WHITE;
|
|
|
|
} else {
|
|
|
|
colour = draw_time >= end_tick ? TC_RED : TC_BLACK;
|
|
|
|
}
|
|
|
|
auto flags = current_schedule->flags;
|
|
|
|
if (ds.GetScheduledDispatchReuseSlots()) ClrBit(flags, DispatchSlot::SDSF_REUSE_SLOT);
|
2024-01-27 21:31:40 +00:00
|
|
|
this->DrawScheduledTime(draw_time, x + WidgetDimensions::scaled.framerect.left, x + this->resize.step_width - 1 - (2 * WidgetDimensions::scaled.framerect.left),
|
2024-01-28 01:48:54 +00:00
|
|
|
y, colour, last, next, flags != 0);
|
2017-05-29 18:37:08 +00:00
|
|
|
current_schedule++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_SUMMARY_PANEL: {
|
2024-01-13 23:44:39 +00:00
|
|
|
const_cast<SchdispatchWindow*>(this)->next_departure_update = INT64_MAX;
|
2022-12-04 20:25:38 +00:00
|
|
|
Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
|
|
|
|
int y = ir.top;
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2024-02-22 21:53:54 +00:00
|
|
|
if (!this->TimeUnitsUsable()) {
|
|
|
|
const Dimension warning_dimensions = GetSpriteSize(SPR_WARNING_SIGN);
|
|
|
|
int left = ir.left;
|
|
|
|
int right = ir.right;
|
|
|
|
const bool rtl = (_current_text_dir == TD_RTL);
|
|
|
|
DrawSprite(SPR_WARNING_SIGN, 0, rtl ? right - warning_dimensions.width - 5 : left + 5, y);
|
|
|
|
if (rtl) {
|
|
|
|
right -= (warning_dimensions.width + 10);
|
|
|
|
} else {
|
|
|
|
left += (warning_dimensions.width + 10);
|
|
|
|
}
|
|
|
|
DrawStringMultiLine(left, right, y, ir.bottom, STR_CANNOT_ENABLE_BECAUSE_TIME_UNITS_UNUSABLE, TC_BLACK);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-02-07 18:36:47 +00:00
|
|
|
auto set_next_departure_update = [&](StateTicks time) {
|
2024-01-21 18:09:24 +00:00
|
|
|
if (time < this->next_departure_update) const_cast<SchdispatchWindow*>(this)->next_departure_update = time;
|
|
|
|
};
|
|
|
|
|
2024-02-18 23:11:00 +00:00
|
|
|
auto draw_warning_generic = [&](StringID text, TextColour colour) {
|
|
|
|
const Dimension warning_dimensions = GetSpriteSize(SPR_WARNING_SIGN);
|
|
|
|
int step_height = std::max<int>(warning_dimensions.height, GetCharacterHeight(FS_NORMAL));
|
|
|
|
int left = ir.left;
|
|
|
|
int right = ir.right;
|
|
|
|
const bool rtl = (_current_text_dir == TD_RTL);
|
|
|
|
DrawSprite(SPR_WARNING_SIGN, 0, rtl ? right - warning_dimensions.width - 5 : left + 5, y + (step_height - warning_dimensions.height) / 2);
|
|
|
|
if (rtl) {
|
|
|
|
right -= (warning_dimensions.width + 10);
|
|
|
|
} else {
|
|
|
|
left += (warning_dimensions.width + 10);
|
|
|
|
}
|
|
|
|
DrawString(left, right, y + (step_height - GetCharacterHeight(FS_NORMAL)) / 2, text, colour);
|
|
|
|
y += step_height;
|
|
|
|
};
|
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
if (!HasBit(v->vehicle_flags, VF_SCHEDULED_DISPATCH) || !this->IsScheduleSelected()) {
|
2023-12-17 01:16:40 +00:00
|
|
|
y += GetCharacterHeight(FS_NORMAL);
|
2022-12-04 20:25:38 +00:00
|
|
|
DrawString(ir.left, ir.right, y, STR_SCHDISPATCH_SUMMARY_NOT_ENABLED);
|
2024-02-18 23:11:00 +00:00
|
|
|
y += GetCharacterHeight(FS_NORMAL) * 2;
|
|
|
|
|
|
|
|
if (HasBit(v->vehicle_flags, VF_TIMETABLE_SEPARATION)) {
|
|
|
|
draw_warning_generic(STR_CANNOT_ENABLE_BECAUSE_AUTO_SEPARATION, TC_BLACK);
|
|
|
|
} else if (v->HasUnbunchingOrder()) {
|
|
|
|
draw_warning_generic(STR_CANNOT_ENABLE_BECAUSE_UNBUNCHING, TC_BLACK);
|
|
|
|
}
|
2017-05-29 18:37:08 +00:00
|
|
|
} else {
|
2022-01-13 19:46:43 +00:00
|
|
|
const DispatchSchedule &ds = this->GetSelectedSchedule();
|
2022-01-13 23:04:38 +00:00
|
|
|
|
2024-01-13 23:44:39 +00:00
|
|
|
uint warnings = 0;
|
2024-01-22 18:28:01 +00:00
|
|
|
uint extra_lines = 0;
|
|
|
|
|
2022-01-13 23:04:38 +00:00
|
|
|
auto draw_warning = [&](StringID text) {
|
2024-02-18 23:11:00 +00:00
|
|
|
draw_warning_generic(text, TC_FROMSTRING);
|
2024-01-13 23:44:39 +00:00
|
|
|
warnings++;
|
2022-01-13 23:04:38 +00:00
|
|
|
};
|
2017-06-06 19:05:13 +00:00
|
|
|
|
2024-02-07 18:36:47 +00:00
|
|
|
auto departure_time_warnings = [&](StateTicks time) {
|
|
|
|
if (_settings_time.time_in_minutes && time > (_state_ticks + (1350 * (uint)_settings_time.ticks_per_minute))) {
|
2024-01-21 18:09:24 +00:00
|
|
|
/* If the departure slot is more than 23 hours ahead of now, show a warning */
|
|
|
|
const TickMinutes now = _settings_time.NowInTickMinutes();
|
|
|
|
const TickMinutes target = _settings_time.ToTickMinutes(time);
|
|
|
|
const TickMinutes delta = target - now;
|
|
|
|
if (delta >= (23 * 60)) {
|
|
|
|
const uint hours = delta.base() / 60;
|
|
|
|
SetDParam(0, hours);
|
|
|
|
draw_warning(STR_SCHDISPATCH_MORE_THAN_N_HOURS_IN_FUTURE);
|
|
|
|
|
|
|
|
set_next_departure_update(_settings_time.FromTickMinutes(target - (hours * 60) + 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-01-27 20:03:50 +00:00
|
|
|
bool have_conditional = false;
|
2022-01-13 23:04:38 +00:00
|
|
|
int schedule_order_index = -1;
|
2020-01-27 20:03:50 +00:00
|
|
|
for (int n = 0; n < v->GetNumOrders(); n++) {
|
|
|
|
const Order *order = v->GetOrder(n);
|
|
|
|
if (order->IsType(OT_CONDITIONAL)) {
|
|
|
|
have_conditional = true;
|
|
|
|
}
|
2022-01-13 23:04:38 +00:00
|
|
|
if (order->GetDispatchScheduleIndex() == this->schedule_index) {
|
|
|
|
schedule_order_index = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (schedule_order_index < 0) {
|
|
|
|
draw_warning(STR_SCHDISPATCH_NOT_ASSIGNED_TO_ORDER);
|
|
|
|
} else {
|
|
|
|
const Order *order = v->GetOrder(schedule_order_index);
|
|
|
|
SetDParam(0, schedule_order_index + 1);
|
|
|
|
|
|
|
|
switch (order->GetType()) {
|
|
|
|
case OT_GOTO_STATION:
|
|
|
|
SetDParam(1, STR_STATION_NAME);
|
|
|
|
SetDParam(2, order->GetDestination());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OT_GOTO_WAYPOINT:
|
|
|
|
SetDParam(1, STR_WAYPOINT_NAME);
|
|
|
|
SetDParam(2, order->GetDestination());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OT_GOTO_DEPOT:
|
2022-02-15 22:56:21 +00:00
|
|
|
if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
|
|
|
|
if (v->type == VEH_AIRCRAFT) {
|
|
|
|
SetDParam(1, STR_ORDER_GO_TO_NEAREST_HANGAR);
|
|
|
|
} else {
|
|
|
|
SetDParam(1, STR_ORDER_GO_TO_NEAREST_DEPOT);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SetDParam(1, STR_DEPOT_NAME);
|
|
|
|
SetDParam(2, v->type);
|
|
|
|
SetDParam(3, order->GetDestination());
|
|
|
|
}
|
2022-01-13 23:04:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SetDParam(1, STR_INVALID_ORDER);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-12-04 20:25:38 +00:00
|
|
|
DrawString(ir.left, ir.right, y, STR_SCHDISPATCH_ASSIGNED_TO_ORDER);
|
2023-12-17 01:16:40 +00:00
|
|
|
y += GetCharacterHeight(FS_NORMAL);
|
2024-01-22 18:28:01 +00:00
|
|
|
extra_lines++;
|
2020-01-27 20:03:50 +00:00
|
|
|
}
|
2022-01-13 23:04:38 +00:00
|
|
|
|
2024-01-22 18:28:01 +00:00
|
|
|
y += WidgetDimensions::scaled.vsep_wide;
|
|
|
|
|
|
|
|
if (ds.GetScheduledDispatchLastDispatch() != INVALID_SCHEDULED_DISPATCH_OFFSET) {
|
2024-02-07 18:36:47 +00:00
|
|
|
const StateTicks last_departure = ds.GetScheduledDispatchStartTick() + ds.GetScheduledDispatchLastDispatch();
|
2024-01-22 18:28:01 +00:00
|
|
|
StringID str;
|
2024-02-07 18:36:47 +00:00
|
|
|
if (_state_ticks < last_departure) {
|
2024-01-22 18:28:01 +00:00
|
|
|
str = STR_SCHDISPATCH_SUMMARY_LAST_DEPARTURE_FUTURE;
|
|
|
|
set_next_departure_update(last_departure);
|
|
|
|
} else {
|
|
|
|
str = STR_SCHDISPATCH_SUMMARY_LAST_DEPARTURE_PAST;
|
|
|
|
}
|
|
|
|
SetDParam(0, last_departure);
|
|
|
|
DrawString(ir.left, ir.right, y, str);
|
|
|
|
y += GetCharacterHeight(FS_NORMAL);
|
2022-01-13 23:04:38 +00:00
|
|
|
|
2024-01-22 18:27:28 +00:00
|
|
|
departure_time_warnings(last_departure);
|
2024-01-22 18:28:01 +00:00
|
|
|
|
2024-02-07 18:36:47 +00:00
|
|
|
if (_settings_time.time_in_minutes && last_departure < (_state_ticks + (1350 * (uint)_settings_time.ticks_per_minute))) {
|
2024-01-22 18:28:01 +00:00
|
|
|
/* If the departure slot is more than 23 hours behind now, show a warning */
|
|
|
|
const TickMinutes now = _settings_time.NowInTickMinutes();
|
|
|
|
const TickMinutes target = _settings_time.ToTickMinutes(last_departure);
|
|
|
|
const TickMinutes delta = now - target;
|
|
|
|
if (delta >= (23 * 60)) {
|
|
|
|
const uint hours = delta.base() / 60;
|
|
|
|
SetDParam(0, hours);
|
|
|
|
DrawString(ir.left, ir.right, y, STR_SCHDISPATCH_MORE_THAN_N_HOURS_IN_PAST);
|
|
|
|
extra_lines++;
|
|
|
|
y += GetCharacterHeight(FS_NORMAL);
|
|
|
|
|
|
|
|
set_next_departure_update(_settings_time.FromTickMinutes(target + ((hours + 1) * 60) + 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DrawString(ir.left, ir.right, y, STR_SCHDISPATCH_SUMMARY_NO_LAST_DEPARTURE);
|
|
|
|
y += GetCharacterHeight(FS_NORMAL);
|
2024-01-22 18:27:28 +00:00
|
|
|
}
|
2024-01-13 23:44:39 +00:00
|
|
|
|
2024-02-07 18:36:47 +00:00
|
|
|
const StateTicks next_departure = GetScheduledDispatchTime(ds, _state_ticks);
|
2024-03-13 17:34:17 +00:00
|
|
|
if (next_departure != INVALID_STATE_TICKS) {
|
|
|
|
set_next_departure_update(next_departure + ds.GetScheduledDispatchDelay());
|
|
|
|
SetDParam(0, next_departure);
|
|
|
|
DrawString(ir.left, ir.right, y, STR_SCHDISPATCH_SUMMARY_NEXT_AVAILABLE_DEPARTURE);
|
|
|
|
}
|
2024-01-21 18:09:24 +00:00
|
|
|
y += GetCharacterHeight(FS_NORMAL);
|
|
|
|
|
|
|
|
departure_time_warnings(next_departure);
|
|
|
|
|
2024-01-22 18:28:01 +00:00
|
|
|
y += WidgetDimensions::scaled.vsep_wide;
|
|
|
|
|
2024-01-21 18:09:24 +00:00
|
|
|
if (ds.GetScheduledDispatchReuseSlots()) {
|
|
|
|
DrawString(ir.left, ir.right, y, STR_SCHDISPATCH_SUMMARY_REUSE_SLOTS_ENABLED);
|
2024-01-22 18:28:01 +00:00
|
|
|
extra_lines++;
|
|
|
|
y += GetCharacterHeight(FS_NORMAL);
|
2024-01-21 18:09:24 +00:00
|
|
|
} else if (!have_conditional) {
|
2022-03-04 18:17:44 +00:00
|
|
|
const int required_vehicle = CalculateMaxRequiredVehicle(v->orders->GetTimetableTotalDuration(), ds.GetScheduledDispatchDuration(), ds.GetScheduledDispatch());
|
2020-01-27 20:03:50 +00:00
|
|
|
if (required_vehicle > 0) {
|
|
|
|
SetDParam(0, required_vehicle);
|
2022-12-04 20:25:38 +00:00
|
|
|
DrawString(ir.left, ir.right, y, STR_SCHDISPATCH_SUMMARY_L1);
|
2024-01-22 18:28:01 +00:00
|
|
|
extra_lines++;
|
|
|
|
y += GetCharacterHeight(FS_NORMAL);
|
2020-01-27 20:03:50 +00:00
|
|
|
}
|
2018-10-24 01:21:56 +00:00
|
|
|
}
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
SetTimetableParams(0, ds.GetScheduledDispatchDuration(), true);
|
2022-12-04 20:25:38 +00:00
|
|
|
DrawString(ir.left, ir.right, y, STR_SCHDISPATCH_SUMMARY_L2);
|
2023-12-17 01:16:40 +00:00
|
|
|
y += GetCharacterHeight(FS_NORMAL);
|
2017-06-06 17:27:00 +00:00
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
SetDParam(0, ds.GetScheduledDispatchStartTick());
|
|
|
|
SetDParam(1, ds.GetScheduledDispatchStartTick() + ds.GetScheduledDispatchDuration());
|
2022-12-04 20:25:38 +00:00
|
|
|
DrawString(ir.left, ir.right, y, STR_SCHDISPATCH_SUMMARY_L3);
|
2023-12-17 01:16:40 +00:00
|
|
|
y += GetCharacterHeight(FS_NORMAL);
|
2020-02-09 23:17:19 +00:00
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
SetTimetableParams(0, ds.GetScheduledDispatchDelay());
|
2022-12-04 20:25:38 +00:00
|
|
|
DrawString(ir.left, ir.right, y, STR_SCHDISPATCH_SUMMARY_L4);
|
2023-12-17 01:16:40 +00:00
|
|
|
y += GetCharacterHeight(FS_NORMAL);
|
2021-11-24 02:12:19 +00:00
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
uint32_t duration = ds.GetScheduledDispatchDuration();
|
2024-01-28 01:48:54 +00:00
|
|
|
for (const DispatchSlot &slot : ds.GetScheduledDispatch()) {
|
|
|
|
if (slot.offset >= duration) {
|
2020-02-09 23:17:19 +00:00
|
|
|
draw_warning(STR_SCHDISPATCH_SLOT_OUTSIDE_SCHEDULE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-22 18:28:01 +00:00
|
|
|
if (warnings != this->warning_count || extra_lines != this->extra_line_count) {
|
2020-02-09 23:17:19 +00:00
|
|
|
SchdispatchWindow *mutable_this = const_cast<SchdispatchWindow *>(this);
|
|
|
|
mutable_this->warning_count = warnings;
|
2024-01-22 18:28:01 +00:00
|
|
|
mutable_this->extra_line_count = extra_lines;
|
2020-02-09 23:17:19 +00:00
|
|
|
mutable_this->ReInit();
|
|
|
|
}
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-01-28 11:50:44 +00:00
|
|
|
* Get slot and whether it's in the header section in the departure time matrix.
|
2017-05-29 18:37:08 +00:00
|
|
|
* @param x Horizontal position in the matrix widget in pixels.
|
|
|
|
* @param y Vertical position in the matrix widget in pixels.
|
2024-01-28 11:50:44 +00:00
|
|
|
* @return slot, and whether the position was in the header section
|
2017-05-29 18:37:08 +00:00
|
|
|
*/
|
2024-01-28 11:50:44 +00:00
|
|
|
std::pair<const DispatchSlot *, bool> GetSlotFromMatrixPoint(int x, int y) const
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
2024-01-28 11:50:44 +00:00
|
|
|
if (!this->IsScheduleSelected()) return { nullptr, false };
|
2022-01-13 19:46:43 +00:00
|
|
|
|
2017-05-29 18:37:08 +00:00
|
|
|
const NWidgetCore *matrix_widget = this->GetWidget<NWidgetCore>(WID_SCHDISPATCH_MATRIX);
|
|
|
|
/* In case of RTL the widgets are swapped as a whole */
|
|
|
|
if (_current_text_dir == TD_RTL) x = matrix_widget->current_x - x;
|
|
|
|
|
2024-01-27 21:31:40 +00:00
|
|
|
uint xt = x / this->resize.step_width;
|
|
|
|
int xm = x % this->resize.step_width;
|
2024-01-28 11:50:44 +00:00
|
|
|
if (xt >= this->num_columns) return { nullptr, false };
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2024-02-25 18:42:28 +00:00
|
|
|
int32_t row = y / this->resize.step_height;
|
2024-01-28 11:50:44 +00:00
|
|
|
if (row >= this->vscroll->GetCapacity()) return { nullptr, false };
|
2017-05-29 18:37:08 +00:00
|
|
|
|
|
|
|
uint pos = ((row + this->vscroll->GetPosition()) * this->num_columns) + xt;
|
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
const DispatchSchedule &ds = this->GetSelectedSchedule();
|
2024-01-28 11:50:44 +00:00
|
|
|
if (pos >= this->item_count || pos >= ds.GetScheduledDispatch().size()) return { nullptr, false };
|
|
|
|
|
|
|
|
return { &ds.GetScheduledDispatch()[pos], xm <= this->header_width };
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle click in the departure time matrix.
|
|
|
|
* @param x Horizontal position in the matrix widget in pixels.
|
|
|
|
* @param y Vertical position in the matrix widget in pixels.
|
|
|
|
*/
|
|
|
|
void TimeClick(int x, int y)
|
|
|
|
{
|
|
|
|
const DispatchSlot *slot;
|
|
|
|
bool is_header;
|
|
|
|
std::tie(slot, is_header) = this->GetSlotFromMatrixPoint(x, y);
|
2022-01-13 19:46:43 +00:00
|
|
|
|
2024-01-28 11:50:44 +00:00
|
|
|
if (slot == nullptr) {
|
2024-01-28 01:48:54 +00:00
|
|
|
if (this->selected_slot != UINT32_MAX) {
|
|
|
|
this->selected_slot = UINT32_MAX;
|
|
|
|
this->SetWidgetDirty(WID_SCHDISPATCH_MATRIX);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-28 11:50:44 +00:00
|
|
|
if (is_header && this->remove_slot_mode) {
|
|
|
|
DoCommandP(0, this->vehicle->index | (this->schedule_index << 20), slot->offset, CMD_SCHEDULED_DISPATCH_REMOVE | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
|
|
|
return;
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
2024-01-28 01:48:54 +00:00
|
|
|
|
2024-01-28 11:50:44 +00:00
|
|
|
if (this->selected_slot == slot->offset) {
|
2024-01-28 01:48:54 +00:00
|
|
|
this->selected_slot = UINT32_MAX;
|
|
|
|
} else {
|
2024-01-28 11:50:44 +00:00
|
|
|
this->selected_slot = slot->offset;
|
2024-01-28 01:48:54 +00:00
|
|
|
}
|
|
|
|
this->SetWidgetDirty(WID_SCHDISPATCH_MATRIX);
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
int32_t ProcessDurationForQueryString(int32_t duration) const
|
2021-11-24 02:10:22 +00:00
|
|
|
{
|
2024-02-07 20:12:39 +00:00
|
|
|
if (!_settings_client.gui.timetable_in_ticks) duration = RoundDivSU(duration, TimetableDisplayUnitSize());
|
2021-11-24 02:10:22 +00:00
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetQueryStringCaptionOffset() const
|
|
|
|
{
|
|
|
|
if (_settings_client.gui.timetable_in_ticks) return 2;
|
|
|
|
if (_settings_time.time_in_minutes) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-01-02 14:31:56 +00:00
|
|
|
virtual void OnClick(Point pt, WidgetID widget, int click_count) override
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
const Vehicle *v = this->vehicle;
|
|
|
|
|
|
|
|
this->clicked_widget = widget;
|
2023-09-15 19:59:08 +00:00
|
|
|
this->CloseChildWindows(WC_QUERY_STRING);
|
2017-05-29 18:37:08 +00:00
|
|
|
|
|
|
|
switch (widget) {
|
|
|
|
case WID_SCHDISPATCH_MATRIX: { /* List */
|
|
|
|
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_SCHDISPATCH_MATRIX);
|
|
|
|
this->TimeClick(pt.x - nwi->pos_x, pt.y - nwi->pos_y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_ENABLED: {
|
2024-01-07 16:41:53 +00:00
|
|
|
uint32_t p2 = 0;
|
2017-05-29 18:37:08 +00:00
|
|
|
if (!HasBit(v->vehicle_flags, VF_SCHEDULED_DISPATCH)) SetBit(p2, 0);
|
2017-09-04 03:40:37 +00:00
|
|
|
|
2017-05-29 18:37:08 +00:00
|
|
|
DoCommandP(0, v->index, p2, CMD_SCHEDULED_DISPATCH | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
2022-03-04 18:17:44 +00:00
|
|
|
if (HasBit(p2, 0) && this->vehicle->orders != nullptr && this->vehicle->orders->GetScheduledDispatchScheduleCount() == 0) {
|
2022-01-13 19:46:43 +00:00
|
|
|
AddNewScheduledDispatchSchedule(v->index);
|
|
|
|
}
|
2017-05-29 18:37:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_ADD: {
|
2022-01-13 19:46:43 +00:00
|
|
|
if (!this->IsScheduleSelected()) break;
|
2021-11-28 02:25:42 +00:00
|
|
|
if (_settings_time.time_in_minutes && _ctrl_pressed) {
|
|
|
|
void ShowScheduledDispatchAddSlotsWindow(SchdispatchWindow *parent, int window_number);
|
|
|
|
ShowScheduledDispatchAddSlotsWindow(this, v->index);
|
|
|
|
} else if (_settings_time.time_in_minutes && _settings_client.gui.timetable_start_text_entry) {
|
2017-05-29 18:37:08 +00:00
|
|
|
ShowQueryString(STR_EMPTY, STR_SCHDISPATCH_ADD_CAPTION, 31, this, CS_NUMERAL, QSF_NONE);
|
|
|
|
} else {
|
2024-02-13 21:34:09 +00:00
|
|
|
ShowSetDateWindow(this, v->index | (this->schedule_index << 20), _state_ticks, EconTime::CurYear(), EconTime::CurYear() + 15, ScheduleAddCallback, STR_SCHDISPATCH_ADD, STR_SCHDISPATCH_ADD_TOOLTIP);
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_SET_DURATION: {
|
2022-01-13 19:46:43 +00:00
|
|
|
if (!this->IsScheduleSelected()) break;
|
2023-05-10 19:06:19 +00:00
|
|
|
CharSetFilter charset_filter = _settings_client.gui.timetable_in_ticks ? CS_NUMERAL : CS_NUMERAL_DECIMAL;
|
2022-01-13 19:46:43 +00:00
|
|
|
SetDParam(0, ProcessDurationForQueryString(this->GetSelectedSchedule().GetScheduledDispatchDuration()));
|
2023-05-10 19:06:19 +00:00
|
|
|
ShowQueryString(STR_JUST_INT, STR_SCHDISPATCH_DURATION_CAPTION_MINUTE + this->GetQueryStringCaptionOffset(), 31, this, charset_filter, QSF_NONE);
|
2017-05-29 18:37:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_SET_START_DATE: {
|
2022-01-13 19:46:43 +00:00
|
|
|
if (!this->IsScheduleSelected()) break;
|
2020-06-23 20:05:21 +00:00
|
|
|
if (_settings_time.time_in_minutes && _settings_client.gui.timetable_start_text_entry) {
|
2023-12-19 01:03:18 +00:00
|
|
|
SetDParam(0, _settings_time.NowInTickMinutes().ClockHHMM());
|
2017-05-29 18:37:08 +00:00
|
|
|
ShowQueryString(STR_JUST_INT, STR_SCHDISPATCH_START_CAPTION_MINUTE, 31, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
|
|
|
|
} else {
|
2024-02-13 21:34:09 +00:00
|
|
|
ShowSetDateWindow(this, v->index | (this->schedule_index << 20), _state_ticks, EconTime::CurYear(), EconTime::CurYear() + 15, SetScheduleStartDateCallback, STR_SCHDISPATCH_SET_START, STR_SCHDISPATCH_START_TOOLTIP);
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_SET_DELAY: {
|
2022-01-13 19:46:43 +00:00
|
|
|
if (!this->IsScheduleSelected()) break;
|
2023-05-10 19:06:19 +00:00
|
|
|
CharSetFilter charset_filter = _settings_client.gui.timetable_in_ticks ? CS_NUMERAL : CS_NUMERAL_DECIMAL;
|
2022-01-13 19:46:43 +00:00
|
|
|
SetDParam(0, ProcessDurationForQueryString(this->GetSelectedSchedule().GetScheduledDispatchDelay()));
|
2023-05-10 19:06:19 +00:00
|
|
|
ShowQueryString(STR_JUST_INT, STR_SCHDISPATCH_DELAY_CAPTION_MINUTE + this->GetQueryStringCaptionOffset(), 31, this, charset_filter, QSF_NONE);
|
2017-05-29 18:37:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-12-18 12:46:25 +00:00
|
|
|
case WID_SCHDISPATCH_MANAGEMENT: {
|
2022-01-13 19:46:43 +00:00
|
|
|
if (!this->IsScheduleSelected()) break;
|
2024-01-21 18:09:24 +00:00
|
|
|
const DispatchSchedule &schedule = this->GetSelectedSchedule();
|
2021-12-18 12:46:25 +00:00
|
|
|
DropDownList list;
|
2022-02-05 01:27:44 +00:00
|
|
|
auto add_item = [&](StringID string, int result) {
|
|
|
|
std::unique_ptr<DropDownListStringItem> item(new DropDownListStringItem(string, result, false));
|
|
|
|
item->SetColourFlags(TC_FORCED);
|
|
|
|
list.emplace_back(std::move(item));
|
|
|
|
};
|
|
|
|
add_item(STR_SCHDISPATCH_RESET_LAST_DISPATCH, SCH_MD_RESET_LAST_DISPATCHED);
|
|
|
|
add_item(STR_SCHDISPATCH_CLEAR, SCH_MD_CLEAR_SCHEDULE);
|
|
|
|
add_item(STR_SCHDISPATCH_REMOVE_SCHEDULE, SCH_MD_REMOVE_SCHEDULE);
|
2023-05-07 13:02:37 +00:00
|
|
|
add_item(STR_SCHDISPATCH_DUPLICATE_SCHEDULE, SCH_MD_DUPLICATE_SCHEDULE);
|
2023-05-07 19:06:47 +00:00
|
|
|
add_item(STR_SCHDISPATCH_APPEND_VEHICLE_SCHEDULES, SCH_MD_APPEND_VEHICLE_SCHEDULES);
|
2024-01-28 01:48:54 +00:00
|
|
|
list.push_back(std::make_unique<DropDownListCheckedItem>(schedule.GetScheduledDispatchReuseSlots(), STR_SCHDISPATCH_REUSE_DEPARTURE_SLOTS, SCH_MD_REUSE_DEPARTURE_SLOTS, false));
|
2021-12-18 12:46:25 +00:00
|
|
|
ShowDropDownList(this, std::move(list), -1, WID_SCHDISPATCH_MANAGEMENT);
|
2017-05-29 18:37:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-01-13 19:46:43 +00:00
|
|
|
|
|
|
|
case WID_SCHDISPATCH_PREV:
|
|
|
|
if (!this->IsScheduleSelected()) break;
|
2024-01-28 01:48:54 +00:00
|
|
|
if (this->schedule_index > 0) {
|
|
|
|
this->schedule_index--;
|
|
|
|
this->selected_slot = UINT32_MAX;
|
|
|
|
}
|
2022-01-13 19:46:43 +00:00
|
|
|
this->ReInit();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_NEXT:
|
|
|
|
if (!this->IsScheduleSelected()) break;
|
2024-01-28 01:48:54 +00:00
|
|
|
if (this->schedule_index < (int)(this->vehicle->orders->GetScheduledDispatchScheduleCount() - 1)) {
|
|
|
|
this->schedule_index++;
|
|
|
|
this->selected_slot = UINT32_MAX;
|
|
|
|
}
|
2022-01-13 19:46:43 +00:00
|
|
|
this->ReInit();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_ADD_SCHEDULE:
|
|
|
|
AddNewScheduledDispatchSchedule(this->vehicle->index);
|
|
|
|
break;
|
2023-04-29 11:19:28 +00:00
|
|
|
|
|
|
|
case WID_SCHDISPATCH_RENAME:
|
|
|
|
if (!this->IsScheduleSelected()) break;
|
|
|
|
SetDParamStr(0, this->GetSelectedSchedule().ScheduleName().c_str());
|
|
|
|
ShowQueryString(STR_JUST_RAW_STRING, STR_SCHDISPATCH_RENAME_SCHEDULE_CAPTION,
|
|
|
|
MAX_LENGTH_VEHICLE_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
|
|
|
|
break;
|
2023-05-09 19:16:36 +00:00
|
|
|
|
2023-09-23 11:05:05 +00:00
|
|
|
case WID_SCHDISPATCH_ADJUST: {
|
2023-05-09 19:16:36 +00:00
|
|
|
if (!this->IsScheduleSelected()) break;
|
2023-05-10 19:06:19 +00:00
|
|
|
CharSetFilter charset_filter = _settings_client.gui.timetable_in_ticks ? CS_NUMERAL_SIGNED : CS_NUMERAL_DECIMAL_SIGNED;
|
2023-05-09 19:16:36 +00:00
|
|
|
SetDParam(0, 0);
|
2023-05-10 19:06:19 +00:00
|
|
|
ShowQueryString(STR_JUST_INT, STR_SCHDISPATCH_ADJUST_CAPTION_MINUTE + this->GetQueryStringCaptionOffset(), 31, this, charset_filter, QSF_NONE);
|
2023-05-09 19:16:36 +00:00
|
|
|
break;
|
2023-09-23 11:05:05 +00:00
|
|
|
}
|
|
|
|
|
2024-01-27 21:31:40 +00:00
|
|
|
case WID_SCHDISPATCH_REMOVE: {
|
|
|
|
if (!this->IsScheduleSelected()) break;
|
|
|
|
this->remove_slot_mode = !this->remove_slot_mode;
|
|
|
|
this->SetWidgetLoweredState(WID_SCHDISPATCH_REMOVE, this->remove_slot_mode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-01-28 01:48:54 +00:00
|
|
|
case WID_SCHDISPATCH_MANAGE_SLOT: {
|
|
|
|
const DispatchSlot *selected_slot = this->GetSelectedDispatchSlot();
|
|
|
|
if (selected_slot == nullptr) break;
|
|
|
|
const DispatchSchedule &schedule = this->GetSelectedSchedule();
|
|
|
|
|
|
|
|
DropDownList list;
|
2024-01-28 17:14:03 +00:00
|
|
|
auto add_item = [&](StringID str, uint bit, bool disabled) {
|
|
|
|
list.push_back(std::make_unique<DropDownListCheckedItem>(HasBit(selected_slot->flags, bit), str, bit, disabled));
|
|
|
|
};
|
|
|
|
add_item(STR_SCHDISPATCH_REUSE_THIS_DEPARTURE_SLOT, DispatchSlot::SDSF_REUSE_SLOT, schedule.GetScheduledDispatchReuseSlots());
|
|
|
|
for (uint8_t flag_bit = DispatchSlot::SDSF_FIRST_TAG; flag_bit <= DispatchSlot::SDSF_LAST_TAG; flag_bit++) {
|
|
|
|
SetDParam(0, 1 + flag_bit - DispatchSlot::SDSF_FIRST_TAG);
|
|
|
|
add_item(STR_SCHDISPATCH_REUSE_THIS_DEPARTURE_TAG, flag_bit, false);
|
|
|
|
}
|
|
|
|
|
2024-01-28 01:48:54 +00:00
|
|
|
ShowDropDownList(this, std::move(list), -1, WID_SCHDISPATCH_MANAGE_SLOT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-09-23 11:05:05 +00:00
|
|
|
case WID_SCHDISPATCH_MOVE_LEFT:
|
|
|
|
if (!this->IsScheduleSelected()) break;
|
|
|
|
if (this->schedule_index > 0) {
|
|
|
|
DoCommandP(0, this->vehicle->index, (this->schedule_index - 1) | (this->schedule_index << 16), CMD_SCHEDULED_DISPATCH_SWAP_SCHEDULES | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE), CcSwapSchDispatchSchedules);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_MOVE_RIGHT:
|
|
|
|
if (!this->IsScheduleSelected()) break;
|
|
|
|
if (this->schedule_index < (int)(this->vehicle->orders->GetScheduledDispatchScheduleCount() - 1)) {
|
|
|
|
DoCommandP(0, this->vehicle->index, (this->schedule_index + 1) | (this->schedule_index << 16), CMD_SCHEDULED_DISPATCH_SWAP_SCHEDULES | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE), CcSwapSchDispatchSchedules);
|
|
|
|
}
|
|
|
|
break;
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
|
2022-01-14 23:24:41 +00:00
|
|
|
static void ClearScheduleCallback(Window *win, bool confirmed)
|
|
|
|
{
|
|
|
|
if (confirmed) {
|
|
|
|
SchdispatchWindow *w = (SchdispatchWindow*)win;
|
|
|
|
if (w->IsScheduleSelected()) {
|
|
|
|
DoCommandP(0, w->vehicle->index | (w->schedule_index << 20), 0, CMD_SCHEDULED_DISPATCH_CLEAR | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RemoveScheduleCallback(Window *win, bool confirmed)
|
|
|
|
{
|
|
|
|
if (confirmed) {
|
|
|
|
SchdispatchWindow *w = (SchdispatchWindow*)win;
|
|
|
|
if (w->IsScheduleSelected()) {
|
|
|
|
DoCommandP(0, w->vehicle->index | (w->schedule_index << 20), 0, CMD_SCHEDULED_DISPATCH_REMOVE_SCHEDULE | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-02 14:31:56 +00:00
|
|
|
void OnDropdownSelect(WidgetID widget, int index) override
|
2021-12-18 12:46:25 +00:00
|
|
|
{
|
2024-02-22 21:53:54 +00:00
|
|
|
if (!this->TimeUnitsUsable()) return;
|
|
|
|
|
2021-12-18 12:46:25 +00:00
|
|
|
switch (widget) {
|
|
|
|
case WID_SCHDISPATCH_MANAGEMENT: {
|
2022-01-13 19:46:43 +00:00
|
|
|
if (!this->IsScheduleSelected()) break;
|
2021-12-18 12:46:25 +00:00
|
|
|
switch((ManagementDropdown)index) {
|
|
|
|
case SCH_MD_RESET_LAST_DISPATCHED:
|
2022-01-13 19:46:43 +00:00
|
|
|
DoCommandP(0, this->vehicle->index | (this->schedule_index << 20), 0, CMD_SCHEDULED_DISPATCH_RESET_LAST_DISPATCH | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
2021-12-18 12:46:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_MD_CLEAR_SCHEDULE:
|
2022-01-14 23:24:41 +00:00
|
|
|
if (this->GetSelectedSchedule().GetScheduledDispatch().empty()) return;
|
|
|
|
SetDParam(0, (uint)this->GetSelectedSchedule().GetScheduledDispatch().size());
|
|
|
|
ShowQuery(STR_SCHDISPATCH_QUERY_CLEAR_SCHEDULE_CAPTION, STR_SCHDISPATCH_QUERY_CLEAR_SCHEDULE_TEXT, this, ClearScheduleCallback);
|
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_MD_REMOVE_SCHEDULE:
|
2022-01-14 23:24:41 +00:00
|
|
|
SetDParam(0, (uint)this->GetSelectedSchedule().GetScheduledDispatch().size());
|
|
|
|
ShowQuery(STR_SCHDISPATCH_QUERY_REMOVE_SCHEDULE_CAPTION, STR_SCHDISPATCH_QUERY_REMOVE_SCHEDULE_TEXT, this, RemoveScheduleCallback);
|
2021-12-18 12:46:25 +00:00
|
|
|
break;
|
2023-05-07 13:02:37 +00:00
|
|
|
|
|
|
|
case SCH_MD_DUPLICATE_SCHEDULE:
|
|
|
|
DoCommandP(0, this->vehicle->index | (this->schedule_index << 20), 0, CMD_SCHEDULED_DISPATCH_DUPLICATE_SCHEDULE | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
|
|
|
break;
|
2023-05-07 19:06:47 +00:00
|
|
|
|
|
|
|
case SCH_MD_APPEND_VEHICLE_SCHEDULES: {
|
|
|
|
static const CursorID clone_icons[] = {
|
|
|
|
SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH,
|
|
|
|
SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE
|
|
|
|
};
|
|
|
|
SetObjectToPlaceWnd(clone_icons[this->vehicle->type], PAL_NONE, HT_VEHICLE, this);
|
|
|
|
break;
|
|
|
|
}
|
2024-01-21 18:09:24 +00:00
|
|
|
|
|
|
|
case SCH_MD_REUSE_DEPARTURE_SLOTS: {
|
|
|
|
DoCommandP(0, this->vehicle->index | (this->schedule_index << 20), this->GetSelectedSchedule().GetScheduledDispatchReuseSlots() ? 0 : 1, CMD_SCHEDULED_DISPATCH_SET_REUSE_SLOTS | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
|
|
|
break;
|
|
|
|
}
|
2021-12-18 12:46:25 +00:00
|
|
|
}
|
2024-01-28 01:48:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_MANAGE_SLOT: {
|
|
|
|
const DispatchSlot *selected_slot = this->GetSelectedDispatchSlot();
|
|
|
|
if (selected_slot == nullptr) break;
|
|
|
|
|
2024-01-28 17:14:03 +00:00
|
|
|
uint64_t p3 = 0;
|
|
|
|
SetBit(p3, index + 16);
|
|
|
|
if (!HasBit(selected_slot->flags, index)) SetBit(p3, index);
|
|
|
|
DoCommandPEx(0, this->vehicle->index | (this->schedule_index << 20), this->selected_slot, p3, CMD_SCHEDULED_DISPATCH_SET_SLOT_FLAGS | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE), nullptr, nullptr, 0);
|
2024-01-28 01:48:54 +00:00
|
|
|
break;
|
2021-12-18 12:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-28 10:05:14 +00:00
|
|
|
virtual void OnQueryTextFinished(char *str) override
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
2024-02-22 21:53:54 +00:00
|
|
|
if (!this->TimeUnitsUsable()) return;
|
|
|
|
|
2019-04-11 17:14:13 +00:00
|
|
|
if (str == nullptr) return;
|
2017-05-29 18:37:08 +00:00
|
|
|
const Vehicle *v = this->vehicle;
|
|
|
|
|
|
|
|
switch (this->clicked_widget) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_ADD: {
|
2022-01-13 19:46:43 +00:00
|
|
|
if (!this->IsScheduleSelected()) break;
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2023-02-15 22:53:02 +00:00
|
|
|
if (StrEmpty(str)) break;
|
|
|
|
|
|
|
|
char *end;
|
2024-01-07 16:41:53 +00:00
|
|
|
int32_t val = std::strtoul(str, &end, 10);
|
2023-02-15 22:53:02 +00:00
|
|
|
if (val >= 0 && end != nullptr && *end == 0) {
|
2017-05-29 18:37:08 +00:00
|
|
|
uint minutes = (val % 100) % 60;
|
|
|
|
uint hours = (val / 100) % 24;
|
2024-02-07 18:36:47 +00:00
|
|
|
StateTicks slot = _settings_time.FromTickMinutes(_settings_time.NowInTickMinutes().ToSameDayClockTime(hours, minutes));
|
2022-01-13 19:46:43 +00:00
|
|
|
ScheduleAddIntl(v->index | (this->schedule_index << 20), slot, 0, 0);
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_SET_START_DATE: {
|
2022-01-13 19:46:43 +00:00
|
|
|
if (!this->IsScheduleSelected()) break;
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2023-02-15 22:53:02 +00:00
|
|
|
if (StrEmpty(str)) break;
|
|
|
|
|
|
|
|
char *end;
|
2024-01-07 16:41:53 +00:00
|
|
|
int32_t val = std::strtoul(str, &end, 10);
|
2023-02-15 22:53:02 +00:00
|
|
|
if (val >= 0 && end != nullptr && *end == 0) {
|
2017-05-29 18:37:08 +00:00
|
|
|
uint minutes = (val % 100) % 60;
|
|
|
|
uint hours = (val / 100) % 24;
|
2024-02-07 18:36:47 +00:00
|
|
|
StateTicks start = _settings_time.FromTickMinutes(_settings_time.NowInTickMinutes().ToSameDayClockTime(hours, minutes));
|
2022-01-13 19:46:43 +00:00
|
|
|
SetScheduleStartDateIntl(v->index | (this->schedule_index << 20), start);
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_SET_DURATION: {
|
2022-01-13 19:46:43 +00:00
|
|
|
if (!this->IsScheduleSelected()) break;
|
2023-05-10 19:06:19 +00:00
|
|
|
Ticks val = ParseTimetableDuration(str);
|
2017-05-29 18:37:08 +00:00
|
|
|
|
|
|
|
if (val > 0) {
|
2022-01-13 19:46:43 +00:00
|
|
|
DoCommandP(0, v->index | (this->schedule_index << 20), val, CMD_SCHEDULED_DISPATCH_SET_DURATION | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_SET_DELAY: {
|
2022-01-13 19:46:43 +00:00
|
|
|
if (!this->IsScheduleSelected()) break;
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2023-02-15 22:53:02 +00:00
|
|
|
if (StrEmpty(str)) break;
|
|
|
|
|
2023-05-10 19:06:19 +00:00
|
|
|
DoCommandP(0, v->index | (this->schedule_index << 20), ParseTimetableDuration(str), CMD_SCHEDULED_DISPATCH_SET_DELAY | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
2017-05-29 18:37:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-04-29 11:19:28 +00:00
|
|
|
|
|
|
|
case WID_SCHDISPATCH_RENAME: {
|
|
|
|
if (str == nullptr) return;
|
|
|
|
|
|
|
|
DoCommandP(0, v->index | (this->schedule_index << 20), 0, CMD_SCHEDULED_DISPATCH_RENAME_SCHEDULE | CMD_MSG(STR_ERROR_CAN_T_RENAME_SCHEDULE), nullptr, str);
|
|
|
|
break;
|
|
|
|
}
|
2023-05-09 19:16:36 +00:00
|
|
|
|
|
|
|
case WID_SCHDISPATCH_ADJUST: {
|
|
|
|
if (!this->IsScheduleSelected()) break;
|
2023-05-10 19:06:19 +00:00
|
|
|
Ticks val = ParseTimetableDuration(str);
|
2023-05-09 19:16:36 +00:00
|
|
|
|
|
|
|
if (val != 0) {
|
|
|
|
DoCommandP(0, v->index | (this->schedule_index << 20), val, CMD_SCHEDULED_DISPATCH_ADJUST | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
|
2019-04-28 10:05:14 +00:00
|
|
|
virtual void OnResize() override
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
this->vscroll->SetCapacityFromWidget(this, WID_SCHDISPATCH_MATRIX);
|
|
|
|
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_SCHDISPATCH_MATRIX);
|
|
|
|
this->num_columns = nwi->current_x / nwi->resize_x;
|
|
|
|
}
|
|
|
|
|
2019-04-28 10:05:14 +00:00
|
|
|
virtual void OnFocus(Window *previously_focused_window) override
|
2017-05-29 18:37:08 +00:00
|
|
|
{
|
|
|
|
if (HasFocusedVehicleChanged(this->window_number, previously_focused_window)) {
|
2023-05-06 18:14:39 +00:00
|
|
|
MarkDirtyFocusedRoutePaths(this->vehicle);
|
2017-05-29 18:37:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-07 19:06:47 +00:00
|
|
|
bool OnVehicleSelect(const Vehicle *v) override
|
|
|
|
{
|
|
|
|
if (v->orders == nullptr || v->orders->GetScheduledDispatchScheduleCount() == 0) return false;
|
|
|
|
|
|
|
|
DoCommandP(0, this->vehicle->index, v->index, CMD_SCHEDULED_DISPATCH_APPEND_VEHICLE_SCHEDULE | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
|
|
|
ResetObjectToPlace();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-29 18:37:08 +00:00
|
|
|
const Vehicle *GetVehicle()
|
|
|
|
{
|
|
|
|
return this->vehicle;
|
|
|
|
}
|
2021-11-28 02:25:42 +00:00
|
|
|
|
|
|
|
void AddMultipleDepartureSlots(uint start, uint step, uint end)
|
|
|
|
{
|
2022-12-27 00:13:37 +00:00
|
|
|
bool wrap_mode = false;
|
|
|
|
if (end < start) {
|
|
|
|
const DispatchSchedule &ds = this->GetSelectedSchedule();
|
|
|
|
if (ds.GetScheduledDispatchDuration() == (1440 * _settings_time.ticks_per_minute)) {
|
|
|
|
/* 24 hour timetabling */
|
|
|
|
end += 1440;
|
|
|
|
wrap_mode = true;
|
|
|
|
}
|
|
|
|
}
|
2022-01-13 19:46:43 +00:00
|
|
|
if (end < start || step == 0 || !this->IsScheduleSelected()) return;
|
2021-11-28 02:25:42 +00:00
|
|
|
|
2024-02-07 18:36:47 +00:00
|
|
|
StateTicks slot = _settings_time.FromTickMinutes(_settings_time.NowInTickMinutes().ToSameDayClockTime(0, start));
|
2022-12-27 00:13:37 +00:00
|
|
|
ScheduleAddIntl(this->vehicle->index | (this->schedule_index << 20), slot, (end - start) / step, step * _settings_time.ticks_per_minute, wrap_mode);
|
2021-11-28 02:25:42 +00:00
|
|
|
}
|
2017-05-29 18:37:08 +00:00
|
|
|
};
|
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
void CcAddNewSchDispatchSchedule(const CommandCost &result, TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd)
|
2022-01-13 19:46:43 +00:00
|
|
|
{
|
|
|
|
SchdispatchWindow *w = dynamic_cast<SchdispatchWindow*>(FindWindowById(WC_SCHDISPATCH_SLOTS, p1));
|
|
|
|
if (w != nullptr) {
|
|
|
|
w->schedule_index = INT_MAX;
|
|
|
|
w->AutoSelectSchedule();
|
|
|
|
w->ReInit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
void CcSwapSchDispatchSchedules(const CommandCost &result, TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd)
|
2023-09-23 11:05:05 +00:00
|
|
|
{
|
|
|
|
SchdispatchWindow *w = dynamic_cast<SchdispatchWindow*>(FindWindowById(WC_SCHDISPATCH_SLOTS, p1));
|
|
|
|
if (w != nullptr) {
|
|
|
|
w->schedule_index = GB(p2, 0, 16);
|
|
|
|
w->AutoSelectSchedule();
|
|
|
|
w->ReInit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-21 22:24:49 +00:00
|
|
|
static constexpr NWidgetPart _nested_schdispatch_widgets[] = {
|
2017-05-29 18:37:08 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
2023-04-29 11:19:28 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SCHDISPATCH_RENAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_SCHDISPATCH_RENAME_SCHEDULE_TOOLTIP),
|
2023-09-23 11:05:05 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SCHDISPATCH_MOVE_LEFT), SetMinimalSize(12, 14), SetDataTip(SPR_ARROW_LEFT, STR_SCHDISPATCH_MOVE_SCHEDULE),
|
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SCHDISPATCH_MOVE_RIGHT), SetMinimalSize(12, 14), SetDataTip(SPR_ARROW_RIGHT, STR_SCHDISPATCH_MOVE_SCHEDULE),
|
2017-05-29 18:37:08 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, WID_SCHDISPATCH_CAPTION), SetDataTip(STR_SCHDISPATCH_CAPTION, STR_NULL),
|
|
|
|
NWidget(WWT_SHADEBOX, COLOUR_GREY),
|
|
|
|
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
|
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_GREY),
|
|
|
|
EndContainer(),
|
2022-01-13 19:46:43 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2024-02-18 23:11:00 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCHDISPATCH_ENABLED), SetDataTip(STR_SCHDISPATCH_ENABLED, STR_NULL), SetFill(1, 1), SetResize(1, 0),
|
2023-04-29 11:19:28 +00:00
|
|
|
NWidget(WWT_TEXT, COLOUR_GREY, WID_SCHDISPATCH_HEADER), SetAlignment(SA_CENTER), SetDataTip(STR_JUST_STRING3, STR_NULL), SetFill(1, 1), SetResize(1, 0),
|
2022-01-13 19:46:43 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCHDISPATCH_PREV), SetDataTip(STR_SCHDISPATCH_PREV_SCHEDULE, STR_SCHDISPATCH_PREV_SCHEDULE_TOOLTIP), SetFill(1, 1), SetResize(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCHDISPATCH_NEXT), SetDataTip(STR_SCHDISPATCH_NEXT_SCHEDULE, STR_SCHDISPATCH_NEXT_SCHEDULE_TOOLTIP), SetFill(1, 1), SetResize(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCHDISPATCH_ADD_SCHEDULE), SetDataTip(STR_SCHDISPATCH_ADD_SCHEDULE, STR_SCHDISPATCH_ADD_SCHEDULE_TOOLTIP), SetFill(1, 1), SetResize(1, 0),
|
|
|
|
EndContainer(),
|
2017-05-29 18:37:08 +00:00
|
|
|
EndContainer(),
|
2022-01-13 19:46:43 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_MATRIX, COLOUR_GREY, WID_SCHDISPATCH_MATRIX), SetResize(1, 1), SetScrollbar(WID_SCHDISPATCH_V_SCROLL),
|
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SCHDISPATCH_V_SCROLL),
|
2017-05-29 18:37:08 +00:00
|
|
|
EndContainer(),
|
2022-01-13 19:46:43 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2024-01-27 20:15:11 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCHDISPATCH_ADD), SetDataTip(STR_SCHDISPATCH_ADD, STR_SCHDISPATCH_ADD_TOOLTIP), SetFill(1, 1), SetResize(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCHDISPATCH_ADJUST), SetDataTip(STR_SCHDISPATCH_ADJUST, STR_SCHDISPATCH_ADJUST_TOOLTIP), SetFill(1, 1), SetResize(1, 0),
|
2024-01-27 21:31:40 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCHDISPATCH_REMOVE), SetDataTip(STR_SCHDISPATCH_REMOVE, STR_SCHDISPATCH_REMOVE_TOOLTIP), SetFill(1, 1), SetResize(1, 0),
|
2024-01-28 01:48:54 +00:00
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SCHDISPATCH_MANAGE_SLOT), SetDataTip(STR_SCHDISPATCH_MANAGE_SLOT, STR_NULL), SetFill(1, 1), SetResize(1, 0),
|
2024-01-27 20:15:11 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_SCHDISPATCH_SUMMARY_PANEL), SetMinimalSize(400, 22), SetResize(1, 0), EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2022-01-13 19:46:43 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCHDISPATCH_SET_START_DATE), SetDataTip(STR_SCHDISPATCH_START, STR_SCHDISPATCH_START_TOOLTIP), SetFill(1, 1), SetResize(1, 0),
|
2024-01-27 20:15:11 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCHDISPATCH_SET_DURATION), SetDataTip(STR_SCHDISPATCH_DURATION, STR_SCHDISPATCH_DURATION_TOOLTIP), SetFill(1, 1), SetResize(1, 0),
|
2022-01-13 19:46:43 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCHDISPATCH_SET_DELAY), SetDataTip(STR_SCHDISPATCH_DELAY, STR_SCHDISPATCH_DELAY_TOOLTIP), SetFill(1, 1), SetResize(1, 0),
|
2023-05-07 19:06:47 +00:00
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SCHDISPATCH_MANAGEMENT), SetDataTip(STR_SCHDISPATCH_MANAGE, STR_NULL), SetFill(1, 1), SetResize(1, 0),
|
2022-01-13 19:46:43 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
|
2017-05-29 18:37:08 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2023-11-29 20:32:54 +00:00
|
|
|
static WindowDesc _schdispatch_desc(__FILE__, __LINE__,
|
2017-05-29 18:37:08 +00:00
|
|
|
WDP_AUTO, "scheduled_dispatch_slots", 400, 130,
|
|
|
|
WC_SCHDISPATCH_SLOTS, WC_VEHICLE_TIMETABLE,
|
|
|
|
WDF_CONSTRUCTION,
|
2023-11-19 12:19:17 +00:00
|
|
|
std::begin(_nested_schdispatch_widgets), std::end(_nested_schdispatch_widgets)
|
2017-05-29 18:37:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the slot dispatching slots
|
|
|
|
* @param v The vehicle to show the slot dispatching slots for
|
|
|
|
*/
|
|
|
|
void ShowSchdispatchWindow(const Vehicle *v)
|
|
|
|
{
|
|
|
|
AllocateWindowDescFront<SchdispatchWindow>(&_schdispatch_desc, v->index);
|
|
|
|
}
|
2021-11-28 02:25:42 +00:00
|
|
|
|
|
|
|
enum ScheduledDispatchAddSlotsWindowWidgets {
|
|
|
|
WID_SCHDISPATCH_ADD_SLOT_START_HOUR,
|
|
|
|
WID_SCHDISPATCH_ADD_SLOT_START_MINUTE,
|
|
|
|
WID_SCHDISPATCH_ADD_SLOT_STEP_HOUR,
|
|
|
|
WID_SCHDISPATCH_ADD_SLOT_STEP_MINUTE,
|
|
|
|
WID_SCHDISPATCH_ADD_SLOT_END_HOUR,
|
|
|
|
WID_SCHDISPATCH_ADD_SLOT_END_MINUTE,
|
|
|
|
WID_SCHDISPATCH_ADD_SLOT_ADD_BUTTON,
|
|
|
|
WID_SCHDISPATCH_ADD_SLOT_START_TEXT,
|
|
|
|
WID_SCHDISPATCH_ADD_SLOT_STEP_TEXT,
|
|
|
|
WID_SCHDISPATCH_ADD_SLOT_END_TEXT,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ScheduledDispatchAddSlotsWindow : Window {
|
2023-12-19 01:03:18 +00:00
|
|
|
ClockFaceMinutes start;
|
|
|
|
ClockFaceMinutes step;
|
|
|
|
ClockFaceMinutes end;
|
2021-11-28 02:25:42 +00:00
|
|
|
|
|
|
|
ScheduledDispatchAddSlotsWindow(WindowDesc *desc, WindowNumber window_number, SchdispatchWindow *parent) :
|
|
|
|
Window(desc)
|
|
|
|
{
|
2023-12-19 01:03:18 +00:00
|
|
|
this->start = _settings_time.NowInTickMinutes().ToClockFaceMinutes();
|
2021-11-28 02:25:42 +00:00
|
|
|
this->step = 30;
|
|
|
|
this->end = this->start + 60;
|
|
|
|
this->parent = parent;
|
|
|
|
this->CreateNestedTree();
|
|
|
|
this->FinishInitNested(window_number);
|
|
|
|
}
|
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
|
2021-11-28 02:25:42 +00:00
|
|
|
{
|
|
|
|
Point pt = { this->parent->left + this->parent->width / 2 - sm_width / 2, this->parent->top + this->parent->height / 2 - sm_height / 2 };
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2024-01-02 14:31:56 +00:00
|
|
|
virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
|
2021-11-28 02:25:42 +00:00
|
|
|
{
|
|
|
|
Dimension d = {0, 0};
|
|
|
|
switch (widget) {
|
|
|
|
default: return;
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_START_TEXT:
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_STEP_TEXT:
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_END_TEXT:
|
|
|
|
d = maxdim(d, GetStringBoundingBox(STR_SCHDISPATCH_ADD_DEPARTURE_SLOTS_START));
|
|
|
|
d = maxdim(d, GetStringBoundingBox(STR_SCHDISPATCH_ADD_DEPARTURE_SLOTS_STEP));
|
|
|
|
d = maxdim(d, GetStringBoundingBox(STR_SCHDISPATCH_ADD_DEPARTURE_SLOTS_END));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_START_HOUR:
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_STEP_HOUR:
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_END_HOUR:
|
|
|
|
for (uint i = 0; i < 24; i++) {
|
|
|
|
SetDParam(0, i);
|
|
|
|
d = maxdim(d, GetStringBoundingBox(STR_JUST_INT));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_START_MINUTE:
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_STEP_MINUTE:
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_END_MINUTE:
|
|
|
|
for (uint i = 0; i < 60; i++) {
|
|
|
|
SetDParam(0, i);
|
|
|
|
d = maxdim(d, GetStringBoundingBox(STR_JUST_INT));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
d.width += padding.width;
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = d;
|
|
|
|
}
|
|
|
|
|
2024-01-02 14:31:56 +00:00
|
|
|
virtual void SetStringParameters(WidgetID widget) const override
|
2021-11-28 02:25:42 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2023-12-19 01:03:18 +00:00
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_START_HOUR: SetDParam(0, start.ClockHour()); break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_START_MINUTE: SetDParam(0, start.ClockMinute()); break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_STEP_HOUR: SetDParam(0, step.ClockHour()); break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_STEP_MINUTE: SetDParam(0, step.ClockMinute()); break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_END_HOUR: SetDParam(0, end.ClockHour()); break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_END_MINUTE: SetDParam(0, end.ClockMinute()); break;
|
2021-11-28 02:25:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-02 14:31:56 +00:00
|
|
|
virtual void OnClick(Point pt, WidgetID widget, int click_count) override
|
2021-11-28 02:25:42 +00:00
|
|
|
{
|
2023-12-19 01:03:18 +00:00
|
|
|
auto handle_hours_dropdown = [&](ClockFaceMinutes current) {
|
2021-11-28 02:25:42 +00:00
|
|
|
DropDownList list;
|
|
|
|
for (uint i = 0; i < 24; i++) {
|
2023-09-12 19:06:47 +00:00
|
|
|
SetDParam(0, i);
|
|
|
|
list.emplace_back(new DropDownListStringItem(STR_JUST_INT, i, false));
|
2021-11-28 02:25:42 +00:00
|
|
|
}
|
2023-12-19 01:03:18 +00:00
|
|
|
ShowDropDownList(this, std::move(list), current.ClockHour(), widget);
|
2021-11-28 02:25:42 +00:00
|
|
|
};
|
|
|
|
|
2023-12-19 01:03:18 +00:00
|
|
|
auto handle_minutes_dropdown = [&](ClockFaceMinutes current) {
|
2021-11-28 02:25:42 +00:00
|
|
|
DropDownList list;
|
|
|
|
for (uint i = 0; i < 60; i++) {
|
2023-09-12 19:06:47 +00:00
|
|
|
SetDParam(0, i);
|
|
|
|
list.emplace_back(new DropDownListStringItem(STR_JUST_INT, i, false));
|
2021-11-28 02:25:42 +00:00
|
|
|
}
|
2023-12-19 01:03:18 +00:00
|
|
|
ShowDropDownList(this, std::move(list), current.ClockMinute(), widget);
|
2021-11-28 02:25:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
switch (widget) {
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_START_HOUR:
|
|
|
|
handle_hours_dropdown(this->start);
|
|
|
|
break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_START_MINUTE:
|
|
|
|
handle_minutes_dropdown(this->start);
|
|
|
|
break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_STEP_HOUR:
|
|
|
|
handle_hours_dropdown(this->step);
|
|
|
|
break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_STEP_MINUTE:
|
|
|
|
handle_minutes_dropdown(this->step);
|
|
|
|
break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_END_HOUR:
|
|
|
|
handle_hours_dropdown(this->end);
|
|
|
|
break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_END_MINUTE:
|
|
|
|
handle_minutes_dropdown(this->end);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_ADD_BUTTON:
|
2023-12-19 01:03:18 +00:00
|
|
|
static_cast<SchdispatchWindow *>(this->parent)->AddMultipleDepartureSlots(this->start.base(), this->step.base(), this->end.base());
|
2023-09-15 22:56:33 +00:00
|
|
|
this->Close();
|
2021-11-28 02:25:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-02 14:31:56 +00:00
|
|
|
virtual void OnDropdownSelect(WidgetID widget, int index) override
|
2021-11-28 02:25:42 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_START_HOUR:
|
2023-12-19 01:03:18 +00:00
|
|
|
this->start = ClockFaceMinutes::FromClockFace(index, this->start.ClockMinute());
|
2021-11-28 02:25:42 +00:00
|
|
|
break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_START_MINUTE:
|
2023-12-19 01:03:18 +00:00
|
|
|
this->start = ClockFaceMinutes::FromClockFace(this->start.ClockHour(), index);
|
2021-11-28 02:25:42 +00:00
|
|
|
break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_STEP_HOUR:
|
2023-12-19 01:03:18 +00:00
|
|
|
this->step = ClockFaceMinutes::FromClockFace(index, this->step.ClockMinute());
|
2021-11-28 02:25:42 +00:00
|
|
|
break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_STEP_MINUTE:
|
2023-12-19 01:03:18 +00:00
|
|
|
this->step = ClockFaceMinutes::FromClockFace(this->step.ClockHour(), index);
|
2021-11-28 02:25:42 +00:00
|
|
|
break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_END_HOUR:
|
2023-12-19 01:03:18 +00:00
|
|
|
this->end = ClockFaceMinutes::FromClockFace(index, this->end.ClockMinute());
|
2021-11-28 02:25:42 +00:00
|
|
|
break;
|
|
|
|
case WID_SCHDISPATCH_ADD_SLOT_END_MINUTE:
|
2023-12-19 01:03:18 +00:00
|
|
|
this->end = ClockFaceMinutes::FromClockFace(this->end.ClockHour(), index);
|
2021-11-28 02:25:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this->SetWidgetDirty(widget);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-01-21 22:24:49 +00:00
|
|
|
static constexpr NWidgetPart _nested_scheduled_dispatch_add_widgets[] = {
|
2021-11-28 02:25:42 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_TIME_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN),
|
|
|
|
NWidget(NWID_VERTICAL), SetPIP(6, 6, 6),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(6, 6, 6),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_BROWN, WID_SCHDISPATCH_ADD_SLOT_START_TEXT), SetDataTip(STR_SCHDISPATCH_ADD_DEPARTURE_SLOTS_START, STR_NULL),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_SCHDISPATCH_ADD_SLOT_START_HOUR), SetFill(1, 0), SetDataTip(STR_JUST_INT, STR_DATE_MINUTES_HOUR_TOOLTIP),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_SCHDISPATCH_ADD_SLOT_START_MINUTE), SetFill(1, 0), SetDataTip(STR_JUST_INT, STR_DATE_MINUTES_MINUTE_TOOLTIP),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(6, 6, 6),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_BROWN, WID_SCHDISPATCH_ADD_SLOT_STEP_TEXT), SetDataTip(STR_SCHDISPATCH_ADD_DEPARTURE_SLOTS_STEP, STR_NULL),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_SCHDISPATCH_ADD_SLOT_STEP_HOUR), SetFill(1, 0), SetDataTip(STR_JUST_INT, STR_DATE_MINUTES_HOUR_TOOLTIP),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_SCHDISPATCH_ADD_SLOT_STEP_MINUTE), SetFill(1, 0), SetDataTip(STR_JUST_INT, STR_DATE_MINUTES_MINUTE_TOOLTIP),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(6, 6, 6),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_BROWN, WID_SCHDISPATCH_ADD_SLOT_END_TEXT), SetDataTip(STR_SCHDISPATCH_ADD_DEPARTURE_SLOTS_END, STR_NULL),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_SCHDISPATCH_ADD_SLOT_END_HOUR), SetFill(1, 0), SetDataTip(STR_JUST_INT, STR_DATE_MINUTES_HOUR_TOOLTIP),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_SCHDISPATCH_ADD_SLOT_END_MINUTE), SetFill(1, 0), SetDataTip(STR_JUST_INT, STR_DATE_MINUTES_MINUTE_TOOLTIP),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_SCHDISPATCH_ADD_SLOT_ADD_BUTTON), SetMinimalSize(100, 12), SetDataTip(STR_SCHDISPATCH_ADD, STR_SCHDISPATCH_ADD_TOOLTIP),
|
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer()
|
|
|
|
};
|
|
|
|
|
2023-11-29 20:32:54 +00:00
|
|
|
static WindowDesc _scheduled_dispatch_add_desc(__FILE__, __LINE__,
|
2021-11-28 02:25:42 +00:00
|
|
|
WDP_CENTER, nullptr, 0, 0,
|
|
|
|
WC_SET_DATE, WC_NONE,
|
|
|
|
0,
|
2023-11-19 12:19:17 +00:00
|
|
|
std::begin(_nested_scheduled_dispatch_add_widgets), std::end(_nested_scheduled_dispatch_add_widgets)
|
2021-11-28 02:25:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
void ShowScheduledDispatchAddSlotsWindow(SchdispatchWindow *parent, int window_number)
|
|
|
|
{
|
2023-09-15 19:59:08 +00:00
|
|
|
CloseWindowByClass(WC_SET_DATE);
|
2021-11-28 02:25:42 +00:00
|
|
|
|
|
|
|
new ScheduledDispatchAddSlotsWindow(&_scheduled_dispatch_add_desc, window_number, parent);
|
|
|
|
}
|
2022-01-15 00:21:31 +00:00
|
|
|
|
|
|
|
void SchdispatchInvalidateWindows(const Vehicle *v)
|
|
|
|
{
|
|
|
|
v = v->FirstShared();
|
2023-09-18 17:34:50 +00:00
|
|
|
for (Window *w : Window::Iterate()) {
|
2022-01-15 00:21:31 +00:00
|
|
|
if (w->window_class == WC_VEHICLE_TIMETABLE) {
|
|
|
|
if (static_cast<GeneralVehicleWindow *>(w)->vehicle->FirstShared() == v) w->SetDirty();
|
|
|
|
}
|
2023-05-13 10:54:48 +00:00
|
|
|
if (w->window_class == WC_SCHDISPATCH_SLOTS || w->window_class == WC_VEHICLE_ORDERS) {
|
2022-01-15 00:21:31 +00:00
|
|
|
if (static_cast<GeneralVehicleWindow *>(w)->vehicle->FirstShared() == v) w->InvalidateData(VIWD_MODIFY_ORDERS, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|