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.
master
EgzoT 6 years ago committed by Ahmed Samy
parent 7967bd4385
commit e6f273d5e1

@ -72,11 +72,13 @@ 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
table.insert(settings.flags, { if not flag.temporary then
position = flag.pos, table.insert(settings.flags, {
icon = flag.icon, position = flag.pos,
description = flag.description, icon = flag.icon,
}) description = flag.description,
})
end
end end
settings.zoom = self:getZoom() settings.zoom = self:getZoom()
g_settings.setNode('Minimap', settings) g_settings.setNode('Minimap', settings)
@ -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:setIcon('/images/game/minimap/flag' .. 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: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

Loading…
Cancel
Save