diff options
Diffstat (limited to 'src/util/base64.cpp')
0 files changed, 0 insertions, 0 deletions
local menupath = engine.get_mainmenu_path()..DIR_DELIM
local commonpath = engine.get_builtin_path()..DIR_DELIM.."common"..DIR_DELIM
dofile(menupath.."filterlist.lua")
dofile(menupath.."modmgr.lua")
dofile(menupath.."modstore.lua")
dofile(menupath.."gamemgr.lua")
dofile(menupath.."textures.lua")
dofile(menupath.."menubar.lua")
dofile(commonpath.."async_event.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!
menu = {}
local tabbuilder = {}
local worldlist = nil
--------------------------------------------------------------------------------
local function filter_texture_pack_list(list)
retval = {"None"}
for _,i in ipairs(list) do
if i~="base" then
table.insert(retval, i)
end
end
return retval
end
--------------------------------------------------------------------------------
function menu.render_favorite(spec,render_details)
local text = ""
if spec.name ~= nil then
text = text .. engine.formspec_escape(spec.name:trim())
-- if spec.description ~= nil and
-- engine.formspec_escape(spec.description):trim() ~= "" then
-- text = text .. " (" .. engine.formspec_escape(spec.description) .. ")"
-- end
else
if spec.address ~= nil then
text = text .. spec.address:trim()
if spec.port ~= nil then
text = text .. ":" .. spec.port
end
end
end
if not render_details then
return text
end
local details = ""
if spec.password == true then
details = details .. "*"
else
details = 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
details = details .. " "
local playercount = ""
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 .. engine.formspec_escape(details) .. 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 text2textlist(xpos,ypos,width,height,tl_name,textlen,text,transparency)
local textlines = engine.splittext(text,textlen)
local retval = "textlist[" .. xpos .. "," .. ypos .. ";"
.. width .. "," .. height .. ";"
.. tl_name .. ";"
for i=1, #textlines, 1 do
textlines[i] = textlines[i]:gsub("\r","")
retval = retval .. engine.formspec_escape(textlines[i]) .. ","
end
retval = retval .. ";0;"
if transparency then
retval = retval .. "true"
end
retval = retval .. "]"
return retval
end
--------------------------------------------------------------------------------
function init_globals()
--init gamedata
gamedata.worldindex = 0
worldlist = filterlist.create(
engine.get_worlds,
compare_worlds,
function(element,uid)
if element.name == uid then
return true
end
return false
end, --unique id compare fct
function(element,gameid)
if element.gameid == gameid then
return true
end
return false
end --filter fct
)
filterlist.add_sort_mechanism(worldlist,"alphabetic",sort_worlds_alphabetic)
filterlist.set_sortmode(worldlist,"alphabetic")
end
--------------------------------------------------------------------------------
function update_menu()
local formspec
-- handle errors
if gamedata.errormessage ~= nil then
formspec = "size[12,5.2,true]" ..
"textarea[1,2;10,2;;ERROR: " ..
engine.formspec_escape(gamedata.errormessage) ..
";]"..
"button[4.5,4.2;3,0.5;btn_error_confirm;" .. fgettext("Ok") .. "]"
else
formspec = tabbuilder.gettab()
end
engine.update_formspec(formspec)
end
--------------------------------------------------------------------------------
function menu.render_world_list()
local retval = ""
local current_worldlist = filterlist.get_list(worldlist)
for i,v in ipairs(current_worldlist) do
if retval ~= "" then
retval = retval ..","
end
retval = retval .. engine.formspec_escape(v.name) ..
" \\[" .. engine.formspec_escape(v.gameid) .. "\\]"
end
return retval
end
--------------------------------------------------------------------------------
function menu.render_texture_pack_list(list)
local retval = ""
for i, v in ipairs(list) do
if retval ~= "" then
retval = retval ..","
end
retval = retval .. engine.formspec_escape(v)
end
return retval
end
--------------------------------------------------------------------------------
function menu.asyncOnlineFavourites()
menu.favorites = {}
engine.handle_async(
function(param)
return engine.get_favorites("online")
end,
nil,
function(result)
menu.favorites = result
engine.event_handler("Refresh")
end
)
end
--------------------------------------------------------------------------------
function menu.init()
--init menu data
gamemgr.update_gamelist()
menu.last_game = tonumber(engine.setting_get("main_menu_last_game_idx"))
if type(menu.last_game) ~= "number" then
menu.last_game = 1
end
if engine.setting_getbool("public_serverlist") then
menu.asyncOnlineFavourites()
else
menu.favorites = engine.get_favorites("local")
end
menu.defaulttexturedir = engine.get_texturepath_share() .. DIR_DELIM .. "base" ..
DIR_DELIM .. "pack" .. DIR_DELIM
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.update_last_game()
local current_world = filterlist.get_raw_element(worldlist,
engine.setting_get("mainmenu_last_selected_world")
)
if current_world == nil then
return
end
local gamespec, i = gamemgr.find_by_gameid(current_world.gameid)
if i ~= nil then
menu.last_game = i
engine.setting_set("main_menu_last_game_idx",menu.last_game)
end
end
--------------------------------------------------------------------------------
function menu.handle_key_up_down(fields,textlist,settingname)
if fields["key_up"] then
local oldidx = engine.get_textlist_index(textlist)
if oldidx ~= nil and oldidx > 1 then
local newidx = oldidx -1
engine.setting_set(settingname,
filterlist.get_raw_index(worldlist,newidx))
end
end
if fields["key_down"] then
local oldidx = engine.get_textlist_index(textlist)
if oldidx ~= nil and oldidx < filterlist.size(worldlist) then
local newidx = oldidx + 1
engine.setting_set(settingname,
filterlist.get_raw_index(worldlist,newidx))
end
end
end
--------------------------------------------------------------------------------
function tabbuilder.dialog_create_world()
local mapgens = {"v6", "v7", "indev", "singlenode", "math"}
local current_seed = engine.setting_get("fixed_map_seed") or ""
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)
local retval =
"label[2,0;" .. fgettext("World name") .. "]"..
"field[4.5,0.4;6,0.5;te_world_name;;]" ..
"label[2,1;" .. fgettext("Seed") .. "]"..
"field[4.5,1.4;6,0.5;te_seed;;".. current_seed .. "]" ..
"label[2,2;" .. fgettext("Mapgen") .. "]"..
"dropdown[4.2,2;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
"label[2,3;" .. fgettext("Game") .. "]"..
"textlist[4.2,3;5.8,2.3;games;" .. gamemgr.gamelist() ..
";" .. menu.last_game .. ";true]" ..
"button[5,5.5;2.6,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
"button[7.5,5.5;2.8,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
return retval
end
--------------------------------------------------------------------------------
function tabbuilder.dialog_delete_world()
return "label[2,2;" ..
fgettext("Delete World \"$1\"?", filterlist.get_raw_list(worldlist)[menu.world_to_del].name) .. "]"..
"button[3.5,4.2;2.6,0.5;world_delete_confirm;" .. fgettext("Yes").. "]" ..
"button[6,4.2;2.8,0.5;world_delete_cancel;" .. fgettext("No") .. "]"
end
--------------------------------------------------------------------------------
function tabbuilder.gettab()
local tsize = tabbuilder.tabsizes[tabbuilder.current_tab] or {width=12, height=5.2}
local retval = "size[" .. tsize.width .. "," .. tsize.height .. ",true]"
if tabbuilder.show_buttons then
retval = retval .. tabbuilder.tab_header()
end
local buildfunc = tabbuilder.tabfuncs[tabbuilder.current_tab]
if buildfunc ~= nil then
retval = retval .. buildfunc()
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)
if fields["world_create_confirm"] or
fields["key_enter"] then
local worldname = fields["te_world_name"]
local gameindex = engine.get_textlist_index("games")
if gameindex ~= nil and
worldname ~= "" then
local message = nil
if not filterlist.uid_exists_raw(worldlist,worldname) then
engine.setting_set("mg_name",fields["dd_mapgen"])
message = engine.create_world(worldname,gameindex)
else
message = fgettext("A world named \"$1\" already exists", worldname)
end
engine.setting_set("fixed_map_seed", fields["te_seed"])
if message ~= nil then
gamedata.errormessage = message
else
menu.last_game = gameindex
engine.setting_set("main_menu_last_game_idx",gameindex)
filterlist.refresh(worldlist)
engine.setting_set("mainmenu_last_selected_world",
filterlist.raw_index_by_uid(worldlist,worldname))
end
else
gamedata.errormessage =
fgettext("No worldname given or no game selected")
end
end
if fields["games"] then
tabbuilder.skipformupdate = true
return
end
--close dialog
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.world_to_del > 0 and
menu.world_to_del <= #filterlist.get_raw_list(worldlist) then
engine.delete_world(menu.world_to_del)
menu.world_to_del = 0
filterlist.refresh(worldlist)
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)
if fields["te_name"] ~= nil then
gamedata.playername = fields["te_name"]
engine.setting_set("name", fields["te_name"])
end
if fields["favourites"] ~= nil then
local event = engine.explode_textlist_event(fields["favourites"])
if event.type == "DCL" then
if event.index <= #menu.favorites then
gamedata.address = menu.favorites[event.index].address
gamedata.port = menu.favorites[event.index].port
gamedata.playername = fields["te_name"]
if fields["te_pwd"] ~= nil then
gamedata.password = fields["te_pwd"]
end
gamedata.selected_world = 0
if menu.favorites ~= nil then
gamedata.servername = menu.favorites[event.index].name
gamedata.serverdescription = menu.favorites[event.index].description
end
if gamedata.address ~= nil and
gamedata.port ~= nil then
engine.setting_set("address",gamedata.address)
engine.setting_set("remote_port",gamedata.port)
engine.start()
end
end
end
if event.type == "CHG" then
if event.index <= #menu.favorites then
local address = menu.favorites[event.index].address
local port = menu.favorites[event.index].port
if address ~= nil and
port ~= nil then
engine.setting_set("address",address)
engine.setting_set("remote_port",port)
end
menu.fav_selected = event.index
end
end
return
end
if fields["key_up"] ~= nil or
fields["key_down"] ~= nil then
local fav_idx = engine.get_textlist_index("favourites")
if fav_idx ~= nil then
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
end
local address = menu.favorites[fav_idx].address
local port = menu.favorites[fav_idx].port
if address ~= nil and
port ~= nil then
engine.setting_set("address",address)
engine.setting_set("remote_port",port)
end
menu.fav_selected = fav_idx
return
end
if fields["cb_public_serverlist"] ~= nil then
engine.setting_set("public_serverlist", fields["cb_public_serverlist"])
if engine.setting_getbool("public_serverlist") then
menu.asyncOnlineFavourites()
else
menu.favorites = engine.get_favorites("local")
end
menu.fav_selected = nil
return
end
if fields["btn_delete_favorite"] ~= nil then
local current_favourite = engine.get_textlist_index("favourites")
if current_favourite == nil then return end
engine.delete_favorite(current_favourite)
menu.favorites = engine.get_favorites()
menu.fav_selected = nil
engine.setting_set("address","")
engine.setting_set("remote_port","30000")
return
end
if fields["btn_mp_connect"] ~= nil or
fields["key_enter"] ~= nil then
gamedata.playername = fields["te_name"]
gamedata.password = fields["te_pwd"]
gamedata.address = fields["te_address"]
gamedata.port = fields["te_port"]
local fav_idx = engine.get_textlist_index("favourites")
if fav_idx ~= nil and fav_idx <= #menu.favorites and
menu.favorites[fav_idx].address == fields["te_address"] and
menu.favorites[fav_idx].port == fields["te_port"] then
gamedata.servername = menu.favorites[fav_idx].name
gamedata.serverdescription = menu.favorites[fav_idx].description
else
gamedata.servername = ""
gamedata.serverdescription = ""
end
gamedata.selected_world = 0
engine.setting_set("address",fields["te_address"])
engine.setting_set("remote_port",fields["te_port"])
engine.start()
return
end
end
--------------------------------------------------------------------------------
function tabbuilder.handle_server_buttons(fields)
local world_doubleclick = false
if fields["srv_worlds"] ~= nil then
local event = engine.explode_textlist_event(fields["srv_worlds"])
if event.type == "DCL" then
world_doubleclick = true
end
if event.type == "CHG" then
engine.setting_set("mainmenu_last_selected_world",
filterlist.get_raw_index(worldlist,engine.get_textlist_index("srv_worlds")))
end
end
menu.handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world")