src/build_vehicle_gui.cpp
branchnoai
changeset 9694 e72987579514
parent 9686 d3c195c226f9
child 9701 d1ac22c62f64
equal deleted inserted replaced
9693:31fcaa5375a1 9694:e72987579514
    51 	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW },
    51 	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW },
    52 	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   239,     0,    13, 0x0,                     STR_018C_WINDOW_TITLE_DRAG_THIS },
    52 	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   239,     0,    13, 0x0,                     STR_018C_WINDOW_TITLE_DRAG_THIS },
    53 	{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,             STR_SORT_ORDER_TIP},
    53 	{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,             STR_SORT_ORDER_TIP},
    54 	{      WWT_PANEL,  RESIZE_RIGHT,    14,    81,   227,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
    54 	{      WWT_PANEL,  RESIZE_RIGHT,    14,    81,   227,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
    55 	{    WWT_TEXTBTN,     RESIZE_LR,    14,   228,   239,    14,    25, STR_0225,                STR_SORT_CRITERIA_TIP},
    55 	{    WWT_TEXTBTN,     RESIZE_LR,    14,   228,   239,    14,    25, STR_0225,                STR_SORT_CRITERIA_TIP},
    56 	{     WWT_MATRIX,     RESIZE_RB,    14,     0,   227,    26,   121, 0x0,                     STR_NULL },
    56 	{     WWT_MATRIX,     RESIZE_RB,    14,     0,   227,    26,    39, 0x101,                   STR_NULL },
    57 	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   228,   239,    26,   121, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
    57 	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   228,   239,    26,    39, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
    58 	{      WWT_PANEL,    RESIZE_RTB,    14,     0,   239,   122,   243, 0x0,                     STR_NULL },
    58 	{      WWT_PANEL,    RESIZE_RTB,    14,     0,   239,    40,   161, 0x0,                     STR_NULL },
    59 
    59 
    60 	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   244,   255, 0x0,                     STR_NULL },
    60 	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   162,   173, 0x0,                     STR_NULL },
    61 	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,   115,   227,   244,   255, 0x0,                     STR_NULL },
    61 	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,   115,   227,   162,   173, 0x0,                     STR_NULL },
    62 	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   228,   239,   244,   255, 0x0,                     STR_RESIZE_BUTTON },
    62 	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   228,   239,   162,   173, 0x0,                     STR_RESIZE_BUTTON },
    63 	{   WIDGETS_END},
    63 	{   WIDGETS_END},
    64 };
    64 };
    65 
    65 
    66 /* Setup widget strings to fit the different types of vehicles */
    66 /* Setup widget strings to fit the different types of vehicles */
    67 static void SetupWindowStrings(Window *w, byte type)
    67 static void SetupWindowStrings(Window *w, byte type)
   977 static void NewVehicleWndProc(Window *w, WindowEvent *e)
   977 static void NewVehicleWndProc(Window *w, WindowEvent *e)
   978 {
   978 {
   979 	buildvehicle_d *bv = &WP(w, buildvehicle_d);
   979 	buildvehicle_d *bv = &WP(w, buildvehicle_d);
   980 
   980 
   981 	switch (e->event) {
   981 	switch (e->event) {
       
   982 		case WE_CREATE: {
       
   983 			bv->vehicle_type = *(VehicleType*)e->we.create.data;
       
   984 			int vlh = GetVehicleListHeight(bv->vehicle_type);
       
   985 
       
   986 			ResizeWindow(w, 0, vlh - 14);
       
   987 			w->resize.step_height = vlh;
       
   988 			w->vscroll.cap = 1;
       
   989 			w->widget[BUILD_VEHICLE_WIDGET_LIST].data = 0x101;
       
   990 
       
   991 			w->resize.width  = w->width;
       
   992 			w->resize.height = w->height;
       
   993 		} break;
       
   994 
   982 		case WE_INVALIDATE_DATA:
   995 		case WE_INVALIDATE_DATA:
   983 			bv->regenerate_list = true;
   996 			bv->regenerate_list = true;
   984 			SetWindowDirty(w);
   997 			SetWindowDirty(w);
   985 			break;
   998 			break;
   986 
   999 
  1042 			break;
  1055 			break;
  1043 	}
  1056 	}
  1044 }
  1057 }
  1045 
  1058 
  1046 static const WindowDesc _build_vehicle_desc = {
  1059 static const WindowDesc _build_vehicle_desc = {
  1047 	WDP_AUTO, WDP_AUTO, 240, 256,
  1060 	WDP_AUTO, WDP_AUTO, 240, 174, 240, 256,
  1048 	WC_BUILD_VEHICLE, WC_NONE,
  1061 	WC_BUILD_VEHICLE, WC_NONE,
  1049 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
  1062 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
  1050 	_build_vehicle_widgets,
  1063 	_build_vehicle_widgets,
  1051 	NewVehicleWndProc
  1064 	NewVehicleWndProc
  1052 };
  1065 };
  1063 
  1076 
  1064 	assert(IsPlayerBuildableVehicleType(type));
  1077 	assert(IsPlayerBuildableVehicleType(type));
  1065 
  1078 
  1066 	DeleteWindowById(WC_BUILD_VEHICLE, num);
  1079 	DeleteWindowById(WC_BUILD_VEHICLE, num);
  1067 
  1080 
  1068 	w = AllocateWindowDescFront(&_build_vehicle_desc, num);
  1081 	w = AllocateWindowDescFront(&_build_vehicle_desc, num, &type);
  1069 
  1082 
  1070 	if (w == NULL) return;
  1083 	if (w == NULL) return;
  1071 
  1084 
  1072 	w->caption_color = (tile != 0) ? GetTileOwner(tile) : _local_player;
  1085 	w->caption_color = (tile != 0) ? GetTileOwner(tile) : _local_player;
  1073 	w->resize.step_height = GetVehicleListHeight(type);
       
  1074 	w->vscroll.cap = w->resize.step_height == 24 ? 4 : 8;
       
  1075 	w->widget[BUILD_VEHICLE_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
       
  1076 
  1086 
  1077 	bv = &WP(w, buildvehicle_d);
  1087 	bv = &WP(w, buildvehicle_d);
  1078 	EngList_Create(&bv->eng_list);
  1088 	EngList_Create(&bv->eng_list);
  1079 	bv->sel_engine      = INVALID_ENGINE;
  1089 	bv->sel_engine      = INVALID_ENGINE;
  1080 
  1090 
  1081 	bv->vehicle_type    = type;
       
  1082 	bv->regenerate_list = false;
  1091 	bv->regenerate_list = false;
  1083 
  1092 
  1084 	bv->sort_criteria         = _last_sort_criteria[type];
  1093 	bv->sort_criteria         = _last_sort_criteria[type];
  1085 	bv->descending_sort_order = _last_sort_order[type];
  1094 	bv->descending_sort_order = _last_sort_order[type];
  1086 
  1095 
  1087 	switch (type) {
  1096 	switch (type) {
  1088 		default: NOT_REACHED();
  1097 		default: NOT_REACHED();
  1089 		case VEH_TRAIN:
  1098 		case VEH_TRAIN:
  1090 			WP(w, buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
  1099 			WP(w, buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
  1091 			ResizeWindow(w, 0, 16);
       
  1092 			break;
  1100 			break;
  1093 		case VEH_ROAD:
  1101 		case VEH_ROAD:
  1094 			WP(w, buildvehicle_d).filter.roadtypes = (tile == 0) ? ROADTYPES_ALL : GetRoadTypes(tile);
  1102 			WP(w, buildvehicle_d).filter.roadtypes = (tile == 0) ? ROADTYPES_ALL : GetRoadTypes(tile);
  1095 			ResizeWindow(w, 0, 16);
       
  1096 		case VEH_SHIP:
  1103 		case VEH_SHIP:
  1097 			break;
  1104 			break;
  1098 		case VEH_AIRCRAFT:
  1105 		case VEH_AIRCRAFT:
  1099 			bv->filter.flags =
  1106 			bv->filter.flags =
  1100 				tile == 0 ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags;
  1107 				tile == 0 ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags;
  1101 			break;
  1108 			break;
  1102 	}
  1109 	}
  1103 	SetupWindowStrings(w, type);
  1110 	SetupWindowStrings(w, type);
  1104 	ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
  1111 	ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
  1105 
  1112 
  1106 	w->resize.width  = w->width;
       
  1107 	w->resize.height = w->height;
       
  1108 
       
  1109 	GenerateBuildList(w); // generate the list, since we need it in the next line
  1113 	GenerateBuildList(w); // generate the list, since we need it in the next line
  1110 	/* Select the first engine in the list as default when opening the window */
  1114 	/* Select the first engine in the list as default when opening the window */
  1111 	if (EngList_Count(&bv->eng_list) > 0) bv->sel_engine = bv->eng_list[0];
  1115 	if (EngList_Count(&bv->eng_list) > 0) bv->sel_engine = bv->eng_list[0];
  1112 }
  1116 }