--- a/src/vehicle_gui.cpp Mon Dec 03 23:39:38 2007 +0000
+++ b/src/vehicle_gui.cpp Tue Jan 22 21:00:30 2008 +0000
@@ -5,33 +5,40 @@
#include "stdafx.h"
#include "openttd.h"
#include "debug.h"
-#include "functions.h"
-#include "player.h"
+#include "player_func.h"
#include "station.h"
-#include "strings.h"
-#include "table/sprites.h"
-#include "table/strings.h"
-#include "vehicle.h"
-#include "window.h"
#include "engine.h"
#include "gui.h"
-#include "command.h"
-#include "gfx.h"
+#include "window_gui.h"
+#include "textbuf_gui.h"
+#include "command_func.h"
#include "variables.h"
#include "vehicle_gui.h"
-#include "viewport.h"
+#include "viewport_func.h"
+#include "gfx_func.h"
#include "train.h"
#include "newgrf_callbacks.h"
#include "newgrf_engine.h"
#include "newgrf_text.h"
-#include "date.h"
#include "ship.h"
#include "aircraft.h"
#include "roadveh.h"
#include "depot.h"
-#include "helpers.hpp"
#include "cargotype.h"
#include "group.h"
+#include "group_gui.h"
+#include "strings_func.h"
+#include "functions.h"
+#include "window_func.h"
+#include "vehicle_func.h"
+#include "autoreplace_gui.h"
+#include "core/alloc_func.hpp"
+#include "string_func.h"
+#include "settings_type.h"
+#include "widgets/dropdown_func.h"
+
+#include "table/sprites.h"
+#include "table/strings.h"
struct Sorting {
Listing aircraft;
@@ -506,6 +513,8 @@
for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
if (!HasBit(cmask, cid)) continue;
+ if (b >= lastof(_userstring) - (2 + 2 * 4)) break; // ", " and two calls to Utf8Encode()
+
if (!first) b = strecpy(b, ", ", lastof(_userstring));
first = false;
@@ -515,6 +524,10 @@
/* Terminate and display the completed string */
*b = '\0';
+
+ /* Make sure we detect any buffer overflow */
+ assert(b < endof(_userstring));
+
return DrawStringMultiLine(x, y, STR_SPEC_USERSTRING, w);
}
@@ -542,20 +555,14 @@
if (va != last_vehicle[0]) {
last_vehicle[0] = va;
- if (IsCustomName(va->string_id)) {
- GetString(last_name[0], va->string_id, lastof(last_name[0]));
- } else {
- last_name[0][0] = '\0';
- }
+ SetDParam(0, va->index);
+ GetString(last_name[0], STR_VEHICLE_NAME, lastof(last_name[0]));
}
if (vb != last_vehicle[1]) {
last_vehicle[1] = vb;
- if (IsCustomName(vb->string_id)) {
- GetString(last_name[1], vb->string_id, lastof(last_name[1]));
- } else {
- last_name[1][0] = '\0';
- }
+ SetDParam(1, vb->index);
+ GetString(last_name[1], STR_VEHICLE_NAME, lastof(last_name[1]));
}
r = strcmp(last_name[0], last_name[1]); // sort by name
@@ -736,14 +743,12 @@
VLW_WIDGET_CAPTION,
VLW_WIDGET_STICKY,
VLW_WIDGET_SORT_ORDER,
- VLW_WIDGET_SORT_BY_TEXT,
VLW_WIDGET_SORT_BY_PULLDOWN,
VLW_WIDGET_EMPTY_TOP_RIGHT,
VLW_WIDGET_LIST,
VLW_WIDGET_SCROLLBAR,
VLW_WIDGET_OTHER_PLAYER_FILLER,
VLW_WIDGET_AVAILABLE_VEHICLES,
- VLW_WIDGET_MANAGE_VEHICLES,
VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN,
VLW_WIDGET_STOP_ALL,
VLW_WIDGET_START_ALL,
@@ -756,8 +761,7 @@
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 247, 0, 13, 0x0, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_STICKYBOX, RESIZE_LR, 14, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
- { WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
- { WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
+ { WWT_DROPDOWN, RESIZE_NONE, 14, 81, 247, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
{ WWT_PANEL, RESIZE_RIGHT, 14, 248, 259, 14, 25, 0x0, STR_NULL},
{ WWT_MATRIX, RESIZE_RB, 14, 0, 247, 26, 169, 0x0, STR_NULL},
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 248, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
@@ -765,8 +769,7 @@
{ WWT_PANEL, RESIZE_RTB, 14, 0, 247, 170, 181, 0x0, STR_NULL},
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 105, 170, 181, 0x0, STR_AVAILABLE_ENGINES_TIP},
- { WWT_TEXTBTN, RESIZE_TB, 14, 106, 211, 170, 181, STR_MANAGE_LIST, STR_MANAGE_LIST_TIP},
- { WWT_TEXTBTN, RESIZE_TB, 14, 212, 223, 170, 181, STR_0225, STR_MANAGE_LIST_TIP},
+ { WWT_DROPDOWN, RESIZE_TB, 14, 106, 223, 170, 181, STR_MANAGE_LIST, STR_MANAGE_LIST_TIP},
{ WWT_PUSHIMGBTN, RESIZE_TB, 14, 224, 235, 170, 181, SPR_FLAG_VEH_STOPPED, STR_MASS_STOP_LIST_TIP},
{ WWT_PUSHIMGBTN, RESIZE_TB, 14, 236, 247, 170, 181, SPR_FLAG_VEH_RUNNING, STR_MASS_START_LIST_TIP},
@@ -794,7 +797,6 @@
} else {
w->SetWidgetsHiddenState(true,
VLW_WIDGET_AVAILABLE_VEHICLES,
- VLW_WIDGET_MANAGE_VEHICLES,
VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN,
VLW_WIDGET_STOP_ALL,
VLW_WIDGET_START_ALL,
@@ -929,7 +931,6 @@
int max;
int i;
const PlayerID owner = (PlayerID)w->caption_color;
- const Player *p = GetPlayer(owner);
const uint16 window_type = w->window_number & VLW_MASK;
const uint16 index = GB(w->window_number, 16, 16);
@@ -949,7 +950,7 @@
break;
case VLW_STANDARD: /* Company Name */
- SetDParam(0, p->index);
+ SetDParam(0, owner);
SetDParam(1, w->vscroll.count);
break;
@@ -977,7 +978,6 @@
}
w->SetWidgetsDisabledState(vl->l.list_length == 0,
- VLW_WIDGET_MANAGE_VEHICLES,
VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN,
VLW_WIDGET_STOP_ALL,
VLW_WIDGET_START_ALL,
@@ -988,7 +988,7 @@
/* draw sorting criteria string */
DrawString(85, 15, _vehicle_sort_listing[vl->l.sort_type], TC_BLACK);
/* draw arrow pointing up/down for ascending/descending sorting */
- DoDrawString(vl->l.flags & VL_DESC ? DOWNARROW : UPARROW, 69, 15, TC_BLACK);
+ DrawSortButtonState(w, VLW_WIDGET_SORT_ORDER, vl->l.flags & VL_DESC ? SBS_DOWN : SBS_UP);
max = min(w->vscroll.pos + w->vscroll.cap, vl->l.list_length);
for (i = w->vscroll.pos; i < max; ++i) {
@@ -998,14 +998,10 @@
SetDParam(0, v->profit_this_year);
SetDParam(1, v->profit_last_year);
- DrawVehicleImage(v, x + 19, y + 6, w->widget[VLW_WIDGET_LIST].right - w->widget[VLW_WIDGET_LIST].left - 20, 0, INVALID_VEHICLE);
+ DrawVehicleImage(v, x + 19, y + 6, INVALID_VEHICLE, w->widget[VLW_WIDGET_LIST].right - w->widget[VLW_WIDGET_LIST].left - 20, 0);
DrawString(x + 19, y + w->resize.step_height - 8, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, TC_FROMSTRING);
- if ((v->type == VEH_TRAIN && v->string_id != STR_SV_TRAIN_NAME) ||
- (v->type == VEH_ROAD && v->string_id != STR_SV_ROADVEH_NAME) ||
- (v->type == VEH_SHIP && v->string_id != STR_SV_SHIP_NAME) ||
- (v->type == VEH_AIRCRAFT && v->string_id != STR_SV_AIRCRAFT_NAME)) {
-
+ if (v->name != NULL) {
/* The vehicle got a name so we will print it */
SetDParam(0, v->index);
DrawString(x + 19, y, STR_01AB, TC_FROMSTRING);
@@ -1057,7 +1053,7 @@
vl->_sorting->order = !!(vl->l.flags & VL_DESC);
SetWindowDirty(w);
break;
- case VLW_WIDGET_SORT_BY_TEXT: case VLW_WIDGET_SORT_BY_PULLDOWN:/* Select sorting criteria dropdown menu */
+ case VLW_WIDGET_SORT_BY_PULLDOWN:/* Select sorting criteria dropdown menu */
ShowDropDownMenu(w, _vehicle_sort_listing, vl->l.sort_type, VLW_WIDGET_SORT_BY_PULLDOWN, 0, 0);
return;
case VLW_WIDGET_LIST: { /* Matrix to show vehicles */
@@ -1079,7 +1075,6 @@
ShowBuildVehicleWindow(0, vl->vehicle_type);
break;
- case VLW_WIDGET_MANAGE_VEHICLES:
case VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN: {
static StringID action_str[] = {
STR_REPLACE_VEHICLES,
@@ -1123,7 +1118,7 @@
switch (e->we.dropdown.index) {
case 0: /* Replace window */
- ShowReplaceVehicleWindow(vl->vehicle_type);
+ ShowReplaceGroupVehicleWindow(DEFAULT_GROUP, vl->vehicle_type);
break;
case 1: /* Send for servicing */
DoCommandP(0, GB(w->window_number, 16, 16) /* StationID or OrderID (depending on VLW) */,
@@ -1151,6 +1146,7 @@
break;
case WE_TICK: /* resort the list every 20 seconds orso (10 days) */
+ if (_pause_game != 0) break;
if (--vl->l.resort_timer == 0) {
StationID station = ((w->window_number & VLW_MASK) == VLW_STATION_LIST) ? GB(w->window_number, 16, 16) : INVALID_STATION;
PlayerID owner = (PlayerID)w->caption_color;
@@ -1538,7 +1534,7 @@
case VEH_ROAD:
case VEH_SHIP:
case VEH_AIRCRAFT:
- DrawVehicleImage(v, 3, 57, 0, 0, INVALID_VEHICLE);
+ DrawVehicleImage(v, 3, 57, INVALID_VEHICLE, 0, 0);
DrawVehicleDetails(v, 75, 57, w->vscroll.pos, w->vscroll.cap, det_tab);
break;
@@ -1649,26 +1645,6 @@
/* Unified vehicle GUI - Vehicle View Window */
-/** Constants of vehicle view widget indices */
-enum VehicleViewWindowWidgets {
- VVW_WIDGET_CLOSEBOX = 0,
- VVW_WIDGET_CAPTION,
- VVW_WIDGET_STICKY,
- VVW_WIDGET_PANEL,
- VVW_WIDGET_VIEWPORT,
- VVW_WIDGET_START_STOP_VEH,
- VVW_WIDGET_CENTER_MAIN_VIEH,
- VVW_WIDGET_GOTO_DEPOT,
- VVW_WIDGET_REFIT_VEH,
- VVW_WIDGET_SHOW_ORDERS,
- VVW_WIDGET_SHOW_DETAILS,
- VVW_WIDGET_CLONE_VEH,
- VVW_WIDGET_EMPTY_BOTTOM_RIGHT,
- VVW_WIDGET_RESIZE,
- VVW_WIDGET_TURN_AROUND,
- VVW_WIDGET_FORCE_PROCEED,
-};
-
/** Vehicle view widgets. */
static const Widget _vehicle_view_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, // VVW_WIDGET_CLOSEBOX
@@ -1987,7 +1963,7 @@
SetDParam(0, depot->town_index);
SetDParam(1, v->GetDisplaySpeed());
}
- if (HasBit(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HasBit(v->current_order.flags, OFB_PART_OF_ORDERS)) {
+ if (HasBit(v->current_order.flags, OF_HALT_IN_DEPOT) && !HasBit(v->current_order.flags, OF_PART_OF_ORDERS)) {
str = _heading_for_depot_strings[v->type] + _patches.vehicle_speed;
} else {
str = _heading_for_depot_service_strings[v->type] + _patches.vehicle_speed;
@@ -2162,3 +2138,14 @@
} break;
}
}
+
+void DrawVehicleImage(const Vehicle *v, int x, int y, VehicleID selection, int count, int skip)
+{
+ switch (v->type) {
+ case VEH_TRAIN: DrawTrainImage(v, x, y, selection, count, skip); break;
+ case VEH_ROAD: DrawRoadVehImage(v, x, y, selection, count); break;
+ case VEH_SHIP: DrawShipImage(v, x, y, selection); break;
+ case VEH_AIRCRAFT: DrawAircraftImage(v, x, y, selection); break;
+ default: NOT_REACHED();
+ }
+}