feat(api)!: menu script-message changes (#653)

- `open-menu` now only opens the menu, while closing any existing one first, even if it has the same `type`.
- `update-menu` will only update a currently opened menu of the same type. If no menu is open, or current menu's type is different, it doesn't do anything.
- `close-menu [type]` can be used to close any currently opened menu when called without a `[type]` argument, or only a menu of `[type]` type.
- uosc now keeps track of a currently opened menu type on the `user-data/uosc/menu/type` property, accessible via `mp.get_property_native('user-data/uosc/menu/type')`. This property is `nil` if no uosc menu is opened.

This is to achieve a predictable and granular control of menus with no implicit magic going on in the background.

The main difference is that `open-menu` can no longer be used to toggle the menu. You have to implement toggling manually by calling `open-menu` or `close-menu [type]` when appropriate. You can check if your menu is still opened either by getting or observing the `user-data/uosc/menu/type` property, or using the `on_close` menu callback.
This commit is contained in:
christoph-heinrich
2023-09-30 17:11:37 +02:00
committed by GitHub
parent c88c476ec7
commit 512281ac4b
3 changed files with 16 additions and 9 deletions

View File

@@ -1283,8 +1283,7 @@ mp.register_script_message('open-menu', function(json, submenu_id)
if type(data) ~= 'table' or type(data.items) ~= 'table' then
msg.error('open-menu: received json didn\'t produce a table with menu configuration')
else
if data.type and Menu:is_open(data.type) then Menu:close()
else open_command_menu(data, {submenu = submenu_id, on_close = data.on_close}) end
open_command_menu(data, {submenu = submenu_id, on_close = data.on_close})
end
end)
mp.register_script_message('update-menu', function(json)
@@ -1293,10 +1292,12 @@ mp.register_script_message('update-menu', function(json)
msg.error('update-menu: received json didn\'t produce a table with menu configuration')
else
local menu = data.type and Menu:is_open(data.type)
if menu then menu:update(data)
else open_command_menu(data) end
if menu then menu:update(data) end
end
end)
mp.register_script_message('close-menu', function(type)
if Menu:is_open(type) then Menu:close() end
end)
mp.register_script_message('thumbfast-info', function(json)
local data = utils.parse_json(json)
if type(data) ~= 'table' or not data.width or not data.height then