summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-05-31 14:04:19 +0000
committerfrosch <frosch@openttd.org>2009-05-31 14:04:19 +0000
commitea229c32bc6f681742627125b26791bebeaf2d1a (patch)
treeb4bbb546ea77079599e1b99a522af7541d4f00a1 /src
parent9853c0dc224e01cf3394336ab074cbb18592bd5b (diff)
downloadopenttd-ea229c32bc6f681742627125b26791bebeaf2d1a.tar.xz
(svn r16483) -Codechange: Enumerate tabs in train details window.
Diffstat (limited to 'src')
-rw-r--r--src/train_gui.cpp30
-rw-r--r--src/vehicle_gui.cpp25
-rw-r--r--src/vehicle_gui.h8
3 files changed, 46 insertions, 17 deletions
diff --git a/src/train_gui.cpp b/src/train_gui.cpp
index b0a2ca30a..8dc526c56 100644
--- a/src/train_gui.cpp
+++ b/src/train_gui.cpp
@@ -174,13 +174,19 @@ static void TrainDetailsCapacityTab(const Vehicle *v, int left, int right, int y
}
}
-int GetTrainDetailsWndVScroll(VehicleID veh_id, byte det_tab)
+/**
+ * Determines the number of lines in the train details window
+ * @param veh_id Train
+ * @param det_tab Selected details tab
+ * @return Number of line
+ */
+int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
{
AcceptedCargo act_cargo;
AcceptedCargo max_cargo;
int num = 0;
- if (det_tab == 3) { // Total cargo tab
+ if (det_tab == TDW_TAB_TOTALS) { // Total cargo tab
memset(max_cargo, 0, sizeof(max_cargo));
memset(act_cargo, 0, sizeof(act_cargo));
@@ -212,11 +218,14 @@ int GetTrainDetailsWndVScroll(VehicleID veh_id, byte det_tab)
* @param left The left most coordinate to draw
* @param right The right most coordinate to draw
* @param y The y coordinate
+ * @param vscroll_pos Position of scrollbar
+ * @param vscroll_cap Number of lines currently displayed
+ * @param det_tab Selected details tab
*/
-void DrawTrainDetails(const Vehicle *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, byte det_tab)
+void DrawTrainDetails(const Vehicle *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab)
{
/* draw the first 3 details tabs */
- if (det_tab != 3) {
+ if (det_tab != TDW_TAB_TOTALS) {
const Vehicle *u = v;
int x = 1;
for (;;) {
@@ -235,14 +244,21 @@ void DrawTrainDetails(const Vehicle *v, int left, int right, int y, int vscroll_
int py = y + 2;
switch (det_tab) {
default: NOT_REACHED();
- case 0: TrainDetailsCargoTab( v, px, right, py); break;
- case 1:
+
+ case TDW_TAB_CARGO:
+ TrainDetailsCargoTab(v, px, right, py);
+ break;
+
+ case TDW_TAB_INFO:
/* Only show name and value for the 'real' part */
if (!IsArticulatedPart(v)) {
TrainDetailsInfoTab(v, px, right, py);
}
break;
- case 2: TrainDetailsCapacityTab(v, px, right, py); break;
+
+ case TDW_TAB_CAPACITY:
+ TrainDetailsCapacityTab(v, px, right, py);
+ break;
}
y += 14;
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 2cea2dae3..077f108c0 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1272,6 +1272,11 @@ enum VehicleDetailsWindowWidgets {
VLD_WIDGET_RESIZE,
};
+assert_compile(VLD_WIDGET_DETAILS_CARGO_CARRIED == VLD_WIDGET_DETAILS_CARGO_CARRIED + TDW_TAB_CARGO );
+assert_compile(VLD_WIDGET_DETAILS_TRAIN_VEHICLES == VLD_WIDGET_DETAILS_CARGO_CARRIED + TDW_TAB_INFO );
+assert_compile(VLD_WIDGET_DETAILS_CAPACITY_OF_EACH == VLD_WIDGET_DETAILS_CARGO_CARRIED + TDW_TAB_CAPACITY);
+assert_compile(VLD_WIDGET_DETAILS_TOTAL_CARGO == VLD_WIDGET_DETAILS_CARGO_CARRIED + TDW_TAB_TOTALS );
+
/** Vehicle details widgets. */
static const Widget _vehicle_details_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW}, // VLD_WIDGET_CLOSEBOX
@@ -1321,14 +1326,14 @@ static const NWidgetPart _nested_vehicle_details_widgets[] = {
};
-extern int GetTrainDetailsWndVScroll(VehicleID veh_id, byte det_tab);
-extern void DrawTrainDetails(const Vehicle *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, byte det_tab);
+extern int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab);
+extern void DrawTrainDetails(const Vehicle *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab);
extern void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y);
extern void DrawShipDetails(const Vehicle *v, int left, int right, int y);
extern void DrawAircraftDetails(const Vehicle *v, int left, int right, int y);
struct VehicleDetailsWindow : Window {
- int tab;
+ TrainDetailsWindowTabs tab;
/** Initialize a newly created vehicle details window */
VehicleDetailsWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
@@ -1383,7 +1388,7 @@ struct VehicleDetailsWindow : Window {
this->widget[VLD_WIDGET_MIDDLE_DETAILS].data = (this->vscroll.cap << 8) + 1;
this->owner = v->owner;
- this->tab = 0;
+ this->tab = TDW_TAB_CARGO;
this->FindWindowPlacementAndResize(desc);
}
@@ -1408,11 +1413,11 @@ struct VehicleDetailsWindow : Window {
* @param left The left most coordinate to draw
* @param right The right most coordinate to draw
* @param y The y coordinate
- * @param vscroll_pos (train only)
- * @param vscroll_cap (train only)
- * @param det_tab (train only)
+ * @param vscroll_pos Position of scrollbar (train only)
+ * @param vscroll_cap Number of lines currently displayed (train only)
+ * @param det_tab Selected details tab (train only)
*/
- static void DrawVehicleDetails(const Vehicle *v, int left, int right, int y, int vscroll_pos, uint vscroll_cap, byte det_tab)
+ static void DrawVehicleDetails(const Vehicle *v, int left, int right, int y, int vscroll_pos, uint vscroll_cap, TrainDetailsWindowTabs det_tab)
{
switch (v->type) {
case VEH_TRAIN: DrawTrainDetails(v, left, right, y, vscroll_pos, vscroll_cap, det_tab); break;
@@ -1427,7 +1432,7 @@ struct VehicleDetailsWindow : Window {
virtual void OnPaint()
{
const Vehicle *v = Vehicle::Get(this->window_number);
- byte det_tab = this->tab;
+ TrainDetailsWindowTabs det_tab = this->tab;
this->SetWidgetDisabledState(VLD_WIDGET_RENAME_VEHICLE, v->owner != _local_company);
@@ -1556,7 +1561,7 @@ struct VehicleDetailsWindow : Window {
widget,
WIDGET_LIST_END);
- this->tab = widget - VLD_WIDGET_DETAILS_CARGO_CARRIED;
+ this->tab = (TrainDetailsWindowTabs)(widget - VLD_WIDGET_DETAILS_CARGO_CARRIED);
this->SetDirty();
break;
}
diff --git a/src/vehicle_gui.h b/src/vehicle_gui.h
index 855b750ca..fb3516ec4 100644
--- a/src/vehicle_gui.h
+++ b/src/vehicle_gui.h
@@ -35,6 +35,14 @@ enum VehicleViewWindowWidgets {
VVW_WIDGET_FORCE_PROCEED,
};
+/** The tabs in the train details window */
+enum TrainDetailsWindowTabs {
+ TDW_TAB_CARGO = 0, ///< Tab with cargo carried by the vehicles
+ TDW_TAB_INFO, ///< Tab with name and value of the vehicles
+ TDW_TAB_CAPACITY, ///< Tab with cargo capacity of the vehicles
+ TDW_TAB_TOTALS, ///< Tab with sum of total cargo transported
+};
+
/** Vehicle List Window type flags */
enum {
VLW_STANDARD = 0 << 8,