summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-09-05 23:26:45 +0000
committerrubidium <rubidium@openttd.org>2007-09-05 23:26:45 +0000
commit07c67183bdd1327c143c9023cace9ecaa015e641 (patch)
treea0fd629e7df1f3bb90e655b561bd22b3d110db79
parent0db524e175df6ae7aa1702072465fa421132793d (diff)
downloadopenttd-07c67183bdd1327c143c9023cace9ecaa015e641.tar.xz
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
-rw-r--r--src/aircraft_gui.cpp213
-rw-r--r--src/roadveh_gui.cpp281
-rw-r--r--src/ship_gui.cpp179
-rw-r--r--src/train_gui.cpp207
-rw-r--r--src/vehicle_gui.cpp389
-rw-r--r--src/window.h4
6 files changed, 543 insertions, 730 deletions
diff --git a/src/aircraft_gui.cpp b/src/aircraft_gui.cpp
index b161c84a7..fc94df771 100644
--- a/src/aircraft_gui.cpp
+++ b/src/aircraft_gui.cpp
@@ -23,6 +23,50 @@
#include "vehicle_gui.h"
#include "newgrf_engine.h"
+/**
+* Draw the details for the given vehicle at the position (x,y)
+*
+* @param v current vehicle
+* @param x The x coordinate
+* @param y The y coordinate
+*/
+void DrawAircraftDetails(const Vehicle *v, int x, int y)
+{
+ int y_offset = (v->Next()->cargo_cap != 0) ? -11 : 0;
+
+ for (const Vehicle *u = v ; u != NULL ; u = u->Next()) {
+ if (IsNormalAircraft(u)) {
+ SetDParam(0, u->engine_type);
+ SetDParam(1, u->build_year);
+ SetDParam(2, u->value);
+ DrawString(x, y, STR_A011_BUILT_VALUE, 0);
+
+ SetDParam(0, u->cargo_type);
+ SetDParam(1, u->cargo_cap);
+ SetDParam(2, u->Next()->cargo_type);
+ SetDParam(3, u->Next()->cargo_cap);
+ DrawString(x, y + 10, (u->Next()->cargo_cap != 0) ? STR_A019_CAPACITY : STR_A01A_CAPACITY, 0);
+ }
+
+ if (u->cargo_cap != 0) {
+ uint cargo_count = u->cargo.Count();
+
+ y_offset += 11;
+ if (cargo_count != 0) {
+ /* Cargo names (fix pluralness) */
+ SetDParam(0, u->cargo_type);
+ SetDParam(1, cargo_count);
+ SetDParam(2, u->cargo.Source());
+ DrawString(x, y + 21 + y_offset, STR_8813_FROM, 0);
+ }
+ }
+ }
+
+ SetDParam(0, v->cargo.FeederShare());
+ DrawString(x, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, 0);
+}
+
+
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
{
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
@@ -56,172 +100,3 @@ void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2)
ShowVehicleViewWindow(v);
}
}
-
-static void AircraftDetailsWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_PAINT: {
- const Vehicle *v = GetVehicle(w->window_number);
-
- SetWindowWidgetDisabledState(w, 2, v->owner != _local_player);
-
- /* Disable service-scroller when interval is set to disabled */
- SetWindowWidgetDisabledState(w, 5, !_patches.servint_aircraft);
- SetWindowWidgetDisabledState(w, 6, !_patches.servint_aircraft);
-
- SetDParam(0, v->index);
- DrawWindowWidgets(w);
-
- /* Draw running cost */
- {
- int year = v->age / 366;
-
- SetDParam(1, year);
-
- SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
- SetDParam(2, v->max_age / 366);
- SetDParam(3, v->GetDisplayRunningCost());
- DrawString(2, 15, STR_A00D_AGE_RUNNING_COST_YR, 0);
- }
-
- /* Draw max speed */
- {
- SetDParam(0, v->GetDisplayMaxSpeed());
- DrawString(2, 25, STR_A00E_MAX_SPEED, 0);
- }
-
- /* Draw profit */
- {
- SetDParam(0, v->profit_this_year);
- SetDParam(1, v->profit_last_year);
- DrawString(2, 35, STR_A00F_PROFIT_THIS_YEAR_LAST_YEAR, 0);
- }
-
- /* Draw breakdown & reliability */
- {
- SetDParam(0, v->reliability * 100 >> 16);
- SetDParam(1, v->breakdowns_since_last_service);
- DrawString(2, 45, STR_A010_RELIABILITY_BREAKDOWNS, 0);
- }
-
- /* Draw service interval text */
- {
- SetDParam(0, v->service_interval);
- SetDParam(1, v->date_of_last_service);
- DrawString(13, 115, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0);
- }
-
- /* Draw Transfer credits text */
- {
- SetDParam(0, v->cargo.FeederShare());
- DrawString(60, 101, STR_FEEDER_CARGO_VALUE, 0);
- }
-
- DrawAircraftImage(v, 3, 57, INVALID_VEHICLE);
-
- {
- const Vehicle *u;
- int y = 57;
-
- do {
- if (IsNormalAircraft(v)) {
- SetDParam(0, v->engine_type);
- SetDParam(1, v->build_year);
- SetDParam(2, v->value);
- DrawString(60, y, STR_A011_BUILT_VALUE, 0);
- y += 10;
-
- SetDParam(0, v->cargo_type);
- SetDParam(1, v->cargo_cap);
- u = v->Next();
- SetDParam(2, u->cargo_type);
- SetDParam(3, u->cargo_cap);
- DrawString(60, y, (u->cargo_cap != 0) ? STR_A019_CAPACITY : STR_A01A_CAPACITY, 0);
- y += 14;
- }
-
- uint cargo_count = v->cargo.Count();
- if (cargo_count != 0) {
-
- /* Cargo names (fix pluralness) */
- SetDParam(0, v->cargo_type);
- SetDParam(1, cargo_count);
- SetDParam(2, v->cargo.Source());
- DrawString(60, y, STR_8813_FROM, 0);
-
- y += 10;
- }
- } while ((v = v->Next()) != NULL);
- }
- } break;
-
- case WE_CLICK: {
- int mod;
- const Vehicle *v;
- switch (e->we.click.widget) {
- case 2: /* rename */
- v = GetVehicle(w->window_number);
- SetDParam(0, v->index);
- ShowQueryString(STR_VEHICLE_NAME, STR_A030_NAME_AIRCRAFT, 31, 150, w, CS_ALPHANUMERAL);
- break;
- case 5: /* increase int */
- mod = _ctrl_pressed? 5 : 10;
- goto do_change_service_int;
- case 6: /* decrease int */
- mod = _ctrl_pressed?- 5 : -10;
-do_change_service_int:
- v = GetVehicle(w->window_number);
-
- mod = GetServiceIntervalClamped(mod + v->service_interval);
- if (mod == v->service_interval) return;
-
- DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
- break;
- }
- } break;
-
- case WE_ON_EDIT_TEXT:
- if (e->we.edittext.str[0] != '\0') {
- _cmd_text = e->we.edittext.str;
- DoCommandP(0, w->window_number, 0, NULL,
- CMD_NAME_VEHICLE | CMD_MSG(STR_A031_CAN_T_NAME_AIRCRAFT));
- }
- break;
- }
-}
-
-
-static const Widget _aircraft_details_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
-{ WWT_CAPTION, RESIZE_NONE, 14, 11, 349, 0, 13, STR_A00C_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS },
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 350, 389, 0, 13, STR_01AA_NAME, STR_A032_NAME_AIRCRAFT },
-{ WWT_PANEL, RESIZE_NONE, 14, 0, 389, 14, 55, 0x0, STR_NULL },
-{ WWT_PANEL, RESIZE_NONE, 14, 0, 389, 56, 113, 0x0, STR_NULL },
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 114, 119, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL },
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 120, 125, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL },
-{ WWT_PANEL, RESIZE_NONE, 14, 11, 389, 114, 125, 0x0, STR_NULL },
-{ WIDGETS_END},
-};
-
-static const WindowDesc _aircraft_details_desc = {
- WDP_AUTO, WDP_AUTO, 390, 126, 390, 126,
- WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
- _aircraft_details_widgets,
- AircraftDetailsWndProc
-};
-
-
-void ShowAircraftDetailsWindow(const Vehicle *v)
-{
- Window *w;
- VehicleID veh = v->index;
-
- DeleteWindowById(WC_VEHICLE_ORDERS, veh);
- DeleteWindowById(WC_VEHICLE_DETAILS, veh);
-
- w = AllocateWindowDescFront(&_aircraft_details_desc, veh);
- w->caption_color = v->owner;
-// w->vscroll.cap = 6;
-// w->traindetails_d.tab = 0;
-}
diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp
index 331053605..ae5bfd255 100644
--- a/src/roadveh_gui.cpp
+++ b/src/roadveh_gui.cpp
@@ -19,249 +19,104 @@
#include "vehicle_gui.h"
#include "newgrf_engine.h"
-static inline int RoadVehLengthToPixels(int length)
-{
- return (length * 28) / 8;
-}
-void DrawRoadVehImage(const Vehicle *v, int x, int y, int count, VehicleID selection)
+void DrawRoadVehDetails(const Vehicle *v, int x, int y)
{
- int dx = 0;
+ uint y_offset = RoadVehHasArticPart(v) ? 15 :0;
+ StringID str;
- /* Road vehicle lengths are measured in eighths of the standard length, so
- * count is the number of standard vehicles that should be drawn. If it is
- * 0, we draw enough vehicles for 10 standard vehicle lengths. */
- int max_length = (count == 0) ? 80 : count * 8;
+ SetDParam(0, v->engine_type);
+ SetDParam(1, v->build_year);
+ SetDParam(2, v->value);
+ DrawString(x, y + y_offset, STR_9011_BUILT_VALUE, 0);
- do {
- int length = v->u.road.cached_veh_length;
+ if (RoadVehHasArticPart(v)) {
+ AcceptedCargo max_cargo;
+ char capacity[512];
- if (dx + length > 0 && dx <= max_length) {
- SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
- DrawSprite(v->GetImage(DIR_W), pal, x + 14 + RoadVehLengthToPixels(dx), y + 6);
+ memset(max_cargo, 0, sizeof(max_cargo));
- if (v->index == selection) {
- DrawFrameRect(x - 1, y - 1, x + 28, y + 12, 15, FR_BORDERONLY);
- }
+ for (const Vehicle *u = v; u != NULL; u = u->Next()) {
+ max_cargo[u->cargo_type] += u->cargo_cap;
}
- dx += length;
- v = v->Next();
- } while (v != NULL && dx < max_length);
-}
-
-static void RoadVehDetailsWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_CREATE: {
- const Vehicle *v = GetVehicle(w->window_number);
-
- if (!RoadVehHasArticPart(v)) break;
-
- /* Draw the text under the vehicle instead of next to it, minus the
- * height already allocated for the cargo of the first vehicle. */
- uint height_extension = 15 - 11;
-
- /* Add space for the cargo amount for each part. */
- do {
- height_extension += 11;
- } while ((v = v->Next()) != NULL);
-
- ResizeWindow(w, 0, height_extension);
- } break;
-
- case WE_PAINT: {
- const Vehicle *v = GetVehicle(w->window_number);
- StringID str;
- uint y_offset = RoadVehHasArticPart(v) ? 15 :0;
-
- SetWindowWidgetDisabledState(w, 2, v->owner != _local_player);
- /* disable service-scroller when interval is set to disabled */
- SetWindowWidgetDisabledState(w, 5, !_patches.servint_roadveh);
- SetWindowWidgetDisabledState(w, 6, !_patches.servint_roadveh);
-
- SetDParam(0, v->index);
- DrawWindowWidgets(w);
-
- /* Draw running cost */
- {
- int year = v->age / 366;
-
- SetDParam(1, year);
-
- SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
- SetDParam(2, v->max_age / 366);
- SetDParam(3, v->GetDisplayRunningCost());
- DrawString(2, 15, STR_900D_AGE_RUNNING_COST_YR, 0);
- }
-
- /* Draw max speed */
- {
- SetDParam(0, v->GetDisplayMaxSpeed());
- DrawString(2, 25, STR_900E_MAX_SPEED, 0);
- }
-
- /* Draw profit */
- {
- SetDParam(0, v->profit_this_year);
- SetDParam(1, v->profit_last_year);
- DrawString(2, 35, STR_900F_PROFIT_THIS_YEAR_LAST_YEAR, 0);
- }
-
- /* Draw breakdown & reliability */
- {
- SetDParam(0, v->reliability * 100 >> 16);
- SetDParam(1, v->breakdowns_since_last_service);
- DrawString(2, 45, STR_9010_RELIABILITY_BREAKDOWNS, 0);
- }
-
- DrawRoadVehImage(v, 3, 57, 0, INVALID_VEHICLE);
-
- SetDParam(0, v->engine_type);
- SetDParam(1, v->build_year);
- SetDParam(2, v->value);
- DrawString(34, 57 + y_offset, STR_9011_BUILT_VALUE, 0);
-
- if (RoadVehHasArticPart(v)) {
- AcceptedCargo max_cargo;
- char capacity[512];
+ GetString(capacity, STR_ARTICULATED_RV_CAPACITY, lastof(capacity));
- memset(max_cargo, 0, sizeof(max_cargo));
+ bool first = true;
+ for (CargoID i = 0; i < NUM_CARGO; i++) {
+ if (max_cargo[i] > 0) {
+ char buffer[128];
- for (const Vehicle *u = v; u != NULL; u = u->Next()) {
- max_cargo[u->cargo_type] += u->cargo_cap;
- }
-
- GetString(capacity, STR_ARTICULATED_RV_CAPACITY, lastof(capacity));
-
- bool first = true;
- for (CargoID i = 0; i < NUM_CARGO; i++) {
- if (max_cargo[i] > 0) {
- char buffer[128];
-
- SetDParam(0, i);
- SetDParam(1, max_cargo[i]);
- GetString(buffer, STR_BARE_CARGO, lastof(buffer));
-
- if (!first) strecat(capacity, ", ", lastof(capacity));
- strecat(capacity, buffer, lastof(capacity));
+ SetDParam(0, i);
+ SetDParam(1, max_cargo[i]);
+ GetString(buffer, STR_BARE_CARGO, lastof(buffer));
- first = false;
- }
+ if (!first) strecat(capacity, ", ", lastof(capacity));
+ strecat(capacity, buffer, lastof(capacity));
+ first = false;
}
+ }
- SetDParamStr(0, capacity);
- DrawStringTruncated(34, 67 + y_offset, STR_JUST_STRING, 0, w->width - 34);
-
- for (const Vehicle *u = v; u != NULL; u = u->Next()) {
- str = STR_8812_EMPTY;
- if (!u->cargo.Empty()) {
- SetDParam(0, u->cargo_type);
- SetDParam(1, u->cargo.Count());
- SetDParam(2, u->cargo.Source());
- str = STR_8813_FROM;
- }
- DrawString(34, 78 + y_offset, str, 0);
-
- y_offset += 11;
- }
-
- y_offset -= 11;
- } else {
- SetDParam(0, v->cargo_type);
- SetDParam(1, v->cargo_cap);
- DrawString(34, 67 + y_offset, STR_9012_CAPACITY, 0);
+ SetDParamStr(0, capacity);
+ DrawStringTruncated(x, y + 10 + y_offset, STR_JUST_STRING, 0, 380 - x);
+ for (const Vehicle *u = v; u != NULL; u = u->Next()) {
str = STR_8812_EMPTY;
- if (!v->cargo.Empty()) {
- SetDParam(0, v->cargo_type);
- SetDParam(1, v->cargo.Count());
- SetDParam(2, v->cargo.Source());
+ if (!u->cargo.Empty()) {
+ SetDParam(0, u->cargo_type);
+ SetDParam(1, u->cargo.Count());
+ SetDParam(2, u->cargo.Source());
str = STR_8813_FROM;
}
- DrawString(34, 78 + y_offset, str, 0);
- }
-
- /* Draw Transfer credits text */
- SetDParam(0, v->cargo.FeederShare());
- DrawString(34, 90 + y_offset, STR_FEEDER_CARGO_VALUE, 0);
+ DrawString(x, y + 21 + y_offset, str, 0);
- /* Draw service interval text */
- {
- SetDParam(0, v->service_interval);
- SetDParam(1, v->date_of_last_service);
- DrawString(13, 102 + y_offset, _patches.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, 0);
+ y_offset += 11;
}
- } break;
-
- case WE_CLICK: {
- int mod;
- const Vehicle *v;
- switch (e->we.click.widget) {
- case 2: /* rename */
- v = GetVehicle(w->window_number);
- SetDParam(0, v->index);
- ShowQueryString(STR_VEHICLE_NAME, STR_902C_NAME_ROAD_VEHICLE, 31, 150, w, CS_ALPHANUMERAL);
- break;
-
- case 5: /* increase int */
- mod = _ctrl_pressed? 5 : 10;
- goto do_change_service_int;
- case 6: /* decrease int */
- mod = _ctrl_pressed? -5 : -10;
-do_change_service_int:
- v = GetVehicle(w->window_number);
- mod = GetServiceIntervalClamped(mod + v->service_interval);
- if (mod == v->service_interval) return;
+ y_offset -= 11;
+ } else {
+ SetDParam(0, v->cargo_type);
+ SetDParam(1, v->cargo_cap);
+ DrawString(x, y + 10 + y_offset, STR_9012_CAPACITY, 0);
- DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
- break;
- }
- } break;
-
- case WE_ON_EDIT_TEXT: {
- if (e->we.edittext.str[0] != '\0') {
- _cmd_text = e->we.edittext.str;
- DoCommandP(0, w->window_number, 0, NULL,
- CMD_NAME_VEHICLE | CMD_MSG(STR_902D_CAN_T_NAME_ROAD_VEHICLE));
+ str = STR_8812_EMPTY;
+ if (!v->cargo.Empty()) {
+ SetDParam(0, v->cargo_type);
+ SetDParam(1, v->cargo.Count());
+ SetDParam(2, v->cargo.Source());
+ str = STR_8813_FROM;
}
- } break;
-
+ DrawString(x, y + 21 + y_offset, str, 0);
}
-}
-static const Widget _roadveh_details_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_NONE, 14, 11, 339, 0, 13, STR_900C_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 340, 379, 0, 13, STR_01AA_NAME, STR_902E_NAME_ROAD_VEHICLE},
-{ WWT_PANEL, RESIZE_NONE, 14, 0, 379, 14, 55, 0x0, STR_NULL},
-{ WWT_PANEL, RESIZE_BOTTOM, 14, 0, 379, 56, 100, 0x0, STR_NULL},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 101, 106, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 107, 112, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL},
-{ WWT_PANEL, RESIZE_TB, 14, 11, 379, 101, 112, 0x0, STR_NULL},
-{ WIDGETS_END},
-};
+ /* Draw Transfer credits text */
+ SetDParam(0, v->cargo.FeederShare());
+ DrawString(x, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, 0);
+}
-static const WindowDesc _roadveh_details_desc = {
- WDP_AUTO, WDP_AUTO, 380, 113, 380, 113,
- WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
- _roadveh_details_widgets,
- RoadVehDetailsWndProc
-};
+static inline int RoadVehLengthToPixels(int length)
+{
+ return (length * 28) / 8;
+}
-void ShowRoadVehDetailsWindow(const Vehicle *v)
+void DrawRoadVehImage(const Vehicle *v, int x, int y, int count, VehicleID selection)
{
- Window *w;
- VehicleID veh = v->index;
+ /* Road vehicle lengths are measured in eighths of the standard length, so
+ * count is the number of standard vehicles that should be drawn. If it is
+ * 0, we draw enough vehicles for 10 standard vehicle lengths. */
+ int max_length = (count == 0) ? 80 : count * 8;
- DeleteWindowById(WC_VEHICLE_ORDERS, veh);
- DeleteWindowById(WC_VEHICLE_DETAILS, veh);
+ for (int dx = 0 ; v != NULL && dx < max_length ; dx += v->u.road.cached_veh_length, v = v->Next()) {
+ if (dx + v->u.road.cached_veh_length > 0 && dx <= max_length) {
+ SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
+ DrawSprite(v->GetImage(DIR_W), pal, x + 14 + RoadVehLengthToPixels(dx), y + 6);
- w = AllocateWindowDescFront(&_roadveh_details_desc, veh);
- w->caption_color = v->owner;
+ if (v->index == selection) {
+ DrawFrameRect(x - 1, y - 1, x + 28, y + 12, 15, FR_BORDERONLY);
+ }
+ }
+ }
}
void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2)
diff --git a/src/ship_gui.cpp b/src/ship_gui.cpp
index 5f7bdd1fe..1e885de86 100644
--- a/src/ship_gui.cpp
+++ b/src/ship_gui.cpp
@@ -27,153 +27,6 @@ void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection)
}
}
-static void ShipDetailsWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_PAINT: {
- const Vehicle *v = GetVehicle(w->window_number);
- StringID str;
-
- SetWindowWidgetDisabledState(w, 2, v->owner != _local_player);
- /* disable service-scroller when interval is set to disabled */
- SetWindowWidgetDisabledState(w, 5, !_patches.servint_ships);
- SetWindowWidgetDisabledState(w, 6, !_patches.servint_ships);
-
- SetDParam(0, v->index);
- DrawWindowWidgets(w);
-
- /* Draw running cost */
- {
- int year = v->age / 366;
-
- SetDParam(1, year);
-
- SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
- SetDParam(2, v->max_age / 366);
- SetDParam(3, v->GetDisplayRunningCost());
- DrawString(2, 15, STR_9812_AGE_RUNNING_COST_YR, 0);
- }
-
- /* Draw max speed */
- {
- SetDParam(0, v->GetDisplayMaxSpeed());
- DrawString(2, 25, STR_9813_MAX_SPEED, 0);
- }
-
- /* Draw profit */
- {
- SetDParam(0, v->profit_this_year);
- SetDParam(1, v->profit_last_year);
- DrawString(2, 35, STR_9814_PROFIT_THIS_YEAR_LAST_YEAR, 0);
- }
-
- /* Draw breakdown & reliability */
- {
- SetDParam(0, v->reliability * 100 >> 16);
- SetDParam(1, v->breakdowns_since_last_service);
- DrawString(2, 45, STR_9815_RELIABILITY_BREAKDOWNS, 0);
- }
-
- /* Draw service interval text */
- {
- SetDParam(0, v->service_interval);
- SetDParam(1, v->date_of_last_service);
- DrawString(13, 102, _patches.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, 0);
- }
-
- DrawShipImage(v, 3, 57, INVALID_VEHICLE);
-
- SetDParam(0, v->engine_type);
- SetDParam(1, v->build_year);
- SetDParam(2, v->value);
- DrawString(74, 57, STR_9816_BUILT_VALUE, 0);
-
- SetDParam(0, v->cargo_type);
- SetDParam(1, v->cargo_cap);
- DrawString(74, 67, STR_9817_CAPACITY, 0);
-
- str = STR_8812_EMPTY;
- if (!v->cargo.Empty()) {
- SetDParam(0, v->cargo_type);
- SetDParam(1, v->cargo.Count());
- SetDParam(2, v->cargo.Source());
- str = STR_8813_FROM;
- }
- DrawString(74, 78, str, 0);
-
- /* Draw Transfer credits text */
- SetDParam(0, v->cargo.FeederShare());
- DrawString(74, 89, STR_FEEDER_CARGO_VALUE, 0);
-
- } break;
-
- case WE_CLICK: {
- int mod;
- const Vehicle *v;
- switch (e->we.click.widget) {
- case 2: /* rename */
- v = GetVehicle(w->window_number);
- SetDParam(0, v->index);
- ShowQueryString(STR_VEHICLE_NAME, STR_9831_NAME_SHIP, 31, 150, w, CS_ALPHANUMERAL);
- break;
- case 5: /* increase int */
- mod = _ctrl_pressed? 5 : 10;
- goto do_change_service_int;
- case 6: /* decrease int */
- mod = _ctrl_pressed ? - 5 : -10;
-do_change_service_int:
- v = GetVehicle(w->window_number);
-
- mod = GetServiceIntervalClamped(mod + v->service_interval);
- if (mod == v->service_interval) return;
-
- DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
- break;
- }
- } break;
-
- case WE_ON_EDIT_TEXT:
- if (e->we.edittext.str[0] != '\0') {
- _cmd_text = e->we.edittext.str;
- DoCommandP(0, w->window_number, 0, NULL,
- CMD_NAME_VEHICLE | CMD_MSG(STR_9832_CAN_T_NAME_SHIP));
- }
- break;
- }
-}
-
-
-static const Widget _ship_details_widgets[] = {
-{ 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},
-{ WWT_PANEL, RESIZE_NONE, 14, 0, 404, 14, 55, 0x0, STR_NULL},
-{ 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},
-{ WIDGETS_END},
-};
-
-static const WindowDesc _ship_details_desc = {
- WDP_AUTO, WDP_AUTO, 405, 113, 405, 113,
- WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
- _ship_details_widgets,
- ShipDetailsWndProc
-};
-
-void ShowShipDetailsWindow(const Vehicle *v)
-{
- Window *w;
- VehicleID veh = v->index;
-
- DeleteWindowById(WC_VEHICLE_ORDERS, veh);
- DeleteWindowById(WC_VEHICLE_DETAILS, veh);
- w = AllocateWindowDescFront(&_ship_details_desc, veh);
- w->caption_color = v->owner;
-}
-
void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2)
{
const Vehicle *v;
@@ -186,3 +39,35 @@ void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2)
}
ShowVehicleViewWindow(v);
}
+
+/**
+* Draw the details for the given vehicle at the position (x,y)
+*
+* @param v current vehicle
+* @param x The x coordinate
+* @param y The y coordinate
+*/
+void DrawShipDetails(const Vehicle *v, int x, int y)
+{
+ SetDParam(0, v->engine_type);
+ SetDParam(1, v->build_year);
+ SetDParam(2, v->value);
+ DrawString(x, y, STR_9816_BUILT_VALUE, 0);
+
+ SetDParam(0, v->cargo_type);
+ SetDParam(1, v->cargo_cap);
+ DrawString(x, y + 10, STR_9817_CAPACITY, 0);
+
+ StringID str = STR_8812_EMPTY;
+ if (!v->cargo.Empty()) {
+ SetDParam(0, v->cargo_type);
+ SetDParam(1, v->cargo.Count());
+ SetDParam(2, v->cargo.Source());
+ str = STR_8813_FROM;
+ }
+ DrawString(x, y + 21, str, 0);
+
+ /* Draw Transfer credits text */
+ SetDParam(0, v->cargo.FeederShare());
+ DrawString(x, y + 33, STR_FEEDER_CARGO_VALUE, 0);
+}
diff --git a/src/train_gui.cpp b/src/train_gui.cpp
index cf8dcbc15..78672613c 100644
--- a/src/train_gui.cpp
+++ b/src/train_gui.cpp
@@ -152,31 +152,20 @@ static void TrainDetailsCapacityTab(const Vehicle *v, int x, int y)
}
}
-
-static void DrawTrainDetailsWindow(Window *w)
+int GetTrainDetailsWndVScroll(VehicleID veh_id, byte det_tab)
{
- byte det_tab = WP(w, traindetails_d).tab;
- const Vehicle *v;
- const Vehicle *u;
AcceptedCargo act_cargo;
AcceptedCargo max_cargo;
- int num;
- int x;
- int y;
- int sel;
+ int num = 0;
- num = 0;
- u = v = GetVehicle(w->window_number);
if (det_tab == 3) { // Total cargo tab
- for (CargoID i = 0; i < lengthof(act_cargo); i++) {
- act_cargo[i] = 0;
- max_cargo[i] = 0;
- }
+ memset(max_cargo, 0, sizeof(max_cargo));
+ memset(act_cargo, 0, sizeof(act_cargo));
- do {
- act_cargo[u->cargo_type] += u->cargo.Count();
- max_cargo[u->cargo_type] += u->cargo_cap;
- } while ((u = u->Next()) != NULL);
+ for (const Vehicle *v = GetVehicle(veh_id) ; v != NULL ; v = v->Next()) {
+ act_cargo[v->cargo_type] += v->cargo.Count();
+ max_cargo[v->cargo_type] += v->cargo_cap;
+ }
/* Set scroll-amount seperately from counting, as to not compute num double
* for more carriages of the same type
@@ -186,60 +175,22 @@ static void DrawTrainDetailsWindow(Window *w)
}
num++; // needs one more because first line is description string
} else {
- do {
- if (!IsArticulatedPart(u) || u->cargo_cap != 0) num++;
- } while ((u = u->Next()) != NULL);
+ for (const Vehicle *v = GetVehicle(veh_id) ; v != NULL ; v = v->Next()) {
+ if (!IsArticulatedPart(v) || v->cargo_cap != 0) num++;
+ }
}
- SetVScrollCount(w, num);
-
- DisableWindowWidget(w, det_tab + 9);
- SetWindowWidgetDisabledState(w, 2, v->owner != _local_player);
-
- /* disable service-scroller when interval is set to disabled */
- SetWindowWidgetDisabledState(w, 6, !_patches.servint_trains);
- SetWindowWidgetDisabledState(w, 7, !_patches.servint_trains);
-
- SetDParam(0, v->index);
- DrawWindowWidgets(w);
-
- SetDParam(1, v->age / 366);
-
- x = 2;
-
- SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
- SetDParam(2, v->max_age / 366);
- SetDParam(3, v->GetDisplayRunningCost());
- DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0);
-
- SetDParam(2, v->GetDisplayMaxSpeed());
- SetDParam(1, v->u.rail.cached_power);
- SetDParam(0, v->u.rail.cached_weight);
- SetDParam(3, v->u.rail.cached_max_te / 1000);
- DrawString(x, 25, (_patches.realistic_acceleration && v->u.rail.railtype != RAILTYPE_MAGLEV) ?
- STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE :
- STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, 0);
-
- SetDParam(0, v->profit_this_year);
- SetDParam(1, v->profit_last_year);
- DrawString(x, 35, STR_885F_PROFIT_THIS_YEAR_LAST_YEAR, 0);
-
- SetDParam(0, 100 * (v->reliability>>8) >> 8);
- SetDParam(1, v->breakdowns_since_last_service);
- DrawString(x, 45, STR_8860_RELIABILITY_BREAKDOWNS, 0);
-
- SetDParam(0, v->service_interval);
- SetDParam(1, v->date_of_last_service);
- DrawString(x + 11, 57 + (w->vscroll.cap * 14), _patches.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, 0);
-
- y = 57;
- sel = w->vscroll.pos;
+ return num;
+}
+void DrawTrainDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint16 vscroll_cap, byte det_tab)
+{
/* draw the first 3 details tabs */
if (det_tab != 3) {
+ const Vehicle *u = v;
x = 1;
for (;;) {
- if (--sel < 0 && sel >= -w->vscroll.cap) {
+ if (--vscroll_pos < 0 && vscroll_pos >= -vscroll_cap) {
int dx = 0;
int px;
int py;
@@ -277,10 +228,21 @@ static void DrawTrainDetailsWindow(Window *w)
if (v == NULL) return;
}
} else {
+ AcceptedCargo act_cargo;
+ AcceptedCargo max_cargo;
+
+ memset(max_cargo, 0, sizeof(max_cargo));
+ memset(act_cargo, 0, sizeof(act_cargo));
+
+ for (const Vehicle *u = v; u != NULL ; u = u->Next()) {
+ act_cargo[u->cargo_type] += u->cargo.Count();
+ max_cargo[u->cargo_type] += u->cargo_cap;
+ }
+
/* draw total cargo tab */
DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY_TEXT, 0);
for (CargoID i = 0; i < NUM_CARGO; i++) {
- if (max_cargo[i] > 0 && --sel < 0 && sel > -w->vscroll.cap) {
+ if (max_cargo[i] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
y += 14;
SetDParam(0, i); // {CARGO} #1
SetDParam(1, act_cargo[i]); // {CARGO} #2
@@ -294,114 +256,3 @@ static void DrawTrainDetailsWindow(Window *w)
DrawString(x, y + 15, STR_FEEDER_CARGO_VALUE, 0);
}
}
-
-static void TrainDetailsWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_PAINT:
- DrawTrainDetailsWindow(w);
- break;
- case WE_CLICK: {
- int mod;
- const Vehicle *v;
- switch (e->we.click.widget) {
- case 2: /* name train */
- v = GetVehicle(w->window_number);
- SetDParam(0, v->index);
- ShowQueryString(STR_VEHICLE_NAME, STR_8865_NAME_TRAIN, 31, 150, w, CS_ALPHANUMERAL);
- break;
- case 6: /* inc serv interval */
- mod = _ctrl_pressed? 5 : 10;
- goto do_change_service_int;
-
- case 7: /* dec serv interval */
- mod = _ctrl_pressed? -5 : -10;
-do_change_service_int:
- v = GetVehicle(w->window_number);
-
- mod = GetServiceIntervalClamped(mod + v->service_interval);
- if (mod == v->service_interval) return;
-
- DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
- break;
- /* details buttons*/
- case 9: // Cargo
- case 10: // Information
- case 11: // Capacities
- case 12: // Total cargo
- EnableWindowWidget(w, 9);
- EnableWindowWidget(w, 10);
- EnableWindowWidget(w, 11);
- EnableWindowWidget(w, 12);
- EnableWindowWidget(w, e->we.click.widget);
- WP(w,traindetails_d).tab = e->we.click.widget - 9;
- SetWindowDirty(w);
- break;
- }
- } break;
-
- case WE_ON_EDIT_TEXT:
- if (e->we.edittext.str[0] != '\0') {
- _cmd_text = e->we.edittext.str;
- DoCommandP(0, w->window_number, 0, NULL,
- CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN));
- }
- break;
-
- case WE_RESIZE:
- if (e->we.sizing.diff.x != 0) ResizeButtons(w, 9, 12);
- if (e->we.sizing.diff.y == 0) break;
-
- w->vscroll.cap += e->we.sizing.diff.y / 14;
- w->widget[4].data = (w->vscroll.cap << 8) + 1;
- break;
- }
-}
-
-static const Widget _train_details_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 329, 0, 13, STR_8802_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PUSHTXTBTN, RESIZE_LR, 14, 330, 369, 0, 13, STR_01AA_NAME, STR_8867_NAME_TRAIN},
-{ WWT_PANEL, RESIZE_RIGHT, 14, 0, 369, 14, 55, 0x0, STR_NULL},
-{ WWT_MATRIX, RESIZE_RB, 14, 0, 357, 56, 139, 0x601, STR_NULL},
-{ WWT_SCROLLBAR, RESIZE_LRB, 14, 358, 369, 56, 139, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 140, 145, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 146, 151, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL},
-{ WWT_PANEL, RESIZE_RTB, 14, 11, 369, 140, 151, 0x0, STR_NULL},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 89, 152, 163, STR_013C_CARGO, STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 90, 178, 152, 163, STR_013D_INFORMATION, STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES},
-{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 179, 268, 152, 163, STR_013E_CAPACITIES, STR_8851_SHOW_CAPACITIES_OF_EACH},
-{ WWT_PUSHTXTBTN, RESIZE_RTB, 14, 269, 357, 152, 163, STR_013E_TOTAL_CARGO, STR_8852_SHOW_TOTAL_CARGO},
-{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 358, 369, 152, 163, 0x0, STR_RESIZE_BUTTON},
-{ WIDGETS_END},
-};
-
-
-static const WindowDesc _train_details_desc = {
- WDP_AUTO, WDP_AUTO, 370, 164, 370, 164,
- WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
- _train_details_widgets,
- TrainDetailsWndProc
-};
-
-
-void ShowTrainDetailsWindow(const Vehicle *v)
-{
- Window *w;
- VehicleID veh = v->index;
-
- DeleteWindowById(WC_VEHICLE_ORDERS, veh);
- DeleteWindowById(WC_VEHICLE_DETAILS, veh);
-
- w = AllocateWindowDescFront(&_train_details_desc, veh);
-
- w->caption_color = v->owner;
- w->vscroll.cap = 6;
- w->widget[4].data = (w->vscroll.cap << 8) + 1;
-
- w->resize.step_height = 14;
- w->resize.height = w->height - 14 * 2; /* Minimum of 4 wagons in the display */
-
- WP(w,traindetails_d).tab = 0;
-}
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index da36d99f9..316295ef9 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1273,6 +1273,374 @@ void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, TileIndex
}
+/* Unified vehicle GUI - Vehicle Details Window */
+
+/** Constants of vehicle details widget indices */
+enum VehicleDetailsWindowWidgets {
+ VLD_WIDGET_CLOSEBOX = 0,
+ VLD_WIDGET_CAPTION,
+ VLD_WIDGET_RENAME_VEHICLE,
+ VLD_WIDGET_TOP_DETAILS,
+ VLD_WIDGET_INCREASE_SERVICING_INTERVAL,
+ VLD_WIDGET_DECREASE_SERVICING_INTERVAL,
+ VLD_WIDGET_BOTTOM_RIGHT,
+ VLD_WIDGET_MIDDLE_DETAILS,
+ VLD_WIDGET_SCROLLBAR,
+ VLD_WIDGET_DETAILS_CARGO_CARRIED,
+ VLD_WIDGET_DETAILS_TRAIN_VEHICLES,
+ VLD_WIDGET_DETAILS_CAPACITY_OF_EACH,
+ VLD_WIDGET_DETAILS_TOTAL_CARGO,
+ VLD_WIDGET_RESIZE,
+};
+
+/** Vehicle details widgets. */
+static const Widget _vehicle_details_widgets[] = {
+ { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // VLD_WIDGET_CLOSEBOX
+ { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 364, 0, 13, 0x0, STR_018C_WINDOW_TITLE_DRAG_THIS}, // VLD_WIDGET_CAPTION
+ { WWT_PUSHTXTBTN, RESIZE_LR, 14, 365, 404, 0, 13, STR_01AA_NAME, STR_NULL /* filled in later */}, // VLD_WIDGET_RENAME_VEHICLE
+ { WWT_PANEL, RESIZE_RIGHT, 14, 0, 404, 14, 55, 0x0, STR_NULL}, // VLD_WIDGET_TOP_DETAILS
+ { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 101, 106, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL}, // VLD_WIDGET_INCREASE_SERVICING_INTERVAL
+ { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 107, 112, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL}, // VLD_WIDGET_DECREASE_SERVICING_INTERVAL
+ { WWT_PANEL, RESIZE_RTB, 14, 11, 404, 101, 112, 0x0, STR_NULL}, // VLD_WIDGET_BOTTOM_RIGHT
+ { WWT_MATRIX, RESIZE_RB, 14, 0, 392, 56, 100, 0x701, STR_NULL}, // VLD_WIDGET_MIDDLE_DETAILS
+ { WWT_SCROLLBAR, RESIZE_LRB, 14, 393, 404, 56, 100, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // VLD_WIDGET_SCROLLBAR
+ { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 95, 113, 124, STR_013C_CARGO, STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED}, // VLD_WIDGET_DETAILS_CARGO_CARRIED
+ { WWT_PUSHTXTBTN, RESIZE_TB, 14, 96, 194, 113, 124, STR_013D_INFORMATION, STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES},// VLD_WIDGET_DETAILS_TRAIN_VEHICLES
+ { WWT_PUSHTXTBTN, RESIZE_TB, 14, 195, 293, 113, 124, STR_013E_CAPACITIES, STR_8851_SHOW_CAPACITIES_OF_EACH}, // VLD_WIDGET_DETAILS_CAPACITY_OF_EACH
+ { WWT_PUSHTXTBTN, RESIZE_RTB, 14, 294, 392, 113, 124, STR_013E_TOTAL_CARGO, STR_8852_SHOW_TOTAL_CARGO}, // VLD_WIDGET_DETAILS_TOTAL_CARGO
+ { WWT_RESIZEBOX, RESIZE_LRTB, 14, 393, 404, 113, 124, 0x0, STR_RESIZE_BUTTON}, // VLD_RESIZE
+ { WIDGETS_END},
+};
+
+
+/** Command indices for the _vehicle_command_translation_table. */
+enum VehicleStringTranslation {
+ VST_VEHICLE_AGE_RUNNING_COST_YR,
+ VST_VEHICLE_MAX_SPEED,
+ VST_VEHICLE_PROFIT_THIS_YEAR_LAST_YEAR,
+ VST_VEHICLE_RELIABILITY_BREAKDOWNS,
+};
+
+/** Command codes for the shared buttons indexed by VehicleCommandTranslation and vehicle type. */
+static const StringID _vehicle_translation_table[][4] = {
+ { // VST_VEHICLE_AGE_RUNNING_COST_YR
+ STR_885D_AGE_RUNNING_COST_YR,
+ STR_900D_AGE_RUNNING_COST_YR,
+ STR_9812_AGE_RUNNING_COST_YR,
+ STR_A00D_AGE_RUNNING_COST_YR,
+ },
+ { // VST_VEHICLE_MAX_SPEED
+ STR_NULL,
+ STR_900E_MAX_SPEED,
+ STR_9813_MAX_SPEED,
+ STR_A00E_MAX_SPEED,
+ },
+ { // VST_VEHICLE_PROFIT_THIS_YEAR_LAST_YEAR
+ STR_885F_PROFIT_THIS_YEAR_LAST_YEAR,
+ STR_900F_PROFIT_THIS_YEAR_LAST_YEAR,
+ STR_9814_PROFIT_THIS_YEAR_LAST_YEAR,
+ STR_A00F_PROFIT_THIS_YEAR_LAST_YEAR,
+ },
+ { // VST_VEHICLE_RELIABILITY_BREAKDOWNS
+ STR_8860_RELIABILITY_BREAKDOWNS,
+ STR_9010_RELIABILITY_BREAKDOWNS,
+ STR_9815_RELIABILITY_BREAKDOWNS,
+ STR_A010_RELIABILITY_BREAKDOWNS,
+ },
+};
+
+/** Initialize a newly created vehicle details window */
+void CreateVehicleDetailsWindow(Window *w)
+{
+ const Vehicle *v = GetVehicle(w->window_number);
+
+ switch (v->type) {
+ case VEH_TRAIN:
+ ResizeWindow(w, 0, 39);
+
+ w->vscroll.cap = 6;
+ w->height += 12;
+ w->resize.step_height = 14;
+ w->resize.height = w->height - 14 * 2; // Minimum of 4 wagons in the display
+
+ w->widget[VLD_WIDGET_RENAME_VEHICLE].tooltips = STR_8867_NAME_TRAIN;
+ w->widget[VLD_WIDGET_CAPTION].data = STR_8802_DETAILS;
+ break;
+
+ case VEH_ROAD: {
+ w->widget[VLD_WIDGET_CAPTION].data = STR_900C_DETAILS;
+ w->widget[VLD_WIDGET_RENAME_VEHICLE].tooltips = STR_902E_NAME_ROAD_VEHICLE;
+
+ if (!RoadVehHasArticPart(v)) break;
+
+ /* Draw the text under the vehicle instead of next to it, minus the
+ * height already allocated for the cargo of the first vehicle. */
+ uint height_extension = 15 - 11;
+
+ /* Add space for the cargo amount for each part. */
+ for (const Vehicle *u = v; u != NULL; u = u->Next()) {
+ height_extension += 11;
+ }
+
+ ResizeWindow(w, 0, height_extension);
+ } break;
+
+ case VEH_SHIP:
+ w->widget[VLD_WIDGET_RENAME_VEHICLE].tooltips = STR_982F_NAME_SHIP;
+ w->widget[VLD_WIDGET_CAPTION].data = STR_9811_DETAILS;
+ break;
+
+ case VEH_AIRCRAFT:
+ ResizeWindow(w, 0, 11);
+ w->widget[VLD_WIDGET_RENAME_VEHICLE].tooltips = STR_A032_NAME_AIRCRAFT;
+ w->widget[VLD_WIDGET_CAPTION].data = STR_A00C_DETAILS;
+ break;
+ default: NOT_REACHED();
+ }
+
+ if (v->type != VEH_TRAIN) {
+ w->vscroll.cap = 1;
+ w->widget[VLD_WIDGET_MIDDLE_DETAILS].right += 12;
+ }
+
+ w->widget[VLD_WIDGET_MIDDLE_DETAILS].data = (w->vscroll.cap << 8) + 1;
+ w->caption_color = v->owner;
+
+ WP(w, vehicledetails_d).tab = 0;
+}
+
+/** Checks whether service interval is enabled for the vehicle. */
+static bool inline IsVehicleServiceIntervalEnabled(const VehicleType vehicle_type)
+{
+ switch (vehicle_type) {
+ case VEH_TRAIN: return _patches.servint_trains != 0; break;
+ case VEH_ROAD: return _patches.servint_roadveh != 0; break;
+ case VEH_SHIP: return _patches.servint_ships != 0; break;
+ case VEH_AIRCRAFT: return _patches.servint_aircraft != 0; break;
+ default: NOT_REACHED();
+ }
+}
+
+extern int GetTrainDetailsWndVScroll(VehicleID veh_id, byte det_tab);
+extern void DrawTrainDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint16 vscroll_cap, byte det_tab);
+extern void DrawRoadVehDetails(const Vehicle *v, int x, int y);
+extern void DrawShipDetails(const Vehicle *v, int x, int y);
+extern void DrawAircraftDetails(const Vehicle *v, int x, int y);
+
+/**
+* Draw the details for the given vehicle at the position (x,y) of the Details windows
+*
+* @param v current vehicle
+* @param x The x coordinate
+* @param y The y coordinate
+* @param vscroll_pos (train only)
+* @param vscroll_cap (train only)
+* @param det_tab (train only)
+*/
+static inline void DrawVehicleDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint vscroll_cap, byte det_tab)
+{
+ switch (v->type) {
+ case VEH_TRAIN: DrawTrainDetails(v, x, y, vscroll_pos, vscroll_cap, det_tab); break;
+ case VEH_ROAD: DrawRoadVehDetails(v, x, y); break;
+ case VEH_SHIP: DrawShipDetails(v, x, y); break;
+ case VEH_AIRCRAFT: DrawAircraftDetails(v, x, y); break;
+ default: NOT_REACHED();
+ }
+}
+
+/** Repaint vehicle details window. */
+static void DrawVehicleDetailsWindow(Window *w)
+{
+ const Vehicle *v = GetVehicle(w->window_number);
+ byte det_tab = WP(w, vehicledetails_d).tab;
+
+ SetWindowWidgetDisabledState(w, VLD_WIDGET_RENAME_VEHICLE, v->owner != _local_player);
+
+ if (v->type == VEH_TRAIN) {
+ DisableWindowWidget(w, det_tab + 9);
+ SetVScrollCount(w, GetTrainDetailsWndVScroll(v->index, det_tab));
+ }
+
+ SetWindowWidgetsHiddenState(w, v->type != VEH_TRAIN,
+ VLD_WIDGET_SCROLLBAR,
+ VLD_WIDGET_DETAILS_CARGO_CARRIED,
+ VLD_WIDGET_DETAILS_TRAIN_VEHICLES,
+ VLD_WIDGET_DETAILS_CAPACITY_OF_EACH,
+ VLD_WIDGET_DETAILS_TOTAL_CARGO,
+ VLD_WIDGET_RESIZE,
+ WIDGET_LIST_END);
+
+ /* Disable service-scroller when interval is set to disabled */
+ SetWindowWidgetsDisabledState(w, !IsVehicleServiceIntervalEnabled(v->type),
+ VLD_WIDGET_INCREASE_SERVICING_INTERVAL,
+ VLD_WIDGET_DECREASE_SERVICING_INTERVAL,
+ WIDGET_LIST_END);
+
+
+ SetDParam(0, v->index);
+ DrawWindowWidgets(w);
+
+ /* Draw running cost */
+ SetDParam(1, v->age / 366);
+ SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
+ SetDParam(2, v->max_age / 366);
+ SetDParam(3, v->GetDisplayRunningCost());
+ DrawString(2, 15, _vehicle_translation_table[VST_VEHICLE_AGE_RUNNING_COST_YR][v->type], 0);
+
+ /* Draw max speed */
+ switch (v->type) {
+ case VEH_TRAIN:
+ SetDParam(2, v->GetDisplayMaxSpeed());
+ SetDParam(1, v->u.rail.cached_power);
+ SetDParam(0, v->u.rail.cached_weight);
+ SetDParam(3, v->u.rail.cached_max_te / 1000);
+ DrawString(2, 25, (_patches.realistic_acceleration && v->u.rail.railtype != RAILTYPE_MAGLEV) ?
+ STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE :
+ STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, 0);
+ break;
+
+ case VEH_ROAD:
+ case VEH_SHIP:
+ case VEH_AIRCRAFT:
+ SetDParam(0, v->GetDisplayMaxSpeed());
+ DrawString(2, 25, _vehicle_translation_table[VST_VEHICLE_MAX_SPEED][v->type], 0);
+ break;
+
+ default: NOT_REACHED();
+ }
+
+ /* Draw profit */
+ SetDParam(0, v->profit_this_year);
+ SetDParam(1, v->profit_last_year);
+ DrawString(2, 35, _vehicle_translation_table[VST_VEHICLE_PROFIT_THIS_YEAR_LAST_YEAR][v->type], 0);
+
+ /* Draw breakdown & reliability */
+ SetDParam(0, v->reliability * 100 >> 16);
+ SetDParam(1, v->breakdowns_since_last_service);
+ DrawString(2, 45, _vehicle_translation_table[VST_VEHICLE_RELIABILITY_BREAKDOWNS][v->type], 0);
+
+ /* Draw service interval text */
+ SetDParam(0, v->service_interval);
+ SetDParam(1, v->date_of_last_service);
+ DrawString(13, w->height - (v->type != VEH_TRAIN ? 11 : 23), _patches.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, 0);
+
+ switch (v->type) {
+ case VEH_TRAIN:
+ DrawVehicleDetails(v, 2, 57, w->vscroll.pos, w->vscroll.cap, det_tab);
+ break;
+
+ case VEH_ROAD:
+ case VEH_SHIP:
+ case VEH_AIRCRAFT:
+ DrawVehicleImage(v, 3, 57, 0, 0, INVALID_VEHICLE);
+ DrawVehicleDetails(v, 75, 57, w->vscroll.pos, w->vscroll.cap, det_tab);
+ break;
+
+ default: NOT_REACHED();
+ }
+}
+
+/** Message strings for renaming vehicles indexed by vehicle type. */
+static const StringID _name_vehicle_title[] = {
+ STR_8865_NAME_TRAIN,
+ STR_902C_NAME_ROAD_VEHICLE,
+ STR_9831_NAME_SHIP,
+ STR_A030_NAME_AIRCRAFT
+};
+
+/** Message strings for error while renaming indexed by vehicle type. */
+static const StringID _name_vehicle_error[] = {
+ STR_8866_CAN_T_NAME_TRAIN,
+ STR_902D_CAN_T_NAME_ROAD_VEHICLE,
+ STR_9832_CAN_T_NAME_SHIP,
+ STR_A031_CAN_T_NAME_AIRCRAFT
+};
+
+/** Window event hook for vehicle details. */
+static void VehicleDetailsWndProc(Window *w, WindowEvent *e)
+{
+ switch (e->event) {
+ case WE_CREATE:
+ CreateVehicleDetailsWindow(w);
+ break;
+
+ case WE_PAINT:
+ DrawVehicleDetailsWindow(w);
+ break;
+
+ case WE_CLICK: {
+ switch (e->we.click.widget) {
+ case VLD_WIDGET_RENAME_VEHICLE: {// rename
+ const Vehicle *v = GetVehicle(w->window_number);
+ SetDParam(0, v->index);
+ ShowQueryString(STR_VEHICLE_NAME, _name_vehicle_title[v->type], 31, 150, w, CS_ALPHANUMERAL);
+ } break;
+
+ case VLD_WIDGET_INCREASE_SERVICING_INTERVAL: // increase int
+ case VLD_WIDGET_DECREASE_SERVICING_INTERVAL: { // decrease int
+ int mod = _ctrl_pressed ? 5 : 10;
+ const Vehicle *v = GetVehicle(w->window_number);
+
+ mod = (e->we.click.widget == VLD_WIDGET_DECREASE_SERVICING_INTERVAL) ? -mod : mod;
+ mod = GetServiceIntervalClamped(mod + v->service_interval);
+ if (mod == v->service_interval) return;
+
+ DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
+ } break;
+
+ case VLD_WIDGET_DETAILS_CARGO_CARRIED:
+ case VLD_WIDGET_DETAILS_TRAIN_VEHICLES:
+ case VLD_WIDGET_DETAILS_CAPACITY_OF_EACH:
+ case VLD_WIDGET_DETAILS_TOTAL_CARGO:
+ SetWindowWidgetsDisabledState(w, false,
+ VLD_WIDGET_DETAILS_CARGO_CARRIED,
+ VLD_WIDGET_DETAILS_TRAIN_VEHICLES,
+ VLD_WIDGET_DETAILS_CAPACITY_OF_EACH,
+ VLD_WIDGET_DETAILS_TOTAL_CARGO,
+ e->we.click.widget,
+ WIDGET_LIST_END);
+
+ WP(w, vehicledetails_d).tab = e->we.click.widget - 9;
+ SetWindowDirty(w);
+ break;
+ }
+ } break;
+
+ case WE_ON_EDIT_TEXT:
+ if (!StrEmpty(e->we.edittext.str)) {
+ _cmd_text = e->we.edittext.str;
+ DoCommandP(0, w->window_number, 0, NULL, CMD_NAME_VEHICLE | CMD_MSG(_name_vehicle_error[GetVehicle(w->window_number)->type]));
+ }
+ break;
+
+ case WE_RESIZE:
+ if (e->we.sizing.diff.x != 0) ResizeButtons(w, 9, 12);
+ if (e->we.sizing.diff.y == 0) break;
+
+ w->vscroll.cap += e->we.sizing.diff.y / 14;
+ w->widget[VLD_WIDGET_MIDDLE_DETAILS].data = (w->vscroll.cap << 8) + 1;
+ break;
+ }
+}
+
+/** Vehicle details window descriptor. */
+static const WindowDesc _vehicle_details_desc = {
+ WDP_AUTO, WDP_AUTO, 405, 113, 405, 113,
+ WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
+ _vehicle_details_widgets,
+ VehicleDetailsWndProc
+};
+
+/** Shows the vehicle details window of the given vehicle. */
+static void ShowVehicleDetailsWindow(const Vehicle *v)
+{
+ DeleteWindowById(WC_VEHICLE_ORDERS, v->index);
+ DeleteWindowById(WC_VEHICLE_DETAILS, v->index);
+ AllocateWindowDescFront(&_vehicle_details_desc, v->index);
+}
+
+
/* Unified vehicle GUI - Vehicle View Window */
/** Constants of vehicle view widget indices */
@@ -1509,27 +1877,6 @@ static void CreateVehicleViewWindow(Window *w)
}
}
-
-/* When unified GUI is complete these functions will also be unified to one
- * function in this module */
-void ShowAircraftDetailsWindow(const Vehicle *v);
-void ShowShipDetailsWindow(const Vehicle *v);
-void ShowRoadVehDetailsWindow(const Vehicle *v);
-void ShowTrainDetailsWindow(const Vehicle *v);
-
-
-/** Provisional dispatch to vehicle-specific detail window functions. */
-static void ShowVehicleDetailsWindow(const Vehicle *v)
-{
- switch (v->type) {
- case VEH_TRAIN: ShowTrainDetailsWindow(v); break;
- case VEH_ROAD: ShowRoadVehDetailsWindow(v); break;
- case VEH_SHIP: ShowShipDetailsWindow(v); break;
- case VEH_AIRCRAFT: ShowAircraftDetailsWindow(v); break;
- default: NOT_REACHED();
- }
-}
-
/** Checks whether the vehicle may be refitted at the moment.*/
static bool IsVehicleRefitable(const Vehicle *v)
{
diff --git a/src/window.h b/src/window.h
index a441dd6eb..8af918631 100644
--- a/src/window.h
+++ b/src/window.h
@@ -378,10 +378,10 @@ struct order_d {
};
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(order_d));
-struct traindetails_d {
+struct vehicledetails_d {
byte tab;
};
-assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(traindetails_d));
+assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehicledetails_d));
struct smallmap_d {
int32 scroll_x;