restore map clicking
This commit is contained in:
parent
46df3c7dbe
commit
53ead20de5
|
@ -13,6 +13,7 @@ Module
|
||||||
- game_console
|
- game_console
|
||||||
- game_outfit
|
- game_outfit
|
||||||
- game_containers
|
- game_containers
|
||||||
|
- game_combatcontrols
|
||||||
|
|
||||||
onLoad: |
|
onLoad: |
|
||||||
dofile 'game'
|
dofile 'game'
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
CombatControls = {}
|
CombatControls = {}
|
||||||
|
|
||||||
|
local combatControlsButton
|
||||||
|
|
||||||
function CombatControls.init()
|
function CombatControls.init()
|
||||||
|
combatControlsButton = TopMenu.addGameButton('combatControlsButton', 'Combat Controls', 'combatcontrols.png', CombatControls.toggle)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function CombatControls.terminate()
|
function CombatControls.terminate()
|
||||||
end
|
combatControlsButton:destroy()
|
||||||
|
combatControlsButton = nil
|
||||||
|
end
|
||||||
|
|
|
@ -3,5 +3,10 @@ Module
|
||||||
description: Combat controls window
|
description: Combat controls window
|
||||||
author: OTClient team
|
author: OTClient team
|
||||||
website: https://github.com/edubart/otclient
|
website: https://github.com/edubart/otclient
|
||||||
|
|
||||||
onLoad: |
|
onLoad: |
|
||||||
dofile 'combatcontrols'
|
dofile 'combatcontrols'
|
||||||
|
CombatControls.init()
|
||||||
|
|
||||||
|
onUnload: |
|
||||||
|
CombatControls.terminate()
|
||||||
|
|
|
@ -522,6 +522,45 @@ 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 = getVisibleSize();
|
||||||
|
Position cameraPosition = getCameraPosition();
|
||||||
|
|
||||||
|
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(m_followingCreature)
|
||||||
|
tilePos2D += m_followingCreature->getWalkOffset() * scaleFactor;
|
||||||
|
tilePos2D /= m_tileSize;
|
||||||
|
|
||||||
|
Position tilePos = Position(1 + (int)tilePos2D.x - m_virtualCenterOffset.x, 1 + (int)tilePos2D.y - m_virtualCenterOffset.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;
|
||||||
|
}
|
||||||
|
|
||||||
Point MapView::transformPositionTo2D(const Position& position)
|
Point MapView::transformPositionTo2D(const Position& position)
|
||||||
{
|
{
|
||||||
Position cameraPosition = getCameraPosition();
|
Position cameraPosition = getCameraPosition();
|
||||||
|
|
|
@ -80,6 +80,7 @@ public:
|
||||||
int getFirstVisibleFloor();
|
int getFirstVisibleFloor();
|
||||||
int getLastVisibleFloor();
|
int getLastVisibleFloor();
|
||||||
Position getCameraPosition();
|
Position getCameraPosition();
|
||||||
|
TilePtr getTile(const Point& mousePos, const Rect& mapRect);
|
||||||
Size getVisibleDimension() { return m_visibleDimension; }
|
Size getVisibleDimension() { return m_visibleDimension; }
|
||||||
Size getVisibleSize() { return m_visibleDimension * m_tileSize; }
|
Size getVisibleSize() { return m_visibleDimension * m_tileSize; }
|
||||||
CreaturePtr getFollowingCreature() { return m_followingCreature; }
|
CreaturePtr getFollowingCreature() { return m_followingCreature; }
|
||||||
|
|
|
@ -103,48 +103,11 @@ void UIMap::setCameraPosition(const Position& pos)
|
||||||
|
|
||||||
TilePtr UIMap::getTile(const Point& mousePos)
|
TilePtr UIMap::getTile(const Point& mousePos)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
if(!m_mapRect.contains(mousePos))
|
if(!m_mapRect.contains(mousePos))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
// Get tile position
|
//TODO: move MapView code to UIMap and rework this shit
|
||||||
Point relativeStretchMousePos = mousePos - m_mapRect.topLeft();
|
return m_mapView->getTile(mousePos, m_mapRect);
|
||||||
|
|
||||||
LocalPlayerPtr localPlayer = g_game.getLocalPlayer();
|
|
||||||
if(localPlayer)
|
|
||||||
relativeStretchMousePos += localPlayer->getWalkOffset();
|
|
||||||
|
|
||||||
Size mapSize(g_map.getVibibleSize().width() * Otc::TILE_PIXELS, g_map.getVibibleSize().height() * Otc::TILE_PIXELS);
|
|
||||||
|
|
||||||
PointF stretchFactor(m_mapRect.width() / (float)mapSize.width(), m_mapRect.height() / (float)mapSize.height());
|
|
||||||
PointF relativeMousePos = PointF(relativeStretchMousePos.x, relativeStretchMousePos.y) / stretchFactor;
|
|
||||||
|
|
||||||
PointF tilePosF = relativeMousePos / Otc::TILE_PIXELS;
|
|
||||||
Position tilePos = Position(1 + (int)tilePosF.x - g_map.getCentralOffset().x, 1 + (int)tilePosF.y - g_map.getCentralOffset().y, 0) + g_map.getCentralPosition();
|
|
||||||
if(!tilePos.isValid())
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
// Get tile
|
|
||||||
TilePtr tile = nullptr;
|
|
||||||
|
|
||||||
// We must check every floor, from top to bottom to check for a clickable tile
|
|
||||||
int firstFloor = g_map.getFirstVisibleFloor();
|
|
||||||
tilePos.coveredUp(tilePos.z - firstFloor);
|
|
||||||
for(int i = firstFloor; i <= Map::MAX_Z; i++) {
|
|
||||||
tile = g_map.getTile(tilePos);
|
|
||||||
if(tile && tile->isClickable())
|
|
||||||
break;
|
|
||||||
tilePos.coveredDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo: get creature, using walkOffset etc.
|
|
||||||
|
|
||||||
if(!tile || !tile->isClickable())
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return tile;
|
|
||||||
*/
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect)
|
void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect)
|
||||||
|
|
Loading…
Reference in New Issue