From b695c388e9b3ded981692bca9f405da9f8714699 Mon Sep 17 00:00:00 2001 From: Zughy <4279489-marco_a@users.noreply.gitlab.com> Date: Mon, 31 Aug 2020 01:29:32 +0200 Subject: [PATCH] Editor: arenas can be now renamed via editor (new section: settings) --- _editor/editor_icons.lua | 21 +++++ _editor/editor_main.lua | 2 +- _editor/tools_settings.lua | 91 +++++++++++++++++++++ _editor/tools_spawner.lua | 3 +- api.lua | 7 +- init.lua | 1 + locale/arena_lib.it.tr | 4 + locale/template.txt | 4 + player_manager.lua | 27 ++++++ textures/arenalib_editor_settings.png | Bin 0 -> 191 bytes textures/arenalib_tool_settings_rename.png | Bin 0 -> 132 bytes 11 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 _editor/tools_settings.lua create mode 100644 textures/arenalib_editor_settings.png create mode 100644 textures/arenalib_tool_settings_rename.png diff --git a/_editor/editor_icons.lua b/_editor/editor_icons.lua index 4764c61..93b69f9 100644 --- a/_editor/editor_icons.lua +++ b/_editor/editor_icons.lua @@ -78,6 +78,27 @@ minetest.register_tool("arena_lib:editor_signs", { +minetest.register_tool("arena_lib:editor_settings", { + + description = S("Settings"), + inventory_image = "arenalib_editor_settings.png", + groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"}, + on_place = function() end, + on_drop = function() end, + + on_use = function(itemstack, user) + + arena_lib.HUD_send_msg("hotbar", user:get_player_name(), S("Arena settings")) + + minetest.after(0, function() + arena_lib.give_settings_tools(user) + end) + end + +}) + + + minetest.register_tool("arena_lib:editor_info", { description = S("Info"), diff --git a/_editor/editor_main.lua b/_editor/editor_main.lua index c4e2c49..46e9f3c 100644 --- a/_editor/editor_main.lua +++ b/_editor/editor_main.lua @@ -5,7 +5,7 @@ local editor_tools = { "arena_lib:editor_players", "arena_lib:editor_spawners", "arena_lib:editor_signs", - "", + "arena_lib:editor_settings", "", "arena_lib:editor_info", "arena_lib:editor_enable", diff --git a/_editor/tools_settings.lua b/_editor/tools_settings.lua new file mode 100644 index 0000000..cdddefd --- /dev/null +++ b/_editor/tools_settings.lua @@ -0,0 +1,91 @@ +local S = minetest.get_translator("arena_lib") + +local function get_rename_formspec() end +local function get_properties_formspec() end + +local settings_tools = { + "arena_lib:settings_rename", + --"arena_lib:settings_properties", + "", + "", + "", + "", + "", + "arena_lib:editor_return", + "arena_lib:editor_quit", +} + + + + + +minetest.register_tool("arena_lib:settings_rename", { + + description = S("Rename arena"), + inventory_image = "arenalib_tool_settings_rename.png", + groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"}, + on_place = function() end, + on_drop = function() end, + + on_use = function(itemstack, user, pointed_thing) + local p_name = user:get_player_name() + minetest.show_formspec(p_name, "arena_lib:settings_rename", get_rename_formspec(p_name)) + end +}) + + + +minetest.register_tool("arena_lib:settings_properties", { + + description = S("Arena properties"), + inventory_image = "arenalib_tool_settings_editor.png", + groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"}, + on_place = function() end, + on_drop = function() end, + + on_use = function(itemstack, user, pointed_thing) + local p_name = user:get_player_name() + minetest.show_formspec(p_name, "arena_lib:settings_properties", get_properties_formspec(p_name)) + end +}) + + + +function arena_lib.give_settings_tools(user) + user:get_inventory():set_list("main", settings_tools) +end + + + + + +---------------------------------------------- +---------------FUNZIONI LOCALI---------------- +---------------------------------------------- + +function get_properties_formspec(p_name) + + local formspec = { + "size[6,4]" + } + + return table.concat(formspec, "") + +end + + + +function get_rename_formspec(p_name) + + local formspec = { + "size[5.2,0.4]", + "no_prepend[]", + "bgcolor[;neither]", + "field[0.2,0.25;4,1;rename;;]", + "button[3.8,-0.05;1.5,1;rename_confirm;Rename Arena]", + "field_close_on_enter[rename;false]" + } + + return table.concat(formspec, "") + +end diff --git a/_editor/tools_spawner.lua b/_editor/tools_spawner.lua index cca36d3..f8edcfc 100644 --- a/_editor/tools_spawner.lua +++ b/_editor/tools_spawner.lua @@ -1,6 +1,7 @@ +local S = minetest.get_translator("arena_lib") + local function change_spawner_ID() end -local S = minetest.get_translator("arena_lib") local spawners_tools_team = { "arena_lib:spawner_team_add", "arena_lib:spawner_team_remove", diff --git a/api.lua b/api.lua index 22e2aee..9bfc3cb 100644 --- a/api.lua +++ b/api.lua @@ -324,11 +324,13 @@ end -function arena_lib.rename_arena(sender, mod, arena_name, new_name) +function arena_lib.rename_arena(sender, mod, arena_name, new_name, in_editor) local id, arena = arena_lib.get_arena_by_name(mod, arena_name) - if not ARENA_LIB_EDIT_PRECHECKS_PASSED(sender, arena) then return end + if not in_editor then + if not ARENA_LIB_EDIT_PRECHECKS_PASSED(sender, arena) then return end + end -- se esiste già un'arena con il nuovo nome, annullo if arena_lib.get_arena_by_name(mod, new_name) then @@ -347,6 +349,7 @@ function arena_lib.rename_arena(sender, mod, arena_name, new_name) update_storage(false, mod, id, arena) minetest.chat_send_player(sender, S("Arena @1 successfully renamed in @2", old_name, new_name)) + return true end diff --git a/init.lua b/init.lua index 09ce257..b79a937 100644 --- a/init.lua +++ b/init.lua @@ -14,6 +14,7 @@ dofile(minetest.get_modpath("arena_lib") .. "/_dependencies/parties.lua") dofile(minetest.get_modpath("arena_lib") .. "/_editor/editor_main.lua") dofile(minetest.get_modpath("arena_lib") .. "/_editor/editor_icons.lua") dofile(minetest.get_modpath("arena_lib") .. "/_editor/tools_players.lua") +dofile(minetest.get_modpath("arena_lib") .. "/_editor/tools_settings.lua") dofile(minetest.get_modpath("arena_lib") .. "/_editor/tools_sign.lua") dofile(minetest.get_modpath("arena_lib") .. "/_editor/tools_spawner.lua") dofile(minetest.get_modpath("arena_lib") .. "/_hud/hud_main.lua") diff --git a/locale/arena_lib.it.tr b/locale/arena_lib.it.tr index 1632520..aaee177 100644 --- a/locale/arena_lib.it.tr +++ b/locale/arena_lib.it.tr @@ -163,6 +163,10 @@ Change the current number=Cambia il numero attuale Teams: on (click to toggle off)=Squadre: attive (premi per disattivare) Teams: off (click to toggle on)=Squadre: non attive (premi per attivare) +# _editor/tools_settings.lua +Rename arena=Rinomina arena +Arena properties=Proprietà arena + # _editor/tools_spawner.lua Add spawner=Aggiungi spawner Remove spawner=Rimuovi spawner diff --git a/locale/template.txt b/locale/template.txt index 9835492..71280ab 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -163,6 +163,10 @@ Change the current number= Teams: on (click to toggle off)= Teams: off (click to toggle on)= +# _editor/tools_settings.lua +Rename arena= +Arena properties= + # _editor/tools_spawner.lua Add spawner= Remove spawner= diff --git a/player_manager.lua b/player_manager.lua index ea92428..111d65f 100644 --- a/player_manager.lua +++ b/player_manager.lua @@ -115,3 +115,30 @@ minetest.register_on_respawnplayer(function(player) return true end) + + + + minetest.register_on_player_receive_fields(function(player, formname, fields) + + if formname ~= "arena_lib:settings_rename" and formname ~= "arena_lib:settings_editor" then return end + + local p_name = player:get_player_name() + local mod = player:get_meta():get_string("arena_lib_editor.mod") + local arena_name = player:get_meta():get_string("arena_lib_editor.arena") + + -- GUI per rinominare arena + if formname == "arena_lib:settings_rename" then + + if fields.rename_confirm or fields.key_enter then + if arena_lib.rename_arena(p_name, mod, arena_name, fields.rename, true) then + player:get_meta():set_string("arena_lib_editor.arena", fields.rename) + minetest.close_formspec(p_name, formname) + end + end + + -- GUI per modificare proprietà + else + + end + + end) diff --git a/textures/arenalib_editor_settings.png b/textures/arenalib_editor_settings.png new file mode 100644 index 0000000000000000000000000000000000000000..30960e5bcd263ffbfae4e2268c0d6dc2c106444c GIT binary patch literal 191 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPHV5AX?b1=0pOdQAmW7EJCte{6^4 z6y}9MA;yv*zhDN3XE)M-oH$Px$B>F!x_t))4=8Z3EM&f5vS1lwBb&^N{mVMquJgUQ z!+3xteZzL{RF030nrkX`Z>`q#O3yfQOM6`z<5km3tDe0v+b(ekmHxZ;Kl6m8@|~tUWoLrc{{`B_;OXk;vd$@?2>@+2MqK~^ literal 0 HcmV?d00001 diff --git a/textures/arenalib_tool_settings_rename.png b/textures/arenalib_tool_settings_rename.png new file mode 100644 index 0000000000000000000000000000000000000000..be871de8cf60f45952cc2017e5431d19424635aa GIT binary patch literal 132 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`-kvUwAr-fh6C@-LIJm#JzsNPw z(C5v+?d$(@N-+g@^dzzgnlMBP8ntx_zGZS^Q>gCM&{vRd&~uw6UeLyQlr7*5YYk(k eb}f%G14GuO*EX9kY~2ntmci52&t;ucLK6TWk|&S= literal 0 HcmV?d00001