init.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. --Luanti
  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. mt_color_red = "#FF3300"
  24. MAIN_TAB_W = 15.5
  25. MAIN_TAB_H = 7.1
  26. TABHEADER_H = 0.85
  27. GAMEBAR_H = 1.25
  28. GAMEBAR_OFFSET_DESKTOP = 0.375
  29. GAMEBAR_OFFSET_TOUCH = 0.15
  30. local menupath = core.get_mainmenu_path()
  31. local basepath = core.get_builtin_path()
  32. defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
  33. DIR_DELIM .. "pack" .. DIR_DELIM
  34. dofile(basepath .. "common" .. DIR_DELIM .. "filterlist.lua")
  35. dofile(basepath .. "fstk" .. DIR_DELIM .. "buttonbar.lua")
  36. dofile(basepath .. "fstk" .. DIR_DELIM .. "dialog.lua")
  37. dofile(basepath .. "fstk" .. DIR_DELIM .. "tabview.lua")
  38. dofile(basepath .. "fstk" .. DIR_DELIM .. "ui.lua")
  39. dofile(menupath .. DIR_DELIM .. "async_event.lua")
  40. dofile(menupath .. DIR_DELIM .. "common.lua")
  41. dofile(menupath .. DIR_DELIM .. "serverlistmgr.lua")
  42. dofile(menupath .. DIR_DELIM .. "game_theme.lua")
  43. dofile(menupath .. DIR_DELIM .. "content" .. DIR_DELIM .. "init.lua")
  44. dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
  45. dofile(menupath .. DIR_DELIM .. "settings" .. DIR_DELIM .. "init.lua")
  46. dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
  47. dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua")
  48. dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
  49. dofile(menupath .. DIR_DELIM .. "dlg_register.lua")
  50. dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
  51. dofile(menupath .. DIR_DELIM .. "dlg_version_info.lua")
  52. dofile(menupath .. DIR_DELIM .. "dlg_reinstall_mtg.lua")
  53. dofile(menupath .. DIR_DELIM .. "dlg_clients_list.lua")
  54. local tabs = {
  55. content = dofile(menupath .. DIR_DELIM .. "tab_content.lua"),
  56. about = dofile(menupath .. DIR_DELIM .. "tab_about.lua"),
  57. local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua"),
  58. play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
  59. }
  60. --------------------------------------------------------------------------------
  61. local function main_event_handler(tabview, event)
  62. if event == "MenuQuit" then
  63. core.close()
  64. end
  65. return true
  66. end
  67. --------------------------------------------------------------------------------
  68. local function init_globals()
  69. -- Init gamedata
  70. gamedata.worldindex = 0
  71. menudata.worldlist = filterlist.create(
  72. core.get_worlds,
  73. compare_worlds,
  74. -- Unique id comparison function
  75. function(element, uid)
  76. return element.name == uid
  77. end,
  78. -- Filter function
  79. function(element, gameid)
  80. return element.gameid == gameid
  81. end
  82. )
  83. menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
  84. menudata.worldlist:set_sortmode("alphabetic")
  85. mm_game_theme.init()
  86. mm_game_theme.set_engine() -- This is just a fallback.
  87. -- Create main tabview
  88. local tv_main = tabview_create("maintab", {x = MAIN_TAB_W, y = MAIN_TAB_H}, {x = 0, y = 0})
  89. tv_main:set_autosave_tab(true)
  90. tv_main:add(tabs.local_game)
  91. tv_main:add(tabs.play_online)
  92. tv_main:add(tabs.content)
  93. tv_main:add(tabs.about)
  94. tv_main:set_global_event_handler(main_event_handler)
  95. tv_main:set_fixed_size(false)
  96. local last_tab = core.settings:get("maintab_LAST")
  97. if last_tab and tv_main.current_tab ~= last_tab then
  98. tv_main:set_tab(last_tab)
  99. end
  100. tv_main:set_end_button({
  101. icon = defaulttexturedir .. "settings_btn.png",
  102. label = fgettext("Settings"),
  103. name = "open_settings",
  104. on_click = function(tabview)
  105. local dlg = create_settings_dlg()
  106. dlg:set_parent(tabview)
  107. tabview:hide()
  108. dlg:show()
  109. return true
  110. end,
  111. })
  112. ui.set_default("maintab")
  113. tv_main:show()
  114. ui.update()
  115. check_reinstall_mtg()
  116. check_new_version()
  117. end
  118. assert(os.execute == nil)
  119. init_globals()