(svn r24023) -Fix [FS#5090]: pass cases down into the list of cargos

This commit is contained in:
rubidium 2012-03-10 19:18:04 +00:00
parent 19923e81f9
commit bf6434abaf
3 changed files with 16 additions and 77 deletions

View File

@ -1946,8 +1946,8 @@ STR_STATION_BUILD_COVERAGE_OFF :{BLACK}Off
STR_STATION_BUILD_COVERAGE_ON :{BLACK}On
STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP :{BLACK}Don't highlight coverage area of proposed site
STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP :{BLACK}Highlight coverage area of proposed site
STR_STATION_BUILD_ACCEPTS_CARGO :{BLACK}Accepts: {GOLD}{RAW_STRING}
STR_STATION_BUILD_SUPPLIES_CARGO :{BLACK}Supplies: {GOLD}{RAW_STRING}
STR_STATION_BUILD_ACCEPTS_CARGO :{BLACK}Accepts: {GOLD}{CARGO_LIST}
STR_STATION_BUILD_SUPPLIES_CARGO :{BLACK}Supplies: {GOLD}{CARGO_LIST}
# Join station window
STR_JOIN_STATION_CAPTION :{WHITE}Join station
@ -2722,7 +2722,7 @@ STR_STATION_VIEW_EN_ROUTE_FROM :{YELLOW}({CARGO
STR_STATION_VIEW_ACCEPTS_BUTTON :{BLACK}Accepts
STR_STATION_VIEW_ACCEPTS_TOOLTIP :{BLACK}Show list of accepted cargo
STR_STATION_VIEW_ACCEPTS_CARGO :{BLACK}Accepts: {WHITE}{RAW_STRING}
STR_STATION_VIEW_ACCEPTS_CARGO :{BLACK}Accepts: {WHITE}{CARGO_LIST}
STR_STATION_VIEW_RATINGS_BUTTON :{BLACK}Ratings
STR_STATION_VIEW_RATINGS_TOOLTIP :{BLACK}Show station ratings
@ -2967,9 +2967,9 @@ STR_PURCHASE_INFO_WEIGHT_CWEIGHT :{BLACK}Weight:
STR_PURCHASE_INFO_COST_SPEED :{BLACK}Cost: {GOLD}{CURRENCY_LONG}{BLACK} Speed: {GOLD}{VELOCITY}
STR_PURCHASE_INFO_AIRCRAFT_CAPACITY :{BLACK}Capacity: {GOLD}{CARGO_LONG}, {CARGO_LONG}
STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT :{BLACK}Powered Wagons: {GOLD}+{POWER}{BLACK} Weight: {GOLD}+{WEIGHT_SHORT}
STR_PURCHASE_INFO_REFITTABLE_TO :{BLACK}Refittable to: {GOLD}
STR_PURCHASE_INFO_REFITTABLE_TO :{BLACK}Refittable to: {GOLD}{STRING2}
STR_PURCHASE_INFO_ALL_TYPES :All cargo types
STR_PURCHASE_INFO_ALL_BUT :All but {GOLD}
STR_PURCHASE_INFO_ALL_BUT :All but {CARGO_LIST}
STR_PURCHASE_INFO_MAX_TE :{BLACK}Max. Tractive Effort: {GOLD}{FORCE}
STR_PURCHASE_INFO_AIRCRAFT_RANGE :{BLACK}Range: {GOLD}{COMMA} tiles
@ -4422,6 +4422,7 @@ STR_JUST_CHECKMARK :{CHECKMARK}
STR_JUST_COMMA :{COMMA}
STR_JUST_CURRENCY_SHORT :{CURRENCY_SHORT}
STR_JUST_CURRENCY_LONG :{CURRENCY_LONG}
STR_JUST_CARGO_LIST :{CARGO_LIST}
STR_JUST_INT :{NUM}
STR_JUST_DATE_TINY :{DATE_TINY}
STR_JUST_DATE_SHORT :{DATE_SHORT}

View File

@ -34,45 +34,6 @@
#include "table/strings.h"
/**
* Draw a (multi)line of cargoes seperated by commas, and prefixed with a string.
* @param cargo_mask Mask of cargoes to include in the list.
* @param r Rectangle to draw the cargoes in.
* @param prefix String to use as prefix for the list of cargoes.
* @return Bottom position of the last line used for drawing the cargoes.
*/
static int DrawCargoListText(uint32 cargo_mask, const Rect &r, StringID prefix)
{
bool first = true;
char string[512];
char *b = string;
CargoID i;
FOR_EACH_SET_CARGO_ID(i, cargo_mask) {
if (b >= lastof(string) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
if (first) {
first = false;
} else {
/* Add a comma if this is not the first item */
*b++ = ',';
*b++ = ' ';
}
b = InlineString(b, CargoSpec::Get(i)->name);
}
/* If first is still true then no cargo is accepted */
if (first) b = InlineString(b, STR_JUST_NOTHING);
*b = '\0';
/* Make sure we detect any buffer overflow */
assert(b < endof(string));
SetDParamStr(0, string);
return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, prefix);
}
/**
* Calculates and draws the accepted or supplied cargo around the selected tile(s)
* @param left x position where the string is to be drawn
@ -106,8 +67,8 @@ int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageTyp
if (cargoes[i] >= (supplies ? 1U : 8U)) SetBit(cargo_mask, i);
}
}
Rect r = {left, top, right, INT32_MAX};
return DrawCargoListText(cargo_mask, r, supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO);
SetDParam(0, cargo_mask);
return DrawStringMultiLine(left, right, top, INT32_MAX, supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO);
}
/**
@ -1091,8 +1052,8 @@ struct StationViewWindow : public Window {
for (CargoID i = 0; i < NUM_CARGO; i++) {
if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::GES_ACCEPTANCE)) SetBit(cargo_mask, i);
}
Rect s = {r.left + WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP, r.right - WD_FRAMERECT_RIGHT, INT32_MAX};
int bottom = DrawCargoListText(cargo_mask, s, STR_STATION_VIEW_ACCEPTS_CARGO);
SetDParam(0, cargo_mask);
int bottom = DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, INT32_MAX, STR_STATION_VIEW_ACCEPTS_CARGO);
return CeilDiv(bottom - r.top - WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL);
}

View File

@ -931,49 +931,26 @@ uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
uint32 cmask = GetUnionOfArticulatedRefitMasks(engine, false);
/* List of cargo types available in this climate */
uint32 lmask = _cargo_mask;
char string[512];
char *b = string;
/* Draw nothing if the engine is not refittable */
if (HasAtMostOneBit(cmask)) return y;
b = InlineString(b, STR_PURCHASE_INFO_REFITTABLE_TO);
if (cmask == lmask) {
/* Engine can be refitted to all types in this climate */
b = InlineString(b, STR_PURCHASE_INFO_ALL_TYPES);
SetDParam(0, STR_PURCHASE_INFO_ALL_TYPES);
} else {
/* Check if we are able to refit to more cargo types and unable to. If
* so, invert the cargo types to list those that we can't refit to. */
if (CountBits(cmask ^ lmask) < CountBits(cmask) && CountBits(cmask ^ lmask) <= 7) {
cmask ^= lmask;
b = InlineString(b, STR_PURCHASE_INFO_ALL_BUT);
}
bool first = true;
/* Add each cargo type to the list */
const CargoSpec *cs;
FOR_ALL_SORTED_CARGOSPECS(cs) {
if (!HasBit(cmask, cs->Index())) continue;
if (b >= lastof(string) - (2 + 2 * 4)) break; // ", " and two calls to Utf8Encode()
if (!first) b = strecpy(b, ", ", lastof(string));
first = false;
b = InlineString(b, cs->name);
SetDParam(0, STR_PURCHASE_INFO_ALL_BUT);
} else {
SetDParam(0, STR_JUST_CARGO_LIST);
}
SetDParam(1, cmask);
}
/* Terminate and display the completed string */
*b = '\0';
/* Make sure we detect any buffer overflow */
assert(b < endof(string));
SetDParamStr(0, string);
return DrawStringMultiLine(left, right, y, INT32_MAX, STR_JUST_RAW_STRING);
return DrawStringMultiLine(left, right, y, INT32_MAX, STR_PURCHASE_INFO_REFITTABLE_TO);
}
/** Get the cargo subtype text from NewGRF for the vehicle details window. */