Separate optional from required mod dependencies in main menu (#4721)
authorWuzzy <wuzzy2@mail.ru>
Sat, 5 Nov 2016 17:42:14 +0000 (18:42 +0100)
committerest31 <est31@users.noreply.github.com>
Sat, 5 Nov 2016 17:42:14 +0000 (18:42 +0100)
* Separate optional from require dep's in main menu

* Simplify modmgr mod dependency listing code

builtin/mainmenu/dlg_config_world.lua
builtin/mainmenu/modmgr.lua
builtin/mainmenu/tab_mods.lua

index 6e6224c926f816f43a5f1d67f2825b135275951b..7b3ab985296b1dd828e32c563acb4804716b25e0 100644 (file)
@@ -47,13 +47,18 @@ local function get_formspec(data)
        if mod == nil then
                mod = {name=""}
        end
+
+       local hard_deps, soft_deps = modmgr.get_dependencies(mod.path)
        
        retval = retval ..
                "label[0,0.7;" .. fgettext("Mod:") .. "]" ..
                "label[0.75,0.7;" .. mod.name .. "]" ..
-               "label[0,1.25;" .. fgettext("Depends:") .. "]" ..
-               "textlist[0,1.75;5,4.25;world_config_depends;" ..
-               modmgr.get_dependencies(mod.path) .. ";0]" ..
+               "label[0,1.25;" .. fgettext("Dependencies:") .. "]" ..
+               "textlist[0,1.75;5,2.125;world_config_depends;" ..
+               hard_deps .. ";0]" ..
+               "label[0,3.875;" .. fgettext("Optional dependencies:") .. "]" ..
+               "textlist[0,4.375;5,1.8;world_config_optdepends;" ..
+               soft_deps .. ";0]" ..
                "button[3.25,7;2.5,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" ..
                "button[5.75,7;2.5,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]"
 
@@ -86,11 +91,11 @@ local function get_formspec(data)
        if enabled_all then 
                retval = retval ..
                        "button[8.75,0.125;2.5,0.5;btn_disable_all_mods;" .. fgettext("Disable all") .. "]" ..
-                       "textlist[5.5,0.75;5.75,5.25;world_config_modlist;"
+                       "textlist[5.5,0.75;5.75,5.4;world_config_modlist;"
        else
                retval = retval ..
                        "button[8.75,0.125;2.5,0.5;btn_enable_all_mods;" .. fgettext("Enable all") .. "]" ..
-                       "textlist[5.5,0.75;5.75,5.25;world_config_modlist;"
+                       "textlist[5.5,0.75;5.75,5.4;world_config_modlist;"
        end
        retval = retval .. modmgr.render_modlist(data.list)
        retval = retval .. ";" .. data.selected_mod .."]"
index f996df7baf23ac49dfff39e1eea46bb05b96e41e..bf87b1dfa1749621a482b42e27c68a2731662916 100644 (file)
@@ -284,27 +284,32 @@ end
 
 --------------------------------------------------------------------------------
 function modmgr.get_dependencies(modfolder)
-       local toadd = ""
+       local toadd_hard = ""
+       local toadd_soft = ""
        if modfolder ~= nil then
                local filename = modfolder ..
                                        DIR_DELIM .. "depends.txt"
 
+               local hard_dependencies = {}
+               local soft_dependencies = {}
                local dependencyfile = io.open(filename,"r")
-
                if dependencyfile then
                        local dependency = dependencyfile:read("*l")
                        while dependency do
-                               if toadd ~= "" then
-                                       toadd = toadd .. ","
+                               if string.sub(dependency, -1, -1) == "?" then
+                                       table.insert(soft_dependencies, string.sub(dependency, 1, -2))
+                               else
+                                       table.insert(hard_dependencies, dependency)
                                end
-                               toadd = toadd .. dependency
                                dependency = dependencyfile:read()
                        end
                        dependencyfile:close()
                end
+               toadd_hard = table.concat(hard_dependencies, ",")
+               toadd_soft = table.concat(soft_dependencies, ",")
        end
 
-       return toadd
+       return toadd_hard, toadd_soft
 end
 
 --------------------------------------------------------------------------------
index 5b59aa1107c3467d15a34961ee3f4f2c8718b0ac..4a5b6c0414181cc8032875178a187eb46b6e8aa3 100644 (file)
@@ -98,12 +98,24 @@ local function get_formspec(tabview, name, tabdata)
                                .. fgettext("Uninstall selected modpack") .. "]"
                else
                        --show dependencies
-
-                       retval = retval .. "," .. fgettext("Depends:") .. ","
-
-                       local toadd = modmgr.get_dependencies(selected_mod.path)
-
-                       retval = retval .. toadd .. ";0]"
+                       local toadd_hard, toadd_soft = modmgr.get_dependencies(selected_mod.path)
+                       if toadd_hard == "" and toadd_soft == "" then
+                               retval = retval .. "," .. fgettext("No dependencies.")
+                       else
+                               if toadd_hard ~= "" then
+                                       retval = retval .. "," .. fgettext("Dependencies:") .. ","
+                                       retval = retval .. toadd_hard
+                               end
+                               if toadd_soft ~= "" then
+                                       if toadd_hard ~= "" then
+                                               retval = retval .. ","
+                                       end
+                                       retval = retval .. "," .. fgettext("Optional dependencies:") .. ","
+                                       retval = retval .. toadd_soft
+                               end
+                       end
+
+                       retval = retval .. ";0]"
 
                        retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
                                .. fgettext("Uninstall selected mod") .. "]"