@@ -356,12 +356,13 @@ enum VehicleRefitWidgets {
/** Refit cargo window. */
struct RefitWindow : public Window {
int sel; ///< Index in refit options, \c -1 if nothing is selected.
RefitOption *cargo; ///< Refit option selected by \v sel.
SubtypeList list[NUM_CARGO]; ///< List of refit subtypes available for each sorted cargo.
VehicleOrderID order; ///< If not #INVALID_VEH_ORDER_ID, selection is part of a refit order (rather than execute directly).
uint information_width; ///< Width required for correctly displaying all cargos in the information panel.
Scrollbar *vscroll;
/**
* Collects all (cargo, subcargo) refit options of a vehicle chain.
*/
void BuildRefitList()
@@ -521,12 +522,16 @@ struct RefitWindow : public Window {
{
switch (widget) {
case VRW_MATRIX:
resize->height = WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM;
size->height = resize->height * 8;
break;
case VRW_INFOPANEL:
size->width = WD_FRAMERECT_LEFT + this->information_width + WD_FRAMERECT_RIGHT;
}
virtual void SetStringParameters(int widget) const
if (widget == VRW_CAPTION) SetDParam(0, Vehicle::Get(this->window_number)->index);
@@ -557,12 +562,33 @@ struct RefitWindow : public Window {
virtual void OnInvalidateData(int data)
switch (data) {
case 0: { // The consist lenght of the vehicle has changed; rebuild the entire list.
this->BuildRefitList();
uint max_width = 0;
Vehicle *v = Vehicle::Get(this->window_number);
/* Check the width of all cargo information strings. */
for (uint i = 0; i < NUM_CARGO; i++) {
for (uint j = 0; j < this->list[i].Length(); j++) {
CommandCost cost = DoCommand(v->tile, v->index, list[i][j].cargo | list[i][j].subtype << 8, DC_QUERY_COST, GetCmdRefitVeh(v->type));
if (cost.Succeeded()) {
SetDParam(0, list[i][j].cargo);
SetDParam(1, _returned_refit_capacity);
SetDParam(2, cost.GetCost());
Dimension dim = GetStringBoundingBox(STR_REFIT_NEW_CAPACITY_COST_OF_REFIT);
max_width = max(dim.width, max_width);
if (this->information_width < max_width) {
this->information_width = max_width;
this->ReInit();
/* FALL THROUGH */
case 1: // A new cargo has been selected.
this->cargo = GetRefitOption();
Status change: