init.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. -- Luanti
  2. -- Copyright (C) 2014 sapier
  3. -- SPDX-License-Identifier: LGPL-2.1-or-later
  4. MAIN_TAB_W = 15.5
  5. MAIN_TAB_H = 7.1
  6. TABHEADER_H = 0.85
  7. GAMEBAR_H = 1.25
  8. GAMEBAR_OFFSET_DESKTOP = 0.375
  9. GAMEBAR_OFFSET_TOUCH = 0.15
  10. local menupath = core.get_mainmenu_path()
  11. local basepath = core.get_builtin_path()
  12. defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
  13. DIR_DELIM .. "pack" .. DIR_DELIM
  14. dofile(basepath .. "common" .. DIR_DELIM .. "menu.lua")
  15. dofile(basepath .. "common" .. DIR_DELIM .. "filterlist.lua")
  16. dofile(basepath .. "fstk" .. DIR_DELIM .. "buttonbar.lua")
  17. dofile(basepath .. "fstk" .. DIR_DELIM .. "dialog.lua")
  18. dofile(basepath .. "fstk" .. DIR_DELIM .. "tabview.lua")
  19. dofile(basepath .. "fstk" .. DIR_DELIM .. "ui.lua")
  20. dofile(menupath .. DIR_DELIM .. "async_event.lua")
  21. dofile(menupath .. DIR_DELIM .. "common.lua")
  22. dofile(menupath .. DIR_DELIM .. "serverlistmgr.lua")
  23. dofile(menupath .. DIR_DELIM .. "game_theme.lua")
  24. dofile(menupath .. DIR_DELIM .. "content" .. DIR_DELIM .. "init.lua")
  25. dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
  26. dofile(basepath .. "common" .. DIR_DELIM .. "settings" .. DIR_DELIM .. "init.lua")
  27. dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
  28. dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua")
  29. dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
  30. dofile(menupath .. DIR_DELIM .. "dlg_register.lua")
  31. dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
  32. dofile(menupath .. DIR_DELIM .. "dlg_version_info.lua")
  33. dofile(menupath .. DIR_DELIM .. "dlg_reinstall_mtg.lua")
  34. dofile(menupath .. DIR_DELIM .. "dlg_rebind_keys.lua")
  35. dofile(menupath .. DIR_DELIM .. "dlg_clients_list.lua")
  36. dofile(menupath .. DIR_DELIM .. "dlg_server_list_mods.lua")
  37. local tabs = {
  38. content = dofile(menupath .. DIR_DELIM .. "tab_content.lua"),
  39. about = dofile(menupath .. DIR_DELIM .. "tab_about.lua"),
  40. local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua"),
  41. play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
  42. }
  43. --------------------------------------------------------------------------------
  44. local function main_event_handler(tabview, event)
  45. if event == "MenuQuit" then
  46. core.close()
  47. end
  48. return true
  49. end
  50. --------------------------------------------------------------------------------
  51. local function init_globals()
  52. -- Init gamedata
  53. gamedata.worldindex = 0
  54. menudata.worldlist = filterlist.create(
  55. core.get_worlds,
  56. compare_worlds,
  57. -- Unique id comparison function
  58. function(element, uid)
  59. return element.name == uid
  60. end,
  61. -- Filter function
  62. function(element, gameid)
  63. return element.gameid == gameid
  64. end
  65. )
  66. menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
  67. menudata.worldlist:set_sortmode("alphabetic")
  68. mm_game_theme.init()
  69. mm_game_theme.set_engine() -- This is just a fallback.
  70. -- Create main tabview
  71. local tv_main = tabview_create("maintab", {x = MAIN_TAB_W, y = MAIN_TAB_H}, {x = 0, y = 0})
  72. tv_main:set_autosave_tab(true)
  73. tv_main:add(tabs.local_game)
  74. tv_main:add(tabs.play_online)
  75. tv_main:add(tabs.content)
  76. tv_main:add(tabs.about)
  77. tv_main:set_global_event_handler(main_event_handler)
  78. tv_main:set_fixed_size(false)
  79. local last_tab = core.settings:get("maintab_LAST")
  80. if last_tab and tv_main.current_tab ~= last_tab then
  81. tv_main:set_tab(last_tab)
  82. end
  83. tv_main:set_end_button({
  84. icon = defaulttexturedir .. "settings_btn.png",
  85. label = fgettext("Settings"),
  86. name = "open_settings",
  87. on_click = function(tabview)
  88. local dlg = create_settings_dlg()
  89. dlg:set_parent(tabview)
  90. tabview:hide()
  91. dlg:show()
  92. return true
  93. end,
  94. })
  95. ui.set_default("maintab")
  96. tv_main:show()
  97. ui.update()
  98. check_reinstall_mtg()
  99. migrate_keybindings()
  100. check_new_version()
  101. end
  102. assert(os.execute == nil)
  103. init_globals()