src/industry_gui.cpp
changeset 8047 50d438fdf470
parent 8040 92c69fcd0d61
child 8049 4182740f3d82
equal deleted inserted replaced
8046:65332c1c99d2 8047:50d438fdf470
    50 {
    50 {
    51 	return CircularTileSearch(tile, 9, SearchTileForIndustry, type);
    51 	return CircularTileSearch(tile, 9, SearchTileForIndustry, type);
    52 }
    52 }
    53 bool _ignore_restrictions;
    53 bool _ignore_restrictions;
    54 
    54 
    55 enum {
    55 /** Names of the widgets of the dynamic place industries gui */
    56 	DYNA_INDU_MATRIX_WIDGET = 2,
    56 enum DynamicPlaceIndustriesWidgets {
    57 	DYNA_INDU_INFOPANEL = 4,
    57 	DPIW_CLOSEBOX = 0,
    58 	DYNA_INDU_FUND_WIDGET,
    58 	DPIW_CAPTION,
    59 	DYNA_INDU_RESIZE_WIDGET,
    59 	DPIW_MATRIX_WIDGET,
       
    60 	DPIW_SCROLLBAR,
       
    61 	DPIW_INFOPANEL,
       
    62 	DPIW_FUND_WIDGET,
       
    63 	DPIW_RESIZE_WIDGET,
    60 };
    64 };
    61 
    65 
    62 /** Attached struct to the window extended data */
    66 /** Attached struct to the window extended data */
    63 struct fnd_d {
    67 struct fnd_d {
    64 	int index;             ///< index of the element in the matrix
    68 	int index;             ///< index of the element in the matrix
    85 
    89 
    86 			/* Shorten the window to the equivalant of the additionnal purchase
    90 			/* Shorten the window to the equivalant of the additionnal purchase
    87 			 * info coming from the callback.  SO it will only be available to tis full
    91 			 * info coming from the callback.  SO it will only be available to tis full
    88 			 * height when newindistries are loaded */
    92 			 * height when newindistries are loaded */
    89 			if (!_loaded_newgrf_features.has_newindustries) {
    93 			if (!_loaded_newgrf_features.has_newindustries) {
    90 				w->widget[DYNA_INDU_INFOPANEL].bottom -= 44;
    94 				w->widget[DPIW_INFOPANEL].bottom -= 44;
    91 				w->widget[DYNA_INDU_FUND_WIDGET].bottom -= 44;
    95 				w->widget[DPIW_FUND_WIDGET].bottom -= 44;
    92 				w->widget[DYNA_INDU_FUND_WIDGET].top -= 44;
    96 				w->widget[DPIW_FUND_WIDGET].top -= 44;
    93 				w->widget[DYNA_INDU_RESIZE_WIDGET].bottom -= 44;
    97 				w->widget[DPIW_RESIZE_WIDGET].bottom -= 44;
    94 				w->widget[DYNA_INDU_RESIZE_WIDGET].top -= 44;
    98 				w->widget[DPIW_RESIZE_WIDGET].top -= 44;
    95 				w->resize.height = w->height -= 44;
    99 				w->resize.height = w->height -= 44;
    96 			}
   100 			}
    97 
   101 
    98 			WP(w, fnd_d).timer_enabled = _loaded_newgrf_features.has_newindustries;
   102 			WP(w, fnd_d).timer_enabled = _loaded_newgrf_features.has_newindustries;
    99 
   103 
   136 			WP(w, fnd_d).callback_timer = DAY_TICKS;
   140 			WP(w, fnd_d).callback_timer = DAY_TICKS;
   137 		} break;
   141 		} break;
   138 
   142 
   139 		case WE_PAINT: {
   143 		case WE_PAINT: {
   140 			const IndustrySpec *indsp = (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(WP(w, fnd_d).select);
   144 			const IndustrySpec *indsp = (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(WP(w, fnd_d).select);
   141 			int x_str = w->widget[DYNA_INDU_INFOPANEL].left + 3;
   145 			int x_str = w->widget[DPIW_INFOPANEL].left + 3;
   142 			int y_str = w->widget[DYNA_INDU_INFOPANEL].top + 3;
   146 			int y_str = w->widget[DPIW_INFOPANEL].top + 3;
   143 			const Widget *wi = &w->widget[DYNA_INDU_INFOPANEL];
   147 			const Widget *wi = &w->widget[DPIW_INFOPANEL];
   144 			int max_width = wi->right - wi->left - 4;
   148 			int max_width = wi->right - wi->left - 4;
   145 
   149 
   146 			/* Raw industries might be prospected. Show this fact by changing the string
   150 			/* Raw industries might be prospected. Show this fact by changing the string
   147 			 * In Editor, you just build, while ingame, or you fund or you prospect */
   151 			 * In Editor, you just build, while ingame, or you fund or you prospect */
   148 			if (_game_mode == GM_EDITOR) {
   152 			if (_game_mode == GM_EDITOR) {
   149 				/* We've chosen many random industries but no industries have been specified */
   153 				/* We've chosen many random industries but no industries have been specified */
   150 				if (indsp == NULL) _fund_gui.enabled[WP(w, fnd_d).index] = _opt.diff.number_industries != 0;
   154 				if (indsp == NULL) _fund_gui.enabled[WP(w, fnd_d).index] = _opt.diff.number_industries != 0;
   151 				w->widget[DYNA_INDU_FUND_WIDGET].data = STR_BUILD_NEW_INDUSTRY;
   155 				w->widget[DPIW_FUND_WIDGET].data = STR_BUILD_NEW_INDUSTRY;
   152 			} else {
   156 			} else {
   153 				w->widget[DYNA_INDU_FUND_WIDGET].data = (_patches.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_PROSPECT_NEW_INDUSTRY : STR_FUND_NEW_INDUSTRY;
   157 				w->widget[DPIW_FUND_WIDGET].data = (_patches.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_PROSPECT_NEW_INDUSTRY : STR_FUND_NEW_INDUSTRY;
   154 			}
   158 			}
   155 			w->SetWidgetDisabledState(DYNA_INDU_FUND_WIDGET, !_fund_gui.enabled[WP(w, fnd_d).index]);
   159 			w->SetWidgetDisabledState(DPIW_FUND_WIDGET, !_fund_gui.enabled[WP(w, fnd_d).index]);
   156 
   160 
   157 			SetVScrollCount(w, _fund_gui.count);
   161 			SetVScrollCount(w, _fund_gui.count);
   158 
   162 
   159 			DrawWindowWidgets(w);
   163 			DrawWindowWidgets(w);
   160 
   164 
   230 				SetDParam(0, str);
   234 				SetDParam(0, str);
   231 				DrawStringMultiLine(x_str, y_str, STR_JUST_STRING, max_width, wi->bottom - wi->top - 40);
   235 				DrawStringMultiLine(x_str, y_str, STR_JUST_STRING, max_width, wi->bottom - wi->top - 40);
   232 			}
   236 			}
   233 		} break;
   237 		} break;
   234 
   238 
       
   239 		case WE_DOUBLE_CLICK:
       
   240 			if (e->we.click.widget != DPIW_MATRIX_WIDGET) break;
       
   241 			e->we.click.widget = DPIW_FUND_WIDGET;
       
   242 			/* Fall through */
       
   243 
   235 		case WE_CLICK:
   244 		case WE_CLICK:
   236 			switch (e->we.click.widget) {
   245 			switch (e->we.click.widget) {
   237 				case DYNA_INDU_MATRIX_WIDGET: {
   246 				case DPIW_MATRIX_WIDGET: {
   238 					const IndustrySpec *indsp;
   247 					const IndustrySpec *indsp;
   239 					int y = (e->we.click.pt.y - w->widget[DYNA_INDU_MATRIX_WIDGET].top) / 13 + w->vscroll.pos ;
   248 					int y = (e->we.click.pt.y - w->widget[DPIW_MATRIX_WIDGET].top) / 13 + w->vscroll.pos ;
   240 
   249 
   241 					if (y >= 0 && y < _fund_gui.count) { // Is it within the boundaries of available data?
   250 					if (y >= 0 && y < _fund_gui.count) { // Is it within the boundaries of available data?
   242 						WP(w, fnd_d).index = y;
   251 						WP(w, fnd_d).index = y;
   243 						WP(w, fnd_d).select = _fund_gui.index[WP(w, fnd_d).index];
   252 						WP(w, fnd_d).select = _fund_gui.index[WP(w, fnd_d).index];
   244 						indsp = (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(WP(w, fnd_d).select);
   253 						indsp = (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(WP(w, fnd_d).select);
   252 							ResetObjectToPlace();
   261 							ResetObjectToPlace();
   253 						}
   262 						}
   254 					}
   263 					}
   255 				} break;
   264 				} break;
   256 
   265 
   257 				case DYNA_INDU_FUND_WIDGET: {
   266 				case DPIW_FUND_WIDGET: {
   258 					if (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) {
   267 					if (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) {
   259 						w->HandleButtonClick(DYNA_INDU_FUND_WIDGET);
   268 						w->HandleButtonClick(DPIW_FUND_WIDGET);
   260 
   269 
   261 						if (GetNumTowns() == 0) {
   270 						if (GetNumTowns() == 0) {
   262 							ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_CAN_T_GENERATE_INDUSTRIES, 0, 0);
   271 							ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_CAN_T_GENERATE_INDUSTRIES, 0, 0);
   263 						} else {
   272 						} else {
   264 							extern void GenerateIndustries();
   273 							extern void GenerateIndustries();
   266 							GenerateIndustries();
   275 							GenerateIndustries();
   267 							_generating_world = false;
   276 							_generating_world = false;
   268 						}
   277 						}
   269 					} else if (_game_mode != GM_EDITOR && _patches.raw_industry_construction == 2 && GetIndustrySpec(WP(w, fnd_d).select)->IsRawIndustry()) {
   278 					} else if (_game_mode != GM_EDITOR && _patches.raw_industry_construction == 2 && GetIndustrySpec(WP(w, fnd_d).select)->IsRawIndustry()) {
   270 						DoCommandP(0, WP(w, fnd_d).select, 0, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
   279 						DoCommandP(0, WP(w, fnd_d).select, 0, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
   271 						w->HandleButtonClick(DYNA_INDU_FUND_WIDGET);
   280 						w->HandleButtonClick(DPIW_FUND_WIDGET);
   272 					} else {
   281 					} else {
   273 						HandlePlacePushButton(w, DYNA_INDU_FUND_WIDGET, SPR_CURSOR_INDUSTRY, VHM_RECT, NULL);
   282 						HandlePlacePushButton(w, DPIW_FUND_WIDGET, SPR_CURSOR_INDUSTRY, VHM_RECT, NULL);
   274 					}
   283 					}
   275 				} break;
   284 				} break;
   276 			}
   285 			}
   277 			break;
   286 			break;
   278 
   287 
   279 		case WE_RESIZE: {
   288 		case WE_RESIZE: {
   280 			/* Adjust the number of items in the matrix depending of the rezise */
   289 			/* Adjust the number of items in the matrix depending of the rezise */
   281 			w->vscroll.cap  += e->we.sizing.diff.y / (int)w->resize.step_height;
   290 			w->vscroll.cap  += e->we.sizing.diff.y / (int)w->resize.step_height;
   282 			w->widget[DYNA_INDU_MATRIX_WIDGET].data = (w->vscroll.cap << 8) + 1;
   291 			w->widget[DPIW_MATRIX_WIDGET].data = (w->vscroll.cap << 8) + 1;
   283 		} break;
   292 		} break;
   284 
   293 
   285 		case WE_PLACE_OBJ: {
   294 		case WE_PLACE_OBJ: {
   286 			bool success = true;
   295 			bool success = true;
   287 			/* We do not need to protect ourselves against "Random Many Industries" in this mode */
   296 			/* We do not need to protect ourselves against "Random Many Industries" in this mode */
   340 			w->RaiseButtons();
   349 			w->RaiseButtons();
   341 			break;
   350 			break;
   342 	}
   351 	}
   343 }
   352 }
   344 
   353 
       
   354 /** Widget definition of the dynamic place industries gui */
   345 static const Widget _build_dynamic_industry_widgets[] = {
   355 static const Widget _build_dynamic_industry_widgets[] = {
   346 {   WWT_CLOSEBOX,    RESIZE_NONE,    7,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},
   356 {   WWT_CLOSEBOX,    RESIZE_NONE,    7,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},            // DPIW_CLOSEBOX
   347 {    WWT_CAPTION,   RESIZE_RIGHT,    7,    11,   169,     0,    13, STR_0314_FUND_NEW_INDUSTRY,     STR_018C_WINDOW_TITLE_DRAG_THIS},
   357 {    WWT_CAPTION,   RESIZE_RIGHT,    7,    11,   169,     0,    13, STR_0314_FUND_NEW_INDUSTRY,     STR_018C_WINDOW_TITLE_DRAG_THIS},  // DPIW_CAPTION
   348 {     WWT_MATRIX,      RESIZE_RB,    7,     0,   157,    14,   118, 0x801,                          STR_INDUSTRY_SELECTION_HINT},
   358 {     WWT_MATRIX,      RESIZE_RB,    7,     0,   157,    14,   118, 0x801,                          STR_INDUSTRY_SELECTION_HINT},      // DPIW_MATRIX_WIDGET
   349 {  WWT_SCROLLBAR,     RESIZE_LRB,    7,   158,   169,    14,   118, 0x0,                            STR_0190_SCROLL_BAR_SCROLLS_LIST},
   359 {  WWT_SCROLLBAR,     RESIZE_LRB,    7,   158,   169,    14,   118, 0x0,                            STR_0190_SCROLL_BAR_SCROLLS_LIST}, // DPIW_SCROLLBAR
   350 {      WWT_PANEL,     RESIZE_RTB,    7,     0,   169,   119,   199, 0x0,                            STR_NULL},
   360 {      WWT_PANEL,     RESIZE_RTB,    7,     0,   169,   119,   199, 0x0,                            STR_NULL},                         // DPIW_INFOPANEL
   351 {    WWT_TEXTBTN,     RESIZE_RTB,    7,     0,   157,   200,   211, STR_FUND_NEW_INDUSTRY,          STR_NULL},
   361 {    WWT_TEXTBTN,     RESIZE_RTB,    7,     0,   157,   200,   211, STR_FUND_NEW_INDUSTRY,          STR_NULL},                         // DPIW_FUND_WIDGET
   352 {  WWT_RESIZEBOX,    RESIZE_LRTB,    7,   158,   169,   200,   211, 0x0,                            STR_RESIZE_BUTTON},
   362 {  WWT_RESIZEBOX,    RESIZE_LRTB,    7,   158,   169,   200,   211, 0x0,                            STR_RESIZE_BUTTON},                // DPIW_RESIZE_WIDGET
   353 {   WIDGETS_END},
   363 {   WIDGETS_END},
   354 };
   364 };
   355 
   365 
       
   366 /** Window definition of the dynamic place industries gui */
   356 static const WindowDesc _build_industry_dynamic_desc = {
   367 static const WindowDesc _build_industry_dynamic_desc = {
   357 	WDP_AUTO, WDP_AUTO, 170, 212, 170, 212,
   368 	WDP_AUTO, WDP_AUTO, 170, 212, 170, 212,
   358 	WC_BUILD_INDUSTRY, WC_NONE,
   369 	WC_BUILD_INDUSTRY, WC_NONE,
   359 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
   370 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
   360 	_build_dynamic_industry_widgets,
   371 	_build_dynamic_industry_widgets,
   382 static inline bool IsProductionAlterable(const Industry *i)
   393 static inline bool IsProductionAlterable(const Industry *i)
   383 {
   394 {
   384 	return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
   395 	return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
   385 			(i->accepts_cargo[0] == CT_INVALID || i->accepts_cargo[0] == CT_VALUABLES));
   396 			(i->accepts_cargo[0] == CT_INVALID || i->accepts_cargo[0] == CT_VALUABLES));
   386 }
   397 }
       
   398 
       
   399 /** Names of the widgets of the view industry gui */
       
   400 enum IndustryViewWidgets {
       
   401 	IVW_CLOSEBOX = 0,
       
   402 	IVW_CAPTION,
       
   403 	IVW_STICKY,
       
   404 	IVW_BACKGROUND,
       
   405 	IVW_VIEWPORT,
       
   406 	IVW_INFO,
       
   407 	IVW_GOTO,
       
   408 	IVW_SPACER,
       
   409 };
   387 
   410 
   388 /** Information to store about the industry window */
   411 /** Information to store about the industry window */
   389 struct indview_d : public vp_d {
   412 struct indview_d : public vp_d {
   390 	byte editbox_line;        ///< The line clicked to open the edit box
   413 	byte editbox_line;        ///< The line clicked to open the edit box
   391 	byte clicked_line;        ///< The line of the button that has been clicked
   414 	byte clicked_line;        ///< The line of the button that has been clicked
   528 
   551 
   529 	case WE_CLICK: {
   552 	case WE_CLICK: {
   530 		Industry *i;
   553 		Industry *i;
   531 
   554 
   532 		switch (e->we.click.widget) {
   555 		switch (e->we.click.widget) {
   533 		case 5: {
   556 		case IVW_INFO: {
   534 			int line, x;
   557 			int line, x;
   535 
   558 
   536 			i = GetIndustry(w->window_number);
   559 			i = GetIndustry(w->window_number);
   537 
   560 
   538 			/* We should work if needed.. */
   561 			/* We should work if needed.. */
   563 					SetDParam(0, i->production_rate[line] * 8);
   586 					SetDParam(0, i->production_rate[line] * 8);
   564 					ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_GAME_PRODUCTION, 10, 100, w, CS_ALPHANUMERAL);
   587 					ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_GAME_PRODUCTION, 10, 100, w, CS_ALPHANUMERAL);
   565 				}
   588 				}
   566 			}
   589 			}
   567 		} break;
   590 		} break;
   568 		case 6:
   591 		case IVW_GOTO:
   569 			i = GetIndustry(w->window_number);
   592 			i = GetIndustry(w->window_number);
   570 			ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
   593 			ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
   571 		} break;
   594 		} break;
   572 
   595 
   573 		}
   596 		}
   597 			i->last_month_production[j] = 8 * i->production_rate[j];
   620 			i->last_month_production[j] = 8 * i->production_rate[j];
   598 		}
   621 		}
   599 	}
   622 	}
   600 }
   623 }
   601 
   624 
       
   625 /** Widget definition of the view industy gui */
   602 static const Widget _industry_view_widgets[] = {
   626 static const Widget _industry_view_widgets[] = {
   603 {   WWT_CLOSEBOX,   RESIZE_NONE,     9,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},
   627 {   WWT_CLOSEBOX,   RESIZE_NONE,     9,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},            // IVW_CLOSEBOX
   604 {    WWT_CAPTION,   RESIZE_NONE,     9,    11,   247,     0,    13, STR_4801,          STR_018C_WINDOW_TITLE_DRAG_THIS},
   628 {    WWT_CAPTION,   RESIZE_NONE,     9,    11,   247,     0,    13, STR_4801,          STR_018C_WINDOW_TITLE_DRAG_THIS},  // IVW_CAPTION
   605 {  WWT_STICKYBOX,   RESIZE_NONE,     9,   248,   259,     0,    13, 0x0,               STR_STICKY_BUTTON},
   629 {  WWT_STICKYBOX,   RESIZE_NONE,     9,   248,   259,     0,    13, 0x0,               STR_STICKY_BUTTON},                // IVW_STICKY
   606 {      WWT_PANEL,   RESIZE_NONE,     9,     0,   259,    14,   105, 0x0,               STR_NULL},
   630 {      WWT_PANEL,   RESIZE_NONE,     9,     0,   259,    14,   105, 0x0,               STR_NULL},                         // IVW_BACKGROUND
   607 {      WWT_INSET,   RESIZE_NONE,     9,     2,   257,    16,   103, 0x0,               STR_NULL},
   631 {      WWT_INSET,   RESIZE_NONE,     9,     2,   257,    16,   103, 0x0,               STR_NULL},                         // IVW_VIEWPORT
   608 {      WWT_PANEL,   RESIZE_NONE,     9,     0,   259,   106,   147, 0x0,               STR_NULL},
   632 {      WWT_PANEL,   RESIZE_NONE,     9,     0,   259,   106,   147, 0x0,               STR_NULL},                         // IVW_INFO
   609 { WWT_PUSHTXTBTN,   RESIZE_NONE,     9,     0,   129,   148,   159, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON},
   633 { WWT_PUSHTXTBTN,   RESIZE_NONE,     9,     0,   129,   148,   159, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON}, // IVW_GOTO
   610 {      WWT_PANEL,   RESIZE_NONE,     9,   130,   259,   148,   159, 0x0,               STR_NULL},
   634 {      WWT_PANEL,   RESIZE_NONE,     9,   130,   259,   148,   159, 0x0,               STR_NULL},                         // IVW_SPACER
   611 {   WIDGETS_END},
   635 {   WIDGETS_END},
   612 };
   636 };
   613 
   637 
       
   638 /** Window definition of the view industy gui */
   614 static const WindowDesc _industry_view_desc = {
   639 static const WindowDesc _industry_view_desc = {
   615 	WDP_AUTO, WDP_AUTO, 260, 160, 260, 160,
   640 	WDP_AUTO, WDP_AUTO, 260, 160, 260, 160,
   616 	WC_INDUSTRY_VIEW, WC_NONE,
   641 	WC_INDUSTRY_VIEW, WC_NONE,
   617 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
   642 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
   618 	_industry_view_widgets,
   643 	_industry_view_widgets,
   630 		WP(w, indview_d).clicked_button = 0;
   655 		WP(w, indview_d).clicked_button = 0;
   631 		AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetIndustry(w->window_number)->xy + TileDiffXY(1, 1), ZOOM_LVL_INDUSTRY);
   656 		AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetIndustry(w->window_number)->xy + TileDiffXY(1, 1), ZOOM_LVL_INDUSTRY);
   632 	}
   657 	}
   633 }
   658 }
   634 
   659 
   635 enum {
   660 /** Names of the widgets of the industry directory gui */
   636 	DIRECTORY_INDU_SORTBYNAME = 3,
   661 enum IndustryDirectoryWidgets {
   637 	DIRECTORY_INDU_SORTBYTYPE,
   662 	IDW_CLOSEBOX = 0,
   638 	DIRECTORY_INDU_SORTBYPROD,
   663 	IDW_CAPTION,
   639 	DIRECTORY_INDU_SORTBYTRANSPORT,
   664 	IDW_STICKY,
   640 	DIRECTORY_INDU_SHOWINDU = 8,
   665 	IDW_SORTBYNAME,
   641 };
   666 	IDW_SORTBYTYPE,
   642 
   667 	IDW_SORTBYPROD,
       
   668 	IDW_SORTBYTRANSPORT,
       
   669 	IDW_SPACER,
       
   670 	IDW_INDUSRTY_LIST,
       
   671 	IDW_SCROLLBAR,
       
   672 	IDW_RESIZE,
       
   673 };
       
   674 
       
   675 /** Widget definition of the industy directory gui */
   643 static const Widget _industry_directory_widgets[] = {
   676 static const Widget _industry_directory_widgets[] = {
   644 {   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},
   677 {   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},             // IDW_CLOSEBOX
   645 {    WWT_CAPTION,   RESIZE_NONE,    13,    11,   495,     0,    13, STR_INDUSTRYDIR_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
   678 {    WWT_CAPTION,   RESIZE_NONE,    13,    11,   495,     0,    13, STR_INDUSTRYDIR_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS},   // IDW_CAPTION
   646 {  WWT_STICKYBOX,   RESIZE_NONE,    13,   496,   507,     0,    13, 0x0,                     STR_STICKY_BUTTON},
   679 {  WWT_STICKYBOX,   RESIZE_NONE,    13,   496,   507,     0,    13, 0x0,                     STR_STICKY_BUTTON},                 // IDW_STICKY
   647 { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,   100,    14,    25, STR_SORT_BY_NAME,        STR_SORT_ORDER_TIP},
   680 { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,   100,    14,    25, STR_SORT_BY_NAME,        STR_SORT_ORDER_TIP},                // IDW_SORTBYNAME
   648 { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   101,   200,    14,    25, STR_SORT_BY_TYPE,        STR_SORT_ORDER_TIP},
   681 { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   101,   200,    14,    25, STR_SORT_BY_TYPE,        STR_SORT_ORDER_TIP},                // IDW_SORTBYTYPE
   649 { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   201,   300,    14,    25, STR_SORT_BY_PRODUCTION,  STR_SORT_ORDER_TIP},
   682 { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   201,   300,    14,    25, STR_SORT_BY_PRODUCTION,  STR_SORT_ORDER_TIP},                // IDW_SORTBYPROD
   650 { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   301,   400,    14,    25, STR_SORT_BY_TRANSPORTED, STR_SORT_ORDER_TIP},
   683 { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   301,   400,    14,    25, STR_SORT_BY_TRANSPORTED, STR_SORT_ORDER_TIP},                // IDW_SORTBYTRANSPORT
   651 {      WWT_PANEL,   RESIZE_NONE,    13,   401,   495,    14,    25, 0x0,                     STR_NULL},
   684 {      WWT_PANEL,   RESIZE_NONE,    13,   401,   495,    14,    25, 0x0,                     STR_NULL},                          // IDW_SPACER
   652 {      WWT_PANEL, RESIZE_BOTTOM,    13,     0,   495,    26,   189, 0x0,                     STR_200A_TOWN_NAMES_CLICK_ON_NAME},
   685 {      WWT_PANEL, RESIZE_BOTTOM,    13,     0,   495,    26,   189, 0x0,                     STR_200A_TOWN_NAMES_CLICK_ON_NAME}, // IDW_INDUSRTY_LIST
   653 {  WWT_SCROLLBAR, RESIZE_BOTTOM,    13,   496,   507,    14,   177, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST},
   686 {  WWT_SCROLLBAR, RESIZE_BOTTOM,    13,   496,   507,    14,   177, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST},  // IDW_SCROLLBAR
   654 {  WWT_RESIZEBOX,     RESIZE_TB,    13,   496,   507,   178,   189, 0x0,                     STR_RESIZE_BUTTON},
   687 {  WWT_RESIZEBOX,     RESIZE_TB,    13,   496,   507,   178,   189, 0x0,                     STR_RESIZE_BUTTON},                 // IDW_RESIZE
   655 {   WIDGETS_END},
   688 {   WIDGETS_END},
   656 };
   689 };
   657 
   690 
   658 static uint _num_industry_sort;
   691 static uint _num_industry_sort;
   659 
   692 
   813 		}
   846 		}
   814 	} break;
   847 	} break;
   815 
   848 
   816 	case WE_CLICK:
   849 	case WE_CLICK:
   817 		switch (e->we.click.widget) {
   850 		switch (e->we.click.widget) {
   818 			case DIRECTORY_INDU_SORTBYNAME: {
   851 			case IDW_SORTBYNAME: {
   819 				_industry_sort_order = _industry_sort_order == 0 ? 1 : 0;
   852 				_industry_sort_order = _industry_sort_order == 0 ? 1 : 0;
   820 				_industry_sort_dirty = true;
   853 				_industry_sort_dirty = true;
   821 				SetWindowDirty(w);
   854 				SetWindowDirty(w);
   822 			} break;
   855 			} break;
   823 
   856 
   824 			case DIRECTORY_INDU_SORTBYTYPE: {
   857 			case IDW_SORTBYTYPE: {
   825 				_industry_sort_order = _industry_sort_order == 2 ? 3 : 2;
   858 				_industry_sort_order = _industry_sort_order == 2 ? 3 : 2;
   826 				_industry_sort_dirty = true;
   859 				_industry_sort_dirty = true;
   827 				SetWindowDirty(w);
   860 				SetWindowDirty(w);
   828 			} break;
   861 			} break;
   829 
   862 
   830 			case DIRECTORY_INDU_SORTBYPROD: {
   863 			case IDW_SORTBYPROD: {
   831 				_industry_sort_order = _industry_sort_order == 4 ? 5 : 4;
   864 				_industry_sort_order = _industry_sort_order == 4 ? 5 : 4;
   832 				_industry_sort_dirty = true;
   865 				_industry_sort_dirty = true;
   833 				SetWindowDirty(w);
   866 				SetWindowDirty(w);
   834 			} break;
   867 			} break;
   835 
   868 
   836 			case DIRECTORY_INDU_SORTBYTRANSPORT: {
   869 			case IDW_SORTBYTRANSPORT: {
   837 				_industry_sort_order = _industry_sort_order == 6 ? 7 : 6;
   870 				_industry_sort_order = _industry_sort_order == 6 ? 7 : 6;
   838 				_industry_sort_dirty = true;
   871 				_industry_sort_dirty = true;
   839 				SetWindowDirty(w);
   872 				SetWindowDirty(w);
   840 			} break;
   873 			} break;
   841 
   874 
   842 			case DIRECTORY_INDU_SHOWINDU: {
   875 			case IDW_INDUSRTY_LIST: {
   843 				int y = (e->we.click.pt.y - 28) / 10;
   876 				int y = (e->we.click.pt.y - 28) / 10;
   844 				uint16 p;
   877 				uint16 p;
   845 
   878 
   846 				if (!IsInsideMM(y, 0, w->vscroll.cap)) return;
   879 				if (!IsInsideMM(y, 0, w->vscroll.cap)) return;
   847 				p = y + w->vscroll.pos;
   880 				p = y + w->vscroll.pos;
   860 		w->vscroll.cap += e->we.sizing.diff.y / 10;
   893 		w->vscroll.cap += e->we.sizing.diff.y / 10;
   861 		break;
   894 		break;
   862 	}
   895 	}
   863 }
   896 }
   864 
   897 
   865 
   898 /** Window definition of the industy directory gui */
   866 /* Industry List */
       
   867 static const WindowDesc _industry_directory_desc = {
   899 static const WindowDesc _industry_directory_desc = {
   868 	WDP_AUTO, WDP_AUTO, 508, 190, 508, 190,
   900 	WDP_AUTO, WDP_AUTO, 508, 190, 508, 190,
   869 	WC_INDUSTRY_DIRECTORY, WC_NONE,
   901 	WC_INDUSTRY_DIRECTORY, WC_NONE,
   870 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   902 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   871 	_industry_directory_widgets,
   903 	_industry_directory_widgets,
   872 	IndustryDirectoryWndProc
   904 	IndustryDirectoryWndProc
   873 };
   905 };
   874 
   906 
   875 
       
   876 void ShowIndustryDirectory()
   907 void ShowIndustryDirectory()
   877 {
   908 {
   878 	Window *w = AllocateWindowDescFront(&_industry_directory_desc, 0);
   909 	Window *w = AllocateWindowDescFront(&_industry_directory_desc, 0);
   879 
   910 
   880 	if (w != NULL) {
   911 	if (w != NULL) {