src/ship_gui.cpp
author rubidium
Wed, 19 Dec 2007 23:26:02 +0000
changeset 8108 b42a0e5c67ef
parent 8107 bb7deea89175
child 8114 dd6d21dc99c1
permissions -rw-r--r--
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
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
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6198
diff changeset
     3
/** @file ship_gui.cpp */
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6198
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1820
diff changeset
     6
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1294
diff changeset
     7
#include "debug.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     8
#include "functions.h"
3961
9868b766fda7 (svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents: 3948
diff changeset
     9
#include "ship.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 243
diff changeset
    10
#include "table/strings.h"
7266
b16e67e992b4 (svn r10587) -Codechange: move the string/dparam related stuff from variables.h to strings.h
rubidium
parents: 7219
diff changeset
    11
#include "strings.h"
2187
a0e206ce9fbf (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"
8107
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 7824
diff changeset
    14
#include "window_gui.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "command.h"
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
    18
#include "depot.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2113
diff changeset
    19
#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
    20
#include "newgrf_engine.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
4442
9f8bb348d58f (svn r6215) -Codechange: [vehicle list windows] unified Player(vehicle)WndProc into PlayerVehWndProc
bjarni
parents: 4436
diff changeset
    22
void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection)
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: 1751
diff changeset
    23
{
7134
5b2d47128d05 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7063
diff changeset
    24
	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
    25
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: 1751
diff changeset
    26
	if (v->index == selection) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    27
		DrawFrameRect(x - 5, y - 1, x + 67, y + 21, 15, FR_BORDERONLY);
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: 1751
diff changeset
    28
	}
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: 1751
diff changeset
    29
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
    31
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
    32
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
    33
	const Vehicle *v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	if (!success) return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3887
diff changeset
    36
	v = GetVehicle(_new_vehicle_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
	if (v->tile == _backup_orders_tile) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
		_backup_orders_tile = 0;
7653
dd252420d9c2 (svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents: 7530
diff changeset
    39
		RestoreVehicleOrders(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
	}
7486
bf6a94009823 (svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents: 7484
diff changeset
    41
	ShowVehicleViewWindow(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
}
7530
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    43
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    44
/**
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    45
* Draw the details for the given vehicle at the position (x,y)
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    46
*
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    47
* @param v current vehicle
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    48
* @param x The x coordinate
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    49
* @param y The y coordinate
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    50
*/
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    51
void DrawShipDetails(const Vehicle *v, int x, int y)
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    52
{
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    53
	SetDParam(0, v->engine_type);
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    54
	SetDParam(1, v->build_year);
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    55
	SetDParam(2, v->value);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7653
diff changeset
    56
	DrawString(x, y, STR_9816_BUILT_VALUE, TC_FROMSTRING);
7530
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    57
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    58
	SetDParam(0, v->cargo_type);
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    59
	SetDParam(1, v->cargo_cap);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7653
diff changeset
    60
	DrawString(x, y + 10, STR_9817_CAPACITY, TC_FROMSTRING);
7530
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    61
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    62
	StringID str = STR_8812_EMPTY;
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    63
	if (!v->cargo.Empty()) {
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    64
		SetDParam(0, v->cargo_type);
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    65
		SetDParam(1, v->cargo.Count());
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    66
		SetDParam(2, v->cargo.Source());
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    67
		str = STR_8813_FROM;
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    68
	}
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7653
diff changeset
    69
	DrawString(x, y + 21, str, TC_FROMSTRING);
7530
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    70
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    71
	/* Draw Transfer credits text */
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    72
	SetDParam(0, v->cargo.FeederShare());
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7653
diff changeset
    73
	DrawString(x, y + 33, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING);
7530
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7488
diff changeset
    74
}