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

OTClient How to add a label or code to disable resize windows?

johnsamir

Advanced OT User
Joined
Oct 13, 2009
Messages
847
Solutions
6
Reaction score
151
Location
Nowhere
Hello i have been modifying trade windows size, i won't want it to be shrinked or resized by player, how do i add a label into the code to prevent this or where should i look? i was looking at tradewindows.otui but can't see the piece of code
Lua:
TradeWindow < MiniWindow
  !text: tr('Trade')
  height: 115

  UIItem
    id: tradeItem
    virtual: true
    size: 16 16
    anchors.top: parent.top
    anchors.left: parent.left
    margin-top: 4
    margin-left: 4

  MiniWindowContents
    padding: 2
    
    Label
      id: ownTradeLabel
      anchors.top: parent.top
      anchors.left: parent.left
      anchors.right: parent.horizontalCenter

    Label
      id: counterTradeLabel
      anchors.top: parent.top
      anchors.left: parent.horizontalCenter
      anchors.right: parent.right

    Label
      id: ownTradeCountLabel
      anchors.top: ownTradeLabel.bottom
      anchors.left: ownTradeLabel.left
      anchors.right: ownTradeLabel.right
      font: verdana-9px-bold
      text-align: center

    Label
      id: counterTradeCountLabel
      anchors.top: counterTradeLabel.bottom
      anchors.left: counterTradeLabel.left
      anchors.right: counterTradeLabel.right
      font: verdana-9px-bold
      text-align: center

    ScrollableFlatPanel
      id: ownTradeContainer
      anchors.top: ownTradeCountLabel.bottom
      anchors.bottom: acceptButton.top
      anchors.left: ownTradeCountLabel.left
      anchors.right: ownTradeCountLabel.right
      margin-bottom: 3
      padding: 2
      layout:
        type: grid
        cell-size: 34 34
        flow: false
        cell-spacing: 1
      vertical-scrollbar: ownTradeScrollBar

    VerticalScrollBar
      id: ownTradeScrollBar
      anchors.top: ownTradeContainer.top
      anchors.bottom: ownTradeContainer.bottom
      anchors.right: parent.horizontalCenter
      step: 14
      pixels-scroll: true
      $!on:
        width: 0

    ScrollableFlatPanel
      id: counterTradeContainer
      anchors.top: counterTradeCountLabel.bottom
      anchors.bottom: acceptButton.top
      anchors.left: counterTradeCountLabel.left
      anchors.right: counterTradeCountLabel.right
      margin-bottom: 3
      padding: 2
      layout:
        type: grid
        cell-size: 34 34
        flow: true
        cell-spacing:
      vertical-scrollbar: counterTradeScrollBar

    VerticalScrollBar
      id: counterTradeScrollBar
      anchors.top: counterTradeContainer.top
      anchors.bottom: counterTradeContainer.bottom
      anchors.right: parent.right
      step: 14
      pixels-scroll: true
      $!on:
        width: 0

    Button
      !text: tr('Accept')
      id: acceptButton
      anchors.bottom: parent.bottom
      anchors.left: parent.left
      anchors.right: parent.horizontalCenter
      margin-right: 2
      enabled: false
      @onClick: g_game.acceptTrade(); self:disable()

    Button
      !text: tr('Reject')
      id: rejectButton
      anchors.bottom: parent.bottom
      anchors.right: parent.right
      anchors.left: parent.horizontalCenter
      margin-left: 2
      @onClick: g_game.rejectTrade()
 
