local FORMAS = { 10, 5, 2, 1 } function colocarFlotante(bar) local host = bar.otmmoHost if not host or host:isDestroyed() then return end local cols = bar.otmmoColumnas or 10 local rows = math.ceil(10 / cols) local width, height = math.max(110, cols * 46 + 8), rows * 46 + 26 host:resize(width, height) bar:breakAnchors() bar:addAnchor(AnchorTop, 'parent', AnchorTop) bar:addAnchor(AnchorLeft, 'parent', AnchorLeft) bar:setMarginTop(24) bar:setMarginLeft(4) bar:resize(cols * 46, rows * 46) local tab = bar.tabBar tab:breakAnchors() tab:setMargin(0) tab:addAnchor(AnchorTop, 'parent', AnchorTop) tab:addAnchor(AnchorLeft, 'parent', AnchorLeft) tab:resize(cols * 46, rows * 46) if not bar.otmmoGrid then bar.otmmoGrid = UIGridLayout.create(tab) bar.otmmoGrid:setCellSize({ width = 46, height = 46 }) tab:setLayout(bar.otmmoGrid) end bar.otmmoGrid:setNumColumns(cols) for i, button in ipairs(tab:getChildren()) do button:setVisible(i <= 10) end bar.prevPanel:hide() bar.nextPanel:hide() host:bindRectToParent() end function instalarFlotantes() local root = modules.game_interface.getRootPanel() for i = 1, 2 do local bar = actionBars[i] if bar and not bar.otmmoHost then local host = g_ui.createWidget('Panel', root) host:setId('barraFlotante' .. i) host:setBackgroundColor(OtmmoTheme.color.bg2) host:setBorderWidth(1) host:setBorderColor(OtmmoTheme.color.border) local handle = g_ui.createWidget('UIButton', host) handle:setText('Barra ' .. i) handle:setHeight(22) handle:addAnchor(AnchorTop, 'parent', AnchorTop) handle:addAnchor(AnchorLeft, 'parent', AnchorLeft) handle:addAnchor(AnchorRight, 'parent', AnchorRight) handle:setMarginRight(28) handle:setTooltip('Arrastra para mover la barra') local shape = g_ui.createWidget('UIButton', host) shape:setText('#') shape:setSize({ width = 24, height = 22 }) shape:addAnchor(AnchorTop, 'parent', AnchorTop) shape:addAnchor(AnchorRight, 'parent', AnchorRight) shape:setTooltip('Cambiar forma: fila, dos filas, cinco filas, columna') bar.otmmoHost = host bar.otmmoColumnas = tonumber(g_settings.getString('otmmo-barra-forma-' .. i)) or 10 if not table.find(FORMAS, bar.otmmoColumnas) then bar.otmmoColumnas = 10 end -- explícita, no efectiva: con el panel del juego oculto (salir) isVisible() da false aunque la barra siga encendida local visible = bar:isExplicitlyVisible() bar:setParent(host) colocarFlotante(bar) local map = modules.game_interface.getMapPanel() host:setPosition({ x = math.max(root:getX(), map:getX() + (map:getWidth() - host:getWidth()) / 2), y = math.max(root:getY(), map:getY() + map:getHeight() - host:getHeight() - 8 - (i - 1) * 76) }) OtmmoVentanas.moverCon(host, handle, 'barra-' .. i) host:setVisible(visible) local index = i shape.onClick = function() if OtmmoVentanas.bloqueada() then return end local n = table.find(FORMAS, bar.otmmoColumnas) or 1 bar.otmmoColumnas = FORMAS[n % #FORMAS + 1] g_settings.set('otmmo-barra-forma-' .. index, bar.otmmoColumnas) colocarFlotante(bar) OtmmoVentanas.guardar(host) end connect(bar, { -- OJO: onVisibilityChange tambien llega cuando se oculta un ANTECESOR (al salir, gameRootPanel:hide()) con v=false. -- Copiar ese v dejaba el host oculto para siempre (al reentrar nadie lo volvia a mostrar). Se copia la -- visibilidad EXPLICITA de la barra, que no cambia por lo que le pase a sus padres. onVisibilityChange = function() if not host:isDestroyed() then host:setVisible(bar:isExplicitlyVisible()) end end, onDestroy = function() if not host:isDestroyed() then host:destroy() end end, }) elseif bar then -- reentrada: se reafirma el host con la visibilidad que la barra tiene ahora (ya con su juego de teclas) if bar.otmmoHost and not bar.otmmoHost:isDestroyed() then bar.otmmoHost:setVisible(bar:isExplicitlyVisible()) end colocarFlotante(bar) end end end