openttd updated to 1.5.0-beta2
--HG-- branch : openttd
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* $Id: vehicle_gui.cpp 26086 2013-11-24 14:46:26Z rubidium $ */
|
||||
/* $Id: vehicle_gui.cpp 27134 2015-02-01 20:54:24Z frosch $ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -39,6 +39,8 @@
|
||||
#include "tilehighlight_func.h"
|
||||
#include "zoom_func.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
|
||||
Sorting _sorting;
|
||||
|
||||
@@ -96,6 +98,30 @@ const StringID BaseVehicleListWindow::vehicle_depot_name[] = {
|
||||
STR_VEHICLE_LIST_SEND_AIRCRAFT_TO_HANGAR
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the number of digits the biggest unit number of a set of vehicles has.
|
||||
* @param vehicles The list of vehicles.
|
||||
* @return The number of digits to allocate space for.
|
||||
*/
|
||||
uint GetUnitNumberDigits(VehicleList &vehicles)
|
||||
{
|
||||
uint unitnumber = 0;
|
||||
for (const Vehicle **v = vehicles.Begin(); v != vehicles.End(); v++) {
|
||||
unitnumber = max<uint>(unitnumber, (*v)->unitnumber);
|
||||
}
|
||||
|
||||
if (unitnumber >= 10000) return 5;
|
||||
if (unitnumber >= 1000) return 4;
|
||||
if (unitnumber >= 100) return 3;
|
||||
|
||||
/*
|
||||
* When the smallest unit number is less than 10, it is
|
||||
* quite likely that it will expand to become more than
|
||||
* 10 quite soon.
|
||||
*/
|
||||
return 2;
|
||||
}
|
||||
|
||||
void BaseVehicleListWindow::BuildVehicleList()
|
||||
{
|
||||
if (!this->vehicles.NeedRebuild()) return;
|
||||
@@ -104,21 +130,7 @@ void BaseVehicleListWindow::BuildVehicleList()
|
||||
|
||||
GenerateVehicleSortList(&this->vehicles, this->vli);
|
||||
|
||||
uint unitnumber = 0;
|
||||
for (const Vehicle **v = this->vehicles.Begin(); v != this->vehicles.End(); v++) {
|
||||
unitnumber = max<uint>(unitnumber, (*v)->unitnumber);
|
||||
}
|
||||
|
||||
/* Because 111 is much less wide than e.g. 999 we use the
|
||||
* wider numbers to determine the width instead of just
|
||||
* the random number that it seems to be. */
|
||||
if (unitnumber >= 1000) {
|
||||
this->unitnumber_digits = 4;
|
||||
} else if (unitnumber >= 100) {
|
||||
this->unitnumber_digits = 3;
|
||||
} else {
|
||||
this->unitnumber_digits = 2;
|
||||
}
|
||||
this->unitnumber_digits = GetUnitNumberDigits(this->vehicles);
|
||||
|
||||
this->vehicles.RebuildDone();
|
||||
this->vscroll->SetCount(this->vehicles.Length());
|
||||
@@ -653,7 +665,7 @@ struct RefitWindow : public Window {
|
||||
break;
|
||||
|
||||
case WID_VR_VEHICLE_PANEL_DISPLAY:
|
||||
size->height = GetVehicleHeight(Vehicle::Get(this->window_number)->type);
|
||||
size->height = ScaleGUITrad(GetVehicleHeight(Vehicle::Get(this->window_number)->type));
|
||||
break;
|
||||
|
||||
case WID_VR_INFO:
|
||||
@@ -750,7 +762,7 @@ struct RefitWindow : public Window {
|
||||
}
|
||||
|
||||
if (left != right) {
|
||||
DrawFrameRect(left, r.top + WD_FRAMERECT_TOP, right, r.top + WD_FRAMERECT_TOP + 13, COLOUR_WHITE, FR_BORDERONLY);
|
||||
DrawFrameRect(left, r.top + WD_FRAMERECT_TOP, right, r.top + WD_FRAMERECT_TOP + ScaleGUITrad(14) - 1, COLOUR_WHITE, FR_BORDERONLY);
|
||||
}
|
||||
|
||||
left = INT32_MIN;
|
||||
@@ -1276,6 +1288,9 @@ static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y, Veh
|
||||
const Order *order = v->GetOrder(start);
|
||||
if (order == NULL) return;
|
||||
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
int l_offset = rtl ? 0 : ScaleGUITrad(6);
|
||||
int r_offset = rtl ? ScaleGUITrad(6) : 0;
|
||||
int i = 0;
|
||||
VehicleOrderID oid = start;
|
||||
|
||||
@@ -1284,7 +1299,7 @@ static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y, Veh
|
||||
|
||||
if (order->IsType(OT_GOTO_STATION)) {
|
||||
SetDParam(0, order->GetDestination());
|
||||
DrawString(left + 6, right - 6, y, STR_TINY_BLACK_STATION);
|
||||
DrawString(left + l_offset, right - r_offset, y, STR_TINY_BLACK_STATION);
|
||||
|
||||
y += FONT_HEIGHT_SMALL;
|
||||
if (++i == 4) break;
|
||||
@@ -1328,7 +1343,7 @@ void DrawVehicleImage(const Vehicle *v, int left, int right, int y, VehicleID se
|
||||
uint GetVehicleListHeight(VehicleType type, uint divisor)
|
||||
{
|
||||
/* Name + vehicle + profit */
|
||||
uint base = GetVehicleHeight(type) + 2 * FONT_HEIGHT_SMALL;
|
||||
uint base = ScaleGUITrad(GetVehicleHeight(type)) + 2 * FONT_HEIGHT_SMALL;
|
||||
/* Drawing of the 4 small orders + profit*/
|
||||
if (type >= VEH_SHIP) base = max(base, 5U * FONT_HEIGHT_SMALL);
|
||||
|
||||
@@ -1352,13 +1367,13 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
|
||||
int width = right - left;
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
|
||||
int text_offset = GetDigitWidth() * this->unitnumber_digits + WD_FRAMERECT_RIGHT;
|
||||
int text_offset = max<int>(GetSpriteSize(SPR_PROFIT_LOT).width, GetDigitWidth() * this->unitnumber_digits) + WD_FRAMERECT_RIGHT;
|
||||
int text_left = left + (rtl ? 0 : text_offset);
|
||||
int text_right = right - (rtl ? text_offset : 0);
|
||||
|
||||
bool show_orderlist = this->vli.vtype >= VEH_SHIP;
|
||||
int orderlist_left = left + (rtl ? 0 : max(100 + text_offset, width / 2));
|
||||
int orderlist_right = right - (rtl ? max(100 + text_offset, width / 2) : 0);
|
||||
int orderlist_left = left + (rtl ? 0 : max(ScaleGUITrad(100) + text_offset, width / 2));
|
||||
int orderlist_right = right - (rtl ? max(ScaleGUITrad(100) + text_offset, width / 2) : 0);
|
||||
|
||||
int image_left = (rtl && show_orderlist) ? orderlist_right : text_left;
|
||||
int image_right = (!rtl && show_orderlist) ? orderlist_left : text_right;
|
||||
@@ -1484,7 +1499,7 @@ public:
|
||||
|
||||
case WID_VL_SORT_ORDER: {
|
||||
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
||||
d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the string is centred and it also looks better.
|
||||
d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
|
||||
d.height += padding.height;
|
||||
*size = maxdim(*size, d);
|
||||
break;
|
||||
@@ -1894,7 +1909,7 @@ struct VehicleDetailsWindow : Window {
|
||||
uint desired_height;
|
||||
if (v->HasArticulatedPart()) {
|
||||
/* An articulated RV has its text drawn under the sprite instead of after it, hence 15 pixels extra. */
|
||||
desired_height = WD_FRAMERECT_TOP + 15 + 3 * FONT_HEIGHT_NORMAL + 2 + WD_FRAMERECT_BOTTOM;
|
||||
desired_height = WD_FRAMERECT_TOP + ScaleGUITrad(15) + 3 * FONT_HEIGHT_NORMAL + 2 + WD_FRAMERECT_BOTTOM;
|
||||
/* Add space for the cargo amount for each part. */
|
||||
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
|
||||
if (u->cargo_cap != 0) desired_height += FONT_HEIGHT_NORMAL + 1;
|
||||
@@ -1951,7 +1966,7 @@ struct VehicleDetailsWindow : Window {
|
||||
}
|
||||
|
||||
case WID_VD_MATRIX:
|
||||
resize->height = WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM;
|
||||
resize->height = max(ScaleGUITrad(14), WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM);
|
||||
size->height = 4 * resize->height;
|
||||
break;
|
||||
|
||||
@@ -2078,7 +2093,9 @@ struct VehicleDetailsWindow : Window {
|
||||
case WID_VD_MIDDLE_DETAILS: {
|
||||
/* For other vehicles, at the place of the matrix. */
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
uint sprite_width = max<uint>(UnScaleByZoom(GetSprite(v->GetImage(rtl ? DIR_E : DIR_W, EIT_IN_DETAILS), ST_NORMAL)->width, ZOOM_LVL_GUI), 70U) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
|
||||
uint sprite_width = UnScaleGUI(
|
||||
max<uint>(GetSprite(v->GetImage(rtl ? DIR_E : DIR_W, EIT_IN_DETAILS), ST_NORMAL)->width, 70U)) +
|
||||
WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
|
||||
|
||||
uint text_left = r.left + (rtl ? 0 : sprite_width);
|
||||
uint text_right = r.right - (rtl ? sprite_width : 0);
|
||||
@@ -2830,7 +2847,7 @@ int GetVehicleWidth(Vehicle *v, EngineImageType image_type)
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
SpriteID sprite = v->GetImage(rtl ? DIR_E : DIR_W, image_type);
|
||||
const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL);
|
||||
vehicle_width = UnScaleByZoom(real_sprite->width, ZOOM_LVL_GUI);
|
||||
vehicle_width = UnScaleGUI(real_sprite->width);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user