2013-07-07 20:28:36 -04:00
|
|
|
os.setlocale("C", "numeric")
|
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
local scriptpath = engine.get_scriptdir()
|
|
|
|
|
|
|
|
dofile(scriptpath .. DIR_DELIM .. "modmgr.lua")
|
|
|
|
dofile(scriptpath .. DIR_DELIM .. "modstore.lua")
|
|
|
|
dofile(scriptpath .. DIR_DELIM .. "gamemgr.lua")
|
|
|
|
|
|
|
|
local menu = {}
|
|
|
|
local tabbuilder = {}
|
|
|
|
local menubar = {}
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function render_favourite(spec)
|
|
|
|
local text = ""
|
|
|
|
|
|
|
|
if spec.name ~= nil then
|
|
|
|
text = text .. spec.name:trim()
|
|
|
|
|
|
|
|
if spec.description ~= nil then
|
|
|
|
--TODO make sure there's no invalid chat in spec.description
|
|
|
|
text = text .. " (" .. fs_escape_string(spec.description) .. ")"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if spec.address ~= nil then
|
|
|
|
text = text .. spec.address:trim()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local details = ""
|
|
|
|
if spec.password == true then
|
|
|
|
details = " *"
|
|
|
|
else
|
|
|
|
details = " "
|
|
|
|
end
|
|
|
|
|
|
|
|
if spec.creative then
|
|
|
|
details = details .. "C"
|
|
|
|
else
|
|
|
|
details = details .. " "
|
|
|
|
end
|
|
|
|
|
|
|
|
if spec.damage then
|
|
|
|
details = details .. "D"
|
|
|
|
else
|
|
|
|
details = details .. " "
|
|
|
|
end
|
|
|
|
|
|
|
|
if spec.pvp then
|
|
|
|
details = details .. "P"
|
|
|
|
else
|
|
|
|
details = details .. " "
|
|
|
|
end
|
|
|
|
|
2013-07-08 20:21:09 -04:00
|
|
|
if spec.port ~= nil then
|
|
|
|
text = text .. ":" .. spec.port:trim()
|
|
|
|
else
|
|
|
|
text = text .. ":??"
|
|
|
|
end
|
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
return text
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
os.tempfolder = function()
|
|
|
|
local filetocheck = os.tmpname()
|
|
|
|
os.remove(filetocheck)
|
|
|
|
|
|
|
|
local randname = "MTTempModFolder_" .. math.random(0,10000)
|
|
|
|
if DIR_DELIM == "\\" then
|
|
|
|
local tempfolder = os.getenv("TEMP")
|
|
|
|
return tempfolder .. filetocheck
|
|
|
|
else
|
|
|
|
local backstring = filetocheck:reverse()
|
|
|
|
return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-07-07 15:53:40 -04:00
|
|
|
function menu.set_texture(identifier,gamedetails)
|
|
|
|
local texture_set = false
|
2013-07-08 17:48:29 -04:00
|
|
|
if menu.texturepack ~= nil and gamedetails ~= nil then
|
2013-07-07 15:53:40 -04:00
|
|
|
local path = menu.basetexturedir ..
|
|
|
|
gamedetails.id .. "_menu_" .. identifier .. ".png"
|
|
|
|
|
|
|
|
if engine.set_background(identifier,path) then
|
|
|
|
texture_set = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-08 17:48:29 -04:00
|
|
|
if not texture_set and gamedetails ~= nil then
|
2013-07-07 15:53:40 -04:00
|
|
|
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
|
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
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)
|
|
|
|
|
|
|
|
--background
|
2013-07-07 15:53:40 -04:00
|
|
|
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
|
2013-06-23 12:30:21 -04:00
|
|
|
end
|
|
|
|
|
2013-07-07 15:53:40 -04:00
|
|
|
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
|
2013-06-23 12:30:21 -04:00
|
|
|
|
2013-07-07 15:53:40 -04:00
|
|
|
if not background_set then
|
|
|
|
engine.set_clouds(true)
|
|
|
|
end
|
2013-06-23 12:30:21 -04:00
|
|
|
|
2013-07-07 15:53:40 -04:00
|
|
|
menu.set_texture("overlay",gamedetails)
|
|
|
|
menu.set_texture("header",gamedetails)
|
|
|
|
menu.set_texture("footer",gamedetails)
|
2013-06-23 12:30:21 -04:00
|
|
|
|
|
|
|
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()
|
|
|
|
menu.game_last_check = nil
|
2013-07-08 17:48:29 -04:00
|
|
|
|
|
|
|
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)
|
2013-06-23 12:30:21 -04:00
|
|
|
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
|
|
|
|
gamedata.worldindex = 0
|
|
|
|
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()
|
|
|
|
|
|
|
|
local formspec = "size[12,5.2]"
|
|
|
|
|
|
|
|
-- handle errors
|
|
|
|
if gamedata.errormessage ~= nil then
|
|
|
|
formspec = formspec ..
|
|
|
|
"field[1,2;10,2;;ERROR: " ..
|
|
|
|
gamedata.errormessage ..
|
|
|
|
";]"..
|
|
|
|
"button[4.5,4.2;3,0.5;btn_error_confirm;Ok]"
|
|
|
|
else
|
|
|
|
formspec = formspec .. tabbuilder.gettab()
|
|
|
|
end
|
|
|
|
|
|
|
|
engine.update_formspec(formspec)
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function menu.filtered_game_list()
|
|
|
|
local retval = ""
|
|
|
|
|
|
|
|
local current_game = menu.lastgame()
|
|
|
|
|
|
|
|
for i=1,#menu.worldlist,1 do
|
|
|
|
if menu.worldlist[i].gameid == current_game.id then
|
|
|
|
if retval ~= "" then
|
|
|
|
retval = retval ..","
|
|
|
|
end
|
|
|
|
|
|
|
|
retval = retval .. menu.worldlist[i].name ..
|
2013-07-07 15:53:40 -04:00
|
|
|
" \\[" .. menu.worldlist[i].gameid .. "\\]"
|
2013-06-23 12:30:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return retval
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function menu.filtered_game_list_raw()
|
|
|
|
local retval = {}
|
|
|
|
|
|
|
|
local current_game = menu.lastgame()
|
|
|
|
|
|
|
|
for i=1,#menu.worldlist,1 do
|
|
|
|
if menu.worldlist[i].gameid == current_game.id then
|
|
|
|
table.insert(retval,menu.worldlist[i])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return retval
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function menu.filtered_index_to_plain(filtered_index)
|
|
|
|
|
|
|
|
local current_game = menu.lastgame()
|
|
|
|
|
|
|
|
local temp_idx = 0
|
|
|
|
|
2013-07-08 15:02:42 -04:00
|
|
|
if menu.worldlist == nil then
|
|
|
|
return -1
|
|
|
|
end
|
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
for i=1,#menu.worldlist,1 do
|
|
|
|
if menu.worldlist[i].gameid == current_game.id then
|
|
|
|
temp_idx = temp_idx +1
|
|
|
|
end
|
|
|
|
|
|
|
|
if temp_idx == filtered_index then
|
|
|
|
return i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return -1
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function menu.init()
|
|
|
|
--init menu data
|
|
|
|
gamemgr.update_gamelist()
|
|
|
|
|
|
|
|
menu.worldlist = engine.get_worlds()
|
|
|
|
|
|
|
|
menu.last_world = tonumber(engine.setting_get("main_menu_last_world_idx"))
|
|
|
|
menu.last_game = tonumber(engine.setting_get("main_menu_last_game_idx"))
|
|
|
|
|
|
|
|
if type(menu.last_world) ~= "number" then
|
|
|
|
menu.last_world = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if type(menu.last_game) ~= "number" then
|
|
|
|
menu.last_game = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if engine.setting_getbool("public_serverlist") then
|
|
|
|
menu.favorites = engine.get_favorites("online")
|
|
|
|
else
|
|
|
|
menu.favorites = engine.get_favorites("local")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-07-07 15:53:40 -04:00
|
|
|
menu.defaulttexturedir = engine.get_gamepath() .. DIR_DELIM .. ".." ..
|
2013-06-23 12:30:21 -04:00
|
|
|
DIR_DELIM .. "textures" .. DIR_DELIM .. "base" ..
|
|
|
|
DIR_DELIM .. "pack" .. DIR_DELIM
|
2013-07-07 15:53:40 -04:00
|
|
|
menu.basetexturedir = menu.defaulttexturedir
|
|
|
|
|
|
|
|
menu.texturepack = engine.setting_get("texture_path")
|
|
|
|
|
|
|
|
if menu.texturepack ~= nil then
|
|
|
|
menu.basetexturedir = menu.texturepack .. DIR_DELIM
|
|
|
|
end
|
2013-06-23 12:30:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function menu.lastgame()
|
|
|
|
if menu.last_game > 0 and menu.last_game <= #gamemgr.games then
|
|
|
|
return gamemgr.games[menu.last_game]
|
|
|
|
end
|
|
|
|
|
|
|
|
if #gamemgr.games >= 1 then
|
|
|
|
menu.last_game = 1
|
|
|
|
return gamemgr.games[menu.last_game]
|
|
|
|
end
|
|
|
|
|
|
|
|
--error case!!
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function menu.lastworld()
|
|
|
|
if menu.last_world ~= nil and
|
|
|
|
menu.last_world > 0 and
|
|
|
|
menu.last_world <= #menu.worldlist then
|
|
|
|
return menu.worldlist[menu.last_world]
|
|
|
|
end
|
|
|
|
|
|
|
|
if #menu.worldlist >= 1 then
|
|
|
|
menu.last_world = 1
|
|
|
|
return menu.worldlist[menu.last_world]
|
|
|
|
end
|
|
|
|
|
|
|
|
--error case!!
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function menu.update_last_game(world_idx)
|
|
|
|
if gamedata.selected_world <= #menu.worldlist then
|
|
|
|
local world = menu.worldlist[gamedata.selected_world]
|
|
|
|
|
2013-07-08 15:02:42 -04:00
|
|
|
if world == nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
for i=1,#gamemgr.games,1 do
|
|
|
|
if gamemgr.games[i].id == world.gameid then
|
|
|
|
menu.last_game = i
|
|
|
|
engine.setting_set("main_menu_last_game_idx",menu.last_game)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
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()
|
2013-07-07 15:53:40 -04:00
|
|
|
menubar.formspec = "box[-0.3,5.625;12.4,1.3;000000]" ..
|
|
|
|
"box[-0.3,5.6;12.4,0.05;FFFFFF]"
|
2013-06-23 12:30:21 -04:00
|
|
|
menubar.buttons = {}
|
|
|
|
|
2013-07-07 15:53:40 -04:00
|
|
|
local button_base = -0.25
|
2013-06-23 12:30:21 -04:00
|
|
|
|
|
|
|
local maxbuttons = #gamemgr.games
|
|
|
|
|
2013-07-07 15:53:40 -04:00
|
|
|
if maxbuttons > 10 then
|
|
|
|
maxbuttons = 10
|
2013-06-23 12:30:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
for i=1,maxbuttons,1 do
|
|
|
|
|
|
|
|
local btn_name = "menubar_btn_" .. gamemgr.games[i].id
|
2013-07-07 15:53:40 -04:00
|
|
|
local buttonpos = button_base + (i-1) * 1.245
|
2013-06-23 12:30:21 -04:00
|
|
|
if gamemgr.games[i].menuicon_path ~= nil and
|
|
|
|
gamemgr.games[i].menuicon_path ~= "" then
|
|
|
|
|
|
|
|
menubar.formspec = menubar.formspec ..
|
2013-07-07 15:53:40 -04:00
|
|
|
"image_button[" .. buttonpos .. ",5.7;1.3,1.3;" ..
|
2013-06-23 12:30:21 -04:00
|
|
|
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 ..
|
2013-07-07 15:53:40 -04:00
|
|
|
"image_button[" .. buttonpos .. ",5.7;1.3,1.3;;" ..btn_name ..
|
2013-06-23 12:30:21 -04:00
|
|
|
";" .. text .. ";true;true]"
|
|
|
|
end
|
|
|
|
|
|
|
|
local toadd = {
|
|
|
|
btn_name = btn_name,
|
|
|
|
index = i,
|
|
|
|
}
|
|
|
|
|
|
|
|
table.insert(menubar.buttons,toadd)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.dialog_create_world()
|
2013-07-03 01:25:26 -04:00
|
|
|
local mapgens = {"v6", "v7", "indev", "singlenode", "math"}
|
|
|
|
|
|
|
|
local current_mg = engine.setting_get("mg_name")
|
|
|
|
|
|
|
|
local mglist = ""
|
|
|
|
local selindex = 1
|
|
|
|
local i = 1
|
|
|
|
for k,v in pairs(mapgens) do
|
|
|
|
if current_mg == v then
|
|
|
|
selindex = i
|
|
|
|
end
|
|
|
|
i = i + 1
|
|
|
|
mglist = mglist .. v .. ","
|
|
|
|
end
|
|
|
|
mglist = mglist:sub(1, -2)
|
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
local retval =
|
|
|
|
"label[2,0;World name]"..
|
|
|
|
"label[2,1;Mapgen]"..
|
|
|
|
"field[4.5,0.4;6,0.5;te_world_name;;]" ..
|
|
|
|
"label[2,2;Game]"..
|
|
|
|
"button[5,4.5;2.6,0.5;world_create_confirm;Create]" ..
|
|
|
|
"button[7.5,4.5;2.8,0.5;world_create_cancel;Cancel]" ..
|
2013-07-03 01:25:26 -04:00
|
|
|
"dropdown[4.2,1;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
|
2013-06-23 12:30:21 -04:00
|
|
|
"textlist[4.2,1.9;5.8,2.3;games;" ..
|
|
|
|
gamemgr.gamelist() ..
|
|
|
|
";" .. menu.last_game .. ";true]"
|
|
|
|
|
|
|
|
return retval
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.dialog_delete_world()
|
|
|
|
return "label[2,2;Delete World \"" .. menu.lastworld().name .. "\"?]"..
|
|
|
|
"button[3.5,4.2;2.6,0.5;world_delete_confirm;Yes]" ..
|
|
|
|
"button[6,4.2;2.8,0.5;world_delete_cancel;No]"
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.gettab()
|
|
|
|
local retval = ""
|
|
|
|
|
|
|
|
if tabbuilder.show_buttons then
|
|
|
|
retval = retval .. tabbuilder.tab_header()
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "singleplayer" then
|
|
|
|
retval = retval .. tabbuilder.tab_singleplayer()
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "multiplayer" then
|
|
|
|
retval = retval .. tabbuilder.tab_multiplayer()
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "server" then
|
|
|
|
retval = retval .. tabbuilder.tab_server()
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "settings" then
|
|
|
|
retval = retval .. tabbuilder.tab_settings()
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "credits" then
|
|
|
|
retval = retval .. tabbuilder.tab_credits()
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "dialog_create_world" then
|
|
|
|
retval = retval .. tabbuilder.dialog_create_world()
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "dialog_delete_world" then
|
|
|
|
retval = retval .. tabbuilder.dialog_delete_world()
|
|
|
|
end
|
|
|
|
|
|
|
|
retval = retval .. modmgr.gettab(tabbuilder.current_tab)
|
|
|
|
retval = retval .. gamemgr.gettab(tabbuilder.current_tab)
|
|
|
|
retval = retval .. modstore.gettab(tabbuilder.current_tab)
|
|
|
|
|
|
|
|
return retval
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.handle_create_world_buttons(fields)
|
|
|
|
|
2013-07-08 15:02:42 -04:00
|
|
|
if fields["world_create_confirm"] or
|
|
|
|
fields["key_enter"] then
|
2013-06-23 12:30:21 -04:00
|
|
|
|
|
|
|
local worldname = fields["te_world_name"]
|
|
|
|
local gameindex = engine.get_textlist_index("games")
|
|
|
|
|
|
|
|
if gameindex > 0 and
|
|
|
|
worldname ~= "" then
|
2013-07-07 15:53:40 -04:00
|
|
|
menu.worldlist = engine.get_worlds()
|
|
|
|
|
|
|
|
local found = false
|
|
|
|
for i=1,#menu.worldlist,1 do
|
2013-07-07 20:36:41 -04:00
|
|
|
if menu.worldlist[i].name == worldname then
|
2013-07-07 15:53:40 -04:00
|
|
|
found = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local message = nil
|
2013-06-23 12:30:21 -04:00
|
|
|
|
2013-07-07 15:53:40 -04:00
|
|
|
if not found then
|
|
|
|
engine.setting_set("mg_name",fields["dd_mapgen"])
|
|
|
|
message = engine.create_world(worldname,gameindex)
|
|
|
|
else
|
|
|
|
message = "A world named \"" .. worldname .. "\" already exists"
|
|
|
|
end
|
2013-06-23 12:30:21 -04:00
|
|
|
|
|
|
|
if message ~= nil then
|
|
|
|
gamedata.errormessage = message
|
|
|
|
else
|
2013-07-07 15:53:40 -04:00
|
|
|
menu.last_game = gameindex
|
|
|
|
engine.setting_set("main_menu_last_game_idx",gameindex)
|
2013-06-23 12:30:21 -04:00
|
|
|
menu.worldlist = engine.get_worlds()
|
|
|
|
|
|
|
|
local worldlist = menu.worldlist
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "singleplayer" then
|
|
|
|
worldlist = menu.filtered_game_list_raw()
|
|
|
|
end
|
|
|
|
|
|
|
|
local index = 0
|
|
|
|
|
|
|
|
for i=1,#worldlist,1 do
|
|
|
|
if worldlist[i].name == worldname then
|
|
|
|
index = i
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2013-07-03 01:25:26 -04:00
|
|
|
|
|
|
|
engine.setting_set("main_menu_singleplayer_world_idx", index)
|
|
|
|
menu.last_world = index
|
2013-06-23 12:30:21 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
gamedata.errormessage = "No worldname given or no game selected"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["games"] then
|
|
|
|
tabbuilder.skipformupdate = true
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
tabbuilder.is_dialog = false
|
|
|
|
tabbuilder.show_buttons = true
|
|
|
|
tabbuilder.current_tab = engine.setting_get("main_menu_tab")
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.handle_delete_world_buttons(fields)
|
|
|
|
|
|
|
|
if fields["world_delete_confirm"] then
|
|
|
|
if menu.last_world > 0 and
|
2013-07-07 15:53:40 -04:00
|
|
|
menu.last_world <= #menu.worldlist then
|
2013-06-23 12:30:21 -04:00
|
|
|
engine.delete_world(menu.last_world)
|
|
|
|
menu.worldlist = engine.get_worlds()
|
|
|
|
menu.last_world = 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tabbuilder.is_dialog = false
|
|
|
|
tabbuilder.show_buttons = true
|
|
|
|
tabbuilder.current_tab = engine.setting_get("main_menu_tab")
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.handle_multiplayer_buttons(fields)
|
2013-07-07 15:53:40 -04:00
|
|
|
|
|
|
|
if fields["te_name"] ~= nil then
|
|
|
|
gamedata.playername = fields["te_name"]
|
|
|
|
engine.setting_set("name", fields["te_name"])
|
|
|
|
end
|
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
if fields["favourites"] ~= nil then
|
|
|
|
local event = explode_textlist_event(fields["favourites"])
|
|
|
|
if event.typ == "DCL" then
|
2013-07-07 15:53:40 -04:00
|
|
|
--gamedata.address = menu.favorites[event.index].name
|
2013-06-23 12:30:21 -04:00
|
|
|
if gamedata.address == nil then
|
|
|
|
gamedata.address = menu.favorites[event.index].address
|
|
|
|
end
|
|
|
|
gamedata.port = menu.favorites[event.index].port
|
|
|
|
gamedata.playername = fields["te_name"]
|
2013-07-07 15:53:40 -04:00
|
|
|
if fields["te_pwd"] ~= nil then
|
|
|
|
gamedata.password = fields["te_pwd"]
|
|
|
|
end
|
2013-06-23 12:30:21 -04:00
|
|
|
gamedata.selected_world = 0
|
|
|
|
|
|
|
|
if gamedata.address ~= nil and
|
|
|
|
gamedata.port ~= nil then
|
|
|
|
|
|
|
|
engine.start()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if event.typ == "CHG" then
|
2013-07-08 20:21:09 -04:00
|
|
|
local address = menu.favorites[event.index].name
|
|
|
|
if address == nil then
|
|
|
|
address = menu.favorites[event.index].address
|
|
|
|
end
|
2013-06-23 12:30:21 -04:00
|
|
|
local port = menu.favorites[event.index].port
|
|
|
|
|
|
|
|
if address ~= nil and
|
|
|
|
port ~= nil then
|
|
|
|
engine.setting_set("address",address)
|
|
|
|
engine.setting_set("port",port)
|
|
|
|
end
|
2013-07-07 15:53:40 -04:00
|
|
|
|
|
|
|
menu.fav_selected = event.index
|
2013-06-23 12:30:21 -04:00
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-07-07 15:53:40 -04:00
|
|
|
if fields["key_up"] ~= nil or
|
|
|
|
fields["key_down"] ~= nil then
|
|
|
|
|
|
|
|
local fav_idx = engine.get_textlist_index("favourites")
|
|
|
|
|
|
|
|
if fields["key_up"] ~= nil and fav_idx > 1 then
|
|
|
|
fav_idx = fav_idx -1
|
|
|
|
else if fields["key_down"] and fav_idx < #menu.favorites then
|
|
|
|
fav_idx = fav_idx +1
|
|
|
|
end end
|
|
|
|
|
|
|
|
local address = menu.favorites[fav_idx].name
|
|
|
|
if address == nil then
|
|
|
|
address = menu.favorites[fav_idx].address
|
|
|
|
end
|
|
|
|
local port = menu.favorites[fav_idx].port
|
|
|
|
|
|
|
|
if address ~= nil and
|
|
|
|
port ~= nil then
|
|
|
|
engine.setting_set("address",address)
|
|
|
|
engine.setting_set("port",port)
|
|
|
|
end
|
|
|
|
|
|
|
|
menu.fav_selected = fav_idx
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
if fields["cb_public_serverlist"] ~= nil then
|
|
|
|
engine.setting_setbool("public_serverlist",
|
|
|
|
tabbuilder.tobool(fields["cb_public_serverlist"]))
|
|
|
|
|
|
|
|
if engine.setting_getbool("public_serverlist") then
|
|
|
|
menu.favorites = engine.get_favorites("online")
|
|
|
|
else
|
|
|
|
menu.favorites = engine.get_favorites("local")
|
|
|
|
end
|
2013-07-07 15:53:40 -04:00
|
|
|
|
|
|
|
return
|
2013-06-23 12:30:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if fields["btn_delete_favorite"] ~= nil then
|
|
|
|
local current_favourite = engine.get_textlist_index("favourites")
|
|
|
|
engine.delete_favorite(current_favourite)
|
|
|
|
menu.favorites = engine.get_favorites()
|
|
|
|
|
|
|
|
engine.setting_set("address","")
|
|
|
|
engine.setting_get("port","")
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-07-07 15:53:40 -04:00
|
|
|
if fields["btn_mp_connect"] ~= nil or
|
|
|
|
fields["key_enter"] then
|
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
gamedata.playername = fields["te_name"]
|
|
|
|
gamedata.password = fields["te_pwd"]
|
|
|
|
gamedata.address = fields["te_address"]
|
|
|
|
gamedata.port = fields["te_port"]
|
|
|
|
gamedata.selected_world = 0
|
2013-07-07 15:53:40 -04:00
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
engine.start()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.handle_server_buttons(fields)
|
|
|
|
|
|
|
|
local world_doubleclick = false
|
|
|
|
|
2013-07-07 15:53:40 -04:00
|
|
|
if fields["srv_worlds"] ~= nil then
|
|
|
|
local event = explode_textlist_event(fields["srv_worlds"])
|
2013-06-23 12:30:21 -04:00
|
|
|
|
2013-07-07 15:53:40 -04:00
|
|
|
if event.typ == "DCL" then
|
2013-06-23 12:30:21 -04:00
|
|
|
world_doubleclick = true
|
|
|
|
end
|
2013-07-07 15:53:40 -04:00
|
|
|
if event.typ == "CHG" then
|
|
|
|
engine.setting_set("main_menu_last_world_idx",engine.get_textlist_index("srv_worlds"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["key_up"] then
|
|
|
|
local oldidx = engine.get_textlist_index("srv_worlds")
|
|
|
|
|
|
|
|
if oldidx > 1 then
|
|
|
|
local newidx = oldidx -1
|
|
|
|
engine.setting_set("main_menu_last_world_idx",newidx)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["key_down"] then
|
|
|
|
local oldidx = engine.get_textlist_index("srv_worlds")
|
|
|
|
|
|
|
|
if oldidx < #menu.worldlist then
|
|
|
|
local newidx = oldidx + 1
|
|
|
|
engine.setting_set("main_menu_last_world_idx",newidx)
|
|
|
|
end
|
2013-06-23 12:30:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if fields["cb_creative_mode"] then
|
|
|
|
engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"]))
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["cb_enable_damage"] then
|
|
|
|
engine.setting_setbool("enable_damage",tabbuilder.tobool(fields["cb_enable_damage"]))
|
|
|
|
end
|
2013-07-07 15:53:40 -04:00
|
|
|
|
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
if fields["start_server"] ~= nil or
|
2013-07-07 15:53:40 -04:00
|
|
|
world_doubleclick or
|
|
|
|
fields["key_enter"] then
|
2013-06-23 12:30:21 -04:00
|
|
|
local selected = engine.get_textlist_index("srv_worlds")
|
|
|
|
if selected > 0 then
|
2013-07-07 15:53:40 -04:00
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
gamedata.playername = fields["te_playername"]
|
2013-07-07 15:53:40 -04:00
|
|
|
gamedata.password = fields["te_passwd"]
|
2013-06-23 12:30:21 -04:00
|
|
|
gamedata.port = fields["te_serverport"]
|
2013-07-07 15:53:40 -04:00
|
|
|
gamedata.address = ""
|
2013-06-23 12:30:21 -04:00
|
|
|
gamedata.selected_world = selected
|
|
|
|
|
|
|
|
engine.setting_set("main_menu_tab",tabbuilder.current_tab)
|
|
|
|
engine.setting_set("main_menu_last_world_idx",gamedata.selected_world)
|
|
|
|
|
|
|
|
menu.update_last_game(gamedata.selected_world)
|
|
|
|
engine.start()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["world_create"] ~= nil then
|
|
|
|
tabbuilder.current_tab = "dialog_create_world"
|
|
|
|
tabbuilder.is_dialog = true
|
|
|
|
tabbuilder.show_buttons = false
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["world_delete"] ~= nil then
|
|
|
|
local selected = engine.get_textlist_index("srv_worlds")
|
|
|
|
if selected > 0 then
|
2013-07-07 15:53:40 -04:00
|
|
|
menu.last_world = engine.get_textlist_index("srv_worlds")
|
2013-06-23 12:30:21 -04:00
|
|
|
if menu.lastworld() ~= nil and
|
|
|
|
menu.lastworld().name ~= nil and
|
|
|
|
menu.lastworld().name ~= "" then
|
|
|
|
tabbuilder.current_tab = "dialog_delete_world"
|
|
|
|
tabbuilder.is_dialog = true
|
|
|
|
tabbuilder.show_buttons = false
|
|
|
|
else
|
|
|
|
menu.last_world = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["world_configure"] ~= nil then
|
|
|
|
selected = engine.get_textlist_index("srv_worlds")
|
|
|
|
if selected > 0 then
|
|
|
|
modmgr.world_config_selected_world = selected
|
|
|
|
if modmgr.init_worldconfig() then
|
|
|
|
tabbuilder.current_tab = "dialog_configure_world"
|
|
|
|
tabbuilder.is_dialog = true
|
|
|
|
tabbuilder.show_buttons = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.tobool(text)
|
|
|
|
if text == "true" then
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
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
|
|
|
|
if fields["cb_3d_clouds"] then
|
|
|
|
engine.setting_setbool("enable_3d_clouds",tabbuilder.tobool(fields["cb_3d_clouds"]))
|
|
|
|
end
|
|
|
|
if fields["cb_opaque_water"] then
|
|
|
|
engine.setting_setbool("opaque_water",tabbuilder.tobool(fields["cb_opaque_water"]))
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["cb_mipmapping"] then
|
|
|
|
engine.setting_setbool("mip_map",tabbuilder.tobool(fields["cb_mipmapping"]))
|
|
|
|
end
|
|
|
|
if fields["cb_anisotrophic"] then
|
|
|
|
engine.setting_setbool("anisotropic_filter",tabbuilder.tobool(fields["cb_anisotrophic"]))
|
|
|
|
end
|
|
|
|
if fields["cb_bilinear"] then
|
|
|
|
engine.setting_setbool("bilinear_filter",tabbuilder.tobool(fields["cb_bilinear"]))
|
|
|
|
end
|
|
|
|
if fields["cb_trilinear"] then
|
|
|
|
engine.setting_setbool("trilinear_filter",tabbuilder.tobool(fields["cb_trilinear"]))
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["cb_shaders"] then
|
|
|
|
engine.setting_setbool("enable_shaders",tabbuilder.tobool(fields["cb_shaders"]))
|
|
|
|
end
|
|
|
|
if fields["cb_pre_ivis"] then
|
|
|
|
engine.setting_setbool("preload_item_visuals",tabbuilder.tobool(fields["cb_pre_ivis"]))
|
|
|
|
end
|
|
|
|
if fields["cb_particles"] then
|
|
|
|
engine.setting_setbool("enable_particles",tabbuilder.tobool(fields["cb_particles"]))
|
|
|
|
end
|
|
|
|
if fields["cb_finite_liquid"] then
|
|
|
|
engine.setting_setbool("liquid_finite",tabbuilder.tobool(fields["cb_finite_liquid"]))
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["btn_change_keys"] ~= nil then
|
|
|
|
engine.show_keys_menu()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.handle_singleplayer_buttons(fields)
|
|
|
|
|
|
|
|
local world_doubleclick = false
|
|
|
|
|
|
|
|
if fields["sp_worlds"] ~= nil then
|
|
|
|
local event = explode_textlist_event(fields["sp_worlds"])
|
|
|
|
|
|
|
|
if event.typ == "DCL" then
|
|
|
|
world_doubleclick = true
|
|
|
|
end
|
2013-07-07 15:53:40 -04:00
|
|
|
|
|
|
|
if event.typ == "CHG" then
|
|
|
|
engine.setting_set("main_menu_singleplayer_world_idx",engine.get_textlist_index("sp_worlds"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["key_up"] then
|
|
|
|
local oldidx = engine.get_textlist_index("sp_worlds")
|
|
|
|
|
|
|
|
if oldidx > 1 then
|
|
|
|
local newidx = oldidx -1
|
|
|
|
engine.setting_set("main_menu_singleplayer_world_idx",newidx)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["key_down"] then
|
|
|
|
local oldidx = engine.get_textlist_index("sp_worlds")
|
|
|
|
|
|
|
|
if oldidx < #menu.filtered_game_list_raw() then
|
|
|
|
local newidx = oldidx + 1
|
|
|
|
engine.setting_set("main_menu_singleplayer_world_idx",newidx)
|
|
|
|
end
|
2013-06-23 12:30:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if fields["cb_creative_mode"] then
|
|
|
|
engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"]))
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["cb_enable_damage"] then
|
|
|
|
engine.setting_setbool("enable_damage",tabbuilder.tobool(fields["cb_enable_damage"]))
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["play"] ~= nil or
|
2013-07-07 15:53:40 -04:00
|
|
|
world_doubleclick or
|
|
|
|
fields["key_enter"] then
|
2013-06-23 12:30:21 -04:00
|
|
|
local selected = engine.get_textlist_index("sp_worlds")
|
|
|
|
if selected > 0 then
|
|
|
|
gamedata.selected_world = menu.filtered_index_to_plain(selected)
|
|
|
|
gamedata.singleplayer = true
|
2013-07-03 01:25:26 -04:00
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
engine.setting_set("main_menu_tab",tabbuilder.current_tab)
|
|
|
|
engine.setting_set("main_menu_singleplayer_world_idx",selected)
|
|
|
|
|
|
|
|
menu.update_last_game(gamedata.selected_world)
|
|
|
|
|
|
|
|
engine.start()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["world_create"] ~= nil then
|
|
|
|
tabbuilder.current_tab = "dialog_create_world"
|
|
|
|
tabbuilder.is_dialog = true
|
|
|
|
tabbuilder.show_buttons = false
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["world_delete"] ~= nil then
|
|
|
|
local selected = engine.get_textlist_index("sp_worlds")
|
|
|
|
if selected > 0 then
|
|
|
|
menu.last_world = menu.filtered_index_to_plain(selected)
|
|
|
|
if menu.lastworld() ~= nil and
|
|
|
|
menu.lastworld().name ~= nil and
|
|
|
|
menu.lastworld().name ~= "" then
|
|
|
|
tabbuilder.current_tab = "dialog_delete_world"
|
|
|
|
tabbuilder.is_dialog = true
|
|
|
|
tabbuilder.show_buttons = false
|
|
|
|
else
|
|
|
|
menu.last_world = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["world_configure"] ~= nil then
|
|
|
|
selected = engine.get_textlist_index("sp_worlds")
|
|
|
|
if selected > 0 then
|
|
|
|
modmgr.world_config_selected_world = menu.filtered_index_to_plain(selected)
|
|
|
|
if modmgr.init_worldconfig() then
|
|
|
|
tabbuilder.current_tab = "dialog_configure_world"
|
|
|
|
tabbuilder.is_dialog = true
|
|
|
|
tabbuilder.show_buttons = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.tab_header()
|
|
|
|
|
|
|
|
if tabbuilder.last_tab_index == nil then
|
|
|
|
tabbuilder.last_tab_index = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
local toadd = ""
|
|
|
|
|
|
|
|
for i=1,#tabbuilder.current_buttons,1 do
|
|
|
|
|
|
|
|
if toadd ~= "" then
|
|
|
|
toadd = toadd .. ","
|
|
|
|
end
|
|
|
|
|
|
|
|
toadd = toadd .. tabbuilder.current_buttons[i].caption
|
|
|
|
end
|
|
|
|
return "tabheader[-0.3,-0.99;main_tab;" .. toadd ..";" .. tabbuilder.last_tab_index .. ";true;false]"
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.handle_tab_buttons(fields)
|
|
|
|
|
|
|
|
if fields["main_tab"] then
|
|
|
|
local index = tonumber(fields["main_tab"])
|
|
|
|
tabbuilder.last_tab_index = index
|
|
|
|
tabbuilder.current_tab = tabbuilder.current_buttons[index].name
|
|
|
|
|
|
|
|
engine.setting_set("main_menu_tab",tabbuilder.current_tab)
|
|
|
|
end
|
|
|
|
|
|
|
|
--handle tab changes
|
|
|
|
if tabbuilder.current_tab ~= tabbuilder.old_tab then
|
|
|
|
if tabbuilder.current_tab ~= "singleplayer" then
|
|
|
|
menu.reset_gametype()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "singleplayer" then
|
|
|
|
menu.update_gametype()
|
|
|
|
end
|
|
|
|
|
|
|
|
tabbuilder.old_tab = tabbuilder.current_tab
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.init()
|
|
|
|
tabbuilder.current_tab = engine.setting_get("main_menu_tab")
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == nil or
|
|
|
|
tabbuilder.current_tab == "" then
|
|
|
|
tabbuilder.current_tab = "singleplayer"
|
|
|
|
engine.setting_set("main_menu_tab",tabbuilder.current_tab)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--initialize tab buttons
|
|
|
|
tabbuilder.last_tab = nil
|
|
|
|
tabbuilder.show_buttons = true
|
|
|
|
|
|
|
|
tabbuilder.current_buttons = {}
|
|
|
|
table.insert(tabbuilder.current_buttons,{name="singleplayer", caption="Singleplayer"})
|
|
|
|
table.insert(tabbuilder.current_buttons,{name="multiplayer", caption="Client"})
|
|
|
|
table.insert(tabbuilder.current_buttons,{name="server", caption="Server"})
|
|
|
|
table.insert(tabbuilder.current_buttons,{name="settings", caption="Settings"})
|
|
|
|
|
|
|
|
if engine.setting_getbool("main_menu_game_mgr") then
|
|
|
|
table.insert(tabbuilder.current_buttons,{name="game_mgr", caption="Games"})
|
|
|
|
end
|
|
|
|
|
|
|
|
if engine.setting_getbool("main_menu_mod_mgr") then
|
|
|
|
table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption="Mods"})
|
|
|
|
end
|
|
|
|
table.insert(tabbuilder.current_buttons,{name="credits", caption="Credits"})
|
|
|
|
|
|
|
|
|
|
|
|
for i=1,#tabbuilder.current_buttons,1 do
|
|
|
|
if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then
|
|
|
|
tabbuilder.last_tab_index = i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
menu.update_gametype()
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.tab_multiplayer()
|
2013-07-07 15:53:40 -04:00
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
local retval =
|
|
|
|
"vertlabel[0,-0.25;CLIENT]" ..
|
|
|
|
"label[1,-0.25;Favorites:]"..
|
|
|
|
"label[1,4.25;Address/Port]"..
|
|
|
|
"label[9,0;Name/Password]" ..
|
|
|
|
"field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" ..
|
|
|
|
"field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("port") .."]" ..
|
|
|
|
"button[6.45,3.95;2.25,0.5;btn_delete_favorite;Delete]" ..
|
|
|
|
"button[9,4.95;2.5,0.5;btn_mp_connect;Connect]" ..
|
|
|
|
"field[9.25,1;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" ..
|
|
|
|
"pwdfield[9.25,1.75;2.5,0.5;te_pwd;]" ..
|
|
|
|
"checkbox[1,3.6;cb_public_serverlist;Public Serverlist;" ..
|
|
|
|
dump(engine.setting_getbool("public_serverlist")) .. "]" ..
|
|
|
|
"textlist[1,0.35;7.5,3.35;favourites;"
|
|
|
|
|
|
|
|
if #menu.favorites > 0 then
|
|
|
|
retval = retval .. render_favourite(menu.favorites[1])
|
|
|
|
|
|
|
|
for i=2,#menu.favorites,1 do
|
|
|
|
retval = retval .. "," .. render_favourite(menu.favorites[i])
|
|
|
|
end
|
|
|
|
end
|
2013-07-08 20:21:09 -04:00
|
|
|
|
|
|
|
print("cfav: " .. dump(menu.fav_selected))
|
2013-07-07 15:53:40 -04:00
|
|
|
if menu.fav_selected ~= nil then
|
|
|
|
retval = retval .. ";" .. menu.fav_selected .. "]"
|
|
|
|
else
|
|
|
|
retval = retval .. ";0]"
|
|
|
|
end
|
2013-06-23 12:30:21 -04:00
|
|
|
|
|
|
|
return retval
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.tab_server()
|
2013-07-07 15:53:40 -04:00
|
|
|
local index = engine.setting_get("main_menu_last_world_idx")
|
|
|
|
|
|
|
|
if index == nil then
|
|
|
|
index = 0
|
|
|
|
end
|
|
|
|
|
2013-06-23 12:30:21 -04:00
|
|
|
local retval =
|
|
|
|
"button[4,4.15;2.6,0.5;world_delete;Delete]" ..
|
|
|
|
"button[6.5,4.15;2.8,0.5;world_create;New]" ..
|
|
|
|
"button[9.2,4.15;2.55,0.5;world_configure;Configure]" ..
|
|
|
|
"button[8.5,4.9;3.25,0.5;start_server;Start Game]" ..
|
|
|
|
"label[4,-0.25;Select World:]"..
|
|
|
|
"vertlabel[0,-0.25;START SERVER]" ..
|
|
|
|
"checkbox[0.5,0.25;cb_creative_mode;Creative Mode;" ..
|
|
|
|
dump(engine.setting_getbool("creative_mode")) .. "]"..
|
|
|
|
"checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" ..
|
|
|
|
dump(engine.setting_getbool("enable_damage")) .. "]"..
|
|
|
|
"field[0.8,2.2;3,0.5;te_playername;Name;" ..
|
|
|
|
engine.setting_get("name") .. "]" ..
|
|
|
|
"pwdfield[0.8,3.2;3,0.5;te_passwd;Password]" ..
|
|
|
|
"field[0.8,5.2;3,0.5;te_serverport;Server Port;30000]" ..
|
|
|
|
"textlist[4,0.25;7.5,3.7;srv_worlds;"
|
|
|
|
|
|
|
|
if #menu.worldlist > 0 then
|
|
|
|
retval = retval .. menu.worldlist[1].name ..
|
2013-07-07 15:53:40 -04:00
|
|
|
" \\[" .. menu.worldlist[1].gameid .. "\\]"
|
2013-06-23 12:30:21 -04:00
|
|
|
|
|
|
|
for i=2,#menu.worldlist,1 do
|
|
|
|
retval = retval .. "," .. menu.worldlist[i].name ..
|
2013-07-07 15:53:40 -04:00
|
|
|
" \\[" .. menu.worldlist[i].gameid .. "\\]"
|
2013-06-23 12:30:21 -04:00
|
|
|
end
|
|
|
|
end
|
2013-07-08 20:21:09 -04:00
|
|
|
|
|
|
|
retval = retval .. ";" .. index .. "]"
|
2013-06-23 12:30:21 -04:00
|
|
|
|
|
|
|
return retval
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.tab_settings()
|
|
|
|
return "vertlabel[0,0;SETTINGS]" ..
|
|
|
|
"checkbox[1,0.75;cb_fancy_trees;Fancy trees;" .. dump(engine.setting_getbool("new_style_leaves")) .. "]"..
|
|
|
|
"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[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")) .. "]"..
|
|
|
|
"checkbox[4,1.75;cb_bilinear;Bi-Linear Filtering;" .. dump(engine.setting_getbool("bilinear_filter")) .. "]"..
|
|
|
|
"checkbox[4,2.25;cb_trilinear;Tri-Linear Filtering;" .. dump(engine.setting_getbool("trilinear_filter")) .. "]"..
|
|
|
|
|
|
|
|
"checkbox[7.5,0.75;cb_shaders;Shaders;" .. dump(engine.setting_getbool("enable_shaders")) .. "]"..
|
|
|
|
"checkbox[7.5,1.25;cb_pre_ivis;Preload item visuals;".. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
|
|
|
|
"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]"
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.tab_singleplayer()
|
|
|
|
local index = engine.setting_get("main_menu_singleplayer_world_idx")
|
2013-07-03 01:25:26 -04:00
|
|
|
|
2013-07-08 20:21:09 -04:00
|
|
|
if index == nil then
|
2013-06-23 12:30:21 -04:00
|
|
|
index = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
return "button[4,4.15;2.6,0.5;world_delete;Delete]" ..
|
|
|
|
"button[6.5,4.15;2.8,0.5;world_create;New]" ..
|
|
|
|
"button[9.2,4.15;2.55,0.5;world_configure;Configure]" ..
|
|
|
|
"button[8.5,4.95;3.25,0.5;play;Play]" ..
|
|
|
|
"label[4,-0.25;Select World:]"..
|
|
|
|
"vertlabel[0,-0.25;SINGLE PLAYER]" ..
|
|
|
|
"checkbox[0.5,0.25;cb_creative_mode;Creative Mode;" ..
|
|
|
|
dump(engine.setting_getbool("creative_mode")) .. "]"..
|
|
|
|
"checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" ..
|
|
|
|
dump(engine.setting_getbool("enable_damage")) .. "]"..
|
|
|
|
"textlist[4,0.25;7.5,3.7;sp_worlds;" ..
|
|
|
|
menu.filtered_game_list() ..
|
|
|
|
";" .. index .. "]" ..
|
|
|
|
menubar.formspec
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.tab_credits()
|
|
|
|
return "vertlabel[0,-0.5;CREDITS]" ..
|
|
|
|
"label[0.5,3;Minetest " .. engine.get_version() .. "]" ..
|
|
|
|
"label[0.5,3.3;http://minetest.net]" ..
|
2013-07-07 15:53:40 -04:00
|
|
|
"image[0.5,1;" .. menu.defaulttexturedir .. "logo.png]" ..
|
2013-06-23 12:30:21 -04:00
|
|
|
"textlist[3.5,-0.25;8.5,5.8;list_credits;" ..
|
2013-07-07 13:54:38 -04:00
|
|
|
"#FFFF00Core Developers," ..
|
2013-06-23 12:30:21 -04:00
|
|
|
"Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
|
|
|
|
"Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,"..
|
|
|
|
"PilzAdam <pilzadam@minetest.net>," ..
|
|
|
|
"IIya Zhuravlev (thexyz) <xyz@minetest.net>,"..
|
|
|
|
"Lisa Milne (darkrose) <lisa@ltmnet.com>,"..
|
|
|
|
"Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,"..
|
|
|
|
"proller <proler@gmail.com>,"..
|
|
|
|
"sfan5 <sfan5@live.de>,"..
|
|
|
|
"kahrl <kahrl@gmx.net>,"..
|
|
|
|
","..
|
2013-07-07 13:54:38 -04:00
|
|
|
"#FFFF00Active Contributors," ..
|
2013-06-23 12:30:21 -04:00
|
|
|
"sapier,"..
|
|
|
|
"Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,"..
|
|
|
|
"Jurgen Doser (doserj) <jurgen.doser@gmail.com>,"..
|
|
|
|
"Jeija <jeija@mesecons.net>,"..
|
|
|
|
"MirceaKitsune <mirceakitsune@gmail.com>,"..
|
2013-07-07 13:54:38 -04:00
|
|
|
"ShadowNinja,"..
|
|
|
|
"dannydark <the_skeleton_of_a_child@yahoo.co.uk>,"..
|
2013-06-23 12:30:21 -04:00
|
|
|
"0gb.us <0gb.us@0gb.us>,"..
|
|
|
|
"," ..
|
2013-07-07 13:54:38 -04:00
|
|
|
"#FFFF00Previous Contributors," ..
|
2013-06-23 12:30:21 -04:00
|
|
|
"Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,"..
|
|
|
|
"Jonathan Neuschafer <j.neuschaefer@gmx.net>,"..
|
|
|
|
"Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,"..
|
|
|
|
"Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,"..
|
|
|
|
"matttpt <matttpt@gmail.com>,"..
|
|
|
|
"JacobF <queatz@gmail.com>,"..
|
|
|
|
";0;true]"
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function tabbuilder.checkretval(retval)
|
|
|
|
|
|
|
|
if retval ~= nil then
|
|
|
|
if retval.current_tab ~= nil then
|
|
|
|
tabbuilder.current_tab = retval.current_tab
|
|
|
|
end
|
|
|
|
|
|
|
|
if retval.is_dialog ~= nil then
|
|
|
|
tabbuilder.is_dialog = retval.is_dialog
|
|
|
|
end
|
|
|
|
|
|
|
|
if retval.show_buttons ~= nil then
|
|
|
|
tabbuilder.show_buttons = retval.show_buttons
|
|
|
|
end
|
|
|
|
|
|
|
|
if retval.skipformupdate ~= nil then
|
|
|
|
tabbuilder.skipformupdate = retval.skipformupdate
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- initialize callbacks
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
engine.button_handler = function(fields)
|
|
|
|
--print("Buttonhandler: tab: " .. tabbuilder.current_tab .. " fields: " .. dump(fields))
|
|
|
|
|
|
|
|
if fields["btn_error_confirm"] then
|
|
|
|
gamedata.errormessage = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local retval = modmgr.handle_buttons(tabbuilder.current_tab,fields)
|
|
|
|
tabbuilder.checkretval(retval)
|
|
|
|
|
|
|
|
retval = gamemgr.handle_buttons(tabbuilder.current_tab,fields)
|
|
|
|
tabbuilder.checkretval(retval)
|
|
|
|
|
|
|
|
retval = modstore.handle_buttons(tabbuilder.current_tab,fields)
|
|
|
|
tabbuilder.checkretval(retval)
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "dialog_create_world" then
|
|
|
|
tabbuilder.handle_create_world_buttons(fields)
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "dialog_delete_world" then
|
|
|
|
tabbuilder.handle_delete_world_buttons(fields)
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "singleplayer" then
|
|
|
|
tabbuilder.handle_singleplayer_buttons(fields)
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "multiplayer" then
|
|
|
|
tabbuilder.handle_multiplayer_buttons(fields)
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "settings" then
|
|
|
|
tabbuilder.handle_settings_buttons(fields)
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabbuilder.current_tab == "server" then
|
|
|
|
tabbuilder.handle_server_buttons(fields)
|
|
|
|
end
|
|
|
|
|
|
|
|
--tab buttons
|
|
|
|
tabbuilder.handle_tab_buttons(fields)
|
|
|
|
|
|
|
|
--menubar buttons
|
|
|
|
menubar.handle_buttons(fields)
|
|
|
|
|
|
|
|
if not tabbuilder.skipformupdate then
|
|
|
|
--update menu
|
|
|
|
update_menu()
|
|
|
|
else
|
|
|
|
tabbuilder.skipformupdate = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
engine.event_handler = function(event)
|
|
|
|
if event == "MenuQuit" then
|
|
|
|
if tabbuilder.is_dialog then
|
|
|
|
tabbuilder.is_dialog = false
|
|
|
|
tabbuilder.show_buttons = true
|
|
|
|
tabbuilder.current_tab = engine.setting_get("main_menu_tab")
|
|
|
|
update_menu()
|
|
|
|
else
|
|
|
|
engine.close()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- menu startup
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
init_globals()
|
|
|
|
menu.init()
|
|
|
|
tabbuilder.init()
|
|
|
|
menubar.refresh()
|
|
|
|
modstore.init()
|
|
|
|
update_menu()
|