2005-07-24 16:12:37 +02:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-04-04 03:35:16 +02:00
|
|
|
/** @file ship_gui.cpp */
|
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
#include "stdafx.h"
|
2005-06-02 21:30:21 +02:00
|
|
|
#include "openttd.h"
|
2005-02-05 16:58:59 +01:00
|
|
|
#include "debug.h"
|
2005-07-22 09:02:20 +02:00
|
|
|
#include "functions.h"
|
2006-06-05 13:28:00 +02:00
|
|
|
#include "ship.h"
|
2004-11-25 11:47:30 +01:00
|
|
|
#include "table/strings.h"
|
2007-07-16 11:16:58 +02:00
|
|
|
#include "strings.h"
|
2005-07-24 17:56:31 +02:00
|
|
|
#include "table/sprites.h"
|
2004-08-09 19:04:08 +02:00
|
|
|
#include "gui.h"
|
|
|
|
#include "vehicle.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "command.h"
|
2005-02-06 11:18:47 +01:00
|
|
|
#include "depot.h"
|
2005-07-22 00:15:02 +02:00
|
|
|
#include "vehicle_gui.h"
|
2006-02-03 13:55:21 +01:00
|
|
|
#include "newgrf_engine.h"
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2006-08-29 19:41:13 +02:00
|
|
|
void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection)
|
2005-05-11 18:17:03 +02:00
|
|
|
{
|
2007-07-01 21:11:47 +02:00
|
|
|
DrawSprite(v->GetImage(DIR_W), GetVehiclePalette(v), x + 32, y + 10);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2005-05-11 18:17:03 +02:00
|
|
|
if (v->index == selection) {
|
2005-11-14 20:48:04 +01:00
|
|
|
DrawFrameRect(x - 5, y - 1, x + 67, y + 21, 15, FR_BORDERONLY);
|
2005-05-11 18:17:03 +02:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
|
|
|
static void ShipDetailsWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-05-11 18:17:03 +02:00
|
|
|
switch (e->event) {
|
|
|
|
case WE_PAINT: {
|
|
|
|
const Vehicle *v = GetVehicle(w->window_number);
|
|
|
|
StringID str;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2006-10-03 04:08:15 +02:00
|
|
|
SetWindowWidgetDisabledState(w, 2, v->owner != _local_player);
|
2007-04-04 03:35:16 +02:00
|
|
|
/* disable service-scroller when interval is set to disabled */
|
2006-10-03 04:08:15 +02:00
|
|
|
SetWindowWidgetDisabledState(w, 5, !_patches.servint_ships);
|
|
|
|
SetWindowWidgetDisabledState(w, 6, !_patches.servint_ships);
|
2004-09-04 15:06:09 +02:00
|
|
|
|
2007-06-25 00:42:11 +02:00
|
|
|
SetDParam(0, v->index);
|
2004-08-09 19:04:08 +02:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
/* Draw running cost */
|
|
|
|
{
|
|
|
|
int year = v->age / 366;
|
|
|
|
|
2004-12-02 23:53:07 +01:00
|
|
|
SetDParam(1, year);
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2005-08-01 00:28:49 +02:00
|
|
|
SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
|
2004-12-02 23:53:07 +01:00
|
|
|
SetDParam(2, v->max_age / 366);
|
2007-08-29 23:27:16 +02:00
|
|
|
SetDParam(3, v->GetDisplayRunningCost());
|
2004-08-09 19:04:08 +02:00
|
|
|
DrawString(2, 15, STR_9812_AGE_RUNNING_COST_YR, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw max speed */
|
|
|
|
{
|
2007-08-28 08:46:33 +02:00
|
|
|
SetDParam(0, v->GetDisplayMaxSpeed());
|
2004-08-09 19:04:08 +02:00
|
|
|
DrawString(2, 25, STR_9813_MAX_SPEED, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw profit */
|
|
|
|
{
|
2007-06-21 19:25:17 +02:00
|
|
|
SetDParam(0, v->profit_this_year);
|
|
|
|
SetDParam(1, v->profit_last_year);
|
2004-08-09 19:04:08 +02:00
|
|
|
DrawString(2, 35, STR_9814_PROFIT_THIS_YEAR_LAST_YEAR, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw breakdown & reliability */
|
|
|
|
{
|
2004-12-02 23:53:07 +01:00
|
|
|
SetDParam(0, v->reliability * 100 >> 16);
|
|
|
|
SetDParam(1, v->breakdowns_since_last_service);
|
2004-08-09 19:04:08 +02:00
|
|
|
DrawString(2, 45, STR_9815_RELIABILITY_BREAKDOWNS, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw service interval text */
|
|
|
|
{
|
2004-12-02 23:53:07 +01:00
|
|
|
SetDParam(0, v->service_interval);
|
|
|
|
SetDParam(1, v->date_of_last_service);
|
2007-04-19 00:10:36 +02:00
|
|
|
DrawString(13, 102, _patches.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, 0);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DrawShipImage(v, 3, 57, INVALID_VEHICLE);
|
|
|
|
|
2007-06-25 16:46:32 +02:00
|
|
|
SetDParam(0, v->engine_type);
|
2006-08-20 21:05:28 +02:00
|
|
|
SetDParam(1, v->build_year);
|
2007-06-21 19:25:17 +02:00
|
|
|
SetDParam(2, v->value);
|
2004-08-09 19:04:08 +02:00
|
|
|
DrawString(74, 57, STR_9816_BUILT_VALUE, 0);
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2006-10-20 13:53:29 +02:00
|
|
|
SetDParam(0, v->cargo_type);
|
2004-12-02 23:53:07 +01:00
|
|
|
SetDParam(1, v->cargo_cap);
|
2004-08-09 19:04:08 +02:00
|
|
|
DrawString(74, 67, STR_9817_CAPACITY, 0);
|
|
|
|
|
|
|
|
str = STR_8812_EMPTY;
|
2007-06-22 13:58:59 +02:00
|
|
|
if (!v->cargo.Empty()) {
|
2004-12-02 23:53:07 +01:00
|
|
|
SetDParam(0, v->cargo_type);
|
2007-06-22 13:58:59 +02:00
|
|
|
SetDParam(1, v->cargo.Count());
|
|
|
|
SetDParam(2, v->cargo.Source());
|
2004-08-09 19:04:08 +02:00
|
|
|
str = STR_8813_FROM;
|
|
|
|
}
|
|
|
|
DrawString(74, 78, str, 0);
|
2007-03-02 19:49:11 +01:00
|
|
|
|
|
|
|
/* Draw Transfer credits text */
|
2007-06-22 13:58:59 +02:00
|
|
|
SetDParam(0, v->cargo.FeederShare());
|
2007-03-02 19:49:11 +01:00
|
|
|
DrawString(74, 89, STR_FEEDER_CARGO_VALUE, 0);
|
|
|
|
|
2005-05-11 18:17:03 +02:00
|
|
|
} break;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2005-05-11 18:17:03 +02:00
|
|
|
case WE_CLICK: {
|
|
|
|
int mod;
|
|
|
|
const Vehicle *v;
|
2006-09-23 04:39:24 +02:00
|
|
|
switch (e->we.click.widget) {
|
2004-08-09 19:04:08 +02:00
|
|
|
case 2: /* rename */
|
2005-05-11 18:17:03 +02:00
|
|
|
v = GetVehicle(w->window_number);
|
2007-06-25 00:42:11 +02:00
|
|
|
SetDParam(0, v->index);
|
|
|
|
ShowQueryString(STR_VEHICLE_NAME, STR_9831_NAME_SHIP, 31, 150, w, CS_ALPHANUMERAL);
|
2004-08-09 19:04:08 +02:00
|
|
|
break;
|
|
|
|
case 5: /* increase int */
|
2004-09-04 15:06:09 +02:00
|
|
|
mod = _ctrl_pressed? 5 : 10;
|
2005-05-11 18:17:03 +02:00
|
|
|
goto do_change_service_int;
|
2004-08-09 19:04:08 +02:00
|
|
|
case 6: /* decrease int */
|
2007-04-19 00:10:36 +02:00
|
|
|
mod = _ctrl_pressed ? - 5 : -10;
|
2005-05-11 18:17:03 +02:00
|
|
|
do_change_service_int:
|
|
|
|
v = GetVehicle(w->window_number);
|
2004-09-04 15:06:09 +02:00
|
|
|
|
2005-05-11 18:17:03 +02:00
|
|
|
mod = GetServiceIntervalClamped(mod + v->service_interval);
|
|
|
|
if (mod == v->service_interval) return;
|
2004-09-04 15:06:09 +02:00
|
|
|
|
2006-01-05 22:35:54 +01:00
|
|
|
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
|
2004-08-09 19:04:08 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-05-11 18:17:03 +02:00
|
|
|
} break;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2005-10-22 08:39:32 +02:00
|
|
|
case WE_ON_EDIT_TEXT:
|
2006-09-23 04:39:24 +02:00
|
|
|
if (e->we.edittext.str[0] != '\0') {
|
|
|
|
_cmd_text = e->we.edittext.str;
|
2005-05-15 20:50:55 +02:00
|
|
|
DoCommandP(0, w->window_number, 0, NULL,
|
|
|
|
CMD_NAME_VEHICLE | CMD_MSG(STR_9832_CAN_T_NAME_SHIP));
|
|
|
|
}
|
2005-10-22 08:39:32 +02:00
|
|
|
break;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const Widget _ship_details_widgets[] = {
|
2006-08-22 16:38:37 +02:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 364, 0, 13, STR_9811_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 365, 404, 0, 13, STR_01AA_NAME, STR_982F_NAME_SHIP},
|
2006-10-24 16:15:17 +02:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 404, 14, 55, 0x0, STR_NULL},
|
2007-03-02 19:49:11 +01:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 404, 56, 100, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 101, 106, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 107, 112, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 11, 404, 101, 112, 0x0, STR_NULL},
|
2004-09-07 23:48:09 +02:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 19:04:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _ship_details_desc = {
|
2007-07-27 14:49:04 +02:00
|
|
|
WDP_AUTO, WDP_AUTO, 405, 113, 405, 113,
|
2007-04-19 00:10:36 +02:00
|
|
|
WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW,
|
2004-08-09 19:04:08 +02:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
|
|
_ship_details_widgets,
|
|
|
|
ShipDetailsWndProc
|
|
|
|
};
|
|
|
|
|
2007-08-29 22:50:58 +02:00
|
|
|
void ShowShipDetailsWindow(const Vehicle *v)
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
VehicleID veh = v->index;
|
2005-11-14 20:48:04 +01:00
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
DeleteWindowById(WC_VEHICLE_ORDERS, veh);
|
|
|
|
DeleteWindowById(WC_VEHICLE_DETAILS, veh);
|
2006-11-11 10:47:44 +01:00
|
|
|
w = AllocateWindowDescFront(&_ship_details_desc, veh);
|
2004-08-09 19:04:08 +02:00
|
|
|
w->caption_color = v->owner;
|
|
|
|
}
|
|
|
|
|
2005-06-24 14:38:35 +02:00
|
|
|
void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2006-07-26 05:33:12 +02:00
|
|
|
const Vehicle *v;
|
2004-08-09 19:04:08 +02:00
|
|
|
if (!success) return;
|
|
|
|
|
2006-06-04 11:28:33 +02:00
|
|
|
v = GetVehicle(_new_vehicle_id);
|
2004-08-09 19:04:08 +02:00
|
|
|
if (v->tile == _backup_orders_tile) {
|
|
|
|
_backup_orders_tile = 0;
|
|
|
|
RestoreVehicleOrders(v, _backup_orders_data);
|
|
|
|
}
|
2007-08-29 22:50:58 +02:00
|
|
|
ShowVehicleViewWindow(v);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|