diff --git a/formspec_handler.lua b/formspec_handler.lua index d3ad0b7..12d5378 100644 --- a/formspec_handler.lua +++ b/formspec_handler.lua @@ -129,6 +129,7 @@ minetest.register_on_player_receive_fields(function(player, bot_key, fields) local bot_name = bot_list[tonumber(string.split(fields.saved,":")[2])] data.fields[bot_name]=nil mod_storage:from_table(data) + --print(dump(mod_storage:to_table())) end elseif #form_parts == 2 and form_parts[1] == "rename" then -- print("Rename Bot formspec received") @@ -137,19 +138,26 @@ minetest.register_on_player_receive_fields(function(player, bot_key, fields) minetest.close_formspec(player:get_player_name(), bot_key) if fields.saved then local bot_name = bot_list[tonumber(string.split(fields.saved,":")[2])] - vbots.load(pos,player,"renameto_"..bot_name) + + parts = string.split(bot_name,",vbotsep,") + if #parts == 2 and parts[1] == player:get_player_name() then + bot_name = parts[2] + vbots.load(pos,player,"renamefrom_"..bot_name) + end + end elseif #form_parts == 2 and form_parts[1] == "renameto" then -- print("Renameto formspec received") local bot_data = vbots.bot_info[form_parts[2]] local pos=bot_data.pos - minetest.close_formspec(player:get_player_name(), bot_key) + local pname = player:get_player_name() + minetest.close_formspec(pname, bot_key) local oldname = fields.oldname local newname = fields.newname if newname and oldname then local hold = data.fields[oldname] - data.fields[oldname] = nil - data.fields[newname] = hold + data.fields[pname..",vbotsep,"..oldname] = nil + data.fields[pname..",vbotsep,"..newname] = hold mod_storage:from_table(data) -- print("renamed "..oldname.." to "..newname) end diff --git a/init.lua b/init.lua index 16ddd0f..d5cdc82 100644 --- a/init.lua +++ b/init.lua @@ -46,7 +46,7 @@ vbots.load = function(pos,player,mode) local parts for n,d in pairs(data) do parts = string.split(n,",vbotsep,") - if #parts == 2 and parts[1] == player:get_name() then + if #parts == 2 and parts[1] == player:get_player_name() then bot_list = bot_list..parts[2].."," end end @@ -55,6 +55,7 @@ vbots.load = function(pos,player,mode) local formname if not mode then formspec = "size[5,9]".. + "image_button_exit[4,8;1,1;vbots_gui_check.png;ok;]".. "image_button_exit[4,0;1,1;vbots_gui_delete.png;delete;]".. "tooltip[4,0;1,1;delete]".. "image_button_exit[4,1;1,1;vbots_gui_rename.png;rename;]".. @@ -62,18 +63,21 @@ vbots.load = function(pos,player,mode) "textlist[0,0;4,9;saved;"..bot_list.."]" formname = "loadbot,"..key elseif mode == "delete" then - formspec = "size[4,9]no_prepend[]".. + formspec = "size[5,9]no_prepend[]".. + "image_button_exit[4,8;1,1;vbots_gui_check.png;ok;]".. "bgcolor[#F00]".. "textlist[0,0;4,9;saved;"..bot_list.."]" formname = "delete,"..key elseif mode == "rename" then - formspec = "size[4,9]no_prepend[]".. + formspec = "size[5,9]no_prepend[]".. + "image_button_exit[4,8;1,1;vbots_gui_check.png;ok;]".. "bgcolor[#0F0]".. "textlist[0,0;4,9;saved;"..bot_list.."]" formname = "rename,"..key - elseif mode:sub(1,8) == "renameto" then - local fromname = mode:sub(10) - formspec = "size[5,5]no_prepend[]".. + elseif mode:sub(1,10) == "renamefrom" then + local fromname = mode:sub(12) + formspec = "size[6,6]no_prepend[]".. + "image_button_exit[5,5;1,1;vbots_gui_check.png;ok;]".. "bgcolor[#00F]".. "field[0,0;5,2;oldname;Old Name;"..fromname.."]".. "field[0,1;5,4;newname;New Name;]"