roadveh_gui.c
author truelight
Tue, 22 Aug 2006 15:39:22 +0000
changeset 4347 38fc1b161e89
parent 4345 1da147230c79
child 4389 18d6ccfb5335
permissions -rw-r--r--
(svn r6048) -Codechange: all InitializeXXX are plural, just not Depot
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1820
diff changeset
     4
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1294
diff changeset
     5
#include "debug.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     6
#include "functions.h"
3959
48f178431701 (svn r5118) Add IsRoadVehInDepot{Stopped,}()
tron
parents: 3948
diff changeset
     7
#include "roadveh.h"
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1907
diff changeset
     8
#include "table/sprites.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 374
diff changeset
     9
#include "table/strings.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 671
diff changeset
    10
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "gui.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "engine.h"
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
    20
#include "depot.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2113
diff changeset
    21
#include "vehicle_gui.h"
2962
f0a49b646c48 (svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents: 2958
diff changeset
    22
#include "newgrf_engine.h"
4261
28670f743746 (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4243
diff changeset
    23
#include "date.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    25
/**
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    26
 * Draw the purchase info details of road vehicle at a given location.
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    27
 * @param x,y location where to draw the info
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    28
 * @param engine_number the engine of which to draw the info of
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    29
 */
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    30
void DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number)
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    31
{
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    32
	const RoadVehicleInfo *rvi = RoadVehInfo(engine_number);
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
    33
	const Engine *e = GetEngine(engine_number);
3990
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    34
	bool refittable = (_engine_info[engine_number].refit_mask != 0);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    35
	YearMonthDay ymd;
4288
393de75451b1 (svn r5918) -Cleanup: rename ConvertDayToYMD/ConvertYMDToDay as they really convert a Date to/from a YearMonthDay.
rubidium
parents: 4286
diff changeset
    36
	ConvertDateToYMD(e->intro_date, &ymd);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    37
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    38
	/* Purchase cost - Max speed */
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    39
	SetDParam(0, rvi->base_cost * (_price.roadveh_base>>3)>>5);
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3431
diff changeset
    40
	SetDParam(1, rvi->max_speed / 2);
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    41
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    42
	y += 10;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    43
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    44
	/* Running cost */
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    45
	SetDParam(0, rvi->running_cost * _price.roadveh_running >> 8);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    46
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    47
	y += 10;
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    48
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    49
	/* Cargo type + capacity */
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 1986
diff changeset
    50
	SetDParam(0, _cargoc.names_long[rvi->cargo_type]);
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    51
	SetDParam(1, rvi->capacity);
3990
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    52
	SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    53
	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    54
	y += 10;
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    55
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    56
	/* Design date - Life length */
4293
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4288
diff changeset
    57
	SetDParam(0, ymd.year);
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    58
	SetDParam(1, e->lifelength);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    59
	DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    60
	y += 10;
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    61
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    62
	/* Reliability */
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    63
	SetDParam(0, e->reliability * 100 >> 16);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    64
	DrawString(x, y, STR_PURCHASE_INFO_RELIABILITY, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    65
	y += 10;
4243
b0361faa4dfd (svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents: 4171
diff changeset
    66
b0361faa4dfd (svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents: 4171
diff changeset
    67
	/* Additional text from NewGRF */
b0361faa4dfd (svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents: 4171
diff changeset
    68
	// XXX 227 will become a calculated width...
b0361faa4dfd (svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents: 4171
diff changeset
    69
	y += ShowAdditionalText(x, y, 227, engine_number);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    70
}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    71
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
    72
static void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
{
3049
d6109b5fd55d (svn r3631) - 2cc: Remove use of some temporary variables and perform minor optimization in the form of the ternary operator.
peter1138
parents: 3040
diff changeset
    74
	PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3049
diff changeset
    75
	DrawSprite(GetRoadVehImage(v, DIR_W) | pal, x + 14, y + 6);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	if (v->index == selection) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    78
		DrawFrameRect(x - 1, y - 1, x + 28, y + 12, 15, FR_BORDERONLY);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
3990
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    82
static void RoadVehRefitWndProc(Window *w, WindowEvent *e)
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    83
{
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    84
	switch (e->event) {
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    85
		case WE_PAINT: {
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    86
			const Vehicle *v = GetVehicle(w->window_number);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    87
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    88
			SetDParam(0, v->string_id);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    89
			SetDParam(1, v->unitnumber);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    90
			DrawWindowWidgets(w);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    91
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    92
			WP(w,refit_d).cargo = DrawVehicleRefitWindow(v, WP(w,refit_d).sel);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    93
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    94
			if (WP(w,refit_d).cargo != CT_INVALID) {
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    95
				int32 cost = DoCommand(v->tile, v->index, WP(w,refit_d).cargo, DC_QUERY_COST, CMD_REFIT_ROAD_VEH);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    96
				if (!CmdFailed(cost)) {
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    97
					SetDParam(0, _cargoc.names_long[WP(w,refit_d).cargo]);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    98
					SetDParam(1, _returned_refit_capacity);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
    99
					SetDParam(2, cost);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   100
					DrawString(1, 137, STR_9840_NEW_CAPACITY_COST_OF_REFIT, 0);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   101
				}
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   102
			}
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   103
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   104
			break;
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   105
		}
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   106
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   107
		case WE_CLICK:
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   108
			switch (e->click.widget) {
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   109
				case 2: { /* List box */
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   110
					int y = e->click.pt.y - 25;
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   111
					if (y >= 0) {
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   112
						WP(w,refit_d).sel = y / 10;
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   113
						SetWindowDirty(w);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   114
					}
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   115
					break;
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   116
				}
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   117
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   118
				case 4: /* Refit button */
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   119
					if (WP(w,refit_d).cargo != CT_INVALID) {
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   120
						const Vehicle *v = GetVehicle(w->window_number);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   121
						if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_ROAD_VEH | CMD_MSG(STR_REFIT_ROAD_VEHICLE_CAN_T)))
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   122
							DeleteWindow(w);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   123
					}
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   124
					break;
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   125
			}
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   126
			break;
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   127
	}
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   128
}
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   129
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   130
static const Widget _road_veh_refit_widgets[] = {
4345
1da147230c79 (svn r6046) CodeChange : Rename WWT_5 Widget type to WWT_LABEL : a centered label
belugas
parents: 4344
diff changeset
   131
{   WWT_CLOSEBOX, RESIZE_NONE, 14,  0,  10,   0,  13, STR_00C5,                            STR_018B_CLOSE_WINDOW },
1da147230c79 (svn r6046) CodeChange : Rename WWT_5 Widget type to WWT_LABEL : a centered label
belugas
parents: 4344
diff changeset
   132
{    WWT_CAPTION, RESIZE_NONE, 14, 11, 239,   0,  13, STR_983B_REFIT,                      STR_018C_WINDOW_TITLE_DRAG_THIS },
1da147230c79 (svn r6046) CodeChange : Rename WWT_5 Widget type to WWT_LABEL : a centered label
belugas
parents: 4344
diff changeset
   133
{     WWT_IMGBTN, RESIZE_NONE, 14,  0, 239,  14, 135, 0x0,                                 STR_983D_SELECT_TYPE_OF_CARGO_FOR },
1da147230c79 (svn r6046) CodeChange : Rename WWT_5 Widget type to WWT_LABEL : a centered label
belugas
parents: 4344
diff changeset
   134
{     WWT_IMGBTN, RESIZE_NONE, 14,  0, 239, 136, 157, 0x0,                                 STR_NULL },
1da147230c79 (svn r6046) CodeChange : Rename WWT_5 Widget type to WWT_LABEL : a centered label
belugas
parents: 4344
diff changeset
   135
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14,  0, 239, 158, 169, STR_REFIT_ROAD_VEHICLE,              STR_REFIT_ROAD_VEHICLE_TO_CARRY_HIGHLIGHTED },
1da147230c79 (svn r6046) CodeChange : Rename WWT_5 Widget type to WWT_LABEL : a centered label
belugas
parents: 4344
diff changeset
   136
{      WWT_LABEL, RESIZE_NONE,  0,  0, 239,  13,  26, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, STR_NULL},
3990
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   137
{    WIDGETS_END },
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   138
};
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   139
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   140
static const WindowDesc _road_veh_refit_desc = {
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   141
	-1, -1, 240, 170,
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   142
	WC_VEHICLE_REFIT, WC_VEHICLE_VIEW,
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   143
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   144
	_road_veh_refit_widgets,
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   145
	RoadVehRefitWndProc,
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   146
};
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   147
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   148
static void ShowRoadVehRefitWindow(const Vehicle *v)
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   149
{
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   150
	Window *w;
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   151
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   152
	DeleteWindowById(WC_VEHICLE_REFIT, v->index);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   153
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   154
	_alloc_wnd_parent_num = v->index;
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   155
	w = AllocateWindowDesc(&_road_veh_refit_desc);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   156
	w->window_number = v->index;
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   157
	w->caption_color = v->owner;
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   158
	WP(w,refit_d).sel = -1;
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   159
}
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   160
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
static void RoadVehDetailsWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
{
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   163
	switch (e->event) {
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   164
	case WE_PAINT: {
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   165
		const Vehicle *v = GetVehicle(w->window_number);
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   166
		StringID str;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
		w->disabled_state = v->owner == _local_player ? 0 : (1 << 2);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   169
		// disable service-scroller when interval is set to disabled
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   170
		if (!_patches.servint_roadveh) w->disabled_state |= (1 << 5) | (1 << 6);
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 10
diff changeset
   171
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   172
		SetDParam(0, v->string_id);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   173
		SetDParam(1, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
		/* Draw running cost */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
			int year = v->age / 366;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   180
			SetDParam(1, year);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   181
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2252
diff changeset
   182
			SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   183
			SetDParam(2, v->max_age / 366);
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   184
			SetDParam(3, RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running >> 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
			DrawString(2, 15, STR_900D_AGE_RUNNING_COST_YR, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
		/* Draw max speed */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
		{
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3431
diff changeset
   190
			SetDParam(0, v->max_speed / 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
			DrawString(2, 25, STR_900E_MAX_SPEED, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
		/* Draw profit */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
		{
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   196
			SetDParam(0, v->profit_this_year);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   197
			SetDParam(1, v->profit_last_year);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
			DrawString(2, 35, STR_900F_PROFIT_THIS_YEAR_LAST_YEAR, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
		/* Draw breakdown & reliability */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
		{
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   203
			SetDParam(0, v->reliability * 100 >> 16);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   204
			SetDParam(1, v->breakdowns_since_last_service);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
			DrawString(2, 45, STR_9010_RELIABILITY_BREAKDOWNS, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
		/* Draw service interval text */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
		{
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   210
			SetDParam(0, v->service_interval);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   211
			SetDParam(1, v->date_of_last_service);
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 10
diff changeset
   212
			DrawString(13, 90, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
		DrawRoadVehImage(v, 3, 57, INVALID_VEHICLE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   217
		SetDParam(0, GetCustomEngineName(v->engine_type));
4329
0e6e689f66e7 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4299
diff changeset
   218
		SetDParam(1, v->build_year);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   219
		SetDParam(2, v->value);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
		DrawString(34, 57, STR_9011_BUILT_VALUE, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   221
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 1986
diff changeset
   222
		SetDParam(0, _cargoc.names_long[v->cargo_type]);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   223
		SetDParam(1, v->cargo_cap);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
		DrawString(34, 67, STR_9012_CAPACITY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
		str = STR_8812_EMPTY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
		if (v->cargo_count != 0) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   228
			SetDParam(0, v->cargo_type);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   229
			SetDParam(1, v->cargo_count);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   230
			SetDParam(2, v->cargo_source);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
			str = STR_8813_FROM;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
		DrawString(34, 78, str, 0);
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   234
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   236
	case WE_CLICK: {
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   237
		int mod;
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   238
		const Vehicle *v;
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   239
		switch (e->click.widget) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
		case 2: /* rename */
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   241
			v = GetVehicle(w->window_number);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   242
			SetDParam(0, v->unitnumber);
4299
91f5d2bedcff (svn r5944) -Merge TGP (r5578, r5579, r5724, r5726): -Feature: filter for textboxes to only
truelight
parents: 4293
diff changeset
   243
			ShowQueryString(v->string_id, STR_902C_NAME_ROAD_VEHICLE, 31, 150, w->window_class, w->window_number, CS_ALPHANUMERAL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
		case 5: /* increase int */
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 10
diff changeset
   247
			mod = _ctrl_pressed? 5 : 10;
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   248
			goto do_change_service_int;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
		case 6: /* decrease int */
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 10
diff changeset
   250
			mod = _ctrl_pressed? -5 : -10;
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   251
do_change_service_int:
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   252
			v = GetVehicle(w->window_number);
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 10
diff changeset
   253
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   254
			mod = GetServiceIntervalClamped(mod + v->service_interval);
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   255
			if (mod == v->service_interval) return;
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 10
diff changeset
   256
2819
f25fb6ee397f (svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents: 2806
diff changeset
   257
			DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
		}
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   260
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
	case WE_ON_EDIT_TEXT: {
1820
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1790
diff changeset
   263
		if (e->edittext.str[0] != '\0') {
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1790
diff changeset
   264
			_cmd_text = e->edittext.str;
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1790
diff changeset
   265
			DoCommandP(0, w->window_number, 0, NULL,
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1790
diff changeset
   266
				CMD_NAME_VEHICLE | CMD_MSG(STR_902D_CAN_T_NAME_ROAD_VEHICLE));
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1790
diff changeset
   267
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
static const Widget _roadveh_details_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   274
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   275
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   339,     0,    13, STR_900C_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   276
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   340,   379,     0,    13, STR_01AA_NAME,    STR_902E_NAME_ROAD_VEHICLE},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   277
{     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   379,    14,    55, 0x0,              STR_NULL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   278
{     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   379,    56,    88, 0x0,              STR_NULL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   279
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    10,    89,    94, STR_0188,         STR_884D_INCREASE_SERVICING_INTERVAL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   280
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    10,    95,   100, STR_0189,         STR_884E_DECREASE_SERVICING_INTERVAL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   281
{     WWT_IMGBTN,   RESIZE_NONE,    14,    11,   379,    89,   100, 0x0,              STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   282
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
static const WindowDesc _roadveh_details_desc = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
	-1,-1, 380, 101,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
	WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	_roadveh_details_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
	RoadVehDetailsWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   293
static void ShowRoadVehDetailsWindow(const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	VehicleID veh = v->index;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   297
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
	DeleteWindowById(WC_VEHICLE_DETAILS, veh);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   300
	_alloc_wnd_parent_num = veh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	w = AllocateWindowDesc(&_roadveh_details_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
	w->window_number = veh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	w->caption_color = v->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
3887
ece644bbf459 (svn r4943) uint tile -> TileIndex tile, byte player -> PlayerID player
tron
parents: 3884
diff changeset
   306
void CcCloneRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2)
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   307
{
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3887
diff changeset
   308
	if (success) ShowRoadVehViewWindow(GetVehicle(_new_vehicle_id));
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   309
}
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   310
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
static void RoadVehViewWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
{
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
   313
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
	case WE_PAINT: {
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   315
		Vehicle *v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
		StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
3990
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   318
		w->disabled_state = (v->owner != _local_player) ? (1 << 8 | 1 << 7 | 1 << 12) : 0;
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   319
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   320
		/* Disable refit button if vehicle not refittable */
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   321
		if (_engine_info[v->engine_type].refit_mask == 0) SETBIT(w->disabled_state, 12);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
		/* draw widgets & caption */
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   324
		SetDParam(0, v->string_id);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   325
		SetDParam(1, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
		if (v->u.road.crashed_ctr != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
			str = STR_8863_CRASHED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
		} else if (v->breakdown_ctr == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
			str = STR_885C_BROKEN_DOWN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
		} else if (v->vehstatus & VS_STOPPED) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
			str = STR_8861_STOPPED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
		} else {
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
   335
			switch (v->current_order.type) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
			case OT_GOTO_STATION: {
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
   337
				SetDParam(0, v->current_order.station);
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3431
diff changeset
   338
				SetDParam(1, v->cur_speed / 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
				str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
			case OT_GOTO_DEPOT: {
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   343
				Depot *depot = GetDepot(v->current_order.station);
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   344
				SetDParam(0, depot->town_index);
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3431
diff changeset
   345
				SetDParam(1, v->cur_speed / 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
				str = STR_HEADING_FOR_ROAD_DEPOT + _patches.vehicle_speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
			case OT_LOADING:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
			case OT_LEAVESTATION:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
				str = STR_882F_LOADING_UNLOADING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
			default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
				if (v->num_orders == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
					str = STR_NO_ORDERS + _patches.vehicle_speed;
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3431
diff changeset
   357
					SetDParam(0, v->cur_speed / 2);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   358
				} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
					str = STR_EMPTY;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   360
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
2103
a2b3106d33d5 (svn r2613) - Truncate savegames, and vehicle-texts in their window.
Darkvater
parents: 2084
diff changeset
   365
		/* draw the flag plus orders */
2517
6e3832ddd0f6 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2498
diff changeset
   366
		DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, 2, w->widget[5].top + 1);
2113
be2f07df0dfa (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2103
diff changeset
   367
		DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
		DrawWindowViewport(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
	} break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   370
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
	case WE_CLICK: {
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   372
		const Vehicle *v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   374
		switch (e->click.widget) {
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   375
		case 5: /* start stop */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   376
			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_ROADVEH | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   378
		case 6: /* center main view */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
			ScrollMainWindowTo(v->x_pos, v->y_pos);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
			break;
3990
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   381
		case 7: /* goto depot */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
			DoCommandP(v->tile, v->index, 0, NULL, CMD_SEND_ROADVEH_TO_DEPOT | CMD_MSG(STR_9018_CAN_T_SEND_VEHICLE_TO_DEPOT));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   384
		case 8: /* turn around */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
			DoCommandP(v->tile, v->index, 0, NULL, CMD_TURN_ROADVEH | CMD_MSG(STR_9033_CAN_T_MAKE_VEHICLE_TURN));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   387
		case 9: /* show orders */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
			ShowOrdersWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   390
		case 10: /* show details */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
			ShowRoadVehDetailsWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
			break;
3990
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   393
		case 11: /* clone vehicle */
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   394
			DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneRoadVeh, CMD_CLONE_VEHICLE | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
3990
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   395
			break;
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   396
		case 12: /* Refit vehicle */
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   397
			ShowRoadVehRefitWindow(v);
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   398
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
	} break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   401
1485
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1330
diff changeset
   402
	case WE_RESIZE:
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1330
diff changeset
   403
		w->viewport->width  += e->sizing.diff.x;
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1330
diff changeset
   404
		w->viewport->height += e->sizing.diff.y;
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1330
diff changeset
   405
		w->viewport->virtual_width  += e->sizing.diff.x;
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1330
diff changeset
   406
		w->viewport->virtual_height += e->sizing.diff.y;
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1330
diff changeset
   407
		break;
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1330
diff changeset
   408
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
	case WE_DESTROY:
3990
a317e665fb77 (svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents: 3960
diff changeset
   410
		DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
		DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
		DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   413
		break;
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   414
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   415
	case WE_MOUSELOOP:
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   416
		{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   417
			const Vehicle *v = GetVehicle(w->window_number);
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3990
diff changeset
   418
			uint32 h = IsRoadVehInDepotStopped(v) ? 1 << 7 | 1 << 8 : 1 << 11 | 1 << 12;
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3990
diff changeset
   419
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   420
			if (h != w->hidden_state) {
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   421
				w->hidden_state = h;
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   422
				SetWindowDirty(w);
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   423
			}
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   424
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
static const Widget _roadveh_view_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   429
{ WWT_CLOSEBOX,   RESIZE_NONE,  14,   0,  10,   0,  13, STR_00C5,          STR_018B_CLOSE_WINDOW },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   430
{ WWT_CAPTION,    RESIZE_RIGHT, 14,  11, 237,   0,  13, STR_9002,          STR_018C_WINDOW_TITLE_DRAG_THIS },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   431
{ WWT_STICKYBOX,  RESIZE_LR,    14, 238, 249,   0,  13, 0x0,               STR_STICKY_BUTTON },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   432
{ WWT_IMGBTN,     RESIZE_RB,    14,   0, 231,  14, 103, 0x0,               STR_NULL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   433
{ WWT_6,          RESIZE_RB,    14,   2, 229,  16, 101, 0x0,               STR_NULL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   434
{ WWT_PUSHIMGBTN, RESIZE_RTB,   14,   0, 237, 104, 115, 0x0,               STR_901C_CURRENT_VEHICLE_ACTION },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   435
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  14,  31, 0x2AB,             STR_901E_CENTER_MAIN_VIEW_ON_VEHICLE },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   436
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  32,  49, 0x2AE,             STR_901F_SEND_VEHICLE_TO_DEPOT },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   437
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  50,  67, 0x2CB,             STR_9020_FORCE_VEHICLE_TO_TURN_AROUND },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   438
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  68,  85, 0x2B2,             STR_901D_SHOW_VEHICLE_S_ORDERS },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   439
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  86, 103, 0x2B3,             STR_9021_SHOW_ROAD_VEHICLE_DETAILS },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   440
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  32,  49, SPR_CLONE_ROADVEH, STR_CLONE_ROAD_VEHICLE_INFO },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   441
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  50,  67, 0x2B4,             STR_REFIT_ROAD_VEHICLE_TO_CARRY },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   442
{ WWT_PANEL,      RESIZE_LRB,   14, 232, 249, 104, 103, 0x0,               STR_NULL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   443
{ WWT_RESIZEBOX,  RESIZE_LRTB,  14, 238, 249, 104, 115, 0x0,               STR_NULL },
1485
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1330
diff changeset
   444
{ WIDGETS_END }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
static const WindowDesc _roadveh_view_desc = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
	-1,-1, 250, 116,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
	WC_VEHICLE_VIEW,0,
1485
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1330
diff changeset
   450
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
	_roadveh_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
	RoadVehViewWndProc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   455
void ShowRoadVehViewWindow(const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   457
	Window *w = AllocateWindowDescFront(&_roadveh_view_desc, v->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   459
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
		w->caption_color = v->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
		AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
static void DrawNewRoadVehWindow(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
	if (w->window_number == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
		w->disabled_state = 1 << 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
	// setup scroller
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
		int count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
		int num = NUM_ROAD_ENGINES;
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   475
		const Engine *e = GetEngine(ROAD_ENGINES_INDEX);
1926
530480d14685 (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1922
diff changeset
   476
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
			if (HASBIT(e->player_avail, _local_player))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
				count++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
		} while (++e,--num);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
		SetVScrollCount(w, count);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
	DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
		int num = NUM_ROAD_ENGINES;
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   488
		const Engine *e = GetEngine(ROAD_ENGINES_INDEX);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
		int x = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
		int y = 15;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
		int sel = WP(w,buildtrain_d).sel_index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
		int pos = w->vscroll.pos;
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2466
diff changeset
   493
		EngineID engine_id = ROAD_ENGINES_INDEX;
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2477
diff changeset
   494
		EngineID selected_id = INVALID_ENGINE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
			if (HASBIT(e->player_avail, _local_player)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
				if (sel==0) selected_id = engine_id;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   499
				if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
					DrawString(x+59, y+2, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10);
3040
7043c0de7c6d (svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents: 2962
diff changeset
   501
					DrawRoadVehEngine(x+29, y+6, engine_id, GetEnginePalette(engine_id, _local_player));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
					y += 14;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   504
				sel--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
		} while (++engine_id, ++e,--num);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
		WP(w,buildtrain_d).sel_engine = selected_id;
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2477
diff changeset
   509
		if (selected_id != INVALID_ENGINE) {
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   510
			DrawRoadVehPurchaseInfo(2, w->widget[4].top + 1, selected_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   515
void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   517
	const Vehicle *v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
	if (!success) return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3887
diff changeset
   521
	v = GetVehicle(_new_vehicle_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
	if (v->tile == _backup_orders_tile) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
		_backup_orders_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
		RestoreVehicleOrders(v, _backup_orders_data);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
	ShowRoadVehViewWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
static void NewRoadVehWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   531
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
	case WE_PAINT:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
		DrawNewRoadVehWindow(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
	case WE_CLICK:
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
   537
		switch (e->click.widget) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
		case 2: { /* listbox */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
			uint i = (e->click.pt.y - 14) / 14;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   540
			if (i < w->vscroll.cap) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
				WP(w,buildtrain_d).sel_index = i + w->vscroll.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
				SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
		case 5: { /* build */
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2477
diff changeset
   547
			EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2477
diff changeset
   548
			if (sel_eng != INVALID_ENGINE)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
				DoCommandP(w->window_number, sel_eng, 0, CcBuildRoadVeh, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
968
84a870c7a585 (svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents: 919
diff changeset
   552
		case 6: { /* rename */
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2477
diff changeset
   553
			EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2477
diff changeset
   554
			if (sel_eng != INVALID_ENGINE) {
968
84a870c7a585 (svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents: 919
diff changeset
   555
				WP(w,buildtrain_d).rename_engine = sel_eng;
84a870c7a585 (svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents: 919
diff changeset
   556
				ShowQueryString(GetCustomEngineName(sel_eng),
4299
91f5d2bedcff (svn r5944) -Merge TGP (r5578, r5579, r5724, r5726): -Feature: filter for textboxes to only
truelight
parents: 4293
diff changeset
   557
					STR_9036_RENAME_ROAD_VEHICLE_TYPE, 31, 160, w->window_class, w->window_number, CS_ALPHANUMERAL);
968
84a870c7a585 (svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents: 919
diff changeset
   558
			}
84a870c7a585 (svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents: 919
diff changeset
   559
		}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2517
diff changeset
   563
	case WE_ON_EDIT_TEXT:
1820
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1790
diff changeset
   564
		if (e->edittext.str[0] != '\0') {
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1790
diff changeset
   565
			_cmd_text = e->edittext.str;
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1790
diff changeset
   566
			DoCommandP(0, WP(w, buildtrain_d).rename_engine, 0, NULL,
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1790
diff changeset
   567
				CMD_RENAME_ENGINE | CMD_MSG(STR_9037_CAN_T_RENAME_ROAD_VEHICLE));
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1790
diff changeset
   568
		}
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2517
diff changeset
   569
		break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   570
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   571
	case WE_RESIZE: {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   572
		if (e->sizing.diff.y == 0) break;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   573
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   574
		w->vscroll.cap += e->sizing.diff.y / 14;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   575
		w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   576
	} break;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   577
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   578
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
static const Widget _new_road_veh_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   582
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                   STR_018B_CLOSE_WINDOW},
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   583
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   247,     0,    13, STR_9006_NEW_ROAD_VEHICLES, STR_018C_WINDOW_TITLE_DRAG_THIS},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   584
{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   235,    14,   125, 0x801,                      STR_9026_ROAD_VEHICLE_SELECTION},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   585
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   236,   247,    14,   125, 0x0,                        STR_0190_SCROLL_BAR_SCROLLS_LIST},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   586
{     WWT_IMGBTN,     RESIZE_TB,    14,     0,   247,   126,   197, 0x0,                        STR_NULL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   587
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   117,   198,   209, STR_9007_BUILD_VEHICLE,     STR_9027_BUILD_THE_HIGHLIGHTED_ROAD},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   588
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   118,   235,   198,   209, STR_9034_RENAME,            STR_9035_RENAME_ROAD_VEHICLE_TYPE},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   589
{  WWT_RESIZEBOX,     RESIZE_TB,    14,   236,   247,   198,   209, 0x0,                        STR_RESIZE_BUTTON},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   590
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
static const WindowDesc _new_road_veh_desc = {
4243
b0361faa4dfd (svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents: 4171
diff changeset
   594
	-1, -1, 248, 210,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
	WC_BUILD_VEHICLE,0,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   596
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
	_new_road_veh_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
	NewRoadVehWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
static void ShowBuildRoadVehWindow(TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
	DeleteWindowById(WC_BUILD_VEHICLE, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
	w = AllocateWindowDesc(&_new_road_veh_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
	w->window_number = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
	w->vscroll.cap = 8;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   610
	w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   611
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   612
	w->resize.step_height = 14;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   613
	w->resize.height = w->height - 14 * 4; /* Minimum of 4 vehicles in the display */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   614
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
	if (tile != 0) {
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   616
		w->caption_color = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
		w->caption_color = _local_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
static void DrawRoadDepotWindow(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
{
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   624
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
	int num,x,y;
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   627
	Depot *depot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
	tile = w->window_number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
	/* setup disabled buttons */
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   632
	w->disabled_state =
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   633
		IsTileOwner(tile, _local_player) ? 0 : ((1<<4) | (1<<7) | (1<<8));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
	/* determine amount of items for scroller */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
	num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
	FOR_ALL_VEHICLES(v) {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   638
		if (v->type == VEH_Road && IsRoadVehInDepot(v) && v->tile == tile) num++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
	}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   640
	SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
	/* locate the depot struct */
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   643
	depot = GetDepotByTile(tile);
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   644
	assert(depot != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   646
	SetDParam(0, depot->town_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
	DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
	x = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
	y = 15;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   651
	num = w->vscroll.pos * w->hscroll.cap;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
	FOR_ALL_VEHICLES(v) {
3959
48f178431701 (svn r5118) Add IsRoadVehInDepot{Stopped,}()
tron
parents: 3948
diff changeset
   654
		if (v->type == VEH_Road && IsRoadVehInDepot(v) && v->tile == tile &&
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   655
				--num < 0 && num >=	-w->vscroll.cap * w->hscroll.cap) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
			DrawRoadVehImage(v, x+24, y, WP(w,traindepot_d).sel);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   657
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   658
			SetDParam(0, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
			DrawString(x, y+2, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
2517
6e3832ddd0f6 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2498
diff changeset
   661
			DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, x + 16, y);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   662
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   663
			if ((x+=56) == 2 + 56 * w->hscroll.cap) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
				x = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
				y += 14;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2406
diff changeset
   671
static int GetVehicleFromRoadDepotWndPt(const Window *w, int x, int y, Vehicle **veh)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
{
969
862685f513ca (svn r1464) -Fix: [1099106] Resizeable portion of bus/air/rail depots window unclickable
darkvater
parents: 968
diff changeset
   673
	uint xt,row,xm;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
	TileIndex tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
	int pos;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   677
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
	xt = x / 56;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
	xm = x % 56;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   680
	if (xt >= w->hscroll.cap) return 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
969
862685f513ca (svn r1464) -Fix: [1099106] Resizeable portion of bus/air/rail depots window unclickable
darkvater
parents: 968
diff changeset
   682
	row = (y - 14) / 14;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   683
	if (row >= w->vscroll.cap) return 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
971
374251680a61 (svn r1466) -Fix: oops, depot windows can of course also scroll horizontally. Thanks si-m1.
darkvater
parents: 969
diff changeset
   685
	pos = (row + w->vscroll.pos) * w->hscroll.cap + xt;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
	tile = w->window_number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
	FOR_ALL_VEHICLES(v) {
3959
48f178431701 (svn r5118) Add IsRoadVehInDepot{Stopped,}()
tron
parents: 3948
diff changeset
   689
		if (v->type == VEH_Road && IsRoadVehInDepot(v) && v->tile == tile &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
				--pos < 0) {
1986
fcc849a38ae6 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1977
diff changeset
   691
			*veh = v;
fcc849a38ae6 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1977
diff changeset
   692
			if (xm >= 24) return 0;
fcc849a38ae6 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1977
diff changeset
   693
			if (xm <= 16) return -1; /* show window */
fcc849a38ae6 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1977
diff changeset
   694
			return -2; /* start stop */
fcc849a38ae6 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1977
diff changeset
   695
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	return 1; /* outside */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
static void RoadDepotClickVeh(Window *w, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
	Vehicle *v;
10
c35ab8426202 (svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents: 0
diff changeset
   704
	int mode;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
10
c35ab8426202 (svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents: 0
diff changeset
   706
	mode = GetVehicleFromRoadDepotWndPt(w, x, y, &v);
c35ab8426202 (svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents: 0
diff changeset
   707
	if (mode > 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
10
c35ab8426202 (svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents: 0
diff changeset
   709
	// share / copy orders
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   710
	if (_thd.place_mode && mode <= 0) {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   711
		_place_clicked_vehicle = v;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   712
		return;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   713
	}
10
c35ab8426202 (svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents: 0
diff changeset
   714
c35ab8426202 (svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents: 0
diff changeset
   715
	switch (mode) {
c35ab8426202 (svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents: 0
diff changeset
   716
	case 0: // start dragging of vehicle
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
		if (v != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
			WP(w,traindepot_d).sel = v->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
			SetWindowDirty(w);
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3049
diff changeset
   720
			SetObjectToPlaceWnd(GetVehiclePalette(v) | GetRoadVehImage(v, DIR_W), 4, w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
10
c35ab8426202 (svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents: 0
diff changeset
   724
	case -1: // show info window
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
		ShowRoadVehViewWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
10
c35ab8426202 (svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents: 0
diff changeset
   728
	case -2: // click start/stop flag
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
		DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_ROADVEH | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
	default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
		NOT_REACHED();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   737
/**
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   738
 * Clones a road vehicle
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   739
 * @param *v is the original vehicle to clone
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   740
 * @param *w is the window of the depot where the clone is build
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   741
 */
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   742
static void HandleCloneVehClick(const Vehicle *v, const Window *w)
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   743
{
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   744
	if (v == NULL || v->type != VEH_Road) return;
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   745
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   746
	DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneRoadVeh,
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   747
		CMD_CLONE_VEHICLE | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE)
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   748
	);
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   749
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   750
	ResetObjectToPlace();
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   751
}
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   752
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   753
static void ClonePlaceObj(const Window *w)
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   754
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   755
	const Vehicle *v = CheckMouseOverVehicle();
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   756
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   757
	if (v != NULL) HandleCloneVehClick(v, w);
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   758
}
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   759
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
static void RoadDepotWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
{
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
   762
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
	case WE_PAINT:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
		DrawRoadDepotWindow(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
	case WE_CLICK: {
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
   768
		switch (e->click.widget) {
982
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 971
diff changeset
   769
		case 5:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
			RoadDepotClickVeh(w, e->click.pt.x, e->click.pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
			break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   772
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   773
		case 7:
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   774
			ResetObjectToPlace();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
			ShowBuildRoadVehWindow(w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
			break;
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2252
diff changeset
   777
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   778
		case 8: /* clone button */
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   779
			InvalidateWidget(w, 8);
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   780
				TOGGLEBIT(w->click_state, 8);
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2252
diff changeset
   781
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   782
				if (HASBIT(w->click_state, 8)) {
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   783
					_place_clicked_vehicle = NULL;
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   784
					SetObjectToPlaceWnd(SPR_CURSOR_CLONE, VHM_RECT, w);
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   785
				} else {
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   786
					ResetObjectToPlace();
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   787
				}
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   788
					break;
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2252
diff changeset
   789
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   790
			case 9: /* scroll to tile */
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   791
				ResetObjectToPlace();
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   792
				ScrollMainWindowToTile(w->window_number);
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   793
					break;
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   794
		}
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   795
	} break;
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2252
diff changeset
   796
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   797
	case WE_PLACE_OBJ:
2958
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
   798
		ClonePlaceObj(w);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   799
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   801
	case WE_ABORT_PLACE_OBJ:
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   802
		CLRBIT(w->click_state, 8);
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   803
		InvalidateWidget(w, 8);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   804
		break;
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2252
diff changeset
   805
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   806
	// check if a vehicle in a depot was clicked..
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   807
	case WE_MOUSELOOP: {
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   808
		const Vehicle *v = _place_clicked_vehicle;
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   809
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   810
		// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   811
		if (v != NULL && HASBIT(w->click_state, 8)) {
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   812
			_place_clicked_vehicle = NULL;
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   813
			HandleCloneVehClick(v, w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
	} break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   816
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
	case WE_DESTROY:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
		DeleteWindowById(WC_BUILD_VEHICLE, w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
2755
ba133949851b (svn r3300) Remove unreachable code - in this case some duplicate breaks
tron
parents: 2725
diff changeset
   821
	case WE_DRAGDROP:
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
   822
		switch (e->click.widget) {
982
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 971
diff changeset
   823
		case 5: {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
			Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
			VehicleID sel = WP(w,traindepot_d).sel;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
			WP(w,traindepot_d).sel = INVALID_VEHICLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
			if (GetVehicleFromRoadDepotWndPt(w, e->dragdrop.pt.x, e->dragdrop.pt.y, &v) == 0 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
					v != NULL &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
					sel == v->index) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
				ShowRoadVehViewWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
		} break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   836
982
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 971
diff changeset
   837
		case 4:
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 971
diff changeset
   838
			if (!HASBIT(w->disabled_state, 4) &&
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   839
					WP(w,traindepot_d).sel != INVALID_VEHICLE) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
				Vehicle *v;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   841
982
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 971
diff changeset
   842
				HandleButtonClick(w, 4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   844
				v = GetVehicle(WP(w,traindepot_d).sel);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
				WP(w,traindepot_d).sel = INVALID_VEHICLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
				_backup_orders_tile = v->tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
				BackupVehicleOrders(v, _backup_orders_data);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   849
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
				if (!DoCommandP(v->tile, v->index, 0, NULL, CMD_SELL_ROAD_VEH | CMD_MSG(STR_9014_CAN_T_SELL_ROAD_VEHICLE)))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
					_backup_orders_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
			break;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   854
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
		default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
			WP(w,traindepot_d).sel = INVALID_VEHICLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   861
	case WE_RESIZE:
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   862
		/* Update the scroll + matrix */
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   863
		w->vscroll.cap += e->sizing.diff.y / 14;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   864
		w->hscroll.cap += e->sizing.diff.x / 56;
982
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 971
diff changeset
   865
		w->widget[5].unkA = (w->vscroll.cap << 8) + w->hscroll.cap;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   866
		break;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   867
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
static const Widget _road_depot_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   872
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   873
{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   302,     0,    13, STR_9003_ROAD_VEHICLE_DEPOT, STR_018C_WINDOW_TITLE_DRAG_THIS},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   874
{  WWT_STICKYBOX,     RESIZE_LR,    14,   303,   314,     0,    13, 0x0,                         STR_STICKY_BUTTON},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   875
{      WWT_PANEL,    RESIZE_LRB,    14,   280,   302,    14,    13, 0x0,                         STR_NULL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   876
{     WWT_IMGBTN,   RESIZE_LRTB,    14,   280,   302,    14,    55, 0x2A9,                       STR_9024_DRAG_ROAD_VEHICLE_TO_HERE},
982
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 971
diff changeset
   877
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   878
{     WWT_MATRIX,     RESIZE_RB,    14,     0,   279,    14,    55, 0x305,                       STR_9022_VEHICLES_CLICK_ON_VEHICLE},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   879
{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   303,   314,    14,    55, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   880
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   100,    56,    67, STR_9004_NEW_VEHICLES,       STR_9023_BUILD_NEW_ROAD_VEHICLE},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   881
{WWT_NODISTXTBTN,     RESIZE_TB,    14,   101,   200,    56,    67, STR_CLONE_ROAD_VEHICLE,      STR_CLONE_ROAD_VEHICLE_DEPOT_INFO},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   882
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   201,   302,    56,    67, STR_00E4_LOCATION,           STR_9025_CENTER_MAIN_VIEW_ON_ROAD},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   883
{      WWT_PANEL,    RESIZE_RTB,    14,   303,   302,    56,    67, 0x0,                         STR_NULL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   884
{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   303,   314,    56,    67, 0x0,                         STR_RESIZE_BUTTON},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   885
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
static const WindowDesc _road_depot_desc = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
	-1, -1, 315, 68,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
	WC_VEHICLE_DEPOT,0,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   891
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
	_road_depot_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
	RoadDepotWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   896
void ShowRoadDepotWindow(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   898
	Window *w = AllocateWindowDescFront(&_road_depot_desc, tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   899
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   900
	if (w != NULL) {
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   901
		w->caption_color = GetTileOwner(w->window_number);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   902
		w->hscroll.cap = 5;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
		w->vscroll.cap = 3;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   904
		w->resize.step_width = 56;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   905
		w->resize.step_height = 14;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   906
		WP(w,traindepot_d).sel = INVALID_VEHICLE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
		_backup_orders_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   911
static const Widget _player_roadveh_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   912
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   913
{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   247,     0,    13, STR_9001_ROAD_VEHICLES, STR_018C_WINDOW_TITLE_DRAG_THIS},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   914
{  WWT_STICKYBOX,     RESIZE_LR,    14,   248,   259,     0,    13, 0x0,                    STR_STICKY_BUTTON},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   915
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,            STR_SORT_ORDER_TIP},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   916
{      WWT_PANEL,   RESIZE_NONE,    14,    81,   235,    14,    25, 0x0,                    STR_SORT_CRITERIA_TIP},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   917
{    WWT_TEXTBTN,   RESIZE_NONE,    14,   236,   247,    14,    25, STR_0225,               STR_SORT_CRITERIA_TIP},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   918
{      WWT_PANEL,  RESIZE_RIGHT,    14,   248,   259,    14,    25, 0x0,                    STR_NULL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   919
{     WWT_MATRIX,     RESIZE_RB,    14,     0,   247,    26,   207, 0x701,                  STR_901A_ROAD_VEHICLES_CLICK_ON},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   920
{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   248,   259,    26,   207, 0x0,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   921
/* only for our road list, a 'Build Vehicle' button that opens the depot of the last built depot */
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   922
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   124,   208,   219, STR_8815_NEW_VEHICLES,  STR_901B_BUILD_NEW_ROAD_VEHICLES},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   923
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   125,   247,   208,   219, STR_REPLACE_VEHICLES,   STR_REPLACE_HELP},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   924
{      WWT_PANEL,    RESIZE_RTB,    14,   248,   247,   208,   219, 0x0,                    STR_NULL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   925
{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   248,   259,   208,   219, 0x0,                    STR_RESIZE_BUTTON},
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   926
{   WIDGETS_END},
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   927
};
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
   928
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   929
static const Widget _other_player_roadveh_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   930
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   931
{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   247,     0,    13, STR_9001_ROAD_VEHICLES, STR_018C_WINDOW_TITLE_DRAG_THIS},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   932
{  WWT_STICKYBOX,     RESIZE_LR,    14,   248,   259,     0,    13, 0x0,                    STR_STICKY_BUTTON},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   933
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,            STR_SORT_ORDER_TIP},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   934
{      WWT_PANEL,   RESIZE_NONE,    14,    81,   235,    14,    25, 0x0,                    STR_SORT_CRITERIA_TIP},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   935
{    WWT_TEXTBTN,   RESIZE_NONE,    14,   236,   247,    14,    25, STR_0225,               STR_SORT_CRITERIA_TIP},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   936
{      WWT_PANEL,  RESIZE_RIGHT,    14,   248,   259,    14,    25, 0x0,                    STR_NULL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   937
{     WWT_MATRIX,     RESIZE_RB,    14,     0,   247,    26,   207, 0x701,                  STR_901A_ROAD_VEHICLES_CLICK_ON},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   938
{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   248,   259,    26,   207, 0x0,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   939
{      WWT_PANEL,    RESIZE_RTB,    14,     0,   247,   208,   219, 0x0,                    STR_NULL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   940
{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   248,   259,   208,   219, 0x0,                    STR_RESIZE_BUTTON},
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   941
{   WIDGETS_END},
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   942
};
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
   943
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
static void PlayerRoadVehWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
{
2466
1aa260b43faa (svn r2992) Use PlayerID, StationID and INVALID_STATION instead of int, int and -1
tron
parents: 2436
diff changeset
   946
	StationID station = GB(w->window_number, 16, 16);
1aa260b43faa (svn r2992) Use PlayerID, StationID and INVALID_STATION instead of int, int and -1
tron
parents: 2436
diff changeset
   947
	PlayerID owner = GB(w->window_number, 0, 8);
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   948
	vehiclelist_d *vl = &WP(w, vehiclelist_d);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   949
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
   950
	switch (e->event) {
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
   951
	case WE_PAINT: {
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   952
		int x = 2;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   953
		int y = PLY_WND_PRC__OFFSET_TOP_WIDGET;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   954
		int max;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   955
		int i;
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   956
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   957
		BuildVehicleList(vl, VEH_Road, owner, station);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   958
		SortVehicleList(vl);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   960
		SetVScrollCount(w, vl->list_length);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   961
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   962
		// disable 'Sort By' tooltip on Unsorted sorting criteria
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   963
		if (vl->sort_type == SORT_BY_UNSORTED) w->disabled_state |= (1 << 3);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   964
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
		/* draw the widgets */
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   966
		if (station == INVALID_STATION) {
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   967
			const Player *p = GetPlayer(owner);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   968
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   969
			/* Company Name -- (###) Road vehicles */
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   970
			SetDParam(0, p->name_1);
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   971
			SetDParam(1, p->name_2);
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   972
			SetDParam(2, w->vscroll.count);
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   973
			w->widget[1].unkA = STR_9001_ROAD_VEHICLES;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   974
		} else {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   975
			/* Station Name -- (###) Road vehicles */
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   976
			SetDParam(0, station);
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   977
			SetDParam(1, w->vscroll.count);
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   978
			w->widget[1].unkA = STR_SCHEDULED_ROAD_VEHICLES;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
		}
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   980
		DrawWindowWidgets(w);
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   981
		/* draw sorting criteria string */
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   982
		DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   983
		/* draw arrow pointing up/down for ascending/descending sorting */
2406
8c873205483a (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2273
diff changeset
   984
		DoDrawString(vl->flags & VL_DESC ? DOWNARROW : UPARROW, 69, 15, 0x10);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
   985
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   986
		max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   987
		for (i = w->vscroll.pos; i < max; ++i) {
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   988
			const Vehicle* v = vl->sort_list[i];
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   989
			StringID str;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
   990
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   991
			assert(v->type == VEH_Road && v->owner == owner);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   992
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   993
			DrawRoadVehImage(v, x + 22, y + 6, INVALID_VEHICLE);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   994
			DrawVehicleProfitButton(v, x, y + 13);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
   995
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   996
			SetDParam(0, v->unitnumber);
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3990
diff changeset
   997
			if (IsRoadVehInDepot(v)) {
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
   998
				str = STR_021F;
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3990
diff changeset
   999
			} else {
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1000
				str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3990
diff changeset
  1001
			}
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1002
			DrawString(x, y + 2, str, 0);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1003
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1004
			SetDParam(0, v->profit_this_year);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1005
			SetDParam(1, v->profit_last_year);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1006
			DrawString(x + 24, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1007
671
6f1d8c908156 (svn r1109) Fix c&p bug: In vehicle lists a name was displayed for road vehicles even if they had none
tron
parents: 588
diff changeset
  1008
			if (v->string_id != STR_SV_ROADVEH_NAME) {
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1009
				SetDParam(0, v->string_id);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1010
				DrawString(x + 24, y, STR_01AB, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
			}
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1012
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1013
			y += PLY_WND_PRC__SIZE_OF_ROW_SMALL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
		}
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1015
		}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1017
	case WE_CLICK: {
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  1018
		switch (e->click.widget) {
757
7bfd863750a7 (svn r1213) -Feature: Stickified vehicle lists
darkvater
parents: 755
diff changeset
  1019
		case 3: /* Flip sorting method ascending/descending */
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1020
			vl->flags ^= VL_DESC;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1021
			vl->flags |= VL_RESORT;
1246
eb66ff34348f (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1151
diff changeset
  1022
			_sorting.roadveh.order = !!(vl->flags & VL_DESC);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1023
			SetWindowDirty(w);
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1024
			break;
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1025
757
7bfd863750a7 (svn r1213) -Feature: Stickified vehicle lists
darkvater
parents: 755
diff changeset
  1026
		case 4: case 5:/* Select sorting criteria dropdown menu */
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
  1027
			ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1028
			return;
757
7bfd863750a7 (svn r1213) -Feature: Stickified vehicle lists
darkvater
parents: 755
diff changeset
  1029
		case 7: { /* Matrix to show vehicles */
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 168
diff changeset
  1030
			uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
  1031
			const Vehicle *v;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1032
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1033
			if (id_v >= w->vscroll.cap) return; // click out of bounds
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1035
			id_v += w->vscroll.pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
  1037
			if (id_v >= vl->list_length) return; // click out of list bound
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1038
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
  1039
			v	= vl->sort_list[id_v];
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1040
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
  1041
			assert(v->type == VEH_Road && v->owner == owner);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1042
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
  1043
			ShowRoadVehViewWindow(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
3884
793081f80381 (svn r4940) Remove the dubious feature of remembering the last built depot. It serves no real purpose except causing confusion
tron
parents: 3477
diff changeset
  1046
		case 9: /* Build new Vehicle */
793081f80381 (svn r4940) Remove the dubious feature of remembering the last built depot. It serves no real purpose except causing confusion
tron
parents: 3477
diff changeset
  1047
			if (!IsWindowOfPrototype(w, _player_roadveh_widgets)) break;
793081f80381 (svn r4940) Remove the dubious feature of remembering the last built depot. It serves no real purpose except causing confusion
tron
parents: 3477
diff changeset
  1048
			ShowBuildRoadVehWindow(0);
793081f80381 (svn r4940) Remove the dubious feature of remembering the last built depot. It serves no real purpose except causing confusion
tron
parents: 3477
diff changeset
  1049
			break;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1050
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
  1051
		case 10: {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
  1052
			if (!IsWindowOfPrototype(w, _player_roadveh_widgets)) break;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
  1053
			ShowReplaceVehicleWindow(VEH_Road);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
  1054
			break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
  1055
		}
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1056
		}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1057
	}	break;
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1058
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1059
	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1060
		if (vl->sort_type != e->dropdown.index) {
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1061
			// value has changed -> resort
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1062
			vl->flags |= VL_RESORT;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1063
			vl->sort_type = e->dropdown.index;
1246
eb66ff34348f (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1151
diff changeset
  1064
			_sorting.roadveh.criteria = vl->sort_type;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1065
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1066
			// enable 'Sort By' if a sorter criteria is chosen
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
  1067
			if (vl->sort_type != SORT_BY_UNSORTED) CLRBIT(w->disabled_state, 3);
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1068
		}
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1069
		SetWindowDirty(w);
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1070
		break;
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1071
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1072
	case WE_CREATE: /* set up resort timer */
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1073
		vl->sort_list = NULL;
1246
eb66ff34348f (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1151
diff changeset
  1074
		vl->flags = VL_REBUILD | (_sorting.roadveh.order << (VL_DESC - 1));
eb66ff34348f (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1151
diff changeset
  1075
		vl->sort_type = _sorting.roadveh.criteria;
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1076
		vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1077
		break;
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1078
767
27edbcad701c (svn r1232) Plug memory leak
tron
parents: 757
diff changeset
  1079
	case WE_DESTROY:
4280
90e7b2ea8627 (svn r5910) Fix some more warnings on MSVC by using (void*) casts. Followup of r5907.
Darkvater
parents: 4266
diff changeset
  1080
		free((void*)vl->sort_list);
767
27edbcad701c (svn r1232) Plug memory leak
tron
parents: 757
diff changeset
  1081
		break;
27edbcad701c (svn r1232) Plug memory leak
tron
parents: 757
diff changeset
  1082
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1083
	case WE_TICK: /* resort the list every 20 seconds orso (10 days) */
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1084
		if (--vl->resort_timer == 0) {
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1085
			DEBUG(misc, 1) ("Periodic resort road vehicles list player %d station %d",
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1086
				owner, station);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1087
			vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1088
			vl->flags |= VL_RESORT;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1089
			SetWindowDirty(w);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1090
		}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1091
		break;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1092
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1093
	case WE_RESIZE:
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1094
		/* Update the scroll + matrix */
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1095
		w->vscroll.cap += e->sizing.diff.y / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1096
		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1097
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
static const WindowDesc _player_roadveh_desc = {
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1102
	-1, -1, 260, 220,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
	WC_ROADVEH_LIST,0,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1104
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
	_player_roadveh_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
	PlayerRoadVehWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
static const WindowDesc _other_player_roadveh_desc = {
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1110
	-1, -1, 260, 220,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
	WC_ROADVEH_LIST,0,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1112
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
	_other_player_roadveh_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
	PlayerRoadVehWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
2466
1aa260b43faa (svn r2992) Use PlayerID, StationID and INVALID_STATION instead of int, int and -1
tron
parents: 2436
diff changeset
  1118
void ShowPlayerRoadVehicles(PlayerID player, StationID station)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
	if ( player == _local_player) {
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1123
		w = AllocateWindowDescFront(&_player_roadveh_desc, (station << 16) | player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
	} else  {
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 555
diff changeset
  1125
		w = AllocateWindowDescFront(&_other_player_roadveh_desc, (station << 16) | player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
	}
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1127
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
		w->caption_color = player;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1129
		w->vscroll.cap = 7; // maximum number of vehicles shown
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1130
		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1131
		w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1132
		w->resize.height = 220 - (PLY_WND_PRC__SIZE_OF_ROW_SMALL * 3); /* Minimum of 4 vehicles */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
}