(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance

This commit is contained in:
glx 2007-11-03 15:32:07 +00:00
parent a416f540fa
commit e3dfdaa470

View File

@ -138,7 +138,6 @@ static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
case WE_PAINT: { case WE_PAINT: {
const IndustrySpec *indsp = (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(WP(w, fnd_d).select); const IndustrySpec *indsp = (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(WP(w, fnd_d).select);
StringID str = STR_4827_REQUIRES;
int x_str = w->widget[DYNA_INDU_INFOPANEL].left + 3; int x_str = w->widget[DYNA_INDU_INFOPANEL].left + 3;
int y_str = w->widget[DYNA_INDU_INFOPANEL].top + 3; int y_str = w->widget[DYNA_INDU_INFOPANEL].top + 3;
const Widget *wi = &w->widget[DYNA_INDU_INFOPANEL]; const Widget *wi = &w->widget[DYNA_INDU_INFOPANEL];
@ -190,34 +189,28 @@ static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
} }
/* Draw the accepted cargos, if any. Otherwhise, will print "Nothing" */ /* Draw the accepted cargos, if any. Otherwhise, will print "Nothing" */
if (indsp->accepts_cargo[0] != CT_INVALID) { StringID str = STR_4827_REQUIRES;
SetDParam(0, GetCargo(indsp->accepts_cargo[0])->name); byte p = 0;
if (indsp->accepts_cargo[1] != CT_INVALID) { SetDParam(0, STR_00D0_NOTHING);
SetDParam(1, GetCargo(indsp->accepts_cargo[1])->name); for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) {
str = STR_4828_REQUIRES; if (indsp->accepts_cargo[j] == CT_INVALID) continue;
if (indsp->accepts_cargo[2] != CT_INVALID) { if (p > 0) str++;
SetDParam(2, GetCargo(indsp->accepts_cargo[2])->name); SetDParam(p++, GetCargo(indsp->accepts_cargo[j])->name);
str = STR_4829_REQUIRES;
}
}
} else {
SetDParam(0, STR_00D0_NOTHING);
} }
DrawStringTruncated(x_str, y_str, str, 0, max_width); DrawStringTruncated(x_str, y_str, str, 0, max_width);
y_str += 11; y_str += 11;
/* Draw the produced cargos, if any. Otherwhise, will print "Nothing" */ /* Draw the produced cargos, if any. Otherwhise, will print "Nothing" */
str = STR_4827_PRODUCES; str = STR_4827_PRODUCES;
if (indsp->produced_cargo[0] != CT_INVALID) { p = 0;
SetDParam(0, GetCargo(indsp->produced_cargo[0])->name); SetDParam(0, STR_00D0_NOTHING);
if (indsp->produced_cargo[1] != CT_INVALID) { for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
SetDParam(1, GetCargo(indsp->produced_cargo[1])->name); if (indsp->produced_cargo[j] == CT_INVALID) continue;
str = STR_4828_PRODUCES; if (p > 0) str++;
} SetDParam(p++, GetCargo(indsp->produced_cargo[j])->name);
} else {
SetDParam(0, STR_00D0_NOTHING);
} }
DrawStringTruncated(x_str, y_str, str, 0, max_width); DrawStringTruncated(x_str, y_str, str, 0, max_width);
y_str += 11;
/* Get the additional purchase info text, if it has not already been */ /* Get the additional purchase info text, if it has not already been */
if (_fund_gui.text[WP(w, fnd_d).index] == STR_NULL) { // Have i been called already? if (_fund_gui.text[WP(w, fnd_d).index] == STR_NULL) { // Have i been called already?
@ -230,7 +223,6 @@ static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
} }
} }
y_str += 11;
/* Draw the Additional purchase text, provided by newgrf callback, if any. /* Draw the Additional purchase text, provided by newgrf callback, if any.
* Otherwhise, will print Nothing */ * Otherwhise, will print Nothing */
str = _fund_gui.text[WP(w, fnd_d).index]; str = _fund_gui.text[WP(w, fnd_d).index];
@ -411,27 +403,42 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
const Industry *i = GetIndustry(w->window_number); const Industry *i = GetIndustry(w->window_number);
const IndustrySpec *ind = GetIndustrySpec(i->type); const IndustrySpec *ind = GetIndustrySpec(i->type);
int lines = -3; int lines = -3;
bool first = true;
bool has_accept = false;
if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) { if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) {
for (uint j = 0; j < lengthof(i->accepts_cargo) && i->accepts_cargo[j] != CT_INVALID; j++) { for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
if (j == 0) lines++; if (i->accepts_cargo[j] == CT_INVALID) continue;
has_accept = true;
if (first) {
lines++;
first = false;
}
lines++; lines++;
} }
} else if (i->accepts_cargo[0] != CT_INVALID) { } else {
lines++; for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
if (i->accepts_cargo[j] == CT_INVALID) continue;
has_accept = true;
lines++;
break;
}
} }
for (uint j = 0; j < lengthof(i->produced_cargo) && i->produced_cargo[j] != CT_INVALID; j++) { first = true;
if (j == 0) { for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
if (i->accepts_cargo[0] != CT_INVALID) lines++; if (i->produced_cargo[j] == CT_INVALID) continue;
if (first) {
if (has_accept) lines++;
lines++; lines++;
first = false;
} }
lines++; lines++;
} }
if (HASBIT(ind->callback_flags, CBM_IND_WINDOW_MORE_TEXT)) lines += 2; if (HASBIT(ind->callback_flags, CBM_IND_WINDOW_MORE_TEXT)) lines += 2;
for (uint j = 5; j <= 7; j++) { for (byte j = 5; j <= 7; j++) {
if (j != 5) w->widget[j].top += lines * 10; if (j != 5) w->widget[j].top += lines * 10;
w->widget[j].bottom += lines * 10; w->widget[j].bottom += lines * 10;
} }
@ -442,44 +449,50 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
Industry *i = GetIndustry(w->window_number); Industry *i = GetIndustry(w->window_number);
const IndustrySpec *ind = GetIndustrySpec(i->type); const IndustrySpec *ind = GetIndustrySpec(i->type);
int y = 111; int y = 111;
bool first = true;
bool has_accept = false;
SetDParam(0, w->window_number); SetDParam(0, w->window_number);
DrawWindowWidgets(w); DrawWindowWidgets(w);
if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) { if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) {
for (uint j = 0; j < lengthof(i->accepts_cargo) && i->accepts_cargo[j] != CT_INVALID; j++) { for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
if (j == 0) { if (i->accepts_cargo[j] == CT_INVALID) continue;
has_accept = true;
if (first) {
DrawString(2, y, STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING, 0); DrawString(2, y, STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING, 0);
y += 10; y += 10;
first = false;
} }
SetDParam(0, i->accepts_cargo[j]); SetDParam(0, i->accepts_cargo[j]);
SetDParam(1, i->incoming_cargo_waiting[j]); SetDParam(1, i->incoming_cargo_waiting[j]);
DrawString(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, 0); DrawString(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, 0);
y += 10; y += 10;
} }
} else if (i->accepts_cargo[0] != CT_INVALID) { } else {
StringID str; StringID str = STR_4827_REQUIRES;
byte p = 0;
SetDParam(0, GetCargo(i->accepts_cargo[0])->name); for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
str = STR_4827_REQUIRES; if (i->accepts_cargo[j] == CT_INVALID) continue;
if (i->accepts_cargo[1] != CT_INVALID) { has_accept = true;
SetDParam(1, GetCargo(i->accepts_cargo[1])->name); if (p > 0) str++;
str = STR_4828_REQUIRES; SetDParam(p++, GetCargo(i->accepts_cargo[j])->name);
if (i->accepts_cargo[2] != CT_INVALID) { }
SetDParam(2, GetCargo(i->accepts_cargo[2])->name); if (has_accept) {
str = STR_4829_REQUIRES; DrawString(2, y, str, 0);
} y += 10;
} }
DrawString(2, y, str, 0);
y += 10;
} }
for (uint j = 0; j < lengthof(i->produced_cargo) && i->produced_cargo[j] != CT_INVALID; j++) { first = true;
if (j == 0) { for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
if (i->accepts_cargo[0] != CT_INVALID) y += 10; if (i->produced_cargo[j] == CT_INVALID) continue;
if (first) {
if (has_accept) y += 10;
DrawString(2, y, STR_482A_PRODUCTION_LAST_MONTH, 0); DrawString(2, y, STR_482A_PRODUCTION_LAST_MONTH, 0);
y += 10; y += 10;
WP(w, indview_d).production_offset_y = y; WP(w, indview_d).production_offset_y = y;
first = false;
} }
SetDParam(0, i->produced_cargo[j]); SetDParam(0, i->produced_cargo[j]);