]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - builtin/mainmenu.lua
Show portnumber for ip adresses only
[dragonfireclient.git] / builtin / mainmenu.lua
index 91084c2c63d066bca47fab69b2c789a58c10c017..febf1984a352fd3510e896dcf8b58e0a5f77c1e6 100644 (file)
@@ -2,18 +2,26 @@ os.setlocale("C", "numeric")
 
 local scriptpath = engine.get_scriptdir()
 
-dofile(scriptpath .. DIR_DELIM .. "mainmenu_worldlist.lua")
+mt_color_grey  = "#AAAAAA"
+mt_color_blue  = "#0000DD"
+mt_color_green = "#00DD00"
+mt_color_dark_green = "#003300"
+
+--for all other colors ask sfan5 to complete his worK!
+
+dofile(scriptpath .. DIR_DELIM .. "filterlist.lua")
 dofile(scriptpath .. DIR_DELIM .. "modmgr.lua")
 dofile(scriptpath .. DIR_DELIM .. "modstore.lua")
 dofile(scriptpath .. DIR_DELIM .. "gamemgr.lua")
+dofile(scriptpath .. DIR_DELIM .. "mm_textures.lua")
+dofile(scriptpath .. DIR_DELIM .. "mm_menubar.lua")
 
-local menu = {}
+menu = {}
 local tabbuilder = {}
-local menubar = {}
 local worldlist = nil
 
 --------------------------------------------------------------------------------
-function render_favourite(spec,render_details)
+function menu.render_favorite(spec,render_details)
        local text = ""
        
        if spec.name ~= nil then
@@ -26,6 +34,10 @@ function render_favourite(spec,render_details)
        else
                if spec.address ~= nil then
                        text = text .. spec.address:trim()
+                       
+                       if spec.port ~= nil then
+                               text = text .. ":" .. spec.port
+                       end
                end
        end
        
@@ -57,9 +69,17 @@ function render_favourite(spec,render_details)
        else
                details = details .. "_"
        end
-       details = details .. "  "
+       details = details .. " "
+       
+       local playercount = ""
        
-       return fs_escape_string(details) .. text
+       if spec.clients ~= nil and
+               spec.clients_max ~= nil then
+               playercount = string.format("%03d",spec.clients) .. "/" ..
+                                               string.format("%03d",spec.clients_max) .. " "
+       end
+       
+       return playercount .. fs_escape_string(details) ..  text
 end
 
 --------------------------------------------------------------------------------
@@ -78,171 +98,6 @@ os.tempfolder = function()
 
 end
 
