From b3db44f8013118f6950a45eb36a06312e869a452 Mon Sep 17 00:00:00 2001
From: sapier <Sapier at GMX dot net>
Date: Thu, 18 Jul 2013 00:35:58 +0200
Subject: [PATCH] Fix bug in world creation Add old style mod selection in
 worldconfig dialog

---
 builtin/mainmenu.lua    |  11 ++--
 builtin/modmgr.lua      | 113 ++++++++++++++++++++++++++++++++--------
 src/defaultsettings.cpp |   1 +
 3 files changed, 100 insertions(+), 25 deletions(-)

diff --git a/builtin/mainmenu.lua b/builtin/mainmenu.lua
index 718a90253..18e82f499 100644
--- a/builtin/mainmenu.lua
+++ b/builtin/mainmenu.lua
@@ -342,7 +342,7 @@ function tabbuilder.handle_create_world_buttons(fields)
 			
 			local message = nil
 			
-			if not filterlist.uid_exists(worldlist,worldname) then
+			if not filterlist.uid_exists_raw(worldlist,worldname) then
 				engine.setting_set("mg_name",fields["dd_mapgen"])
 				message = engine.create_world(worldname,gameindex)
 			else
@@ -613,7 +613,6 @@ function tabbuilder.handle_settings_buttons(fields)
 	if fields["cb_fancy_trees"] then
 		engine.setting_setbool("new_style_leaves",tabbuilder.tobool(fields["cb_fancy_trees"]))
 	end
-		
 	if fields["cb_smooth_lighting"] then
 		engine.setting_setbool("smooth_lighting",tabbuilder.tobool(fields["cb_smooth_lighting"]))
 	end
@@ -623,7 +622,10 @@ function tabbuilder.handle_settings_buttons(fields)
 	if fields["cb_opaque_water"] then
 		engine.setting_setbool("opaque_water",tabbuilder.tobool(fields["cb_opaque_water"]))
 	end
-			
+	if fields["old_style_modselection"] then
+		engine.setting_setbool("old_style_mod_selection",tabbuilder.tobool(fields["old_style_modselection"]))
+	end
+	
 	if fields["cb_mipmapping"] then
 		engine.setting_setbool("mip_map",tabbuilder.tobool(fields["cb_mipmapping"]))
 	end
@@ -908,6 +910,7 @@ function tabbuilder.tab_settings()
 			"checkbox[1,1.25;cb_smooth_lighting;Smooth Lighting;".. dump(engine.setting_getbool("smooth_lighting"))	.. "]"..
 			"checkbox[1,1.75;cb_3d_clouds;3D Clouds;" 			.. dump(engine.setting_getbool("enable_3d_clouds"))	.. "]"..
 			"checkbox[1,2.25;cb_opaque_water;Opaque Water;" 		.. dump(engine.setting_getbool("opaque_water"))		.. "]"..
+			"checkbox[1,2.75;old_style_modselection;Old style modmgr;" .. dump(engine.setting_getbool("old_style_mod_selection"))		.. "]"..
 			
 			"checkbox[4,0.75;cb_mipmapping;Mip-Mapping;" 		.. dump(engine.setting_getbool("mip_map"))			.. "]"..
 			"checkbox[4,1.25;cb_anisotrophic;Anisotropic Filtering;".. dump(engine.setting_getbool("anisotropic_filter"))	.. "]"..
@@ -919,7 +922,7 @@ function tabbuilder.tab_settings()
 			"checkbox[7.5,1.75;cb_particles;Enable Particles;"	.. dump(engine.setting_getbool("enable_particles"))	.. "]"..
 			"checkbox[7.5,2.25;cb_finite_liquid;Finite Liquid;"	.. dump(engine.setting_getbool("liquid_finite"))		.. "]"..
 			
-			"button[1,3.75;2.25,0.5;btn_change_keys;Change keys]"
+			"button[1,4.25;2.25,0.5;btn_change_keys;Change keys]"
 end
 
 --------------------------------------------------------------------------------
diff --git a/builtin/modmgr.lua b/builtin/modmgr.lua
index 3256c3b9f..c4bc40448 100644
--- a/builtin/modmgr.lua
+++ b/builtin/modmgr.lua
@@ -393,8 +393,47 @@ function modmgr.dialog_configure_world()
 		"textlist[0,1.5;5,4.25;world_config_depends;" ..
 		modmgr.get_dependencies(mod.path) .. ";0]" ..
 		"button[9.25,6.35;2,0.5;btn_config_world_save;Save]" ..
