UIGameMap allow clicking in black
This commit is contained in:
parent
4caf5bfcac
commit
b39623d437
|
@ -58,10 +58,9 @@ function UIGameMap:onMouseRelease(mousePosition, mouseButton)
|
|||
end
|
||||
|
||||
local tile = self:getTile(mousePosition)
|
||||
if tile == nil then return false end
|
||||
|
||||
local localPlayerPos = g_game.getLocalPlayer():getPosition()
|
||||
local autoWalkPos = tile:getPosition()
|
||||
local autoWalkPos = self:getPosition(mousePosition)
|
||||
if autoWalkPos.z ~= localPlayerPos.z then
|
||||
local dz = autoWalkPos.z - localPlayerPos.z
|
||||
autoWalkPos.x = autoWalkPos.x + dz
|
||||
|
@ -69,10 +68,17 @@ function UIGameMap:onMouseRelease(mousePosition, mouseButton)
|
|||
autoWalkPos.z = localPlayerPos.z
|
||||
end
|
||||
|
||||
local lookThing = tile:getTopLookThing()
|
||||
local useThing = tile:getTopUseThing()
|
||||
local creatureThing = tile:getTopCreature()
|
||||
local multiUseThing = tile:getTopMultiUseThing()
|
||||
local lookThing
|
||||
local useThing
|
||||
local creatureThing
|
||||
local multiUseThing
|
||||
|
||||
if tile then
|
||||
lookThing = tile:getTopLookThing()
|
||||
useThing = tile:getTopUseThing()
|
||||
creatureThing = tile:getTopCreature()
|
||||
multiUseThing = tile:getTopMultiUseThing()
|
||||
end
|
||||
|
||||
local ret = modules.game_interface.processMouseAction(mousePosition, mouseButton, autoWalkPos, lookThing, useThing, creatureThing, multiUseThing)
|
||||
if ret then
|
||||
|
|
|
@ -494,6 +494,7 @@ void OTClient::registerLuaFunctions()
|
|||
g_lua.bindClassMemberFunction<UIMap>("getFollowingCreature", &UIMap::getFollowingCreature);
|
||||
g_lua.bindClassMemberFunction<UIMap>("getDrawFlags", &UIMap::getDrawFlags);
|
||||
g_lua.bindClassMemberFunction<UIMap>("getCameraPosition", &UIMap::getCameraPosition);
|
||||
g_lua.bindClassMemberFunction<UIMap>("getPosition", &UIMap::getPosition);
|
||||
g_lua.bindClassMemberFunction<UIMap>("getTile", &UIMap::getTile);
|
||||
g_lua.bindClassMemberFunction<UIMap>("getMaxZoomIn", &UIMap::getMaxZoomIn);
|
||||
g_lua.bindClassMemberFunction<UIMap>("getMaxZoomOut", &UIMap::getMaxZoomOut);
|
||||
|
|
|
@ -617,48 +617,6 @@ Position MapView::getCameraPosition()
|
|||
return m_customCameraPosition;
|
||||
}
|
||||
|
||||
TilePtr MapView::getTile(const Point& mousePos, const Rect& mapRect)
|
||||
{
|
||||
Point relativeMousePos = mousePos - mapRect.topLeft();
|
||||
Size visibleSize = m_visibleDimension * m_tileSize;
|
||||
Position cameraPosition = getCameraPosition();
|
||||
|
||||
// if we have no camera, its impossible to get the tile
|
||||
if(!cameraPosition.isValid())
|
||||
return nullptr;
|
||||
|
||||
float scaleFactor = m_tileSize / (float)Otc::TILE_PIXELS;
|
||||
|
||||
|
||||
float horizontalStretchFactor = visibleSize.width() / (float)mapRect.width();
|
||||
float verticalStretchFactor = visibleSize.height() / (float)mapRect.height();
|
||||
|
||||
Point tilePos2D = Point(relativeMousePos.x * horizontalStretchFactor, relativeMousePos.y * verticalStretchFactor);
|
||||
|
||||
if(isFollowingCreature())
|
||||
tilePos2D += m_followingCreature->getWalkOffset() * scaleFactor;
|
||||
tilePos2D /= m_tileSize;
|
||||
|
||||
Position tilePos = Position(1 + (int)tilePos2D.x - m_visibleCenterOffset.x, 1 + (int)tilePos2D.y - m_visibleCenterOffset.y, 0) + cameraPosition;
|
||||
if(!tilePos.isValid())
|
||||
return nullptr;
|
||||
|
||||
// we must check every floor, from top to bottom to check for a clickable tile
|
||||
TilePtr tile;
|
||||
tilePos.coveredUp(tilePos.z - m_cachedFirstVisibleFloor);
|
||||
for(int i = m_cachedFirstVisibleFloor; i <= m_cachedLastVisibleFloor; i++) {
|
||||
tile = g_map.getTile(tilePos);
|
||||
if(tile && tile->isClickable())
|
||||
break;
|
||||
tilePos.coveredDown();
|
||||
}
|
||||
|
||||
if(!tile || !tile->isClickable())
|
||||
return nullptr;
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
void MapView::setDrawMinimapColors(bool enable)
|
||||
{
|
||||
if(m_drawMinimapColors == enable)
|
||||
|
|
|
@ -67,6 +67,10 @@ public:
|
|||
// map dimension related
|
||||
void setVisibleDimension(const Size& visibleDimension);
|
||||
Size getVisibleDimension() { return m_visibleDimension; }
|
||||
int getTileSize() { return m_tileSize; }
|
||||
Point getVisibleCenterOffset() { return m_visibleCenterOffset; }
|
||||
int getCachedFirstVisibleFloor() { return m_cachedFirstVisibleFloor; }
|
||||
int getCachedLastVisibleFloor() { return m_cachedLastVisibleFloor; }
|
||||
|
||||
// view mode related
|
||||
void setViewMode(ViewMode viewMode);
|
||||
|
@ -100,8 +104,6 @@ public:
|
|||
void setShader(const PainterShaderProgramPtr& shader) { m_shader = shader; }
|
||||
PainterShaderProgramPtr getShader() { return m_shader; }
|
||||
|
||||
// get tile
|
||||
TilePtr getTile(const Point& mousePos, const Rect& mapRect);
|
||||
|
||||
MapViewPtr asMapView() { return static_self_cast<MapView>(); }
|
||||
|
||||
|
|
|
@ -116,18 +116,57 @@ void UIMap::setKeepAspectRatio(bool enable)
|
|||
updateMapSize();
|
||||
}
|
||||
|
||||
Position UIMap::getPosition(const Point& mousePos)
|
||||
{
|
||||
if(!m_mapRect.contains(mousePos))
|
||||
return Position();
|
||||
|
||||
Point relativeMousePos = mousePos - m_mapRect.topLeft();
|
||||
Size visibleSize = getVisibleDimension() * m_mapView->getTileSize();
|
||||
Position cameraPosition = getCameraPosition();
|
||||
|
||||
// if we have no camera, its impossible to get the tile
|
||||
if(!cameraPosition.isValid())
|
||||
return Position();
|
||||
|
||||
float scaleFactor = m_mapView->getTileSize() / (float)Otc::TILE_PIXELS;
|
||||
float horizontalStretchFactor = visibleSize.width() / (float)m_mapRect.width();
|
||||
float verticalStretchFactor = visibleSize.height() / (float)m_mapRect.height();
|
||||
|
||||
Point tilePos2D = Point(relativeMousePos.x * horizontalStretchFactor, relativeMousePos.y * verticalStretchFactor);
|
||||
|
||||
if(m_mapView->isFollowingCreature())
|
||||
tilePos2D += getFollowingCreature()->getWalkOffset() * scaleFactor;
|
||||
tilePos2D /= m_mapView->getTileSize();
|
||||
|
||||
Point visibleCenterOffset = m_mapView->getVisibleCenterOffset();
|
||||
Position position = Position(1 + (int)tilePos2D.x - visibleCenterOffset.x, 1 + (int)tilePos2D.y - visibleCenterOffset.y, 0) + cameraPosition;
|
||||
if(!position.isValid())
|
||||
return Position();
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
TilePtr UIMap::getTile(const Point& mousePos)
|
||||
{
|
||||
/*
|
||||
* Known Issue: If you move a container widget into the map rect
|
||||
* and you move an item onto itself it will allow this to execute
|
||||
* still dropping the item on the ground.
|
||||
*/
|
||||
if(!m_mapRect.contains(mousePos))
|
||||
Position tilePos = getPosition(mousePos);
|
||||
if(!tilePos.isValid())
|
||||
return nullptr;
|
||||
|
||||
//TODO: move MapView code to UIMap and rework this shit
|
||||
return m_mapView->getTile(mousePos, m_mapRect);
|
||||
// we must check every floor, from top to bottom to check for a clickable tile
|
||||
TilePtr tile;
|
||||
tilePos.coveredUp(tilePos.z - m_mapView->getCachedFirstVisibleFloor());
|
||||
for(int i = m_mapView->getCachedFirstVisibleFloor(); i <= m_mapView->getCachedLastVisibleFloor(); i++) {
|
||||
tile = g_map.getTile(tilePos);
|
||||
if(tile && tile->isClickable())
|
||||
break;
|
||||
tilePos.coveredDown();
|
||||
}
|
||||
|
||||
if(!tile || !tile->isClickable())
|
||||
return nullptr;
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
void UIMap::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
||||
|
|
|
@ -68,6 +68,7 @@ public:
|
|||
CreaturePtr getFollowingCreature() { return m_mapView->getFollowingCreature(); }
|
||||
Otc::DrawFlags getDrawFlags() { return m_mapView->getDrawFlags(); }
|
||||
Position getCameraPosition() { return m_mapView->getCameraPosition(); }
|
||||
Position getPosition(const Point& mousePos);
|
||||
TilePtr getTile(const Point& mousePos);
|
||||
int getMaxZoomIn() { return m_maxZoomIn; }
|
||||
int getMaxZoomOut() { return m_maxZoomOut; }
|
||||
|
|
Loading…
Reference in New Issue