Should check the menu category before creating a separator.

This commit is contained in:
BenDol 2014-07-13 22:57:45 +12:00
parent 935b9e4cd6
commit 0c77179c46
1 changed files with 18 additions and 5 deletions

View File

@ -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,13 +580,15 @@ function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
-- hooked menu options -- hooked menu options
for _,category in pairs(hookedMenuOptions) do for _,category in pairs(hookedMenuOptions) do
if not isMenuHookCategoryEmpty(category) then
menu:addSeparator() menu:addSeparator()
for name,opt in pairs(category) do for name,opt in pairs(category) do
if opt.condition(menuPosition, lookThing, useThing, creatureThing) then if opt and opt.condition(menuPosition, lookThing, useThing, creatureThing) then
menu:addOption(name, opt.callback, opt.shortcut) menu:addOption(name, opt.callback, opt.shortcut)
end end
end end
end end
end
menu:display(menuPosition) menu:display(menuPosition)
end end