mirror of
https://github.com/edubart/otclient.git
synced 2025-04-29 17:19:20 +02:00

* Added new left and right game button panels. * Relocated main game toggle buttons to the right side of the screen to make it easier to toggle miniwindows. * Added table.empty(t) function to table lib. * Renamed module game_healthbar to game_healthinfo. * Combat controls now save per character (e.g. Fight mode, chase mode, safe fight mode) * Last channels open now save per character. * Fixed typo in containers.lua. * Added logout prompting window message when you logout via the logout button. * Added exit promting window message when you attempt to exit the client. * Repositioned some minimap buttons. * Fixed so when creatures health percent is < 1 it will not draw the creature information. Known Issues: * If you move a container widget into the map rect if you move an item onto itself it will allow this to execute still dropping the item on the ground. * The server is calling to open channels after onGameStart is executed causing it to focus the last tab opened. Fix: Don't save channels to the settings that are opened by the server.
115 lines
3.6 KiB
Lua
115 lines
3.6 KiB
Lua
Containers = {}
|
|
|
|
local function refreshContainerItems(container)
|
|
for slot=0,container:getCapacity()-1 do
|
|
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
|
itemWidget:setItem(container:getItem(slot))
|
|
end
|
|
end
|
|
|
|
local function onContainerOpen(container, previousContainer)
|
|
local containerWindow
|
|
if previousContainer then
|
|
containerWindow = previousContainer.window
|
|
previousContainer.window = nil
|
|
previousContainer.itemsPanel = nil
|
|
else
|
|
containerWindow = g_ui.createWidget('ContainerWindow', GameInterface.getRightPanel())
|
|
end
|
|
containerWindow:setId('container' .. container:getId())
|
|
local containerPanel = containerWindow:getChildById('contentsPanel')
|
|
local containerItemWidget = containerWindow:getChildById('containerItemWidget')
|
|
containerWindow.onClose = function()
|
|
g_game.close(container)
|
|
containerWindow:hide()
|
|
end
|
|
|
|
-- this disables scrollbar auto hiding
|
|
local scrollbar = containerWindow:getChildById('miniwindowScrollBar')
|
|
scrollbar:mergeStyle({ ['$disabled'] = { ['width'] = scrollbar:getWidth() } })
|
|
|
|
local upButton = containerWindow:getChildById('upButton')
|
|
upButton.onClick = function()
|
|
g_game.openParent(container)
|
|
end
|
|
upButton:setVisible(container:hasParent())
|
|
|
|
local name = container:getName()
|
|
name = name:sub(1,1):upper() .. name:sub(2)
|
|
containerWindow:setText(name)
|
|
|
|
containerItemWidget:setItem(container:getContainerItem())
|
|
|
|
containerPanel:destroyChildren()
|
|
for slot=0,container:getCapacity()-1 do
|
|
local itemWidget = g_ui.createWidget('Item', containerPanel)
|
|
itemWidget:setId('item' .. slot)
|
|
itemWidget:setItem(container:getItem(slot))
|
|
itemWidget:setMargin(3)
|
|
itemWidget.position = container:getSlotPosition(slot)
|
|
end
|
|
|
|
container.window = containerWindow
|
|
container.itemsPanel = containerPanel
|
|
end
|
|
|
|
local function onContainerClose(container)
|
|
if container.window then container.window:destroy() end
|
|
end
|
|
|
|
local function onContainerAddItem(container, slot, item)
|
|
if not container.window then return end
|
|
refreshContainerItems(container)
|
|
end
|
|
|
|
local function onContainerUpdateItem(container, slot, item, oldItem)
|
|
if not container.window then return end
|
|
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
|
itemWidget:setItem(item)
|
|
end
|
|
|
|
local function onContainerRemoveItem(container, slot, item)
|
|
if not container.window then return end
|
|
refreshContainerItems(container)
|
|
end
|
|
|
|
function Containers.init()
|
|
g_ui.importStyle('container.otui')
|
|
|
|
connect(Container, { onOpen = onContainerOpen,
|
|
onClose = onContainerClose,
|
|
onAddItem = onContainerAddItem,
|
|
onUpdateItem = onContainerUpdateItem,
|
|
onRemoveItem = onContainerRemoveItem })
|
|
connect(Game, { onGameEnd = Containers.clean() })
|
|
|
|
Containers.reloadContainers()
|
|
end
|
|
|
|
function Containers.terminate()
|
|
disconnect(Container, { onOpen = onContainerOpen,
|
|
onClose = onContainerClose,
|
|
onAddItem = onContainerAddItem,
|
|
onUpdateItem = onContainerUpdateItem,
|
|
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
|
|
|
|
function Containers.clean()
|
|
for containerid,container in pairs(g_game.getContainers()) do
|
|
if container.window then
|
|
container.window:destroy()
|
|
container.window = nil
|
|
container.itemsPanel = nil
|
|
end
|
|
end
|
|
end
|