UIGameMap allow clicking in black
This commit is contained in:
parent
4caf5bfcac
commit
b39623d437
|
@ -58,10 +58,9 @@ function UIGameMap:onMouseRelease(mousePosition, mouseButton)
|
||||||
end
|
end
|
||||||
|
|
||||||
local tile = self:getTile(mousePosition)
|
local tile = self:getTile(mousePosition)
|
||||||
if tile == nil then return false end
|
|
||||||
|
|
||||||
local localPlayerPos = g_game.getLocalPlayer():getPosition()
|
local localPlayerPos = g_game.getLocalPlayer():getPosition()
|
||||||
local autoWalkPos = tile:getPosition()
|
local autoWalkPos = self:getPosition(mousePosition)
|
||||||
if autoWalkPos.z ~= localPlayerPos.z then
|
if autoWalkPos.z ~= localPlayerPos.z then
|
||||||
local dz = autoWalkPos.z - localPlayerPos.z
|
local dz = autoWalkPos.z - localPlayerPos.z
|
||||||
autoWalkPos.x = autoWalkPos.x + dz
|
autoWalkPos.x = autoWalkPos.x + dz
|
||||||
|
@ -69,10 +68,17 @@ function UIGameMap:onMouseRelease(mousePosition, mouseButton)
|
||||||
autoWalkPos.z = localPlayerPos.z
|
autoWalkPos.z = localPlayerPos.z
|
||||||
end
|
end
|
||||||
|
|
||||||
local lookThing = tile:getTopLookThing()
|
local lookThing
|
||||||
local useThing = tile:getTopUseThing()
|
local useThing
|
||||||
local creatureThing = tile:getTopCreature()
|
local creatureThing
|
||||||
local multiUseThing = tile:getTopMultiUseThing()
|
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)
|
local ret = modules.game_interface.processMouseAction(mousePosition, mouseButton, autoWalkPos, lookThing, useThing, creatureThing, multiUseThing)
|
||||||
if ret then
|
if ret then
|
||||||
|
|
|
@ -494,6 +494,7 @@ void OTClient::registerLuaFunctions()
|
||||||
g_lua.bindClassMemberFunction<UIMap>("getFollowingCreature", &UIMap::getFollowingCreature);
|
g_lua.bindClassMemberFunction<UIMap>("getFollowingCreature", &UIMap::getFollowingCreature);
|
||||||
g_lua.bindClassMemberFunction<UIMap>("getDrawFlags", &UIMap::getDrawFlags);
|
g_lua.bindClassMemberFunction<UIMap>("getDrawFlags", &UIMap::getDrawFlags);
|
||||||
g_lua.bindClassMemberFunction<UIMap>("getCameraPosition", &UIMap::getCameraPosition);
|
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>("getTile", &UIMap::getTile);
|
||||||
g_lua.bindClassMemberFunction<UIMap>("getMaxZoomIn", &UIMap::getMaxZoomIn);
|
g_lua.bindClassMemberFunction<UIMap>("getMaxZoomIn", &UIMap::getMaxZoomIn);
|
||||||
g_lua.bindClassMemberFunction<UIMap>("getMaxZoomOut", &UIMap::getMaxZoomOut);
|
g_lua.bindClassMemberFunction<UIMap>("getMaxZoomOut", &UIMap::getMaxZoomOut);
|
||||||
|
|
|
@ -617,48 +617,6 @@ Position MapView::getCameraPosition()
|
||||||
return m_customCameraPosition;
|
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)
|
void MapView::setDrawMinimapColors(bool enable)
|
||||||
{
|
{
|
||||||
if(m_drawMinimapColors == enable)
|
if(m_drawMinimapColors == enable)
|
||||||
|
|
|
@ -67,6 +67,10 @@ public:
|
||||||
// map dimension related
|
// map dimension related
|
||||||
void setVisibleDimension(const Size& visibleDimension);
|
void setVisibleDimension(const Size& visibleDimension);
|
||||||
Size getVisibleDimension() { return m_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
|
// view mode related
|
||||||
void setViewMode(ViewMode viewMode);
|
void setViewMode(ViewMode viewMode);
|
||||||
|
@ -100,8 +104,6 @@ public:
|
||||||
void setShader(const PainterShaderProgramPtr& shader) { m_shader = shader; }
|
void setShader(const PainterShaderProgramPtr& shader) { m_shader = shader; }
|
||||||
PainterShaderProgramPtr getShader() { return m_shader; }
|
PainterShaderProgramPtr getShader() { return m_shader; }
|
||||||
|
|
||||||
// get tile
|
|
||||||
TilePtr getTile(const Point& mousePos, const Rect& mapRect);
|
|
||||||
|
|
||||||
MapViewPtr asMapView() { return static_self_cast<MapView>(); }
|
MapViewPtr asMapView() { return static_self_cast<MapView>(); }
|
||||||
|
|
||||||
|
|
|
@ -116,18 +116,57 @@ void UIMap::setKeepAspectRatio(bool enable)
|
||||||
updateMapSize();
|
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)
|
TilePtr UIMap::getTile(const Point& mousePos)
|
||||||
{
|
{
|
||||||
/*
|
Position tilePos = getPosition(mousePos);
|
||||||
* Known Issue: If you move a container widget into the map rect
|
if(!tilePos.isValid())
|
||||||
* 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))
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
//TODO: move MapView code to UIMap and rework this shit
|
// we must check every floor, from top to bottom to check for a clickable tile
|
||||||
return m_mapView->getTile(mousePos, m_mapRect);
|
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)
|
void UIMap::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
||||||
|
|
|
@ -68,6 +68,7 @@ public:
|
||||||
CreaturePtr getFollowingCreature() { return m_mapView->getFollowingCreature(); }
|
CreaturePtr getFollowingCreature() { return m_mapView->getFollowingCreature(); }
|
||||||
Otc::DrawFlags getDrawFlags() { return m_mapView->getDrawFlags(); }
|
Otc::DrawFlags getDrawFlags() { return m_mapView->getDrawFlags(); }
|
||||||
Position getCameraPosition() { return m_mapView->getCameraPosition(); }
|
Position getCameraPosition() { return m_mapView->getCameraPosition(); }
|
||||||
|
Position getPosition(const Point& mousePos);
|
||||||
TilePtr getTile(const Point& mousePos);
|
TilePtr getTile(const Point& mousePos);
|
||||||
int getMaxZoomIn() { return m_maxZoomIn; }
|
int getMaxZoomIn() { return m_maxZoomIn; }
|
||||||
int getMaxZoomOut() { return m_maxZoomOut; }
|
int getMaxZoomOut() { return m_maxZoomOut; }
|
||||||
|
|
Loading…
Reference in New Issue