[kovarex] [1.1.5] LuaStyle overrides are not save-stable after setting style.

This subforum contains all the issues which we already resolved.
Post Reply
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5202
Joined: Tue Jul 12, 2016 9:03 am
Contact:

[kovarex] [1.1.5] LuaStyle overrides are not save-stable after setting style.

Post by eradicator »

What

Setting a style by name on a LuaGuiElement that already has manual style overrides removes the overrides - but only after save/load.

guistyle.png
guistyle.png (162.34 KiB) Viewed 1670 times

Expected behavior

Gui apperance should not be altered by save/load cycles.

Explanation

I'm using on_gui_changed_* events to change the style of textboxes to 'invalid_value_textfield' when the user inputs garbage, and back to normal when the value becomes ok. But because the textfield had a fxied width set upon creation i noticed that this resets the fixed width - but only if the user saves/loads while the gui is still open. I don't want to have to create two seperate gui style prototypes for every text field of non-standard width...

Reproduction
  1. Use the code.
  2. Save the game.
  3. Load the game.
  4. See how the gui changed.

Code: Select all

/c

local p = game.player
p.gui.center.clear()

local f = p.gui.center.add{
  type = 'frame'
  }
  
f.style.width = 190
  
local x1 = f.add{
  type = 'textfield',
  text = 'Short text',
  }

x1.style.width = 80
x1.style.minimal_width = 10
x1.style.horizontally_squashable = true

local x2 = f.add{
  type = 'textfield',
  text = 'Short text',
  }

x2.style.width = 80
x2.style = 'textbox' --[[this triggers the bug]]
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Rseding91
Factorio Staff
Factorio Staff
Posts: 12231
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.1.5] LuaStyle overrides are not save-stable after setting style.

Post by Rseding91 »

Looking into this; this is going to be a difficult one to "fix".

The issue is: the actual widget has the runtime-AGUI style values set and then when the mod changes the runtime-Factorio styles it has no idea it needs to go over and un-set values on the AGUI version. It only ever checks "if factorio-style has-value -> set AGUI-style value" and leaves behind values from the old factorio-style.

There are 30 different style types each with 5-20 style values; so around 350~ different values that could be set/unset when changing a styles parent.

I'm not sure if there's any good way to go about clearning things that shouldn't be set anymore. The style system was never built to handle removing style values; only adding and or changing ones that exist.

The actual factorio-style values that mods have read/write access to are stable. It's the AGUI-style values that get cleared and re-built when you save->exit->load the game. They are keeping old values around from the old factorio-styles.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5032
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [1.1.5] LuaStyle overrides are not save-stable after setting style.

Post by Klonan »

I think setting the style by name should reset everything to default values, and then only populate the values defined by the specific style,

So if you set 'width = 80', then 'style = textfield', the width would be cleared.
(You can then override afterwards using LuaStyle

Rseding91
Factorio Staff
Factorio Staff
Posts: 12231
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.1.5] LuaStyle overrides are not save-stable after setting style.

Post by Rseding91 »

Klonan wrote:
Tue Jan 05, 2021 8:25 am
I think setting the style by name should reset everything to default values, and then only populate the values defined by the specific style,

So if you set 'width = 80', then 'style = textfield', the width would be cleared.
(You can then override afterwards using LuaStyle
That's the goal; but as I described above the entire style system isn't built to work that way so it's going to be a lot of tedious work to make it happen and make sure it doesn't crash when it does.
If you want to get ahold of me I'm almost always on Discord.

kovarex
Factorio Staff
Factorio Staff
Posts: 8058
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [1.1.5] LuaStyle overrides are not save-stable after setting style.

Post by kovarex »

Thanks for the report, it is now fixed for the next version. When testing it, I also noticed, that the widget doesn't trigger resize according to the new style size restriction when the parent size is changed, so it was fixed as well.
Rseding91 wrote:
Mon Jan 04, 2021 7:13 pm
There are 30 different style types each with 5-20 style values; so around 350~ different values that could be set/unset when changing a styles parent.
With the help of fast editing and regex, making the clear method wasn't that big of a thing.

User avatar
NIronwolf
Inserter
Inserter
Posts: 35
Joined: Sat Jul 07, 2018 6:44 am
Contact:

Re: [kovarex] [1.1.5] LuaStyle overrides are not save-stable after setting style.

Post by NIronwolf »

Hurray for automating coding. :D

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5202
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [1.1.5] LuaStyle overrides are not save-stable after setting style.

Post by eradicator »

Klonan wrote:
Tue Jan 05, 2021 8:25 am
I think setting the style by name should reset everything to default values
Yes. That would be logical thing. Thus it becomes an easy to fix bug in my mod :D.

kovarex wrote:
Wed Jan 06, 2021 10:08 pm
Thanks for the report, it is now fixed for the next version
Great.

Have a nice new Year everyone!
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Resolved Problems and Bugs”