-		"button[7.4,6.35;2,0.5;btn_config_world_cancel;Cancel]" ..
-		"button[5.5,-0.125;5.75,0.5;btn_all_mods;Enable all Mods]" ..
+		"button[7.4,6.35;2,0.5;btn_config_world_cancel;Cancel]"
+	
+	if engine.setting_get("old_style_mod_selection") == "true" then
+		local selected = engine.get_textlist_index("world_config_modlist")
+		local mod = filterlist.get_list(modmgr.modlist)[selected]
+		
+		if mod ~= nil then
+			if mod.is_modpack then
+				local rawlist = filterlist.get_raw_list(modmgr.modlist)
+				
+				local all_enabled = true
+				for j=1,#rawlist,1 do
+					if rawlist[j].modpack == mod.name and
+						rawlist[j].enabled ~= true then
+							all_enabled = false
+							break
+					end
+				end
+				
+				if all_enabled == false then
+					retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_enable;Enable MP]"
+				else
+					retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_disable;Disable MP]"
+				end
+			else
+				if mod.enabled then
+					retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;enabled;true]"
+				else
+					retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;enabled;false]"
+				end
+			end
+		
+		end
+		
+		retval = retval ..
+			"button[8.5,-0.125;2.5,0.5;btn_all_mods;Enable all]"
+	else
+		retval = retval ..
+		"button[5.5,-0.125;5.75,0.5;btn_all_mods;Enable all Mods]"
+	end
+		retval = retval ..
 		"textlist[5.5,0.5;5.5,5.75;world_config_modlist;"
 		
 
@@ -627,33 +666,65 @@ function modmgr.handle_configure_world_buttons(fields)
 	if fields["world_config_modlist"] ~= nil then
 		local event = explode_textlist_event(fields["world_config_modlist"])
 		modmgr.world_config_selected_mod = event.index
+
+		if engine.setting_get("old_style_mod_selection") ~= "true" then
+			if event.typ == "DCL" then
+				local mod = filterlist.get_list(modmgr.modlist)[event.index]
+				
+				if mod.typ == "game_mod" then
+					return nil
+				end
+				
+				if not mod.is_modpack then
+					mod.enabled = not mod.enabled
+				else
+					local list = filterlist.get_raw_list(modmgr.modlist)
+					local toset = nil
+					
+					for i=1,#list,1 do
+						if list[i].modpack == mod.name then
+							if toset == nil then
+								toset = not list[i].enabled
+							end
+							
+							list[i].enabled = toset
+						end
+					end
+				end
+			end
+		end
+	end
+	
+	if engine.setting_get("old_style_mod_selection") == "true" then
+		if fields["cb_mod_enable"] ~= nil then
+			local mod = filterlist.get_list(modmgr.modlist)
+				[engine.get_textlist_index("world_config_modlist")]
+			if fields["cb_mod_enable"] == "true" then
+				mod.enabled = true
+			else
+				mod.enabled = false
+			end
+		end
 		
-		if event.typ == "DCL" then
-			local mod = filterlist.get_list(modmgr.modlist)[event.index]
+		if fields["btn_mp_enable"] ~= nil or 
+			fields["btn_mp_disable"] then
+			local mod = filterlist.get_list(modmgr.modlist)
+				[engine.get_textlist_index("world_config_modlist")]
 			
-			if mod.typ == "game_mod" then
-				return nil
+			local toset=false
+			if fields["btn_mp_enable"] ~= nil then
+				toset = true
 			end
+			local list = filterlist.get_raw_list(modmgr.modlist)
 			
-			if not mod.is_modpack then
-				mod.enabled = not mod.enabled
-			else
-				local list = filterlist.get_raw_list(modmgr.modlist)
-				local toset = nil
-				
-				for i=1,#list,1 do
-					if list[i].modpack == mod.name then
-						if toset == nil then
-							toset = not list[i].enabled
-						end
-						
-						list[i].enabled = toset
-					end
+			for i=1,#list,1 do
+				if list[i].modpack == mod.name then
+					list[i].enabled = toset
 				end
 			end
 		end
 	end
-
+	
 	if fields["cb_hide_gamemods"] ~= nil then
 		local current = filterlist.get_filtercriteria(modmgr.modlist)
 		
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index a6d52cb15..67140a8f3 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -264,6 +264,7 @@ void set_default_settings(Settings *settings)
 	settings->setDefault("ipv6_server", "false");
 
 	settings->setDefault("main_menu_mod_mgr","1");
+	settings->setDefault("old_style_mod_selection","true");
 	settings->setDefault("main_menu_game_mgr","1");
 	settings->setDefault("modstore_download_url", "http://forum.minetest.net/media/");
 	settings->setDefault("modstore_listmods_url", "http://forum.minetest.net/mmdb/mods/");
-- 
GitLab