[0.13] Checkbox style

Place to get help with not working mods / modding interface.
Post Reply
Helfima
Fast Inserter
Fast Inserter
Posts: 199
Joined: Tue Jun 28, 2016 11:40 am
Contact:

[0.13] Checkbox style

Post 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

Attachments
2016-07-03_144833.png
2016-07-03_144833.png (315.68 KiB) Viewed 3736 times

User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: [0.13] Checkbox style

Post 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.
My mods on the Factorio Mod Portal :geek:

Helfima
Fast Inserter
Fast Inserter
Posts: 199
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: [0.13] Checkbox style

Post by Helfima »

i have suppressed the AppData\Roaming\Factorio folder but no change

User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: [0.13] Checkbox style

Post 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 .
My mods on the Factorio Mod Portal :geek:

Helfima
Fast Inserter
Fast Inserter
Posts: 199
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: [0.13] Checkbox style

Post by Helfima »

hum i have deleted crop-cache.dat in the first time but not ok

Helfima
Fast Inserter
Fast Inserter
Posts: 199
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: [0.13] Checkbox style

Post 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

User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: [0.13] Checkbox style

Post 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 ;-)
My mods on the Factorio Mod Portal :geek:

User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: [0.13] Checkbox style

Post 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...
My mods on the Factorio Mod Portal :geek:

Helfima
Fast Inserter
Fast Inserter
Posts: 199
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: [0.13] Checkbox style

Post 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

User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: [0.13] Checkbox style

Post 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> ???
My mods on the Factorio Mod Portal :geek:


User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: [0.13] Checkbox style

Post by binbinhfr »

yes ! this type, I red the release notes !!! :-)
My mods on the Factorio Mod Portal :geek:

Post Reply

Return to “Modding help”