]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
CheatDB Support & Enable/Disable CSMs in Main Menu
authorElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 1 Dec 2020 13:32:54 +0000 (14:32 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 1 Dec 2020 13:32:54 +0000 (14:32 +0100)
builtin/mainmenu/dlg_contentstore.lua
builtin/mainmenu/pkgmgr.lua
builtin/mainmenu/tab_content.lua
src/script/lua_api/l_mainmenu.cpp

index 6525f60137fc61b67c14aa80e28fea65e0afbe4f..b3616bfc856340506b325109abdd4d6d16cfb479 100644 (file)
@@ -40,8 +40,8 @@ local num_per_page = 5
 local filter_type = 1
 local filter_types_titles = {
        fgettext("All packages"),
-       fgettext("Games"),
-       fgettext("Mods"),
+--     fgettext("Games"),
+       fgettext("Clientmods"),
        fgettext("Texture packs"),
 }
 
@@ -50,7 +50,7 @@ local download_queue = {}
 
 local filter_types_type = {
        nil,
-       "game",
+--     "game",
        "mod",
        "txp",
 }
@@ -254,7 +254,7 @@ end
 function store.update_paths()
        local mod_hash = {}
        pkgmgr.refresh_globals()
-       for _, mod in pairs(pkgmgr.global_mods:get_list()) do
+       for _, mod in pairs(pkgmgr.clientmods:get_list()) do
                if mod.author then
                        mod_hash[mod.author:lower() .. "/" .. mod.name] = mod
                end
index 5b880731009af0e151890a961d16653eddf147e1..d4acb2b6af90224269dd7a98326aab92aee8ef2b 100644 (file)
@@ -592,7 +592,7 @@ function pkgmgr.install_dir(type, path, basename, targetpath)
                                clean_path = get_last_folder(cleanup_path(basefolder.path))
                        end
                        if clean_path then
-                               targetpath = core.get_modpath() .. DIR_DELIM .. clean_path
+                               targetpath = core.get_clientmodpath() .. DIR_DELIM .. clean_path
                        else
                                return nil,
                                        fgettext("Install Mod: Unable to find suitable folder name for modpack $1",
@@ -619,7 +619,7 @@ function pkgmgr.install_dir(type, path, basename, targetpath)
                        end
 
                        if targetfolder ~= nil and pkgmgr.isValidModname(targetfolder) then
-                               targetpath = core.get_modpath() .. DIR_DELIM .. targetfolder
+                               targetpath = core.get_clientmodpath() .. DIR_DELIM .. targetfolder
                        else
                                return nil, fgettext("Install Mod: Unable to find real mod name for: $1", path)
                        end
@@ -671,6 +671,54 @@ function pkgmgr.install(type, modfilename, basename, dest)
 end
 
 --------------------------------------------------------------------------------
+function pkgmgr.prepareclientmodlist(data)
+       local retval = {}
+
+       local clientmods = {}
+
+       --read clientmods
+       local modpath = core.get_clientmodpath()
+
+       if modpath ~= nil and
+               modpath ~= "" then
+               get_mods(modpath,clientmods)
+       end
+
+       for i=1,#clientmods,1 do
+               clientmods[i].type = "mod"
+               clientmods[i].loc = "global"
+               clientmods[i].is_clientside = true
+               retval[#retval + 1] = clientmods[i]
+       end
+
+       --read mods configuration
+       local filename = modpath ..
+                               DIR_DELIM .. "mods.conf"
+
+       local conffile = Settings(filename)
+
+       for key,value in pairs(conffile:to_table()) do
+               if key:sub(1, 9) == "load_mod_" then
+                       key = key:sub(10)
+                       local element = nil
+                       for i=1,#retval,1 do
+                               if retval[i].name == key and
+                                       not retval[i].is_modpack then
+                                       element = retval[i]
+                                       break
+                               end
+                       end
+                       if element ~= nil then
+                               element.enabled = value ~= "false" and value ~= "nil" and value
+                       else
+                               core.log("info", "Clientmod: " .. key .. " " .. dump(value) .. " but not found")
+                       end
+               end
+       end
+
+       return retval
+end
+
 function pkgmgr.preparemodlist(data)
        local retval = {}
 
@@ -813,6 +861,10 @@ function pkgmgr.refresh_globals()
                        pkgmgr.comparemod, is_equal, nil, {})
        pkgmgr.global_mods:add_sort_mechanism("alphabetic", sort_mod_list)
        pkgmgr.global_mods:set_sortmode("alphabetic")
+       pkgmgr.clientmods = filterlist.create(pkgmgr.prepareclientmodlist,
+                       pkgmgr.comparemod, is_equal, nil, {})
+       pkgmgr.clientmods:add_sort_mechanism("alphabetic", sort_mod_list)
+       pkgmgr.clientmods:set_sortmode("alphabetic")
 end
 
 --------------------------------------------------------------------------------
index 336730bf4d7ea84ca558fcf831885b361503b47a..62321059731f8b22f04fe33b5b98883dc532457a 100644 (file)
 local packages_raw
 local packages
 
+local function modname_valid(name)
+       return not name:find("[^a-z0-9_]")
+end
+
 --------------------------------------------------------------------------------
 local function get_formspec(tabview, name, tabdata)
        if pkgmgr.global_mods == nil then
@@ -33,6 +37,7 @@ local function get_formspec(tabview, name, tabdata)
                table.insert_all(packages_raw, pkgmgr.games)
                table.insert_all(packages_raw, pkgmgr.get_texture_packs())
                table.insert_all(packages_raw, pkgmgr.global_mods:get_list())
+               table.insert_all(packages_raw, pkgmgr.clientmods:get_list())
 
                local function get_data()
                        return packages_raw
@@ -45,6 +50,38 @@ local function get_formspec(tabview, name, tabdata)
 
                packages = filterlist.create(get_data, pkgmgr.compare_package,
                                is_equal, nil, {})
+                               
+               local filename = core.get_clientmodpath() .. DIR_DELIM .. "mods.conf"
+
+               local conffile = Settings(filename)
+               local mods = conffile:to_table()
+       
+               for i = 1, #packages_raw do
+                       local mod = packages_raw[i]
+                       if mod.is_clientside and not mod.is_modpack then
+                               if modname_valid(mod.name) then
+                                       conffile:set("load_mod_" .. mod.name,
+                                               mod.enabled and "true" or "false")
+                               elseif mod.enabled then
+                                       gamedata.errormessage = fgettext_ne("Failed to enable clientmo" ..
+                                               "d \"$1\" as it contains disallowed characters. " ..
+                                               "Only characters [a-z0-9_] are allowed.",
+                                               mod.name)
+                               end
+                               mods["load_mod_" .. mod.name] = nil
+                       end
+               end
+               
+               -- Remove mods that are not present anymore
+               for key in pairs(mods) do
+                       if key:sub(1, 9) == "load_mod_" then
+                               conffile:remove(key)
+                       end
+               end
+
+               if not conffile:write() then
+                       core.log("error", "Failed to write clientmod config file")
+               end
        end
 
        if tabdata.selected_pkg == nil then
@@ -94,9 +131,21 @@ local function get_formspec(tabview, name, tabdata)
 
                if selected_pkg.type == "mod" then
                        if selected_pkg.is_modpack then
-                               retval = retval ..
-                                       "button[8.65,4.65;3.25,1;btn_mod_mgr_rename_modpack;" ..
-                                       fgettext("Rename") .. "]"
+                               if selected_pkg.is_clientside then
+                                       if pkgmgr.is_modpack_entirely_enabled({list = packages}, selected_pkg.name) then
+                                               retval = retval ..
+                                                       "button[8.65,4.65;3.25,1;btn_mod_mgr_mp_disable;" ..
+                                                       fgettext("Disable modpack") .. "]"
+                                       else
+                                               retval = retval ..
+                                                       "button[8.65,4.65;3.25,1;btn_mod_mgr_mp_enable;" ..
+                                                       fgettext("Enable modpack") .. "]"
+                                       end
+                               else
+                                       retval = retval ..
+                                               "button[8.65,4.65;3.25,1;btn_mod_mgr_rename_modpack;" ..
+                                               fgettext("Rename") .. "]"
+                               end
                        else
                                --show dependencies
                                desc = desc .. "\n\n"
@@ -117,6 +166,17 @@ local function get_formspec(tabview, name, tabdata)
                                                        "\n" .. toadd_soft
                                        end
                                end
+                               if selected_pkg.is_clientside then
+                                       if selected_pkg.enabled then
+                                               retval = retval ..
+                                                       "button[8.65,4.65;3.25,1;btn_mod_mgr_disable_mod;" ..
+                                                       fgettext("Disable") .. "]"
+                                       else
+                                               retval = retval ..
+                                                       "button[8.65,4.65;3.25,1;btn_mod_mgr_enable_mod;" ..
+                                                       fgettext("Enable") .. "]"
+                                       end
+                               end
                        end
 
                else
@@ -150,6 +210,26 @@ local function handle_buttons(tabview, fields, tabname, tabdata)
        if fields["pkglist"] ~= nil then
                local event = core.explode_table_event(fields["pkglist"])
                tabdata.selected_pkg = event.row
+               local mod = packages:get_list()[tabdata.selected_pkg]
+               
+               if event.type == "DCL" and mod.is_clientside then
+                       pkgmgr.enable_mod({data = {list = packages, selected_mod = tabdata.selected_pkg}})
+                       packages = nil
+               end
+               return true
+       end
+       
+       if fields.btn_mod_mgr_mp_enable ~= nil or
+                       fields.btn_mod_mgr_mp_disable ~= nil then
+               pkgmgr.enable_mod({data = {list = packages, selected_mod = tabdata.selected_pkg}}, fields.btn_mod_mgr_mp_enable ~= nil)
+               packages = nil
+               return true
+       end
+       
+       if fields.btn_mod_mgr_enable_mod ~= nil or
+                       fields.btn_mod_mgr_disable_mod ~= nil then
+               pkgmgr.enable_mod({data = {list = packages, selected_mod = tabdata.selected_pkg}}, fields.btn_mod_mgr_enable_mod ~= nil)
+               packages = nil
                return true
        end
 
index 0aa2760e9ff0105cb9ddf1aed4ede54fb1e50f31..2cf4a979b567f5eb1e49fd8a6e51829b2f621f43 100644 (file)
@@ -902,6 +902,9 @@ bool ModApiMainMenu::mayModifyPath(const std::string &path)
        if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "mods")))
                return true;
 
+       if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "clientmods")))
+               return true;
+
        if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "textures")))
                return true;