2
0

init.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. --Minetest
  2. --Copyright (C) 2014 sapier
  3. --
  4. --This program is free software; you can redistribute it and/or modify
  5. --it under the terms of the GNU Lesser General Public License as published by
  6. --the Free Software Foundation; either version 2.1 of the License, or
  7. --(at your option) any later version.
  8. --
  9. --This program is distributed in the hope that it will be useful,
  10. --but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. --MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. --GNU Lesser General Public License for more details.
  13. --
  14. --You should have received a copy of the GNU Lesser General Public License along
  15. --with this program; if not, write to the Free Software Foundation, Inc.,
  16. --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. mt_color_grey = "#AAAAAA"
  18. mt_color_blue = "#6389FF"
  19. mt_color_lightblue = "#99CCFF"
  20. mt_color_green = "#72FF63"
  21. mt_color_dark_green = "#25C191"
  22. mt_color_orange = "#FF8800"
  23. local menupath = core.get_mainmenu_path()
  24. local basepath = core.get_builtin_path()
  25. defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
  26. DIR_DELIM .. "pack" .. DIR_DELIM
  27. dofile(basepath .. "common" .. DIR_DELIM .. "filterlist.lua")
  28. dofile(basepath .. "fstk" .. DIR_DELIM .. "buttonbar.lua")
  29. dofile(basepath .. "fstk" .. DIR_DELIM .. "dialog.lua")
  30. dofile(basepath .. "fstk" .. DIR_DELIM .. "tabview.lua")
  31. dofile(basepath .. "fstk" .. DIR_DELIM .. "ui.lua")
  32. dofile(menupath .. DIR_DELIM .. "async_event.lua")
  33. dofile(menupath .. DIR_DELIM .. "common.lua")
  34. dofile(menupath .. DIR_DELIM .. "pkgmgr.lua")
  35. dofile(menupath .. DIR_DELIM .. "serverlistmgr.lua")
  36. dofile(menupath .. DIR_DELIM .. "game_theme.lua")
  37. dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
  38. dofile(menupath .. DIR_DELIM .. "dlg_settings_advanced.lua")
  39. dofile(menupath .. DIR_DELIM .. "dlg_contentstore.lua")
  40. dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
  41. dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua")
  42. dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
  43. dofile(menupath .. DIR_DELIM .. "dlg_register.lua")
  44. dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
  45. local tabs = {}
  46. tabs.settings = dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
  47. tabs.content = dofile(menupath .. DIR_DELIM .. "tab_content.lua")
  48. tabs.about = dofile(menupath .. DIR_DELIM .. "tab_about.lua")
  49. tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua")
  50. tabs.play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
  51. --------------------------------------------------------------------------------
  52. local function main_event_handler(tabview, event)
  53. if event == "MenuQuit" then
  54. core.close()
  55. end
  56. return true
  57. end
  58. --------------------------------------------------------------------------------
  59. local function init_globals()
  60. -- Init gamedata
  61. gamedata.worldindex = 0
  62. menudata.worldlist = filterlist.create(
  63. core.get_worlds,
  64. compare_worlds,
  65. -- Unique id comparison function
  66. function(element, uid)
  67. return element.name == uid
  68. end,
  69. -- Filter function
  70. function(element, gameid)
  71. return element.gameid == gameid
  72. end
  73. )
  74. menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
  75. menudata.worldlist:set_sortmode("alphabetic")
  76. if not core.settings:get("menu_last_game") then
  77. local default_game = core.settings:get("default_game") or "minetest"
  78. core.settings:set("menu_last_game", default_game)
  79. end
  80. mm_game_theme.init()
  81. -- Create main tabview
  82. local tv_main = tabview_create("maintab", {x = 12, y = 5.4}, {x = 0, y = 0})
  83. tv_main:set_autosave_tab(true)
  84. tv_main:add(tabs.local_game)
  85. tv_main:add(tabs.play_online)
  86. tv_main:add(tabs.content)
  87. tv_main:add(tabs.settings)
  88. tv_main:add(tabs.about)
  89. tv_main:set_global_event_handler(main_event_handler)
  90. tv_main:set_fixed_size(false)
  91. local last_tab = core.settings:get("maintab_LAST")
  92. if last_tab and tv_main.current_tab ~= last_tab then
  93. tv_main:set_tab(last_tab)
  94. end
  95. -- In case the folder of the last selected game has been deleted,
  96. -- display "Minetest" as a header
  97. if tv_main.current_tab == "local" then
  98. local game = pkgmgr.find_by_gameid(core.settings:get("menu_last_game"))
  99. if game == nil then
  100. mm_game_theme.reset()
  101. end
  102. end
  103. ui.set_default("maintab")
  104. tv_main:show()
  105. ui.update()
  106. end
  107. init_globals()