diff --git a/README.md b/README.md index e930354..be432f2 100644 --- a/README.md +++ b/README.md @@ -54,3 +54,6 @@ For this case, the NPC can be muted. This works either with the staff or by selecting the appropriate option in the talk menu after having started edit mode by claiming to be the NPC's owner. +Skin +==== +The skin and what the NPC wields can be changed via the "Edit Skin" button. diff --git a/functions.lua b/functions.lua index 7f440ea..2486ec2 100644 --- a/functions.lua +++ b/functions.lua @@ -1234,6 +1234,11 @@ local function get_fs_talkdialog(player, n_id, d_id) -- find the right index for the dialog_list dropdown above local d_id_to_dropdown_index = {} + -- allow to change skin, wielded items etc. + if(edit_mode) then + table.insert(formspec, "button[15.75,3.5;3.5,0.9;edit_skin;Edit Skin]") + end + -- display the window with the text the NPC is saying if(edit_mode and dialog and dialog.n_dialogs) then -- sort all dialogs by d_sort @@ -1281,6 +1286,7 @@ local function get_fs_talkdialog(player, n_id, d_id) table.insert(formspec, minetest.formspec_escape(active_dialog.d_text):trim()) table.insert(formspec, ";#000000;#FFFFFF]") end + table.insert(formspec, "scrollbaroptions[min=0;max=14;smallstep=1;largestep=2;arrows=show]") table.insert(formspec, "scrollbar[0.2,24.2;0.2,7;vertical;scr0;0]") table.insert(formspec, "scroll_container[0,24;56,7;scr0;vertical;1]") @@ -2693,6 +2699,15 @@ minetest.register_on_player_receive_fields( return end + -- change skin, cape and wielded items + if(edit_mode and fields.edit_skin) then + local dialog = yl_speak_up.speak_to[pname].dialog + -- necessary so that the fashin formspec can be created + yl_speak_up.speak_to[pname].n_npc = dialog.n_npc + minetest.show_formspec(pname, "yl_speak_up:fashion", yl_speak_up.get_fs_fashion(pname)) + return + end + -- start edit mode (requires npc_talk_owner) if fields.button_start_edit_mode then -- check if this particular NPC is really owned by this player or if the player has global privs @@ -3314,13 +3329,19 @@ local function create_preview(main_skin) return skin end -local function get_fs_fashion(pname) +yl_speak_up.get_fs_fashion = function(pname) local textures = yl_speak_up.speak_to[pname].textures local maintable, mainlist, mainindex = get_npc_skins(textures[2]) local capetable, capelist, capeindex = get_npc_capes(textures[1]) local preview = create_preview(textures[2]) + local button_cancel = "Cancel" + -- is this player editing this particular NPC? then rename the button + if( yl_speak_up.edit_mode[pname] + and yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id) then + button_cancel = "Back" + end local formspec = { "formspec_version[3]", "size[13.4,9.5]", @@ -3363,7 +3384,7 @@ local function get_fs_fashion(pname) "image[4.7,1;4,8;", preview, "]", - "button_exit[0.3,8.4;3,0.75;button_cancel;Cancel]", + "button_exit[0.3,8.4;3,0.75;button_cancel;"..button_cancel.."]", "button[10.1,8.4;3,0.75;button_save;Save]" } return table.concat(formspec, "") @@ -3379,16 +3400,41 @@ minetest.register_on_player_receive_fields( --fashion local textures = yl_speak_up.speak_to[pname].textures if fields then - if fields.quit or fields.button_cancel then + -- catch ESC as well + if fields.quit or fields.button_cancel or fields.button_exit then + -- is the player editing this npc? then we need to go back to the edit menu + if( yl_speak_up.edit_mode[pname] + and yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id) then + minetest.show_formspec(pname, "yl_speak_up:talk", get_fs_talkdialog(player, yl_speak_up.speak_to[pname].n_id, yl_speak_up.speak_to[pname].d_id)) + return + end yl_speak_up.speak_to[pname] = nil return end - if fields.set_cape then - textures[1] = fields.set_cape + -- only change cape if there really is a diffrent one selected + if fields.set_cape and fields.set_cape ~= textures[1] then + -- only set the cape if it is part of the list of allowed capes + local capetable, capelist, capeindex = get_npc_capes(textures[1]) + for _, v in pairs(capetable) do + if(v == fields.set_cape) then + textures[1] = fields.set_cape + -- we have found it + break + end + end end - if fields.set_skin then - textures[2] = fields.set_skin + -- only change the skin if there really is a diffrent new one selected + if fields.set_skin and fields.set_skin ~= textures[2] then + -- only set the skin if it is part of the list of allowed skins + local maintable, mainlist, mainindex = get_npc_skins(textures[2]) + for _, v in pairs(maintable) do + if(v == fields.set_skin) then + textures[2] = fields.set_skin + -- we have found it + break + end + end end if fields.set_shield then textures[3] = fields.set_shield @@ -3409,7 +3455,7 @@ minetest.register_on_player_receive_fields( --fashion --yl_speak_up.speak_to[pname].textures = textures end - minetest.show_formspec(pname, "yl_speak_up:fashion", get_fs_fashion(pname)) + minetest.show_formspec(pname, "yl_speak_up:fashion", yl_speak_up.get_fs_fashion(pname)) end ) @@ -3434,7 +3480,7 @@ function yl_speak_up.fashion(player, obj) yl_speak_up.speak_to[pname].n_npc = "Unknown" end - minetest.show_formspec(pname, "yl_speak_up:fashion", get_fs_fashion(pname)) + minetest.show_formspec(pname, "yl_speak_up:fashion", yl_speak_up.get_fs_fashion(pname)) end