init.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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_green = "#72FF63"
  20. mt_color_dark_green = "#25C191"
  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 .. "common" .. DIR_DELIM .. "async_event.lua")
  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 .. "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 .. "textures.lua")
  37. dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
  38. dofile(menupath .. DIR_DELIM .. "dlg_settings_advanced.lua")
  39. if PLATFORM ~= "Android" then
  40. dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
  41. dofile(menupath .. DIR_DELIM .. "dlg_delete_mod.lua")
  42. dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
  43. dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
  44. end
  45. local tabs = {}
  46. tabs.settings = dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
  47. tabs.mods = dofile(menupath .. DIR_DELIM .. "tab_mods.lua")
  48. tabs.credits = dofile(menupath .. DIR_DELIM .. "tab_credits.lua")
  49. if PLATFORM == "Android" then
  50. tabs.simple_main = dofile(menupath .. DIR_DELIM .. "tab_simple_main.lua")
  51. else
  52. tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua")
  53. tabs.play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
  54. tabs.texturepacks = dofile(menupath .. DIR_DELIM .. "tab_texturepacks.lua")
  55. end
  56. --------------------------------------------------------------------------------
  57. local function main_event_handler(tabview, event)
  58. if event == "MenuQuit" then
  59. core.close()
  60. end
  61. return true
  62. end
  63. --------------------------------------------------------------------------------
  64. local function init_globals()
  65. -- Init gamedata
  66. gamedata.worldindex = 0
  67. if PLATFORM == "Android" then
  68. local world_list = core.get_worlds()
  69. local world_index
  70. local found_singleplayerworld = false
  71. for i, world in ipairs(world_list) do
  72. if world.name == "singleplayerworld" then
  73. found_singleplayerworld = true
  74. world_index = i
  75. break
  76. end
  77. end
  78. if not found_singleplayerworld then
  79. core.create_world("singleplayerworld", 1)
  80. world_list = core.get_worlds()
  81. for i, world in ipairs(world_list) do
  82. if world.name == "singleplayerworld" then
  83. world_index = i
  84. break
  85. end
  86. end
  87. end
  88. gamedata.worldindex = world_index
  89. else
  90. menudata.worldlist = filterlist.create(
  91. core.get_worlds,
  92. compare_worlds,
  93. -- Unique id comparison function
  94. function(element, uid)
  95. return element.name == uid
  96. end,
  97. -- Filter function
  98. function(element, gameid)
  99. return element.gameid == gameid
  100. end
  101. )
  102. menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
  103. menudata.worldlist:set_sortmode("alphabetic")
  104. if not core.settings:get("menu_last_game") then
  105. local default_game = core.settings:get("default_game") or "minetest"
  106. core.settings:set("menu_last_game", default_game)
  107. end
  108. mm_texture.init()
  109. end
  110. -- Create main tabview
  111. local tv_main = tabview_create("maintab", {x = 12, y = 5.4}, {x = 0, y = 0})
  112. if PLATFORM == "Android" then
  113. tv_main:add(tabs.simple_main)
  114. tv_main:add(tabs.settings)
  115. else
  116. tv_main:set_autosave_tab(true)
  117. tv_main:add(tabs.local_game)
  118. tv_main:add(tabs.play_online)
  119. tv_main:add(tabs.settings)
  120. tv_main:add(tabs.texturepacks)
  121. end
  122. tv_main:add(tabs.mods)
  123. tv_main:add(tabs.credits)
  124. tv_main:set_global_event_handler(main_event_handler)
  125. tv_main:set_fixed_size(false)
  126. if PLATFORM ~= "Android" then
  127. tv_main:set_tab(core.settings:get("maintab_LAST"))
  128. end
  129. ui.set_default("maintab")
  130. tv_main:show()
  131. -- Create modstore ui
  132. if PLATFORM == "Android" then
  133. modstore.init({x = 12, y = 6}, 3, 2)
  134. else
  135. modstore.init({x = 12, y = 8}, 4, 3)
  136. end
  137. ui.update()
  138. core.sound_play("main_menu", true)
  139. end
  140. init_globals()