Item with quality in sprite-button LuaGuiElement

Place to get help with not working mods / modding interface.
VinDust
Manual Inserter
Manual Inserter
Posts: 2
Joined: Wed Nov 27, 2024 6:00 pm
Contact:

Item with quality in sprite-button LuaGuiElement

Post by VinDust »

How to draw item with quality in slot-like sprite-button correctly?
User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 444
Joined: Thu Dec 21, 2017 8:02 am
Contact:

Re: Item with quality in sprite-button LuaGuiElement

Post 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)
creator of 55 mods
My api requests/suggestions: ui relative for overlay||Grenade arc||Player Modifiers||textbox::selection||Singleplayer RCON||disable car's ground sounds
User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 444
Joined: Thu Dec 21, 2017 8:02 am
Contact:

Re: Item with quality in sprite-button LuaGuiElement

Post 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
creator of 55 mods
My api requests/suggestions: ui relative for overlay||Grenade arc||Player Modifiers||textbox::selection||Singleplayer RCON||disable car's ground sounds
Post Reply

Return to “Modding help”