--- a/src/airport_gui.cpp Fri Aug 03 18:24:48 2007 +0000
+++ b/src/airport_gui.cpp Sat Aug 04 17:26:22 2007 +0000
@@ -34,7 +34,7 @@
FSMportsClassIDByte fsmports_class;
byte station_type;
byte station_count;
-} _railstation;
+} _airport;
//TODO: remove above after conversion
@@ -56,8 +56,8 @@
{
//DoCommandP(tile, _selected_airport_type, _ctrl_pressed, CcBuildAirport, CMD_BUILD_AIRPORT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE));
DoCommandP(tile,
- _railstation.orientation | (_railstation.numtracks << 8) | (_railstation.platlength << 16) | (_ctrl_pressed << 24),
- _selected_airport_type | ((_railstation.newstation_selected)? 0x80 : 0x00) | (_railstation.fsmports_class << 8) | (_railstation.station_type << 16), CcBuildAirport,
+ _airport.orientation | (_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));
}
@@ -176,8 +176,9 @@
case WE_PAINT: {
bool newstations = (GetNumFSMportsClasses() != 0);
+ //DrawPixelInfo tmp_dpi, *old_dpi;
int y_offset;
- const FSMportsSpec *fsmportspec = newstations ? GetCustomFSMportsSpec(_railstation.fsmports_class, _railstation.station_type) : NULL;
+ const FSMportsSpec *fsmportspec = newstations ? GetCustomFSMportsSpec(_airport.fsmports_class, _airport.station_type) : NULL;
int i; // airport enabling loop
uint32 avail_airports;
@@ -199,31 +200,61 @@
* This should be part of newgrf-airports, i suppose
*/
for (i = 0; i < 9; i++) SetWindowWidgetDisabledState(w, i + 7, !HASBIT(avail_airports, i));
-
airport = GetAirport(_selected_airport_type);
- if (_railstation.newstation_selected) {
- int x = _railstation.platlength;
- int y = _railstation.numtracks;
- if (_railstation.orientation == 0) Swap(x, y);
+ //if (_airport.newstation_selected) {
+ int x = fsmportspec->size_x[_airport.orientation];
+ int y = fsmportspec->size_y[_airport.orientation];
+ //if (_airport.orientation == 0) Swap(x, y);
SetTileSelectSize(x, y);
- } else {
- // select default the coverage area to 'Off' (16)
- SetTileSelectSize(airport->size_x, airport->size_y);
+ for (byte j = 0; j < 4; j++)
+ {
+ 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
}
+
+ byte preview_sprite = 0xFF;
+ for (byte j = 0; j < fsmportspec->numlayouts; j++)
+ {
+ 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);
+ SetWindowWidgetDisabledState(w, 28 + GB((byte)*layout_ptr,1,2), false);
+ if (j == _airport.orientation) {
+ 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
+
_thd.airport = _selected_airport_type;
_thd.airport_template = true;
- int rad = _patches.modified_catchment ? ((_railstation.newstation_selected)? fsmportspec->portFSM->catchment : airport->catchment) : 4;
+ int rad = _patches.modified_catchment ? ((_airport.newstation_selected)? fsmportspec->portFSM->catchment : airport->catchment) : 4;
if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
- SetDParam(0, GetFSMportsClassName(_railstation.fsmports_class));
+ SetDParam(0, GetFSMportsClassName(_airport.fsmports_class));
DrawWindowWidgets(w);
- y_offset = newstations ? 90 : 0;
+ /* Set up a clipping area for the preview */
+ DrawFSMportsTile(9, 106, preview_sprite, _airport.fsmports_class, _airport.station_type);
+
+ //if (FillDrawPixelInfo(&tmp_dpi, 9, 106, 96, 64)) {
+ //old_dpi = _cur_dpi;
+ //_cur_dpi = &tmp_dpi;
+ //if (!DrawStationTile(32, 16, _cur_railtype, AXIS_X, _airport.station_class, _airport.station_type)) {
+ // StationPickerDrawSprite(32, 16, STATION_RAIL, _cur_railtype, INVALID_ROADTYPE, 2);
+ //}
+ //_cur_dpi = old_dpi;
+ //}
+
+ y_offset = newstations ? 170 : 0;
// strings such as 'Size' and 'Coverage Area'
// 'Coverage Area'
@@ -233,17 +264,17 @@
uint16 i;
uint y = 35;
- for (i = w->vscroll.pos; i < _railstation.station_count && i < (uint)(w->vscroll.pos + w->vscroll.cap); i++) {
- const FSMportsSpec *fsmportspec = GetCustomFSMportsSpec(_railstation.fsmports_class, i);
+ for (i = w->vscroll.pos; i < _airport.station_count && i < (uint)(w->vscroll.pos + w->vscroll.cap); i++) {
+ const FSMportsSpec *fsmportspec = GetCustomFSMportsSpec(_airport.fsmports_class, i);
if (fsmportspec != NULL && fsmportspec->name != 0) {
if (HASBIT(fsmportspec->callbackmask, CBM_STATION_AVAIL) && GetFSMportsCallback(CBID_STATION_AVAILABILITY, 0, 0, fsmportspec, NULL, INVALID_TILE) == 0) {
GfxFillRect(8, y - 2, 127, y + 10, (1 << PALETTE_MODIFIER_GREYOUT));
}
- DrawStringTruncated(9, y, fsmportspec->name, i == _railstation.station_type ? 12 : 16, 118);
+ DrawStringTruncated(9, y, fsmportspec->name, i == _airport.station_type ? 12 : 16, 118);
} else {
- DrawStringTruncated(9, y, STR_STAT_CLASS_DFLT, i == _railstation.station_type ? 12 : 16, 118);
+ DrawStringTruncated(9, y, STR_STAT_CLASS_DFLT, i == _airport.station_type ? 12 : 16, 118);
}
y += 14;
@@ -259,7 +290,7 @@
case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15:
RaiseWindowWidget(w, _selected_airport_type + 7);
_selected_airport_type = e->we.click.widget - 7;
- _railstation.newstation_selected = false;
+ if (GetNumFSMportsClasses() == 0) _airport.newstation_selected = false;
LowerWindowWidget(w, _selected_airport_type + 7);
SndPlayFx(SND_15_BEEP);
SetWindowDirty(w);
@@ -273,7 +304,7 @@
break;
case 23:
case 24:
- ShowDropDownMenu(w, BuildFSMportsClassDropdown(), _railstation.fsmports_class, 24, 0, 1 << FSMPORTS_CLASS_WAYP);
+ ShowDropDownMenu(w, BuildFSMportsClassDropdown(), _airport.fsmports_class, 24, 0, 1 << FSMPORTS_CLASS_WAYP);
break;
case 25: {
@@ -282,34 +313,44 @@
if (y >= w->vscroll.cap) return;
y += w->vscroll.pos;
- if (y >= _railstation.station_count) return;
+ if (y >= _airport.station_count) return;
/* Check station availability callback */
- fsmportspec = GetCustomFSMportsSpec(_railstation.fsmports_class, y);
+ fsmportspec = GetCustomFSMportsSpec(_airport.fsmports_class, y);
if (fsmportspec != NULL &&
HASBIT(fsmportspec->callbackmask, CBM_STATION_AVAIL) &&
GetFSMportsCallback(CBID_STATION_AVAILABILITY, 0, 0, fsmportspec, NULL, INVALID_TILE) == 0) return;
- _railstation.station_type = y;
- _railstation.numtracks = fsmportspec->width;
- _railstation.platlength = fsmportspec->lengths;
- _railstation.newstation_selected = true;
+ _airport.station_type = y;
+ _airport.platlength= fsmportspec->size_y[_airport.orientation];
+ _airport.numtracks = fsmportspec->size_x[_airport.orientation];
+ _airport.newstation_selected = true;
SndPlayFx(SND_15_BEEP);
SetWindowDirty(w);
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));
+ SndPlayFx(SND_15_BEEP);
+ SetWindowDirty(w);
+ break;
}
} break;
case WE_DROPDOWN_SELECT: {
- if (_railstation.fsmports_class != e->we.dropdown.index) {
- _railstation.fsmports_class = (FSMportsClassID)e->we.dropdown.index;
- _railstation.station_type = 0;
- _railstation.station_count = GetNumCustomFSMports(_railstation.fsmports_class);
+ if (_airport.fsmports_class != e->we.dropdown.index) {
+ _airport.fsmports_class = (FSMportsClassID)e->we.dropdown.index;
+ _airport.station_type = 0;
+ _airport.station_count = GetNumCustomFSMports(_airport.fsmports_class);
- w->vscroll.count = _railstation.station_count;
- w->vscroll.pos = _railstation.station_type;
+ w->vscroll.count = _airport.station_count;
+ w->vscroll.pos = _airport.station_type;
}
SndPlayFx(SND_15_BEEP);
@@ -362,33 +403,40 @@
static const Widget _newports_build_airport_picker_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 147, 0, 13, STR_3001_AIRPORT_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 14, 142, 0x0, STR_NULL},
-{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 143, 179, 0x0, STR_NULL},
-{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 180, 217, 0x0, STR_NULL},
-{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 218, 267, 0x0, STR_NULL},
-{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 268, 329, 0x0, STR_NULL},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 117, 128, STR_SMALL_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 155, 166, STR_CITY_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 231, 242, STR_HELIPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 167, 178, STR_METRO_AIRPORT , STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 193, 204, STR_INTERNATIONAL_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 129, 140, STR_COMMUTER_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 255, 266, STR_HELIDEPOT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 205, 216, STR_INTERCONTINENTAL_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 243, 254, STR_HELISTATION, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 14, 73, 281, 292, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE},
-{ WWT_TEXTBTN, RESIZE_NONE, 14, 74, 133, 281, 292, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA},
-{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 104, 117, STR_SMALL_AIRPORTS, STR_NULL},
-{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 142, 155, STR_LARGE_AIRPORTS, STR_NULL},
-{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 180, 193, STR_HUB_AIRPORTS, STR_NULL},
-{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 218, 231, STR_HELIPORTS, STR_NULL},
-{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 268, 281, STR_3066_COVERAGE_AREA_HIGHLIGHT, STR_NULL},
+{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 14, 222, 0x0, STR_NULL},
+{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 223, 259, 0x0, STR_NULL},
+{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 260, 297, 0x0, STR_NULL},
+{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 298, 347, 0x0, STR_NULL},
+{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 348, 409, 0x0, STR_NULL},
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 197, 208, STR_SMALL_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 235, 246, STR_CITY_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 311, 322, STR_HELIPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 247, 258, STR_METRO_AIRPORT , STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 273, 284, STR_INTERNATIONAL_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 209, 220, STR_COMMUTER_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 335, 346, STR_HELIDEPOT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 285, 296, STR_INTERCONTINENTAL_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 323, 334, STR_HELISTATION, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 14, 73, 361, 372, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE},
+{ WWT_TEXTBTN, RESIZE_NONE, 14, 74, 133, 361, 372, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA},
+{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 184, 197, STR_SMALL_AIRPORTS, STR_NULL},
+{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 222, 235, STR_LARGE_AIRPORTS, STR_NULL},
+{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 260, 273, STR_HUB_AIRPORTS, STR_NULL},
+{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 298, 311, STR_HELIPORTS, STR_NULL},
+{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 348, 361, STR_3066_COVERAGE_AREA_HIGHLIGHT, STR_NULL},
/* newstations gui additions */
//TODO: modify for airport specific texts
{ WWT_INSET, RESIZE_NONE, 14, 7, 140, 17, 28, STR_02BD, STR_SELECT_STATION_CLASS_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 129, 139, 18, 27, STR_0225, STR_SELECT_STATION_CLASS_TIP},
{ WWT_MATRIX, RESIZE_NONE, 14, 7, 128, 32, 102, 0x501, STR_SELECT_STATION_TYPE_TIP},
{ WWT_SCROLLBAR, RESIZE_NONE, 14, 129, 140, 32, 102, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
+{ WWT_INSET, RESIZE_NONE, 7, 7, 107, 104, 172, 0x0, STR_NULL},
+{ WWT_IMGBTN, RESIZE_NONE, 14, 109, 140, 104, 119, SPR_IMG_ARROW_NE_WHITE, STR_NULL},
+{ WWT_IMGBTN, RESIZE_NONE, 14, 109, 140, 120, 135, SPR_IMG_ARROW_SE_WHITE, STR_NULL},
+{ WWT_IMGBTN, RESIZE_NONE, 14, 109, 140, 136, 151, SPR_IMG_ARROW_SW_WHITE, STR_NULL},
+{ WWT_IMGBTN, RESIZE_NONE, 14, 109, 140, 152, 167, SPR_IMG_ARROW_NW_WHITE, STR_NULL},
+
+
{ WIDGETS_END},
};
@@ -401,7 +449,7 @@
};
static const WindowDesc _newports_build_airport_desc = {
- WDP_AUTO, WDP_AUTO, 148, 330, 148, 330,
+ WDP_AUTO, WDP_AUTO, 148, 410, 148, 410,
WC_BUILD_STATION, WC_BUILD_TOOLBAR,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_newports_build_airport_picker_widgets,
@@ -413,16 +461,19 @@
Window *w;
if (GetNumFSMportsClasses() == 0) {
w = AllocateWindowDesc(&_build_airport_desc);
- _railstation.newstations = false;
+ _airport.station_type = 0;
+ _airport.newstations = false;
} else
{
w = AllocateWindowDesc(&_newports_build_airport_desc);
- _railstation.newstations = true;
- _railstation.station_count = GetNumCustomFSMports(_railstation.fsmports_class);
+ _airport.station_type = 0;
+ _airport.newstation_selected = true;
+ _airport.newstations = true;
+ _airport.station_count = GetNumCustomFSMports(_airport.fsmports_class);
- w->vscroll.count = _railstation.station_count;
+ w->vscroll.count = _airport.station_count;
w->vscroll.cap = 5;
- w->vscroll.pos = clamp(_railstation.station_type - 2, 0, w->vscroll.count - w->vscroll.cap);
+ w->vscroll.pos = clamp(_airport.station_type - 2, 0, w->vscroll.count - w->vscroll.cap);
}
}