mirror of https://github.com/OpenTTD/OpenTTD
(svn r18118) -Codechange: improve behaviour of the engine lists (both build vehicle/autoreplace) w.r.t. large(r) fonts and RTL. RTL support for 'wider than usual' vehicles is still needed though.
parent
f025475535
commit
5589792d0c
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
|
uint GetEngineListHeight(VehicleType type);
|
||||||
void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group);
|
void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group);
|
||||||
|
|
||||||
/** Widget numbers of the autoreplace GUI. */
|
/** Widget numbers of the autoreplace GUI. */
|
||||||
|
@ -226,11 +227,8 @@ public:
|
||||||
|
|
||||||
this->InitNested(desc, vehicletype);
|
this->InitNested(desc, vehicletype);
|
||||||
|
|
||||||
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(RVW_WIDGET_LEFT_MATRIX)->current_y / this->resize.step_height);
|
/* Update the scrollbars/matrix 'definitions' */
|
||||||
this->vscroll2.SetCapacity(this->vscroll.GetCapacity()); // these two are always the same
|
this->OnResize();
|
||||||
|
|
||||||
this->GetWidget<NWidgetCore>(RVW_WIDGET_LEFT_MATRIX)->widget_data =
|
|
||||||
this->GetWidget<NWidgetCore>(RVW_WIDGET_RIGHT_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
|
|
||||||
|
|
||||||
this->owner = _local_company;
|
this->owner = _local_company;
|
||||||
this->sel_group = id_g;
|
this->sel_group = id_g;
|
||||||
|
@ -241,8 +239,8 @@ public:
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case RVW_WIDGET_LEFT_MATRIX:
|
case RVW_WIDGET_LEFT_MATRIX:
|
||||||
case RVW_WIDGET_RIGHT_MATRIX:
|
case RVW_WIDGET_RIGHT_MATRIX:
|
||||||
resize->height = GetVehicleListHeight((VehicleType)this->window_number);
|
resize->height = GetEngineListHeight((VehicleType)this->window_number);
|
||||||
size->height = (resize->height <= 14 ? 8 : 4) * resize->height;
|
size->height = (this->window_number <= VEH_ROAD ? 8 : 4) * resize->height;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RVW_WIDGET_LEFT_DETAILS:
|
case RVW_WIDGET_LEFT_DETAILS:
|
||||||
|
|
|
@ -35,6 +35,16 @@
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the height of a single 'entry' in the engine lists.
|
||||||
|
* @param type the vehicle type to get the height of
|
||||||
|
* @return the height for the entry
|
||||||
|
*/
|
||||||
|
uint GetEngineListHeight(VehicleType type)
|
||||||
|
{
|
||||||
|
return max<uint>(FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM, GetVehicleListHeight(type));
|
||||||
|
}
|
||||||
|
|
||||||
enum BuildVehicleWidgets {
|
enum BuildVehicleWidgets {
|
||||||
BUILD_VEHICLE_WIDGET_CLOSEBOX = 0,
|
BUILD_VEHICLE_WIDGET_CLOSEBOX = 0,
|
||||||
BUILD_VEHICLE_WIDGET_CAPTION,
|
BUILD_VEHICLE_WIDGET_CAPTION,
|
||||||
|
@ -678,7 +688,7 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
|
||||||
|
|
||||||
/** Engine drawing loop
|
/** Engine drawing loop
|
||||||
* @param type Type of vehicle (VEH_*)
|
* @param type Type of vehicle (VEH_*)
|
||||||
* @param x The left most location of the list
|
* @param l The left most location of the list
|
||||||
* @param r The right most location of the list
|
* @param r The right most location of the list
|
||||||
* @param y The top most location of teh list
|
* @param y The top most location of teh list
|
||||||
* @param eng_list What engines to draw
|
* @param eng_list What engines to draw
|
||||||
|
@ -688,38 +698,28 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
|
||||||
* @param show_count Whether to show the amount of engines or not
|
* @param show_count Whether to show the amount of engines or not
|
||||||
* @param selected_group the group to list the engines of
|
* @param selected_group the group to list the engines of
|
||||||
*/
|
*/
|
||||||
void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group)
|
void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group)
|
||||||
{
|
{
|
||||||
byte step_size = GetVehicleListHeight(type);
|
static const int sprite_widths[] = { 60, 60, 76, 67 };
|
||||||
byte x_offset = 0;
|
static const int sprite_y_offsets[] = { -1, -1, -2, -2 };
|
||||||
byte y_offset = 0;
|
|
||||||
|
|
||||||
|
/* Obligatory sanity checks! */
|
||||||
|
assert((uint)type < lengthof(sprite_widths));
|
||||||
|
assert_compile(lengthof(sprite_y_offsets) == lengthof(sprite_widths));
|
||||||
assert(max <= eng_list->Length());
|
assert(max <= eng_list->Length());
|
||||||
|
|
||||||
switch (type) {
|
bool rtl = _dynlang.text_dir == TD_RTL;
|
||||||
case VEH_TRAIN:
|
int step_size = GetEngineListHeight(type);
|
||||||
x++; // train and road vehicles use the same offset, except trains are one more pixel to the right
|
int sprite_width = sprite_widths[type];
|
||||||
/* Fallthough */
|
|
||||||
case VEH_ROAD:
|
int sprite_x = (rtl ? r - sprite_width / 2 : l + sprite_width / 2) - 1;
|
||||||
x += 26;
|
int sprite_y_offset = sprite_y_offsets[type] + step_size / 2;
|
||||||
x_offset = 30;
|
|
||||||
y += 2;
|
int text_left = l + (rtl ? WD_FRAMERECT_LEFT : sprite_width);
|
||||||
y_offset = 4;
|
int text_right = r - (rtl ? sprite_width : WD_FRAMERECT_RIGHT);
|
||||||
break;
|
|
||||||
case VEH_SHIP:
|
int normal_text_y_offset = (step_size - FONT_HEIGHT_NORMAL) / 2;
|
||||||
x += 35;
|
int small_text_y_offset = step_size - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 1;
|
||||||
x_offset = 40;
|
|
||||||
y += 7;
|
|
||||||
y_offset = 3;
|
|
||||||
break;
|
|
||||||
case VEH_AIRCRAFT:
|
|
||||||
x += 27;
|
|
||||||
x_offset = 33;
|
|
||||||
y += 7;
|
|
||||||
y_offset = 3;
|
|
||||||
break;
|
|
||||||
default: NOT_REACHED();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; min < max; min++, y += step_size) {
|
for (; min < max; min++, y += step_size) {
|
||||||
const EngineID engine = (*eng_list)[min];
|
const EngineID engine = (*eng_list)[min];
|
||||||
|
@ -727,11 +727,11 @@ void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *
|
||||||
const uint num_engines = GetGroupNumEngines(_local_company, selected_group, engine);
|
const uint num_engines = GetGroupNumEngines(_local_company, selected_group, engine);
|
||||||
|
|
||||||
SetDParam(0, engine);
|
SetDParam(0, engine);
|
||||||
DrawString(x + x_offset, r, y, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK);
|
DrawString(text_left, text_right, y + normal_text_y_offset, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK);
|
||||||
DrawVehicleEngine(x, y + y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company));
|
DrawVehicleEngine(sprite_x, y + sprite_y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company));
|
||||||
if (show_count) {
|
if (show_count) {
|
||||||
SetDParam(0, num_engines);
|
SetDParam(0, num_engines);
|
||||||
DrawString(x, r, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT);
|
DrawString(text_left, text_right, y + small_text_y_offset, STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -837,6 +837,9 @@ struct BuildVehicleWindow : Window {
|
||||||
|
|
||||||
this->FinishInitNested(desc, tile == INVALID_TILE ? (int)type : tile);
|
this->FinishInitNested(desc, tile == INVALID_TILE ? (int)type : tile);
|
||||||
|
|
||||||
|
/* Update the scrollbars/matrix 'definitions' */
|
||||||
|
this->OnResize();
|
||||||
|
|
||||||
this->eng_list.ForceRebuild();
|
this->eng_list.ForceRebuild();
|
||||||
this->GenerateBuildList(); // generate the list, since we need it in the next line
|
this->GenerateBuildList(); // generate the list, since we need it in the next line
|
||||||
/* Select the first engine in the list as default when opening the window */
|
/* Select the first engine in the list as default when opening the window */
|
||||||
|
@ -1090,7 +1093,7 @@ struct BuildVehicleWindow : Window {
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case BUILD_VEHICLE_WIDGET_LIST:
|
case BUILD_VEHICLE_WIDGET_LIST:
|
||||||
resize->height = GetVehicleListHeight(this->vehicle_type);
|
resize->height = GetEngineListHeight(this->vehicle_type);
|
||||||
size->height = 3 * resize->height;
|
size->height = 3 * resize->height;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue