diff --git a/src/citymania/cm_highlight.cpp b/src/citymania/cm_highlight.cpp index dcdf82c314..b6ecdd5f52 100644 --- a/src/citymania/cm_highlight.cpp +++ b/src/citymania/cm_highlight.cpp @@ -2,7 +2,7 @@ #include "cm_highlight.hpp" -#include "cm_blueprint.hpp" +// #include "cm_blueprint.hpp" #include "cm_main.hpp" #include "cm_station_gui.hpp" @@ -13,6 +13,7 @@ #include "../industry.h" #include "../landscape.h" #include "../newgrf_railtype.h" +#include "../newgrf_station.h" #include "../town.h" #include "../town_kdtree.h" #include "../tilearea_type.h" @@ -41,6 +42,16 @@ RoadBits FindRailsToConnect(TileIndex tile); extern DiagDirection _build_depot_direction; ///< Currently selected depot direction extern uint32 _realtime_tick; +struct RailStationGUISettings { + Axis orientation; ///< Currently selected rail station orientation + + bool newstations; ///< Are custom station definitions available? + StationClassID station_class; ///< Currently selected custom station class (if newstations is \c true ) + byte station_type; ///< %Station type within the currently selected custom station class (if newstations is \c true ) + byte station_count; ///< Number of custom stations (if newstations is \c true ) +}; +extern RailStationGUISettings _railstation; ///< Settings of the station builder GUI + namespace citymania { @@ -116,7 +127,11 @@ ObjectTileHighlight ObjectTileHighlight::make_rail_tunnel_head(DiagDirection ddi bool ObjectHighlight::operator==(const ObjectHighlight& oh) { if (this->type != oh.type) return false; - return (this->tile == oh.tile && this->ddir == oh.ddir && this->blueprint == oh.blueprint); + return (this->tile == oh.tile + && this->end_tile == oh.end_tile + && this->axis == oh.axis + && this->ddir == oh.ddir + && this->blueprint == oh.blueprint); // switch (this->type) { // case Type::RAIL_DEPOT: return this->tile == oh.tile && this->ddir == oh.ddir; // default: return true; @@ -129,13 +144,21 @@ bool ObjectHighlight::operator!=(const ObjectHighlight& oh) { } -ObjectHighlight ObjectHighlight::make_depot(TileIndex tile, DiagDirection ddir) { +ObjectHighlight ObjectHighlight::make_rail_depot(TileIndex tile, DiagDirection ddir) { auto oh = ObjectHighlight{ObjectHighlight::Type::RAIL_DEPOT}; oh.tile = tile; oh.ddir = ddir; return oh; } +ObjectHighlight ObjectHighlight::make_rail_station(TileIndex start_tile, TileIndex end_tile, Axis axis) { + auto oh = ObjectHighlight{ObjectHighlight::Type::RAIL_STATION}; + oh.tile = start_tile; + oh.end_tile = end_tile; + oh.axis = axis; + return oh; +} + // ObjectHighlight ObjectHighlight::make_blueprint(TileIndex tile, sp blueprint) { // auto oh = ObjectHighlight{ObjectHighlight::Type::BLUEPRINT}; // oh.tile = tile; @@ -186,6 +209,13 @@ void ObjectHighlight::UpdateTiles() { } break; } + case Type::RAIL_STATION: { + auto ta = OrthogonalTileArea(this->tile, this->end_tile); + TILE_AREA_LOOP(tile, ta) { + this->tiles.insert({tile, ObjectTileHighlight::make_rail_station(this->axis)}); + } + break; + } // case Type::BLUEPRINT: // if (this->blueprint && this->tile != INVALID_TILE) // this->tiles = this->blueprint->GetTiles(this->tile); @@ -534,21 +564,21 @@ static void SetStationSelectionHighlight(const TileInfo *ti, TileHighlight &th) if (_highlight_station_to_join) highlight_station = _highlight_station_to_join; - if (draw_selection) { - auto b = CalcTileBorders(ti->tile, [](TileIndex t) { - auto x = TileX(t) * TILE_SIZE, y = TileY(t) * TILE_SIZE; - return IsInsideSelectedRectangle(x, y); - }); - const SpriteID pal[] = {SPR_PALETTE_ZONING_RED, SPR_PALETTE_ZONING_YELLOW, SPR_PALETTE_ZONING_LIGHT_BLUE, SPR_PALETTE_ZONING_GREEN}; - auto color = pal[(int)_station_building_status]; - if (_thd.make_square_red) color = SPR_PALETTE_ZONING_RED; - if (b.first != ZoningBorder::NONE) - th.add_border(b.first, color); - if (IsInsideSelectedRectangle(TileX(ti->tile) * TILE_SIZE, TileY(ti->tile) * TILE_SIZE)) { - th.ground_pal = GetTintBySelectionColour(color); - return; - } - } + // if (draw_selection) { + // auto b = CalcTileBorders(ti->tile, [](TileIndex t) { + // auto x = TileX(t) * TILE_SIZE, y = TileY(t) * TILE_SIZE; + // return IsInsideSelectedRectangle(x, y); + // }); + // const SpriteID pal[] = {SPR_PALETTE_ZONING_RED, SPR_PALETTE_ZONING_YELLOW, SPR_PALETTE_ZONING_LIGHT_BLUE, SPR_PALETTE_ZONING_GREEN}; + // auto color = pal[(int)_station_building_status]; + // if (_thd.make_square_red) color = SPR_PALETTE_ZONING_RED; + // if (b.first != ZoningBorder::NONE) + // th.add_border(b.first, color); + // if (IsInsideSelectedRectangle(TileX(ti->tile) * TILE_SIZE, TileY(ti->tile) * TILE_SIZE)) { + // th.ground_pal = GetTintBySelectionColour(color); + // return; + // } + // } auto coverage_getter = [draw_selection, highlight_station](TileIndex t) { auto x = TileX(t) * TILE_SIZE, y = TileY(t) * TILE_SIZE; @@ -872,6 +902,7 @@ HighLightStyle UpdateTileSelection(HighLightStyle new_drawstyle) { _thd.cm_new = ObjectHighlight(ObjectHighlight::Type::NONE); auto pt = GetTileBelowCursor(); auto tile = (pt.x == -1 ? INVALID_TILE : TileVirtXY(pt.x, pt.y)); + // fprintf(stderr, "UPDATE %d %d %d %d\n", tile, _thd.size.x, _thd.size.y, (int)((_thd.place_mode & HT_DRAG_MASK) == HT_RECT)); // if (_thd.place_mode == CM_HT_BLUEPRINT_PLACE) { // UpdateBlueprintTileSelection(pt, tile); // new_drawstyle = CM_HT_BLUEPRINT_PLACE; @@ -883,7 +914,17 @@ HighLightStyle UpdateTileSelection(HighLightStyle new_drawstyle) { if (dir >= DiagDirection::DIAGDIR_END) { dir = AddAutodetectionRotation(AutodetectRailObjectDirection(tile, pt)); } - _thd.cm_new = ObjectHighlight::make_depot(tile, dir); + _thd.cm_new = ObjectHighlight::make_rail_depot(tile, dir); + } + new_drawstyle = HT_RECT; + } else if (_thd.outersize.x > 0) { // station + if (_thd.size.x >= (int)TILE_SIZE && _thd.size.y >= (int)TILE_SIZE) { + auto start_tile = TileXY(_thd.pos.x / TILE_SIZE, _thd.pos.y / TILE_SIZE); + auto end_tile = TileXY( + std::min((_thd.pos.x + _thd.size.x) / TILE_SIZE, MapSizeX()) - 1, + std::min((_thd.pos.y + _thd.size.y) / TILE_SIZE, MapSizeY()) - 1 + ); + _thd.cm_new = ObjectHighlight::make_rail_station(start_tile, end_tile, _railstation.orientation); } new_drawstyle = HT_RECT; } diff --git a/src/citymania/cm_highlight_type.hpp b/src/citymania/cm_highlight_type.hpp index e831ace1ad..288c319f25 100644 --- a/src/citymania/cm_highlight_type.hpp +++ b/src/citymania/cm_highlight_type.hpp @@ -154,11 +154,14 @@ public: enum class Type { NONE = 0, RAIL_DEPOT = 1, + RAIL_STATION = 2, // BLUEPRINT = 2, }; Type type; TileIndex tile = INVALID_TILE; + TileIndex end_tile = INVALID_TILE; + Axis axis = INVALID_AXIS; DiagDirection ddir = INVALID_DIAGDIR; sp blueprint = nullptr; @@ -173,7 +176,8 @@ public: bool operator==(const ObjectHighlight& oh); bool operator!=(const ObjectHighlight& oh); - static ObjectHighlight make_depot(TileIndex tile, DiagDirection ddir); + static ObjectHighlight make_rail_depot(TileIndex tile, DiagDirection ddir); + static ObjectHighlight make_rail_station(TileIndex start_tile, TileIndex end_tile, Axis axis); // static ObjectHighlight make_blueprint(TileIndex tile, sp blueprint); void Draw(const TileInfo *ti);