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