(svn r7099) -Fix (r4768): When changing the selected newstation type, ensure the station size chosen is permitted. If not, pick the first valid sizes.
authorpeter1138
Tue, 07 Nov 2006 15:25:07 +0000
changeset 5049 43340069c983
parent 5048 b784951def0a
child 5050 659c09a2b29e
(svn r7099) -Fix (r4768): When changing the selected newstation type, ensure the station size chosen is permitted. If not, pick the first valid sizes.
rail_gui.c
--- a/rail_gui.c	Tue Nov 07 14:41:53 2006 +0000
+++ b/rail_gui.c	Tue Nov 07 15:25:07 2006 +0000
@@ -631,6 +631,30 @@
 			CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
 }
 
+/* Check if the currently selected station size is allowed */
+static void CheckSelectedSize(Window *w, const StationSpec *statspec)
+{
+	if (statspec == NULL || _railstation.dragdrop) return;
+
+	if (HASBIT(statspec->disallowed_platforms, _railstation.numtracks - 1)) {
+		RaiseWindowWidget(w, _railstation.numtracks + 4);
+		_railstation.numtracks = 1;
+		while (HASBIT(statspec->disallowed_platforms, _railstation.numtracks - 1)) {
+			_railstation.numtracks++;
+		}
+		LowerWindowWidget(w, _railstation.numtracks + 4);
+	}
+
+	if (HASBIT(statspec->disallowed_lengths, _railstation.platlength - 1)) {
+		RaiseWindowWidget(w, _railstation.platlength + 11);
+		_railstation.platlength = 1;
+		while (HASBIT(statspec->disallowed_lengths, _railstation.platlength - 1)) {
+			_railstation.platlength++;
+		}
+		LowerWindowWidget(w, _railstation.platlength + 11);
+	}
+}
+
 static void StationBuildWndProc(Window *w, WindowEvent *e)
 {
 	switch (e->event) {
@@ -824,6 +848,9 @@
 				GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE) == 0) return;
 
 			_railstation.station_type = y;
+
+			CheckSelectedSize(w, statspec);
+
 			SndPlayFx(SND_15_BEEP);
 			SetWindowDirty(w);
 			break;
@@ -837,6 +864,8 @@
 			_railstation.station_type  = 0;
 			_railstation.station_count = GetNumCustomStations(_railstation.station_class);
 
+			CheckSelectedSize(w, GetCustomStationSpec(_railstation.station_class, _railstation.station_type));
+
 			w->vscroll.count = _railstation.station_count;
 			w->vscroll.pos   = _railstation.station_type;
 		}