1
0
Fork 0

(svn r13134) -Codechange: make a class of the Airport Picker Window.

release/0.7
belugas 2008-05-17 03:31:22 +00:00
parent 17bd325574
commit 27c3d210c4
1 changed files with 95 additions and 94 deletions

View File

@ -138,6 +138,8 @@ void ShowBuildAirToolbar()
if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w); if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w);
} }
class AirportPickerWindow : public PickerWindowBase {
enum { enum {
BAW_BOTTOMPANEL = 10, BAW_BOTTOMPANEL = 10,
BAW_SMALL_AIRPORT, BAW_SMALL_AIRPORT,
@ -155,26 +157,29 @@ enum {
BAW_BTN_DOHILIGHT, BAW_BTN_DOHILIGHT,
}; };
static void BuildAirportPickerWndProc(Window *w, WindowEvent *e) public:
{
switch (e->event) {
case WE_CREATE:
w->SetWidgetLoweredState(BAW_BTN_DONTHILIGHT, !_station_show_coverage);
w->SetWidgetLoweredState(BAW_BTN_DOHILIGHT, _station_show_coverage);
w->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
break;
case WE_PAINT: { AirportPickerWindow(const WindowDesc *desc) : PickerWindowBase(desc)
{
this->SetWidgetLoweredState(BAW_BTN_DONTHILIGHT, !_station_show_coverage);
this->SetWidgetLoweredState(BAW_BTN_DOHILIGHT, _station_show_coverage);
this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
this->FindWindowPlacementAndResize(desc);
}
virtual void OnPaint()
{
int i; // airport enabling loop int i; // airport enabling loop
uint32 avail_airports; uint32 avail_airports;
const AirportFTAClass *airport; const AirportFTAClass *airport;
avail_airports = GetValidAirports(); avail_airports = GetValidAirports();
w->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT); this->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
if (!HasBit(avail_airports, 0) && _selected_airport_type == AT_SMALL) _selected_airport_type = AT_LARGE; if (!HasBit(avail_airports, 0) && _selected_airport_type == AT_SMALL) _selected_airport_type = AT_LARGE;
if (!HasBit(avail_airports, 1) && _selected_airport_type == AT_LARGE) _selected_airport_type = AT_SMALL; if (!HasBit(avail_airports, 1) && _selected_airport_type == AT_LARGE) _selected_airport_type = AT_SMALL;
w->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT); this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
/* 'Country Airport' starts at widget BAW_SMALL_AIRPORT, and if its bit is set, it is /* 'Country Airport' starts at widget BAW_SMALL_AIRPORT, and if its bit is set, it is
* available, so take its opposite value to set the disabled state. * available, so take its opposite value to set the disabled state.
@ -182,7 +187,7 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
* XXX TODO : all airports should be held in arrays, with all relevant data. * XXX TODO : all airports should be held in arrays, with all relevant data.
* This should be part of newgrf-airports, i suppose * This should be part of newgrf-airports, i suppose
*/ */
for (i = 0; i < BAW_AIRPORT_COUNT; i++) w->SetWidgetDisabledState(i + BAW_SMALL_AIRPORT, !HasBit(avail_airports, i)); for (i = 0; i < BAW_AIRPORT_COUNT; i++) this->SetWidgetDisabledState(i + BAW_SMALL_AIRPORT, !HasBit(avail_airports, i));
/* select default the coverage area to 'Off' (16) */ /* select default the coverage area to 'Off' (16) */
airport = GetAirport(_selected_airport_type); airport = GetAirport(_selected_airport_type);
@ -192,49 +197,45 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
DrawWindowWidgets(w); DrawWindowWidgets(this);
/* strings such as 'Size' and 'Coverage Area' */ /* strings such as 'Size' and 'Coverage Area' */
int text_end = DrawStationCoverageAreaText(2, 206, SCT_ALL, rad, false); int text_end = DrawStationCoverageAreaText(2, 206, SCT_ALL, rad, false);
text_end = DrawStationCoverageAreaText(2, text_end + 4, SCT_ALL, rad, true) + 4; text_end = DrawStationCoverageAreaText(2, text_end + 4, SCT_ALL, rad, true) + 4;
if (text_end != w->widget[BAW_BOTTOMPANEL].bottom) { if (text_end != this->widget[BAW_BOTTOMPANEL].bottom) {
w->SetDirty(); this->SetDirty();
ResizeWindowForWidget(w, BAW_BOTTOMPANEL, 0, text_end - w->widget[BAW_BOTTOMPANEL].bottom); ResizeWindowForWidget(this, BAW_BOTTOMPANEL, 0, text_end - this->widget[BAW_BOTTOMPANEL].bottom);
w->SetDirty(); this->SetDirty();
} }
break;
} }
case WE_CLICK: { virtual void OnClick(Point pt, int widget)
switch (e->we.click.widget) { {
switch (widget) {
case BAW_SMALL_AIRPORT: case BAW_CITY_AIRPORT: case BAW_HELIPORT: case BAW_METRO_AIRPORT: case BAW_SMALL_AIRPORT: case BAW_CITY_AIRPORT: case BAW_HELIPORT: case BAW_METRO_AIRPORT:
case BAW_STR_INTERNATIONAL_AIRPORT: case BAW_COMMUTER_AIRPORT: case BAW_HELIDEPOT: case BAW_STR_INTERNATIONAL_AIRPORT: case BAW_COMMUTER_AIRPORT: case BAW_HELIDEPOT:
case BAW_STR_INTERCONTINENTAL_AIRPORT: case BAW_HELISTATION: case BAW_STR_INTERCONTINENTAL_AIRPORT: case BAW_HELISTATION:
w->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT); this->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
_selected_airport_type = e->we.click.widget - BAW_SMALL_AIRPORT; _selected_airport_type = widget - BAW_SMALL_AIRPORT;
w->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT); this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
w->SetDirty(); this->SetDirty();
break; break;
case BAW_BTN_DONTHILIGHT: case BAW_BTN_DOHILIGHT: case BAW_BTN_DONTHILIGHT: case BAW_BTN_DOHILIGHT:
_station_show_coverage = (e->we.click.widget != BAW_BTN_DONTHILIGHT); _station_show_coverage = (widget != BAW_BTN_DONTHILIGHT);
w->SetWidgetLoweredState(BAW_BTN_DONTHILIGHT, !_station_show_coverage); this->SetWidgetLoweredState(BAW_BTN_DONTHILIGHT, !_station_show_coverage);
w->SetWidgetLoweredState(BAW_BTN_DOHILIGHT, _station_show_coverage); this->SetWidgetLoweredState(BAW_BTN_DOHILIGHT, _station_show_coverage);
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
w->SetDirty(); this->SetDirty();
break; break;
} }
} break; }
case WE_TICK: virtual void OnTick()
CheckRedrawStationCoverage(w); {
break; CheckRedrawStationCoverage(this);
case WE_DESTROY:
ResetObjectToPlace();
break;
}
} }
};
static const Widget _build_airport_picker_widgets[] = { static const Widget _build_airport_picker_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
@ -268,12 +269,12 @@ static const WindowDesc _build_airport_desc = {
WC_BUILD_STATION, WC_BUILD_TOOLBAR, WC_BUILD_STATION, WC_BUILD_TOOLBAR,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_airport_picker_widgets, _build_airport_picker_widgets,
BuildAirportPickerWndProc NULL
}; };
static void ShowBuildAirportPicker() static void ShowBuildAirportPicker()
{ {
new Window(&_build_airport_desc); new AirportPickerWindow(&_build_airport_desc);
} }
void InitializeAirportGui() void InitializeAirportGui()