# aircraft_gui.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #include "stdafx.h"
    00013 #include "aircraft.h"
    00014 #include "vehicle_gui.h"
    00015 #include "newgrf_engine.h"
    00016 #include "strings_func.h"
    00017 #include "vehicle_func.h"
    00018 #include "gfx_func.h"
    00019 #include "window_gui.h"
    00020 #include "spritecache.h"
    00021
    00022 #include "table/sprites.h"
    00023 #include "table/strings.h"
    00024
    00033 void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
    00034 {
    00035   int y_offset = (v->Next()->cargo_cap != 0) ? -(FONT_HEIGHT_NORMAL + 1): 0;
    00036   Money feeder_share = 0;
    00037
    00038   for (const Aircraft *u = v; u != NULL; u = u->Next()) {
    00039     if (u->IsNormalAircraft()) {
    00040       SetDParam(0, u->engine_type);
    00041       SetDParam(1, u->build_year);
    00042       SetDParam(2, u->value);
    00043       DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
    00044
    00045       SetDParam(0, u->cargo_type);
    00046       SetDParam(1, u->cargo_cap);
    00047       SetDParam(2, u->Next()->cargo_type);
    00048       SetDParam(3, u->Next()->cargo_cap);
    00049       SetDParam(4, GetCargoSubtypeText(u));
    00050       DrawString(left, right, y + FONT_HEIGHT_NORMAL, (u->Next()->cargo_cap != 0) ? STR_VEHICLE_INFO_CAPACITY_CAPACITY : STR_VEHICLE_INFO_CAPACITY);
    00051     }
    00052
    00053     if (u->cargo_cap != 0) {
    00054       uint cargo_count = u->cargo.Count();
    00055
    00056       y_offset += FONT_HEIGHT_NORMAL + 1;
    00057       if (cargo_count != 0) {
    00058         /* Cargo names (fix pluralness) */
    00059         SetDParam(0, u->cargo_type);
    00060         SetDParam(1, cargo_count);
    00061         SetDParam(2, u->cargo.Source());
    00062         DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1 + y_offset, STR_VEHICLE_DETAILS_CARGO_FROM);
    00063         feeder_share += u->cargo.FeederShare();
    00064       }
    00065     }
    00066   }
    00067
    00068   SetDParam(0, feeder_share);
    00069   DrawString(left, right, y + 3 * FONT_HEIGHT_NORMAL + 3 + y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
    00070 }
    00071
    00072
    00081 void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID selection)
    00082 {
    00083   bool rtl = _dynlang.text_dir == TD_RTL;
    00084
    00085   SpriteID sprite = v->GetImage(rtl ? DIR_E : DIR_W);
    00086   const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL);
    00087
    00088   int x = rtl ? right - real_sprite->width - real_sprite->x_offs : left - real_sprite->x_offs;
    00089   bool helicopter = v->subtype == AIR_HELICOPTER;
    00090
    00091   SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
    00092   DrawSprite(sprite, pal, x, y + 10);
    00093   if (helicopter) {
    00094     const Aircraft *a = Aircraft::From(v);
    00095     SpriteID rotor_sprite = GetCustomRotorSprite(a, true);
    00096     if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
    00097     DrawSprite(rotor_sprite, PAL_NONE, x, y + 5);
    00098   }
    00099   if (v->index == selection) {
    00100     x += real_sprite->x_offs;
    00101     y += real_sprite->y_offs + 10 - (helicopter ? 5 : 0);
    00102     DrawFrameRect(x - 1, y - 1, x + real_sprite->width + 1, y + real_sprite->height + (helicopter ? 5 : 0) + 1, COLOUR_WHITE, FR_BORDERONLY);
    00103   }
    00104 }
    00105
    00113 void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2)
    00114 {
    00115   if (success) {
    00116     const Vehicle *v = Vehicle::Get(_new_vehicle_id);
    00117
    00118     if (v->tile == _backup_orders_tile) {
    00119       _backup_orders_tile = 0;
    00120       RestoreVehicleOrders(v);
    00121     }
    00122     ShowVehicleViewWindow(v);
    00123   }
    00124 }