# ship_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: ship_gui.cpp 18144 2009-11-17 15:26:46Z 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 "vehicle_base.h"
    00014 #include "window_gui.h"
    00015 #include "gfx_func.h"
    00016 #include "vehicle_gui.h"
    00017 #include "strings_func.h"
    00018 #include "vehicle_func.h"
    00019 #include "spritecache.h"
    00020
    00021 #include "table/strings.h"
    00022
    00031 void DrawShipImage(const Vehicle *v, int left, int right, int y, VehicleID selection)
    00032 {
    00033   bool rtl = _dynlang.text_dir == TD_RTL;
    00034
    00035   SpriteID sprite = v->GetImage(rtl ? DIR_E : DIR_W);
    00036   const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL);
    00037
    00038   int x = rtl ? right - real_sprite->width - real_sprite->x_offs : left - real_sprite->x_offs;
    00039
    00040   DrawSprite(sprite, GetVehiclePalette(v), x, y + 10);
    00041
    00042   if (v->index == selection) {
    00043     x += real_sprite->x_offs;
    00044     y += real_sprite->y_offs + 10;
    00045     DrawFrameRect(x - 1, y - 1, x + real_sprite->width + 1, y + real_sprite->height + 1, COLOUR_WHITE, FR_BORDERONLY);
    00046   }
    00047 }
    00048
    00049 void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2)
    00050 {
    00051   const Vehicle *v;
    00052   if (!success) return;
    00053
    00054   v = Vehicle::Get(_new_vehicle_id);
    00055   if (v->tile == _backup_orders_tile) {
    00056     _backup_orders_tile = 0;
    00057     RestoreVehicleOrders(v);
    00058   }
    00059   ShowVehicleViewWindow(v);
    00060 }
    00061
    00070 void DrawShipDetails(const Vehicle *v, int left, int right, int y)
    00071 {
    00072   SetDParam(0, v->engine_type);
    00073   SetDParam(1, v->build_year);
    00074   SetDParam(2, v->value);
    00075   DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
    00076
    00077   SetDParam(0, v->cargo_type);
    00078   SetDParam(1, v->cargo_cap);
    00079   SetDParam(4, GetCargoSubtypeText(v));
    00080   DrawString(left, right, y + FONT_HEIGHT_NORMAL, STR_VEHICLE_INFO_CAPACITY);
    00081
    00082   StringID str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
    00083   if (!v->cargo.Empty()) {
    00084     SetDParam(0, v->cargo_type);
    00085     SetDParam(1, v->cargo.Count());
    00086     SetDParam(2, v->cargo.Source());
    00087     str = STR_VEHICLE_DETAILS_CARGO_FROM;
    00088   }
    00089   DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1, str);
    00090
    00091   /* Draw Transfer credits text */
    00092   SetDParam(0, v->cargo.FeederShare());
    00093   DrawString(left, right, y + 3 * FONT_HEIGHT_NORMAL + 3, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
    00094 }