train_gui.c
changeset 2561 c78c3d248897
parent 2549 f1d3b383d557
child 2562 9397cf08c273
equal deleted inserted replaced
2560:00ad0c27c2f3 2561:c78c3d248897
   161 	ShowTrainViewWindow(v);
   161 	ShowTrainViewWindow(v);
   162 }
   162 }
   163 
   163 
   164 void CcCloneTrain(bool success, uint tile, uint32 p1, uint32 p2)
   164 void CcCloneTrain(bool success, uint tile, uint32 p1, uint32 p2)
   165 {
   165 {
   166 	Vehicle *v;
   166 	if (success) {
   167 
   167 		const Vehicle* v = GetVehicle(_new_aircraft_id);
   168 	if (!success)
   168 
   169 		return;
   169 		ShowTrainViewWindow(v);
   170 
   170 	}
   171 	v = GetVehicle(_new_train_id);
       
   172 	ShowTrainViewWindow(v);
       
   173 }
   171 }
   174 
   172 
   175 static void engine_drawing_loop(int *x, int *y, int *pos, int *sel,
   173 static void engine_drawing_loop(int *x, int *y, int *pos, int *sel,
   176 	EngineID* selected_id, RailType railtype, byte show_max, bool is_engine)
   174 	EngineID* selected_id, RailType railtype, byte show_max, bool is_engine)
   177 {
   175 {
   602 /**
   600 /**
   603  * Clones a train
   601  * Clones a train
   604  * @param *v is the original vehicle to clone
   602  * @param *v is the original vehicle to clone
   605  * @param *w is the window of the depot where the clone is build
   603  * @param *w is the window of the depot where the clone is build
   606  */
   604  */
   607 static bool HandleCloneVehClick(Vehicle *v, Window *w)
   605 static void HandleCloneVehClick(const Vehicle* v, const Window* w)
   608 {
   606 {
   609 
   607 	if (v == NULL || v->type != VEH_Train) return;
   610 	if (!v){
       
   611 		return false;
       
   612 	}
       
   613 
   608 
   614 	// for train vehicles: subtype 0 for locs and not zero for others
   609 	// for train vehicles: subtype 0 for locs and not zero for others
   615 	if (v->type == VEH_Train && v->subtype != 0) {
   610 	if (v->subtype != TS_Front_Engine) {
   616 		v = GetFirstVehicleInChain(v);
   611 		v = GetFirstVehicleInChain(v);
   617 		if (v->subtype != 0) // This happens when clicking on a train in depot with no loc attached
   612 		// Do nothing when clicking on a train in depot with no loc attached
   618 			return false;
   613 		if (v->subtype != TS_Front_Engine) return;
   619 	}else{
   614 	}
   620 		if (v->type != VEH_Train) {
   615 
   621 			// it's not a train, Do Nothing
   616 	DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneTrain,
   622 			return false;
   617 		CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE)
   623 		}
   618 	);
   624 	}
       
   625 
       
   626     DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneTrain, CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
       
   627 
   619 
   628 	ResetObjectToPlace();
   620 	ResetObjectToPlace();
   629 
   621 }
   630 	return true;
   622 
   631 }
   623 static void ClonePlaceObj(TileIndex tile, const Window* w)
   632 
   624 {
   633 static void ClonePlaceObj(uint tile, Window *w)
   625 	Vehicle* v = CheckMouseOverVehicle();
   634 {
   626 
   635 	Vehicle *v;
   627 	if (v != NULL) HandleCloneVehClick(v, w);
   636 
       
   637 
       
   638 	v = CheckMouseOverVehicle();
       
   639 	if (v && HandleCloneVehClick(v, w))
       
   640 		return;
       
   641 }
   628 }
   642 
   629 
   643 static void TrainDepotWndProc(Window *w, WindowEvent *e)
   630 static void TrainDepotWndProc(Window *w, WindowEvent *e)
   644 {
   631 {
   645 	switch(e->event) {
   632 	switch(e->event) {
   684 		InvalidateWidget(w, 9);
   671 		InvalidateWidget(w, 9);
   685 	} break;
   672 	} break;
   686 
   673 
   687 	// check if a vehicle in a depot was clicked..
   674 	// check if a vehicle in a depot was clicked..
   688 	case WE_MOUSELOOP: {
   675 	case WE_MOUSELOOP: {
   689 		Vehicle *v = _place_clicked_vehicle;
   676 		const Vehicle* v = _place_clicked_vehicle;
   690 	// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
   677 
       
   678 		// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
   691 		if (v != NULL && HASBIT(w->click_state, 9)) {
   679 		if (v != NULL && HASBIT(w->click_state, 9)) {
   692 			_place_clicked_vehicle = NULL;
   680 			_place_clicked_vehicle = NULL;
   693 			HandleCloneVehClick( v, w);
   681 			HandleCloneVehClick(v, w);
   694 		}
   682 		}
   695 	} break;
   683 	} break;
   696 
   684 
   697 
   685 
   698 	case WE_DESTROY:
   686 	case WE_DESTROY:
   905 { WWT_PANEL,      RESIZE_LRB,   14, 232, 249, 122, 121, 0x0,      STR_NULL },
   893 { WWT_PANEL,      RESIZE_LRB,   14, 232, 249, 122, 121, 0x0,      STR_NULL },
   906 { WWT_RESIZEBOX,  RESIZE_LRTB,  14, 238, 249, 122, 133, 0x0,      STR_NULL },
   894 { WWT_RESIZEBOX,  RESIZE_LRTB,  14, 238, 249, 122, 133, 0x0,      STR_NULL },
   907 { WIDGETS_END }
   895 { WIDGETS_END }
   908 };
   896 };
   909 
   897 
       
   898 static void ShowTrainDetailsWindow(const Vehicle* v);
       
   899 
   910 static void TrainViewWndProc(Window *w, WindowEvent *e)
   900 static void TrainViewWndProc(Window *w, WindowEvent *e)
   911 {
   901 {
   912 	switch (e->event) {
   902 	switch (e->event) {
   913 	case WE_PAINT: {
   903 	case WE_PAINT: {
   914 		const Vehicle *v, *u;
   904 		const Vehicle *v, *u;
  1061 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
  1051 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
  1062 	_train_view_widgets,
  1052 	_train_view_widgets,
  1063 	TrainViewWndProc
  1053 	TrainViewWndProc
  1064 };
  1054 };
  1065 
  1055 
  1066 void ShowTrainViewWindow(Vehicle *v)
  1056 void ShowTrainViewWindow(const Vehicle* v)
  1067 {
  1057 {
  1068 	Window *w;
  1058 	Window* w = AllocateWindowDescFront(&_train_view_desc,v->index);
  1069 
  1059 
  1070 	w = AllocateWindowDescFront(&_train_view_desc,v->index);
  1060 	if (w != NULL) {
  1071 	if (w) {
       
  1072 		w->caption_color = v->owner;
  1061 		w->caption_color = v->owner;
  1073 		AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), 0);
  1062 		AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), 0);
  1074 	}
  1063 	}
  1075 }
  1064 }
  1076 
  1065 
  1318 	_train_details_widgets,
  1307 	_train_details_widgets,
  1319 	TrainDetailsWndProc
  1308 	TrainDetailsWndProc
  1320 };
  1309 };
  1321 
  1310 
  1322 
  1311 
  1323 void ShowTrainDetailsWindow(Vehicle *v)
  1312 static void ShowTrainDetailsWindow(const Vehicle* v)
  1324 {
  1313 {
  1325 	Window *w;
  1314 	Window *w;
  1326 	VehicleID veh = v->index;
  1315 	VehicleID veh = v->index;
  1327 
  1316 
  1328 	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
  1317 	DeleteWindowById(WC_VEHICLE_ORDERS, veh);