Hello i have been modifying trade windows size, i won't want it to be shrinked or resized by player, how do i add a label into the code to prevent this or where should i look? i was looking at tradewindows.otui but can't see the piece of code
Lua:
TradeWindow < MiniWindow
  !text: tr('Trade')
  height: 115

  UIItem
    id: tradeItem
    virtual: true
    size: 16 16
    anchors.top: parent.top
    anchors.left: parent.left
    margin-top: 4
    margin-left: 4

  MiniWindowContents
    padding: 2
   
    Label
      id: ownTradeLabel
      anchors.top: parent.top
      anchors.left: parent.left
      anchors.right: parent.horizontalCenter

    Label
      id: counterTradeLabel
      anchors.top: parent.top
      anchors.left: parent.horizontalCenter
      anchors.right: parent.right

    Label
      id: ownTradeCountLabel
      anchors.top: ownTradeLabel.bottom
      anchors.left: ownTradeLabel.left
      anchors.right: ownTradeLabel.right
      font: verdana-9px-bold
      text-align: center

    Label
      id: counterTradeCountLabel
      anchors.top: counterTradeLabel.bottom
      anchors.left: counterTradeLabel.left
      anchors.right: counterTradeLabel.right
      font: verdana-9px-bold
      text-align: center

    ScrollableFlatPanel
      id: ownTradeContainer
      anchors.top: ownTradeCountLabel.bottom
      anchors.bottom: acceptButton.top
      anchors.left: ownTradeCountLabel.left
      anchors.right: ownTradeCountLabel.right
      margin-bottom: 3
      padding: 2
      layout:
        type: grid
        cell-size: 34 34
        flow: false
        cell-spacing: 1
      vertical-scrollbar: ownTradeScrollBar

    VerticalScrollBar
      id: ownTradeScrollBar
      anchors.top: ownTradeContainer.top
      anchors.bottom: ownTradeContainer.bottom
      anchors.right: parent.horizontalCenter
      step: 14
      pixels-scroll: true
      $!on:
        width: 0

    ScrollableFlatPanel
      id: counterTradeContainer
      anchors.top: counterTradeCountLabel.bottom
      anchors.bottom: acceptButton.top
      anchors.left: counterTradeCountLabel.left
      anchors.right: counterTradeCountLabel.right
      margin-bottom: 3
      padding: 2
      layout:
        type: grid
        cell-size: 34 34
        flow: true
        cell-spacing:
      vertical-scrollbar: counterTradeScrollBar

    VerticalScrollBar
      id: counterTradeScrollBar
      anchors.top: counterTradeContainer.top
      anchors.bottom: counterTradeContainer.bottom
      anchors.right: parent.right
      step: 14
      pixels-scroll: true
      $!on:
        width: 0

    Button
      !text: tr('Accept')
      id: acceptButton
      anchors.bottom: parent.bottom
      anchors.left: parent.left
      anchors.right: parent.horizontalCenter
      margin-right: 2
      enabled: false
      @onClick: g_game.acceptTrade(); self:disable()

    Button
      !text: tr('Reject')
      id: rejectButton
      anchors.bottom: parent.bottom
      anchors.right: parent.right
      anchors.left: parent.horizontalCenter
      margin-left: 2
      @onClick: g_game.rejectTrade()

You need to put it in Lua within the init() function.
Something like:

Lua:
window = g_ui.loadUI('window')
window:disableResize()

I just cannot show you how exactly to do it because you didn't show your module's Lua code.
You need to show the file modules/game_playertrade/playertrade.lua if you want to know how exactly to do it.
 
You need to put it in Lua within the init() function.
Something like:

Lua:
window = g_ui.loadUI('window')
window:disableResize()

I just cannot show you how exactly to do it because you didn't show your module's Lua code.
You need to show the file modules/game_playertrade/playertrade.lua if you want to know how exactly to do it.
Hello man, sorry i didn't think that it must be handled in lua that why i did not upload the file here is playertrade.lua
Lua:
tradeWindow = nil

function init()
  g_ui.importStyle('tradewindow')

  connect(g_game, { onOwnTrade = onGameOwnTrade,
                    onCounterTrade = onGameCounterTrade,
                    onCloseTrade = onGameCloseTrade,
                    onGameEnd = onGameCloseTrade })
end

function terminate()
  disconnect(g_game, { onOwnTrade = onGameOwnTrade,
                       onCounterTrade = onGameCounterTrade,
                       onCloseTrade = onGameCloseTrade,
                       onGameEnd = onGameCloseTrade })

  if tradeWindow then
    tradeWindow:destroy()
  end
end

function createTrade()
  tradeWindow = g_ui.createWidget('TradeWindow', modules.game_interface.getRightPanel())
  tradeWindow.onClose = function()
    g_game.rejectTrade()
    tradeWindow:hide()
  end
  tradeWindow:setup()
end

