mirror of
				https://github.com/sys4-fr/server-nalc.git
				synced 2025-10-31 20:45:22 +01:00 
			
		
		
		
	add an menu in soundset
add an menu in soundset and and button in unified_inventory and chatcommand to display menu
This commit is contained in:
		
							
								
								
									
										1
									
								
								mods/soundset/depends.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								mods/soundset/depends.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | unified_inventory? | ||||||
| @@ -3,8 +3,34 @@ minetest.log("action","[mod soundset] Loading...") | |||||||
| sounds = {} | sounds = {} | ||||||
| sounds.file = minetest.get_worldpath() .. "/sounds_config.txt" | sounds.file = minetest.get_worldpath() .. "/sounds_config.txt" | ||||||
| sounds.gainplayers = {} | sounds.gainplayers = {} | ||||||
|  | sounds.tmp = {} | ||||||
|  |  | ||||||
|  |  | ||||||
|  | local function save_sounds_config() | ||||||
|  | 	local input = io.open(sounds.file, "w") | ||||||
|  | 	if input then | ||||||
|  | 		input:write(minetest.serialize(sounds.gainplayers)) | ||||||
|  | 		input:close() | ||||||
|  | 	else | ||||||
|  | 		minetest.log("action","echec d'ouverture (mode:w) de " .. sounds.file) | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  |  | ||||||
|  |  | ||||||
|  | local function load_sounds_config() | ||||||
|  | 	local file = io.open(sounds.file, "r") | ||||||
|  | 	if file then | ||||||
|  | 		sounds.gainplayers = minetest.deserialize(file:read("*all")) | ||||||
|  | 		file:close() | ||||||
|  | 	end | ||||||
|  | 	print("type: "..tostring(type(sounds.gainplayers))) | ||||||
|  | 	if sounds.gainplayers == nil or type(sounds.gainplayers) ~= "table" then | ||||||
|  | 		sounds.gainplayers = {} | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  |  | ||||||
|  | load_sounds_config() | ||||||
|  |  | ||||||
| sounds.set_sound = function(name, param) | sounds.set_sound = function(name, param) | ||||||
| 	if param == "" then | 	if param == "" then | ||||||
| 		minetest.chat_send_player(name, "/setsound <music|ambience|mobs|other> <number>") | 		minetest.chat_send_player(name, "/setsound <music|ambience|mobs|other> <number>") | ||||||
| @@ -13,18 +39,16 @@ sounds.set_sound = function(name, param) | |||||||
| 	local param_name, param_value = param:match("^(%S+)%s(%S+)$") | 	local param_name, param_value = param:match("^(%S+)%s(%S+)$") | ||||||
| 	if param_name == nil or param_value == nil then | 	if param_name == nil or param_value == nil then | ||||||
| 		minetest.chat_send_player(name, "invalid param, /setsound <music|ambience|mobs|other> <number>") | 		minetest.chat_send_player(name, "invalid param, /setsound <music|ambience|mobs|other> <number>") | ||||||
| 		minetest.log("action", "invalid param, see /setsound <music|ambience|mobs|other> <number>") |  | ||||||
| 		return | 		return | ||||||
| 	end | 	end | ||||||
| 	 | 	 | ||||||
| 	if param_name ~= "music" and param_name ~= "ambience" and param_name ~= "mobs" and param_name ~= "other" then | 	if param_name ~= "music" and param_name ~= "ambience" and param_name ~= "mobs" and param_name ~= "other" then | ||||||
| 		minetest.chat_send_player(name, "invalid param " .. param_name) | 		minetest.chat_send_player(name, "invalid param " .. param_name) | ||||||
| 		minetest.log("action", "invalid param, /setsound " .. param_name) |  | ||||||
| 		return | 		return | ||||||
| 	end | 	end | ||||||
| 	local value = tonumber(param_value) | 	local value = tonumber(param_value) | ||||||
| 	if value == nil then | 	if value == nil then | ||||||
| 		minetest.log("action", "invalid value, " ..param_value .. " must be number") | 		minetest.chat_send_player(name, "invalid value, " ..param_value .. " must be number") | ||||||
| 		return | 		return | ||||||
| 	end | 	end | ||||||
| 	 | 	 | ||||||
| @@ -36,22 +60,12 @@ sounds.set_sound = function(name, param) | |||||||
| 	 | 	 | ||||||
| 	if sounds.gainplayers[name][param_name] == value then | 	if sounds.gainplayers[name][param_name] == value then | ||||||
| 		minetest.chat_send_player(name, "volume " .. param_name .. " already set to " .. value) | 		minetest.chat_send_player(name, "volume " .. param_name .. " already set to " .. value) | ||||||
| 		minetest.log("action", name ..", volume " .. param_name .. "  already set to " .. value) |  | ||||||
| 		return | 		return | ||||||
| 	end | 	end | ||||||
| 		 | 		 | ||||||
| 	sounds.gainplayers[name][param_name] = value | 	sounds.gainplayers[name][param_name] = value | ||||||
| 	minetest.chat_send_player(name, "sound " .. param_name .. " set to " .. value) | 	minetest.chat_send_player(name, "sound " .. param_name .. " set to " .. value) | ||||||
| 	minetest.log("action", name ..", sound " .. param_name .. " set to " .. value) | 	save_sounds_config() | ||||||
|  |  | ||||||
|  |  | ||||||
| 	local input = io.open(sounds.file, "w") |  | ||||||
| 	if input then |  | ||||||
| 		input:write(minetest.serialize(sounds.gainplayers)) |  | ||||||
| 		input:close() |  | ||||||
| 	else |  | ||||||
| 		minetest.log("action","echec d'ouverture (mode:w) de " .. sounds.file) |  | ||||||
| 	end |  | ||||||
| end | end | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -67,31 +81,119 @@ sounds.get_gain = function(name, sound_type) | |||||||
| end | end | ||||||
|  |  | ||||||
|  |  | ||||||
|  | local formspec = "size[6,6]".. | ||||||
|  | 				"label[2,0;Sound Menu]".. | ||||||
|  | 				"label[0.3,1.2;MUSIC]".. | ||||||
|  | 				"image_button[1.6,1;1,1;soundset_dec.png;vmusic;-]".. | ||||||
|  | 				"label[2.7,1.2;%s]".. | ||||||
|  | 				"image_button[3.5,1;1,1;soundset_inc.png;vmusic;+]".. | ||||||
|  | 				"label[0,2.2;AMBIENCE]".. | ||||||
|  | 				"image_button[1.6,2;1,1;soundset_dec.png;vambience;-]".. | ||||||
|  | 				"label[2.7,2.2;%s]".. | ||||||
|  | 				"image_button[3.5,2;1,1;soundset_inc.png;vambience;+]".. | ||||||
|  | 				"button_exit[0.5,5.2;1.5,1;abort;Abort]".. | ||||||
|  | 				"button_exit[4,5.2;1.5,1;abort;Ok]" | ||||||
|  |  | ||||||
| local function load_sounds_config() |  | ||||||
| 	local file = io.open(sounds.file, "r") | local on_show_settings = function(name, music, ambience) | ||||||
| 	if file then | 	if not sounds.tmp[name] then | ||||||
| 		sounds.gainplayers = minetest.deserialize(file:read("*all")) | 		sounds.tmp[name] = {} | ||||||
| 		file:close() |  | ||||||
| 	end |  | ||||||
| 	if sounds.gainplayers == nil then |  | ||||||
| 		sounds.gainplayers = {} |  | ||||||
| 	end | 	end | ||||||
|  | 	sounds.tmp[name]["music"] = music | ||||||
|  | 	sounds.tmp[name]["ambience"] = ambience | ||||||
|  | 	minetest.show_formspec( name, "soundset:settings", string.format(formspec, tostring(music), tostring(ambience) )) | ||||||
| end | end | ||||||
|  |  | ||||||
|  |  | ||||||
| load_sounds_config() | minetest.register_on_player_receive_fields(function(player, formname, fields) | ||||||
|  | 	if formname == "soundset:settings" then | ||||||
|  | 		local name = player:get_player_name() | ||||||
|  | 		local fmusic = sounds.tmp[name]["music"] | ||||||
|  | 		local fambience = sounds.tmp[name]["ambience"] | ||||||
|  | 		if fields["abort"] == "Ok" then | ||||||
|  | 			if sounds.gainplayers[name]["music"] ~= fmusic or sounds.gainplayers[name]["ambience"] ~= fambience then | ||||||
|  | 				sounds.gainplayers[name]["music"] = fmusic | ||||||
|  | 				sounds.gainplayers[name]["ambience"] = fambience | ||||||
|  | 				save_sounds_config() | ||||||
|  | 			end | ||||||
|  | 			sounds.tmp[name] = nil | ||||||
|  | 			return | ||||||
|  | 		elseif fields["abort"] == "Abort" then | ||||||
|  | 			sounds.tmp[name] = nil | ||||||
|  | 			return | ||||||
|  | 		elseif fields["vmusic"] == "+" then | ||||||
|  | 			if fmusic < 100 then | ||||||
|  | 				fmusic = fmusic +5 | ||||||
|  | 				if fmusic > 100 then | ||||||
|  | 					fmusic = 100 | ||||||
|  | 				end | ||||||
|  | 			end | ||||||
|  | 		elseif fields["vmusic"] == "-" then | ||||||
|  | 			if fmusic > 0 then | ||||||
|  | 				fmusic = fmusic -5 | ||||||
|  | 				if fmusic < 0 then | ||||||
|  | 					fmusic = 0 | ||||||
|  | 				end | ||||||
|  | 			end | ||||||
|  | 		elseif fields["vambience"] == "+" then | ||||||
|  | 			if fambience < 100 then | ||||||
|  | 				fambience = fambience +5 | ||||||
|  | 				if fambience > 100 then | ||||||
|  | 					fambience = 100 | ||||||
|  | 				end | ||||||
|  | 			end | ||||||
|  | 		elseif fields["vambience"] == "-" then | ||||||
|  | 			if fambience > 0 then | ||||||
|  | 				fambience = fambience -5 | ||||||
|  | 				if fambience < 0 then | ||||||
|  | 					fambience = 0 | ||||||
|  | 				end | ||||||
|  | 			end | ||||||
|  | 		elseif fields["quit"] == "true" then | ||||||
|  | 			sounds.tmp[name] = nil | ||||||
|  | 			return | ||||||
|  | 		else | ||||||
|  | 			return | ||||||
|  | 		end | ||||||
|  |  | ||||||
| minetest.register_chatcommand("setsound", { | 		on_show_settings(name, fmusic, fambience) | ||||||
|  | 	end | ||||||
|  | end) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | if (minetest.get_modpath("unified_inventory")) then | ||||||
|  | 	unified_inventory.register_button("menu_soundset", { | ||||||
|  | 		type = "image", | ||||||
|  | 		image = "soundset_menu_icon.png", | ||||||
|  | 		tooltip = "sounds menu ", | ||||||
|  | 		action = function(player) | ||||||
|  | 			local name = player:get_player_name() | ||||||
|  | 			on_show_settings(name, sounds.gainplayers[name]["music"], sounds.gainplayers[name]["ambience"]) | ||||||
|  | 		end, | ||||||
|  | 	}) | ||||||
|  | end | ||||||
|  |  | ||||||
|  | minetest.register_chatcommand("soundset", { | ||||||
|  | 	params = "", | ||||||
|  | 	description = "Display volume menu formspec", | ||||||
|  | 	privs = {interact=true}, | ||||||
|  | 	func = function(name, param) | ||||||
|  | 		on_show_settings(name, sounds.gainplayers[name]["music"], sounds.gainplayers[name]["ambience"]) | ||||||
|  | 	end | ||||||
|  | })	 | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | minetest.register_chatcommand("soundsets", { | ||||||
| 	params = "<music|ambience|mobs|other> <number>", | 	params = "<music|ambience|mobs|other> <number>", | ||||||
| 	 description = "set volume sound <music|ambience|mobs|other>", | 	description = "Set volume sound <music|ambience|mobs|other>", | ||||||
| 	privs = {interact=true}, | 	privs = {interact=true}, | ||||||
| 	func = sounds.set_sound, | 	func = sounds.set_sound, | ||||||
| }) | }) | ||||||
|  |  | ||||||
| minetest.register_chatcommand("getsound", { | minetest.register_chatcommand("soundsetg", { | ||||||
| 	params = "", | 	params = "", | ||||||
| 	 description = "print volume sound <music|ambience|mobs|other>", | 	 description = "Display volume sound <music|ambience|mobs|other>", | ||||||
| 	privs = {interact=true}, | 	privs = {interact=true}, | ||||||
| 	func = function(name, param) | 	func = function(name, param) | ||||||
| 		local conf = "" | 		local conf = "" | ||||||
| @@ -109,5 +211,6 @@ minetest.register_on_joinplayer(function(player) | |||||||
| 		sounds.gainplayers[name] = { ["music"] = 50, ["ambience"] = 50, ["mobs"] = 50, ["other"] = 50 } | 		sounds.gainplayers[name] = { ["music"] = 50, ["ambience"] = 50, ["mobs"] = 50, ["other"] = 50 } | ||||||
| 	end | 	end | ||||||
| end) | end) | ||||||
|  |  | ||||||
| minetest.log("action","[mod soundset] Loaded") | minetest.log("action","[mod soundset] Loaded") | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,3 +4,8 @@ by LeMagnesium and crabman77 | |||||||
| YOUR mod can use THIS mod to have a volume that's adjustable by the player(s) | YOUR mod can use THIS mod to have a volume that's adjustable by the player(s) | ||||||
|  |  | ||||||
| 0.1 - Initial Release | 0.1 - Initial Release | ||||||
|  | 0.2 - add menu setting and button for unified_inventory and chatcommand to display menu | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | Licenses images: Author:mikhog  http://opengameart.org/content/play-pause-mute-and-unmute-buttons  CC0 1.0 Universal (CC0 1.0) Public Domain Dedication | ||||||
|   | |||||||
							
								
								
									
										
											BIN
										
									
								
								mods/soundset/textures/soundset_dec.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								mods/soundset/textures/soundset_dec.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 5.5 KiB | 
							
								
								
									
										
											BIN
										
									
								
								mods/soundset/textures/soundset_inc.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								mods/soundset/textures/soundset_inc.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 5.5 KiB | 
							
								
								
									
										
											BIN
										
									
								
								mods/soundset/textures/soundset_menu_icon.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								mods/soundset/textures/soundset_menu_icon.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 6.2 KiB | 
		Reference in New Issue
	
	Block a user