ship_gui.c
changeset 919 544f374ee392
parent 893 f4698309dec7
child 968 84a870c7a585
equal deleted inserted replaced
918:c092add72215 919:544f374ee392
    44 
    44 
    45 static void ShipRefitWndProc(Window *w, WindowEvent *e)
    45 static void ShipRefitWndProc(Window *w, WindowEvent *e)
    46 {
    46 {
    47 	switch(e->event) {
    47 	switch(e->event) {
    48 	case WE_PAINT: {
    48 	case WE_PAINT: {
    49 		Vehicle *v = &_vehicles[w->window_number];
    49 		Vehicle *v = GetVehicle(w->window_number);
    50 		const byte *b;
    50 		const byte *b;
    51 		int sel;
    51 		int sel;
    52 		int x,y;
    52 		int x,y;
    53 		byte color;
    53 		byte color;
    54 		int cargo;
    54 		int cargo;
   121 					SetWindowDirty(w);
   121 					SetWindowDirty(w);
   122 				}
   122 				}
   123 			} break;
   123 			} break;
   124 		case 4: /* refit button */
   124 		case 4: /* refit button */
   125 			if (WP(w,refit_d).cargo != 0xFF) {
   125 			if (WP(w,refit_d).cargo != 0xFF) {
   126 				Vehicle *v = &_vehicles[w->window_number];
   126 				Vehicle *v = GetVehicle(w->window_number);
   127 				if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_SHIP | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP)))
   127 				if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_SHIP | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP)))
   128 					DeleteWindow(w);
   128 					DeleteWindow(w);
   129 			}
   129 			}
   130 		  break;
   130 		  break;
   131 		}
   131 		}
   164 	WP(w,refit_d).sel = -1;
   164 	WP(w,refit_d).sel = -1;
   165 }
   165 }
   166 
   166 
   167 static void ShipDetailsWndProc(Window *w, WindowEvent *e)
   167 static void ShipDetailsWndProc(Window *w, WindowEvent *e)
   168 {
   168 {
   169 	Vehicle *v = &_vehicles[w->window_number];
   169 	Vehicle *v = GetVehicle(w->window_number);
   170 	StringID str;
   170 	StringID str;
   171 	int mod;
   171 	int mod;
   172 
   172 
   173 	switch(e->event) {
   173 	switch(e->event) {
   174 	case WE_PAINT:
   174 	case WE_PAINT:
   324 void CcBuildShip(bool success, uint tile, uint32 p1, uint32 p2)
   324 void CcBuildShip(bool success, uint tile, uint32 p1, uint32 p2)
   325 {
   325 {
   326 	Vehicle *v;
   326 	Vehicle *v;
   327 	if (!success) return;
   327 	if (!success) return;
   328 
   328 
   329 	v = &_vehicles[_new_ship_id];
   329 	v = GetVehicle(_new_ship_id);
   330 	if (v->tile == _backup_orders_tile) {
   330 	if (v->tile == _backup_orders_tile) {
   331 		_backup_orders_tile = 0;
   331 		_backup_orders_tile = 0;
   332 		RestoreVehicleOrders(v, _backup_orders_data);
   332 		RestoreVehicleOrders(v, _backup_orders_data);
   333 	}
   333 	}
   334 	ShowShipViewWindow(v);
   334 	ShowShipViewWindow(v);
   482 
   482 
   483 
   483 
   484 static void ShipViewWndProc(Window *w, WindowEvent *e) {
   484 static void ShipViewWndProc(Window *w, WindowEvent *e) {
   485 	switch(e->event) {
   485 	switch(e->event) {
   486 	case WE_PAINT: {
   486 	case WE_PAINT: {
   487 		Vehicle *v = &_vehicles[w->window_number];
   487 		Vehicle *v = GetVehicle(w->window_number);
   488 		uint32 disabled = 1<<8;
   488 		uint32 disabled = 1<<8;
   489 		StringID str;
   489 		StringID str;
   490 
   490 
   491 		// Possible to refit?
   491 		// Possible to refit?
   492 		if (ShipVehInfo(v->engine_type)->refittable &&
   492 		if (ShipVehInfo(v->engine_type)->refittable &&
   544 		DrawStringCentered(125, 105, str, 0);
   544 		DrawStringCentered(125, 105, str, 0);
   545 		DrawWindowViewport(w);
   545 		DrawWindowViewport(w);
   546 	} break;
   546 	} break;
   547 
   547 
   548 	case WE_CLICK: {
   548 	case WE_CLICK: {
   549 		Vehicle *v = &_vehicles[w->window_number];
   549 		Vehicle *v = GetVehicle(w->window_number);
   550 
   550 
   551 		switch(e->click.widget) {
   551 		switch(e->click.widget) {
   552 		case 5: /* start stop */
   552 		case 5: /* start stop */
   553 			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP));
   553 			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP));
   554 			break;
   554 			break;
   797 					WP(w,traindepot_d).sel != INVALID_VEHICLE)	{
   797 					WP(w,traindepot_d).sel != INVALID_VEHICLE)	{
   798 				Vehicle *v;
   798 				Vehicle *v;
   799 
   799 
   800 				HandleButtonClick(w, 5);
   800 				HandleButtonClick(w, 5);
   801 
   801 
   802 				v = &_vehicles[WP(w,traindepot_d).sel];
   802 				v = GetVehicle(WP(w,traindepot_d).sel);
   803 				WP(w,traindepot_d).sel = INVALID_VEHICLE;
   803 				WP(w,traindepot_d).sel = INVALID_VEHICLE;
   804 
   804 
   805 				_backup_orders_tile = v->tile;
   805 				_backup_orders_tile = v->tile;
   806 				BackupVehicleOrders(v, _backup_orders_data);
   806 				BackupVehicleOrders(v, _backup_orders_data);
   807 
   807 
   880 			_stringwidth_base = 0;
   880 			_stringwidth_base = 0;
   881 		}
   881 		}
   882 		sel--;
   882 		sel--;
   883 
   883 
   884 		if (sched->type == OT_GOTO_STATION) {
   884 		if (sched->type == OT_GOTO_STATION) {
   885 			st = DEREF_STATION(sched->station);
   885 			st = GetStation(sched->station);
   886 
   886 
   887 			if (!(st->had_vehicle_of_type & HVOT_BUOY)) {
   887 			if (!(st->had_vehicle_of_type & HVOT_BUOY)) {
   888 				SetDParam(0, sched->station);
   888 				SetDParam(0, sched->station);
   889 				DrawString(x, y, STR_A036, 0);
   889 				DrawString(x, y, STR_A036, 0);
   890 
   890 
   960 				SetDParam(1, p->name_2);
   960 				SetDParam(1, p->name_2);
   961 				SetDParam(2, w->vscroll.count);
   961 				SetDParam(2, w->vscroll.count);
   962 				w->widget[1].unkA = STR_9805_SHIPS;
   962 				w->widget[1].unkA = STR_9805_SHIPS;
   963 			} else {
   963 			} else {
   964 				/* Station Name -- (###) Trains */
   964 				/* Station Name -- (###) Trains */
   965 				SetDParam(0, DEREF_STATION(station)->index);
   965 				SetDParam(0, GetStation(station)->index);
   966 				SetDParam(1, w->vscroll.count);
   966 				SetDParam(1, w->vscroll.count);
   967 				w->widget[1].unkA = STR_SCHEDULED_SHIPS;
   967 				w->widget[1].unkA = STR_SCHEDULED_SHIPS;
   968 			}
   968 			}
   969 			DrawWindowWidgets(w);
   969 			DrawWindowWidgets(w);
   970 		}
   970 		}
   974 		DoDrawString(
   974 		DoDrawString(
   975 			vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
   975 			vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
   976 
   976 
   977 		max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
   977 		max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
   978 		for (i = w->vscroll.pos; i < max; ++i) {
   978 		for (i = w->vscroll.pos; i < max; ++i) {
   979 			Vehicle *v = DEREF_VEHICLE(vl->sort_list[i].index);
   979 			Vehicle *v = GetVehicle(vl->sort_list[i].index);
   980 			StringID str;
   980 			StringID str;
   981 
   981 
   982 			assert(v->type == VEH_Ship);
   982 			assert(v->type == VEH_Ship);
   983 
   983 
   984 			DrawShipImage(v, x + 19, y + 6, INVALID_VEHICLE);
   984 			DrawShipImage(v, x + 19, y + 6, INVALID_VEHICLE);
  1026 			{
  1026 			{
  1027 				Vehicle *v;
  1027 				Vehicle *v;
  1028 
  1028 
  1029 				if (id_v >= vl->list_length) return; // click out of list bound
  1029 				if (id_v >= vl->list_length) return; // click out of list bound
  1030 
  1030 
  1031 				v	= DEREF_VEHICLE(vl->sort_list[id_v].index);
  1031 				v	= GetVehicle(vl->sort_list[id_v].index);
  1032 
  1032 
  1033 				assert(v->type == VEH_Ship);
  1033 				assert(v->type == VEH_Ship);
  1034 
  1034 
  1035 				ShowShipViewWindow(v);
  1035 				ShowShipViewWindow(v);
  1036 			}
  1036 			}