fix dragqueen and containers
This commit is contained in:
parent
9b9e837e97
commit
bd63bde722
|
@ -1,5 +1,5 @@
|
|||
function UIMap:onDragEnter(mousePos)
|
||||
local tile = self:getTile(mousePosition)
|
||||
local tile = self:getTile(mousePos)
|
||||
if not tile then return false end
|
||||
|
||||
local thing = tile:getTopMoveThing()
|
||||
|
|
|
@ -18,7 +18,7 @@ function Containers.getFreeContainerId()
|
|||
end
|
||||
|
||||
-- hooked events
|
||||
function Containers.onContainerOpen(containerId, itemId, name, capacity, hasParent)
|
||||
function Containers.onContainerOpen(containerId, itemId, name, capacity, hasParent, items)
|
||||
local container = m_containers[containerId]
|
||||
if container then
|
||||
Game.gameRightPanel:removeChild(container)
|
||||
|
@ -35,22 +35,26 @@ function Containers.onContainerOpen(containerId, itemId, name, capacity, hasPare
|
|||
-- parent button
|
||||
end
|
||||
|
||||
container.itemCount = 0
|
||||
container.itemCount = #items
|
||||
container.capacity = capacity
|
||||
|
||||
for i=1,capacity do
|
||||
local item = UIItem.create()
|
||||
item:setStyle('Item')
|
||||
container:addChild(item)
|
||||
item.position = {x=65535, y=containerId+64, z=i-1}
|
||||
local itemWidget = UIItem.create()
|
||||
itemWidget:setStyle('Item')
|
||||
container:addChild(itemWidget)
|
||||
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
|
||||
|
||||
m_containers[containerId] = container
|
||||
print("opencid ".. containerId)
|
||||
end
|
||||
|
||||
function Containers.onContainerClose(containerId)
|
||||
print("closecid ".. containerId)
|
||||
local container = m_containers[containerId]
|
||||
if container then
|
||||
Game.gameRightPanel:removeChild(container)
|
||||
|
@ -59,23 +63,75 @@ function Containers.onContainerClose(containerId)
|
|||
end
|
||||
|
||||
function Containers.onContainerAddItem(containerId, item)
|
||||
print("addcid ".. containerId)
|
||||
local container = m_containers[containerId]
|
||||
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
|
||||
while i >= 1 do
|
||||
local itemWidget = container:getChildByIndex(i)
|
||||
if not itemWidget then return end
|
||||
|
||||
local nextItemWidget = container:getChildByIndex(i+1)
|
||||
if not nextItemWidget then return end
|
||||
|
||||
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)
|
||||
|
||||
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 = container.itemCount
|
||||
pos.z = pos.z - 1
|
||||
item:setPos(pos)
|
||||
|
||||
local itemWidget = container:getChildByIndex(container.itemCount + 1)
|
||||
itemWidget:setItem(item)
|
||||
container.itemCount = container.itemCount + 1
|
||||
nextItemWidget:setItem(nil)
|
||||
end
|
||||
|
||||
container.itemCount = container.itemCount - 1
|
||||
end
|
||||
|
||||
connect(Game, { onLogin = Containers.clean,
|
||||
onLogout = Containers.clean,
|
||||
onContainerOpen = Containers.onContainerOpen,
|
||||
onContainerClose = Containers.onContainerClose,
|
||||
onContainerAddItem = Containers.onContainerAddItem })
|
||||
onContainerAddItem = Containers.onContainerAddItem,
|
||||
onContainerUpdateItem = Containers.onContainerUpdateItem,
|
||||
onContainerRemoveItem = Containers.onContainerRemoveItem })
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ UIWindow
|
|||
anchors.top: prev.bottom
|
||||
anchors.horizontalCenter: prev.horizontalCenter
|
||||
margin-top: 5
|
||||
&position: {x=65535, y=5, z=0}
|
||||
|
||||
Item
|
||||
// ammo
|
||||
|
|
|
@ -198,6 +198,7 @@ void OTClient::registerLuaFunctions()
|
|||
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>("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>("walk", std::bind(&Game::walk, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction<Game>("forceWalk", std::bind(&Game::forceWalk, &g_game, _1));
|
||||
|
|
|
@ -435,12 +435,14 @@ void ProtocolGame::parseOpenContainer(InputMessage& msg)
|
|||
bool hasParent = (msg.getU8() != 0);
|
||||
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++) {
|
||||
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)
|
||||
|
|
|
@ -27,6 +27,11 @@
|
|||
#include <framework/graphics/graphics.h>
|
||||
#include <otclient/core/localplayer.h>
|
||||
|
||||
UIMap::UIMap()
|
||||
{
|
||||
m_dragable = true;
|
||||
}
|
||||
|
||||
void UIMap::draw()
|
||||
{
|
||||
drawSelf();
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
class UIMap : public UIWidget
|
||||
{
|
||||
public:
|
||||
UIMap();
|
||||
void draw();
|
||||
|
||||
Position getPosition(const Point& mousePos);
|
||||
|
|
Loading…
Reference in New Issue