• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

how to make a MiniWindow spawns in the middle?

sabodden

Member
Joined
Sep 27, 2019
Messages
138
Reaction score
18
I have this UI:
Code:
MiniWindow
  id: mainWindow
  width: 625
  height: 160
  top: 100
  bottom: 100
  left: 100
  right: 100
  @onClose: modules.game_minimap.onMiniWindowClose()

but when i show it
it always comes on top left

how to make it always spawn in the middle of screen? on the center...
 
Lua:
local testWindowWidth = testWindow:getWidth() / 2
local testWindowHeight = testWindow:getHeight() / 2
local pos = {x = (g_window.getWidth() / 2) - testWindowWidth, y = (g_window.getHeight() / 2) - testWindowHeight}
testWindow:setPosition(pos)
 
Lua:
local testWindowWidth = testWindow:getWidth() / 2
local testWindowHeight = testWindow:getHeight() / 2
local pos = {x = (g_window.getWidth() / 2) - testWindowWidth, y = (g_window.getHeight() / 2) - testWindowHeight}
testWindow:setPosition(pos)

Lol i think that is the way!!! TY

It change the position, but don't put in the center horizontal/vertical, did u know why?
 
Don't know why, when I printed g_window.getWidth() having "full screened" the client, it shows that height is 1440px when in fact it is 1920px. After reloading the module it works as it should and prints 1920px :l.

It's because of this line g_window.setMinimumSize({ width = 800, height = 600 }) inside client.lua (I had 1440x950 that's why it printed 1440px). Don't know why it takes minimumSize instead of actual size of window.
 
Last edited:
anchors.centerIn: parent

or

anchors.horizontalcenter: parent.horizontalcenter
anchors.verticalcenter: parent.verticalcenter

And show us how are you create a window
 
Don't know why, when I printed g_window.getWidth() having "full screened" the client, it shows that height is 1440px when in fact it is 1920px. After reloading the module it works as it should and prints 1920px :l.

It's because of this line g_window.setMinimumSize({ width = 800, height = 600 }) inside client.lua (I had 1440x950 that's why it printed 1440px). Don't know why it takes minimumSize instead of actual size of window.

:(

sad, same here, only works if i reload the modules


anchors.centerIn: parent

or

anchors.horizontalcenter: parent.horizontalcenter
anchors.verticalcenter: parent.verticalcenter

And show us how are you create a window


if i do
anchors.centerIn: parent

or

anchors.horizontalcenter: parent.horizontalcenter
anchors.verticalcenter: parent.verticalcenter

it works, put in the center, but i cant move the window and i want to be able to move the window where i want to, just want the first spawn in the center
 
So, show me how do you create a window, are you using g_ui.createWidget or g_ui.displayUI?


Code:
mainWindow = g_ui.displayUI('main.otui')

Code:
function init()
    mainWindow = nil
    mainButton = nil

    g_keyboard.bindKeyDown('Shift+F12', onoff)

    mainWindow = g_ui.displayUI('main.otui')

    SpawnsInCenter(mainWindow)

    mainWindow:hide()
    mainWindow:recursiveGetChildById('minimizeButton'):hide()
end

function terminate()
    g_keyboard.unbindKeyDown('Shift+F12')
    mainWindow:hide()
end

function onoff()
    if mainWindow:isVisible() then
        mainWindow:hide()
    else
        mainWindow:show()
    end
end

function SpawnsInCenter(mainWindow)
    local screen_width = mainWindow:getWidth() / 2
    local screen_height = mainWindow:getHeight() / 2
    local pos = {x = (g_window.getWidth() / 2) - screen_width, y = (g_window.getHeight() / 2) - screen_height}
    mainWindow:setPosition(pos)
end
 
Lua:
UIWindow
  id: protected15
  anchors.centerIn: parent
  size: 971 625
  phantom: false

This is .otui code, probably you're not using UIWindow style but UIWidget
 
i dont get your point...
anchors.centerIn: parent
was working before
the problem is when i use anchors i cant move the window around
 
Lua:
UIWindow
  id: protected15
  anchors.centerIn: parent
  size: 971 625
  phantom: false

This is .otui code, probably you're not using UIWindow style but UIWidget
MiniWindow inherits UIMiniWindow which is draggable.
 
Doesn't matter, they still can be moved. All the windows in left/right panels are MiniWindow.

Under mainWindow = g_ui.displayUI('main.otui') add mainWindow:breakAnchors(), now it's centered and you can move it around.

THANK YOU, how can i give him best answer?
 
Back
Top