mirror of
				https://github.com/mt-mods/signs_lib.git
				synced 2025-11-04 13:25:29 +01:00 
			
		
		
		
	Compare commits
	
		
			9 Commits
		
	
	
		
			2021-03-01
			...
			1327cb2112
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					1327cb2112 | ||
| 
						 | 
					c08eb3452f | ||
| 
						 | 
					3ee06f9ba2 | ||
| 
						 | 
					02c19e89d9 | ||
| 
						 | 
					8b6f5e23a6 | ||
| 
						 | 
					85dd92fb25 | ||
| 
						 | 
					16b9251511 | ||
| 
						 | 
					b0fac5ef9f | ||
| 
						 | 
					34689b5b04 | 
@@ -22,7 +22,7 @@ That said, there are some basic text formatting options:
 | 
			
		||||
 | 
			
		||||
  Writing "^" followed by a letter "a" through "h" will produce double-wide versions of these arrows, in the same order.  These wide arrows occupy 0x89 to 0x91 in the character set.
 | 
			
		||||
 | 
			
		||||
* A color may be specified in the sign text by using "#" followed by a single hexadcimal digit (0-9 or a-f).  These colors come from the standard Linux/IRC/CGA color set, and are shown in the sign's formspec.  Any color change will remain in effect until changed again, or until the next line break.  Any number of color changes in any arbitrary arrangement is allowed.
 | 
			
		||||
* A color may be specified in the sign text by using "#" followed by a single hexadcimal digit (0-9 or a-f).  These colors come from the standard Linux/IRC/CGA color set, and are shown in the sign's formspec.  Any color change will remain in effect until changed again, or until the next line break.  Any number of color changes in any arbitrary arrangement is allowed. To write "#" on a sign, write "##".
 | 
			
		||||
 | 
			
		||||
* Most writable signs can display double-wide text by flipping a switch in the sign's formspec.
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										91
									
								
								api.lua
									
									
									
									
									
								
							
							
						
						
									
										91
									
								
								api.lua
									
									
									
									
									
								
							@@ -4,6 +4,8 @@ local S = signs_lib.gettext
 | 
			
		||||
 | 
			
		||||
local function get_sign_formspec() end
 | 
			
		||||
 | 
			
		||||
signs_lib.glow_item = "basic_materials:energy_crystal_simple"
 | 
			
		||||
 | 
			
		||||
signs_lib.lbm_restore_nodes = {}
 | 
			
		||||
signs_lib.old_fenceposts = {}
 | 
			
		||||
signs_lib.old_fenceposts_replacement_signs = {}
 | 
			
		||||
@@ -180,7 +182,7 @@ function signs_lib.delete_objects(pos)
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function signs_lib.spawn_entity(pos, texture)
 | 
			
		||||
function signs_lib.spawn_entity(pos, texture, glow)
 | 
			
		||||
	local node = minetest.get_node(pos)
 | 
			
		||||
	local def = minetest.registered_items[node.name]
 | 
			
		||||
	if not def or not def.entity_info then return end
 | 
			
		||||
@@ -229,6 +231,10 @@ function signs_lib.spawn_entity(pos, texture)
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	if glow ~= "" then
 | 
			
		||||
		obj:set_properties( {glow = tonumber(glow * 5)} )
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	if yaw then
 | 
			
		||||
		obj:set_rotation({x = pitch, y = yaw, z=0})
 | 
			
		||||
 | 
			
		||||
@@ -247,14 +253,15 @@ function signs_lib.spawn_entity(pos, texture)
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function signs_lib.set_obj_text(pos, text)
 | 
			
		||||
