diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index d82ef40a99..b2d45042b1 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -792,7 +792,7 @@ do_clear:; * @param dir Direction that the road is following. * @return True if the next tile at dir direction is suitable for being connected directly by a second roadbit at the end of the road being built. */ -static bool CanConnectToRoad(TileIndex tile, RoadType rt, DiagDirection dir) +bool CanConnectToRoad(TileIndex tile, RoadType rt, DiagDirection dir) { RoadBits bits = GetAnyRoadBits(tile + TileOffsByDiagDir(dir), rt, false); return (bits & DiagDirToRoadBits(ReverseDiagDir(dir))) != 0; diff --git a/src/road_func.h b/src/road_func.h index 665da5a8cf..be48e4b040 100644 --- a/src/road_func.h +++ b/src/road_func.h @@ -181,4 +181,6 @@ RoadTypes GetCompanyRoadtypes(const CompanyID company); void UpdateLevelCrossing(TileIndex tile, bool sound = true); +bool CanConnectToRoad(TileIndex tile, RoadType rt, DiagDirection dir); + #endif /* ROAD_FUNC_H */ diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 41233594cb..0017c9969b 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -1,4 +1,4 @@ -/* $Id: road_gui.cpp 27163 2015-02-22 15:26:27Z frosch $ */ +/* $Id: road_gui.cpp 26460 2014-04-13 10:47:39Z frosch $ */ /* * This file is part of OpenTTD. @@ -30,14 +30,11 @@ #include "company_base.h" #include "hotkeys.h" #include "road_gui.h" -#include "zoom_func.h" #include "widgets/road_widget.h" #include "table/strings.h" -#include "safeguards.h" - static void ShowRVStationPicker(Window *parent, RoadStopType rs); static void ShowRoadDepotPicker(Window *parent); @@ -450,18 +447,11 @@ struct BuildRoadToolbarWindow : Window { virtual void OnInvalidateData(int data = 0, bool gui_scope = true) { if (!gui_scope) return; - - bool can_build = CanBuildVehicleInfrastructure(VEH_ROAD); - this->SetWidgetsDisabledState(!can_build, + this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD), WID_ROT_DEPOT, WID_ROT_BUS_STATION, WID_ROT_TRUCK_STATION, WIDGET_LIST_END); - if (!can_build) { - DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_ROAD); - DeleteWindowById(WC_BUS_STATION, TRANSPORT_ROAD); - DeleteWindowById(WC_TRUCK_STATION, TRANSPORT_ROAD); - } } /** @@ -644,6 +634,8 @@ struct BuildRoadToolbarWindow : Window { case WID_ROT_FULLROAD: _place_road_flag = RF_NONE; + if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X; + if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y; VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_PLACE_FULLROAD); break; @@ -716,6 +708,7 @@ struct BuildRoadToolbarWindow : Window { break; case DDSP_PLACE_AUTOROAD: + case DDSP_PLACE_FULLROAD: _place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X); if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y; if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X; @@ -734,21 +727,6 @@ struct BuildRoadToolbarWindow : Window { break; - case DDSP_PLACE_FULLROAD: - /* For autoroad we need to update the - * direction of the road */ - if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y && - ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) || - (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) { - /* Set dir = X */ - _place_road_flag &= ~RF_DIR_Y; - } - else { - /* Set dir = Y */ - _place_road_flag |= RF_DIR_Y; - } - break; - default: break; } @@ -756,6 +734,20 @@ struct BuildRoadToolbarWindow : Window { VpSelectTilesWithMethod(pt.x, pt.y, select_method); } + void TryToRemoveExtraRoadBits(TileIndex tile, RoadBits &rb) { + for (DiagDirection dir = DIAGDIR_BEGIN; dir != DIAGDIR_END; dir++) { + RoadBits dir_rb = DiagDirToRoadBits(dir); + if (!(rb & dir_rb)) continue; + if (CanConnectToRoad(tile, _cur_roadtype, dir)) continue; + DoCommandP(tile, tile, + (dir_rb == ROAD_NW || dir_rb == ROAD_NE ? 0 : 3) | + (dir_rb & ROAD_X ? 0 : 4) | + (_cur_roadtype << 3), + CMD_REMOVE_LONG_ROAD); + rb &= ~dir_rb; + } + } + virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) { if (pt.x != -1) { @@ -786,13 +778,27 @@ struct BuildRoadToolbarWindow : Window { break; case DDSP_PLACE_FULLROAD: - DoCommandP(start_tile, end_tile, - _place_road_flag | (_cur_roadtype << 3) | - (_one_way_button_clicked << 5) | (1 << 6) | - (start_tile > end_tile ? 1 : 2), // always build full roads + if (start_tile == end_tile || _remove_button_clicked) { + _place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3)); + DoCommandP(start_tile, end_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5), _remove_button_clicked ? CMD_REMOVE_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) : CMD_BUILD_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road), CcPlaySound1D); + } else { + _place_road_flag &= RF_DIR_Y; + RoadBits road_dir = _place_road_flag ? ROAD_Y : ROAD_X; + // if (start_tile > end_tile) Swap(start_tile, end_tile); + RoadBits start_extra_rb = GetAnyRoadBits(start_tile, _cur_roadtype, false) & ~road_dir; + RoadBits end_extra_rb = GetAnyRoadBits(end_tile, _cur_roadtype, false) & ~road_dir; + this->TryToRemoveExtraRoadBits(start_tile, start_extra_rb); + this->TryToRemoveExtraRoadBits(end_tile, end_extra_rb); + if ((bool)start_extra_rb != (start_tile > end_tile)) _place_road_flag |= RF_START_HALFROAD_Y; + if (!end_extra_rb != (start_tile > end_tile)) _place_road_flag |= RF_END_HALFROAD_Y; + DoCommandP(start_tile, end_tile, + _place_road_flag | (_cur_roadtype << 3) | + (_one_way_button_clicked << 5) | (1 << 6), + CMD_BUILD_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road), CcPlaySound1D); + } break; case DDSP_BUILD_BUSSTOP: @@ -1014,7 +1020,7 @@ static WindowDesc _build_road_scen_desc( /** * Show the road building toolbar in the scenario editor. - * @return The just opened toolbar, or \c NULL if the toolbar was already open. + * @return The just opened toolbar. */ Window *ShowBuildRoadScenToolbar() { @@ -1036,19 +1042,11 @@ struct BuildRoadDepotWindow : public PickerWindowBase { this->FinishInitNested(TRANSPORT_ROAD); } - virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) - { - if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return; - - size->width = ScaleGUITrad(64) + 2; - size->height = ScaleGUITrad(48) + 2; - } - virtual void DrawWidget(const Rect &r, int widget) const { if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return; - DrawRoadDepotSprite(r.left + 1 + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), (DiagDirection)(widget - WID_BROD_DEPOT_NE + DIAGDIR_NE), _cur_roadtype); + DrawRoadDepotSprite(r.left - 1, r.top, (DiagDirection)(widget - WID_BROD_DEPOT_NE + DIAGDIR_NE), _cur_roadtype); } virtual void OnClick(Point pt, int widget, int click_count) @@ -1176,20 +1174,12 @@ struct BuildRoadStationWindow : public PickerWindowBase { } } - virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) - { - if (!IsInsideMM(widget, WID_BROS_STATION_NE, WID_BROS_STATION_Y + 1)) return; - - size->width = ScaleGUITrad(64) + 2; - size->height = ScaleGUITrad(48) + 2; - } - virtual void DrawWidget(const Rect &r, int widget) const { if (!IsInsideMM(widget, WID_BROS_STATION_NE, WID_BROS_STATION_Y + 1)) return; StationType st = (this->window_class == WC_BUS_STATION) ? STATION_BUS : STATION_TRUCK; - StationPickerDrawSprite(r.left + 1 + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), st, INVALID_RAILTYPE, widget < WID_BROS_STATION_X ? ROADTYPE_ROAD : _cur_roadtype, widget - WID_BROS_STATION_NE); + StationPickerDrawSprite(r.left + TILE_PIXELS, r.bottom - TILE_PIXELS, st, INVALID_RAILTYPE, widget < WID_BROS_STATION_X ? ROADTYPE_ROAD : _cur_roadtype, widget - WID_BROS_STATION_NE); } virtual void OnClick(Point pt, int widget, int click_count) diff --git a/src/viewport.cpp b/src/viewport.cpp index 00fc2300e1..57ed47260e 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1101,7 +1101,7 @@ static void DrawTileSelection(const TileInfo *ti) HighLightStyle type = GetPartOfAutoLine(ti->x, ti->y, _thd.selstart, _thd.selend, _thd.drawstyle & HT_DIR_MASK); if (type < HT_DIR_END) { DrawAutorailSelection(ti, type); - } else if (_thd.dir2 < HT_DIR_END) { + } else if (_thd.dir2 < HT_DIR_END) { /* FIXME mb missing condition (_thd.drawstyle & HT_POLY) */ type = GetPartOfAutoLine(ti->x, ti->y, _thd.selstart2, _thd.selend2, _thd.dir2); if (type < HT_DIR_END) DrawAutorailSelection(ti, type, PALETTE_SEL_TILE_BLUE);