src/industry_gui.cpp
changeset 9169 2dc9af0f4704
parent 9164 18e971e0b44f
child 9173 b38373e203a9
equal deleted inserted replaced
9168:888730a77af3 9169:2dc9af0f4704
   425 	IVW_BACKGROUND,
   425 	IVW_BACKGROUND,
   426 	IVW_VIEWPORT,
   426 	IVW_VIEWPORT,
   427 	IVW_INFO,
   427 	IVW_INFO,
   428 	IVW_GOTO,
   428 	IVW_GOTO,
   429 	IVW_SPACER,
   429 	IVW_SPACER,
       
   430 	IVW_RESIZE,
   430 };
   431 };
   431 
   432 
   432 /** Information to store about the industry window */
   433 /** Information to store about the industry window */
   433 struct indview_d : public vp_d {
   434 struct indview_d : public vp_d {
   434 	byte editbox_line;        ///< The line clicked to open the edit box
   435 	byte editbox_line;        ///< The line clicked to open the edit box
   455 			if (HasBit(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) {
   456 			if (HasBit(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) {
   456 				for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
   457 				for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
   457 					if (i->accepts_cargo[j] == CT_INVALID) continue;
   458 					if (i->accepts_cargo[j] == CT_INVALID) continue;
   458 					has_accept = true;
   459 					has_accept = true;
   459 					if (first) {
   460 					if (first) {
   460 						DrawString(2, y, STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING, TC_FROMSTRING);
   461 						DrawStringTruncated(2, y, STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING, TC_FROMSTRING, w->widget[IVW_INFO].right - 2);
   461 						y += 10;
   462 						y += 10;
   462 						first = false;
   463 						first = false;
   463 					}
   464 					}
   464 					SetDParam(0, i->accepts_cargo[j]);
   465 					SetDParam(0, i->accepts_cargo[j]);
   465 					SetDParam(1, i->incoming_cargo_waiting[j]);
   466 					SetDParam(1, i->incoming_cargo_waiting[j]);
   466 					SetDParam(2, GetCargoSuffix(j, CST_VIEW, i, i->type, ind));
   467 					SetDParam(2, GetCargoSuffix(j, CST_VIEW, i, i->type, ind));
   467 					DrawString(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, TC_FROMSTRING);
   468 					DrawStringTruncated(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, TC_FROMSTRING, w->widget[IVW_INFO].right - 4);
   468 					y += 10;
   469 					y += 10;
   469 				}
   470 				}
   470 			} else {
   471 			} else {
   471 				StringID str = STR_4827_REQUIRES;
   472 				StringID str = STR_4827_REQUIRES;
   472 				byte p = 0;
   473 				byte p = 0;
   476 					if (p > 0) str++;
   477 					if (p > 0) str++;
   477 					SetDParam(p++, GetCargo(i->accepts_cargo[j])->name);
   478 					SetDParam(p++, GetCargo(i->accepts_cargo[j])->name);
   478 					SetDParam(p++, GetCargoSuffix(j, CST_VIEW, i, i->type, ind));
   479 					SetDParam(p++, GetCargoSuffix(j, CST_VIEW, i, i->type, ind));
   479 				}
   480 				}
   480 				if (has_accept) {
   481 				if (has_accept) {
   481 					DrawString(2, y, str, TC_FROMSTRING);
   482 					DrawStringTruncated(2, y, str, TC_FROMSTRING, w->widget[IVW_INFO].right - 2);
   482 					y += 10;
   483 					y += 10;
   483 				}
   484 				}
   484 			}
   485 			}
   485 
   486 
   486 			first = true;
   487 			first = true;
   487 			for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
   488 			for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
   488 				if (i->produced_cargo[j] == CT_INVALID) continue;
   489 				if (i->produced_cargo[j] == CT_INVALID) continue;
   489 				if (first) {
   490 				if (first) {
   490 					if (has_accept) y += 10;
   491 					if (has_accept) y += 10;
   491 					DrawString(2, y, STR_482A_PRODUCTION_LAST_MONTH, TC_FROMSTRING);
   492 					DrawStringTruncated(2, y, STR_482A_PRODUCTION_LAST_MONTH, TC_FROMSTRING, w->widget[IVW_INFO].right - 2);
   492 					y += 10;
   493 					y += 10;
   493 					WP(w, indview_d).production_offset_y = y;
   494 					WP(w, indview_d).production_offset_y = y;
   494 					first = false;
   495 					first = false;
   495 				}
   496 				}
   496 
   497 
   497 				SetDParam(0, i->produced_cargo[j]);
   498 				SetDParam(0, i->produced_cargo[j]);
   498 				SetDParam(1, i->last_month_production[j]);
   499 				SetDParam(1, i->last_month_production[j]);
   499 				SetDParam(2, GetCargoSuffix(j + 3, CST_VIEW, i, i->type, ind));
   500 				SetDParam(2, GetCargoSuffix(j + 3, CST_VIEW, i, i->type, ind));
   500 
   501 
   501 				SetDParam(3, i->last_month_pct_transported[j] * 100 >> 8);
   502 				SetDParam(3, i->last_month_pct_transported[j] * 100 >> 8);
   502 				DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), y, STR_482B_TRANSPORTED, TC_FROMSTRING);
   503 				uint x = 4 + (IsProductionAlterable(i) ? 30 : 0);
       
   504 				DrawStringTruncated(x, y, STR_482B_TRANSPORTED, TC_FROMSTRING, w->widget[IVW_INFO].right - x);
   503 				/* Let's put out those buttons.. */
   505 				/* Let's put out those buttons.. */
   504 				if (IsProductionAlterable(i)) {
   506 				if (IsProductionAlterable(i)) {
   505 					DrawArrowButtons(5, y, 3, (WP(w, indview_d).clicked_line == j + 1) ? WP(w, indview_d).clicked_button : 0,
   507 					DrawArrowButtons(5, y, 3, (WP(w, indview_d).clicked_line == j + 1) ? WP(w, indview_d).clicked_button : 0,
   506 							!IsProductionMinimum(i, j), !IsProductionMaximum(i, j));
   508 							!IsProductionMinimum(i, j), !IsProductionMaximum(i, j));
   507 				}
   509 				}
   590 			WP(w, indview_d).clicked_line = 0;
   592 			WP(w, indview_d).clicked_line = 0;
   591 			WP(w, indview_d).clicked_button = 0;
   593 			WP(w, indview_d).clicked_button = 0;
   592 			w->SetDirty();
   594 			w->SetDirty();
   593 			break;
   595 			break;
   594 
   596 
       
   597 		case WE_RESIZE:
       
   598 			w->viewport->width           += e->we.sizing.diff.x;
       
   599 			w->viewport->height          += e->we.sizing.diff.y;
       
   600 			w->viewport->virtual_width   += e->we.sizing.diff.x;
       
   601 			w->viewport->virtual_height  += e->we.sizing.diff.y;
       
   602 			WP(w, vp_d).dest_scrollpos_x -= e->we.sizing.diff.x;
       
   603 			WP(w, vp_d).dest_scrollpos_y -= e->we.sizing.diff.y;
       
   604 			UpdateViewportPosition(w);
       
   605 			break;
       
   606 
   595 		case WE_ON_EDIT_TEXT:
   607 		case WE_ON_EDIT_TEXT:
   596 			if (!StrEmpty(e->we.edittext.str)) {
   608 			if (!StrEmpty(e->we.edittext.str)) {
   597 				Industry* i = GetIndustry(w->window_number);
   609 				Industry* i = GetIndustry(w->window_number);
   598 				int line = WP(w, indview_d).editbox_line;
   610 				int line = WP(w, indview_d).editbox_line;
   599 
   611 
   614 }
   626 }
   615 
   627 
   616 /** Widget definition of the view industy gui */
   628 /** Widget definition of the view industy gui */
   617 static const Widget _industry_view_widgets[] = {
   629 static const Widget _industry_view_widgets[] = {
   618 {   WWT_CLOSEBOX,   RESIZE_NONE,     9,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},            // IVW_CLOSEBOX
   630 {   WWT_CLOSEBOX,   RESIZE_NONE,     9,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},            // IVW_CLOSEBOX
   619 {    WWT_CAPTION,   RESIZE_NONE,     9,    11,   247,     0,    13, STR_4801,          STR_018C_WINDOW_TITLE_DRAG_THIS},  // IVW_CAPTION
   631 {    WWT_CAPTION,  RESIZE_RIGHT,     9,    11,   247,     0,    13, STR_4801,          STR_018C_WINDOW_TITLE_DRAG_THIS},  // IVW_CAPTION
   620 {  WWT_STICKYBOX,   RESIZE_NONE,     9,   248,   259,     0,    13, 0x0,               STR_STICKY_BUTTON},                // IVW_STICKY
   632 {  WWT_STICKYBOX,     RESIZE_LR,     9,   248,   259,     0,    13, 0x0,               STR_STICKY_BUTTON},                // IVW_STICKY
   621 {      WWT_PANEL,   RESIZE_NONE,     9,     0,   259,    14,   105, 0x0,               STR_NULL},                         // IVW_BACKGROUND
   633 {      WWT_PANEL,     RESIZE_RB,     9,     0,   259,    14,   105, 0x0,               STR_NULL},                         // IVW_BACKGROUND
   622 {      WWT_INSET,   RESIZE_NONE,     9,     2,   257,    16,   103, 0x0,               STR_NULL},                         // IVW_VIEWPORT
   634 {      WWT_INSET,     RESIZE_RB,     9,     2,   257,    16,   103, 0x0,               STR_NULL},                         // IVW_VIEWPORT
   623 {      WWT_PANEL, RESIZE_BOTTOM,     9,     0,   259,   106,   107, 0x0,               STR_NULL},                         // IVW_INFO
   635 {      WWT_PANEL,    RESIZE_RTB,     9,     0,   259,   106,   107, 0x0,               STR_NULL},                         // IVW_INFO
   624 { WWT_PUSHTXTBTN,     RESIZE_TB,     9,     0,   129,   108,   119, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON}, // IVW_GOTO
   636 { WWT_PUSHTXTBTN,     RESIZE_TB,     9,     0,   129,   108,   119, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON}, // IVW_GOTO
   625 {      WWT_PANEL,     RESIZE_TB,     9,   130,   259,   108,   119, 0x0,               STR_NULL},                         // IVW_SPACER
   637 {      WWT_PANEL,    RESIZE_RTB,     9,   130,   247,   108,   119, 0x0,               STR_NULL},                         // IVW_SPACER
       
   638 {  WWT_RESIZEBOX,   RESIZE_LRTB,     9,   248,   259,   108,   119, 0x0,               STR_RESIZE_BUTTON},                // IVW_RESIZE
   626 {   WIDGETS_END},
   639 {   WIDGETS_END},
   627 };
   640 };
   628 
   641 
   629 /** Window definition of the view industy gui */
   642 /** Window definition of the view industy gui */
   630 static const WindowDesc _industry_view_desc = {
   643 static const WindowDesc _industry_view_desc = {
   631 	WDP_AUTO, WDP_AUTO, 260, 120, 260, 120,
   644 	WDP_AUTO, WDP_AUTO, 260, 120, 260, 120,
   632 	WC_INDUSTRY_VIEW, WC_NONE,
   645 	WC_INDUSTRY_VIEW, WC_NONE,
   633 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
   646 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   634 	_industry_view_widgets,
   647 	_industry_view_widgets,
   635 	IndustryViewWndProc
   648 	IndustryViewWndProc
   636 };
   649 };
   637 
   650 
   638 void ShowIndustryViewWindow(int industry)
   651 void ShowIndustryViewWindow(int industry)