mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-02 09:40:35 +00:00
TBTR: Fix display of vehicle sprites for some NewGRFs, fix issues in large UI modes
Slight code, GUI layout, and savegame format tidying
This commit is contained in:
parent
4a9df57665
commit
5877cd0f9b
@ -787,7 +787,7 @@ public:
|
||||
switch (index) {
|
||||
case ADI_TEMPLATE_REPLACE: // TemplateReplace Window
|
||||
if (vli.vtype == VEH_TRAIN) {
|
||||
ShowTemplateReplaceWindow(this->unitnumber_digits, this->resize.step_height);
|
||||
ShowTemplateReplaceWindow(this->unitnumber_digits);
|
||||
}
|
||||
break;
|
||||
case ADI_REPLACE: // Replace window
|
||||
|
@ -45,7 +45,7 @@ std::vector<uint32> _sl_xv_discardable_chunk_ids; ///< list of chunks
|
||||
static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version os SLXI chunk
|
||||
|
||||
const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
|
||||
{ XSLFI_TEMPLATE_REPLACEMENT, XSCF_NULL, 3, 3, "template_replacement", NULL, NULL, "TRPL,TMPL" },
|
||||
{ XSLFI_TEMPLATE_REPLACEMENT, XSCF_NULL, 4, 4, "template_replacement", NULL, NULL, "TRPL,TMPL" },
|
||||
{ XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker
|
||||
};
|
||||
|
||||
|
@ -12,14 +12,15 @@
|
||||
const SaveLoad* GTD() {
|
||||
|
||||
static const SaveLoad _template_veh_desc[] = {
|
||||
SLE_REF(TemplateVehicle, next, REF_TEMPLATE_VEHICLE),
|
||||
SLE_REF(TemplateVehicle, next, REF_TEMPLATE_VEHICLE),
|
||||
|
||||
SLE_VAR(TemplateVehicle, reuse_depot_vehicles, SLE_UINT8),
|
||||
SLE_VAR(TemplateVehicle, keep_remaining_vehicles, SLE_UINT8),
|
||||
SLE_VAR(TemplateVehicle, refit_as_template, SLE_UINT8),
|
||||
|
||||
SLE_VAR(TemplateVehicle, owner, SLE_UINT32),
|
||||
SLE_VAR(TemplateVehicle, owner_b, SLE_UINT8),
|
||||
SLE_CONDVAR_X(TemplateVehicle, owner, SLE_VAR_U8 | SLE_FILE_U32, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 3)),
|
||||
SLE_CONDVAR_X(TemplateVehicle, owner, SLE_UINT8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 4)),
|
||||
SLE_CONDNULL_X(1, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 3)),
|
||||
|
||||
SLE_VAR(TemplateVehicle, engine_type, SLE_UINT16),
|
||||
SLE_VAR(TemplateVehicle, cargo_type, SLE_UINT8),
|
||||
@ -38,11 +39,10 @@ const SaveLoad* GTD() {
|
||||
SLE_VAR(TemplateVehicle, weight, SLE_UINT32),
|
||||
SLE_VAR(TemplateVehicle, max_te, SLE_UINT32),
|
||||
|
||||
SLE_VAR(TemplateVehicle, spritenum, SLE_UINT8),
|
||||
SLE_CONDVAR_X(TemplateVehicle, sprite_seq.seq[0].sprite, SLE_UINT32, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 1)),
|
||||
SLE_CONDVAR_X(TemplateVehicle, sprite_seq.count, SLE_UINT32, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 2)),
|
||||
SLE_CONDARR_X(TemplateVehicle, sprite_seq.seq, SLE_UINT32, 8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 2)),
|
||||
SLE_VAR(TemplateVehicle, image_width, SLE_UINT32),
|
||||
SLE_CONDNULL_X(1, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 3)),
|
||||
SLE_CONDNULL_X(4, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 1)),
|
||||
SLE_CONDNULL_X(36, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 2, 3)),
|
||||
SLE_CONDNULL_X(4, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 3)),
|
||||
|
||||
SLE_END()
|
||||
};
|
||||
@ -134,10 +134,11 @@ void AfterLoadTemplateVehiclesUpdateImage()
|
||||
if (t_len == tv_len) {
|
||||
Train *v = t;
|
||||
for (TemplateVehicle *u = tv; u != NULL; u = u->Next(), v = v->Next()) {
|
||||
u->spritenum = v->spritenum;
|
||||
v->GetImage(DIR_W, EIT_PURCHASE, &u->sprite_seq);
|
||||
u->image_width = v->GetDisplayImageWidth();
|
||||
v->GetImage(DIR_W, EIT_IN_DEPOT, &u->sprite_seq);
|
||||
u->image_dimensions.SetFromTrain(v);
|
||||
}
|
||||
} else {
|
||||
DEBUG(misc, 0, "AfterLoadTemplateVehiclesUpdateImage: vehicle count mismatch: %u, %u", t_len, tv_len);
|
||||
}
|
||||
delete t;
|
||||
}
|
||||
|
@ -129,7 +129,6 @@ class TemplateCreateWindow : public Window {
|
||||
private:
|
||||
Scrollbar *hscroll;
|
||||
Scrollbar *vscroll;
|
||||
int line_height;
|
||||
Train* virtual_train;
|
||||
bool *create_window_open; /// used to notify main window of progress (dummy way of disabling 'delete' while editing a template)
|
||||
VehicleID sel;
|
||||
@ -138,9 +137,8 @@ private:
|
||||
uint32 template_index;
|
||||
|
||||
public:
|
||||
TemplateCreateWindow(WindowDesc* _wdesc, TemplateVehicle *to_edit, bool *window_open, int step_h) : Window(_wdesc)
|
||||
TemplateCreateWindow(WindowDesc* _wdesc, TemplateVehicle *to_edit, bool *window_open) : Window(_wdesc)
|
||||
{
|
||||
this->line_height = step_h;
|
||||
this->CreateNestedTree(_wdesc != NULL);
|
||||
this->hscroll = this->GetScrollbar(TCW_SCROLLBAR_H_NEW_TMPL);
|
||||
this->vscroll = this->GetScrollbar(TCW_SCROLLBAR_V_NEW_TMPL);
|
||||
@ -293,7 +291,7 @@ public:
|
||||
switch(widget) {
|
||||
case TCW_NEW_TMPL_PANEL: {
|
||||
if (this->virtual_train) {
|
||||
DrawTrainImage(virtual_train, r.left+TRAIN_FRONT_SPACE, r.right - 25, r.top + 2, this->sel, EIT_PURCHASE, this->hscroll->GetPosition(), this->vehicle_over);
|
||||
DrawTrainImage(virtual_train, r.left + TRAIN_FRONT_SPACE, r.right - 25, r.top + 2, this->sel, EIT_IN_DEPOT, this->hscroll->GetPosition(), this->vehicle_over);
|
||||
SetDParam(0, CeilDiv(virtual_train->gcache.cached_total_length * 10, TILE_SIZE));
|
||||
SetDParam(1, 1);
|
||||
DrawString(r.left, r.right, r.top, STR_TINY_BLACK_DECIMAL, TC_BLACK, SA_RIGHT);
|
||||
@ -327,7 +325,7 @@ public:
|
||||
SetDParam(0, i);
|
||||
SetDParam(1, cargo_caps[i]);
|
||||
DrawString(8, r.right, y, STR_TMPL_CARGO_SUMMARY, TC_LIGHT_BLUE, SA_LEFT);
|
||||
y += this->line_height / 3;
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -453,7 +451,7 @@ public:
|
||||
|
||||
for (CargoID i = 0; i < NUM_CARGO; ++i) {
|
||||
if (cargo_caps[i] > 0) {
|
||||
height += this->line_height / 3;
|
||||
height += FONT_HEIGHT_NORMAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -555,10 +553,10 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void ShowTemplateCreateWindow(TemplateVehicle *to_edit, bool *create_window_open, int step_h)
|
||||
void ShowTemplateCreateWindow(TemplateVehicle *to_edit, bool *create_window_open)
|
||||
{
|
||||
if (BringWindowToFrontById(WC_CREATE_TEMPLATE, VEH_TRAIN) != NULL) return;
|
||||
new TemplateCreateWindow(&_template_create_window_desc, to_edit, create_window_open, step_h);
|
||||
new TemplateCreateWindow(&_template_create_window_desc, to_edit, create_window_open);
|
||||
}
|
||||
|
||||
void CcSetVirtualTrain(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
|
||||
|
@ -14,6 +14,6 @@
|
||||
|
||||
#include "tbtr_template_vehicle.h"
|
||||
|
||||
void ShowTemplateCreateWindow(TemplateVehicle*, bool*, int);
|
||||
void ShowTemplateCreateWindow(TemplateVehicle*, bool*);
|
||||
|
||||
#endif
|
||||
|
@ -117,7 +117,9 @@ static const NWidgetPart _widgets[] = {
|
||||
EndContainer(),
|
||||
//Top Matrix
|
||||
NWidget(NWID_VERTICAL),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY, TRW_WIDGET_INSET_GROUPS), SetMinimalTextLines(1, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM), SetResize(1, 0), EndContainer(),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY),
|
||||
NWidget(WWT_TEXT, COLOUR_GREY, TRW_WIDGET_INSET_GROUPS), SetPadding(2, 2, 2, 2), SetResize(1, 0), SetDataTip(STR_TMPL_MAINGUI_DEFINEDGROUPS, STR_NULL),
|
||||
EndContainer(),
|
||||
NWidget(NWID_HORIZONTAL),
|
||||
NWidget(WWT_MATRIX, COLOUR_GREY, TRW_WIDGET_TOP_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetDataTip(0x1, STR_REPLACE_HELP_LEFT_ARRAY), SetResize(1, 0), SetScrollbar(TRW_WIDGET_TOP_SCROLLBAR),
|
||||
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, TRW_WIDGET_TOP_SCROLLBAR),
|
||||
@ -125,7 +127,9 @@ static const NWidgetPart _widgets[] = {
|
||||
EndContainer(),
|
||||
// Template Display
|
||||
NWidget(NWID_VERTICAL),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY, TRW_WIDGET_INSET_TEMPLATES), SetMinimalTextLines(1, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM), SetResize(1, 0), EndContainer(),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY),
|
||||
NWidget(WWT_TEXT, COLOUR_GREY, TRW_WIDGET_INSET_TEMPLATES), SetPadding(2, 2, 2, 2), SetResize(1, 0), SetDataTip(STR_TMPL_AVAILABLE_TEMPLATES, STR_NULL),
|
||||
EndContainer(),
|
||||
NWidget(NWID_HORIZONTAL),
|
||||
NWidget(WWT_MATRIX, COLOUR_GREY, TRW_WIDGET_BOTTOM_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetDataTip(0x1, STR_REPLACE_HELP_RIGHT_ARRAY), SetResize(1, 1), SetScrollbar(TRW_WIDGET_MIDDLE_SCROLLBAR),
|
||||
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, TRW_WIDGET_MIDDLE_SCROLLBAR),
|
||||
@ -133,7 +137,9 @@ static const NWidgetPart _widgets[] = {
|
||||
EndContainer(),
|
||||
// Info Area
|
||||
NWidget(NWID_VERTICAL),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY, TRW_WIDGET_TMPL_INFO_INSET), SetMinimalTextLines(1, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM), SetResize(1,0), EndContainer(),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY),
|
||||
NWidget(WWT_TEXT, COLOUR_GREY, TRW_WIDGET_TMPL_INFO_INSET), SetPadding(2, 2, 2, 2), SetResize(1, 0), SetDataTip(STR_TMPL_TEMPLATE_INFO, STR_NULL),
|
||||
EndContainer(),
|
||||
NWidget(NWID_HORIZONTAL),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY, TRW_WIDGET_TMPL_INFO_PANEL), SetMinimalSize(216,120), SetResize(1,0), SetScrollbar(TRW_WIDGET_BOTTOM_SCROLLBAR), EndContainer(),
|
||||
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, TRW_WIDGET_BOTTOM_SCROLLBAR),
|
||||
@ -184,12 +190,12 @@ class TemplateReplaceWindow : public Window {
|
||||
private:
|
||||
|
||||
GUIGroupList groups; ///< List of groups
|
||||
byte unitnumber_digits;
|
||||
uint unitnumber_digits;
|
||||
|
||||
SmallVector<int, 16> indents; ///< Indentation levels
|
||||
|
||||
short line_height;
|
||||
short matrixContentLeftMargin;
|
||||
int bottom_matrix_item_size = 0;
|
||||
|
||||
int details_height; ///< Minimal needed height of the details panels (found so far).
|
||||
RailType sel_railtype; ///< Type of rail tracks selected.
|
||||
@ -204,13 +210,13 @@ private:
|
||||
bool editInProgress;
|
||||
|
||||
public:
|
||||
TemplateReplaceWindow(WindowDesc *wdesc, byte dig, int step_h) : Window(wdesc)
|
||||
TemplateReplaceWindow(WindowDesc *wdesc, uint unitnumber_digits) : Window(wdesc)
|
||||
{
|
||||
// listing/sorting
|
||||
templates.SetSortFuncs(this->template_sorter_funcs);
|
||||
|
||||
// From BaseVehicleListWindow
|
||||
this->unitnumber_digits = dig;
|
||||
this->unitnumber_digits = unitnumber_digits;
|
||||
|
||||
/* Find the most used vehicle type, which is usually
|
||||
* better than 'just' the first/previous vehicle type. */
|
||||
@ -230,8 +236,6 @@ public:
|
||||
|
||||
this->details_height = 10 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
||||
|
||||
this->line_height = step_h;
|
||||
|
||||
this->CreateNestedTree(wdesc != NULL);
|
||||
this->vscroll[0] = this->GetScrollbar(TRW_WIDGET_TOP_SCROLLBAR);
|
||||
this->vscroll[1] = this->GetScrollbar(TRW_WIDGET_MIDDLE_SCROLLBAR);
|
||||
@ -265,11 +269,11 @@ public:
|
||||
{
|
||||
switch (widget) {
|
||||
case TRW_WIDGET_TOP_MATRIX:
|
||||
resize->height = GetVehicleListHeight(VEH_TRAIN, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP) / 2;
|
||||
resize->height = WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM;
|
||||
size->height = 8 * resize->height;
|
||||
break;
|
||||
case TRW_WIDGET_BOTTOM_MATRIX:
|
||||
resize->height = GetVehicleListHeight(VEH_TRAIN, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP);
|
||||
this->bottom_matrix_item_size = resize->height = WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + ScaleGUITrad(GetVehicleHeight(VEH_TRAIN));
|
||||
size->height = 4 * resize->height;
|
||||
break;
|
||||
case TRW_WIDGET_TRAIN_RAILTYPE_DROPDOWN: {
|
||||
@ -304,27 +308,15 @@ public:
|
||||
{
|
||||
switch (widget) {
|
||||
case TRW_WIDGET_TOP_MATRIX: {
|
||||
DrawAllGroupsFunction(this->line_height, r);
|
||||
DrawAllGroupsFunction(r);
|
||||
break;
|
||||
}
|
||||
case TRW_WIDGET_BOTTOM_MATRIX: {
|
||||
DrawTemplateList(this->line_height, r);
|
||||
DrawTemplateList(r);
|
||||
break;
|
||||
}
|
||||
case TRW_WIDGET_TMPL_INFO_PANEL: {
|
||||
DrawTemplateInfo(this->line_height, r);
|
||||
break;
|
||||
}
|
||||
case TRW_WIDGET_INSET_GROUPS: {
|
||||
DrawString(r.left + 2, r.right - 2, r.top + 2, STR_TMPL_MAINGUI_DEFINEDGROUPS);
|
||||
break;
|
||||
}
|
||||
case TRW_WIDGET_INSET_TEMPLATES: {
|
||||
DrawString(r.left + 2, r.right - 2, r.top + 2, STR_TMPL_AVAILABLE_TEMPLATES);
|
||||
break;
|
||||
}
|
||||
case TRW_WIDGET_TMPL_INFO_INSET: {
|
||||
DrawString(r.left + 2, r.right - 2, r.top + 2, STR_TMPL_TEMPLATE_INFO);
|
||||
DrawTemplateInfo(r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -360,7 +352,7 @@ public:
|
||||
for (CargoID i = 0; i < NUM_CARGO; ++i) {
|
||||
if (cargo_caps[i] > 0) {
|
||||
if (count_columns % max_columns == 0) {
|
||||
height += this->line_height / 3;
|
||||
height += FONT_HEIGHT_NORMAL;
|
||||
}
|
||||
|
||||
++count_columns;
|
||||
@ -405,7 +397,7 @@ public:
|
||||
}
|
||||
case TRW_WIDGET_TMPL_BUTTONS_DEFINE: {
|
||||
editInProgress = true;
|
||||
ShowTemplateCreateWindow(0, &editInProgress, this->line_height);
|
||||
ShowTemplateCreateWindow(nullptr, &editInProgress);
|
||||
UpdateButtonState();
|
||||
break;
|
||||
}
|
||||
@ -413,7 +405,7 @@ public:
|
||||
if ((this->selected_template_index >= 0) && (this->selected_template_index < (short)this->templates.Length())) {
|
||||
editInProgress = true;
|
||||
TemplateVehicle *sel = TemplateVehicle::Get(((this->templates)[selected_template_index])->index);
|
||||
ShowTemplateCreateWindow(sel, &editInProgress, this->line_height);
|
||||
ShowTemplateCreateWindow(sel, &editInProgress);
|
||||
UpdateButtonState();
|
||||
}
|
||||
break;
|
||||
@ -447,7 +439,7 @@ public:
|
||||
ShowDropDownList(this, GetRailTypeDropDownList(true), sel_railtype, TRW_WIDGET_TRAIN_RAILTYPE_DROPDOWN);
|
||||
break;
|
||||
case TRW_WIDGET_TOP_MATRIX: {
|
||||
uint16 newindex = (uint16)((pt.y - this->nested_array[TRW_WIDGET_TOP_MATRIX]->pos_y) / (this->line_height / 2) ) + this->vscroll[0]->GetPosition();
|
||||
uint16 newindex = (uint16)((pt.y - this->nested_array[TRW_WIDGET_TOP_MATRIX]->pos_y) / (WD_MATRIX_TOP + FONT_HEIGHT_NORMAL+ WD_MATRIX_BOTTOM) ) + this->vscroll[0]->GetPosition();
|
||||
if (newindex == this->selected_group_index || newindex >= this->groups.Length()) {
|
||||
this->selected_group_index = -1;
|
||||
} else if (newindex < this->groups.Length()) {
|
||||
@ -457,7 +449,7 @@ public:
|
||||
break;
|
||||
}
|
||||
case TRW_WIDGET_BOTTOM_MATRIX: {
|
||||
uint16 newindex = (uint16)((pt.y - this->nested_array[TRW_WIDGET_BOTTOM_MATRIX]->pos_y) / this->line_height) + this->vscroll[1]->GetPosition();
|
||||
uint16 newindex = (uint16)((pt.y - this->nested_array[TRW_WIDGET_BOTTOM_MATRIX]->pos_y) / this->bottom_matrix_item_size) + this->vscroll[1]->GetPosition();
|
||||
if (newindex == this->selected_template_index || newindex >= templates.Length()) {
|
||||
this->selected_template_index = -1;
|
||||
} else if (newindex < templates.Length()) {
|
||||
@ -620,7 +612,7 @@ public:
|
||||
this->vscroll[0]->SetCount(groups.Length());
|
||||
}
|
||||
|
||||
void DrawAllGroupsFunction(int line_height, const Rect &r) const
|
||||
void DrawAllGroupsFunction(const Rect &r) const
|
||||
{
|
||||
int left = r.left + WD_MATRIX_LEFT;
|
||||
int right = r.right - WD_MATRIX_RIGHT;
|
||||
@ -634,7 +626,7 @@ public:
|
||||
|
||||
/* Fill the background of the current cell in a darker tone for the currently selected template */
|
||||
if (this->selected_group_index == i) {
|
||||
GfxFillRect(r.left + 1, y, r.right, y + (this->line_height) / 2, _colour_gradient[COLOUR_GREY][3]);
|
||||
GfxFillRect(r.left + 1, y, r.right, y + WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM, _colour_gradient[COLOUR_GREY][3]);
|
||||
}
|
||||
|
||||
int text_y = y + ScaleGUITrad(3);
|
||||
@ -653,29 +645,22 @@ public:
|
||||
}
|
||||
|
||||
/* Draw the number of trains that still need to be treated by the currently selected template replacement */
|
||||
TemplateReplacement *tr = GetTemplateReplacementByGroupID(g_id);
|
||||
const TemplateReplacement *tr = GetTemplateReplacementByGroupID(g_id);
|
||||
if (tr) {
|
||||
TemplateVehicle *tv = TemplateVehicle::Get(tr->sel_template);
|
||||
int num_trains = NumTrainsNeedTemplateReplacement(g_id, tv);
|
||||
const TemplateVehicle *tv = TemplateVehicle::Get(tr->sel_template);
|
||||
const int num_trains = NumTrainsNeedTemplateReplacement(g_id, tv);
|
||||
// Draw text
|
||||
TextColour color = TC_GREY;
|
||||
if (num_trains) color = TC_BLACK;
|
||||
DrawString(left, right - ScaleGUITrad(16), text_y, STR_TMPL_NUM_TRAINS_NEED_RPL, color, SA_RIGHT);
|
||||
DrawString(left, right - ScaleGUITrad(16), text_y, STR_TMPL_NUM_TRAINS_NEED_RPL, num_trains ? TC_BLACK : TC_GREY, SA_RIGHT);
|
||||
// Draw number
|
||||
if (num_trains ) {
|
||||
color = TC_ORANGE;
|
||||
} else {
|
||||
color = TC_GREY;
|
||||
}
|
||||
SetDParam(0, num_trains);
|
||||
DrawString(left, right - ScaleGUITrad(4), text_y, STR_JUST_INT, color, SA_RIGHT);
|
||||
DrawString(left, right - ScaleGUITrad(4), text_y, STR_JUST_INT, num_trains ? TC_ORANGE : TC_GREY, SA_RIGHT);
|
||||
}
|
||||
|
||||
y += line_height / 2;
|
||||
y += WD_MATRIX_TOP + FONT_HEIGHT_NORMAL+ WD_MATRIX_BOTTOM;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawTemplateList(int line_height, const Rect &r) const
|
||||
void DrawTemplateList(const Rect &r) const
|
||||
{
|
||||
int left = r.left;
|
||||
int right = r.right;
|
||||
@ -690,7 +675,7 @@ public:
|
||||
|
||||
/* Fill the background of the current cell in a darker tone for the currently selected template */
|
||||
if (this->selected_template_index == (int32) i) {
|
||||
GfxFillRect(left + 1, y, right, y + this->line_height, _colour_gradient[COLOUR_GREY][3]);
|
||||
GfxFillRect(left + 1, y, right, y + this->bottom_matrix_item_size, _colour_gradient[COLOUR_GREY][3]);
|
||||
}
|
||||
|
||||
/* Draw the template */
|
||||
@ -706,7 +691,7 @@ public:
|
||||
SetDParam(1, 1);
|
||||
DrawString(left, right - ScaleGUITrad(4), y + ScaleGUITrad(2), STR_TINY_BLACK_DECIMAL, TC_BLACK, SA_RIGHT);
|
||||
|
||||
int bottom_edge = y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - ScaleGUITrad(4);
|
||||
int bottom_edge = y + this->bottom_matrix_item_size - FONT_HEIGHT_NORMAL - WD_FRAMERECT_BOTTOM;
|
||||
|
||||
/* Buying cost */
|
||||
SetDParam(0, CalculateOverallTemplateCost(v));
|
||||
@ -718,7 +703,7 @@ public:
|
||||
|
||||
/* Draw whether the current template is in use by any group */
|
||||
if (v->NumGroupsUsingTemplate() > 0) {
|
||||
DrawString(left + ScaleGUITrad(35), right, bottom_edge - FONT_HEIGHT_SMALL - ScaleGUITrad(3),
|
||||
DrawString(left + ScaleGUITrad(35), right, bottom_edge - FONT_HEIGHT_NORMAL - WD_FRAMERECT_BOTTOM,
|
||||
STR_TMP_TEMPLATE_IN_USE, TC_GREEN, SA_LEFT);
|
||||
}
|
||||
|
||||
@ -734,11 +719,11 @@ public:
|
||||
color = v->IsSetRefitAsTemplate() ? TC_LIGHT_BLUE : TC_GREY;
|
||||
DrawString(right - ScaleGUITrad(75), right, bottom_edge, STR_TMPL_CONFIG_REFIT, color, SA_LEFT);
|
||||
|
||||
y += line_height;
|
||||
y += this->bottom_matrix_item_size;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawTemplateInfo(int line_height, const Rect &r) const
|
||||
void DrawTemplateInfo(const Rect &r) const
|
||||
{
|
||||
if ((this->selected_template_index < 0) || (this->selected_template_index >= (short)this->templates.Length())) {
|
||||
return;
|
||||
@ -783,7 +768,7 @@ public:
|
||||
x += ScaleGUITrad(250);
|
||||
if (count_columns % max_columns == 0) {
|
||||
x = left;
|
||||
top += this->line_height / 3;
|
||||
top += FONT_HEIGHT_NORMAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -817,7 +802,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void ShowTemplateReplaceWindow(byte dig, int step_h)
|
||||
void ShowTemplateReplaceWindow(uint unitnumber_digits)
|
||||
{
|
||||
new TemplateReplaceWindow(&_replace_rail_vehicle_desc, dig, step_h);
|
||||
new TemplateReplaceWindow(&_replace_rail_vehicle_desc, unitnumber_digits);
|
||||
}
|
||||
|
@ -23,6 +23,6 @@
|
||||
|
||||
typedef GUIList<const Group*> GUIGroupList;
|
||||
|
||||
void ShowTemplateReplaceWindow(byte, int);
|
||||
void ShowTemplateReplaceWindow(uint);
|
||||
|
||||
#endif
|
||||
|
@ -51,6 +51,19 @@ TemplateReplacementPool _template_replacement_pool("TemplateReplacementPool");
|
||||
INSTANTIATE_POOL_METHODS(TemplateReplacement)
|
||||
|
||||
|
||||
void TemplateVehicleImageDimensions::SetFromTrain(const Train *t)
|
||||
{
|
||||
this->reference_width = TRAININFO_DEFAULT_VEHICLE_WIDTH;
|
||||
this->vehicle_pitch = 0;
|
||||
this->cached_veh_length = t->gcache.cached_veh_length;
|
||||
|
||||
const Engine *e = t->GetEngine();
|
||||
if (e->GetGRF() != NULL && is_custom_sprite(e->u.rail.image_index)) {
|
||||
this->reference_width = e->GetGRF()->traininfo_vehicle_width;
|
||||
this->vehicle_pitch = e->GetGRF()->traininfo_vehicle_pitch;
|
||||
}
|
||||
}
|
||||
|
||||
TemplateVehicle::TemplateVehicle(VehicleType ty, EngineID eid, byte subtypeflag, Owner current_owner)
|
||||
{
|
||||
this->type = ty;
|
||||
@ -62,7 +75,6 @@ TemplateVehicle::TemplateVehicle(VehicleType ty, EngineID eid, byte subtypeflag,
|
||||
this->first = this;
|
||||
this->next = 0x0;
|
||||
this->previous = 0x0;
|
||||
this->owner_b = _current_company;
|
||||
|
||||
this->sprite_seq.Set(SPR_IMG_QUERY);
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
|
||||
#include "sortlist_type.h"
|
||||
|
||||
#include "zoom_func.h"
|
||||
|
||||
#define FOR_ALL_TEMPLATES_FROM(var, start) FOR_ALL_ITEMS_FROM(TemplateVehicle, template_index, var, start)
|
||||
#define FOR_ALL_TEMPLATES(var) FOR_ALL_TEMPLATES_FROM(var, 0)
|
||||
|
||||
@ -51,6 +53,29 @@ extern TemplatePool _template_pool;
|
||||
/// listing/sorting templates
|
||||
typedef GUIList<const TemplateVehicle*> GUITemplateList;
|
||||
|
||||
struct TemplateVehicleImageDimensions {
|
||||
int reference_width;
|
||||
int vehicle_pitch;
|
||||
int cached_veh_length;
|
||||
|
||||
void SetFromTrain(const Train *t);
|
||||
|
||||
int GetDisplayImageWidth() const
|
||||
{
|
||||
return ScaleGUITrad(this->cached_veh_length * this->reference_width / VEHICLE_LENGTH);
|
||||
}
|
||||
|
||||
int GetOffsetX() const
|
||||
{
|
||||
return ScaleGUITrad(this->reference_width) / 2;
|
||||
}
|
||||
|
||||
int GetOffsetY() const
|
||||
{
|
||||
return ScaleGUITrad(this->vehicle_pitch);
|
||||
}
|
||||
};
|
||||
|
||||
struct TemplateVehicle : TemplatePool::PoolItem<&_template_pool>, BaseVehicle {
|
||||
private:
|
||||
TemplateVehicle *next; ///< pointer to the next vehicle in the chain
|
||||
@ -69,8 +94,7 @@ public:
|
||||
// Things derived from a virtual train
|
||||
TemplateVehicle *other_multiheaded_part; ///< Multiheaded Engine support
|
||||
Money value; ///< Value of the vehicle
|
||||
Owner owner;
|
||||
OwnerByte owner_b;
|
||||
OwnerByte owner;
|
||||
|
||||
EngineID engine_type; ///< The type of engine used for this vehicle.
|
||||
CargoID cargo_type; ///< type of cargo this vehicle is carrying
|
||||
@ -89,9 +113,8 @@ public:
|
||||
uint32 weight;
|
||||
uint32 max_te;
|
||||
|
||||
byte spritenum;
|
||||
VehicleSpriteSeq sprite_seq; ///< Vehicle appearance.
|
||||
uint32 image_width;
|
||||
VehicleSpriteSeq sprite_seq; ///< NOSAVE: Vehicle appearance.
|
||||
TemplateVehicleImageDimensions image_dimensions; ///< NOSAVE: image dimensions
|
||||
|
||||
TemplateVehicle(VehicleType type = VEH_INVALID, EngineID e = INVALID_ENGINE, byte B = 0, Owner = _local_company);
|
||||
TemplateVehicle(EngineID, RailVehicleInfo*);
|
||||
|
@ -131,9 +131,9 @@ void DrawTemplate(const TemplateVehicle *tv, int left, int right, int y)
|
||||
|
||||
while (t) {
|
||||
PaletteID pal = GetEnginePalette(t->engine_type, _current_company);
|
||||
t->sprite_seq.Draw(offset + t->image_width / 2, ScaleGUITrad(11), pal, false);
|
||||
t->sprite_seq.Draw(offset + t->image_dimensions.GetOffsetX(), t->image_dimensions.GetOffsetY() + ScaleGUITrad(11), pal, false);
|
||||
|
||||
offset += t->image_width;
|
||||
offset += t->image_dimensions.GetDisplayImageWidth();
|
||||
t = t->Next();
|
||||
}
|
||||
|
||||
@ -165,10 +165,8 @@ inline void SetupTemplateVehicleFromVirtual(TemplateVehicle *tmp, TemplateVehicl
|
||||
tmp->weight = gcache->cached_weight;
|
||||
tmp->max_te = gcache->cached_max_te / 1000;
|
||||
|
||||
tmp->spritenum = virt->spritenum;
|
||||
virt->GetImage(DIR_W, EIT_PURCHASE, &tmp->sprite_seq);
|
||||
Point *p = new Point();
|
||||
tmp->image_width = virt->GetDisplayImageWidth(p);
|
||||
virt->GetImage(DIR_W, EIT_IN_DEPOT, &tmp->sprite_seq);
|
||||
tmp->image_dimensions.SetFromTrain(virt);
|
||||
}
|
||||
|
||||
// create a full TemplateVehicle based train according to a virtual train
|
||||
@ -293,7 +291,7 @@ void NeutralizeStatus(Train *t)
|
||||
DoCommand(0, t->index, 0, DC_EXEC, CMD_RENAME_VEHICLE, NULL);
|
||||
}
|
||||
|
||||
bool TrainMatchesTemplate(const Train *t, TemplateVehicle *tv) {
|
||||
bool TrainMatchesTemplate(const Train *t, const TemplateVehicle *tv) {
|
||||
while (t && tv) {
|
||||
if (t->engine_type != tv->engine_type) {
|
||||
return false;
|
||||
@ -308,7 +306,7 @@ bool TrainMatchesTemplate(const Train *t, TemplateVehicle *tv) {
|
||||
}
|
||||
|
||||
|
||||
bool TrainMatchesTemplateRefit(const Train *t, TemplateVehicle *tv)
|
||||
bool TrainMatchesTemplateRefit(const Train *t, const TemplateVehicle *tv)
|
||||
{
|
||||
if (!tv->refit_as_template) {
|
||||
return true;
|
||||
@ -346,7 +344,7 @@ void CopyWagonStatus(TemplateVehicle *from, Train *to)
|
||||
to->cargo_subtype = from->cargo_subtype;
|
||||
}
|
||||
|
||||
int NumTrainsNeedTemplateReplacement(GroupID g_id, TemplateVehicle *tv)
|
||||
int NumTrainsNeedTemplateReplacement(GroupID g_id, const TemplateVehicle *tv)
|
||||
{
|
||||
int count = 0;
|
||||
if (!tv) return count;
|
||||
|
@ -44,7 +44,7 @@ bool ChainContainsVehicle(Train*, Train*);
|
||||
Train* ChainContainsEngine(EngineID, Train*);
|
||||
Train* DepotContainsEngine(TileIndex, EngineID, Train*);
|
||||
|
||||
int NumTrainsNeedTemplateReplacement(GroupID, TemplateVehicle*);
|
||||
int NumTrainsNeedTemplateReplacement(GroupID, const TemplateVehicle*);
|
||||
|
||||
CommandCost TestBuyAllTemplateVehiclesInChain(TemplateVehicle *tv, TileIndex tile);
|
||||
|
||||
@ -57,7 +57,7 @@ void TransferCargoForTrain(Train*, Train*);
|
||||
|
||||
void NeutralizeStatus(Train *t);
|
||||
|
||||
bool TrainMatchesTemplate(const Train *t, TemplateVehicle *tv);
|
||||
bool TrainMatchesTemplateRefit(const Train *t, TemplateVehicle *tv);
|
||||
bool TrainMatchesTemplate(const Train *t, const TemplateVehicle *tv);
|
||||
bool TrainMatchesTemplateRefit(const Train *t, const TemplateVehicle *tv);
|
||||
|
||||
#endif
|
||||
|
@ -4223,8 +4223,6 @@ Train* CmdBuildVirtualRailVehicle(EngineID eid, bool lax_engine_check, StringID
|
||||
train_part->SetVirtual();
|
||||
}
|
||||
|
||||
v->UpdateViewport(true, false);
|
||||
|
||||
v->ConsistChanged(CCF_ARRANGE);
|
||||
|
||||
CheckConsistencyOfArticulatedVehicle(v);
|
||||
|
@ -808,9 +808,8 @@ inline void SetupTemplateVehicleFromVirtual(TemplateVehicle *tmp, TemplateVehicl
|
||||
tmp->weight = gcache->cached_weight;
|
||||
tmp->max_te = gcache->cached_max_te / 1000;
|
||||
|
||||
tmp->spritenum = virt->spritenum;
|
||||
virt->GetImage(DIR_W, EIT_PURCHASE, &tmp->sprite_seq);
|
||||
tmp->image_width = virt->GetDisplayImageWidth();
|
||||
virt->GetImage(DIR_W, EIT_IN_DEPOT, &tmp->sprite_seq);
|
||||
tmp->image_dimensions.SetFromTrain(virt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1678,7 +1678,7 @@ public:
|
||||
break;
|
||||
case ADI_TEMPLATE_REPLACE:
|
||||
if (vli.vtype == VEH_TRAIN) {
|
||||
ShowTemplateReplaceWindow(this->unitnumber_digits, this->resize.step_height);
|
||||
ShowTemplateReplaceWindow(this->unitnumber_digits);
|
||||
}
|
||||
break;
|
||||
case ADI_SERVICE: // Send for servicing
|
||||
|
Loading…
Reference in New Issue
Block a user