buttonsWindow = nil contentsPanel = nil function init() buttonsWindow = g_ui.loadUI('buttons', modules.game_interface.getRightPanel()) if not buttonsWindow then return end buttonsWindow:disableResize() buttonsWindow:setup() buttonsWindow:setHeight(48) contentsPanel = buttonsWindow.contentsPanel if not contentsPanel or not buttonsWindow.forceOpen or not contentsPanel.buttons then buttonsWindow:close() end end function terminate() if buttonsWindow then buttonsWindow:destroy() buttonsWindow = nil end end function takeButtons(buttons) if not buttonsWindow.forceOpen or not contentsPanel.buttons then return end for i, button in ipairs(buttons) do takeButton(button, true) end updateOrder() end function takeButton(button, dontUpdateOrder) if not buttonsWindow.forceOpen or not contentsPanel.buttons then return end button:setParent(contentsPanel.buttons) if not dontUpdateOrder then updateOrder() end end function updateOrder() local children = contentsPanel.buttons:getChildren() table.sort(children, function(a, b) return (a.index or 1000) < (b.index or 1000) end) contentsPanel.buttons:reorderChildren(children) local visibleCount = 0 for _, child in ipairs(children) do if child:isVisible() then visibleCount = visibleCount + 1 end end if visibleCount > 6 and buttonsWindow:getHeight() < 52 then buttonsWindow:setHeight(70) end end function onToggleButtonClick(button) local function toggleButtonsVisibility(value) for _, child in ipairs(buttonsWindow:getChildren()) do if child:getId() ~= "storeButton" and child:getId() ~= "toggleButton" then child:setVisible(value) end end if value then buttonsWindow:setHeight(70) else buttonsWindow:setHeight(48) end end if button:isOn() then button:setOn(false) toggleButtonsVisibility(false) else button:setOn(true) toggleButtonsVisibility(true) end end