[Rseding91] [0.17.37]choose-elem-button: wierd interaction with locked button and updating style

This subforum contains all the issues which we already resolved.
Post Reply
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

[Rseding91] [0.17.37]choose-elem-button: wierd interaction with locked button and updating style

Post by Choumiko »

I'm trying to create a gui that looks and behaves similar to the vanilla logistics request gui:
  • Clicking a button with an item selects that button without opening the selection window
  • Clicking the same button again opens the selection window
For that to work i have to set LuaGuiElement.locked = true for buttons that have an item set and are not the currently selected button.
When clicking on a button that is not the selected one, i unlock it and assign a different style and the previous selected button gets locked again and gets a new style assigned.

Expected behavior: After assigning a style to a locked button it is displayed correctly

Actual behavior: They seem to get stuck in displaying the clicked_graphical_set of the previous style

To reproduce:
Install the attached mod, start a new save, click the buttons from left to right. The first row of buttons gets un/locked as described above,
the second row is unlocked all the time and behave like expected (except that the item selection window shows up every time)

Clicking each of the top row buttons one leads to:
Screenshot from 2019-05-08 00-21-32.png
Screenshot from 2019-05-08 00-21-32.png (12.56 KiB) Viewed 1861 times

Then clicking the first 3 again:
Screenshot from 2019-05-08 00-22-27.png
Screenshot from 2019-05-08 00-22-27.png (15.96 KiB) Viewed 1861 times
I can work around it by destroying and creating the button(s) again after each click that changes the style, but that seems unnecessary.


factorio.current.log
Attachments
TestModGui_3.0.1.zip
(2 KiB) Downloaded 60 times

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

Re: [0.17.37]choose-elem-button: wierd interaction with locked button and updating style

Post by Rseding91 »

I'm not understanding what's broken and what isn't here. Setting locked=true on a choose-elem-button should disable all interaction with that button since the player can't do anything anymore

The whole "clicked" state in buttons really was never meant to exist for mods and doesn't work when mods do things to the buttons in that state.

Can you please explain in less words what is happening and what you expect to happen?
If you want to get ahold of me I'm almost always on Discord.

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

Re: [0.17.37]choose-elem-button: wierd interaction with locked button and updating style

Post by Rseding91 »

Ok, after talking about this more with Bilka I now understand what's happening. This is a fundimental problem with the entire LuaGuiElement style system that I don't currently have a good solution for.

The problem is: setting element.style doesn't *actually* change the element style. All it does is set the parent on the style. The way styles work in the widget system is: when the GUI goes to read a given style property it goes to the immediate style on the widget and checks if it has that property defined. If not, it goes to the parent style and repeats until it finds a defined value.

In your example the default style for the button has the clicked style defined and so when you do element.style = ... you just change the parent and the style value on the widget still has the original clicked style defined so it never "walks up the parent".

This isn't specific to buttons - everything that has sub-styles has this issue. Example: viewtopic.php?f=7&t=71391
If you want to get ahold of me I'm almost always on Discord.

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

Re: [Rseding91] [0.17.37]choose-elem-button: wierd interaction with locked button and updating style

Post by Rseding91 »

Actually, another correction: I still don't know what you're actually trying to report.

What series of actions are you performing and what outcomes do you expect?

When I click on the buttons they change colors but I have no idea what you think they're supposed to be doing.
If you want to get ahold of me I'm almost always on Discord.

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

Re: [Rseding91] [0.17.37]choose-elem-button: wierd interaction with locked button and updating style

Post by Rseding91 »

Possibly what you might be misunderstanding is how parent styles work?

The base button style defines the clicked/hovered graphical sets so if you don't *remove* those from the base button style or explicitly define new ones every one of your buttons will have that graphical set when clicked/hovered.
If you want to get ahold of me I'm almost always on Discord.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [Rseding91] [0.17.37]choose-elem-button: wierd interaction with locked button and updating style

Post by Choumiko »

Rseding91 wrote:
Fri May 31, 2019 2:37 am
What series of actions are you performing and what outcomes do you expect?
Maybe this gif helps:
strange.gif
strange.gif (162.84 KiB) Viewed 1775 times

Basically every sequence of clicks you do in the first row should result in the same visible result as when you repeat the sequence in the second row.

The only difference between the 2 rows of buttons (and the handling code):
Unexpected behavior buttons are choose-elem-buttons, they all start with .locked set. The clicked button gets unlocked, all other buttons get locked.

So since setting the same styles to 2 different button types results in a different look that seems to be an issue/bug ?

Vanilla probably does it differently, but that's what i'm trying to achieve:
vanilla.gif
vanilla.gif (95.55 KiB) Viewed 1775 times
Rseding91 wrote:
Thu May 30, 2019 11:21 pm
This isn't specific to buttons - everything that has sub-styles has this issue. Example: viewtopic.php?f=7&t=71391
Link doesn't work for me
Attachments
TestModGui_3.0.2.zip
(1.56 KiB) Downloaded 55 times

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [0.17.37]choose-elem-button: wierd interaction with locked button and updating style

Post by Choumiko »

Rseding91 wrote:
Thu May 30, 2019 10:29 pm
Setting locked=true on a choose-elem-button should disable all interaction with that button since the player can't do anything anymore
They still raise on_gui_click, which is good, please don't change that :)
The whole "clicked" state in buttons really was never meant to exist for mods and doesn't work when mods do things to the buttons in that state.
That might be what lead me to post this report, from my original post: "They seem to get stuck in displaying the clicked_graphical_set of the previous style"
I have a workaround that isn't too ugly, so feel free to move this to not a bug/minor issues.

Btw, thanks for taking the time trying to figure out what i wanted to report.

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

Re: [Rseding91] [0.17.37]choose-elem-button: wierd interaction with locked button and updating style

Post by Rseding91 »

Ok, I think it's now fixed forthe next version of 0.17. I say think because I really don't understand what the "correct" behavior should be for these buttons in the different states. Every time I think I understand some strange new behavior shows up.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Resolved Problems and Bugs”