mirror of https://github.com/OpenTTD/OpenTTD
(svn r16483) -Codechange: Enumerate tabs in train details window.
parent
9853c0dc22
commit
ea229c32bc
|
@ -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 act_cargo;
|
||||||
AcceptedCargo max_cargo;
|
AcceptedCargo max_cargo;
|
||||||
int num = 0;
|
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(max_cargo, 0, sizeof(max_cargo));
|
||||||
memset(act_cargo, 0, sizeof(act_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 left The left most coordinate to draw
|
||||||
* @param right The right most coordinate to draw
|
* @param right The right most coordinate to draw
|
||||||
* @param y The y coordinate
|
* @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 */
|
/* draw the first 3 details tabs */
|
||||||
if (det_tab != 3) {
|
if (det_tab != TDW_TAB_TOTALS) {
|
||||||
const Vehicle *u = v;
|
const Vehicle *u = v;
|
||||||
int x = 1;
|
int x = 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -235,14 +244,21 @@ void DrawTrainDetails(const Vehicle *v, int left, int right, int y, int vscroll_
|
||||||
int py = y + 2;
|
int py = y + 2;
|
||||||
switch (det_tab) {
|
switch (det_tab) {
|
||||||
default: NOT_REACHED();
|
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 */
|
/* Only show name and value for the 'real' part */
|
||||||
if (!IsArticulatedPart(v)) {
|
if (!IsArticulatedPart(v)) {
|
||||||
TrainDetailsInfoTab(v, px, right, py);
|
TrainDetailsInfoTab(v, px, right, py);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2: TrainDetailsCapacityTab(v, px, right, py); break;
|
|
||||||
|
case TDW_TAB_CAPACITY:
|
||||||
|
TrainDetailsCapacityTab(v, px, right, py);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
y += 14;
|
y += 14;
|
||||||
|
|
||||||
|
|
|
@ -1272,6 +1272,11 @@ enum VehicleDetailsWindowWidgets {
|
||||||
VLD_WIDGET_RESIZE,
|
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. */
|
/** Vehicle details widgets. */
|
||||||
static const Widget _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
|
{ 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 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, byte 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 DrawRoadVehDetails(const Vehicle *v, int left, int right, int y);
|
||||||
extern void DrawShipDetails(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);
|
extern void DrawAircraftDetails(const Vehicle *v, int left, int right, int y);
|
||||||
|
|
||||||
struct VehicleDetailsWindow : Window {
|
struct VehicleDetailsWindow : Window {
|
||||||
int tab;
|
TrainDetailsWindowTabs tab;
|
||||||
|
|
||||||
/** Initialize a newly created vehicle details window */
|
/** Initialize a newly created vehicle details window */
|
||||||
VehicleDetailsWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
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->widget[VLD_WIDGET_MIDDLE_DETAILS].data = (this->vscroll.cap << 8) + 1;
|
||||||
this->owner = v->owner;
|
this->owner = v->owner;
|
||||||
|
|
||||||
this->tab = 0;
|
this->tab = TDW_TAB_CARGO;
|
||||||
|
|
||||||
this->FindWindowPlacementAndResize(desc);
|
this->FindWindowPlacementAndResize(desc);
|
||||||
}
|
}
|
||||||
|
@ -1408,11 +1413,11 @@ struct VehicleDetailsWindow : Window {
|
||||||
* @param left The left most coordinate to draw
|
* @param left The left most coordinate to draw
|
||||||
* @param right The right most coordinate to draw
|
* @param right The right most coordinate to draw
|
||||||
* @param y The y coordinate
|
* @param y The y coordinate
|
||||||
* @param vscroll_pos (train only)
|
* @param vscroll_pos Position of scrollbar (train only)
|
||||||
* @param vscroll_cap (train only)
|
* @param vscroll_cap Number of lines currently displayed (train only)
|
||||||
* @param det_tab (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) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN: DrawTrainDetails(v, left, right, y, vscroll_pos, vscroll_cap, det_tab); break;
|
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()
|
virtual void OnPaint()
|
||||||
{
|
{
|
||||||
const Vehicle *v = Vehicle::Get(this->window_number);
|
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);
|
this->SetWidgetDisabledState(VLD_WIDGET_RENAME_VEHICLE, v->owner != _local_company);
|
||||||
|
|
||||||
|
@ -1556,7 +1561,7 @@ struct VehicleDetailsWindow : Window {
|
||||||
widget,
|
widget,
|
||||||
WIDGET_LIST_END);
|
WIDGET_LIST_END);
|
||||||
|
|
||||||
this->tab = widget - VLD_WIDGET_DETAILS_CARGO_CARRIED;
|
this->tab = (TrainDetailsWindowTabs)(widget - VLD_WIDGET_DETAILS_CARGO_CARRIED);
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,14 @@ enum VehicleViewWindowWidgets {
|
||||||
VVW_WIDGET_FORCE_PROCEED,
|
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 */
|
/** Vehicle List Window type flags */
|
||||||
enum {
|
enum {
|
||||||
VLW_STANDARD = 0 << 8,
|
VLW_STANDARD = 0 << 8,
|
||||||
|
|
Loading…
Reference in New Issue