function signs_lib.set_obj_text(pos, text, glow)
 | 
			
		||||
	local split = signs_lib.split_lines_and_words
 | 
			
		||||
	local text_ansi = Utf8ToAnsi(text)
 | 
			
		||||
	local n = minetest.registered_nodes[minetest.get_node(pos).name]
 | 
			
		||||
	signs_lib.delete_objects(pos)
 | 
			
		||||
	-- only create sign entity for actual text
 | 
			
		||||
	if text_ansi and text_ansi ~= "" then
 | 
			
		||||
		signs_lib.spawn_entity(pos, signs_lib.make_sign_texture(split(text_ansi), pos) )
 | 
			
		||||
		signs_lib.spawn_entity(pos,
 | 
			
		||||
				signs_lib.make_sign_texture(split(text_ansi), pos), glow)
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@@ -548,8 +555,9 @@ local function make_line_texture(line, lineno, pos, line_width, line_height, cwi
 | 
			
		||||
				end
 | 
			
		||||
			end
 | 
			
		||||
			local c = word:sub(i, i)
 | 
			
		||||
			if c == "#" then
 | 
			
		||||
				local cc = tonumber(word:sub(i+1, i+1), 16)
 | 
			
		||||
			local c2 = word:sub(i+1, i+1)
 | 
			
		||||
			if c == "#" and c2 ~= "#" then
 | 
			
		||||
				local cc = tonumber(c2, 16)
 | 
			
		||||
				if cc then
 | 
			
		||||
					i = i + 1
 | 
			
		||||
					cur_color = cc
 | 
			
		||||
@@ -700,13 +708,19 @@ end
 | 
			
		||||
 | 
			
		||||
function signs_lib.rightclick_sign(pos, node, player, itemstack, pointed_thing)
 | 
			
		||||
 | 
			
		||||
	if not signs_lib.can_modify(pos, player) then return end
 | 
			
		||||
	if not player or not signs_lib.can_modify(pos, player) then return end
 | 
			
		||||
 | 
			
		||||
	player:get_meta():set_string("signslib:pos", minetest.pos_to_string(pos))
 | 
			
		||||
	minetest.show_formspec(player:get_player_name(), "signs_lib:sign", get_sign_formspec(pos, node.name))
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function signs_lib.destruct_sign(pos)
 | 
			
		||||
	local meta = minetest.get_meta(pos)
 | 
			
		||||
	local glow = meta:get_string("glow")
 | 
			
		||||
	if glow ~= "" and not minetest.is_creative_enabled("") then
 | 
			
		||||
		local num = tonumber(glow)
 | 
			
		||||
		minetest.add_item(pos, ItemStack(signs_lib.glow_item .. " " .. num))
 | 
			
		||||
	end
 | 
			
		||||
	signs_lib.delete_objects(pos)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@@ -720,6 +734,30 @@ local function make_infotext(text)
 | 
			
		||||
	return table.concat(lines2, "\n")
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function signs_lib.glow(pos, node, puncher)
 | 
			
		||||
	local name = puncher:get_player_name()
 | 
			
		||||
	if minetest.is_protected(pos, name) then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
	local tool = puncher:get_wielded_item()
 | 
			
		||||
	if tool:get_name() == signs_lib.glow_item then
 | 
			
		||||
		local meta = minetest.get_meta(pos)
 | 
			
		||||
		local glow = tonumber(meta:get_string("glow"))
 | 
			
		||||
		if not glow then
 | 
			
		||||
			glow = 1
 | 
			
		||||
		elseif glow < 3 then
 | 
			
		||||
			glow = glow + 1
 | 
			
		||||
		else
 | 
			
		||||
			return -- already at brightest level
 | 
			
		||||
		end
 | 
			
		||||
		if not minetest.is_creative_enabled(name) then
 | 
			
		||||
			tool:take_item()
 | 
			
		||||
			puncher:set_wielded_item(tool)
 | 
			
		||||
		end
 | 
			
		||||
		meta:set_string("glow", glow)
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function signs_lib.update_sign(pos, fields)
 | 
			
		||||
	local meta = minetest.get_meta(pos)
 | 
			
		||||
 | 
			
		||||
@@ -737,7 +775,9 @@ function signs_lib.update_sign(pos, fields)
 | 
			
		||||
 | 
			
		||||
	meta:set_string("text", text)
 | 
			
		||||
	meta:set_string("infotext", ownstr..make_infotext(text).." ")
 | 
			
		||||
	signs_lib.set_obj_text(pos, text)
 | 
			
		||||
 | 
			
		||||
	local glow = meta:get_string("glow")
 | 
			
		||||
	signs_lib.set_obj_text(pos, text, glow)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function signs_lib.can_modify(pos, player)
 | 
			
		||||
@@ -902,6 +942,23 @@ function signs_lib.register_fence_with_sign()
 | 
			
		||||
	minetest.log("warning", "[signs_lib] ".."Attempt to call no longer used function signs_lib.register_fence_with_sign()")
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local use_glow = function(pos, node, puncher, pointed_thing)
 | 
			
		||||
	if puncher then -- if e.g. a machine tries to punch; only a real person should change the lighting
 | 
			
		||||
		signs_lib.glow(pos, node, puncher)
 | 
			
		||||
	end
 | 
			
		||||
	return signs_lib.update_sign(pos)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local glow_drops = function(pos, oldnode, oldmetadata, digger)
 | 
			
		||||
	if digger and minetest.is_creative_enabled(digger:get_player_name()) then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
	local glow = oldmetadata and oldmetadata.fields and oldmetadata.fields.glow
 | 
			
		||||
	if glow then
 | 
			
		||||
		minetest.add_item(pos, ItemStack(signs_lib.glow_item .. " " .. glow))
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function signs_lib.register_sign(name, raw_def)
 | 
			
		||||
	local def = table.copy(raw_def)
 | 
			
		||||
 | 
			
		||||
@@ -917,9 +974,16 @@ function signs_lib.register_sign(name, raw_def)
 | 
			
		||||
	def.after_place_node = raw_def.after_place_node or signs_lib.after_place_node
 | 
			
		||||
 | 
			
		||||
	if raw_def.entity_info then
 | 
			
		||||
 | 
			
		||||
		if def.allow_glow ~= false then
 | 
			
		||||
			def.on_punch        = raw_def.on_punch            or use_glow
 | 
			
		||||
			def.after_dig_node  = raw_def.after_dig_node      or glow_drops
 | 
			
		||||
		else
 | 
			
		||||
			def.on_punch        = raw_def.on_punch            or signs_lib.update_sign
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		def.on_rightclick       = raw_def.on_rightclick       or signs_lib.rightclick_sign
 | 
			
		||||
		def.on_destruct         = raw_def.on_destruct         or signs_lib.destruct_sign
 | 
			
		||||
		def.on_punch            = raw_def.on_punch            or signs_lib.update_sign
 | 
			
		||||
		def.number_of_lines     = raw_def.number_of_lines     or signs_lib.standard_lines
 | 
			
		||||
		def.horiz_scaling       = raw_def.horiz_scaling       or signs_lib.standard_hscale
 | 
			
		||||
		def.vert_scaling        = raw_def.vert_scaling        or signs_lib.standard_vscale
 | 
			
		||||
@@ -1228,16 +1292,17 @@ function get_sign_formspec(pos, nodename)
 | 
			
		||||
 | 
			
		||||
	local formspec = {
 | 
			
		||||
		"size[6,4]",
 | 
			
		||||
		"textarea[0,-0.3;6.5,3;text;;" .. minetest.formspec_escape(txt) .. "]",
 | 
			
		||||
		"background[-0.5,-0.5;7,5;signs_lib_sign_bg.jpg]",
 | 
			
		||||
		"button_exit[2,3.4;2,1;ok;" .. S("Write") .. "]"
 | 
			
		||||
		"background[-0.5,-0.5;7,5;signs_lib_sign_bg.png]",
 | 
			
		||||
		"image[0.1,2.4;7,1;signs_lib_sign_color_palette.png]", 
 | 
			
		||||
		"textarea[0.15,-0.2;6.3,2.8;text;;" .. minetest.formspec_escape(txt) .. "]",
 | 
			
		||||
		"button_exit[3,3.4;2,1;ok;" .. S("Write") .. "]"
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if minetest.registered_nodes[nodename].allow_widefont then
 | 
			
		||||
		local state = "off"
 | 
			
		||||
		if meta:get_int("widefont") == 1 then state = "on" end
 | 
			
		||||
		formspec[5] = "label[0.5,3.4;Use wide font]"
 | 
			
		||||
		formspec[6] = "image_button[0.6,3.7;1,0.6;signs_lib_switch_" .. state .. ".png;"
 | 
			
		||||
		formspec[#formspec+1] = "label[0.9,3.4;Use wide font]"
 | 
			
		||||
		formspec[#formspec+1] = "image_button[1.1,3.7;1,0.6;signs_lib_switch_" .. state .. ".png;"
 | 
			
		||||
				.. state .. ";;;false;signs_lib_switch_interm.png]"
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								mod.conf
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								mod.conf
									
									
									
									
									
								
							@@ -3,4 +3,4 @@ author = VanessaE
 | 
			
		||||
depends = default
 | 
			
		||||
optional_depends = intllib, screwdriver, streetspoles, streetlamps, cottages, prefab_redo
 | 
			
		||||
description = Adds signs with readable text.
 | 
			
		||||
min_minetest_version = 5.2.0
 | 
			
		||||
min_minetest_version = 5.4.0
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 81 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								textures/signs_lib_sign_bg.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								textures/signs_lib_sign_bg.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 75 B  | 
							
								
								
									
										
											BIN
										
									
								
								textures/signs_lib_sign_color_palette.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								textures/signs_lib_sign_color_palette.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 14 KiB  | 
		Reference in New Issue
	
	Block a user