]> git.lizzy.rs Git - minetest.git/blob - builtin/mainmenu/init.lua
Organize builtin into subdirectories
[minetest.git] / builtin / mainmenu / init.lua
1
2 local menupath = engine.get_mainmenu_path()..DIR_DELIM
3 local commonpath = engine.get_builtin_path()..DIR_DELIM.."common"..DIR_DELIM
4
5 dofile(menupath.."filterlist.lua")
6 dofile(menupath.."modmgr.lua")
7 dofile(menupath.."modstore.lua")
8 dofile(menupath.."gamemgr.lua")
9 dofile(menupath.."textures.lua")
10 dofile(menupath.."menubar.lua")
11 dofile(commonpath.."async_event.lua")
12
13 mt_color_grey  = "#AAAAAA"
14 mt_color_blue  = "#0000DD"
15 mt_color_green = "#00DD00"
16 mt_color_dark_green = "#003300"
17
18 --for all other colors ask sfan5 to complete his worK!
19
20 menu = {}
21 local tabbuilder = {}
22 local worldlist = nil
23
24 --------------------------------------------------------------------------------
25 local function filter_texture_pack_list(list)
26         retval = {"None"}
27         for _,i in ipairs(list) do
28                 if i~="base" then
29                         table.insert(retval, i)
30                 end
31         end
32         return retval
33 end
34
35 --------------------------------------------------------------------------------
36 function menu.render_favorite(spec,render_details)
37         local text = ""
38
39         if spec.name ~= nil then
40                 text = text .. engine.formspec_escape(spec.name:trim())
41
42 --              if spec.description ~= nil and
43 --                      engine.formspec_escape(spec.description):trim() ~= "" then
44 --                      text = text .. " (" .. engine.formspec_escape(spec.description) .. ")"
45 --              end
46         else
47                 if spec.address ~= nil then
48                         text = text .. spec.address:trim()
49
50                         if spec.port ~= nil then
51                                 text = text .. ":" .. spec.port
52                         end
53                 end
54         end
55
56         if not render_details then
57                 return text
58         end
59
60         local details = ""
61         if spec.password == true then
62                 details = details .. "*"
63         else
64                 details = details .. "_"
65         end
66
67         if spec.creative then
68                 details = details .. "C"
69         else
70                 details = details .. "_"
71         end
72
73         if spec.damage then
74                 details = details .. "D"
75         else
76                 details = details .. "_"
77         end
78
79         if spec.pvp then
80                 details = details .. "P"
81         else
82                 details = details .. "_"
83         end
84         details = details .. " "
85
86         local playercount = ""
87
88         if spec.clients ~= nil and
89                 spec.clients_max ~= nil then
90                 playercount = string.format("%03d",spec.clients) .. "/" ..
91                                                 string.format("%03d",spec.clients_max) .. " "
92         end
93
94         return playercount .. engine.formspec_escape(details) ..  text
95 end
96
97 --------------------------------------------------------------------------------
98 os.tempfolder = function()
99         local filetocheck = os.tmpname()
100         os.remove(filetocheck)
101
102         local randname = "MTTempModFolder_" .. math.random(0,10000)
103         if DIR_DELIM == "\\" then
104                 local tempfolder = os.getenv("TEMP")
105                 return tempfolder .. filetocheck
106         else
107                 local backstring = filetocheck:reverse()
108                 return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname
109         end
110
111 end
112
113 --------------------------------------------------------------------------------
114 function text2textlist(xpos,ypos,width,height,tl_name,textlen,text,transparency)
115         local textlines = engine.splittext(text,textlen)
116         
117         local retval = "textlist[" .. xpos .. "," .. ypos .. ";"
118                                                                 .. width .. "," .. height .. ";"
119                                                                 .. tl_name .. ";"
120         
121         for i=1, #textlines, 1 do
122                 textlines[i] = textlines[i]:gsub("\r","")
123                 retval = retval .. engine.formspec_escape(textlines[i]) .. ","
124         end
125         
126         retval = retval .. ";0;"
127         
128         if transparency then
129                 retval = retval .. "true"
130         end
131         
132         retval = retval .. "]"
133
134         return retval
135 end
136
137 --------------------------------------------------------------------------------
138 function init_globals()
139         --init gamedata
140         gamedata.worldindex = 0
141
142         worldlist = filterlist.create(
143                                         engine.get_worlds,
144                                         compare_worlds,
145                                         function(element,uid)
146                                                 if element.name == uid then
147                                                         return true
148                                                 end
149                                                 return false
150                                         end, --unique id compare fct
151                                         function(element,gameid)
152                                                 if element.gameid == gameid then
153                                                         return true
154                                                 end
155                                                 return false
156                                         end --filter fct
157                                         )
158
159         filterlist.add_sort_mechanism(worldlist,"alphabetic",sort_worlds_alphabetic)
160         filterlist.set_sortmode(worldlist,"alphabetic")
161 end
162
163 --------------------------------------------------------------------------------
164 function update_menu()
165
166         local formspec
167
168         -- handle errors
169         if gamedata.errormessage ~= nil then
170                 formspec = "size[12,5.2,true]" ..
171                         "textarea[1,2;10,2;;ERROR: " ..
172                         engine.formspec_escape(gamedata.errormessage) ..
173                         ";]"..
174                         "button[4.5,4.2;3,0.5;btn_error_confirm;" .. fgettext("Ok") .. "]"
175         else
176                 formspec = tabbuilder.gettab()
177         end
178
179         engine.update_formspec(formspec)
180 end
181
182 --------------------------------------------------------------------------------
183 function menu.render_world_list()
184         local retval = ""
185
186         local current_worldlist = filterlist.get_list(worldlist)
187
188         for i,v in ipairs(current_worldlist) do
189                 if retval ~= "" then
190                         retval = retval ..","
191                 end
192
193                 retval = retval .. engine.formspec_escape(v.name) ..
194                                         " \\[" .. engine.formspec_escape(v.gameid) .. "\\]"
195         end
196
197         return retval
198 end
199
200 --------------------------------------------------------------------------------
201 function menu.render_texture_pack_list(list)
202         local retval = ""
203
204         for i, v in ipairs(list) do
205                 if retval ~= "" then
206                         retval = retval ..","
207                 end
208
209                 retval = retval .. engine.formspec_escape(v)
210         end
211
212         return retval
213 end
214
215 --------------------------------------------------------------------------------
216 function menu.asyncOnlineFavourites()
217         menu.favorites = {}
218         engine.handle_async(
219                 function(param)
220                         return engine.get_favorites("online")
221                 end,
222                 nil,
223                 function(result)
224                         menu.favorites = result
225                         engine.event_handler("Refresh")
226                 end
227                 )
228 end
229
230 --------------------------------------------------------------------------------
231 function menu.init()
232         --init menu data
233         gamemgr.update_gamelist()
234
235         menu.last_game  = tonumber(engine.setting_get("main_menu_last_game_idx"))
236
237         if type(menu.last_game) ~= "number" then
238                 menu.last_game = 1
239         end
240
241         if engine.setting_getbool("public_serverlist") then
242                 menu.asyncOnlineFavourites()
243         else
244                 menu.favorites = engine.get_favorites("local")
245         end
246
247         menu.defaulttexturedir = engine.get_texturepath_share() .. DIR_DELIM .. "base" ..
248                                         DIR_DELIM .. "pack" .. DIR_DELIM
249 end
250
251 --------------------------------------------------------------------------------
252 function menu.lastgame()
253         if menu.last_game > 0 and menu.last_game <= #gamemgr.games then
254                 return gamemgr.games[menu.last_game]
255         end
256
257         if #gamemgr.games >= 1 then
258                 menu.last_game = 1
259                 return gamemgr.games[menu.last_game]
260         end
261
262         --error case!!
263         return nil
264 end
265
266 --------------------------------------------------------------------------------
267 function menu.update_last_game()
268
269         local current_world = filterlist.get_raw_element(worldlist,
270                                                         engine.setting_get("mainmenu_last_selected_world")
271                                                         )
272
273         if current_world == nil then
274                 return
275         end
276
277         local gamespec, i = gamemgr.find_by_gameid(current_world.gameid)
278         if i ~= nil then
279                 menu.last_game = i
280                 engine.setting_set("main_menu_last_game_idx",menu.last_game)
281         end
282 end
283
284 --------------------------------------------------------------------------------
285 function menu.handle_key_up_down(fields,textlist,settingname)
286
287         if fields["key_up"] then
288                 local oldidx = engine.get_textlist_index(textlist)
289
290                 if oldidx ~= nil and oldidx > 1 then
291                         local newidx = oldidx -1
292                         engine.setting_set(settingname,
293                                 filterlist.get_raw_index(worldlist,newidx))
294                 end
295         end
296
297         if fields["key_down"] then
298                 local oldidx = engine.get_textlist_index(textlist)
299
300                 if oldidx ~= nil and oldidx < filterlist.size(worldlist) then
301                         local newidx = oldidx + 1
302                         engine.setting_set(settingname,
303                                 filterlist.get_raw_index(worldlist,newidx))
304                 end
305         end
306 end
307
308 --------------------------------------------------------------------------------
309 function tabbuilder.dialog_create_world()
310         local mapgens = {"v6", "v7", "indev", "singlenode", "math"}
311
312         local current_seed = engine.setting_get("fixed_map_seed") or ""
313         local current_mg   = engine.setting_get("mg_name")
314
315         local mglist = ""
316         local selindex = 1
317         local i = 1
318         for k,v in pairs(mapgens) do
319                 if current_mg == v then
320                         selindex = i
321                 end
322                 i = i + 1
323                 mglist = mglist .. v .. ","
324         end
325         mglist = mglist:sub(1, -2)
326
327         local retval =
328                 "label[2,0;" .. fgettext("World name") .. "]"..
329                 "field[4.5,0.4;6,0.5;te_world_name;;]" ..
330
331                 "label[2,1;" .. fgettext("Seed") .. "]"..
332                 "field[4.5,1.4;6,0.5;te_seed;;".. current_seed .. "]" ..
333
334                 "label[2,2;" .. fgettext("Mapgen") .. "]"..
335                 "dropdown[4.2,2;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
336
337                 "label[2,3;" .. fgettext("Game") .. "]"..
338                 "textlist[4.2,3;5.8,2.3;games;" .. gamemgr.gamelist() ..
339                 ";" .. menu.last_game .. ";true]" ..
340
341                 "button[5,5.5;2.6,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
342                 "button[7.5,5.5;2.8,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
343
344         return retval
345 end
346
347 --------------------------------------------------------------------------------
348 function tabbuilder.dialog_delete_world()
349         return  "label[2,2;" ..
350                         fgettext("Delete World \"$1\"?", filterlist.get_raw_list(worldlist)[menu.world_to_del].name) .. "]"..
351                         "button[3.5,4.2;2.6,0.5;world_delete_confirm;" .. fgettext("Yes").. "]" ..
352                         "button[6,4.2;2.8,0.5;world_delete_cancel;" .. fgettext("No") .. "]"
353 end
354
355 --------------------------------------------------------------------------------
356
357 function tabbuilder.gettab()
358         local tsize = tabbuilder.tabsizes[tabbuilder.current_tab] or {width=12, height=5.2}
359         local retval = "size[" .. tsize.width .. "," .. tsize.height .. ",true]"
360
361         if tabbuilder.show_buttons then
362                 retval = retval .. tabbuilder.tab_header()
363         end
364
365         local buildfunc = tabbuilder.tabfuncs[tabbuilder.current_tab]
366         if buildfunc ~= nil then
367                 retval = retval .. buildfunc()
368         end
369
370         retval = retval .. modmgr.gettab(tabbuilder.current_tab)
371         retval = retval .. gamemgr.gettab(tabbuilder.current_tab)
372         retval = retval .. modstore.gettab(tabbuilder.current_tab)
373
374         return retval
375 end
376
377 --------------------------------------------------------------------------------
378 function tabbuilder.handle_create_world_buttons(fields)
379
380         if fields["world_create_confirm"] or
381                 fields["key_enter"] then
382
383                 local worldname = fields["te_world_name"]
384                 local gameindex = engine.get_textlist_index("games")
385
386                 if gameindex ~= nil and
387                         worldname ~= "" then
388
389                         local message = nil
390
391                         if not filterlist.uid_exists_raw(worldlist,worldname) then
392                                 engine.setting_set("mg_name",fields["dd_mapgen"])
393                                 message = engine.create_world(worldname,gameindex)
394                         else
395                                 message = fgettext("A world named \"$1\" already exists", worldname)
396                         end
397
398                         engine.setting_set("fixed_map_seed", fields["te_seed"])
399
400                         if message ~= nil then
401                                 gamedata.errormessage = message
402                         else
403                                 menu.last_game = gameindex
404                                 engine.setting_set("main_menu_last_game_idx",gameindex)
405
406                                 filterlist.refresh(worldlist)
407                                 engine.setting_set("mainmenu_last_selected_world",
408                                                                         filterlist.raw_index_by_uid(worldlist,worldname))
409                         end
410                 else
411                         gamedata.errormessage =
412                                 fgettext("No worldname given or no game selected")
413                 end
414         end
415
416         if fields["games"] then
417                 tabbuilder.skipformupdate = true
418                 return
419         end
420
421         --close dialog
422         tabbuilder.is_dialog = false
423         tabbuilder.show_buttons = true
424         tabbuilder.current_tab = engine.setting_get("main_menu_tab")
425 end
426
427 --------------------------------------------------------------------------------
428 function tabbuilder.handle_delete_world_buttons(fields)
429
430         if fields["world_delete_confirm"] then
431                 if menu.world_to_del > 0 and
432                         menu.world_to_del <= #filterlist.get_raw_list(worldlist) then
433                         engine.delete_world(menu.world_to_del)
434                         menu.world_to_del = 0
435                         filterlist.refresh(worldlist)
436                 end
437         end
438
439         tabbuilder.is_dialog = false
440         tabbuilder.show_buttons = true
441         tabbuilder.current_tab = engine.setting_get("main_menu_tab")
442 end
443
444 --------------------------------------------------------------------------------
445 function tabbuilder.handle_multiplayer_buttons(fields)
446
447         if fields["te_name"] ~= nil then
448                 gamedata.playername = fields["te_name"]
449                 engine.setting_set("name", fields["te_name"])
450         end
451
452         if fields["favourites"] ~= nil then
453                 local event = engine.explode_textlist_event(fields["favourites"])
454                 if event.type == "DCL" then
455                         if event.index <= #menu.favorites then
456                                 gamedata.address = menu.favorites[event.index].address
457                                 gamedata.port = menu.favorites[event.index].port
458                                 gamedata.playername             = fields["te_name"]
459                                 if fields["te_pwd"] ~= nil then
460                                         gamedata.password               = fields["te_pwd"]
461                                 end
462                                 gamedata.selected_world = 0
463
464                                 if menu.favorites ~= nil then
465                                         gamedata.servername = menu.favorites[event.index].name
466                                         gamedata.serverdescription = menu.favorites[event.index].description
467                                 end
468
469                                 if gamedata.address ~= nil and
470                                         gamedata.port ~= nil then
471                                         engine.setting_set("address",gamedata.address)
472                                         engine.setting_set("remote_port",gamedata.port)
473                                         engine.start()
474                                 end
475                         end
476                 end
477
478                 if event.type == "CHG" then
479                         if event.index <= #menu.favorites then
480                                 local address = menu.favorites[event.index].address
481                                 local port = menu.favorites[event.index].port
482
483                                 if address ~= nil and
484                                         port ~= nil then
485                                         engine.setting_set("address",address)
486                                         engine.setting_set("remote_port",port)
487                                 end
488
489                                 menu.fav_selected = event.index
490                         end
491                 end
492                 return
493         end
494
495         if fields["key_up"] ~= nil or
496                 fields["key_down"] ~= nil then
497
498                 local fav_idx = engine.get_textlist_index("favourites")
499
500                 if fav_idx ~= nil then
501                         if fields["key_up"] ~= nil and fav_idx > 1 then
502                                 fav_idx = fav_idx -1
503                         else if fields["key_down"] and fav_idx < #menu.favorites then
504                                 fav_idx = fav_idx +1
505                         end end
506                 end
507
508                 local address = menu.favorites[fav_idx].address
509                 local port = menu.favorites[fav_idx].port
510
511                 if address ~= nil and
512                         port ~= nil then
513                         engine.setting_set("address",address)
514                         engine.setting_set("remote_port",port)
515                 end
516
517                 menu.fav_selected = fav_idx
518                 return
519         end
520
521         if fields["cb_public_serverlist"] ~= nil then
522                 engine.setting_set("public_serverlist", fields["cb_public_serverlist"])
523
524                 if engine.setting_getbool("public_serverlist") then
525                         menu.asyncOnlineFavourites()
526                 else
527                         menu.favorites = engine.get_favorites("local")
528                 end
529                 menu.fav_selected = nil
530                 return
531         end
532
533         if fields["btn_delete_favorite"] ~= nil then
534                 local current_favourite = engine.get_textlist_index("favourites")
535                 if current_favourite == nil then return end
536                 engine.delete_favorite(current_favourite)
537                 menu.favorites = engine.get_favorites()
538                 menu.fav_selected = nil
539
540                 engine.setting_set("address","")
541                 engine.setting_set("remote_port","30000")
542
543                 return
544         end
545
546         if fields["btn_mp_connect"] ~= nil or
547                 fields["key_enter"] ~= nil then
548
549                 gamedata.playername             = fields["te_name"]
550                 gamedata.password               = fields["te_pwd"]
551                 gamedata.address                = fields["te_address"]
552                 gamedata.port                   = fields["te_port"]
553
554                 local fav_idx = engine.get_textlist_index("favourites")
555
556                 if fav_idx ~= nil and fav_idx <= #menu.favorites and
557                         menu.favorites[fav_idx].address == fields["te_address"] and
558                         menu.favorites[fav_idx].port    == fields["te_port"] then
559
560                         gamedata.servername                     = menu.favorites[fav_idx].name
561                         gamedata.serverdescription      = menu.favorites[fav_idx].description
562                 else
563                         gamedata.servername                     = ""
564                         gamedata.serverdescription      = ""
565                 end
566
567                 gamedata.selected_world = 0
568
569                 engine.setting_set("address",fields["te_address"])
570                 engine.setting_set("remote_port",fields["te_port"])
571
572                 engine.start()
573                 return
574         end
575 end
576
577 --------------------------------------------------------------------------------
578 function tabbuilder.handle_server_buttons(fields)
579
580         local world_doubleclick = false
581
582         if fields["srv_worlds"] ~= nil then
583                 local event = engine.explode_textlist_event(fields["srv_worlds"])
584
585                 if event.type == "DCL" then
586                         world_doubleclick = true
587                 end
588                 if event.type == "CHG" then
589                         engine.setting_set("mainmenu_last_selected_world",
590                                 filterlist.get_raw_index(worldlist,engine.get_textlist_index("srv_worlds")))
591                 end
592         end
593
594         menu.handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world")
595
596         if fields["cb_creative_mode"] then
597                 engine.setting_set("creative_mode", fields["cb_creative_mode"])
598         end
599
600         if fields["cb_enable_damage"] then
601                 engine.setting_set("enable_damage", fields["cb_enable_damage"])
602         end
603
604         if fields["cb_server_announce"] then
605                 engine.setting_set("server_announce", fields["cb_server_announce"])
606         end
607
608         if fields["start_server"] ~= nil or
609                 world_doubleclick or
610                 fields["key_enter"] then
611                 local selected = engine.get_textlist_index("srv_worlds")
612                 if selected ~= nil then
613                         gamedata.playername             = fields["te_playername"]
614                         gamedata.password               = fields["te_passwd"]
615                         gamedata.port                   = fields["te_serverport"]
616                         gamedata.address                = ""
617                         gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
618
619                         engine.setting_set("port",gamedata.port)
620                         if fields["te_serveraddr"] ~= nil then
621                                 engine.setting_set("bind_address",fields["te_serveraddr"])
622                         end
623
624                         menu.update_last_game(gamedata.selected_world)
625                         engine.start()
626                 end
627         end
628
629         if fields["world_create"] ~= nil then
630                 tabbuilder.current_tab = "dialog_create_world"
631                 tabbuilder.is_dialog = true
632                 tabbuilder.show_buttons = false
633         end
634
635         if fields["world_delete"] ~= nil then
636                 local selected = engine.get_textlist_index("srv_worlds")
637                 if selected ~= nil and
638                         selected <= filterlist.size(worldlist) then
639                         local world = filterlist.get_list(worldlist)[selected]
640                         if world ~= nil and
641                                 world.name ~= nil and
642                                 world.name ~= "" then
643                                 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
644                                 tabbuilder.current_tab = "dialog_delete_world"
645                                 tabbuilder.is_dialog = true
646                                 tabbuilder.show_buttons = false
647                         else
648                                 menu.world_to_del = 0
649                         end
650                 end
651         end
652
653         if fields["world_configure"] ~= nil then
654                 selected = engine.get_textlist_index("srv_worlds")
655                 if selected ~= nil then
656                         modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
657                         if modmgr.init_worldconfig() then
658                                 tabbuilder.current_tab = "dialog_configure_world"
659                                 tabbuilder.is_dialog = true
660                                 tabbuilder.show_buttons = false
661                         end
662                 end
663         end
664 end
665
666 --------------------------------------------------------------------------------
667 function tabbuilder.handle_settings_buttons(fields)
668         if fields["cb_fancy_trees"] then
669                 engine.setting_set("new_style_leaves", fields["cb_fancy_trees"])
670         end
671         if fields["cb_smooth_lighting"] then
672                 engine.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
673         end
674         if fields["cb_3d_clouds"] then
675                 engine.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
676         end
677         if fields["cb_opaque_water"] then
678                 engine.setting_set("opaque_water", fields["cb_opaque_water"])
679         end
680
681         if fields["cb_mipmapping"] then
682                 engine.setting_set("mip_map", fields["cb_mipmapping"])
683         end
684         if fields["cb_anisotrophic"] then
685                 engine.setting_set("anisotropic_filter", fields["cb_anisotrophic"])
686         end
687         if fields["cb_bilinear"] then
688                 engine.setting_set("bilinear_filter", fields["cb_bilinear"])
689         end
690         if fields["cb_trilinear"] then
691                 engine.setting_set("trilinear_filter", fields["cb_trilinear"])
692         end
693
694         if fields["cb_shaders"] then
695                 if (engine.setting_get("video_driver") == "direct3d8" or engine.setting_get("video_driver") == "direct3d9") then
696                         engine.setting_set("enable_shaders", "false")
697                         gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
698                 else
699                         engine.setting_set("enable_shaders", fields["cb_shaders"])
700                 end
701         end
702         if fields["cb_pre_ivis"] then
703                 engine.setting_set("preload_item_visuals", fields["cb_pre_ivis"])
704         end
705         if fields["cb_particles"] then
706                 engine.setting_set("enable_particles", fields["cb_particles"])
707         end
708         if fields["cb_bumpmapping"] then
709                 engine.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
710         end
711         if fields["cb_parallax"] then
712                 engine.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
713         end
714         if fields["cb_generate_normalmaps"] then
715                 engine.setting_set("generate_normalmaps", fields["cb_generate_normalmaps"])
716         end
717         if fields["cb_waving_water"] then
718                 engine.setting_set("enable_waving_water", fields["cb_waving_water"])
719         end
720         if fields["cb_waving_leaves"] then
721                 engine.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
722         end
723         if fields["cb_waving_plants"] then
724                 engine.setting_set("enable_waving_plants", fields["cb_waving_plants"])
725         end
726         if fields["btn_change_keys"] ~= nil then
727                 engine.show_keys_menu()
728         end
729 end
730
731 --------------------------------------------------------------------------------
732 function tabbuilder.handle_singleplayer_buttons(fields)
733
734         local world_doubleclick = false
735
736         if fields["sp_worlds"] ~= nil then
737                 local event = engine.explode_textlist_event(fields["sp_worlds"])
738
739                 if event.type == "DCL" then
740                         world_doubleclick = true
741                 end
742
743                 if event.type == "CHG" then
744                         engine.setting_set("mainmenu_last_selected_world",
745                                 filterlist.get_raw_index(worldlist,engine.get_textlist_index("sp_worlds")))
746                 end
747         end
748
749         menu.handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world")
750
751         if fields["cb_creative_mode"] then
752                 engine.setting_set("creative_mode", fields["cb_creative_mode"])
753         end
754
755         if fields["cb_enable_damage"] then
756                 engine.setting_set("enable_damage", fields["cb_enable_damage"])
757         end
758
759         if fields["play"] ~= nil or
760                 world_doubleclick or
761                 fields["key_enter"] then
762                 local selected = engine.get_textlist_index("sp_worlds")
763                 if selected ~= nil then
764                         gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
765                         gamedata.singleplayer   = true
766
767                         menu.update_last_game(gamedata.selected_world)
768
769                         engine.start()
770                 end
771         end
772
773         if fields["world_create"] ~= nil then
774                 tabbuilder.current_tab = "dialog_create_world"
775                 tabbuilder.is_dialog = true
776                 tabbuilder.show_buttons = false
777         end
778
779         if fields["world_delete"] ~= nil then
780                 local selected = engine.get_textlist_index("sp_worlds")
781                 if selected ~= nil and
782                         selected <= filterlist.size(worldlist) then
783                         local world = filterlist.get_list(worldlist)[selected]
784                         if world ~= nil and
785                                 world.name ~= nil and
786                                 world.name ~= "" then
787                                 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
788                                 tabbuilder.current_tab = "dialog_delete_world"
789                                 tabbuilder.is_dialog = true
790                                 tabbuilder.show_buttons = false
791                         else
792                                 menu.world_to_del = 0
793                         end
794                 end
795         end
796
797         if fields["world_configure"] ~= nil then
798                 selected = engine.get_textlist_index("sp_worlds")
799                 if selected ~= nil then
800                         modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
801                         if modmgr.init_worldconfig() then
802                                 tabbuilder.current_tab = "dialog_configure_world"
803                                 tabbuilder.is_dialog = true
804                                 tabbuilder.show_buttons = false
805                         end
806                 end
807         end
808 end
809
810 --------------------------------------------------------------------------------
811 function tabbuilder.handle_texture_pack_buttons(fields)
812         if fields["TPs"] ~= nil then
813                 local event = engine.explode_textlist_event(fields["TPs"])
814                 if event.type == "CHG" or event.type == "DCL" then
815                         local index = engine.get_textlist_index("TPs")
816                         engine.setting_set("mainmenu_last_selected_TP",
817                                 index)
818                         local list = filter_texture_pack_list(engine.get_dirlist(engine.get_texturepath(), true))
819                         local current_index = engine.get_textlist_index("TPs")
820                         if current_index ~= nil and #list >= current_index then
821                                 local new_path = engine.get_texturepath()..DIR_DELIM..list[current_index]
822                                 if list[current_index] == "None" then new_path = "" end
823
824                                 engine.setting_set("texture_path", new_path)
825                         end
826                 end
827         end
828 end
829
830 --------------------------------------------------------------------------------
831 function tabbuilder.tab_header()
832
833         if tabbuilder.last_tab_index == nil then
834                 tabbuilder.last_tab_index = 1
835         end
836
837         local toadd = ""
838
839         for i=1,#tabbuilder.current_buttons,1 do
840
841                 if toadd ~= "" then
842                         toadd = toadd .. ","
843                 end
844
845                 toadd = toadd .. tabbuilder.current_buttons[i].caption
846         end
847         return "tabheader[-0.3,-0.99;main_tab;" .. toadd ..";" .. tabbuilder.last_tab_index .. ";true;false]"
848 end
849
850 --------------------------------------------------------------------------------
851 function tabbuilder.handle_tab_buttons(fields)
852
853         if fields["main_tab"] then
854                 local index = tonumber(fields["main_tab"])
855                 tabbuilder.last_tab_index = index
856                 tabbuilder.current_tab = tabbuilder.current_buttons[index].name
857
858                 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
859         end
860
861         --handle tab changes
862         if tabbuilder.current_tab ~= tabbuilder.old_tab then
863                 if tabbuilder.current_tab ~= "singleplayer" and not tabbuilder.is_dialog then
864                         menu.update_gametype(true)
865                 end
866         end
867
868         if tabbuilder.current_tab == "singleplayer" then
869                 menu.update_gametype()
870         end
871
872         tabbuilder.old_tab = tabbuilder.current_tab
873 end
874
875 --------------------------------------------------------------------------------
876 function tabbuilder.tab_multiplayer()
877
878         local retval =
879                 "vertlabel[0,-0.25;".. fgettext("CLIENT") .. "]" ..
880                 "label[1,-0.25;".. fgettext("Favorites:") .. "]"..
881                 "label[1,4.25;".. fgettext("Address/Port") .. "]"..
882                 "label[9,2.75;".. fgettext("Name/Password") .. "]" ..
883                 "field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" ..
884                 "field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("remote_port") .."]" ..
885                 "checkbox[1,3.6;cb_public_serverlist;".. fgettext("Public Serverlist") .. ";" ..
886                 dump(engine.setting_getbool("public_serverlist")) .. "]"
887
888         if not engine.setting_getbool("public_serverlist") then
889                 retval = retval ..
890                 "button[6.45,3.95;2.25,0.5;btn_delete_favorite;".. fgettext("Delete") .. "]"
891         end
892
893         retval = retval ..
894                 "button[9,4.95;2.5,0.5;btn_mp_connect;".. fgettext("Connect") .. "]" ..
895                 "field[9.3,3.75;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" ..
896                 "pwdfield[9.3,4.5;2.5,0.5;te_pwd;]" ..
897                 "textarea[9.3,0.25;2.5,2.75;;"
898         if menu.fav_selected ~= nil and
899                 menu.favorites[menu.fav_selected].description ~= nil then
900                 retval = retval ..
901                         engine.formspec_escape(menu.favorites[menu.fav_selected].description,true)
902         end
903
904         retval = retval ..
905                 ";]" ..
906                 "textlist[1,0.35;7.5,3.35;favourites;"
907
908         local render_details = engine.setting_getbool("public_serverlist")
909
910         if #menu.favorites > 0 then
911                 retval = retval .. menu.render_favorite(menu.favorites[1],render_details)
912
913                 for i=2,#menu.favorites,1 do
914                         retval = retval .. "," .. menu.render_favorite(menu.favorites[i],render_details)
915                 end
916         end
917
918         if menu.fav_selected ~= nil then
919                 retval = retval .. ";" .. menu.fav_selected .. "]"
920         else
921                 retval = retval .. ";0]"
922         end
923
924         return retval
925 end
926
927 --------------------------------------------------------------------------------
928 function tabbuilder.tab_server()
929
930         local index = filterlist.get_current_index(worldlist,
931                                 tonumber(engine.setting_get("mainmenu_last_selected_world"))
932                                 )
933
934         local retval =
935                 "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" ..
936                 "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" ..
937                 "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" ..
938                 "button[8.5,4.9;3.25,0.5;start_server;".. fgettext("Start Game") .. "]" ..
939                 "label[4,-0.25;".. fgettext("Select World:") .. "]"..
940                 "vertlabel[0,-0.25;".. fgettext("START SERVER") .. "]" ..
941                 "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
942                 dump(engine.setting_getbool("creative_mode")) .. "]"..
943                 "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
944                 dump(engine.setting_getbool("enable_damage")) .. "]"..
945                 "checkbox[0.5,1.15;cb_server_announce;".. fgettext("Public") .. ";" ..
946                 dump(engine.setting_getbool("server_announce")) .. "]"..
947                 "field[0.8,3.2;3.5,0.5;te_playername;".. fgettext("Name") .. ";" ..
948                 engine.setting_get("name") .. "]" ..
949                 "pwdfield[0.8,4.2;3.5,0.5;te_passwd;".. fgettext("Password") .. "]"
950                 
951         local bind_addr = engine.setting_get("bind_address")
952         if bind_addr ~= nil and bind_addr ~= "" then
953                 retval = retval ..
954                         "field[0.8,5.2;2.25,0.5;te_serveraddr;".. fgettext("Bind Address") .. ";" ..
955                         engine.setting_get("bind_address") .."]" ..
956                         "field[3.05,5.2;1.25,0.5;te_serverport;".. fgettext("Port") .. ";" ..
957                         engine.setting_get("port") .."]"
958         else
959                 retval = retval ..
960                         "field[0.8,5.2;3.5,0.5;te_serverport;".. fgettext("Server Port") .. ";" ..
961                         engine.setting_get("port") .."]"
962         end
963         
964         retval = retval ..
965                 "textlist[4,0.25;7.5,3.7;srv_worlds;" ..
966                 menu.render_world_list() ..
967                 ";" .. index .. "]"
968
969         return retval
970 end
971
972 --------------------------------------------------------------------------------
973 function tabbuilder.tab_settings()
974         tab_string =
975                         "vertlabel[0,0;" .. fgettext("SETTINGS") .. "]" ..
976                         "checkbox[1,0;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";"
977                                         .. dump(engine.setting_getbool("new_style_leaves")) .. "]"..
978                         "checkbox[1,0.5;cb_smooth_lighting;".. fgettext("Smooth Lighting")
979                                         .. ";".. dump(engine.setting_getbool("smooth_lighting")) .. "]"..
980                         "checkbox[1,1;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
981                                         .. dump(engine.setting_getbool("enable_3d_clouds")) .. "]"..
982                         "checkbox[1,1.5;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
983                                         .. dump(engine.setting_getbool("opaque_water")) .. "]"..
984                         "checkbox[1,2.0;cb_pre_ivis;".. fgettext("Preload item visuals") .. ";"
985                                         .. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
986                         "checkbox[1,2.5;cb_particles;".. fgettext("Enable Particles") .. ";"
987                                         .. dump(engine.setting_getbool("enable_particles"))     .. "]"..
988                         "checkbox[4.5,0;cb_mipmapping;".. fgettext("Mip-Mapping") .. ";"
989                                         .. dump(engine.setting_getbool("mip_map")) .. "]"..
990                         "checkbox[4.5,0.5;cb_anisotrophic;".. fgettext("Anisotropic Filtering") .. ";"
991                                         .. dump(engine.setting_getbool("anisotropic_filter")) .. "]"..
992                         "checkbox[4.5,1.0;cb_bilinear;".. fgettext("Bi-Linear Filtering") .. ";"
993                                         .. dump(engine.setting_getbool("bilinear_filter")) .. "]"..
994                         "checkbox[4.5,1.5;cb_trilinear;".. fgettext("Tri-Linear Filtering") .. ";"
995                                         .. dump(engine.setting_getbool("trilinear_filter")) .. "]"..
996
997                         "checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";"
998                                         .. dump(engine.setting_getbool("enable_shaders")) .. "]"..
999                         "button[1,4.5;2.25,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
1000
1001         if engine.setting_getbool("enable_shaders") then
1002                 tab_string = tab_string ..
1003                         "checkbox[8,0.5;cb_bumpmapping;".. fgettext("Bumpmapping") .. ";"
1004                                         .. dump(engine.setting_getbool("enable_bumpmapping")) .. "]"..
1005                         "checkbox[8,1.0;cb_parallax;".. fgettext("Parallax Occlusion") .. ";"
1006                                         .. dump(engine.setting_getbool("enable_parallax_occlusion")) .. "]"..
1007                         "checkbox[8,1.5;cb_generate_normalmaps;".. fgettext("Generate Normalmaps") .. ";"
1008                                         .. dump(engine.setting_getbool("generate_normalmaps")) .. "]"..
1009                         "checkbox[8,2.0;cb_waving_water;".. fgettext("Waving Water") .. ";"
1010                                         .. dump(engine.setting_getbool("enable_waving_water")) .. "]"..
1011                         "checkbox[8,2.5;cb_waving_leaves;".. fgettext("Waving Leaves") .. ";"
1012                                         .. dump(engine.setting_getbool("enable_waving_leaves")) .. "]"..
1013                         "checkbox[8,3.0;cb_waving_plants;".. fgettext("Waving Plants") .. ";"
1014                                         .. dump(engine.setting_getbool("enable_waving_plants")) .. "]"
1015         else
1016                 tab_string = tab_string ..
1017                         "textlist[8.33,0.7;4,1;;#888888" .. fgettext("Bumpmapping") .. ";0;true]" ..
1018                         "textlist[8.33,1.2;4,1;;#888888" .. fgettext("Parallax Occlusion") .. ";0;true]" ..
1019                         "textlist[8.33,1.7;4,1;;#888888" .. fgettext("Generate Normalmaps") .. ";0;true]" ..
1020                         "textlist[8.33,2.2;4,1;;#888888" .. fgettext("Waving Water") .. ";0;true]" ..
1021                         "textlist[8.33,2.7;4,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" ..
1022                         "textlist[8.33,3.2;4,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]"
1023         end
1024         return tab_string
1025 end
1026
1027 --------------------------------------------------------------------------------
1028 function tabbuilder.tab_singleplayer()
1029
1030         local index = filterlist.get_current_index(worldlist,
1031                                 tonumber(engine.setting_get("mainmenu_last_selected_world"))
1032                                 )
1033
1034         return  "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" ..
1035                         "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" ..
1036                         "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" ..
1037                         "button[8.5,4.95;3.25,0.5;play;".. fgettext("Play") .. "]" ..
1038                         "label[4,-0.25;".. fgettext("Select World:") .. "]"..
1039                         "vertlabel[0,-0.25;".. fgettext("SINGLE PLAYER") .. "]" ..
1040                         "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
1041                         dump(engine.setting_getbool("creative_mode")) .. "]"..
1042                         "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
1043                         dump(engine.setting_getbool("enable_damage")) .. "]"..
1044                         "textlist[4,0.25;7.5,3.7;sp_worlds;" ..
1045                         menu.render_world_list() ..
1046                         ";" .. index .. "]" ..
1047                         menubar.formspec
1048 end
1049
1050 --------------------------------------------------------------------------------
1051 function tabbuilder.tab_texture_packs()
1052         local retval = "label[4,-0.25;".. fgettext("Select texture pack:") .. "]"..
1053                         "vertlabel[0,-0.25;".. fgettext("TEXTURE PACKS") .. "]" ..
1054                         "textlist[4,0.25;7.5,5.0;TPs;"
1055
1056         local current_texture_path = engine.setting_get("texture_path")
1057         local list = filter_texture_pack_list(engine.get_dirlist(engine.get_texturepath(), true))
1058         local index = tonumber(engine.setting_get("mainmenu_last_selected_TP"))
1059
1060         if index == nil then index = 1 end
1061
1062         if current_texture_path == "" then
1063                 retval = retval ..
1064                         menu.render_texture_pack_list(list) ..
1065                         ";" .. index .. "]"
1066                 return retval
1067         end
1068
1069         local infofile = current_texture_path ..DIR_DELIM.."info.txt"
1070         local infotext = ""
1071         local f = io.open(infofile, "r")
1072         if f==nil then
1073                 infotext = fgettext("No information available")
1074         else
1075                 infotext = f:read("*all")
1076                 f:close()
1077         end
1078
1079         local screenfile = current_texture_path..DIR_DELIM.."screenshot.png"
1080         local no_screenshot = nil
1081         if not file_exists(screenfile) then
1082                 screenfile = nil
1083                 no_screenshot = menu.defaulttexturedir .. "no_screenshot.png"
1084         end
1085
1086         return  retval ..
1087                         menu.render_texture_pack_list(list) ..
1088                         ";" .. index .. "]" ..
1089                         "image[0.65,0.25;4.0,3.7;"..engine.formspec_escape(screenfile or no_screenshot).."]"..
1090                         "textarea[1.0,3.25;3.7,1.5;;"..engine.formspec_escape(infotext or "")..";]"
1091 end
1092
1093 --------------------------------------------------------------------------------
1094 function tabbuilder.tab_credits()
1095         local logofile = menu.defaulttexturedir .. "logo.png"
1096         return  "vertlabel[0,-0.5;CREDITS]" ..
1097                         "label[0.5,3;Minetest " .. engine.get_version() .. "]" ..
1098                         "label[0.5,3.3;http://minetest.net]" ..
1099                         "image[0.5,1;" .. engine.formspec_escape(logofile) .. "]" ..
1100                         "textlist[3.5,-0.25;8.5,5.8;list_credits;" ..
1101                         "#FFFF00" .. fgettext("Core Developers") .."," ..
1102                         "Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
1103                         "Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,"..
1104                         "PilzAdam <pilzadam@minetest.net>," ..
1105                         "Ilya Zhuravlev (xyz) <xyz@minetest.net>,"..
1106                         "Lisa Milne (darkrose) <lisa@ltmnet.com>,"..
1107                         "Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,"..
1108                         "proller <proler@gmail.com>,"..
1109                         "sfan5 <sfan5@live.de>,"..
1110                         "kahrl <kahrl@gmx.net>,"..
1111                         "sapier,"..
1112                         "ShadowNinja <shadowninja@minetest.net>,"..
1113                         "Nathanael Courant (Nore/Novatux) <nore@mesecons.net>,"..
1114                         "BlockMen,"..
1115                         ","..
1116                         "#FFFF00" .. fgettext("Active Contributors") .. "," ..
1117                         "Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,"..
1118                         "Jurgen Doser (doserj) <jurgen.doser@gmail.com>,"..
1119                         "Jeija <jeija@mesecons.net>,"..
1120                         "MirceaKitsune <mirceakitsune@gmail.com>,"..
1121                         "dannydark <the_skeleton_of_a_child@yahoo.co.uk>,"..
1122                         "0gb.us <0gb.us@0gb.us>,"..
1123                         "," ..
1124                         "#FFFF00" .. fgettext("Previous Contributors") .. "," ..
1125                         "Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,"..
1126                         "Jonathan Neuschafer <j.neuschaefer@gmx.net>,"..
1127                         "Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,"..
1128                         "Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,"..
1129                         "matttpt <matttpt@gmail.com>,"..
1130                         "JacobF <queatz@gmail.com>,"..
1131                         ";0;true]"
1132 end
1133
1134 --------------------------------------------------------------------------------
1135 function tabbuilder.init()
1136         tabbuilder.tabfuncs = {
1137                 singleplayer  = tabbuilder.tab_singleplayer,
1138                 multiplayer   = tabbuilder.tab_multiplayer,
1139                 server        = tabbuilder.tab_server,
1140                 settings      = tabbuilder.tab_settings,
1141                 texture_packs = tabbuilder.tab_texture_packs,
1142                 credits       = tabbuilder.tab_credits,
1143                 dialog_create_world = tabbuilder.dialog_create_world,
1144                 dialog_delete_world = tabbuilder.dialog_delete_world
1145         }
1146
1147         tabbuilder.tabsizes = {
1148                 dialog_create_world = {width=12, height=7},
1149                 dialog_delete_world = {width=12, height=5.2}
1150         }
1151
1152         tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1153
1154         if tabbuilder.current_tab == nil or
1155                 tabbuilder.current_tab == "" then
1156                 tabbuilder.current_tab = "singleplayer"
1157                 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
1158         end
1159
1160         --initialize tab buttons
1161         tabbuilder.last_tab = nil
1162         tabbuilder.show_buttons = true
1163
1164         tabbuilder.current_buttons = {}
1165         table.insert(tabbuilder.current_buttons,{name="singleplayer", caption=fgettext("Singleplayer")})
1166         table.insert(tabbuilder.current_buttons,{name="multiplayer", caption=fgettext("Client")})
1167         table.insert(tabbuilder.current_buttons,{name="server", caption=fgettext("Server")})
1168         table.insert(tabbuilder.current_buttons,{name="settings", caption=fgettext("Settings")})
1169         table.insert(tabbuilder.current_buttons,{name="texture_packs", caption=fgettext("Texture Packs")})
1170
1171         if engine.setting_getbool("main_menu_game_mgr") then
1172                 table.insert(tabbuilder.current_buttons,{name="game_mgr", caption=fgettext("Games")})
1173         end
1174
1175         if engine.setting_getbool("main_menu_mod_mgr") then
1176                 table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption=fgettext("Mods")})
1177         end
1178         table.insert(tabbuilder.current_buttons,{name="credits", caption=fgettext("Credits")})
1179
1180
1181         for i=1,#tabbuilder.current_buttons,1 do
1182                 if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then
1183                         tabbuilder.last_tab_index = i
1184                 end
1185         end
1186
1187         if tabbuilder.current_tab ~= "singleplayer" then
1188                 menu.update_gametype(true)
1189         else
1190                 menu.update_gametype()
1191         end
1192 end
1193
1194 --------------------------------------------------------------------------------
1195 function tabbuilder.checkretval(retval)
1196
1197         if retval ~= nil then
1198                 if retval.current_tab ~= nil then
1199                         tabbuilder.current_tab = retval.current_tab
1200                 end
1201
1202                 if retval.is_dialog ~= nil then
1203                         tabbuilder.is_dialog = retval.is_dialog
1204                 end
1205
1206                 if retval.show_buttons ~= nil then
1207                         tabbuilder.show_buttons = retval.show_buttons
1208                 end
1209
1210                 if retval.skipformupdate ~= nil then
1211                         tabbuilder.skipformupdate = retval.skipformupdate
1212                 end
1213
1214                 if retval.ignore_menu_quit == true then
1215                         tabbuilder.ignore_menu_quit = true
1216                 else
1217                         tabbuilder.ignore_menu_quit = false
1218                 end
1219         end
1220 end
1221
1222 --------------------------------------------------------------------------------
1223 --------------------------------------------------------------------------------
1224 -- initialize callbacks
1225 --------------------------------------------------------------------------------
1226 --------------------------------------------------------------------------------
1227 engine.button_handler = function(fields)
1228         --print("Buttonhandler: tab: " .. tabbuilder.current_tab .. " fields: " .. dump(fields))
1229
1230         if fields["btn_error_confirm"] then
1231                 gamedata.errormessage = nil
1232         end
1233
1234         local retval = modmgr.handle_buttons(tabbuilder.current_tab,fields)
1235         tabbuilder.checkretval(retval)
1236
1237         retval = gamemgr.handle_buttons(tabbuilder.current_tab,fields)
1238         tabbuilder.checkretval(retval)
1239
1240         retval = modstore.handle_buttons(tabbuilder.current_tab,fields)
1241         tabbuilder.checkretval(retval)
1242
1243         if tabbuilder.current_tab == "dialog_create_world" then
1244                 tabbuilder.handle_create_world_buttons(fields)
1245         end
1246
1247         if tabbuilder.current_tab == "dialog_delete_world" then
1248                 tabbuilder.handle_delete_world_buttons(fields)
1249         end
1250
1251         if tabbuilder.current_tab == "singleplayer" then
1252                 tabbuilder.handle_singleplayer_buttons(fields)
1253         end
1254
1255         if tabbuilder.current_tab == "texture_packs" then
1256                 tabbuilder.handle_texture_pack_buttons(fields)
1257         end
1258
1259         if tabbuilder.current_tab == "multiplayer" then
1260                 tabbuilder.handle_multiplayer_buttons(fields)
1261         end
1262
1263         if tabbuilder.current_tab == "settings" then
1264                 tabbuilder.handle_settings_buttons(fields)
1265         end
1266
1267         if tabbuilder.current_tab == "server" then
1268                 tabbuilder.handle_server_buttons(fields)
1269         end
1270
1271         --tab buttons
1272         tabbuilder.handle_tab_buttons(fields)
1273
1274         --menubar buttons
1275         menubar.handle_buttons(fields)
1276
1277         if not tabbuilder.skipformupdate then
1278                 --update menu
1279                 update_menu()
1280         else
1281                 tabbuilder.skipformupdate = false
1282         end
1283 end
1284
1285 --------------------------------------------------------------------------------
1286 engine.event_handler = function(event)
1287         if event == "MenuQuit" then
1288                 if tabbuilder.is_dialog then
1289                         if tabbuilder.ignore_menu_quit then
1290                                 return
1291                         end
1292
1293                         tabbuilder.is_dialog = false
1294                         tabbuilder.show_buttons = true
1295                         tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1296                         menu.update_gametype()
1297                         update_menu()
1298                 else
1299                         engine.close()
1300                 end
1301         end
1302
1303         if event == "Refresh" then
1304                 update_menu()
1305         end
1306 end
1307
1308 --------------------------------------------------------------------------------
1309 function menu.update_gametype(reset)
1310         local game = menu.lastgame()
1311
1312         if reset or game == nil then
1313                 mm_texture.reset()
1314                 engine.set_topleft_text("")
1315                 filterlist.set_filtercriteria(worldlist,nil)
1316         else
1317                 mm_texture.update(tabbuilder.current_tab,game)
1318                 engine.set_topleft_text(game.name)
1319                 filterlist.set_filtercriteria(worldlist,game.id)
1320         end
1321 end
1322
1323 --------------------------------------------------------------------------------
1324 --------------------------------------------------------------------------------
1325 -- menu startup
1326 --------------------------------------------------------------------------------
1327 --------------------------------------------------------------------------------
1328 init_globals()
1329 mm_texture.init()
1330 menu.init()
1331 tabbuilder.init()
1332 menubar.refresh()
1333 modstore.init()
1334
1335 engine.sound_play("main_menu", true)
1336
1337 update_menu()