Changeset - r12069:84bc50fb033a
[Not reviewed]
master
0 3 0
frosch - 15 years ago 2009-05-31 14:04:19
frosch@openttd.org
(svn r16483) -Codechange: Enumerate tabs in train details window.
3 files changed with 46 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/train_gui.cpp
Show inline comments
 
@@ -171,19 +171,25 @@ static void TrainDetailsCapacityTab(cons
 
		SetDParam(4, GetCargoSubtypeText(v));
 
		SetDParam(5, _settings_game.vehicle.freight_trains);
 
		DrawString(left, right, y, FreightWagonMult(v->cargo_type) > 1 ? STR_VEHICLE_INFO_CAPACITY_MULT : STR_VEHICLE_INFO_CAPACITY);
 
	}
 
}
 

	
 
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));
 

	
 
		for (const Vehicle *v = Vehicle::Get(veh_id) ; v != NULL ; v = v->Next()) {
 
			act_cargo[v->cargo_type] += v->cargo.Count();
 
			max_cargo[v->cargo_type] += v->cargo_cap;
 
@@ -209,17 +215,20 @@ int GetTrainDetailsWndVScroll(VehicleID 
 
 * Draw the details for the given vehicle at the given position
 
 *
 
 * @param v     current vehicle
 
 * @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 (;;) {
 
			if (--vscroll_pos < 0 && vscroll_pos >= -vscroll_cap) {
 
				int dx = 0;
 

	
 
@@ -232,20 +241,27 @@ void DrawTrainDetails(const Vehicle *v, 
 
				} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0);
 

	
 
				int px = x + WagonLengthToPixels(dx) + 2;
 
				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;
 

	
 
				v = u;
 
			} else {
 
				/* Move to the next line */
src/vehicle_gui.cpp
Show inline comments
 
@@ -1269,12 +1269,17 @@ enum VehicleDetailsWindowWidgets {
 
	VLD_WIDGET_DETAILS_TRAIN_VEHICLES,
 
	VLD_WIDGET_DETAILS_CAPACITY_OF_EACH,
 
	VLD_WIDGET_DETAILS_TOTAL_CARGO,
 
	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
 
	{    WWT_CAPTION,  RESIZE_RIGHT,  COLOUR_GREY,  11, 352,   0,  13, STR_VEHICLE_DETAILS_CAPTION,        STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS},            // VLD_WIDGET_CAPTION
 
	{ WWT_PUSHTXTBTN,     RESIZE_LR,  COLOUR_GREY, 353, 392,   0,  13, STR_VEHICLE_NAME_BUTTON,            STR_NULL /* filled in later */},                // VLD_WIDGET_RENAME_VEHICLE
 
	{  WWT_STICKYBOX,     RESIZE_LR,  COLOUR_GREY, 393, 404,   0,  13, STR_NULL,                           STR_STICKY_BUTTON},                             // VLD_WIDGET_STICKY
 
@@ -1318,20 +1323,20 @@ static const NWidgetPart _nested_vehicle
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, VLD_WIDGET_DETAILS_TOTAL_CARGO), SetMinimalSize(99, 12), SetDataTip(STR_VEHICLE_DETAIL_TAB_TOTAL_CARGO, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CARGO_TOOLTIP), SetResize(1, 0),
 
		NWidget(WWT_RESIZEBOX, COLOUR_GREY, VLD_WIDGET_RESIZE),
 
	EndContainer(),
 
};
 

	
 

	
 
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)
 
	{
 
		const Vehicle *v = Vehicle::Get(this->window_number);
 

	
 
@@ -1380,13 +1385,13 @@ struct VehicleDetailsWindow : Window {
 
			this->widget[VLD_WIDGET_MIDDLE_DETAILS].right += 12;
 
		}
 

	
 
		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);
 
	}
 

	
 
	/** Checks whether service interval is enabled for the vehicle. */
 
	static bool IsVehicleServiceIntervalEnabled(const VehicleType vehicle_type, CompanyID company_id)
 
@@ -1405,17 +1410,17 @@ struct VehicleDetailsWindow : Window {
 
	 * Draw the details for the given vehicle at the position of the Details windows
 
	 *
 
	 * @param v     current vehicle
 
	 * @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;
 
			case VEH_ROAD:     DrawRoadVehDetails(v, left, right, y);  break;
 
			case VEH_SHIP:     DrawShipDetails(v, left, right, y);     break;
 
			case VEH_AIRCRAFT: DrawAircraftDetails(v, left, right, y); break;
 
@@ -1424,13 +1429,13 @@ struct VehicleDetailsWindow : Window {
 
	}
 

	
 
	/** Repaint vehicle details 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);
 

	
 
		if (v->type == VEH_TRAIN) {
 
			this->DisableWidget(det_tab + VLD_WIDGET_DETAILS_CARGO_CARRIED);
 
			SetVScrollCount(this, GetTrainDetailsWndVScroll(v->index, det_tab));
 
@@ -1553,13 +1558,13 @@ struct VehicleDetailsWindow : Window {
 
					VLD_WIDGET_DETAILS_TRAIN_VEHICLES,
 
					VLD_WIDGET_DETAILS_CAPACITY_OF_EACH,
 
					VLD_WIDGET_DETAILS_TOTAL_CARGO,
 
					widget,
 
					WIDGET_LIST_END);
 

	
 
				this->tab = widget - VLD_WIDGET_DETAILS_CARGO_CARRIED;
 
				this->tab = (TrainDetailsWindowTabs)(widget - VLD_WIDGET_DETAILS_CARGO_CARRIED);
 
				this->SetDirty();
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
src/vehicle_gui.h
Show inline comments
 
@@ -32,12 +32,20 @@ enum VehicleViewWindowWidgets {
 
	VVW_WIDGET_EMPTY_BOTTOM_RIGHT,
 
	VVW_WIDGET_RESIZE,
 
	VVW_WIDGET_TURN_AROUND,
 
	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,
 
	VLW_SHARED_ORDERS = 1 << 8,
 
	VLW_STATION_LIST  = 2 << 8,
 
	VLW_DEPOT_LIST    = 3 << 8,
0 comments (0 inline, 0 general)