From b98b887effc0cf2a4ce131830f7716ef5a332cb1 Mon Sep 17 00:00:00 2001 From: Renato Date: Thu, 16 Mar 2023 13:35:41 -0300 Subject: [PATCH] fix #476 #475 --- src/client/mapview.cpp | 33 +++++++++++++++------------------ src/client/mapview.h | 2 ++ src/client/uimap.cpp | 9 ++------- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/client/mapview.cpp b/src/client/mapview.cpp index 3a3dd53887..d3564c5d4c 100644 --- a/src/client/mapview.cpp +++ b/src/client/mapview.cpp @@ -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); } @@ -371,6 +360,9 @@ void MapView::updateRect(const Rect& rect) { m_posInfo.drawOffset = m_posInfo.srcRect.topLeft(); m_posInfo.horizontalStretchFactor = rect.width() / static_cast(m_posInfo.srcRect.width()); m_posInfo.verticalStretchFactor = rect.height() / static_cast(m_posInfo.srcRect.height()); + + m_mousePosition = getPosition(g_window.getMousePosition()); + onMouseMove(m_mousePosition, true); } m_posInfo.camera = getCameraPosition(); @@ -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) @@ -820,6 +816,7 @@ void MapView::updateViewportDirectionCache() } } +Position MapView::getCameraPosition() { return isFollowingCreature() ? m_followingCreature->getPosition() : m_customCameraPosition; } std::vector 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); diff --git a/src/client/mapview.h b/src/client/mapview.h index 6777d33edb..c11345c49f 100644 --- a/src/client/mapview.h +++ b/src/client/mapview.h @@ -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(); } void resetLastCamera() { m_lastCameraPosition = {}; } diff --git a/src/client/uimap.cpp b/src/client/uimap.cpp index 8269af64ea..f393d4f387 100644 --- a/src/client/uimap.cpp +++ b/src/client/uimap.cpp @@ -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)