Improvements to popupmenus, fix #245 and #246

master
Eduardo Bart 11 years ago
parent 835adfb4ce
commit 7e01306fc6

@ -1,17 +1,9 @@
PopupMenuButton < UIButton
height: 18
margin-left: 5
margin-right: 5
margin-top: 1
margin-bottom: 1
size: 0 21
text-offset: 0 0
text-offset: 4 0
text-align: left
font: verdana-11px-antialised
image-source: /images/ui/button_popupmenu
image-color: white
image-clip: 0 0 20 20
image-border: 2
color: #aaaaaa
background-color: alpha
@ -24,6 +16,13 @@ PopupMenuButton < UIButton
$disabled:
color: #555555
PopupMenuShortcutLabel < Label
font: verdana-11px-antialised
text-align: right
anchors.fill: parent
margin-right: 2
margin-left: 5
PopupMenuSeparator < UIWidget
margin-left: 2
margin-right: 2
@ -39,5 +38,4 @@ PopupMenu < UIPopupMenu
width: 50
image-source: /images/ui/menubox
image-border: 3
padding-top: 3
padding-bottom: 3
padding: 3

@ -33,11 +33,23 @@ function UIPopupMenu:display(pos)
currentMenu = self
end
function UIPopupMenu:onGeometryChange()
function UIPopupMenu:onGeometryChange(oldRect, newRect)
local parent = self:getParent()
if not parent then return end
local ymax = parent:getY() + parent:getHeight()
local xmax = parent:getX() + parent:getWidth()
if newRect.y + newRect.height > ymax then
local newy = newRect.y - newRect.height
if newy > 0 and newy + newRect.height < ymax then self:setY(newy) end
end
if newRect.x + newRect.width > xmax then
local newx = newRect.x - newRect.width
if newx > 0 and newx + newRect.width < xmax then self:setX(newx) end
end
self:bindRectToParent()
end
function UIPopupMenu:addOption(optionName, optionCallback)
function UIPopupMenu:addOption(optionName, optionCallback, shortcut)
local optionWidget = g_ui.createWidget(self:getStyleName() .. 'Button', self)
local lastOptionWidget = self:getLastChild()
optionWidget.onClick = function(self)
@ -46,6 +58,13 @@ function UIPopupMenu:addOption(optionName, optionCallback)
end
optionWidget:setText(optionName)
local width = optionWidget:getTextSize().width + optionWidget:getMarginLeft() + optionWidget:getMarginRight() + 15
if shortcut then
local shortcutLabel = g_ui.createWidget(self:getStyleName() .. 'ShortcutLabel', optionWidget)
shortcutLabel:setText(shortcut)
width = width + shortcutLabel:getTextSize().width + shortcutLabel:getMarginLeft() + shortcutLabel:getMarginRight()
end
self:setWidth(math.max(self:getWidth(), width))
end

@ -433,7 +433,7 @@ function addTabText(text, speaktype, tab, creatureName)
end
label.onMouseRelease = function (self, mousePos, mouseButton)
processMessageMenu(mousePos, mouseButton, creatureName, text)
processMessageMenu(mousePos, mouseButton, creatureName, text, self)
end
if consoleBuffer:getChildCount() > MAX_LINES then
@ -460,7 +460,7 @@ function processChannelTabMenu(tab, mousePos, mouseButton)
menu:display(mousePos)
end
function processMessageMenu(mousePos, mouseButton, creatureName, text)
function processMessageMenu(mousePos, mouseButton, creatureName, text, label)
if mouseButton == MouseRightButton then
local menu = g_ui.createWidget('PopupMenu')
if creatureName then
@ -481,20 +481,18 @@ function processMessageMenu(mousePos, mouseButton, creatureName, text)
end
menu:addSeparator()
end
--TODO select all
menu:addOption(tr('Copy message'), function () g_window.setClipboardText(text) end)
if modules.game_ruleviolation.hasWindowAccess() then
menu:addSeparator()
menu:addOption(tr('Rule Violation'), function() modules.game_ruleviolation.show(creatureName, text:match('.+%:%s(.+)')) end)
menu:addSeparator()
end
menu:addSeparator()
menu:addOption(tr('Copy name'), function () g_window.setClipboardText(creatureName) end)
else
--TODO select all
menu:addOption(tr('Copy message'), function () g_window.setClipboardText(text) end)
end
if label:hasSelection() then
menu:addOption(tr('Copy'), function() g_window.setClipboardText(label:getSelection()) end, '(Ctrl+C)')
end
menu:addOption(tr('Copy message'), function() g_window.setClipboardText(text) end)
menu:addOption(tr('Select all'), function() label:selectAll() end)
menu:display(mousePos)
end
end

@ -344,24 +344,28 @@ end
function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
if not g_game.isOnline() then return end
local menu = g_ui.createWidget('PopupMenu')
local classic = modules.client_options.getOption('classicControl')
local shortcut = nil
if not classic then shortcut = '(Shift)' else shortcut = nil end
if lookThing then
menu:addOption(tr('Look'), function() g_game.look(lookThing) end)
menu:addOption(tr('Look'), function() g_game.look(lookThing) end, shortcut)
end
if not classic then shortcut = '(Ctrl)' else shortcut = nil end
if useThing then
if useThing:isContainer() then
if useThing:getParentContainer() then
menu:addOption(tr('Open'), function() g_game.open(useThing, useThing:getParentContainer()) end)
menu:addOption(tr('Open'), function() g_game.open(useThing, useThing:getParentContainer()) end, shortcut)
menu:addOption(tr('Open in new window'), function() g_game.open(useThing) end)
else
menu:addOption(tr('Open'), function() g_game.open(useThing) end)
menu:addOption(tr('Open'), function() g_game.open(useThing) end, shortcut)
end
else
if useThing:isMultiUse() then
menu:addOption(tr('Use with ...'), function() startUseWith(useThing) end)
menu:addOption(tr('Use with ...'), function() startUseWith(useThing) end, shortcut)
else
menu:addOption(tr('Use'), function() g_game.use(useThing) end)
menu:addOption(tr('Use'), function() g_game.use(useThing) end, shortcut)
end
end
@ -410,10 +414,11 @@ function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
end
else
if not classic then shortcut = '(Alt)' else shortcut = nil end
if g_game.getAttackingCreature() ~= creatureThing then
menu:addOption(tr('Attack'), function() g_game.attack(creatureThing) end)
menu:addOption(tr('Attack'), function() g_game.attack(creatureThing) end, shortcut)
else
menu:addOption(tr('Stop Attack'), function() g_game.cancelAttack() end)
menu:addOption(tr('Stop Attack'), function() g_game.cancelAttack() end, shortcut)
end
if g_game.getFollowingCreature() ~= creatureThing then
@ -472,7 +477,6 @@ function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
menu:addSeparator()
menu:addOption(tr('Copy Name'), function() g_window.setClipboardText(creatureThing:getName()) end)
end
menu:display(menuPosition)

Loading…
Cancel
Save