Skip to content

Commit

Permalink
Safe widgets reordering api (#3941)
Browse files Browse the repository at this point in the history
* Add a mechanism so widgetHandler reordering api can be used safely.

* Check reordersNeeded on DrawScreen and Update, and manual reorder at
MouseMove and MouseRelease.

* Hook UpdateWidgetCallInRaw and InsertWidgetRaw methods inside profiler
widget instead of the queued methods.

* Use EnableWidgetRaw and DisableWidgetRaw inside tests.

* Cleaner way to hook PerformReorders for special methods.

* Recursive reordering to account for reorderings with further reordering
side effects.

* widgetHandler:HookReorderPostMethods -> widgetHandler:HookReorderSpecialFuncs and some comments.

* Some top level methods need returning several values.

* Just wrap two return parameters for all top level callins.
  • Loading branch information
saurtron authored Nov 20, 2024
1 parent b9b6a78 commit 154eb88
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 50 deletions.
8 changes: 4 additions & 4 deletions luaui/Widgets/Tests/cmd_blueprint/test_cmd_blueprint_line.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function setup()

initialWidgetActive = widgetHandler.knownWidgets[widgetName].active
if initialWidgetActive then
widgetHandler:DisableWidget(widgetName)
widgetHandler:DisableWidgetRaw(widgetName)
end
widgetHandler:EnableWidget(widgetName, true)
widgetHandler:EnableWidgetRaw(widgetName, true)

widget = widgetHandler:FindWidget(widgetName)
assert(widget)
Expand All @@ -29,9 +29,9 @@ end
function cleanup()
Test.clearMap()

widgetHandler:DisableWidget(widgetName)
widgetHandler:DisableWidgetRaw(widgetName)
if initialWidgetActive then
widgetHandler:EnableWidget(widgetName, false)
widgetHandler:EnableWidgetRaw(widgetName, false)
end

Spring.SetCameraState(initialCameraState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function setup()

initialWidgetActive = widgetHandler.knownWidgets[widgetName].active
if initialWidgetActive then
widgetHandler:DisableWidget(widgetName)
widgetHandler:DisableWidgetRaw(widgetName)
end
widgetHandler:EnableWidget(widgetName, true)
widgetHandler:EnableWidgetRaw(widgetName, true)

widget = widgetHandler:FindWidget(widgetName)
assert(widget)
Expand All @@ -29,9 +29,9 @@ end
function cleanup()
Test.clearMap()

widgetHandler:DisableWidget(widgetName)
widgetHandler:DisableWidgetRaw(widgetName)
if initialWidgetActive then
widgetHandler:EnableWidget(widgetName, false)
widgetHandler:EnableWidgetRaw(widgetName, false)
end

Spring.SetCameraState(initialCameraState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ function setup()

initialWidgetActive = widgetHandler.knownWidgets[widgetName].active
if initialWidgetActive then
widgetHandler:DisableWidget(widgetName)
widgetHandler:DisableWidgetRaw(widgetName)
end
widgetHandler:EnableWidget(widgetName, true)
widgetHandler:EnableWidgetRaw(widgetName, true)
end

function cleanup()
Test.clearMap()

widgetHandler:DisableWidget(widgetName)
widgetHandler:DisableWidgetRaw(widgetName)
if initialWidgetActive then
widgetHandler:EnableWidget(widgetName, false)
widgetHandler:EnableWidgetRaw(widgetName, false)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ function setup()

initialWidgetActive = widgetHandler.knownWidgets[widgetName].active
if initialWidgetActive then
widgetHandler:DisableWidget(widgetName)
widgetHandler:DisableWidgetRaw(widgetName)
end
widgetHandler:EnableWidget(widgetName, true)
widgetHandler:EnableWidgetRaw(widgetName, true)
end

function cleanup()
Test.clearMap()

widgetHandler:DisableWidget(widgetName)
widgetHandler:DisableWidgetRaw(widgetName)
if initialWidgetActive then
widgetHandler:EnableWidget(widgetName, false)
widgetHandler:EnableWidgetRaw(widgetName, false)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ function setup()

initialWidgetActive = widgetHandler.knownWidgets[widgetName].active
if initialWidgetActive then
widgetHandler:DisableWidget(widgetName)
widgetHandler:DisableWidgetRaw(widgetName)
end
widgetHandler:EnableWidget(widgetName, true)
widgetHandler:EnableWidgetRaw(widgetName, true)
end

function cleanup()
Test.clearMap()

widgetHandler:DisableWidget(widgetName)
widgetHandler:DisableWidgetRaw(widgetName)
if initialWidgetActive then
widgetHandler:EnableWidget(widgetName, false)
widgetHandler:EnableWidgetRaw(widgetName, false)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ function setup()

initialWidgetActive = widgetHandler.knownWidgets[widgetName].active
if initialWidgetActive then
widgetHandler:DisableWidget(widgetName)
widgetHandler:DisableWidgetRaw(widgetName)
end
widgetHandler:EnableWidget(widgetName, true)
widgetHandler:EnableWidgetRaw(widgetName, true)
end

function cleanup()
Test.clearMap()

widgetHandler:DisableWidget(widgetName)
widgetHandler:DisableWidgetRaw(widgetName)
if initialWidgetActive then
widgetHandler:EnableWidget(widgetName, false)
widgetHandler:EnableWidgetRaw(widgetName, false)
end
end

Expand Down
12 changes: 6 additions & 6 deletions luaui/Widgets/dbg_widget_profiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ local function StartHook()
Spring.Echo("hooked all callins")

--// hook the UpdateCallin function
oldUpdateWidgetCallIn = wh.UpdateWidgetCallIn
wh.UpdateWidgetCallIn = function(self, name, w)
oldUpdateWidgetCallIn = wh.UpdateWidgetCallInRaw
wh.UpdateWidgetCallInRaw = function(self, name, w)
local listName = name .. 'List'
local ciList = self[listName]
if ciList then
Expand All @@ -236,8 +236,8 @@ local function StartHook()
Spring.Echo("hooked UpdateCallin")

--// hook the InsertWidget function
oldInsertWidget = wh.InsertWidget
widgetHandler.InsertWidget = function(self, widget)
oldInsertWidget = wh.InsertWidgetRaw
widgetHandler.InsertWidgetRaw = function(self, widget)
if widget == nil then
return
end
Expand Down Expand Up @@ -283,9 +283,9 @@ local function StopHook()
Spring.Echo("unhooked all callins")

--// unhook the UpdateCallin and InsertWidget functions
wh.UpdateWidgetCallIn = oldUpdateWidgetCallIn
wh.UpdateWidgetCallInRaw = oldUpdateWidgetCallIn
Spring.Echo("unhooked UpdateCallin")
wh.InsertWidget = oldInsertWidget
wh.InsertWidgetRaw = oldInsertWidget
Spring.Echo("unhooked InsertWidget")
end

Expand Down
Loading

0 comments on commit 154eb88

Please sign in to comment.