1
0

init.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. local function window_info_equal(a, b)
  2. return
  3. -- size
  4. a.size.x == b.size.x and a.size.y == b.size.y and
  5. -- real_gui_scaling, real_hud_scaling
  6. a.real_gui_scaling == b.real_gui_scaling and
  7. a.real_hud_scaling == b.real_hud_scaling and
  8. -- max_formspec_size
  9. a.max_formspec_size.x == b.max_formspec_size.x and
  10. a.max_formspec_size.y == b.max_formspec_size.y and
  11. -- touch_controls
  12. a.touch_controls == b.touch_controls
  13. end
  14. local last_window_info = {}
  15. local function show_fullscreen_fs(name, window)
  16. print(dump(window))
  17. local size = window.max_formspec_size
  18. local touch_text = window.touch_controls and "Touch controls enabled" or
  19. "Touch controls disabled"
  20. local fs = {
  21. "formspec_version[4]",
  22. ("size[%f,%f]"):format(size.x, size.y),
  23. "padding[0,0]",
  24. "bgcolor[;true]",
  25. ("button[%f,%f;1,1;%s;%s]"):format(0, 0, "tl", "TL"),
  26. ("button[%f,%f;1,1;%s;%s]"):format(size.x - 1, 0, "tr", "TR"),
  27. ("button[%f,%f;1,1;%s;%s]"):format(size.x - 1, size.y - 1, "br", "BR"),
  28. ("button[%f,%f;1,1;%s;%s]"):format(0, size.y - 1, "bl", "BL"),
  29. ("label[%f,%f;%s]"):format(size.x / 2, size.y / 2, "Fullscreen"),
  30. ("label[%f,%f;%s]"):format(size.x / 2, size.y / 2 + 1, touch_text),
  31. }
  32. core.show_formspec(name, "testfullscreenfs:fs", table.concat(fs))
  33. core.chat_send_player(name, ("Calculated size of %f, %f"):format(size.x, size.y))
  34. last_window_info[name] = window
  35. end
  36. core.register_chatcommand("testfullscreenfs", {
  37. func = function(name)
  38. local window = core.get_player_window_information(name)
  39. if not window then
  40. return false, "Unable to get window info"
  41. end
  42. show_fullscreen_fs(name, window)
  43. return true
  44. end,
  45. })
  46. core.register_globalstep(function()
  47. for name, last_window in pairs(last_window_info) do
  48. local window = core.get_player_window_information(name)
  49. if window and not window_info_equal(last_window, window) then
  50. show_fullscreen_fs(name, window)
  51. end
  52. end
  53. end)
  54. core.register_on_player_receive_fields(function(player, formname, fields)
  55. if formname == "testfullscreenfs:fs" and fields.quit then
  56. last_window_info[player:get_player_name()] = nil
  57. end
  58. end)
  59. core.register_on_leaveplayer(function(player)
  60. last_window_info[player:get_player_name()] = nil
  61. end)