better handling of exiting the color selector form

also prints a warning if the user clicked "Accept" without a color selected
This commit is contained in:
Vanessa Dannenberg 2018-08-27 19:45:34 -04:00
parent 057baacf2d
commit 62806f795e

@ -1045,20 +1045,28 @@ minetest.register_craft( {
}) })
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)
print(dump(fields))
if formname == "unifieddyes:dye_select_form" then if formname == "unifieddyes:dye_select_form" then
local player_name = player:get_player_name() local player_name = player:get_player_name()
local s1 = string.sub(minetest.serialize(fields), 11) if fields.quit then
local s3 = string.sub(s1,1, string.find(s1, '"')-1) if not fields.accept then
if s3 == "cancel" then
unifieddyes.player_selected_dye[player_name] = nil unifieddyes.player_selected_dye[player_name] = nil
return return
elseif s3 == "accept" and unifieddyes.player_selected_dye[player_name] then else
local dye = unifieddyes.player_selected_dye[player_name] local dye = unifieddyes.player_selected_dye[player_name]
if not dye then
minetest.chat_send_player(player_name, "*** Clicked \"Accept\", but no color was selected!")
return
end
unifieddyes.player_current_dye[player_name] = dye unifieddyes.player_current_dye[player_name] = dye
unifieddyes.player_selected_dye[player_name] = nil unifieddyes.player_selected_dye[player_name] = nil
minetest.chat_send_player(player_name, "*** Selected "..string.sub(dye, 5).." for the airbrush.") minetest.chat_send_player(player_name, "*** Selected "..string.sub(dye, 5).." for the airbrush.")
return return
end
else else
local s1 = string.sub(minetest.serialize(fields), 11)
local s3 = string.sub(s1,1, string.find(s1, '"')-1)
local inv = player:get_inventory() local inv = player:get_inventory()
local creative = creative and creative.is_enabled_for(player_name) local creative = creative and creative.is_enabled_for(player_name)
local dye = "dye:"..s3 local dye = "dye:"..s3