Fixed an issue with the battle list filter.

More work on the minimap, interface changes, fixed direction controls, fixed reseting, fixed some draw things (needs some more work to finish).
Fixed a bug in the battle list causing Battle.onFollow(creature) to execute when there was no follow.
This commit is contained in:
BeniS
2012-07-09 23:37:47 +12:00
committed by Eduardo Bart
parent c8d9833444
commit 902ce06e88
13 changed files with 135 additions and 38 deletions

View File

@@ -241,6 +241,8 @@ void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldP
{
// animate walk
creature->walk(oldPos, newPos);
g_lua.callGlobalField("g_game", "onCreatureMove", creature, oldPos, newPos);
}
void Game::processCreatureTeleport(const CreaturePtr& creature)
@@ -251,6 +253,8 @@ void Game::processCreatureTeleport(const CreaturePtr& creature)
// locks the walk for a while when teleporting
if(creature == m_localPlayer)
m_localPlayer->lockWalk();
g_lua.callGlobalField("g_game", "onCreatureTeleport", creature);
}
void Game::processChannelList(const std::vector<std::tuple<int, std::string>>& channelList)
@@ -528,6 +532,8 @@ void Game::forceWalk(Otc::Direction direction)
default:
break;
}
g_lua.callGlobalField("g_game", "onForceWalk", direction);
}
void Game::turn(Otc::Direction direction)
@@ -736,8 +742,11 @@ void Game::cancelAttackAndFollow()
m_localPlayer->lockWalk();
setAttackingCreature(nullptr);
setFollowingCreature(nullptr);
if(isAttacking())
setAttackingCreature(nullptr);
if(isFollowing())
setFollowingCreature(nullptr);
m_protocolGame->sendCancelAttackAndFollow();
}

View File

@@ -127,7 +127,7 @@ void MapView::draw(const Rect& rect)
Point drawOffset = ((m_drawDimension - m_visibleDimension - Size(1,1)).toPoint()/2) * m_tileSize;
if(m_followingCreature)
if(isFollowingCreature())
drawOffset += m_followingCreature->getWalkOffset() * scaleFactor;
Size srcSize = rect.size();
@@ -210,11 +210,32 @@ void MapView::draw(const Rect& rect)
}
} else if(m_viewMode > NEAR_VIEW) {
// draw a cross in the center instead of our creature
/*
Known Issue: Changing Z axis causes the cross to go off a little bit.
*/
Rect vRect(0, 0, 2, 10);
Rect hRect(0, 0, 10, 2);
vRect.moveCenter(rect.center());
hRect.moveCenter(rect.center());
g_painter->setColor(Color::white);
if(!m_follow && m_followingCreature)
{
Position pos = m_followingCreature->getPosition();
Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset;
p.x = p.x * horizontalStretchFactor;
p.y = p.y * verticalStretchFactor;
p += rect.topLeft();
vRect.setX(p.x); vRect.setY(p.y - 4);
hRect.setX(p.x - 4); hRect.setY(p.y);
hRect.setWidth(10); hRect.setHeight(2);
vRect.setWidth(2); vRect.setHeight(10);
}
else {
vRect.moveCenter(rect.center());
hRect.moveCenter(rect.center());
}
g_painter->drawFilledRect(vRect);
g_painter->drawFilledRect(hRect);
}
@@ -525,14 +546,15 @@ void MapView::optimizeForSize(const Size& visibleSize)
void MapView::followCreature(const CreaturePtr& creature)
{
m_follow = true;
m_followingCreature = creature;
requestVisibleTilesCacheUpdate();
}
void MapView::setCameraPosition(const Position& pos)
{
m_follow = false;
m_customCameraPosition = pos;
m_followingCreature = nullptr;
requestVisibleTilesCacheUpdate();
}
@@ -623,8 +645,9 @@ int MapView::calcLastVisibleFloor()
Position MapView::getCameraPosition()
{
if(m_followingCreature)
if(isFollowingCreature())
return m_followingCreature->getPosition();
return m_customCameraPosition;
}
@@ -641,13 +664,12 @@ TilePtr MapView::getTile(const Point& mousePos, const Rect& mapRect)
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)
if(isFollowingCreature())
tilePos2D += m_followingCreature->getWalkOffset() * scaleFactor;
tilePos2D /= m_tileSize;

View File

@@ -89,6 +89,7 @@ public:
// camera related
void followCreature(const CreaturePtr& creature);
CreaturePtr getFollowingCreature() { return m_followingCreature; }
bool isFollowingCreature() { return m_followingCreature && m_follow; }
void setCameraPosition(const Position& pos);
Position getCameraPosition();
@@ -141,6 +142,7 @@ private:
Boolean<true> m_drawTexts;
Boolean<true> m_smooth;
Boolean<false> m_drawMinimapColors;
Boolean<true> m_follow;
std::vector<TilePtr> m_cachedVisibleTiles;
std::vector<CreaturePtr> m_cachedFloorVisibleCreatures;
EventPtr m_updateTilesCacheEvent;

View File

@@ -511,6 +511,7 @@ void ProtocolGame::parseCreatureMove(const InputMessagePtr& msg)
// update map tiles
if(!g_map.removeThing(thing))
g_logger.traceError("could not remove thing");
g_map.addThing(thing, newPos);
}