2007-06-20 19:26:25 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file timetable_gui.cpp GUI for time tabling. */
|
2007-06-20 19:26:25 +00:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2007-06-20 19:26:25 +00:00
|
|
|
#include "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
2009-01-03 23:32:59 +00:00
|
|
|
#include "window_func.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "textbuf_gui.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_base.h"
|
2008-01-07 14:23:25 +00:00
|
|
|
#include "string_func.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "gfx_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2008-03-23 06:56:33 +00:00
|
|
|
enum TimetableViewWindowWidgets {
|
|
|
|
TTV_WIDGET_CLOSEBOX = 0,
|
|
|
|
TTV_CAPTION,
|
2008-03-27 14:34:29 +00:00
|
|
|
TTV_ORDER_VIEW,
|
2008-03-23 06:56:33 +00:00
|
|
|
TTV_STICKY,
|
|
|
|
TTV_TIMETABLE_PANEL,
|
|
|
|
TTV_SCROLLBAR,
|
|
|
|
TTV_SUMMARY_PANEL,
|
|
|
|
TTV_CHANGE_TIME,
|
|
|
|
TTV_CLEAR_TIME,
|
|
|
|
TTV_RESET_LATENESS,
|
|
|
|
TTV_AUTOFILL,
|
|
|
|
TTV_EMPTY,
|
|
|
|
TTV_RESIZE,
|
|
|
|
};
|
|
|
|
|
2008-04-14 12:40:09 +00:00
|
|
|
void SetTimetableParams(int param1, int param2, uint32 time)
|
2007-06-20 19:26:25 +00:00
|
|
|
{
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_client.gui.timetable_in_ticks) {
|
2007-06-20 19:26:25 +00:00
|
|
|
SetDParam(param1, STR_TIMETABLE_TICKS);
|
|
|
|
SetDParam(param2, time);
|
|
|
|
} else {
|
|
|
|
SetDParam(param1, STR_TIMETABLE_DAYS);
|
|
|
|
SetDParam(param2, time / DAY_TICKS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-16 13:39:25 +00:00
|
|
|
struct TimetableWindow : Window {
|
|
|
|
int sel_index;
|
2009-11-08 20:52:14 +00:00
|
|
|
const Vehicle *vehicle; ///< Vehicle monitored by the window.
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-11-08 20:52:14 +00:00
|
|
|
TimetableWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
2008-05-16 13:39:25 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
this->vehicle = Vehicle::Get(window_number);
|
2009-11-08 20:52:14 +00:00
|
|
|
this->InitNested(desc, window_number);
|
2009-02-09 02:33:10 +00:00
|
|
|
this->owner = this->vehicle->owner;
|
2008-05-16 13:39:25 +00:00
|
|
|
this->sel_index = -1;
|
2009-11-08 20:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case TTV_TIMETABLE_PANEL:
|
|
|
|
resize->height = FONT_HEIGHT_NORMAL;
|
|
|
|
size->height = WD_FRAMERECT_TOP + 8 * resize->height + WD_FRAMERECT_BOTTOM;
|
|
|
|
break;
|
2008-05-23 23:02:13 +00:00
|
|
|
|
2009-11-08 20:52:14 +00:00
|
|
|
case TTV_SUMMARY_PANEL:
|
|
|
|
size->height = WD_FRAMERECT_TOP + 2 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-16 13:39:25 +00:00
|
|
|
}
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-05-16 13:39:25 +00:00
|
|
|
int GetOrderFromTimetableWndPt(int y, const Vehicle *v)
|
|
|
|
{
|
2009-11-08 20:52:14 +00:00
|
|
|
int sel = (y - this->GetWidget<NWidgetBase>(TTV_TIMETABLE_PANEL)->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL;
|
2008-05-16 13:39:25 +00:00
|
|
|
|
2009-09-02 08:40:31 +00:00
|
|
|
if ((uint)sel >= this->vscroll.GetCapacity()) return INVALID_ORDER;
|
2008-05-16 13:39:25 +00:00
|
|
|
|
2009-09-02 08:40:31 +00:00
|
|
|
sel += this->vscroll.GetPosition();
|
2008-05-16 13:39:25 +00:00
|
|
|
|
2009-01-03 13:20:32 +00:00
|
|
|
return (sel < v->GetNumOrders() * 2 && sel >= 0) ? sel : INVALID_ORDER;
|
2007-06-20 19:26:25 +00:00
|
|
|
}
|
|
|
|
|
2008-09-24 16:40:06 +00:00
|
|
|
virtual void OnInvalidateData(int data)
|
2008-05-16 13:39:25 +00:00
|
|
|
{
|
2008-09-24 16:40:06 +00:00
|
|
|
switch (data) {
|
|
|
|
case 0:
|
|
|
|
/* Autoreplace replaced the vehicle */
|
2009-05-16 23:34:14 +00:00
|
|
|
this->vehicle = Vehicle::Get(this->window_number);
|
2008-09-24 16:40:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
/* Removed / replaced all orders (after deleting / sharing) */
|
|
|
|
if (this->sel_index == -1) break;
|
|
|
|
|
|
|
|
this->DeleteChildWindows();
|
|
|
|
this->sel_index = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
/* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
|
|
|
|
* the order is being created / removed */
|
|
|
|
if (this->sel_index == -1) break;
|
|
|
|
|
|
|
|
VehicleOrderID from = GB(data, 0, 8);
|
|
|
|
VehicleOrderID to = GB(data, 8, 8);
|
|
|
|
|
|
|
|
if (from == to) break; // no need to change anything
|
|
|
|
|
|
|
|
/* if from == INVALID_VEH_ORDER_ID, one order was added; if to == INVALID_VEH_ORDER_ID, one order was removed */
|
2009-01-03 13:20:32 +00:00
|
|
|
uint old_num_orders = this->vehicle->GetNumOrders() - (uint)(from == INVALID_VEH_ORDER_ID) + (uint)(to == INVALID_VEH_ORDER_ID);
|
2008-09-24 16:40:06 +00:00
|
|
|
|
|
|
|
VehicleOrderID selected_order = (this->sel_index + 1) / 2;
|
|
|
|
if (selected_order == old_num_orders) selected_order = 0; // when last travel time is selected, it belongs to order 0
|
|
|
|
|
|
|
|
bool travel = HasBit(this->sel_index, 0);
|
|
|
|
|
|
|
|
if (from != selected_order) {
|
|
|
|
/* Moving from preceeding order? */
|
|
|
|
selected_order -= (int)(from <= selected_order);
|
|
|
|
/* Moving to preceeding order? */
|
|
|
|
selected_order += (int)(to <= selected_order);
|
|
|
|
} else {
|
|
|
|
/* Now we are modifying the selected order */
|
|
|
|
if (to == INVALID_VEH_ORDER_ID) {
|
|
|
|
/* Deleting selected order */
|
|
|
|
this->DeleteChildWindows();
|
|
|
|
this->sel_index = -1;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
/* Moving selected order */
|
|
|
|
selected_order = to;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* recompute new sel_index */
|
|
|
|
this->sel_index = 2 * selected_order - (int)travel;
|
|
|
|
/* travel time of first order needs special handling */
|
2009-01-03 13:20:32 +00:00
|
|
|
if (this->sel_index == -1) this->sel_index = this->vehicle->GetNumOrders() * 2 - 1;
|
2008-09-24 16:40:06 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
const Vehicle *v = this->vehicle;
|
2008-05-16 13:39:25 +00:00
|
|
|
int selected = this->sel_index;
|
|
|
|
|
2009-09-02 08:40:31 +00:00
|
|
|
this->vscroll.SetCount(v->GetNumOrders() * 2);
|
2008-05-16 13:39:25 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (v->owner == _local_company) {
|
2008-07-14 21:01:49 +00:00
|
|
|
bool disable = true;
|
|
|
|
if (selected != -1) {
|
2009-05-23 12:27:42 +00:00
|
|
|
const Order *order = v->GetOrder(((selected + 1) / 2) % v->GetNumOrders());
|
2008-07-14 21:01:49 +00:00
|
|
|
if (selected % 2 == 1) {
|
|
|
|
disable = order != NULL && order->IsType(OT_CONDITIONAL);
|
|
|
|
} else {
|
|
|
|
disable = order == NULL || ((!order->IsType(OT_GOTO_STATION) || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) && !order->IsType(OT_CONDITIONAL));
|
|
|
|
}
|
2008-05-16 13:39:25 +00:00
|
|
|
}
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-07-14 21:01:49 +00:00
|
|
|
this->SetWidgetDisabledState(TTV_CHANGE_TIME, disable);
|
|
|
|
this->SetWidgetDisabledState(TTV_CLEAR_TIME, disable);
|
|
|
|
|
2008-05-16 13:39:25 +00:00
|
|
|
this->EnableWidget(TTV_RESET_LATENESS);
|
|
|
|
this->EnableWidget(TTV_AUTOFILL);
|
|
|
|
} else {
|
|
|
|
this->DisableWidget(TTV_CHANGE_TIME);
|
|
|
|
this->DisableWidget(TTV_CLEAR_TIME);
|
|
|
|
this->DisableWidget(TTV_RESET_LATENESS);
|
|
|
|
this->DisableWidget(TTV_AUTOFILL);
|
|
|
|
}
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-05-16 13:39:25 +00:00
|
|
|
this->SetWidgetLoweredState(TTV_AUTOFILL, HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE));
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2009-11-08 20:52:14 +00:00
|
|
|
}
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-11-08 20:52:14 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
if (widget == TTV_CAPTION) SetDParam(0, this->vehicle->index);
|
|
|
|
}
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-11-08 20:52:14 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
const Vehicle *v = this->vehicle;
|
|
|
|
int selected = this->sel_index;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-11-08 20:52:14 +00:00
|
|
|
switch (widget) {
|
|
|
|
case TTV_TIMETABLE_PANEL: {
|
|
|
|
int y = r.top + WD_FRAMERECT_TOP;
|
|
|
|
int i = this->vscroll.GetPosition();
|
|
|
|
VehicleOrderID order_id = (i + 1) / 2;
|
|
|
|
bool final_order = false;
|
|
|
|
|
|
|
|
const Order *order = v->GetOrder(order_id);
|
|
|
|
while (order != NULL) {
|
|
|
|
/* Don't draw anything if it extends past the end of the window. */
|
|
|
|
if (!this->vscroll.IsVisible(i)) break;
|
|
|
|
|
|
|
|
if (i % 2 == 0) {
|
|
|
|
DrawOrderString(v, order, order_id, y, i == selected, true, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT);
|
|
|
|
|
|
|
|
order_id++;
|
|
|
|
|
|
|
|
if (order_id >= v->GetNumOrders()) {
|
|
|
|
order = v->GetOrder(0);
|
|
|
|
final_order = true;
|
|
|
|
} else {
|
|
|
|
order = order->next;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
StringID string;
|
2008-05-16 13:39:25 +00:00
|
|
|
|
2009-11-08 20:52:14 +00:00
|
|
|
if (order->IsType(OT_CONDITIONAL)) {
|
|
|
|
string = STR_TIMETABLE_NO_TRAVEL;
|
|
|
|
} else if (order->travel_time == 0) {
|
|
|
|
string = STR_TIMETABLE_TRAVEL_NOT_TIMETABLED;
|
|
|
|
} else {
|
|
|
|
SetTimetableParams(0, 1, order->travel_time);
|
|
|
|
string = STR_TIMETABLE_TRAVEL_FOR;
|
|
|
|
}
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-11-08 20:52:14 +00:00
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y, string, (i == selected) ? TC_WHITE : TC_BLACK);
|
2008-05-16 13:39:25 +00:00
|
|
|
|
2009-11-08 20:52:14 +00:00
|
|
|
if (final_order) break;
|
|
|
|
}
|
2008-05-16 13:39:25 +00:00
|
|
|
|
2009-11-08 20:52:14 +00:00
|
|
|
i++;
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-05-16 13:39:25 +00:00
|
|
|
}
|
2009-11-08 20:52:14 +00:00
|
|
|
break;
|
2008-05-16 13:39:25 +00:00
|
|
|
}
|
|
|
|
|
2009-11-08 20:52:14 +00:00
|
|
|
case TTV_SUMMARY_PANEL: {
|
|
|
|
int y = r.top + WD_FRAMERECT_TOP;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-11-08 20:52:14 +00:00
|
|
|
uint total_time = 0;
|
|
|
|
bool complete = true;
|
|
|
|
for (const Order *order = v->GetOrder(0); order != NULL; order = order->next) {
|
|
|
|
total_time += order->travel_time + order->wait_time;
|
|
|
|
if (order->travel_time == 0 && !order->IsType(OT_CONDITIONAL)) complete = false;
|
|
|
|
if (order->wait_time == 0 && order->IsType(OT_GOTO_STATION) && !(order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) complete = false;
|
|
|
|
}
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-11-08 20:52:14 +00:00
|
|
|
if (total_time != 0) {
|
|
|
|
SetTimetableParams(0, 1, total_time);
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, complete ? STR_TIMETABLE_TOTAL_TIME : STR_TIMETABLE_TOTAL_TIME_INCOMPLETE);
|
|
|
|
}
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-06-26 11:01:06 +00:00
|
|
|
|
2009-11-08 20:52:14 +00:00
|
|
|
if (v->lateness_counter == 0 || (!_settings_client.gui.timetable_in_ticks && v->lateness_counter / DAY_TICKS == 0)) {
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_TIMETABLE_STATUS_ON_TIME);
|
|
|
|
} else {
|
|
|
|
SetTimetableParams(0, 1, abs(v->lateness_counter));
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, v->lateness_counter < 0 ? STR_TIMETABLE_STATUS_EARLY : STR_TIMETABLE_STATUS_LATE);
|
|
|
|
}
|
|
|
|
break;
|
2008-05-16 13:39:25 +00:00
|
|
|
}
|
2007-06-26 11:01:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-16 13:39:25 +00:00
|
|
|
static inline uint32 PackTimetableArgs(const Vehicle *v, uint selected)
|
|
|
|
{
|
|
|
|
uint order_number = (selected + 1) / 2;
|
|
|
|
uint is_journey = (selected % 2 == 1) ? 1 : 0;
|
|
|
|
|
2009-01-03 13:20:32 +00:00
|
|
|
if (order_number >= v->GetNumOrders()) order_number = 0;
|
2008-05-16 13:39:25 +00:00
|
|
|
|
|
|
|
return v->index | (order_number << 16) | (is_journey << 24);
|
2007-06-20 19:26:25 +00:00
|
|
|
}
|
|
|
|
|
2008-05-16 13:39:25 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
2008-09-24 16:40:06 +00:00
|
|
|
const Vehicle *v = this->vehicle;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-05-16 13:39:25 +00:00
|
|
|
switch (widget) {
|
2009-03-15 00:32:18 +00:00
|
|
|
case TTV_ORDER_VIEW: // Order view button
|
2008-05-16 13:39:25 +00:00
|
|
|
ShowOrdersWindow(v);
|
|
|
|
break;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case TTV_TIMETABLE_PANEL: { // Main panel.
|
2008-05-16 13:39:25 +00:00
|
|
|
int selected = GetOrderFromTimetableWndPt(pt.y, v);
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-09-24 16:40:06 +00:00
|
|
|
this->DeleteChildWindows();
|
|
|
|
this->sel_index = (selected == INVALID_ORDER || selected == this->sel_index) ? -1 : selected;
|
2008-05-16 13:39:25 +00:00
|
|
|
} break;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case TTV_CHANGE_TIME: { // "Wait For" button.
|
2008-05-16 13:39:25 +00:00
|
|
|
int selected = this->sel_index;
|
|
|
|
VehicleOrderID real = (selected + 1) / 2;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-01-03 13:20:32 +00:00
|
|
|
if (real >= v->GetNumOrders()) real = 0;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-05-23 12:27:42 +00:00
|
|
|
const Order *order = v->GetOrder(real);
|
2008-05-16 13:39:25 +00:00
|
|
|
StringID current = STR_EMPTY;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-05-16 13:39:25 +00:00
|
|
|
if (order != NULL) {
|
|
|
|
uint time = (selected % 2 == 1) ? order->travel_time : order->wait_time;
|
2008-05-29 15:13:28 +00:00
|
|
|
if (!_settings_client.gui.timetable_in_ticks) time /= DAY_TICKS;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-05-16 13:39:25 +00:00
|
|
|
if (time != 0) {
|
|
|
|
SetDParam(0, time);
|
2009-07-23 19:31:50 +00:00
|
|
|
current = STR_JUST_INT;
|
2007-06-20 19:26:25 +00:00
|
|
|
}
|
2008-05-16 13:39:25 +00:00
|
|
|
}
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-09-15 16:29:40 +00:00
|
|
|
ShowQueryString(current, STR_TIMETABLE_CHANGE_TIME, 31, 150, this, CS_NUMERAL, QSF_NONE);
|
2008-05-16 13:39:25 +00:00
|
|
|
} break;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case TTV_CLEAR_TIME: { // Clear waiting time button.
|
2008-05-16 13:39:25 +00:00
|
|
|
uint32 p1 = PackTimetableArgs(v, this->sel_index);
|
2009-08-05 17:59:21 +00:00
|
|
|
DoCommandP(0, p1, 0, CMD_CHANGE_TIMETABLE | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
2008-05-16 13:39:25 +00:00
|
|
|
} break;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case TTV_RESET_LATENESS: // Reset the vehicle's late counter.
|
2009-08-05 17:59:21 +00:00
|
|
|
DoCommandP(0, v->index, 0, CMD_SET_VEHICLE_ON_TIME | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
2008-05-16 13:39:25 +00:00
|
|
|
break;
|
2007-06-25 20:55:43 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case TTV_AUTOFILL: { // Autofill the timetable.
|
2008-11-18 23:53:37 +00:00
|
|
|
uint32 p2 = 0;
|
|
|
|
if (!HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) SetBit(p2, 0);
|
|
|
|
if (_ctrl_pressed) SetBit(p2, 1);
|
2009-08-05 17:59:21 +00:00
|
|
|
DoCommandP(0, v->index, p2, CMD_AUTOFILL_TIMETABLE | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
2008-11-18 23:53:37 +00:00
|
|
|
} break;
|
2008-05-16 13:39:25 +00:00
|
|
|
}
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-05-16 13:39:25 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
2008-05-10 08:58:52 +00:00
|
|
|
|
2008-05-16 13:39:25 +00:00
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
|
{
|
|
|
|
if (str == NULL) return;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-09-24 16:40:06 +00:00
|
|
|
const Vehicle *v = this->vehicle;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-05-16 13:39:25 +00:00
|
|
|
uint32 p1 = PackTimetableArgs(v, this->sel_index);
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-05-16 13:39:25 +00:00
|
|
|
uint64 time = StrEmpty(str) ? 0 : strtoul(str, NULL, 10);
|
2008-05-29 15:13:28 +00:00
|
|
|
if (!_settings_client.gui.timetable_in_ticks) time *= DAY_TICKS;
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2008-06-27 17:46:43 +00:00
|
|
|
uint32 p2 = minu(time, UINT16_MAX);
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-08-05 17:59:21 +00:00
|
|
|
DoCommandP(0, p1, p2, CMD_CHANGE_TIMETABLE | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
2008-05-16 13:39:25 +00:00
|
|
|
}
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-10-24 14:53:55 +00:00
|
|
|
virtual void OnResize()
|
2008-05-16 13:39:25 +00:00
|
|
|
{
|
2009-10-17 14:29:10 +00:00
|
|
|
/* Update the scroll bar */
|
2009-11-08 20:52:14 +00:00
|
|
|
this->vscroll.SetCapacity((this->GetWidget<NWidgetBase>(TTV_TIMETABLE_PANEL)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / this->resize.step_height);
|
2007-06-20 19:26:25 +00:00
|
|
|
}
|
2008-05-16 13:39:25 +00:00
|
|
|
};
|
2007-06-20 19:26:25 +00:00
|
|
|
|
2009-05-03 11:53:06 +00:00
|
|
|
static const NWidgetPart _nested_timetable_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY, TTV_WIDGET_CLOSEBOX),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, TTV_CAPTION), SetDataTip(STR_TIMETABLE_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-08-05 17:59:21 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, TTV_ORDER_VIEW), SetMinimalSize(61, 14), SetDataTip( STR_TIMETABLE_ORDER_VIEW, STR_TIMETABLE_ORDER_VIEW_TOOLTIP),
|
2009-05-03 11:53:06 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_GREY, TTV_STICKY),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, TTV_TIMETABLE_PANEL), SetMinimalSize(388, 82), SetResize(1, 10), SetDataTip(STR_NULL, STR_TIMETABLE_TOOLTIP), EndContainer(),
|
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_GREY, TTV_SCROLLBAR),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, TTV_SUMMARY_PANEL), SetMinimalSize(400, 22), SetResize(1, 0), EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, TTV_CHANGE_TIME), SetMinimalSize(110, 12), SetDataTip(STR_TIMETABLE_CHANGE_TIME, STR_TIMETABLE_WAIT_TIME_TOOLTIP),
|
2009-08-05 17:59:21 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, TTV_CLEAR_TIME), SetMinimalSize(110, 12), SetDataTip(STR_TIMETABLE_CLEAR_TIME, STR_TIMETABLE_CLEAR_TIME_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, TTV_RESET_LATENESS), SetMinimalSize(118, 12), SetDataTip(STR_TIMETABLE_RESET_LATENESS, STR_TIMETABLE_RESET_LATENESS_TOOLTIP),
|
2009-05-03 11:53:06 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, TTV_AUTOFILL), SetMinimalSize(50, 12), SetDataTip(STR_TIMETABLE_AUTOFILL, STR_TIMETABLE_AUTOFILL_TOOLTIP),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, TTV_EMPTY), SetMinimalSize(0, 12), SetResize(1, 0), EndContainer(),
|
|
|
|
NWidget(WWT_RESIZEBOX,COLOUR_GREY, TTV_RESIZE),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _timetable_desc(
|
2009-11-17 19:16:48 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 400, 130,
|
2007-06-20 19:26:25 +00:00
|
|
|
WC_VEHICLE_TIMETABLE, WC_VEHICLE_VIEW,
|
2009-02-04 16:59:41 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE | WDF_CONSTRUCTION,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_timetable_widgets, lengthof(_nested_timetable_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2007-06-20 19:26:25 +00:00
|
|
|
|
|
|
|
void ShowTimetableWindow(const Vehicle *v)
|
|
|
|
{
|
2009-01-03 23:32:59 +00:00
|
|
|
DeleteWindowById(WC_VEHICLE_DETAILS, v->index, false);
|
|
|
|
DeleteWindowById(WC_VEHICLE_ORDERS, v->index, false);
|
2008-05-16 13:39:25 +00:00
|
|
|
AllocateWindowDescFront<TimetableWindow>(&_timetable_desc, v->index);
|
2007-06-20 19:26:25 +00:00
|
|
|
}
|