ship_gui.c
changeset 2561 233dafd7cf6c
parent 2549 5587f9a38563
child 2562 5c34e4b3ec13
equal deleted inserted replaced
2560:14bc4eaa3551 2561:233dafd7cf6c
   136 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   136 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   137 	_ship_refit_widgets,
   137 	_ship_refit_widgets,
   138 	ShipRefitWndProc,
   138 	ShipRefitWndProc,
   139 };
   139 };
   140 
   140 
   141 static void ShowShipRefitWindow(Vehicle *v)
   141 static void ShowShipRefitWindow(const Vehicle* v)
   142 {
   142 {
   143 	Window *w;
   143 	Window *w;
   144 
   144 
   145 	DeleteWindowById(WC_VEHICLE_REFIT, v->index);
   145 	DeleteWindowById(WC_VEHICLE_REFIT, v->index);
   146 
   146 
   285 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   285 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   286 	_ship_details_widgets,
   286 	_ship_details_widgets,
   287 	ShipDetailsWndProc
   287 	ShipDetailsWndProc
   288 };
   288 };
   289 
   289 
   290 static void ShowShipDetailsWindow(Vehicle *v)
   290 static void ShowShipDetailsWindow(const Vehicle* v)
   291 {
   291 {
   292 	Window *w;
   292 	Window *w;
   293 	VehicleID veh = v->index;
   293 	VehicleID veh = v->index;
   294 	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
   294 	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
   295 	DeleteWindowById(WC_VEHICLE_DETAILS, veh);
   295 	DeleteWindowById(WC_VEHICLE_DETAILS, veh);
   312 	ShowShipViewWindow(v);
   312 	ShowShipViewWindow(v);
   313 }
   313 }
   314 
   314 
   315 void CcCloneShip(bool success, uint tile, uint32 p1, uint32 p2)
   315 void CcCloneShip(bool success, uint tile, uint32 p1, uint32 p2)
   316 {
   316 {
   317 	Vehicle *v;
   317 	if (success) {
   318 	if (!success) return;
   318 		const Vehicle* v = GetVehicle(_new_aircraft_id);
   319 
   319 
   320 	v = GetVehicle(_new_ship_id);
   320 		ShowShipViewWindow(v);
   321 	ShowShipViewWindow(v);
   321 	}
   322 }
   322 }
   323 
   323 
   324 static void NewShipWndProc(Window *w, WindowEvent *e)
   324 static void NewShipWndProc(Window *w, WindowEvent *e)
   325 {
   325 {
   326 	switch(e->event) {
   326 	switch(e->event) {
   526 		DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0);
   526 		DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0);
   527 		DrawWindowViewport(w);
   527 		DrawWindowViewport(w);
   528 	} break;
   528 	} break;
   529 
   529 
   530 		case WE_CLICK: {
   530 		case WE_CLICK: {
   531 			Vehicle *v = GetVehicle(w->window_number);
   531 			const Vehicle* v = GetVehicle(w->window_number);
   532 
   532 
   533 			switch(e->click.widget) {
   533 			switch (e->click.widget) {
   534 				case 5: /* start stop */
   534 				case 5: /* start stop */
   535 					DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP));
   535 					DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP));
   536 					break;
   536 					break;
   537 				case 6: /* center main view */
   537 				case 6: /* center main view */
   538 					ScrollMainWindowTo(v->x_pos, v->y_pos);
   538 					ScrollMainWindowTo(v->x_pos, v->y_pos);
   549 				case 10: /* show details */
   549 				case 10: /* show details */
   550 					ShowShipDetailsWindow(v);
   550 					ShowShipDetailsWindow(v);
   551 					break;
   551 					break;
   552 				case 11: {
   552 				case 11: {
   553 					/* clone vehicle */
   553 					/* clone vehicle */
   554 					Vehicle *v;
       
   555 					v = GetVehicle(w->window_number);
       
   556 					DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneShip, CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
   554 					DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneShip, CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
   557 				} break;
   555 				} break;
   558 			}
   556 			}
   559 		} break;
   557 		} break;
   560 
   558 
   609 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   607 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
   610 	_ship_view_widgets,
   608 	_ship_view_widgets,
   611 	ShipViewWndProc
   609 	ShipViewWndProc
   612 };
   610 };
   613 
   611 
   614 void ShowShipViewWindow(Vehicle *v)
   612 void ShowShipViewWindow(const Vehicle* v)
   615 {
   613 {
   616 	Window *w;
   614 	Window* w = AllocateWindowDescFront(&_ship_view_desc, v->index);
   617 
   615 
   618 	w = AllocateWindowDescFront(&_ship_view_desc, v->index);
   616 	if (w != NULL) {
   619 	if (w) {
       
   620 		w->caption_color = v->owner;
   617 		w->caption_color = v->owner;
   621 		AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), 0);
   618 		AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), 0);
   622 	}
   619 	}
   623 }
   620 }
   624 
   621 
   743 /**
   740 /**
   744  * Clones a ship
   741  * Clones a ship
   745  * @param *v is the original vehicle to clone
   742  * @param *v is the original vehicle to clone
   746  * @param *w is the window of the depot where the clone is build
   743  * @param *w is the window of the depot where the clone is build
   747  */
   744  */
   748 static bool HandleCloneVehClick(Vehicle *v, Window *w)
   745 static void HandleCloneVehClick(const Vehicle* v, const Window* w)
   749 {
   746 {
   750 
   747 	if (v == NULL || v->type != VEH_Ship) return;
   751 	if (!v){
   748 
   752 		return false;
   749 	DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneShip,
   753 	}
   750 		CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP)
   754 
   751 	);
   755 	if (v->type != VEH_Ship) {
       
   756 		// it's not a ship, do nothing
       
   757 		return false;
       
   758 	}
       
   759 
       
   760 
       
   761     DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0,CcCloneShip,CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
       
   762 
   752 
   763 	ResetObjectToPlace();
   753 	ResetObjectToPlace();
   764 
   754 }
   765 	return true;
   755 
   766 }
   756 static void ClonePlaceObj(TileIndex tile, const Window* w)
   767 
   757 {
   768 static void ClonePlaceObj(uint tile, Window *w)
   758 	Vehicle* v = CheckMouseOverVehicle();
   769 {
   759 
   770 	Vehicle *v;
   760 	if (v != NULL) HandleCloneVehClick(v, w);
   771 
       
   772 
       
   773 	v = CheckMouseOverVehicle();
       
   774 	if (v && HandleCloneVehClick(v, w))
       
   775 		return;
       
   776 }
   761 }
   777 
   762 
   778 static void ShipDepotWndProc(Window *w, WindowEvent *e) {
   763 static void ShipDepotWndProc(Window *w, WindowEvent *e) {
   779 	switch(e->event) {
   764 	switch(e->event) {
   780 	case WE_PAINT:
   765 	case WE_PAINT:
   810 			break;
   795 			break;
   811 		}
   796 		}
   812 		break;
   797 		break;
   813 
   798 
   814 	case WE_PLACE_OBJ: {
   799 	case WE_PLACE_OBJ: {
   815 		//ClonePlaceObj(e->place.tile, w);
       
   816 		ClonePlaceObj(w->window_number, w);
   800 		ClonePlaceObj(w->window_number, w);
   817 	} break;
   801 	} break;
   818 
   802 
   819 	case WE_ABORT_PLACE_OBJ: {
   803 	case WE_ABORT_PLACE_OBJ: {
   820 		CLRBIT(w->click_state, 8);
   804 		CLRBIT(w->click_state, 8);
   821 		InvalidateWidget(w, 8);
   805 		InvalidateWidget(w, 8);
   822 	} break;
   806 	} break;
   823 
   807 
   824 	// check if a vehicle in a depot was clicked..
   808 	// check if a vehicle in a depot was clicked..
   825 	case WE_MOUSELOOP: {
   809 	case WE_MOUSELOOP: {
   826 		Vehicle *v = _place_clicked_vehicle;
   810 		const Vehicle* v = _place_clicked_vehicle;
   827 
   811 
   828 	// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
   812 		// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
   829 		if (v != NULL && HASBIT(w->click_state, 8)) {
   813 		if (v != NULL && HASBIT(w->click_state, 8)) {
   830 			_place_clicked_vehicle = NULL;
   814 			_place_clicked_vehicle = NULL;
   831 			HandleCloneVehClick(v, w);
   815 			HandleCloneVehClick(v, w);
   832 		}
   816 		}
   833 	} break;
   817 	} break;