From a5ad910ff536b511a865d0490b6cf95394ba3d94 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 7 Jun 2009 14:33:52 +0100 Subject: [PATCH] Hide and show station highlights when approaching --- include/IStation.hpp | 2 ++ src/Game.cpp | 31 ++++++++++++++++++++++++++++++- src/Map.cpp | 3 ++- src/Station.cpp | 9 +++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/include/IStation.hpp b/include/IStation.hpp index e4fe0b9..583d37d 100644 --- a/include/IStation.hpp +++ b/include/IStation.hpp @@ -45,6 +45,8 @@ struct IStation { // the highlight is drawn typedef tuple HighlightColour; virtual HighlightColour highlightColour() const = 0; + virtual bool highlightVisible() const = 0; + virtual void setHighlightVisible(bool onOff) = 0; }; typedef std::tr1::shared_ptr IStationPtr; diff --git a/src/Game.cpp b/src/Game.cpp index 6378456..feee3e2 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -50,11 +50,16 @@ public: private: void lookAhead(); void setStatus(const string& aString) { myStatusMsg = aString; } + void nearStation(IStationPtr aStation); + void leftStation(); IMapPtr myMap; ITrainPtr myTrain; ILightPtr mySun; + // Station the train is either approaching or stopped at + IStationPtr myActiveStation; + // Camera position float myHorizAngle, myVertAngle, myViewRadius; @@ -169,6 +174,24 @@ void Game::update(IPickBufferPtr aPickBuffer, int aDelta) lookAhead(); } +// Signal that we are approaching a station +void Game::nearStation(IStationPtr aStation) +{ + leftStation(); // Clear any previous station + + myActiveStation = aStation; + aStation->setHighlightVisible(true); +} + +// Signal that we are no longer at or approaching a station +void Game::leftStation() +{ + if (myActiveStation) { + myActiveStation->setHighlightVisible(false); + myActiveStation.reset(); + } +} + // Look along the track and notify the player of any stations, points, etc. // that they are approaching void Game::lookAhead() @@ -179,6 +202,7 @@ void Game::lookAhead() // Are we sitting on a station?' if (it.status == TRACK_STATION) { setStatus("Stop here for station " + it.station->name()); + nearStation(it.station); return; } @@ -190,9 +214,11 @@ void Game::lookAhead() switch (it.status) { case TRACK_STATION: setStatus("Approaching station " + it.station->name()); + nearStation(it.station); break; case TRACK_NO_MORE: setStatus("Oh no! You're going to crash!"); + leftStation(); break; default: break; @@ -200,7 +226,10 @@ void Game::lookAhead() return; } } - + + // We're not approaching any station + leftStation(); + // Nothing to report setStatus(""); } diff --git a/src/Map.cpp b/src/Map.cpp index d6c0a77..de3f09b 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -707,7 +707,8 @@ void Map::renderSector(IGraphicsPtr aContext, int id, } // Draw the station, if any - if (tile.station) + if (tile.station + && (shouldDrawGridLines || tile.station->highlightVisible())) highlightTile(aContext, makePoint(x, y), tile.station->highlightColour()); diff --git a/src/Station.cpp b/src/Station.cpp index 9c28bb3..cd81144 100644 --- a/src/Station.cpp +++ b/src/Station.cpp @@ -32,12 +32,16 @@ public: const string& name() const { return myName; } void setName(const string& aName) { myName = aName; } HighlightColour highlightColour() const { return myColour; } + bool highlightVisible() const { return isHighlightVisible; } + void setHighlightVisible(bool onOff); private: string myName; HighlightColour myColour; + bool isHighlightVisible; }; Station::Station() + : isHighlightVisible(false) { using namespace boost; @@ -54,6 +58,11 @@ Station::Station() colourRand()); } +void Station::setHighlightVisible(bool onOff) +{ + isHighlightVisible = onOff; +} + IStationPtr makeStation() { return IStationPtr(new Station); -- 2.39.2