summaryrefslogtreecommitdiff
path: root/src/build_vehicle_gui.cpp
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2007-02-06 11:11:12 +0000
committerbjarni <bjarni@openttd.org>2007-02-06 11:11:12 +0000
commit80125fd934af1e79aa3223f9892d5754d3b4affa (patch)
treee35fe2197ef3aba9cb1b1902312f0f010202376b /src/build_vehicle_gui.cpp
parent2918fab68d1a37c0a342dfae4a2bfa350facaf8b (diff)
downloadopenttd-80125fd934af1e79aa3223f9892d5754d3b4affa.tar.xz
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
-The user will notice the following changes: All vehicle types behaves in the same way Adding/removing an engine (new design and so on) can no longer result in the window selecting a new engine All valid replacements will be displayed since it looks at refitting options as well (this solves the missing ships with the newships GRF) Since you can't replace an engine into itself, the engine selected in the left list will no longer appear in the right list -The code changes: Instead of looping all engines all the time, each list generates a list like the build windows This ensures consistent list generation since only one function can loop all engines Unified code for all vehicle types It now use the lists to call the drawing code in the build vehicle window Works on selected EngineIDs instead of selected index in the list
Diffstat (limited to 'src/build_vehicle_gui.cpp')
-rw-r--r--src/build_vehicle_gui.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 38b66bef5..e67fc6dd5 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -733,12 +733,14 @@ static void DrawVehicleEngine(byte type, int x, int y, EngineID engine, SpriteID
* @param min where to start in the list
* @param max where in the list to end
* @param selected_id what engine to highlight as selected, if any
+ * @param show_count Display the number of vehicles (used by autoreplace)
*/
-static void DrawEngineList(byte type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id)
+void DrawEngineList(byte type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count)
{
byte step_size = GetVehicleListHeight(type);
byte x_offset = 0;
byte y_offset = 0;
+ Player *p = GetPlayer(_local_player);
assert(max <= EngList_Count(&eng_list));
@@ -771,7 +773,11 @@ static void DrawEngineList(byte type, int x, int y, const EngineList eng_list, u
const EngineID engine = eng_list[min];
DrawString(x + x_offset, y, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10);
- DrawVehicleEngine(type, x, y + y_offset, engine, GetEnginePalette(engine, _local_player));
+ DrawVehicleEngine(type, x, y + y_offset, engine, (show_count && p->num_engines[engine] == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player));
+ if (show_count) {
+ SetDParam(0, p->num_engines[engine]);
+ DrawStringRightAligned(213, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, 0);
+ }
}
}
@@ -786,7 +792,7 @@ static void DrawBuildVehicleWindow(Window *w)
SetDParam(0, bv->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles
DrawWindowWidgets(w);
- DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine);
+ DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine, false);
if (bv->sel_engine != INVALID_ENGINE) {
const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];