src/airport_gui.cpp
branchNewGRF_ports
changeset 6762 aebd7285dbc2
parent 6760 d7a806a9aa44
child 6764 9ba2e4d4a57f
--- a/src/airport_gui.cpp	Mon Aug 06 01:24:26 2007 +0000
+++ b/src/airport_gui.cpp	Mon Aug 06 03:09:53 2007 +0000
@@ -24,7 +24,7 @@
 //TODO: remove station.h once converted to newgrf airports. stations just used as temporary loader
 #include "station.h"
 static struct {
-	byte orientation;
+	byte layout_set;
 	byte numtracks;
 	byte platlength;
 	bool dragdrop;
@@ -34,6 +34,7 @@
 	FSMportsClassIDByte fsmports_class;
 	byte station_type;
 	byte station_count;
+	byte direction;
 } _airport;
 
 static byte _selected_airport_type = 0;
@@ -53,7 +54,7 @@
 {
 	if (_airport.station_type != 0xFF) /*0xFF represents No Airports Available to build */
 		DoCommandP(tile,
-				_airport.orientation | (_airport.numtracks << 8) | (_airport.platlength << 16) | (_ctrl_pressed << 24),
+				_airport.layout_set | (_airport.numtracks << 8) | (_airport.platlength << 16) | (_ctrl_pressed << 24),
 				_selected_airport_type | ((_airport.newstation_selected)? 0x80 : 0x00) | (_airport.fsmports_class << 8) | (_airport.station_type << 16), CcBuildAirport,
 				CMD_BUILD_AIRPORT | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE));
 }
@@ -202,13 +203,13 @@
 		{
 			SetWindowWidgetDisabledState(w, 28 + j, true);
 			RaiseWindowWidget(w, 28 + j);
-			w->widget[28 + _airport.orientation].data = SPR_IMG_ARROW_NE_WHITE + j;  //reset arrows to white
+			w->widget[28 + j].data = SPR_IMG_ARROW_NE_WHITE + j;  //reset arrows to white
 		}
 
 		if (_airport.station_type != 0xFF)
 		{
-			int x = fsmportspec->size_x[_airport.orientation];
-			int y = fsmportspec->size_y[_airport.orientation];
+			int x = fsmportspec->size_x[_airport.layout_set];
+			int y = fsmportspec->size_y[_airport.layout_set];
 			SetTileSelectSize(x, y);
 
 			/* an airport is available, so read it and update screen accordingly */
@@ -216,16 +217,16 @@
 			{
 				if (fsmportspec->layouts[j] == NULL) break;
 				/* enable the permitted orientations */
-				byte *layout_ptr = (byte*)alloca(x*y + 1);
-				memcpy(layout_ptr, fsmportspec->layouts[j], (x * y) + 1);
+				byte *layout_ptr = (byte*)alloca(x*y + 2);
+				memcpy(layout_ptr, fsmportspec->layouts[j], (x * y) + 2);
 				SetWindowWidgetDisabledState(w, 28 + GB((byte)*layout_ptr,1,2), false);
-				if (j == _airport.orientation) {
+				if (j == _airport.layout_set) {
 					layout_ptr++;
 					preview_sprite = *layout_ptr;
 				}
 			}
-			LowerWindowWidget(w, 28 + _airport.orientation);
-			w->widget[28 + _airport.orientation].data = SPR_IMG_ARROW_NE_YELLOW + _airport.orientation;  //show in yellow
+			LowerWindowWidget(w, 28 + ((_airport.direction - 1) / 2));
+			w->widget[28 + ((_airport.direction - 1) / 2)].data = SPR_IMG_ARROW_NE_YELLOW + ((_airport.direction - 1) / 2);  //show in yellow
 
 			_thd.airport = _airport.station_type;
 			_thd.airport_template = true;
@@ -312,9 +313,9 @@
 				GetFSMportsCallback(CBID_STATION_AVAILABILITY, 0, 0, fsmportspec, NULL, INVALID_TILE) == 0) return;
 
 			_airport.station_type = y;
-			_airport.orientation = 0;
-			_airport.platlength= fsmportspec->size_y[_airport.orientation];
-			_airport.numtracks = fsmportspec->size_x[_airport.orientation];
+			_airport.layout_set = 0;
+			_airport.platlength= fsmportspec->size_y[_airport.layout_set];
+			_airport.numtracks = fsmportspec->size_x[_airport.layout_set];
 			_airport.newstation_selected = true;
 
 			SndPlayFx(SND_15_BEEP);
@@ -322,12 +323,30 @@
 			break;
 			}
 		case 28: case 29: case 30: case 31:
-			w->widget[28 + _airport.orientation].data = SPR_IMG_ARROW_NE_WHITE + _airport.orientation;  //reset arrow to white
-			_airport.orientation = (e->we.click.widget - 28);
-			SetWindowWidgetLoweredState(w, 28, (_airport.orientation == 0));
-			SetWindowWidgetLoweredState(w, 29, (_airport.orientation == 1));
-			SetWindowWidgetLoweredState(w, 30, (_airport.orientation == 2));
-			SetWindowWidgetLoweredState(w, 31, (_airport.orientation == 3));
+			w->widget[28 + ((_airport.direction - 1) / 2)].data = SPR_IMG_ARROW_NE_WHITE + ((_airport.direction - 1) / 2);  //reset arrow to white
+
+			/* find the layout_set that corresponds to the selected orientation */
+			FSMportsSpec *fsmportspec = GetCustomFSMportsSpec(_airport.fsmports_class, _airport.station_type);
+			_airport.layout_set = 0;
+			_airport.direction = (byte)((e->we.click.widget - 28) * 2 + 1);
+			for (byte j = 0; j < fsmportspec->numlayouts; j++)
+			{
+				int x = fsmportspec->size_x[j];
+				int y = fsmportspec->size_y[j];
+				if (fsmportspec->layouts[j] == NULL) break;
+				/* enable the permitted orientations */
+				byte *layout_ptr = (byte*)alloca(x*y + 2);
+				memcpy(layout_ptr, fsmportspec->layouts[j], (x * y) + 2);
+				if (*layout_ptr == _airport.direction) {
+					_airport.layout_set = j;
+					break;
+				}
+			}
+
+			SetWindowWidgetLoweredState(w, 28, (_airport.direction == 01));
+			SetWindowWidgetLoweredState(w, 29, (_airport.direction == 03));
+			SetWindowWidgetLoweredState(w, 30, (_airport.direction == 05));
+			SetWindowWidgetLoweredState(w, 31, (_airport.direction == 07));
 			SndPlayFx(SND_15_BEEP);
 			SetWindowDirty(w);
 			break;
@@ -338,7 +357,8 @@
 		if (_airport.fsmports_class != e->we.dropdown.index) {
 			_airport.fsmports_class = (FSMportsClassID)e->we.dropdown.index;
 			_airport.station_type  = 0;
-			_airport.orientation = 0;
+			_airport.layout_set = 0;
+			_airport.direction = 1;
 			_airport.station_count = GetNumCustomFSMports(_airport.fsmports_class);
 
 			w->vscroll.count = _airport.station_count;
@@ -459,7 +479,8 @@
 	{
 		w = AllocateWindowDesc(&_newports_build_airport_desc);
 		_airport.station_type = 0;
-		_airport.orientation = 0;
+		_airport.layout_set = 0;
+		_airport.direction = 1;
 		_airport.newstation_selected = true;
 		_airport.newstations = true;
 		_airport.station_count = GetNumCustomFSMports(_airport.fsmports_class);