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 text2textlist(xpos,ypos,width,height,tl_name,textlen,text,transparency)
124 local textlines = engine.splittext(text,textlen)
126 local retval = "textlist[" .. xpos .. "," .. ypos .. ";"
127 .. width .. "," .. height .. ";"
130 for i=1, #textlines, 1 do
131 textlines[i] = textlines[i]:gsub("\r","")
132 retval = retval .. engine.formspec_escape(textlines[i]) .. ","
135 retval = retval .. ";0;"
138 retval = retval .. "true"
141 retval = retval .. "]"
146 --------------------------------------------------------------------------------
147 function init_globals()
149 gamedata.worldindex = 0
151 worldlist = filterlist.create(
154 function(element,uid)
155 if element.name == uid then
159 end, --unique id compare fct
160 function(element,gameid)
161 if element.gameid == gameid then
168 filterlist.add_sort_mechanism(worldlist,"alphabetic",sort_worlds_alphabetic)
169 filterlist.set_sortmode(worldlist,"alphabetic")
172 --------------------------------------------------------------------------------
173 function update_menu()
178 if gamedata.errormessage ~= nil then
179 formspec = "size[12,5.2,true]" ..
180 "textarea[1,2;10,2;;ERROR: " ..
181 engine.formspec_escape(gamedata.errormessage) ..
183 "button[4.5,4.2;3,0.5;btn_error_confirm;" .. fgettext("Ok") .. "]"
185 formspec = tabbuilder.gettab()
188 engine.update_formspec(formspec)
191 --------------------------------------------------------------------------------
192 function menu.render_world_list()
195 local current_worldlist = filterlist.get_list(worldlist)
197 for i,v in ipairs(current_worldlist) do
199 retval = retval ..","
202 retval = retval .. engine.formspec_escape(v.name) ..
203 " \\[" .. engine.formspec_escape(v.gameid) .. "\\]"
209 --------------------------------------------------------------------------------
210 function menu.render_texture_pack_list(list)
213 for i, v in ipairs(list) do
215 retval = retval ..","
218 retval = retval .. engine.formspec_escape(v)
224 --------------------------------------------------------------------------------
225 function menu.asyncOnlineFavourites()
229 return engine.get_favorites("online")
233 menu.favorites = result
234 engine.event_handler("Refresh")
239 --------------------------------------------------------------------------------
242 gamemgr.update_gamelist()
244 menu.last_game = tonumber(engine.setting_get("main_menu_last_game_idx"))
246 if type(menu.last_game) ~= "number" then
250 if engine.setting_getbool("public_serverlist") then
251 menu.asyncOnlineFavourites()
253 menu.favorites = engine.get_favorites("local")
256 menu.defaulttexturedir = engine.get_texturepath_share() .. DIR_DELIM .. "base" ..
257 DIR_DELIM .. "pack" .. DIR_DELIM
260 --------------------------------------------------------------------------------
261 function menu.lastgame()
262 if menu.last_game > 0 and menu.last_game <= #gamemgr.games then
263 return gamemgr.games[menu.last_game]
266 if #gamemgr.games >= 1 then
268 return gamemgr.games[menu.last_game]
275 --------------------------------------------------------------------------------
276 function menu.update_last_game()
278 local current_world = filterlist.get_raw_element(worldlist,
279 engine.setting_get("mainmenu_last_selected_world")
282 if current_world == nil then
286 local gamespec, i = gamemgr.find_by_gameid(current_world.gameid)
289 engine.setting_set("main_menu_last_game_idx",menu.last_game)
293 --------------------------------------------------------------------------------
294 function menu.handle_key_up_down(fields,textlist,settingname)
296 if fields["key_up"] then
297 local oldidx = engine.get_textlist_index(textlist)
299 if oldidx ~= nil and oldidx > 1 then
300 local newidx = oldidx -1
301 engine.setting_set(settingname,
302 filterlist.get_raw_index(worldlist,newidx))
306 if fields["key_down"] then
307 local oldidx = engine.get_textlist_index(textlist)
309 if oldidx ~= nil and oldidx < filterlist.size(worldlist) then
310 local newidx = oldidx + 1
311 engine.setting_set(settingname,
312 filterlist.get_raw_index(worldlist,newidx))
317 --------------------------------------------------------------------------------
318 function tabbuilder.dialog_create_world()
319 local mapgens = {"v6", "v7", "indev", "singlenode", "math"}
321 local current_seed = engine.setting_get("fixed_map_seed") or ""
322 local current_mg = engine.setting_get("mg_name")
327 for k,v in pairs(mapgens) do
328 if current_mg == v then
332 mglist = mglist .. v .. ","
334 mglist = mglist:sub(1, -2)
337 "label[2,0;" .. fgettext("World name") .. "]"..
338 "field[4.5,0.4;6,0.5;te_world_name;;]" ..
340 "label[2,1;" .. fgettext("Seed") .. "]"..
341 "field[4.5,1.4;6,0.5;te_seed;;".. current_seed .. "]" ..
343 "label[2,2;" .. fgettext("Mapgen") .. "]"..
344 "dropdown[4.2,2;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
346 "label[2,3;" .. fgettext("Game") .. "]"..
347 "textlist[4.2,3;5.8,2.3;games;" .. gamemgr.gamelist() ..
348 ";" .. menu.last_game .. ";true]" ..
350 "button[5,5.5;2.6,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
351 "button[7.5,5.5;2.8,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
356 --------------------------------------------------------------------------------
357 function tabbuilder.dialog_delete_world()
358 return "label[2,2;" ..
359 fgettext("Delete World \"$1\"?", filterlist.get_raw_list(worldlist)[menu.world_to_del].name) .. "]"..
360 "button[3.5,4.2;2.6,0.5;world_delete_confirm;" .. fgettext("Yes").. "]" ..
361 "button[6,4.2;2.8,0.5;world_delete_cancel;" .. fgettext("No") .. "]"
364 --------------------------------------------------------------------------------
366 function tabbuilder.gettab()
367 local tsize = tabbuilder.tabsizes[tabbuilder.current_tab] or {width=12, height=5.2}
368 local retval = "size[" .. tsize.width .. "," .. tsize.height .. ",true]"
370 if tabbuilder.show_buttons then
371 retval = retval .. tabbuilder.tab_header()
374 local buildfunc = tabbuilder.tabfuncs[tabbuilder.current_tab]
375 if buildfunc ~= nil then
376 retval = retval .. buildfunc()
379 retval = retval .. modmgr.gettab(tabbuilder.current_tab)
380 retval = retval .. gamemgr.gettab(tabbuilder.current_tab)
381 retval = retval .. modstore.gettab(tabbuilder.current_tab)
386 --------------------------------------------------------------------------------
387 function tabbuilder.handle_create_world_buttons(fields)
389 if fields["world_create_confirm"] or
390 fields["key_enter"] then
392 local worldname = fields["te_world_name"]
393 local gameindex = engine.get_textlist_index("games")
395 if gameindex ~= nil and
400 if not filterlist.uid_exists_raw(worldlist,worldname) then
401 engine.setting_set("mg_name",fields["dd_mapgen"])
402 message = engine.create_world(worldname,gameindex)
404 message = fgettext("A world named \"$1\" already exists", worldname)
407 engine.setting_set("fixed_map_seed", fields["te_seed"])
409 if message ~= nil then
410 gamedata.errormessage = message
412 menu.last_game = gameindex
413 engine.setting_set("main_menu_last_game_idx",gameindex)
415 filterlist.refresh(worldlist)
416 engine.setting_set("mainmenu_last_selected_world",
417 filterlist.raw_index_by_uid(worldlist,worldname))
420 gamedata.errormessage =
421 fgettext("No worldname given or no game selected")
425 if fields["games"] then
426 tabbuilder.skipformupdate = true
431 tabbuilder.is_dialog = false
432 tabbuilder.show_buttons = true
433 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
436 --------------------------------------------------------------------------------
437 function tabbuilder.handle_delete_world_buttons(fields)
439 if fields["world_delete_confirm"] then
440 if menu.world_to_del > 0 and
441 menu.world_to_del <= #filterlist.get_raw_list(worldlist) then
442 engine.delete_world(menu.world_to_del)
443 menu.world_to_del = 0
444 filterlist.refresh(worldlist)
448 tabbuilder.is_dialog = false
449 tabbuilder.show_buttons = true
450 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
453 --------------------------------------------------------------------------------
454 function tabbuilder.handle_multiplayer_buttons(fields)
456 if fields["te_name"] ~= nil then
457 gamedata.playername = fields["te_name"]
458 engine.setting_set("name", fields["te_name"])
461 if fields["favourites"] ~= nil then
462 local event = engine.explode_textlist_event(fields["favourites"])
463 if event.type == "DCL" then
464 if event.index <= #menu.favorites then
465 gamedata.address = menu.favorites[event.index].address
466 gamedata.port = menu.favorites[event.index].port
467 gamedata.playername = fields["te_name"]
468 if fields["te_pwd"] ~= nil then
469 gamedata.password = fields["te_pwd"]
471 gamedata.selected_world = 0
473 if menu.favorites ~= nil then
474 gamedata.servername = menu.favorites[event.index].name
475 gamedata.serverdescription = menu.favorites[event.index].description
478 if gamedata.address ~= nil and
479 gamedata.port ~= nil then
480 engine.setting_set("address",gamedata.address)
481 engine.setting_set("remote_port",gamedata.port)
487 if event.type == "CHG" then
488 if event.index <= #menu.favorites then
489 local address = menu.favorites[event.index].address
490 local port = menu.favorites[event.index].port
492 if address ~= nil and
494 engine.setting_set("address",address)
495 engine.setting_set("remote_port",port)
498 menu.fav_selected = event.index
504 if fields["key_up"] ~= nil or
505 fields["key_down"] ~= nil then
507 local fav_idx = engine.get_textlist_index("favourites")
509 if fav_idx ~= nil then
510 if fields["key_up"] ~= nil and fav_idx > 1 then
512 else if fields["key_down"] and fav_idx < #menu.favorites then
517 local address = menu.favorites[fav_idx].address
518 local port = menu.favorites[fav_idx].port
520 if address ~= nil and
522 engine.setting_set("address",address)
523 engine.setting_set("remote_port",port)
526 menu.fav_selected = fav_idx
530 if fields["cb_public_serverlist"] ~= nil then
531 engine.setting_set("public_serverlist", fields["cb_public_serverlist"])
533 if engine.setting_getbool("public_serverlist") then
534 menu.asyncOnlineFavourites()
536 menu.favorites = engine.get_favorites("local")
538 menu.fav_selected = nil
542 if fields["btn_delete_favorite"] ~= nil then
543 local current_favourite = engine.get_textlist_index("favourites")
544 if current_favourite == nil then return end
545 engine.delete_favorite(current_favourite)
546 menu.favorites = engine.get_favorites()
547 menu.fav_selected = nil
549 engine.setting_set("address","")
550 engine.setting_set("remote_port","30000")
555 if fields["btn_mp_connect"] ~= nil or
556 fields["key_enter"] ~= nil then
558 gamedata.playername = fields["te_name"]
559 gamedata.password = fields["te_pwd"]
560 gamedata.address = fields["te_address"]
561 gamedata.port = fields["te_port"]
563 local fav_idx = engine.get_textlist_index("favourites")
565 if fav_idx ~= nil and fav_idx <= #menu.favorites and
566 menu.favorites[fav_idx].address == fields["te_address"] and
567 menu.favorites[fav_idx].port == fields["te_port"] then
569 gamedata.servername = menu.favorites[fav_idx].name
570 gamedata.serverdescription = menu.favorites[fav_idx].description
572 gamedata.servername = ""
573 gamedata.serverdescription = ""
576 gamedata.selected_world = 0
578 engine.setting_set("address",fields["te_address"])
579 engine.setting_set("remote_port",fields["te_port"])
586 --------------------------------------------------------------------------------
587 function tabbuilder.handle_server_buttons(fields)
589 local world_doubleclick = false
591 if fields["srv_worlds"] ~= nil then
592 local event = engine.explode_textlist_event(fields["srv_worlds"])
594 if event.type == "DCL" then
595 world_doubleclick = true
597 if event.type == "CHG" then
598 engine.setting_set("mainmenu_last_selected_world",
599 filterlist.get_raw_index(worldlist,engine.get_textlist_index("srv_worlds")))
603 menu.handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world")
605 if fields["cb_creative_mode"] then
606 engine.setting_set("creative_mode", fields["cb_creative_mode"])
609 if fields["cb_enable_damage"] then
610 engine.setting_set("enable_damage", fields["cb_enable_damage"])
613 if fields["cb_server_announce"] then
614 engine.setting_set("server_announce", fields["cb_server_announce"])
617 if fields["start_server"] ~= nil or
619 fields["key_enter"] then
620 local selected = engine.get_textlist_index("srv_worlds")
621 if selected ~= nil then
622 gamedata.playername = fields["te_playername"]
623 gamedata.password = fields["te_passwd"]
624 gamedata.port = fields["te_serverport"]
625 gamedata.address = ""
626 gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
628 engine.setting_set("port",gamedata.port)
629 if fields["te_serveraddr"] ~= nil then
630 engine.setting_set("bind_address",fields["te_serveraddr"])
633 menu.update_last_game(gamedata.selected_world)
638 if fields["world_create"] ~= nil then
639 tabbuilder.current_tab = "dialog_create_world"
640 tabbuilder.is_dialog = true
641 tabbuilder.show_buttons = false
644 if fields["world_delete"] ~= nil then
645 local selected = engine.get_textlist_index("srv_worlds")
646 if selected ~= nil and
647 selected <= filterlist.size(worldlist) then
648 local world = filterlist.get_list(worldlist)[selected]
650 world.name ~= nil and
651 world.name ~= "" then
652 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
653 tabbuilder.current_tab = "dialog_delete_world"
654 tabbuilder.is_dialog = true
655 tabbuilder.show_buttons = false
657 menu.world_to_del = 0
662 if fields["world_configure"] ~= nil then
663 selected = engine.get_textlist_index("srv_worlds")
664 if selected ~= nil then
665 modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
666 if modmgr.init_worldconfig() then
667 tabbuilder.current_tab = "dialog_configure_world"
668 tabbuilder.is_dialog = true
669 tabbuilder.show_buttons = false
675 --------------------------------------------------------------------------------
676 function tabbuilder.handle_settings_buttons(fields)
677 if fields["cb_fancy_trees"] then
678 engine.setting_set("new_style_leaves", fields["cb_fancy_trees"])
680 if fields["cb_smooth_lighting"] then
681 engine.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
683 if fields["cb_3d_clouds"] then
684 engine.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
686 if fields["cb_opaque_water"] then
687 engine.setting_set("opaque_water", fields["cb_opaque_water"])
690 if fields["cb_mipmapping"] then
691 engine.setting_set("mip_map", fields["cb_mipmapping"])
693 if fields["cb_anisotrophic"] then
694 engine.setting_set("anisotropic_filter", fields["cb_anisotrophic"])
696 if fields["cb_bilinear"] then
697 engine.setting_set("bilinear_filter", fields["cb_bilinear"])
699 if fields["cb_trilinear"] then
700 engine.setting_set("trilinear_filter", fields["cb_trilinear"])
703 if fields["cb_shaders"] then
704 if (engine.setting_get("video_driver") == "direct3d8" or engine.setting_get("video_driver") == "direct3d9") then
705 engine.setting_set("enable_shaders", "false")
706 gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
708 engine.setting_set("enable_shaders", fields["cb_shaders"])
711 if fields["cb_pre_ivis"] then
712 engine.setting_set("preload_item_visuals", fields["cb_pre_ivis"])
714 if fields["cb_particles"] then
715 engine.setting_set("enable_particles", fields["cb_particles"])
717 if fields["cb_finite_liquid"] then
718 engine.setting_set("liquid_finite", fields["cb_finite_liquid"])
720 if fields["cb_bumpmapping"] then
721 engine.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
723 if fields["cb_parallax"] then
724 engine.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
726 if fields["cb_waving_water"] then
727 engine.setting_set("enable_waving_water", fields["cb_waving_water"])
729 if fields["cb_waving_leaves"] then
730 engine.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
732 if fields["cb_waving_plants"] then
733 engine.setting_set("enable_waving_plants", fields["cb_waving_plants"])
735 if fields["btn_change_keys"] ~= nil then
736 engine.show_keys_menu()
740 --------------------------------------------------------------------------------
741 function tabbuilder.handle_singleplayer_buttons(fields)
743 local world_doubleclick = false
745 if fields["sp_worlds"] ~= nil then
746 local event = engine.explode_textlist_event(fields["sp_worlds"])
748 if event.type == "DCL" then
749 world_doubleclick = true
752 if event.type == "CHG" then
753 engine.setting_set("mainmenu_last_selected_world",
754 filterlist.get_raw_index(worldlist,engine.get_textlist_index("sp_worlds")))
758 menu.handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world")
760 if fields["cb_creative_mode"] then
761 engine.setting_set("creative_mode", fields["cb_creative_mode"])
764 if fields["cb_enable_damage"] then
765 engine.setting_set("enable_damage", fields["cb_enable_damage"])
768 if fields["play"] ~= nil or
770 fields["key_enter"] then
771 local selected = engine.get_textlist_index("sp_worlds")
772 if selected ~= nil then
773 gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
774 gamedata.singleplayer = true
776 menu.update_last_game(gamedata.selected_world)
782 if fields["world_create"] ~= nil then
783 tabbuilder.current_tab = "dialog_create_world"
784 tabbuilder.is_dialog = true
785 tabbuilder.show_buttons = false
788 if fields["world_delete"] ~= nil then
789 local selected = engine.get_textlist_index("sp_worlds")
790 if selected ~= nil and
791 selected <= filterlist.size(worldlist) then
792 local world = filterlist.get_list(worldlist)[selected]
794 world.name ~= nil and
795 world.name ~= "" then
796 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
797 tabbuilder.current_tab = "dialog_delete_world"
798 tabbuilder.is_dialog = true
799 tabbuilder.show_buttons = false
801 menu.world_to_del = 0
806 if fields["world_configure"] ~= nil then
807 selected = engine.get_textlist_index("sp_worlds")
808 if selected ~= nil then
809 modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
810 if modmgr.init_worldconfig() then
811 tabbuilder.current_tab = "dialog_configure_world"
812 tabbuilder.is_dialog = true
813 tabbuilder.show_buttons = false
819 --------------------------------------------------------------------------------
820 function tabbuilder.handle_texture_pack_buttons(fields)
821 if fields["TPs"] ~= nil then
822 local event = engine.explode_textlist_event(fields["TPs"])
823 if event.type == "CHG" or event.type == "DCL" then
824 local index = engine.get_textlist_index("TPs")
825 engine.setting_set("mainmenu_last_selected_TP",
827 local list = filter_texture_pack_list(engine.get_dirlist(engine.get_texturepath(), true))
828 local current_index = engine.get_textlist_index("TPs")
829 if current_index ~= nil and #list >= current_index then
830 local new_path = engine.get_texturepath()..DIR_DELIM..list[current_index]
831 if list[current_index] == "None" then new_path = "" end
833 engine.setting_set("texture_path", new_path)
839 --------------------------------------------------------------------------------
840 function tabbuilder.tab_header()
842 if tabbuilder.last_tab_index == nil then
843 tabbuilder.last_tab_index = 1
848 for i=1,#tabbuilder.current_buttons,1 do
854 toadd = toadd .. tabbuilder.current_buttons[i].caption
856 return "tabheader[-0.3,-0.99;main_tab;" .. toadd ..";" .. tabbuilder.last_tab_index .. ";true;false]"
859 --------------------------------------------------------------------------------
860 function tabbuilder.handle_tab_buttons(fields)
862 if fields["main_tab"] then
863 local index = tonumber(fields["main_tab"])
864 tabbuilder.last_tab_index = index
865 tabbuilder.current_tab = tabbuilder.current_buttons[index].name
867 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
871 if tabbuilder.current_tab ~= tabbuilder.old_tab then
872 if tabbuilder.current_tab ~= "singleplayer" and not tabbuilder.is_dialog then
873 menu.update_gametype(true)
877 if tabbuilder.current_tab == "singleplayer" then
878 menu.update_gametype()
881 tabbuilder.old_tab = tabbuilder.current_tab
884 --------------------------------------------------------------------------------
885 function tabbuilder.tab_multiplayer()
888 "vertlabel[0,-0.25;".. fgettext("CLIENT") .. "]" ..
889 "label[1,-0.25;".. fgettext("Favorites:") .. "]"..
890 "label[1,4.25;".. fgettext("Address/Port") .. "]"..
891 "label[9,2.75;".. fgettext("Name/Password") .. "]" ..
892 "field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" ..
893 "field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("remote_port") .."]" ..
894 "checkbox[1,3.6;cb_public_serverlist;".. fgettext("Public Serverlist") .. ";" ..
895 dump(engine.setting_getbool("public_serverlist")) .. "]"
897 if not engine.setting_getbool("public_serverlist") then
899 "button[6.45,3.95;2.25,0.5;btn_delete_favorite;".. fgettext("Delete") .. "]"
903 "button[9,4.95;2.5,0.5;btn_mp_connect;".. fgettext("Connect") .. "]" ..
904 "field[9.3,3.75;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" ..
905 "pwdfield[9.3,4.5;2.5,0.5;te_pwd;]" ..
906 "textarea[9.3,0.25;2.5,2.75;;"
907 if menu.fav_selected ~= nil and
908 menu.favorites[menu.fav_selected].description ~= nil then
910 engine.formspec_escape(menu.favorites[menu.fav_selected].description,true)
915 "textlist[1,0.35;7.5,3.35;favourites;"
917 local render_details = engine.setting_getbool("public_serverlist")
919 if #menu.favorites > 0 then
920 retval = retval .. menu.render_favorite(menu.favorites[1],render_details)
922 for i=2,#menu.favorites,1 do
923 retval = retval .. "," .. menu.render_favorite(menu.favorites[i],render_details)
927 if menu.fav_selected ~= nil then
928 retval = retval .. ";" .. menu.fav_selected .. "]"
930 retval = retval .. ";0]"
936 --------------------------------------------------------------------------------
937 function tabbuilder.tab_server()
939 local index = filterlist.get_current_index(worldlist,
940 tonumber(engine.setting_get("mainmenu_last_selected_world"))
944 "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" ..
945 "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" ..
946 "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" ..
947 "button[8.5,4.9;3.25,0.5;start_server;".. fgettext("Start Game") .. "]" ..
948 "label[4,-0.25;".. fgettext("Select World:") .. "]"..
949 "vertlabel[0,-0.25;".. fgettext("START SERVER") .. "]" ..
950 "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
951 dump(engine.setting_getbool("creative_mode")) .. "]"..
952 "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
953 dump(engine.setting_getbool("enable_damage")) .. "]"..
954 "checkbox[0.5,1.15;cb_server_announce;".. fgettext("Public") .. ";" ..
955 dump(engine.setting_getbool("server_announce")) .. "]"..
956 "field[0.8,3.2;3.5,0.5;te_playername;".. fgettext("Name") .. ";" ..
957 engine.setting_get("name") .. "]" ..
958 "pwdfield[0.8,4.2;3.5,0.5;te_passwd;".. fgettext("Password") .. "]"
960 local bind_addr = engine.setting_get("bind_address")
961 if bind_addr ~= nil and bind_addr ~= "" then
963 "field[0.8,5.2;2.25,0.5;te_serveraddr;".. fgettext("Bind Address") .. ";" ..
964 engine.setting_get("bind_address") .."]" ..
965 "field[3.05,5.2;1.25,0.5;te_serverport;".. fgettext("Port") .. ";" ..
966 engine.setting_get("port") .."]"
969 "field[0.8,5.2;3.5,0.5;te_serverport;".. fgettext("Server Port") .. ";" ..
970 engine.setting_get("port") .."]"
974 "textlist[4,0.25;7.5,3.7;srv_worlds;" ..
975 menu.render_world_list() ..
981 --------------------------------------------------------------------------------
982 function tabbuilder.tab_settings()
984 "vertlabel[0,0;" .. fgettext("SETTINGS") .. "]" ..
985 "checkbox[1,0;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";"
986 .. dump(engine.setting_getbool("new_style_leaves")) .. "]"..
987 "checkbox[1,0.5;cb_smooth_lighting;".. fgettext("Smooth Lighting")
988 .. ";".. dump(engine.setting_getbool("smooth_lighting")) .. "]"..
989 "checkbox[1,1;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
990 .. dump(engine.setting_getbool("enable_3d_clouds")) .. "]"..
991 "checkbox[1,1.5;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
992 .. dump(engine.setting_getbool("opaque_water")) .. "]"..
993 "checkbox[1,2.0;cb_pre_ivis;".. fgettext("Preload item visuals") .. ";"
994 .. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
995 "checkbox[1,2.5;cb_particles;".. fgettext("Enable Particles") .. ";"
996 .. dump(engine.setting_getbool("enable_particles")) .. "]"..
997 "checkbox[1,3.0;cb_finite_liquid;".. fgettext("Finite Liquid") .. ";"
998 .. dump(engine.setting_getbool("liquid_finite")) .. "]"..
1000 "checkbox[4.5,0;cb_mipmapping;".. fgettext("Mip-Mapping") .. ";"
1001 .. dump(engine.setting_getbool("mip_map")) .. "]"..
1002 "checkbox[4.5,0.5;cb_anisotrophic;".. fgettext("Anisotropic Filtering") .. ";"
1003 .. dump(engine.setting_getbool("anisotropic_filter")) .. "]"..
1004 "checkbox[4.5,1.0;cb_bilinear;".. fgettext("Bi-Linear Filtering") .. ";"
1005 .. dump(engine.setting_getbool("bilinear_filter")) .. "]"..
1006 "checkbox[4.5,1.5;cb_trilinear;".. fgettext("Tri-Linear Filtering") .. ";"
1007 .. dump(engine.setting_getbool("trilinear_filter")) .. "]"..
1009 "checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";"
1010 .. dump(engine.setting_getbool("enable_shaders")) .. "]"..
1011 "button[1,4.5;2.25,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
1013 if engine.setting_getbool("enable_shaders") then
1014 tab_string = tab_string ..
1015 "checkbox[8,0.5;cb_bumpmapping;".. fgettext("Bumpmapping") .. ";"
1016 .. dump(engine.setting_getbool("enable_bumpmapping")) .. "]"..
1017 "checkbox[8,1.0;cb_parallax;".. fgettext("Parallax Occlusion") .. ";"
1018 .. dump(engine.setting_getbool("enable_parallax_occlusion")) .. "]"..
1019 "checkbox[8,1.5;cb_waving_water;".. fgettext("Waving Water") .. ";"
1020 .. dump(engine.setting_getbool("enable_waving_water")) .. "]"..
1021 "checkbox[8,2.0;cb_waving_leaves;".. fgettext("Waving Leaves") .. ";"
1022 .. dump(engine.setting_getbool("enable_waving_leaves")) .. "]"..
1023 "checkbox[8,2.5;cb_waving_plants;".. fgettext("Waving Plants") .. ";"
1024 .. dump(engine.setting_getbool("enable_waving_plants")) .. "]"
1026 tab_string = tab_string ..
1027 "textlist[8.33,0.7;4,1;;#888888" .. fgettext("Bumpmapping") .. ";0;true]" ..
1028 "textlist[8.33,1.2;4,1;;#888888" .. fgettext("Parallax Occlusion") .. ";0;true]" ..
1029 "textlist[8.33,1.7;4,1;;#888888" .. fgettext("Waving Water") .. ";0;true]" ..
1030 "textlist[8.33,2.2;4,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" ..
1031 "textlist[8.33,2.7;4,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]"
1036 --------------------------------------------------------------------------------
1037 function tabbuilder.tab_singleplayer()
1039 local index = filterlist.get_current_index(worldlist,
1040 tonumber(engine.setting_get("mainmenu_last_selected_world"))
1043 return "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" ..
1044 "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" ..
1045 "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" ..
1046 "button[8.5,4.95;3.25,0.5;play;".. fgettext("Play") .. "]" ..
1047 "label[4,-0.25;".. fgettext("Select World:") .. "]"..
1048 "vertlabel[0,-0.25;".. fgettext("SINGLE PLAYER") .. "]" ..
1049 "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
1050 dump(engine.setting_getbool("creative_mode")) .. "]"..
1051 "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
1052 dump(engine.setting_getbool("enable_damage")) .. "]"..
1053 "textlist[4,0.25;7.5,3.7;sp_worlds;" ..
1054 menu.render_world_list() ..
1055 ";" .. index .. "]" ..
1059 --------------------------------------------------------------------------------
1060 function tabbuilder.tab_texture_packs()
1061 local retval = "label[4,-0.25;".. fgettext("Select texture pack:") .. "]"..
1062 "vertlabel[0,-0.25;".. fgettext("TEXTURE PACKS") .. "]" ..
1063 "textlist[4,0.25;7.5,5.0;TPs;"
1065 local current_texture_path = engine.setting_get("texture_path")
1066 local list = filter_texture_pack_list(engine.get_dirlist(engine.get_texturepath(), true))
1067 local index = tonumber(engine.setting_get("mainmenu_last_selected_TP"))
1069 if index == nil then index = 1 end
1071 if current_texture_path == "" then
1073 menu.render_texture_pack_list(list) ..
1078 local infofile = current_texture_path ..DIR_DELIM.."info.txt"
1080 local f = io.open(infofile, "r")
1082 infotext = fgettext("No information available")
1084 infotext = f:read("*all")
1088 local screenfile = current_texture_path..DIR_DELIM.."screenshot.png"
1089 local no_screenshot = nil
1090 if not file_exists(screenfile) then
1092 no_screenshot = menu.defaulttexturedir .. "no_screenshot.png"
1096 menu.render_texture_pack_list(list) ..
1097 ";" .. index .. "]" ..
1098 "image[0.65,0.25;4.0,3.7;"..engine.formspec_escape(screenfile or no_screenshot).."]"..
1099 "textarea[1.0,3.25;3.7,1.5;;"..engine.formspec_escape(infotext or "")..";]"
1102 --------------------------------------------------------------------------------
1103 function tabbuilder.tab_credits()
1104 local logofile = menu.defaulttexturedir .. "logo.png"
1105 return "vertlabel[0,-0.5;CREDITS]" ..
1106 "label[0.5,3;Minetest " .. engine.get_version() .. "]" ..
1107 "label[0.5,3.3;http://minetest.net]" ..
1108 "image[0.5,1;" .. engine.formspec_escape(logofile) .. "]" ..
1109 "textlist[3.5,-0.25;8.5,5.8;list_credits;" ..
1110 "#FFFF00" .. fgettext("Core Developers") .."," ..
1111 "Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
1112 "Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,"..
1113 "PilzAdam <pilzadam@minetest.net>," ..
1114 "Ilya Zhuravlev (xyz) <xyz@minetest.net>,"..
1115 "Lisa Milne (darkrose) <lisa@ltmnet.com>,"..
1116 "Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,"..
1117 "proller <proler@gmail.com>,"..
1118 "sfan5 <sfan5@live.de>,"..
1119 "kahrl <kahrl@gmx.net>,"..
1121 "ShadowNinja <shadowninja@minetest.net>,"..
1122 "Nathanael Courant (Nore/Novatux) <nore@mesecons.net>,"..
1125 "#FFFF00" .. fgettext("Active Contributors") .. "," ..
1126 "Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,"..
1127 "Jurgen Doser (doserj) <jurgen.doser@gmail.com>,"..
1128 "Jeija <jeija@mesecons.net>,"..
1129 "MirceaKitsune <mirceakitsune@gmail.com>,"..
1130 "dannydark <the_skeleton_of_a_child@yahoo.co.uk>,"..
1131 "0gb.us <0gb.us@0gb.us>,"..
1133 "#FFFF00" .. fgettext("Previous Contributors") .. "," ..
1134 "Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,"..
1135 "Jonathan Neuschafer <j.neuschaefer@gmx.net>,"..
1136 "Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,"..
1137 "Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,"..
1138 "matttpt <matttpt@gmail.com>,"..
1139 "JacobF <queatz@gmail.com>,"..
1143 --------------------------------------------------------------------------------
1144 function tabbuilder.init()
1145 tabbuilder.tabfuncs = {
1146 singleplayer = tabbuilder.tab_singleplayer,
1147 multiplayer = tabbuilder.tab_multiplayer,
1148 server = tabbuilder.tab_server,
1149 settings = tabbuilder.tab_settings,
1150 texture_packs = tabbuilder.tab_texture_packs,
1151 credits = tabbuilder.tab_credits,
1152 dialog_create_world = tabbuilder.dialog_create_world,
1153 dialog_delete_world = tabbuilder.dialog_delete_world
1156 tabbuilder.tabsizes = {
1157 dialog_create_world = {width=12, height=7},
1158 dialog_delete_world = {width=12, height=5.2}
1161 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1163 if tabbuilder.current_tab == nil or
1164 tabbuilder.current_tab == "" then
1165 tabbuilder.current_tab = "singleplayer"
1166 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
1169 --initialize tab buttons
1170 tabbuilder.last_tab = nil
1171 tabbuilder.show_buttons = true
1173 tabbuilder.current_buttons = {}
1174 table.insert(tabbuilder.current_buttons,{name="singleplayer", caption=fgettext("Singleplayer")})
1175 table.insert(tabbuilder.current_buttons,{name="multiplayer", caption=fgettext("Client")})
1176 table.insert(tabbuilder.current_buttons,{name="server", caption=fgettext("Server")})
1177 table.insert(tabbuilder.current_buttons,{name="settings", caption=fgettext("Settings")})
1178 table.insert(tabbuilder.current_buttons,{name="texture_packs", caption=fgettext("Texture Packs")})
1180 if engine.setting_getbool("main_menu_game_mgr") then
1181 table.insert(tabbuilder.current_buttons,{name="game_mgr", caption=fgettext("Games")})
1184 if engine.setting_getbool("main_menu_mod_mgr") then
1185 table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption=fgettext("Mods")})
1187 table.insert(tabbuilder.current_buttons,{name="credits", caption=fgettext("Credits")})
1190 for i=1,#tabbuilder.current_buttons,1 do
1191 if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then
1192 tabbuilder.last_tab_index = i
1196 if tabbuilder.current_tab ~= "singleplayer" then
1197 menu.update_gametype(true)
1199 menu.update_gametype()
1203 --------------------------------------------------------------------------------
1204 function tabbuilder.checkretval(retval)
1206 if retval ~= nil then
1207 if retval.current_tab ~= nil then
1208 tabbuilder.current_tab = retval.current_tab
1211 if retval.is_dialog ~= nil then
1212 tabbuilder.is_dialog = retval.is_dialog
1215 if retval.show_buttons ~= nil then
1216 tabbuilder.show_buttons = retval.show_buttons
1219 if retval.skipformupdate ~= nil then
1220 tabbuilder.skipformupdate = retval.skipformupdate
1223 if retval.ignore_menu_quit == true then
1224 tabbuilder.ignore_menu_quit = true
1226 tabbuilder.ignore_menu_quit = false
1231 --------------------------------------------------------------------------------
1232 --------------------------------------------------------------------------------
1233 -- initialize callbacks
1234 --------------------------------------------------------------------------------
1235 --------------------------------------------------------------------------------
1236 engine.button_handler = function(fields)
1237 --print("Buttonhandler: tab: " .. tabbuilder.current_tab .. " fields: " .. dump(fields))
1239 if fields["btn_error_confirm"] then
1240 gamedata.errormessage = nil
1243 local retval = modmgr.handle_buttons(tabbuilder.current_tab,fields)
1244 tabbuilder.checkretval(retval)
1246 retval = gamemgr.handle_buttons(tabbuilder.current_tab,fields)
1247 tabbuilder.checkretval(retval)
1249 retval = modstore.handle_buttons(tabbuilder.current_tab,fields)
1250 tabbuilder.checkretval(retval)
1252 if tabbuilder.current_tab == "dialog_create_world" then
1253 tabbuilder.handle_create_world_buttons(fields)
1256 if tabbuilder.current_tab == "dialog_delete_world" then
1257 tabbuilder.handle_delete_world_buttons(fields)
1260 if tabbuilder.current_tab == "singleplayer" then
1261 tabbuilder.handle_singleplayer_buttons(fields)
1264 if tabbuilder.current_tab == "texture_packs" then
1265 tabbuilder.handle_texture_pack_buttons(fields)
1268 if tabbuilder.current_tab == "multiplayer" then
1269 tabbuilder.handle_multiplayer_buttons(fields)
1272 if tabbuilder.current_tab == "settings" then
1273 tabbuilder.handle_settings_buttons(fields)
1276 if tabbuilder.current_tab == "server" then
1277 tabbuilder.handle_server_buttons(fields)
1281 tabbuilder.handle_tab_buttons(fields)
1284 menubar.handle_buttons(fields)
1286 if not tabbuilder.skipformupdate then
1290 tabbuilder.skipformupdate = false
1294 --------------------------------------------------------------------------------
1295 engine.event_handler = function(event)
1296 if event == "MenuQuit" then
1297 if tabbuilder.is_dialog then
1298 if tabbuilder.ignore_menu_quit then
1302 tabbuilder.is_dialog = false
1303 tabbuilder.show_buttons = true
1304 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1305 menu.update_gametype()
1312 if event == "Refresh" then
1317 --------------------------------------------------------------------------------
1318 function menu.update_gametype(reset)
1319 local game = menu.lastgame()
1321 if reset or game == nil then
1323 engine.set_topleft_text("")
1324 filterlist.set_filtercriteria(worldlist,nil)
1326 mm_texture.update(tabbuilder.current_tab,game)
1327 engine.set_topleft_text(game.name)
1328 filterlist.set_filtercriteria(worldlist,game.id)
1332 --------------------------------------------------------------------------------
1333 --------------------------------------------------------------------------------
1335 --------------------------------------------------------------------------------
1336 --------------------------------------------------------------------------------
1344 engine.sound_play("main_menu", true)