fix dragqueen and containers

This commit is contained in:
Henrique Santiago 2012-01-20 00:33:11 -02:00
parent 9b9e837e97
commit bd63bde722
7 changed files with 87 additions and 21 deletions

View File

@ -1,10 +1,10 @@
function UIMap:onDragEnter(mousePos) function UIMap:onDragEnter(mousePos)
local tile = self:getTile(mousePosition) local tile = self:getTile(mousePos)
if not tile then return false end if not tile then return false end
local thing = tile:getTopMoveThing() local thing = tile:getTopMoveThing()
if not thing then return false end if not thing then return false end
self.currentDragThing = thing self.currentDragThing = thing
setTargetCursor() setTargetCursor()
return true return true

View File

@ -18,7 +18,7 @@ function Containers.getFreeContainerId()
end end
-- hooked events -- hooked events
function Containers.onContainerOpen(containerId, itemId, name, capacity, hasParent) function Containers.onContainerOpen(containerId, itemId, name, capacity, hasParent, items)
local container = m_containers[containerId] local container = m_containers[containerId]
if container then if container then
Game.gameRightPanel:removeChild(container) Game.gameRightPanel:removeChild(container)
@ -35,22 +35,26 @@ function Containers.onContainerOpen(containerId, itemId, name, capacity, hasPare
-- parent button -- parent button
end end
container.itemCount = 0 container.itemCount = #items
container.capacity = capacity container.capacity = capacity
for i=1,capacity do for i=1,capacity do
local item = UIItem.create() local itemWidget = UIItem.create()
item:setStyle('Item') itemWidget:setStyle('Item')
container:addChild(item) container:addChild(itemWidget)
item.position = {x=65535, y=containerId+64, z=i-1} itemWidget.position = {x=65535, y=containerId+64, z=i-1}
if i <= #items then
local item = items[i]
item:setPos(itemWidget.position)
itemWidget:setItem(item)
end
end end
m_containers[containerId] = container m_containers[containerId] = container
print("opencid ".. containerId)
end end
function Containers.onContainerClose(containerId) function Containers.onContainerClose(containerId)
print("closecid ".. containerId)
local container = m_containers[containerId] local container = m_containers[containerId]
if container then if container then
Game.gameRightPanel:removeChild(container) Game.gameRightPanel:removeChild(container)
@ -59,23 +63,75 @@ function Containers.onContainerClose(containerId)
end end
function Containers.onContainerAddItem(containerId, item) function Containers.onContainerAddItem(containerId, item)
print("addcid ".. containerId)
local container = m_containers[containerId] local container = m_containers[containerId]
if not container or not item or container.itemCount >= container.capacity then return end if not container or not item or container.itemCount >= container.capacity then return end
-- maybe this has to be moved to client internal's files local i = container.itemCount
local pos = item:getPos() while i >= 1 do
pos.z = container.itemCount local itemWidget = container:getChildByIndex(i)
item:setPos(pos) if not itemWidget then return end
local nextItemWidget = container:getChildByIndex(i+1)
if not nextItemWidget then return end
local itemWidget = container:getChildByIndex(container.itemCount + 1) local swapItem = itemWidget:getItem()
if swapItem then
swapItem:setPos(nextItemWidget.position)
nextItemWidget:setItem(swapItem)
end
i = i - 1
end
local itemWidget = container:getChildByIndex(1)
if not itemWidget then return end
item:setPos(itemWidget.position)
itemWidget:setItem(item) itemWidget:setItem(item)
container.itemCount = container.itemCount + 1
container.itemCount = container.itemCount + 1
end
function Containers.onContainerUpdateItem(containerId, slot, item)
local container = m_containers[containerId]
if not container then return end
local itemWidget = container:getChildByIndex(slot + 1)
if not itemWidget then return end
itemWidget:setItem(item)
end
function Containers.onContainerRemoveItem(containerId, slot)
local container = m_containers[containerId]
if not container then return end
local itemWidget = container:getChildByIndex(slot+1)
if not itemWidget then return end
itemWidget:setItem(nil)
for i=slot,container.itemCount-2 do
local itemWidget = container:getChildByIndex(i+1)
if not itemWidget then return end
local nextItemWidget = container:getChildByIndex(i+2)
if not nextItemWidget then return end
local item = nextItemWidget:getItem()
local pos = item:getPos()
pos.z = pos.z - 1
item:setPos(pos)
itemWidget:setItem(item)
nextItemWidget:setItem(nil)
end
container.itemCount = container.itemCount - 1
end end
connect(Game, { onLogin = Containers.clean, connect(Game, { onLogin = Containers.clean,
onLogout = Containers.clean, onLogout = Containers.clean,
onContainerOpen = Containers.onContainerOpen, onContainerOpen = Containers.onContainerOpen,
onContainerClose = Containers.onContainerClose, onContainerClose = Containers.onContainerClose,
onContainerAddItem = Containers.onContainerAddItem }) onContainerAddItem = Containers.onContainerAddItem,
onContainerUpdateItem = Containers.onContainerUpdateItem,
onContainerRemoveItem = Containers.onContainerRemoveItem })

View File

@ -77,6 +77,7 @@ UIWindow
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter anchors.horizontalCenter: prev.horizontalCenter
margin-top: 5 margin-top: 5
&position: {x=65535, y=5, z=0}
Item Item
// ammo // ammo

View File

@ -198,6 +198,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction<Game>("open", std::bind(&Game::open, &g_game, _1, _2)); g_lua.bindClassStaticFunction<Game>("open", std::bind(&Game::open, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("use", std::bind(&Game::use, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("use", std::bind(&Game::use, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("useWith", std::bind(&Game::useWith, &g_game, _1, _2)); g_lua.bindClassStaticFunction<Game>("useWith", std::bind(&Game::useWith, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("move", std::bind(&Game::move, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction<Game>("useInventoryItem", std::bind(&Game::useInventoryItem, &g_game, _1, _2)); g_lua.bindClassStaticFunction<Game>("useInventoryItem", std::bind(&Game::useInventoryItem, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("walk", std::bind(&Game::walk, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("walk", std::bind(&Game::walk, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("forceWalk", std::bind(&Game::forceWalk, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("forceWalk", std::bind(&Game::forceWalk, &g_game, _1));

View File

@ -435,12 +435,14 @@ void ProtocolGame::parseOpenContainer(InputMessage& msg)
bool hasParent = (msg.getU8() != 0); bool hasParent = (msg.getU8() != 0);
int itemCount = msg.getU8(); int itemCount = msg.getU8();
g_lua.callGlobalField("Game", "onContainerOpen", containerId, itemId, name, capacity, hasParent); std::vector<ItemPtr> items;
items.reserve(itemCount);
for(int i = 0; i < itemCount; i++) { for(int i = 0; i < itemCount; i++) {
ItemPtr item = internalGetItem(msg); ItemPtr item = internalGetItem(msg);
g_game.processContainerAddItem(containerId, item); items.push_back(item);
} }
g_lua.callGlobalField("Game", "onContainerOpen", containerId, itemId, name, capacity, hasParent, items);
} }
void ProtocolGame::parseCloseContainer(InputMessage& msg) void ProtocolGame::parseCloseContainer(InputMessage& msg)

View File

@ -27,6 +27,11 @@
#include <framework/graphics/graphics.h> #include <framework/graphics/graphics.h>
#include <otclient/core/localplayer.h> #include <otclient/core/localplayer.h>
UIMap::UIMap()
{
m_dragable = true;
}
void UIMap::draw() void UIMap::draw()
{ {
drawSelf(); drawSelf();

View File

@ -30,6 +30,7 @@
class UIMap : public UIWidget class UIMap : public UIWidget
{ {
public: public:
UIMap();
void draw(); void draw();
Position getPosition(const Point& mousePos); Position getPosition(const Point& mousePos);