Finishing Minimap Icons

Added rightclick menues:
- on map mark: 'Delete Mark'
- on minimap: 'Create Mark'

Dialog:
http://i.imgur.com/BY33k.png
This commit is contained in:
Samuel 2012-10-12 01:42:10 +02:00
parent 3990ee76e7
commit 053d29a64b
3 changed files with 266 additions and 2 deletions

View File

@ -0,0 +1,190 @@
FlagButton < CheckBox
size: 15 15
margin-left: 2
image-source: images/flagcheckbox.png
image-size: 15 15
image-border: 3
icon-source: images/mapflags.png
icon-size: 11 11
icon-clip: 0 0 11 11
icon-offset: 2 4
text:
$!checked:
image-clip: 26 0 26 26
$hover !checked:
image-clip: 78 0 26 26
$checked:
image-clip: 0 0 26 26
$hover checked:
image-clip: 52 0 26 26
FlagWindow < MainWindow
id: flagWindow
!text: tr('Create Map Mark')
size: 196 170
Label
id: position
!text: tr('Position:')
text-auto-resize: true
anchors.top: parent.top
anchors.left: parent.left
margin-top: 2
Label
!text: tr('Description:')
anchors.left: parent.left
anchors.top: prev.bottom
margin-top: 7
TextEdit
id: description
margin-top: 3
anchors.left: parent.left
anchors.top: prev.bottom
width: 158
FlagButton
id: flag1
anchors.left: parent.left
anchors.top: prev.bottom
margin-top: 6
margin-left: 0
FlagButton
id: flag2
icon-clip: 11 0 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag3
icon-clip: 22 0 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag4
icon-clip: 33 0 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag5
icon-clip: 44 0 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag6
icon-clip: 55 0 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag7
icon-clip: 66 0 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag8
icon-clip: 77 0 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag9
icon-clip: 88 0 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag10
icon-clip: 99 0 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag11
icon-clip: 0 11 11 11
anchors.left: parent.left
anchors.top: prev.bottom
margin-top: 6
margin-left: 0
FlagButton
id: flag12
icon-clip: 11 11 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag13
icon-clip: 22 11 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag14
icon-clip: 33 11 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag15
icon-clip: 44 11 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag16
icon-clip: 55 11 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag17
icon-clip: 66 11 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag18
icon-clip: 77 11 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag19
icon-clip: 88 11 11 11
anchors.left: prev.right
anchors.top: prev.top
FlagButton
id: flag20
icon-clip: 99 11 11 11
anchors.left: prev.right
anchors.top: prev.top
Button
id: okButton
!text: tr('Ok')
anchors.top: prev.bottom
anchors.left: parent.left
margin-top: 10
width: 60
Button
id: cancelButton
!text: tr('Cancel')
anchors.top: prev.top
anchors.left: prev.right
margin-left: 15
width: 60

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

View File

@ -8,6 +8,7 @@ minimapButton = nil
minimapWindow = nil
flagsPanel = nil
flagWindow = nil
nextFlagId = 0
--[[
Known Issue (TODO):
@ -15,6 +16,8 @@ nextFlagId = 0
you change floor it will not update the minimap.
]]
function init()
g_ui.importStyle('flagwindow.otui')
connect(g_game, {
onGameStart = online,
onGameEnd = offline,
@ -34,7 +37,9 @@ function init()
minimapWidget = minimapWindow:recursiveGetChildById('minimap')
g_mouse.bindAutoPress(minimapWidget, compassClick, nil, MouseRightButton)
g_mouse.bindAutoPress(minimapWidget, compassClick, nil, MouseLeftButton)
--g_mouse.bindAutoPress(minimapWidget, compassClick, nil, MouseLeftButton)
minimapWidget.onMousePress = createThingMenu
minimapWidget:setAutoViewMode(false)
minimapWidget:setViewMode(1) -- mid view
minimapWidget:setDrawMinimapColors(true)
@ -62,6 +67,7 @@ function terminate()
disconnect(LocalPlayer, { onPositionChange = center,
onPositionChange = updateMapFlags })
destroyFlagWindow()
saveMapFlags()
if g_game.isOnline() then
saveMap()
@ -73,6 +79,69 @@ function terminate()
minimapWindow:destroy()
end
function destroyFlagWindow()
if flagWindow then
flagWindow:destroy()
flagWindow = nil
end
end
function createThingMenu(widget, menuPosition, button)
if not g_game.isOnline() then return end
if button ~= MouseRightButton then return end
local menu = g_ui.createWidget('PopupMenu')
if widget == minimapWidget then
menu:addOption(tr('Create mark'), function()
local position = minimapWidget:getPosition(menuPosition)
if position then
showFlagDialog(position)
end
end)
else
menu:addOption(tr('Delete mark'), function()
widget:destroy()
end)
end
menu:display(menuPosition)
end
function showFlagDialog(position)
if flagWindow then return end
if not position then return end
flagWindow = g_ui.createWidget('FlagWindow', rootWidget)
local positionLabel = flagWindow:getChildById('position')
local description = flagWindow:getChildById('description')
local okButton = flagWindow:getChildById('okButton')
local cancelButton = flagWindow:getChildById('cancelButton')
positionLabel:setText(tr('Position: %i %i %i', position.x, position.y, position.z))
flagRadioGroup = UIRadioGroup.create()
local flagCheckbox = {}
for i = 1, 20 do
local checkbox = flagWindow:getChildById('flag' .. i)
table.insert(flagCheckbox, checkbox)
checkbox.icon = i
flagRadioGroup:addWidget(checkbox)
end
flagRadioGroup:selectWidget(flagCheckbox[1])
cancelButton.onClick = function()
flagRadioGroup:destroy()
destroyFlagWindow()
end
okButton.onClick = function()
addMapFlag(position, flagRadioGroup:getSelectedWidget().icon, description:getText())
flagRadioGroup:destroy()
destroyFlagWindow()
end
end
function loadMapFlags()
mapFlags = {}
@ -135,10 +204,13 @@ function addMapFlag(pos, icon, message, flagId, version)
flagWidget.position = pos
flagWidget.icon = icon
flagWidget.description = message
if message and message:len() > 0 then
flagWidget:setTooltip(tr(message))
end
flagWidget.id = flagId
flagWidget.version = version
updateMapFlag(flagId)
flagWidget.onMousePress = createThingMenu
end
function getMapArea()
@ -235,6 +307,8 @@ function center()
local player = g_game.getLocalPlayer()
if not player then return end
minimapWidget:followCreature(player)
updateMapFlags()
end
function compassClick(self, mousePos, mouseButton, elapsed)