Page 1 of 1

[kovarex] [0.17.79] LuaGuiElement switch created in on_player_created broken

Posted: Sat Nov 23, 2019 1:39 pm
by jan1i3
* The hitbox of a switch - the area where you click it to change the state - seems to not consider the left_label_caption
* The right_label_tooltip seems to be offset somehow so that it simply doesn't appear ever.
* The entire width is determined incorrectly, as you can see here
WidthWrong.png
WidthWrong.png (26.44 KiB) Viewed 2055 times
* The switch does not fire any events (tested on_gui_click and on_gui_switch_state_changed)

expected behavior: well,
the hitbox should be where the switch visually is at
the right_label_tooltip should pop up when hovering the right label
the width should consider both labels and the switch itself
the switch should fire events when clicked and state changed


as a comparison, a switch created using commands afterwards works as expected (see expected behavior)

Code: Select all

/c game.player.gui.screen.frame1.add{
  type = "switch",
  name = "sw3",
  left_label_caption = "left",
  left_label_tooltip = "left tooltip",
  right_label_caption = "right, also with more text",
  right_label_tooltip = "right tooltip",
}
ThirdSwitch.png
ThirdSwitch.png (56.94 KiB) Viewed 2055 times

reproduce:
load the example mod
create a new world
try pressing the switches
try pressing the button (which does trigger events -> game.print gets run)
try hovering the 2nd switch's lables
add the new switch with the command (see above)
try that switch (also tirggers events)


here is the code for the mod, to make it easier to see what it does:

Code: Select all

script.on_event(defines.events.on_player_created, function(event)
  local player = game.get_player(event.player_index)
  local frame = player.gui.screen.add{
    type = "frame",
    direction = "vertical",
    caption = "test",
    name = "frame1",
  }
  frame.force_auto_center()
  frame.add{
    type = "switch",
    name = "sw_1",
  }
  frame.add{
    type = "switch",
    name = "sw_2",
    switch_state = "left",
    allow_none_state = false,
    left_label_caption = "left",
    right_label_caption = "right with more text",
    left_label_tooltip = "left tooltip",
    right_label_tooltip = "right tooltip",
  }
  frame.add{
    type = "button",
    name = "btn_1",
  }
end)

script.on_event(defines.events.on_gui_click, function(event)
  game.print("clicked " .. event.element.type .. " " .. tostring(event.element.caption or event.element.name))
end)
script.on_event(defines.events.on_gui_switch_state_changed, function(event)
  game.print("switched " .. event.element.type .. " " .. tostring(event.element.caption or event.element.name))
end)

Re: [0.17.79] LuaGuiElement switch created in on_player_created broken

Posted: Sat Dec 28, 2019 11:51 pm
by jan1i3
Switches loaded from a save have the exact same issues.

reproduce:
load the example mod
create a new world
add the new switch with the command (see above)
try that switch (tirggers events)
save the game
load that game
try that switch again (does not tirgger events)

Re: [kovarex] [0.17.79] LuaGuiElement switch created in on_player_created broken

Posted: Fri Jun 26, 2020 9:33 pm
by kovarex
Hello, thanks for the report, it is fixed for the next release.

Re: [kovarex] [0.17.79] LuaGuiElement switch created in on_player_created broken

Posted: Sun Jul 26, 2020 1:39 pm
by jan1i3
Thanks :D