2 math.randomseed(os.time())
3 os.setlocale("C", "numeric")
7 print(debug.traceback(""))
11 local scriptpath = engine.get_scriptdir()
13 mt_color_grey = "#AAAAAA"
14 mt_color_blue = "#0000DD"
15 mt_color_green = "#00DD00"
16 mt_color_dark_green = "#003300"
18 --for all other colors ask sfan5 to complete his worK!
20 dofile(scriptpath .. DIR_DELIM .. "misc_helpers.lua")
21 dofile(scriptpath .. DIR_DELIM .. "filterlist.lua")
22 dofile(scriptpath .. DIR_DELIM .. "modmgr.lua")
23 dofile(scriptpath .. DIR_DELIM .. "modstore.lua")
24 dofile(scriptpath .. DIR_DELIM .. "gamemgr.lua")
25 dofile(scriptpath .. DIR_DELIM .. "mm_textures.lua")
26 dofile(scriptpath .. DIR_DELIM .. "mm_menubar.lua")
27 dofile(scriptpath .. DIR_DELIM .. "async_event.lua")
33 --------------------------------------------------------------------------------
34 local function filter_texture_pack_list(list)
36 for _,i in ipairs(list) do
38 table.insert(retval, i)
44 --------------------------------------------------------------------------------
45 function menu.render_favorite(spec,render_details)
48 if spec.name ~= nil then
49 text = text .. engine.formspec_escape(spec.name:trim())
51 -- if spec.description ~= nil and
52 -- engine.formspec_escape(spec.description):trim() ~= "" then
53 -- text = text .. " (" .. engine.formspec_escape(spec.description) .. ")"
56 if spec.address ~= nil then
57 text = text .. spec.address:trim()
59 if spec.port ~= nil then
60 text = text .. ":" .. spec.port
65 if not render_details then
70 if spec.password == true then
71 details = details .. "*"
73 details = details .. "_"
77 details = details .. "C"
79 details = details .. "_"
83 details = details .. "D"
85 details = details .. "_"
89 details = details .. "P"
91 details = details .. "_"
93 details = details .. " "
95 local playercount = ""
97 if spec.clients ~= nil and
98 spec.clients_max ~= nil then
99 playercount = string.format("%03d",spec.clients) .. "/" ..
100 string.format("%03d",spec.clients_max) .. " "
103 return playercount .. engine.formspec_escape(details) .. text
106 --------------------------------------------------------------------------------
107 os.tempfolder = function()
108 local filetocheck = os.tmpname()
109 os.remove(filetocheck)
111 local randname = "MTTempModFolder_" .. math.random(0,10000)
112 if DIR_DELIM == "\\" then
113 local tempfolder = os.getenv("TEMP")
114 return tempfolder .. filetocheck
116 local backstring = filetocheck:reverse()
117 return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname
122 --------------------------------------------------------------------------------
123 function init_globals()
125 gamedata.worldindex = 0
127 worldlist = filterlist.create(
130 function(element,uid)
131 if element.name == uid then
135 end, --unique id compare fct
136 function(element,gameid)
137 if element.gameid == gameid then
144 filterlist.add_sort_mechanism(worldlist,"alphabetic",sort_worlds_alphabetic)
145 filterlist.set_sortmode(worldlist,"alphabetic")
148 --------------------------------------------------------------------------------
149 function update_menu()
154 if gamedata.errormessage ~= nil then
155 formspec = "size[12,5.2]" ..
156 "field[1,2;10,2;;ERROR: " ..
157 gamedata.errormessage ..
159 "button[4.5,4.2;3,0.5;btn_error_confirm;" .. fgettext("Ok") .. "]"
161 formspec = tabbuilder.gettab()
164 engine.update_formspec(formspec)
167 --------------------------------------------------------------------------------
168 function menu.render_world_list()
171 local current_worldlist = filterlist.get_list(worldlist)
173 for i,v in ipairs(current_worldlist) do
175 retval = retval ..","
178 retval = retval .. engine.formspec_escape(v.name) ..
179 " \\[" .. engine.formspec_escape(v.gameid) .. "\\]"
185 --------------------------------------------------------------------------------
186 function menu.render_texture_pack_list(list)
189 for i,v in ipairs(list) do
191 retval = retval ..","
200 --------------------------------------------------------------------------------
201 function menu.asyncOnlineFavourites()
205 return engine.get_favorites("online")
209 menu.favorites = result
210 engine.event_handler("Refresh")
215 --------------------------------------------------------------------------------
218 gamemgr.update_gamelist()
220 menu.last_game = tonumber(engine.setting_get("main_menu_last_game_idx"))
222 if type(menu.last_game) ~= "number" then
226 if engine.setting_getbool("public_serverlist") then
227 menu.asyncOnlineFavourites()
229 menu.favorites = engine.get_favorites("local")
232 menu.defaulttexturedir = engine.get_texturepath() .. DIR_DELIM .. "base" ..
233 DIR_DELIM .. "pack" .. DIR_DELIM
236 --------------------------------------------------------------------------------
237 function menu.lastgame()
238 if menu.last_game > 0 and menu.last_game <= #gamemgr.games then
239 return gamemgr.games[menu.last_game]
242 if #gamemgr.games >= 1 then
244 return gamemgr.games[menu.last_game]
251 --------------------------------------------------------------------------------
252 function menu.update_last_game()
254 local current_world = filterlist.get_raw_element(worldlist,
255 engine.setting_get("mainmenu_last_selected_world")
258 if current_world == nil then
262 local gamespec, i = gamemgr.find_by_gameid(current_world.gameid)
265 engine.setting_set("main_menu_last_game_idx",menu.last_game)
269 --------------------------------------------------------------------------------
270 function menu.handle_key_up_down(fields,textlist,settingname)
272 if fields["key_up"] then
273 local oldidx = engine.get_textlist_index(textlist)
276 local newidx = oldidx -1
277 engine.setting_set(settingname,
278 filterlist.get_raw_index(worldlist,newidx))
282 if fields["key_down"] then
283 local oldidx = engine.get_textlist_index(textlist)
285 if oldidx < filterlist.size(worldlist) then
286 local newidx = oldidx + 1
287 engine.setting_set(settingname,
288 filterlist.get_raw_index(worldlist,newidx))
293 --------------------------------------------------------------------------------
294 function tabbuilder.dialog_create_world()
295 local mapgens = {"v6", "v7", "indev", "singlenode", "math"}
297 local current_seed = engine.setting_get("fixed_map_seed") or ""
298 local current_mg = engine.setting_get("mg_name")
303 for k,v in pairs(mapgens) do
304 if current_mg == v then
308 mglist = mglist .. v .. ","
310 mglist = mglist:sub(1, -2)
313 "label[2,0;" .. fgettext("World name") .. "]"..
314 "field[4.5,0.4;6,0.5;te_world_name;;]" ..
316 "label[2,1;" .. fgettext("Seed") .. "]"..
317 "field[4.5,1.4;6,0.5;te_seed;;".. current_seed .. "]" ..
319 "label[2,2;" .. fgettext("Mapgen") .. "]"..
320 "dropdown[4.2,2;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
322 "label[2,3;" .. fgettext("Game") .. "]"..
323 "textlist[4.2,3;5.8,2.3;games;" .. gamemgr.gamelist() ..
324 ";" .. menu.last_game .. ";true]" ..
326 "button[5,5.5;2.6,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
327 "button[7.5,5.5;2.8,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
332 --------------------------------------------------------------------------------
333 function tabbuilder.dialog_delete_world()
334 return "label[2,2;" ..
335 fgettext("Delete World \"$1\"?", filterlist.get_raw_list(worldlist)[menu.world_to_del].name) .. "]"..
336 "button[3.5,4.2;2.6,0.5;world_delete_confirm;" .. fgettext("Yes").. "]" ..
337 "button[6,4.2;2.8,0.5;world_delete_cancel;" .. fgettext("No") .. "]"
340 --------------------------------------------------------------------------------
342 function tabbuilder.gettab()
343 local tsize = tabbuilder.tabsizes[tabbuilder.current_tab] or {width=12, height=5.2}
344 local retval = "size[" .. tsize.width .. "," .. tsize.height .. "]"
346 if tabbuilder.show_buttons then
347 retval = retval .. tabbuilder.tab_header()
350 local buildfunc = tabbuilder.tabfuncs[tabbuilder.current_tab]
351 if buildfunc ~= nil then
352 retval = retval .. buildfunc()
355 retval = retval .. modmgr.gettab(tabbuilder.current_tab)
356 retval = retval .. gamemgr.gettab(tabbuilder.current_tab)
357 retval = retval .. modstore.gettab(tabbuilder.current_tab)
362 --------------------------------------------------------------------------------
363 function tabbuilder.handle_create_world_buttons(fields)
365 if fields["world_create_confirm"] or
366 fields["key_enter"] then
368 local worldname = fields["te_world_name"]
369 local gameindex = engine.get_textlist_index("games")
376 if not filterlist.uid_exists_raw(worldlist,worldname) then
377 engine.setting_set("mg_name",fields["dd_mapgen"])
378 message = engine.create_world(worldname,gameindex)
380 message = fgettext("A world named \"$1\" already exists", worldname)
383 engine.setting_set("fixed_map_seed", fields["te_seed"])
385 if message ~= nil then
386 gamedata.errormessage = message
388 menu.last_game = gameindex
389 engine.setting_set("main_menu_last_game_idx",gameindex)
391 filterlist.refresh(worldlist)
392 engine.setting_set("mainmenu_last_selected_world",
393 filterlist.raw_index_by_uid(worldlist,worldname))
396 gamedata.errormessage =
397 fgettext("No worldname given or no game selected")
401 if fields["games"] then
402 tabbuilder.skipformupdate = true
407 tabbuilder.is_dialog = false
408 tabbuilder.show_buttons = true
409 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
412 --------------------------------------------------------------------------------
413 function tabbuilder.handle_delete_world_buttons(fields)
415 if fields["world_delete_confirm"] then
416 if menu.world_to_del > 0 and
417 menu.world_to_del <= #filterlist.get_raw_list(worldlist) then
418 engine.delete_world(menu.world_to_del)
419 menu.world_to_del = 0
420 filterlist.refresh(worldlist)
424 tabbuilder.is_dialog = false
425 tabbuilder.show_buttons = true
426 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
429 --------------------------------------------------------------------------------
430 function tabbuilder.handle_multiplayer_buttons(fields)
432 if fields["te_name"] ~= nil then
433 gamedata.playername = fields["te_name"]
434 engine.setting_set("name", fields["te_name"])
437 if fields["favourites"] ~= nil then
438 local event = explode_textlist_event(fields["favourites"])
439 if event.typ == "DCL" then
440 if event.index <= #menu.favorites then
441 gamedata.address = menu.favorites[event.index].address
442 gamedata.port = menu.favorites[event.index].port
443 gamedata.playername = fields["te_name"]
444 if fields["te_pwd"] ~= nil then
445 gamedata.password = fields["te_pwd"]
447 gamedata.selected_world = 0
449 if menu.favorites ~= nil then
450 gamedata.servername = menu.favorites[event.index].name
451 gamedata.serverdescription = menu.favorites[event.index].description
454 if gamedata.address ~= nil and
455 gamedata.port ~= nil then
456 engine.setting_set("address",gamedata.address)
457 engine.setting_set("remote_port",gamedata.port)
463 if event.typ == "CHG" then
464 if event.index <= #menu.favorites then
465 local address = menu.favorites[event.index].address
466 local port = menu.favorites[event.index].port
468 if address ~= nil and
470 engine.setting_set("address",address)
471 engine.setting_set("remote_port",port)
474 menu.fav_selected = event.index
480 if fields["key_up"] ~= nil or
481 fields["key_down"] ~= nil then
483 local fav_idx = engine.get_textlist_index("favourites")
485 if fields["key_up"] ~= nil and fav_idx > 1 then
487 else if fields["key_down"] and fav_idx < #menu.favorites then
491 local address = menu.favorites[fav_idx].address
492 local port = menu.favorites[fav_idx].port
494 if address ~= nil and
496 engine.setting_set("address",address)
497 engine.setting_set("remote_port",port)
500 menu.fav_selected = fav_idx
504 if fields["cb_public_serverlist"] ~= nil then
505 engine.setting_set("public_serverlist", fields["cb_public_serverlist"])
507 if engine.setting_getbool("public_serverlist") then
508 menu.asyncOnlineFavourites()
510 menu.favorites = engine.get_favorites("local")
512 menu.fav_selected = nil
516 if fields["btn_delete_favorite"] ~= nil then
517 local current_favourite = engine.get_textlist_index("favourites")
518 engine.delete_favorite(current_favourite)
519 menu.favorites = engine.get_favorites()
520 menu.fav_selected = nil
522 engine.setting_set("address","")
523 engine.setting_set("remote_port","30000")
528 if fields["btn_mp_connect"] ~= nil or
529 fields["key_enter"] ~= nil then
531 gamedata.playername = fields["te_name"]
532 gamedata.password = fields["te_pwd"]
533 gamedata.address = fields["te_address"]
534 gamedata.port = fields["te_port"]
536 local fav_idx = engine.get_textlist_index("favourites")
538 if fav_idx > 0 and fav_idx <= #menu.favorites and
539 menu.favorites[fav_idx].address == fields["te_address"] and
540 menu.favorites[fav_idx].port == fields["te_port"] then
542 gamedata.servername = menu.favorites[fav_idx].name
543 gamedata.serverdescription = menu.favorites[fav_idx].description
545 gamedata.servername = ""
546 gamedata.serverdescription = ""
549 gamedata.selected_world = 0
551 engine.setting_set("address",fields["te_address"])
552 engine.setting_set("remote_port",fields["te_port"])
559 --------------------------------------------------------------------------------
560 function tabbuilder.handle_server_buttons(fields)
562 local world_doubleclick = false
564 if fields["srv_worlds"] ~= nil then
565 local event = explode_textlist_event(fields["srv_worlds"])
567 if event.typ == "DCL" then
568 world_doubleclick = true
570 if event.typ == "CHG" then
571 engine.setting_set("mainmenu_last_selected_world",
572 filterlist.get_raw_index(worldlist,engine.get_textlist_index("srv_worlds")))
576 menu.handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world")
578 if fields["cb_creative_mode"] then
579 engine.setting_set("creative_mode", fields["cb_creative_mode"])
582 if fields["cb_enable_damage"] then
583 engine.setting_set("enable_damage", fields["cb_enable_damage"])
586 if fields["cb_server_announce"] then
587 engine.setting_set("server_announce", fields["cb_server_announce"])
590 if fields["start_server"] ~= nil or
592 fields["key_enter"] then
593 local selected = engine.get_textlist_index("srv_worlds")
595 gamedata.playername = fields["te_playername"]
596 gamedata.password = fields["te_passwd"]
597 gamedata.port = fields["te_serverport"]
598 gamedata.address = ""
599 gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
601 engine.setting_set("port",gamedata.port)
603 menu.update_last_game(gamedata.selected_world)
608 if fields["world_create"] ~= nil then
609 tabbuilder.current_tab = "dialog_create_world"
610 tabbuilder.is_dialog = true
611 tabbuilder.show_buttons = false
614 if fields["world_delete"] ~= nil then
615 local selected = engine.get_textlist_index("srv_worlds")
617 selected <= filterlist.size(worldlist) then
618 local world = filterlist.get_list(worldlist)[selected]
620 world.name ~= nil and
621 world.name ~= "" then
622 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
623 tabbuilder.current_tab = "dialog_delete_world"
624 tabbuilder.is_dialog = true
625 tabbuilder.show_buttons = false
627 menu.world_to_del = 0
632 if fields["world_configure"] ~= nil then
633 selected = engine.get_textlist_index("srv_worlds")
635 modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
636 if modmgr.init_worldconfig() then
637 tabbuilder.current_tab = "dialog_configure_world"
638 tabbuilder.is_dialog = true
639 tabbuilder.show_buttons = false
645 --------------------------------------------------------------------------------
646 function tabbuilder.handle_settings_buttons(fields)
647 if fields["cb_fancy_trees"] then
648 engine.setting_set("new_style_leaves", fields["cb_fancy_trees"])
650 if fields["cb_smooth_lighting"] then
651 engine.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
653 if fields["cb_3d_clouds"] then
654 engine.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
656 if fields["cb_opaque_water"] then
657 engine.setting_set("opaque_water", fields["cb_opaque_water"])
660 if fields["cb_mipmapping"] then
661 engine.setting_set("mip_map", fields["cb_mipmapping"])
663 if fields["cb_anisotrophic"] then
664 engine.setting_set("anisotropic_filter", fields["cb_anisotrophic"])
666 if fields["cb_bilinear"] then
667 engine.setting_set("bilinear_filter", fields["cb_bilinear"])
669 if fields["cb_trilinear"] then
670 engine.setting_set("trilinear_filter", fields["cb_trilinear"])
673 if fields["cb_shaders"] then
674 if (engine.setting_get("video_driver") == "direct3d8" or engine.setting_get("video_driver") == "direct3d9") then
675 engine.setting_set("enable_shaders", "false")
676 gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
678 engine.setting_set("enable_shaders", fields["cb_shaders"])
681 if fields["cb_pre_ivis"] then
682 engine.setting_set("preload_item_visuals", fields["cb_pre_ivis"])
684 if fields["cb_particles"] then
685 engine.setting_set("enable_particles", fields["cb_particles"])
687 if fields["cb_finite_liquid"] then
688 engine.setting_set("liquid_finite", fields["cb_finite_liquid"])
690 if fields["cb_bumpmapping"] then
691 engine.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
693 if fields["cb_parallax"] then
694 engine.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
696 if fields["cb_waving_water"] then
697 engine.setting_set("enable_waving_water", fields["cb_waving_water"])
699 if fields["cb_waving_leaves"] then
700 engine.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
702 if fields["cb_waving_plants"] then
703 engine.setting_set("enable_waving_plants", fields["cb_waving_plants"])
705 if fields["btn_change_keys"] ~= nil then
706 engine.show_keys_menu()
710 --------------------------------------------------------------------------------
711 function tabbuilder.handle_singleplayer_buttons(fields)
713 local world_doubleclick = false
715 if fields["sp_worlds"] ~= nil then
716 local event = explode_textlist_event(fields["sp_worlds"])
718 if event.typ == "DCL" then
719 world_doubleclick = true
722 if event.typ == "CHG" then
723 engine.setting_set("mainmenu_last_selected_world",
724 filterlist.get_raw_index(worldlist,engine.get_textlist_index("sp_worlds")))
728 menu.handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world")
730 if fields["cb_creative_mode"] then
731 engine.setting_set("creative_mode", fields["cb_creative_mode"])
734 if fields["cb_enable_damage"] then
735 engine.setting_set("enable_damage", fields["cb_enable_damage"])
738 if fields["play"] ~= nil or
740 fields["key_enter"] then
741 local selected = engine.get_textlist_index("sp_worlds")
743 gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
744 gamedata.singleplayer = true
746 menu.update_last_game(gamedata.selected_world)
752 if fields["world_create"] ~= nil then
753 tabbuilder.current_tab = "dialog_create_world"
754 tabbuilder.is_dialog = true
755 tabbuilder.show_buttons = false
758 if fields["world_delete"] ~= nil then
759 local selected = engine.get_textlist_index("sp_worlds")
761 selected <= filterlist.size(worldlist) then
762 local world = filterlist.get_list(worldlist)[selected]
764 world.name ~= nil and
765 world.name ~= "" then
766 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
767 tabbuilder.current_tab = "dialog_delete_world"
768 tabbuilder.is_dialog = true
769 tabbuilder.show_buttons = false
771 menu.world_to_del = 0
776 if fields["world_configure"] ~= nil then
777 selected = engine.get_textlist_index("sp_worlds")
779 modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
780 if modmgr.init_worldconfig() then
781 tabbuilder.current_tab = "dialog_configure_world"
782 tabbuilder.is_dialog = true
783 tabbuilder.show_buttons = false
789 --------------------------------------------------------------------------------
790 function tabbuilder.handle_texture_pack_buttons(fields)
791 if fields["TPs"] ~= nil then
792 local event = explode_textlist_event(fields["TPs"])
793 if event.typ == "CHG" or event.typ=="DCL" then
794 local index = engine.get_textlist_index("TPs")
795 engine.setting_set("mainmenu_last_selected_TP",
797 local list = filter_texture_pack_list(engine.get_dirlist(engine.get_texturepath(), true))
798 local current_index = engine.get_textlist_index("TPs")
799 if #list >= current_index then
800 local new_path = engine.get_texturepath()..DIR_DELIM..list[current_index]
801 if list[current_index] == "None" then new_path = "" end
803 engine.setting_set("texture_path", new_path)
809 --------------------------------------------------------------------------------
810 function tabbuilder.tab_header()
812 if tabbuilder.last_tab_index == nil then
813 tabbuilder.last_tab_index = 1
818 for i=1,#tabbuilder.current_buttons,1 do
824 toadd = toadd .. tabbuilder.current_buttons[i].caption
826 return "tabheader[-0.3,-0.99;main_tab;" .. toadd ..";" .. tabbuilder.last_tab_index .. ";true;false]"
829 --------------------------------------------------------------------------------
830 function tabbuilder.handle_tab_buttons(fields)
832 if fields["main_tab"] then
833 local index = tonumber(fields["main_tab"])
834 tabbuilder.last_tab_index = index
835 tabbuilder.current_tab = tabbuilder.current_buttons[index].name
837 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
841 if tabbuilder.current_tab ~= tabbuilder.old_tab then
842 if tabbuilder.current_tab ~= "singleplayer" and not tabbuilder.is_dialog then
843 menu.update_gametype(true)
847 if tabbuilder.current_tab == "singleplayer" then
848 menu.update_gametype()
851 tabbuilder.old_tab = tabbuilder.current_tab
854 --------------------------------------------------------------------------------
855 function tabbuilder.tab_multiplayer()
858 "vertlabel[0,-0.25;".. fgettext("CLIENT") .. "]" ..
859 "label[1,-0.25;".. fgettext("Favorites:") .. "]"..
860 "label[1,4.25;".. fgettext("Address/Port") .. "]"..
861 "label[9,2.75;".. fgettext("Name/Password") .. "]" ..
862 "field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" ..
863 "field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("remote_port") .."]" ..
864 "checkbox[1,3.6;cb_public_serverlist;".. fgettext("Public Serverlist") .. ";" ..
865 dump(engine.setting_getbool("public_serverlist")) .. "]"
867 if not engine.setting_getbool("public_serverlist") then
869 "button[6.45,3.95;2.25,0.5;btn_delete_favorite;".. fgettext("Delete") .. "]"
873 "button[9,4.95;2.5,0.5;btn_mp_connect;".. fgettext("Connect") .. "]" ..
874 "field[9.3,3.75;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" ..
875 "pwdfield[9.3,4.5;2.5,0.5;te_pwd;]" ..
876 "textarea[9.3,0.25;2.5,2.75;;"
877 if menu.fav_selected ~= nil and
878 menu.favorites[menu.fav_selected].description ~= nil then
880 engine.formspec_escape(menu.favorites[menu.fav_selected].description,true)
885 "textlist[1,0.35;7.5,3.35;favourites;"
887 local render_details = engine.setting_getbool("public_serverlist")
889 if #menu.favorites > 0 then
890 retval = retval .. menu.render_favorite(menu.favorites[1],render_details)
892 for i=2,#menu.favorites,1 do
893 retval = retval .. "," .. menu.render_favorite(menu.favorites[i],render_details)
897 if menu.fav_selected ~= nil then
898 retval = retval .. ";" .. menu.fav_selected .. "]"
900 retval = retval .. ";0]"
906 --------------------------------------------------------------------------------
907 function tabbuilder.tab_server()
909 local index = filterlist.get_current_index(worldlist,
910 tonumber(engine.setting_get("mainmenu_last_selected_world"))
914 "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" ..
915 "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" ..
916 "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" ..
917 "button[8.5,4.9;3.25,0.5;start_server;".. fgettext("Start Game") .. "]" ..
918 "label[4,-0.25;".. fgettext("Select World:") .. "]"..
919 "vertlabel[0,-0.25;".. fgettext("START SERVER") .. "]" ..
920 "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
921 dump(engine.setting_getbool("creative_mode")) .. "]"..
922 "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
923 dump(engine.setting_getbool("enable_damage")) .. "]"..
924 "checkbox[0.5,1.15;cb_server_announce;".. fgettext("Public") .. ";" ..
925 dump(engine.setting_getbool("server_announce")) .. "]"..
926 "field[0.8,3.2;3,0.5;te_playername;".. fgettext("Name") .. ";" ..
927 engine.setting_get("name") .. "]" ..
928 "pwdfield[0.8,4.2;3,0.5;te_passwd;".. fgettext("Password") .. "]" ..
929 "field[0.8,5.2;3,0.5;te_serverport;".. fgettext("Server Port") .. ";" ..
930 engine.setting_get("port") .."]" ..
931 "textlist[4,0.25;7.5,3.7;srv_worlds;" ..
932 menu.render_world_list() ..
938 --------------------------------------------------------------------------------
939 function tabbuilder.tab_settings()
941 "vertlabel[0,0;" .. fgettext("SETTINGS") .. "]" ..
942 "checkbox[1,0;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";"
943 .. dump(engine.setting_getbool("new_style_leaves")) .. "]"..
944 "checkbox[1,0.5;cb_smooth_lighting;".. fgettext("Smooth Lighting")
945 .. ";".. dump(engine.setting_getbool("smooth_lighting")) .. "]"..
946 "checkbox[1,1;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
947 .. dump(engine.setting_getbool("enable_3d_clouds")) .. "]"..
948 "checkbox[1,1.5;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
949 .. dump(engine.setting_getbool("opaque_water")) .. "]"..
950 "checkbox[1,2.0;cb_pre_ivis;".. fgettext("Preload item visuals") .. ";"
951 .. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
952 "checkbox[1,2.5;cb_particles;".. fgettext("Enable Particles") .. ";"
953 .. dump(engine.setting_getbool("enable_particles")) .. "]"..
954 "checkbox[1,3.0;cb_finite_liquid;".. fgettext("Finite Liquid") .. ";"
955 .. dump(engine.setting_getbool("liquid_finite")) .. "]"..
957 "checkbox[4.5,0;cb_mipmapping;".. fgettext("Mip-Mapping") .. ";"
958 .. dump(engine.setting_getbool("mip_map")) .. "]"..
959 "checkbox[4.5,0.5;cb_anisotrophic;".. fgettext("Anisotropic Filtering") .. ";"
960 .. dump(engine.setting_getbool("anisotropic_filter")) .. "]"..
961 "checkbox[4.5,1.0;cb_bilinear;".. fgettext("Bi-Linear Filtering") .. ";"
962 .. dump(engine.setting_getbool("bilinear_filter")) .. "]"..
963 "checkbox[4.5,1.5;cb_trilinear;".. fgettext("Tri-Linear Filtering") .. ";"
964 .. dump(engine.setting_getbool("trilinear_filter")) .. "]"..
966 "checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";"
967 .. dump(engine.setting_getbool("enable_shaders")) .. "]"..
968 "button[1,4.5;2.25,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
970 if engine.setting_getbool("enable_shaders") then
971 tab_string = tab_string ..
972 "checkbox[8,0.5;cb_bumpmapping;".. fgettext("Bumpmapping") .. ";"
973 .. dump(engine.setting_getbool("enable_bumpmapping")) .. "]"..
974 "checkbox[8,1.0;cb_parallax;".. fgettext("Parallax Occlusion") .. ";"
975 .. dump(engine.setting_getbool("enable_parallax_occlusion")) .. "]"..
976 "checkbox[8,1.5;cb_waving_water;".. fgettext("Waving Water") .. ";"
977 .. dump(engine.setting_getbool("enable_waving_water")) .. "]"..
978 "checkbox[8,2.0;cb_waving_leaves;".. fgettext("Waving Leaves") .. ";"
979 .. dump(engine.setting_getbool("enable_waving_leaves")) .. "]"..
980 "checkbox[8,2.5;cb_waving_plants;".. fgettext("Waving Plants") .. ";"
981 .. dump(engine.setting_getbool("enable_waving_plants")) .. "]"
983 tab_string = tab_string ..
984 "textlist[8.33,0.7;4,1;;#888888" .. fgettext("Bumpmapping") .. ";0;true]" ..
985 "textlist[8.33,1.2;4,1;;#888888" .. fgettext("Parallax Occlusion") .. ";0;true]" ..
986 "textlist[8.33,1.7;4,1;;#888888" .. fgettext("Waving Water") .. ";0;true]" ..
987 "textlist[8.33,2.2;4,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" ..
988 "textlist[8.33,2.7;4,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]"
993 --------------------------------------------------------------------------------
994 function tabbuilder.tab_singleplayer()
996 local index = filterlist.get_current_index(worldlist,
997 tonumber(engine.setting_get("mainmenu_last_selected_world"))
1000 return "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" ..
1001 "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" ..
1002 "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" ..
1003 "button[8.5,4.95;3.25,0.5;play;".. fgettext("Play") .. "]" ..
1004 "label[4,-0.25;".. fgettext("Select World:") .. "]"..
1005 "vertlabel[0,-0.25;".. fgettext("SINGLE PLAYER") .. "]" ..
1006 "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
1007 dump(engine.setting_getbool("creative_mode")) .. "]"..
1008 "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
1009 dump(engine.setting_getbool("enable_damage")) .. "]"..
1010 "textlist[4,0.25;7.5,3.7;sp_worlds;" ..
1011 menu.render_world_list() ..
1012 ";" .. index .. "]" ..
1016 --------------------------------------------------------------------------------
1017 function tabbuilder.tab_texture_packs()
1018 local retval = "label[4,-0.25;".. fgettext("Select texture pack:") .. "]"..
1019 "vertlabel[0,-0.25;".. fgettext("TEXTURE PACKS") .. "]" ..
1020 "textlist[4,0.25;7.5,5.0;TPs;"
1022 local current_texture_path = engine.setting_get("texture_path")
1023 local list = filter_texture_pack_list(engine.get_dirlist(engine.get_texturepath(), true))
1024 local index = tonumber(engine.setting_get("mainmenu_last_selected_TP"))
1026 if index == nil then index = 1 end
1028 if current_texture_path == "" then
1030 menu.render_texture_pack_list(list) ..
1035 local infofile = current_texture_path ..DIR_DELIM.."info.txt"
1037 local f = io.open(infofile, "r")
1039 infotext = fgettext("No information available")
1041 infotext = f:read("*all")
1045 local screenfile = current_texture_path..DIR_DELIM.."screenshot.png"
1046 local no_screenshot = nil
1047 if not file_exists(screenfile) then
1049 no_screenshot = engine.get_texturepath()..DIR_DELIM..
1050 "base"..DIR_DELIM.."pack"..DIR_DELIM.."no_screenshot.png"
1054 menu.render_texture_pack_list(list) ..
1055 ";" .. index .. "]" ..
1056 "image[0.65,0.25;4.0,3.7;"..engine.formspec_escape(screenfile or no_screenshot).."]"..
1057 "textarea[1.0,3.25;3.7,1.5;;"..engine.formspec_escape(infotext or "")..";]"
1060 --------------------------------------------------------------------------------
1061 function tabbuilder.tab_credits()
1062 local logofile = menu.defaulttexturedir .. "logo.png"
1063 return "vertlabel[0,-0.5;CREDITS]" ..
1064 "label[0.5,3;Minetest " .. engine.get_version() .. "]" ..
1065 "label[0.5,3.3;http://minetest.net]" ..
1066 "image[0.5,1;" .. engine.formspec_escape(logofile) .. "]" ..
1067 "textlist[3.5,-0.25;8.5,5.8;list_credits;" ..
1068 "#FFFF00" .. fgettext("Core Developers") .."," ..
1069 "Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
1070 "Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,"..
1071 "PilzAdam <pilzadam@minetest.net>," ..
1072 "Ilya Zhuravlev (xyz) <xyz@minetest.net>,"..
1073 "Lisa Milne (darkrose) <lisa@ltmnet.com>,"..
1074 "Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,"..
1075 "proller <proler@gmail.com>,"..
1076 "sfan5 <sfan5@live.de>,"..
1077 "kahrl <kahrl@gmx.net>,"..
1079 "ShadowNinja <shadowninja@minetest.net>,"..
1080 "Nathanael Courant (Nore/Novatux) <nore@mesecons.net>,"..
1083 "#FFFF00" .. fgettext("Active Contributors") .. "," ..
1084 "Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,"..
1085 "Jurgen Doser (doserj) <jurgen.doser@gmail.com>,"..
1086 "Jeija <jeija@mesecons.net>,"..
1087 "MirceaKitsune <mirceakitsune@gmail.com>,"..
1088 "dannydark <the_skeleton_of_a_child@yahoo.co.uk>,"..
1089 "0gb.us <0gb.us@0gb.us>,"..
1091 "#FFFF00" .. fgettext("Previous Contributors") .. "," ..
1092 "Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,"..
1093 "Jonathan Neuschafer <j.neuschaefer@gmx.net>,"..
1094 "Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,"..
1095 "Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,"..
1096 "matttpt <matttpt@gmail.com>,"..
1097 "JacobF <queatz@gmail.com>,"..
1101 --------------------------------------------------------------------------------
1102 function tabbuilder.init()
1103 tabbuilder.tabfuncs = {
1104 singleplayer = tabbuilder.tab_singleplayer,
1105 multiplayer = tabbuilder.tab_multiplayer,
1106 server = tabbuilder.tab_server,
1107 settings = tabbuilder.tab_settings,
1108 texture_packs = tabbuilder.tab_texture_packs,
1109 credits = tabbuilder.tab_credits,
1110 dialog_create_world = tabbuilder.dialog_create_world,
1111 dialog_delete_world = tabbuilder.dialog_delete_world
1114 tabbuilder.tabsizes = {
1115 dialog_create_world = {width=12, height=7},
1116 dialog_delete_world = {width=12, height=5.2}
1119 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1121 if tabbuilder.current_tab == nil or
1122 tabbuilder.current_tab == "" then
1123 tabbuilder.current_tab = "singleplayer"
1124 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
1127 --initialize tab buttons
1128 tabbuilder.last_tab = nil
1129 tabbuilder.show_buttons = true
1131 tabbuilder.current_buttons = {}
1132 table.insert(tabbuilder.current_buttons,{name="singleplayer", caption=fgettext("Singleplayer")})
1133 table.insert(tabbuilder.current_buttons,{name="multiplayer", caption=fgettext("Client")})
1134 table.insert(tabbuilder.current_buttons,{name="server", caption=fgettext("Server")})
1135 table.insert(tabbuilder.current_buttons,{name="settings", caption=fgettext("Settings")})
1136 table.insert(tabbuilder.current_buttons,{name="texture_packs", caption=fgettext("Texture Packs")})
1138 if engine.setting_getbool("main_menu_game_mgr") then
1139 table.insert(tabbuilder.current_buttons,{name="game_mgr", caption=fgettext("Games")})
1142 if engine.setting_getbool("main_menu_mod_mgr") then
1143 table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption=fgettext("Mods")})
1145 table.insert(tabbuilder.current_buttons,{name="credits", caption=fgettext("Credits")})
1148 for i=1,#tabbuilder.current_buttons,1 do
1149 if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then
1150 tabbuilder.last_tab_index = i
1154 if tabbuilder.current_tab ~= "singleplayer" then
1155 menu.update_gametype(true)
1157 menu.update_gametype()
1161 --------------------------------------------------------------------------------
1162 function tabbuilder.checkretval(retval)
1164 if retval ~= nil then
1165 if retval.current_tab ~= nil then
1166 tabbuilder.current_tab = retval.current_tab
1169 if retval.is_dialog ~= nil then
1170 tabbuilder.is_dialog = retval.is_dialog
1173 if retval.show_buttons ~= nil then
1174 tabbuilder.show_buttons = retval.show_buttons
1177 if retval.skipformupdate ~= nil then
1178 tabbuilder.skipformupdate = retval.skipformupdate
1181 if retval.ignore_menu_quit == true then
1182 tabbuilder.ignore_menu_quit = true
1184 tabbuilder.ignore_menu_quit = false
1189 --------------------------------------------------------------------------------
1190 --------------------------------------------------------------------------------
1191 -- initialize callbacks
1192 --------------------------------------------------------------------------------
1193 --------------------------------------------------------------------------------
1194 engine.button_handler = function(fields)
1195 --print("Buttonhandler: tab: " .. tabbuilder.current_tab .. " fields: " .. dump(fields))
1197 if fields["btn_error_confirm"] then
1198 gamedata.errormessage = nil
1201 local retval = modmgr.handle_buttons(tabbuilder.current_tab,fields)
1202 tabbuilder.checkretval(retval)
1204 retval = gamemgr.handle_buttons(tabbuilder.current_tab,fields)
1205 tabbuilder.checkretval(retval)
1207 retval = modstore.handle_buttons(tabbuilder.current_tab,fields)
1208 tabbuilder.checkretval(retval)
1210 if tabbuilder.current_tab == "dialog_create_world" then
1211 tabbuilder.handle_create_world_buttons(fields)
1214 if tabbuilder.current_tab == "dialog_delete_world" then
1215 tabbuilder.handle_delete_world_buttons(fields)
1218 if tabbuilder.current_tab == "singleplayer" then
1219 tabbuilder.handle_singleplayer_buttons(fields)
1222 if tabbuilder.current_tab == "texture_packs" then
1223 tabbuilder.handle_texture_pack_buttons(fields)
1226 if tabbuilder.current_tab == "multiplayer" then
1227 tabbuilder.handle_multiplayer_buttons(fields)
1230 if tabbuilder.current_tab == "settings" then
1231 tabbuilder.handle_settings_buttons(fields)
1234 if tabbuilder.current_tab == "server" then
1235 tabbuilder.handle_server_buttons(fields)
1239 tabbuilder.handle_tab_buttons(fields)
1242 menubar.handle_buttons(fields)
1244 if not tabbuilder.skipformupdate then
1248 tabbuilder.skipformupdate = false
1252 --------------------------------------------------------------------------------
1253 engine.event_handler = function(event)
1254 if event == "MenuQuit" then
1255 if tabbuilder.is_dialog then
1256 if tabbuilder.ignore_menu_quit then
1260 tabbuilder.is_dialog = false
1261 tabbuilder.show_buttons = true
1262 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1263 menu.update_gametype()
1270 if event == "Refresh" then
1275 --------------------------------------------------------------------------------
1276 function menu.update_gametype(reset)
1277 local game = menu.lastgame()
1279 if reset or game == nil then
1281 engine.set_topleft_text("")
1282 filterlist.set_filtercriteria(worldlist,nil)
1284 mm_texture.update(tabbuilder.current_tab,game)
1285 engine.set_topleft_text(game.name)
1286 filterlist.set_filtercriteria(worldlist,game.id)
1290 --------------------------------------------------------------------------------
1291 --------------------------------------------------------------------------------
1293 --------------------------------------------------------------------------------
1294 --------------------------------------------------------------------------------
1302 engine.sound_play("main_menu", true)