Skip to content

Commit

Permalink
SHERLOCK: Fix display of location names on overhead map
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Apr 23, 2015
1 parent afbc333 commit 1ae176f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
74 changes: 74 additions & 0 deletions engines/sherlock/map.cpp
Expand Up @@ -113,6 +113,7 @@ int Map::show() {

// Load the entire map
ImageFile bigMap("bigmap.vgs");
screen.setPalette(bigMap._palette);

// Load need sprites
setupSprites();
Expand Down Expand Up @@ -194,6 +195,10 @@ int Map::show() {
_placesShown = true;
}

if (_cursorIndex == 0) {
Common::Point pt = events.mousePos();
highlightIcon(Common::Point(pt.x - 4 + _bigPos.x, pt.y + _bigPos.y));
}
updateMap(false);
}

Expand Down Expand Up @@ -321,6 +326,34 @@ void Map::eraseTopLine() {
screen.blitFrom(_topLine, Common::Point(0, 0));
}

/**
* Prints the name of the specified icon
*/
void Map::showPlaceName(int idx, bool highlighted) {
People &people = *_vm->_people;
Screen &screen = *_vm->_screen;

Common::String name = _locationNames[idx];
int width = screen.stringWidth(name);

if (!_cursorIndex) {
saveIcon(people[AL]._imageFrame, _lDrawnPos);

bool flipped = people[AL]._sequenceNumber == MAP_DOWNLEFT || people[AL]._sequenceNumber == MAP_LEFT
|| people[AL]._sequenceNumber == MAP_UPLEFT;
screen._backBuffer1.transBlitFrom(people[AL]._imageFrame->_frame, _lDrawnPos, flipped);
}

if (highlighted) {
int xp = (SHERLOCK_SCREEN_WIDTH - screen.stringWidth(name)) / 2;
screen.gPrint(Common::Point(xp + 2, 2), 0, name.c_str());
screen.gPrint(Common::Point(xp + 1, 1), 0, name.c_str());
screen.gPrint(Common::Point(xp, 0), 12, name.c_str());

screen.slamArea(xp, 0, screen.stringWidth(name) + 2, 15);
}
}

/**
* Update all on-screen sprites to account for any scrolling of the map
*/
Expand Down Expand Up @@ -473,4 +506,45 @@ void Map::restoreIcon() {
screen._backBuffer1.blitFrom(_iconSave, _savedPos);
}

/**
* Handles highlighting map icons, showing their names
*/
void Map::highlightIcon(const Common::Point &pt) {
int oldPoint = _point;

// Iterate through the icon list
bool done = false;
for (uint idx = 0; idx < _points.size(); ++idx) {
const MapEntry &entry = _points[idx];

// Check whether the mouse is over a given icon
if (entry.x != 0 && entry.y != 0) {
if (Common::Rect(entry.x - 8, entry.y - 8, entry.x + 9, entry.y + 9).contains(pt)) {
done = true;

if (_point != idx && _vm->readFlags(idx)) {
// Changed to a new valid (visible) location
eraseTopLine();
showPlaceName(idx, true);
_point = idx;
}
}
}
}

if (!done) {
// No icon was highlighted
if (_point != -1) {
// No longer highlighting previously highlighted icon, so erase it
showPlaceName(_point, false);
eraseTopLine();
}

_point = -1;
} else if (oldPoint != -1 && oldPoint != _point) {
showPlaceName(oldPoint, false);
eraseTopLine();
}
}

} // End of namespace Sherlock
3 changes: 3 additions & 0 deletions engines/sherlock/map.h
Expand Up @@ -76,13 +76,16 @@ class Map {

void saveTopLine();
void eraseTopLine();
void showPlaceName(int idx, bool highlighted);

void updateMap(bool flushScreen);

void walkTheStreets();

void saveIcon(ImageFrame *src, const Common::Point &pt);
void restoreIcon();

void highlightIcon(const Common::Point &pt);
public:
Map(SherlockEngine *vm);

Expand Down

0 comments on commit 1ae176f

Please sign in to comment.