src/industry_gui.cpp
branchgamebalance
changeset 9910 0b2aebc8283e
parent 9903 dc85aaa556ae
child 9911 0b8b245a2391
equal deleted inserted replaced
9909:dce9a6923bb7 9910:0b2aebc8283e
    35 {
    35 {
    36 	switch (e->event) {
    36 	switch (e->event) {
    37 	case WE_PAINT:
    37 	case WE_PAINT:
    38 		DrawWindowWidgets(w);
    38 		DrawWindowWidgets(w);
    39 		if (_thd.place_mode == 1 && _thd.window_class == WC_BUILD_INDUSTRY) {
    39 		if (_thd.place_mode == 1 && _thd.window_class == WC_BUILD_INDUSTRY) {
    40 			int ind_type = _build_industry_types[_opt_ptr->landscape][WP(w,def_d).data_1];
    40 			int ind_type = _build_industry_types[_opt_ptr->landscape][WP(w, def_d).data_1];
    41 
    41 
    42 			SetDParam(0, (_eco->GetPrice(CEconomy::BUILD_INDUSTRY) >> 5) * GetIndustrySpec(ind_type)->cost_multiplier);
    42 			SetDParam(0, (_eco->GetPrice(CEconomy::BUILD_INDUSTRY) >> 5) * GetIndustrySpec(ind_type)->cost_multiplier);
    43 			DrawStringCentered(85, w->height - 21, STR_482F_COST, 0);
    43 			DrawStringCentered(85, w->height - 21, STR_482F_COST, 0);
    44 		}
    44 		}
    45 		break;
    45 		break;
    46 
    46 
    47 	case WE_CLICK: {
    47 	case WE_CLICK: {
    48 		int wid = e->we.click.widget;
    48 		int wid = e->we.click.widget;
    49 		if (wid >= 3) {
    49 		if (wid >= 3) {
    50 			if (HandlePlacePushButton(w, wid, SPR_CURSOR_INDUSTRY, 1, NULL))
    50 			if (HandlePlacePushButton(w, wid, SPR_CURSOR_INDUSTRY, 1, NULL))
    51 				WP(w,def_d).data_1 = wid - 3;
    51 				WP(w, def_d).data_1 = wid - 3;
    52 		}
    52 		}
    53 	} break;
    53 	} break;
    54 
    54 
    55 	case WE_PLACE_OBJ:
    55 	case WE_PLACE_OBJ:
    56 		if (DoCommandP(e->we.place.tile, _build_industry_types[_opt_ptr->landscape][WP(w,def_d).data_1], 0, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY)))
    56 		if (DoCommandP(e->we.place.tile, _build_industry_types[_opt_ptr->landscape][WP(w, def_d).data_1], 0, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY)))
    57 			ResetObjectToPlace();
    57 			ResetObjectToPlace();
    58 		break;
    58 		break;
    59 
    59 
    60 	case WE_ABORT_PLACE_OBJ:
    60 	case WE_ABORT_PLACE_OBJ:
    61 		RaiseWindowButtons(w);
    61 		RaiseWindowButtons(w);
   272 };
   272 };
   273 
   273 
   274 void ShowBuildIndustryWindow()
   274 void ShowBuildIndustryWindow()
   275 {
   275 {
   276 	if (!IsValidPlayer(_current_player)) return;
   276 	if (!IsValidPlayer(_current_player)) return;
   277 	AllocateWindowDescFront(_industry_window_desc[_patches.build_rawmaterial_ind][_opt_ptr->landscape],0);
   277 	AllocateWindowDescFront(_industry_window_desc[_patches.build_rawmaterial_ind][_opt_ptr->landscape], 0);
   278 }
   278 }
   279 
   279 
   280 static inline bool isProductionMinimum(const Industry *i, int pt) {
   280 static inline bool isProductionMinimum(const Industry *i, int pt) {
   281 	return i->production_rate[pt] == 1;
   281 	return i->production_rate[pt] == 1;
   282 }
   282 }
   328 
   328 
   329 			SetDParam(2, i->pct_transported[0] * 100 >> 8);
   329 			SetDParam(2, i->pct_transported[0] * 100 >> 8);
   330 			DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 127, STR_482B_TRANSPORTED, 0);
   330 			DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 127, STR_482B_TRANSPORTED, 0);
   331 			/* Let's put out those buttons.. */
   331 			/* Let's put out those buttons.. */
   332 			if (IsProductionAlterable(i)) {
   332 			if (IsProductionAlterable(i)) {
   333 				DrawArrowButtons(5, 127, 3, (WP(w,vp2_d).data_2 == 1) ? WP(w,vp2_d).data_3 : 0,
   333 				DrawArrowButtons(5, 127, 3, (WP(w, vp2_d).data_2 == 1) ? WP(w, vp2_d).data_3 : 0,
   334 						!isProductionMinimum(i, 0), !isProductionMaximum(i, 0));
   334 						!isProductionMinimum(i, 0), !isProductionMaximum(i, 0));
   335 			}
   335 			}
   336 
   336 
   337 			if (i->produced_cargo[1] != CT_INVALID) {
   337 			if (i->produced_cargo[1] != CT_INVALID) {
   338 				SetDParam(0, i->produced_cargo[1]);
   338 				SetDParam(0, i->produced_cargo[1]);
   339 				SetDParam(1, i->total_production[1]);
   339 				SetDParam(1, i->total_production[1]);
   340 				SetDParam(2, i->pct_transported[1] * 100 >> 8);
   340 				SetDParam(2, i->pct_transported[1] * 100 >> 8);
   341 				DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 137, STR_482B_TRANSPORTED, 0);
   341 				DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 137, STR_482B_TRANSPORTED, 0);
   342 				/* Let's put out those buttons.. */
   342 				/* Let's put out those buttons.. */
   343 				if (IsProductionAlterable(i)) {
   343 				if (IsProductionAlterable(i)) {
   344 					DrawArrowButtons(5, 137, 3, (WP(w,vp2_d).data_2 == 2) ? WP(w,vp2_d).data_3 : 0,
   344 					DrawArrowButtons(5, 137, 3, (WP(w, vp2_d).data_2 == 2) ? WP(w, vp2_d).data_3 : 0,
   345 						!isProductionMinimum(i, 1), !isProductionMaximum(i, 1));
   345 						!isProductionMinimum(i, 1), !isProductionMaximum(i, 1));
   346 				}
   346 				}
   347 			}
   347 			}
   348 		}
   348 		}
   349 
   349 
   377 					}
   377 					}
   378 
   378 
   379 					UpdateIndustryProduction(i);
   379 					UpdateIndustryProduction(i);
   380 					SetWindowDirty(w);
   380 					SetWindowDirty(w);
   381 					w->flags4 |= 5 << WF_TIMEOUT_SHL;
   381 					w->flags4 |= 5 << WF_TIMEOUT_SHL;
   382 					WP(w,vp2_d).data_2 = line+1;
   382 					WP(w, vp2_d).data_2 = line + 1;
   383 					WP(w,vp2_d).data_3 = (x < 15 ? 1 : 2);
   383 					WP(w, vp2_d).data_3 = (x < 15 ? 1 : 2);
   384 				} else if (IS_INT_INSIDE(x, 34, 160)) {
   384 				} else if (IS_INT_INSIDE(x, 34, 160)) {
   385 					/* clicked the text */
   385 					/* clicked the text */
   386 					WP(w,vp2_d).data_1 = line;
   386 					WP(w, vp2_d).data_1 = line;
   387 					SetDParam(0, i->production_rate[line] * 8);
   387 					SetDParam(0, i->production_rate[line] * 8);
   388 					ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_GAME_PRODUCTION, 10, 100, w, CS_ALPHANUMERAL);
   388 					ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_GAME_PRODUCTION, 10, 100, w, CS_ALPHANUMERAL);
   389 				}
   389 				}
   390 			}
   390 			}
   391 		} break;
   391 		} break;
   392 		case 6:
   392 		case 6:
   393 			i = GetIndustry(w->window_number);
   393 			i = GetIndustry(w->window_number);
   394 			ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
   394 			ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
   395 		}	break;
   395 		} break;
   396 
   396 
   397 		}
   397 		}
   398 		break;
   398 		break;
   399 	case WE_TIMEOUT:
   399 	case WE_TIMEOUT:
   400 		WP(w,vp2_d).data_2 = 0;
   400 		WP(w, vp2_d).data_2 = 0;
   401 		WP(w,vp2_d).data_3 = 0;
   401 		WP(w, vp2_d).data_3 = 0;
   402 		SetWindowDirty(w);
   402 		SetWindowDirty(w);
   403 		break;
   403 		break;
   404 
   404 
   405 	case WE_ON_EDIT_TEXT:
   405 	case WE_ON_EDIT_TEXT:
   406 		if (e->we.edittext.str[0] != '\0') {
   406 		if (e->we.edittext.str[0] != '\0') {
   407 			Industry* i = GetIndustry(w->window_number);
   407 			Industry* i = GetIndustry(w->window_number);
   408 			int line = WP(w,vp2_d).data_1;
   408 			int line = WP(w, vp2_d).data_1;
   409 
   409 
   410 			i->production_rate[line] = clampu(atoi(e->we.edittext.str), 0, 255);
   410 			i->production_rate[line] = clampu(atoi(e->we.edittext.str), 0, 255);
   411 			UpdateIndustryProduction(i);
   411 			UpdateIndustryProduction(i);
   412 			SetWindowDirty(w);
   412 			SetWindowDirty(w);
   413 		}
   413 		}
   447 {
   447 {
   448 	Window *w = AllocateWindowDescFront(&_industry_view_desc, industry);
   448 	Window *w = AllocateWindowDescFront(&_industry_view_desc, industry);
   449 
   449 
   450 	if (w != NULL) {
   450 	if (w != NULL) {
   451 		w->flags4 |= WF_DISABLE_VP_SCROLL;
   451 		w->flags4 |= WF_DISABLE_VP_SCROLL;
   452 		WP(w,vp2_d).data_1 = 0;
   452 		WP(w, vp2_d).data_1 = 0;
   453 		WP(w,vp2_d).data_2 = 0;
   453 		WP(w, vp2_d).data_2 = 0;
   454 		WP(w,vp2_d).data_3 = 0;
   454 		WP(w, vp2_d).data_3 = 0;
   455 		AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetIndustry(w->window_number)->xy + TileDiffXY(1, 1), 1);
   455 		AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetIndustry(w->window_number)->xy + TileDiffXY(1, 1), 1);
   456 	}
   456 	}
   457 }
   457 }
   458 
   458 
   459 static const Widget _industry_directory_widgets[] = {
   459 static const Widget _industry_directory_widgets[] = {
   597 		}
   597 		}
   598 
   598 
   599 		SetVScrollCount(w, _num_industry_sort);
   599 		SetVScrollCount(w, _num_industry_sort);
   600 
   600 
   601 		DrawWindowWidgets(w);
   601 		DrawWindowWidgets(w);
   602 		DoDrawString(_industry_sort_order & 1 ? DOWNARROW : UPARROW, _indicator_positions[_industry_sort_order>>1], 15, 0x10);
   602 		DoDrawString(_industry_sort_order & 1 ? DOWNARROW : UPARROW, _indicator_positions[_industry_sort_order >> 1], 15, 0x10);
   603 
   603 
   604 		p = w->vscroll.pos;
   604 		p = w->vscroll.pos;
   605 		n = 0;
   605 		n = 0;
   606 
   606 
   607 		while (p < _num_industry_sort) {
   607 		while (p < _num_industry_sort) {
   615 				if (i->produced_cargo[1] != CT_INVALID) {
   615 				if (i->produced_cargo[1] != CT_INVALID) {
   616 					SetDParam(3, i->produced_cargo[1]);
   616 					SetDParam(3, i->produced_cargo[1]);
   617 					SetDParam(4, i->total_production[1]);
   617 					SetDParam(4, i->total_production[1]);
   618 					SetDParam(5, i->pct_transported[0] * 100 >> 8);
   618 					SetDParam(5, i->pct_transported[0] * 100 >> 8);
   619 					SetDParam(6, i->pct_transported[1] * 100 >> 8);
   619 					SetDParam(6, i->pct_transported[1] * 100 >> 8);
   620 					DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM_TWO, 0);
   620 					DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM_TWO, 0);
   621 				} else {
   621 				} else {
   622 					SetDParam(3, i->pct_transported[0] * 100 >> 8);
   622 					SetDParam(3, i->pct_transported[0] * 100 >> 8);
   623 					DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM, 0);
   623 					DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM, 0);
   624 				}
   624 				}
   625 			} else {
   625 			} else {
   626 				DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM_NOPROD, 0);
   626 				DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM_NOPROD, 0);
   627 			}
   627 			}
   628 			p++;
   628 			p++;
   629 			if (++n == w->vscroll.cap) break;
   629 			if (++n == w->vscroll.cap) break;
   630 		}
   630 		}
   631 	} break;
   631 	} break;
   632 
   632 
   633 	case WE_CLICK:
   633 	case WE_CLICK:
   634 		switch (e->we.click.widget) {
   634 		switch (e->we.click.widget) {
   635 		case 3: {
   635 		case 3: {
   636 			_industry_sort_order = _industry_sort_order==0 ? 1 : 0;
   636 			_industry_sort_order = _industry_sort_order == 0 ? 1 : 0;
   637 			_industry_sort_dirty = true;
   637 			_industry_sort_dirty = true;
   638 			SetWindowDirty(w);
   638 			SetWindowDirty(w);
   639 		} break;
   639 		} break;
   640 
   640 
   641 		case 4: {
   641 		case 4: {
   642 			_industry_sort_order = _industry_sort_order==2 ? 3 : 2;
   642 			_industry_sort_order = _industry_sort_order == 2 ? 3 : 2;
   643 			_industry_sort_dirty = true;
   643 			_industry_sort_dirty = true;
   644 			SetWindowDirty(w);
   644 			SetWindowDirty(w);
   645 		} break;
   645 		} break;
   646 
   646 
   647 		case 5: {
   647 		case 5: {
   648 			_industry_sort_order = _industry_sort_order==4 ? 5 : 4;
   648 			_industry_sort_order = _industry_sort_order == 4 ? 5 : 4;
   649 			_industry_sort_dirty = true;
   649 			_industry_sort_dirty = true;
   650 			SetWindowDirty(w);
   650 			SetWindowDirty(w);
   651 		} break;
   651 		} break;
   652 
   652 
   653 		case 6: {
   653 		case 6: {
   654 			_industry_sort_order = _industry_sort_order==6 ? 7 : 6;
   654 			_industry_sort_order = _industry_sort_order == 6 ? 7 : 6;
   655 			_industry_sort_dirty = true;
   655 			_industry_sort_dirty = true;
   656 			SetWindowDirty(w);
   656 			SetWindowDirty(w);
   657 		} break;
   657 		} break;
   658 
   658 
   659 		case 8: {
   659 		case 8: {