aboutsummaryrefslogtreecommitdiff
path: root/builtin/mainmenu/dlg_create_world.lua
blob: e9ca7799fa752464f751392d01172d39f21a366d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
--Minetest
--Copyright (C) 2014 sapier
--
--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.

local function create_world_formspec(dialogdata)
	local mapgens = core.get_mapgen_names()

	local current_seed = core.settings:get("fixed_map_seed") or ""
	local current_mg   = core.settings: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 gameid = core.settings:get("menu_last_game")
	
	local game, gameidx = nil , 0
	if gameid ~= nil then
		game, gameidx = gamemgr.find_by_gameid(gameid)
		
		if gameidx == nil then
			gameidx = 0
		end
	end

	current_seed = core.formspec_escape(current_seed)
	local retval =
		"size[11.5,6.5,true]" ..
		"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() ..
		";" .. gameidx .. ";true]" ..

		"button[3.25,6;2.5,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
		"button[5.75,6;2.5,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
		
	if #gamemgr.games == 0 then
		retval = retval .. "box[2,4;8,1;#ff8800]label[2.25,4;" ..
				fgettext("You have no subgames installed.") .. "]label[2.25,4.4;" ..
				fgettext("Download one from minetest.net") .. "]"
	elseif #gamemgr.games == 1 and gamemgr.games[1].id == "minimal" then
		retval = retval .. "box[1.75,4;8.7,1;#ff8800]label[2,4;" ..
				fgettext("Warning: The minimal development test is meant for developers.") .. "]label[2,4.4;" ..
				fgettext("Download a subgame, such as minetest_game, from minetest.net") .. "]"
	end

	return retval

end

local function create_world_buttonhandler(this, fields)

	if fields["world_create_confirm"] or
		fields["key_enter"] then

		local worldname = fields["te_world_name"]
		local gameindex = core.get_textlist_index("games")

		if gameindex ~= nil and
			worldname ~= "" then

			local message = nil

			core.settings:set("fixed_map_seed", fields["te_seed"])

			if not menudata.worldlist:uid_exists_raw(worldname) then
				core.settings:set("mg_name",fields["dd_mapgen"])
				message = core.create_world(worldname,gameindex)
			else
				message = fgettext("A world named \"$1\" already exists", worldname)
			end

			if message ~= nil then
				gamedata.errormessage = message
			else
				core.settings:set("menu_last_game",gamemgr.games[gameindex].id)
				if this.data.update_worldlist_filter then
					menudata.worldlist:set_filtercriteria(gamemgr.games[gameindex].id)
					mm_texture.update("singleplayer", gamemgr.games[gameindex].id)
				end
				menudata.worldlist:refresh()
				core.settings:set("mainmenu_last_selected_world",
									menudata.worldlist:raw_index_by_uid(worldname))
			end
		else
			gamedata.errormessage =
				fgettext("No worldname given or no game selected")
		end
		this:delete()
		return true
	end

	if fields["games"] then
		return true
	end
	
	if fields["world_create_cancel"] then
		this:delete()
		return true
	end

	return false
end


function create_create_world_dlg(update_worldlistfilter)
	local retval = dialog_create("sp_create_world",
					create_world_formspec,
					create_world_buttonhandler,
					nil)
	retval.update_worldlist_filter = update_worldlistfilter
	
	return retval
