mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r14157) -Codechange: Add and use string properties for rail types instead of relying on consecutive string IDs.
This commit is contained in:
parent
0d4e7f9537
commit
ff07598ce2
|
@ -18,6 +18,7 @@
|
|||
#include "autoreplace_func.h"
|
||||
#include "gfx_func.h"
|
||||
#include "player_func.h"
|
||||
#include "widgets/dropdown_type.h"
|
||||
#include "widgets/dropdown_func.h"
|
||||
#include "engine_func.h"
|
||||
#include "engine_base.h"
|
||||
|
@ -29,14 +30,6 @@
|
|||
|
||||
void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group);
|
||||
|
||||
static const StringID _rail_types_list[] = {
|
||||
STR_RAIL_VEHICLES,
|
||||
STR_ELRAIL_VEHICLES,
|
||||
STR_MONORAIL_VEHICLES,
|
||||
STR_MAGLEV_VEHICLES,
|
||||
INVALID_STRING_ID
|
||||
};
|
||||
|
||||
enum ReplaceVehicleWindowWidgets {
|
||||
RVW_WIDGET_LEFT_MATRIX = 3,
|
||||
RVW_WIDGET_LEFT_SCROLLBAR,
|
||||
|
@ -310,7 +303,8 @@ public:
|
|||
|
||||
if (this->window_number == VEH_TRAIN) {
|
||||
/* Show the selected railtype in the pulldown menu */
|
||||
this->widget[RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN].data = _rail_types_list[sel_railtype];
|
||||
const RailtypeInfo *rti = GetRailTypeInfo(sel_railtype);
|
||||
this->widget[RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN].data = rti->strings.replace_text;
|
||||
}
|
||||
|
||||
this->DrawWidgets();
|
||||
|
@ -363,9 +357,17 @@ public:
|
|||
this->SetDirty();
|
||||
break;
|
||||
|
||||
case RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN: /* Railtype selection dropdown menu */
|
||||
ShowDropDownMenu(this, _rail_types_list, sel_railtype, RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN, 0, ~GetPlayer(_local_player)->avail_railtypes);
|
||||
case RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN: { /* Railtype selection dropdown menu */
|
||||
const Player *p = GetPlayer(_local_player);
|
||||
DropDownList *list = new DropDownList();
|
||||
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
|
||||
const RailtypeInfo *rti = GetRailTypeInfo(rt);
|
||||
|
||||
list->push_back(new DropDownListStringItem(rti->strings.replace_text, rt, !HasBit(p->avail_railtypes, rt)));
|
||||
}
|
||||
ShowDropDownList(this, list, sel_railtype, RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN);
|
||||
break;
|
||||
}
|
||||
|
||||
case RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE: /* toggle renew_keep_length */
|
||||
DoCommandP(0, 5, GetPlayer(_local_player)->renew_keep_length ? 0 : 1, NULL, CMD_SET_AUTOREPLACE);
|
||||
|
|
|
@ -1113,7 +1113,14 @@ struct BuildVehicleWindow : Window {
|
|||
uint max = min(this->vscroll.pos + this->vscroll.cap, this->eng_list.Length());
|
||||
|
||||
SetVScrollCount(this, this->eng_list.Length());
|
||||
SetDParam(0, this->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles
|
||||
if (this->vehicle_type == VEH_TRAIN) {
|
||||
if (this->filter.railtype == RAILTYPE_END) {
|
||||
SetDParam(0, STR_ALL_AVAIL_RAIL_VEHICLES);
|
||||
} else {
|
||||
const RailtypeInfo *rti = GetRailTypeInfo(this->filter.railtype);
|
||||
SetDParam(0, rti->strings.build_caption);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set text of sort by dropdown */
|
||||
this->widget[BUILD_VEHICLE_WIDGET_SORT_DROPDOWN].data = _sort_listing[this->vehicle_type][this->sort_criteria];
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "strings_func.h"
|
||||
#include "engine_gui.h"
|
||||
#include "articulated_vehicles.h"
|
||||
#include "rail.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
#include "table/sprites.h"
|
||||
|
@ -29,13 +30,7 @@ StringID GetEngineCategoryName(EngineID engine)
|
|||
case VEH_AIRCRAFT: return STR_8104_AIRCRAFT;
|
||||
case VEH_SHIP: return STR_8105_SHIP;
|
||||
case VEH_TRAIN:
|
||||
switch (RailVehInfo(engine)->railtype) {
|
||||
default: NOT_REACHED();
|
||||
case RAILTYPE_RAIL: return STR_8102_RAILROAD_LOCOMOTIVE;
|
||||
case RAILTYPE_ELECTRIC: return STR_8102_RAILROAD_LOCOMOTIVE;
|
||||
case RAILTYPE_MONO: return STR_8106_MONORAIL_LOCOMOTIVE;
|
||||
case RAILTYPE_MAGLEV: return STR_8107_MAGLEV_LOCOMOTIVE;
|
||||
}
|
||||
return GetRailTypeInfo(RailVehInfo(engine)->railtype)->strings.new_loco;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,10 @@ struct RailtypeInfo {
|
|||
|
||||
struct {
|
||||
StringID toolbar_caption;
|
||||
StringID menu_text;
|
||||
StringID build_caption;
|
||||
StringID replace_text;
|
||||
StringID new_loco;
|
||||
} strings;
|
||||
|
||||
/** sprite number difference between a piece of track on a snowy ground and the corresponding one on normal ground */
|
||||
|
|
|
@ -39,7 +39,13 @@ RailtypeInfo _railtypes[] = {
|
|||
},
|
||||
|
||||
/* strings */
|
||||
{ STR_100A_RAILROAD_CONSTRUCTION },
|
||||
{
|
||||
STR_100A_RAILROAD_CONSTRUCTION,
|
||||
STR_1015_RAILROAD_CONSTRUCTION,
|
||||
STR_881C_NEW_RAIL_VEHICLES,
|
||||
STR_RAIL_VEHICLES,
|
||||
STR_8102_RAILROAD_LOCOMOTIVE,
|
||||
},
|
||||
|
||||
/* Offset of snow tiles */
|
||||
SPR_RAIL_SNOW_OFFSET,
|
||||
|
@ -99,7 +105,13 @@ RailtypeInfo _railtypes[] = {
|
|||
},
|
||||
|
||||
/* strings */
|
||||
{ STR_TITLE_ELRAIL_CONSTRUCTION },
|
||||
{
|
||||
STR_TITLE_ELRAIL_CONSTRUCTION,
|
||||
STR_TOOLB_ELRAIL_CONSTRUCTION,
|
||||
STR_NEW_ELRAIL_VEHICLES,
|
||||
STR_ELRAIL_VEHICLES,
|
||||
STR_8102_RAILROAD_LOCOMOTIVE,
|
||||
},
|
||||
|
||||
/* Offset of snow tiles */
|
||||
SPR_RAIL_SNOW_OFFSET,
|
||||
|
@ -155,7 +167,13 @@ RailtypeInfo _railtypes[] = {
|
|||
},
|
||||
|
||||
/* strings */
|
||||
{ STR_100B_MONORAIL_CONSTRUCTION },
|
||||
{
|
||||
STR_100B_MONORAIL_CONSTRUCTION,
|
||||
STR_1016_MONORAIL_CONSTRUCTION,
|
||||
STR_881D_NEW_MONORAIL_VEHICLES,
|
||||
STR_MONORAIL_VEHICLES,
|
||||
STR_8106_MONORAIL_LOCOMOTIVE,
|
||||
},
|
||||
|
||||
/* Offset of snow tiles */
|
||||
SPR_MONO_SNOW_OFFSET,
|
||||
|
@ -211,7 +229,13 @@ RailtypeInfo _railtypes[] = {
|
|||
},
|
||||
|
||||
/* strings */
|
||||
{ STR_100C_MAGLEV_CONSTRUCTION },
|
||||
{
|
||||
STR_100C_MAGLEV_CONSTRUCTION,
|
||||
STR_1017_MAGLEV_CONSTRUCTION,
|
||||
STR_881E_NEW_MAGLEV_VEHICLES,
|
||||
STR_MAGLEV_VEHICLES,
|
||||
STR_8107_MAGLEV_LOCOMOTIVE,
|
||||
},
|
||||
|
||||
/* Offset of snow tiles */
|
||||
SPR_MGLV_SNOW_OFFSET,
|
||||
|
|
Loading…
Reference in New Issue