tibia-client/modules/core_widgets/uipopupmenu.lua

52 lines
1.2 KiB
Lua
Raw Normal View History

2012-01-02 21:46:40 +01:00
-- extends UIWidget
UIPopupMenu = extends(UIWidget)
-- public functions
function UIPopupMenu.create()
local menu = UIPopupMenu.internalCreate()
local layout = UIVerticalLayout.create(menu)
layout:setFitParent(true)
menu:setLayout(layout)
return menu
end
2012-01-02 23:09:49 +01:00
function UIPopupMenu.display(menu, pos)
displayUI(menu, {x = pos.x, y = pos.y})
2012-01-02 23:09:49 +01:00
menu:bindRectToParent()
menu:grabMouse()
menu:grabKeyboard()
2012-01-02 21:46:40 +01:00
return menu
end
2012-01-02 23:09:49 +01:00
function UIPopupMenu.addOption(menu, optionName, optionCallback)
2012-01-03 02:32:34 +01:00
local optionWidget = createWidget(menu:getStyleName() .. 'Button', menu)
2012-01-02 23:09:49 +01:00
local lastOptionWidget = menu:getLastChild()
optionWidget.onClick = function()
optionCallback()
menu:destroy()
2012-01-02 21:46:40 +01:00
end
2012-01-02 23:09:49 +01:00
optionWidget:setText(optionName)
end
function UIPopupMenu.addSeparator(menu)
2012-01-03 02:32:34 +01:00
local separatorWidget = createWidget(menu:getStyleName() .. 'Separator', separator)
2012-01-02 21:46:40 +01:00
end
2012-01-02 23:09:49 +01:00
-- hooked events
function UIPopupMenu.onMousePress(menu, mousePos, mouseButton)
-- clicks outside menu area destroys the menu
if not menu:containsPoint(mousePos) then
menu:destroy()
2012-01-02 21:46:40 +01:00
return true
end
return false
end
2012-01-02 23:09:49 +01:00
function UIPopupMenu.onKeyPress(menu, keyCode, keyText, keyboardModifiers)
if keyCode == KeyEscape then
menu:destroy()
return true
end
return false
end