src/ship_gui.cpp
changeset 7486 bf6a94009823
parent 7484 7734e4119e70
child 7488 6f51ddf4c225
equal deleted inserted replaced
7485:d8799216928a 7486:bf6a94009823
   161 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   161 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   162 	_ship_details_widgets,
   162 	_ship_details_widgets,
   163 	ShipDetailsWndProc
   163 	ShipDetailsWndProc
   164 };
   164 };
   165 
   165 
   166 static void ShowShipDetailsWindow(const Vehicle *v)
   166 void ShowShipDetailsWindow(const Vehicle *v)
   167 {
   167 {
   168 	Window *w;
   168 	Window *w;
   169 	VehicleID veh = v->index;
   169 	VehicleID veh = v->index;
   170 
   170 
   171 	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
   171 	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
   182 	v = GetVehicle(_new_vehicle_id);
   182 	v = GetVehicle(_new_vehicle_id);
   183 	if (v->tile == _backup_orders_tile) {
   183 	if (v->tile == _backup_orders_tile) {
   184 		_backup_orders_tile = 0;
   184 		_backup_orders_tile = 0;
   185 		RestoreVehicleOrders(v, _backup_orders_data);
   185 		RestoreVehicleOrders(v, _backup_orders_data);
   186 	}
   186 	}
   187 	ShowShipViewWindow(v);
   187 	ShowVehicleViewWindow(v);
   188 }
   188 }
   189 
       
   190 static void ShipViewWndProc(Window *w, WindowEvent *e)
       
   191 {
       
   192 	switch (e->event) {
       
   193 		case WE_PAINT: {
       
   194 			Vehicle *v = GetVehicle(w->window_number);
       
   195 			StringID str;
       
   196 			bool refitable_and_stopped_in_depot = ShipVehInfo(v->engine_type)->refittable && IsShipInDepotStopped(v);
       
   197 			bool is_localplayer = v->owner == _local_player;
       
   198 
       
   199 			SetWindowWidgetDisabledState(w,  7, !is_localplayer);
       
   200 			SetWindowWidgetDisabledState(w,  8,
       
   201 			                             !is_localplayer ||      // Disable if owner is not local player
       
   202 			                             !refitable_and_stopped_in_depot); // Disable if the ship is not refitable or stopped in a depot
       
   203 			SetWindowWidgetDisabledState(w, 11, !is_localplayer);
       
   204 
       
   205 			/* draw widgets & caption */
       
   206 			SetDParam(0, v->index);
       
   207 			DrawWindowWidgets(w);
       
   208 
       
   209 			if (v->breakdown_ctr == 1) {
       
   210 				str = STR_885C_BROKEN_DOWN;
       
   211 			} else if (v->vehstatus & VS_STOPPED) {
       
   212 				str = STR_8861_STOPPED;
       
   213 			} else {
       
   214 				switch (v->current_order.type) {
       
   215 					case OT_GOTO_STATION: {
       
   216 						SetDParam(0, v->current_order.dest);
       
   217 						SetDParam(1, v->GetDisplaySpeed());
       
   218 						str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
       
   219 					} break;
       
   220 
       
   221 					case OT_GOTO_DEPOT: {
       
   222 						Depot *depot = GetDepot(v->current_order.dest);
       
   223 						SetDParam(0, depot->town_index);
       
   224 						SetDParam(1, v->GetDisplaySpeed());
       
   225 						if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
       
   226 							str = STR_HEADING_FOR_SHIP_DEPOT + _patches.vehicle_speed;
       
   227 						} else {
       
   228 							str = STR_HEADING_FOR_SHIP_DEPOT_SERVICE + _patches.vehicle_speed;
       
   229 						}
       
   230 					} break;
       
   231 
       
   232 					case OT_LOADING:
       
   233 					case OT_LEAVESTATION:
       
   234 						str = STR_882F_LOADING_UNLOADING;
       
   235 						break;
       
   236 
       
   237 					default:
       
   238 						if (v->num_orders == 0) {
       
   239 							str = STR_NO_ORDERS + _patches.vehicle_speed;
       
   240 							SetDParam(0, v->GetDisplaySpeed());
       
   241 						} else {
       
   242 							str = STR_EMPTY;
       
   243 						}
       
   244 						break;
       
   245 				}
       
   246 			}
       
   247 
       
   248 		/* draw the flag plus orders */
       
   249 		DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, 2, w->widget[5].top + 1);
       
   250 		DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0);
       
   251 		DrawWindowViewport(w);
       
   252 	} break;
       
   253 
       
   254 		case WE_CLICK: {
       
   255 			const Vehicle *v = GetVehicle(w->window_number);
       
   256 
       
   257 			switch (e->we.click.widget) {
       
   258 				case 5: /* start stop */
       
   259 					DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP));
       
   260 					break;
       
   261 				case 6: /* center main view */
       
   262 					ScrollMainWindowTo(v->x_pos, v->y_pos);
       
   263 					break;
       
   264 				case 7: /* goto hangar */
       
   265 					DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL, CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_9819_CAN_T_SEND_SHIP_TO_DEPOT));
       
   266 					break;
       
   267 				case 8: /* refit */
       
   268 					ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID);
       
   269 					break;
       
   270 				case 9: /* show orders */
       
   271 					ShowOrdersWindow(v);
       
   272 					break;
       
   273 				case 10: /* show details */
       
   274 					ShowShipDetailsWindow(v);
       
   275 					break;
       
   276 				case 11: {
       
   277 					/* clone vehicle */
       
   278 					DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneVehicle, CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
       
   279 				} break;
       
   280 			}
       
   281 		} break;
       
   282 
       
   283 		case WE_RESIZE:
       
   284 			w->viewport->width          += e->we.sizing.diff.x;
       
   285 			w->viewport->height         += e->we.sizing.diff.y;
       
   286 			w->viewport->virtual_width  += e->we.sizing.diff.x;
       
   287 			w->viewport->virtual_height += e->we.sizing.diff.y;
       
   288 			break;
       
   289 
       
   290 		case WE_DESTROY:
       
   291 			DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
       
   292 			DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
       
   293 			DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
       
   294 			DeleteWindowById(WC_VEHICLE_TIMETABLE, w->window_number);
       
   295 			break;
       
   296 
       
   297 		case WE_MOUSELOOP: {
       
   298 			const Vehicle *v = GetVehicle(w->window_number);
       
   299 			bool ship_stopped = IsShipInDepotStopped(v);
       
   300 
       
   301 			/* Widget 7 (send to depot) must be hidden if the ship is already stopped in depot.
       
   302 			 * Widget 11 (clone) should then be shown, since cloning is allowed only while in depot and stopped.
       
   303 			 * This sytem allows to have two buttons, on top of each otherother*/
       
   304 			if (ship_stopped != IsWindowWidgetHidden(w, 7) || ship_stopped == IsWindowWidgetHidden(w, 11)) {
       
   305 				SetWindowWidgetHiddenState(w,  7, ship_stopped);  // send to depot
       
   306 				SetWindowWidgetHiddenState(w, 11, !ship_stopped); // clone
       
   307 				SetWindowDirty(w);
       
   308 			}
       
   309 		}
       
   310 	}
       
   311 }
       
   312 
       
   313 static const Widget _ship_view_widgets[] = {
       
   314 {   WWT_CLOSEBOX, RESIZE_NONE,  14,   0,  10,   0,  13, STR_00C5,                STR_018B_CLOSE_WINDOW},
       
   315 {    WWT_CAPTION, RESIZE_RIGHT, 14,  11, 237,   0,  13, STR_980F,                STR_018C_WINDOW_TITLE_DRAG_THIS},
       
   316 {  WWT_STICKYBOX, RESIZE_LR,    14, 238, 249,   0,  13, 0x0,                     STR_STICKY_BUTTON},
       
   317 {      WWT_PANEL, RESIZE_RB,    14,   0, 231,  14, 103, 0x0,                     STR_NULL},
       
   318 {      WWT_INSET, RESIZE_RB,    14,   2, 229,  16, 101, 0x0,                     STR_NULL},
       
   319 {    WWT_PUSHBTN, RESIZE_RTB,   14,   0, 237, 104, 115, 0x0,                     STR_9827_CURRENT_SHIP_ACTION_CLICK},
       
   320 { WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  14,  31, SPR_CENTRE_VIEW_VEHICLE, STR_9829_CENTER_MAIN_VIEW_ON_SHIP},
       
   321 { WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  32,  49, SPR_SEND_SHIP_TODEPOT,   STR_982A_SEND_SHIP_TO_DEPOT},
       
   322 { WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  50,  67, SPR_REFIT_VEHICLE,       STR_983A_REFIT_CARGO_SHIP_TO_CARRY},
       
   323 { WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  68,  85, SPR_SHOW_ORDERS,         STR_9828_SHOW_SHIP_S_ORDERS},
       
   324 { WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  86, 103, SPR_SHOW_VEHICLE_DETAILS, STR_982B_SHOW_SHIP_DETAILS},
       
   325 { WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  32,  49, SPR_CLONE_SHIP,          STR_CLONE_SHIP_INFO},
       
   326 {      WWT_PANEL, RESIZE_LRB,   14, 232, 249, 104, 103, 0x0,                     STR_NULL },
       
   327 {  WWT_RESIZEBOX, RESIZE_LRTB,  14, 238, 249, 104, 115, 0x0,                     STR_NULL },
       
   328 { WIDGETS_END }
       
   329 };
       
   330 
       
   331 static const WindowDesc _ship_view_desc = {
       
   332 	WDP_AUTO, WDP_AUTO, 250, 116, 250, 116,
       
   333 	WC_VEHICLE_VIEW, WC_NONE,
       
   334 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
       
   335 	_ship_view_widgets,
       
   336 	ShipViewWndProc
       
   337 };
       
   338 
       
   339 void ShowShipViewWindow(const Vehicle *v)
       
   340 {
       
   341 	Window *w = AllocateWindowDescFront(&_ship_view_desc, v->index);
       
   342 
       
   343 	if (w != NULL) {
       
   344 		w->caption_color = v->owner;
       
   345 		AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), ZOOM_LVL_SHIP);
       
   346 	}
       
   347 }