dlg_clients_list.lua 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. -- Luanti
  2. -- Copyright (C) 2024 siliconsniffer
  3. -- SPDX-License-Identifier: LGPL-2.1-or-later
  4. local function clients_list_formspec(dialogdata)
  5. local TOUCH_GUI = core.settings:get_bool("touch_gui")
  6. local clients_list = dialogdata.server.clients_list
  7. local servername = dialogdata.server.name
  8. local function fmt_formspec_list(clients_list)
  9. local escaped = {}
  10. for i, str in ipairs(clients_list) do
  11. escaped[i] = core.formspec_escape(str)
  12. end
  13. return table.concat(escaped, ",")
  14. end
  15. local formspec = {
  16. "formspec_version[8]",
  17. "size[6,9.5]",
  18. TOUCH_GUI and "padding[0.01,0.01]" or "",
  19. "hypertext[0,0;6,1.5;;<global margin=5 halign=center valign=middle>",
  20. fgettext("This is the list of clients connected to\n$1",
  21. "<b>" .. core.hypertext_escape(servername) .. "</b>") .. "]",
  22. "textlist[0.5,1.5;5,6.8;;" .. fmt_formspec_list(clients_list) .. "]",
  23. "button[1.5,8.5;3,0.8;quit;OK]"
  24. }
  25. return table.concat(formspec, "")
  26. end
  27. local function clients_list_buttonhandler(this, fields)
  28. if fields.quit then
  29. this:delete()
  30. return true
  31. end
  32. return false
  33. end
  34. function create_clientslist_dialog(server)
  35. local retval = dialog_create("dlg_clients_list",
  36. clients_list_formspec,
  37. clients_list_buttonhandler,
  38. nil)
  39. retval.data.server = server
  40. return retval
  41. end