[Rseding91] [0.17.37]choose-elem-button: wierd interaction with locked button and updating style
Posted: Tue May 07, 2019 10:30 pm
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 (12.56 KiB) Viewed 3190 times
Then clicking the first 3 again:
Screenshot from 2019-05-08 00-22-27.png (15.96 KiB) Viewed 3190 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.
0.000 2019-05-08 00:30:16; Factorio 0.17.37 (build 44853, linux64, alpha)
0.027 Operating system: Linux (Ubuntu 18.04)
0.027 Program arguments: "./factorio"
0.027 Read data path: /home/choumiko/factorio/data
0.027 Write data path: /home/choumiko/factorio [25528/195884MB]
0.027 Binaries path: /home/choumiko/factorio/bin
0.032 System info: [CPU: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz, 8 cores, RAM: 15990 MB]
0.032 Environment: DISPLAY=:1 WAYLAND_DISPLAY=<unset> DESKTOP_SESSION=ubuntu XDG_SESSION_DESKTOP=ubuntu XDG_CURRENT_DESKTOP=ubuntu:GNOME
0.032 Display options: [FullScreen: 0] [VSync: 0] [UIScale: custom (100.0%)] [Native DPI: 1] [Screen: 0] [Special: 00] [Lang: en]
0.148 Available displays: 2
0.148 [0]: PLX2783H 27" - {[1920,0], 1920x1080, SDL_PIXELFORMAT_RGB888, 60Hz}
0.148 [1]: SMBX2450 24" - {[0,0], 1920x1080, SDL_PIXELFORMAT_RGB888, 60Hz}
0.175 Initialised OpenGL:[0] GeForce GTX 1070/PCIe/SSE2; driver: 3.3.0 NVIDIA 390.116
0.175 [Extensions] s3tc:yes; KHR_debug:yes; ARB_clear_texture:yes, ARB_copy_image:yes
0.175 [Version] 3.3
0.194 Graphics settings preset: very-high
0.194 Dedicated video memory size 8192 MB
0.194 Graphics options: [Graphics quality: high] [Video memory usage: all] [Light scale: 100%] [DXT: high-quality]
0.194 [Max load threads: 32] [Max texture size: 0] [Tex.Stream.: 0] [Rotation quality: normal] [Color: 32bit]
0.296 Info ModManager.cpp:240: Found duplicate mod AutoTrash, using higher version (4.0.6 > 4.0.5).
0.329 Loading mod core 0.0.0 (data.lua)
0.374 Loading mod base 0.17.37 (data.lua)
0.497 Loading mod TestModGui 3.0.1 (data.lua)
0.550 Loading mod base 0.17.37 (data-updates.lua)
0.609 Checksum for core: 1237570159
0.609 Checksum of base: 3494064191
0.609 Checksum of TestModGui: 1108552575
0.957 Loading sounds...
0.969 Info PlayerData.cpp:67: Local player-data.json available, timestamp 1557268215
0.969 Info PlayerData.cpp:74: Cloud player-data.json unavailable
1.049 Initial atlas bitmap size is 16384
1.069 Created atlas bitmap 16384x16376 [none]
1.072 Created atlas bitmap 16384x11468 [none]
1.072 Created atlas bitmap 8192x3884 [decal]
1.072 Created atlas bitmap 16384x4288 [low-object]
1.072 Created atlas bitmap 2048x192 [icon-background, not-compressed, linear-minification, linear-magnification, linear-mip-level, , no-crop, no-scale]
1.073 Created atlas bitmap 8192x3552 [mipmap, linear-minification, linear-magnification, linear-mip-level]
1.073 Created atlas bitmap 16384x6880 [terrain, mipmap, linear-minification, linear-mip-level, no-crop]
1.073 Created atlas bitmap 4096x1600 [smoke, mipmap, linear-minification, linear-magnification]
1.074 Created atlas bitmap 4096x1408 [not-compressed, mipmap, linear-minification, linear-magnification, linear-mip-level, no-crop, no-scale]
1.074 Created atlas bitmap 8192x1496 [alpha-mask]
1.076 Created atlas bitmap 16384x12644 [shadow, linear-magnification, alpha-mask]
1.076 Created atlas bitmap 8192x2352 [shadow, mipmap, linear-magnification, alpha-mask]
1.692 Atlases loaded from disk cache.
1.699 Texture processor created (2048). GPU accelerated compression Supported: yes, Enabled: yes/yes. Test passed. YCoCgDXT PSNR: 35.83, BC3 PSNR: 33.82
1.700 Parallel Sprite Loader initialized (threads: 0)
1.727 Sprites loaded
1.752 Generated mipmaps (4) for atlas [3] of size 16384x4288
1.759 Generated mipmaps (3) for atlas [5] of size 8192x3552
1.780 Generated mipmaps (3) for atlas [6] of size 16384x6880
1.782 Generated mipmaps (3) for atlas [7] of size 4096x1600
1.788 Generated mipmaps (3) for atlas [8] of size 4096x1408
1.790 Generated mipmaps (3) for atlas [11] of size 8192x2352
1.793 Custom inputs active: 6
1.837 Factorio initialised
1.837 Info HttpSharedState.cpp:54: Downloading https://updater.factorio.com/updater/get-available-versions?username=Choumiko&token=<private>&apiVersion=2
2.817 0 packages available to download (experimental updates enabled).
Re: [0.17.37]choose-elem-button: wierd interaction with locked button and updating style
Posted: Thu May 30, 2019 10:29 pm
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?
Re: [0.17.37]choose-elem-button: wierd interaction with locked button and updating style
Posted: Thu May 30, 2019 11:21 pm
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
Re: [Rseding91] [0.17.37]choose-elem-button: wierd interaction with locked button and updating style
Posted: Fri May 31, 2019 2:37 am
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.
Re: [Rseding91] [0.17.37]choose-elem-button: wierd interaction with locked button and updating style
Posted: Fri May 31, 2019 2:39 am
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.
Re: [Rseding91] [0.17.37]choose-elem-button: wierd interaction with locked button and updating style
What series of actions are you performing and what outcomes do you expect?
Maybe this gif helps:
strange.gif (162.84 KiB) Viewed 3104 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:
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.
Re: [Rseding91] [0.17.37]choose-elem-button: wierd interaction with locked button and updating style
Posted: Wed Jun 05, 2019 10:07 pm
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.