init.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 = "#0000DD"
  19. mt_color_green = "#00DD00"
  20. mt_color_dark_green = "#003300"
  21. --for all other colors ask sfan5 to complete his work!
  22. local menupath = core.get_mainmenu_path()
  23. local basepath = core.get_builtin_path()
  24. defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
  25. DIR_DELIM .. "pack" .. DIR_DELIM
  26. dofile(basepath .. DIR_DELIM .. "common" .. DIR_DELIM .. "async_event.lua")
  27. dofile(basepath .. DIR_DELIM .. "common" .. DIR_DELIM .. "filterlist.lua")
  28. dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "buttonbar.lua")
  29. dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "dialog.lua")
  30. dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "tabview.lua")
  31. dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "ui.lua")
  32. dofile(menupath .. DIR_DELIM .. "common.lua")
  33. dofile(menupath .. DIR_DELIM .. "gamemgr.lua")
  34. dofile(menupath .. DIR_DELIM .. "modmgr.lua")
  35. dofile(menupath .. DIR_DELIM .. "store.lua")
  36. dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
  37. dofile(menupath .. DIR_DELIM .. "tab_credits.lua")
  38. dofile(menupath .. DIR_DELIM .. "tab_mods.lua")
  39. dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
  40. if PLATFORM ~= "Android" then
  41. dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
  42. dofile(menupath .. DIR_DELIM .. "dlg_delete_mod.lua")
  43. dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
  44. dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
  45. dofile(menupath .. DIR_DELIM .. "tab_multiplayer.lua")
  46. dofile(menupath .. DIR_DELIM .. "tab_server.lua")
  47. dofile(menupath .. DIR_DELIM .. "tab_singleplayer.lua")
  48. dofile(menupath .. DIR_DELIM .. "tab_texturepacks.lua")
  49. dofile(menupath .. DIR_DELIM .. "textures.lua")
  50. else
  51. dofile(menupath .. DIR_DELIM .. "tab_simple_main.lua")
  52. end
  53. --------------------------------------------------------------------------------
  54. local function main_event_handler(tabview, event)
  55. if event == "MenuQuit" then
  56. core.close()
  57. end
  58. return true
  59. end
  60. --------------------------------------------------------------------------------
  61. local function init_globals()
  62. -- Init gamedata
  63. gamedata.worldindex = 0
  64. if PLATFORM ~= "Android" then
  65. menudata.worldlist = filterlist.create(
  66. core.get_worlds,
  67. compare_worlds,
  68. -- Unique id comparison function
  69. function(element, uid)
  70. return element.name == uid
  71. end,
  72. -- Filter function
  73. function(element, gameid)
  74. return element.gameid == gameid
  75. end
  76. )
  77. menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
  78. menudata.worldlist:set_sortmode("alphabetic")
  79. if not core.setting_get("menu_last_game") then
  80. local default_game = core.setting_get("default_game") or "minetest"
  81. core.setting_set("menu_last_game", default_game )
  82. end
  83. mm_texture.init()
  84. else
  85. local world_list = core.get_worlds()
  86. local found_singleplayerworld = false
  87. for i,world in pairs(world_list) do
  88. if world.name == "singleplayerworld" then
  89. found_singleplayerworld = true
  90. gamedata.worldindex = i
  91. break
  92. end
  93. end
  94. if not found_singleplayerworld then
  95. core.create_world("singleplayerworld", 1)
  96. local world_list = core.get_worlds()
  97. for i,world in pairs(world_list) do
  98. if world.name == "singleplayerworld" then
  99. gamedata.worldindex = i
  100. break
  101. end
  102. end
  103. end
  104. end
  105. -- Create main tabview
  106. local tv_main = tabview_create("maintab",{x=12,y=5.2},{x=0,y=0})
  107. if PLATFORM ~= "Android" then
  108. tv_main:set_autosave_tab(true)
  109. end
  110. if PLATFORM ~= "Android" then
  111. tv_main:add(tab_singleplayer)
  112. tv_main:add(tab_multiplayer)
  113. tv_main:add(tab_server)
  114. else
  115. tv_main:add(tab_simple_main)
  116. end
  117. tv_main:add(tab_settings)
  118. if PLATFORM ~= "Android" then
  119. tv_main:add(tab_texturepacks)
  120. end
  121. tv_main:add(tab_mods)
  122. tv_main:add(tab_credits)
  123. tv_main:set_global_event_handler(main_event_handler)
  124. tv_main:set_fixed_size(false)
  125. if not (PLATFORM == "Android") then
  126. tv_main:set_tab(core.setting_get("maintab_LAST"))
  127. end
  128. ui.set_default("maintab")
  129. tv_main:show()
  130. -- Create modstore ui
  131. if PLATFORM == "Android" then
  132. modstore.init({x=12, y=6}, 3, 2)
  133. else
  134. modstore.init({x=12, y=8}, 4, 3)
  135. end
  136. ui.update()
  137. core.sound_play("main_menu", true)
  138. end
  139. init_globals()