• 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!

setPosition of SinglelineTextEditWindow to mousePos

mar173

Member
Joined
Aug 14, 2016
Messages
34
Reaction score
18
modules/client_textedit/textedit.lua/function show

added:
activeWindow:setPosition(modules.game_interface.gameMapPanel.mousePos)

It doesn't work:( BotTextEdit onClick always creates a window in the middle of the game window.
mousePos is not nil, i tested {x=100,y=100} not working aswell.

Lua:
  activeWindow = window
  activeWindow:raise()
  activeWindow:focus()
  if g_app.isMobile() then
    window.text:focus()
    local flags = 0
    if options.multiline then
      flags = 1
    end
    g_window.showTextEditor(window:getText(), window.description:getText(), window.text:getText(), flags)
  end

  activeWindow:setPosition(modules.game_interface.gameMapPanel.mousePos)

  return activeWindow
end
 
ok working -.- a lot depends on anchors


Lua:
  activeWindow = window
  activeWindow:raise()
  activeWindow:focus()
  if g_app.isMobile() then
    window.text:focus()
    local flags = 0
    if options.multiline then
      flags = 1
    end
    g_window.showTextEditor(window:getText(), window.description:getText(), window.text:getText(), flags)
  end


  activeWindow:breakAnchors()
  --activeWindow:addAnchor(AnchorLeft, 'parent', AnchorLeft)
  --activeWindow:addAnchor(AnchorTop, 'parent', AnchorTop)
  activeWindow:setPosition(modules.game_interface.gameMapPanel.mousePos)

  return activeWindow
end
Post automatically merged:


player list.png
PlayerList - simple add with single function

Lua:
AddPlayerList('friend_list', 'Add Friend', 120, '#007A0433')
AddTabMenu('Main', {
    { 'empty5_label', nil, '' },
    { 'empty5_separator' },
})
AddPlayerList('enemy_list', 'Add Enemy', 120, '#A6000633')


Lua:
local otui = [[
ListItem < UIWidget
  background-color: alpha
  text-offset: 3 1
  focusable: true
  height: 16
  font: verdana-11px-rounded
  text-align: left

  $focus:
    background-color: #00000055

  Button
    id: remove
    !text: tr('X')
    anchors.right: parent.right
    anchors.verticalCenter: parent.verticalCenter
    width: 14
    height: 14
    margin-right: 15
    text-align: center
    text-offset: 0 1
    tooltip: Remove item from the list.
]]
g_ui.importStyleFromString(otui)

function AddPlayerList(_id, bttn_name, height, color)

    local id = _id

    if GENERAL_SETTINGS[id] == nil then
        GENERAL_SETTINGS[id] = {}
    end

    local player_list = GENERAL_SETTINGS[id]

    local ui = UIsetupUI([[
Panel
  id: ]] .. id .. '\n' .. [[
  margin: 3
  padding: 3
  height: ]] .. height .. '\n' .. [[
  background-color: ]] .. color .. '\n' .. [[

  TextList
    id: list
    height: ]] .. height - 48 .. '\n' .. [[
    anchors.left: parent.left
    anchors.right: parent.right
    anchors.top: parent.top
    vertical-scrollbar: scrollbar

  VerticalScrollBar
    id: scrollbar
    anchors.top: list.top
    anchors.bottom: list.bottom
    anchors.right: list.right
    step: 14
    pixels-scroll: true

  BotTextEdit
    id: name
    anchors.top: list.bottom
    margin-top: 3
    anchors.left: parent.left
    anchors.right: parent.right

  BotButton
    id: add
    text: ]] .. bttn_name .. '\n' .. [[
    anchors.top: prev.bottom
    margin-top: 3
    anchors.left: parent.left
    anchors.right: parent.right
    font: verdana-11px-rounded
]]   )
    local ui_list = ui.list
    local ui_name = ui.name
    local ui_add = ui.add
    local rootWidget = g_ui.getRootWidget()
    local moving_item = false

    local function addListItem(item_name)
        local name = item_name
        local label = g_ui.createWidget("ListItem", ui_list)
        label:setId('ListItem' .. name)
        label:setText(name)
        label.remove.onClick = function()
            table.remove(player_list, table.find(player_list, name))
            label:destroy()
            CONFIG:save(CONFIG_GENERAL)
        end
        label.onMousePress = function(widget, mousePos, mouseButton)
            if not moving_item and mouseButton == 1 then
                local child = rootWidget:recursiveGetChildByPos(mousePos)
                if child and widget == child then
                    --print('press', widget:getText())
                    moving_item = true
                end
            end
        end
        label.onMouseRelease = function(widget, mousePos, mouseButton)
            if moving_item and mouseButton == 1 then
                local start_item = ui_list:getFocusedChild()
                local end_item = rootWidget:recursiveGetChildByPos(mousePos)
                if start_item and end_item and start_item ~= end_item and start_item == widget and
                    start_item:getId():find('ListItem') and end_item:getId():find('ListItem') then
                    local start_index = ui_list:getChildIndex(start_item)
                    local end_index = ui_list:getChildIndex(end_item)
                    ui_list:moveChildToIndex(start_item, end_index)
                    ui_list:ensureChildVisible(start_item)
                    ui_list:moveChildToIndex(end_item, start_index)
                    ui_list:ensureChildVisible(end_item)
                    player_list[start_index] = end_item:getText()
                    player_list[end_index] = start_item:getText()
                    CONFIG:save(CONFIG_GENERAL)
                end
                moving_item = false
            end
        end
        CONFIG:save(CONFIG_GENERAL)
    end

    for _, item_name in ipairs(player_list) do
        addListItem(item_name)
    end

    ui_add.onClick = function()
        local names = string.split(ui_name:getText(), ",")
        if #names == 0 then
            print("MKBot[PlayerList]: Name is missing!")
            return
        end
        for i = 1, #names do
            local name = names[i]:trim()
            if name:len() == 0 then
                print("MKBot[PlayerList]: Name is missing!")
            else
                if not table.find(player_list, name) then
                    table.insert(player_list, name)
                    addListItem(name)
                    ui_name:setText("")
                else
                    print("MKBot[PlayerList]: Player " .. name .. " is already added!")
                    ui_name:setText("")
                end
            end
        end
    end
end
 
Last edited:
better solution:

Lua:
  activeWindow:breakAnchors()
  activeWindow:setPosition(g_window.getMousePosition())

or

Lua:
  activeWindow:breakAnchors()
  activeWindow:addAnchor(AnchorLeft, 'parent', AnchorLeft)
  activeWindow:addAnchor(AnchorTop, 'parent', AnchorTop)
  activeWindow:setMarginLeft(g_window.getMousePosition().x)
  activeWindow:setMarginTop(g_window.getMousePosition().y)
 
Back
Top