init.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. local current_mod_name = minetest.get_current_modname()
  2. local current_mod_path = minetest.get_modpath(current_mod_name)
  3. local lanapixel_path = current_mod_path .. "/fonts/LanaPixel.ttf"
  4. local monogram_path = current_mod_path .. "/fonts/Monogram.ttf"
  5. minetest.register_on_player_receive_fields(function(player, formname, fields)
  6. if formname ~= "pixel_fonts" then return end
  7. local player_name = player:get_player_name()
  8. local settings = minetest.settings
  9. if fields.install then
  10. settings:set("font_path", lanapixel_path)
  11. settings:set("font_size", 22)
  12. settings:set("mono_font_path", monogram_path)
  13. settings:set("chat_font_size", 32)
  14. elseif fields.uninstall then
  15. settings:remove "font_path"
  16. settings:remove "font_size"
  17. settings:remove "mono_font_path"
  18. settings:remove "chat_font_size"
  19. end
  20. settings:write()
  21. minetest.chat_send_player(
  22. player_name,
  23. "Please exit the game and disable this mod.\n"
  24. .. "Exiting is necessary for the fonts to be fully applied,\n"
  25. .. "and there's no need to keep the mod enabled."
  26. )
  27. minetest.close_formspec(player_name, "pixel_fonts")
  28. end)
  29. local function open_font_formspec(player_name)
  30. local formspec = [[
  31. size[4,3]
  32. button[0.5,0.5;3,1;install;Install fonts]
  33. button[0.5,1.5;3,1;uninstall;Uninstall fonts]
  34. ]]
  35. minetest.show_formspec(player_name, "pixel_fonts", formspec)
  36. end
  37. minetest.register_on_joinplayer(
  38. function(player) open_font_formspec(player:get_player_name()) end
  39. )