Page 1 of 1

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

Posted: Mon Dec 14, 2020 5:42 pm
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 3202 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]]

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

Posted: Mon Jan 04, 2021 7:13 pm
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.

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

Posted: Tue Jan 05, 2021 8:25 am
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

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

Posted: Tue Jan 05, 2021 2:31 pm
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.

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

Posted: Wed Jan 06, 2021 10:08 pm
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.

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

Posted: Thu Jan 07, 2021 11:25 am
by NIronwolf
Hurray for automating coding. :D

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

Posted: Fri Jan 08, 2021 9:52 pm
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!