[0.17.79] LuaGuiElement switch created in on_player_created broken

Post your bugs and problems so we can fix them.
Post Reply
jan1i3
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sun Dec 09, 2018 1:36 pm
Contact:

[0.17.79] LuaGuiElement switch created in on_player_created broken

Post by jan1i3 » Sat Nov 23, 2019 1:39 pm

* 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 104 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 104 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)
Attachments
SimpleTest_0.0.1.zip
(794 Bytes) Downloaded 2 times
factorio-current.log
(8.81 KiB) Downloaded 4 times

Post Reply

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users