Page 1 of 1
[0.13] Checkbox style
Posted: Sun Jul 03, 2016 12:56 pm
by Helfima
Hello
i have un probleme on checkbox style, the image are splited see the attachement
Code: Select all
function simpleIcon(filename, width, height, scale, shift, position)
return {
filename = filename,
width = width,
height = height,
scale = scale,
shift = shift,
x = position.x,
y = position.y
}
end
local function addCheckboxStyleX32(name,icon,iconSize)
local iconSize = 32
local size = iconSize
local offset = 10
data.raw["gui-style"].default[name] = {
type = "checkbox_style",
parent = "checkbox_style",
width = iconSize,
height = iconSize,
default_background = simpleIcon("__core__/graphics/gui.png", 36, 36, size/18, {offset,0}, {x=111,y=0}),
hovered_background = simpleIcon("__core__/graphics/gui.png", 36, 36, size/18, {offset,0}, {x=148,y=0}),
clicked_background = simpleIcon("__core__/graphics/gui.png", 36, 36, size/18, {offset,0}, {x=184,y=0}),
disabled_background = simpleIcon("__core__/graphics/gui.png", 36, 36, size/18, {offset,0}, {x=111,y=0}),
checked = simpleIcon(icon, iconSize, iconSize, 0.7, {3,0}, {x=0,y=0})
}
end
Re: [0.13] Checkbox style
Posted: Tue Jul 05, 2016 11:37 am
by binbinhfr
Sometimes, when I have cropping problems like this, I delete the cache file in the main factorio directory, so it will be regenerated.
Re: [0.13] Checkbox style
Posted: Wed Jul 06, 2016 8:15 am
by Helfima
i have suppressed the AppData\Roaming\Factorio folder but no change
Re: [0.13] Checkbox style
Posted: Wed Jul 06, 2016 9:13 am
by binbinhfr
Helfima wrote:i have suppressed the AppData\Roaming\Factorio folder but no change
the file I was speaking of is named crop-cache.dat .
Re: [0.13] Checkbox style
Posted: Wed Jul 06, 2016 1:54 pm
by Helfima
hum i have deleted crop-cache.dat in the first time but not ok
Re: [0.13] Checkbox style
Posted: Thu Jul 07, 2016 11:43 am
by Helfima
now we must use sprite button
http://lua-api.factorio.com/0.13.6/LuaG ... ent.sprite
it's ok for item/recipe but wait 0.13.6 for more supported type
viewtopic.php?f=11&t=28390#p180308
when it's ready i write the solution
Re: [0.13] Checkbox style
Posted: Thu Jul 07, 2016 3:15 pm
by binbinhfr
could you please explain how you use the sprite button for displaying any game's item icon ?
for me, item icon path is available in data.lua runtime, but not in control.lua where you create the sprite button and you need the path... I must miss something

Re: [0.13] Checkbox style
Posted: Fri Jul 08, 2016 2:35 pm
by binbinhfr
Any idea ? I still wonder how you can get the filepath of any item from control.lua, in order to stick it into the sprite variable...
Re: [0.13] Checkbox style
Posted: Fri Jul 08, 2016 3:07 pm
by Helfima
sorry last day i m so tired and i no explained
i make a quite response (i'm working)
it's not the path of image, it's a key "<element_type>/<element_name>" for exemple "item/iron-steel" is the key for iron steel element
but for recipe it's particular, u must check if the name exist in item_prototype
u must define a style for the button (for the size of button)
step1: get the type
Code: Select all
function PlayerController.methods:getRecipeIconType(recipe)
local item = self:getItemPrototype(recipe.name)
if item ~= nil then
return "item"
end
local fluid = self:getFluidPrototype(recipe.name)
if fluid ~= nil then
return "fluid"
else
return "recipe"
end
end
step2: add sprite button
Code: Select all
--------------------------------------------------------------------------------------
--@param parent - LuaGuiElement
--@param style- string style
--@param action- string action
--@param type- string type of element
--@param key- string name of element
--@param caption- string label for string button
function ElementGui.methods:addStyledSpriteButton(parent, style, action, type, key, caption)
Logging:trace("ElementGui:addStyledSpriteButton", style,action, type, key, caption)
local options = {}
options.type = "sprite-button"
if key ~= nil then
options.name = action..key
else
options.name = action
end
options.style = style
options.sprite = type.."/"..key
local button = nil
local ok , err = pcall(function()
button = parent.add(options)
end)
if not ok then
Logging:error("ElementGui:addStyledSpriteButton", action, type, key, err)
if parent[options.name] and parent[options.name].valid then
parent[options.name].destroy()
end
self:addIconButton(parent, action, type, key, caption)
end
return button
end
Re: [0.13] Checkbox style
Posted: Fri Jul 08, 2016 3:46 pm
by binbinhfr
it's not the path of image, it's a key "<element_type>/<element_name>" for exemple "item/iron-steel" is the key for iron steel element
OK !!!
In the doc it's written "Path the the image to display on this sprite-button."
I thought it was a file path, like filename in pictures of data... ex : filename = "__core__/graphics/gui.png",
How did you figure it out that it was in the form <element_type>/<element_name> ???
Re: [0.13] Checkbox style
Posted: Mon Jul 11, 2016 12:47 pm
by Helfima
Re: [0.13] Checkbox style
Posted: Mon Jul 11, 2016 1:18 pm
by binbinhfr
yes ! this type, I red the release notes !!!