---------------------------------------------------------------------------------
-function cleanup_path(temppath)
-       
-       local parts = temppath:split("-")
-       temppath = ""   
-       for i=1,#parts,1 do
-               if temppath ~= "" then
-                       temppath = temppath .. "_"
-               end
-               temppath = temppath .. parts[i]
-       end
-       
-       parts = temppath:split(".")
-       temppath = ""   
-       for i=1,#parts,1 do
-               if temppath ~= "" then
-                       temppath = temppath .. "_"
-               end
-               temppath = temppath .. parts[i]
-       end
-       
-       parts = temppath:split("'")
-       temppath = ""   
-       for i=1,#parts,1 do
-               if temppath ~= "" then
-                       temppath = temppath .. ""
-               end
-               temppath = temppath .. parts[i]
-       end
-       
-       parts = temppath:split(" ")
-       temppath = ""   
-       for i=1,#parts,1 do
-               if temppath ~= "" then
-                       temppath = temppath
-               end
-               temppath = temppath .. parts[i]
-       end
-       
-       return temppath
-end
-
---------------------------------------------------------------------------------
-
-function menu.set_texture(identifier,gamedetails)
-       local texture_set = false
-       if menu.texturepack ~= nil and gamedetails ~= nil then
-               local path = menu.basetexturedir .. 
-                                               gamedetails.id .. "_menu_" .. identifier .. ".png"
-               
-               if engine.set_background(identifier,path) then
-                       texture_set = true
-               end
-       end
-       
-       if not texture_set and gamedetails ~= nil then
-               local path = gamedetails.path .. DIR_DELIM .."menu" .. 
-                                                                        DIR_DELIM .. identifier .. ".png"
-               if engine.set_background(identifier,path) then
-                       texture_set = true
-               end
-       end
-       
-       if not texture_set then
-               local path = menu.basetexturedir .. DIR_DELIM .."menu_" .. 
-                                                                               identifier .. ".png"
-               if engine.set_background(identifier,path) then
-                       texture_set = true
-               end
-       end
-       
-       if not texture_set then
-               local path = menu.defaulttexturedir .. DIR_DELIM .."menu_" .. 
-                                                                               identifier .. ".png"
-               engine.set_background(identifier,path)
-       end
-end
-
---------------------------------------------------------------------------------
-function menu.update_gametype()
-       
-       
-       
-       if (menu.game_last_check == nil or
-               menu.game_last_check ~= menu.last_game) and
-               tabbuilder.current_tab == "singleplayer" then
-               
-               local gamedetails = menu.lastgame()
-               engine.set_topleft_text(gamedetails.name)
-               filterlist.set_filtercriteria(worldlist,gamedetails.id)
-               
-               --background
-               local background_set = false
-               if menu.texturepack ~= nil then
-                       local path_background_texture = menu.basetexturedir .. 
-                                                                               gamedetails.id .. "_menu_background.png"
-                       
-                       if engine.set_background("background",path_background_texture) then
-                               background_set = true
-                               engine.set_clouds(false)
-                       end
-               end
-               
-               if not background_set then
-                       local path_background_texture = gamedetails.path .. DIR_DELIM .."menu" .. 
-                                                                                DIR_DELIM .. "background.png"
-                       if engine.set_background("background",path_background_texture) then
-                               background_set = true
-                               engine.set_clouds(false)
-                       end
-               end
-               
-               if not background_set then
-                       engine.set_clouds(true)
-               end
-               
-               menu.set_texture("overlay",gamedetails)
-               menu.set_texture("header",gamedetails)
-               menu.set_texture("footer",gamedetails)
-               
-               menu.game_last_check = menu.last_game
-       else
-               if menu.game_last_check ~= menu.last_game then
-                       menu.game_last_check = menu.last_game
-                       menu.reset_gametype()
-               end
-       end
-end
-
---------------------------------------------------------------------------------
-function menu.reset_gametype()
-       filterlist.set_filtercriteria(worldlist,nil)
-       menu.game_last_check = nil
-       
-       local path_background_texture = menu.basetexturedir .. "menu_background.png"
-                       
-       if engine.set_background("background",path_background_texture) then
-               background_set = true
-               engine.set_clouds(false)
-       else
-               engine.set_clouds(true)
-       end 
-
-       menu.set_texture("overlay",nil)
-       menu.set_texture("header",nil)
-       menu.set_texture("footer",nil)
-       engine.set_topleft_text("")
-end
-
---------------------------------------------------------------------------------
-function get_last_folder(text,count)
-       local parts = text:split(DIR_DELIM)
-       
-       if count == nil then
-               return parts[#parts]
-       end
-       
-       local retval = ""
-       for i=1,count,1 do
-               retval = retval .. parts[#parts - (count-i)] .. DIR_DELIM
-       end
-       
-       return retval
-end
-
 --------------------------------------------------------------------------------
 function init_globals()
        --init gamedata
@@ -270,44 +125,6 @@ function init_globals()
                                        
 end
 
---------------------------------------------------------------------------------
-function identify_filetype(name)
-
-       if name:sub(-3):lower() == "zip" then
-               return {
-                               name = name,
-                               type = "zip"
-                               }
-       end
-       
-       if name:sub(-6):lower() == "tar.gz" or
-               name:sub(-3):lower() == "tgz"then
-               return {
-                               name = name,
-                               type = "tgz"
-                               }
-       end
-       
-       if name:sub(-6):lower() == "tar.bz2" then
-               return {
-                               name = name,
-                               type = "tbz"
-                               }
-       end
-       
-       if name:sub(-2):lower() == "7z" then
-               return {
-                               name = name,
-                               type = "7z"
-                               }
-       end
-
-       return {
-               name = name,
-               type = "ukn"
-       }
-end
-
 --------------------------------------------------------------------------------
 function update_menu()
 
@@ -362,17 +179,9 @@ function menu.init()
                menu.favorites = engine.get_favorites("local")
        end
        
-       
        menu.defaulttexturedir = engine.get_gamepath() .. DIR_DELIM .. ".." ..
-                                               DIR_DELIM .. "textures" .. DIR_DELIM .. "base" .. 
-                                               DIR_DELIM .. "pack" .. DIR_DELIM
-       menu.basetexturedir = menu.defaulttexturedir
-       
-       menu.texturepack = engine.setting_get("texture_path")
-       
-       if menu.texturepack ~= nil then
-               menu.basetexturedir = menu.texturepack .. DIR_DELIM
-       end
+                                       DIR_DELIM .. "textures" .. DIR_DELIM .. "base" .. 
+                                       DIR_DELIM .. "pack" .. DIR_DELIM
 end
 
 --------------------------------------------------------------------------------
@@ -419,7 +228,7 @@ function menu.handle_key_up_down(fields,textlist,settingname)
                if oldidx > 1 then
                        local newidx = oldidx -1
                        engine.setting_set(settingname,
-                               filterlist.get_engine_index(worldlist,newidx))
+                               filterlist.get_raw_index(worldlist,newidx))
                end
        end
        
@@ -429,69 +238,8 @@ function menu.handle_key_up_down(fields,textlist,settingname)
                if oldidx < filterlist.size(worldlist) then
                        local newidx = oldidx + 1
                        engine.setting_set(settingname,
-                               filterlist.get_engine_index(worldlist,newidx))
-               end
-       end
-end
-
-
---------------------------------------------------------------------------------
-function menubar.handle_buttons(fields)
-       for i=1,#menubar.buttons,1 do
-               if fields[menubar.buttons[i].btn_name] ~= nil then
-                       menu.last_game = menubar.buttons[i].index
-                       engine.setting_set("main_menu_last_game_idx",menu.last_game)
-                       menu.update_gametype()
-               end
-       end
-end
-
---------------------------------------------------------------------------------
-function menubar.refresh()
-       menubar.formspec = "box[-0.3,5.625;12.4,1.3;000000]" ..
-                                          "box[-0.3,5.6;12.4,0.05;FFFFFF]"
-       menubar.buttons = {}
-
-       local button_base = -0.25
-       
-       local maxbuttons = #gamemgr.games
-       
-       if maxbuttons > 10 then
-               maxbuttons = 10
-       end
-       
-       for i=1,maxbuttons,1 do
-
-               local btn_name = "menubar_btn_" .. gamemgr.games[i].id
-               local buttonpos = button_base + (i-1) * 1.245
-               if gamemgr.games[i].menuicon_path ~= nil and
-                       gamemgr.games[i].menuicon_path ~= "" then
-
-                       menubar.formspec = menubar.formspec ..
-                               "image_button[" .. buttonpos ..  ",5.7;1.3,1.3;"  ..
-                               gamemgr.games[i].menuicon_path .. ";" .. btn_name .. ";;true;false]"
-               else
-               
-                       local part1 = gamemgr.games[i].id:sub(1,5)
-                       local part2 = gamemgr.games[i].id:sub(6,10)
-                       local part3 = gamemgr.games[i].id:sub(11)
-                       
-                       local text = part1 .. "\n" .. part2
-                       if part3 ~= nil and
-                               part3 ~= "" then
-                               text = text .. "\n" .. part3
-                       end
-                       menubar.formspec = menubar.formspec ..
-                               "image_button[" .. buttonpos ..  ",5.7;1.3,1.3;;" ..btn_name ..
-                               ";" .. text .. ";true;true]"
+                               filterlist.get_raw_index(worldlist,newidx))
                end
