summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-08-24 21:31:24 +0000
committerpeter1138 <peter1138@openttd.org>2008-08-24 21:31:24 +0000
commit6261063689a738338e1c37b183a8c6509ebd0b8d (patch)
tree927dfaba4b82723d3a08f65704230729ffdb3405 /src
parent8abd4137d4bc6714451e28f1748db81905984b66 (diff)
downloadopenttd-6261063689a738338e1c37b183a8c6509ebd0b8d.tar.xz
(svn r14157) -Codechange: Add and use string properties for rail types instead of relying on consecutive string IDs.
Diffstat (limited to 'src')
-rw-r--r--src/autoreplace_gui.cpp24
-rw-r--r--src/build_vehicle_gui.cpp9
-rw-r--r--src/engine_gui.cpp9
-rw-r--r--src/rail.h4
-rw-r--r--src/table/railtypes.h32
5 files changed, 55 insertions, 23 deletions
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
index 1268cf18b..7b6645e66 100644
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -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);
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index cf902cdad..7a2282097 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -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];
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
index e574545fe..f2eba113e 100644
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -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;
}
}
diff --git a/src/rail.h b/src/rail.h
index f5ee6b14f..e7d8f293c 100644
--- a/src/rail.h
+++ b/src/rail.h
@@ -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 */
diff --git a/src/table/railtypes.h b/src/table/railtypes.h
index 0d86851f5..8bfa65645 100644
--- a/src/table/railtypes.h
+++ b/src/table/railtypes.h
@@ -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,