(svn r13142) -Codechange: make classes of the Build[RailDepot|RailStation|RailWaypoint|Signal]Window

This commit is contained in:
glx 2008-05-17 16:27:36 +00:00
parent 7812b24a77
commit fdcb4e6402
1 changed files with 397 additions and 398 deletions

View File

@ -756,6 +756,31 @@ void ShowBuildRailToolbar(RailType railtype, int button)
if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w); if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w);
} }
/* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
* --pasky */
static void HandleStationPlacement(TileIndex start, TileIndex end)
{
uint sx = TileX(start);
uint sy = TileY(start);
uint ex = TileX(end);
uint ey = TileY(end);
uint w,h;
if (sx > ex) Swap(sx, ex);
if (sy > ey) Swap(sy, ey);
w = ex - sx + 1;
h = ey - sy + 1;
if (!_railstation.orientation) Swap(w, h);
DoCommandP(TileXY(sx, sy),
_railstation.orientation | (w << 8) | (h << 16) | (_ctrl_pressed << 24),
_cur_railtype | (_railstation.station_class << 8) | (_railstation.station_type << 16), CcStation,
CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
}
struct BuildRailStationWindow : public PickerWindowBase {
private:
/** Enum referring to the widgets of the rail stations window */ /** Enum referring to the widgets of the rail stations window */
enum BuildRailStationWidgets { enum BuildRailStationWidgets {
BRSW_CLOSEBOX = 0, BRSW_CLOSEBOX = 0,
@ -793,50 +818,27 @@ enum BuildRailStationWidgets {
BRSW_NEWST_SCROLL BRSW_NEWST_SCROLL
}; };
/* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
* --pasky */
static void HandleStationPlacement(TileIndex start, TileIndex end)
{
uint sx = TileX(start);
uint sy = TileY(start);
uint ex = TileX(end);
uint ey = TileY(end);
uint w,h;
if (sx > ex) Swap(sx, ex);
if (sy > ey) Swap(sy, ey);
w = ex - sx + 1;
h = ey - sy + 1;
if (!_railstation.orientation) Swap(w, h);
DoCommandP(TileXY(sx, sy),
_railstation.orientation | (w << 8) | (h << 16) | (_ctrl_pressed << 24),
_cur_railtype | (_railstation.station_class << 8) | (_railstation.station_type << 16), CcStation,
CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
}
/* Check if the currently selected station size is allowed */ /* Check if the currently selected station size is allowed */
static void CheckSelectedSize(Window *w, const StationSpec *statspec) void CheckSelectedSize(const StationSpec *statspec)
{ {
if (statspec == NULL || _railstation.dragdrop) return; if (statspec == NULL || _railstation.dragdrop) return;
if (HasBit(statspec->disallowed_platforms, _railstation.numtracks - 1)) { if (HasBit(statspec->disallowed_platforms, _railstation.numtracks - 1)) {
w->RaiseWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN); this->RaiseWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN);
_railstation.numtracks = 1; _railstation.numtracks = 1;
while (HasBit(statspec->disallowed_platforms, _railstation.numtracks - 1)) { while (HasBit(statspec->disallowed_platforms, _railstation.numtracks - 1)) {
_railstation.numtracks++; _railstation.numtracks++;
} }
w->LowerWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN); this->LowerWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN);
} }
if (HasBit(statspec->disallowed_lengths, _railstation.platlength - 1)) { if (HasBit(statspec->disallowed_lengths, _railstation.platlength - 1)) {
w->RaiseWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN); this->RaiseWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN);
_railstation.platlength = 1; _railstation.platlength = 1;
while (HasBit(statspec->disallowed_lengths, _railstation.platlength - 1)) { while (HasBit(statspec->disallowed_lengths, _railstation.platlength - 1)) {
_railstation.platlength++; _railstation.platlength++;
} }
w->LowerWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN); this->LowerWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN);
} }
} }
@ -852,22 +854,34 @@ static DropDownList *BuildStationClassDropDown()
return list; return list;
} }
static void StationBuildWndProc(Window *w, WindowEvent *e) public:
BuildRailStationWindow(const WindowDesc *desc, bool newstation) : PickerWindowBase(desc)
{ {
switch (e->event) { this->LowerWidget(_railstation.orientation + BRSW_PLATFORM_DIR_X);
case WE_CREATE:
w->LowerWidget(_railstation.orientation + BRSW_PLATFORM_DIR_X);
if (_railstation.dragdrop) { if (_railstation.dragdrop) {
w->LowerWidget(BRSW_PLATFORM_DRAG_N_DROP); this->LowerWidget(BRSW_PLATFORM_DRAG_N_DROP);
} else { } else {
w->LowerWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN); this->LowerWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN);
w->LowerWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN); this->LowerWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN);
} }
w->SetWidgetLoweredState(BRSW_HIGHLIGHT_OFF, !_station_show_coverage); this->SetWidgetLoweredState(BRSW_HIGHLIGHT_OFF, !_station_show_coverage);
w->SetWidgetLoweredState(BRSW_HIGHLIGHT_ON, _station_show_coverage); this->SetWidgetLoweredState(BRSW_HIGHLIGHT_ON, _station_show_coverage);
break;
case WE_PAINT: { this->FindWindowPlacementAndResize(desc);
_railstation.newstations = newstation;
if (newstation) {
_railstation.station_count = GetNumCustomStations(_railstation.station_class);
this->vscroll.count = _railstation.station_count;
this->vscroll.cap = 5;
this->vscroll.pos = Clamp(_railstation.station_type - 2, 0, this->vscroll.count - this->vscroll.cap);
}
}
virtual void OnPaint()
{
bool newstations = _railstation.newstations; bool newstations = _railstation.newstations;
DrawPixelInfo tmp_dpi, *old_dpi; DrawPixelInfo tmp_dpi, *old_dpi;
const StationSpec *statspec = newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL; const StationSpec *statspec = newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL;
@ -890,16 +904,16 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
for (uint bits = 0; bits < 7; bits++) { for (uint bits = 0; bits < 7; bits++) {
bool disable = bits >= _patches.station_spread; bool disable = bits >= _patches.station_spread;
if (statspec == NULL) { if (statspec == NULL) {
w->SetWidgetDisabledState(bits + BRSW_PLATFORM_NUM_1, disable); this->SetWidgetDisabledState(bits + BRSW_PLATFORM_NUM_1, disable);
w->SetWidgetDisabledState(bits + BRSW_PLATFORM_LEN_1, disable); this->SetWidgetDisabledState(bits + BRSW_PLATFORM_LEN_1, disable);
} else { } else {
w->SetWidgetDisabledState(bits + BRSW_PLATFORM_NUM_1, HasBit(statspec->disallowed_platforms, bits) || disable); this->SetWidgetDisabledState(bits + BRSW_PLATFORM_NUM_1, HasBit(statspec->disallowed_platforms, bits) || disable);
w->SetWidgetDisabledState(bits + BRSW_PLATFORM_LEN_1, HasBit(statspec->disallowed_lengths, bits) || disable); this->SetWidgetDisabledState(bits + BRSW_PLATFORM_LEN_1, HasBit(statspec->disallowed_lengths, bits) || disable);
} }
} }
SetDParam(0, GetStationClassName(_railstation.station_class)); SetDParam(0, GetStationClassName(_railstation.station_class));
w->DrawWidgets(); this->DrawWidgets();
int y_offset = newstations ? 90 : 0; int y_offset = newstations ? 90 : 0;
@ -930,16 +944,16 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
int text_end = DrawStationCoverageAreaText(2, 166 + y_offset, SCT_ALL, rad, false); int text_end = DrawStationCoverageAreaText(2, 166 + y_offset, 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[BRSW_BACKGROUND].bottom) { if (text_end != this->widget[BRSW_BACKGROUND].bottom) {
w->SetDirty(); this->SetDirty();
ResizeWindowForWidget(w, BRSW_BACKGROUND, 0, text_end - w->widget[BRSW_BACKGROUND].bottom); ResizeWindowForWidget(this, BRSW_BACKGROUND, 0, text_end - this->widget[BRSW_BACKGROUND].bottom);
w->SetDirty(); this->SetDirty();
} }
if (newstations) { if (newstations) {
uint y = 35; uint y = 35;
for (uint16 i = w->vscroll.pos; i < _railstation.station_count && i < (uint)(w->vscroll.pos + w->vscroll.cap); i++) { for (uint16 i = this->vscroll.pos; i < _railstation.station_count && i < (uint)(this->vscroll.pos + this->vscroll.cap); i++) {
const StationSpec *statspec = GetCustomStationSpec(_railstation.station_class, i); const StationSpec *statspec = GetCustomStationSpec(_railstation.station_class, i);
if (statspec != NULL && statspec->name != 0) { if (statspec != NULL && statspec->name != 0) {
@ -955,17 +969,18 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
y += 14; y += 14;
} }
} }
} break; }
case WE_CLICK: { virtual void OnClick(Point pt, int widget)
switch (e->we.click.widget) { {
switch (widget) {
case BRSW_PLATFORM_DIR_X: case BRSW_PLATFORM_DIR_X:
case BRSW_PLATFORM_DIR_Y: case BRSW_PLATFORM_DIR_Y:
w->RaiseWidget(_railstation.orientation + BRSW_PLATFORM_DIR_X); this->RaiseWidget(_railstation.orientation + BRSW_PLATFORM_DIR_X);
_railstation.orientation = e->we.click.widget - BRSW_PLATFORM_DIR_X; _railstation.orientation = widget - BRSW_PLATFORM_DIR_X;
w->LowerWidget(_railstation.orientation + BRSW_PLATFORM_DIR_X); this->LowerWidget(_railstation.orientation + BRSW_PLATFORM_DIR_X);
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
w->SetDirty(); this->SetDirty();
break; break;
case BRSW_PLATFORM_NUM_1: case BRSW_PLATFORM_NUM_1:
@ -975,10 +990,10 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
case BRSW_PLATFORM_NUM_5: case BRSW_PLATFORM_NUM_5:
case BRSW_PLATFORM_NUM_6: case BRSW_PLATFORM_NUM_6:
case BRSW_PLATFORM_NUM_7: { case BRSW_PLATFORM_NUM_7: {
w->RaiseWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN); this->RaiseWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN);
w->RaiseWidget(BRSW_PLATFORM_DRAG_N_DROP); this->RaiseWidget(BRSW_PLATFORM_DRAG_N_DROP);
_railstation.numtracks = e->we.click.widget - BRSW_PLATFORM_NUM_BEGIN; _railstation.numtracks = widget - BRSW_PLATFORM_NUM_BEGIN;
_railstation.dragdrop = false; _railstation.dragdrop = false;
const StationSpec *statspec = _railstation.newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL; const StationSpec *statspec = _railstation.newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL;
@ -986,17 +1001,17 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
/* The previously selected number of platforms in invalid */ /* The previously selected number of platforms in invalid */
for (uint i = 0; i < 7; i++) { for (uint i = 0; i < 7; i++) {
if (!HasBit(statspec->disallowed_lengths, i)) { if (!HasBit(statspec->disallowed_lengths, i)) {
w->RaiseWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN); this->RaiseWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN);
_railstation.platlength = i + 1; _railstation.platlength = i + 1;
break; break;
} }
} }
} }
w->LowerWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN); this->LowerWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN);
w->LowerWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN); this->LowerWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN);
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
w->SetDirty(); this->SetDirty();
break; break;
} }
@ -1007,10 +1022,10 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
case BRSW_PLATFORM_LEN_5: case BRSW_PLATFORM_LEN_5:
case BRSW_PLATFORM_LEN_6: case BRSW_PLATFORM_LEN_6:
case BRSW_PLATFORM_LEN_7: { case BRSW_PLATFORM_LEN_7: {
w->RaiseWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN); this->RaiseWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN);
w->RaiseWidget(BRSW_PLATFORM_DRAG_N_DROP); this->RaiseWidget(BRSW_PLATFORM_DRAG_N_DROP);
_railstation.platlength = e->we.click.widget - BRSW_PLATFORM_LEN_BEGIN; _railstation.platlength = widget - BRSW_PLATFORM_LEN_BEGIN;
_railstation.dragdrop = false; _railstation.dragdrop = false;
const StationSpec *statspec = _railstation.newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL; const StationSpec *statspec = _railstation.newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL;
@ -1018,30 +1033,30 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
/* The previously selected number of tracks in invalid */ /* The previously selected number of tracks in invalid */
for (uint i = 0; i < 7; i++) { for (uint i = 0; i < 7; i++) {
if (!HasBit(statspec->disallowed_platforms, i)) { if (!HasBit(statspec->disallowed_platforms, i)) {
w->RaiseWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN); this->RaiseWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN);
_railstation.numtracks = i + 1; _railstation.numtracks = i + 1;
break; break;
} }
} }
} }
w->LowerWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN); this->LowerWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN);
w->LowerWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN); this->LowerWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN);
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
w->SetDirty(); this->SetDirty();
break; break;
} }
case BRSW_PLATFORM_DRAG_N_DROP: { case BRSW_PLATFORM_DRAG_N_DROP: {
_railstation.dragdrop ^= true; _railstation.dragdrop ^= true;
w->ToggleWidgetLoweredState(BRSW_PLATFORM_DRAG_N_DROP); this->ToggleWidgetLoweredState(BRSW_PLATFORM_DRAG_N_DROP);
/* get the first allowed length/number of platforms */ /* get the first allowed length/number of platforms */
const StationSpec *statspec = _railstation.newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL; const StationSpec *statspec = _railstation.newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL;
if (statspec != NULL && HasBit(statspec->disallowed_lengths, _railstation.platlength - 1)) { if (statspec != NULL && HasBit(statspec->disallowed_lengths, _railstation.platlength - 1)) {
for (uint i = 0; i < 7; i++) { for (uint i = 0; i < 7; i++) {
if (!HasBit(statspec->disallowed_lengths, i)) { if (!HasBit(statspec->disallowed_lengths, i)) {
w->RaiseWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN); this->RaiseWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN);
_railstation.platlength = i + 1; _railstation.platlength = i + 1;
break; break;
} }
@ -1050,38 +1065,38 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
if (statspec != NULL && HasBit(statspec->disallowed_platforms, _railstation.numtracks - 1)) { if (statspec != NULL && HasBit(statspec->disallowed_platforms, _railstation.numtracks - 1)) {
for (uint i = 0; i < 7; i++) { for (uint i = 0; i < 7; i++) {
if (!HasBit(statspec->disallowed_platforms, i)) { if (!HasBit(statspec->disallowed_platforms, i)) {
w->RaiseWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN); this->RaiseWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN);
_railstation.numtracks = i + 1; _railstation.numtracks = i + 1;
break; break;
} }
} }
} }
w->SetWidgetLoweredState(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN, !_railstation.dragdrop); this->SetWidgetLoweredState(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN, !_railstation.dragdrop);
w->SetWidgetLoweredState(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN, !_railstation.dragdrop); this->SetWidgetLoweredState(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN, !_railstation.dragdrop);
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
w->SetDirty(); this->SetDirty();
} break; } break;
case BRSW_HIGHLIGHT_OFF: case BRSW_HIGHLIGHT_OFF:
case BRSW_HIGHLIGHT_ON: case BRSW_HIGHLIGHT_ON:
_station_show_coverage = (e->we.click.widget != BRSW_HIGHLIGHT_OFF); _station_show_coverage = (widget != BRSW_HIGHLIGHT_OFF);
w->SetWidgetLoweredState(BRSW_HIGHLIGHT_OFF, !_station_show_coverage); this->SetWidgetLoweredState(BRSW_HIGHLIGHT_OFF, !_station_show_coverage);
w->SetWidgetLoweredState(BRSW_HIGHLIGHT_ON, _station_show_coverage); this->SetWidgetLoweredState(BRSW_HIGHLIGHT_ON, _station_show_coverage);
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
w->SetDirty(); this->SetDirty();
break; break;
case BRSW_NEWST_DROPDOWN: case BRSW_NEWST_DROPDOWN:
ShowDropDownList(w, BuildStationClassDropDown(), _railstation.station_class, BRSW_NEWST_DROPDOWN); ShowDropDownList(this, BuildStationClassDropDown(), _railstation.station_class, BRSW_NEWST_DROPDOWN);
break; break;
case BRSW_NEWST_LIST: { case BRSW_NEWST_LIST: {
const StationSpec *statspec; const StationSpec *statspec;
int y = (e->we.click.pt.y - 32) / 14; int y = (pt.y - 32) / 14;
if (y >= w->vscroll.cap) return; if (y >= this->vscroll.cap) return;
y += w->vscroll.pos; y += this->vscroll.pos;
if (y >= _railstation.station_count) return; if (y >= _railstation.station_count) return;
/* Check station availability callback */ /* Check station availability callback */
@ -1092,40 +1107,37 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
_railstation.station_type = y; _railstation.station_type = y;
CheckSelectedSize(w, statspec); this->CheckSelectedSize(statspec);
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
w->SetDirty(); this->SetDirty();
break; break;
} }
} }
} break; }
case WE_DROPDOWN_SELECT: virtual void OnDropdownSelect(int widget, int index)
if (_railstation.station_class != e->we.dropdown.index) { {
_railstation.station_class = (StationClassID)e->we.dropdown.index; if (_railstation.station_class != index) {
_railstation.station_class = (StationClassID)index;
_railstation.station_type = 0; _railstation.station_type = 0;
_railstation.station_count = GetNumCustomStations(_railstation.station_class); _railstation.station_count = GetNumCustomStations(_railstation.station_class);
CheckSelectedSize(w, GetCustomStationSpec(_railstation.station_class, _railstation.station_type)); this->CheckSelectedSize(GetCustomStationSpec(_railstation.station_class, _railstation.station_type));
w->vscroll.count = _railstation.station_count; this->vscroll.count = _railstation.station_count;
w->vscroll.pos = _railstation.station_type; this->vscroll.pos = _railstation.station_type;
} }
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
w->SetDirty(); this->SetDirty();
break;
case WE_TICK:
CheckRedrawStationCoverage(w);
break;
case WE_DESTROY:
ResetObjectToPlace();
break;
} }
virtual void OnTick()
{
CheckRedrawStationCoverage(this);
} }
};
/** Widget definition of the standard build rail station window */ /** Widget definition of the standard build rail station window */
static const Widget _station_builder_widgets[] = { static const Widget _station_builder_widgets[] = {
@ -1197,7 +1209,7 @@ static const WindowDesc _station_builder_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,
_station_builder_widgets, _station_builder_widgets,
StationBuildWndProc NULL
}; };
static const WindowDesc _newstation_builder_desc = { static const WindowDesc _newstation_builder_desc = {
@ -1205,23 +1217,15 @@ static const WindowDesc _newstation_builder_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,
_newstation_builder_widgets, _newstation_builder_widgets,
StationBuildWndProc NULL
}; };
static void ShowStationBuilder() static void ShowStationBuilder()
{ {
Window *w;
if (GetNumStationClasses() <= 2 && GetNumCustomStations(STAT_CLASS_DFLT) == 1) { if (GetNumStationClasses() <= 2 && GetNumCustomStations(STAT_CLASS_DFLT) == 1) {
w = new Window(&_station_builder_desc); new BuildRailStationWindow(&_station_builder_desc, false);
_railstation.newstations = false;
} else { } else {
w = new Window(&_newstation_builder_desc); new BuildRailStationWindow(&_newstation_builder_desc, true);
_railstation.newstations = true;
_railstation.station_count = GetNumCustomStations(_railstation.station_class);
w->vscroll.count = _railstation.station_count;
w->vscroll.cap = 5;
w->vscroll.pos = Clamp(_railstation.station_type - 2, 0, w->vscroll.count - w->vscroll.cap);
} }
} }
@ -1243,61 +1247,61 @@ enum BuildSignalWidgets {
BSW_DRAG_SIGNALS_DENSITY_INCREASE, BSW_DRAG_SIGNALS_DENSITY_INCREASE,
}; };
struct BuildSignalWindow : public PickerWindowBase {
private:
/** /**
* Draw dynamic a signal-sprite in a button in the signal GUI * Draw dynamic a signal-sprite in a button in the signal GUI
* Draw the sprite +1px to the right and down if the button is lowered and change the sprite to sprite + 1 (red to green light) * Draw the sprite +1px to the right and down if the button is lowered and change the sprite to sprite + 1 (red to green light)
* *
* @param w Window on which the widget is located
* @param widget_index index of this widget in the window * @param widget_index index of this widget in the window
* @param image the sprite to draw * @param image the sprite to draw
* @param xrel the relativ x value of the sprite in the grf * @param xrel the relativ x value of the sprite in the grf
* @param xsize the width of the sprite * @param xsize the width of the sprite
*/ */
static void DrawSignalSprite(const Window *w, byte widget_index, SpriteID image, int8 xrel, uint8 xsize) void DrawSignalSprite(byte widget_index, SpriteID image, int8 xrel, uint8 xsize)
{ {
DrawSprite(image + w->IsWidgetLowered(widget_index), PAL_NONE, DrawSprite(image + this->IsWidgetLowered(widget_index), PAL_NONE,
w->widget[widget_index].left + (w->widget[widget_index].right - w->widget[widget_index].left) / 2 - xrel - xsize / 2 + this->widget[widget_index].left + (this->widget[widget_index].right - this->widget[widget_index].left) / 2 - xrel - xsize / 2 +
w->IsWidgetLowered(widget_index), w->widget[widget_index].bottom - 3 + w->IsWidgetLowered(widget_index)); this->IsWidgetLowered(widget_index), this->widget[widget_index].bottom - 3 + this->IsWidgetLowered(widget_index));
} }
/** public:
* Signal selection window event definition BuildSignalWindow(const WindowDesc *desc) : PickerWindowBase(desc)
*
* @param w window pointer
* @param e event been triggered
*/
static void SignalBuildWndProc(Window *w, WindowEvent *e)
{ {
switch (e->event) { this->FindWindowPlacementAndResize(desc);
case WE_PAINT: };
w->LowerWidget((_cur_signal_variant == SIG_ELECTRIC ? BSW_ELECTRIC_NORM : BSW_SEMAPHORE_NORM) + _cur_signal_type);
w->SetWidgetLoweredState(BSW_CONVERT, _convert_signal_button); virtual void OnPaint()
{
this->LowerWidget((_cur_signal_variant == SIG_ELECTRIC ? BSW_ELECTRIC_NORM : BSW_SEMAPHORE_NORM) + _cur_signal_type);
w->SetWidgetDisabledState(BSW_DRAG_SIGNALS_DENSITY_DECREASE, _patches.drag_signals_density == 1); this->SetWidgetLoweredState(BSW_CONVERT, _convert_signal_button);
w->SetWidgetDisabledState(BSW_DRAG_SIGNALS_DENSITY_INCREASE, _patches.drag_signals_density == 20);
w->DrawWidgets(); this->SetWidgetDisabledState(BSW_DRAG_SIGNALS_DENSITY_DECREASE, _patches.drag_signals_density == 1);
this->SetWidgetDisabledState(BSW_DRAG_SIGNALS_DENSITY_INCREASE, _patches.drag_signals_density == 20);
this->DrawWidgets();
/* The 'hardcoded' off sets are needed because they are reused sprites. */ /* The 'hardcoded' off sets are needed because they are reused sprites. */
DrawSignalSprite(w, BSW_SEMAPHORE_NORM, SPR_IMG_SIGNAL_SEMAPHORE_NORM, 0, 12); // xsize of sprite + 1 == 9 this->DrawSignalSprite(BSW_SEMAPHORE_NORM, SPR_IMG_SIGNAL_SEMAPHORE_NORM, 0, 12); // xsize of sprite + 1 == 9
DrawSignalSprite(w, BSW_SEMAPHORE_ENTRY, SPR_IMG_SIGNAL_SEMAPHORE_ENTRY, -1, 13); // xsize of sprite + 1 == 10 this->DrawSignalSprite(BSW_SEMAPHORE_ENTRY, SPR_IMG_SIGNAL_SEMAPHORE_ENTRY, -1, 13); // xsize of sprite + 1 == 10
DrawSignalSprite(w, BSW_SEMAPHORE_EXIT, SPR_IMG_SIGNAL_SEMAPHORE_EXIT, 0, 12); // xsize of sprite + 1 == 9 this->DrawSignalSprite(BSW_SEMAPHORE_EXIT, SPR_IMG_SIGNAL_SEMAPHORE_EXIT, 0, 12); // xsize of sprite + 1 == 9
DrawSignalSprite(w, BSW_SEMAPHORE_COMBO, SPR_IMG_SIGNAL_SEMAPHORE_COMBO, 0, 12); // xsize of sprite + 1 == 9 this->DrawSignalSprite(BSW_SEMAPHORE_COMBO, SPR_IMG_SIGNAL_SEMAPHORE_COMBO, 0, 12); // xsize of sprite + 1 == 9
DrawSignalSprite(w, BSW_ELECTRIC_NORM, SPR_IMG_SIGNAL_ELECTRIC_NORM, -1, 4); this->DrawSignalSprite(BSW_ELECTRIC_NORM, SPR_IMG_SIGNAL_ELECTRIC_NORM, -1, 4);
DrawSignalSprite(w, BSW_ELECTRIC_ENTRY, SPR_IMG_SIGNAL_ELECTRIC_ENTRY, -2, 6); this->DrawSignalSprite(BSW_ELECTRIC_ENTRY, SPR_IMG_SIGNAL_ELECTRIC_ENTRY, -2, 6);
DrawSignalSprite(w, BSW_ELECTRIC_EXIT, SPR_IMG_SIGNAL_ELECTRIC_EXIT, -2, 6); this->DrawSignalSprite(BSW_ELECTRIC_EXIT, SPR_IMG_SIGNAL_ELECTRIC_EXIT, -2, 6);
DrawSignalSprite(w, BSW_ELECTRIC_COMBO, SPR_IMG_SIGNAL_ELECTRIC_COMBO, -2, 6); this->DrawSignalSprite(BSW_ELECTRIC_COMBO, SPR_IMG_SIGNAL_ELECTRIC_COMBO, -2, 6);
/* Draw dragging signal density value in the BSW_DRAG_SIGNALS_DENSITY widget */ /* Draw dragging signal density value in the BSW_DRAG_SIGNALS_DENSITY widget */
SetDParam(0, _patches.drag_signals_density); SetDParam(0, _patches.drag_signals_density);
DrawStringCentered(w->widget[BSW_DRAG_SIGNALS_DENSITY].left + (w->widget[BSW_DRAG_SIGNALS_DENSITY].right - DrawStringCentered(this->widget[BSW_DRAG_SIGNALS_DENSITY].left + (this->widget[BSW_DRAG_SIGNALS_DENSITY].right -
w->widget[BSW_DRAG_SIGNALS_DENSITY].left) / 2 + 1, this->widget[BSW_DRAG_SIGNALS_DENSITY].left) / 2 + 1,
w->widget[BSW_DRAG_SIGNALS_DENSITY].top + 2, STR_JUST_INT, TC_ORANGE); this->widget[BSW_DRAG_SIGNALS_DENSITY].top + 2, STR_JUST_INT, TC_ORANGE);
break; }
case WE_CLICK: virtual void OnClick(Point pt, int widget)
switch (e->we.click.widget) { {
switch (widget) {
case BSW_SEMAPHORE_NORM: case BSW_SEMAPHORE_NORM:
case BSW_SEMAPHORE_ENTRY: case BSW_SEMAPHORE_ENTRY:
case BSW_SEMAPHORE_EXIT: case BSW_SEMAPHORE_EXIT:
@ -1306,10 +1310,10 @@ static void SignalBuildWndProc(Window *w, WindowEvent *e)
case BSW_ELECTRIC_ENTRY: case BSW_ELECTRIC_ENTRY:
case BSW_ELECTRIC_EXIT: case BSW_ELECTRIC_EXIT:
case BSW_ELECTRIC_COMBO: case BSW_ELECTRIC_COMBO:
w->RaiseWidget((_cur_signal_variant == SIG_ELECTRIC ? BSW_ELECTRIC_NORM : BSW_SEMAPHORE_NORM) + _cur_signal_type); this->RaiseWidget((_cur_signal_variant == SIG_ELECTRIC ? BSW_ELECTRIC_NORM : BSW_SEMAPHORE_NORM) + _cur_signal_type);
_cur_signal_type = (SignalType)((uint)((e->we.click.widget - BSW_SEMAPHORE_NORM) % (SIGTYPE_COMBO + 1))); _cur_signal_type = (SignalType)((uint)((widget - BSW_SEMAPHORE_NORM) % (SIGTYPE_COMBO + 1)));
_cur_signal_variant = e->we.click.widget >= BSW_ELECTRIC_NORM ? SIG_ELECTRIC : SIG_SEMAPHORE; _cur_signal_variant = widget >= BSW_ELECTRIC_NORM ? SIG_ELECTRIC : SIG_SEMAPHORE;
break; break;
case BSW_CONVERT: case BSW_CONVERT:
@ -1333,14 +1337,9 @@ static void SignalBuildWndProc(Window *w, WindowEvent *e)
default: break; default: break;
} }
w->SetDirty(); this->SetDirty();
break;
case WE_DESTROY:
ResetObjectToPlace();
break;
}
} }
};
/** Widget definition of the build signal window */ /** Widget definition of the build signal window */
static const Widget _signal_builder_widgets[] = { static const Widget _signal_builder_widgets[] = {
@ -1371,7 +1370,7 @@ static const WindowDesc _signal_builder_desc = {
WC_BUILD_SIGNAL, WC_BUILD_TOOLBAR, WC_BUILD_SIGNAL, WC_BUILD_TOOLBAR,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_signal_builder_widgets, _signal_builder_widgets,
SignalBuildWndProc NULL
}; };
/** /**
@ -1379,9 +1378,11 @@ static const WindowDesc _signal_builder_desc = {
*/ */
static void ShowSignalBuilder() static void ShowSignalBuilder()
{ {
new Window(&_signal_builder_desc); new BuildSignalWindow(&_signal_builder_desc);
} }
struct BuildRailDepotWindow : public PickerWindowBase {
private:
/** Enum referring to the widgets of the build rail depot window */ /** Enum referring to the widgets of the build rail depot window */
enum BuildRailDepotWidgets { enum BuildRailDepotWidgets {
BRDW_CLOSEBOX = 0, BRDW_CLOSEBOX = 0,
@ -1393,41 +1394,39 @@ enum BuildRailDepotWidgets {
BRDW_DEPOT_NW, BRDW_DEPOT_NW,
}; };
static void BuildTrainDepotWndProc(Window *w, WindowEvent *e) public:
BuildRailDepotWindow(const WindowDesc *desc) : PickerWindowBase(desc)
{ {
switch (e->event) { this->LowerWidget(_build_depot_direction + BRDW_DEPOT_NE);
case WE_CREATE: w->LowerWidget(_build_depot_direction + BRDW_DEPOT_NE); break; this->FindWindowPlacementAndResize(desc);
}
case WE_PAINT: { virtual void OnPaint()
w->DrawWidgets(); {
this->DrawWidgets();
DrawTrainDepotSprite(70, 17, DIAGDIR_NE, _cur_railtype); DrawTrainDepotSprite(70, 17, DIAGDIR_NE, _cur_railtype);
DrawTrainDepotSprite(70, 69, DIAGDIR_SE, _cur_railtype); DrawTrainDepotSprite(70, 69, DIAGDIR_SE, _cur_railtype);
DrawTrainDepotSprite( 2, 69, DIAGDIR_SW, _cur_railtype); DrawTrainDepotSprite( 2, 69, DIAGDIR_SW, _cur_railtype);
DrawTrainDepotSprite( 2, 17, DIAGDIR_NW, _cur_railtype); DrawTrainDepotSprite( 2, 17, DIAGDIR_NW, _cur_railtype);
break;
} }
case WE_CLICK: virtual void OnClick(Point pt, int widget)
switch (e->we.click.widget) { {
switch (widget) {
case BRDW_DEPOT_NE: case BRDW_DEPOT_NE:
case BRDW_DEPOT_SE: case BRDW_DEPOT_SE:
case BRDW_DEPOT_SW: case BRDW_DEPOT_SW:
case BRDW_DEPOT_NW: case BRDW_DEPOT_NW:
w->RaiseWidget(_build_depot_direction + BRDW_DEPOT_NE); this->RaiseWidget(_build_depot_direction + BRDW_DEPOT_NE);
_build_depot_direction = (DiagDirection)(e->we.click.widget - BRDW_DEPOT_NE); _build_depot_direction = (DiagDirection)(widget - BRDW_DEPOT_NE);
w->LowerWidget(_build_depot_direction + BRDW_DEPOT_NE); this->LowerWidget(_build_depot_direction + BRDW_DEPOT_NE);
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
w->SetDirty(); this->SetDirty();
break;
}
break;
case WE_DESTROY:
ResetObjectToPlace();
break; break;
} }
} }
};
/** Widget definition of the build rail depot window */ /** Widget definition of the build rail depot window */
static const Widget _build_depot_widgets[] = { static const Widget _build_depot_widgets[] = {
@ -1446,14 +1445,16 @@ static const WindowDesc _build_depot_desc = {
WC_BUILD_DEPOT, WC_BUILD_TOOLBAR, WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_depot_widgets, _build_depot_widgets,
BuildTrainDepotWndProc NULL
}; };
static void ShowBuildTrainDepotPicker() static void ShowBuildTrainDepotPicker()
{ {
new Window(&_build_depot_desc); new BuildRailDepotWindow(&_build_depot_desc);
} }
struct BuildRailWaypointWindow : PickerWindowBase {
private:
/** Enum referring to the widgets of the build NewGRF rail waypoint window */ /** Enum referring to the widgets of the build NewGRF rail waypoint window */
enum BuildRailWaypointWidgets { enum BuildRailWaypointWidgets {
BRWW_CLOSEBOX = 0, BRWW_CLOSEBOX = 0,
@ -1467,23 +1468,28 @@ enum BuildRailWaypointWidgets {
BRWW_SCROLL, BRWW_SCROLL,
}; };
static void BuildWaypointWndProc(Window *w, WindowEvent *e) public:
BuildRailWaypointWindow(const WindowDesc *desc) : PickerWindowBase(desc)
{
this->hscroll.cap = 5;
this->hscroll.count = _waypoint_count;
};
virtual void OnPaint()
{ {
switch (e->event) {
case WE_PAINT: {
uint i; uint i;
for (i = 0; i < w->hscroll.cap; i++) { for (i = 0; i < this->hscroll.cap; i++) {
w->SetWidgetLoweredState(i + BRWW_WAYPOINT_1, (w->hscroll.pos + i) == _cur_waypoint_type); this->SetWidgetLoweredState(i + BRWW_WAYPOINT_1, (this->hscroll.pos + i) == _cur_waypoint_type);
} }
w->DrawWidgets(); this->DrawWidgets();
for (i = 0; i < w->hscroll.cap; i++) { for (i = 0; i < this->hscroll.cap; i++) {
if (w->hscroll.pos + i < w->hscroll.count) { if (this->hscroll.pos + i < this->hscroll.count) {
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, w->hscroll.pos + i); const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, this->hscroll.pos + i);
DrawWaypointSprite(2 + i * 68, 25, w->hscroll.pos + i, _cur_railtype); DrawWaypointSprite(2 + i * 68, 25, this->hscroll.pos + i, _cur_railtype);
if (statspec != NULL && if (statspec != NULL &&
HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && HasBit(statspec->callbackmask, CBM_STATION_AVAIL) &&
@ -1492,16 +1498,17 @@ static void BuildWaypointWndProc(Window *w, WindowEvent *e)
} }
} }
} }
break;
} }
case WE_CLICK: {
switch (e->we.click.widget) { virtual void OnClick(Point pt, int widget)
{
switch (widget) {
case BRWW_WAYPOINT_1: case BRWW_WAYPOINT_1:
case BRWW_WAYPOINT_2: case BRWW_WAYPOINT_2:
case BRWW_WAYPOINT_3: case BRWW_WAYPOINT_3:
case BRWW_WAYPOINT_4: case BRWW_WAYPOINT_4:
case BRWW_WAYPOINT_5: { case BRWW_WAYPOINT_5: {
byte type = e->we.click.widget - BRWW_WAYPOINT_1 + w->hscroll.pos; byte type = widget - BRWW_WAYPOINT_1 + this->hscroll.pos;
/* Check station availability callback */ /* Check station availability callback */
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, type); const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, type);
@ -1511,18 +1518,12 @@ static void BuildWaypointWndProc(Window *w, WindowEvent *e)
_cur_waypoint_type = type; _cur_waypoint_type = type;
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
w->SetDirty(); this->SetDirty();
break; break;
} }
} }
break;
}
case WE_DESTROY:
ResetObjectToPlace();
break;
}
} }
};
/** Widget definition for the build NewGRF rail waypoint window */ /** Widget definition for the build NewGRF rail waypoint window */
static const Widget _build_waypoint_widgets[] = { static const Widget _build_waypoint_widgets[] = {
@ -1545,14 +1546,12 @@ static const WindowDesc _build_waypoint_desc = {
WC_BUILD_DEPOT, WC_BUILD_TOOLBAR, WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_waypoint_widgets, _build_waypoint_widgets,
BuildWaypointWndProc NULL
}; };
static void ShowBuildWaypointPicker() static void ShowBuildWaypointPicker()
{ {
Window *w = new Window(&_build_waypoint_desc); new BuildRailWaypointWindow(&_build_waypoint_desc);
w->hscroll.cap = 5;
w->hscroll.count = _waypoint_count;
} }