aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2020-12-01 14:32:54 +0100
committerElias Fleckenstein <eliasfleckenstein@web.de>2020-12-01 14:32:54 +0100
commit89995efee487939d47e852d35a777e5dcfc28f35 (patch)
tree7295942c60de1bbfd652e8817e45f7c6fb034477
parent3df23e23cd1ace3449660077665f5ebe3e13fdc2 (diff)
downloaddragonfireclient-89995efee487939d47e852d35a777e5dcfc28f35.tar.xz
CheatDB Support & Enable/Disable CSMs in Main Menu
-rw-r--r--builtin/mainmenu/dlg_contentstore.lua8
-rw-r--r--builtin/mainmenu/pkgmgr.lua56
-rw-r--r--builtin/mainmenu/tab_content.lua86
-rw-r--r--src/script/lua_api/l_mainmenu.cpp3
4 files changed, 144 insertions, 9 deletions
diff --git a/builtin/mainmenu/dlg_contentstore.lua b/builtin/mainmenu/dlg_contentstore.lua
index 6525f6013..b3616bfc8 100644
--- a/builtin/mainmenu/dlg_contentstore.lua
+++ b/builtin/mainmenu/dlg_contentstore.lua
@@ -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
diff --git a/builtin/mainmenu/pkgmgr.lua b/builtin/mainmenu/pkgmgr.lua
index 5b8807310..d4acb2b6a 100644
--- a/builtin/mainmenu/pkgmgr.lua
+++ b/builtin/mainmenu/pkgmgr.lua
@@ -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
--------------------------------------------------------------------------------
diff --git a/builtin/mainmenu/tab_content.lua b/builtin/mainmenu/tab_content.lua
index 336730bf4..623210597 100644
--- a/builtin/mainmenu/tab_content.lua
+++ b/builtin/mainmenu/tab_content.lua
@@ -19,6 +19,10 @@
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
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index 0aa2760e9..2cf4a979b 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -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;