Browse Source

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.
EgzoT 2 years ago
parent
commit
e6f273d5e1
1 changed files with 15 additions and 7 deletions
  1. 15
    7
      modules/gamelib/ui/uiminimap.lua

+ 15
- 7
modules/gamelib/ui/uiminimap.lua View File

@@ -72,11 +72,13 @@ end
72 72
 function UIMinimap:save()
73 73
   local settings = { flags={} }
74 74
   for _,flag in pairs(self.flags) do
75
-    table.insert(settings.flags, {
76
-      position = flag.pos,
77
-      icon = flag.icon,
78
-      description = flag.description,
79
-    })
75
+    if not flag.temporary then
76
+      table.insert(settings.flags, {
77
+        position = flag.pos,
78
+        icon = flag.icon,
79
+        description = flag.description,
80
+      })
81
+    end
80 82
   end
81 83
   settings.zoom = self:getZoom()
82 84
   g_settings.setNode('Minimap', settings)
@@ -110,19 +112,25 @@ function UIMinimap:setCrossPosition(pos)
110 112
   end
111 113
 end
112 114
 
113
-function UIMinimap:addFlag(pos, icon, description)
115
+function UIMinimap:addFlag(pos, icon, description, temporary)
114 116
   if not pos or not icon then return end
115 117
   local flag = self:getFlag(pos, icon, description)
116 118
   if flag or not icon then
117 119
     return
118 120
   end
121
+  temporary = temporary or false
119 122
 
120 123
   flag = g_ui.createWidget('MinimapFlag')
121 124
   self:insertChild(1, flag)
122 125
   flag.pos = pos
123 126
   flag.description = description
124 127
   flag.icon = icon
125
-  flag:setIcon('/images/game/minimap/flag' .. icon)
128
+  flag.temporary = temporary
129
+  if type(tonumber(icon)) == 'number' then
130
+    flag:setIcon('/images/game/minimap/flag' .. icon)
131
+  else
132
+    flag:setIcon(resolvepath(icon, 1))
133
+  end
126 134
   flag:setTooltip(description)
127 135
   flag.onMouseRelease = onFlagMouseRelease
128 136
   flag.onDestroy = function() table.removevalue(self.flags, flag) end

Loading…
Cancel
Save