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

Generated on Sun Jun 5 04:19:54 2011 for OpenTTD by  doxygen 1.6.1