preparations for d_dynamic dialog
This commit is contained in:
parent
eaf84cfd31
commit
e3e03ee990
@ -172,6 +172,8 @@ end
|
||||
yl_speak_up.check_and_add_as_generic_dialog = function(dialog, n_id)
|
||||
yl_speak_up.generic_dialogs[n_id] = nil
|
||||
yl_speak_up.generic_dialog_conditions[n_id] = nil
|
||||
-- we do *not* want d_dynamic in generic dialogs (each NPC will get its own anyway):
|
||||
dialog.n_dialogs["d_dynamic"] = nil
|
||||
-- get the start dialog
|
||||
local d_id = yl_speak_up.get_start_dialog_id(dialog)
|
||||
if(not(d_id)
|
||||
@ -443,6 +445,19 @@ end
|
||||
|
||||
yl_speak_up.add_generic_dialogs = function(dialog, current_n_id, player)
|
||||
dialog = yl_speak_up.strip_generic_dialogs(dialog)
|
||||
-- make sure we can add d_dynamic dialog:
|
||||
if(not(dialog)) then
|
||||
dialog = {}
|
||||
end
|
||||
if(not(dialog.n_dialogs)) then
|
||||
dialog.n_dialogs = {}
|
||||
end
|
||||
-- make sure the dynamic dialog exists (as an empty dialog):
|
||||
-- (initial_dialog looks for dialog.n_npc in order to determine if it's a new npc;
|
||||
-- so we are safe here with an initialized dialog)
|
||||
dialog.n_dialogs["d_dynamic"] = {}
|
||||
dialog.n_dialogs["d_dynamic"].d_options = {}
|
||||
|
||||
if(not(player) or not(current_n_id)) then
|
||||
return dialog
|
||||
end
|
||||
@ -453,12 +468,6 @@ yl_speak_up.add_generic_dialogs = function(dialog, current_n_id, player)
|
||||
start_dialog_current = "d_1"
|
||||
end
|
||||
-- unconfigured NPC are in special need of generic dialogs
|
||||
if(not(dialog)) then
|
||||
dialog = {}
|
||||
end
|
||||
if(not(dialog.n_dialogs)) then
|
||||
dialog.n_dialogs = {}
|
||||
end
|
||||
if(not(dialog.n_dialogs[start_dialog_current])) then
|
||||
dialog.n_dialogs[start_dialog_current] = {}
|
||||
end
|
||||
|
@ -92,6 +92,11 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
||||
yl_speak_up.set_muted(pname, obj, false)
|
||||
end
|
||||
|
||||
-- changes to d_dynamic are *not* changed (the content of that dialog has to be provided
|
||||
-- dynamicly by a function):
|
||||
if(d_id == "d_dynamic") then
|
||||
return
|
||||
end
|
||||
|
||||
-- new options etc. may be added; store these IDs so that we can switch to the right target
|
||||
local result = {}
|
||||
|
@ -34,6 +34,10 @@ yl_speak_up.input_save_or_discard_changes = function(player, formname, fields)
|
||||
end
|
||||
-- clear list of changes
|
||||
yl_speak_up.npc_was_changed[ n_id ] = {}
|
||||
-- save_dialog removed d_dynamic (because that is never to be saved!); we have
|
||||
-- to add d_dynamic back so that we can use it as a target dialog in further editing:
|
||||
yl_speak_up.speak_to[pname].dialog.n_dialogs["d_dynamic"] = {}
|
||||
yl_speak_up.speak_to[pname].dialog.n_dialogs["d_dynamic"].d_options = {}
|
||||
|
||||
-- discard changes and continue on to the next dialog
|
||||
elseif(edit_mode and fields.discard_dialog_changes) then
|
||||
|
@ -308,7 +308,7 @@ yl_speak_up.get_fs_talkdialog_main_text = function(pname, formspec, h, dialog, d
|
||||
-- static help text instead of text input field for d_got_item
|
||||
if(c_d_id == "d_got_item") then
|
||||
table.insert(formspec, "hypertext[0.2,5;19.6,17.8;d_text;"..
|
||||
"<normal>Note:\nThis is a special dialog."..
|
||||
"<normal>Note:\nThis is a special dialog. "..
|
||||
"It will be called when the player clicks on "..
|
||||
"<b>I want to give you something</b>."..
|
||||
"\nMost of the things listed below will be added automaticly when you add a "..
|
||||
@ -337,7 +337,7 @@ yl_speak_up.get_fs_talkdialog_main_text = function(pname, formspec, h, dialog, d
|
||||
-- static help text instead of text input field for d_trade
|
||||
elseif(c_d_id == "d_trade") then
|
||||
table.insert(formspec, "hypertext[0.2,5;19.6,17.8;d_text;"..
|
||||
"<normal>Note:\nThis is a special dialog."..
|
||||
"<normal>Note:\nThis is a special dialog. "..
|
||||
"It will be called when the player clicks on "..
|
||||
"<b>Let's trade!</b>."..
|
||||
"\nSome of the things listed below will be added automaticly when you add a "..
|
||||
@ -367,6 +367,21 @@ yl_speak_up.get_fs_talkdialog_main_text = function(pname, formspec, h, dialog, d
|
||||
"executing the effect(s), the trade list view will be shown to the "..
|
||||
"player."..
|
||||
"\n</normal>]")
|
||||
elseif(c_d_id == "d_dynamic") then
|
||||
table.insert(formspec, "hypertext[0.2,5;19.6,17.8;d_text;"..
|
||||
"<normal>Note:\nThis is a special dialog. "..
|
||||
"Each time right before this special dialog is displayed, a "..
|
||||
"function is called that can fill the <b>d_dynamic</b> dialog "..
|
||||
"with text and options."..
|
||||
"\nThat function has to decide <b>based on NPC, player and context</b> what "..
|
||||
"it wants to display this time."..
|
||||
"\nThe d_dynamic dialog is <b>never saved</b> as part of the dialog. "..
|
||||
"It has to be dynamicly created by your function each time it is needed."..
|
||||
"\nThe d_dynamic dialog will always be available as a <b>legitimate target "..
|
||||
"dialog</b> of a dialog option. Its options can do all that options of "..
|
||||
"other dialogs can do. Its options they can lead back to normal static "..
|
||||
"parts of the dialog."..
|
||||
"\n</normal>]")
|
||||
elseif(active_dialog and active_dialog.d_text) then
|
||||
table.insert(formspec, "textarea[0.2,5;19.6,17.8;d_text;;"..
|
||||
minetest.formspec_escape(active_dialog.d_text or "?")..
|
||||
|
@ -33,7 +33,7 @@ yl_speak_up.debug = true
|
||||
--###
|
||||
|
||||
yl_speak_up.get_number_from_id = function(any_id)
|
||||
if(not(any_id) or any_id == "d_got_item" or any_id == "d_end") then
|
||||
if(not(any_id) or any_id == "d_got_item" or any_id == "d_end" or any_id == "d_dynamic") then
|
||||
return "0"
|
||||
end
|
||||
return string.split(any_id, "_")[2]
|
||||
@ -102,6 +102,10 @@ yl_speak_up.save_dialog = function(n_id, dialog)
|
||||
yl_speak_up.update_stored_npc_data(n_id, dialog)
|
||||
-- make sure we never store any automaticly added generic dialogs
|
||||
dialog = yl_speak_up.strip_generic_dialogs(dialog)
|
||||
-- never store d_dynamic dialogs
|
||||
if(dialog.n_dialogs and dialog.n_dialogs["d_dynamic"]) then
|
||||
dialog.n_dialogs["d_dynamic"] = nil
|
||||
end
|
||||
local content = minetest.write_json(dialog)
|
||||
return minetest.safe_file_write(p, content)
|
||||
end
|
||||
@ -111,6 +115,7 @@ end
|
||||
yl_speak_up.load_dialog = function(n_id, player) -- returns the saved dialog
|
||||
local p = save_path(n_id)
|
||||
|
||||
-- note: add_generic_dialogs will also add an empty d_dynamic dialog
|
||||
local file, err = io.open(p, "r")
|
||||
if err then
|
||||
return yl_speak_up.add_generic_dialogs({}, n_id, player)
|
||||
@ -561,6 +566,7 @@ function yl_speak_up.talk(self, clicker)
|
||||
self = yl_speak_up.initialize_npc(self)
|
||||
end
|
||||
|
||||
-- TODO: load inventory only when the npc actually uses one?
|
||||
-- create a detached inventory for the npc and load its inventory
|
||||
yl_speak_up.load_npc_inventory(id_prefix.."_"..tostring(self.yl_speak_up.id))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user