-               
-               local toadd = {
-                       btn_name = btn_name,
-                       index = i,
-               }
-               
-               table.insert(menubar.buttons,toadd)
        end
 end
 
@@ -592,7 +340,7 @@ function tabbuilder.handle_create_world_buttons(fields)
                        
                        local message = nil
                        
-                       if not filterlist.uid_exists(worldlist,worldname) then
+                       if not filterlist.uid_exists_raw(worldlist,worldname) then
                                engine.setting_set("mg_name",fields["dd_mapgen"])
                                message = engine.create_world(worldname,gameindex)
                        else
@@ -607,7 +355,7 @@ function tabbuilder.handle_create_world_buttons(fields)
                                
                                filterlist.refresh(worldlist)
                                engine.setting_set("mainmenu_last_selected_world",
-                                                                       filterlist.engine_index_by_uid(worldlist,worldname))
+                                                                       filterlist.raw_index_by_uid(worldlist,worldname))
                        end
                else
                        gamedata.errormessage = "No worldname given or no game selected"
@@ -778,7 +526,7 @@ function tabbuilder.handle_server_buttons(fields)
                end
                if event.typ == "CHG" then
                        engine.setting_set("mainmenu_last_selected_world",
-                               filterlist.get_engine_index(worldlist,engine.get_textlist_index("srv_worlds")))
+                               filterlist.get_raw_index(worldlist,engine.get_textlist_index("srv_worlds")))
                end
        end
        