end
float m_last_sent_position_timer; float m_last_sent_move_precision; bool m_armor_groups_sent; v2f m_animation_range; float m_animation_speed; float m_animation_blend; bool m_animation_sent; std::map<std::string, core::vector2d<v3f> > m_bone_position; bool m_bone_position_sent; int m_attachment_parent_id; std::string m_attachment_bone; v3f m_attachment_position; v3f m_attachment_rotation; bool m_attachment_sent; }; /* PlayerSAO needs some internals exposed. */ class LagPool { float m_pool; float m_max; public: LagPool(): m_pool(15), m_max(15) {} void setMax(float new_max) { m_max = new_max; if(m_pool > new_max) m_pool = new_max; } void add(float dtime) { m_pool -= dtime; if(m_pool < 0) m_pool = 0; } bool grab(float dtime) { if(dtime <= 0) return true; if(m_pool + dtime > m_max) return false; m_pool += dtime; return true; } }; class PlayerSAO : public ServerActiveObject { public: PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_, const std::set<std::string> &privs, bool is_singleplayer); ~PlayerSAO(); ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_PLAYER; } ActiveObjectType getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; } std::string getDescription(); /* Active object <-> environment interface */ void addedToEnvironment(u32 dtime_s); void removingFromEnvironment(); bool isStaticAllowed() const; std::string getClientInitializationData(u16 protocol_version); std::string getStaticData(); bool isAttached(); void step(float dtime, bool send_recommended); void setBasePosition(const v3f &position); void setPos(v3f pos); void moveTo(v3f pos, bool continuous); void setYaw(float); void setPitch(float); /* Interaction interface */ int punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher, float time_from_last_punch); void rightClick(ServerActiveObject *clicker); s16 getHP() const; void setHP(s16 hp); s16 readDamage(); u16 getBreath() const; void setBreath(u16 breath); void setArmorGroups(const ItemGroupList &armor_groups); void setAnimation(v2f frame_range, float frame_speed, float frame_blend); void setBonePosition(std::string bone, v3f position, v3f rotation); void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation); ObjectProperties* accessObjectProperties(); void notifyObjectPropertiesModified(); void setNametagColor(video::SColor color); video::SColor getNametagColor(); /* Inventory interface */ Inventory* getInventory(); const Inventory* getInventory() const; InventoryLocation getInventoryLocation() const; std::string getWieldList() const; int getWieldIndex() const; void setWieldIndex(int i); /* PlayerSAO-specific */ void disconnected(); Player* getPlayer() { return m_player; } u16 getPeerID() const { return m_peer_id; } // Cheat prevention v3f getLastGoodPosition() const { return m_last_good_position; } float resetTimeFromLastPunch() { float r = m_time_from_last_punch; m_time_from_last_punch = 0.0; return r; } void noCheatDigStart(v3s16 p) { m_nocheat_dig_pos = p; m_nocheat_dig_time = 0; } v3s16 getNoCheatDigPos() { return m_nocheat_dig_pos; } float getNoCheatDigTime() { return m_nocheat_dig_time; } void noCheatDigEnd() { m_nocheat_dig_pos = v3s16(32767, 32767, 32767); } LagPool& getDigPool() { return m_dig_pool; } // Returns true if cheated bool checkMovementCheat(); // Other void updatePrivileges(const std::set<std::string> &privs, bool is_singleplayer) { m_privs = privs; m_is_singleplayer = is_singleplayer; } bool getCollisionBox(aabb3f *toset); bool collideWithObjects(); private: std::string getPropertyPacket(); Player *m_player; u16 m_peer_id; Inventory *m_inventory; s16 m_damage; // Cheat prevention LagPool m_dig_pool; LagPool m_move_pool; v3f m_last_good_position; float m_time_from_last_punch; v3s16 m_nocheat_dig_pos; float m_nocheat_dig_time; int m_wield_index; bool m_position_not_sent; ItemGroupList m_armor_groups; bool m_armor_groups_sent; bool m_properties_sent; struct ObjectProperties m_prop; // Cached privileges for enforcement std::set<std::string> m_privs; bool m_is_singleplayer; v2f m_animation_range; float m_animation_speed; float m_animation_blend; bool m_animation_sent; std::map<std::string, core::vector2d<v3f> > m_bone_position; // Stores position and rotation for each bone name bool m_bone_position_sent; int m_attachment_parent_id; std::string m_attachment_bone; v3f m_attachment_position; v3f m_attachment_rotation; bool m_attachment_sent; video::SColor m_nametag_color; bool m_nametag_sent; public: float m_physics_override_speed; float m_physics_override_jump; float m_physics_override_gravity; bool m_physics_override_sneak; bool m_physics_override_sneak_glitch; bool m_physics_override_sent; }; #endif