Compare commits
	
		
			26 Commits
		
	
	
		
			9412ac740a
			...
			0de66b1a09
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 0de66b1a09 | ||
|  | aa46556020 | ||
|  | ce59bd35d4 | ||
|  | 8c3efefd92 | ||
|  | 92c6a53fb2 | ||
|  | f17922cf68 | ||
|  | f91436d6ce | ||
|  | 4cc44d004e | ||
|  | 584c215aee | ||
|  | 5b91f9f171 | ||
|  | 54e6406e53 | ||
|  | 917dd8714f | ||
|  | 6ef7dda7de | ||
|  | a3c41cbd8d | ||
|  | 3866c41ab9 | ||
|  | e2c13c4d27 | ||
|  | a7d5653d8f | ||
|  | efe7434dd4 | ||
|  | df26d31a2d | ||
|  | 50d19faa48 | ||
|  | d93f5b0cf2 | ||
|  | f83bc9cccf | ||
|  | f88e0412fc | ||
|  | 6e6ff93d29 | ||
|  | 2fd3604cac | ||
|  | 96f9c85c77 | 
| @@ -1,5 +1,7 @@ | ||||
| #  Crafting Guide | ||||
|  | ||||
| [](https://content.minetest.net/packages/jp/craftguide/) [](https://content.minetest.net/packages/jp/craftguide/) | ||||
|  | ||||
| #### `craftguide` is the most comprehensive crafting guide on Minetest. | ||||
| #### Consult the [Minetest Wiki](http://wiki.minetest.net/Crafting_guide) for more details. | ||||
|  | ||||
|   | ||||
							
								
								
									
										303
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						| @@ -23,6 +23,7 @@ local reg_aliases = core.registered_aliases | ||||
| local log = core.log | ||||
| local after = core.after | ||||
| local clr = core.colorize | ||||
| local sound_play = core.sound_play | ||||
| local parse_json = core.parse_json | ||||
| local write_json = core.write_json | ||||
| local chat_send = core.chat_send_player | ||||
| @@ -103,6 +104,7 @@ local FMT = { | ||||
| 	image = "image[%f,%f;%f,%f;%s]", | ||||
| 	button = "button[%f,%f;%f,%f;%s;%s]", | ||||
| 	tooltip = "tooltip[%f,%f;%f,%f;%s]", | ||||
| 	hypertext = "hypertext[%f,%f;%f,%f;;%s]", | ||||
| 	item_image = "item_image[%f,%f;%f,%f;%s]", | ||||
| 	image_button = "image_button[%f,%f;%f,%f;%s;%s;%s]", | ||||
| 	animated_image = "animated_image[%f,%f;%f,%f;;%s;%u;%u]", | ||||
| @@ -110,6 +112,31 @@ local FMT = { | ||||
| 	arrow = "image_button[%f,%f;0.8,0.8;%s;%s;;;false;%s]", | ||||
| } | ||||
|  | ||||
| local styles = fmt([[ | ||||
| 	style[filter;border=false] | ||||
| 	style_type[label,field;font_size=16] | ||||
| 	style_type[image_button;border=false] | ||||
| 	style_type[button;border=false;font=bold;font_size=18] | ||||
| 	style_type[item_image_button;border=false;bgimg_hovered=%s;bgimg_pressed=%s] | ||||
| 	style[search;fgimg=%s;fgimg_hovered=%s] | ||||
| 	style[clear;fgimg=%s;fgimg_hovered=%s] | ||||
| 	style[prev_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s] | ||||
| 	style[next_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s] | ||||
| 	style[prev_recipe;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s] | ||||
| 	style[next_recipe;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s] | ||||
| 	style[prev_usage;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s] | ||||
| 	style[next_usage;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s] | ||||
| ]], | ||||
| PNG.selected, PNG.selected, | ||||
| PNG.search, PNG.search_hover, | ||||
| PNG.clear, PNG.clear_hover, | ||||
| PNG.prev, PNG.prev_hover, PNG.prev_hover, | ||||
| PNG.next, PNG.next_hover, PNG.next_hover, | ||||
| PNG.prev, PNG.prev_hover, PNG.prev_hover, | ||||
| PNG.next, PNG.next_hover, PNG.next_hover, | ||||
| PNG.prev, PNG.prev_hover, PNG.prev_hover, | ||||
| PNG.next, PNG.next_hover, PNG.next_hover) | ||||
|  | ||||
| local function get_lang_code(name) | ||||
| 	local info = get_player_info(name) | ||||
| 	return info and info.lang_code | ||||
| @@ -145,6 +172,11 @@ craftguide.group_stereotypes = { | ||||
| 	wool = "wool:white", | ||||
| 	wood = "default:wood", | ||||
| 	tree = "default:tree", | ||||
| 	sand = "default:sand", | ||||
| 	glass = "default:glass", | ||||
| 	stick = "default:stick", | ||||
| 	stone = "default:stone", | ||||
| 	leaves = "default:leaves", | ||||
| 	coal = "default:coal_lump", | ||||
| 	vessel = "vessels:glass_bottle", | ||||
| 	flower = "flowers:dandelion_yellow", | ||||
| @@ -153,20 +185,20 @@ craftguide.group_stereotypes = { | ||||
| } | ||||
|  | ||||
| local group_names = { | ||||
| 	carpet = S"Any carpet", | ||||
| 	coal = S"Any coal", | ||||
| 	dye = S"Any dye", | ||||
| 	flower = S"Any flower", | ||||
| 	glass = S"Any glass", | ||||
| 	leaves = S"Any leaves", | ||||
| 	mushroom = S"Any mushroom", | ||||
| 	coal = S"Any coal", | ||||
| 	sand = S"Any sand", | ||||
| 	stick = S"Any stick", | ||||
| 	stone = S"Any kind of stone block", | ||||
| 	tree = S"Any tree", | ||||
| 	vessel = S"Any vessel", | ||||
| 	wool = S"Any wool", | ||||
| 	glass = S"Any glass", | ||||
| 	stick = S"Any stick", | ||||
| 	stone = S"Any stone", | ||||
| 	carpet = S"Any carpet", | ||||
| 	flower = S"Any flower", | ||||
| 	leaves = S"Any leaves", | ||||
| 	vessel = S"Any vessel", | ||||
| 	wood = S"Any wood planks", | ||||
| 	mushroom = S"Any mushroom", | ||||
|  | ||||
| 	["color_red,flower"] = S"Any red flower", | ||||
| 	["color_blue,flower"] = S"Any blue flower", | ||||
| @@ -586,6 +618,7 @@ end | ||||
|  | ||||
| local function get_usages(recipe) | ||||
| 	local added = {} | ||||
|  | ||||
| 	for _, item in pairs(recipe.items) do | ||||
| 		item = reg_aliases[item] or item | ||||
| 		if not added[item] then | ||||
| @@ -624,68 +657,50 @@ local function cache_usages(item) | ||||
| end | ||||
|  | ||||
| local function drop_table(name, drop) | ||||
| 	local drop_sure, drop_maybe = {}, {} | ||||
| 	local count_sure = 0 | ||||
| 	local drop_items = drop.items or {} | ||||
| 	local max_items = drop.max_items | ||||
|  | ||||
| 	for i = 1, #drop_items do | ||||
| 		local di = drop_items[i] | ||||
| 		local valid_rarity = di.rarity and di.rarity > 1 | ||||
|  | ||||
| 		if di.rarity or not max_items or | ||||
| 				(max_items and not di.rarity and count_sure < max_items) then | ||||
| 			for j = 1, #di.items do | ||||
| 				local dstack = ItemStack(di.items[j]) | ||||
| 				local dname  = dstack:get_name() | ||||
| 				local dcount = dstack:get_count() | ||||
| 				local empty  = dstack:is_empty() | ||||
|  | ||||
| 			if not dstack:is_empty() and (dname ~= name or | ||||
| 				if not empty and (dname ~= name or | ||||
| 						(dname == name and dcount > 1)) then | ||||
| 				if not di.rarity or di.rarity <= 1 then | ||||
| 					if drop_sure[dname] then | ||||
| 						if dcount > drop_sure[dname].output then | ||||
| 							dcount = dcount + drop_sure[dname].output | ||||
| 						else | ||||
| 							dcount = drop_sure[dname].output | ||||
| 						end | ||||
| 					end | ||||
| 					local rarity = valid_rarity and di.rarity | ||||
|  | ||||
| 					drop_sure[dname] = { | ||||
| 						output = dcount, | ||||
| 						tools  = di.tools, | ||||
| 					} | ||||
| 				else | ||||
| 					drop_maybe[#drop_maybe + 1] = { | ||||
| 						item   = dname, | ||||
| 						output = dcount, | ||||
| 						rarity = di.rarity, | ||||
| 					craftguide.register_craft{ | ||||
| 						type   = rarity and "digging_chance" or "digging", | ||||
| 						items  = {name}, | ||||
| 						output = fmt("%s %u", dname, dcount), | ||||
| 						rarity = rarity, | ||||
| 						tools  = di.tools, | ||||
| 					} | ||||
| 				end | ||||
| 			end | ||||
| 		end | ||||
| 	end | ||||
|  | ||||
| 	for item, data in pairs(drop_sure) do | ||||
| 		craftguide.register_craft{ | ||||
| 			type   = "digging", | ||||
| 			items  = {name}, | ||||
| 			output = fmt("%s %u", item, data.output), | ||||
| 			tools  = data.tools, | ||||
| 		} | ||||
| 		if not di.rarity then | ||||
| 			count_sure = count_sure + 1 | ||||
| 		end | ||||
|  | ||||
| 	for _, data in ipairs(drop_maybe) do | ||||
| 		craftguide.register_craft{ | ||||
| 			type   = "digging_chance", | ||||
| 			items  = {name}, | ||||
| 			output = fmt("%s %u", data.item, data.output), | ||||
| 			rarity = data.rarity, | ||||
| 			tools  = data.tools, | ||||
| 		} | ||||
| 	end | ||||
| end | ||||
|  | ||||
| local function cache_drops(name, drop) | ||||
| 	if true_str(drop) then | ||||
| 		local dstack = ItemStack(drop) | ||||
| 		if not dstack:is_empty() and dstack:get_name() ~= name then | ||||
| 		local dname  = dstack:get_name() | ||||
| 		local empty  = dstack:is_empty() | ||||
|  | ||||
| 		if not empty and dname ~= name then | ||||
| 			craftguide.register_craft{ | ||||
| 				type = "digging", | ||||
| 				items = {name}, | ||||
| @@ -707,9 +722,21 @@ local function cache_recipes(item) | ||||
| 			_recipes[#recipes + 1 - k] = v | ||||
| 		end | ||||
|  | ||||
| 		local shift = 0 | ||||
| 		local size_rpl = maxn(replacements[item]) | ||||
| 		local size_rcp = #_recipes | ||||
|  | ||||
| 		if size_rpl > size_rcp then | ||||
| 			shift = size_rcp - size_rpl | ||||
| 		end | ||||
|  | ||||
| 		for k, v in pairs(replacements[item]) do | ||||
| 			k = k + shift | ||||
|  | ||||
| 			if _recipes[k] then | ||||
| 				_recipes[k].replacements = v | ||||
| 			end | ||||
| 		end | ||||
|  | ||||
| 		recipes = _recipes | ||||
| 	end | ||||
| @@ -799,11 +826,11 @@ local function toupper(str) | ||||
| 	return str:gsub("%f[%w]%l", upper):gsub("_", " ") | ||||
| end | ||||
|  | ||||
| local function strip_newline(str) | ||||
| 	return match(str, "[^\n]*") | ||||
| local function nice_strip(str, limit) | ||||
| 	return #str > limit and fmt("%s...", sub(str, 1, limit - 3)) or str | ||||
| end | ||||
|  | ||||
| local function get_desc(item, lang_code) | ||||
| local function get_desc(item) | ||||
| 	if sub(item, 1, 1) == "_" then | ||||
| 		item = sub(item, 2) | ||||
| 	end | ||||
| @@ -813,10 +840,13 @@ local function get_desc(item, lang_code) | ||||
| 	if def then | ||||
| 		local desc = def.description | ||||
| 		if true_str(desc) then | ||||
| 			desc = desc:trim():match("[^\n]*") | ||||
|  | ||||
| 			if not find(desc, "%u") then | ||||
| 				return strip_newline(toupper(desc)) | ||||
| 				desc = toupper(desc) | ||||
| 			end | ||||
| 			return strip_newline(translate(lang_code, desc)) | ||||
|  | ||||
| 			return desc | ||||
|  | ||||
| 		elseif true_str(item) then | ||||
| 			return toupper(match(item, ":(.*)")) | ||||
| @@ -826,7 +856,7 @@ local function get_desc(item, lang_code) | ||||
| 	return S("Unknown Item (@1)", item) | ||||
| end | ||||
|  | ||||
| local function get_tooltip(item, info, lang_code) | ||||
| local function get_tooltip(item, info) | ||||
| 	local tooltip | ||||
|  | ||||
| 	if info.groups then | ||||
| @@ -844,7 +874,7 @@ local function get_tooltip(item, info, lang_code) | ||||
| 			tooltip = S("Any item belonging to the group(s): @1", groupstr) | ||||
| 		end | ||||
| 	else | ||||
| 		tooltip = get_desc(item, lang_code) | ||||
| 		tooltip = get_desc(item) | ||||
| 	end | ||||
|  | ||||
| 	local function add(str) | ||||
| @@ -860,13 +890,13 @@ local function get_tooltip(item, info, lang_code) | ||||
| 	end | ||||
|  | ||||
| 	if info.replace then | ||||
| 		for i = 1, #info.replace do | ||||
| 			local rpl = match(info.replace[i], "%S+") | ||||
| 			local desc = clr("#ff0", get_desc(rpl, lang_code)) | ||||
| 		for i = 1, #info.replace.items do | ||||
| 			local rpl = match(info.replace.items[i], "%S+") | ||||
| 			local desc = clr("#ff0", get_desc(rpl)) | ||||
|  | ||||
| 			if info.cooktime then | ||||
| 			if info.replace.type == "cooking" then | ||||
| 				tooltip = add(S("Replaced by @1 on smelting", desc)) | ||||
| 			elseif info.burntime then | ||||
| 			elseif info.replace.type == "fuel" then | ||||
| 				tooltip = add(S("Replaced by @1 on burning", desc)) | ||||
| 			else | ||||
| 				tooltip = add(S("Replaced by @1 on crafting", desc)) | ||||
| @@ -890,21 +920,21 @@ local function get_tooltip(item, info, lang_code) | ||||
| 		if several then | ||||
| 			for i = 1, #info.tools do | ||||
| 				names = fmt("%s\t\t- %s\n", | ||||
| 					names, clr("#ff0", get_desc(info.tools[i], lang_code))) | ||||
| 					names, clr("#ff0", get_desc(info.tools[i]))) | ||||
| 			end | ||||
|  | ||||
| 			tooltip = add(S("Only drop if using one of these tools: @1", | ||||
| 				sub(names, 1, -2))) | ||||
| 		else | ||||
| 			tooltip = add(S("Only drop if using this tool: @1", | ||||
| 				clr("#ff0", get_desc(info.tools[1], lang_code)))) | ||||
| 				clr("#ff0", get_desc(info.tools[1])))) | ||||
| 		end | ||||
| 	end | ||||
|  | ||||
| 	return fmt("tooltip[%s;%s]", item, ESC(tooltip)) | ||||
| end | ||||
|  | ||||
| local function get_output_fs(lang_code, fs, rcp, shapeless, right, btn_size, _btn_size, spacing) | ||||
| local function get_output_fs(fs, rcp, shapeless, right, btn_size, _btn_size, spacing) | ||||
| 	local custom_recipe = craft_types[rcp.type] | ||||
|  | ||||
| 	if custom_recipe or shapeless or rcp.type == "cooking" then | ||||
| @@ -969,7 +999,7 @@ local function get_output_fs(lang_code, fs, rcp, shapeless, right, btn_size, _bt | ||||
| 		} | ||||
|  | ||||
| 		if next(infos) then | ||||
| 			fs[#fs + 1] = get_tooltip(_name, infos, lang_code) | ||||
| 			fs[#fs + 1] = get_tooltip(_name, infos) | ||||
| 		end | ||||
|  | ||||
| 		if infos.burntime then | ||||
| @@ -984,7 +1014,7 @@ local function get_output_fs(lang_code, fs, rcp, shapeless, right, btn_size, _bt | ||||
| 	end | ||||
| end | ||||
|  | ||||
| local function get_grid_fs(lang_code, fs, rcp, spacing) | ||||
| local function get_grid_fs(fs, rcp, spacing) | ||||
| 	local width = rcp.width or 1 | ||||
| 	local right, btn_size, _btn_size = 0, ITEM_BTN_SIZE | ||||
| 	local cooktime, shapeless | ||||
| @@ -1049,11 +1079,11 @@ local function get_grid_fs(lang_code, fs, rcp, spacing) | ||||
| 		for j = 1, #(rcp.replacements or {}) do | ||||
| 			local replacement = rcp.replacements[j] | ||||
| 			if replacement[1] == name then | ||||
| 				replace = replace or {} | ||||
| 				replace = replace or {type = rcp.type, items = {}} | ||||
|  | ||||
| 				local added | ||||
|  | ||||
| 				for _, v in ipairs(replace) do | ||||
| 				for _, v in ipairs(replace.items) do | ||||
| 					if replacement[2] == v then | ||||
| 						added = true | ||||
| 						break | ||||
| @@ -1062,7 +1092,7 @@ local function get_grid_fs(lang_code, fs, rcp, spacing) | ||||
|  | ||||
| 				if not added then | ||||
| 					label = fmt("%s%s\nR", label ~= "" and "\n" or "", label) | ||||
| 					replace[#replace + 1] = replacement[2] | ||||
| 					replace.items[#replace.items + 1] = replacement[2] | ||||
| 				end | ||||
| 			end | ||||
| 		end | ||||
| @@ -1073,13 +1103,7 @@ local function get_grid_fs(lang_code, fs, rcp, spacing) | ||||
| 			fs[#fs + 1] = fmt(FMT.image, X, Y, btn_size, btn_size, PNG.selected) | ||||
| 		end | ||||
|  | ||||
| 		local btn_name = "" | ||||
|  | ||||
| 		if groups then | ||||
| 			btn_name = fmt("group|%s|%s", groups[1], item) | ||||
| 		elseif item ~= "" then | ||||
| 			btn_name = item | ||||
| 		end | ||||
| 		local btn_name = groups and fmt("group|%s|%s", groups[1], item) or item | ||||
|  | ||||
| 		fs[#fs + 1] = fmt(FMT.item_image_button, | ||||
| 			X, Y, btn_size, btn_size, item, btn_name, label) | ||||
| @@ -1101,7 +1125,7 @@ local function get_grid_fs(lang_code, fs, rcp, spacing) | ||||
| 		} | ||||
|  | ||||
| 		if next(infos) then | ||||
| 			fs[#fs + 1] = get_tooltip(btn_name, infos, lang_code) | ||||
| 			fs[#fs + 1] = get_tooltip(btn_name, infos) | ||||
| 		end | ||||
| 	end | ||||
|  | ||||
| @@ -1109,25 +1133,25 @@ local function get_grid_fs(lang_code, fs, rcp, spacing) | ||||
| 		fs[#fs + 1] = "style_type[item_image_button;border=false]" | ||||
| 	end | ||||
|  | ||||
| 	get_output_fs(lang_code, fs, rcp, shapeless, right, btn_size, _btn_size, spacing) | ||||
| 	get_output_fs(fs, rcp, shapeless, right, btn_size, _btn_size, spacing) | ||||
| end | ||||
|  | ||||
| local function get_rcp_lbl(lang_code, show_usages, unum, rnum, fs, panel, spacing, rn, is_recipe) | ||||
| local function get_rcp_lbl(fs, data, panel, spacing, rn, is_recipe) | ||||
| 	local lbl | ||||
|  | ||||
| 	if (not sfinv_only and is_recipe) or (sfinv_only and not show_usages) then | ||||
| 		lbl = ES("Recipe @1 of @2", rnum, rn) | ||||
| 	if (not sfinv_only and is_recipe) or (sfinv_only and not data.show_usages) then | ||||
| 		lbl = ES("Recipe @1 of @2", data.rnum, rn) | ||||
|  | ||||
| 	elseif not sfinv_only or (sfinv_only and show_usages) then | ||||
| 		lbl = ES("Usage @1 of @2", unum, rn) | ||||
| 	elseif not sfinv_only or (sfinv_only and data.show_usages) then | ||||
| 		lbl = ES("Usage @1 of @2", data.unum, rn) | ||||
|  | ||||
| 	elseif sfinv_only then | ||||
| 		lbl = show_usages and ES("Usage @1 of @2", unum, rn) or | ||||
| 			ES("Recipe @1 of @2", rnum, rn) | ||||
| 		lbl = data.show_usages and ES("Usage @1 of @2", data.unum, rn) or | ||||
| 			ES("Recipe @1 of @2", data.rnum, rn) | ||||
| 	end | ||||
|  | ||||
| 	lbl = translate(lang_code, lbl) | ||||
| 	local lbl_len = #(lbl):gsub("[\128-\191]", "") -- Count chars, not bytes in UTF-8 strings | ||||
| 	local _lbl = translate(data.lang_code, lbl) | ||||
| 	local lbl_len = #_lbl:gsub("[\128-\191]", "") -- Count chars, not bytes in UTF-8 strings | ||||
| 	local shift = min(0.9, abs(13 - max(13, lbl_len)) * 0.1) | ||||
|  | ||||
| 	fs[#fs + 1] = fmt(FMT.label, | ||||
| @@ -1141,33 +1165,25 @@ local function get_rcp_lbl(lang_code, show_usages, unum, rnum, fs, panel, spacin | ||||
| 		local x_arrow = XOFFSET + (sfinv_only and 1.7 or 1) | ||||
| 		local y_arrow = YOFFSET + (sfinv_only and 3.3 or 1.4 + spacing) | ||||
|  | ||||
| 		fs[#fs + 1] = fmt([[ | ||||
| 			style[%s;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s] | ||||
| 			style[%s;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s] | ||||
| 		]], | ||||
| 		prev_name, PNG.prev, PNG.prev_hover, PNG.prev_hover, | ||||
| 		next_name, PNG.next, PNG.next_hover, PNG.next_hover) | ||||
|  | ||||
| 		fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2), | ||||
| 			x_arrow - shift, y_arrow, PNG.prev, prev_name, "", | ||||
| 			x_arrow + 1.8,   y_arrow, PNG.next, next_name, "") | ||||
| 	end | ||||
|  | ||||
| 	local rcp = is_recipe and panel.rcp[rnum] or panel.rcp[unum] | ||||
| 	get_grid_fs(lang_code, fs, rcp, spacing) | ||||
| 	local rcp = is_recipe and panel.rcp[data.rnum] or panel.rcp[data.unum] | ||||
| 	get_grid_fs(fs, rcp, spacing) | ||||
| end | ||||
|  | ||||
| local function get_title_fs(query_item, lang_code, favs, fs, spacing) | ||||
| 	local desc = ESC(get_desc(query_item, lang_code)) | ||||
| 	desc = #desc > 33 and fmt("%s...", sub(desc, 1, 30)) or desc | ||||
| 	local t_desc = query_item | ||||
| 	t_desc = #t_desc > 40 and fmt("%s...", sub(t_desc, 1, 37)) or t_desc | ||||
| local function get_title_fs(query_item, favs, fs, spacing) | ||||
| 	fs[#fs + 1] = "style_type[label;font=bold;font_size=22]" | ||||
| 	fs[#fs + 1] = fmt(FMT.label, 8.75, spacing - 0.1, nice_strip(ESC(get_desc(query_item)), 45)) | ||||
| 	fs[#fs + 1] = "style_type[label;font=mono;font_size=16]" | ||||
| 	fs[#fs + 1] = fmt(FMT.label, 8.75, spacing + 0.3, clr("#7bf", nice_strip(query_item, 35))) | ||||
| 	fs[#fs + 1] = "style_type[label;font=normal;font_size=16]" | ||||
|  | ||||
| 	fs[#fs + 1] = fmt("hypertext[9.05,%f;5.85,1.2;;%s]", | ||||
| 		spacing - 0.1, | ||||
| 		fmt("<item name=%s float=right width=64 height=64 rotate=yes>" .. | ||||
| 		    "<big><b>%s</b></big>\n<style color=#7bf font=mono>%s</style>", | ||||
| 			query_item, desc, t_desc)) | ||||
| 	fs[#fs + 1] = fmt(FMT.hypertext, | ||||
| 		13.8, spacing - 0.15, 1.1, 1.3, | ||||
| 		fmt("<item name=%s width=64 rotate=yes>", query_item)) | ||||
|  | ||||
| 	local fav = is_fav(favs, query_item) | ||||
| 	local nfavs = #favs | ||||
| @@ -1196,17 +1212,15 @@ local function get_title_fs(query_item, lang_code, favs, fs, spacing) | ||||
| 	end | ||||
| end | ||||
|  | ||||
| local function get_panels(lang_code, query_item, recipes, usages, show_usages, | ||||
| 			  favs, unum, rnum, fs) | ||||
|  | ||||
| local function get_panels(data, fs) | ||||
| 	local _title   = {name = "title", height = 1.2} | ||||
| 	local _favs    = {name = "favs",  height = 1.91} | ||||
| 	local _recipes  = {name = "recipes", rcp = recipes, height = 3.5} | ||||
| 	local _usages   = {name = "usages",  rcp = usages,  height = 3.5} | ||||
| 	local _recipes = {name = "recipes", rcp = data.recipes, height = 3.5} | ||||
| 	local _usages  = {name = "usages",  rcp = data.usages,  height = 3.5} | ||||
| 	local panels   = {_title, _recipes, _usages, _favs} | ||||
|  | ||||
| 	if sfinv_only then | ||||
| 		panels = {show_usages and _usages or _recipes} | ||||
| 		panels = {data.show_usages and _usages or _recipes} | ||||
| 	end | ||||
|  | ||||
| 	for idx = 1, #panels do | ||||
| @@ -1219,12 +1233,11 @@ local function get_panels(lang_code, query_item, recipes, usages, show_usages, | ||||
| 		end | ||||
|  | ||||
| 		local rn = panel.rcp and #panel.rcp | ||||
| 		local is_recipe = sfinv_only and not show_usages or panel.name == "recipes" | ||||
| 		local is_recipe = sfinv_only and not data.show_usages or panel.name == "recipes" | ||||
| 		local recipe_or_usage = panel.name == "recipes" or panel.name == "usages" | ||||
|  | ||||
| 		if rn then | ||||
| 			get_rcp_lbl(lang_code, show_usages, unum, rnum, fs, panel, | ||||
| 				    spacing, rn, is_recipe) | ||||
| 			get_rcp_lbl(fs, data, panel, spacing, rn, is_recipe) | ||||
| 		end | ||||
|  | ||||
| 		if sfinv_only then return end | ||||
| @@ -1233,26 +1246,24 @@ local function get_panels(lang_code, query_item, recipes, usages, show_usages, | ||||
| 			-0.2 + spacing, panel.height, PNG.bg_full, 10) | ||||
|  | ||||
| 		if recipe_or_usage and not rn then | ||||
| 			local X = XOFFSET - 0.7 | ||||
| 			local Y = YOFFSET - 0.4 + spacing | ||||
| 			local lbl = is_recipe and ES"No recipes" or ES"No usages" | ||||
|  | ||||
| 			fs[#fs + 1] = fmt(FMT.image, X, Y, 2, 2, PNG.nothing) | ||||
|  | ||||
| 			fs[#fs + 1] = fmt(FMT.tooltip, | ||||
| 				X, Y, 2, 2, is_recipe and ES"No recipes" or ES"No usages") | ||||
| 			fs[#fs + 1] = fmt(FMT.hypertext, | ||||
| 				8.29, YOFFSET + spacing + 0.3, 6.8, 1, | ||||
| 				fmt("<center><style size=20><b>%s</b></style></center>", lbl)) | ||||
|  | ||||
| 		elseif panel.name == "title" then | ||||
| 			get_title_fs(query_item, lang_code, favs, fs, spacing) | ||||
| 			get_title_fs(data.query_item, data.favs, fs, spacing) | ||||
|  | ||||
| 		elseif panel.name == "favs" then | ||||
| 			fs[#fs + 1] = fmt(FMT.label, 8.3, spacing - 0.15, ES"Bookmarks") | ||||
|  | ||||
| 			for i = 1, #favs do | ||||
| 				local item = favs[i] | ||||
| 			for i = 1, #data.favs do | ||||
| 				local item = data.favs[i] | ||||
| 				local X = 7.85 + (i - 0.5) | ||||
| 				local Y = spacing + 0.4 | ||||
|  | ||||
| 				if query_item == item then | ||||
| 				if data.query_item == item then | ||||
| 					fs[#fs + 1] = fmt(FMT.image, X, Y, | ||||
| 						ITEM_BTN_SIZE, ITEM_BTN_SIZE, PNG.selected) | ||||
| 				end | ||||
| @@ -1279,30 +1290,15 @@ local function make_fs(data) | ||||
| 			9 - 0.9, LINES + 0.4, PNG.bg_full, 10) | ||||
| 	end | ||||
|  | ||||
| 	fs[#fs + 1] = styles | ||||
|  | ||||
| 	fs[#fs + 1] = fmt([[ | ||||
| 		style[filter;border=false] | ||||
| 		field[0.4,0.2;2.6,1;filter;;%s] | ||||
| 		field_close_on_enter[filter;false] | ||||
| 		box[0,0;2.5,0.6;#bababa25] | ||||
| 	]], | ||||
| 	ESC(data.filter)) | ||||
|  | ||||
| 	fs[#fs + 1] = fmt([[ | ||||
| 		style_type[label,field;font_size=16] | ||||
| 		style_type[image_button;border=false] | ||||
| 		style_type[button;border=false;font=bold;font_size=18] | ||||
| 		style_type[item_image_button;border=false;bgimg_hovered=%s;bgimg_pressed=%s] | ||||
| 		style[search;fgimg=%s;fgimg_hovered=%s] | ||||
| 		style[clear;fgimg=%s;fgimg_hovered=%s] | ||||
| 		style[prev_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s] | ||||
| 		style[next_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s] | ||||
| 	]], | ||||
| 	PNG.selected, PNG.selected, | ||||
| 	PNG.search, PNG.search_hover, | ||||
| 	PNG.clear, PNG.clear_hover, | ||||
| 	PNG.prev, PNG.prev_hover, PNG.prev_hover, | ||||
| 	PNG.next, PNG.next_hover, PNG.next_hover) | ||||
|  | ||||
| 	fs[#fs + 1] = fmt(mul_elem(FMT.image_button, 2), | ||||
| 		2.6, -0.06, 0.85, 0.85, "", "search", "", | ||||
| 		3.3, -0.06, 0.85, 0.85, "", "clear", "") | ||||
| @@ -1332,10 +1328,9 @@ local function make_fs(data) | ||||
| 			lbl = ES"Collect items to reveal more recipes" | ||||
| 		end | ||||
|  | ||||
| 		fs[#fs + 1] = fmt("hypertext[%f,%f;%f,%f;;%s]", | ||||
| 		fs[#fs + 1] = fmt(FMT.hypertext, | ||||
| 			0.05, 3, 8.29, 1, | ||||
| 			fmt("<center><style size=20><b>%s</b></style></center>]", | ||||
| 				translate(data.lang_code, lbl))) | ||||
| 			fmt("<center><style size=20><b>%s</b></style></center>", lbl)) | ||||
| 	end | ||||
|  | ||||
| 	local first_item = (data.pagenum - 1) * IPP | ||||
| @@ -1358,8 +1353,7 @@ local function make_fs(data) | ||||
| 	end | ||||
|  | ||||
| 	if (data.recipes and #data.recipes > 0) or (data.usages and #data.usages > 0) then | ||||
| 		get_panels(data.lang_code, data.query_item, data.recipes, data.usages, | ||||
| 			   data.show_usages, data.favs, data.unum, data.rnum, fs) | ||||
| 		get_panels(data, fs) | ||||
| 	end | ||||
|  | ||||
| 	return concat(fs) | ||||
| @@ -1486,15 +1480,15 @@ core.register_craft = function(def) | ||||
| 	end | ||||
|  | ||||
| 	for i = 1, #output do | ||||
| 		local name = output[i] | ||||
| 		rcp_num[name] = (rcp_num[name] or 0) + 1 | ||||
| 		local item = output[i] | ||||
| 		rcp_num[item] = (rcp_num[item] or 0) + 1 | ||||
|  | ||||
| 		if def.replacements then | ||||
| 			if def.type == "fuel" then | ||||
| 				replacements.fuel[name] = def.replacements | ||||
| 				replacements.fuel[item] = def.replacements | ||||
| 			else | ||||
| 				replacements[name] = replacements[name] or {} | ||||
| 				replacements[name][rcp_num[name]] = def.replacements | ||||
| 				replacements[item] = replacements[item] or {} | ||||
| 				replacements[item][rcp_num[item]] = def.replacements | ||||
| 			end | ||||
| 		end | ||||
| 	end | ||||
| @@ -1631,9 +1625,14 @@ on_joinplayer(function(player) | ||||
| end) | ||||
|  | ||||
| local function fields(player, _f) | ||||
| 	if _f.quit then return end | ||||
| 	local name = player:get_player_name() | ||||
| 	local data = pdata[name] | ||||
|  | ||||
| 	if not _f.key_enter_field then | ||||
| 		sound_play("craftguide_click", {to_player = name, gain = 0.2}) | ||||
| 	end | ||||
|  | ||||
| 	if _f.clear then | ||||
| 		reset_data(data) | ||||
|  | ||||
| @@ -2124,13 +2123,11 @@ function craftguide.show(name, item, show_usages) | ||||
| 	if not recipes and not usages then | ||||
| 		if not recipes_cache[item] and not usages_cache[item] then | ||||
| 			return false, msg(name, fmt("%s: %s", | ||||
| 				S"No recipe or usage for this item", | ||||
| 				get_desc(item, data.lang_code))) | ||||
| 				S"No recipe or usage for this item", get_desc(item))) | ||||
| 		end | ||||
|  | ||||
| 		return false, msg(name, fmt("%s: %s", | ||||
| 			S"You don't know a recipe or usage for this item", | ||||
| 			get_desc(item, data.lang_code))) | ||||
| 			S"You don't know a recipe or usage for this item", get_desc(item))) | ||||
| 	end | ||||
|  | ||||
| 	data.query_item = item | ||||
|   | ||||
							
								
								
									
										40
									
								
								locale/craftguide.zh_CN.tr
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,40 @@ | ||||
| # textdomain: craftguide | ||||
|  | ||||
| Any black dye=任何黑染料 | ||||
| Any black flower=任何黑花 | ||||
| Any blue dye=任何蓝染料 | ||||
| Any blue flower=任何蓝花 | ||||
| Any brown dye=任何棕染料 | ||||
| Any coal=任何煤炭 | ||||
| Any cyan dye=任何青染料 | ||||
| Any dark green dye=任何暗绿染料 | ||||
| Any dark grey dye=任何暗灰染料 | ||||
| Any green dye=任何绿染料 | ||||
| Any green flower=任何绿花 | ||||
| Any grey dye=任何灰染料 | ||||
| Any item belonging to the group(s): @1=任何属于以下组别的物品:@1 | ||||
| Any kind of stone block=任何石方块 | ||||
| Any magenta dye=任何品红染料 | ||||
| Any orange dye=任何橙染料 | ||||
| Any orange flower=任何橙花 | ||||
| Any pink dye=任何粉红染料 | ||||
| Any red dye=任何红染料 | ||||
| Any red flower=任何红花 | ||||
| Any sand=任何沙 | ||||
| Any stick=任何棒 | ||||
| Any vessel=任何容器 | ||||
| Any violet dye=任何紫染料 | ||||
| Any violet flower=任何紫花 | ||||
| Any white dye=任何白染料 | ||||
| Any white flower=任何白花 | ||||
| Any wood planks=任何木板 | ||||
| Any wool=任何羊毛 | ||||
| Any yellow dye=任何黄染料 | ||||
| Any yellow flower=任何黄花 | ||||
| Cooking time: @1=熔炼时间为:@1 | ||||
| No items to show=没有可显示的项目。 | ||||
| Recipe @1 of @2=第@1个配方,共@2个 | ||||
| Usage @1 of @2=第@1个用法,共@2个 | ||||
| Recipe is too big to be displayed=配方太大,无法显示。 | ||||
| Shapeless=无序配方 | ||||
| Unknown Item=不明物品 | ||||
| @@ -27,7 +27,7 @@ Any dark grey dye= | ||||
| Any green dye= | ||||
| Any green flower= | ||||
| Any grey dye= | ||||
| Any kind of stone block= | ||||
| Any stone= | ||||
| Any magenta dye= | ||||
| Any orange dye= | ||||
| Any orange flower= | ||||
|   | ||||
							
								
								
									
										
											BIN
										
									
								
								sounds/craftguide_click.ogg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| Before Width: | Height: | Size: 230 B After Width: | Height: | Size: 3.2 KiB | 
| Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 1.3 KiB | 
| Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 2.6 KiB | 
| Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 2.2 KiB | 
| Before Width: | Height: | Size: 708 B After Width: | Height: | Size: 4.1 KiB | 
| Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 5.0 KiB | 
| Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 5.4 KiB | 
| Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.6 KiB | 
| Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 7.3 KiB | 
| Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 5.1 KiB | 
| Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 2.4 KiB | 
| Before Width: | Height: | Size: 727 B After Width: | Height: | Size: 2.7 KiB | 
| Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 3.3 KiB | 
| Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 1.6 KiB | 
| Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 6.1 KiB | 
| Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.5 KiB | 
| Before Width: | Height: | Size: 912 B After Width: | Height: | Size: 1.3 KiB | 
| Before Width: | Height: | Size: 305 B After Width: | Height: | Size: 3.9 KiB | 
| Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.0 KiB | 
| Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 2.3 KiB |