@@ -805,7 +553,7 @@ function tabbuilder.handle_server_buttons(fields)
                        gamedata.password               = fields["te_passwd"]
                        gamedata.port                   = fields["te_serverport"]
                        gamedata.address                = ""
-                       gamedata.selected_world = filterlist.get_engine_index(worldlist,selected)
+                       gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
                        
                        menu.update_last_game(gamedata.selected_world)
                        engine.start()
@@ -826,7 +574,7 @@ function tabbuilder.handle_server_buttons(fields)
                        if world ~= nil and
                                world.name ~= nil and
                                world.name ~= "" then
-                               menu.world_to_del = filterlist.get_engine_index(worldlist,selected)
+                               menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
                                tabbuilder.current_tab = "dialog_delete_world"
                                tabbuilder.is_dialog = true
                                tabbuilder.show_buttons = false
@@ -839,7 +587,7 @@ function tabbuilder.handle_server_buttons(fields)
        if fields["world_configure"] ~= nil then
                selected = engine.get_textlist_index("srv_worlds")
                if selected > 0 then
-                       modmgr.world_config_selected_world = filterlist.get_engine_index(worldlist,selected)
+                       modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
                        if modmgr.init_worldconfig() then
                                tabbuilder.current_tab = "dialog_configure_world"
                                tabbuilder.is_dialog = true
@@ -863,7 +611,6 @@ function tabbuilder.handle_settings_buttons(fields)
        if fields["cb_fancy_trees"] then
                engine.setting_setbool("new_style_leaves",tabbuilder.tobool(fields["cb_fancy_trees"]))
        end
-               
        if fields["cb_smooth_lighting"] then
                engine.setting_setbool("smooth_lighting",tabbuilder.tobool(fields["cb_smooth_lighting"]))
        end
@@ -873,7 +620,10 @@ function tabbuilder.handle_settings_buttons(fields)
        if fields["cb_opaque_water"] then
                engine.setting_setbool("opaque_water",tabbuilder.tobool(fields["cb_opaque_water"]))
        end
-                       
+       if fields["old_style_modselection"] then
+               engine.setting_setbool("old_style_mod_selection",tabbuilder.tobool(fields["old_style_modselection"]))
+       end
+       
        if fields["cb_mipmapping"] then
                engine.setting_setbool("mip_map",tabbuilder.tobool(fields["cb_mipmapping"]))
        end
@@ -919,7 +669,7 @@ function tabbuilder.handle_singleplayer_buttons(fields)
                
                if event.typ == "CHG" then
                        engine.setting_set("mainmenu_last_selected_world",
-                               filterlist.get_engine_index(worldlist,engine.get_textlist_index("sp_worlds")))
+                               filterlist.get_raw_index(worldlist,engine.get_textlist_index("sp_worlds")))
                end
        end
        
@@ -938,7 +688,7 @@ function tabbuilder.handle_singleplayer_buttons(fields)
                fields["key_enter"] then
                local selected = engine.get_textlist_index("sp_worlds")
                if selected > 0 then
-                       gamedata.selected_world = filterlist.get_engine_index(worldlist,selected)
+                       gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
                        gamedata.singleplayer   = true
                        
                        menu.update_last_game(gamedata.selected_world)
@@ -961,7 +711,7 @@ function tabbuilder.handle_singleplayer_buttons(fields)
                        if world ~= nil and
                                world.name ~= nil and
                                world.name ~= "" then
-                               menu.world_to_del = filterlist.get_engine_index(worldlist,selected)
+                               menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
                                tabbuilder.current_tab = "dialog_delete_world"
                                tabbuilder.is_dialog = true
                                tabbuilder.show_buttons = false
