clean containers when relogging
This commit is contained in:
parent
4b7e0e8e58
commit
d4afb71263
|
@ -1,4 +1,5 @@
|
||||||
Containers = {}
|
Containers = {}
|
||||||
|
|
||||||
local function refreshContainerItems(container)
|
local function refreshContainerItems(container)
|
||||||
for slot=0,container:getCapacity()-1 do
|
for slot=0,container:getCapacity()-1 do
|
||||||
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
||||||
|
@ -48,22 +49,22 @@ local function onContainerOpen(container, previousContainer)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onContainerClose(container)
|
local function onContainerClose(container)
|
||||||
local containerWindow = container.window
|
if container.window then container.window:destroy() end
|
||||||
if containerWindow then
|
|
||||||
containerWindow:destroy()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onContainerAddItem(container, slot, item)
|
local function onContainerAddItem(container, slot, item)
|
||||||
|
if not container.window then return end
|
||||||
refreshContainerItems(container)
|
refreshContainerItems(container)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onContainerUpdateItem(container, slot, item, oldItem)
|
local function onContainerUpdateItem(container, slot, item, oldItem)
|
||||||
|
if not container.window then return end
|
||||||
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
||||||
itemWidget:setItem(item)
|
itemWidget:setItem(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onContainerRemoveItem(container, slot, item)
|
local function onContainerRemoveItem(container, slot, item)
|
||||||
|
if not container.window then return end
|
||||||
refreshContainerItems(container)
|
refreshContainerItems(container)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -75,6 +76,9 @@ function Containers.init()
|
||||||
onAddItem = onContainerAddItem,
|
onAddItem = onContainerAddItem,
|
||||||
onUpdateItem = onContainerUpdateItem,
|
onUpdateItem = onContainerUpdateItem,
|
||||||
onRemoveItem = onContainerRemoveItem })
|
onRemoveItem = onContainerRemoveItem })
|
||||||
|
connect(Game, { onGameEnd = Containers.clean() })
|
||||||
|
|
||||||
|
Containers.reloadContainers()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Containers.terminate()
|
function Containers.terminate()
|
||||||
|
@ -83,8 +87,23 @@ function Containers.terminate()
|
||||||
onAddItem = onContainerAddItem,
|
onAddItem = onContainerAddItem,
|
||||||
onUpdateItem = onContainerUpdateItem,
|
onUpdateItem = onContainerUpdateItem,
|
||||||
onRemoveItem = onContainerRemoveItem })
|
onRemoveItem = onContainerRemoveItem })
|
||||||
|
disconnect(Game, { onGameEnd = Containers.clean() })
|
||||||
|
Containers = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function Containers.reloadContainers()
|
||||||
|
Containers.clean()
|
||||||
|
for containerid,container in pairs(g_game.getContainers()) do
|
||||||
|
onContainerOpen(container)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Containers.clean()
|
function Containers.clean()
|
||||||
|
for containerid,container in pairs(g_game.getContainers()) do
|
||||||
|
if container.window then
|
||||||
|
container.window:destroy()
|
||||||
|
container.window = nil
|
||||||
|
container.itemsPnale = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -123,6 +123,8 @@ void Connection::write(uint8* buffer, uint16 size)
|
||||||
|
|
||||||
if(!m_sendEvent || m_sendEvent->isExecuted() || m_sendEvent->isCanceled()) {
|
if(!m_sendEvent || m_sendEvent->isExecuted() || m_sendEvent->isCanceled()) {
|
||||||
auto weakSelf = ConnectionWeakPtr(shared_from_this());
|
auto weakSelf = ConnectionWeakPtr(shared_from_this());
|
||||||
|
|
||||||
|
// wait 1 ms to do the real send
|
||||||
m_sendEvent = g_eventDispatcher.scheduleEvent([=] {
|
m_sendEvent = g_eventDispatcher.scheduleEvent([=] {
|
||||||
if(!weakSelf.lock())
|
if(!weakSelf.lock())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -107,6 +107,12 @@ void Protocol::internalRecvHeader(uint8* buffer, uint16 size)
|
||||||
|
|
||||||
void Protocol::internalRecvData(uint8* buffer, uint16 size)
|
void Protocol::internalRecvData(uint8* buffer, uint16 size)
|
||||||
{
|
{
|
||||||
|
// process data only if really connected
|
||||||
|
if(!isConnected()) {
|
||||||
|
logTraceError("received data while disconnected");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(m_inputMessage.getBuffer() + InputMessage::CHECKSUM_POS, buffer, size);
|
memcpy(m_inputMessage.getBuffer() + InputMessage::CHECKSUM_POS, buffer, size);
|
||||||
|
|
||||||
if(m_checksumEnabled) {
|
if(m_checksumEnabled) {
|
||||||
|
|
|
@ -1300,10 +1300,10 @@ void UIWidget::onGeometryChange(const Rect& oldRect, const Rect& newRect)
|
||||||
updateText();
|
updateText();
|
||||||
|
|
||||||
// move children that is outside the parent rect to inside again
|
// move children that is outside the parent rect to inside again
|
||||||
//for(const UIWidgetPtr& child : m_children) {
|
for(const UIWidgetPtr& child : m_children) {
|
||||||
//if(!child->isAnchored())
|
if(!child->isAnchored())
|
||||||
//child->bindRectToParent();
|
child->bindRectToParent();
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWidget::onLayoutUpdate()
|
void UIWidget::onLayoutUpdate()
|
||||||
|
|
|
@ -48,7 +48,11 @@ void Game::resetGameStates()
|
||||||
m_safeFight = true;
|
m_safeFight = true;
|
||||||
m_followingCreature = nullptr;
|
m_followingCreature = nullptr;
|
||||||
m_attackingCreature = nullptr;
|
m_attackingCreature = nullptr;
|
||||||
|
|
||||||
|
for(auto& it : m_containers)
|
||||||
|
(it.second)->close();
|
||||||
m_containers.clear();
|
m_containers.clear();
|
||||||
|
|
||||||
m_worldName = "";
|
m_worldName = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue