Skip to content

Commit

Permalink
fix #476 #475
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah committed Mar 16, 2023
1 parent 900c7cb commit b98b887
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
33 changes: 15 additions & 18 deletions src/client/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,8 @@ void MapView::updateVisibleTiles()
m_lockedFirstVisibleFloor = m_floorViewMode == LOCKED ? m_posInfo.camera.z : -1;

const uint8_t prevFirstVisibleFloor = m_cachedFirstVisibleFloor;
if (m_lastCameraPosition != m_posInfo.camera) {
if (m_mousePosition.isValid()) {
const Otc::Direction direction = m_lastCameraPosition.getDirectionFromPosition(m_posInfo.camera);
m_mousePosition = m_mousePosition.translatedToDirection(direction);

if (m_posInfo.camera.z != m_lastCameraPosition.z) {
m_mousePosition.z += m_posInfo.camera.z - m_lastCameraPosition.z;
m_mousePosition = m_mousePosition.translatedToDirection(direction); // Two steps
}

onMouseMove(m_mousePosition, true);
}

if (m_lastCameraPosition != m_posInfo.camera) {
if (m_lastCameraPosition.z != m_posInfo.camera.z) {
onFloorChange(m_posInfo.camera.z, m_lastCameraPosition.z);
}
Expand Down Expand Up @@ -371,6 +360,9 @@ void MapView::updateRect(const Rect& rect) {
m_posInfo.drawOffset = m_posInfo.srcRect.topLeft();
m_posInfo.horizontalStretchFactor = rect.width() / static_cast<float>(m_posInfo.srcRect.width());
m_posInfo.verticalStretchFactor = rect.height() / static_cast<float>(m_posInfo.srcRect.height());

m_mousePosition = getPosition(g_window.getMousePosition());
onMouseMove(m_mousePosition, true);
}

m_posInfo.camera = getCameraPosition();
Expand Down Expand Up @@ -561,16 +553,20 @@ void MapView::followCreature(const CreaturePtr& creature)
requestUpdateVisibleTiles();
}

Position MapView::getCameraPosition()
{
return isFollowingCreature() ? m_followingCreature->getPosition() : m_customCameraPosition;
}

void MapView::setCameraPosition(const Position& pos)
{
m_follow = false;
m_customCameraPosition = pos;
requestUpdateVisibleTiles();
requestUpdateVisibleTiles(); \
}

Position MapView::getPosition(const Point& mousePos)
{
if (!m_posInfo.rect.contains(mousePos))
return {};

const auto& relativeMousePos = mousePos - m_posInfo.rect.topLeft();
return getPosition(relativeMousePos, m_posInfo.rect.size());
}

Position MapView::getPosition(const Point& point, const Size& mapSize)
Expand Down Expand Up @@ -820,6 +816,7 @@ void MapView::updateViewportDirectionCache()
}
}

Position MapView::getCameraPosition() { return isFollowingCreature() ? m_followingCreature->getPosition() : m_customCameraPosition; }
std::vector<CreaturePtr> MapView::getSightSpectators(bool multiFloor)
{
return g_map.getSpectatorsInRangeEx(getCameraPosition(), multiFloor, m_posInfo.awareRange.left - 1, m_posInfo.awareRange.right - 2, m_posInfo.awareRange.top - 1, m_posInfo.awareRange.bottom - 2);
Expand Down
2 changes: 2 additions & 0 deletions src/client/mapview.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class MapView : public LuaObject

Position getPosition(const Point& point, const Size& mapSize);

Position getPosition(const Point& mousePos);

MapViewPtr asMapView() { return static_self_cast<MapView>(); }

void resetLastCamera() { m_lastCameraPosition = {}; }
Expand Down
9 changes: 2 additions & 7 deletions src/client/uimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,8 @@ void UIMap::setKeepAspectRatio(bool enable)
updateMapSize();
}

Position UIMap::getPosition(const Point& mousePos)
{
if (!m_mapRect.contains(mousePos))
return {};

const auto& relativeMousePos = mousePos - m_mapRect.topLeft();
return m_mapView->getPosition(relativeMousePos, m_mapRect.size());
Position UIMap::getPosition(const Point& mousePos) {
return m_mapView->getPosition(mousePos);
}

TilePtr UIMap::getTile(const Point& mousePos)
Expand Down

1 comment on commit b98b887

@SkullzOTS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.