function fillTrade(name, items, counter)
  if not tradeWindow then
    createTrade()
  end

  local tradeItemWidget = tradeWindow:getChildById('tradeItem')
  tradeItemWidget:setItemId(items[1]:getId())

  local tradeContainer
  local label
  local countLabel
  if counter then
    tradeContainer = tradeWindow:recursiveGetChildById('counterTradeContainer')
    label = tradeWindow:recursiveGetChildById('counterTradeLabel')
    countLabel = tradeWindow:recursiveGetChildById('counterTradeCountLabel')
    tradeWindow:recursiveGetChildById('acceptButton'):enable()
  else
    tradeContainer = tradeWindow:recursiveGetChildById('ownTradeContainer')
    label = tradeWindow:recursiveGetChildById('ownTradeLabel')
    countLabel = tradeWindow:recursiveGetChildById('ownTradeCountLabel')
  end
  label:setText(name)
  countLabel:setText(tr("Items") .. ": " .. #items)
 

  for index,item in ipairs(items) do
    local itemWidget = g_ui.createWidget('Item', tradeContainer)
    itemWidget:setItem(item)
    itemWidget:setVirtual(true)
    itemWidget:setMargin(0)
    itemWidget.onClick = function()
      g_game.inspectTrade(counter, index-1)
    end
  end
end

function onGameOwnTrade(name, items)
  fillTrade(name, items, false)
end

function onGameCounterTrade(name, items)
  fillTrade(name, items, true)
end

function onGameCloseTrade()
  if tradeWindow then
    tradeWindow:destroy()
    tradeWindow = nil
  end
end
 
Hello man, sorry i didn't think that it must be handled in lua that why i did not upload the file here is playertrade.lua
Lua:
tradeWindow = nil

function init()
  g_ui.importStyle('tradewindow')

  connect(g_game, { onOwnTrade = onGameOwnTrade,
                    onCounterTrade = onGameCounterTrade,
                    onCloseTrade = onGameCloseTrade,
                    onGameEnd = onGameCloseTrade })
end

function terminate()
  disconnect(g_game, { onOwnTrade = onGameOwnTrade,
                       onCounterTrade = onGameCounterTrade,
                       onCloseTrade = onGameCloseTrade,
                       onGameEnd = onGameCloseTrade })

  if tradeWindow then
    tradeWindow:destroy()
  end
end

function createTrade()
  tradeWindow = g_ui.createWidget('TradeWindow', modules.game_interface.getRightPanel())
  tradeWindow.onClose = function()
    g_game.rejectTrade()
    tradeWindow:hide()
  end
  tradeWindow:setup()
end

function fillTrade(name, items, counter)
  if not tradeWindow then
    createTrade()
  end

  local tradeItemWidget = tradeWindow:getChildById('tradeItem')
  tradeItemWidget:setItemId(items[1]:getId())

  local tradeContainer
  local label
  local countLabel
  if counter then
    tradeContainer = tradeWindow:recursiveGetChildById('counterTradeContainer')
    label = tradeWindow:recursiveGetChildById('counterTradeLabel')
    countLabel = tradeWindow:recursiveGetChildById('counterTradeCountLabel')
    tradeWindow:recursiveGetChildById('acceptButton'):enable()
  else
    tradeContainer = tradeWindow:recursiveGetChildById('ownTradeContainer')
    label = tradeWindow:recursiveGetChildById('ownTradeLabel')
    countLabel = tradeWindow:recursiveGetChildById('ownTradeCountLabel')
  end
  label:setText(name)
  countLabel:setText(tr("Items") .. ": " .. #items)
 

  for index,item in ipairs(items) do
    local itemWidget = g_ui.createWidget('Item', tradeContainer)
    itemWidget:setItem(item)
    itemWidget:setVirtual(true)
    itemWidget:setMargin(0)
    itemWidget.onClick = function()
      g_game.inspectTrade(counter, index-1)
    end
  end
end

function onGameOwnTrade(name, items)
  fillTrade(name, items, false)
end

function onGameCounterTrade(name, items)
  fillTrade(name, items, true)
end

function onGameCloseTrade()
  if tradeWindow then
    tradeWindow:destroy()
    tradeWindow = nil
  end
end

Change it:

Lua:
function createTrade()
  tradeWindow = g_ui.createWidget('TradeWindow', modules.game_interface.getRightPanel())
  tradeWindow.onClose = function()
    g_game.rejectTrade()
    tradeWindow:hide()
  end
  tradeWindow:setup()
end

To:

Lua:
function createTrade()
  tradeWindow = g_ui.createWidget('TradeWindow', modules.game_interface.getRightPanel())
  tradeWindow.onClose = function()
    g_game.rejectTrade()
    tradeWindow:hide()
  end
  tradeWindow:setup()
  tradeWindow:disableResize()
end
 
Change it:

Lua:
function createTrade()
  tradeWindow = g_ui.createWidget('TradeWindow', modules.game_interface.getRightPanel())
  tradeWindow.onClose = function()
    g_game.rejectTrade()
    tradeWindow:hide()
  end
  tradeWindow:setup()
end

To:

Lua:
function createTrade()
  tradeWindow = g_ui.createWidget('TradeWindow', modules.game_interface.getRightPanel())
  tradeWindow.onClose = function()
    g_game.rejectTrade()
    tradeWindow:hide()
  end
  tradeWindow:setup()
  tradeWindow:disableResize()
end
thanks bro, it works, this block all kinds of resizing without this the trade windows can by shrinked 100% i want it to be shrinked until it display at least 1 square and nothing more than that is it possible? for examples backpack can be shrinked till certain point 1 sqauare line, im looking for something similar
Lua:
TradeWindow < MiniWindow
  !text: tr('Trade')
  height: 115

  UIItem
    id: tradeItem
    virtual: true
    size: 16 16
    anchors.top: parent.top
    anchors.left: parent.left
    margin-top: 4
    margin-left: 4

  MiniWindowContents
    padding: 2
 
    Label
      id: ownTradeLabel
      anchors.top: parent.top
      anchors.left: parent.left
      anchors.right: parent.horizontalCenter

    Label
      id: counterTradeLabel
      anchors.top: parent.top
      anchors.left: parent.horizontalCenter
      anchors.right: parent.right

    Label
      id: ownTradeCountLabel
      anchors.top: ownTradeLabel.bottom
      anchors.left: ownTradeLabel.left
      anchors.right: ownTradeLabel.right
      font: verdana-9px-bold
      text-align: center

    Label
      id: counterTradeCountLabel
      anchors.top: counterTradeLabel.bottom
      anchors.left: counterTradeLabel.left
      anchors.right: counterTradeLabel.right
      font: verdana-9px-bold
      text-align: center

    ScrollableFlatPanel
      id: ownTradeContainer
      anchors.top: ownTradeCountLabel.bottom
      anchors.bottom: acceptButton.top
      anchors.left: ownTradeCountLabel.left
      anchors.right: ownTradeCountLabel.right
      margin-bottom: 3
      padding: 2
      layout:
        type: grid
        cell-size: 34 34
        flow: true
        cell-spacing: 1
      vertical-scrollbar: ownTradeScrollBar

    VerticalScrollBar
      id: ownTradeScrollBar
      anchors.top: ownTradeContainer.top
      anchors.bottom: ownTradeContainer.bottom
      anchors.right: parent.horizontalCenter
      step: 34
      pixels-scroll: true
      $!on:
        width: 0

    ScrollableFlatPanel
      id: counterTradeContainer
      anchors.top: counterTradeCountLabel.bottom
      anchors.bottom: acceptButton.top
      anchors.left: counterTradeCountLabel.left
      anchors.right: counterTradeCountLabel.right
      margin-bottom: 3
      padding: 2
      layout:
        type: grid
        cell-size: 34 34
        flow: true
        cell-spacing:
      vertical-scrollbar: counterTradeScrollBar

    VerticalScrollBar
      id: counterTradeScrollBar
      anchors.top: counterTradeContainer.top
      anchors.bottom: counterTradeContainer.bottom
      anchors.right: parent.right
      step: 14
      pixels-scroll: true
      $!on:
        width: 0

    Button
      !text: tr('Accept')
      id: acceptButton
      anchors.bottom: parent.bottom
      anchors.left: parent.left
      anchors.right: parent.horizontalCenter
      margin-right: 2
      enabled: false
      @onClick: g_game.acceptTrade(); self:disable()

    Button
      !text: tr('Reject')
      id: rejectButton
      anchors.bottom: parent.bottom
      anchors.right: parent.right
      anchors.left: parent.horizontalCenter
      margin-left: 2
      @onClick: g_game.rejectTrade()

I don't want it to be able to shrink more than what is displayed in the picture but if player want to resize to view more items they shouldn't get problem, i don't know if you get me
 
Last edited:
thanks bro, it works, this block all kinds of resizing without this the trade windows can by shrinked 100% i want it to be shrinked until it display at least 1 square and nothing more than that is it possible? for examples backpack can be shrinked till certain point 1 sqauare line, im looking for something similar
Lua:
TradeWindow < MiniWindow
  !text: tr('Trade')
  height: 115

  UIItem
    id: tradeItem
    virtual: true
    size: 16 16
    anchors.top: parent.top
    anchors.left: parent.left
    margin-top: 4
    margin-left: 4

  MiniWindowContents
    padding: 2
 
    Label
      id: ownTradeLabel
      anchors.top: parent.top
      anchors.left: parent.left
      anchors.right: parent.horizontalCenter

    Label
      id: counterTradeLabel
      anchors.top: parent.top
      anchors.left: parent.horizontalCenter
      anchors.right: parent.right

    Label
      id: ownTradeCountLabel
      anchors.top: ownTradeLabel.bottom
      anchors.left: ownTradeLabel.left
      anchors.right: ownTradeLabel.right
      font: verdana-9px-bold
      text-align: center

    Label
      id: counterTradeCountLabel
      anchors.top: counterTradeLabel.bottom
      anchors.left: counterTradeLabel.left
      anchors.right: counterTradeLabel.right
      font: verdana-9px-bold
      text-align: center

    ScrollableFlatPanel
      id: ownTradeContainer
      anchors.top: ownTradeCountLabel.bottom
      anchors.bottom: acceptButton.top
      anchors.left: ownTradeCountLabel.left
      anchors.right: ownTradeCountLabel.right
      margin-bottom: 3
      padding: 2
      layout:
        type: grid
        cell-size: 34 34
        flow: true
        cell-spacing: 1
      vertical-scrollbar: ownTradeScrollBar

    VerticalScrollBar
      id: ownTradeScrollBar
      anchors.top: ownTradeContainer.top
      anchors.bottom: ownTradeContainer.bottom
      anchors.right: parent.horizontalCenter
      step: 34
      pixels-scroll: true
      $!on:
        width: 0

    ScrollableFlatPanel
      id: counterTradeContainer
      anchors.top: counterTradeCountLabel.bottom
      anchors.bottom: acceptButton.top
      anchors.left: counterTradeCountLabel.left
      anchors.right: counterTradeCountLabel.right
      margin-bottom: 3
      padding: 2
      layout:
        type: grid
        cell-size: 34 34
        flow: true
        cell-spacing:
      vertical-scrollbar: counterTradeScrollBar

    VerticalScrollBar
      id: counterTradeScrollBar
      anchors.top: counterTradeContainer.top
      anchors.bottom: counterTradeContainer.bottom
      anchors.right: parent.right
      step: 14
      pixels-scroll: true
      $!on:
        width: 0

    Button
      !text: tr('Accept')
      id: acceptButton
      anchors.bottom: parent.bottom
      anchors.left: parent.left
      anchors.right: parent.horizontalCenter
      margin-right: 2
      enabled: false
      @onClick: g_game.acceptTrade(); self:disable()

    Button
      !text: tr('Reject')
      id: rejectButton
      anchors.bottom: parent.bottom
      anchors.right: parent.right
      anchors.left: parent.horizontalCenter
      margin-left: 2
      @onClick: g_game.rejectTrade()

I don't want it to be able to shrink more than what is displayed in the picture but if player want to resize to view more items they shouldn't get problem, i don't know if you get me

Change it:

Lua:
function createTrade()
  tradeWindow = g_ui.createWidget('TradeWindow', modules.game_interface.getRightPanel())
  tradeWindow.onClose = function()
    g_game.rejectTrade()
    tradeWindow:hide()
  end
  tradeWindow:setup()
end

To:

Lua:
function createTrade()
  tradeWindow = g_ui.createWidget('TradeWindow', modules.game_interface.getRightPanel())
  tradeWindow.onClose = function()
    g_game.rejectTrade()
    tradeWindow:hide()
  end
  tradeWindow:setContentMinimumHeight( ADD_HERE_THE_SIZE_THAT_YOU_WANT_AS_MINIMUM )
  tradeWindow:setup()
  tradeWindow:setHeight( ADD_HERE_THE_SIZE_THAT_YOU_WANT_AS_FIRST )
end
 
Last edited:
Back
Top