Should check the menu category before creating a separator.

master
BenDol 10 years ago
parent 935b9e4cd6
commit 0c77179c46

@ -412,6 +412,17 @@ function startTradeWith(thing)
g_mouse.pushCursor('target') g_mouse.pushCursor('target')
end end
function isMenuHookCategoryEmpty(category)
if category and not table.empty(category) then
for _,opt in pairs(category) do
if opt and not table.empty(opt) then
return false
end
end
end
return true
end
function addMenuHook(category, name, callback, condition, shortcut) function addMenuHook(category, name, callback, condition, shortcut)
if not hookedMenuOptions[category] then if not hookedMenuOptions[category] then
hookedMenuOptions[category] = {} hookedMenuOptions[category] = {}
@ -424,7 +435,7 @@ function addMenuHook(category, name, callback, condition, shortcut)
end end
function removeMenuHook(category, name) function removeMenuHook(category, name)
hookedMenuOptions[category][name] = {} hookedMenuOptions[category][name] = nil
end end
function createThingMenu(menuPosition, lookThing, useThing, creatureThing) function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
@ -569,10 +580,12 @@ function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
-- hooked menu options -- hooked menu options
for _,category in pairs(hookedMenuOptions) do for _,category in pairs(hookedMenuOptions) do
menu:addSeparator() if not isMenuHookCategoryEmpty(category) then
for name,opt in pairs(category) do menu:addSeparator()
if opt.condition(menuPosition, lookThing, useThing, creatureThing) then for name,opt in pairs(category) do
menu:addOption(name, opt.callback, opt.shortcut) if opt and opt.condition(menuPosition, lookThing, useThing, creatureThing) then
menu:addOption(name, opt.callback, opt.shortcut)
end
end end
end end
end end

Loading…
Cancel
Save