Page 1 of 1

Item with quality in sprite-button LuaGuiElement

Posted: Mon Dec 16, 2024 9:43 pm
by VinDust
How to draw item with quality in slot-like sprite-button correctly?

Re: Item with quality in sprite-button LuaGuiElement

Posted: Thu Dec 19, 2024 4:59 pm
by ownlyme
i'm wondering the same thing
an item picker (choose-elem-button) could work in some cases, but for me that's not an option because it needs to show a number too
i'd say generate a sprite for every item you need for all the qualities... (vram is cheap, especially if you're on nvidia /s)

Re: Item with quality in sprite-button LuaGuiElement

Posted: Thu Dec 19, 2024 11:25 pm
by ownlyme

Code: Select all

local function make_sprites(item)
	for _, quality in pairs(data.raw.quality) do
		if quality.icon or quality.icons and quality.icons[1] and (quality.icons[1].filename or quality.icons[1][1]) then
			local spr = {
				type="sprite",
				name = item.name.."-"..quality.name,				
				priority = "extra-high",
				layers = {}
			}
			if item.icons then
				for _, icon in pairs(item.icons) do
					table.insert(spr.layers,{
						filename = icon.filename or icon[1],
						height = icon.icon_size or 64,
						width = icon.icon_size or 64,
					})
				end
			elseif item.icon then
				table.insert(spr.layers,{
					filename = item.icon,
					height = item.icon_size or 64,
					width = item.icon_size or 64,
				})
			end
			if quality.name ~="normal" then
				if quality.icon then
					table.insert(spr.layers,{
						filename = quality.icon,
						height = quality.icon_size or 64,
						width = quality.icon_size or 64,
						scale = 24/( quality.icon_size or 64),
						shift = {-20,20},
					})
				elseif quality.icons then
					table.insert(spr.layers,{
						filename = quality.icons[1].filename or quality.icons[1][1],
						height = quality.icons[1].icon_size or 64,
						width = quality.icons[1].icon_size or 64,
						scale = 24/(quality.icons[1].icon_size or 64),
						shift = {-20,20},
					})
				end
			end
			if #spr.layers >0 then
				data:extend{spr}
			else
				--error(item.name.." "..quality.name)
			end
		end
	end
end