mehah / otclient

An alternative tibia client for otserv written in C++20 and Lua, made with a modular system that uses lua scripts for ingame interface and functionality, making otclient flexible and easy to customize
Other
257 stars 196 forks source link

Widget child index desyncs when moving miniwindows in gamePanels #322

Closed BenDol closed 2 years ago

BenDol commented 2 years ago

Priority

High

Area

What happened?

The m_childIndex doesn't stay in sync, to reproduce move windows around in the gamePanels, also the leftPanel does save windows correctly or at least does not load correctly.

When you revert the change to UIWidget:getChildIndex(widget) to count the index again it works (since backwards compatibility isn't retained also)

Changing to this:

function UIMiniWindowContainer:onDrop(widget, mousePos)
  if widget.UIMiniWindowContainer then
    local oldParent = widget:getParent()
    if oldParent == self then return true end

    if oldParent then oldParent:removeChild(widget) end

    if widget.movedWidget then
      local index = widget.movedWidget:getChildIndex()
      self:insertChild(index + widget.movedIndex, widget)
    else
      self:addChild(widget)
    end

    self:fitAll(widget)
    return true
  end
end

or adding backwards compatibility:

int getChildIndex(const UIWidgetPtr& child = nullptr);

Does not solve the issues.

What OS are you seeing the problem on?

Windows

Code of Conduct

conde2 commented 2 years ago

Maybe the problem is in here:

    { // cache index
        child->m_childIndex = index + 1;
        for (size_t i = index; ++i < childrenSize;)
            m_children[i]->m_childIndex += 1;
    }

shouldn't it be i = index + 1 on the for loop?

BenDol commented 2 years ago

I think that is correct if that is in moveChildToIndex

Although when its setting its children's index it doesn't seems correct? Not sure I'll have to skim through how the indexing works.

conde2 commented 2 years ago

I think that is correct if that is in moveChildToIndex

Although when its setting its children's index it doesn't seems correct? Not sure I'll have to skim through how the indexing works.

I'm refering to the for loop in void UIWidget::insertChild(size_t index, const UIWidgetPtr& child)

But it seems to be fine, its using the pre increment there.