2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-04-04 04:08:47 +00:00
|
|
|
/** @file vehicle_gui.cpp */
|
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "debug.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2005-07-21 19:36:43 +00:00
|
|
|
#include "player.h"
|
2005-09-27 18:51:04 +00:00
|
|
|
#include "station.h"
|
2005-02-06 08:18:00 +00:00
|
|
|
#include "strings.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"
|
2004-09-06 18:15:13 +00:00
|
|
|
#include "vehicle.h"
|
2004-12-10 18:16:08 +00:00
|
|
|
#include "window.h"
|
2005-01-02 17:23:04 +00:00
|
|
|
#include "engine.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "gfx.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
|
|
|
#include "vehicle_gui.h"
|
2005-10-24 19:40:48 +00:00
|
|
|
#include "viewport.h"
|
2005-11-18 23:41:03 +00:00
|
|
|
#include "train.h"
|
2006-04-23 22:33:10 +00:00
|
|
|
#include "newgrf_callbacks.h"
|
2006-02-03 12:55:21 +00:00
|
|
|
#include "newgrf_engine.h"
|
2006-04-23 22:33:10 +00:00
|
|
|
#include "newgrf_text.h"
|
2006-08-14 14:21:15 +00:00
|
|
|
#include "date.h"
|
2006-08-29 17:41:13 +00:00
|
|
|
#include "ship.h"
|
|
|
|
#include "aircraft.h"
|
|
|
|
#include "roadveh.h"
|
|
|
|
#include "depot.h"
|
2007-01-10 18:56:51 +00:00
|
|
|
#include "helpers.hpp"
|
2007-02-20 22:09:21 +00:00
|
|
|
#include "cargotype.h"
|
2007-05-19 09:40:18 +00:00
|
|
|
#include "group.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct Sorting {
|
2006-09-03 23:27:38 +00:00
|
|
|
Listing aircraft;
|
|
|
|
Listing roadveh;
|
|
|
|
Listing ship;
|
|
|
|
Listing train;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-09-03 23:27:38 +00:00
|
|
|
|
|
|
|
static Sorting _sorting;
|
|
|
|
|
2005-07-21 22:15:02 +00:00
|
|
|
static bool _internal_sort_order; // descending/ascending
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
typedef int CDECL VehicleSortListingTypeFunction(const void*, const void*);
|
|
|
|
|
|
|
|
static VehicleSortListingTypeFunction VehicleNumberSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleNameSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleAgeSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleProfitThisYearSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleProfitLastYearSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleCargoSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleReliabilitySorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleMaxSpeedSorter;
|
2006-02-03 18:32:59 +00:00
|
|
|
static VehicleSortListingTypeFunction VehicleModelSorter;
|
|
|
|
static VehicleSortListingTypeFunction VehicleValueSorter;
|
2005-09-26 13:38:12 +00:00
|
|
|
|
|
|
|
static VehicleSortListingTypeFunction* const _vehicle_sorter[] = {
|
2004-11-25 06:05:47 +00:00
|
|
|
&VehicleNumberSorter,
|
|
|
|
&VehicleNameSorter,
|
|
|
|
&VehicleAgeSorter,
|
|
|
|
&VehicleProfitThisYearSorter,
|
|
|
|
&VehicleProfitLastYearSorter,
|
|
|
|
&VehicleCargoSorter,
|
|
|
|
&VehicleReliabilitySorter,
|
2006-02-03 18:32:59 +00:00
|
|
|
&VehicleMaxSpeedSorter,
|
|
|
|
&VehicleModelSorter,
|
|
|
|
&VehicleValueSorter,
|
2004-11-25 06:05:47 +00:00
|
|
|
};
|
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
const StringID _vehicle_sort_listing[] = {
|
2004-11-25 06:05:47 +00:00
|
|
|
STR_SORT_BY_NUMBER,
|
|
|
|
STR_SORT_BY_DROPDOWN_NAME,
|
|
|
|
STR_SORT_BY_AGE,
|
|
|
|
STR_SORT_BY_PROFIT_THIS_YEAR,
|
|
|
|
STR_SORT_BY_PROFIT_LAST_YEAR,
|
|
|
|
STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE,
|
|
|
|
STR_SORT_BY_RELIABILITY,
|
|
|
|
STR_SORT_BY_MAX_SPEED,
|
2006-02-03 18:32:59 +00:00
|
|
|
STR_SORT_BY_MODEL,
|
|
|
|
STR_SORT_BY_VALUE,
|
2004-11-25 06:05:47 +00:00
|
|
|
INVALID_STRING_ID
|
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void RebuildVehicleLists()
|
2004-12-10 18:16:08 +00:00
|
|
|
{
|
2006-11-18 16:47:02 +00:00
|
|
|
Window* const *wz;
|
|
|
|
|
|
|
|
FOR_ALL_WINDOWS(wz) {
|
|
|
|
Window *w = *wz;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
|
|
|
switch (w->window_class) {
|
2006-11-18 16:47:02 +00:00
|
|
|
case WC_TRAINS_LIST:
|
|
|
|
case WC_ROADVEH_LIST:
|
|
|
|
case WC_SHIPS_LIST:
|
|
|
|
case WC_AIRCRAFT_LIST:
|
|
|
|
WP(w, vehiclelist_d).l.flags |= VL_REBUILD;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2007-02-01 15:49:12 +00:00
|
|
|
|
|
|
|
default: break;
|
2004-12-10 18:16:08 +00:00
|
|
|
}
|
2006-11-18 16:47:02 +00:00
|
|
|
}
|
2004-12-10 18:16:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ResortVehicleLists()
|
2004-12-10 18:16:08 +00:00
|
|
|
{
|
2006-11-18 16:47:02 +00:00
|
|
|
Window* const *wz;
|
|
|
|
|
|
|
|
FOR_ALL_WINDOWS(wz) {
|
|
|
|
Window *w = *wz;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
|
|
|
switch (w->window_class) {
|
2006-11-18 16:47:02 +00:00
|
|
|
case WC_TRAINS_LIST:
|
|
|
|
case WC_ROADVEH_LIST:
|
|
|
|
case WC_SHIPS_LIST:
|
|
|
|
case WC_AIRCRAFT_LIST:
|
|
|
|
WP(w, vehiclelist_d).l.flags |= VL_RESORT;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2007-02-01 15:49:12 +00:00
|
|
|
|
|
|
|
default: break;
|
2004-12-10 18:16:08 +00:00
|
|
|
}
|
2006-11-18 16:47:02 +00:00
|
|
|
}
|
2004-12-10 18:16:08 +00:00
|
|
|
}
|
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
void BuildVehicleList(vehiclelist_d *vl, PlayerID owner, uint16 index, uint16 window_type)
|
2004-12-10 18:16:08 +00:00
|
|
|
{
|
2006-09-04 15:13:49 +00:00
|
|
|
if (!(vl->l.flags & VL_REBUILD)) return;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2007-01-21 01:07:15 +00:00
|
|
|
DEBUG(misc, 3, "Building vehicle list for player %d at station %d", owner, index);
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2007-01-21 01:07:15 +00:00
|
|
|
vl->l.list_length = GenerateVehicleSortList(&vl->sort_list, &vl->length_of_sort_list, vl->vehicle_type, owner, index, window_type);
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2006-09-04 15:13:49 +00:00
|
|
|
vl->l.flags &= ~VL_REBUILD;
|
|
|
|
vl->l.flags |= VL_RESORT;
|
2004-12-10 18:16:08 +00:00
|
|
|
}
|
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
void SortVehicleList(vehiclelist_d *vl)
|
2004-12-10 18:16:08 +00:00
|
|
|
{
|
2006-09-04 15:13:49 +00:00
|
|
|
if (!(vl->l.flags & VL_RESORT)) return;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
_internal_sort_order = (vl->l.flags & VL_DESC) != 0;
|
2006-09-04 15:13:49 +00:00
|
|
|
qsort((void*)vl->sort_list, vl->l.list_length, sizeof(vl->sort_list[0]),
|
|
|
|
_vehicle_sorter[vl->l.sort_type]);
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2006-09-04 15:13:49 +00:00
|
|
|
vl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
|
|
|
|
vl->l.flags &= ~VL_RESORT;
|
2004-12-10 18:16:08 +00:00
|
|
|
}
|
|
|
|
|
2006-10-05 13:11:17 +00:00
|
|
|
void DepotSortList(Vehicle **v, uint16 length)
|
|
|
|
{
|
|
|
|
_internal_sort_order = 0;
|
|
|
|
qsort((void*)v, length, sizeof(v[0]), _vehicle_sorter[0]);
|
|
|
|
}
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2007-04-04 04:08:47 +00:00
|
|
|
/** draw the vehicle profit button in the vehicle list window. */
|
2005-09-18 20:56:44 +00:00
|
|
|
void DrawVehicleProfitButton(const Vehicle *v, int x, int y)
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID pal;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2007-04-04 04:08:47 +00:00
|
|
|
/* draw profit-based colored icons */
|
2005-11-14 19:48:04 +00:00
|
|
|
if (v->age <= 365 * 2) {
|
2007-01-14 19:57:49 +00:00
|
|
|
pal = PALETTE_TO_GREY;
|
2005-11-14 19:48:04 +00:00
|
|
|
} else if (v->profit_last_year < 0) {
|
2007-01-14 19:57:49 +00:00
|
|
|
pal = PALETTE_TO_RED;
|
2005-11-14 19:48:04 +00:00
|
|
|
} else if (v->profit_last_year < 10000) {
|
2007-01-14 19:57:49 +00:00
|
|
|
pal = PALETTE_TO_YELLOW;
|
2005-11-14 19:48:04 +00:00
|
|
|
} else {
|
2007-01-14 19:57:49 +00:00
|
|
|
pal = PALETTE_TO_GREEN;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(SPR_BLOT, pal, x, y);
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct RefitOption {
|
2006-10-01 12:00:32 +00:00
|
|
|
CargoID cargo;
|
|
|
|
byte subtype;
|
|
|
|
uint16 value;
|
|
|
|
EngineID engine;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-10-01 12:00:32 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct RefitList {
|
2006-10-01 12:00:32 +00:00
|
|
|
uint num_lines;
|
|
|
|
RefitOption *items;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-10-01 12:00:32 +00:00
|
|
|
|
2006-10-01 12:25:31 +00:00
|
|
|
static RefitList *BuildRefitList(const Vehicle *v)
|
2006-10-01 12:00:32 +00:00
|
|
|
{
|
|
|
|
uint max_lines = 256;
|
2007-01-11 17:29:39 +00:00
|
|
|
RefitOption *refit = CallocT<RefitOption>(max_lines);
|
|
|
|
RefitList *list = CallocT<RefitList>(1);
|
2006-10-01 12:00:32 +00:00
|
|
|
Vehicle *u = (Vehicle*)v;
|
|
|
|
uint num_lines = 0;
|
|
|
|
uint i;
|
|
|
|
|
|
|
|
do {
|
|
|
|
uint32 cmask = EngInfo(u->engine_type)->refit_mask;
|
|
|
|
byte callbackmask = EngInfo(u->engine_type)->callbackmask;
|
|
|
|
|
2006-10-24 07:10:37 +00:00
|
|
|
/* Skip this engine if it has no capacity */
|
|
|
|
if (u->cargo_cap == 0) continue;
|
|
|
|
|
2006-10-01 12:00:32 +00:00
|
|
|
/* Loop through all cargos in the refit mask */
|
2007-03-21 13:19:01 +00:00
|
|
|
for (CargoID cid = 0; cid < NUM_CARGO && num_lines < max_lines; cid++) {
|
2006-10-01 12:00:32 +00:00
|
|
|
/* Skip cargo type if it's not listed */
|
2007-02-24 23:36:40 +00:00
|
|
|
if (!HASBIT(cmask, cid)) continue;
|
2006-10-08 19:28:55 +00:00
|
|
|
|
2006-10-01 12:00:32 +00:00
|
|
|
/* Check the vehicle's callback mask for cargo suffixes */
|
|
|
|
if (HASBIT(callbackmask, CBM_CARGO_SUFFIX)) {
|
|
|
|
/* Make a note of the original cargo type. It has to be
|
|
|
|
* changed to test the cargo & subtype... */
|
|
|
|
CargoID temp_cargo = u->cargo_type;
|
|
|
|
byte temp_subtype = u->cargo_subtype;
|
|
|
|
byte refit_cyc;
|
|
|
|
|
2007-02-22 22:09:51 +00:00
|
|
|
u->cargo_type = cid;
|
2006-10-01 12:00:32 +00:00
|
|
|
|
|
|
|
for (refit_cyc = 0; refit_cyc < 16 && num_lines < max_lines; refit_cyc++) {
|
|
|
|
bool duplicate = false;
|
|
|
|
uint16 callback;
|
|
|
|
|
|
|
|
u->cargo_subtype = refit_cyc;
|
|
|
|
callback = GetVehicleCallback(CBID_VEHICLE_CARGO_SUFFIX, 0, 0, u->engine_type, u);
|
|
|
|
|
|
|
|
if (callback == 0xFF) callback = CALLBACK_FAILED;
|
|
|
|
if (refit_cyc != 0 && callback == CALLBACK_FAILED) break;
|
|
|
|
|
|
|
|
/* Check if this cargo and subtype combination are listed */
|
|
|
|
for (i = 0; i < num_lines && !duplicate; i++) {
|
2007-02-22 22:09:51 +00:00
|
|
|
if (refit[i].cargo == cid && refit[i].value == callback) duplicate = true;
|
2006-10-01 12:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (duplicate) continue;
|
|
|
|
|
2007-02-22 22:09:51 +00:00
|
|
|
refit[num_lines].cargo = cid;
|
2006-10-01 12:00:32 +00:00
|
|
|
refit[num_lines].subtype = refit_cyc;
|
|
|
|
refit[num_lines].value = callback;
|
|
|
|
refit[num_lines].engine = u->engine_type;
|
|
|
|
num_lines++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the vehicle's cargo type */
|
|
|
|
u->cargo_type = temp_cargo;
|
|
|
|
u->cargo_subtype = temp_subtype;
|
|
|
|
} else {
|
|
|
|
/* No cargo suffix callback -- use no subtype */
|
|
|
|
bool duplicate = false;
|
|
|
|
|
|
|
|
for (i = 0; i < num_lines && !duplicate; i++) {
|
2007-02-22 22:09:51 +00:00
|
|
|
if (refit[i].cargo == cid && refit[i].value == CALLBACK_FAILED) duplicate = true;
|
2006-10-01 12:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!duplicate) {
|
2007-02-22 22:09:51 +00:00
|
|
|
refit[num_lines].cargo = cid;
|
2006-10-01 12:00:32 +00:00
|
|
|
refit[num_lines].subtype = 0;
|
|
|
|
refit[num_lines].value = CALLBACK_FAILED;
|
|
|
|
refit[num_lines].engine = INVALID_ENGINE;
|
|
|
|
num_lines++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-30 13:03:56 +00:00
|
|
|
} while (v->type == VEH_TRAIN && (u = u->Next()) != NULL && num_lines < max_lines);
|
2006-10-01 12:00:32 +00:00
|
|
|
|
|
|
|
list->num_lines = num_lines;
|
|
|
|
list->items = refit;
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2005-05-26 16:31:32 +00:00
|
|
|
/** Draw the list of available refit options for a consist.
|
2005-05-14 12:36:16 +00:00
|
|
|
* Draw the list and highlight the selected refit option (if any)
|
2007-04-18 00:41:09 +00:00
|
|
|
* @param *list first vehicle in consist to get the refit-options of
|
2005-05-14 12:36:16 +00:00
|
|
|
* @param sel selected refit cargo-type in the window
|
2007-04-18 00:41:09 +00:00
|
|
|
* @param pos position of the selected item in caller widow
|
|
|
|
* @param rows number of rows(capacity) in caller window
|
|
|
|
* @param delta step height in caller window
|
2006-10-01 12:25:31 +00:00
|
|
|
* @return the refit option that is hightlighted, NULL if none
|
2005-05-14 12:36:16 +00:00
|
|
|
*/
|
2006-10-01 12:25:31 +00:00
|
|
|
static RefitOption *DrawVehicleRefitWindow(const RefitList *list, int sel, uint pos, uint rows, uint delta)
|
2005-05-14 12:36:16 +00:00
|
|
|
{
|
2006-10-01 12:00:32 +00:00
|
|
|
RefitOption *refit = list->items;
|
2006-10-01 12:25:31 +00:00
|
|
|
RefitOption *selected = NULL;
|
2006-10-01 12:00:32 +00:00
|
|
|
uint num_lines = list->num_lines;
|
|
|
|
uint y = 31;
|
|
|
|
uint i;
|
|
|
|
|
|
|
|
/* Draw the list, and find the selected cargo (by its position in list) */
|
2006-10-01 14:55:53 +00:00
|
|
|
for (i = 0; i < num_lines; i++) {
|
2006-10-01 12:00:32 +00:00
|
|
|
byte colour = 16;
|
|
|
|
if (sel == 0) {
|
2006-10-01 12:25:31 +00:00
|
|
|
selected = &refit[i];
|
2006-10-01 12:00:32 +00:00
|
|
|
colour = 12;
|
|
|
|
}
|
2005-05-14 12:36:16 +00:00
|
|
|
|
2006-10-01 14:55:53 +00:00
|
|
|
if (i >= pos && i < pos + rows) {
|
2006-10-01 12:00:32 +00:00
|
|
|
/* Draw the cargo name */
|
2007-02-20 22:09:21 +00:00
|
|
|
int last_x = DrawString(2, y, GetCargo(refit[i].cargo)->name, colour);
|
2006-10-01 12:00:32 +00:00
|
|
|
|
|
|
|
/* If the callback succeeded, draw the cargo suffix */
|
|
|
|
if (refit[i].value != CALLBACK_FAILED) {
|
|
|
|
DrawString(last_x + 1, y, GetGRFStringID(GetEngineGRFID(refit[i].engine), 0xD000 + refit[i].value), colour);
|
|
|
|
}
|
|
|
|
y += delta;
|
2005-05-14 12:36:16 +00:00
|
|
|
}
|
2006-10-01 12:00:32 +00:00
|
|
|
|
|
|
|
sel--;
|
2006-02-14 09:31:05 +00:00
|
|
|
}
|
|
|
|
|
2006-10-01 12:25:31 +00:00
|
|
|
return selected;
|
2005-05-14 12:36:16 +00:00
|
|
|
}
|
|
|
|
|
2006-09-27 07:23:38 +00:00
|
|
|
static void VehicleRefitWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->event) {
|
|
|
|
case WE_PAINT: {
|
2006-10-01 12:00:32 +00:00
|
|
|
Vehicle *v = GetVehicle(w->window_number);
|
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_TRAIN) {
|
2006-10-01 12:00:32 +00:00
|
|
|
uint length = CountVehiclesInChain(v);
|
|
|
|
|
|
|
|
if (length != WP(w, refit_d).length) {
|
|
|
|
/* Consist length has changed, so rebuild the refit list */
|
|
|
|
free(WP(w, refit_d).list->items);
|
|
|
|
free(WP(w, refit_d).list);
|
|
|
|
WP(w, refit_d).list = BuildRefitList(v);
|
|
|
|
WP(w, refit_d).length = length;
|
|
|
|
}
|
|
|
|
}
|
2006-09-27 07:23:38 +00:00
|
|
|
|
2006-10-01 15:03:15 +00:00
|
|
|
SetVScrollCount(w, WP(w, refit_d).list->num_lines);
|
|
|
|
|
2007-06-24 22:42:11 +00:00
|
|
|
SetDParam(0, v->index);
|
2006-09-27 07:23:38 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
2007-04-18 22:10:36 +00:00
|
|
|
WP(w, refit_d).cargo = DrawVehicleRefitWindow(WP(w, refit_d).list, WP(w, refit_d).sel, w->vscroll.pos, w->vscroll.cap, w->resize.step_height);
|
2006-09-27 07:23:38 +00:00
|
|
|
|
2007-04-18 22:10:36 +00:00
|
|
|
if (WP(w, refit_d).cargo != NULL) {
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost cost;
|
2007-02-17 17:12:19 +00:00
|
|
|
|
2007-04-18 22:10:36 +00:00
|
|
|
cost = DoCommand(v->tile, v->index, WP(w, refit_d).cargo->cargo | WP(w, refit_d).cargo->subtype << 8,
|
2007-02-17 17:12:19 +00:00
|
|
|
DC_QUERY_COST, GetCmdRefitVeh(GetVehicle(w->window_number)->type));
|
2006-09-27 07:23:38 +00:00
|
|
|
|
2007-06-18 16:42:40 +00:00
|
|
|
if (CmdSucceeded(cost)) {
|
2007-04-18 22:10:36 +00:00
|
|
|
SetDParam(0, WP(w, refit_d).cargo->cargo);
|
2006-09-27 07:23:38 +00:00
|
|
|
SetDParam(1, _returned_refit_capacity);
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(2, cost.GetCost());
|
2006-10-01 12:00:32 +00:00
|
|
|
DrawString(2, w->widget[5].top + 1, STR_9840_NEW_CAPACITY_COST_OF_REFIT, 0);
|
2006-09-27 07:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-18 22:41:53 +00:00
|
|
|
} break;
|
2006-09-27 07:23:38 +00:00
|
|
|
|
|
|
|
case WE_CLICK:
|
|
|
|
switch (e->we.click.widget) {
|
2006-10-01 12:00:32 +00:00
|
|
|
case 3: { // listbox
|
|
|
|
int y = e->we.click.pt.y - w->widget[3].top;
|
2006-09-27 07:23:38 +00:00
|
|
|
if (y >= 0) {
|
2007-04-18 22:10:36 +00:00
|
|
|
WP(w, refit_d).sel = (y / (int)w->resize.step_height) + w->vscroll.pos;
|
2006-09-27 07:23:38 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
} break;
|
2006-10-01 12:00:32 +00:00
|
|
|
case 6: // refit button
|
2007-04-18 22:10:36 +00:00
|
|
|
if (WP(w, refit_d).cargo != NULL) {
|
2006-09-27 07:23:38 +00:00
|
|
|
const Vehicle *v = GetVehicle(w->window_number);
|
|
|
|
|
2006-10-03 14:52:39 +00:00
|
|
|
if (WP(w, refit_d).order == INVALID_VEH_ORDER_ID) {
|
|
|
|
int command = 0;
|
|
|
|
|
|
|
|
switch (v->type) {
|
2007-05-15 11:28:22 +00:00
|
|
|
default: NOT_REACHED();
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: command = CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE); break;
|
|
|
|
case VEH_ROAD: command = CMD_REFIT_ROAD_VEH | CMD_MSG(STR_REFIT_ROAD_VEHICLE_CAN_T); break;
|
|
|
|
case VEH_SHIP: command = CMD_REFIT_SHIP | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP); break;
|
|
|
|
case VEH_AIRCRAFT: command = CMD_REFIT_AIRCRAFT | CMD_MSG(STR_A042_CAN_T_REFIT_AIRCRAFT); break;
|
2006-10-03 14:52:39 +00:00
|
|
|
}
|
2007-04-18 22:10:36 +00:00
|
|
|
if (DoCommandP(v->tile, v->index, WP(w, refit_d).cargo->cargo | WP(w, refit_d).cargo->subtype << 8, NULL, command)) DeleteWindow(w);
|
2006-10-03 14:52:39 +00:00
|
|
|
} else {
|
2007-04-18 22:10:36 +00:00
|
|
|
if (DoCommandP(v->tile, v->index, WP(w, refit_d).cargo->cargo | WP(w, refit_d).cargo->subtype << 8 | WP(w, refit_d).order << 16, NULL, CMD_ORDER_REFIT)) DeleteWindow(w);
|
2006-09-27 07:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2006-10-01 12:00:32 +00:00
|
|
|
|
|
|
|
case WE_RESIZE:
|
|
|
|
w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
|
|
|
|
w->widget[3].data = (w->vscroll.cap << 8) + 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_DESTROY:
|
|
|
|
free(WP(w, refit_d).list->items);
|
|
|
|
free(WP(w, refit_d).list);
|
|
|
|
break;
|
2006-09-27 07:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const Widget _vehicle_refit_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 239, 0, 13, STR_983B_REFIT, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
2006-10-01 12:00:32 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 239, 14, 27, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, STR_983D_SELECT_TYPE_OF_CARGO_FOR},
|
2006-10-08 17:56:08 +00:00
|
|
|
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 227, 28, 139, 0x801, STR_EMPTY},
|
2006-10-01 12:00:32 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 228, 239, 28, 139, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 0, 239, 140, 161, 0x0, STR_NULL},
|
2006-10-01 12:00:32 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 227, 162, 173, 0x0, STR_NULL},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_TB, 14, 228, 239, 162, 173, 0x0, STR_RESIZE_BUTTON},
|
2006-09-27 07:23:38 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _vehicle_refit_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 240, 174, 240, 174,
|
2007-04-18 22:10:36 +00:00
|
|
|
WC_VEHICLE_REFIT, WC_VEHICLE_VIEW,
|
2006-10-01 12:00:32 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
2006-09-27 07:23:38 +00:00
|
|
|
_vehicle_refit_widgets,
|
|
|
|
VehicleRefitWndProc,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Show the refit window for a vehicle
|
|
|
|
* @param *v The vehicle to show the refit window for
|
2007-04-18 22:10:36 +00:00
|
|
|
* @param order of the vehicle ( ? )
|
2006-09-27 07:23:38 +00:00
|
|
|
*/
|
2006-10-03 14:52:39 +00:00
|
|
|
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order)
|
2006-09-27 07:23:38 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
DeleteWindowById(WC_VEHICLE_REFIT, v->index);
|
|
|
|
|
2006-11-11 09:47:44 +00:00
|
|
|
w = AllocateWindowDescFront(&_vehicle_refit_desc, v->index);
|
2006-10-03 14:52:39 +00:00
|
|
|
WP(w, refit_d).order = order;
|
2006-10-02 08:41:20 +00:00
|
|
|
|
|
|
|
if (w != NULL) {
|
|
|
|
w->caption_color = v->owner;
|
|
|
|
w->vscroll.cap = 8;
|
|
|
|
w->resize.step_height = 14;
|
|
|
|
WP(w, refit_d).sel = -1;
|
|
|
|
WP(w, refit_d).list = BuildRefitList(v);
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_TRAIN) WP(w, refit_d).length = CountVehiclesInChain(v);
|
2006-10-02 08:41:20 +00:00
|
|
|
SetVScrollCount(w, WP(w, refit_d).list->num_lines);
|
|
|
|
|
|
|
|
switch (v->type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN:
|
2006-10-08 17:56:08 +00:00
|
|
|
w->widget[3].tooltips = STR_RAIL_SELECT_TYPE_OF_CARGO_FOR;
|
2006-10-02 08:41:20 +00:00
|
|
|
w->widget[6].data = STR_RAIL_REFIT_VEHICLE;
|
|
|
|
w->widget[6].tooltips = STR_RAIL_REFIT_TO_CARRY_HIGHLIGHTED;
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_ROAD:
|
2006-10-08 17:56:08 +00:00
|
|
|
w->widget[3].tooltips = STR_ROAD_SELECT_TYPE_OF_CARGO_FOR;
|
2006-10-02 08:41:20 +00:00
|
|
|
w->widget[6].data = STR_REFIT_ROAD_VEHICLE;
|
|
|
|
w->widget[6].tooltips = STR_REFIT_ROAD_VEHICLE_TO_CARRY_HIGHLIGHTED;
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_SHIP:
|
2006-10-08 17:56:08 +00:00
|
|
|
w->widget[3].tooltips = STR_983D_SELECT_TYPE_OF_CARGO_FOR;
|
2006-10-02 08:41:20 +00:00
|
|
|
w->widget[6].data = STR_983C_REFIT_SHIP;
|
|
|
|
w->widget[6].tooltips = STR_983E_REFIT_SHIP_TO_CARRY_HIGHLIGHTED;
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_AIRCRAFT:
|
2006-10-08 17:56:08 +00:00
|
|
|
w->widget[3].tooltips = STR_A03E_SELECT_TYPE_OF_CARGO_FOR;
|
2006-10-02 08:41:20 +00:00
|
|
|
w->widget[6].data = STR_A03D_REFIT_AIRCRAFT;
|
|
|
|
w->widget[6].tooltips = STR_A03F_REFIT_AIRCRAFT_TO_CARRY;
|
|
|
|
break;
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
2006-09-27 07:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-04 04:08:47 +00:00
|
|
|
/** Display additional text from NewGRF in the purchase information window */
|
2006-10-23 21:39:15 +00:00
|
|
|
uint ShowAdditionalText(int x, int y, uint w, EngineID engine)
|
2006-04-23 22:33:10 +00:00
|
|
|
{
|
|
|
|
uint16 callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, NULL);
|
|
|
|
if (callback == CALLBACK_FAILED) return 0;
|
|
|
|
|
2007-04-04 04:08:47 +00:00
|
|
|
/* STR_02BD is used to start the string with {BLACK} */
|
2006-10-23 18:13:24 +00:00
|
|
|
SetDParam(0, GetGRFStringID(GetEngineGRFID(engine), 0xD000 + callback));
|
|
|
|
return DrawStringMultiLine(x, y, STR_02BD, w);
|
2006-04-23 22:33:10 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 04:08:47 +00:00
|
|
|
/** Count the number of bits that are set in a mask */
|
2006-10-23 21:39:15 +00:00
|
|
|
static uint CountBits(uint32 mask)
|
|
|
|
{
|
|
|
|
uint c = 0;
|
|
|
|
for (; mask != 0; mask >>= 1) if (HASBIT(mask, 0)) c++;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2007-04-04 04:08:47 +00:00
|
|
|
/** Display list of cargo types of the engine, for the purchase information window */
|
2006-10-23 21:39:15 +00:00
|
|
|
uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine)
|
|
|
|
{
|
|
|
|
/* List of cargo types of this engine */
|
|
|
|
uint32 cmask = EngInfo(engine)->refit_mask;
|
|
|
|
/* List of cargo types available in this climate */
|
2007-02-22 22:09:51 +00:00
|
|
|
uint32 lmask = _cargo_mask;
|
2006-10-23 21:39:15 +00:00
|
|
|
char *b = _userstring;
|
|
|
|
|
|
|
|
/* Draw nothing if the engine is not refittable */
|
|
|
|
if (CountBits(cmask) <= 1) return 0;
|
|
|
|
|
|
|
|
b = InlineString(b, STR_PURCHASE_INFO_REFITTABLE_TO);
|
|
|
|
|
|
|
|
if (cmask == lmask) {
|
|
|
|
/* Engine can be refitted to all types in this climate */
|
|
|
|
b = InlineString(b, STR_PURCHASE_INFO_ALL_TYPES);
|
|
|
|
} else {
|
|
|
|
/* Check if we are able to refit to more cargo types and unable to. If
|
|
|
|
* so, invert the cargo types to list those that we can't refit to. */
|
|
|
|
if (CountBits(cmask ^ lmask) < CountBits(cmask)) {
|
|
|
|
cmask ^= lmask;
|
|
|
|
b = InlineString(b, STR_PURCHASE_INFO_ALL_BUT);
|
|
|
|
}
|
|
|
|
|
2007-02-22 22:09:51 +00:00
|
|
|
bool first = true;
|
|
|
|
|
2006-10-23 21:39:15 +00:00
|
|
|
/* Add each cargo type to the list */
|
2007-02-22 22:09:51 +00:00
|
|
|
for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
|
2007-02-24 23:36:40 +00:00
|
|
|
if (!HASBIT(cmask, cid)) continue;
|
2007-02-22 22:09:51 +00:00
|
|
|
|
|
|
|
if (!first) b = strecpy(b, ", ", lastof(_userstring));
|
|
|
|
first = false;
|
2006-10-23 21:39:15 +00:00
|
|
|
|
2007-02-22 22:09:51 +00:00
|
|
|
b = InlineString(b, GetCargo(cid)->name);
|
2006-10-23 21:39:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Terminate and display the completed string */
|
|
|
|
*b = '\0';
|
|
|
|
return DrawStringMultiLine(x, y, STR_SPEC_USERSTRING, w);
|
|
|
|
}
|
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2007-04-04 04:08:47 +00:00
|
|
|
/* if the sorting criteria had the same value, sort vehicle by unitnumber */
|
2004-09-14 14:19:53 +00:00
|
|
|
#define VEHICLEUNITNUMBERSORTER(r, a, b) {if (r == 0) {r = a->unitnumber - b->unitnumber;}}
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleNumberSorter(const void *a, const void *b)
|
2004-09-06 21:20:01 +00:00
|
|
|
{
|
2006-08-14 20:25:29 +00:00
|
|
|
const Vehicle* va = *(const Vehicle**)a;
|
|
|
|
const Vehicle* vb = *(const Vehicle**)b;
|
2004-09-06 21:20:01 +00:00
|
|
|
int r = va->unitnumber - vb->unitnumber;
|
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
|
}
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleNameSorter(const void *a, const void *b)
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
2006-10-16 10:29:29 +00:00
|
|
|
static const Vehicle *last_vehicle[2] = { NULL, NULL };
|
|
|
|
static char last_name[2][64] = { "", "" };
|
|
|
|
|
2006-08-14 20:25:29 +00:00
|
|
|
const Vehicle* va = *(const Vehicle**)a;
|
|
|
|
const Vehicle* vb = *(const Vehicle**)b;
|
2004-09-06 18:15:13 +00:00
|
|
|
int r;
|
|
|
|
|
2006-10-16 10:29:29 +00:00
|
|
|
if (va != last_vehicle[0]) {
|
|
|
|
last_vehicle[0] = va;
|
|
|
|
if (IsCustomName(va->string_id)) {
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(last_name[0], va->string_id, lastof(last_name[0]));
|
2006-10-16 10:29:29 +00:00
|
|
|
} else {
|
|
|
|
last_name[0][0] = '\0';
|
|
|
|
}
|
|
|
|
}
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2006-10-16 10:29:29 +00:00
|
|
|
if (vb != last_vehicle[1]) {
|
|
|
|
last_vehicle[1] = vb;
|
|
|
|
if (IsCustomName(vb->string_id)) {
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(last_name[1], vb->string_id, lastof(last_name[1]));
|
2006-10-16 10:29:29 +00:00
|
|
|
} else {
|
|
|
|
last_name[1][0] = '\0';
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-16 10:29:29 +00:00
|
|
|
r = strcmp(last_name[0], last_name[1]); // sort by name
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-09-14 14:19:53 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
2004-09-06 21:20:01 +00:00
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleAgeSorter(const void *a, const void *b)
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
2006-08-14 20:25:29 +00:00
|
|
|
const Vehicle* va = *(const Vehicle**)a;
|
|
|
|
const Vehicle* vb = *(const Vehicle**)b;
|
2004-09-06 21:20:01 +00:00
|
|
|
int r = va->age - vb->age;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2004-09-14 14:19:53 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
2004-09-06 21:20:01 +00:00
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
|
}
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleProfitThisYearSorter(const void *a, const void *b)
|
2004-09-06 21:20:01 +00:00
|
|
|
{
|
2006-08-14 20:25:29 +00:00
|
|
|
const Vehicle* va = *(const Vehicle**)a;
|
|
|
|
const Vehicle* vb = *(const Vehicle**)b;
|
2007-06-21 14:32:27 +00:00
|
|
|
int r = ClampToI32(va->profit_this_year - vb->profit_this_year);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-09-14 14:19:53 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
2004-09-06 21:20:01 +00:00
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
|
}
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleProfitLastYearSorter(const void *a, const void *b)
|
2004-09-06 21:20:01 +00:00
|
|
|
{
|
2006-08-14 20:25:29 +00:00
|
|
|
const Vehicle* va = *(const Vehicle**)a;
|
|
|
|
const Vehicle* vb = *(const Vehicle**)b;
|
2007-06-21 14:32:27 +00:00
|
|
|
int r = ClampToI32(va->profit_last_year - vb->profit_last_year);
|
2004-09-06 21:20:01 +00:00
|
|
|
|
2004-09-14 14:19:53 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
2004-09-06 21:20:01 +00:00
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
|
}
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleCargoSorter(const void *a, const void *b)
|
2004-09-06 21:20:01 +00:00
|
|
|
{
|
2006-08-14 20:25:29 +00:00
|
|
|
const Vehicle* va = *(const Vehicle**)a;
|
|
|
|
const Vehicle* vb = *(const Vehicle**)b;
|
2005-10-23 13:04:44 +00:00
|
|
|
const Vehicle* v;
|
|
|
|
AcceptedCargo cargoa;
|
|
|
|
AcceptedCargo cargob;
|
2004-09-06 21:20:01 +00:00
|
|
|
int r = 0;
|
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
memset(cargoa, 0, sizeof(cargoa));
|
|
|
|
memset(cargob, 0, sizeof(cargob));
|
2007-08-30 13:03:56 +00:00
|
|
|
for (v = va; v != NULL; v = v->Next()) cargoa[v->cargo_type] += v->cargo_cap;
|
|
|
|
for (v = vb; v != NULL; v = v->Next()) cargob[v->cargo_type] += v->cargo_cap;
|
2004-09-06 21:20:01 +00:00
|
|
|
|
2007-03-21 13:19:01 +00:00
|
|
|
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
2005-10-23 13:04:44 +00:00
|
|
|
r = cargoa[i] - cargob[i];
|
|
|
|
if (r != 0) break;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
2004-09-06 21:20:01 +00:00
|
|
|
|
2004-12-11 11:00:54 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
|
|
|
|
2004-09-06 21:20:01 +00:00
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
|
}
|
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleReliabilitySorter(const void *a, const void *b)
|
2004-09-06 21:20:01 +00:00
|
|
|
{
|
2006-08-14 20:25:29 +00:00
|
|
|
const Vehicle* va = *(const Vehicle**)a;
|
|
|
|
const Vehicle* vb = *(const Vehicle**)b;
|
2004-09-06 21:20:01 +00:00
|
|
|
int r = va->reliability - vb->reliability;
|
|
|
|
|
2004-09-14 14:19:53 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
2004-09-06 21:20:01 +00:00
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
2004-09-06 21:20:01 +00:00
|
|
|
|
2005-09-26 13:38:12 +00:00
|
|
|
static int CDECL VehicleMaxSpeedSorter(const void *a, const void *b)
|
2004-09-06 21:20:01 +00:00
|
|
|
{
|
2006-08-14 20:25:29 +00:00
|
|
|
const Vehicle* va = *(const Vehicle**)a;
|
|
|
|
const Vehicle* vb = *(const Vehicle**)b;
|
2005-01-26 12:51:04 +00:00
|
|
|
int max_speed_a = 0xFFFF, max_speed_b = 0xFFFF;
|
|
|
|
int r;
|
|
|
|
const Vehicle *ua = va, *ub = vb;
|
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
if (va->type == VEH_TRAIN && vb->type == VEH_TRAIN) {
|
2005-01-27 11:33:14 +00:00
|
|
|
do {
|
|
|
|
if (RailVehInfo(ua->engine_type)->max_speed != 0)
|
|
|
|
max_speed_a = min(max_speed_a, RailVehInfo(ua->engine_type)->max_speed);
|
2007-08-30 13:03:56 +00:00
|
|
|
} while ((ua = ua->Next()) != NULL);
|
2005-01-26 12:51:04 +00:00
|
|
|
|
2005-01-27 11:33:14 +00:00
|
|
|
do {
|
|
|
|
if (RailVehInfo(ub->engine_type)->max_speed != 0)
|
|
|
|
max_speed_b = min(max_speed_b, RailVehInfo(ub->engine_type)->max_speed);
|
2007-08-30 13:03:56 +00:00
|
|
|
} while ((ub = ub->Next()) != NULL);
|
2005-01-27 11:33:14 +00:00
|
|
|
|
|
|
|
r = max_speed_a - max_speed_b;
|
|
|
|
} else {
|
|
|
|
r = va->max_speed - vb->max_speed;
|
|
|
|
}
|
2004-09-06 21:20:01 +00:00
|
|
|
|
2004-09-14 14:19:53 +00:00
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
2004-09-06 21:20:01 +00:00
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2005-01-02 17:23:04 +00:00
|
|
|
|
2006-02-03 18:32:59 +00:00
|
|
|
static int CDECL VehicleModelSorter(const void *a, const void *b)
|
|
|
|
{
|
2006-08-14 20:25:29 +00:00
|
|
|
const Vehicle* va = *(const Vehicle**)a;
|
|
|
|
const Vehicle* vb = *(const Vehicle**)b;
|
2006-02-03 18:32:59 +00:00
|
|
|
int r = va->engine_type - vb->engine_type;
|
|
|
|
|
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL VehicleValueSorter(const void *a, const void *b)
|
|
|
|
{
|
2006-08-14 20:25:29 +00:00
|
|
|
const Vehicle* va = *(const Vehicle**)a;
|
|
|
|
const Vehicle* vb = *(const Vehicle**)b;
|
2006-02-03 18:32:59 +00:00
|
|
|
const Vehicle *u;
|
2007-06-21 14:32:27 +00:00
|
|
|
Money valuea = 0, valueb = 0;
|
2006-02-03 18:32:59 +00:00
|
|
|
|
2007-08-30 13:03:56 +00:00
|
|
|
for (u = va; u != NULL; u = u->Next()) valuea += u->value;
|
|
|
|
for (u = vb; u != NULL; u = u->Next()) valueb += u->value;
|
2006-02-03 18:32:59 +00:00
|
|
|
|
2007-06-21 14:32:27 +00:00
|
|
|
int r = ClampToI32(valuea - valueb);
|
2006-02-03 18:32:59 +00:00
|
|
|
|
|
|
|
VEHICLEUNITNUMBERSORTER(r, va, vb);
|
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeGUI()
|
2005-01-31 11:03:23 +00:00
|
|
|
{
|
|
|
|
memset(&_sorting, 0, sizeof(_sorting));
|
|
|
|
}
|
2005-10-24 19:40:48 +00:00
|
|
|
|
|
|
|
/** Assigns an already open vehicle window to a new vehicle.
|
2005-11-14 19:48:04 +00:00
|
|
|
* Assigns an already open vehicle window to a new vehicle. If the vehicle got
|
|
|
|
* any sub window open (orders and so on) it will change owner too.
|
|
|
|
* @param *from_v the current owner of the window
|
|
|
|
* @param *to_v the new owner of the window
|
|
|
|
*/
|
2005-10-24 19:40:48 +00:00
|
|
|
void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
w = FindWindowById(WC_VEHICLE_VIEW, from_v->index);
|
|
|
|
if (w != NULL) {
|
|
|
|
w->window_number = to_v->index;
|
2005-11-14 19:48:04 +00:00
|
|
|
WP(w, vp_d).follow_vehicle = to_v->index;
|
2005-10-24 19:40:48 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
|
|
|
|
w = FindWindowById(WC_VEHICLE_ORDERS, from_v->index);
|
|
|
|
if (w != NULL) {
|
|
|
|
w->window_number = to_v->index;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
w = FindWindowById(WC_VEHICLE_REFIT, from_v->index);
|
|
|
|
if (w != NULL) {
|
|
|
|
w->window_number = to_v->index;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
w = FindWindowById(WC_VEHICLE_DETAILS, from_v->index);
|
|
|
|
if (w != NULL) {
|
|
|
|
w->window_number = to_v->index;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-08-29 17:41:13 +00:00
|
|
|
|
2006-12-07 00:51:20 +00:00
|
|
|
enum VehicleListWindowWidgets {
|
2006-09-28 23:05:03 +00:00
|
|
|
VLW_WIDGET_CLOSEBOX = 0,
|
|
|
|
VLW_WIDGET_CAPTION,
|
|
|
|
VLW_WIDGET_STICKY,
|
|
|
|
VLW_WIDGET_SORT_ORDER,
|
|
|
|
VLW_WIDGET_SORT_BY_TEXT,
|
|
|
|
VLW_WIDGET_SORT_BY_PULLDOWN,
|
2006-12-07 14:03:55 +00:00
|
|
|
VLW_WIDGET_EMPTY_TOP_RIGHT,
|
2006-09-28 23:05:03 +00:00
|
|
|
VLW_WIDGET_LIST,
|
|
|
|
VLW_WIDGET_SCROLLBAR,
|
|
|
|
VLW_WIDGET_OTHER_PLAYER_FILLER,
|
2007-01-26 19:24:02 +00:00
|
|
|
VLW_WIDGET_AVAILABLE_VEHICLES,
|
2006-12-07 14:03:55 +00:00
|
|
|
VLW_WIDGET_MANAGE_VEHICLES,
|
|
|
|
VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN,
|
2006-09-29 11:30:48 +00:00
|
|
|
VLW_WIDGET_STOP_ALL,
|
|
|
|
VLW_WIDGET_START_ALL,
|
2006-12-07 14:03:55 +00:00
|
|
|
VLW_WIDGET_EMPTY_BOTTOM_RIGHT,
|
2006-09-28 23:05:03 +00:00
|
|
|
VLW_WIDGET_RESIZE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _vehicle_list_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 247, 0, 13, 0x0, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, 14, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, 14, 248, 259, 14, 25, 0x0, STR_NULL},
|
|
|
|
{ WWT_MATRIX, RESIZE_RB, 14, 0, 247, 26, 169, 0x0, STR_NULL},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 248, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2006-12-07 14:03:55 +00:00
|
|
|
/* Widget to be shown for other players hiding the following 6 widgets */
|
2006-12-07 22:31:20 +00:00
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 0, 247, 170, 181, 0x0, STR_NULL},
|
2006-12-07 14:03:55 +00:00
|
|
|
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 105, 170, 181, 0x0, STR_AVAILABLE_ENGINES_TIP},
|
2006-12-08 18:56:39 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_TB, 14, 106, 211, 170, 181, STR_MANAGE_LIST, STR_MANAGE_LIST_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_TB, 14, 212, 223, 170, 181, STR_0225, STR_MANAGE_LIST_TIP},
|
2006-12-07 14:03:55 +00:00
|
|
|
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_TB, 14, 224, 235, 170, 181, SPR_FLAG_VEH_STOPPED, STR_MASS_STOP_LIST_TIP},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_TB, 14, 236, 247, 170, 181, SPR_FLAG_VEH_RUNNING, STR_MASS_START_LIST_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 248, 247, 170, 181, 0x0, STR_NULL},
|
2006-09-28 23:05:03 +00:00
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 248, 259, 170, 181, 0x0, STR_RESIZE_BUTTON},
|
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
2006-09-28 18:13:31 +00:00
|
|
|
static void CreateVehicleListWindow(Window *w)
|
2006-08-29 17:41:13 +00:00
|
|
|
{
|
|
|
|
vehiclelist_d *vl = &WP(w, vehiclelist_d);
|
2006-09-28 18:13:31 +00:00
|
|
|
uint16 window_type = w->window_number & VLW_MASK;
|
2007-01-10 18:56:51 +00:00
|
|
|
PlayerID player = (PlayerID)GB(w->window_number, 0, 8);
|
2006-09-28 23:05:03 +00:00
|
|
|
|
2007-05-18 17:31:41 +00:00
|
|
|
vl->vehicle_type = (VehicleType)GB(w->window_number, 11, 5);
|
2006-09-29 20:41:28 +00:00
|
|
|
vl->length_of_sort_list = 0;
|
|
|
|
vl->sort_list = NULL;
|
2006-09-28 23:05:03 +00:00
|
|
|
w->caption_color = player;
|
|
|
|
|
|
|
|
/* Hide the widgets that we will not use in this window
|
|
|
|
* Some windows contains actions only fit for the owner */
|
|
|
|
if (player == _local_player) {
|
2006-10-02 00:28:31 +00:00
|
|
|
HideWindowWidget(w, VLW_WIDGET_OTHER_PLAYER_FILLER);
|
2007-01-26 19:24:02 +00:00
|
|
|
SetWindowWidgetDisabledState(w, VLW_WIDGET_AVAILABLE_VEHICLES, window_type != VLW_STANDARD);
|
2006-09-28 23:05:03 +00:00
|
|
|
} else {
|
2006-10-06 21:44:18 +00:00
|
|
|
SetWindowWidgetsHiddenState(w, true,
|
2007-01-26 19:24:02 +00:00
|
|
|
VLW_WIDGET_AVAILABLE_VEHICLES,
|
2006-12-07 14:03:55 +00:00
|
|
|
VLW_WIDGET_MANAGE_VEHICLES,
|
|
|
|
VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN,
|
2006-10-06 21:44:18 +00:00
|
|
|
VLW_WIDGET_STOP_ALL,
|
|
|
|
VLW_WIDGET_START_ALL,
|
2006-12-07 14:03:55 +00:00
|
|
|
VLW_WIDGET_EMPTY_BOTTOM_RIGHT,
|
2006-10-06 21:44:18 +00:00
|
|
|
WIDGET_LIST_END);
|
2006-09-28 23:05:03 +00:00
|
|
|
}
|
2006-09-28 18:13:31 +00:00
|
|
|
|
|
|
|
/* Set up the window widgets */
|
2006-09-28 23:05:03 +00:00
|
|
|
switch (vl->vehicle_type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN:
|
2006-09-30 20:59:23 +00:00
|
|
|
w->widget[VLW_WIDGET_LIST].tooltips = STR_883D_TRAINS_CLICK_ON_TRAIN_FOR;
|
2007-01-26 19:24:02 +00:00
|
|
|
w->widget[VLW_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_TRAINS;
|
2006-09-28 23:05:03 +00:00
|
|
|
break;
|
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_ROAD:
|
2006-09-30 20:59:23 +00:00
|
|
|
w->widget[VLW_WIDGET_LIST].tooltips = STR_901A_ROAD_VEHICLES_CLICK_ON;
|
2007-01-26 19:30:11 +00:00
|
|
|
w->widget[VLW_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_ROAD_VEHICLES;
|
2006-09-28 23:05:03 +00:00
|
|
|
break;
|
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_SHIP:
|
2006-09-30 20:59:23 +00:00
|
|
|
w->widget[VLW_WIDGET_LIST].tooltips = STR_9823_SHIPS_CLICK_ON_SHIP_FOR;
|
2007-01-26 19:24:02 +00:00
|
|
|
w->widget[VLW_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_SHIPS;
|
2006-09-28 23:05:03 +00:00
|
|
|
break;
|
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_AIRCRAFT:
|
2006-09-30 20:59:23 +00:00
|
|
|
w->widget[VLW_WIDGET_LIST].tooltips = STR_A01F_AIRCRAFT_CLICK_ON_AIRCRAFT;
|
2007-01-26 19:24:02 +00:00
|
|
|
w->widget[VLW_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_AIRCRAFT;
|
2006-09-28 23:05:03 +00:00
|
|
|
break;
|
|
|
|
|
2006-12-07 14:03:55 +00:00
|
|
|
default: NOT_REACHED();
|
2006-09-28 23:05:03 +00:00
|
|
|
}
|
|
|
|
|
2006-09-28 18:13:31 +00:00
|
|
|
switch (window_type) {
|
|
|
|
case VLW_SHARED_ORDERS:
|
2006-09-28 23:05:03 +00:00
|
|
|
w->widget[VLW_WIDGET_CAPTION].data = STR_VEH_WITH_SHARED_ORDERS_LIST;
|
2006-09-28 18:13:31 +00:00
|
|
|
break;
|
|
|
|
case VLW_STANDARD: /* Company Name - standard widget setup */
|
2006-09-28 23:05:03 +00:00
|
|
|
switch (vl->vehicle_type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: w->widget[VLW_WIDGET_CAPTION].data = STR_881B_TRAINS; break;
|
|
|
|
case VEH_ROAD: w->widget[VLW_WIDGET_CAPTION].data = STR_9001_ROAD_VEHICLES; break;
|
|
|
|
case VEH_SHIP: w->widget[VLW_WIDGET_CAPTION].data = STR_9805_SHIPS; break;
|
|
|
|
case VEH_AIRCRAFT: w->widget[VLW_WIDGET_CAPTION].data = STR_A009_AIRCRAFT; break;
|
2006-09-28 23:05:03 +00:00
|
|
|
default: NOT_REACHED(); break;
|
|
|
|
}
|
2006-09-28 18:13:31 +00:00
|
|
|
break;
|
|
|
|
case VLW_STATION_LIST: /* Station Name */
|
|
|
|
switch (vl->vehicle_type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: w->widget[VLW_WIDGET_CAPTION].data = STR_SCHEDULED_TRAINS; break;
|
|
|
|
case VEH_ROAD: w->widget[VLW_WIDGET_CAPTION].data = STR_SCHEDULED_ROAD_VEHICLES; break;
|
|
|
|
case VEH_SHIP: w->widget[VLW_WIDGET_CAPTION].data = STR_SCHEDULED_SHIPS; break;
|
|
|
|
case VEH_AIRCRAFT: w->widget[VLW_WIDGET_CAPTION].data = STR_SCHEDULED_AIRCRAFT; break;
|
2006-09-04 15:13:49 +00:00
|
|
|
default: NOT_REACHED(); break;
|
|
|
|
}
|
2006-09-28 18:13:31 +00:00
|
|
|
break;
|
2006-09-30 13:39:34 +00:00
|
|
|
|
|
|
|
case VLW_DEPOT_LIST:
|
|
|
|
switch (vl->vehicle_type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: w->widget[VLW_WIDGET_CAPTION].data = STR_VEHICLE_LIST_TRAIN_DEPOT; break;
|
|
|
|
case VEH_ROAD: w->widget[VLW_WIDGET_CAPTION].data = STR_VEHICLE_LIST_ROADVEH_DEPOT; break;
|
|
|
|
case VEH_SHIP: w->widget[VLW_WIDGET_CAPTION].data = STR_VEHICLE_LIST_SHIP_DEPOT; break;
|
|
|
|
case VEH_AIRCRAFT: w->widget[VLW_WIDGET_CAPTION].data = STR_VEHICLE_LIST_AIRCRAFT_DEPOT; break;
|
2006-09-30 13:39:34 +00:00
|
|
|
default: NOT_REACHED(); break;
|
|
|
|
}
|
|
|
|
break;
|
2006-09-28 18:13:31 +00:00
|
|
|
default: NOT_REACHED(); break;
|
|
|
|
}
|
2006-09-04 15:13:49 +00:00
|
|
|
|
2006-09-28 18:13:31 +00:00
|
|
|
switch (vl->vehicle_type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN:
|
2006-09-28 18:13:31 +00:00
|
|
|
w->resize.step_width = 1;
|
|
|
|
/* Fallthrough */
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_ROAD:
|
2006-09-28 18:13:31 +00:00
|
|
|
w->vscroll.cap = 7;
|
|
|
|
w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL;
|
|
|
|
w->resize.height = 220 - (PLY_WND_PRC__SIZE_OF_ROW_SMALL * 3); // Minimum of 4 vehicles
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_SHIP:
|
|
|
|
case VEH_AIRCRAFT:
|
2006-09-28 18:13:31 +00:00
|
|
|
w->vscroll.cap = 4;
|
|
|
|
w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_BIG;
|
|
|
|
break;
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
2006-09-04 15:13:49 +00:00
|
|
|
|
2006-09-28 23:05:03 +00:00
|
|
|
w->widget[VLW_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
|
2006-09-28 18:13:31 +00:00
|
|
|
|
|
|
|
/* Set up sorting. Make the window-specific _sorting variable
|
|
|
|
* point to the correct global _sorting struct so we are freed
|
|
|
|
* from having conditionals during window operation */
|
|
|
|
switch (vl->vehicle_type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: vl->_sorting = &_sorting.train; break;
|
|
|
|
case VEH_ROAD: vl->_sorting = &_sorting.roadveh; break;
|
|
|
|
case VEH_SHIP: vl->_sorting = &_sorting.ship; break;
|
|
|
|
case VEH_AIRCRAFT: vl->_sorting = &_sorting.aircraft; break;
|
2006-09-28 18:13:31 +00:00
|
|
|
default: NOT_REACHED(); break;
|
|
|
|
}
|
2006-09-04 15:13:49 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
vl->l.flags = VL_REBUILD | (vl->_sorting->order ? VL_DESC : VL_NONE);
|
2006-09-28 18:13:31 +00:00
|
|
|
vl->l.sort_type = vl->_sorting->criteria;
|
|
|
|
vl->sort_list = NULL;
|
2007-04-18 22:41:53 +00:00
|
|
|
vl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
|
2006-09-28 18:13:31 +00:00
|
|
|
}
|
2006-09-04 15:13:49 +00:00
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
void DrawSmallOrderList(const Vehicle *v, int x, int y)
|
2006-10-05 08:15:51 +00:00
|
|
|
{
|
|
|
|
const Order *order;
|
|
|
|
int sel, i = 0;
|
|
|
|
|
|
|
|
sel = v->cur_order_index;
|
|
|
|
|
|
|
|
FOR_VEHICLE_ORDERS(v, order) {
|
|
|
|
if (sel == 0) DrawString(x - 6, y, STR_SMALL_RIGHT_ARROW, 16);
|
|
|
|
sel--;
|
|
|
|
|
|
|
|
if (order->type == OT_GOTO_STATION) {
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_SHIP && GetStation(order->dest)->IsBuoy()) continue;
|
2006-10-05 08:15:51 +00:00
|
|
|
|
|
|
|
SetDParam(0, order->dest);
|
|
|
|
DrawString(x, y, STR_A036, 0);
|
|
|
|
|
|
|
|
y += 6;
|
|
|
|
if (++i == 4) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-28 18:13:31 +00:00
|
|
|
static void DrawVehicleListWindow(Window *w)
|
|
|
|
{
|
|
|
|
vehiclelist_d *vl = &WP(w, vehiclelist_d);
|
|
|
|
int x = 2;
|
|
|
|
int y = PLY_WND_PRC__OFFSET_TOP_WIDGET;
|
|
|
|
int max;
|
|
|
|
int i;
|
|
|
|
const PlayerID owner = (PlayerID)w->caption_color;
|
|
|
|
const Player *p = GetPlayer(owner);
|
|
|
|
const uint16 window_type = w->window_number & VLW_MASK;
|
2007-01-21 01:07:15 +00:00
|
|
|
const uint16 index = GB(w->window_number, 16, 16);
|
2006-09-28 18:13:31 +00:00
|
|
|
|
2007-01-21 01:07:15 +00:00
|
|
|
BuildVehicleList(vl, owner, index, window_type);
|
2006-09-28 18:13:31 +00:00
|
|
|
SortVehicleList(vl);
|
|
|
|
SetVScrollCount(w, vl->l.list_length);
|
|
|
|
|
|
|
|
/* draw the widgets */
|
|
|
|
switch (window_type) {
|
|
|
|
case VLW_SHARED_ORDERS: /* Shared Orders */
|
|
|
|
if (vl->l.list_length == 0) {
|
2006-10-05 08:27:40 +00:00
|
|
|
/* We can't open this window without vehicles using this order
|
|
|
|
* and we should close the window when deleting the order */
|
|
|
|
NOT_REACHED();
|
2006-09-28 18:13:31 +00:00
|
|
|
}
|
|
|
|
SetDParam(0, w->vscroll.count);
|
|
|
|
break;
|
2006-08-29 21:36:39 +00:00
|
|
|
|
2006-09-28 18:13:31 +00:00
|
|
|
case VLW_STANDARD: /* Company Name */
|
2007-06-25 13:30:38 +00:00
|
|
|
SetDParam(0, p->index);
|
|
|
|
SetDParam(1, w->vscroll.count);
|
2006-09-28 23:05:03 +00:00
|
|
|
break;
|
2006-08-29 21:36:39 +00:00
|
|
|
|
2006-09-28 23:05:03 +00:00
|
|
|
case VLW_STATION_LIST: /* Station Name */
|
2007-01-21 01:07:15 +00:00
|
|
|
SetDParam(0, index);
|
2006-09-28 23:05:03 +00:00
|
|
|
SetDParam(1, w->vscroll.count);
|
|
|
|
break;
|
2006-09-30 13:39:34 +00:00
|
|
|
|
|
|
|
case VLW_DEPOT_LIST:
|
|
|
|
switch (vl->vehicle_type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: SetDParam(0, STR_8800_TRAIN_DEPOT); break;
|
|
|
|
case VEH_ROAD: SetDParam(0, STR_9003_ROAD_VEHICLE_DEPOT); break;
|
|
|
|
case VEH_SHIP: SetDParam(0, STR_9803_SHIP_DEPOT); break;
|
|
|
|
case VEH_AIRCRAFT: SetDParam(0, STR_A002_AIRCRAFT_HANGAR); break;
|
2006-09-30 13:39:34 +00:00
|
|
|
default: NOT_REACHED(); break;
|
|
|
|
}
|
2007-03-08 16:27:54 +00:00
|
|
|
if (vl->vehicle_type == VEH_AIRCRAFT) {
|
2007-01-21 01:07:15 +00:00
|
|
|
SetDParam(1, index); // Airport name
|
2006-09-30 13:39:34 +00:00
|
|
|
} else {
|
2007-01-21 01:07:15 +00:00
|
|
|
SetDParam(1, GetDepot(index)->town_index);
|
2006-09-30 13:39:34 +00:00
|
|
|
}
|
|
|
|
SetDParam(2, w->vscroll.count);
|
|
|
|
break;
|
2006-09-28 23:05:03 +00:00
|
|
|
default: NOT_REACHED(); break;
|
2006-09-28 18:13:31 +00:00
|
|
|
}
|
2006-09-04 15:13:49 +00:00
|
|
|
|
2006-10-06 21:44:18 +00:00
|
|
|
SetWindowWidgetsDisabledState(w, vl->l.list_length == 0,
|
2006-12-07 14:03:55 +00:00
|
|
|
VLW_WIDGET_MANAGE_VEHICLES,
|
|
|
|
VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN,
|
2006-10-06 21:44:18 +00:00
|
|
|
VLW_WIDGET_STOP_ALL,
|
|
|
|
VLW_WIDGET_START_ALL,
|
|
|
|
WIDGET_LIST_END);
|
2006-08-29 17:41:13 +00:00
|
|
|
|
2006-10-04 00:51:13 +00:00
|
|
|
DrawWindowWidgets(w);
|
2006-09-04 15:13:49 +00:00
|
|
|
|
2006-09-28 18:13:31 +00:00
|
|
|
/* draw sorting criteria string */
|
|
|
|
DrawString(85, 15, _vehicle_sort_listing[vl->l.sort_type], 0x10);
|
|
|
|
/* draw arrow pointing up/down for ascending/descending sorting */
|
|
|
|
DoDrawString(vl->l.flags & VL_DESC ? DOWNARROW : UPARROW, 69, 15, 0x10);
|
|
|
|
|
|
|
|
max = min(w->vscroll.pos + w->vscroll.cap, vl->l.list_length);
|
|
|
|
for (i = w->vscroll.pos; i < max; ++i) {
|
|
|
|
const Vehicle *v = vl->sort_list[i];
|
2006-10-05 08:15:51 +00:00
|
|
|
StringID str;
|
2006-09-28 18:13:31 +00:00
|
|
|
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, v->profit_this_year);
|
|
|
|
SetDParam(1, v->profit_last_year);
|
2006-09-28 18:13:31 +00:00
|
|
|
|
2006-10-06 08:47:01 +00:00
|
|
|
DrawVehicleImage(v, x + 19, y + 6, w->widget[VLW_WIDGET_LIST].right - w->widget[VLW_WIDGET_LIST].left - 20, 0, INVALID_VEHICLE);
|
2006-10-05 08:15:51 +00:00
|
|
|
DrawString(x + 19, y + w->resize.step_height - 8, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
|
2006-09-28 18:13:31 +00:00
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
if ((v->type == VEH_TRAIN && v->string_id != STR_SV_TRAIN_NAME) ||
|
|
|
|
(v->type == VEH_ROAD && v->string_id != STR_SV_ROADVEH_NAME) ||
|
|
|
|
(v->type == VEH_SHIP && v->string_id != STR_SV_SHIP_NAME) ||
|
|
|
|
(v->type == VEH_AIRCRAFT && v->string_id != STR_SV_AIRCRAFT_NAME)) {
|
2006-09-28 18:13:31 +00:00
|
|
|
|
2006-10-05 08:15:51 +00:00
|
|
|
/* The vehicle got a name so we will print it */
|
2007-06-24 22:42:11 +00:00
|
|
|
SetDParam(0, v->index);
|
2006-10-05 08:15:51 +00:00
|
|
|
DrawString(x + 19, y, STR_01AB, 0);
|
|
|
|
}
|
2006-09-28 18:13:31 +00:00
|
|
|
|
2006-10-05 08:15:51 +00:00
|
|
|
if (w->resize.step_height == PLY_WND_PRC__SIZE_OF_ROW_BIG) DrawSmallOrderList(v, x + 138, y);
|
2006-09-03 23:27:38 +00:00
|
|
|
|
2007-08-29 21:49:08 +00:00
|
|
|
if (v->IsInDepot()) {
|
2006-10-05 08:15:51 +00:00
|
|
|
str = STR_021F;
|
|
|
|
} else {
|
|
|
|
str = (v->age > v->max_age - 366) ? STR_00E3 : STR_00E2;
|
2006-09-28 18:13:31 +00:00
|
|
|
}
|
2006-10-05 08:15:51 +00:00
|
|
|
|
2006-09-28 18:13:31 +00:00
|
|
|
SetDParam(0, v->unitnumber);
|
|
|
|
DrawString(x, y + 2, str, 0);
|
2006-08-29 17:41:13 +00:00
|
|
|
|
2006-09-28 18:13:31 +00:00
|
|
|
DrawVehicleProfitButton(v, x, y + 13);
|
2006-08-29 17:41:13 +00:00
|
|
|
|
2006-09-28 18:13:31 +00:00
|
|
|
y += w->resize.step_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bitmask for w->window_number
|
|
|
|
* 0-7 PlayerID (owner)
|
|
|
|
* 8-10 window type (use flags in vehicle_gui.h)
|
|
|
|
* 11-15 vehicle type (using VEH_, but can be compressed to fewer bytes if needed)
|
|
|
|
* 16-31 StationID or OrderID depending on window type (bit 8-10)
|
|
|
|
**/
|
|
|
|
void PlayerVehWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
vehiclelist_d *vl = &WP(w, vehiclelist_d);
|
|
|
|
|
|
|
|
switch (e->event) {
|
|
|
|
case WE_CREATE:
|
|
|
|
CreateVehicleListWindow(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_PAINT:
|
|
|
|
DrawVehicleListWindow(w);
|
|
|
|
break;
|
2006-08-29 17:41:13 +00:00
|
|
|
|
|
|
|
case WE_CLICK: {
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2006-09-28 23:05:03 +00:00
|
|
|
case VLW_WIDGET_SORT_ORDER: /* Flip sorting method ascending/descending */
|
2006-09-04 15:13:49 +00:00
|
|
|
vl->l.flags ^= VL_DESC;
|
|
|
|
vl->l.flags |= VL_RESORT;
|
|
|
|
|
|
|
|
vl->_sorting->order = !!(vl->l.flags & VL_DESC);
|
2006-08-29 17:41:13 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2006-09-28 23:05:03 +00:00
|
|
|
case VLW_WIDGET_SORT_BY_TEXT: case VLW_WIDGET_SORT_BY_PULLDOWN:/* Select sorting criteria dropdown menu */
|
|
|
|
ShowDropDownMenu(w, _vehicle_sort_listing, vl->l.sort_type, VLW_WIDGET_SORT_BY_PULLDOWN, 0, 0);
|
2006-08-29 17:41:13 +00:00
|
|
|
return;
|
2006-09-28 23:05:03 +00:00
|
|
|
case VLW_WIDGET_LIST: { /* Matrix to show vehicles */
|
2006-09-23 02:39:24 +00:00
|
|
|
uint32 id_v = (e->we.click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / w->resize.step_height;
|
2006-08-29 17:41:13 +00:00
|
|
|
const Vehicle *v;
|
|
|
|
|
|
|
|
if (id_v >= w->vscroll.cap) return; // click out of bounds
|
|
|
|
|
|
|
|
id_v += w->vscroll.pos;
|
|
|
|
|
2006-09-04 15:13:49 +00:00
|
|
|
if (id_v >= vl->l.list_length) return; // click out of list bound
|
2006-08-29 17:41:13 +00:00
|
|
|
|
|
|
|
v = vl->sort_list[id_v];
|
|
|
|
|
2007-08-29 20:50:58 +00:00
|
|
|
ShowVehicleViewWindow(v);
|
2006-08-29 17:41:13 +00:00
|
|
|
} break;
|
|
|
|
|
2007-01-26 19:24:02 +00:00
|
|
|
case VLW_WIDGET_AVAILABLE_VEHICLES:
|
2007-01-22 02:09:51 +00:00
|
|
|
ShowBuildVehicleWindow(0, vl->vehicle_type);
|
2006-08-30 23:01:45 +00:00
|
|
|
break;
|
2006-08-29 17:41:13 +00:00
|
|
|
|
2006-12-07 14:03:55 +00:00
|
|
|
case VLW_WIDGET_MANAGE_VEHICLES:
|
|
|
|
case VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN: {
|
|
|
|
static StringID action_str[] = {
|
|
|
|
STR_REPLACE_VEHICLES,
|
|
|
|
STR_SEND_FOR_SERVICING,
|
|
|
|
STR_NULL,
|
|
|
|
INVALID_STRING_ID
|
|
|
|
};
|
|
|
|
|
|
|
|
static const StringID depot_name[] = {
|
|
|
|
STR_SEND_TRAIN_TO_DEPOT,
|
|
|
|
STR_SEND_ROAD_VEHICLE_TO_DEPOT,
|
|
|
|
STR_SEND_SHIP_TO_DEPOT,
|
|
|
|
STR_SEND_AIRCRAFT_TO_HANGAR
|
|
|
|
};
|
|
|
|
|
|
|
|
/* XXX - Substite string since the dropdown cannot handle dynamic strings */
|
2007-02-07 19:10:19 +00:00
|
|
|
action_str[2] = depot_name[vl->vehicle_type];
|
2007-06-26 08:11:11 +00:00
|
|
|
ShowDropDownMenu(w, action_str, 0, VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN, 0, (w->window_number & VLW_MASK) == VLW_STANDARD ? 0 : 1);
|
2006-08-29 17:41:13 +00:00
|
|
|
break;
|
2006-12-07 14:03:55 +00:00
|
|
|
}
|
2006-09-29 11:30:48 +00:00
|
|
|
|
|
|
|
case VLW_WIDGET_STOP_ALL:
|
|
|
|
case VLW_WIDGET_START_ALL:
|
2006-10-07 08:24:11 +00:00
|
|
|
DoCommandP(0, GB(w->window_number, 16, 16), (w->window_number & VLW_MASK) | (1 << 6) | (e->we.click.widget == VLW_WIDGET_START_ALL ? (1 << 5) : 0) | vl->vehicle_type, NULL, CMD_MASS_START_STOP);
|
2006-09-29 11:30:48 +00:00
|
|
|
break;
|
2006-08-29 17:41:13 +00:00
|
|
|
}
|
2007-04-18 22:41:53 +00:00
|
|
|
} break;
|
2006-08-29 17:41:13 +00:00
|
|
|
|
|
|
|
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
|
2006-12-07 14:03:55 +00:00
|
|
|
switch (e->we.dropdown.button) {
|
|
|
|
case VLW_WIDGET_SORT_BY_PULLDOWN:
|
|
|
|
if (vl->l.sort_type != e->we.dropdown.index) {
|
2007-04-04 04:08:47 +00:00
|
|
|
/* value has changed -> resort */
|
2006-12-07 14:03:55 +00:00
|
|
|
vl->l.flags |= VL_RESORT;
|
|
|
|
vl->l.sort_type = e->we.dropdown.index;
|
|
|
|
vl->_sorting->criteria = vl->l.sort_type;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN:
|
|
|
|
assert(vl->l.list_length != 0);
|
|
|
|
|
|
|
|
switch (e->we.dropdown.index) {
|
|
|
|
case 0: /* Replace window */
|
|
|
|
ShowReplaceVehicleWindow(vl->vehicle_type);
|
|
|
|
break;
|
|
|
|
case 1: /* Send for servicing */
|
|
|
|
DoCommandP(0, GB(w->window_number, 16, 16) /* StationID or OrderID (depending on VLW) */,
|
|
|
|
(w->window_number & VLW_MASK) | DEPOT_MASS_SEND | DEPOT_SERVICE,
|
|
|
|
NULL,
|
2007-01-22 16:16:52 +00:00
|
|
|
GetCmdSendToDepot(vl->vehicle_type));
|
2006-12-07 14:03:55 +00:00
|
|
|
break;
|
|
|
|
case 2: /* Send to Depots */
|
|
|
|
DoCommandP(0, GB(w->window_number, 16, 16) /* StationID or OrderID (depending on VLW) */,
|
|
|
|
(w->window_number & VLW_MASK) | DEPOT_MASS_SEND,
|
|
|
|
NULL,
|
2007-01-22 16:16:52 +00:00
|
|
|
GetCmdSendToDepot(vl->vehicle_type));
|
2006-12-07 14:03:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: NOT_REACHED();
|
2006-08-29 17:41:13 +00:00
|
|
|
}
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_DESTROY:
|
|
|
|
free((void*)vl->sort_list);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_TICK: /* resort the list every 20 seconds orso (10 days) */
|
2006-09-04 15:13:49 +00:00
|
|
|
if (--vl->l.resort_timer == 0) {
|
2006-09-04 15:16:58 +00:00
|
|
|
StationID station = ((w->window_number & VLW_MASK) == VLW_STATION_LIST) ? GB(w->window_number, 16, 16) : INVALID_STATION;
|
2006-09-04 15:13:49 +00:00
|
|
|
PlayerID owner = (PlayerID)w->caption_color;
|
|
|
|
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG(misc, 3, "Periodic resort %d list player %d at station %d", vl->vehicle_type, owner, station);
|
2006-09-04 15:13:49 +00:00
|
|
|
vl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
|
|
|
|
vl->l.flags |= VL_RESORT;
|
2006-08-29 17:41:13 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-09-03 23:27:38 +00:00
|
|
|
case WE_RESIZE: /* Update the scroll + matrix */
|
2006-09-23 02:39:24 +00:00
|
|
|
w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
|
2006-09-28 23:05:03 +00:00
|
|
|
w->widget[VLW_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
|
2006-08-29 17:41:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-09-28 23:05:03 +00:00
|
|
|
|
|
|
|
static const WindowDesc _player_vehicle_list_train_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 260, 182, 260, 182,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_TRAINS_LIST, WC_NONE,
|
2006-11-10 19:24:14 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
|
|
|
_vehicle_list_widgets,
|
|
|
|
PlayerVehWndProc
|
2006-09-28 23:05:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _player_vehicle_list_road_veh_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 260, 182, 260, 182,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_ROADVEH_LIST, WC_NONE,
|
2006-10-04 17:09:17 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
|
|
|
_vehicle_list_widgets,
|
|
|
|
PlayerVehWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _player_vehicle_list_ship_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 260, 182, 260, 182,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_SHIPS_LIST, WC_NONE,
|
2006-10-04 17:09:17 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
|
|
|
_vehicle_list_widgets,
|
|
|
|
PlayerVehWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _player_vehicle_list_aircraft_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 260, 182, 260, 182,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_AIRCRAFT_LIST, WC_NONE,
|
2006-09-28 23:05:03 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
|
|
|
_vehicle_list_widgets,
|
|
|
|
PlayerVehWndProc
|
|
|
|
};
|
|
|
|
|
2007-05-18 17:31:41 +00:00
|
|
|
static void ShowVehicleListWindowLocal(PlayerID player, uint16 VLW_flag, VehicleType vehicle_type, uint16 unique_number)
|
2006-09-28 23:05:03 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
2006-10-31 21:15:56 +00:00
|
|
|
WindowNumber num;
|
2006-09-28 23:05:03 +00:00
|
|
|
|
2006-10-31 21:15:56 +00:00
|
|
|
if (!IsValidPlayer(player)) return;
|
|
|
|
|
2007-01-21 00:01:47 +00:00
|
|
|
num = (unique_number << 16) | (vehicle_type << 11) | VLW_flag | player;
|
2006-09-28 23:05:03 +00:00
|
|
|
|
2006-12-07 00:51:20 +00:00
|
|
|
/* The vehicle list windows have been unified. Just some strings need
|
|
|
|
* to be changed which happens in the WE_CREATE event and resizing
|
|
|
|
* some of the windows to the correct size */
|
2006-10-04 17:09:17 +00:00
|
|
|
switch (vehicle_type) {
|
2007-01-21 13:16:31 +00:00
|
|
|
default: NOT_REACHED();
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN:
|
2006-12-07 00:51:20 +00:00
|
|
|
w = AllocateWindowDescFront(&_player_vehicle_list_train_desc, num);
|
|
|
|
if (w != NULL) ResizeWindow(w, 65, 38);
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_ROAD:
|
2006-12-07 00:51:20 +00:00
|
|
|
w = AllocateWindowDescFront(&_player_vehicle_list_road_veh_desc, num);
|
|
|
|
if (w != NULL) ResizeWindow(w, 0, 38);
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_SHIP:
|
2006-12-07 00:51:20 +00:00
|
|
|
w = AllocateWindowDescFront(&_player_vehicle_list_ship_desc, num);
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_AIRCRAFT:
|
2006-12-07 00:51:20 +00:00
|
|
|
w = AllocateWindowDescFront(&_player_vehicle_list_aircraft_desc, num);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w != NULL) {
|
|
|
|
/* Set the minimum window size to the current window size */
|
|
|
|
w->resize.width = w->width;
|
|
|
|
w->resize.height = w->height;
|
2006-09-28 23:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-18 17:31:41 +00:00
|
|
|
void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type)
|
2006-09-28 23:05:03 +00:00
|
|
|
{
|
2007-05-19 09:40:18 +00:00
|
|
|
if (player == _local_player && _patches.advanced_vehicle_list) {
|
|
|
|
ShowPlayerGroup(player, vehicle_type);
|
|
|
|
} else {
|
|
|
|
ShowVehicleListWindowLocal(player, VLW_STANDARD, vehicle_type, 0);
|
|
|
|
}
|
2006-09-28 23:05:03 +00:00
|
|
|
}
|
|
|
|
|
2007-01-21 00:01:47 +00:00
|
|
|
void ShowVehicleListWindow(const Vehicle *v)
|
2006-09-28 23:05:03 +00:00
|
|
|
{
|
|
|
|
if (v->orders == NULL) return; // no shared list to show
|
2007-01-21 00:01:47 +00:00
|
|
|
ShowVehicleListWindowLocal(v->owner, VLW_SHARED_ORDERS, v->type, v->orders->index);
|
|
|
|
}
|
|
|
|
|
2007-05-18 17:31:41 +00:00
|
|
|
void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, StationID station)
|
2007-01-21 00:01:47 +00:00
|
|
|
{
|
|
|
|
ShowVehicleListWindowLocal(player, VLW_STATION_LIST, vehicle_type, station);
|
2006-09-30 13:39:34 +00:00
|
|
|
}
|
|
|
|
|
2007-05-18 17:31:41 +00:00
|
|
|
void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, TileIndex depot_tile)
|
2006-09-30 13:39:34 +00:00
|
|
|
{
|
|
|
|
uint16 depot_airport_index;
|
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
if (vehicle_type == VEH_AIRCRAFT) {
|
2006-09-30 13:39:34 +00:00
|
|
|
depot_airport_index = GetStationIndex(depot_tile);
|
|
|
|
} else {
|
|
|
|
Depot *depot = GetDepotByTile(depot_tile);
|
|
|
|
if (depot == NULL) return; // no depot to show
|
|
|
|
depot_airport_index = depot->index;
|
|
|
|
}
|
2007-01-21 00:01:47 +00:00
|
|
|
ShowVehicleListWindowLocal(player, VLW_DEPOT_LIST, vehicle_type, depot_airport_index);
|
2006-09-29 07:30:44 +00:00
|
|
|
}
|
2007-08-29 20:50:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Unified vehicle GUI - Vehicle View Window */
|
|
|
|
|
|
|
|
/** Constants of vehicle view widget indices */
|
|
|
|
enum VehicleViewWindowWidgets {
|
|
|
|
VVW_WIDGET_CLOSEBOX = 0,
|
|
|
|
VVW_WIDGET_CAPTION,
|
|
|
|
VVW_WIDGET_STICKY,
|
|
|
|
VVW_WIDGET_PANEL,
|
|
|
|
VVW_WIDGET_VIEWPORT,
|
|
|
|
VVW_WIDGET_START_STOP_VEH,
|
|
|
|
VVW_WIDGET_CENTER_MAIN_VIEH,
|
|
|
|
VVW_WIDGET_GOTO_DEPOT,
|
|
|
|
VVW_WIDGET_REFIT_VEH,
|
|
|
|
VVW_WIDGET_SHOW_ORDERS,
|
|
|
|
VVW_WIDGET_SHOW_DETAILS,
|
|
|
|
VVW_WIDGET_CLONE_VEH,
|
|
|
|
VVW_WIDGET_EMPTY_BOTTOM_RIGHT,
|
|
|
|
VVW_WIDGET_RESIZE,
|
|
|
|
VVW_WIDGET_TURN_AROUND,
|
|
|
|
VVW_WIDGET_FORCE_PROCEED,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Vehicle view widgets. */
|
|
|
|
static const Widget _vehicle_view_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, // VVW_WIDGET_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 237, 0, 13, 0x0 /* filled later */, STR_018C_WINDOW_TITLE_DRAG_THIS }, // VVW_WIDGET_CAPTION
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, 14, 238, 249, 0, 13, 0x0, STR_STICKY_BUTTON }, // VVW_WIDGET_STICKY
|
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 231, 14, 103, 0x0, STR_NULL }, // VVW_WIDGET_PANEL
|
|
|
|
{ WWT_INSET, RESIZE_RB, 14, 2, 229, 16, 101, 0x0, STR_NULL }, // VVW_WIDGET_VIEWPORT
|
|
|
|
{ WWT_PUSHBTN, RESIZE_RTB, 14, 0, 237, 104, 115, 0x0, 0x0 /* filled later */ }, // VVW_WIDGET_START_STOP_VEH
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 14, 31, SPR_CENTRE_VIEW_VEHICLE, 0x0 /* filled later */ }, // VVW_WIDGET_CENTER_MAIN_VIEH
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, 0x0 /* filled later */, 0x0 /* filled later */ }, // VVW_WIDGET_GOTO_DEPOT
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 50, 67, SPR_REFIT_VEHICLE, 0x0 /* filled later */ }, // VVW_WIDGET_REFIT_VEH
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, SPR_SHOW_ORDERS, 0x0 /* filled later */ }, // VVW_WIDGET_SHOW_ORDERS
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 86, 103, SPR_SHOW_VEHICLE_DETAILS, 0x0 /* filled later */ }, // VVW_WIDGET_SHOW_DETAILS
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, 0x0 /* filled later */, 0x0 /* filled later */ }, // VVW_WIDGET_CLONE_VEH
|
|
|
|
{ WWT_PANEL, RESIZE_LRB, 14, 232, 249, 104, 103, 0x0, STR_NULL }, // VVW_WIDGET_EMPTY_BOTTOM_RIGHT
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 238, 249, 104, 115, 0x0, STR_NULL }, // VVW_WIDGET_RESIZE
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 50, 67, SPR_FORCE_VEHICLE_TURN, STR_9020_FORCE_VEHICLE_TO_TURN_AROUND }, // VVW_WIDGET_TURN_AROUND
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 50, 67, SPR_IGNORE_SIGNALS, STR_884A_FORCE_TRAIN_TO_PROCEED }, // VVW_WIDGET_FORCE_PROCEED
|
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void VehicleViewWndProc(Window *w, WindowEvent *e);
|
|
|
|
|
|
|
|
/** Vehicle view window descriptor for all vehicles but trains. */
|
|
|
|
static const WindowDesc _vehicle_view_desc = {
|
|
|
|
WDP_AUTO, WDP_AUTO, 250, 116, 250, 116,
|
|
|
|
WC_VEHICLE_VIEW, WC_NONE,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
|
|
|
_vehicle_view_widgets,
|
|
|
|
VehicleViewWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Vehicle view window descriptor for trains. Only minimum_height and
|
|
|
|
* default_height are different for train view.
|
|
|
|
*/
|
|
|
|
static const WindowDesc _train_view_desc = {
|
|
|
|
WDP_AUTO, WDP_AUTO, 250, 134, 250, 134,
|
|
|
|
WC_VEHICLE_VIEW, WC_NONE,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
|
|
|
_vehicle_view_widgets,
|
|
|
|
VehicleViewWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Just to make sure, nobody has changed the vehicle type constants, as we are
|
|
|
|
using them for array indexing in a number of places here. */
|
|
|
|
assert_compile(VEH_TRAIN == 0);
|
|
|
|
assert_compile(VEH_ROAD == 1);
|
|
|
|
assert_compile(VEH_SHIP == 2);
|
|
|
|
assert_compile(VEH_AIRCRAFT == 3);
|
|
|
|
|
|
|
|
/** Zoom levels for vehicle views indexed by vehicle type. */
|
|
|
|
static const ZoomLevel _vehicle_view_zoom_levels[] = {
|
|
|
|
ZOOM_LVL_TRAIN,
|
|
|
|
ZOOM_LVL_ROADVEH,
|
|
|
|
ZOOM_LVL_SHIP,
|
|
|
|
ZOOM_LVL_AIRCRAFT,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Constants for geometry of vehicle view viewport */
|
|
|
|
static const int VV_VIEWPORT_X = 3;
|
|
|
|
static const int VV_VIEWPORT_Y = 17;
|
|
|
|
static const int VV_INITIAL_VIEWPORT_WIDTH = 226;
|
|
|
|
static const int VV_INITIAL_VIEWPORT_HEIGHT = 84;
|
|
|
|
static const int VV_INITIAL_VIEWPORT_HEIGHT_TRAIN = 102;
|
|
|
|
|
|
|
|
/** Shows the vehicle view window of the given vehicle. */
|
|
|
|
void ShowVehicleViewWindow(const Vehicle *v)
|
|
|
|
{
|
|
|
|
Window *w = AllocateWindowDescFront((v->type == VEH_TRAIN) ? &_train_view_desc : &_vehicle_view_desc, v->index);
|
|
|
|
|
|
|
|
if (w != NULL) {
|
|
|
|
w->caption_color = v->owner;
|
|
|
|
AssignWindowViewport(w, VV_VIEWPORT_X, VV_VIEWPORT_Y, VV_INITIAL_VIEWPORT_WIDTH,
|
|
|
|
(v->type == VEH_TRAIN) ? VV_INITIAL_VIEWPORT_HEIGHT_TRAIN : VV_INITIAL_VIEWPORT_HEIGHT,
|
|
|
|
w->window_number | (1 << 31), _vehicle_view_zoom_levels[v->type]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Initialize a newly created vehicle view window */
|
|
|
|
static void CreateVehicleViewWindow(Window *w)
|
|
|
|
{
|
|
|
|
const Vehicle *v = GetVehicle(w->window_number);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fill in data and tooltip codes for the widgets and
|
|
|
|
* move some of the buttons for trains
|
|
|
|
*/
|
|
|
|
switch (v->type) {
|
|
|
|
case VEH_TRAIN:
|
|
|
|
w->widget[VVW_WIDGET_CAPTION].data = STR_882E;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_START_STOP_VEH].tooltips = STR_8846_CURRENT_TRAIN_ACTION_CLICK;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_CENTER_MAIN_VIEH].tooltips = STR_8848_CENTER_MAIN_VIEW_ON_TRAIN;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_GOTO_DEPOT].data = SPR_SEND_TRAIN_TODEPOT;
|
|
|
|
w->widget[VVW_WIDGET_GOTO_DEPOT].tooltips = STR_8849_SEND_TRAIN_TO_DEPOT;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_REFIT_VEH].tooltips = STR_RAIL_REFIT_VEHICLE_TO_CARRY;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_SHOW_ORDERS].tooltips = STR_8847_SHOW_TRAIN_S_ORDERS;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_SHOW_DETAILS].tooltips = STR_884C_SHOW_TRAIN_DETAILS;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_CLONE_VEH].data = SPR_CLONE_TRAIN;
|
|
|
|
w->widget[VVW_WIDGET_CLONE_VEH].tooltips = STR_CLONE_TRAIN_INFO;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_TURN_AROUND].tooltips = STR_884B_REVERSE_DIRECTION_OF_TRAIN;
|
|
|
|
|
|
|
|
|
|
|
|
/* due to more buttons we must modify the layout a bit for trains */
|
|
|
|
w->widget[VVW_WIDGET_PANEL].bottom = 121;
|
|
|
|
w->widget[VVW_WIDGET_VIEWPORT].bottom = 119;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_START_STOP_VEH].top = 122;
|
|
|
|
w->widget[VVW_WIDGET_START_STOP_VEH].bottom = 133;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_REFIT_VEH].top = 68;
|
|
|
|
w->widget[VVW_WIDGET_REFIT_VEH].bottom = 85;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_SHOW_ORDERS].top = 86;
|
|
|
|
w->widget[VVW_WIDGET_SHOW_ORDERS].bottom = 103;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_SHOW_DETAILS].top = 104;
|
|
|
|
w->widget[VVW_WIDGET_SHOW_DETAILS].bottom = 121;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_EMPTY_BOTTOM_RIGHT].top = 122;
|
|
|
|
w->widget[VVW_WIDGET_EMPTY_BOTTOM_RIGHT].bottom = 121;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_RESIZE].top = 122;
|
|
|
|
w->widget[VVW_WIDGET_RESIZE].bottom = 133;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_TURN_AROUND].top = 68;
|
|
|
|
w->widget[VVW_WIDGET_TURN_AROUND].bottom = 85;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_ROAD:
|
|
|
|
w->widget[VVW_WIDGET_CAPTION].data = STR_9002;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_START_STOP_VEH].tooltips = STR_901C_CURRENT_VEHICLE_ACTION;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_CENTER_MAIN_VIEH].tooltips = STR_901E_CENTER_MAIN_VIEW_ON_VEHICLE;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_GOTO_DEPOT].data = SPR_SEND_ROADVEH_TODEPOT;
|
|
|
|
w->widget[VVW_WIDGET_GOTO_DEPOT].tooltips = STR_901F_SEND_VEHICLE_TO_DEPOT;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_REFIT_VEH].tooltips = STR_REFIT_ROAD_VEHICLE_TO_CARRY;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_SHOW_ORDERS].tooltips = STR_901D_SHOW_VEHICLE_S_ORDERS;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_SHOW_DETAILS].tooltips = STR_9021_SHOW_ROAD_VEHICLE_DETAILS;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_CLONE_VEH].data = SPR_CLONE_ROADVEH;
|
|
|
|
w->widget[VVW_WIDGET_CLONE_VEH].tooltips = STR_CLONE_ROAD_VEHICLE_INFO;
|
|
|
|
|
|
|
|
SetWindowWidgetHiddenState(w, VVW_WIDGET_FORCE_PROCEED, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_SHIP:
|
|
|
|
w->widget[VVW_WIDGET_CAPTION].data = STR_980F;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_START_STOP_VEH].tooltips = STR_9827_CURRENT_SHIP_ACTION_CLICK;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_CENTER_MAIN_VIEH].tooltips = STR_9829_CENTER_MAIN_VIEW_ON_SHIP;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_GOTO_DEPOT].data = SPR_SEND_SHIP_TODEPOT;
|
|
|
|
w->widget[VVW_WIDGET_GOTO_DEPOT].tooltips = STR_982A_SEND_SHIP_TO_DEPOT;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_REFIT_VEH].tooltips = STR_983A_REFIT_CARGO_SHIP_TO_CARRY;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_SHOW_ORDERS].tooltips = STR_9828_SHOW_SHIP_S_ORDERS;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_SHOW_DETAILS].tooltips = STR_982B_SHOW_SHIP_DETAILS;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_CLONE_VEH].data = SPR_CLONE_SHIP;
|
|
|
|
w->widget[VVW_WIDGET_CLONE_VEH].tooltips = STR_CLONE_SHIP_INFO;
|
|
|
|
|
|
|
|
SetWindowWidgetsHiddenState(w, true,
|
|
|
|
VVW_WIDGET_TURN_AROUND,
|
|
|
|
VVW_WIDGET_FORCE_PROCEED,
|
|
|
|
WIDGET_LIST_END);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_AIRCRAFT:
|
|
|
|
w->widget[VVW_WIDGET_CAPTION].data = STR_A00A;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_START_STOP_VEH].tooltips = STR_A027_CURRENT_AIRCRAFT_ACTION;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_CENTER_MAIN_VIEH].tooltips = STR_A029_CENTER_MAIN_VIEW_ON_AIRCRAFT;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_GOTO_DEPOT].data = SPR_SEND_AIRCRAFT_TODEPOT;
|
|
|
|
w->widget[VVW_WIDGET_GOTO_DEPOT].tooltips = STR_A02A_SEND_AIRCRAFT_TO_HANGAR;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_REFIT_VEH].tooltips = STR_A03B_REFIT_AIRCRAFT_TO_CARRY;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_SHOW_ORDERS].tooltips = STR_A028_SHOW_AIRCRAFT_S_ORDERS;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_SHOW_DETAILS].tooltips = STR_A02B_SHOW_AIRCRAFT_DETAILS;
|
|
|
|
|
|
|
|
w->widget[VVW_WIDGET_CLONE_VEH].data = SPR_CLONE_AIRCRAFT;
|
|
|
|
w->widget[VVW_WIDGET_CLONE_VEH].tooltips = STR_CLONE_AIRCRAFT_INFO;
|
|
|
|
|
|
|
|
SetWindowWidgetsHiddenState(w, true,
|
|
|
|
VVW_WIDGET_TURN_AROUND,
|
|
|
|
VVW_WIDGET_FORCE_PROCEED,
|
|
|
|
WIDGET_LIST_END);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* When unified GUI is complete these functions will also be unified to one
|
|
|
|
* function in this module */
|
|
|
|
void ShowAircraftDetailsWindow(const Vehicle *v);
|
|
|
|
void ShowShipDetailsWindow(const Vehicle *v);
|
|
|
|
void ShowRoadVehDetailsWindow(const Vehicle *v);
|
|
|
|
void ShowTrainDetailsWindow(const Vehicle *v);
|
|
|
|
|
|
|
|
|
|
|
|
/** Provisional dispatch to vehicle-specific detail window functions. */
|
|
|
|
static void ShowVehicleDetailsWindow(const Vehicle *v)
|
|
|
|
{
|
|
|
|
switch (v->type) {
|
|
|
|
case VEH_TRAIN: ShowTrainDetailsWindow(v); break;
|
|
|
|
case VEH_ROAD: ShowRoadVehDetailsWindow(v); break;
|
|
|
|
case VEH_SHIP: ShowShipDetailsWindow(v); break;
|
|
|
|
case VEH_AIRCRAFT: ShowAircraftDetailsWindow(v); break;
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Checks whether the vehicle may be refitted at the moment.*/
|
|
|
|
static bool IsVehicleRefitable(const Vehicle *v)
|
|
|
|
{
|
|
|
|
/* Why is this so different for different vehicles?
|
|
|
|
* Does maybe work one solution for all?
|
|
|
|
*/
|
|
|
|
switch (v->type) {
|
|
|
|
case VEH_TRAIN: return false;
|
2007-08-29 21:49:08 +00:00
|
|
|
case VEH_ROAD: return EngInfo(v->engine_type)->refit_mask != 0 && v->IsStoppedInDepot();
|
|
|
|
case VEH_SHIP: return ShipVehInfo(v->engine_type)->refittable && v->IsStoppedInDepot();
|
|
|
|
case VEH_AIRCRAFT: return v->IsStoppedInDepot();
|
2007-08-29 20:50:58 +00:00
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Message strings for heading to depot indexed by vehicle type. */
|
|
|
|
static const StringID _heading_for_depot_strings[] = {
|
|
|
|
STR_HEADING_FOR_TRAIN_DEPOT,
|
|
|
|
STR_HEADING_FOR_ROAD_DEPOT,
|
|
|
|
STR_HEADING_FOR_SHIP_DEPOT,
|
|
|
|
STR_HEADING_FOR_HANGAR,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Message strings for heading to depot and servicing indexed by vehicle type. */
|
|
|
|
static const StringID _heading_for_depot_service_strings[] = {
|
|
|
|
STR_HEADING_FOR_TRAIN_DEPOT_SERVICE,
|
|
|
|
STR_HEADING_FOR_ROAD_DEPOT_SERVICE,
|
|
|
|
STR_HEADING_FOR_SHIP_DEPOT_SERVICE,
|
|
|
|
STR_HEADING_FOR_HANGAR_SERVICE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Repaint vehicle view window. */
|
|
|
|
static void DrawVehicleViewWindow(Window *w)
|
|
|
|
{
|
|
|
|
const Vehicle *v = GetVehicle(w->window_number);
|
|
|
|
StringID str;
|
|
|
|
bool is_localplayer = v->owner == _local_player;
|
|
|
|
bool refitable_and_stopped_in_depot = IsVehicleRefitable(v);
|
|
|
|
|
|
|
|
SetWindowWidgetDisabledState(w, VVW_WIDGET_GOTO_DEPOT, !is_localplayer);
|
|
|
|
SetWindowWidgetDisabledState(w, VVW_WIDGET_REFIT_VEH,
|
|
|
|
!refitable_and_stopped_in_depot || !is_localplayer);
|
|
|
|
SetWindowWidgetDisabledState(w, VVW_WIDGET_CLONE_VEH, !is_localplayer);
|
|
|
|
|
|
|
|
if (v->type == VEH_TRAIN) {
|
|
|
|
SetWindowWidgetDisabledState(w, VVW_WIDGET_FORCE_PROCEED, !is_localplayer);
|
|
|
|
SetWindowWidgetDisabledState(w, VVW_WIDGET_TURN_AROUND, !is_localplayer);
|
|
|
|
|
|
|
|
/* Cargo refit button is disabled, until we know we can enable it below. */
|
|
|
|
|
|
|
|
if (is_localplayer) {
|
|
|
|
/* See if any vehicle can be refitted */
|
2007-08-30 13:03:56 +00:00
|
|
|
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
|
2007-08-29 20:50:58 +00:00
|
|
|
if (EngInfo(u->engine_type)->refit_mask != 0 ||
|
|
|
|
(RailVehInfo(v->engine_type)->railveh_type != RAILVEH_WAGON && v->cargo_cap != 0)) {
|
|
|
|
EnableWindowWidget(w, VVW_WIDGET_REFIT_VEH);
|
|
|
|
/* We have a refittable carriage, bail out */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw widgets & caption */
|
|
|
|
SetDParam(0, v->index);
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
if (v->vehstatus & VS_CRASHED) {
|
|
|
|
str = STR_8863_CRASHED;
|
|
|
|
} else if (v->type != VEH_AIRCRAFT && v->breakdown_ctr == 1) { // check for aircraft necessary?
|
|
|
|
str = STR_885C_BROKEN_DOWN;
|
|
|
|
} else if (v->vehstatus & VS_STOPPED) {
|
|
|
|
if (v->type == VEH_TRAIN) {
|
|
|
|
if (v->cur_speed == 0) {
|
|
|
|
if (v->u.rail.cached_power == 0) {
|
|
|
|
str = STR_TRAIN_NO_POWER;
|
|
|
|
} else {
|
|
|
|
str = STR_8861_STOPPED;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SetDParam(0, v->GetDisplaySpeed());
|
|
|
|
str = STR_TRAIN_STOPPING + _patches.vehicle_speed;
|
|
|
|
}
|
|
|
|
} else { // no train
|
|
|
|
str = STR_8861_STOPPED;
|
|
|
|
}
|
|
|
|
} else { // vehicle is in a "normal" state, show current order
|
|
|
|
switch (v->current_order.type) {
|
|
|
|
case OT_GOTO_STATION: {
|
|
|
|
SetDParam(0, v->current_order.dest);
|
|
|
|
SetDParam(1, v->GetDisplaySpeed());
|
|
|
|
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case OT_GOTO_DEPOT: {
|
|
|
|
if (v->type == VEH_AIRCRAFT) {
|
|
|
|
/* Aircrafts always go to a station, even if you say depot */
|
|
|
|
SetDParam(0, v->current_order.dest);
|
|
|
|
SetDParam(1, v->GetDisplaySpeed());
|
|
|
|
} else {
|
|
|
|
Depot *depot = GetDepot(v->current_order.dest);
|
|
|
|
SetDParam(0, depot->town_index);
|
|
|
|
SetDParam(1, v->GetDisplaySpeed());
|
|
|
|
}
|
|
|
|
if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
|
|
|
|
str = _heading_for_depot_strings[v->type] + _patches.vehicle_speed;
|
|
|
|
} else {
|
|
|
|
str = _heading_for_depot_service_strings[v->type] + _patches.vehicle_speed;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case OT_LOADING:
|
|
|
|
str = STR_882F_LOADING_UNLOADING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OT_GOTO_WAYPOINT: {
|
|
|
|
assert(v->type == VEH_TRAIN);
|
|
|
|
SetDParam(0, v->current_order.dest);
|
|
|
|
str = STR_HEADING_FOR_WAYPOINT + _patches.vehicle_speed;
|
|
|
|
SetDParam(1, v->GetDisplaySpeed());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OT_LEAVESTATION:
|
|
|
|
if (v->type != VEH_AIRCRAFT) {
|
|
|
|
str = STR_882F_LOADING_UNLOADING;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall-through if aircraft. Does this even happen? */
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (v->num_orders == 0) {
|
|
|
|
str = STR_NO_ORDERS + _patches.vehicle_speed;
|
|
|
|
SetDParam(0, v->GetDisplaySpeed());
|
|
|
|
} else {
|
|
|
|
str = STR_EMPTY;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw the flag plus orders */
|
|
|
|
DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, 2, w->widget[VVW_WIDGET_START_STOP_VEH].top + 1);
|
|
|
|
DrawStringCenteredTruncated(w->widget[VVW_WIDGET_START_STOP_VEH].left + 8, w->widget[VVW_WIDGET_START_STOP_VEH].right, w->widget[VVW_WIDGET_START_STOP_VEH].top + 1, str, 0);
|
|
|
|
DrawWindowViewport(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Command indices for the _vehicle_command_translation_table. */
|
|
|
|
enum VehicleCommandTranslation {
|
|
|
|
VCT_CMD_START_STOP = 0,
|
|
|
|
VCT_CMD_GOTO_DEPOT,
|
|
|
|
VCT_CMD_CLONE_VEH,
|
|
|
|
VCT_CMD_TURN_AROUND,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Command codes for the shared buttons indexed by VehicleCommandTranslation and vehicle type. */
|
|
|
|
static const uint32 _vehicle_command_translation_table[][4] = {
|
|
|
|
{ // VCT_CMD_START_STOP
|
|
|
|
CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN),
|
|
|
|
CMD_START_STOP_ROADVEH | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE),
|
|
|
|
CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP),
|
|
|
|
CMD_START_STOP_AIRCRAFT | CMD_MSG(STR_A016_CAN_T_STOP_START_AIRCRAFT)
|
|
|
|
},
|
|
|
|
{ // VCT_CMD_GOTO_DEPOT
|
|
|
|
/* TrainGotoDepot has a nice randomizer in the pathfinder, which causes desyncs... */
|
|
|
|
CMD_SEND_TRAIN_TO_DEPOT | CMD_NO_TEST_IF_IN_NETWORK | CMD_MSG(STR_8830_CAN_T_SEND_TRAIN_TO_DEPOT),
|
|
|
|
CMD_SEND_ROADVEH_TO_DEPOT | CMD_MSG(STR_9018_CAN_T_SEND_VEHICLE_TO_DEPOT),
|
|
|
|
CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_9819_CAN_T_SEND_SHIP_TO_DEPOT),
|
|
|
|
CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_MSG(STR_A012_CAN_T_SEND_AIRCRAFT_TO)
|
|
|
|
},
|
|
|
|
{ // VCT_CMD_CLONE_VEH
|
|
|
|
CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE),
|
|
|
|
CMD_CLONE_VEHICLE | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE),
|
|
|
|
CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP),
|
|
|
|
CMD_CLONE_VEHICLE | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT)
|
|
|
|
},
|
|
|
|
{ // VCT_CMD_TURN_AROUND
|
|
|
|
CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_8869_CAN_T_REVERSE_DIRECTION),
|
|
|
|
CMD_TURN_ROADVEH | CMD_MSG(STR_9033_CAN_T_MAKE_VEHICLE_TURN),
|
|
|
|
0xffffffff, // invalid for ships
|
|
|
|
0xffffffff // invalid for aircrafts
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Window event hook for vehicle view. */
|
|
|
|
static void VehicleViewWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->event) {
|
|
|
|
case WE_CREATE:
|
|
|
|
CreateVehicleViewWindow(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_PAINT:
|
|
|
|
DrawVehicleViewWindow(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_CLICK: {
|
|
|
|
const Vehicle *v = GetVehicle(w->window_number);
|
|
|
|
|
|
|
|
switch (e->we.click.widget) {
|
|
|
|
case VVW_WIDGET_START_STOP_VEH: /* start stop */
|
|
|
|
DoCommandP(v->tile, v->index, 0, NULL,
|
|
|
|
_vehicle_command_translation_table[VCT_CMD_START_STOP][v->type]);
|
|
|
|
break;
|
|
|
|
case VVW_WIDGET_CENTER_MAIN_VIEH: /* center main view */
|
|
|
|
ScrollMainWindowTo(v->x_pos, v->y_pos);
|
|
|
|
break;
|
|
|
|
case VVW_WIDGET_GOTO_DEPOT: /* goto hangar */
|
|
|
|
DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL,
|
|
|
|
_vehicle_command_translation_table[VCT_CMD_GOTO_DEPOT][v->type]);
|
|
|
|
break;
|
|
|
|
case VVW_WIDGET_REFIT_VEH: /* refit */
|
|
|
|
ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID);
|
|
|
|
break;
|
|
|
|
case VVW_WIDGET_SHOW_ORDERS: /* show orders */
|
|
|
|
ShowOrdersWindow(v);
|
|
|
|
break;
|
|
|
|
case VVW_WIDGET_SHOW_DETAILS: /* show details */
|
|
|
|
ShowVehicleDetailsWindow(v);
|
|
|
|
break;
|
|
|
|
case VVW_WIDGET_CLONE_VEH: /* clone vehicle */
|
|
|
|
DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneVehicle,
|
|
|
|
_vehicle_command_translation_table[VCT_CMD_CLONE_VEH][v->type]);
|
|
|
|
break;
|
|
|
|
case VVW_WIDGET_TURN_AROUND: /* turn around */
|
|
|
|
assert(v->type == VEH_TRAIN || v->type == VEH_ROAD);
|
|
|
|
DoCommandP(v->tile, v->index, 0, NULL,
|
|
|
|
_vehicle_command_translation_table[VCT_CMD_TURN_AROUND][v->type]);
|
|
|
|
break;
|
|
|
|
case VVW_WIDGET_FORCE_PROCEED: /* force proceed */
|
|
|
|
assert(v->type == VEH_TRAIN);
|
|
|
|
DoCommandP(v->tile, v->index, 0, NULL, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_8862_CAN_T_MAKE_TRAIN_PASS_SIGNAL));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_RESIZE:
|
|
|
|
w->viewport->width += e->we.sizing.diff.x;
|
|
|
|
w->viewport->height += e->we.sizing.diff.y;
|
|
|
|
w->viewport->virtual_width += e->we.sizing.diff.x;
|
|
|
|
w->viewport->virtual_height += e->we.sizing.diff.y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_DESTROY:
|
|
|
|
DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
|
|
|
|
DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
|
|
|
|
DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
|
|
|
|
DeleteWindowById(WC_VEHICLE_TIMETABLE, w->window_number);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_MOUSELOOP: {
|
|
|
|
const Vehicle *v = GetVehicle(w->window_number);
|
2007-08-29 21:49:08 +00:00
|
|
|
bool veh_stopped = v->IsStoppedInDepot();
|
2007-08-29 20:50:58 +00:00
|
|
|
|
|
|
|
/* Widget VVW_WIDGET_GOTO_DEPOT must be hidden if the vehicle is already
|
|
|
|
* stopped in depot.
|
|
|
|
* Widget VVW_WIDGET_CLONE_VEH should then be shown, since cloning is
|
|
|
|
* allowed only while in depot and stopped.
|
|
|
|
* This sytem allows to have two buttons, on top of each other.
|
|
|
|
* The same system applies to widget VVW_WIDGET_REFIT_VEH and VVW_WIDGET_TURN_AROUND.*/
|
|
|
|
if (veh_stopped != IsWindowWidgetHidden(w, VVW_WIDGET_GOTO_DEPOT) || veh_stopped == IsWindowWidgetHidden(w, VVW_WIDGET_CLONE_VEH)) {
|
|
|
|
SetWindowWidgetHiddenState(w, VVW_WIDGET_GOTO_DEPOT, veh_stopped); // send to depot
|
|
|
|
SetWindowWidgetHiddenState(w, VVW_WIDGET_CLONE_VEH, !veh_stopped); // clone
|
|
|
|
if (v->type == VEH_ROAD || v->type == VEH_TRAIN) {
|
|
|
|
SetWindowWidgetHiddenState(w, VVW_WIDGET_REFIT_VEH, !veh_stopped); // refit
|
|
|
|
SetWindowWidgetHiddenState(w, VVW_WIDGET_TURN_AROUND, veh_stopped); // force turn around
|
|
|
|
}
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|