2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/** @file order_gui.cpp */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "road_map.h"
|
2006-03-24 08:55:08 +00:00
|
|
|
#include "station_map.h"
|
2005-02-13 11:18:02 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "vehicle.h"
|
|
|
|
#include "station.h"
|
|
|
|
#include "town.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "viewport.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "depot.h"
|
2005-03-24 17:03:37 +00:00
|
|
|
#include "waypoint.h"
|
2005-11-18 23:41:03 +00:00
|
|
|
#include "train.h"
|
2006-03-31 10:47:06 +00:00
|
|
|
#include "water_map.h"
|
2006-09-28 23:05:03 +00:00
|
|
|
#include "vehicle_gui.h"
|
2007-06-20 19:17:22 +00:00
|
|
|
#include "timetable.h"
|
2007-02-20 22:09:21 +00:00
|
|
|
#include "cargotype.h"
|
2007-12-12 14:37:35 +00:00
|
|
|
#include "order.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-24 18:22:31 +00:00
|
|
|
enum OrderWindowWidgets {
|
|
|
|
ORDER_WIDGET_CLOSEBOX = 0,
|
|
|
|
ORDER_WIDGET_CAPTION,
|
2007-06-20 19:17:22 +00:00
|
|
|
ORDER_WIDGET_TIMETABLE_VIEW,
|
2007-01-24 18:22:31 +00:00
|
|
|
ORDER_WIDGET_ORDER_LIST,
|
|
|
|
ORDER_WIDGET_SCROLLBAR,
|
|
|
|
ORDER_WIDGET_SKIP,
|
|
|
|
ORDER_WIDGET_DELETE,
|
|
|
|
ORDER_WIDGET_NON_STOP,
|
|
|
|
ORDER_WIDGET_GOTO,
|
|
|
|
ORDER_WIDGET_FULL_LOAD,
|
|
|
|
ORDER_WIDGET_UNLOAD,
|
2007-01-24 18:41:27 +00:00
|
|
|
ORDER_WIDGET_REFIT,
|
2007-01-24 18:22:31 +00:00
|
|
|
ORDER_WIDGET_TRANSFER,
|
|
|
|
ORDER_WIDGET_SHARED_ORDER_LIST,
|
|
|
|
ORDER_WIDGET_RESIZE_BAR,
|
|
|
|
ORDER_WIDGET_RESIZE,
|
|
|
|
};
|
|
|
|
|
2007-06-08 18:59:29 +00:00
|
|
|
/**
|
|
|
|
* Return the memorised selected order.
|
|
|
|
*
|
|
|
|
* @param w current window
|
|
|
|
* @return the memorised order if it is a vaild one
|
|
|
|
* else return the number of orders
|
|
|
|
*/
|
2006-07-26 03:33:12 +00:00
|
|
|
static int OrderGetSel(const Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
const Vehicle *v = GetVehicle(w->window_number);
|
2007-12-16 10:54:08 +00:00
|
|
|
int num = WP(w, order_d).sel;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
return (num >= 0 && num < v->num_orders) ? num : v->num_orders;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-08 18:59:29 +00:00
|
|
|
/**
|
|
|
|
* Calculate the selected order.
|
|
|
|
* The calculation is based on the relative (to the window) y click position and
|
|
|
|
* the position of the scrollbar.
|
|
|
|
*
|
|
|
|
* @param w current window
|
|
|
|
* @param y Y-value of the click relative to the window origin
|
|
|
|
* @param v current vehicle
|
|
|
|
* @return the new selected order if the order is valid else return that
|
|
|
|
* an invalid one has been selected.
|
|
|
|
*/
|
|
|
|
static int GetOrderFromOrderWndPt(Window *w, int y, const Vehicle *v)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Calculation description:
|
|
|
|
* 15 = 14 (w->widget[ORDER_WIDGET_ORDER_LIST].top) + 1 (frame-line)
|
|
|
|
* 10 = order text hight
|
|
|
|
*/
|
|
|
|
int sel = (y - 15) / 10;
|
|
|
|
|
|
|
|
if ((uint)sel >= w->vscroll.cap) return INVALID_ORDER;
|
|
|
|
|
|
|
|
sel += w->vscroll.pos;
|
|
|
|
|
|
|
|
return (sel <= v->num_orders && sel >= 0) ? sel : INVALID_ORDER;
|
|
|
|
}
|
|
|
|
|
2005-06-15 16:58:15 +00:00
|
|
|
static StringID StationOrderStrings[] = {
|
2005-06-15 17:18:32 +00:00
|
|
|
STR_8806_GO_TO,
|
2005-06-15 16:58:15 +00:00
|
|
|
STR_8807_GO_TO_TRANSFER,
|
|
|
|
STR_8808_GO_TO_UNLOAD,
|
|
|
|
STR_8809_GO_TO_TRANSFER_UNLOAD,
|
|
|
|
STR_880A_GO_TO_LOAD,
|
|
|
|
STR_880B_GO_TO_TRANSFER_LOAD,
|
|
|
|
STR_NULL,
|
|
|
|
STR_NULL,
|
|
|
|
STR_880C_GO_NON_STOP_TO,
|
|
|
|
STR_880D_GO_TO_NON_STOP_TRANSFER,
|
|
|
|
STR_880E_GO_NON_STOP_TO_UNLOAD,
|
|
|
|
STR_880F_GO_TO_NON_STOP_TRANSFER_UNLOAD,
|
|
|
|
STR_8810_GO_NON_STOP_TO_LOAD,
|
|
|
|
STR_8811_GO_TO_NON_STOP_TRANSFER_LOAD,
|
|
|
|
STR_NULL
|
|
|
|
};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void DrawOrdersWindow(Window *w)
|
|
|
|
{
|
2005-01-15 19:06:22 +00:00
|
|
|
const Vehicle *v;
|
|
|
|
const Order *order;
|
2004-08-09 17:04:08 +00:00
|
|
|
StringID str;
|
2005-01-15 19:06:22 +00:00
|
|
|
int sel;
|
|
|
|
int y, i;
|
|
|
|
bool shared_orders;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
v = GetVehicle(w->window_number);
|
2005-01-15 08:58:31 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
shared_orders = IsOrderListShared(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
SetVScrollCount(w, v->num_orders + 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
sel = OrderGetSel(w);
|
2005-01-15 19:06:22 +00:00
|
|
|
SetDParam(2, STR_8827_FULL_LOAD);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
order = GetVehicleOrder(v, sel);
|
2004-12-19 21:03:16 +00:00
|
|
|
|
2006-10-24 23:11:40 +00:00
|
|
|
if (v->owner == _local_player) {
|
|
|
|
/* skip */
|
2007-12-02 14:29:48 +00:00
|
|
|
w->SetWidgetDisabledState(ORDER_WIDGET_SKIP, v->num_orders <= 1);
|
2006-10-24 23:11:40 +00:00
|
|
|
|
|
|
|
/* delete */
|
2007-12-02 14:29:48 +00:00
|
|
|
w->SetWidgetDisabledState(ORDER_WIDGET_DELETE,
|
2007-02-12 00:38:15 +00:00
|
|
|
(uint)v->num_orders + ((shared_orders || v->num_orders != 0) ? 1 : 0) <= (uint)WP(w, order_d).sel);
|
2006-10-24 23:11:40 +00:00
|
|
|
|
|
|
|
/* non-stop only for trains */
|
2007-12-02 14:29:48 +00:00
|
|
|
w->SetWidgetDisabledState(ORDER_WIDGET_NON_STOP, v->type != VEH_TRAIN || order == NULL);
|
|
|
|
w->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD, order == NULL); // full load
|
|
|
|
w->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD, order == NULL); // unload
|
|
|
|
w->SetWidgetDisabledState(ORDER_WIDGET_TRANSFER, order == NULL); // transfer
|
2006-10-24 23:11:40 +00:00
|
|
|
/* Disable list of vehicles with the same shared orders if there is no list */
|
2007-12-02 14:29:48 +00:00
|
|
|
w->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders || v->orders == NULL);
|
|
|
|
w->SetWidgetDisabledState(ORDER_WIDGET_REFIT, order == NULL); // Refit
|
|
|
|
w->HideWidget(ORDER_WIDGET_REFIT); // Refit
|
2006-10-24 23:11:40 +00:00
|
|
|
} else {
|
2007-12-02 14:29:48 +00:00
|
|
|
w->DisableWidget(ORDER_WIDGET_TRANSFER);
|
2006-10-24 23:11:40 +00:00
|
|
|
}
|
2006-10-03 14:52:39 +00:00
|
|
|
|
2007-12-02 14:29:48 +00:00
|
|
|
w->ShowWidget(ORDER_WIDGET_UNLOAD); // Unload
|
2006-10-03 02:08:15 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
if (order != NULL) {
|
|
|
|
switch (order->type) {
|
2007-12-11 17:44:55 +00:00
|
|
|
case OT_GOTO_STATION:
|
|
|
|
if (!GetStation(order->dest)->IsBuoy()) break;
|
|
|
|
/* Fall-through */
|
|
|
|
|
|
|
|
case OT_GOTO_WAYPOINT:
|
|
|
|
w->DisableWidget(ORDER_WIDGET_FULL_LOAD);
|
|
|
|
w->DisableWidget(ORDER_WIDGET_UNLOAD);
|
|
|
|
w->DisableWidget(ORDER_WIDGET_TRANSFER);
|
|
|
|
break;
|
2005-10-23 13:04:44 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
case OT_GOTO_DEPOT:
|
2007-12-02 14:29:48 +00:00
|
|
|
w->DisableWidget(ORDER_WIDGET_TRANSFER);
|
2006-10-03 14:52:39 +00:00
|
|
|
|
|
|
|
/* Remove unload and replace it with refit */
|
2007-12-02 14:29:48 +00:00
|
|
|
w->HideWidget(ORDER_WIDGET_UNLOAD);
|
|
|
|
w->ShowWidget(ORDER_WIDGET_REFIT);
|
2005-01-15 19:06:22 +00:00
|
|
|
SetDParam(2,STR_SERVICE);
|
|
|
|
break;
|
|
|
|
|
2006-10-03 02:08:15 +00:00
|
|
|
default: // every other orders
|
2007-12-02 14:29:48 +00:00
|
|
|
w->DisableWidget(ORDER_WIDGET_NON_STOP);
|
|
|
|
w->DisableWidget(ORDER_WIDGET_FULL_LOAD);
|
|
|
|
w->DisableWidget(ORDER_WIDGET_UNLOAD);
|
2005-01-15 19:06:22 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 22:42:11 +00:00
|
|
|
SetDParam(0, v->index);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
y = 15;
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
i = w->vscroll.pos;
|
|
|
|
order = GetVehicleOrder(v, i);
|
|
|
|
while (order != NULL) {
|
|
|
|
str = (v->cur_order_index == i) ? STR_8805 : STR_8804;
|
2006-10-03 14:52:39 +00:00
|
|
|
SetDParam(3, STR_EMPTY);
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2005-01-30 23:41:57 +00:00
|
|
|
if (i - w->vscroll.pos < w->vscroll.cap) {
|
2005-01-15 19:06:22 +00:00
|
|
|
SetDParam(1, 6);
|
|
|
|
|
2005-11-13 14:54:09 +00:00
|
|
|
switch (order->type) {
|
2007-07-23 19:24:32 +00:00
|
|
|
case OT_DUMMY:
|
|
|
|
SetDParam(1, STR_INVALID_ORDER);
|
|
|
|
SetDParam(2, order->dest);
|
|
|
|
break;
|
|
|
|
|
2005-11-13 14:54:09 +00:00
|
|
|
case OT_GOTO_STATION:
|
|
|
|
SetDParam(1, StationOrderStrings[order->flags]);
|
2006-09-03 08:25:27 +00:00
|
|
|
SetDParam(2, order->dest);
|
2005-11-13 14:54:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OT_GOTO_DEPOT: {
|
|
|
|
StringID s = STR_NULL;
|
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_AIRCRAFT) {
|
2005-11-13 14:54:09 +00:00
|
|
|
s = STR_GO_TO_AIRPORT_HANGAR;
|
2006-09-03 08:25:27 +00:00
|
|
|
SetDParam(2, order->dest);
|
2005-11-13 14:54:09 +00:00
|
|
|
} else {
|
2006-09-03 08:25:27 +00:00
|
|
|
SetDParam(2, GetDepot(order->dest)->town_index);
|
2005-11-13 14:54:09 +00:00
|
|
|
|
|
|
|
switch (v->type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: s = (order->flags & OF_NON_STOP) ? STR_880F_GO_NON_STOP_TO_TRAIN_DEPOT : STR_GO_TO_TRAIN_DEPOT; break;
|
|
|
|
case VEH_ROAD: s = STR_9038_GO_TO_ROADVEH_DEPOT; break;
|
|
|
|
case VEH_SHIP: s = STR_GO_TO_SHIP_DEPOT; break;
|
2005-11-13 14:54:09 +00:00
|
|
|
default: break;
|
|
|
|
}
|
2005-01-15 19:06:22 +00:00
|
|
|
}
|
2005-06-15 16:58:15 +00:00
|
|
|
|
2005-11-13 14:54:09 +00:00
|
|
|
if (order->flags & OF_FULL_LOAD) s++; /* service at */
|
|
|
|
|
2005-06-15 16:58:15 +00:00
|
|
|
SetDParam(1, s);
|
2006-10-08 21:10:00 +00:00
|
|
|
if (order->refit_cargo < NUM_CARGO) {
|
2006-10-03 14:52:39 +00:00
|
|
|
SetDParam(3, STR_REFIT_ORDER);
|
2007-02-20 22:09:21 +00:00
|
|
|
SetDParam(4, GetCargo(order->refit_cargo)->name);
|
2006-10-08 21:10:00 +00:00
|
|
|
} else {
|
|
|
|
SetDParam(3, STR_EMPTY);
|
2006-10-03 14:52:39 +00:00
|
|
|
}
|
2005-11-13 14:54:09 +00:00
|
|
|
break;
|
2005-01-15 19:06:22 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-11-13 14:54:09 +00:00
|
|
|
case OT_GOTO_WAYPOINT:
|
|
|
|
SetDParam(1, (order->flags & OF_NON_STOP) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
|
2006-09-03 08:25:27 +00:00
|
|
|
SetDParam(2, order->dest);
|
2005-11-13 14:54:09 +00:00
|
|
|
break;
|
2006-08-22 17:13:49 +00:00
|
|
|
|
|
|
|
default: break;
|
2005-01-15 19:06:22 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
SetDParam(0, i + 1);
|
2007-12-16 10:54:08 +00:00
|
|
|
DrawString(2, y, str, (i == WP(w, order_d).sel) ? TC_WHITE : TC_BLACK);
|
2007-07-23 19:24:32 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
2005-01-15 19:06:22 +00:00
|
|
|
order = order->next;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-30 23:41:57 +00:00
|
|
|
if (i - w->vscroll.pos < w->vscroll.cap) {
|
2005-01-15 19:06:22 +00:00
|
|
|
str = shared_orders ? STR_END_OF_SHARED_ORDERS : STR_882A_END_OF_ORDERS;
|
2007-12-16 10:54:08 +00:00
|
|
|
DrawString(2, y, str, (i == WP(w, order_d).sel) ? TC_WHITE : TC_BLACK);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-12-05 21:30:58 +00:00
|
|
|
Order order;
|
2006-03-31 09:08:02 +00:00
|
|
|
order.next = NULL;
|
|
|
|
order.index = 0;
|
2006-10-03 16:05:11 +00:00
|
|
|
order.refit_cargo = CT_INVALID;
|
|
|
|
order.refit_subtype = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// check depot first
|
|
|
|
if (_patches.gotodepot) {
|
2005-01-29 15:12:40 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case MP_RAILWAY:
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_player)) {
|
2006-07-27 05:30:53 +00:00
|
|
|
if (IsRailDepot(tile)) {
|
2004-12-05 21:30:58 +00:00
|
|
|
order.type = OT_GOTO_DEPOT;
|
2005-03-20 08:43:29 +00:00
|
|
|
order.flags = OF_PART_OF_ORDERS;
|
2006-09-03 08:25:27 +00:00
|
|
|
order.dest = GetDepotByTile(tile)->index;
|
2004-12-05 21:30:58 +00:00
|
|
|
return order;
|
2004-12-06 00:03:26 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-29 23:42:59 +00:00
|
|
|
case MP_ROAD:
|
2007-03-08 16:27:54 +00:00
|
|
|
if (GetRoadTileType(tile) == ROAD_TILE_DEPOT && v->type == VEH_ROAD && IsTileOwner(tile, _local_player)) {
|
2004-12-05 21:30:58 +00:00
|
|
|
order.type = OT_GOTO_DEPOT;
|
2005-03-20 08:43:29 +00:00
|
|
|
order.flags = OF_PART_OF_ORDERS;
|
2006-09-03 08:25:27 +00:00
|
|
|
order.dest = GetDepotByTile(tile)->index;
|
2004-12-05 21:30:58 +00:00
|
|
|
return order;
|
2004-12-06 00:03:26 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_STATION:
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type != VEH_AIRCRAFT) break;
|
2006-03-26 19:20:15 +00:00
|
|
|
if (IsHangar(tile) && IsTileOwner(tile, _local_player)) {
|
2004-12-05 21:30:58 +00:00
|
|
|
order.type = OT_GOTO_DEPOT;
|
2005-12-21 01:14:01 +00:00
|
|
|
order.flags = OF_PART_OF_ORDERS;
|
2006-09-03 08:25:27 +00:00
|
|
|
order.dest = GetStationIndex(tile);
|
2004-12-05 21:30:58 +00:00
|
|
|
return order;
|
2004-12-06 00:03:26 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_WATER:
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type != VEH_SHIP) break;
|
2005-02-07 10:37:12 +00:00
|
|
|
if (IsTileDepotType(tile, TRANSPORT_WATER) &&
|
|
|
|
IsTileOwner(tile, _local_player)) {
|
2006-03-31 10:47:06 +00:00
|
|
|
TileIndex tile2 = GetOtherShipDepotTile(tile);
|
|
|
|
|
2004-12-05 21:30:58 +00:00
|
|
|
order.type = OT_GOTO_DEPOT;
|
2005-03-20 08:43:29 +00:00
|
|
|
order.flags = OF_PART_OF_ORDERS;
|
2006-09-03 08:25:27 +00:00
|
|
|
order.dest = GetDepotByTile(tile < tile2 ? tile : tile2)->index;
|
2004-12-05 21:30:58 +00:00
|
|
|
return order;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-01-29 15:12:40 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-14 13:07:07 +00:00
|
|
|
// check waypoint
|
2005-06-04 11:56:32 +00:00
|
|
|
if (IsTileType(tile, MP_RAILWAY) &&
|
2007-03-08 16:27:54 +00:00
|
|
|
v->type == VEH_TRAIN &&
|
2005-06-04 11:56:32 +00:00
|
|
|
IsTileOwner(tile, _local_player) &&
|
2005-11-16 14:41:01 +00:00
|
|
|
IsRailWaypoint(tile)) {
|
2004-12-05 21:30:58 +00:00
|
|
|
order.type = OT_GOTO_WAYPOINT;
|
|
|
|
order.flags = 0;
|
2006-09-03 08:25:27 +00:00
|
|
|
order.dest = GetWaypointByTile(tile)->index;
|
2004-12-05 21:30:58 +00:00
|
|
|
return order;
|
|
|
|
}
|
2004-09-27 14:30:17 +00:00
|
|
|
|
2005-01-16 11:24:58 +00:00
|
|
|
if (IsTileType(tile, MP_STATION)) {
|
2006-03-24 08:55:08 +00:00
|
|
|
StationID st_index = GetStationIndex(tile);
|
2006-07-26 03:33:12 +00:00
|
|
|
const Station *st = GetStation(st_index);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (st->owner == _current_player || st->owner == OWNER_NONE) {
|
|
|
|
byte facil;
|
2007-03-08 16:27:54 +00:00
|
|
|
(facil=FACIL_DOCK, v->type == VEH_SHIP) ||
|
|
|
|
(facil=FACIL_TRAIN, v->type == VEH_TRAIN) ||
|
|
|
|
(facil=FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
|
2007-03-18 22:07:44 +00:00
|
|
|
(facil=FACIL_BUS_STOP, v->type == VEH_ROAD && IsCargoInClass(v->cargo_type, CC_PASSENGERS)) ||
|
2004-08-09 17:04:08 +00:00
|
|
|
(facil=FACIL_TRUCK_STOP, 1);
|
2004-12-05 21:30:58 +00:00
|
|
|
if (st->facilities & facil) {
|
|
|
|
order.type = OT_GOTO_STATION;
|
|
|
|
order.flags = 0;
|
2006-09-03 08:25:27 +00:00
|
|
|
order.dest = st_index;
|
2004-12-05 21:30:58 +00:00
|
|
|
return order;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// not found
|
2007-03-08 21:39:34 +00:00
|
|
|
order.Free();
|
2006-09-03 08:25:27 +00:00
|
|
|
order.dest = INVALID_STATION;
|
2004-12-05 21:30:58 +00:00
|
|
|
return order;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static bool HandleOrderVehClick(const Vehicle *v, const Vehicle *u, Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-10-23 13:04:44 +00:00
|
|
|
if (u->type != v->type) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-09-09 11:23:49 +00:00
|
|
|
if (!u->IsPrimaryVehicle()) {
|
2007-08-30 21:11:12 +00:00
|
|
|
u = u->First();
|
2007-06-01 12:03:10 +00:00
|
|
|
if (!u->IsPrimaryVehicle()) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet
|
|
|
|
// obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
|
2005-10-23 13:04:44 +00:00
|
|
|
if (v->num_orders != 0 && _ctrl_pressed == 0) return false;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-12-12 14:37:35 +00:00
|
|
|
if (DoCommandP(v->tile, v->index | (u->index << 16), _ctrl_pressed ? CO_SHARE : CO_COPY, NULL,
|
2004-08-09 17:04:08 +00:00
|
|
|
_ctrl_pressed ? CMD_CLONE_ORDER | CMD_MSG(STR_CANT_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_CANT_COPY_ORDER_LIST))) {
|
2007-12-16 10:54:08 +00:00
|
|
|
WP(w, order_d).sel = -1;
|
2004-08-09 17:04:08 +00:00
|
|
|
ResetObjectToPlace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static void OrdersPlaceObj(const Vehicle *v, TileIndex tile, Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-12-05 21:30:58 +00:00
|
|
|
Order cmd;
|
2006-07-26 03:33:12 +00:00
|
|
|
const Vehicle *u;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// check if we're clicking on a vehicle first.. clone orders in that case.
|
|
|
|
u = CheckMouseOverVehicle();
|
2005-10-23 13:04:44 +00:00
|
|
|
if (u != NULL && HandleOrderVehClick(v, u, w)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
cmd = GetOrderCmdFromTile(v, tile);
|
2007-03-08 21:39:34 +00:00
|
|
|
if (!cmd.IsValid()) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-05 21:30:58 +00:00
|
|
|
if (DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), PackOrder(&cmd), NULL, CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER))) {
|
2007-12-16 10:54:08 +00:00
|
|
|
if (WP(w, order_d).sel != -1) WP(w,order_d).sel++;
|
2004-08-09 17:04:08 +00:00
|
|
|
ResetObjectToPlace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-05 22:17:03 +00:00
|
|
|
/**
|
|
|
|
* Handle the click on the goto button.
|
|
|
|
*
|
|
|
|
* @param w current window
|
|
|
|
* @param v current vehicle
|
|
|
|
*/
|
2006-07-26 03:33:12 +00:00
|
|
|
static void OrderClick_Goto(Window *w, const Vehicle *v)
|
2005-01-13 16:55:17 +00:00
|
|
|
{
|
2007-12-07 18:05:49 +00:00
|
|
|
w->InvalidateWidget(ORDER_WIDGET_GOTO);
|
2007-12-02 14:29:48 +00:00
|
|
|
w->ToggleWidgetLoweredState(ORDER_WIDGET_GOTO);
|
|
|
|
if (w->IsWidgetLowered(ORDER_WIDGET_GOTO)) {
|
2005-01-13 16:55:17 +00:00
|
|
|
_place_clicked_vehicle = NULL;
|
2007-11-15 18:28:00 +00:00
|
|
|
SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, VHM_RECT, w);
|
2005-01-13 16:55:17 +00:00
|
|
|
} else {
|
|
|
|
ResetObjectToPlace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-05 22:17:03 +00:00
|
|
|
/**
|
|
|
|
* Handle the click on the full load button.
|
|
|
|
*
|
|
|
|
* @param w current window
|
|
|
|
* @param v current vehicle
|
|
|
|
*/
|
2006-07-26 03:33:12 +00:00
|
|
|
static void OrderClick_FullLoad(Window *w, const Vehicle *v)
|
2005-01-13 16:55:17 +00:00
|
|
|
{
|
2005-01-15 19:06:22 +00:00
|
|
|
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OFB_FULL_LOAD, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
2005-01-13 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
2007-06-05 22:17:03 +00:00
|
|
|
/**
|
|
|
|
* Handle the click on the unload button.
|
|
|
|
*
|
|
|
|
* @param w current window
|
|
|
|
* @param v current vehicle
|
|
|
|
*/
|
2006-07-26 03:33:12 +00:00
|
|
|
static void OrderClick_Unload(Window *w, const Vehicle *v)
|
2005-01-13 16:55:17 +00:00
|
|
|
{
|
2005-01-15 19:06:22 +00:00
|
|
|
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OFB_UNLOAD, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
2005-01-13 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
2007-06-05 22:17:03 +00:00
|
|
|
/**
|
|
|
|
* Handle the click on the nonstop button.
|
|
|
|
*
|
|
|
|
* @param w current window
|
|
|
|
* @param v current vehicle
|
|
|
|
*/
|
2006-07-26 03:33:12 +00:00
|
|
|
static void OrderClick_Nonstop(Window *w, const Vehicle *v)
|
2005-01-13 16:55:17 +00:00
|
|
|
{
|
2005-01-15 19:06:22 +00:00
|
|
|
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OFB_NON_STOP, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
2005-01-13 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
2007-06-05 22:17:03 +00:00
|
|
|
/**
|
|
|
|
* Handle the click on the transfer button.
|
|
|
|
*
|
|
|
|
* @param w current window
|
|
|
|
* @param v current vehicle
|
|
|
|
*/
|
2005-10-23 13:04:44 +00:00
|
|
|
static void OrderClick_Transfer(Window* w, const Vehicle* v)
|
2005-06-15 16:58:15 +00:00
|
|
|
{
|
|
|
|
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OFB_TRANSFER, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
|
|
|
}
|
|
|
|
|
2007-06-05 22:17:03 +00:00
|
|
|
/**
|
|
|
|
* Handle the click on the skip button.
|
|
|
|
* If ctrl is pressed skip to selected order.
|
|
|
|
* Else skip to current order + 1
|
|
|
|
*
|
|
|
|
* @param w current window
|
|
|
|
* @param v current vehicle
|
|
|
|
*/
|
2006-07-26 03:33:12 +00:00
|
|
|
static void OrderClick_Skip(Window *w, const Vehicle *v)
|
2005-01-13 16:55:17 +00:00
|
|
|
{
|
2007-06-04 19:32:45 +00:00
|
|
|
/* Don't skip when there's nothing to skip */
|
|
|
|
if (_ctrl_pressed && v->cur_order_index == OrderGetSel(w)) return;
|
|
|
|
|
|
|
|
DoCommandP(v->tile, v->index, _ctrl_pressed ? OrderGetSel(w) : ((v->cur_order_index + 1) % v->num_orders),
|
|
|
|
NULL, CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_CAN_T_SKIP_TO_ORDER : STR_CAN_T_SKIP_ORDER));
|
2005-01-13 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
2007-06-05 22:17:03 +00:00
|
|
|
/**
|
|
|
|
* Handle the click on the unload button.
|
|
|
|
*
|
|
|
|
* @param w current window
|
|
|
|
* @param v current vehicle
|
|
|
|
*/
|
2006-07-26 03:33:12 +00:00
|
|
|
static void OrderClick_Delete(Window *w, const Vehicle *v)
|
2005-01-13 16:55:17 +00:00
|
|
|
{
|
2005-01-15 19:06:22 +00:00
|
|
|
DoCommandP(v->tile, v->index, OrderGetSel(w), NULL, CMD_DELETE_ORDER | CMD_MSG(STR_8834_CAN_T_DELETE_THIS_ORDER));
|
2005-01-13 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
2007-06-05 22:17:03 +00:00
|
|
|
/**
|
|
|
|
* Handle the click on the refit button.
|
|
|
|
* If ctrl is pressed cancel refitting.
|
|
|
|
* Else show the refit window.
|
|
|
|
*
|
|
|
|
* @param w current window
|
|
|
|
* @param v current vehicle
|
|
|
|
*/
|
2006-10-03 14:52:39 +00:00
|
|
|
static void OrderClick_Refit(Window *w, const Vehicle *v)
|
|
|
|
{
|
|
|
|
if (_ctrl_pressed) {
|
|
|
|
/* Cancel refitting */
|
2007-12-16 10:54:08 +00:00
|
|
|
DoCommandP(v->tile, v->index, (WP(w, order_d).sel << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, NULL, CMD_ORDER_REFIT);
|
2006-10-03 14:52:39 +00:00
|
|
|
} else {
|
2007-12-16 10:54:08 +00:00
|
|
|
ShowVehicleRefitWindow(v, WP(w, order_d).sel);
|
2006-10-03 14:52:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
typedef void OnButtonVehClick(Window *w, const Vehicle *v);
|
2005-01-13 16:55:17 +00:00
|
|
|
|
2007-06-05 22:17:03 +00:00
|
|
|
/**
|
|
|
|
* Keycode function mapping.
|
|
|
|
*
|
|
|
|
* @see _order_keycodes[]
|
|
|
|
* @note Keep them allways in sync with _order_keycodes[]!
|
|
|
|
*/
|
2006-07-26 03:33:12 +00:00
|
|
|
static OnButtonVehClick* const _order_button_proc[] = {
|
2005-01-13 16:55:17 +00:00
|
|
|
OrderClick_Skip,
|
|
|
|
OrderClick_Delete,
|
|
|
|
OrderClick_Nonstop,
|
|
|
|
OrderClick_Goto,
|
|
|
|
OrderClick_FullLoad,
|
2005-06-15 16:58:15 +00:00
|
|
|
OrderClick_Unload,
|
|
|
|
OrderClick_Transfer
|
2005-01-13 16:55:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const uint16 _order_keycodes[] = {
|
|
|
|
'D', //skip order
|
|
|
|
'F', //delete order
|
|
|
|
'G', //non-stop
|
|
|
|
'H', //goto order
|
|
|
|
'J', //full load
|
|
|
|
'K' //unload
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static void OrdersWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-10-23 13:04:44 +00:00
|
|
|
switch (e->event) {
|
2006-10-03 14:52:39 +00:00
|
|
|
case WE_CREATE:
|
2007-01-24 19:19:12 +00:00
|
|
|
/* Ensure that the refit and unload buttons always remain at the same location.
|
|
|
|
* Only one of them can be active at any one time and takes turns on being disabled.
|
|
|
|
* To ensure that they stay at the same location, we also verify that they behave the same
|
|
|
|
* when resizing. */
|
|
|
|
if (GetVehicle(w->window_number)->owner == _local_player) { // only the vehicle owner got these buttons
|
|
|
|
assert(w->widget[ORDER_WIDGET_REFIT].left == w->widget[ORDER_WIDGET_UNLOAD].left);
|
|
|
|
assert(w->widget[ORDER_WIDGET_REFIT].right == w->widget[ORDER_WIDGET_UNLOAD].right);
|
|
|
|
assert(w->widget[ORDER_WIDGET_REFIT].top == w->widget[ORDER_WIDGET_UNLOAD].top);
|
|
|
|
assert(w->widget[ORDER_WIDGET_REFIT].bottom == w->widget[ORDER_WIDGET_UNLOAD].bottom);
|
|
|
|
assert(w->widget[ORDER_WIDGET_REFIT].display_flags == w->widget[ORDER_WIDGET_UNLOAD].display_flags);
|
|
|
|
}
|
2007-06-20 19:17:22 +00:00
|
|
|
|
|
|
|
if (_patches.timetabling) {
|
|
|
|
w->widget[ORDER_WIDGET_CAPTION].right -= 61;
|
|
|
|
} else {
|
2007-12-02 14:29:48 +00:00
|
|
|
w->HideWidget(ORDER_WIDGET_TIMETABLE_VIEW);
|
2007-06-20 19:17:22 +00:00
|
|
|
}
|
|
|
|
|
2006-10-03 14:52:39 +00:00
|
|
|
break;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT:
|
|
|
|
DrawOrdersWindow(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_CLICK: {
|
2007-06-08 18:59:29 +00:00
|
|
|
const Vehicle *v = GetVehicle(w->window_number);
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2007-01-24 18:22:31 +00:00
|
|
|
case ORDER_WIDGET_ORDER_LIST: {
|
2007-06-08 18:59:29 +00:00
|
|
|
ResetObjectToPlace();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-08 18:59:29 +00:00
|
|
|
int sel = GetOrderFromOrderWndPt(w, e->we.click.pt.y, v);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-17 10:14:47 +00:00
|
|
|
if (sel == INVALID_ORDER) {
|
|
|
|
/* This was a click on an empty part of the orders window, so
|
|
|
|
* deselect the currently selected order. */
|
2007-12-16 10:54:08 +00:00
|
|
|
WP(w, order_d).sel = -1;
|
2007-06-17 10:14:47 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
if (_ctrl_pressed && sel < v->num_orders) {
|
2005-01-16 14:42:53 +00:00
|
|
|
const Order *ord = GetVehicleOrder(v, sel);
|
2006-06-27 21:25:53 +00:00
|
|
|
TileIndex xy;
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
switch (ord->type) {
|
2006-09-03 08:25:27 +00:00
|
|
|
case OT_GOTO_STATION: xy = GetStation(ord->dest)->xy ; break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case OT_GOTO_DEPOT: xy = (v->type == VEH_AIRCRAFT) ? GetStation(ord->dest)->xy : GetDepot(ord->dest)->xy; break;
|
2006-09-03 08:25:27 +00:00
|
|
|
case OT_GOTO_WAYPOINT: xy = GetWaypoint(ord->dest)->xy; break;
|
2006-06-27 21:25:53 +00:00
|
|
|
default: xy = 0; break;
|
2004-08-13 20:30:45 +00:00
|
|
|
}
|
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
if (xy != 0) ScrollMainWindowToTile(xy);
|
2004-08-13 20:30:45 +00:00
|
|
|
return;
|
2007-06-08 18:59:29 +00:00
|
|
|
} else {
|
2007-12-16 10:54:08 +00:00
|
|
|
if (sel == WP(w, order_d).sel) {
|
2007-06-08 18:59:29 +00:00
|
|
|
/* Deselect clicked order */
|
2007-12-16 10:54:08 +00:00
|
|
|
WP(w, order_d).sel = -1;
|
2007-06-08 18:59:29 +00:00
|
|
|
} else {
|
|
|
|
/* Select clicked order */
|
2007-12-16 10:54:08 +00:00
|
|
|
WP(w, order_d).sel = sel;
|
2007-06-08 18:59:29 +00:00
|
|
|
|
|
|
|
if (v->owner == _local_player) {
|
|
|
|
/* Activate drag and drop */
|
2007-11-15 18:28:00 +00:00
|
|
|
SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, VHM_DRAG, w);
|
2007-06-08 18:59:29 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-13 20:30:45 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
2007-04-18 22:41:53 +00:00
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-24 18:22:31 +00:00
|
|
|
case ORDER_WIDGET_SKIP:
|
2005-01-13 16:55:17 +00:00
|
|
|
OrderClick_Skip(w, v);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2007-01-24 18:22:31 +00:00
|
|
|
case ORDER_WIDGET_DELETE:
|
2005-01-13 16:55:17 +00:00
|
|
|
OrderClick_Delete(w, v);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2007-01-24 18:22:31 +00:00
|
|
|
case ORDER_WIDGET_NON_STOP:
|
2005-01-13 16:55:17 +00:00
|
|
|
OrderClick_Nonstop(w, v);
|
|
|
|
break;
|
2005-01-15 08:58:31 +00:00
|
|
|
|
2007-01-24 18:22:31 +00:00
|
|
|
case ORDER_WIDGET_GOTO:
|
2005-01-13 16:55:17 +00:00
|
|
|
OrderClick_Goto(w, v);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2007-01-24 18:22:31 +00:00
|
|
|
case ORDER_WIDGET_FULL_LOAD:
|
2005-01-13 16:55:17 +00:00
|
|
|
OrderClick_FullLoad(w, v);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2007-01-24 18:22:31 +00:00
|
|
|
case ORDER_WIDGET_UNLOAD:
|
2005-01-13 16:55:17 +00:00
|
|
|
OrderClick_Unload(w, v);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2007-01-24 18:41:27 +00:00
|
|
|
case ORDER_WIDGET_REFIT:
|
|
|
|
OrderClick_Refit(w, v);
|
|
|
|
break;
|
|
|
|
|
2007-01-24 18:22:31 +00:00
|
|
|
case ORDER_WIDGET_TRANSFER:
|
2005-06-15 16:58:15 +00:00
|
|
|
OrderClick_Transfer(w, v);
|
|
|
|
break;
|
2007-06-20 19:17:22 +00:00
|
|
|
|
|
|
|
case ORDER_WIDGET_TIMETABLE_VIEW:
|
|
|
|
ShowTimetableWindow(v);
|
|
|
|
break;
|
|
|
|
|
2007-01-24 18:22:31 +00:00
|
|
|
case ORDER_WIDGET_SHARED_ORDER_LIST:
|
2007-01-21 00:01:47 +00:00
|
|
|
ShowVehicleListWindow(v);
|
2006-08-26 22:28:40 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} break;
|
2005-01-15 08:58:31 +00:00
|
|
|
|
2007-06-08 18:59:29 +00:00
|
|
|
case WE_DRAGDROP: {
|
|
|
|
const Vehicle *v = GetVehicle(w->window_number);
|
|
|
|
|
|
|
|
switch (e->we.click.widget) {
|
|
|
|
case ORDER_WIDGET_ORDER_LIST: {
|
|
|
|
int from_order = OrderGetSel(w);
|
|
|
|
int to_order = GetOrderFromOrderWndPt(w, e->we.dragdrop.pt.y, v);
|
|
|
|
|
|
|
|
if (!(from_order == to_order || from_order == INVALID_ORDER || from_order > v->num_orders || to_order == INVALID_ORDER || to_order > v->num_orders) &&
|
|
|
|
DoCommandP(v->tile, v->index, from_order | (to_order << 16), NULL, CMD_MOVE_ORDER | CMD_MSG(STR_CAN_T_MOVE_THIS_ORDER))) {
|
|
|
|
WP(w, order_d).sel = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ORDER_WIDGET_DELETE:
|
|
|
|
OrderClick_Delete(w, v);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResetObjectToPlace();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-13 16:55:17 +00:00
|
|
|
case WE_KEYPRESS: {
|
|
|
|
Vehicle *v = GetVehicle(w->window_number);
|
|
|
|
uint i;
|
|
|
|
|
2006-10-24 23:11:40 +00:00
|
|
|
if (v->owner != _local_player) break;
|
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (i = 0; i < lengthof(_order_keycodes); i++) {
|
2006-09-23 02:39:24 +00:00
|
|
|
if (e->we.keypress.keycode == _order_keycodes[i]) {
|
|
|
|
e->we.keypress.cont = false;
|
2005-01-15 08:58:31 +00:00
|
|
|
//see if the button is disabled
|
2007-12-02 14:29:48 +00:00
|
|
|
if (!w->IsWidgetDisabled(i + ORDER_WIDGET_SKIP)) _order_button_proc[i](w, v);
|
2005-01-13 16:55:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_RCLICK: {
|
2006-07-26 03:33:12 +00:00
|
|
|
const Vehicle *v = GetVehicle(w->window_number);
|
2005-11-14 19:48:04 +00:00
|
|
|
int s = OrderGetSel(w);
|
|
|
|
|
2007-01-24 18:22:31 +00:00
|
|
|
if (e->we.click.widget != ORDER_WIDGET_FULL_LOAD) break;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (s == v->num_orders || GetVehicleOrder(v, s)->type != OT_GOTO_DEPOT) {
|
2004-08-09 17:04:08 +00:00
|
|
|
GuiShowTooltips(STR_8857_MAKE_THE_HIGHLIGHTED_ORDER);
|
2005-11-14 19:48:04 +00:00
|
|
|
} else {
|
2005-02-01 09:47:18 +00:00
|
|
|
GuiShowTooltips(STR_SERVICE_HINT);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2005-01-30 23:41:57 +00:00
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
case WE_PLACE_OBJ: {
|
2006-09-23 02:39:24 +00:00
|
|
|
OrdersPlaceObj(GetVehicle(w->window_number), e->we.place.tile, w);
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_ABORT_PLACE_OBJ: {
|
2007-12-02 14:29:48 +00:00
|
|
|
w->RaiseWidget(ORDER_WIDGET_GOTO);
|
2007-12-07 18:05:49 +00:00
|
|
|
w->InvalidateWidget(ORDER_WIDGET_GOTO);
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
// check if a vehicle in a depot was clicked..
|
|
|
|
case WE_MOUSELOOP: {
|
2006-07-26 03:33:12 +00:00
|
|
|
const Vehicle *v = _place_clicked_vehicle;
|
2004-08-12 17:11:47 +00:00
|
|
|
/*
|
|
|
|
* Check if we clicked on a vehicle
|
|
|
|
* and if the GOTO button of this window is pressed
|
|
|
|
* This is because of all open order windows WE_MOUSELOOP is called
|
|
|
|
* and if you have 3 windows open, and this check is not done
|
|
|
|
* the order is copied to the last open window instead of the
|
2006-10-24 23:11:40 +00:00
|
|
|
* one where GOTO is enabled
|
2004-08-12 17:11:47 +00:00
|
|
|
*/
|
2007-12-02 14:29:48 +00:00
|
|
|
if (v != NULL && w->IsWidgetLowered(ORDER_WIDGET_GOTO)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_place_clicked_vehicle = NULL;
|
2005-01-06 22:31:58 +00:00
|
|
|
HandleOrderVehClick(GetVehicle(w->window_number), v, w);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} break;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-30 23:41:57 +00:00
|
|
|
case WE_RESIZE:
|
|
|
|
/* Update the scroll + matrix */
|
2007-01-24 18:22:31 +00:00
|
|
|
w->vscroll.cap = (w->widget[ORDER_WIDGET_ORDER_LIST].bottom - w->widget[ORDER_WIDGET_ORDER_LIST].top) / 10;
|
2005-01-30 23:41:57 +00:00
|
|
|
break;
|
2006-11-02 23:51:05 +00:00
|
|
|
|
|
|
|
case WE_TIMEOUT: { // handle button unclick ourselves...
|
2007-01-24 18:22:31 +00:00
|
|
|
// unclick all buttons except for the 'goto' button (ORDER_WIDGET_GOTO), which is 'persistent'
|
2006-12-04 13:46:03 +00:00
|
|
|
uint i;
|
|
|
|
for (i = 0; i < w->widget_count; i++) {
|
2007-12-02 14:29:48 +00:00
|
|
|
if (w->IsWidgetLowered(i) && i != ORDER_WIDGET_GOTO) {
|
|
|
|
w->RaiseWidget(i);
|
2007-12-07 18:05:49 +00:00
|
|
|
w->InvalidateWidget(i);
|
2006-11-02 23:51:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-01-30 23:41:57 +00:00
|
|
|
}
|
2005-01-13 16:55:17 +00:00
|
|
|
|
2007-06-05 22:17:03 +00:00
|
|
|
/**
|
|
|
|
* Widget definition for player train orders
|
|
|
|
*/
|
2005-01-21 18:36:17 +00:00
|
|
|
static const Widget _orders_train_widgets[] = {
|
2007-06-05 22:17:03 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // ORDER_WIDGET_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 398, 0, 13, STR_8829_ORDERS, STR_018C_WINDOW_TITLE_DRAG_THIS}, // ORDER_WIDGET_CAPTION
|
2007-06-20 19:17:22 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_LR, 14, 338, 398, 0, 13, STR_TIMETABLE_VIEW, STR_TIMETABLE_VIEW_TOOLTIP}, // ORDER_WIDGET_TIMETABLE_VIEW
|
2007-06-05 22:17:03 +00:00
|
|
|
|
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 386, 14, 75, 0x0, STR_8852_ORDERS_LIST_CLICK_ON_ORDER}, // ORDER_WIDGET_ORDER_LIST
|
|
|
|
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 387, 398, 14, 75, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // ORDER_WIDGET_SCROLLBAR
|
|
|
|
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 52, 76, 87, STR_8823_SKIP, STR_8853_SKIP_THE_CURRENT_ORDER}, // ORDER_WIDGET_SKIP
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 53, 105, 76, 87, STR_8824_DELETE, STR_8854_DELETE_THE_HIGHLIGHTED}, // ORDER_WIDGET_DELETE
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 106, 158, 76, 87, STR_8825_NON_STOP, STR_8855_MAKE_THE_HIGHLIGHTED_ORDER}, // ORDER_WIDGET_NON_STOP
|
|
|
|
{ WWT_TEXTBTN, RESIZE_TB, 14, 159, 211, 76, 87, STR_8826_GO_TO, STR_8856_INSERT_A_NEW_ORDER_BEFORE}, // ORDER_WIDGET_GOTO
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 212, 264, 76, 87, STR_FULLLOAD_OR_SERVICE, STR_NULL}, // ORDER_WIDGET_FULL_LOAD
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 265, 319, 76, 87, STR_8828_UNLOAD, STR_8858_MAKE_THE_HIGHLIGHTED_ORDER}, // ORDER_WIDGET_UNLOAD
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 265, 319, 76, 87, STR_REFIT, STR_REFIT_TIP}, // ORDER_WIDGET_REFIT
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 320, 372, 76, 87, STR_886F_TRANSFER, STR_886D_MAKE_THE_HIGHLIGHTED_ORDER}, // ORDER_WIDGET_TRANSFER
|
|
|
|
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_TB, 14, 373, 386, 76, 87, SPR_SHARED_ORDERS_ICON, STR_VEH_WITH_SHARED_ORDERS_LIST_TIP}, // ORDER_WIDGET_SHARED_ORDER_LIST
|
|
|
|
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 387, 386, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_RESIZE_BAR
|
|
|
|
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 387, 398, 76, 87, 0x0, STR_RESIZE_BUTTON}, // ORDER_WIDGET_RESIZE
|
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-01-21 18:36:17 +00:00
|
|
|
static const WindowDesc _orders_train_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 399, 88, 399, 88,
|
2005-01-21 18:36:17 +00:00
|
|
|
WC_VEHICLE_ORDERS,WC_VEHICLE_VIEW,
|
2006-11-02 23:51:05 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
|
2005-01-21 18:36:17 +00:00
|
|
|
_orders_train_widgets,
|
|
|
|
OrdersWndProc
|
|
|
|
};
|
|
|
|
|
2007-06-05 22:17:03 +00:00
|
|
|
/**
|
|
|
|
* Widget definition for player orders (!train)
|
|
|
|
*/
|
2005-01-21 18:36:17 +00:00
|
|
|
static const Widget _orders_widgets[] = {
|
2007-06-05 22:17:03 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // ORDER_WIDGET_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 409, 0, 13, STR_8829_ORDERS, STR_018C_WINDOW_TITLE_DRAG_THIS}, // ORDER_WIDGET_CAPTION
|
2007-06-20 19:17:22 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_LR, 14, 349, 409, 0, 13, STR_TIMETABLE_VIEW, STR_TIMETABLE_VIEW_TOOLTIP}, // ORDER_WIDGET_TIMETABLE_VIEW
|
2007-06-05 22:17:03 +00:00
|
|
|
|
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 397, 14, 75, 0x0, STR_8852_ORDERS_LIST_CLICK_ON_ORDER}, // ORDER_WIDGET_ORDER_LIST
|
|
|
|
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 398, 409, 14, 75, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // ORDER_WIDGET_SCROLLBAR
|
|
|
|
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 63, 76, 87, STR_8823_SKIP, STR_8853_SKIP_THE_CURRENT_ORDER}, // ORDER_WIDGET_SKIP
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 64, 128, 76, 87, STR_8824_DELETE, STR_8854_DELETE_THE_HIGHLIGHTED}, // ORDER_WIDGET_DELETE
|
|
|
|
{ WWT_EMPTY, RESIZE_TB, 14, 0, 0, 76, 87, 0x0, 0x0}, // ORDER_WIDGET_NON_STOP
|
|
|
|
{ WWT_TEXTBTN, RESIZE_TB, 14, 129, 192, 76, 87, STR_8826_GO_TO, STR_8856_INSERT_A_NEW_ORDER_BEFORE}, // ORDER_WIDGET_GOTO
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 193, 256, 76, 87, STR_FULLLOAD_OR_SERVICE, STR_NULL}, // ORDER_WIDGET_FULL_LOAD
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 257, 319, 76, 87, STR_8828_UNLOAD, STR_8858_MAKE_THE_HIGHLIGHTED_ORDER}, // ORDER_WIDGET_UNLOAD
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 257, 319, 76, 87, STR_REFIT, STR_REFIT_TIP}, // ORDER_WIDGET_REFIT
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 320, 383, 76, 87, STR_886F_TRANSFER, STR_886D_MAKE_THE_HIGHLIGHTED_ORDER}, // ORDER_WIDGET_TRANSFER
|
|
|
|
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_TB, 14, 384, 397, 76, 87, SPR_SHARED_ORDERS_ICON, STR_VEH_WITH_SHARED_ORDERS_LIST_TIP}, // ORDER_WIDGET_SHARED_ORDER_LIST
|
|
|
|
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 397, 396, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_RESIZE_BAR
|
|
|
|
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 398, 409, 76, 87, 0x0, STR_RESIZE_BUTTON}, // ORDER_WIDGET_RESIZE
|
|
|
|
{ WIDGETS_END},
|
2005-01-21 18:36:17 +00:00
|
|
|
};
|
|
|
|
|
2005-01-12 22:09:21 +00:00
|
|
|
static const WindowDesc _orders_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 410, 88, 410, 88,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_VEHICLE_ORDERS,WC_VEHICLE_VIEW,
|
2006-11-02 23:51:05 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
|
2005-01-12 22:09:21 +00:00
|
|
|
_orders_widgets,
|
2004-08-09 17:04:08 +00:00
|
|
|
OrdersWndProc
|
|
|
|
};
|
|
|
|
|
2007-06-05 22:17:03 +00:00
|
|
|
/**
|
|
|
|
* Widget definition for competitor orders
|
|
|
|
*/
|
2005-01-12 22:09:21 +00:00
|
|
|
static const Widget _other_orders_widgets[] = {
|
2007-06-20 19:17:22 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // ORDER_WIDGET_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 331, 0, 13, STR_A00B_ORDERS, STR_018C_WINDOW_TITLE_DRAG_THIS}, // ORDER_WIDGET_CAPTION
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_LR, 14, 271, 331, 0, 13, STR_TIMETABLE_VIEW, STR_TIMETABLE_VIEW_TOOLTIP}, // ORDER_WIDGET_TIMETABLE_VIEW
|
2007-06-05 22:17:03 +00:00
|
|
|
|
2007-06-20 19:17:22 +00:00
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 319, 14, 75, 0x0, STR_8852_ORDERS_LIST_CLICK_ON_ORDER}, // ORDER_WIDGET_ORDER_LIST
|
2007-06-05 22:17:03 +00:00
|
|
|
|
2007-06-20 19:17:22 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 320, 331, 14, 75, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // ORDER_WIDGET_SCROLLBAR
|
2007-06-05 22:17:03 +00:00
|
|
|
|
2007-06-20 19:17:22 +00:00
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_SKIP
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_DELETE
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_NON_STOP
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_GOTO
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_FULL_LOAD
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_UNLOAD
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_REFIT
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_TRANSFER
|
2007-06-05 22:17:03 +00:00
|
|
|
|
2007-06-20 19:17:22 +00:00
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_SHARED_ORDER_LIST
|
2007-06-05 22:17:03 +00:00
|
|
|
|
2007-06-20 19:17:22 +00:00
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 0, 319, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_RESIZE_BAR
|
2007-06-05 22:17:03 +00:00
|
|
|
|
2007-06-20 19:17:22 +00:00
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 320, 331, 76, 87, 0x0, STR_RESIZE_BUTTON}, // ORDER_WIDGET_RESIZE
|
2007-06-05 22:17:03 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-01-12 22:09:21 +00:00
|
|
|
static const WindowDesc _other_orders_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 332, 88, 332, 88,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_VEHICLE_ORDERS,WC_VEHICLE_VIEW,
|
2005-01-30 23:41:57 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
2005-01-12 22:09:21 +00:00
|
|
|
_other_orders_widgets,
|
2004-08-09 17:04:08 +00:00
|
|
|
OrdersWndProc
|
|
|
|
};
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
void ShowOrdersWindow(const Vehicle *v)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
VehicleID veh = v->index;
|
|
|
|
|
|
|
|
DeleteWindowById(WC_VEHICLE_ORDERS, veh);
|
|
|
|
DeleteWindowById(WC_VEHICLE_DETAILS, veh);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-21 18:36:17 +00:00
|
|
|
if (v->owner != _local_player) {
|
2006-11-11 09:47:44 +00:00
|
|
|
w = AllocateWindowDescFront(&_other_orders_desc, veh);
|
2005-10-23 13:04:44 +00:00
|
|
|
} else {
|
2007-03-08 16:27:54 +00:00
|
|
|
w = AllocateWindowDescFront((v->type == VEH_TRAIN) ? &_orders_train_desc : &_orders_desc, veh);
|
2005-10-23 13:04:44 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-30 23:41:57 +00:00
|
|
|
if (w != NULL) {
|
|
|
|
w->caption_color = v->owner;
|
|
|
|
w->vscroll.cap = 6;
|
|
|
|
w->resize.step_height = 10;
|
2007-12-16 10:54:08 +00:00
|
|
|
WP(w, order_d).sel = -1;
|
2005-01-30 23:41:57 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|