src/ship_gui.cpp
author rubidium
Tue, 28 Aug 2007 06:46:33 +0000
changeset 7980 9b12784cc39c
parent 7974 6fcdebd75c19
child 7982 539e32cc37ce
permissions -rw-r--r--
(svn r10995) -Codechange: unify the way to get the displayed maxium speed of a vehicle. Patch by nycom.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6524
diff changeset
     3
/** @file ship_gui.cpp */
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6524
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1820
diff changeset
     6
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1294
diff changeset
     7
#include "debug.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     8
#include "functions.h"
3961
e2783f244ac6 (svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents: 3948
diff changeset
     9
#include "ship.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 243
diff changeset
    10
#include "table/strings.h"
7762
03721db0ac1c (svn r10587) -Codechange: move the string/dparam related stuff from variables.h to strings.h
rubidium
parents: 7715
diff changeset
    11
#include "strings.h"
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    12
#include "table/sprites.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "gui.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 "command.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
    17
#include "depot.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2113
diff changeset
    18
#include "vehicle_gui.h"
2962
dbd168a4703a (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
    19
#include "newgrf_engine.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
4442
8d8d0c2df7cb (svn r6215) -Codechange: [vehicle list windows] unified Player(vehicle)WndProc into PlayerVehWndProc
bjarni
parents: 4436
diff changeset
    21
void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection)
1790
4afb4b4e4278 (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: 1751
diff changeset
    22
{
7630
2cd754d7dfa4 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7559
diff changeset
    23
	DrawSprite(v->GetImage(DIR_W), GetVehiclePalette(v), x + 32, y + 10);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
1790
4afb4b4e4278 (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: 1751
diff changeset
    25
	if (v->index == selection) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    26
		DrawFrameRect(x - 5, y - 1, x + 67, y + 21, 15, FR_BORDERONLY);
1790
4afb4b4e4278 (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: 1751
diff changeset
    27
	}
4afb4b4e4278 (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: 1751
diff changeset
    28
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
static void ShipDetailsWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
{
1790
4afb4b4e4278 (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: 1751
diff changeset
    32
	switch (e->event) {
4afb4b4e4278 (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: 1751
diff changeset
    33
	case WE_PAINT: {
4afb4b4e4278 (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: 1751
diff changeset
    34
		const Vehicle *v = GetVehicle(w->window_number);
4afb4b4e4278 (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: 1751
diff changeset
    35
		StringID str;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
    37
		SetWindowWidgetDisabledState(w, 2, v->owner != _local_player);
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6524
diff changeset
    38
		/* disable service-scroller when interval is set to disabled */
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
    39
		SetWindowWidgetDisabledState(w, 5, !_patches.servint_ships);
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
    40
		SetWindowWidgetDisabledState(w, 6, !_patches.servint_ships);
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
    41
7545
9a4834d48970 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7506
diff changeset
    42
		SetDParam(0, v->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
		/* Draw running cost */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
			int year = v->age / 366;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    49
			SetDParam(1, year);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    50
2252
37e3ca7014e0 (svn r2772) Simplify the age notice in the vehicle details window
tron
parents: 2244
diff changeset
    51
			SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    52
			SetDParam(2, v->max_age / 366);
7498
ce6588257e8d (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 7487
diff changeset
    53
			SetDParam(3, ShipVehInfo(v->engine_type)->running_cost * _price.ship_running >> 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
			DrawString(2, 15, STR_9812_AGE_RUNNING_COST_YR, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
		/* Draw max speed */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
		{
7980
9b12784cc39c (svn r10995) -Codechange: unify the way to get the displayed maxium speed of a vehicle. Patch by nycom.
rubidium
parents: 7974
diff changeset
    59
			SetDParam(0, v->GetDisplayMaxSpeed());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
			DrawString(2, 25, STR_9813_MAX_SPEED, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
		/* Draw profit */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
		{
7498
ce6588257e8d (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 7487
diff changeset
    65
			SetDParam(0, v->profit_this_year);
ce6588257e8d (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 7487
diff changeset
    66
			SetDParam(1, v->profit_last_year);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
			DrawString(2, 35, STR_9814_PROFIT_THIS_YEAR_LAST_YEAR, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
		/* Draw breakdown & reliability */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
		{
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    72
			SetDParam(0, v->reliability * 100 >> 16);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    73
			SetDParam(1, v->breakdowns_since_last_service);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
			DrawString(2, 45, STR_9815_RELIABILITY_BREAKDOWNS, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
		}
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
		/* Draw service interval text */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
		{
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    79
			SetDParam(0, v->service_interval);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    80
			SetDParam(1, v->date_of_last_service);
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6916
diff changeset
    81
			DrawString(13, 102, _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
    82
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
		DrawShipImage(v, 3, 57, INVALID_VEHICLE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
7555
e20900912fa2 (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7545
diff changeset
    86
		SetDParam(0, v->engine_type);
4329
9759d5c52010 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4299
diff changeset
    87
		SetDParam(1, v->build_year);
7498
ce6588257e8d (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 7487
diff changeset
    88
		SetDParam(2, v->value);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
		DrawString(74, 57, STR_9816_BUILT_VALUE, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    90
4896
72d7a8614580 (svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents: 4793
diff changeset
    91
		SetDParam(0, v->cargo_type);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    92
		SetDParam(1, v->cargo_cap);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
		DrawString(74, 67, STR_9817_CAPACITY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
		str = STR_8812_EMPTY;
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7498
diff changeset
    96
		if (!v->cargo.Empty()) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    97
			SetDParam(0, v->cargo_type);
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7498
diff changeset
    98
			SetDParam(1, v->cargo.Count());
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7498
diff changeset
    99
			SetDParam(2, v->cargo.Source());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
			str = STR_8813_FROM;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
		DrawString(74, 78, str, 0);
6524
44e22a9b2c97 (svn r8978) -Feature: Rewrite of transfer system.
richk
parents: 6144
diff changeset
   103
44e22a9b2c97 (svn r8978) -Feature: Rewrite of transfer system.
richk
parents: 6144
diff changeset
   104
		/* Draw Transfer credits text */
7506
e52d89f5c7c1 (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 7498
diff changeset
   105
		SetDParam(0, v->cargo.FeederShare());
6524
44e22a9b2c97 (svn r8978) -Feature: Rewrite of transfer system.
richk
parents: 6144
diff changeset
   106
		DrawString(74, 89, STR_FEEDER_CARGO_VALUE, 0);
44e22a9b2c97 (svn r8978) -Feature: Rewrite of transfer system.
richk
parents: 6144
diff changeset
   107
1790
4afb4b4e4278 (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: 1751
diff changeset
   108
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
1790
4afb4b4e4278 (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: 1751
diff changeset
   110
	case WE_CLICK: {
4afb4b4e4278 (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: 1751
diff changeset
   111
		int mod;
4afb4b4e4278 (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: 1751
diff changeset
   112
		const Vehicle *v;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   113
		switch (e->we.click.widget) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
		case 2: /* rename */
1790
4afb4b4e4278 (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: 1751
diff changeset
   115
			v = GetVehicle(w->window_number);
7545
9a4834d48970 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7506
diff changeset
   116
			SetDParam(0, v->index);
9a4834d48970 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7506
diff changeset
   117
			ShowQueryString(STR_VEHICLE_NAME, STR_9831_NAME_SHIP, 31, 150, w, CS_ALPHANUMERAL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
		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
   120
			mod = _ctrl_pressed? 5 : 10;
1790
4afb4b4e4278 (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: 1751
diff changeset
   121
			goto do_change_service_int;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
		case 6: /* decrease int */
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6916
diff changeset
   123
			mod = _ctrl_pressed ? - 5 : -10;
1790
4afb4b4e4278 (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: 1751
diff changeset
   124
do_change_service_int:
4afb4b4e4278 (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: 1751
diff changeset
   125
			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
   126
1790
4afb4b4e4278 (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: 1751
diff changeset
   127
			mod = GetServiceIntervalClamped(mod + v->service_interval);
4afb4b4e4278 (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: 1751
diff changeset
   128
			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
   129
2819
710436dd4288 (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
   130
			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
   131
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
		}
1790
4afb4b4e4278 (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: 1751
diff changeset
   133
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2517
diff changeset
   135
	case WE_ON_EDIT_TEXT:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   136
		if (e->we.edittext.str[0] != '\0') {
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   137
			_cmd_text = e->we.edittext.str;
1820
9b6458526480 (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: 1802
diff changeset
   138
			DoCommandP(0, w->window_number, 0, NULL,
9b6458526480 (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: 1802
diff changeset
   139
				CMD_NAME_VEHICLE | CMD_MSG(STR_9832_CAN_T_NAME_SHIP));
9b6458526480 (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: 1802
diff changeset
   140
		}
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2517
diff changeset
   141
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
static const Widget _ship_details_widgets[] = {
4344
5d0e40cd67b9 (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
   147
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (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
   148
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   364,     0,    13, STR_9811_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS},
5d0e40cd67b9 (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
   149
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   365,   404,     0,    13, STR_01AA_NAME,    STR_982F_NAME_SHIP},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4937
diff changeset
   150
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   404,    14,    55, 0x0,              STR_NULL},
6524
44e22a9b2c97 (svn r8978) -Feature: Rewrite of transfer system.
richk
parents: 6144
diff changeset
   151
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   404,    56,   100, 0x0,              STR_NULL},
44e22a9b2c97 (svn r8978) -Feature: Rewrite of transfer system.
richk
parents: 6144
diff changeset
   152
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    10,   101,   106, STR_0188,         STR_884D_INCREASE_SERVICING_INTERVAL},
44e22a9b2c97 (svn r8978) -Feature: Rewrite of transfer system.
richk
parents: 6144
diff changeset
   153
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    10,   107,   112, STR_0189,         STR_884E_DECREASE_SERVICING_INTERVAL},
44e22a9b2c97 (svn r8978) -Feature: Rewrite of transfer system.
richk
parents: 6144
diff changeset
   154
{      WWT_PANEL,   RESIZE_NONE,    14,    11,   404,   101,   112, 0x0,              STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   155
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
static const WindowDesc _ship_details_desc = {
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7762
diff changeset
   159
	WDP_AUTO, WDP_AUTO, 405, 113, 405, 113,
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6916
diff changeset
   160
	WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	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
   162
	_ship_details_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	ShipDetailsWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   166
static void ShowShipDetailsWindow(const Vehicle *v)
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
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
	VehicleID veh = v->index;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   170
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
	DeleteWindowById(WC_VEHICLE_DETAILS, veh);
5071
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5070
diff changeset
   173
	w = AllocateWindowDescFront(&_ship_details_desc, veh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
	w->caption_color = v->owner;
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   177
void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   179
	const Vehicle *v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
	if (!success) return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
3948
95f9fa0ac551 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3887
diff changeset
   182
	v = GetVehicle(_new_vehicle_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	if (v->tile == _backup_orders_tile) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
		_backup_orders_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
		RestoreVehicleOrders(v, _backup_orders_data);
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
	ShowShipViewWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   190
static void ShipViewWndProc(Window *w, WindowEvent *e)
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   191
{
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
   192
	switch (e->event) {
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   193
		case WE_PAINT: {
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   194
			Vehicle *v = GetVehicle(w->window_number);
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   195
			StringID str;
4779
e74142f0d7d8 (svn r6693) -Fix: [ship view window] disable the refit button when the ship is not refitable or not stopped in a depot
bjarni
parents: 4734
diff changeset
   196
			bool refitable_and_stopped_in_depot = ShipVehInfo(v->engine_type)->refittable && IsShipInDepotStopped(v);
5078
130939b8e39e (svn r7142) -Fix: disable clone button in vehicle view for not owned vehicles (was already done for trains)
glx
parents: 5071
diff changeset
   197
			bool is_localplayer = v->owner == _local_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
5078
130939b8e39e (svn r7142) -Fix: disable clone button in vehicle view for not owned vehicles (was already done for trains)
glx
parents: 5071
diff changeset
   199
			SetWindowWidgetDisabledState(w,  7, !is_localplayer);
130939b8e39e (svn r7142) -Fix: disable clone button in vehicle view for not owned vehicles (was already done for trains)
glx
parents: 5071
diff changeset
   200
			SetWindowWidgetDisabledState(w,  8,
130939b8e39e (svn r7142) -Fix: disable clone button in vehicle view for not owned vehicles (was already done for trains)
glx
parents: 5071
diff changeset
   201
			                             !is_localplayer ||      // Disable if owner is not local player
4779
e74142f0d7d8 (svn r6693) -Fix: [ship view window] disable the refit button when the ship is not refitable or not stopped in a depot
bjarni
parents: 4734
diff changeset
   202
			                             !refitable_and_stopped_in_depot); // Disable if the ship is not refitable or stopped in a depot
5078
130939b8e39e (svn r7142) -Fix: disable clone button in vehicle view for not owned vehicles (was already done for trains)
glx
parents: 5071
diff changeset
   203
			SetWindowWidgetDisabledState(w, 11, !is_localplayer);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   205
			/* draw widgets & caption */
7545
9a4834d48970 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7506
diff changeset
   206
			SetDParam(0, v->index);
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   207
			DrawWindowWidgets(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   209
			if (v->breakdown_ctr == 1) {
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   210
				str = STR_885C_BROKEN_DOWN;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   211
			} else if (v->vehstatus & VS_STOPPED) {
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   212
				str = STR_8861_STOPPED;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   213
			} else {
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   214
				switch (v->current_order.type) {
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   215
					case OT_GOTO_STATION: {
4527
b18634a31a4a (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4524
diff changeset
   216
						SetDParam(0, v->current_order.dest);
7973
ce69b7781d4a (svn r10984) -Codechange: unify the way one can get the current speed in the same forwat so we can display it.
rubidium
parents: 7837
diff changeset
   217
						SetDParam(1, v->GetDisplaySpeed());
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   218
						str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   219
					} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   221
					case OT_GOTO_DEPOT: {
4527
b18634a31a4a (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4524
diff changeset
   222
						Depot *depot = GetDepot(v->current_order.dest);
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   223
						SetDParam(0, depot->town_index);
7973
ce69b7781d4a (svn r10984) -Codechange: unify the way one can get the current speed in the same forwat so we can display it.
rubidium
parents: 7837
diff changeset
   224
						SetDParam(1, v->GetDisplaySpeed());
4633
fae5d85ef53d (svn r6497) -Fix r6165: Vehicles heading for depots when their orders contained "service in depot" displayed the stopping in depot string
bjarni
parents: 4592
diff changeset
   225
						if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
4412
945e8a9bb89a (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4408
diff changeset
   226
							str = STR_HEADING_FOR_SHIP_DEPOT + _patches.vehicle_speed;
945e8a9bb89a (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4408
diff changeset
   227
						} else {
945e8a9bb89a (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4408
diff changeset
   228
							str = STR_HEADING_FOR_SHIP_DEPOT_SERVICE + _patches.vehicle_speed;
945e8a9bb89a (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4408
diff changeset
   229
						}
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   230
					} break;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   231
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   232
					case OT_LOADING:
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   233
					case OT_LEAVESTATION:
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   234
						str = STR_882F_LOADING_UNLOADING;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   235
						break;
2261
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2252
diff changeset
   236
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   237
					default:
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   238
						if (v->num_orders == 0) {
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   239
							str = STR_NO_ORDERS + _patches.vehicle_speed;
7973
ce69b7781d4a (svn r10984) -Codechange: unify the way one can get the current speed in the same forwat so we can display it.
rubidium
parents: 7837
diff changeset
   240
							SetDParam(0, v->GetDisplaySpeed());
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   241
						} else {
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   242
							str = STR_EMPTY;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4012
diff changeset
   243
						}
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   244
						break;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   245
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
2103
9266bb2ac29d (svn r2613) - Truncate savegames, and vehicle-texts in their window.
Darkvater
parents: 2084
diff changeset
   248
		/* draw the flag plus orders */
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5835
diff changeset
   249
		DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, 2, w->widget[5].top + 1);
2113
f228b399da01 (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
   250
		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
   251
		DrawWindowViewport(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   254
		case WE_CLICK: {
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   255
			const Vehicle *v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   257
			switch (e->we.click.widget) {
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   258
				case 5: /* start stop */
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   259
					DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP));
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   260
					break;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   261
				case 6: /* center main view */
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   262
					ScrollMainWindowTo(v->x_pos, v->y_pos);
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   263
					break;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   264
				case 7: /* goto hangar */
4506
0d8fcc0a4e49 (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4456
diff changeset
   265
					DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL, CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_9819_CAN_T_SEND_SHIP_TO_DEPOT));
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   266
					break;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   267
				case 8: /* refit */
4712
273ec3b182bf (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4709
diff changeset
   268
					ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID);
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   269
					break;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   270
				case 9: /* show orders */
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   271
					ShowOrdersWindow(v);
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   272
					break;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   273
				case 10: /* show details */
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   274
					ShowShipDetailsWindow(v);
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   275
					break;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   276
				case 11: {
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   277
					/* clone vehicle */
7974
6fcdebd75c19 (svn r10985) -Codechange: unify/remove duplicate CcClone(Aircraft|RoadVeh|Ship|Train) in favour of CcCloneVehicle.
rubidium
parents: 7973
diff changeset
   278
					DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneVehicle, CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   279
				} break;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   280
			}
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   281
		} break;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   282
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   283
		case WE_RESIZE:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   284
			w->viewport->width          += e->we.sizing.diff.x;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   285
			w->viewport->height         += e->we.sizing.diff.y;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   286
			w->viewport->virtual_width  += e->we.sizing.diff.x;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   287
			w->viewport->virtual_height += e->we.sizing.diff.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   290
		case WE_DESTROY:
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   291
			DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   292
			DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   293
			DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
7559
8e7ef897f126 (svn r10328) -Codechange: Close the timetable window when closing the vehicle window.
maedhros
parents: 7555
diff changeset
   294
			DeleteWindowById(WC_VEHICLE_TIMETABLE, w->window_number);
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   295
			break;
1485
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1330
diff changeset
   296
4702
5179f9adc5b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   297
		case WE_MOUSELOOP: {
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   298
			const Vehicle *v = GetVehicle(w->window_number);
4702
5179f9adc5b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   299
			bool ship_stopped = IsShipInDepotStopped(v);
4000
bab1ebc37da0 (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: 3989
diff changeset
   300
4702
5179f9adc5b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   301
			/* Widget 7 (send to depot) must be hidden if the ship is already stopped in depot.
5179f9adc5b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   302
			 * Widget 11 (clone) should then be shown, since cloning is allowed only while in depot and stopped.
5179f9adc5b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   303
			 * This sytem allows to have two buttons, on top of each otherother*/
5179f9adc5b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   304
			if (ship_stopped != IsWindowWidgetHidden(w, 7) || ship_stopped == IsWindowWidgetHidden(w, 11)) {
5179f9adc5b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   305
				SetWindowWidgetHiddenState(w,  7, ship_stopped);  // send to depot
5179f9adc5b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   306
				SetWindowWidgetHiddenState(w, 11, !ship_stopped); // clone
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   307
				SetWindowDirty(w);
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   308
			}
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2187
diff changeset
   309
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
static const Widget _ship_view_widgets[] = {
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   314
{   WWT_CLOSEBOX, RESIZE_NONE,  14,   0,  10,   0,  13, STR_00C5,                STR_018B_CLOSE_WINDOW},
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   315
{    WWT_CAPTION, RESIZE_RIGHT, 14,  11, 237,   0,  13, STR_980F,                STR_018C_WINDOW_TITLE_DRAG_THIS},
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   316
{  WWT_STICKYBOX, RESIZE_LR,    14, 238, 249,   0,  13, 0x0,                     STR_STICKY_BUTTON},
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   317
{      WWT_PANEL, RESIZE_RB,    14,   0, 231,  14, 103, 0x0,                     STR_NULL},
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   318
{      WWT_INSET, RESIZE_RB,    14,   2, 229,  16, 101, 0x0,                     STR_NULL},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4937
diff changeset
   319
{    WWT_PUSHBTN, RESIZE_RTB,   14,   0, 237, 104, 115, 0x0,                     STR_9827_CURRENT_SHIP_ACTION_CLICK},
4937
a525d56a8d40 (svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents: 4932
diff changeset
   320
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  14,  31, SPR_CENTRE_VIEW_VEHICLE, STR_9829_CENTER_MAIN_VIEW_ON_SHIP},
a525d56a8d40 (svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents: 4932
diff changeset
   321
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  32,  49, SPR_SEND_SHIP_TODEPOT,   STR_982A_SEND_SHIP_TO_DEPOT},
a525d56a8d40 (svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents: 4932
diff changeset
   322
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  50,  67, SPR_REFIT_VEHICLE,       STR_983A_REFIT_CARGO_SHIP_TO_CARRY},
a525d56a8d40 (svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents: 4932
diff changeset
   323
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  68,  85, SPR_SHOW_ORDERS,         STR_9828_SHOW_SHIP_S_ORDERS},
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6916
diff changeset
   324
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  86, 103, SPR_SHOW_VEHICLE_DETAILS, STR_982B_SHOW_SHIP_DETAILS},
4937
a525d56a8d40 (svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents: 4932
diff changeset
   325
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  32,  49, SPR_CLONE_SHIP,          STR_CLONE_SHIP_INFO},
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   326
{      WWT_PANEL, RESIZE_LRB,   14, 232, 249, 104, 103, 0x0,                     STR_NULL },
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   327
{  WWT_RESIZEBOX, RESIZE_LRTB,  14, 238, 249, 104, 115, 0x0,                     STR_NULL },
1485
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1330
diff changeset
   328
{ WIDGETS_END }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
static const WindowDesc _ship_view_desc = {
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7762
diff changeset
   332
	WDP_AUTO, WDP_AUTO, 250, 116, 250, 116,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6125
diff changeset
   333
	WC_VEHICLE_VIEW, WC_NONE,
1485
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1330
diff changeset
   334
	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
   335
	_ship_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
	ShipViewWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   339
void ShowShipViewWindow(const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   341
	Window *w = AllocateWindowDescFront(&_ship_view_desc, v->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   343
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
		w->caption_color = v->owner;
7120
e31767effc16 (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6987
diff changeset
   345
		AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), ZOOM_LVL_SHIP);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
}