aboutsummaryrefslogtreecommitdiff
path: root/src/client/content_cao.cpp
Commit message (Expand)AuthorAge
...
* Fix rotation of attached particlespawnerPedro Gimeno2019-08-31
* Disable autoforward if player is deadANAND2019-08-20
* Merge pull request #8776 from osjc/FixGetNodeJozef Behran2019-08-10
* ContentCAO: Fix broken attachments on join (#8701)SmallJoker2019-07-29
* Fix persistent ^[brighten after damage again (#5739)SmallJoker2019-05-26
* Optimize string (mis)handling (#8128)Jozef Behran2019-05-18
* Attend to review, re-arrange blank lines, update lua_api.txtparamat2019-04-14
* Fix regression in automatic_face_movement_max_rotation_per_secPedro Gimeno2019-04-14
* Consistent HP and damage types (#8167)SmallJoker2019-02-10
* Use true pitch/yaw/roll rotations without loss of precision by pgimeno (#8019)Paul Ouellette2019-02-07
* Proselytize the network. Use IEEE F32 (#8030)SmallJoker2019-01-03
* Fix more transparency issues with ogles2 driver (#8005)stujones112018-12-20
* Network: Send IEEE floats (#7768)SmallJoker2018-12-13
* Add object visual type 'item' (#7870)Alex2018-12-11
* Move client-specific files to 'src/client' (#7902)Quentin Bazin2018-11-28
'n158' href='#n158'>158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "content/subgames.h"
#include "porting.h"
#include "filesys.h"
#include "settings.h"
#include "log.h"
#include "util/strfnd.h"
#include "defaultsettings.h" // for set_default_settings
#include "mapgen/mapgen.h"   // for MapgenParams
#include "util/string.h"

#ifndef SERVER
#include "client/tile.h" // getImagePath
#endif

// The maximum number of identical world names allowed
#define MAX_WORLD_NAMES 100

namespace
{

bool getGameMinetestConfig(const std::string &game_path, Settings &conf)
{
	std::string conf_path = game_path + DIR_DELIM + "minetest.conf";
	return conf.readConfigFile(conf_path.c_str());
}

}

struct GameFindPath
{
	std::string path;
	bool user_specific;
	GameFindPath(const std::string &path, bool user_specific) :
			path(path), user_specific(user_specific)
	{
	}
};

std::string getSubgamePathEnv()
{
	char *subgame_path = getenv("MINETEST_SUBGAME_PATH");
	return subgame_path ? std::string(subgame_path) : "";
}

SubgameSpec findSubgame(const std::string &id)
{
	if (id.empty())
		return SubgameSpec();
	std::string share = porting::path_share;
	std::string user = porting::path_user;

	// Get games install locations
	Strfnd search_paths(getSubgamePathEnv());

	// Get all possible paths fo game
	std::vector<GameFindPath> find_paths;
	while (!search_paths.at_end()) {
		std::string path = search_paths.next(PATH_DELIM);
		path.append(DIR_DELIM).append(id);
		find_paths.emplace_back(path, false);
		path.append("_game");
		find_paths.emplace_back(path, false);
	}

	std::string game_base = DIR_DELIM;
	game_base = game_base.append("games").append(DIR_DELIM).append(id);
	std::string game_suffixed = game_base + "_game";
	find_paths.emplace_back(user + game_suffixed, true);
	find_paths.emplace_back(user + game_base, true);
	find_paths.emplace_back(share + game_suffixed, false);
	find_paths.emplace_back(share + game_base, false);

	// Find game directory
	std::string game_path;
	bool user_game = true; // Game is in user's directory
	for (const GameFindPath &find_path : find_paths) {
		const std::string &try_path = find_path.path;
		if (fs::PathExists(try_path)) {
			game_path = try_path;
			user_game = find_path.user_specific;
			break;
		}
	}

	if (game_path.empty())
		return SubgameSpec();

	std::string gamemod_path = game_path + DIR_DELIM + "mods";

	// Find mod directories
	std::set<std::string> mods_paths;
	if (!user_game)
		mods_paths.insert(share + DIR_DELIM + "mods");
	if (user != share || user_game)
		mods_paths.insert(user + DIR_DELIM + "mods");

	// Get meta
	std::string conf_path = game_path + DIR_DELIM + "game.conf";
	Settings conf;
	conf.readConfigFile(conf_path.c_str());

	std::string game_name;
	if (conf.exists("name"))
		game_name = conf.get("name");
	else
		game_name = id;

	std::string game_author;
	if (conf.exists("author"))
		game_author = conf.get("author");

	int game_release = 0;
	if (conf.exists("release"))
		game_release = conf.getS32("release");

	std::string menuicon_path;
#ifndef SERVER
	menuicon_path = getImagePath(
			game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png");
#endif
	return SubgameSpec(id, game_path, gamemod_path, mods_paths, game_name,
			menuicon_path, game_author, game_release);
}

SubgameSpec findWorldSubgame(const std::string &world_path)
{
	std::string world_gameid = getWorldGameId(world_path, true);
	// See if world contains an embedded game; if so, use it.
	std::string world_gamepath = world_path + DIR_DELIM + "game";
	if (fs::PathExists(world_gamepath)) {
		SubgameSpec gamespec;
		gamespec.id = world_gameid;
		gamespec.path = world_gamepath;
		gamespec.gamemods_path = world_gamepath + DIR_DELIM + "mods";

		Settings conf;
		std::string conf_path = world_gamepath + DIR_DELIM + "game.conf";
		conf.readConfigFile(conf_path.c_str());

		if (conf.exists("name"))
			gamespec.name = conf.get("name");
		else
			gamespec.name = world_gameid;

		return gamespec;
	}
	return findSubgame(world_gameid);
}

std::set<std::string> getAvailableGameIds()
{
	std::set<std::string> gameids;
	std::set<std::string> gamespaths;
	gamespaths.insert(porting::path_share + DIR_DELIM + "games");
	gamespaths.insert(porting::path_user + DIR_DELIM + "games");

	Strfnd search_paths(getSubgamePathEnv());

	while (!search_paths.at_end())
		gamespaths.insert(search_paths.next(PATH_DELIM));

	for (const std::string &gamespath : gamespaths) {
		std::vector<fs::DirListNode> dirlist = fs::GetDirListing(gamespath);
		for (const fs::DirListNode &dln : dirlist) {
			if (!dln.dir)
				continue;

			// If configuration file is not found or broken, ignore game
			Settings conf;
			std::string conf_path = gamespath + DIR_DELIM + dln.name +
						DIR_DELIM + "game.conf";
			if (!conf.readConfigFile(conf_path.c_str()))
				continue;

			// Add it to result
			const char *ends[] = {"_game", NULL};
			std::string shorter = removeStringEnd(dln.name, ends);
			if (!shorter.empty())
				gameids.insert(shorter);
			else
				gameids.insert(dln.name);
		}
	}
	return gameids;
}

std::vector<SubgameSpec> getAvailableGames()
{
	std::vector<SubgameSpec> specs;
	std::set<std::string> gameids = getAvailableGameIds();
	specs.reserve(gameids.size());
	for (const auto &gameid : gameids)
		specs.push_back(findSubgame(gameid));
	return specs;
}

#define LEGACY_GAMEID "minetest"

bool getWorldExists(const std::string &world_path)
{
	return (fs::PathExists(world_path + DIR_DELIM + "map_meta.txt") ||
			fs::PathExists(world_path + DIR_DELIM + "world.mt"));
}

//! Try to get the displayed name of a world
std::string getWorldName(const std::string &world_path, const std::string &default_name)
{
	std::string conf_path = world_path + DIR_DELIM + "world.mt";
	Settings conf;
	bool succeeded = conf.readConfigFile(conf_path.c_str());
	if (!succeeded) {
		return default_name;
	}

	if (!conf.exists("world_name"))
		return default_name;
	return conf.get("world_name");
}

std::string getWorldGameId(const std::string &world_path, bool can_be_legacy)
{
	std::string conf_path = world_path + DIR_DELIM + "world.mt";
	Settings conf;
	bool succeeded = conf.readConfigFile(conf_path.c_str());
	if (!succeeded) {
		if (can_be_legacy) {
			// If map_meta.txt exists, it is probably an old minetest world
			if (fs::PathExists(world_path + DIR_DELIM + "map_meta.txt"))
				return LEGACY_GAMEID;
		}
		return "";
	}
	if (!conf.exists("gameid"))
		return "";
	// The "mesetint" gameid has been discarded
	if (conf.get("gameid") == "mesetint")
		return "minetest";
	return conf.get("gameid");
}

std::string getWorldPathEnv()
{
	char *world_path = getenv("MINETEST_WORLD_PATH");
	return world_path ? std::string(world_path) : "";
}

std::vector<WorldSpec> getAvailableWorlds()
{
	std::vector<WorldSpec> worlds;
	std::set<std::string> worldspaths;

	Strfnd search_paths(getWorldPathEnv());

	while (!search_paths.at_end())
		worldspaths.insert(search_paths.next(PATH_DELIM));

	worldspaths.insert(porting::path_user + DIR_DELIM + "worlds");
	infostream << "Searching worlds..." << std::endl;
	for (const std::string &worldspath : worldspaths) {
		infostream << "  In " << worldspath << ": ";
		std::vector<fs::DirListNode> dirvector = fs::GetDirListing(worldspath);
		for (const fs::DirListNode &dln : dirvector) {
			if (!dln.dir)
				continue;
			std::string fullpath = worldspath + DIR_DELIM + dln.name;
			std::string name = getWorldName(fullpath, dln.name);
			// Just allow filling in the gameid always for now
			bool can_be_legacy = true;
			std::string gameid = getWorldGameId(fullpath, can_be_legacy);
			WorldSpec spec(fullpath, name, gameid);
			if (!spec.isValid()) {
				infostream << "(invalid: " << name << ") ";
			} else {
				infostream << name << " ";
				worlds.push_back(spec);
			}
		}
		infostream << std::endl;
	}
	// Check old world location
	do {
		std::string fullpath = porting::path_user + DIR_DELIM + "world";
		if (!fs::PathExists(fullpath))
			break;
		std::string name = "Old World";
		std::string gameid = getWorldGameId(fullpath, true);
		WorldSpec spec(fullpath, name, gameid);
		infostream << "Old world found." << std::endl;
		worlds.push_back(spec);
	} while (false);
	infostream << worlds.size() << " found." << std::endl;
	return worlds;
}

void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
		const SubgameSpec &gamespec, bool create_world)
{
	std::string final_path = path;

	// If we're creating a new world, ensure that the path isn't already taken
	if (create_world) {
		int counter = 1;
		while (fs::PathExists(final_path) && counter < MAX_WORLD_NAMES) {
			final_path = path + "_" + std::to_string(counter);
			counter++;
		}

		if (fs::PathExists(final_path)) {
			throw BaseException("Too many similar filenames");
		}
	}

	Settings *game_settings = Settings::getLayer(SL_GAME);
	const bool new_game_settings = (game_settings == nullptr);
	if (new_game_settings) {
		// Called by main-menu without a Server instance running
		// -> create and free manually
		game_settings = Settings::createLayer(SL_GAME);
	}

	getGameMinetestConfig(gamespec.path, *game_settings);
	game_settings->removeSecureSettings();

	infostream << "Initializing world at " << final_path << std::endl;

	fs::CreateAllDirs(final_path);

	// Create world.mt if does not already exist
	std::string worldmt_path = final_path + DIR_DELIM "world.mt";
	if (!fs::PathExists(worldmt_path)) {
		Settings conf;

		conf.set("world_name", name);
		conf.set("gameid", gamespec.id);
		conf.set("backend", "sqlite3");
		conf.set("player_backend", "sqlite3");
		conf.set("auth_backend", "sqlite3");
		conf.setBool("creative_mode", g_settings->getBool("creative_mode"));
		conf.setBool("enable_damage", g_settings->getBool("enable_damage"));

		if (!conf.updateConfigFile(worldmt_path.c_str())) {
			throw BaseException("Failed to update the config file");
		}
	}

	// Create map_meta.txt if does not already exist
	std::string map_meta_path = final_path + DIR_DELIM + "map_meta.txt";
	if (!fs::PathExists(map_meta_path)) {
		verbosestream << "Creating map_meta.txt (" << map_meta_path << ")"
			      << std::endl;
		std::ostringstream oss(std::ios_base::binary);

		Settings conf;
		MapgenParams params;

		params.readParams(g_settings);
		params.writeParams(&conf);
		conf.writeLines(oss);
		oss << "[end_of_params]\n";

		fs::safeWriteToFile(map_meta_path, oss.str());
	}

	// The Settings object is no longer needed for created worlds
	if (new_game_settings)
		delete game_settings;
}
="hl opt">) 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]" .. "dropdown[4.2,1;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" .. "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 \"" .. filterlist.get_raw_list(worldlist)[menu.world_to_del].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) 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 > 0 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 = "A world named \"" .. worldname .. "\" already exists" end 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 = "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 = explode_textlist_event(fields["favourites"]) if event.typ == "DCL" 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.start() end end if event.typ == "CHG" 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("port",port) end menu.fav_selected = event.index end return end 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].address 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 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 menu.fav_selected = nil return 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() menu.fav_selected = nil engine.setting_set("address","") engine.setting_get("port","") return end if fields["btn_mp_connect"] ~= nil or fields["key_enter"] 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 > 0 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.start() return end end -------------------------------------------------------------------------------- function tabbuilder.handle_server_buttons(fields) local world_doubleclick = false if fields["srv_worlds"] ~= nil then local event = explode_textlist_event(fields["srv_worlds"]) if event.typ == "DCL" then world_doubleclick = true end if event.typ == "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") 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["cb_server_announce"] then engine.setting_setbool("server_announce",tabbuilder.tobool(fields["cb_server_announce"])) end if fields["start_server"] ~= nil or world_doubleclick or fields["key_enter"] then local selected = engine.get_textlist_index("srv_worlds") if selected > 0 then gamedata.playername = fields["te_playername"] gamedata.password = fields["te_passwd"] gamedata.port = fields["te_serverport"] gamedata.address = "" gamedata.selected_world = filterlist.get_raw_index(worldlist,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("srv_worlds") if selected > 0 and selected <= filterlist.size(worldlist) then local world = filterlist.get_list(worldlist)[selected] if world ~= nil and world.name ~= nil and world.name ~= "" then menu.world_to_del = filterlist.get_raw_index(worldlist,selected) tabbuilder.current_tab = "dialog_delete_world" tabbuilder.is_dialog = true tabbuilder.show_buttons = false else menu.world_to_del = 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 = filterlist.get_raw_index(worldlist,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["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 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 if event.typ == "CHG" then engine.setting_set("mainmenu_last_selected_world", filterlist.get_raw_index(worldlist,engine.get_textlist_index("sp_worlds"))) end end menu.handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world") 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 world_doubleclick or fields["key_enter"] then local selected = engine.get_textlist_index("sp_worlds") if selected > 0 then gamedata.selected_world = filterlist.get_raw_index(worldlist,selected) gamedata.singleplayer = true 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 and selected <= filterlist.size(worldlist) then local world = filterlist.get_list(worldlist)[selected] if world ~= nil and world.name ~= nil and world.name ~= "" then menu.world_to_del = filterlist.get_raw_index(worldlist,selected) tabbuilder.current_tab = "dialog_delete_world" tabbuilder.is_dialog = true tabbuilder.show_buttons = false else menu.world_to_del = 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 = filterlist.get_raw_index(worldlist,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.update_gametype(true) 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() local retval = "vertlabel[0,-0.25;CLIENT]" .. "label[1,-0.25;Favorites:]".. "label[1,4.25;Address/Port]".. "label[9,2.75;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") .."]" .. "checkbox[1,3.6;cb_public_serverlist;Public Serverlist;" .. dump(engine.setting_getbool("public_serverlist")) .. "]" if not engine.setting_getbool("public_serverlist") then retval = retval .. "button[6.45,3.95;2.25,0.5;btn_delete_favorite;Delete]" end retval = retval .. "button[9,4.95;2.5,0.5;btn_mp_connect;Connect]" .. "field[9.3,3.75;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" .. "pwdfield[9.3,4.5;2.5,0.5;te_pwd;]" .. "textarea[9.3,0.25;2.5,2.75;;" if menu.fav_selected ~= nil and menu.favorites[menu.fav_selected].description ~= nil then retval = retval .. fs_escape_string(menu.favorites[menu.fav_selected].description,true) end retval = retval .. ";]" .. "textlist[1,0.35;7.5,3.35;favourites;" local render_details = engine.setting_getbool("public_serverlist") if #menu.favorites > 0 then retval = retval .. menu.render_favorite(menu.favorites[1],render_details) for i=2,#menu.favorites,1 do retval = retval .. "," .. menu.render_favorite(menu.favorites[i],render_details) end end if menu.fav_selected ~= nil then retval = retval .. ";" .. menu.fav_selected .. "]" else retval = retval .. ";0]" end return retval end -------------------------------------------------------------------------------- function tabbuilder.tab_server() local index = filterlist.get_current_index(worldlist, tonumber(engine.setting_get("mainmenu_last_selected_world")) ) 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")) .. "]".. "checkbox[0.5,1.15;cb_server_announce;Public;" .. dump(engine.setting_getbool("server_announce")) .. "]".. "field[0.8,3.2;3,0.5;te_playername;Name;" .. engine.setting_get("name") .. "]" .. "pwdfield[0.8,4.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;" .. menu.render_world_list() .. ";" .. index .. "]" 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[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")) .. "]".. "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,4.25;2.25,0.5;btn_change_keys;Change keys]" end -------------------------------------------------------------------------------- function tabbuilder.tab_singleplayer() local index = filterlist.get_current_index(worldlist, tonumber(engine.setting_get("mainmenu_last_selected_world")) ) 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.render_world_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]" .. "image[0.5,1;" .. menu.defaulttexturedir .. "logo.png]" .. "textlist[3.5,-0.25;8.5,5.8;list_credits;" .. "#FFFF00Core Developers," .. "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>,".. ",".. "#FFFF00Active Contributors," .. "sapier,".. "Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,".. "Jurgen Doser (doserj) <jurgen.doser@gmail.com>,".. "Jeija <jeija@mesecons.net>,".. "MirceaKitsune <mirceakitsune@gmail.com>,".. "ShadowNinja,".. "dannydark <the_skeleton_of_a_child@yahoo.co.uk>,".. "0gb.us <0gb.us@0gb.us>,".. "," .. "#FFFF00Previous Contributors," .. "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") menu.update_gametype() update_menu() else engine.close() end 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() engine.sound_play("main_menu", true) update_menu()