summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2017-08-26 12:12:59 +0000
committerfrosch <frosch@openttd.org>2017-08-26 12:12:59 +0000
commit61c68f906dff81ad8dc5f15868c9ea05e95daad4 (patch)
tree9d64b5e80209b9c1621e77604613d74c49d57bf1 /src
parent1afb3a91f829056d6648a1b54d0ab0995fb8f6ae (diff)
downloadopenttd-61c68f906dff81ad8dc5f15868c9ea05e95daad4.tar.xz
(svn r27899) -Feature: Draw vertical separators at tile distance in the train depot GUI. This only applies if all vehicles use consistent lengths, i.e. either if only using default vehicles, or if only using NewGRF vehicles with 32px reference width. (based on patch by Wolf01)
Diffstat (limited to 'src')
-rw-r--r--src/depot_gui.cpp56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index a99f2e4dd..15291f6b6 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -147,6 +147,7 @@ static void TrainDepotMoveVehicle(const Vehicle *wagon, VehicleID sel, const Veh
static VehicleCellSize _base_block_sizes_depot[VEH_COMPANY_END]; ///< Cell size for vehicle images in the depot view.
static VehicleCellSize _base_block_sizes_purchase[VEH_COMPANY_END]; ///< Cell size for vehicle images in the purchase list.
+static uint _consistent_train_width; ///< Whether trains of all lengths are consistently scaled. Either TRAININFO_DEFAULT_VEHICLE_WIDTH, VEHICLEINFO_FULL_VEHICLE_WIDTH, or 0.
/**
* Get the GUI cell size for a vehicle image.
@@ -219,6 +220,34 @@ void InitDepotWindowBlockSizes()
InitBlocksizeForVehicles(vt, EIT_IN_DEPOT);
InitBlocksizeForVehicles(vt, EIT_PURCHASE);
}
+
+ _consistent_train_width = TRAININFO_DEFAULT_VEHICLE_WIDTH;
+ bool first = true;
+ const Engine *e;
+ FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
+ if (!e->IsEnabled()) continue;
+
+ uint w = TRAININFO_DEFAULT_VEHICLE_WIDTH;
+ if (e->GetGRF() != NULL && is_custom_sprite(e->u.rail.image_index)) {
+ w = e->GetGRF()->traininfo_vehicle_width;
+ if (w != VEHICLEINFO_FULL_VEHICLE_WIDTH) {
+ /* Hopeless.
+ * This is a NewGRF vehicle that uses TRAININFO_DEFAULT_VEHICLE_WIDTH.
+ * If the vehicles are shorter than 8/8 we have fractional lengths, which are not consistent after rounding.
+ */
+ _consistent_train_width = 0;
+ break;
+ }
+ }
+
+ if (first) {
+ _consistent_train_width = w;
+ first = false;
+ } else if (w != _consistent_train_width) {
+ _consistent_train_width = 0;
+ break;
+ }
+ }
}
static void DepotSellAllConfirmationCallback(Window *w, bool confirmed);
@@ -292,7 +321,10 @@ struct DepotWindow : Window {
const Train *u = Train::From(v);
free_wagon = u->IsFreeWagon();
- uint x_space = free_wagon ? ScaleGUITrad(TRAININFO_DEFAULT_VEHICLE_WIDTH) : 0;
+ uint x_space = free_wagon ?
+ ScaleGUITrad(_consistent_train_width != 0 ? _consistent_train_width : TRAININFO_DEFAULT_VEHICLE_WIDTH) :
+ 0;
+
DrawTrainImage(u, image_left + (rtl ? 0 : x_space), image_right - (rtl ? x_space : 0), sprite_y - 1,
this->sel, EIT_IN_DEPOT, free_wagon ? 0 : this->hscroll->GetPosition(), this->vehicle_over);
@@ -340,6 +372,28 @@ struct DepotWindow : Window {
/* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
const NWidgetCore *wid = this->GetWidget<NWidgetCore>(WID_D_MATRIX);
+
+ /* Draw vertical separators at whole tiles.
+ * This only works in two cases:
+ * - All vehicles use VEHICLEINFO_FULL_VEHICLE_WIDTH as reference width.
+ * - All vehicles are 8/8. This cannot be checked for NewGRF, so instead we check for "all vehicles are original vehicles".
+ */
+ if (this->type == VEH_TRAIN && _consistent_train_width != 0) {
+ int w = ScaleGUITrad(2 * _consistent_train_width);
+ int col = _colour_gradient[wid->colour][4];
+ int image_left = rtl ? r.left + this->count_width : r.left + this->header_width;
+ int image_right = rtl ? r.right - this->header_width : r.right - this->count_width;
+ if (rtl) {
+ for (int x = image_right - w; x > image_left; x -= w) {
+ GfxDrawLine(x, r.top, x, r.bottom, col, 1, 3);
+ }
+ } else {
+ for (int x = image_left + w; x < image_right; x += w) {
+ GfxDrawLine(x, r.top, x, r.bottom, col, 1, 3);
+ }
+ }
+ }
+
uint16 rows_in_display = wid->current_y / wid->resize_y;
uint16 num = this->vscroll->GetPosition() * this->num_columns;