src/industry_gui.cpp
changeset 8759 dc74629e649f
parent 8476 513c39859cb6
child 8779 038e02efbc0a
equal deleted inserted replaced
8758:d2655b49862b 8759:dc74629e649f
    58 } _fund_gui;
    58 } _fund_gui;
    59 
    59 
    60 assert_compile(lengthof(_fund_gui.index) == lengthof(_fund_gui.text));
    60 assert_compile(lengthof(_fund_gui.index) == lengthof(_fund_gui.text));
    61 assert_compile(lengthof(_fund_gui.index) == lengthof(_fund_gui.enabled));
    61 assert_compile(lengthof(_fund_gui.index) == lengthof(_fund_gui.enabled));
    62 
    62 
       
    63 /**
       
    64  * Gets the string to display after the cargo name (using callback 37)
       
    65  * @param cargo the cargo for which the suffix is requested
       
    66  * - 00 - first accepted cargo type
       
    67  * - 01 - second accepted cargo type
       
    68  * - 02 - third accepted cargo type
       
    69  * - 03 - first produced cargo type
       
    70  * - 04 - second produced cargo type
       
    71  * @param ind the industry (NULL if in fund window)
       
    72  * @param ind_type the industry type
       
    73  * @param indspec the industry spec
       
    74  * @return the string to display
       
    75  */
       
    76 static StringID GetCargoSuffix(uint cargo, Industry *ind, IndustryType ind_type, const IndustrySpec *indspec)
       
    77 {
       
    78 	if (HasBit(indspec->callback_flags, CBM_IND_CARGO_SUFFIX)) {
       
    79 		bool fund = ind == NULL;
       
    80 		uint8 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, ((!fund) ? 1 << 8 : 0) | cargo, ind, ind_type, (!fund) ? ind->xy : INVALID_TILE);
       
    81 		if (callback != 0xFF) return GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback);
       
    82 	}
       
    83 	return STR_EMPTY;
       
    84 }
       
    85 
    63 static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
    86 static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
    64 {
    87 {
    65 	switch (e->event) {
    88 	switch (e->event) {
    66 		case WE_CREATE: {
    89 		case WE_CREATE: {
    67 			IndustryType ind;
    90 			IndustryType ind;
   177 
   200 
   178 			/* Draw the accepted cargos, if any. Otherwhise, will print "Nothing" */
   201 			/* Draw the accepted cargos, if any. Otherwhise, will print "Nothing" */
   179 			StringID str = STR_4827_REQUIRES;
   202 			StringID str = STR_4827_REQUIRES;
   180 			byte p = 0;
   203 			byte p = 0;
   181 			SetDParam(0, STR_00D0_NOTHING);
   204 			SetDParam(0, STR_00D0_NOTHING);
       
   205 			SetDParam(1, STR_EMPTY);
   182 			for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) {
   206 			for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) {
   183 				if (indsp->accepts_cargo[j] == CT_INVALID) continue;
   207 				if (indsp->accepts_cargo[j] == CT_INVALID) continue;
   184 				if (p > 0) str++;
   208 				if (p > 0) str++;
   185 				SetDParam(p++, GetCargo(indsp->accepts_cargo[j])->name);
   209 				SetDParam(p++, GetCargo(indsp->accepts_cargo[j])->name);
       
   210 				SetDParam(p++, GetCargoSuffix(j, NULL, WP(w, fnd_d).select, indsp));
   186 			}
   211 			}
   187 			DrawStringTruncated(x_str, y_str, str, TC_FROMSTRING, max_width);
   212 			DrawStringTruncated(x_str, y_str, str, TC_FROMSTRING, max_width);
   188 			y_str += 11;
   213 			y_str += 11;
   189 
   214 
   190 			/* Draw the produced cargos, if any. Otherwhise, will print "Nothing" */
   215 			/* Draw the produced cargos, if any. Otherwhise, will print "Nothing" */
   191 			str = STR_4827_PRODUCES;
   216 			str = STR_4827_PRODUCES;
   192 			p = 0;
   217 			p = 0;
   193 			SetDParam(0, STR_00D0_NOTHING);
   218 			SetDParam(0, STR_00D0_NOTHING);
       
   219 			SetDParam(1, STR_EMPTY);
   194 			for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
   220 			for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
   195 				if (indsp->produced_cargo[j] == CT_INVALID) continue;
   221 				if (indsp->produced_cargo[j] == CT_INVALID) continue;
   196 				if (p > 0) str++;
   222 				if (p > 0) str++;
   197 				SetDParam(p++, GetCargo(indsp->produced_cargo[j])->name);
   223 				SetDParam(p++, GetCargo(indsp->produced_cargo[j])->name);
       
   224 				SetDParam(p++, GetCargoSuffix(j + 3, NULL, WP(w, fnd_d).select, indsp));
   198 			}
   225 			}
   199 			DrawStringTruncated(x_str, y_str, str, TC_FROMSTRING, max_width);
   226 			DrawStringTruncated(x_str, y_str, str, TC_FROMSTRING, max_width);
   200 			y_str += 11;
   227 			y_str += 11;
   201 
   228 
   202 			/* Get the additional purchase info text, if it has not already been */
   229 			/* Get the additional purchase info text, if it has not already been */
   487 					y += 10;
   514 					y += 10;
   488 					first = false;
   515 					first = false;
   489 				}
   516 				}
   490 				SetDParam(0, i->accepts_cargo[j]);
   517 				SetDParam(0, i->accepts_cargo[j]);
   491 				SetDParam(1, i->incoming_cargo_waiting[j]);
   518 				SetDParam(1, i->incoming_cargo_waiting[j]);
       
   519 				SetDParam(2, GetCargoSuffix(j, i, i->type, ind));
   492 				DrawString(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, TC_FROMSTRING);
   520 				DrawString(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, TC_FROMSTRING);
   493 				y += 10;
   521 				y += 10;
   494 			}
   522 			}
   495 		} else {
   523 		} else {
   496 			StringID str = STR_4827_REQUIRES;
   524 			StringID str = STR_4827_REQUIRES;
   498 			for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
   526 			for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
   499 				if (i->accepts_cargo[j] == CT_INVALID) continue;
   527 				if (i->accepts_cargo[j] == CT_INVALID) continue;
   500 				has_accept = true;
   528 				has_accept = true;
   501 				if (p > 0) str++;
   529 				if (p > 0) str++;
   502 				SetDParam(p++, GetCargo(i->accepts_cargo[j])->name);
   530 				SetDParam(p++, GetCargo(i->accepts_cargo[j])->name);
       
   531 				SetDParam(p++, GetCargoSuffix(j, i, i->type, ind));
   503 			}
   532 			}
   504 			if (has_accept) {
   533 			if (has_accept) {
   505 				DrawString(2, y, str, TC_FROMSTRING);
   534 				DrawString(2, y, str, TC_FROMSTRING);
   506 				y += 10;
   535 				y += 10;
   507 			}
   536 			}
   518 				first = false;
   547 				first = false;
   519 			}
   548 			}
   520 
   549 
   521 			SetDParam(0, i->produced_cargo[j]);
   550 			SetDParam(0, i->produced_cargo[j]);
   522 			SetDParam(1, i->last_month_production[j]);
   551 			SetDParam(1, i->last_month_production[j]);
   523 
   552 			SetDParam(2, GetCargoSuffix(j + 3, i, i->type, ind));
   524 			SetDParam(2, i->last_month_pct_transported[j] * 100 >> 8);
   553 
       
   554 			SetDParam(3, i->last_month_pct_transported[j] * 100 >> 8);
   525 			DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), y, STR_482B_TRANSPORTED, TC_FROMSTRING);
   555 			DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), y, STR_482B_TRANSPORTED, TC_FROMSTRING);
   526 			/* Let's put out those buttons.. */
   556 			/* Let's put out those buttons.. */
   527 			if (IsProductionAlterable(i)) {
   557 			if (IsProductionAlterable(i)) {
   528 				DrawArrowButtons(5, y, 3, (WP(w, indview_d).clicked_line == j + 1) ? WP(w, indview_d).clicked_button : 0,
   558 				DrawArrowButtons(5, y, 3, (WP(w, indview_d).clicked_line == j + 1) ? WP(w, indview_d).clicked_button : 0,
   529 						!isProductionMinimum(i, j), !isProductionMaximum(i, j));
   559 						!isProductionMinimum(i, j), !isProductionMaximum(i, j));