Add functionality to minimap flags system (#931)

- Add parameter 'temporary' to method 'UIMinimap:addFlag', who prevents saving flag with this parameter (look 'UIMinimap:save' method), add flag only at game session time. Old parameters list work the same at previous - backward compatibility.
- Add possibility to add icon from outside (for example from module folder) using link to this file. Old system with choose flag name by number work the same at previous, now method check if paramether is number then use old system otherwise get icon from path - backward compatibility. 'Mods' friendly.
This commit is contained in:
EgzoT 2018-02-28 21:45:59 +01:00 committed by Ahmed Samy
parent 7967bd4385
commit e6f273d5e1
1 changed files with 15 additions and 7 deletions

View File

@ -72,12 +72,14 @@ end
function UIMinimap:save() function UIMinimap:save()
local settings = { flags={} } local settings = { flags={} }
for _,flag in pairs(self.flags) do for _,flag in pairs(self.flags) do
if not flag.temporary then
table.insert(settings.flags, { table.insert(settings.flags, {
position = flag.pos, position = flag.pos,
icon = flag.icon, icon = flag.icon,
description = flag.description, description = flag.description,
}) })
end end
end
settings.zoom = self:getZoom() settings.zoom = self:getZoom()
g_settings.setNode('Minimap', settings) g_settings.setNode('Minimap', settings)
end end
@ -110,19 +112,25 @@ function UIMinimap:setCrossPosition(pos)
end end
end end
function UIMinimap:addFlag(pos, icon, description) function UIMinimap:addFlag(pos, icon, description, temporary)
if not pos or not icon then return end if not pos or not icon then return end
local flag = self:getFlag(pos, icon, description) local flag = self:getFlag(pos, icon, description)
if flag or not icon then if flag or not icon then
return return
end end
temporary = temporary or false
flag = g_ui.createWidget('MinimapFlag') flag = g_ui.createWidget('MinimapFlag')
self:insertChild(1, flag) self:insertChild(1, flag)
flag.pos = pos flag.pos = pos
flag.description = description flag.description = description
flag.icon = icon flag.icon = icon
flag.temporary = temporary
if type(tonumber(icon)) == 'number' then
flag:setIcon('/images/game/minimap/flag' .. icon) flag:setIcon('/images/game/minimap/flag' .. icon)
else
flag:setIcon(resolvepath(icon, 1))
end
flag:setTooltip(description) flag:setTooltip(description)
flag.onMouseRelease = onFlagMouseRelease flag.onMouseRelease = onFlagMouseRelease
flag.onDestroy = function() table.removevalue(self.flags, flag) end flag.onDestroy = function() table.removevalue(self.flags, flag) end