From beb04d8d8e600f018dc878ae6e96d251aefd3169 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Fri, 24 Aug 2012 19:59:33 -0300 Subject: [PATCH] Fix container bug, miniwindow pos, creature skulls outsite map bound --- modules/corelib/ui/uiminiwindow.lua | 2 +- modules/game_interface/gameinterface.lua | 3 +-- src/otclient/creature.cpp | 9 ++++++--- src/otclient/game.cpp | 21 ++++++++++++++------- src/otclient/game.h | 1 + 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/modules/corelib/ui/uiminiwindow.lua b/modules/corelib/ui/uiminiwindow.lua index 972ed789..4894d03d 100644 --- a/modules/corelib/ui/uiminiwindow.lua +++ b/modules/corelib/ui/uiminiwindow.lua @@ -97,7 +97,7 @@ function UIMiniWindow:setup() elseif selfSettings.position then self:setParent(parent) self:setPosition(topoint(selfSettings.position)) - self:bindRectToParent() + addEvent(function() self:bindRectToParent() end) end end end diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index c1d16b2b..7681c707 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -351,11 +351,10 @@ function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, u if useThing:isContainer() then if useThing:getParentContainer() then g_game.open(useThing, useThing:getParentContainer()) - return true else g_game.open(useThing) - return true end + return true elseif useThing:isMultiUse() then startUseWith(useThing) return true diff --git a/src/otclient/creature.cpp b/src/otclient/creature.cpp index a8155a7e..7126b244 100644 --- a/src/otclient/creature.cpp +++ b/src/otclient/creature.cpp @@ -236,15 +236,18 @@ void Creature::drawInformation(const Point& point, bool useGray, const Rect& par if(m_skull != Otc::SkullNone && m_skullTexture) { g_painter->setColor(Color::white); - g_painter->drawTexturedRect(Rect(point.x + 12, point.y + 5, m_skullTexture->getSize()), m_skullTexture); + Rect skullRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 5, m_skullTexture->getSize()); + g_painter->drawTexturedRect(skullRect, m_skullTexture); } if(m_shield != Otc::ShieldNone && m_shieldTexture && m_showShieldTexture) { g_painter->setColor(Color::white); - g_painter->drawTexturedRect(Rect(point.x, point.y + 5, m_shieldTexture->getSize()), m_shieldTexture); + Rect shieldRect = Rect(backgroundRect.x() + 13.5, backgroundRect.y() + 5, m_shieldTexture->getSize()); + g_painter->drawTexturedRect(shieldRect, m_shieldTexture); } if(m_emblem != Otc::EmblemNone && m_emblemTexture) { g_painter->setColor(Color::white); - g_painter->drawTexturedRect(Rect(point.x + 12, point.y + 16, m_emblemTexture->getSize()), m_emblemTexture); + Rect emblemRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 16, m_emblemTexture->getSize()); + g_painter->drawTexturedRect(emblemRect, m_emblemTexture); } } diff --git a/src/otclient/game.cpp b/src/otclient/game.cpp index b2de7007..66403664 100644 --- a/src/otclient/game.cpp +++ b/src/otclient/game.cpp @@ -663,7 +663,9 @@ void Game::use(const ThingPtr& thing) if(!pos.isValid()) // virtual item pos = Position(0xFFFF, 0, 0); // means that is a item in inventory - m_protocolGame->sendUseItem(pos, thing->getId(), thing->getStackpos(), 0); + // some itens, e.g. parcel, are not set as containers but they are. + // always try to use these items in free container slots. + m_protocolGame->sendUseItem(pos, thing->getId(), thing->getStackpos(), findEmptyContainerId()); } void Game::useInventoryItem(int itemId) @@ -710,13 +712,10 @@ void Game::open(const ItemPtr& item, const ContainerPtr& previousContainer) return; int id = 0; - if(!previousContainer) { - // find a free container id - while(m_containers[id] != nullptr) - id++; - } else { + if(!previousContainer) + id = findEmptyContainerId(); + else id = previousContainer->getId(); - } m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackpos(), id); } @@ -1215,3 +1214,11 @@ std::string Game::formatCreatureName(const std::string& name) formatedName[0] = stdext::upchar(formatedName[0]); return formatedName; } + +int Game::findEmptyContainerId() +{ + int id = 0; + while(m_containers[id] != nullptr) + id++; + return id; +} diff --git a/src/otclient/game.h b/src/otclient/game.h index fa02a5f9..c28a1ca9 100644 --- a/src/otclient/game.h +++ b/src/otclient/game.h @@ -268,6 +268,7 @@ public: std::vector getGMActions() { return m_gmActions; } std::string formatCreatureName(const std::string &name); + int findEmptyContainerId(); protected: void enableBotCall() { m_denyBotCall = false; }