diff -r f6d6d8b1274f -r 05955c6cb536 aircraft_gui.c --- a/aircraft_gui.c Mon Sep 25 17:11:47 2006 +0000 +++ b/aircraft_gui.c Tue Sep 26 16:47:51 2006 +0000 @@ -659,285 +659,6 @@ } } -static void DrawAircraftDepotWindow(Window *w) -{ - Vehicle **vl = WP(w, traindepot_d).vehicle_list; - TileIndex tile = w->window_number; - int x, y, max; - uint16 num = WP(w, traindepot_d).engine_count; - - - /* setup disabled buttons */ - w->disabled_state = - IsTileOwner(tile, _local_player) ? 0 : ((1<<4) | (1<<7) | (1<<8)); - - /* determine amount of items for scroller */ - SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap); - - SetDParam(0, GetStationIndex(tile)); - DrawWindowWidgets(w); - - x = 2; - y = 15; - num = w->vscroll.pos * w->hscroll.cap; - max = min(WP(w, traindepot_d).engine_count, num + (w->vscroll.cap * w->hscroll.cap)); - - for (; num < max; num++) { - const Vehicle *v = vl[num]; - - DrawAircraftImage(v, x + 12, y, WP(w,traindepot_d).sel); - - SetDParam(0, v->unitnumber); - DrawString(x, y + 2, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0); - - DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, x, y + 12); - - if ((x += 74) == 2 + 74 * w->hscroll.cap) { - x = 2; - y += 24; - } - } -} - -static int GetVehicleFromAircraftDepotWndPt(const Window *w, int x, int y, Vehicle **veh) -{ - Vehicle **vl = WP(w, traindepot_d).vehicle_list; - uint xt,row,xm,ym; - int pos; - - xt = x / 74; - xm = x % 74; - if (xt >= w->hscroll.cap) - return 1; - - row = (y - 14) / 24; - ym = (y - 14) % 24; - if (row >= w->vscroll.cap) return 1; - - pos = (row + w->vscroll.pos) * w->hscroll.cap + xt; - - if (WP(w, traindepot_d).engine_count <= pos) return 1; // empty block, so no vehicle is selected - *veh = vl[pos]; - - if (xm >= 12) return 0; // drag vehicle - if (ym <= 12) return -1; // show window - return -2; // start stop -} - -static void AircraftDepotClickAircraft(Window *w, int x, int y) -{ - Vehicle *v = NULL; - int mode = GetVehicleFromAircraftDepotWndPt(w, x, y, &v); - - // share / copy orders - if (_thd.place_mode && mode <= 0) { - _place_clicked_vehicle = v; - return; - } - - switch (mode) { - case 1: - return; - - case 0: // start dragging of vehicle - if (v != NULL) { - WP(w,traindepot_d).sel = v->index; - SetWindowDirty(w); - SetObjectToPlaceWnd(GetVehiclePalette(v) | GetAircraftImage(v, DIR_W), 4, w); - } - break; - - case -1: // show info window - ShowAircraftViewWindow(v); - break; - - case -2: // click start/stop flag - DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_AIRCRAFT | CMD_MSG(STR_A016_CAN_T_STOP_START_AIRCRAFT)); - break; - - default: - NOT_REACHED(); - } -} - -/** - * Clones an aircraft - * @param *v is the original vehicle to clone - * @param *w is the window of the hangar where the clone is build - */ -static void HandleCloneVehClick(const Vehicle *v, const Window *w) -{ - if (v == NULL || v->type != VEH_Aircraft) return; - - DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, - CcCloneAircraft, CMD_CLONE_VEHICLE | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT) - ); - - ResetObjectToPlace(); -} - -static void ClonePlaceObj(const Window *w) -{ - const Vehicle *v = CheckMouseOverVehicle(); - - if (v != NULL) HandleCloneVehClick(v, w); -} - - -static void AircraftDepotWndProc(Window *w, WindowEvent *e) -{ - switch (e->event) { - case WE_CREATE: - WP(w, traindepot_d).vehicle_list = NULL; - WP(w, traindepot_d).engine_list_length = 0; - break; - - case WE_PAINT: - BuildDepotVehicleList(VEH_Aircraft, w->window_number, &WP(w, traindepot_d).vehicle_list, &WP(w, traindepot_d).engine_list_length, &WP(w, traindepot_d).engine_count, NULL, NULL, NULL); - DrawAircraftDepotWindow(w); - break; - - case WE_CLICK: - switch (e->we.click.widget) { - case 5: /* click aircraft */ - AircraftDepotClickAircraft(w, e->we.click.pt.x, e->we.click.pt.y); - break; - - case 7: /* show build aircraft window */ - ResetObjectToPlace(); - ShowBuildAircraftWindow(w->window_number); - break; - - case 8: /* clone button */ - InvalidateWidget(w, 8); - TOGGLEBIT(w->click_state, 8); - - if (HASBIT(w->click_state, 8)) { - _place_clicked_vehicle = NULL; - SetObjectToPlaceWnd(SPR_CURSOR_CLONE, VHM_RECT, w); - } else { - ResetObjectToPlace(); - } - break; - - case 9: ScrollMainWindowToTile(w->window_number); break; - } - break; - - case WE_PLACE_OBJ: - ClonePlaceObj(w); - break; - - case WE_ABORT_PLACE_OBJ: - CLRBIT(w->click_state, 8); - InvalidateWidget(w, 8); - break; - - // check if a vehicle in a depot was clicked.. - case WE_MOUSELOOP: { - const Vehicle *v = _place_clicked_vehicle; - - // since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button - if (v != NULL && HASBIT(w->click_state, 8)) { - _place_clicked_vehicle = NULL; - HandleCloneVehClick(v, w); - } - } break; - - case WE_DESTROY: - DeleteWindowById(WC_BUILD_VEHICLE, w->window_number); - free((void*)WP(w, traindepot_d).vehicle_list); - break; - - case WE_DRAGDROP: - switch (e->we.click.widget) { - case 5: { - Vehicle *v; - VehicleID sel = WP(w,traindepot_d).sel; - - WP(w,traindepot_d).sel = INVALID_VEHICLE; - SetWindowDirty(w); - - if (GetVehicleFromAircraftDepotWndPt(w, e->we.dragdrop.pt.x, e->we.dragdrop.pt.y, &v) == 0 && - v != NULL && - sel == v->index) { - ShowAircraftViewWindow(v); - } - } break; - - case 4: - if (!HASBIT(w->disabled_state, 4) && - WP(w,traindepot_d).sel != INVALID_VEHICLE) { - Vehicle *v; - - HandleButtonClick(w, 4); - - v = GetVehicle(WP(w,traindepot_d).sel); - WP(w,traindepot_d).sel = INVALID_VEHICLE; - - _backup_orders_tile = v->tile; - BackupVehicleOrders(v, _backup_orders_data); - - if (!DoCommandP(v->tile, v->index, 0, NULL, CMD_SELL_AIRCRAFT | CMD_MSG(STR_A01C_CAN_T_SELL_AIRCRAFT))) - _backup_orders_tile = 0; - } - break; - default: - WP(w,traindepot_d).sel = INVALID_VEHICLE; - SetWindowDirty(w); - } - break; - - case WE_RESIZE: - w->vscroll.cap += e->we.sizing.diff.y / 24; - w->hscroll.cap += e->we.sizing.diff.x / 74; - w->widget[5].data = (w->vscroll.cap << 8) + w->hscroll.cap; - break; - } -} - -static const Widget _aircraft_depot_widgets[] = { -{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, -{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 318, 0, 13, STR_A002_AIRCRAFT_HANGAR, STR_018C_WINDOW_TITLE_DRAG_THIS }, -{ WWT_STICKYBOX, RESIZE_LR, 14, 319, 330, 0, 13, 0x0, STR_STICKY_BUTTON }, -{ WWT_PANEL, RESIZE_LRB, 14, 296, 318, 14, 13, 0x0, STR_NULL }, -{ WWT_IMGBTN, RESIZE_LRTB, 14, 296, 318, 14, 61, 0x2A9, STR_A023_DRAG_AIRCRAFT_TO_HERE_TO }, - -{ WWT_MATRIX, RESIZE_RB, 14, 0, 295, 14, 61, 0x204, STR_A021_AIRCRAFT_CLICK_ON_AIRCRAFT }, -{ WWT_SCROLLBAR, RESIZE_LRB, 14, 319, 330, 14, 61, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST }, -{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 105, 62, 73, STR_A003_NEW_AIRCRAFT, STR_A022_BUILD_NEW_AIRCRAFT }, -{WWT_NODISTXTBTN, RESIZE_TB, 14, 106, 212, 62, 73, STR_CLONE_AIRCRAFT, STR_CLONE_AIRCRAFT_INFO_HANGAR_WINDOW }, -{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 213, 318, 62, 73, STR_00E4_LOCATION, STR_A024_CENTER_MAIN_VIEW_ON_HANGAR }, -{ WWT_PANEL, RESIZE_RTB, 14, 319, 318, 62, 73, 0x0, STR_NULL }, -{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 319, 330, 62, 73, 0x0, STR_RESIZE_BUTTON }, -{ WIDGETS_END}, -}; - -static const WindowDesc _aircraft_depot_desc = { - -1, -1, 331, 74, - WC_VEHICLE_DEPOT,0, - WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, - _aircraft_depot_widgets, - AircraftDepotWndProc -}; - - -void ShowAircraftDepotWindow(TileIndex tile) -{ - Window *w; - - w = AllocateWindowDescFront(&_aircraft_depot_desc, tile); - if (w != NULL) { - w->caption_color = GetTileOwner(tile); - w->vscroll.cap = 2; - w->hscroll.cap = 4; - w->resize.step_width = 74; - w->resize.step_height = 24; - WP(w,traindepot_d).sel = INVALID_VEHICLE; - _backup_orders_tile = 0; - } -} - void DrawSmallOrderListAircraft(const Vehicle *v, int x, int y) { const Order *order;