@@ -974,7 +724,7 @@ function tabbuilder.handle_singleplayer_buttons(fields)
        if fields["world_configure"] ~= nil then
                selected = engine.get_textlist_index("sp_worlds")
                if selected > 0 then
-                       modmgr.world_config_selected_world = filterlist.get_engine_index(worldlist,selected)
+                       modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
                        if modmgr.init_worldconfig() then
                                tabbuilder.current_tab = "dialog_configure_world"
                                tabbuilder.is_dialog = true
@@ -1018,7 +768,7 @@ function tabbuilder.handle_tab_buttons(fields)
        --handle tab changes
        if tabbuilder.current_tab ~= tabbuilder.old_tab then
                if tabbuilder.current_tab ~= "singleplayer" then
-                       menu.reset_gametype()
+                       menu.update_gametype(true)
                end
        end
        
@@ -1039,7 +789,6 @@ function tabbuilder.init()
                engine.setting_set("main_menu_tab",tabbuilder.current_tab)
        end
        
-       
        --initialize tab buttons
        tabbuilder.last_tab = nil
        tabbuilder.show_buttons = true
@@ -1105,10 +854,10 @@ function tabbuilder.tab_multiplayer()
        local render_details = engine.setting_getbool("public_serverlist")
 
        if #menu.favorites > 0 then
-               retval = retval .. render_favourite(menu.favorites[1],render_details)
+               retval = retval .. menu.render_favorite(menu.favorites[1],render_details)
                
                for i=2,#menu.favorites,1 do
-                       retval = retval .. "," .. render_favourite(menu.favorites[i],render_details)
+                       retval = retval .. "," .. menu.render_favorite(menu.favorites[i],render_details)
                end
        end
 
@@ -1159,6 +908,7 @@ function tabbuilder.tab_settings()
                        "checkbox[1,1.25;cb_smooth_lighting;Smooth Lighting;".. dump(engine.setting_getbool("smooth_lighting")) .. "]"..
                        "checkbox[1,1.75;cb_3d_clouds;3D Clouds;"                       .. dump(engine.setting_getbool("enable_3d_clouds"))     .. "]"..
                        "checkbox[1,2.25;cb_opaque_water;Opaque Water;"                 .. dump(engine.setting_getbool("opaque_water"))         .. "]"..
+                       "checkbox[1,2.75;old_style_modselection;Old style modmgr;" .. dump(engine.setting_getbool("old_style_mod_selection"))           .. "]"..
                        
                        "checkbox[4,0.75;cb_mipmapping;Mip-Mapping;"            .. dump(engine.setting_getbool("mip_map"))                      .. "]"..
                        "checkbox[4,1.25;cb_anisotrophic;Anisotropic Filtering;".. dump(engine.setting_getbool("anisotropic_filter"))   .. "]"..
@@ -1170,7 +920,7 @@ function tabbuilder.tab_settings()
                        "checkbox[7.5,1.75;cb_particles;Enable Particles;"      .. dump(engine.setting_getbool("enable_particles"))     .. "]"..
                        "checkbox[7.5,2.25;cb_finite_liquid;Finite Liquid;"     .. dump(engine.setting_getbool("liquid_finite"))                .. "]"..
                        
-                       "button[1,3.75;2.25,0.5;btn_change_keys;Change keys]"
+                       "button[1,4.25;2.25,0.5;btn_change_keys;Change keys]"
 end
 
 --------------------------------------------------------------------------------
@@ -1330,15 +1080,31 @@ engine.event_handler = function(event)
        end
 end
 
+--------------------------------------------------------------------------------
+function menu.update_gametype(reset)
+       if reset then
+               mm_texture.reset()
+               engine.set_topleft_text("")
+               filterlist.set_filtercriteria(worldlist,nil)
+       else
+               local game = menu.lastgame()
+               mm_texture.update(tabbuilder.current_tab,game)
+               engine.set_topleft_text(game.name)
+               filterlist.set_filtercriteria(worldlist,game.id)
+       end
+end
+
 --------------------------------------------------------------------------------
 --------------------------------------------------------------------------------
 -- menu startup
 --------------------------------------------------------------------------------
 --------------------------------------------------------------------------------
 init_globals()
+mm_texture.init()
 menu.init()
 tabbuilder.init()
 menubar.refresh()
 modstore.init()
 
+
 update_menu()