Miroir du dépôt skinsdb.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.5KB

  1. local S = minetest.get_translator("skinsdb")
  2. function skins.get_formspec_context(player)
  3. if player then
  4. local playername = player:get_player_name()
  5. skins.ui_context[playername] = skins.ui_context[playername] or {}
  6. return skins.ui_context[playername]
  7. else
  8. return {}
  9. end
  10. end
  11. -- Show skin info
  12. function skins.get_skin_info_formspec(skin)
  13. local texture = skin:get_texture()
  14. local m_name = skin:get_meta_string("name")
  15. local m_author = skin:get_meta_string("author")
  16. local m_license = skin:get_meta_string("license")
  17. local m_format = skin:get_meta("format")
  18. -- overview page
  19. local raw_size = m_format == "1.8" and "2,2" or "2,1"
  20. local formspec = "image[0.8,.6;1,2;"..minetest.formspec_escape(skin:get_preview()).."]"
  21. if texture then
  22. formspec = formspec.."label[6,.5;"..S("Raw texture")..":]"
  23. .."image[6,1;"..raw_size..";"..texture.."]"
  24. end
  25. if m_name ~= "" then
  26. formspec = formspec.."label[2,.5;"..S("Name")..": "..minetest.formspec_escape(m_name).."]"
  27. end
  28. if m_author ~= "" then
  29. formspec = formspec.."label[2,1;"..S("Author")..": "..minetest.formspec_escape(m_author).."]"
  30. end
  31. if m_license ~= "" then
  32. formspec = formspec.."label[2,1.5;"..S("License")..": "..minetest.formspec_escape(m_license).."]"
  33. end
  34. return formspec
  35. end
  36. function skins.get_skin_selection_formspec(player, context, y_delta)
  37. context.skins_list = skins.get_skinlist_for_player(player:get_player_name())
  38. context.total_pages = 1
  39. for i, skin in ipairs(context.skins_list ) do
  40. local page = math.floor((i-1) / 16)+1
  41. skin:set_meta("inv_page", page)
  42. skin:set_meta("inv_page_index", (i-1)%16+1)
  43. context.total_pages = page
  44. end
  45. context.skins_page = context.skins_page or skins.get_player_skin(player):get_meta("inv_page") or 1
  46. context.dropdown_values = nil
  47. local page = context.skins_page
  48. local formspec = ""
  49. for i = (page-1)*16+1, page*16 do
  50. local skin = context.skins_list[i]
  51. if not skin then
  52. break
  53. end
  54. local index_p = skin:get_meta("inv_page_index")
  55. local x = (index_p-1) % 8
  56. local y
  57. if index_p > 8 then
  58. y = y_delta + 1.9
  59. else
  60. y = y_delta
  61. end
  62. formspec = formspec.."image_button["..x..","..y..";1,2;"..
  63. minetest.formspec_escape(skin:get_preview())..";skins_set$"..i..";]"..
  64. "tooltip[skins_set$"..i..";"..minetest.formspec_escape(skin:get_meta_string("name")).."]"
  65. end
  66. if context.total_pages > 1 then
  67. local page_prev = page - 1
  68. local page_next = page + 1
  69. if page_prev < 1 then
  70. page_prev = context.total_pages
  71. end
  72. if page_next > context.total_pages then
  73. page_next = 1
  74. end
  75. local page_list = ""
  76. context.dropdown_values = {}
  77. for pg=1, context.total_pages do
  78. local pagename = S("Page").." "..pg.."/"..context.total_pages
  79. context.dropdown_values[pagename] = pg
  80. if pg > 1 then page_list = page_list.."," end
  81. page_list = page_list..pagename
  82. end
  83. formspec = formspec
  84. .."button[0,"..(y_delta+4.0)..";1,.5;skins_page$"..page_prev..";<<]"
  85. .."dropdown[0.9,"..(y_delta+3.88)..";6.5,.5;skins_selpg;"..page_list..";"..page.."]"
  86. .."button[7,"..(y_delta+4.0)..";1,.5;skins_page$"..page_next..";>>]"
  87. end
  88. return formspec
  89. end
  90. function skins.on_skin_selection_receive_fields(player, context, fields)
  91. for field, _ in pairs(fields) do
  92. local current = string.split(field, "$", 2)
  93. if current[1] == "skins_set" then
  94. skins.set_player_skin(player, context.skins_list[tonumber(current[2])])
  95. return 'set'
  96. elseif current[1] == "skins_page" then
  97. context.skins_page = tonumber(current[2])
  98. return 'page'
  99. end
  100. end
  101. if fields.skins_selpg then
  102. context.skins_page = tonumber(context.dropdown_values[fields.skins_selpg])
  103. return 'page'
  104. end
  105. end