# aircraft_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: aircraft_gui.cpp 18872 2010-01-21 01:38:13Z rubidium $ */
    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 "window_gui.h"
    00019 #include "spritecache.h"
    00020
    00021 #include "table/sprites.h"
    00022 #include "table/strings.h"
    00023
    00032 void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
    00033 {
    00034   int y_offset = (v->Next()->cargo_cap != 0) ? -(FONT_HEIGHT_NORMAL + 1): 0;
    00035   Money feeder_share = 0;
    00036
    00037   for (const Aircraft *u = v; u != NULL; u = u->Next()) {
    00038     if (u->IsNormalAircraft()) {
    00039       SetDParam(0, u->engine_type);
    00040       SetDParam(1, u->build_year);
    00041       SetDParam(2, u->value);
    00042       DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
    00043
    00044       SetDParam(0, u->cargo_type);
    00045       SetDParam(1, u->cargo_cap);
    00046       SetDParam(2, u->Next()->cargo_type);
    00047       SetDParam(3, u->Next()->cargo_cap);
    00048       SetDParam(4, GetCargoSubtypeText(u));
    00049       DrawString(left, right, y + FONT_HEIGHT_NORMAL, (u->Next()->cargo_cap != 0) ? STR_VEHICLE_INFO_CAPACITY_CAPACITY : STR_VEHICLE_INFO_CAPACITY);
    00050     }
    00051
    00052     if (u->cargo_cap != 0) {
    00053       uint cargo_count = u->cargo.Count();
    00054
    00055       y_offset += FONT_HEIGHT_NORMAL + 1;
    00056       if (cargo_count != 0) {
    00057         /* Cargo names (fix pluralness) */
    00058         SetDParam(0, u->cargo_type);
    00059         SetDParam(1, cargo_count);
    00060         SetDParam(2, u->cargo.Source());
    00061         DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1 + y_offset, STR_VEHICLE_DETAILS_CARGO_FROM);
    00062         feeder_share += u->cargo.FeederShare();
    00063       }
    00064     }
    00065   }
    00066
    00067   SetDParam(0, feeder_share);
    00068   DrawString(left, right, y + 3 * FONT_HEIGHT_NORMAL + 3 + y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
    00069 }
    00070
    00071
    00080 void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID selection)
    00081 {
    00082   bool rtl = _dynlang.text_dir == TD_RTL;
    00083
    00084   SpriteID sprite = v->GetImage(rtl ? DIR_E : DIR_W);
    00085   const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL);
    00086
    00087   int x = rtl ? right - real_sprite->width - real_sprite->x_offs : left - real_sprite->x_offs;
    00088   bool helicopter = v->subtype == AIR_HELICOPTER;
    00089
    00090   PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
    00091   DrawSprite(sprite, pal, x, y + 10);
    00092   if (helicopter) {
    00093     const Aircraft *a = Aircraft::From(v);
    00094     SpriteID rotor_sprite = GetCustomRotorSprite(a, true);
    00095     if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
    00096     DrawSprite(rotor_sprite, PAL_NONE, x, y + 5);
    00097   }
    00098   if (v->index == selection) {
    00099     x += real_sprite->x_offs;
    00100     y += real_sprite->y_offs + 10 - (helicopter ? 5 : 0);
    00101     DrawFrameRect(x - 1, y - 1, x + real_sprite->width + 1, y + real_sprite->height + (helicopter ? 5 : 0) + 1, COLOUR_WHITE, FR_BORDERONLY);
    00102   }
    00103 }