mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-06-16 21:58:05 +02:00
allow to select variables in manage_variables
This commit is contained in:
parent
24fd2b0df5
commit
c19e478728
@ -33,7 +33,7 @@ yl_speak_up.create_dropdown_playerlist = function(player, pname,
|
|||||||
tostring(explain_add_player).."]"
|
tostring(explain_add_player).."]"
|
||||||
else
|
else
|
||||||
text = text.."button["..tostring(start_x + 3.8 + stretch_x)..","..tostring(start_y)..
|
text = text.."button["..tostring(start_x + 3.8 + stretch_x)..","..tostring(start_y)..
|
||||||
";"..tostring(3.5 + stretch_x)..",0.9;"..
|
";"..tostring(3.4 + stretch_x)..",0.9;"..
|
||||||
tostring(field_name_for_deleting_player)..";"..
|
tostring(field_name_for_deleting_player)..";"..
|
||||||
tostring(delete_button_text).."]"..
|
tostring(delete_button_text).."]"..
|
||||||
"tooltip["..tostring(field_name_for_deleting_player)..";"..
|
"tooltip["..tostring(field_name_for_deleting_player)..";"..
|
||||||
|
126
quest_api.lua
126
quest_api.lua
@ -164,33 +164,80 @@ yl_speak_up.input_fs_manage_variables = function(player, formname, fields)
|
|||||||
yl_speak_up.show_fs(player, "manage_variables")
|
yl_speak_up.show_fs(player, "manage_variables")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
-- leave this formspec
|
||||||
|
if(fields and (fields.quit or fields.exit)) then
|
||||||
|
local last_fs = yl_speak_up.speak_to[pname][ "working_at" ]
|
||||||
|
yl_speak_up.show_fs(player, last_fs)
|
||||||
-- add a new variable?
|
-- add a new variable?
|
||||||
if(fields and fields.add_variable) then
|
elseif(fields and fields.add_variable) then
|
||||||
|
local error_msg = ""
|
||||||
if(not(fields.add_variable_name) or fields.add_variable_name == ""
|
if(not(fields.add_variable_name) or fields.add_variable_name == ""
|
||||||
or fields.add_variable_name:trim() == "") then
|
or fields.add_variable_name:trim() == "") then
|
||||||
yl_speak_up.show_fs(player, "msg", {
|
error_msg = "Please enter the name of your variable!"
|
||||||
input_to = "yl_speak_up:manage_variables",
|
-- limit names to something more sensible
|
||||||
formspec = "size[6,2]"..
|
elseif(string.len(fields.add_variable_name) > 30) then
|
||||||
"label[0.2,0.5;Please enter the name of your variable!]"..
|
error_msg = "The name of your variable name is too long.\n"..
|
||||||
"button[1.5,1.5;2,0.9;back_from_msg;Back]"})
|
"Only up to 30 characters are allowed."
|
||||||
return
|
elseif(string.len(fields.add_variable_name:trim()) < 2) then
|
||||||
end
|
error_msg = "The name of your variable name is too short.\n"..
|
||||||
-- TODO: limit names to something more sensible?
|
"It has to be at least 2 characters long."
|
||||||
fields.add_variable_name = fields.add_variable_name:trim()
|
else
|
||||||
local res = yl_speak_up.add_quest_variable(pname, fields.add_variable_name)
|
fields.add_variable_name = fields.add_variable_name:trim()
|
||||||
local text = "A new variable named\n \""..tostring(fields.add_variable_name)..
|
local res = yl_speak_up.add_quest_variable(pname, fields.add_variable_name)
|
||||||
"\"\nhas been created."
|
-- not really an error msg here - but fascilitates output
|
||||||
if(not(res)) then
|
error_msg = "A new variable named\n \""..
|
||||||
text = "Failed to create variable named\n \""..
|
minetest.formspec_escape(fields.add_variable_name)..
|
||||||
tostring(fields.add_variable_name).."\"."
|
"\"\nhas been created."
|
||||||
|
if(not(res)) then
|
||||||
|
error_msg = "Failed to create variable named\n \""..
|
||||||
|
minetest.formspec_escape(fields.add_variable_name).."\"."
|
||||||
|
else
|
||||||
|
-- slect this new variable
|
||||||
|
local var_list = yl_speak_up.get_quest_variables(pname, true)
|
||||||
|
-- make names of own variables shorter
|
||||||
|
yl_speak_up.strip_pname_from_varlist(var_list, pname)
|
||||||
|
table.sort(var_list)
|
||||||
|
local index = table.indexof(var_list, fields.add_variable_name)
|
||||||
|
if(index and index > -1) then
|
||||||
|
yl_speak_up.speak_to[pname].tmp_index_variable = index + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
yl_speak_up.show_fs(player, "msg", {
|
yl_speak_up.show_fs(player, "msg", {
|
||||||
input_to = "yl_speak_up:manage_variables",
|
input_to = "yl_speak_up:manage_variables",
|
||||||
formspec = "size[6,2]"..
|
formspec = "size[6,2]"..
|
||||||
"label[0.2,0.0;"..minetest.formspec_escape(text).."]"..
|
"label[0.2,0.0;"..error_msg.."]"..
|
||||||
"button[1.5,1.5;2,0.9;back_from_msg;Back]"})
|
"button[1.5,1.5;2,0.9;back_from_msg;Back]"})
|
||||||
return
|
return
|
||||||
|
-- show where this variable is used
|
||||||
|
elseif(fields and fields.show_var_usage and fields.show_var_usage ~= "") then
|
||||||
|
yl_speak_up.show_fs(player, "msg", {
|
||||||
|
input_to = "yl_speak_up:manage_variables",
|
||||||
|
formspec = yl_speak_up.get_list_of_usage_of_variable(
|
||||||
|
fields.list_var_names, pname, true,
|
||||||
|
"back_from_msg",
|
||||||
|
"Back to manage variables",
|
||||||
|
-- not an internal variable
|
||||||
|
false)
|
||||||
|
})
|
||||||
|
return
|
||||||
|
-- TODO: delete variable
|
||||||
|
-- a var name was selected in the dropdown list
|
||||||
|
elseif(fields and fields.list_var_names and fields.list_var_names ~= "") then
|
||||||
|
local var_list = yl_speak_up.get_quest_variables(pname, true)
|
||||||
|
-- make names of own variables shorter
|
||||||
|
yl_speak_up.strip_pname_from_varlist(var_list, pname)
|
||||||
|
table.sort(var_list)
|
||||||
|
local index = table.indexof(var_list, fields.list_var_names)
|
||||||
|
if(fields.list_var_names == "Add variable:") then
|
||||||
|
index = 0
|
||||||
|
end
|
||||||
|
if(index and index > -1) then
|
||||||
|
yl_speak_up.speak_to[pname].tmp_index_variable = index + 1
|
||||||
|
end
|
||||||
|
-- show the same formspec again, with a diffrent variable selected
|
||||||
|
yl_speak_up.show_fs(player, "manage_variables")
|
||||||
|
return
|
||||||
end
|
end
|
||||||
-- try to go back to the last formspec shown before this one
|
-- try to go back to the last formspec shown before this one
|
||||||
if(not(yl_speak_up.speak_to[pname])) then
|
if(not(yl_speak_up.speak_to[pname])) then
|
||||||
@ -202,13 +249,44 @@ end
|
|||||||
|
|
||||||
|
|
||||||
yl_speak_up.get_fs_manage_variables = function(player, param)
|
yl_speak_up.get_fs_manage_variables = function(player, param)
|
||||||
return "size[12,4]"..
|
local pname = player:get_player_name()
|
||||||
|
-- variables owned by the player - including those with write access
|
||||||
|
local var_list = yl_speak_up.get_quest_variables(pname, true)
|
||||||
|
-- make names of own variables shorter
|
||||||
|
yl_speak_up.strip_pname_from_varlist(var_list, pname)
|
||||||
|
-- the yl_speak_up.create_dropdown_playerlist function needs a table - not a list
|
||||||
|
local table_of_vars = {}
|
||||||
|
for i, k in ipairs(var_list) do
|
||||||
|
table_of_vars[ k ] = true
|
||||||
|
end
|
||||||
|
-- "Add variable:" is currently selected
|
||||||
|
local additional_buttons = ""
|
||||||
|
if(not(yl_speak_up.speak_to[pname].tmp_index_variable)
|
||||||
|
or yl_speak_up.speak_to[pname].tmp_index_variable == 1) then
|
||||||
|
yl_speak_up.speak_to[pname].tmp_index_variable = 1
|
||||||
|
additional_buttons = "button[11.4,1.9;2.5,0.9;add_variable;Create variable]"..
|
||||||
|
"tooltip[add_variable;Create a new varialbe with the name\n"..
|
||||||
|
"you entered in the field to the left.]"
|
||||||
|
else
|
||||||
|
additional_buttons = "button[11.4,1.9;2.5,0.9;show_var_usage;Where is it used?]"..
|
||||||
|
"tooltip[show_var_usage;Show which NPC use this variable in which context.]"
|
||||||
|
end
|
||||||
|
return "size[14,4]"..
|
||||||
"label[2.0,-0.2;* Manage your variables *]"..
|
"label[2.0,-0.2;* Manage your variables *]"..
|
||||||
"label[0.2,1.0;Create this new variable:]"..
|
"label[0.2,2.05;Your variables:]"..
|
||||||
"field[3.7,1.3;6.0,0.6;add_variable_name;;]"..
|
-- offer a dropdown list and a text input field for new varialbe names for adding
|
||||||
"button[9.4,1.0;2.5,0.6;add_variable;Create variable]"..
|
yl_speak_up.create_dropdown_playerlist(player, pname,
|
||||||
"tooltip[add_variable;Enter the name of your new variable.]"..
|
--table_of_names, yl_speak_up.speak_to[pname].tmp_index,
|
||||||
-- TODO: delete variable
|
table_of_vars, yl_speak_up.speak_to[pname].tmp_index_variable,
|
||||||
|
2.2, 1.9, 1.0, "list_var_names", "variable", "Delete selected variable",
|
||||||
|
"add_variable_name",
|
||||||
|
"Enter the name of the new variable you\n"..
|
||||||
|
"want to create.",
|
||||||
|
"delete_variable",
|
||||||
|
"If you click here, the selected variable\n"..
|
||||||
|
"will be deleted."
|
||||||
|
)..
|
||||||
|
additional_buttons..
|
||||||
"button[2.0,3.5;1.0,0.6;back;Back]"
|
"button[2.0,3.5;1.0,0.6;back;Back]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user