Update to 13.0-RC1

This commit is contained in:
Pavel Stupnikov
2023-01-03 15:58:14 +04:00
parent be23283677
commit 59c991fa52
326 changed files with 12923 additions and 8705 deletions

View File

@@ -53,11 +53,12 @@ void CcBuildWagon(Commands cmd, const CommandCost &result, VehicleID new_veh_id,
* Highlight the position where a rail vehicle is dragged over by drawing a light gray background.
* @param px The current x position to draw from.
* @param max_width The maximum space available to draw.
* @param y The vertical centre position to draw from.
* @param selection Selected vehicle that is dragged.
* @param chain Whether a whole chain is dragged.
* @return The width of the highlight mark.
*/
static int HighlightDragPosition(int px, int max_width, VehicleID selection, bool chain)
static int HighlightDragPosition(int px, int max_width, int y, VehicleID selection, bool chain)
{
bool rtl = _current_text_dir == TD_RTL;
@@ -72,8 +73,11 @@ static int HighlightDragPosition(int px, int max_width, VehicleID selection, boo
int drag_hlight_width = std::max(drag_hlight_right - drag_hlight_left + 1, 0);
if (drag_hlight_width > 0) {
GfxFillRect(drag_hlight_left + WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP + 1,
drag_hlight_right - WD_FRAMERECT_RIGHT, ScaleGUITrad(13) - WD_FRAMERECT_BOTTOM, _colour_gradient[COLOUR_GREY][7]);
int height = ScaleSpriteTrad(12);
int top = y - height / 2;
Rect r = {drag_hlight_left, top, drag_hlight_right, top + height - 1};
/* Sprite-scaling is used here as the area is from sprite size */
GfxFillRect(r.Shrink(ScaleSpriteTrad(1)), _colour_gradient[COLOUR_GREY][7]);
}
return drag_hlight_width;
@@ -82,14 +86,12 @@ static int HighlightDragPosition(int px, int max_width, VehicleID selection, boo
/**
* Draws an image of a whole train
* @param v Front vehicle
* @param left The minimum horizontal position
* @param right The maximum horizontal position
* @param y Vertical position to draw at
* @param r Rect to draw at
* @param selection Selected vehicle to draw a frame around
* @param skip Number of pixels to skip at the front (for scrolling)
* @param drag_dest The vehicle another one is dragged over, \c INVALID_VEHICLE if none.
*/
void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
{
bool rtl = _current_text_dir == TD_RTL;
Direction dir = rtl ? DIR_E : DIR_W;
@@ -98,22 +100,22 @@ void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID select
/* Position of highlight box */
int highlight_l = 0;
int highlight_r = 0;
int max_width = right - left + 1;
int height = ScaleGUITrad(14);
int max_width = r.Width();
if (!FillDrawPixelInfo(&tmp_dpi, left, y, max_width, height)) return;
if (!FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) return;
old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi;
int px = rtl ? max_width + skip : -skip;
int y = r.Height() / 2;
bool sel_articulated = false;
bool dragging = (drag_dest != INVALID_VEHICLE);
bool drag_at_end_of_train = (drag_dest == v->index); // Head index is used to mark dragging at end of train.
for (; v != nullptr && (rtl ? px > 0 : px < max_width); v = v->Next()) {
if (dragging && !drag_at_end_of_train && drag_dest == v->index) {
/* Highlight the drag-and-drop destination inside the train. */
int drag_hlight_width = HighlightDragPosition(px, max_width, selection, _cursor.vehchain);
int drag_hlight_width = HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
px += rtl ? -drag_hlight_width : drag_hlight_width;
}
@@ -124,7 +126,7 @@ void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID select
PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
VehicleSpriteSeq seq;
v->GetImage(dir, image_type, &seq);
seq.Draw(px + (rtl ? -offset.x : offset.x), height / 2 + offset.y, pal, (v->vehstatus & VS_CRASHED) != 0);
seq.Draw(px + (rtl ? -offset.x : offset.x), y + offset.y, pal, (v->vehstatus & VS_CRASHED) != 0);
}
if (!v->IsArticulatedPart()) sel_articulated = false;
@@ -147,16 +149,18 @@ void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID select
if (dragging && drag_at_end_of_train) {
/* Highlight the drag-and-drop destination at the end of the train. */
HighlightDragPosition(px, max_width, selection, _cursor.vehchain);
HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
}
_cur_dpi = old_dpi;
if (highlight_l != highlight_r) {
/* Draw the highlight. Now done after drawing all the engines, as
* the next engine after the highlight could overlap it. */
DrawFrameRect(highlight_l, 0, highlight_r, height - 1, COLOUR_WHITE, FR_BORDERONLY);
int height = ScaleSpriteTrad(12);
Rect hr = {highlight_l, 0, highlight_r, height - 1};
DrawFrameRect(hr.Translate(r.left, CenterBounds(r.top, r.bottom, height)).Expand(WidgetDimensions::scaled.bevel), COLOUR_WHITE, FR_BORDERONLY);
}
_cur_dpi = old_dpi;
}
/** Helper struct for the cargo details information */
@@ -182,7 +186,6 @@ struct CargoSummaryItem {
static const uint TRAIN_DETAILS_MIN_INDENT = 32; ///< Minimum indent level in the train details window
static const uint TRAIN_DETAILS_MAX_INDENT = 72; ///< Maximum indent level in the train details window; wider than this and we start on a new line
static const int TRAIN_DETAILS_LIST_INDENT = 10; ///< Indent for list items in the Total Cargo window
/** Container for the cargo summary information. */
typedef std::vector<CargoSummaryItem> CargoSummary;
@@ -341,7 +344,7 @@ int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
num += std::max(1u, (unsigned)_cargo_summary.size());
uint length = GetLengthOfArticulatedVehicle(v);
if (length > TRAIN_DETAILS_MAX_INDENT) num++;
if (length > (uint)ScaleSpriteTrad(TRAIN_DETAILS_MAX_INDENT)) num++;
}
}
@@ -352,32 +355,22 @@ int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
* Draw the details for the given vehicle at the given position
*
* @param v current vehicle
* @param left The left most coordinate to draw
* @param right The right most coordinate to draw
* @param y The y coordinate
* @param r the Rect to draw within
* @param vscroll_pos Position of scrollbar
* @param vscroll_cap Number of lines currently displayed
* @param det_tab Selected details tab
*/
void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab)
void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab)
{
/* get rid of awkward offset */
y -= WD_MATRIX_TOP;
/* Indent the total cargo capacity details */
int offs_left = _current_text_dir == TD_LTR ? TRAIN_DETAILS_LIST_INDENT : 0;
int offs_right = _current_text_dir == TD_LTR ? 0 : TRAIN_DETAILS_LIST_INDENT;
int sprite_height = ScaleGUITrad(GetVehicleHeight(VEH_TRAIN));
int line_height = std::max(sprite_height, WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM);
bool rtl = _current_text_dir == TD_RTL;
int line_height = r.Height();
int sprite_y_offset = line_height / 2;
int text_y_offset = (line_height - FONT_HEIGHT_NORMAL) / 2;
/* draw the first 3 details tabs */
if (det_tab != TDW_TAB_TOTALS) {
bool rtl = _current_text_dir == TD_RTL;
Direction dir = rtl ? DIR_E : DIR_W;
int x = rtl ? right : left;
int x = rtl ? r.right : r.left;
for (; v != nullptr && vscroll_pos > -vscroll_cap; v = v->GetNextVehicle()) {
GetCargoSummaryOfArticulatedVehicle(v, &_cargo_summary);
@@ -392,53 +385,52 @@ void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_po
int pitch = 0;
const Engine *e = Engine::Get(v->engine_type);
if (e->GetGRF() != nullptr) {
pitch = ScaleGUITrad(e->GetGRF()->traininfo_vehicle_pitch);
pitch = ScaleSpriteTrad(e->GetGRF()->traininfo_vehicle_pitch);
}
PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
VehicleSpriteSeq seq;
u->GetImage(dir, EIT_IN_DETAILS, &seq);
seq.Draw(px + (rtl ? -offset.x : offset.x), y - line_height * vscroll_pos + sprite_y_offset + pitch, pal, (v->vehstatus & VS_CRASHED) != 0);
seq.Draw(px + (rtl ? -offset.x : offset.x), r.top - line_height * vscroll_pos + sprite_y_offset + pitch, pal, (v->vehstatus & VS_CRASHED) != 0);
}
px += rtl ? -width : width;
dx += width;
u = u->Next();
} while (u != nullptr && u->IsArticulatedPart());
bool separate_sprite_row = (dx > (uint)ScaleGUITrad(TRAIN_DETAILS_MAX_INDENT));
bool separate_sprite_row = (dx > (uint)ScaleSpriteTrad(TRAIN_DETAILS_MAX_INDENT));
if (separate_sprite_row) {
vscroll_pos--;
dx = 0;
}
int sprite_width = std::max<int>(dx, ScaleSpriteTrad(TRAIN_DETAILS_MIN_INDENT)) + WidgetDimensions::scaled.hsep_normal;
Rect dr = r.Indent(sprite_width, rtl);
uint num_lines = std::max(1u, (unsigned)_cargo_summary.size());
for (uint i = 0; i < num_lines; i++) {
int sprite_width = std::max<int>(dx, ScaleGUITrad(TRAIN_DETAILS_MIN_INDENT)) + 3;
int data_left = left + (rtl ? 0 : sprite_width);
int data_right = right - (rtl ? sprite_width : 0);
if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
int py = y - line_height * vscroll_pos + text_y_offset;
int py = r.top - line_height * vscroll_pos + text_y_offset;
if (i > 0 || separate_sprite_row) {
if (vscroll_pos != 0) GfxFillRect(left, py - WD_MATRIX_TOP - 1, right, py - WD_MATRIX_TOP, _colour_gradient[COLOUR_GREY][5]);
if (vscroll_pos != 0) GfxFillRect(r.left, py - WidgetDimensions::scaled.matrix.top - 1, r.right, py - WidgetDimensions::scaled.matrix.top, _colour_gradient[COLOUR_GREY][5]);
}
switch (det_tab) {
case TDW_TAB_CARGO:
if (i < _cargo_summary.size()) {
TrainDetailsCargoTab(&_cargo_summary[i], data_left, data_right, py);
TrainDetailsCargoTab(&_cargo_summary[i], dr.left, dr.right, py);
} else {
DrawString(data_left, data_right, py, STR_QUANTITY_N_A, TC_LIGHT_BLUE);
DrawString(dr.left, dr.right, py, STR_QUANTITY_N_A, TC_LIGHT_BLUE);
}
break;
case TDW_TAB_INFO:
if (i == 0) TrainDetailsInfoTab(v, data_left, data_right, py);
if (i == 0) TrainDetailsInfoTab(v, dr.left, dr.right, py);
break;
case TDW_TAB_CAPACITY:
if (i < _cargo_summary.size()) {
TrainDetailsCapacityTab(&_cargo_summary[i], data_left, data_right, py);
TrainDetailsCapacityTab(&_cargo_summary[i], dr.left, dr.right, py);
} else {
SetDParam(0, STR_EMPTY);
DrawString(data_left, data_right, py, STR_VEHICLE_INFO_NO_CAPACITY);
DrawString(dr.left, dr.right, py, STR_VEHICLE_INFO_NO_CAPACITY);
}
break;
@@ -449,6 +441,7 @@ void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_po
}
}
} else {
int y = r.top;
CargoArray act_cargo;
CargoArray max_cargo;
Money feeder_share = 0;
@@ -460,9 +453,11 @@ void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_po
}
/* draw total cargo tab */
DrawString(left, right, y + text_y_offset, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_TEXT);
DrawString(r.left, r.right, y + text_y_offset, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_TEXT);
y += line_height;
/* Indent the total cargo capacity details */
Rect ir = r.Indent(WidgetDimensions::scaled.hsep_indent, rtl);
for (CargoID i = 0; i < NUM_CARGO; i++) {
if (max_cargo[i] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
SetDParam(0, i); // {CARGO} #1
@@ -470,11 +465,11 @@ void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_po
SetDParam(2, i); // {SHORTCARGO} #1
SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2
SetDParam(4, _settings_game.vehicle.freight_trains);
DrawString(left + offs_left, right - offs_right, y + text_y_offset, FreightWagonMult(i) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY);
DrawString(ir.left, ir.right, y + text_y_offset, FreightWagonMult(i) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY);
y += line_height;
}
}
SetDParam(0, feeder_share);
DrawString(left, right, y + text_y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
DrawString(r.left, r.right, y + text_y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
}
}