sorcery  ui.lua at [b96185e88b]

File lib/ui.lua artifact a001c55363 part of check-in b96185e88b


local l = sorcery.lib
local dui = sorcery.data.ui

return {
	tooltip = function(a)
		local color = a.color
		if color == nil then color = l.color(136,158,177) end
		local str = a.title
		if a.desc then
			str = str .. '\n' .. color:fmt(minetest.wrap_text(a.desc,60))
		end
		if a.props then
			-- str = str .. '\n'
			for _,prop in pairs(a.props) do
				local c
				if prop.color and l.color.id(prop.color) then
					c = prop.color
				elseif dui.colors[prop.affinity] then
					c = l.color(dui.colors[prop.affinity])
				else
					c = l.color(dui.colors.neutral)
				end

				str = str .. '\n ' .. c:fmt('* ')

				if prop.title then
					str = str .. c:brighten(1.3):fmt(prop.title) .. ': '
				end

				local lines = minetest.wrap_text(prop.desc, 50, true)
				str = str .. c:fmt(lines[1])
				for i=2,#lines do
					str = str .. '\n' .. string.rep(' ',5) .. c:fmt(lines[i])
				end
			end
		end
		return str
	end;
}