mirror of https://github.com/OpenTTD/OpenTTD
(svn r27822) -Feature: Vehicle Group Info: Add profits and occupancy display to group vehicle list (mtm, JGR)
parent
bcc5c9f81d
commit
19d56a33e8
|
@ -55,6 +55,7 @@ static const NWidgetPart _nested_group_widgets[] = {
|
||||||
SetFill(1, 0), SetResize(0, 1), SetScrollbar(WID_GL_LIST_GROUP_SCROLLBAR),
|
SetFill(1, 0), SetResize(0, 1), SetScrollbar(WID_GL_LIST_GROUP_SCROLLBAR),
|
||||||
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_GL_LIST_GROUP_SCROLLBAR),
|
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_GL_LIST_GROUP_SCROLLBAR),
|
||||||
EndContainer(),
|
EndContainer(),
|
||||||
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_GL_INFO), SetFill(1, 0), EndContainer(),
|
||||||
NWidget(NWID_HORIZONTAL),
|
NWidget(NWID_HORIZONTAL),
|
||||||
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_CREATE_GROUP), SetFill(0, 1),
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_CREATE_GROUP), SetFill(0, 1),
|
||||||
SetDataTip(SPR_GROUP_CREATE_TRAIN, STR_GROUP_CREATE_TOOLTIP),
|
SetDataTip(SPR_GROUP_CREATE_TRAIN, STR_GROUP_CREATE_TOOLTIP),
|
||||||
|
@ -371,6 +372,9 @@ public:
|
||||||
max_icon_height = max(max_icon_height, GetSpriteSize(this->GetWidget<NWidgetCore>(WID_GL_DELETE_GROUP)->widget_data).height);
|
max_icon_height = max(max_icon_height, GetSpriteSize(this->GetWidget<NWidgetCore>(WID_GL_DELETE_GROUP)->widget_data).height);
|
||||||
max_icon_height = max(max_icon_height, GetSpriteSize(this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data).height);
|
max_icon_height = max(max_icon_height, GetSpriteSize(this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data).height);
|
||||||
|
|
||||||
|
/* ... minus the height of the group info ... */
|
||||||
|
max_icon_height += (FONT_HEIGHT_NORMAL * 3) + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
||||||
|
|
||||||
/* Get a multiple of tiny_step_height of that amount */
|
/* Get a multiple of tiny_step_height of that amount */
|
||||||
size->height = Ceil(size->height - max_icon_height, tiny_step_height);
|
size->height = Ceil(size->height - max_icon_height, tiny_step_height);
|
||||||
break;
|
break;
|
||||||
|
@ -403,6 +407,11 @@ public:
|
||||||
*size = maxdim(*size, d);
|
*size = maxdim(*size, d);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case WID_GL_INFO: {
|
||||||
|
size->height = (FONT_HEIGHT_NORMAL * 3) + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,6 +536,44 @@ public:
|
||||||
DrawGroupInfo(r.top + WD_FRAMERECT_TOP, r.left, r.right, DEFAULT_GROUP);
|
DrawGroupInfo(r.top + WD_FRAMERECT_TOP, r.left, r.right, DEFAULT_GROUP);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WID_GL_INFO: {
|
||||||
|
Money this_year = 0;
|
||||||
|
Money last_year = 0;
|
||||||
|
uint32 occupancy = 0;
|
||||||
|
uint32 vehicle_count = this->vehicles.Length();
|
||||||
|
|
||||||
|
for (uint i = 0; i < vehicle_count; i++) {
|
||||||
|
const Vehicle *v = this->vehicles[i];
|
||||||
|
assert(v->owner == this->owner);
|
||||||
|
|
||||||
|
this_year += v->GetDisplayProfitThisYear();
|
||||||
|
last_year += v->GetDisplayProfitLastYear();
|
||||||
|
occupancy += v->trip_occupancy;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int left = r.left + WD_FRAMERECT_LEFT + 8;
|
||||||
|
const int right = r.right - WD_FRAMERECT_RIGHT - 8;
|
||||||
|
|
||||||
|
int y = r.top + WD_FRAMERECT_TOP;
|
||||||
|
DrawString(left, right, y, STR_GROUP_PROFIT_THIS_YEAR, TC_BLACK);
|
||||||
|
SetDParam(0, this_year);
|
||||||
|
DrawString(left, right, y, STR_JUST_CURRENCY_LONG, TC_BLACK, SA_RIGHT);
|
||||||
|
|
||||||
|
y += FONT_HEIGHT_NORMAL;
|
||||||
|
DrawString(left, right, y, STR_GROUP_PROFIT_LAST_YEAR, TC_BLACK);
|
||||||
|
SetDParam(0, last_year);
|
||||||
|
DrawString(left, right, y, STR_JUST_CURRENCY_LONG, TC_BLACK, SA_RIGHT);
|
||||||
|
|
||||||
|
y += FONT_HEIGHT_NORMAL;
|
||||||
|
DrawString(left, right, y, STR_GROUP_OCCUPANCY, TC_BLACK);
|
||||||
|
if (vehicle_count > 0) {
|
||||||
|
SetDParam(0, occupancy / vehicle_count);
|
||||||
|
DrawString(left, right, y, STR_GROUP_OCCUPANCY_VALUE, TC_BLACK, SA_RIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case WID_GL_LIST_GROUP: {
|
case WID_GL_LIST_GROUP: {
|
||||||
int y1 = r.top + WD_FRAMERECT_TOP;
|
int y1 = r.top + WD_FRAMERECT_TOP;
|
||||||
int max = min(this->group_sb->GetPosition() + this->group_sb->GetCapacity(), this->groups.Length());
|
int max = min(this->group_sb->GetPosition() + this->group_sb->GetCapacity(), this->groups.Length());
|
||||||
|
|
|
@ -3367,6 +3367,11 @@ STR_GROUP_REMOVE_ALL_VEHICLES :Remove all vehi
|
||||||
|
|
||||||
STR_GROUP_RENAME_CAPTION :{BLACK}Rename a group
|
STR_GROUP_RENAME_CAPTION :{BLACK}Rename a group
|
||||||
|
|
||||||
|
STR_GROUP_PROFIT_THIS_YEAR :Profit this year:
|
||||||
|
STR_GROUP_PROFIT_LAST_YEAR :Profit last year:
|
||||||
|
STR_GROUP_OCCUPANCY :Current usage:
|
||||||
|
STR_GROUP_OCCUPANCY_VALUE :{NUM}%
|
||||||
|
|
||||||
# Build vehicle window
|
# Build vehicle window
|
||||||
STR_BUY_VEHICLE_TRAIN_RAIL_CAPTION :New Rail Vehicles
|
STR_BUY_VEHICLE_TRAIN_RAIL_CAPTION :New Rail Vehicles
|
||||||
STR_BUY_VEHICLE_TRAIN_ELRAIL_CAPTION :New Electric Rail Vehicles
|
STR_BUY_VEHICLE_TRAIN_ELRAIL_CAPTION :New Electric Rail Vehicles
|
||||||
|
|
|
@ -375,6 +375,8 @@ void AfterLoadVehicles(bool part_of_load)
|
||||||
FOR_ALL_VEHICLES(v) {
|
FOR_ALL_VEHICLES(v) {
|
||||||
assert(v->first != NULL);
|
assert(v->first != NULL);
|
||||||
|
|
||||||
|
v->trip_occupancy = CalcPercentVehicleFilled(v, NULL);
|
||||||
|
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN: {
|
case VEH_TRAIN: {
|
||||||
Train *t = Train::From(v);
|
Train *t = Train::From(v);
|
||||||
|
|
|
@ -2160,6 +2160,7 @@ void Vehicle::LeaveStation()
|
||||||
st->loading_vehicles.remove(this);
|
st->loading_vehicles.remove(this);
|
||||||
|
|
||||||
HideFillingPercent(&this->fill_percent_te_id);
|
HideFillingPercent(&this->fill_percent_te_id);
|
||||||
|
trip_occupancy = CalcPercentVehicleFilled(this, NULL);
|
||||||
|
|
||||||
if (this->type == VEH_TRAIN && !(this->vehstatus & VS_CRASHED)) {
|
if (this->type == VEH_TRAIN && !(this->vehstatus & VS_CRASHED)) {
|
||||||
/* Trigger station animation (trains only) */
|
/* Trigger station animation (trains only) */
|
||||||
|
|
|
@ -308,6 +308,7 @@ public:
|
||||||
uint16 refit_cap; ///< Capacity left over from before last refit.
|
uint16 refit_cap; ///< Capacity left over from before last refit.
|
||||||
VehicleCargoList cargo; ///< The cargo this vehicle is carrying
|
VehicleCargoList cargo; ///< The cargo this vehicle is carrying
|
||||||
uint16 cargo_age_counter; ///< Ticks till cargo is aged next.
|
uint16 cargo_age_counter; ///< Ticks till cargo is aged next.
|
||||||
|
int8 trip_occupancy; ///< NOSAVE: Occupancy of vehicle of the current trip (updated after leaving a station).
|
||||||
|
|
||||||
byte day_counter; ///< Increased by one for each day
|
byte day_counter; ///< Increased by one for each day
|
||||||
byte tick_counter; ///< Increased by one for each tick
|
byte tick_counter; ///< Increased by one for each tick
|
||||||
|
|
|
@ -32,6 +32,7 @@ enum GroupListWidgets {
|
||||||
WID_GL_DELETE_GROUP, ///< Delete group button.
|
WID_GL_DELETE_GROUP, ///< Delete group button.
|
||||||
WID_GL_RENAME_GROUP, ///< Rename group button.
|
WID_GL_RENAME_GROUP, ///< Rename group button.
|
||||||
WID_GL_REPLACE_PROTECTION, ///< Replace protection button.
|
WID_GL_REPLACE_PROTECTION, ///< Replace protection button.
|
||||||
|
WID_GL_INFO, ///< Group info.
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* WIDGETS_GROUP_WIDGET_H */
|
#endif /* WIDGETS_GROUP_WIDGET_H */
|
||||||
|
|
Loading…
Reference in New Issue