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")
32 --------------------------------------------------------------------------------
33 local function filter_texture_pack_list(list)
35 for _,i in ipairs(list) do
37 table.insert(retval, i)
43 --------------------------------------------------------------------------------
44 function menu.render_favorite(spec,render_details)
47 if spec.name ~= nil then
48 text = text .. engine.formspec_escape(spec.name:trim())
50 -- if spec.description ~= nil and
51 -- engine.formspec_escape(spec.description):trim() ~= "" then
52 -- text = text .. " (" .. engine.formspec_escape(spec.description) .. ")"
55 if spec.address ~= nil then
56 text = text .. spec.address:trim()
58 if spec.port ~= nil then
59 text = text .. ":" .. spec.port
64 if not render_details then
69 if spec.password == true then
70 details = details .. "*"
72 details = details .. "_"
76 details = details .. "C"
78 details = details .. "_"
82 details = details .. "D"
84 details = details .. "_"
88 details = details .. "P"
90 details = details .. "_"
92 details = details .. " "
94 local playercount = ""
96 if spec.clients ~= nil and
97 spec.clients_max ~= nil then
98 playercount = string.format("%03d",spec.clients) .. "/" ..
99 string.format("%03d",spec.clients_max) .. " "
102 return playercount .. engine.formspec_escape(details) .. text
105 --------------------------------------------------------------------------------
106 os.tempfolder = function()
107 local filetocheck = os.tmpname()
108 os.remove(filetocheck)
110 local randname = "MTTempModFolder_" .. math.random(0,10000)
111 if DIR_DELIM == "\\" then
112 local tempfolder = os.getenv("TEMP")
113 return tempfolder .. filetocheck
115 local backstring = filetocheck:reverse()
116 return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname
121 --------------------------------------------------------------------------------
122 function init_globals()
124 gamedata.worldindex = 0
126 worldlist = filterlist.create(
129 function(element,uid)
130 if element.name == uid then
134 end, --unique id compare fct
135 function(element,gameid)
136 if element.gameid == gameid then
143 filterlist.add_sort_mechanism(worldlist,"alphabetic",sort_worlds_alphabetic)
144 filterlist.set_sortmode(worldlist,"alphabetic")
147 --------------------------------------------------------------------------------
148 function update_menu()
153 if gamedata.errormessage ~= nil then
154 formspec = "size[12,5.2]" ..
155 "field[1,2;10,2;;ERROR: " ..
156 gamedata.errormessage ..
158 "button[4.5,4.2;3,0.5;btn_error_confirm;" .. fgettext("Ok") .. "]"
160 formspec = tabbuilder.gettab()
163 engine.update_formspec(formspec)
166 --------------------------------------------------------------------------------
167 function menu.render_world_list()
170 local current_worldlist = filterlist.get_list(worldlist)
172 for i,v in ipairs(current_worldlist) do
174 retval = retval ..","
177 retval = retval .. engine.formspec_escape(v.name) ..
178 " \\[" .. engine.formspec_escape(v.gameid) .. "\\]"
184 --------------------------------------------------------------------------------
185 function menu.render_texture_pack_list(list)
188 for i,v in ipairs(list) do
190 retval = retval ..","
199 --------------------------------------------------------------------------------
202 gamemgr.update_gamelist()
204 menu.last_game = tonumber(engine.setting_get("main_menu_last_game_idx"))
206 if type(menu.last_game) ~= "number" then
210 if engine.setting_getbool("public_serverlist") then
211 menu.favorites = engine.get_favorites("online")
213 menu.favorites = engine.get_favorites("local")
216 menu.defaulttexturedir = engine.get_texturepath() .. DIR_DELIM .. "base" ..
217 DIR_DELIM .. "pack" .. DIR_DELIM
220 --------------------------------------------------------------------------------
221 function menu.lastgame()
222 if menu.last_game > 0 and menu.last_game <= #gamemgr.games then
223 return gamemgr.games[menu.last_game]
226 if #gamemgr.games >= 1 then
228 return gamemgr.games[menu.last_game]
235 --------------------------------------------------------------------------------
236 function menu.update_last_game()
238 local current_world = filterlist.get_raw_element(worldlist,
239 engine.setting_get("mainmenu_last_selected_world")
242 if current_world == nil then
246 local gamespec, i = gamemgr.find_by_gameid(current_world.gameid)
249 engine.setting_set("main_menu_last_game_idx",menu.last_game)
253 --------------------------------------------------------------------------------
254 function menu.handle_key_up_down(fields,textlist,settingname)
256 if fields["key_up"] then
257 local oldidx = engine.get_textlist_index(textlist)
260 local newidx = oldidx -1
261 engine.setting_set(settingname,
262 filterlist.get_raw_index(worldlist,newidx))
266 if fields["key_down"] then
267 local oldidx = engine.get_textlist_index(textlist)
269 if oldidx < filterlist.size(worldlist) then
270 local newidx = oldidx + 1
271 engine.setting_set(settingname,
272 filterlist.get_raw_index(worldlist,newidx))
277 --------------------------------------------------------------------------------
278 function tabbuilder.dialog_create_world()
279 local mapgens = {"v6", "v7", "indev", "singlenode", "math"}
281 local current_seed = engine.setting_get("fixed_map_seed") or ""
282 local current_mg = engine.setting_get("mg_name")
287 for k,v in pairs(mapgens) do
288 if current_mg == v then
292 mglist = mglist .. v .. ","
294 mglist = mglist:sub(1, -2)
297 "label[2,0;" .. fgettext("World name") .. "]"..
298 "field[4.5,0.4;6,0.5;te_world_name;;]" ..
300 "label[2,1;" .. fgettext("Seed") .. "]"..
301 "field[4.5,1.4;6,0.5;te_seed;;".. current_seed .. "]" ..
303 "label[2,2;" .. fgettext("Mapgen") .. "]"..
304 "dropdown[4.2,2;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
306 "label[2,3;" .. fgettext("Game") .. "]"..
307 "textlist[4.2,3;5.8,2.3;games;" .. gamemgr.gamelist() ..
308 ";" .. menu.last_game .. ";true]" ..
310 "button[5,5.5;2.6,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
311 "button[7.5,5.5;2.8,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
316 --------------------------------------------------------------------------------
317 function tabbuilder.dialog_delete_world()
318 return "label[2,2;" ..
319 fgettext("Delete World \"$1\"?", filterlist.get_raw_list(worldlist)[menu.world_to_del].name) .. "]"..
320 "button[3.5,4.2;2.6,0.5;world_delete_confirm;" .. fgettext("Yes").. "]" ..
321 "button[6,4.2;2.8,0.5;world_delete_cancel;" .. fgettext("No") .. "]"
324 --------------------------------------------------------------------------------
326 function tabbuilder.gettab()
327 local tsize = tabbuilder.tabsizes[tabbuilder.current_tab] or {width=12, height=5.2}
328 local retval = "size[" .. tsize.width .. "," .. tsize.height .. "]"
330 if tabbuilder.show_buttons then
331 retval = retval .. tabbuilder.tab_header()
334 local buildfunc = tabbuilder.tabfuncs[tabbuilder.current_tab]
335 if buildfunc ~= nil then
336 retval = retval .. buildfunc()
339 retval = retval .. modmgr.gettab(tabbuilder.current_tab)
340 retval = retval .. gamemgr.gettab(tabbuilder.current_tab)
341 retval = retval .. modstore.gettab(tabbuilder.current_tab)
346 --------------------------------------------------------------------------------
347 function tabbuilder.handle_create_world_buttons(fields)
349 if fields["world_create_confirm"] or
350 fields["key_enter"] then
352 local worldname = fields["te_world_name"]
353 local gameindex = engine.get_textlist_index("games")
360 if not filterlist.uid_exists_raw(worldlist,worldname) then
361 engine.setting_set("mg_name",fields["dd_mapgen"])
362 message = engine.create_world(worldname,gameindex)
364 message = fgettext("A world named \"$1\" already exists", worldname)
367 engine.setting_set("fixed_map_seed", fields["te_seed"])
369 if message ~= nil then
370 gamedata.errormessage = message
372 menu.last_game = gameindex
373 engine.setting_set("main_menu_last_game_idx",gameindex)
375 filterlist.refresh(worldlist)
376 engine.setting_set("mainmenu_last_selected_world",
377 filterlist.raw_index_by_uid(worldlist,worldname))
380 gamedata.errormessage =
381 fgettext("No worldname given or no game selected")
385 if fields["games"] then
386 tabbuilder.skipformupdate = true
391 tabbuilder.is_dialog = false
392 tabbuilder.show_buttons = true
393 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
396 --------------------------------------------------------------------------------
397 function tabbuilder.handle_delete_world_buttons(fields)
399 if fields["world_delete_confirm"] then
400 if menu.world_to_del > 0 and
401 menu.world_to_del <= #filterlist.get_raw_list(worldlist) then
402 engine.delete_world(menu.world_to_del)
403 menu.world_to_del = 0
404 filterlist.refresh(worldlist)
408 tabbuilder.is_dialog = false
409 tabbuilder.show_buttons = true
410 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
413 --------------------------------------------------------------------------------
414 function tabbuilder.handle_multiplayer_buttons(fields)
416 if fields["te_name"] ~= nil then
417 gamedata.playername = fields["te_name"]
418 engine.setting_set("name", fields["te_name"])
421 if fields["favourites"] ~= nil then
422 local event = explode_textlist_event(fields["favourites"])
423 if event.typ == "DCL" then
424 gamedata.address = menu.favorites[event.index].address
425 gamedata.port = menu.favorites[event.index].port
426 gamedata.playername = fields["te_name"]
427 if fields["te_pwd"] ~= nil then
428 gamedata.password = fields["te_pwd"]
430 gamedata.selected_world = 0
432 if menu.favorites ~= nil then
433 gamedata.servername = menu.favorites[event.index].name
434 gamedata.serverdescription = menu.favorites[event.index].description
437 if gamedata.address ~= nil and
438 gamedata.port ~= nil then
444 if event.typ == "CHG" then
445 local address = menu.favorites[event.index].address
446 local port = menu.favorites[event.index].port
448 if address ~= nil and
450 engine.setting_set("address",address)
451 engine.setting_set("port",port)
454 menu.fav_selected = event.index
459 if fields["key_up"] ~= nil or
460 fields["key_down"] ~= nil then
462 local fav_idx = engine.get_textlist_index("favourites")
464 if fields["key_up"] ~= nil and fav_idx > 1 then
466 else if fields["key_down"] and fav_idx < #menu.favorites then
470 local address = menu.favorites[fav_idx].address
471 local port = menu.favorites[fav_idx].port
473 if address ~= nil and
475 engine.setting_set("address",address)
476 engine.setting_set("port",port)
479 menu.fav_selected = fav_idx
483 if fields["cb_public_serverlist"] ~= nil then
484 engine.setting_set("public_serverlist", fields["cb_public_serverlist"])
486 if engine.setting_getbool("public_serverlist") then
487 menu.favorites = engine.get_favorites("online")
489 menu.favorites = engine.get_favorites("local")
491 menu.fav_selected = nil
495 if fields["btn_delete_favorite"] ~= nil then
496 local current_favourite = engine.get_textlist_index("favourites")
497 engine.delete_favorite(current_favourite)
498 menu.favorites = engine.get_favorites()
499 menu.fav_selected = nil
501 engine.setting_set("address","")
502 engine.setting_get("port","")
507 if fields["btn_mp_connect"] ~= nil or
508 fields["key_enter"] then
510 gamedata.playername = fields["te_name"]
511 gamedata.password = fields["te_pwd"]
512 gamedata.address = fields["te_address"]
513 gamedata.port = fields["te_port"]
515 local fav_idx = engine.get_textlist_index("favourites")
517 if fav_idx > 0 and fav_idx <= #menu.favorites and
518 menu.favorites[fav_idx].address == fields["te_address"] and
519 menu.favorites[fav_idx].port == fields["te_port"] then
521 gamedata.servername = menu.favorites[fav_idx].name
522 gamedata.serverdescription = menu.favorites[fav_idx].description
524 gamedata.servername = ""
525 gamedata.serverdescription = ""
528 gamedata.selected_world = 0
535 --------------------------------------------------------------------------------
536 function tabbuilder.handle_server_buttons(fields)
538 local world_doubleclick = false
540 if fields["srv_worlds"] ~= nil then
541 local event = explode_textlist_event(fields["srv_worlds"])
543 if event.typ == "DCL" then
544 world_doubleclick = true
546 if event.typ == "CHG" then
547 engine.setting_set("mainmenu_last_selected_world",
548 filterlist.get_raw_index(worldlist,engine.get_textlist_index("srv_worlds")))
552 menu.handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world")
554 if fields["cb_creative_mode"] then
555 engine.setting_set("creative_mode", fields["cb_creative_mode"])
558 if fields["cb_enable_damage"] then
559 engine.setting_set("enable_damage", fields["cb_enable_damage"])
562 if fields["cb_server_announce"] then
563 engine.setting_set("server_announce", fields["cb_server_announce"])
566 if fields["start_server"] ~= nil or
568 fields["key_enter"] then
569 local selected = engine.get_textlist_index("srv_worlds")
571 gamedata.playername = fields["te_playername"]
572 gamedata.password = fields["te_passwd"]
573 gamedata.port = fields["te_serverport"]
574 gamedata.address = ""
575 gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
577 menu.update_last_game(gamedata.selected_world)
582 if fields["world_create"] ~= nil then
583 tabbuilder.current_tab = "dialog_create_world"
584 tabbuilder.is_dialog = true
585 tabbuilder.show_buttons = false
588 if fields["world_delete"] ~= nil then
589 local selected = engine.get_textlist_index("srv_worlds")
591 selected <= filterlist.size(worldlist) then
592 local world = filterlist.get_list(worldlist)[selected]
594 world.name ~= nil and
595 world.name ~= "" then
596 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
597 tabbuilder.current_tab = "dialog_delete_world"
598 tabbuilder.is_dialog = true
599 tabbuilder.show_buttons = false
601 menu.world_to_del = 0
606 if fields["world_configure"] ~= nil then
607 selected = engine.get_textlist_index("srv_worlds")
609 modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
610 if modmgr.init_worldconfig() then
611 tabbuilder.current_tab = "dialog_configure_world"
612 tabbuilder.is_dialog = true
613 tabbuilder.show_buttons = false
619 --------------------------------------------------------------------------------
620 function tabbuilder.handle_settings_buttons(fields)
621 if fields["cb_fancy_trees"] then
622 engine.setting_set("new_style_leaves", fields["cb_fancy_trees"])
624 if fields["cb_smooth_lighting"] then
625 engine.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
627 if fields["cb_3d_clouds"] then
628 engine.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
630 if fields["cb_opaque_water"] then
631 engine.setting_set("opaque_water", fields["cb_opaque_water"])
634 if fields["cb_mipmapping"] then
635 engine.setting_set("mip_map", fields["cb_mipmapping"])
637 if fields["cb_anisotrophic"] then
638 engine.setting_set("anisotropic_filter", fields["cb_anisotrophic"])
640 if fields["cb_bilinear"] then
641 engine.setting_set("bilinear_filter", fields["cb_bilinear"])
643 if fields["cb_trilinear"] then
644 engine.setting_set("trilinear_filter", fields["cb_trilinear"])
647 if fields["cb_shaders"] then
648 engine.setting_set("enable_shaders", fields["cb_shaders"])
650 if fields["cb_pre_ivis"] then
651 engine.setting_set("preload_item_visuals", fields["cb_pre_ivis"])
653 if fields["cb_particles"] then
654 engine.setting_set("enable_particles", fields["cb_particles"])
656 if fields["cb_finite_liquid"] then
657 engine.setting_set("liquid_finite", fields["cb_finite_liquid"])
660 if fields["btn_change_keys"] ~= nil then
661 engine.show_keys_menu()
665 --------------------------------------------------------------------------------
666 function tabbuilder.handle_singleplayer_buttons(fields)
668 local world_doubleclick = false
670 if fields["sp_worlds"] ~= nil then
671 local event = explode_textlist_event(fields["sp_worlds"])
673 if event.typ == "DCL" then
674 world_doubleclick = true
677 if event.typ == "CHG" then
678 engine.setting_set("mainmenu_last_selected_world",
679 filterlist.get_raw_index(worldlist,engine.get_textlist_index("sp_worlds")))
683 menu.handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world")
685 if fields["cb_creative_mode"] then
686 engine.setting_set("creative_mode", fields["cb_creative_mode"])
689 if fields["cb_enable_damage"] then
690 engine.setting_set("enable_damage", fields["cb_enable_damage"])
693 if fields["play"] ~= nil or
695 fields["key_enter"] then
696 local selected = engine.get_textlist_index("sp_worlds")
698 gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
699 gamedata.singleplayer = true
701 menu.update_last_game(gamedata.selected_world)
707 if fields["world_create"] ~= nil then
708 tabbuilder.current_tab = "dialog_create_world"
709 tabbuilder.is_dialog = true
710 tabbuilder.show_buttons = false
713 if fields["world_delete"] ~= nil then
714 local selected = engine.get_textlist_index("sp_worlds")
716 selected <= filterlist.size(worldlist) then
717 local world = filterlist.get_list(worldlist)[selected]
719 world.name ~= nil and
720 world.name ~= "" then
721 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
722 tabbuilder.current_tab = "dialog_delete_world"
723 tabbuilder.is_dialog = true
724 tabbuilder.show_buttons = false
726 menu.world_to_del = 0
731 if fields["world_configure"] ~= nil then
732 selected = engine.get_textlist_index("sp_worlds")
734 modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
735 if modmgr.init_worldconfig() then
736 tabbuilder.current_tab = "dialog_configure_world"
737 tabbuilder.is_dialog = true
738 tabbuilder.show_buttons = false
744 --------------------------------------------------------------------------------
745 function tabbuilder.handle_texture_pack_buttons(fields)
746 if fields["TPs"] ~= nil then
747 local event = explode_textlist_event(fields["TPs"])
748 if event.typ == "CHG" or event.typ=="DCL" then
749 local index = engine.get_textlist_index("TPs")
750 engine.setting_set("mainmenu_last_selected_TP",
752 local list = filter_texture_pack_list(engine.get_dirlist(engine.get_texturepath(), true))
753 local current_index = engine.get_textlist_index("TPs")
754 if #list >= current_index then
755 local new_path = engine.get_texturepath()..DIR_DELIM..list[current_index]
756 if list[current_index] == "None" then new_path = "" end
758 engine.setting_set("texture_path", new_path)
764 --------------------------------------------------------------------------------
765 function tabbuilder.tab_header()
767 if tabbuilder.last_tab_index == nil then
768 tabbuilder.last_tab_index = 1
773 for i=1,#tabbuilder.current_buttons,1 do
779 toadd = toadd .. tabbuilder.current_buttons[i].caption
781 return "tabheader[-0.3,-0.99;main_tab;" .. toadd ..";" .. tabbuilder.last_tab_index .. ";true;false]"
784 --------------------------------------------------------------------------------
785 function tabbuilder.handle_tab_buttons(fields)
787 if fields["main_tab"] then
788 local index = tonumber(fields["main_tab"])
789 tabbuilder.last_tab_index = index
790 tabbuilder.current_tab = tabbuilder.current_buttons[index].name
792 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
796 if tabbuilder.current_tab ~= tabbuilder.old_tab then
797 if tabbuilder.current_tab ~= "singleplayer" and not tabbuilder.is_dialog then
798 menu.update_gametype(true)
802 if tabbuilder.current_tab == "singleplayer" then
803 menu.update_gametype()
806 tabbuilder.old_tab = tabbuilder.current_tab
809 --------------------------------------------------------------------------------
810 function tabbuilder.tab_multiplayer()
813 "vertlabel[0,-0.25;".. fgettext("CLIENT") .. "]" ..
814 "label[1,-0.25;".. fgettext("Favorites:") .. "]"..
815 "label[1,4.25;".. fgettext("Address/Port") .. "]"..
816 "label[9,2.75;".. fgettext("Name/Password") .. "]" ..
817 "field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" ..
818 "field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("port") .."]" ..
819 "checkbox[1,3.6;cb_public_serverlist;".. fgettext("Public Serverlist") .. ";" ..
820 dump(engine.setting_getbool("public_serverlist")) .. "]"
822 if not engine.setting_getbool("public_serverlist") then
824 "button[6.45,3.95;2.25,0.5;btn_delete_favorite;".. fgettext("Delete") .. "]"
828 "button[9,4.95;2.5,0.5;btn_mp_connect;".. fgettext("Connect") .. "]" ..
829 "field[9.3,3.75;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" ..
830 "pwdfield[9.3,4.5;2.5,0.5;te_pwd;]" ..
831 "textarea[9.3,0.25;2.5,2.75;;"
832 if menu.fav_selected ~= nil and
833 menu.favorites[menu.fav_selected].description ~= nil then
835 engine.formspec_escape(menu.favorites[menu.fav_selected].description,true)
840 "textlist[1,0.35;7.5,3.35;favourites;"
842 local render_details = engine.setting_getbool("public_serverlist")
844 if #menu.favorites > 0 then
845 retval = retval .. menu.render_favorite(menu.favorites[1],render_details)
847 for i=2,#menu.favorites,1 do
848 retval = retval .. "," .. menu.render_favorite(menu.favorites[i],render_details)
852 if menu.fav_selected ~= nil then
853 retval = retval .. ";" .. menu.fav_selected .. "]"
855 retval = retval .. ";0]"
861 --------------------------------------------------------------------------------
862 function tabbuilder.tab_server()
864 local index = filterlist.get_current_index(worldlist,
865 tonumber(engine.setting_get("mainmenu_last_selected_world"))
869 "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" ..
870 "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" ..
871 "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" ..
872 "button[8.5,4.9;3.25,0.5;start_server;".. fgettext("Start Game") .. "]" ..
873 "label[4,-0.25;".. fgettext("Select World:") .. "]"..
874 "vertlabel[0,-0.25;".. fgettext("START SERVER") .. "]" ..
875 "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
876 dump(engine.setting_getbool("creative_mode")) .. "]"..
877 "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
878 dump(engine.setting_getbool("enable_damage")) .. "]"..
879 "checkbox[0.5,1.15;cb_server_announce;".. fgettext("Public") .. ";" ..
880 dump(engine.setting_getbool("server_announce")) .. "]"..
881 "field[0.8,3.2;3,0.5;te_playername;".. fgettext("Name") .. ";" ..
882 engine.setting_get("name") .. "]" ..
883 "pwdfield[0.8,4.2;3,0.5;te_passwd;".. fgettext("Password") .. "]" ..
884 "field[0.8,5.2;3,0.5;te_serverport;".. fgettext("Server Port") .. ";30000]" ..
885 "textlist[4,0.25;7.5,3.7;srv_worlds;" ..
886 menu.render_world_list() ..
892 --------------------------------------------------------------------------------
893 function tabbuilder.tab_settings()
894 return "vertlabel[0,0;" .. fgettext("SETTINGS") .. "]" ..
895 "checkbox[1,0.75;cb_fancy_trees;".. fgettext("Fancy trees") .. ";"
896 .. dump(engine.setting_getbool("new_style_leaves")) .. "]"..
897 "checkbox[1,1.25;cb_smooth_lighting;".. fgettext("Smooth Lighting")
898 .. ";".. dump(engine.setting_getbool("smooth_lighting")) .. "]"..
899 "checkbox[1,1.75;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
900 .. dump(engine.setting_getbool("enable_3d_clouds")) .. "]"..
901 "checkbox[1,2.25;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
902 .. dump(engine.setting_getbool("opaque_water")) .. "]"..
904 "checkbox[4,0.75;cb_mipmapping;".. fgettext("Mip-Mapping") .. ";"
905 .. dump(engine.setting_getbool("mip_map")) .. "]"..
906 "checkbox[4,1.25;cb_anisotrophic;".. fgettext("Anisotropic Filtering") .. ";"
907 .. dump(engine.setting_getbool("anisotropic_filter")) .. "]"..
908 "checkbox[4,1.75;cb_bilinear;".. fgettext("Bi-Linear Filtering") .. ";"
909 .. dump(engine.setting_getbool("bilinear_filter")) .. "]"..
910 "checkbox[4,2.25;cb_trilinear;".. fgettext("Tri-Linear Filtering") .. ";"
911 .. dump(engine.setting_getbool("trilinear_filter")) .. "]"..
913 "checkbox[7.5,0.75;cb_shaders;".. fgettext("Shaders") .. ";"
914 .. dump(engine.setting_getbool("enable_shaders")) .. "]"..
915 "checkbox[7.5,1.25;cb_pre_ivis;".. fgettext("Preload item visuals") .. ";"
916 .. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
917 "checkbox[7.5,1.75;cb_particles;".. fgettext("Enable Particles") .. ";"
918 .. dump(engine.setting_getbool("enable_particles")) .. "]"..
919 "checkbox[7.5,2.25;cb_finite_liquid;".. fgettext("Finite Liquid") .. ";"
920 .. dump(engine.setting_getbool("liquid_finite")) .. "]"..
922 "button[1,4.25;2.25,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
925 --------------------------------------------------------------------------------
926 function tabbuilder.tab_singleplayer()
928 local index = filterlist.get_current_index(worldlist,
929 tonumber(engine.setting_get("mainmenu_last_selected_world"))
932 return "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" ..
933 "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" ..
934 "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" ..
935 "button[8.5,4.95;3.25,0.5;play;".. fgettext("Play") .. "]" ..
936 "label[4,-0.25;".. fgettext("Select World:") .. "]"..
937 "vertlabel[0,-0.25;".. fgettext("SINGLE PLAYER") .. "]" ..
938 "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
939 dump(engine.setting_getbool("creative_mode")) .. "]"..
940 "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
941 dump(engine.setting_getbool("enable_damage")) .. "]"..
942 "textlist[4,0.25;7.5,3.7;sp_worlds;" ..
943 menu.render_world_list() ..
944 ";" .. index .. "]" ..
948 --------------------------------------------------------------------------------
949 function tabbuilder.tab_texture_packs()
950 local retval = "label[4,-0.25;".. fgettext("Select texture pack:") .. "]"..
951 "vertlabel[0,-0.25;".. fgettext("TEXTURE PACKS") .. "]" ..
952 "textlist[4,0.25;7.5,5.0;TPs;"
954 local current_texture_path = engine.setting_get("texture_path")
955 local list = filter_texture_pack_list(engine.get_dirlist(engine.get_texturepath(), true))
956 local index = tonumber(engine.setting_get("mainmenu_last_selected_TP"))
958 if index == nil then index = 1 end
960 if current_texture_path == "" then
962 menu.render_texture_pack_list(list) ..
967 local infofile = current_texture_path ..DIR_DELIM.."info.txt"
969 local f = io.open(infofile, "r")
971 infotext = fgettext("No information available")
973 infotext = f:read("*all")
977 local screenfile = current_texture_path..DIR_DELIM.."screenshot.png"
978 local no_screenshot = nil
979 if not file_exists(screenfile) then
981 no_screenshot = engine.get_texturepath()..DIR_DELIM..
982 "base"..DIR_DELIM.."pack"..DIR_DELIM.."no_screenshot.png"
986 menu.render_texture_pack_list(list) ..
987 ";" .. index .. "]" ..
988 "image[0.65,0.25;4.0,3.7;"..engine.formspec_escape(screenfile or no_screenshot).."]"..
989 "textarea[1.0,3.25;3.7,1.5;;"..engine.formspec_escape(infotext or "")..";]"
992 --------------------------------------------------------------------------------
993 function tabbuilder.tab_credits()
994 local logofile = menu.defaulttexturedir .. "logo.png"
995 return "vertlabel[0,-0.5;CREDITS]" ..
996 "label[0.5,3;Minetest " .. engine.get_version() .. "]" ..
997 "label[0.5,3.3;http://minetest.net]" ..
998 "image[0.5,1;" .. engine.formspec_escape(logofile) .. "]" ..
999 "textlist[3.5,-0.25;8.5,5.8;list_credits;" ..
1000 "#FFFF00" .. fgettext("Core Developers") .."," ..
1001 "Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
1002 "Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,"..
1003 "PilzAdam <pilzadam@minetest.net>," ..
1004 "Ilya Zhuravlev (xyz) <xyz@minetest.net>,"..
1005 "Lisa Milne (darkrose) <lisa@ltmnet.com>,"..
1006 "Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,"..
1007 "proller <proler@gmail.com>,"..
1008 "sfan5 <sfan5@live.de>,"..
1009 "kahrl <kahrl@gmx.net>,"..
1011 "ShadowNinja <shadowninja@minetest.net>,"..
1012 "Nathanaël Courant (Nore/Novatux) <nore@mesecons.net>,"..
1015 "#FFFF00" .. fgettext("Active Contributors") .. "," ..
1016 "Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,"..
1017 "Jurgen Doser (doserj) <jurgen.doser@gmail.com>,"..
1018 "Jeija <jeija@mesecons.net>,"..
1019 "MirceaKitsune <mirceakitsune@gmail.com>,"..
1020 "dannydark <the_skeleton_of_a_child@yahoo.co.uk>,"..
1021 "0gb.us <0gb.us@0gb.us>,"..
1023 "#FFFF00" .. fgettext("Previous Contributors") .. "," ..
1024 "Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,"..
1025 "Jonathan Neuschafer <j.neuschaefer@gmx.net>,"..
1026 "Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,"..
1027 "Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,"..
1028 "matttpt <matttpt@gmail.com>,"..
1029 "JacobF <queatz@gmail.com>,"..
1033 --------------------------------------------------------------------------------
1034 function tabbuilder.init()
1035 tabbuilder.tabfuncs = {
1036 singleplayer = tabbuilder.tab_singleplayer,
1037 multiplayer = tabbuilder.tab_multiplayer,
1038 server = tabbuilder.tab_server,
1039 settings = tabbuilder.tab_settings,
1040 texture_packs = tabbuilder.tab_texture_packs,
1041 credits = tabbuilder.tab_credits,
1042 dialog_create_world = tabbuilder.dialog_create_world,
1043 dialog_delete_world = tabbuilder.dialog_delete_world
1046 tabbuilder.tabsizes = {
1047 dialog_create_world = {width=12, height=7},
1048 dialog_delete_world = {width=12, height=5.2}
1051 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1053 if tabbuilder.current_tab == nil or
1054 tabbuilder.current_tab == "" then
1055 tabbuilder.current_tab = "singleplayer"
1056 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
1059 --initialize tab buttons
1060 tabbuilder.last_tab = nil
1061 tabbuilder.show_buttons = true
1063 tabbuilder.current_buttons = {}
1064 table.insert(tabbuilder.current_buttons,{name="singleplayer", caption=fgettext("Singleplayer")})
1065 table.insert(tabbuilder.current_buttons,{name="multiplayer", caption=fgettext("Client")})
1066 table.insert(tabbuilder.current_buttons,{name="server", caption=fgettext("Server")})
1067 table.insert(tabbuilder.current_buttons,{name="settings", caption=fgettext("Settings")})
1068 table.insert(tabbuilder.current_buttons,{name="texture_packs", caption=fgettext("Texture Packs")})
1070 if engine.setting_getbool("main_menu_game_mgr") then
1071 table.insert(tabbuilder.current_buttons,{name="game_mgr", caption=fgettext("Games")})
1074 if engine.setting_getbool("main_menu_mod_mgr") then
1075 table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption=fgettext("Mods")})
1077 table.insert(tabbuilder.current_buttons,{name="credits", caption=fgettext("Credits")})
1080 for i=1,#tabbuilder.current_buttons,1 do
1081 if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then
1082 tabbuilder.last_tab_index = i
1086 if tabbuilder.current_tab ~= "singleplayer" then
1087 menu.update_gametype(true)
1089 menu.update_gametype()
1093 --------------------------------------------------------------------------------
1094 function tabbuilder.checkretval(retval)
1096 if retval ~= nil then
1097 if retval.current_tab ~= nil then
1098 tabbuilder.current_tab = retval.current_tab
1101 if retval.is_dialog ~= nil then
1102 tabbuilder.is_dialog = retval.is_dialog
1105 if retval.show_buttons ~= nil then
1106 tabbuilder.show_buttons = retval.show_buttons
1109 if retval.skipformupdate ~= nil then
1110 tabbuilder.skipformupdate = retval.skipformupdate
1115 --------------------------------------------------------------------------------
1116 --------------------------------------------------------------------------------
1117 -- initialize callbacks
1118 --------------------------------------------------------------------------------
1119 --------------------------------------------------------------------------------
1120 engine.button_handler = function(fields)
1121 --print("Buttonhandler: tab: " .. tabbuilder.current_tab .. " fields: " .. dump(fields))
1123 if fields["btn_error_confirm"] then
1124 gamedata.errormessage = nil
1127 local retval = modmgr.handle_buttons(tabbuilder.current_tab,fields)
1128 tabbuilder.checkretval(retval)
1130 retval = gamemgr.handle_buttons(tabbuilder.current_tab,fields)
1131 tabbuilder.checkretval(retval)
1133 retval = modstore.handle_buttons(tabbuilder.current_tab,fields)
1134 tabbuilder.checkretval(retval)
1136 if tabbuilder.current_tab == "dialog_create_world" then
1137 tabbuilder.handle_create_world_buttons(fields)
1140 if tabbuilder.current_tab == "dialog_delete_world" then
1141 tabbuilder.handle_delete_world_buttons(fields)
1144 if tabbuilder.current_tab == "singleplayer" then
1145 tabbuilder.handle_singleplayer_buttons(fields)
1148 if tabbuilder.current_tab == "texture_packs" then
1149 tabbuilder.handle_texture_pack_buttons(fields)
1152 if tabbuilder.current_tab == "multiplayer" then
1153 tabbuilder.handle_multiplayer_buttons(fields)
1156 if tabbuilder.current_tab == "settings" then
1157 tabbuilder.handle_settings_buttons(fields)
1160 if tabbuilder.current_tab == "server" then
1161 tabbuilder.handle_server_buttons(fields)
1165 tabbuilder.handle_tab_buttons(fields)
1168 menubar.handle_buttons(fields)
1170 if not tabbuilder.skipformupdate then
1174 tabbuilder.skipformupdate = false
1178 --------------------------------------------------------------------------------
1179 engine.event_handler = function(event)
1180 if event == "MenuQuit" then
1181 if tabbuilder.is_dialog then
1182 tabbuilder.is_dialog = false
1183 tabbuilder.show_buttons = true
1184 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1185 menu.update_gametype()
1193 --------------------------------------------------------------------------------
1194 function menu.update_gametype(reset)
1195 local game = menu.lastgame()
1197 if reset or game == nil then
1199 engine.set_topleft_text("")
1200 filterlist.set_filtercriteria(worldlist,nil)
1202 mm_texture.update(tabbuilder.current_tab,game)
1203 engine.set_topleft_text(game.name)
1204 filterlist.set_filtercriteria(worldlist,game.id)
1208 --------------------------------------------------------------------------------
1209 --------------------------------------------------------------------------------
1211 --------------------------------------------------------------------------------
1212 --------------------------------------------------------------------------------
1220 engine.sound_play("main_menu", true)